function validateURL(url) {
	return url.match(/[a-z0-9-\.]+\.[a-z]{2,4}\/?([^\s<>\#%"\,\{\}\\|\\\^\[\]`]+)?$/);
}
function reset_button(){
	$("#firstname").val("");
	$("#lastname").val("");
	$("#address").val("");
	$("#city").val("");
	$("#cname").val("");
	$("#cwebsite").val("");
	$("#email").val("");
	$("#phone").val("");
	$("#postcode").val("");
	$("#authinput").val("");	
	$("#cemail").val("");
	$("#other").val("");
	
	$("#country").val("");
	$("#state").val("");
	$("#experience").reset();
	
	$(".errorField").text("");
}
function checkFirstname() {	
	if($("#firstname").val() == "") {		
		$("#errorFirstname").text("Please enter your first name.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#firstname").select();
			   $("#firstname").focus();
		   }
		 });		
		return false;
	} else {
		$("#errorFirstname").text("");
		return true;
	}	
}
function checkCountry() {	
	if($("#country").val() == "") {		
		$("#errorCountry").text("Please enter your country.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#country").select();
			   $("#country").focus();
		   }
		 });		
		return false;
	} else {		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/ajax-list-countries.php",
		   data: "getStateByName=1&countryname="+$("#country").val(),
		   success: function(msg) {			   
			   if(msg == 1) {
					$("#errorCountry").text("");
					return true;   
			   } else {
				   selectVal = $("#ajax_listOfOptions").html();				   
				   if(selectVal=="") {
						$("#country").select();
						$("#country").focus();  
						$("#errorCountry").text("Please enter a valid country.");
						return false;   
				   } else {
					   $("#errorCountry").text("");
						return true;  
				   }
			   }			   
		   }
		 });		
	}	
}

function checkState() {	
	if($("#state").val() == "") {		
		$("#errorState").text("Please enter your state.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#state").select();
			   $("#state").focus();
		   }
		 });		
		return false;
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/ajax-list-countries.php",
		   data: "getStateBySName=1&countryname="+$("#country").val()+"&statename="+$("#state").val(),
		   success: function(msg){			   		
			   if(msg == 1) {
					$("#errorState").text("");
					return true;   
			   } else {
					$("#state").select();
			   		$("#state").focus();  
					$("#errorState").text("Please enter a valid state.");
					return false;
			   }			   
		   }
		 });		
	}	
}

function checkLastname() {
	if($("#lastname").val() == "") {
		$("#errorLastname").text("Please enter your last name.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#lastname").select();
			   $("#lastname").focus();
		   }
		 });		
		return false;
	} else {
		$("#errorLastname").text("");
		return true;
	}	
}
function checkAddress() {
	if($("#address").val() == "") {
		$("#errorAddress").text("Please enter your address.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#address").select();
			   $("#address").focus();
		   }
		 });		
		return false;
	} else {
		$("#errorAddress").text("");
		return true;
	}	
}
function checkCity() {
	if($("#city").val() == "") {
		$("#errorCity").text("Please enter your city.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#city").select();
			   $("#city").focus();
		   }
		 });
		return false;
	} else {
		$("#errorCity").text("");
		return true;
	}	
}
function checkCName() {
	if($("#cname").val() == "") {
		$("#errorCName").text("Please enter your company name.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#cname").select();
			   $("#cname").focus();
		   }
		 });		
		return false;
	} else {
		$("#errorCName").text("");
		return true;
	}	
}
function checkCWebsite() {
	if($("#cwebsite").val() == "") {
		$("#errorCWebsite").text("Please enter your company website.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#cwebsite").select();
			   $("#cwebsite").focus();
		   }
		 });		
		return false;
	} else if(!validateURL($("#cwebsite").val())) { 
		$("#errorCWebsite").text("Please enter a valid website.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#cwebsite").select();
			   $("#cwebsite").focus();
		   }
		 });		
		return false;
	}else {
		$("#errorCWebsite").text("");
		return true;
	}	
}

