function showhide(id,disp)
{
	document.getElementById(id).style.display=disp;
}
function continueadd()
{
		showhide('infotbl','none');
		showhide('logintbl','inline');
}
function gotoregform()
{
	showhide('logintbl','none');
	showhide('createidtbl','inline');
	showhide('orgtbl','inline');
	showhide('contacttbl','inline');
	showhide('btnrow','inline');
}
function to_lower()
{
	document.getElementById("txtUserid").value=document.getElementById("txtUserid").value.toLowerCase();
}
function check_exists()
{

	if(!validateAlphaNumericUserName_new(document.addProfile.txtUserid.value))
	{
		alert("Please enter valid user name");
		document.addProfile.txtUserid.focus();
		var t=setTimeout("setfocus('txtUserid');",10);
		return false;
	}
	if(document.addProfile.txtUserid.value==0)
	{
		alert("Please enter valid user name");
		document.addProfile.txtUserid.focus();
		var t=setTimeout("setfocus('txtUserid');",10);
		return false;
	}
	var passvar="empty&uname="+document.addProfile.txtUserid.value+"&actn=check_exists";	
	var url="modules/advertiserequire/check_availability.php";
	loadmajax(url,'POST',passvar,'usernameinfo');
	//var t=setTimeout("clearfield('txtUserid');",500);
	return false;
}
function setfocus(id)
{
	document.getElementById(id).focus();
}
function clearfield(id)
{
	
	if(document.getElementById("ext").value==1)
	{
		document.getElementById(id).value="";
		document.getElementById(id).focus();
	}
}
/*function change_state(country_id)
{
	if(country_id!="--Select--" && country_id!="")
	{
		var url="modules/advertiserequire/change_state.php";
		loadmajax(url,'POST',country_id,'st');
		return false;
	}
}*/

function change_state(country_id)
{
	if(country_id!="selCountry"&&country_id==130)
	{
	document.getElementById("combo").style.display="inline";
	document.getElementById("txt").style.display="none";
	}
	else
	{
	document.addProfile.state.value="SelState";
	document.getElementById("combo").style.display="none";
	document.getElementById("txt").style.display="inline";
	}
}
//---------Phone number validation --start----
function validate_Phonenumber(fld,type,mandat,show_id,detail)
{
	var val='';
	val=document.getElementById(fld).value;
	var invalid=0;
	val_splt=val.split("-");
	if(val_splt.length>3)
	{
		alert("Please enter valid "+type+" Number");
		document.getElementById(fld).focus();
		val='';
		return false;
	}

	if(mandat=="yes")
	{
		if(!validateNotEmpty(val))
		{
			alert("Please enter "+type+" Number");
			document.getElementById(fld).focus();
			return false;
		}
	}
	if(val!=null && document.getElementById(fld).value!='')
	{
		if(type=="Phone" || type=="Fax")
		{
			//alert(val_splt[0]);
			if(val_splt[1]!=null)
			{
				if(val_splt[0].length<1  || val_splt[1].length<1)
				{
					invalid=1;
				}
			}
			if(val_splt.length<1 )
			{
				invalid=1;
			}
			if(val_splt[0]==null || val_splt[0]<=0 || val_splt[1]==null || val_splt[1]<=0 || val_splt[2]==null || val_splt[2]<=0)
			{
				invalid=1;
			}

			if(!validateInteger(val_splt[0]) || !validateInteger(val_splt[1]) ||  !validateInteger(val_splt[2]))
			{
				invalid=1;
			}
		}
		if(type=="Mobile")
		{
			if(val_splt[0].length<1 )
			{
				invalid=1;
			}
			if(val_splt.length!=2)
			{
				invalid=1;
			}
			if(val_splt[0]==null || val_splt[0]<=0 || val_splt[1]==null || val_splt[1]<=0)
			{
				invalid=1;
			}
			if(!validateInteger(val_splt[0]) || !validateInteger(val_splt[1]))
			{
				invalid=1;
			}
		}

		if(invalid==1)
		{
			alert("Please enter valid "+type+" Number");
			document.getElementById(fld).focus();
			val='';
			return false;
		}
	}
}

//---------Phone number validation --end----

//=======================password strength start
function passwordChanged() {
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
var enoughRegex = new RegExp("(?=.{6,}).*", "g");
var pwd = document.getElementById("txtPassword");
if (strongRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:green">Your password strength is strong!</span>';
} else if (mediumRegex.test(pwd.value)) {
strength.innerHTML = '<span style="color:blue">Your password strength is medium!</span>';
} else { 
strength.innerHTML = '<span style="color:red">Your password strength is weak!</span>';
}
}
//=======================password strength stop

