// JavaScript Document

function showtime()
{	//alert("hello");
	//k=document.getElementById("call_yes").value;
	//alert(k);
		document.getElementById("tm").style.display='block';
		//k1=document.getElementById("call_yes").value;
		//alert(k1);
}
function hidetime()
{	//alert("hello");
		document.getElementById("tm").style.display='none';
}

function validate_mer(frm)
{	
	//alert("fffffffff");
	var i;
 	var ftMerchantUName=document.getElementById('ftMerchantUName').value;
		var ftMerchantPwd=document.getElementById('ftMerchantPwd').value;
		var email=document.getElementById('ftMerchantEmail').value;
		var ftCompanyName=document.getElementById('ftCompanyName').value;
		//var city=document.getElementById('ftMerchantCity').value;
		
		var ftMerchantName=document.getElementById('ftMerchantName').value;
		var ftMerchantAddress=document.getElementById('ftMerchantAddress').value;
		var ftMerchantCity=document.getElementById('ftMerchantCity').value;
		
		var ftMerchantState=document.getElementById('ftMerchantState').value;
		var ftMerchantZip=document.getElementById('ftMerchantZip').value;
		var ftMerchantLocation=document.getElementById('ftMerchantLocation').value;
		var ftCompanyEmail=document.getElementById('ftCompanyEmail').value;
		var ftCompanyDesc=document.getElementById('ftCompanyDesc').value;
		var fnMerchantOpHours=document.getElementById('fnMerchantOpHours').value;
		var ftMerchantArea=document.getElementById('ftMerchantArea').value;
		var ftMerchantSpeciality=document.getElementById('ftMerchantSpeciality').value;
		
		var ftMerchantPh1=document.getElementById('ftMerchantPh1').value;
		var ftMerchantPh2=document.getElementById('ftMerchantPh2').value;
		var ftMerchantPh3=document.getElementById('ftMerchantPh3').value;
		
	 var edit=document.getElementById("edit").value;
		
		if((ftMerchantPh1!="") || (ftMerchantPh2!="") ||( ftMerchantPh3!=""))
			{
				if(ftMerchantPh1=="" || ftMerchantPh2=="" || ftMerchantPh3=="")
				{
					alert("Enter the correct Phone number"); 
					frm.ftMerchantPh1.focus();
					return false;
				}
				a=isNumeric(ftMerchantPh1);
				b=isNumeric(ftMerchantPh2);
				c=isNumeric(ftMerchantPh3);
				if((!a) || (!b) || (!c))
				{
						alert("Enter the numeric Phone number"); 
						frm.ftMerchantPh1.focus();
						return false;	
				}
				if((ftMerchantPh1.length<3) || (ftMerchantPh2.length<3) ||(ftMerchantPh3.length<4))
				{
						alert("Enter 3 digits in Ist, IInd box and 4 digits in IIIrd box in Phone number"); 
						frm.ftMerchantPh1.focus();
						return false;	
				}
				
			}
			
			if(document.getElementById("news").checked==true)
			{
				document.getElementById("news").value='1';
				
			}
			else if(document.getElementById("news").checked==false)
			{ 
			document.getElementById("news").value='0';
			
			}
			
			if(document.getElementById("newsletter").checked==true)
			{
				document.getElementById("newsletter").value='1';
			}
			else if(document.getElementById("newsletter").checked==false)
			{ 
			document.getElementById("newsletter").value='0';
			}
			
			if(document.getElementById("call_yes").checked==true)
			{
				document.getElementById("call_yes").value='1';
				//document.getElementById("tm").style.display='block';
				
			}
			else if(document.getElementById("call_no").checked==true)
			{ 
			document.getElementById("call_no").value='0';
			//document.getElementById("tm").style.display='none';
			
			}
	//alert(edit);
	if(edit==0)
	{
			var fnCategoryId1=document.getElementById("fnCategoryId1").value;
			var fnCategoryId2=document.getElementById("fnCategoryId2").value;
			//rk
			//var fnCategoryId3=document.getElementById("fnCategoryId3").value;
			
			var fnSubCategoryId1=document.getElementById("fnSubCategoryId1").value;
			var fnSubCategoryId2=document.getElementById("fnSubCategoryId2").value;
			//var fnSubCategoryId3=document.getElementById("fnSubCategoryId3").value;
			
			var ftCatExtraDesc2=document.getElementById("ftCatExtraDesc2").value;
			//var ftCatExtraDesc3=document.getElementById("ftCatExtraDesc3").value;
			
			
			if(fnCategoryId1=="")
			{
				
				alert("Please Select Category1");
				frm.fnCategoryId1.focus();
				return false;
			}
			if((fnCategoryId1!="") && (fnSubCategoryId1=='undefined'))
			{
				
				alert("The Category1 has no Sub Category.Select other Category");
				frm.fnCategoryId1.focus();
				return false;
			}
			
			
			if((fnCategoryId2!="") && (fnSubCategoryId2=='undefined'))
			{
				
				alert("The Category2 has no Sub Category.Select other Category");
				frm.fnCategoryId2.focus();
				return false;
			}
			
			
			//rk
		/*	if((fnCategoryId3!="") && (fnSubCategoryId3=='undefined'))
			{
				
				alert("The Category3 has no Sub Category.Select other Category");
				frm.fnCategoryId3.focus();
				return false;
			}*/
			if((fnCategoryId1==fnCategoryId2) && (fnSubCategoryId1==fnSubCategoryId2) && (fnCategoryId1!=""))
			{
				alert("Two Subcategories are duplicate");
				frm.fnSubCategoryId2.focus();
				return false;
			}
			//rk
			/*if((fnCategoryId3==fnCategoryId2) && (fnSubCategoryId3==fnSubCategoryId2) && (fnCategoryId2!=""))
			{
				alert("Two Subcategories are duplicate");
				frm.fnSubCategoryId3.focus();
				return false;
			}*/
			/*if((fnCategoryId3==fnCategoryId1) && (fnSubCategoryId3==fnSubCategoryId1) && (fnCategoryId1!=""))
			{
				alert("Two Subcategories are duplicate");
				frm.fnSubCategoryId3.focus();
				return false;
			}*/
			
			if((fnCategoryId2!="") && (ftCatExtraDesc2==""))
			{
				
				alert("Please fill the description");
				frm.ftCatExtraDesc2.focus();
				return false;
			}
			
			//rk
			/*if((fnCategoryId3!="") && (ftCatExtraDesc3==""))
			{
				
				alert("Please fill the description");
				frm.ftCatExtraDesc3.focus();
				return false;
			}*/
		
	}
	if(edit==1)
	{	//alert("edit");
			var i;
			var numcat=document.getElementById("numcat").value;
	 		//alert(numcat);
			var fnCategoryId=new Array();
			var fnSubCategoryId=new Array();
			var ftCatExtraDesc=new Array();
			for(i=1;i<=numcat;i++)
			{
				fnCategoryId[i]=document.getElementById("fnCategoryId"+i).value;
				fnSubCategoryId[i]=document.getElementById("fnSubCategoryId"+i).value;
				if(i>1)
				{
					 ftCatExtraDesc[i]=document.getElementById("ftCatExtraDesc"+i).value;
				}
				//alert(fnSubCategoryId[i]);
			}
			for(i=1;i<=numcat;i++)
			{
				if(fnCategoryId[i]=="")
				{
				
					alert("Please Select Category"+i);
					//frm.fnCategoryId[i].focus();
					return false;
				}
				if((fnCategoryId[i]!="") && (fnSubCategoryId[i]=='undefined'))
				{
				
					alert("The Category has no Sub Category.Select other Category");
					//frm.fnCategoryId[i].focus();
					return false;
				}
				
				if(i>1)
				{
					//var ftCatExtraDesc[i]=document.getElementById("ftCatExtraDesc"+i).value;
					if((fnCategoryId[i]!="") && (ftCatExtraDesc[i]==''))
					{
					
						alert("Please fill the description");
						//frm.ftCatExtraDesc2.focus();
						return false;
					}
				}
			}
			var test;
			for(i=1;i<=numcat;i++)
			{	
				//alert("i="+fnCategoryId[i]);
				test=0;
					for(j=i+1;j<=numcat;j++)
					{	
						//alert("j="+fnCategoryId[j]);
						if((fnCategoryId[i]==fnCategoryId[j]) && (fnSubCategoryId[i]==fnSubCategoryId[j]) && (fnCategoryId[i]!=""))
						{
							alert("Two Subcategories are duplicate");
							//frm.fnCategoryId+i.focus();
							test=1;
							return false;
						}	
					}
				
			}
	}
	 if(ftMerchantUName=="")
			{
				
				alert("Please Enter Username");
				frm.ftMerchantUName.focus();
				return false;
			}
		if(ftMerchantPwd=="")
			{
				
					alert("Please Enter Password");
					frm.ftMerchantPwd.focus();
					return false;
			}
			if(ftMerchantName=="")
			{
				alert("Please Enter name");
				frm.ftMerchantName.focus();
				return false;
			}
			if(ftCompanyName=="")
			{
					alert("Please Enter Company Name");
					frm.ftCompanyName.focus();
					return false;
			}
			if(ftMerchantAddress=="")
			{
				alert("Please Enter Address");
				frm.ftMerchantAddress.focus();
				return false;
			}
			if(ftMerchantCity=="")
			{
				alert("Please Enter City");
				frm.ftMerchantCity.focus();
				return false;
			}
			if(ftMerchantState=="")
			{
				
				alert("Please Enter State");
				frm.ftMerchantState.focus();
				return false;
			}
			if(ftMerchantZip=="")
			{
				
				alert("Please Enter Zipcode");
				frm.ftMerchantZip.focus();
				return false;
			}
			if(ftMerchantLocation=="")
			{
				
				alert("Please Enter County");
				frm.ftMerchantLocation.focus();
				return false;
			}
			if(email.indexOf('@',0)==-1) 
			{
				alert("The E-Mail address does not contain an '@' character");
				frm.ftMerchantEmail.focus();
				return false;
			}
			else if(email.indexOf('@',0)<1)
			{
				alert("An E-Mail address must contain at least one character before the '@' character" );
				frm.ftMerchantEmail.focus();
				return false;
			}
			else if(email.indexOf ('.',0)==-1)
			{
				alert("An E-Mail address must contain a period ('.') character" );
				frm.ftMerchantEmail.focus();
				return false;
			}
			
			if(ftCompanyDesc=="")
			{
				
				alert("Please Enter Company Description");
				frm.ftCompanyDesc.focus();
				return false;
			}
			
			
			if(ftCompanyEmail.indexOf('@',0)==-1) 
			{
				alert("The E-Mail address does not contain an '@' character");
				frm.ftCompanyEmail.focus();
				return false;
			}
			else if(ftCompanyEmail.indexOf('@',0)<1)
			{
				alert("An E-Mail address must contain at least one character before the '@' character" );
				frm.ftCompanyEmail.focus();
				return false;
			}
			else if(ftCompanyEmail.indexOf ('.',0)==-1)
			{
				alert("An E-Mail address must contain a period ('.') character" );
				frm.ftCompanyEmail.focus();
				return false;
			}
			
			if(fnMerchantOpHours=="")
			{
				
				alert("Please Enter Hours of Operation");
				frm.fnMerchantOpHours.focus();
				return false;
			}
			
			if(ftMerchantArea=="")
			{
				
					alert("Please Enter Areas Serviced");
					frm.ftMerchantArea.focus();
					return false;
			}
			if(ftMerchantSpeciality=="")
			{
				
					alert("Please Enter Specialities");
					frm.ftMerchantSpeciality.focus();
					return false;
			}

			
			
		frm.submit();
			
			
			
	
}

