
// This script ensures this page is not loaded into anyone's frames 
 
// if (top.location != self.location) {
//	top.location = "index.php";
//	}


 /* This script makes the pull down menu work to go to the page you want */
//function goUrl(Selected) {	 
//	var newURL = Selected.options[Selected.selectedIndex].value ;
//	if (newURL!=" ") {
//		document.location.href = newURL;
//	}
//}




 /* This script is for the donations */
function chk(frm) {
 if (frm.donation.value == "")
{
alert("Please enter your donation in the box provided.");
frm.donation.focus();
return (false);
}
var checkOK = "0123456789.";
var checkStr = frm.donation.value;
var allValid = true;
var decPoints = 0;
var allNum = "";
for (i = 0;i < checkStr.length;i++)
{
ch = checkStr.charAt(i);
for (j = 0;j < checkOK.length;j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch == ".")
{
allNum += ".";
decPoints++;
}
else
allNum += ch;
}
if (!allValid)
{
alert("Please use only numbers. (If needed, use the period \".\" sign for the decimal place.)");
frm.donation.focus();
return (false);
}
if (decPoints > 1)
{
alert("Please enter a valid number (only use one period).");
frm.donation.focus();
return (false);
}
var chkVal = allNum;
var prsVal = parseFloat(allNum);
if (chkVal != "" && !(prsVal > "0"))
{
alert("Please enter your donation in the box provided.");
frm.donation.focus();
return (false);
}
frm.amount.value = OKStrOfMN(allNum,1,2)	
return (true);
}



// OKStrOfMN
// rounds off X to N decimal places, ensuring there are at least M leading 0's
// http://www.merlyn.demon.co.uk/js-maths.htm
function OKStrOfMN(X, M, N) 
	{
		var T, S=new String(Math.round(X*Number("1e"+N)))
		while (S.length<M+N) S='0'+S
		var y = S.substr(0, T=(S.length-N));
		if(N>0) 
			{
				y += '.' + S.substr(T, N);
			}
		return y;
	}



	

var highlight_text_on = false	

	
// Highlights search term in articles in campaigns and related sections - turn on and off if possible
// Very simple highlighting script
function highlight_text(txt)
	{		
		if (highlight_text_on == false)
		
			{		
										
			var tag_name_array = new Array ("p","h2","h3","h5", "li") // Exclude h6 in order to preserve the article header links
			//var num = tag_name_array.length;					//and exlude h1 because (apart from being obvious) it highlights the title
			//alert("There are " + num + " elements in this document");				
			
			for (i=0; i < tag_name_array.length; i++) 
				{ 
				 	tag_name = tag_name_array[i]
					//alert (tag_name)
					//tag_name = "p";
					var paras = document.getElementsByTagName(tag_name)
					
					var update_needed = false;			
					
					for (j=0; j < paras.length;  j++) // Go through all paragraphs of each type in array
						{
							
							//n = n+1
							
							p = paras[j];	
							
							z = p.innerHTML
							
							
							if (z.indexOf(" href=") != - 1 || z.indexOf("whitelink") != - 1 || z.indexOf("blacklink") != - 1 || z.indexOf("id=pic") != - 1 || z.indexOf("MS Sans Serif") != - 1)					
							// Don't highlight links:
						
								{
									continue;
									
								}else{
									


									y = p.innerText	// Must be a one line version of these two lines. Can't find it

											// split keyword if it is a phrase 
									phrase_array = txt.split(" ");
									
									for (a=0; a < phrase_array.length; a++) 
										{ 						
					
											keyword_txt = phrase_array[a]
											//alert (keyword_txt)
											
											if (keyword_txt == "the" || keyword_txt == "and")
												{
													continue;
												}
											
											// txt is first letter capitalised		
											highlight_text_on = true
											newstr = "<font name='font_highlight' style='background-color:yellow'>" + keyword_txt + "</font>";
											
											
											itxt = keyword_txt.toLowerCase()
											inewstr = "<font name='font_highlight' style='background-color:yellow'> " + itxt + " </font>";
						
						
										// If I could be bothered it would look neater to iterate through 
										// upper and lower case but there is not much in it
										
											if (y)
												{
													//keyword_txt = "	" + keyword_txt + " "; 
													//if (y.match(keyword_txt))
													if (y.indexOf(keyword_txt) != - 1)
														{							

															// Call function (line 213) to replace the string
															y = replace_str(y,keyword_txt,newstr) 
															update_needed = true;
															//alert (y)
															
							
														}													
													itxt = " " + itxt + " "; 
													//alert(itxt)
													//var re = new RegExp(/\sitxt\s/);
													//if (y.match(re))
													if (y.indexOf(itxt) != - 1)
														{								
															// Call function (line 213)
															y = replace_str(y,itxt,inewstr) 
															update_needed = true;
															//alert (y)
															
							
														}
												}
												
										
										}											
								}
								
							if (update_needed == true)
								{
									document.getElementsByTagName(tag_name)[j].innerHTML=y	
								}
							
	
								
								
								
						}
								
					}
					
			}else{
				
				window.location.reload()
			}	
	
	}
		


function replace_str(w,s,n)
{
    replace_location = w.indexOf(s)
    left_string = w.substring(0,replace_location)
    right_string = w.substring(replace_location + s.length)
    t2 = left_string + n + right_string
    return t2
}



