// JavaScript Document
	function refreshCryptImage(){
		var randomnumber=Math.floor(Math.random()*11)
		document.images['cryptImage'].src = 'crypt.php?t='+randomnumber;	
	}
	
	function focusField(){
		if(document.forms.length){
			document.forms[0][0].focus();	
		}
	}	
	
	function fadePage(){
		new Effect.Appear('pagecontent');	
	}
	
	function directTo(page){
		document.location.href=page;	
	}
	
	function IsNumeric(strString){
	  //  check for valid numeric strings	
	
	   var strValidChars = "0123456789.";
	   var strChar;
	   var blnResult = true;
	
	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
			 blnResult = false;
			 }
		  }
	   return blnResult;
	}
   
   
   function mustLogin(id){
	// <![CDATA[
			alert('You must login to view your rewards'); 
	// ]]>		
   
   }
   function popupDeal(id){
			
		
		// <![CDATA[
			removeRewardsContent();
			var ajax;
			var d = new Date()
			var t = d.getTime() 
			
			ajax =  new Ajax.Updater(
				 'rewardsContent', // DIV id must be declared before the method was called
				 'ajax/ajax_rewardDetail.php?id='+id+'&date='+t,{method:'get',asynchronous:true});
		 
		// ]]>
		
		$('rewardDetails').style.display = 'block';	
	}
	
	function closeRewardsDetail(){
		new Effect.Fade('rewardDetails');
		
	}
	
	function removeRewardsContent(){
		$('rewardsContent').innerHTML = '';
	}
   function updateSubFilter(){
	
		var catList = '';	
		var boxChecked = 0;
		for(i=0;i<document.searCats.searchSubCat.length;i++){
			if(document.searCats.searchSubCat[i].checked){
				
				if(boxChecked==0){
					catList += document.searCats.searchSubCat[i].value;		
				}else{
					catList += ','+document.searCats.searchSubCat[i].value;	
				}
				boxChecked++;
			}
			
		}
		if(boxChecked == 0){
			for(i=0;i<document.searCats.searchCat.length;i++){
				if(document.searCats.searchCat[i].checked){
					
					if(boxChecked==0){
						catList += document.searCats.searchCat[i].value;		
					}else{
						catList += ','+document.searCats.searchCat[i].value;	
					}
					boxChecked++;
				}
			
			}	
		}
		
		if(boxChecked > 0){
			$('searchText').value = '';	
		}
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "dealsBox",        		// DIV id must be declared before the method was called
			 'ajax/ajax_searchRewards.php?catList='+catList+'&t='+t,{method:'get',asynchronous:true});
	
	}
   
    function updateFilter(){
		// <![CDATA[
		var catList = '';	
		var boxChecked = 0;
		for(i=0;i<document.searCats.searchCat.length;i++){
			if(document.searCats.searchCat[i].checked){
				
				if(boxChecked==0){
					catList += document.searCats.searchCat[i].value;		
				}else{
					catList += ','+document.searCats.searchCat[i].value;	
				}
				boxChecked++;
			}
			
		}
			
		if(boxChecked > 0){
			$('searchText').value = '';	
		}
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "dealsBox",        		// DIV id must be declared before the method was called
			 'ajax/ajax_searchRewards.php?catList='+catList+'&t='+t,{method:'get',asynchronous:true});
		
		var ajax2;
		
		
		ajax2 =  new Ajax.Updater(
			 "searchSubCat",        		// DIV id must be declared before the method was called
			 'ajax/ajax_getSubCat.php?catList='+catList+'&t='+t,{method:'get',asynchronous:true, onComplete:moveWindow});
	
		// ]]>	
	}
   
	function moveWindow(){
		window.setTimeout(scrollWindowDownAbit,200);
		
	}
	
	function scrollWindowDownAbit(){
		window.scroll(0,550);	
	}	
	
	
   	function rewardsTextSearch()
	{
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		var searchText = $('searchText').value;
		if(searchText == ''){
			
			updateFilter();
		}else{
			ajax =  new Ajax.Updater(
				 "dealsBox",        		// DIV id must be declared before the method was called
				 'ajax/ajax_searchRewards.php?searchText='+searchText+'&t='+t,{method:'get',asynchronous:true});
		}
		
	}
	
	
   function popup(url){
		
		mywin = window.open(url,"MCube","menubar=0,scrollbars=1,resizable=1,width=535,height=450,left=200,top=200");	
		if (window.focus) 
		{
			mywin.focus();
		}
		return false;
	
	}
	
   	function showFullDescription(divId){
		new Effect.Appear(divId);
		$(divId).style.width='120px';
		var shortDesc = divId+"_";
		$(shortDesc).style.display='none';	
	}
	
   	function viewTopup(id){
		// <![CDATA[		
		var ajax;
		var d = new Date();
		var t = d.getTime();
		
		ajax =  new Ajax.Updater(
			 "balanceList",        		// DIV id must be declared before the method was called
			 'ajax/topup.php?id='+id+'&t='+t,{method:'get',asynchronous:true, onSuccess:showStatus});
	
		// ]]>
	}
	
	
	
	function previewName(){
		// <![CDATA[
					
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			var title = $('format_title').checked;
			var firstname = $('format_firstname').checked;
			var firstinitial = $('format_firstinitial').checked;
			var secondinitial = $('format_secondinitial').checked;
			var surname = $('format_surname').checked;
			
			
			new Ajax.Request('ajax/getPreviewName.php?title='+title+'&firstname='+firstname+'&firstinitial='+firstinitial+'&secondinitial='+secondinitial+'&surname='+surname+'&t='+t, {method: 'get', asynchronous:'true',
				  onSuccess: function(transport) {
						var previewName = $('previewName');
						var inputPreviewName = $('previewCardName');
						if (transport.responseText.length <= 21){
							previewName.update(transport.responseText);
							inputPreviewName.value = transport.responseText;
						}else{
							alert('This name is too long, please try again.');	
							previewName.update(transport.responseText);
							inputPreviewName.value = transport.responseText;
						}
				  }
			});
			
			
			
		// ]]>	
		
	}
	
	
   	function reportLost(id, status)
	{
		// <![CDATA[
			if(confirm("Are you sure?")){		
				var ajax;
				var d = new Date();
				var t = d.getTime();
				
				ajax =  new Ajax.Updater(
					 "balanceList",        		// DIV id must be declared before the method was called
					 'ajax/reportLost.php?id='+id+'&status='+status+'&t='+t,{method:'get',asynchronous:true, onSuccess:showStatus});
			}
		// ]]>	
	}
  
  	function viewBalance(id)
	{
		// <![CDATA[
			new Effect.Appear('statementLoad');
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 "balanceList",        		// DIV id must be declared before the method was called
				 'ajax/getBalance.php?id='+id+'&t='+t,{method:'get',asynchronous:true, onSuccess:showBalance});
		 	
		// ]]>
		
	}
	
	function showStatus(){
		new Effect.Appear('balanceList');	
		// <![CDATA[
			
			/*var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 "cardImage",        		// DIV id must be declared before the method was called
				 'ajax/cardImage.php?card='+id+'&status='+t+'&t='+t,{method:'get',asynchronous:true});*/
		 	
		// ]]>
	}
	
	function showBalance(){
		new Effect.Appear('balanceList');			
	}
	
	
	function getAddress(postcode, divId){
		// <![CDATA[
			new Effect.Appear('saRow');		
			new Effect.Appear('addressDisplay');
			
			
			if($('savedAddress') != null){	 
				new Effect.Fade('savedAddress');
			}
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 divId,        		// DIV id must be declared before the method was called
				 'ajax/getAddress.php?postcode='+postcode+'&divId=finalAddress&t='+t,{method:'get',asynchronous:true, onSuccess:maybeShow});
			/*if(effects){	
		 	 new Effect.toggle('hide_'+divId);
			}*/
		 	
		// ]]>
	}
	
	
	function getAddress2(postcode, divId){
		// <![CDATA[
			new Effect.Appear('saRow2');		
			new Effect.Appear('addressDisplay2');
			
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 divId,        		// DIV id must be declared before the method was called
				 'ajax/getAddress2.php?postcode='+postcode+'&divId=finalAddress2&t='+t,{method:'get',asynchronous:true, onSuccess:maybeShow2});
			/*if(effects){	
		 	 new Effect.toggle('hide_'+divId);
			}*/
		 
		// ]]>
	}
	
	
	function checkContact(theform){
		// <![CDATA[
					
		fields = "";
		valid = true;

		if(theform.senderName.value == ""){
			fields += "You must enter a name.\n";
			
			valid = false;
		}
		
		if(theform.senderEmail.value == ""){
			fields += "You must enter an email address.\n";
			
			valid = false;
		}
		if(theform.message.value == ""){
			fields += "You must enter a message.\n";
			
			valid = false;
		}
		if(theform.cryptic.value == ""){
			fields += "You must enter the image's characters.\n";
			
			valid = false;
		}
		
		
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}else{
			var d = new Date();
			var t = d.getTime(); 
			var crypticVal = theform.cryptic.value.toUpperCase();	
			
			var result = new Ajax.Request('ajax/checkCrypt.php?cryptic='+crypticVal+'&date='+t, {method: 'get', asynchronous:'true',
			  onSuccess: function(transport) {
				  	
					if (transport.responseText == "false"){
						alert("You must enter the correct security code");
						secureCheck = "false";
						
					}else{
						document.getElementById('contacter').submit();
					}
			  }
			});
			
			return(false);
		}
		
		// ]]>	
		
	}
	
	function checkPassword(theform){
		// <![CDATA[
					
		fields = "";
		valid = true;

		if(theform.username.value == ""){
			fields += "You must enter a username.\n";
			$('usernameRow').style.backgroundColor = "#FED9D9";
			$('usernameRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if(theform.dob_day.value == "" || theform.dob_month.value == "" || theform.dob_year.value == ""){
			$('dobRow').style.backgroundImage = "none";
			$('dobRow').style.backgroundColor = "#FED9D9";
			fields += "You must enter a valid date of birth.\n";
			valid = false;
		}
	
		
		
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}
		
		// ]]>	
		
	}
	
	function checkActivate(theform){
		// <![CDATA[
					
		fields = "";
		valid = true;

		if(theform.cardNum.value == ""){
			fields += "You must enter a card number.\n";
			$('cardNumRow').style.backgroundColor = "#FED9D9";
			$('cardNumRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if (IsNumeric(theform.cardNum.value) == false){
			fields += "The card number must be numeric.\n";
			$('cardNumRow').style.backgroundColor = "#FED9D9";
			$('cardNumRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if(theform.dob_day.value == "" || theform.dob_month.value == "" || theform.dob_year.value == ""){
			$('dobRow').style.backgroundImage = "none";
			$('dobRow').style.backgroundColor = "#FED9D9";
			fields += "You must enter a valid date of birth.\n";
			valid = false;
		}
		
		if(theform.activation.value == ""){
			fields += "You must enter an activation number.\n";
			$('activationRow').style.backgroundColor = "#FED9D9";
			$('activationRow').style.backgroundImage = "none";
			valid = false;
		}
	
		
		
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}
		
		// ]]>
	}
	
	
	
	
	function maybeShow(req){
		
		
   		
		var resp = req.responseText; 
		
		if(resp.indexOf('<span>') >= 0){
			addr = resp.substring((resp.indexOf('value="')+7),resp.indexOf('">',resp.indexOf('value="') ) ); 
			
			new Effect.Appear('finalAddress');	
			showFinalAddress(addr);
		}
		$('address').focus();
		$('address').select();
		
	}
	
	
	function maybeShow2(req){
		var resp = req.responseText; 
		
		if(resp.indexOf('<span>') >= 0){
			addr = resp.substring((resp.indexOf('value="')+7),resp.indexOf('">',resp.indexOf('value="') ) ); 
			new Effect.Appear('finalAddress2');	
			showFinalAddress2(addr);
		}
	}
	
	function showFinalAddress2(address, divId){
		// <![CDATA[
			checkapply3($('page2'));		
			new Effect.Appear('finalAddress2');
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 'finalAddress2',        		// DIV id must be declared before the method was called
				 'ajax/showFinalAddress.php?address='+address+"&t="+t,{method:'get',asynchronous:true});
			/*if(effects){	
		 	 new Effect.toggle('hide_'+divId);
			}*/
		 
		// ]]>
	}
	
	
	function showPrevious()
	{
		new Effect.toggle('postcodeRow2');		
		
		new Effect.toggle('saRow2');	
		
	}
	
	
	function showFinalAddress(address, divId){
		// <![CDATA[
			checkapply2($('page2'));		
			new Effect.Appear('finalAddress');
			var ajax;
			var d = new Date();
			var t = d.getTime();
			
			ajax =  new Ajax.Updater(
				 divId,        		// DIV id must be declared before the method was called
				 'ajax/showFinalAddress.php?address='+address+"&t="+t,{method:'get',asynchronous:true});
			/*if(effects){	
		 	 new Effect.toggle('hide_'+divId);
			}*/
		 
		// ]]>
	}
	
	
	function showPassport(){
		 new Effect.toggle('drivingLicenseRow');	
		 new Effect.toggle('passport1Row');	
		 new Effect.toggle('passport2Row');	
	}
	
	
	function compileStartDate(){
		$('StartDate').value = $('start_month').value+''+$('start_year').value;	
	}	
	
	function compileExpiryDate(){
		$('ExpiryDate').value = $('expiry_month').value+''+$('expiry_year').value;	
	}	
	
	function removeSpaces(text){
		var tstring = "";	
		splitstring = text.split(" ");
		for(i = 0; i < splitstring.length; i++)	{
			tstring += splitstring[i];
		}
		return tstring;
	}
	
	function checkcc(theform){
	// <![CDATA[
					
		fields = "";
		valid = true;

		if(theform.Amount.value == ""){
			fields += "You must enter a Load Amount.\n";
			$('loadAmountRow').style.backgroundColor = "#FED9D9";
			$('loadAmountRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if(theform.cardHolderName.value == ""){
			fields += "You must enter a Card Holder Name.\n";
			$('cardHolderRow').style.backgroundColor = "#FED9D9";
			$('cardHolderRow').style.backgroundImage = "none";
			valid = false;
		}
		if(theform.CardType.value == ""){
			fields += "You must enter a Card Type.\n";
			$('cardTypeRow').style.backgroundColor = "#FED9D9";
			$('cardTypeRow').style.backgroundImage = "none";
			valid = false;
		}
		if(theform.expiry_month.value == ""){
			fields += "You must enter an Expiry Month.\n";
			$('expiryDateRow').style.backgroundColor = "#FED9D9";
			$('expiryDateRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if(theform.expiry_year.value == ""){
			fields += "You must enter an Expiry Year.\n";
			$('expiryDateRow').style.backgroundColor = "#FED9D9";
			$('expiryDateRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if(theform.securityCode.value == ""){
			fields += "You must enter a Security Code.\n";
			$('securityCodeRow').style.backgroundColor = "#FED9D9";
			$('securityCodeRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if (IsNumeric(theform.Amount.value) == false){
			fields += "The load amount must only contain numeric characters.\n";
			$('loadAmountRow').style.backgroundColor = "#FED9D9";
			$('loadAmountRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if (IsNumeric(theform.CardNumber.value) == false){
			fields += "The card number must only contain numeric characters.\n";
			$('cardNumberRow').style.backgroundColor = "#FED9D9";
			$('cardNumberRow').style.backgroundImage = "none";
			valid = false;
		}
		if(theform.CardNumber.value.length > 20){
			fields += "The card number must only be 20 characters or less.\n";
			$('cardNumberRow').style.backgroundColor = "#FED9D9";
			$('cardNumberRow').style.backgroundImage = "none";
			valid = false;	
		}
		
		
		
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}
		
		// ]]>
	}
	
	
	
	function checkusername(theform){
		// <![CDATA[
					
		fields = "";
		valid = true;

		if(theform.username.value == ""){
			fields += "You must enter a username.\n";
			$('usernameRow').style.backgroundColor = "#FED9D9";
			$('usernameRow').style.backgroundImage = "none";
			valid = false;
		}
		if(theform.password.value == ""){
			fields += "You must enter a password.\n";
			$('passwordRow').style.backgroundColor = "#FED9D9";
			$('passwordRow').style.backgroundImage = "none";
			valid = false;
		}
		if(theform.confirmpassword.value == ""){
			fields += "You must enter a confirmation password.\n";
			$('confirmpasswordRow').style.backgroundColor = "#FED9D9";
			$('confirmpasswordRow').style.backgroundImage = "none";
			valid = false;
		}
		
		if(theform.securityquestion.value == ""){
			fields += "You must select a security question.\n";
			$('securityQuestionRow').style.backgroundColor = "#FED9D9";
			$('securityQuestionRow').style.backgroundImage = "none";
			valid = false;
		}
		if(theform.securityanswer.value == ""){
			fields += "You must enter a security answer.\n";
			$('securityAnswerRow').style.backgroundColor = "#FED9D9";
			$('securityAnswerRow').style.backgroundImage = "none";
			//Effect.Pulsate('titleRow');
			valid = false;
		}
		if(theform.confirmpassword.value != theform.password.value){
			fields += "You're confirmation password does not match your password.\n";
			$('confirmpasswordRow').style.backgroundColor = "#FED9D9";
			$('confirmpasswordRow').style.backgroundImage = "none";
			valid = false;
		}
		
		var title = $('format_title').checked;
		var firstname = $('format_firstname').checked;
		var firstinitial = $('format_firstinitial').checked;	
		if(title==false && firstname==false && firstinitial==false){
			fields += "You must choose either your title, firstname or first initial for the card format.\n";
			valid = false;
		}
		
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}
		
	
		// ]]>
	}
	
	
	function checkUsernameExists(username){
			// <![CDATA[
			
			var d = new Date();
			var t = d.getTime(); 
			new Effect.Appear('usernameError');
			new Ajax.Request('ajax/checkUsername.php?username='+username+'&date='+t, {method: 'get', asynchronous:'true',
				  onSuccess: function(transport) {
						var valErrror = $('usernameError');
						if (transport.responseText > 0){
							valErrror.update('<span style=\"color:#ff0000;font-weight:bold;\">This username has already been used, please try something else.</span>');
						}else{
							new Effect.Fade('usernameError');
						}
				  }
			});
			// ]]>
	}
	
	
	function checkapply1(theform){
		// <![CDATA[
		fields = "";
		valid = true;

		if(theform.title.value == ""){
			fields += "You must enter your title.\n";
			$('titleRow').style.backgroundColor = "#FED9D9";
			$('titleRow').style.backgroundImage = "none";
			//Effect.Pulsate('titleRow');
			valid = false;
		}
		
		if(theform.firstname.value == ""){
			$('firstnameRow').style.backgroundColor = "#FED9D9";
			$('firstnameRow').style.backgroundImage = "none";
			//Effect.Pulsate('firstnameRow');
			fields += "You must enter your first name.\n";
			valid = false;
		}
		if(theform.surname.value == ""){
			$('surnameRow').style.backgroundColor = "#FED9D9";	
			$('surnameRow').style.backgroundImage = "none";
			fields += "You must enter your surname.\n";
			valid = false;
		}
		if(theform.email.value == ""){
			$('emailRow').style.backgroundColor = "#FED9D9";
			$('emailRow').style.backgroundImage = "none";
			//Effect.Pulsate('emailRow');
			fields += "You must provide us with an email address.\n";
			valid = false;
		}
		if(theform.email.value.indexOf("@") == -1 || theform.email.value.indexOf(".") == -1){
			$('emailRow').style.backgroundColor = "#FED9D9";	
			$('emailRow').style.backgroundImage = "none";
			//Effect.Pulsate('emailRow');
			fields += "You must provide us with a valid email address.\n";
			valid = false;
		}
		
		/*if(theform.confirmEmail.value != theform.email.value){
			$('confirmEmailRow').style.backgroundColor = "#FED9D9";
			$('confirmEmailRow').style.backgroundImage = "none";
			//Effect.Pulsate('confirmEmailRow');
			fields += "The confirmation email address must match the email address.\n";
			valid = false;
		}*/
		if(theform.mobile.value == ""){
			$('mobileRow').style.backgroundColor = "#FED9D9";
			$('mobileRow').style.backgroundImage = "none";
			//Effect.Pulsate('homePhoneRow');
			fields += "You must enter your mobile phone number.\n";
			valid = false;
		}
		
		if(theform.source.value == ""){
			$('sourceRow').style.backgroundImage = "none";
			$('sourceRow').style.backgroundColor = "#FED9D9";
			//Effect.Pulsate('sourceRow');
			fields += "You must select a source from where you heard about the On-X card.\n";
			valid = false;
		}
		if(theform.dob_day.value == "" || theform.dob_month.value == "" || theform.dob_year.value == ""){
			$('dobRow').style.backgroundImage = "none";
			$('dobRow').style.backgroundColor = "#FED9D9";
			fields += "You must enter a valid date of birth.\n";
			valid = false;
		}
		
		if(!theform.acceptRisk.checked){
			$('acceptRiskRow').style.backgroundColor = "#FED9D9";
			$('acceptRiskRow').style.backgroundImage = "none";
			//Effect.Pulsate('termsRow');
			fields += "You must agree to the terms and conditions.\n";
			valid = false;	
		}	
		
		if(!theform.terms.checked){
			$('termsRow').style.backgroundColor = "#FED9D9";
			$('termsRow').style.backgroundImage = "none";
			fields += "You must agree to the terms and conditions.\n";
			valid = false;	
		}	
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}
		
	}
	
	
	function checkapply2(theform){
		// <![CDATA[
		 new Effect.Appear('lessRow');
		 
		var ajax, ajax2;
		var d = new Date();
		var t = d.getTime(); 
		var validation = "false";
		new Effect.Appear('validationError');
		
		new Ajax.Request('ajax/URUcheck1.php?address='+theform.address.value+'&date='+t, {
		  method: 'get',evalScripts: true, asynchronous:'true',
		  onSuccess: function(transport) {
			var valErrror = $('validationError');
			
			if (transport.responseText < 1001){
				document.location.href='apply2.php?error=points';	
			}else if(transport.responseText >= 1001 && transport.responseText <= 1109){
			  new Effect.Appear('drivingLicenseRow');	
			  new Effect.Appear('passport1Row');	
			  new Effect.Appear('passport2Row');	
			  validation = "false";		
			  valErrror.update('<span style=\"color:#ff0000;font-weight:bold;\">Your details do not provide us with enough information, please provide either your Drivers license or passport number. ');
			}else{
				
			  validation = "true";
			  valErrror.update('<span style=\"color:#0A8326;font-weight:bold;\">Your details have been confirmed, please wait.......</span>');
			  theform.submit();
			}
		  }
		});
		// ]]>
		return false;
	}
	
	
	function checkapply3(theform){
		// <![CDATA[
		var ajax, ajax2;
		var d = new Date();
		var t = d.getTime(); 
		var validation = "false";
		new Effect.Appear('validationError');
		new Ajax.Request('ajax/URUcheck1.php?address='+theform.address.value+'&address2='+theform.address2.value+'&date='+t, {
		  method: 'get',evalScripts: true, asynchronous:'true',
		  onSuccess: function(transport) {
			var valErrror = $('validationError');
			
			if (transport.responseText < 1001){
				document.location.href='apply.php?error=points';
			}else if(transport.responseText >= 1001 && transport.responseText <= 1109){
				
			  validation = "false";		
			  valErrror.update('<span style=\"color:#ff0000;font-weight:bold;\">Your details do not provide us with enough information, please provide either your Drivers license or passport number. ');
			}else{
				
			  validation = "true";
			  valErrror.update('<span style=\"color:#0A8326;font-weight:bold;\">Your details have been confirmed, please wait.......</span>'); 
			  theform.submit();
			}
		  }
		});
		// ]]>
		return false;
		
	}
	
	
	
	function checkApply2b(theform){
		// <![CDATA[
		
		var d = new Date();
		var t = d.getTime(); 
		var validation = "false";
		if(document.getElementById('postcode').value == ""){
				
			$('postcodeRow').style.backgroundColor = "#FED9D9";
			$('postcodeRow').style.backgroundImage = "none";
			
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += "You must fill in the postcode";
			alert(message);
			return(false);						 
		}
		
		
			
		if(document.getElementById('address') != null){	
			if(document.getElementById('address').value == ""){
				
				$('saRow').style.backgroundColor = "#FED9D9";
				$('saRow').style.backgroundImage = "none";
				message = "Please address the highlighted fields\n";
				message += "--------------------------------------------------\n";
				message += "You must fill in the address";
				alert(message);
				return(false);						 
			}else{
				
				new Effect.Appear('validationError');
				var url = 'ajax/URUcheck1.php?address='+theform.address.value+'&address2='+theform.address2.value+'&date='+t+'&drivingLicense='+theform.drivingLicense.value+'&passport1='+theform.passport1.value+'&passport2='+theform.passport2.value+'&passport3='+theform.passport3.value+'&passport4='+theform.passport4.value+'&passport5='+theform.passport5.value+'&passport6='+theform.passport6.value+'&passport7='+theform.passport7.value+'&passport8='+theform.passport8.value+'&passportType='+theform.passportType.value;
			}
			
			if($('drivingLicense') != null){
				new Effect.Appear('validationError');	
				var url = 'ajax/URUcheck1.php?date='+t+'&drivingLicense='+theform.drivingLicense.value+'&passport1='+theform.passport1.value+'&passport2='+theform.passport2.value+'&passport3='+theform.passport3.value+'&passport4='+theform.passport4.value+'&passport5='+theform.passport5.value+'&passport6='+theform.passport6.value+'&passport7='+theform.passport7.value+'&passport8='+theform.passport8.value+'&passportType='+theform.passportType.value;	
			}
			
			var myRequest = new Ajax.Request(url, {
			  method: 'get', asynchronous:'true',
			  onSuccess: function(transport) {
				var valErrror = $('validationError');
				
				if (transport.responseText < 1001){
					document.location.href='apply.php?error=points';
				}else if(transport.responseText >= 1001 && transport.responseText <= 1109){	
				  validation = "false";		
				  valErrror.update('<span style=\"color:#ff0000;font-weight:bold;\">Your details do not provide us with enough information, please provide either your Drivers license or passport number.');
				}else{				
				  validation = "true";
	
				  valErrror.update('<span style=\"color:#0A8326;font-weight:bold;\">Your details have been confirmed, please wait.......</span>');
				  theform.submit();
				}
			  },
			  onFailure: function(t) {
				alert('Error ' + t.status + ' -- ' + t.statusText);
			  }
			});
		}
		// ]]>
	}
	
	
	
	var previewUsed = 0;
	
	var onoff;
	function toggleCList(field){
		//alert($('checkboxcount').value);
		if(onoff=='1'){
			onoff = '0';
		}else{
			onoff = '1';
		}
		
		for(i=0;i<$('checkboxcount').value;i++){
			if(onoff == '0'){
				$(field+''+i).checked=false;
			}else{
				$(field+''+i).checked=true;
			}
		}
	}				
	
	function restoreRowBg(rowId){
		$(rowId).style.backgroundImage = "url(images/tr_bg.gif)";
		$(rowId).style.backgroundColor = "#FFFFFF";
	}
	
	
	
	function popUpWindow(url, id){
		GB_showCenter('Deals', url+'?id='+id);
	}
	
	function openWindow(id){
		mywin = window.open('popup2.php?section='+id,"pop","menubar=0,scrollbars=1,resizable=1,width=700,height=600");	
		if (window.focus) 
		{
			mywin.focus();
		}
		return false;
	}
	
	
	function deleteFile(fieldname, id, sectId)
	{
		// <![CDATA[
			
			var ajax;
			var d = new Date()
			var t = d.getTime() 
			
			ajax =  new Ajax.Updater(
				 'fileLocation_'+fieldname,        		// DIV id must be declared before the method was called
				 'ajax_deleteFile.php?fieldname='+fieldname+'&id='+id+'&date='+t+'&sectId='+sectId,{method:'get',asynchronous:true});
		 
		// ]]>
			
	}
	

	
	function goback()
	{
		
		history.go(-1);	

	}
	
	function toggleMenuItem(div){
			if(document.getElementById(div).style.display == "block"){
				document.getElementById(div).style.display = "none";
			}else{
				document.getElementById(div).style.display = "block";
			}
		}
		function sureyn() {
			return confirm("Are you sure?");
		}
		
		function toggleArrow(div){
			var imaage_array=div.src.split("/");
			
			if(imaage_array[(imaage_array.length)-1]=='open.gif'){
				div.src='images/close.gif';
			}else{
				div.src='images/open.gif';	
			}
			
		}
		
		
		function toggleDiv(divId)
		{
			 new Effect.toggle(divId);
		}
		var folderlist = '';
		
		function useFolder(foldername, top)
		{
			if(top==2){	
				folderlist += foldername+'/';	
				$('foldername').value=folderlist;
			}else{
				folderlist = '';
				folderlist += foldername+'/';	
				$('foldername').value=folderlist;
			}
		}
		
		function divOn(div)
		{
				
			document.getElementById(div).style.display = 'block';	
			
		}
	   function recordData()
	   {
		  
	   		getRecordData();
			document.getElementById('recordData').style.display = 'block';
			document.getElementById('metaData').style.display = "none";
			//document.getElementById('previewData').style.display = 'none';
			new Ajax.Request('removePreviewTemp.php');
	   }
	   
	   function homePreview(id, root)
	   {
			new Ajax.Request('ajax_setPreviewId.php?id='+id);  
			GB_showFullScreen('Preview', root+'/page.php?type=preview');
	   }
	   
	   
	   function preview(root)
	   {
		   	
		   
				saveTempRecord();
				saveRecordPreview();
				
				/*window.frames['previewFrame'].document.location.reload(false);
				document.getElementById('previewData').style.display = 'block';
				document.getElementById('recordData').style.display = 'none';
				document.getElementById('metaData').style.display = "none";*/
			
			GB_showFullScreen('Preview', root+'/page.php?type=preview');
			setTimeout("new Ajax.Request('removePreviewTemp.php')",3000);
	   }
	   
	   function imagePreview(image)
	   {
			GB_showCenter('Image Preview', image);  
	   }
	   
	   function reloadData()
	   {
			window.location.reload( false );   
	   }
	   
	   
	   function previewFromMeta()
	   {
		  
		   	document.getElementById('previewData').style.display = 'block';
			document.getElementById('recordData').style.display = 'none';
			document.getElementById('metaData').style.display = "none";
	   }
	   
	   
	   function historyPreview(url)
	   {
		    GB_showFullScreen('Preview', url);	
			//document.getElementById('previewBlock').style.display = 'block';
		   	//document.getElementById('historyPrev').src = url;
			   
	   }
	    
	   function showMessages()
	   {
		 
		   	new Effect.Appear('messages');
			timerID = setTimeout("hideMessages()", 5000);
	   }
	   
	   function hideMessages()
	   {
			new Effect.Fade('messages');	   
	   }
	   
	   function getRecordData()
	   {
		   	window.location.reload( false );
	   }
	   
	   
	   function metaData()
	   {
	   		saveTempRecord();
			document.getElementById('recordData').style.display = 'none';
			document.getElementById('metaData').style.display = "block";
			//document.getElementById('previewData').style.display = 'none';
	   }
	   
	   
	    function getModule(divId, query, level, effects, start, mainMenu, searchTerm){
		// function getModule(){
			 
			// <![CDATA[
			
			var ajax;
			var d = new Date()
			var t = d.getTime() 
			
			ajax =  new Ajax.Updater(
				 'hide_'+divId,        		// DIV id must be declared before the method was called
				 'ajax_modList.php?modId='+divId+'&query='+query+'&level='+level+'&date='+t+'&start='+start+'&mainMenu='+mainMenu+'&searchTerm='+searchTerm,{method:'get',asynchronous:true});
			if(effects){	
		 	 new Effect.toggle('hide_'+divId);
			}
		 
		// ]]>
		
		
	}
	
	
	function searchModule(divId, query, level, effects, start, mainMenu, searchTerm){
		// <![CDATA[
			
			var ajax;
			var d = new Date()
			var t = d.getTime() 
			
			ajax =  new Ajax.Updater(
				 'hide_'+divId,        		// DIV id must be declared before the method was called
				 'ajax_modList.php?modId='+divId+'&query='+query+'&level='+level+'&date='+t+'&start='+start+'&mainMenu='+mainMenu+'&searchTerm='+searchTerm,{method:'get',asynchronous:true});
			
		// ]]>
			
	}
	function getModule2(divId, query, level){
		
			 
			// <![CDATA[
			
			var ajax;
			var d = new Date()
			var t = d.getTime() 
			
			ajax =  new Ajax.Updater(
				 'hide2_'+divId,        		// DIV id must be declared before the method was called
				 'ajax_modList.php?modId='+divId+'&query='+query+'&level='+level+'&date='+t,{method:'get',asynchronous:true});
			
		 new Effect.toggle('hide2_'+divId);
		 //	new Effect.toggle('hide2_'+divId);
		// ]]>
		
		
	}
	
	   function metaDataFromPreview()
	   {
	   		
			document.getElementById('recordData').style.display = 'none';
			document.getElementById('metaData').style.display = "block";
			document.getElementById('previewData').style.display = 'none';
	   }
	   
	   function metaDataMeta()
	   {
	   		saveTempRecordMeta();
			document.getElementById('recordData').style.display = 'none';
			document.getElementById('metaData').style.display = "block";
			document.getElementById('previewData').style.display = 'none';
	   }
	   
	   
	   var seshSaved = function(t) {
			//alert("should of saved ok"+t.responseText);
		}
		
		var seshError = function(t) {
			alert('Error ' + t.status + ' -- ' + t.statusText);
			
		}
	   
	   
	  function saveRecordPreview()
	   {
		   // <![CDATA[	
			title = document.record.Title.value;
			
			entrydate = document.record.EntryDate.value;
			document.record.Copy.EscapeUnicode = true;
			copy = document.record.Copy.value;
			
			//document.getElementById('Copy').EscapeUnicode = true;document.getElementById('Copy_temp').value = document.getElementById('Copy').value;
			new Ajax.Request('createTempRecord.php', {parameters:'title='+title+'&entrydate='+entrydate+'&copy='+copy, onSuccess:seshSaved, onFailure:seshError, asynchronous:true});
			
			
			
			// ]]>
	   }
	   
	   
	   function saveTempRecord()
		{
			// <![CDATA[
					
			title = document.record.Title.value;
			/*entryDay = document.record.day.value;
			entryMonth = document.record.month.value;
			entryYear = document.record.year.value;*/
			entrydate = document.record.EntryDate.value;
			document.record.Copy.EscapeUnicode = true;
			copy = document.record.Copy.value;
			
			//document.getElementById('Copy').EscapeUnicode = true;document.getElementById('Copy_temp').value = document.getElementById('Copy').value;
			new Ajax.Request('storeTempRecord.php', {parameters:'title='+title+'&entrydate='+entrydate+'&copy='+copy, onSuccess:seshSaved, onFailure:seshError, asynchronous:true});
			
			// ]]>
		}
		 

	
	   function checkUserForm(uForm){
	   		
	   		success = true;
			message = "";
	   		if(uForm.username.value==""){
				message += 'You must enter a Username';
				success = false;
			}
			//alert("yo" + uForm.username.value);
			if(success == false){
				alert(message);
				return(false);	
			}else{
				return(true);	
			}
	   }
	   
	   function sortthelist(sortdirection){
		if(sortdirection=='up'){
			if(document.getElementById('sortlist').selectedIndex != 0){
				sItem1 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].text
				sItemValue1 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].value
				sItem2 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex - 1].text
				sItemValue2 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex - 1].value
				
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].text = sItem2
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].value = sItemValue2
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex - 1].text = sItem1
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex - 1].value = sItemValue1
				
				document.getElementById('sortlist').selectedIndex = document.getElementById('sortlist').selectedIndex - 1
			}
		}else{
			if(document.getElementById('sortlist').selectedIndex < (document.getElementById('sortlist').length - 1)){
				sItem1 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].text
				sItemValue1 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].value
				sItem2 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex + 1].text
				sItemValue2 = document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex + 1].value
				
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].text = sItem2
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex].value = sItemValue2
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex + 1].text = sItem1
				document.getElementById('sortlist').options[document.getElementById('sortlist').selectedIndex + 1].value = sItemValue1
				
				document.getElementById('sortlist').selectedIndex = document.getElementById('sortlist').selectedIndex + 1
			}
		}
	}

	function savesortorder(){
		
		var sTemp = new String;
		
		//alert(document.getElementById('sortlist').length);
		
		// selects all items in a list
		for(i=0;i<document.getElementById('sortlist').length;i++){
			 sTemp = sTemp + document.getElementById('sortlist').options[i].value + ',';
		}
		
		sTemp= sTemp.substring(0,sTemp.length - 1)
		document.getElementById('sortorder').value = sTemp
		
	}
	
	// For AJAX loading images
	
	var ajaxloader = function(ele, file) {
			var cont = document.getElementById(ele);
			img = document.createElement('img');
			img.src = file;
			cont.appendChild(img);
	}
	
	// Returns an array of all the indexes  found (it will return false if it doesn't find anything). 
	// in addition to passing a string or number you can pass a regular expression
	Array.prototype.find = function(searchStr) {
	  var returnArray = false;
	  for (i=0; i<this.length; i++) {
		if (typeof(searchStr) == 'function') {
		  if (searchStr.test(this[i])) {
			if (!returnArray) { returnArray = [] }
			returnArray.push(i);
		  }
		} else {
		  if (this[i]===searchStr) {
			if (!returnArray) { returnArray = [] }
			returnArray.push(i);
		  }
		}
	  }
	  return returnArray;
	}
	
	Array.prototype.inArray = function (value) {
	var i;
	for (i=0; i < this.length; i++) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};