function isNumeric(value) {
       if (value == null || !value.toString().match(/^[-]?\d*\.?\d*$/)) return false;
       return true;
   }
function Trim(value) 
		{

			var re = /\s*((\S+\s*)*)/;
			return value.replace(/^\s+|\s+$/g, "");
		}

function statusChange(obj,type)
{	
	//alert("1");
	
		var ajaxRequest; // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		}
		catch (e){
		// Internet Explorer Browsers
			try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) {
				try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
		// Something went wrong
				alert("Your browser broke!");
				return false;
				}
			}
		}
		data=obj.value;
		//alert(data);
		xyz=Math.random();
		ajaxRequest.open("GET","/AJAX.php?type="+type+"&data="+data+"&xyz="+xyz, true);
		ajaxRequest.send(null);
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				if((type=="category1") || (type=="category2") || (type=="category3"))
				{
					//alert(ajaxRequest.responseText);
					result = ajaxRequest.responseText;
					if(type=="category1")
					var sample=document.getElementById('fnSubCategoryId1');
					
					if(type=="category2")
					var sample=document.getElementById('fnSubCategoryId2');
					
					//rk
					/*if(type=="category3")
					var sample=document.getElementById('fnSubCategoryId3');*/
					
					
					//document.getElementById('sub').innerHTML=result;	
					sample.options.length=0;
					t1=result.split('$');
					var l=t1.length;
					
					for(i=0;i<l;i++)
					{
						t2=t1[i].split('~');
						
						var optn = document.createElement("OPTION");
						optn.text = t2[0];
						optn.value = t2[1];
						sample.options.add(optn);
						
						
					}
					if(type=="category2" && data!="")
					document.getElementById('description2').style.display='block';
					else if(type=="category2" && data=="")
					{
					document.getElementById('description2').style.display='none';
					document.getElementById('description2').value='';
					}

					
					if(type=="category3" && data!="")
					document.getElementById('description3').style.display='block';
					else if(type=="category3" && data=="")
					{
					document.getElementById('description3').style.display='none';
					document.getElementById('description3').value='';
					}
					

				}
				else if(type=="username")
				{
					
					result = ajaxRequest.responseText;
					result=Trim(result);
					//alert(result+'1');
					document.getElementById('response').innerHTML=result;
					if(result!="")
					{
						//alert(result!="");
						document.getElementById('ftMerchantUName').value="";
					}
					//document.getElementById('ftMerchantUName').focus();
				}
				else if(type=="userUName")
				{
					
					result = ajaxRequest.responseText;
					result=Trim(result);
					//alert(result+'1');
					document.getElementById('responseUName').innerHTML=result;
					if(result!="")
					{
						//alert(result!="");
						document.getElementById('username').value="";
					}
					//document.getElementById('ftMerchantUName').focus();
				}
				
			}
		}
		
}

