function OpenTerms(){
 		var mywindow = window.open ("termspopup.php","TermsConditions","location=0,status=0,scrollbars=1,width=750,height=700"); 
		mywindow.moveTo(300,100);
}


function OpenPopup(){
		mywindow = window.open ("whyneed.htm","WhyNeeded","location=0,status=0,scrollbars=0,width=550,height=200"); 
		mywindow.moveTo(300,550);
}

function VerifyAge(day,month,year){
		 
}

function ValidateStep1() {
	 
	 
	 if(NewSelectValidate(document.frmregister.customer_Title,"customer_Title",'Title')==false){ return false };
	 if(NewTextValidate(document.frmregister.customer_First_Name,"customer_First_Name",'First Name')==false){ return false };
	 if(NewTextValidate(document.frmregister.customer_Surname,"customer_Surname",'Last Name')==false){ return false };
	 //DOB
	 if(NewSelectValidate(document.frmregister.customer_date,"customer_date",'Date')==false){ return false };
	 if(NewSelectValidate(document.frmregister.customer_month,"customer_month",'Month')==false){ return false };
	 if(NewSelectValidate(document.frmregister.customer_year,"customer_year",'Year')==false){ return false };
	 
	 if(NewSelectValidate(document.frmregister.customer_Gender,"customer_Gender",'Gender')==false){ return false }; 
	 
	 if(NewTextValidate(document.frmregister.customer_Email,"customer_Email",'Email')==false){ return false };
	 if(NewEmailValidate(document.frmregister.customer_Email,'customer_Email',"Valid Email")==false){ return false };
	 
	 
   	 if(document.getElementById("hid_customer_Email").value==1){
 		 	return false;
	 }
 	 
	 if(NewTextValidate(document.frmregister.customer_Password,"customer_Password",'Password')==false){ return false };
	 if(NewTextValidate(document.frmregister.customer_Confirm_Password,"customer_Confirm_Password",'Confirm Password')==false){ return false };
	 if(Comparetextboxes(document.frmregister.customer_Password,document.frmregister.customer_Confirm_Password,"customer_Password","customer_Confirm_Password")==false){ return false;}

	 if(isAlphanum(document.frmregister.customer_Password.value)==false){  document.frmregister.customer_Password.focus();return false; }
	 
	 if(NewTextValidate(document.frmregister.customer_Tel,'customer_Tel','Telephone Number')==false){ return false };
	 
	 if(document.frmregister.customer_Mailing_List.checked == true) {
		 	document.frmregister.customer_Mailing_List.value = 1;
	 } else {
		 document.frmregister.customer_Mailing_List.value = 0;
	 }
	 
	var name = trimAll(document.frmregister.customer_Email.value);
	if (window.XMLHttpRequest) {
	xmlhttp = new XMLHttpRequest();
	}
	//If the user is using IE
	else if (window.ActiveXObject) {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	var url = "ajaxemailidcheck.php?type=add&name="+name;						
	xmlhttp.open('GET', url, true);
	xmlhttp.onreadystatechange = function() {
		if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
			var answer = xmlhttp.responseText;
			if(answer=="") {				
				document.frmregister.submit();
				return true;				
			}else {
				document.frmregister.customer_Email.focus();	
				document.getElementById("emailertext").style.display="";	
				document.getElementById("emailertext").innerHTML = answer;
				return false;
			}
		}
	}
	xmlhttp.send(null);			
	return false;	
	
}
//*********************************Step 2************************************************
function ValidateStep2(){
	if(NewTextValidate(document.frmregisterstep2.customer_Postcode,"customer_Postcode",'Postcode')==false){ return false };
 	/*if(document.frmregisterstep2.find_postcode.value == 0){
		alert("Find your address");
		return false;
	}	*/
	if(document.frmregisterstep2.address){
		if(SelectValidate(document.frmregisterstep2.address,'Address')==false){ return false };
	}
	if(NewTextValidate(document.frmregisterstep2.customer_Address,"customer_Address",'Address line 1')==false){ return false };
	//if(TextValidate(document.frmregisterstep2.customer_Deliv_Address2,'Address line 2')==false){ return false };
	if(NewTextValidate(document.frmregisterstep2.customer_Town,"customer_Town",'Town/City')==false){ return false };
	if(NewTextValidate(document.frmregisterstep2.customer_County,"customer_County",'County')==false){ return false };
	if(document.frmregisterstep2.customer_Country_ID){
		if(NewSelectValidate(document.frmregisterstep2.customer_Country_ID,"customer_Country_ID",'Country')==false){ return false };
	}
	if(NewTextValidate(document.frmregisterstep2.customer_Postcode,"customer_Postcode",'Postcode')==false){ return false };
	if(document.frmregisterstep2.customer_Delivery.checked==true){
			document.frmregisterstep2.customer_Delivery.value = 1;
	} else {	
		document.frmregisterstep2.customer_Delivery.value = 0;
	}	
 	return true;
}