var alphabet = new Array ("A","B","C","D","E","F","G","H","I","J","K","L","M",
"N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

function homepage_keywords(keyletter)
	{
		//alert ('al ' + alphabet[6])
		// Close existing display
		for (x = 0; x < 26; x++)
    		{
				alpha = alphabet[x];
				//alert ('alpha is ' + alpha)
				document.getElementById(alpha).style.display='none';				
			}
		
		// Display chosen 
		//alert ('hello ' + keyletter)
		document.getElementById(keyletter).style.display='block';
	}
	

function val_mail_friend(frm)
	{	
						
		if (frm.to_email.value == "")
			{
	            alert("Please enter the destination email in the \"email address\" field.");
	    		frm.to_email.focus();
				return (false)
        						
        	}else
        	
		if (frm.your_name.value == "")
			{
				alert("Please enter your name in the \"Name\" field.");
				frm.your_name.focus();
				return (false);
						
        	}else	
						
		if (frm.your_email.value == "")
			{
	            alert("Please enter your email in second \"email address\" field.");
	    		frm.your_email.focus();
				return (false)
        						
        	}else
		
            {
				return true;
			}    
	}

// Socialism event

function validEmail(email) {
			invalidChars = " /:,;"
	
			if (email == "") {						// cannot be empty
				emailwrong = "No email address. "
				return false
			}
			for (i=0; i<invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					emailwrong = "Illegal characters in email address. "
					return false
				}
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				emailwrong = "Missing @ in email address. "
				return false
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				emailwrong = "More than one @ in email address. "
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				emailwrong = "Missing '.' in email address. "
				return false
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				emailwrong = "Missing characters after the '.' in email address. "
				return false
			}
			return true
		}


// Socialism event

var emailwrong = "No email address. "
function check_booking(frm)
{

	if(frm.amount.value == 0)
	{
	alert("Please email us for special bulk rates, or select your number of tickets") 
	frm.t1.focus();
   return (false);
  }

  if (frm.name.value == "")
  {
    alert("Please enter your name in the \"Name\" field.");
    frm.name.focus();
    return (false);
  }
  
  if (!validEmail(frm.email.value)) {
		alert(emailwrong + " Please check your email address. Thanks.")
		frm.email.focus()
		frm.email.select()
		return false
	}
	
  if (frm.address.value == "")
  {
    alert("Please enter your address in the \"Address\" field.");
    frm.address.focus();
    return (false);
  }
  
	c0 = frm.country1.selectedIndex;					//Set country code and country full 
	c1 = frm.country1.options[c0].value;
	frm.country.value = c1.split(";")[0];
	frm.MC_countryFull.value = c1.split(";")[1];
  
  if (frm.country.value == "none")
  {
    alert("Please enter your country in the \"country \" field.");
    frm.country1.focus();
    return (false);
  }
  
	
	frm.MC_delname.value = frm.name.value				// set the delivery name and address
 	frm.MC_deladdress.value = frm.address.value
 	frm.MC_delpostcode.value = frm.postcode.value

   	return (true);
}


// Socialism event
function unfocus(x) {								// Stops user entering amount field
	document.ticForm.tickets.focus();
	}


// Socialism event
function recal(frm) 

	{
tot = 0
	
	
	t=frm.t1.selectedIndex			
	tic1 = frm.t1.options[t].value
	if (tic1 > 0)
	   {
			tot = tot + full_weekend*tic1
   			desc1 = tic1 + " Full Weekend ticket(s),"
   		}else{
   		    desc1 = ""
   		}
   		
	
	t=frm.t2.selectedIndex			
	tic2 = frm.t2.options[t].value
	if (tic2 > 0)
	   {
			tot = tot + weekend_conc*tic2
			desc2 = tic2 + " Weekend Concession ticket(s),"
		}else{
   		    desc2 = ""
   		}


	t=frm.t3.selectedIndex			
	tic3 = frm.t3.options[t].value
	if (tic3 > 0)
	   {
			tot = tot + day_full*tic3
			desc3 = tic3 + " One day only ticket(s),"
		}else{
   		    desc3 = ""
   		}

	t=frm.t4.selectedIndex			 
	tic4 = frm.t4.options[t].value
	if (tic4 > 0)
	   {
			tot = tot + day_conc*tic4
			desc4 = tic4 + " One day only concession ticket(s),"
		}else{
   		    desc4 = ""
   		}
   	
   	t=frm.t5.selectedIndex			 
	tic5 = frm.t5.options[t].value
	if (tic5 > 0)
	   {
			tot = tot + rally*tic5
			desc5 = tic5 + " Rally ticket(s),"
		}else{
   		    desc5 = ""
   		}
   	
   	t=frm.t6.selectedIndex			
	tic6 = frm.t6.options[t].value
	if (tic6 > 0)
	   {
			tot = tot + hostel*tic6
   			desc6 = tic6 + " Hostel place(s),"
   		}else{
   		    desc6 = ""
   		}
   		

	frm.amount.value = OKStrOfMN(tot, 1, 2)
	frm.total.value = "£ " + frm.amount.value
  	frm.cartId.value = soc_weekend_title + ": " + desc1 + " " + desc2 + " " + desc3 + " " + desc4 + " " + desc5 + " " + desc6 + " Total " + frm.total.value  	
	frm.desc.value = "Ticket purchase for " + soc_weekend_title
	frm.MC_desc.value = soc_weekend_title
	alert(frm.cartId.value)

}


