// JavaScript Document
function checkDelete()
{
	mycount = 0;
	for(i=0;i<document.frmlistmain.elements.length;i++)
	{
		if(document.frmlistmain.elements[i].name.substr(0,3)=="chk" && document.frmlistmain.elements[i].checked)
			mycount++;	
	}

	if(mycount==0)
	{
		alert("You must check one of the checkboxes.");
		return false;
	}

	if(!confirm("Confirm Deletion of Selected Record(s) ?"))
		return false;	
	else
	{
		document.frmlistmain.action="business_db.php";				
		document.frmlistmain.myaction.value="MultiDelete";					
		return true;	
	}
}

function checkActive()
{
	mycount = 0;
	for(i=0;i<document.frmlistmain.elements.length;i++)
	{
		if(document.frmlistmain.elements[i].name.substr(0,3)=="chk" && document.frmlistmain.elements[i].checked)
			mycount++;	
	}

	if(mycount==0)
	{
		alert("You must check one of the checkboxes.");
		return false;
	}

	if(!confirm("Confirm Active Status of Selected Record(s) ?"))
		return false;	
	else
	{
		document.frmlistmain.action="business_db.php";			
		document.frmlistmain.myaction.value="MultiActive";		
		return true;	
	}
}

function add_new()
{
	document.frmlistmain.myaction.value="add";		
	return true;	
}

function checkInActive()
{
	mycount = 0;
	for(i=0;i<document.frmlistmain.elements.length;i++)
	{
		if(document.frmlistmain.elements[i].name.substr(0,3)=="chk" && document.frmlistmain.elements[i].checked)
			mycount++;	
	}

	if(mycount==0)
	{
		alert("You must check one of the checkboxes.");
		return false;
	}

	if(!confirm("Confirm Inactive Status of Selected Record(s) ?"))
		return false;	
	else
	{
		document.frmlistmain.action="business_db.php";		
		document.frmlistmain.myaction.value="MultiInActive";		
		return true;	
	}
}

function check_Valid(th)
{
	//alert("asdfasdf");
	if(th.category.value<=0)
	{
		alert("Please Select Category !");
		th.category.focus();
		return false;
	}
	if(th.subcategory.value==0)
	{
		alert("Please Select Subcategory !");
		th.subcategory.focus();
		return false;
	}
	if(th.business_name.value<=0)
	{
		alert("Please Select Business Name !");
		th.business_name.focus();
		return false;
	}
	if(th.state.value<=0)
	{
		alert("Please Select Region !");
		th.state.focus();
		return false;
	}
	if(th.tags.value==0)
	{
		alert("Please enter Tags !");
		th.tags.focus();
		return false;
	}
	if(th.m_description.value==0)
	{
		alert("Please enter Description !");
		th.m_description.focus();
		return false;
	}
	if(th.telephone.value<=0)
	{
		alert("Please Enter Telephone !");
		th.telephone.focus();
		return false;
	}
	else
	{	
		var y = ValidateNo(th.telephone.value,"1234567890+-/ ") ;
		if(y == false)
		{
			alert("Please enter Valid Telephone Number.!");
			th.telephone.value = "" ;
			th.telephone.focus();
			return false ;
		}
	}
	/*if(th.website.value<=0)
	{
		alert("Please Enter Website !");
		th.website.focus();
		return false;
	}*/
	if(th.email.value<=0)
	{
		alert("Please Enter Email !");
		th.email.focus();
		return false;
	}
	else
	{
		var e=echeck(th.email.value);
		if(e==false)
		{
			th.email.value="";
			th.email.focus();
			return false;
		}
	}	
	if(th.address.value<=0)
	{
		alert("Please Enter Address !");
		th.address.focus();
		return false;
	}
	if(th.description.value<=0)
	{
		alert("Please Enter Description !");
		th.description.focus();
		return false;
	}
	if(th.comments.value<=0)
	{
		alert("Please Enter Comments !");
		th.comments.focus();
		return false;
	}
	if(th.map1.value<=0)
	{
		alert("Please Upload Map !");
		th.map1.focus();
		return false;
	}
	/*if(th.logo.value<=0)
	{
		alert("Please Select Image !");
		th.logo.focus();
		return false;
	}*/
	return true;
}



function check_Valid_Edit(th)
{
	if(th.category.value<=0)
	{
		alert("Please Select Category !");
		th.category.focus();
		return false;
	}
	if(th.subcategory.value==0)
	{
		alert("Please Select Subcategory !");
		th.subcategory.focus();
		return false;
	}
	if(th.business_name.value<=0)
	{
		alert("Please Select Business Name !");
		th.business_name.focus();
		return false;
	}
	if(th.state.value<=0)
	{
		alert("Please Select Region !");
		th.state.focus();
		return false;
	}
	if(th.tags.value==0)
	{
		alert("Please enter Tags !");
		th.tags.focus();
		return false;
	}
	if(th.m_description.value==0)
	{
		alert("Please enter Description !");
		th.m_description.focus();
		return false;
	}
	if(th.telephone.value<=0)
	{
		alert("Please Enter Telephone !");
		th.telephone.focus();
		return false;
	}
	else
	{	
		var y = ValidateNo(th.telephone.value,"1234567890+-/ ") ;
		if(y == false)
		{
			alert("Please enter Valid Telephone Number.!");
			th.telephone.value = "" ;
			th.telephone.focus();
			return false ;
		}
	}
	/*if(th.website.value<=0)
	{
		alert("Please Enter Website !");
		th.website.focus();
		return false;
	}*/
	if(th.email.value<=0)
	{
		alert("Please Enter Email !");
		th.email.focus();
		return false;
	}
	else
	{
		var e=echeck(th.email.value);
		if(e==false)
		{
			th.email.value="";
			th.email.focus();
			return false;
		}
	}	
	if(th.address.value<=0)
	{
		alert("Please Enter Address !");
		th.address.focus();
		return false;
	}
	if(th.description.value<=0)
	{
		alert("Please Enter Description !");
		th.description.focus();
		return false;
	}
	if(th.comments.value<=0)
	{
		alert("Please Enter Comments !");
		th.comments.focus();
		return false;
	}
	return true;
}


function openwin(f,w,h)
{
	myfile="dispimage.php?f="+f;
	mywin = window.open(myfile,'','scrollbars=yes,top=15,left=20,width='+w+',height='+h);
}	
function echeck(str) 
{
	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail ID");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert("Invalid E-mail ID");
		return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		alert("Invalid E-mail ID");
		return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert("Invalid E-mail ID");
		return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		alert("Invalid E-mail ID");
		return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
		alert("Invalid E-mail ID");
		return false;
	 }

	 return true;				
}
function ValidateNo(NumStr, String)
{    
	for(var Idx=0; Idx<NumStr.length; Idx++)    
	{
		var Char = NumStr.charAt(Idx);
		var Match = false;        
		for(var Idx1=0; Idx1<String.length; Idx1++)        
		{            
			if(Char == String.charAt (Idx1))                
			Match = true;        
		}        
		if (!Match)            
			return false;    
	}    
	return true;
}