function submitprofile(operation)
{
	var alertlist="";
	var fcs="";	

	if(!validateNotEmpty(document.addProfile.txtUserid.value)){alertlist+="Please enter \"User Name\"\n";fcs+="-txtUserid";}
	uname=document.addProfile.txtUserid.value;
	if(validateNotEmpty(uname))
	{		
		if(!validateAlphaNumericUserName_new(uname) || uname==0 || UserName1(uname) || !validateAlphaNumericUserName(uname))
		{
			
			alert("Please enter  valid user name")
			document.addProfile.txtUserid.focus();
			return false;
		}
		if(uname.length<5)
		{
			alert ("User name should be minimum 5 characters");
			document.addProfile.txtUserid.focus();
			return false;
		}
	}
	if(!validateNotEmpty(document.addProfile.txtPassword.value)){alertlist+="Please enter \"password\"\n";fcs+="-txtPassword";}
	if(validateNotEmpty(document.addProfile.txtPassword.value))
	{
		if(document.addProfile.txtPassword.value==document.addProfile.txtUserid.value)
		{
			alert("User name and Password should not be same")
			document.addProfile.txtPassword.value='';
			document.addProfile.txtConpassword.value='';
			document.addProfile.txtPassword.focus();
			return false;
		}
		if(document.addProfile.txtPassword.value==0)
		{
			alert("Please enter valid Password")
			document.addProfile.txtPassword.value='';
			document.addProfile.txtConpassword.value='';
			document.addProfile.txtPassword.focus();
			return false;
		}
		var pwlen = document.addProfile.txtPassword.value;
		var cfpwlen = document.addProfile.txtConpassword.value;
		if(pwlen.length<6 || pwlen.length>8)
		{
			alert("Password should be minimum 6 and maximum 8 characters")
			document.addProfile.txtPassword.value='';
			document.addProfile.txtConpassword.value='';
			document.addProfile.txtPassword.focus();
			return false;
		}
		
		
	}
	if(!validateNotEmpty(document.addProfile.txtConpassword.value)){alertlist+="Please enter \"Confirm Password\"\n";fcs+="-txtConpassword";}
	if(validateNotEmpty(document.addProfile.txtConpassword.value))
	{
		if(document.addProfile.txtPassword.value != document.addProfile.txtConpassword.value)
		{
			document.addProfile.txtPassword.value='';
			document.addProfile.txtConpassword.value='';
			alert("Password and confirm password should be same")
			document.addProfile.txtPassword.focus();
			return false;
		}
	}
	
	//-------------------name of the company-start--------------------------------
	if(!validateNotEmpty(document.addProfile.txtBusinessname.value)){alertlist+="Please enter \"Company Name\"\n";fcs+="-txtBusinessname";}
	if(validateNotEmpty(document.addProfile.txtBusinessname.value))
	{
		if(document.addProfile.txtBusinessname.value.length<2)
		{
			alert("Please enter valid Name of the Company");
			document.addProfile.txtBusinessname.focus();
			return false;
		}
		if(!validateAlpha1BusinessName(document.addProfile.txtBusinessname.value))
		{
			alert("Please enter valid Name of the Company");
			document.addProfile.txtBusinessname.focus();
			return false;
		}
	}
	
	
	//-------------------name of the company-end--------------------------------
	//-------------------Address1&2-start--------------------------------
		if(!validateNotEmpty(document.addProfile.txtAddressline1.value)){alertlist+="Please enter \"Address1\"\n";fcs+="-txtAddressline1";}
		if(validateNotEmpty(document.addProfile.txtAddressline1.value))
		{
			if(document.addProfile.txtAddressline1.value.length<2)
			{
				alert("Please enter valid Address Line 1");
				document.addProfile.txtAddressline1.focus();
				return false;
			}
			if(!checkaddress(document.addProfile.txtAddressline1.value))
			{ 
				alert("Please enter valid Address Line 1");
				document.addProfile.txtAddressline1.focus();
				return false;
			}
			if(document.addProfile.txtAddressline1.value==0)
			{ 
				alert("Please enter valid  Address Line 1");
				document.addProfile.txtAddressline1.focus();
				return false;
			}

		}
		
		
		if(document.addProfile.txtAddressline2.value!="")
		{

			if( document.addProfile.txtAddressline2.value.length<2)
			{
				alert("Please enter valid Address Line 2");
				document.addProfile.txtAddressline2.focus();
				return false;
			}
			
			if(!checkaddress(document.addProfile.txtAddressline2.value))
			{ 
				alert("Please enter valid Address Line 2");
				document.addProfile.txtAddressline2.focus();
				return false;
			}
			if(document.addProfile.txtAddressline2.value==0)
			{
				alert("Please enter valid Address Line 2");
				document.addProfile.txtAddressline2.focus();
				return false;
			}
		}
		//-------------------Address1&2-end--------------------------------
		
		//-------------------City-start--------------------------------
		if(document.addProfile.txtCity.value!="")
		{
			if(!validateCityState(document.addProfile.txtCity.value) || document.addProfile.txtCity.value==0 || document.addProfile.txtCity.value.length<2)
			{
				alert("Please enter valid City/Town");
				document.addProfile.txtCity.focus();
				return false;
			}
		}
		//-------------------City-end--------------------------------
		
		//-------------------Country-start--------------------------------
		if(document.addProfile.country.value=="selCountry"){alertlist+="Please select \"Country\"\n";fcs+="-country";}
		
		//-------------------Country-end--------------------------------
		
		//-------------------State-start--------------------------------
		if(document.addProfile.country.value==130)
		{
			if(document.addProfile.state.value=="SelState"){alertlist+="Please select \"State\"\n";fcs+="-state";}
		}
		else
		{
			if(!validateNotEmpty(document.addProfile.Otherstate.value)){alertlist+="Please enter \"Other State\"\n";fcs+="-Otherstate";}
			if(validateNotEmpty(document.addProfile.Otherstate.value))
			{
				if(!validateCityState(document.addProfile.Otherstate.value) || document.addProfile.Otherstate.value==0 || document.addProfile.Otherstate.value.length<2)
				{
					alert("Please enter valid State");
					document.addProfile.Otherstate.focus();
					return false;
				}
			}
		}
		
		//-------------------State-end--------------------------------
		//-------------------pincode-start--------------------------------
		if(!validateNotEmpty(document.addProfile.txtPinzip.value)){alertlist+="Please enter \"Pincode\"\n";fcs+="-txtPinzip";}		
		if(validateNotEmpty(document.addProfile.txtPinzip.value))
		{
			if(document.addProfile.txtPinzip.value==0 || document.addProfile.txtPinzip.value.length<2)
			{
			alert("Please enter valid Pincode");
			document.addProfile.txtPinzip.focus();
			return false;
			}			

			if(validateNotEmpty(document.addProfile.txtPinzip.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text=="India")
			{
				if(!validateInteger(document.addProfile.txtPinzip.value) || document.addProfile.txtPinzip.value==0)
				{
					alert("Please enter valid Pincode");
					document.addProfile.txtPinzip.focus();
					return false;
				}				
				if(document.addProfile.txtPinzip.value.length < 6 )
				{	
					alert("Pincode should be six or eight digit onlys");
					document.addProfile.txtPinzip.focus();
					return false;					
				}
				else if(document.addProfile.txtPinzip.value.length > 8 )
				{
					alert("Pincode should be six or eight digit only");
					document.addProfile.txtPinzip.focus();
					return false;					
				}
				else if(document.addProfile.txtPinzip.value.length == 7 )
				{
					alert("Pincode should be six or eight digit only");
					document.addProfile.txtPinzip.focus();
					return false;					
				}
			}
			if(validateNotEmpty(document.addProfile.txtPinzip.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text!="India")
			{
				if(!validateZipcode(document.addProfile.txtPinzip.value))
				{
				alert("Please enter valid Pincode");
				document.addProfile.txtPinzip.focus();
				return false;
				}
			}
		}
		
		//-------------------pincode-end--------------------------------
		//-------------------Phone-start-------------------------------
		if(!validateNotEmpty(document.addProfile.txtPhone1.value)){alertlist+="Please enter \"Phone Number1\"\n";fcs+="-txtPhone1";}
		if(validateNotEmpty(document.addProfile.txtPhone1.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text=="India" )
		{
			if(validate_Phonenumber('txtPhone1','phone','yes','','')==false){			
			return false;
			}
		}
		else if(document.addProfile.txtPhone1.value==0 || document.addProfile.txtPhone1.value.length<2)
		{
				alert("Please enter valid Phone Number1");
				document.addProfile.txtPhone1.focus();
				return false;
		}	
			
		//-------------------Phone-end--------------------------------

		//-------------------Phone2-start--------------------------------
		if(validateNotEmpty(document.addProfile.txtPhone2.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text=="India")
		{
			if(validate_Phonenumber('txtPhone2','phone','no','','')==false)
			{
				return false;
			}
		}
		else if(validateNotEmpty(document.addProfile.txtPhone2.value))
		{
			if(document.addProfile.txtPhone2.value==0 || document.addProfile.txtPhone2.value.length<2){
				alert("Please enter valid Phone Number2");
				document.addProfile.txtPhone2.focus();
				return false;
			}
		}	
		//-------------------Phone2-end--------------------------------

		//-------------------Fax-start--------------------------------
		if(validateNotEmpty(document.addProfile.txtFax.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text=="India")
		{
			if(validate_Phonenumber('txtFax','fax','no','','')==false)
			{
				return false;
			}
		}
		else if(validateNotEmpty(document.addProfile.txtFax.value))
		{
			if(document.addProfile.txtFax.value==0 || document.addProfile.txtFax.value.length<2){
				alert("Please enter valid Fax Number");
				document.addProfile.txtFax.focus();
				return false;
			}
		}	
		//-------------------Fax-end--------------------------------
		//-------------------url-start--------------------------------
		if(validateNotEmpty(document.addProfile.txtUrl.value))
		{
			if(!validateUrl(document.addProfile.txtUrl.value))
			{
				alert("Please enter valid URL");
				document.addProfile.txtUrl.focus();
				return false;
			}
		}
		//-------------------url-end--------------------------------

		//-------------------Contact Details-start--------------------------------
		if(!validateNotEmpty(document.addProfile.txtConname.value)){alertlist+="Please enter \"Contact Person Name\"\n";fcs+="-txtConname";}		
		if(validateNotEmpty(document.addProfile.txtConname.value) && !validateAlpha1Name(document.addProfile.txtConname.value) || validateNotEmpty(document.addProfile.txtConname.value) && document.addProfile.txtConname.value.length<2)
		{
			alert("Please enter valid Name")
			document.addProfile.txtConname.focus();
			return false;
		}
		if(!validateNotEmpty(document.addProfile.txtEmail.value)){alertlist+="Please enter \"Email id\"\n";fcs+="-txtEmail";}
		if(validateNotEmpty(document.addProfile.txtEmail.value) && !validateEmail(document.addProfile.txtEmail.value))
		{
			alert("Please enter valid email id");
			document.addProfile.txtEmail.focus();
			return false;
		}
		if(validateNotEmpty(document.addProfile.txtaddPhone.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text=="India")
		{
			if(validate_Phonenumber('txtaddPhone','phone','yes','','')==false){			
			return false;
			}
		}
		else if(validateNotEmpty(document.addProfile.txtaddPhone.value))
		{
			if(document.addProfile.txtaddPhone.value==0 || document.addProfile.txtaddPhone.value.length<2){
				alert("Please enter valid Contact Phone Number");
				document.addProfile.txtaddPhone.focus();
				return false;
			}
		}
		
		if(validateNotEmpty(document.addProfile.txtMobile.value) && document.addProfile.country.options[document.addProfile.country.selectedIndex].text=="India")
		{
			if(validate_Phonenumber('txtMobile','mobile','no','','')==false){
				return false;
			}
		}
		else if(validateNotEmpty(document.addProfile.txtMobile.value))
		{
			if(document.addProfile.txtMobile.value==0 || document.addProfile.txtMobile.value.length<2){
				alert("Please enter valid Mobile Number");
				document.addProfile.txtMobile.focus();
				return false;
			}
		}	

		if(alertlist!="")
		{
			
			alert(alertlist);
			fcs_splt=fcs.split("-");
			//alert(fcs_splt[1]);
			document.getElementById(fcs_splt[1]).focus();
			alertlist="";
			fcs="";
			return false;
		}
		//-------------------Contact Details-end--------------------------------
		
		disablebuttons("-submit_btn-reset_btn-close_btn");
		var passvar="empty&uname="+document.addProfile.txtUserid.value+"&emailid="+document.addProfile.txtEmail.value+"&actn=saveprofile";	
		var url="modules/advertiserequire/check_availability.php";
		loadmajax(url,'POST',passvar,'empty');
		return false;
		

}
function submitprofile_ajax(actn)
{
	


	if(actn=="username_exists")
	{
		alert("User name already exist");
		document.addProfile.txtUserid.value="";
		document.addProfile.txtUserid.focus();
		enablebuttons("-submit_btn-reset_btn-close_btn");
		return false;
	}
	if(actn=="emailid_exists")
	{
		alert("email-id already exist");
		document.addProfile.txtEmail.value="";
		document.addProfile.txtEmail.focus();
		enablebuttons("-submit_btn-reset_btn-close_btn");
		return false;
	}
	if(actn=="saveprofile")
	{
		document.addProfile.operation.value=actn;
		document.addProfile.submit();
	}
}

/**  Function	: closeadd()
	*    ---------------------------------------------------------------- 
	*    Name		: closeadd
	*    Purpose    : To close the form			  
	*    Arguments  : Nil 	
	
	*/ 
	function closeadd()
	{			
	 window.location="index.php";
	}	

	/**  Function	: closeadd()
	*    ---------------------------------------------------------------- 
	*    Name		: closeadd
	*    Purpose    : To close the form			  
	*    Arguments  : Nil 	
	
	*/ 
	function resetadd()
	{
	document.addProfile.operation.value="reset";
	document.addProfile.submit();
	}	