function statusChange1(data,type,i,val)
{	
	
	//alert("first");
		var ajaxRequest; // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		
		}
		catch (e){
		// Internet Explorer Browsers
			try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) {
				try{
					
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
		// Something went wrong
				alert("Your browser broke!");
				return false;
				}
			}
		}
		//alert(i);
		//alert(i+","+type);
		
		//alert("val="+val);
		xyz=Math.random();
		url="/AJAX.php?type=category&data="+data+"&xyz="+xyz;
		ajaxRequest.open("GET",url, true);
		
		ajaxRequest.send(null);
		ajaxRequest.onreadystatechange = function()
		{	
			if(ajaxRequest.readyState == 4)
			{
				//for(var i=1;i<=n;i++)
				//{
						if((type=="category"+i) || (type=="categoryname"))
						{	
							//alert(ajaxRequest.responseText);
							result = ajaxRequest.responseText;
							//alert(result);
							//if(type=="category"+i)
							if(type=="category"+i)
							{	
								var sample=document.getElementById("fnSubCategoryId"+i);
							}
							else
								var sample=document.getElementById("fnSubCategoryId");
							if(i>1)
							{
								if(type=="category"+i && data!="")
								{	
									document.getElementById('description'+i).style.display='block';
								}
								else if(type=="category"+i && data=="")
								{
									document.getElementById('description'+i).style.display='none';
									document.getElementById('description'+i).value="";
								}
							}
							
							//document.getElementById('sub').innerHTML=result;	
							sample.options.length=0;
							t1=result.split('$');
							var l=t1.length;
							
							for(i=0;i<l;i++)
							{
								t2=t1[i].split('~');
								
								var optn = document.createElement("OPTION");
								optn.text = t2[0];
								optn.value = t2[1];
								sample.options.add(optn);
								
								
							}
							//if(type=="category"+i)
							//var val=document.getElementById("fnSubCategory"+i).value;
							//alert(val);
							for(count=0;count<sample.options.length;count++)
							{	
								sample[count].value=sample[count].value.replace(/^\s+|\s+$/g,"");
								if(sample[count].value==val)
								{	
									sample.options[count].selected = true;
								}
						   }
		
						}
				//}
				
			}
			

		}
		
}

