
function checkboxres(){
	//if(document.regform.residential.checked){
		//document.regform.business.checked = 0;
		//document.regform.residential.checked = 1;
		//document.getElementById('bussection').style.visibility='hidden'; 
		//document.getElementById('bussection').style.display='none'
		//document.getElementById('residentialsection').style.visibility='visible'; 
		//document.getElementById('residentialsection').style.display='block'
	//}else{
		//if(document.regform.business.checked){
		//	document.regform.residential.checked = 0;
		//	document.regform.business.checked = 1;
			//document.getElementById('bussection').style.visibility='visible'; 
			//document.getElementById('bussection').style.display='block';
			//document.getElementById('residentialsection').style.visibility='hidden'; 
			//document.getElementById('residentialsection').style.display='none'
		//}
	//}
}

function checkboxbus(){
   if(document.regform.business.checked){
	document.regform.residential.checked = 0;
        document.regform.business.checked = 1;
	document.getElementById('bussection').style.visibility='visible'; 
	document.getElementById('bussection').style.display='block'
	//document.getElementById('residentialsection').style.visibility='hidden'; 
   	//document.getElementById('residentialsection').style.display='none'
   }
   else
   {
	//if(document.regform.residential.checked)
	//{
	document.regform.business.checked = 0;
	document.regform.residential.checked = 1;
	document.getElementById('bussection').style.visibility='hidden'; 
	document.getElementById('bussection').style.display='none';
	//document.getElementById('residentialsection').style.visibility='visible'; 
   	//document.getElementById('residentialsection').style.display='block'
	//}

   }

}

function checkboxomit(){
   if(document.regform.busdirectory.checked){
		document.getElementById('omitsection').style.visibility='hidden'; 
		document.getElementById('omitsection').style.display='none';	
	}
   else
   {
		document.getElementById('omitsection').style.visibility='visible'; 
		document.getElementById('omitsection').style.display='block'
	}
}



function priority_click(){
	var oForm=document.getElementById('regform');	
	oForm.free_listing.checked = 0;
	oForm.web_listing.checked  = 0;
	oForm.priority_listing.checked = 1;
	selectionlimit = 3;
}

function free_click(){
	var oForm=document.getElementById('regform');	
	oForm.free_listing.checked = 1;
	oForm.web_listing.checked =0;
	oForm.priority_listing.checked = 0;
	selectionlimit = 1;
}

function web_click(){
	var oForm=document.getElementById('regform');	
	oForm.free_listing.checked = 0;
	oForm.web_listing.checked =1;
	oForm.priority_listing.checked = 0;
	selectionlimit = 1;
}

function listing_type_change__(){
	alert("hai");
	var oForm=document.getElementById('regform');	
	if(oForm.listing_type.selectedIndex==1){
		selectionlimit = 1;
	}
	if(oForm.listing_type.selectedIndex==2){
		selectionlimit = 1;
	}
	if(oForm.listing_type.selectedIndex==3){
		selectionlimit = 3;
	}
	alert(selectionlimit)
}

function listing_type_change(radio_val){
	
	var oForm=document.getElementById('regform');	
	if(radio_val==0){
		selectionlimit = 1;
	}
	if(radio_val==1){
		selectionlimit = 1;
	}
	if(radio_val==2){
		selectionlimit = 3;
	}
	
}

function checkemail(pEmail){
	var testresults
	var str=pEmail;
	var filter=/^.+@.+\..{2,3}$/;
		if(filter.test(str)) testresults=true;
	else {			
		testresults=false;
	}
	return(testresults);
}

function sameAsContactInfo(){

	var oForm=document.getElementById('regform');	
    if(oForm.chkBoxSameInfo.checked == true)
    {
        oForm.email.value = oForm.contact_email.value;
        oForm.phone2.value = oForm.contact_phone.value;
        oForm.address.value = oForm.contact_address.value;
        oForm.town.value = oForm.contact_town.value;
        oForm.county.value = oForm.contact_county.value;
        oForm.postcode.value = oForm.contact_postcode.value;
    }	
}