//*********************************Step 3************************************************
function ValidateStep3(){
	//if(NewSelectValidate(document.frmregisterstep3.customer_Ship_Title,"customer_Ship_Title",'Title')==false){ return false };
	//if(TextValidate(document.frmregisterstep3.customer_Ship_FirstName,'First Name')==false){ return false };
	//if(TextValidate(document.frmregisterstep3.customer_Ship_LastName,'Last Name')==false){ return false };
	
	if(NewTextValidate(document.frmregisterstep3.customer_D_Postcode,"customer_D_Postcode",'Postcode')==false){ return false };
	
 	if(NewTextValidate(document.frmregisterstep3.customer_D_Address,"customer_D_Address",'Address line 1')==false){ return false };
	//if(TextValidate(document.frmregisterstep3.customer_Ship_Address2,'Address line 2')==false){ return false };
	if(NewTextValidate(document.frmregisterstep3.customer_D_Town,"customer_D_Town",'Town/City')==false){ return false };
	if(NewTextValidate(document.frmregisterstep3.customer_D_County,"customer_D_County",'County')==false){ return false };
	if(document.frmregisterstep3.customer_D_Country_ID){
		if(NewSelectValidate(document.frmregisterstep3.customer_D_Country_ID,"customer_D_Country_ID",'Country')==false){ return false };
	}
	
 	
	return true;
}

//*********************Check existence of duplicate users**********************************************
function Check_User_Exists(emailaddress) {	
 	var xmlhttp; 
	var emailertext = "";
	if (window.XMLHttpRequest) {
	  // code for IE7+, Firefox, Chrome, Opera, Safari
	  xmlhttp=new XMLHttpRequest();
	} else if (window.ActiveXObject) {
	  // code for IE6, IE5
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	} else {
	  alert("Your browser does not support XMLHTTP!");
	}		
	
	xmlhttp.open("GET","usercheck.php?emailaddress="+emailaddress,true);
	
	
	document.getElementById("emailertext").innerHTML = "";
	document.getElementById("hid_customer_Email").value = 0;
	
	xmlhttp.onreadystatechange = function() {
	if(xmlhttp.readyState==4)
	  {
 		emailertext = xmlhttp.responseText;
		if(emailertext!=0){
			document.getElementById("hid_customer_Email").value = 1;
			document.getElementById("emailertext").innerHTML = "&nbsp;Email already exists";
  		} 
  	  }
	}
	xmlhttp.send(null);		
}

/**
Show the manual entry divs
***/
function EnterAddressManually(type) {	
	if(type=="bill") {
		var form = document.frmregisterstep2;
		form.customer_Buildingnumber.value = "";
		form.customer_Buildingname.value = "";
		form.customer_Postcode.value = "";
		form.customer_Address.value = "";
		form.customer_Address2.value = "";
		form.customer_Town.value = "";
		form.customer_County.value = "";
		form.customer_Country_ID.options[0].selected = true;
		form.customer_Country_ID.value = 243; //UK
	}else {
		var form = document.frmregisterstep3;
		form.customer_D_Buildingnumber.value = "";
		form.customer_D_Buildingname.value = "";
		form.customer_D_Postcode.value = "";
		form.customer_D_Address.value = "";
		form.customer_D_Address2.value = "";
		form.customer_D_Town.value = "";
		form.customer_D_County.value = "";
		form.customer_D_Country_ID.options[0].selected = true;
		form.customer_D_Country_ID.value = 243; //UK
	}
	
	document.getElementById("addressresults").style.display="none";
	document.getElementById("manualaddress").style.display="";
	
}

/*******************************Post Code Finder Using AJAX*******************************/
function FindPostCode() {
	if(TextValidate(document.frmregisterstep2.customer_Postcode,'Postcode')==false){ return false };
	document.getElementById("addressresults").style.display="";
	document.getElementById("addressresults").innerHTML = '<div class="resultsCenter"><div class="resultsTop"><div class="resultsFooter"><img align="middle" src="natcImages/ajax-loader.gif">&nbsp;Searching....<br /><br /></div></div>';
	
	document.frmregisterstep2.find_postcode.value = 1;
	
	
	if(document.frmregisterstep2.customer_Postcode.value!=""){
		var postcode = document.frmregisterstep2.customer_Postcode.value;
		var xmlhttp;
		if (window.XMLHttpRequest) {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		  // code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  alert("Your browser does not support XMLHTTP!");
		}		
		
		xmlhttp.open("GET","address_finder.php?postcode="+postcode+"&type=bill",true);
		
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState==4)
			  {
 				document.getElementById("addressresults").innerHTML = "";
				document.getElementById("addressresults").innerHTML = xmlhttp.responseText;
 			  }
			}
			xmlhttp.send(null);		
		}
		
}