function checkEmail() {
	value = $("#email").val();
	if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
		$("#errorEmail").text("Please enter a valid email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#email").select();
			   $("#email").focus();
		   }
		 });		
		return false;
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/register_emailcheck.php",
		   data: "email="+value+"&status=1",	   
		   success: function(msg){
			   msg=msg.split("<ID>")
			   if(msg[1]){
			   $("#ID").val(msg[1]);
			   }
			   if(msg[0] != 1) {					
					$("#errorEmail").html(msg[0]);
					$("#email").select();
			   		$("#email").focus();
					return false;
			   } else {
					$("#errorEmail").text("");
					return true;   
			   }
		   }
		 });		
	}
}
function checkEmailHelp() {
	value = $("#email").val();
	if(value == "" || validateEmailv2(value) == false) {
		$("#errorEmail").text("Please enter a valid email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#email").select();
			   $("#email").focus();
		   }
		 });		
		return false;
	} else {
		$("#errorEmail").text("");
		return true;		
	}
}
function checkPhone() {
	if($("#phone").val() == "" || isNaN($("#phone").val())) {
		$("#errorPhone").text("Please enter a valid phone.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#phone").select();
			   $("#phone").focus();
		   }
		 });		
		return false;
	} else {
		$("#errorPhone").text("");
		return true;
	}
}
function checkPostcode() {	
	var value = $("#postcode").val();
	if($("#country").val() == "Australia" || $("#country").val() == "Aus" || $("#country").val() == "australia") {
		if((isNaN(value) || 999>value || value>9999 || value == "")) {			
			$("#errorPostcode").text("Please enter a valid postcode.");	
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#postcode").select();
				   $("#postcode").focus();
			   }
			 });							
			return false;
		} else {
			$("#errorPostcode").text("");
			return true;
		}
	} else {
		if(value == "") {
			$("#errorPostcode").text("Please enter a valid postcode.");	
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#postcode").select();
				   $("#postcode").focus();
			   }
			 });						
			return false;
		} else {			
			$("#errorPostcode").text("");
			return true;
		}
	}	
}