function statusChange2(obj,type,i)
{	//alert(i);
	//alert('change');
	//alert("hello"+i);
		var ajaxRequest; // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		
		}
		catch (e){
		// Internet Explorer Browsers
			try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			
			} 
			catch (e) {
				try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
		// Something went wrong
				alert("Your browser broke!");
				return false;
				}
			}
		}
		data=obj.value;
		//alert(data);
		xyz=Math.random();
		url="/AJAX.php?type=category&data="+data+"&xyz="+xyz;
		//alert(url);
		ajaxRequest.open("GET",url, true);

		ajaxRequest.send(null);
		
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				
					result=ajaxRequest.responseText;
					//alert(result);
					var sample=document.getElementById('fnSubCategoryId'+i);
					sample.options.length=0;
					t1=result.split('$');
					var l=t1.length;
					
					for(i=0;i<l;i++)
					{
						t2=t1[i].split('~');
						
						var optn = document.createElement("OPTION");
						optn.text = t2[0];
						optn.value = t2[1];
						sample.options.add(optn);
						
						
					}
					
			}
			if(i>1)
					{
						if(data!="")
								document.getElementById('description'+i).style.display='block';
							else
							{
								document.getElementById('description'+i).style.display='none';
								document.getElementById('description'+i).value="";
							}
					}
			

		}
}