// Used to hide/show page type user information when adding a goedit section
// Uses prototype
function pageType(ele)
{
	for(var i=0;i<ele.options.length;i++) {
		if($(ele.options[i].value)) {
			if(ele.options[i].value == ele.options[ele.selectedIndex].value) {
				$(ele.options[ele.selectedIndex].value).show();
				$(ele.options[ele.selectedIndex].value+"Label").show();
			} else {
				$(ele.options[i].value).hide();
				$(ele.options[i].value+"Label").hide();
			}
		}
	}
}


//brendon.spronk - 26 May 2009 - log click on megapod
//field 8 (id) is found as id in megapod.megapod and components.comp_id in megapod.components	
function LogClick(site_id,pod_name,link,img_link,refer_browser,user_status,user_id,id){

	//alert('You clicked :'+id1+''+id2+''+id3+'');
	// <![CDATA[
	
		var ajax;
		var d = new Date()
		var t = d.getTime() 
		
		ajax =  new Ajax.Updater(
			 'megapod', // DIV id must be declared before the method was called
			 'modules/megapod/megapod_click.php?site_id='+site_id+'&pod_name='+pod_name+'&link='+link+'&img_link='+img_link+'&refer_browser='+refer_browser+'&user_status='+user_status+'&user_id='+user_id+'&podid='+id+'' ,{method:'get',asynchronous:true} );
	 
	// ]]>

}

function clearField(el) {
	if (el.defaultValue==el.value) el.value = ""
	}


function checkReferFriend(theform){
	
	fields = "";
	valid = true;

		if(theform.name.value == ""){
		fields += "You must enter your name.\n";
		valid = false;
		}
		
		if(theform.email.value == ""){
			fields += "You must enter an email address.\n";
			valid = false;
		}
		
		if(theform.email.value.indexOf("@") == -1 || theform.email.value.indexOf(".") == -1){
			fields += "You must provide us with a valid email address.\n";
			valid = false;
		}
		
		
		if(theform.to_name.value == ""){
			fields += "You must enter your friends name.\n";
			valid = false;
		}
		
		if(theform.to_email.value == ""){
			fields += "You must enter your friends email address.\n";
			valid = false;
		}
		
		if(theform.to_email.value.indexOf("@") == -1 || theform.to_email.value.indexOf(".") == -1){
			fields += "You must provide us with a valid friends email address.\n";
			valid = false;
		}
		
		if(valid == false){
			message = "Please address the highlighted fields\n";
			message += "--------------------------------------------------\n";
			message += fields;
			alert(message);
			return(false);
		}
		
	}