function sbfrm(name,action)
{
 
 document.getElementById(name).action=action;
 document.getElementById(name).submit();
}

function goto(page)
{
	location.href=page;
}

function validate(total)
{
	

	
	for(i=1; i<=total; i++)
	  {
		  
		  if(document.getElementById(i).value=="")
		    {
				
				alert("Please enter "+document.getElementById("l"+i).innerHTML+".");
				document.getElementById(i).focus();
				return false;
			}
			
			if(document.getElementById(i).name=="email" && echeck(document.getElementById(i).value)==false)
				{
					
				  document.getElementById(i).focus();
				  return false;	
				}
			if(document.getElementById(i).name=="semail" && echeck(document.getElementById(i).value)==false)
				{
					
				  document.getElementById(i).focus();
				  return false;	
				}
				
		   if(document.getElementById(i).name=="bemail" && echeck(document.getElementById(i).value)==false)
				{
					
				  document.getElementById(i).focus();
				  return false;	
				}
				if(document.getElementById(i).name=="npassword" && document.getElementById(i+1).name=="rpassword" && document.getElementById(i+1).value!=document.getElementById(i).value )
				{
					alert("New Password and Re Password dost match.");
				  document.getElementById(i).focus();
				  return false;	
				}
	  }
document.frm1.savestatus.value="ok";	  
document.frm1.submit();
}

function check(count,fld)
{
  if(fld.checked)
   {
	 for(i=1; i<=parseInt(count); i++)
	 {
	   document.getElementById(i).checked="checked";
	 }
   }
   else
   {
      for(i=1; i<=parseInt(count); i++)
	 {
	   document.getElementById(i).checked="";
	 }
   }	 
}

function caction(op,count,action)
{
 
 var temp;
  var total=count;
  for(i=1; i<=total; i++)
	{
	   if(document.getElementById(i).checked)
	     {
		  temp="ok";
		 }
		
	}
	
	if(temp=="ok")
	{
	  if(confirm("Are you shure to "+op))
	  {
	  document.frm1.operation.value=op;
	  document.frm1.action=action;
	  document.frm1.submit();
	  }
   }
   else
   alert("Please make some selection to "+op);
	  	 
}


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 copyfld(fld)
{
	
  if(fld.checked)
   {
	 
	document.frm1.bfname.value=document.frm1.sfname.value ;
	document.frm1.blname.value=document.frm1.slname.value;
	document.frm1.baddress.value=document.frm1.saddress.value;
	document.frm1.baaddress.value=document.frm1.saaddress.value;
	document.frm1.bcity.value=document.frm1.scity.value;
	document.frm1.bstate.value=document.frm1.sstate.value;
	document.frm1.bpcode.value=document.frm1.spcode.value;
	document.frm1.bcountry.selectedIndex=document.frm1.scountry.selectedIndex;
	document.frm1.bemail.value=document.frm1.semail.value;
	document.frm1.bphone.value=document.frm1.sphone.value;
	document.frm1.bmobile.value=document.frm1.smobile.value;
	
	
   }
   else
   {
	 document.frm1.bfname.value='';
	document.frm1.blname.value='';
	document.frm1.baddress.value='';
	document.frm1.baaddress.value='';
	document.frm1.bcity.value='';
	document.frm1.bstate.value='';
	document.frm1.bpcode.value='';
	document.frm1.bcountry.value='';
	document.frm1.bemail.value='';
	document.frm1.bphone.value='';
	document.frm1.bmobile.value=''; 
   }
}