/*
function checkPostcode() {	
	var value = $("#postcode").val();
	if((isNaN(value) || 999>value || value>9999)) {		
		$("#errorPostcode").text("Please enter a valid postcode.");	
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#postcode").select();
			   $("#postcode").focus();
		   }
		 });						
		return false;
	} else {
		$("#errorPostcode").text("");
		return true;
	}
}
*/
function checkCode() {
	code1 = $("#authinput").val();		
	if(code1 == "") {
		$("#errorCode").text("Please enter security code.");
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/checkCode.php",
		   data: "authinput="+code1,	   
		   success: function(msg){
			   if(msg == "same") {
				   $("#errorCode").text("");
			   } else {
				   $("#errorCode").text("Incorrect! Please try again.");
				   $("#authinput").select();
			       $("#authinput").focus();
			   }
			   
		   }
		 });
	}	
}
function checkCEmail() {
	var value1 = $("#cemail").val();
	var value2 = $("#email").val();
	if(value1 != value2) {
		$("#errorCEmail").text("Please confirm email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){			   
			   $("#cemail").select();
			   $("#cemail").focus();
		   }
		 });
		return false;
	} else {
		$("#errorCEmail").text("");
		return true;
	}
}
function checkAccept() {		
	if(!$("#accept").attr("checked")) {
		$("#errorTerm").text("Accept Terms and Conditions?");
		return false;
	} else {
		$("#errorTerm").text("");
		return true;	
	}
}
function freeSubmitHelp() {
	var tag = true;	
	if(!checkPhone()) {
		tag = false
	}
	if(!checkPostcode()) {
		tag = false
	}	
	if(!checkState()) {
		tag = false;
	}
	if(!checkCountry()) {
		tag = false;
	}
	if(!checkCity()) {
		tag = false
	}
	if(!checkAddress()) {
		tag = false
	}
	if(!checkCEmail()) {
		tag = false
	}	
	if(!checkEmailHelp()) {
		tag = false
	}
	if(!checkLastname()) {
		tag = false
	}
	if(!checkFirstname()) {
		tag = false
	}
	if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
		tag = false;
		$("#errorTitle").text("Please select a title.");
	} else {
		$("#errorTitle").text("");
	}
	if(!checkCName()) {
		tag = false
	}
	if(!checkCWebsite()) {
		tag = false
	}			
	code1 = $("#authinput").val();		
	if(code1 == "") {
		$("#errorCode").text("Please enter security code.");
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/checkCode.php",
		   data: "authinput="+code1,	   
		   success: function(msg){
			   if(msg == "same") {
				   $("#errorCode").text("");
				   if(tag == true) {
					$("#customerDetail").submit();		
				} 
			   } else {
				   $("#errorCode").text("Incorrect! Please try again.");
				   $("#authinput").select();
			       $("#authinput").focus();
			   }
			   
		   }
		 });
	}			
	
	return false;	
}
function freeSubmitLinkHelp() {
	var tag = true;	
	if(!checkPhone()) {
		tag = false
	}
	if(!checkPostcode()) {
		tag = false
	}
	if($("#state").val() == "") {		
		$("#errorState").text("Please enter your state.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#state").select();
			   $("#state").focus();
		   }
		 });		
		tag = false;
	}	 
	if($("#country").val() == "") {		
		$("#errorCountry").text("Please enter your country.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#country").select();
			   $("#country").focus();
		   }
		 });		
		tag = false;
	}
	if(!checkCity()) {
		tag = false
	}
	if(!checkAddress()) {
		tag = false
	}
	if(!checkCEmail()) {
		tag = false
	}	
	if(!checkEmailHelp()) {
		tag = false
	}
	if(!checkLastname()) {
		tag = false
	}
	if(!checkFirstname()) {
		tag = false
	}
	
	if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
		tag = false;
		$("#errorTitle").text("Please select a title.");
	} else {
		$("#errorTitle").text("");
	}
	if(!checkCName()) {
		tag = false
	}	
	if(!checkCWebsite()) {
		tag = false
	}		
	code1 = $("#authinput").val();		
	if(code1 == "") {
		$("#errorCode").text("Please enter security code.");
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/checkCode.php",
		   data: "authinput="+code1,	   
		   success: function(msg){
			   if(msg == "same") {
				   $("#errorCode").text("");				   
				   if(tag == true) {
						$("#customerDetail").submit();		
					} 
			   } else {
				   $("#errorCode").text("Incorrect! Please try again.");
				   $("#authinput").select();
			       $("#authinput").focus();
			   }
			   
		   }
		 });
	}				
}
function freeSubmitLink() {
	var tag = true;
	if(!checkFirstname()) {
		tag = false
	}
	if(!checkLastname()) {
		tag = false
	}
	if(!checkCName()) {
		tag = false
	}
	if(!checkCWebsite()) {
		tag = false
	}
	if(!checkPhone()) {
		tag = false
	}
	if(!checkPostcode()) {
		tag = false
	}	
	if(!checkCEmail()) {
		tag = false
	}
	if(!checkAddress()) {
		tag = false
	}
	if(!checkCity()) {
		tag = false
	}	
	if($("#state").val() == "") {		
		$("#errorState").text("Please enter your state.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#state").select();
			   $("#state").focus();
		   }
		 });		
		tag = false;
	}	
	code1 = $("#authinput").val();		
	if(code1 == "") {
		$("#errorCode").text("Please enter security code.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#authinput").select();
			   $("#authinput").focus();
		   }
		 });		
		tag = false;
	} 
	if($("#country").val() == "") {		
		$("#errorCountry").text("Please enter your country.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#country").select();
			   $("#country").focus();
		   }
		 });		
		tag = false;
	}
	value = $("#email").val();
	if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
		$("#errorEmail").text("Please enter a valid email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#email").select();
			   $("#email").focus();
		   }
		 });		
		tag = false;
	}
	if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
		tag = false;
		$("#errorTitle").text("Please select a title.");
	} else {
		$("#errorTitle").text("");
	}
	if(!checkAccept()){
		tag = false;
	}
	if(tag != false) {
		if($("#country").val() == "") {		
			$("#errorCountry").text("Please enter your country.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#country").select();
				   $("#country").focus();
			   }
			 });		
			return false;
		} else {
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/ajax-list-countries.php",
			   data: "getStateByName=1&countryname="+$("#country").val(),
			   success: function(msg){			   
				   if(msg == 1) {
						$("#errorCountry").text("");
						if($("#state").val() == "") {		
							$("#errorState").text("Please enter your state.");		
							$.ajax({
							   type: "GET",
							   url: homelink+"/otto/Utility/AjaxValidate.php",
							   data: "type=code&value=1",	   
							   success: function(msg){
								   $("#state").select();
								   $("#state").focus();
							   }
							 });		
							return false;
						} else {
							$.ajax({
							   type: "GET",
							   url: homelink+"/otto/Utility/ajax-list-countries.php",
							   data: "getStateBySName=1&countryname="+$("#country").val()+"&statename="+$("#state").val(),
							   success: function(msg){			   		
								   if(msg == 1) {
										$("#errorState").text("");
										code1 = $("#authinput").val();		
										if(code1 == "") {
											$("#errorCode").text("Please enter security code.");
										} else {
											$.ajax({
											   type: "GET",
											   url: homelink+"/otto/Utility/checkCode.php",
											   data: "authinput="+code1,	   
											   success: function(msg){												   
												   if(msg == "same") {
													   $("#errorCode").text("");
													   checkEmailSubmit(tag);	
												   } else {
													   $("#errorCode").text("Incorrect! Please try again.");
													   $("#authinput").select();
													   $("#authinput").focus();
												   }
												   
											   }
											 });
										}											
								   } else {
										$("#state").select();
										$("#state").focus();  
										$("#errorState").text("Please enter a valid state.");
										return false;
								   }			   
							   }
							 });		
						}	  
				   } else {
						$("#country").select();
						$("#country").focus();  
						$("#errorCountry").text("Please enter a valid country.");
						return false;
				   }			   
			   }
			 });		
		}	
	}
}
function freeSubmit() {
	var tag = true;
	if(!checkFirstname()) {
		tag = false
	}
	if(!checkLastname()) {
		tag = false
	}
	if(!checkCName()) {
		tag = false
	}
	if(!checkCWebsite()) {
		tag = false
	}
	if(!checkPhone()) {
		tag = false
	}
	if(!checkPostcode()) {
		tag = false
	}	
	if(!checkCEmail()) {
		tag = false
	}
	if(!checkAddress()) {
		tag = false
	}
	if(!checkCity()) {
		tag = false
	}		
	if(!checkState()) {
		tag = false;
	}
	if(!checkCountry()) {
		tag = false;
	}
	if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
		tag = false;
		$("#errorTitle").text("Please select a title.");
	} else {
		$("#errorTitle").text("");
	}
	if(!checkAccept()){
		tag = false;
	}
	code1 = $("#authinput").val();		
	if(code1 == "") {
		$("#errorCode").text("Please enter security code.");
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/checkCode.php",
		   data: "authinput="+code1,	   
		   success: function(msg){
			   if(msg == "same") {
				   $("#errorCode").text("");
				   checkEmailSubmit(tag);	
			   } else {
				   $("#errorCode").text("Incorrect! Please try again.");
				   $("#authinput").select();
				   $("#authinput").focus();
			   }
			   
		   }
		 });
	}		
	return false;
}
$(document).ready(function() {	
	$("#HelpSubmit").click(function(){
		var tag = true;	
	if(!checkPhone()) {
		tag = false
	}
	if(!checkPostcode()) {
		tag = false
	}
	if($("#state").val() == "") {		
		$("#errorState").text("Please enter your state.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#state").select();
			   $("#state").focus();
		   }
		 });		
		tag = false;
	}	 
	if($("#country").val() == "") {		
		$("#errorCountry").text("Please enter your country.");		
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#country").select();
			   $("#country").focus();
		   }
		 });		
		tag = false;
	}
	if(!checkCity()) {
		tag = false
	}
	if(!checkAddress()) {
		tag = false
	}
	if(!checkCEmail()) {
		tag = false
	}	
	if(!checkEmailHelp()) {
		tag = false
	}
	if(!checkLastname()) {
		tag = false
	}
	if(!checkFirstname()) {
		tag = false
	}
	
	if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
		tag = false;
		$("#errorTitle").text("Please select a title.");
	} else {
		$("#errorTitle").text("");
	}
	if(!checkCName()) {
		tag = false
	}	
	if(!checkCWebsite()) {
		tag = false
	}		
	code1 = $("#authinput").val();		
	if(code1 == "") {
		$("#errorCode").text("Please enter security code.");
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/checkCode.php",
		   data: "authinput="+code1,	   
		   success: function(msg){
			   if(msg == "same") {
				   $("#errorCode").text("");				   
				   if(tag == true) {
						$("#customerDetail").submit();		
					} 
			   } else {
				   $("#errorCode").text("Incorrect! Please try again.");
				   $("#authinput").select();
			       $("#authinput").focus();
			   }
			   
		   }
		 });
	}	
			
	return false;
	});
	$("#submitLink").click(function(){
		var tag = true;
		if(!checkFirstname()) {
			tag = false
		}
		if(!checkLastname()) {
			tag = false
		}
		if(!checkCName()) {
			tag = false
		}
		if(!checkCWebsite()) {
			tag = false
		}
		if(!checkPhone()) {
			tag = false
		}
		if(!checkPostcode()) {
			tag = false
		}		
		if(!checkCEmail()) {
			tag = false
		}
		if(!checkAddress()) {
			tag = false
		}
		if(!checkCity()) {
			tag = false
		}		
		if(!checkAccept()){
			tag = false;
		}
		if(!checkState()) {
			tag = false;
		}
		if(!checkCountry()) {
			tag = false;
		}
		code1 = $("#authinput").val();		
		if(code1 == "") {
			$("#errorCode").text("Please enter security code.");
		} else {
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/checkCode.php",
			   data: "authinput="+code1,	   
			   success: function(msg){				   
				   if(msg == "same") {
					   $("#errorCode").text("");
					   if(tag == true) {
							checkEmailSubmit(tag);			
						}	
				   } else {
					   $("#errorCode").text("Incorrect! Please try again.");
					   $("#authinput").select();
					   $("#authinput").focus();
				   }
				   
			   }
			 });
		}
								
		return false;
	});	
	$("#submitForm").click(function(){
		var tag = true;
		if(!checkFirstname()) {
			tag = false
		}
		if(!checkLastname()) {
			tag = false
		}
		if(!checkCName()) {
			tag = false
		}
		if(!checkCWebsite()) {
			tag = false
		}
		if(!checkPhone()) {
			tag = false
		}
		if(!checkPostcode()) {
			tag = false
		}		
		if(!checkCEmail()) {
			tag = false
		}
		if(!checkAddress()) {
			tag = false
		}
		if(!checkCity()) {
			tag = false
		}	
		code1 = $("#authinput").val();		
		if(code1 == "") {
			$("#errorCode").text("Please enter security code.");
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#authinput").select();
				   $("#authinput").focus();
			   }
			 });		
			tag = false;
		} 
		if($("#state").val() == "") {		
			$("#errorState").text("Please enter your state.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#state").select();
				   $("#state").focus();
			   }
			 });		
			tag = false;
		}		
		if($("#country").val() == "") {		
			$("#errorCountry").text("Please enter your country.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#country").select();
				   $("#country").focus();
			   }
			 });		
			tag = false;
		}
		if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
			tag = false;
			$("#errorTitle").text("Please select a title.");
		} else {
			$("#errorTitle").text("");
		}
		if(!checkAccept()){
			tag = false;
		}
		value = $("#email").val();
		if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
			$("#errorEmail").text("Please enter a valid email.");
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#email").select();
				   $("#email").focus();
			   }
			 });		
			tag = false;
		}
		if(tag != false) {
			if($("#country").val() == "") {		
				$("#errorCountry").text("Please enter your country.");		
				$.ajax({
				   type: "GET",
				   url: homelink+"/otto/Utility/AjaxValidate.php",
				   data: "type=code&value=1",	   
				   success: function(msg){
					   $("#country").select();
					   $("#country").focus();
				   }
				 });		
				return false;
			} else {
				$.ajax({
				   type: "GET",
				   url: homelink+"/otto/Utility/ajax-list-countries.php",
				   data: "getStateByName=1&countryname="+$("#country").val(),
				   success: function(msg){			   
					   if(msg == 1) {
							$("#errorCountry").text("");
							if($("#state").val() == "") {		
								$("#errorState").text("Please enter your state.");		
								$.ajax({
								   type: "GET",
								   url: homelink+"/otto/Utility/AjaxValidate.php",
								   data: "type=code&value=1",	   
								   success: function(msg){
									   $("#state").select();
									   $("#state").focus();
								   }
								 });		
								return false;
							} else {
								$.ajax({
								   type: "GET",
								   url: homelink+"/otto/Utility/ajax-list-countries.php",
								   data: "getStateBySName=1&countryname="+$("#country").val()+"&statename="+$("#state").val(),
								   success: function(msg){			   		
									   if(msg == 1) {
											$("#errorState").text("");
											code1 = $("#authinput").val();		
											if(code1 == "") {
												$("#errorCode").text("Please enter security code.");
											} else {
												$.ajax({
												   type: "GET",
												   url: homelink+"/otto/Utility/checkCode.php",
												   data: "authinput="+code1,	   
												   success: function(msg){													   
													   if(msg == "same") {
														   $("#errorCode").text("");
														   if(tag == true) {
																checkEmailSubmit(tag);			
															}	
													   } else {
														   $("#errorCode").text("Incorrect! Please try again.");
														   $("#authinput").select();
														   $("#authinput").focus();
													   }
													   
												   }
												 });
											}	
									   } else {
											$("#state").select();
											$("#state").focus();  
											$("#errorState").text("Please enter a valid state.");
											return false;
									   }			   
								   }
								 });		
							}	  
					   } else {
							$("#country").select();
							$("#country").focus();  
							$("#errorCountry").text("Please enter a valid country.");
							return false;
					   }			   
				   }
				 });		
			}	
		}							
		return false;					
									
	});
	$("#submitLinkClient").click(function(){
		$(document).ready(function(){
			tb_show('',tb_pathToImage + '?modal=true',"");
		});								  
		var tag = true;		
		if(!checkPhone()) {
			tag = false
		}
		if(!checkPostcode()) {
			tag = false
		}
		if(!checkCity()) {
			tag = false
		}
		if($("#state").val() == "") {		
			$("#errorState").text("Please enter your state.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#state").select();
				   $("#state").focus();
			   }
			 });		
			tag = false;
		}
		if($("#country").val() == "") {		
			$("#errorCountry").text("Please enter your country.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#country").select();
				   $("#country").focus();
			   }
			 });		
			tag = false;
		}
		value = $("#email").val();
		if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
			$("#errorEmail").text("Please enter a valid email.");
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#email").select();
				   $("#email").focus();
			   }
			 });		
			tag = false;
		}
		code1 = $("#authinput").val();		
		if(code1 == "") {
			$("#errorCode").text("Please enter security code.");
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#authinput").select();
				   $("#authinput").focus();
			   }
			 });		
			tag = false;
		} 
		/*
		if(!checkState()) {
			tag = false;
		}
		if(!checkCountry()) {
			tag = false;
		}
		*/
		if(!checkAddress()) {
			tag = false
		}
		if(!checkCEmail()) {
			tag = false
		}
		if(!checkLastname()) {
			tag = false
		}
		if(!checkFirstname()) {
			tag = false
		}
		if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
			tag = false;
			$("#errorTitle").text("Please select a title.");
		} else {
			$("#errorTitle").text("");
		}
		if(!checkCWebsite()) {
			tag = false
		}
		if(!checkCName()) {
			tag = false
		}
				
		if(tag != false) {
			if($("#country").val() == "") {		
				$("#errorCountry").text("Please enter your country.");		
				$.ajax({
				   type: "GET",
				   url: homelink+"/otto/Utility/AjaxValidate.php",
				   data: "type=code&value=1",	   
				   success: function(msg){
					   $("#country").select();
					   $("#country").focus();
				   }
				 });		
				return false;
			} else {
				$.ajax({
				   type: "GET",
				   url: homelink+"/otto/Utility/ajax-list-countries.php",
				   data: "getStateByName=1&countryname="+$("#country").val(),
				   success: function(msg){			   
					   if(msg == 1) {
							$("#errorCountry").text("");
							if($("#state").val() == "") {		
								$("#errorState").text("Please enter your state.");		
								$.ajax({
								   type: "GET",
								   url: homelink+"/otto/Utility/AjaxValidate.php",
								   data: "type=code&value=1",	   
								   success: function(msg){
									   $("#state").select();
									   $("#state").focus();
								   }
								 });		
								return false;
							} else {
								$.ajax({
								   type: "GET",
								   url: homelink+"/otto/Utility/ajax-list-countries.php",
								   data: "getStateBySName=1&countryname="+$("#country").val()+"&statename="+$("#state").val(),
								   success: function(msg){			   		
									   if(msg == 1) {
											$("#errorState").text("");
											code1 = $("#authinput").val();		
											if(code1 == "") {
												$("#errorCode").text("Please enter security code.");
											} else {
												$.ajax({
												   type: "GET",
												   url: homelink+"/otto/Utility/checkCode.php",
												   data: "authinput="+code1,	   
												   success: function(msg){
													   if(msg == "same") {
														   $("#errorCode").text("");
														   if(tag == true) {
																checkEmailSubmit(tag);			
															}	
													   } else {
														   $("#errorCode").text("Incorrect! Please try again.");
														   $("#authinput").select();
														   $("#authinput").focus();
													   }
													   
												   }
												 });
											}
									   } else {
											$("#state").select();
											$("#state").focus();  
											$("#errorState").text("Please enter a valid state.");
											return false;
									   }			   
								   }
								 });		
							}	  
					   } else {
							$("#country").select();
							$("#country").focus();  
							$("#errorCountry").text("Please enter a valid country.");
							return false;
					   }			   
				   }
				 });		
			}	
		}
		return false;	
	});	
	$("#submitFormClient").click(function(){
		var tag = true;	
		code1 = $("#authinput").val();		
		if(code1 == "") {
			$("#errorCode").text("Please enter security code.");
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#authinput").select();
				   $("#authinput").focus();
			   }
			 });		
			tag = false;
		} 
		if(!checkPhone()) {
			tag = false
		}
		if(!checkPostcode()) {
			tag = false
		}
		if(!checkCity()) {
			tag = false
		}
		if($("#state").val() == "") {		
			$("#errorState").text("Please enter your state.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#state").select();
				   $("#state").focus();
			   }
			 });		
			tag = false;
		}
		if($("#country").val() == "") {		
			$("#errorCountry").text("Please enter your country.");		
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#country").select();
				   $("#country").focus();
			   }
			 });		
			tag = false;
		}
		value = $("#email").val();
		if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
			$("#errorEmail").text("Please enter a valid email.");
			$.ajax({
			   type: "GET",
			   url: homelink+"/otto/Utility/AjaxValidate.php",
			   data: "type=code&value=1",	   
			   success: function(msg){
				   $("#email").select();
				   $("#email").focus();
			   }
			 });		
			tag = false;
		}
		/*
		if(!checkState()) {
			tag = false;
		}
		if(!checkCountry()) {
			tag = false;
		}
		*/
		if(!checkAddress()) {
			tag = false
		}
		if(!checkCEmail()) {
			tag = false
		}
		if(!checkLastname()) {
			tag = false
		}
		if(!checkFirstname()) {
			tag = false
		}
		if(!($("#title1").attr("checked") || $("#title2").attr("checked") || $("#title3").attr("checked"))) {
			tag = false;
			$("#errorTitle").text("Please select a title.");
		} else {
			$("#errorTitle").text("");
		}
		if(!checkCWebsite()) {
			tag = false
		}
		if(!checkCName()) {
			tag = false
		}
				
		if(tag != false) {
			if($("#country").val() == "") {		
				$("#errorCountry").text("Please enter your country.");		
				$.ajax({
				   type: "GET",
				   url: homelink+"/otto/Utility/AjaxValidate.php",
				   data: "type=code&value=1",	   
				   success: function(msg){
					   $("#country").select();
					   $("#country").focus();
				   }
				 });		
				return false;
			} else {
				$.ajax({
				   type: "GET",
				   url: homelink+"/otto/Utility/ajax-list-countries.php",
				   data: "getStateByName=1&countryname="+$("#country").val(),
				   success: function(msg){			   
					   if(msg == 1) {
							$("#errorCountry").text("");
							if($("#state").val() == "") {		
								$("#errorState").text("Please enter your state.");		
								$.ajax({
								   type: "GET",
								   url: homelink+"/otto/Utility/AjaxValidate.php",
								   data: "type=code&value=1",	   
								   success: function(msg){
									   $("#state").select();
									   $("#state").focus();
								   }
								 });		
								return false;
							} else {
								$.ajax({
								   type: "GET",
								   url: homelink+"/otto/Utility/ajax-list-countries.php",
								   data: "getStateBySName=1&countryname="+$("#country").val()+"&statename="+$("#state").val(),
								   success: function(msg){			   		
									   if(msg == 1) {
											$("#errorState").text("");
											code1 = $("#authinput").val();		
											if(code1 == "") {
												$("#errorCode").text("Please enter security code.");
											} else {
												$.ajax({
												   type: "GET",
												   url: homelink+"/otto/Utility/checkCode.php",
												   data: "authinput="+code1,	   
												   success: function(msg){
													   if(msg == "same") {
														   $("#errorCode").text("");
														   if(tag == true) {
																checkEmailSubmit(tag);			
															}	
													   } else {
														   $("#errorCode").text("Incorrect! Please try again.");
														   $("#authinput").select();
														   $("#authinput").focus();
													   }
													   
												   }
												 });
											}
									   } else {
											$("#state").select();
											$("#state").focus();  
											$("#errorState").text("Please enter a valid state.");
											return false;
									   }			   
								   }
								 });		
							}	  
					   } else {
							$("#country").select();
							$("#country").focus();  
							$("#errorCountry").text("Please enter a valid country.");
							return false;
					   }			   
				   }
				 });		
			}	
		}
		return false;					
									
	});
});
function checkEmailSubmit(tag) {
	value = $("#email").val();
	if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
		$("#errorEmail").text("Please enter a valid email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#email").select();
			   $("#email").focus();
		   }
		 });		
		return false;
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/register_emailcheck.php",
		   data: "email="+value+"&status=1",	   
		   success: function(msg){
			    msg=msg.split("<ID>")
			   if(msg[1]){
			   $("#ID").val(msg[1]);
			   }
			   if(msg[0] != 1) {
					$("#errorEmail").html(msg);
					$("#email").select();
			   		$("#email").focus();
					return false;
			   } else {
					$("#errorEmail").text("");					
					if(tag) {
						$("#customerDetail").submit();	 							
					} else {
						return false;
					}
			   }
		   }
		 });		
	}
}
function checkEmailSubmitClient(tag) {
	value = $("#email").val();
	if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
		$("#errorEmail").text("Please enter a valid email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#email").select();
			   $("#email").focus();
		   }
		 });		
		return false;
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/register_emailcheck.php",
		   data: "email="+value+"&status=1",	   
		   success: function(msg){
			    msg=msg.split("<ID>")
			   if(msg[1]){
			   $("#ID").val(msg[1]);
			   }
			   if(msg[0] != 1) {
					$("#errorEmail").html(msg);
					$("#email").select();
			   		$("#email").focus();
					return false;
			   } else {
					$("#errorEmail").text("");					
					if(tag) {
						$("#customerDetail").submit();	
					} else {
						return false;
					}
			   }
		   }
		 });		
	}
}
function checkEmailSubmitFree(tag) {
	value = $("#email").val();
	if(value == "" || validateEmailv2(value) == false || value.indexOf("gmail.com")!=-1 || value.indexOf("hotmail.com")!=-1 || value.indexOf("yahoo.com")!=-1 || !checkmatch($("#cwebsite").val(),value)) {
		$("#errorEmail").text("Please enter a valid email.");
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/AjaxValidate.php",
		   data: "type=code&value=1",	   
		   success: function(msg){
			   $("#email").select();
			   $("#email").focus();
		   }
		 });		
		return false;
	} else {
		$.ajax({
		   type: "GET",
		   url: homelink+"/otto/Utility/register_emailcheck.php",
		   data: "email="+value+"&status=1",	   
		   success: function(msg){
			    msg=msg.split("<ID>")
			   if(msg[1]){
			   $("#ID").val(msg[1]);
			   }
			   if(msg[0] != 1) {
					$("#errorEmail").html(msg);
					$("#email").select();
			   		$("#email").focus();
					return false;
			   } else {
					$("#errorEmail").text("");					
					if(tag)
						$("#customerDetail").submit();	 
					else
						return false;
			   }
		   }
		 });		
	}
}
function trim(str, chars) {
	return ltrim(rtrim(str, chars), chars);
}
 
function ltrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}
 
function rtrim(str, chars) {
	chars = chars || "\\s";
	return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}
function checkmatch(str1,str2) {		
	str2_new = str2.substr(str2.indexOf("@")+1);
	//alert(str1.indexOf("www"));
	if(str1.indexOf("www")!=-1) {
		str1_new = str1.substr(str1.indexOf(".")+1);
	} else if(str1.indexOf("WWW")!=-1) {
		str1_new = str1.substr(str1.indexOf(".")+1);
	} else {
		if(str1.indexOf("//")!=-1) {
			str1_new = str1.substr(str1.indexOf("//")+2);
		} else {
			str1_new = str1;
		}
	}	
	//alert(str1_new+" "+str2_new);
	if(str1_new.match(str2_new)) {
		return true;
	} else {
		return false;
	}		
}