function refresh(type,formvalue){
	var sError='';
	var oForm=document.getElementById('regform');
	//alert(formvalue);
	
//	if(!oForm.donotcall.checked && oForm.phone.value ==''){		
//		sError+='Field "Add your number" is required.\n';
//	}

//	if(oForm.title!=null && oForm.title.value==''){
//  	sError+='Field "Title" is required.\n';
//    }
  if(formvalue==1){
  if(oForm.phone.value ==''){
  	sError+='Field "Do Not Call Phone Number" is required.\n';
  }
  else if(isNaN(oForm.phone.value))
  {
    sError+='Field "Do Not Call Phone Number" is not in valid format.\n';
  }
  }
    
	
 if(formvalue==2){
	if(oForm.title!=null && oForm.title.selectedIndex==0){
	    sError+='Field "Title" is required.\n';
    }
	
	if(oForm.contact_name.value==''){
		sError+='Field "Your Name" is required.\n';
  	}
  if(oForm.contact_address.value ==''){
  	sError+='Field "Address" is required.\n';		
  }
  if(oForm.contact_town.value ==''){
  	sError+='Field "Town" is required.\n';
  }
  if(oForm.contact_county.value ==''){
  	sError+='Field "County" is required.\n';			
  }
  if (oForm.contact_postcode.value ==''){
  	sError+='Field "Postcode" is required.\n';
  }
  if(oForm.contact_phone.value ==''){
  	sError+='Field "Telephone Number" is required.\n';
  }
  else if(isNaN(oForm.contact_phone.value))
  {
    sError+='Field "Telephone Number" is not in valid format.\n';
  }
  
  if(oForm.contact_email.value ==''){
  	sError+='Field "Email Address" is required.\n';
  }else if(!checkemail(oForm.contact_email.value)){
  	sError+='Field "Email Address" is malformed or invalid.\n';
  }
	
 }
	
 if(formvalue==4){
	if(oForm.reg_username.value ==''){
		sError+='Field "Username" is required.\n';
	}else if(oForm.reg_username.value.indexOf('&')>-1){
		sError+='Field "Username" cannot contain the symbol "&".\n';
	}  	

	//if(oForm.foundus!=null||oForm.reg_password.value!=''){
		if(oForm.reg_password.value ==''){
			sError+='Field "Password" is required.\n';
		}else if(oForm.reg_password.value.length < 6){
			sError+='Field "Password" is should be a minimum of "6" charecters in length\n';
		}else if(oForm.confirmpass.value ==''){
			sError+='Field "Confirm Password" is required.\n';		
		}else if(oForm.reg_password.value != oForm.confirmpass.value){
			sError+='Field "Password" must match the "Confirm Password" field.\n';		
		}else if(oForm.reg_username.value.indexOf('&')>-1){
			sError+='Field "Password" cannot contain the symbol "&".\n';
		}  	
    // }
	 
	 if (oForm.termAcc != null){
		if(!oForm.termAcc.checked){
			sError+='You need to accept our terms and conditions\n';
		}
	}
  }
/*  
  if(oForm.foundus!=null&&oForm.foundus.value==''){
  	sError+='Field "How you found us" is required.\n';
  }
  if(oForm.foundus!=null&&oForm.foundus.selectedIndex==0){
  	sError+='Field "How you found us" is required.\n';
  }
  
changed by iffi   */


	//&&  ! oForm.busdirectory.checked        changed by iffi
	
if(formvalue==3){	
	if(oForm.business.value==1){
		//Validate the business entries as well
		if (oForm.listing_type.value =='9'){
			sError+='Field "Listing Type" is required.\n';
		}
		if (oForm.comname.value ==''){
			sError+='Field "Business Name" is required.\n';
		}
		if (oForm.phone2.value ==''){
			sError+='Field "Business Telephone Number" is required.\n';
		}
		if(oForm.address.value ==''){
			sError+='Field "Business Address" is required.\n'	;		
		}
		if (oForm.town.value ==''){
			sError+='Field "Business Town" is required.\n';
		}
		if (oForm.postcode.value ==''){
			sError+='Field "Postcode" is required.\n';
		}
		if(noselected > selectionlimit ) {
			//sError+='You are only allowed "+selectionlimit+" Business Classifications.\n';
		}else{
			if(noselected == selectionlimit){
				for(i=0;i<oForm.selectedsubs.length;i++){
					oForm.selectedsubs.options[i].selected = true;
				}
			}else{
				//sError+='You must select a Business Classification.\n';		
			}
		}
	}
	
	
	
}  //////////////my
	
	if(sError.length==0){
		oForm.submit();
	}else{
		alert('There are some issues with the form...\n\n'+sError+'\nPlease correct these issues to continue...');
	}
}