function updateTime(id)
{
		var ajaxRequest; // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		
		}
		catch (e){
		// Internet Explorer Browsers
			try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			
			} 
			catch (e) {
				try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
		// Something went wrong
				alert("Your browser broke!");
				return false;
				}
			}
		}
			var x=Math.random();
			var url="/AJAX_time.php?fnMerchantId="+id+"&x="+x;
			
			ajaxRequest.open("GET",url, true);

		ajaxRequest.send(null);
		//alert("hello");
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
				//alert("hello1");
					result=ajaxRequest.responseText;
					//alert(result);
			}
			

		}
}


function statusChange4(obj,type)
{	
	
	
		var ajaxRequest; // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		}
		catch (e){
		// Internet Explorer Browsers
			try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) {
				try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
		// Something went wrong
				alert("Your browser broke!");
				return false;
				}
			}
		}
		data=obj;
		//alert(data);
		xyz=Math.random();
		ajaxRequest.open("GET","/AJAX.php?type="+type+"&data="+data+"&xyz="+xyz, true);
		ajaxRequest.send(null);
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
					
					//document.getElementById('ftCategoryName').value=result;	
					
					
					
					result=ajaxRequest.responseText;
					//alert(result);
					var sample=document.getElementById('fnSubCategoryId');
					sample.options.length=0;
					tn=result.split('|');
					
					document.getElementById('ftCategoryName').value=tn[0];	
					
					t1=tn[1].split('$');
					var l=t1.length;
					
					for(i=0;i<l;i++)
					{
						t2=t1[i].split('~');
						
						var optn = document.createElement("OPTION");
						optn.text = t2[0];
						optn.value = t2[1];
						sample.options.add(optn);
						
						
					}
						
			}

		}
			
}
function statusChange5(obj,type)
{	
	
	
		var ajaxRequest; // The variable that makes Ajax possible!
		try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		}
		catch (e){
		// Internet Explorer Browsers
			try{
		
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) {
				try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e){
		// Something went wrong
				alert("Your browser broke!");
				return false;
				}
			}
		}
		data=obj;
		//alert(data);
		xyz=Math.random();
		ajaxRequest.open("GET","/AJAX.php?type="+type+"&data="+data+"&xyz="+xyz, true);
		ajaxRequest.send(null);
		ajaxRequest.onreadystatechange = function()
		{
			if(ajaxRequest.readyState == 4)
			{
					result=ajaxRequest.responseText;
					document.getElementById('ftSubCategoryName').value=result;	
					
					
					
					
						
			}

		}
			
}

function textCounter1(field,maxlimit) {
if (field.value.length > maxlimit)
{// if too long...trim it!
field.value = field.value.substring(0, maxlimit);
alert("Maximum limit is 800 characters");
}
// otherwise, update 'characters left' counter
}






function getHTTPObject() 
{ try { req = new XMLHttpRequest(); } catch (err1) { try { req = new ActiveXObject("Msxml12.XMLHTTP"); } 
catch (err2) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } 
catch (err3) { req = false; } } } 
return req; 

} 

// We create the HTTP Object

function handleHttpResponse() 
	{ 
		
		
		if (httpn.readyState == 4) 
	{ captchaOK = httpn.responseText; alert(captchaOK);  if(captchaOK != 1) { alert('The entered code was not correct. Please try again'); document.f1.ftVerfication.value=''; document.f1.ftVerfication.focus(); return false; }  if(document.f1.onsubmit())
					 {//this check triggers the validations
						document.f1.submit();
					 }//document.f1.submit(); 
	}
	}

	function checkcode(thecode) 
		{
			var url1 = '/captcheck.php?code='; var captchaOK = 2; // 2 - not yet checked, 1 - correct, 0 - failed
			var httpn = getHTTPObject(); 
			httpn.open("GET", url1 + escape(thecode), true); // httpn.onreadystatechange = handleHttpResponse; 
			httpn.send(null);
			httpn.onreadystatechange = function()
			{
					
						if (httpn.readyState == 4) 
					{ 
							captchaOK = httpn.responseText;   if(captchaOK != 1) { alert('The entered code was not correct. Please try again'); document.f1.ftVerfication.value=''; document.f1.ftVerfication.focus(); return false; }  
							if(document.f1.onsubmit())
									 {//this check triggers the validations
										document.f1.submit();
									 }//document.f1.submit(); 
					}
			}
		} 
		function checkform() 
			{ // First the normal form validation 
			
			if(document.f1.ftVerfication.value=='') 
			{ 
			alert('Please enter the string from the displayed image'); document.f1.ftVerfication.value=''; document.f1.ftVerfication.focus(); return false; 
			} // Now the Ajax CAPTCHA validation 
		checkcode(document.f1.ftVerfication.value);
		 
		 //document.f1.submit();
		return false;
		
		}