/*******************************Shipping details Post Code Finder Using AJAX*******************************/
function Shipping_FindPostCode() {
	
	document.getElementById("addressresults").style.display="";
	document.getElementById("addressresults").innerHTML = '<div class="resultsCenter"><div class="resultsTop"><div class="resultsFooter"><img align="middle" src="natcImages/ajax-loader.gif">&nbsp;Searching....<br /><br /></div></div>';
	
	//document.frmregisterstep2.find_postcode.value = 1;
	
	
	if(document.frmregisterstep3.customer_D_Postcode.value!=""){
		var postcode = document.frmregisterstep3.customer_D_Postcode.value;
		var xmlhttp;
		if (window.XMLHttpRequest) {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		  // code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  alert("Your browser does not support XMLHTTP!");
		}		
		
		xmlhttp.open("GET","address_finder.php?postcode="+postcode+"&type=ship",true);
		
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState==4)
			  {
 				document.getElementById("addressresults").innerHTML = "";
				document.getElementById("addressresults").innerHTML = xmlhttp.responseText;
 			  }
			}
			xmlhttp.send(null);		
		}
		
}

function SelectAddress(addressID,type){
 	document.getElementById("loadingcircle").style.display = "";
	if(addressID!=""){
 		var xmlhttp;
		if (window.XMLHttpRequest) {
		  // code for IE7+, Firefox, Chrome, Opera, Safari
		  xmlhttp=new XMLHttpRequest();
		} else if (window.ActiveXObject) {
		  // code for IE6, IE5
		  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
		} else {
		  alert("Your browser does not support XMLHTTP!");
		}		
		
		xmlhttp.open("GET","address_finder.php?address="+addressID,true);
		
		xmlhttp.onreadystatechange = function() {
			if(xmlhttp.readyState==4)
			  {
 				 if(xmlhttp.responseText!="") {
					 	var addressarray = xmlhttp.responseText.split("@#@");
						if(type == "bill"){
							document.frmregisterstep2.customer_Buildingname.value = addressarray[0];
							document.frmregisterstep2.customer_Address.value = addressarray[1];
							document.frmregisterstep2.customer_Address2.value = addressarray[2];
							document.frmregisterstep2.customer_Town.value = addressarray[3];
							document.frmregisterstep2.customer_County.value = addressarray[4];
							document.frmregisterstep2.customer_Postcode.value = addressarray[5];
							document.frmregisterstep2.customer_Country_ID.selectedIndex = 243;
							document.frmregisterstep2.customer_Country_ID.value = 243;
							
						} else if(type == "ship"){
							document.frmregisterstep3.customer_D_Buildingname.value = addressarray[0];
							document.frmregisterstep3.customer_D_Address.value = addressarray[1];
							document.frmregisterstep3.customer_D_Address2.value = addressarray[2];
							document.frmregisterstep3.customer_D_Town.value = addressarray[3];
							document.frmregisterstep3.customer_D_County.value = addressarray[4];
							document.frmregisterstep3.customer_D_Postcode.value = addressarray[5];
							document.frmregisterstep3.customer_D_Country_ID.selectedIndex = 243;
							document.frmregisterstep3.customer_D_Country_ID.value = 243;
						}
				 }
				document.getElementById("manualaddress").style.display = "";
				document.getElementById("loadingcircle").style.display = "none";
			  }
			}
			xmlhttp.send(null);		
		}
}

/*****************************************Validate Siging************************************/
function ValdiateSignin() {
		
	if(TextValidate(document.frmsignin.customer_Email,'Email')==false){ return false };
	if(EmailValidate(document.frmsignin.customer_Email,'Email')==false){ return false };	
	if(TextValidate(document.frmsignin.customer_Password,'Password')==false){ return false };
	document.frmsignin.action = "signin.php";
	document.frmsignin.submit();
}

function  checkEnterlogin(e){ //e is event object passed from function invocation
	var characterCode //literal character code will be stored in this variable
	
	if(e && e.which){ //if which property of event object is supported (NN4)
	e = e
	characterCode = e.which //character code is contained in NN4's which property
	}
	else{
	e = event
	characterCode = e.keyCode //character code is contained in IE's keyCode property
	}
	
	if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
		ValdiateSignin();
	}
}

function ValidateNominate() {
	 if(SelectValidate(document.frmnominate.nominatenatcol_Title,'Title')==false){ return false };
	 if(TextValidate(document.frmnominate.nominatenatcol_First_Name,'First Name')==false){ return false };
	 if(TextValidate(document.frmnominate.nominatenatcol_Sur_Name,'Surname')==false){ return false };
	 //DOB
	 if(SelectValidate(document.frmnominate.nominate_date,'Date')==false){ return false };
	 if(SelectValidate(document.frmnominate.nominate_month,'Month')==false){ return false };
	 if(SelectValidate(document.frmnominate.nominate_year,'Year')==false){ return false };
	 
	 if(SelectValidate(document.frmnominate.nominatenatcol_Gender,'Gender')==false){ return false }; 
	 if(TextAreaValidate(document.frmnominate.nominatenatcol_Current_Address,'Current Address')==false){ return false }; 
	 
	 if(TextValidate(document.frmnominate.nominatenatcol_Email,'Email')==false){ return false };
	 if(EmailValidate(document.frmnominate.nominatenatcol_Email,'Email')==false){ return false };
	 
	 
	 if(TextValidate(document.frmnominate.nominatenatcol_Contact_Number,'Contact Number')==false){ return false };
	 
	 
   	 if(document.getElementById("hid_nominatenatcol_Email").value==1){
 		return false;
	 }
 	
	return true;
}