/////////////////////////////////////////////
function refresh_edit(type,formvalue){
	var sError='';
	var oForm=document.getElementById('regform'+formvalue);
	
  if(formvalue==1){
  if(oForm.phone.value ==''){
  	sError+='Field "Do Not Call Phone Number" is required.\n';
  }
  else if(isNaN(oForm.phone.value))
  {
    sError+='Field "Do Not Call Phone Number" is not in valid format.\n';
  }
  }
    
	
 if(formvalue==2){
	if(oForm.title!=null && oForm.title.selectedIndex==0){
	    sError+='Field "Title" is required.\n';
    }
	
	if(oForm.contact_name.value==''){
		sError+='Field "Your Name" is required.\n';
  	}
  if(oForm.contact_address.value ==''){
  	sError+='Field "Address" is required.\n';		
  }
  if(oForm.contact_town.value ==''){
  	sError+='Field "Town" is required.\n';
  }
  if(oForm.contact_county.value ==''){
  	sError+='Field "County" is required.\n';			
  }
  if (oForm.contact_postcode.value ==''){
  	sError+='Field "Postcode" is required.\n';
  }
  if(oForm.contact_phone.value ==''){
  	sError+='Field "Telephone Number" is required.\n';
  }
  else if(isNaN(oForm.contact_phone.value))
  {
    sError+='Field "Telephone Number" is not in valid format.\n';
  }
  
  if(oForm.contact_email.value ==''){
  	sError+='Field "Email Address" is required.\n';
  }else if(!checkemail(oForm.contact_email.value)){
  	sError+='Field "Email Address" is malformed or invalid.\n';
  }
	
 }
	
 if(formvalue==4){
	if(oForm.reg_username.value ==''){
		sError+='Field "Username" is required.\n';
	}else if(oForm.reg_username.value.indexOf('&')>-1){
		sError+='Field "Username" cannot contain the symbol "&".\n';
	}  	

	if(oForm.foundus!=null||oForm.reg_password.value!=''){
		if(oForm.reg_password.value ==''){
			sError+='Field "Password" is required.\n';
		}else if(oForm.reg_password.value.length < 6){
			sError+='Field "Password" is should be a minimum of "6" charecters in length\n';
		}else if(oForm.confirmpass.value ==''){
			sError+='Field "Confirm Password" is required.\n';		
		}else if(oForm.reg_password.value != oForm.confirmpass.value){
			sError+='Field "Password" must match the "Confirm Password" field.\n';		
		}else if(oForm.reg_username.value.indexOf('&')>-1){
			sError+='Field "Password" cannot contain the symbol "&".\n';
		}  	
     }
	 
	 if (oForm.termAcc != null){
		if(!oForm.termAcc.checked){
			sError+='You need to accept our terms and conditions\n';
		}
	}
  }

	
if(formvalue==3){	
	if(oForm.business.value==1){
		//Validate the business entries as well
		
		if (oForm.comname.value ==''){
			sError+='Field "Business Name" is required.\n';
		}
		if (oForm.phone2.value ==''){
			sError+='Field "Business Telephone Number" is required.\n';
		}
		if(oForm.address.value ==''){
			sError+='Field "Business Address" is required.\n'	;		
		}
		if (oForm.town.value ==''){
			sError+='Field "Business Town" is required.\n';
		}
		if (oForm.postcode.value ==''){
			sError+='Field "Postcode" is required.\n';
		}
		if(noselected > selectionlimit ) {
			//sError+='You are only allowed "+selectionlimit+" Business Classifications.\n';
		}else{
			if(noselected == selectionlimit){
				for(i=0;i<oForm.selectedsubs.length;i++){
					oForm.selectedsubs.options[i].selected = true;
				}
			}else{
				//sError+='You must select a Business Classification.\n';		
			}
		}
	}
	
	
	
}  //////////////my
	
	if(sError.length==0){
		oForm.submit();
	}else{
		alert('There are some issues with the form...\n\n'+sError+'\nPlease correct these issues to continue...');
	}
}



////////////////////////////////////////////////

function ValidateForm(){
	var NameBox = document.form122.cname.value;
	var TelBox =  document.form122.tel.value;
	var checkCount = 0;
	
	alert("I am in function");
	if ((NameBox =="")||(NameBox ==null)){
	alert("You have not provided your name")
	NameBox.focus
	return false
	}
	else
	{checkCount = checkCount + 1}

	
	if ((TelBox =="")||(TelBox ==null)){
		alert("Please Enter a Valid Phone Number")
		TelBox.focus
		return false
	}
	else
	{checkCount = checkCount + 1}
	
	if (checkCount == 2){
	document.form122.submit();
	}

}
