// Check Field
// For Other Domain
 
var flag;

// Email Validation
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 isDigit(field)
{
	 
	if(isNaN(field.value))
	{ 
		field.value= "";
	}
}

function isEmpty(field,fieldName)
{
	if(field.value.replace(/^\s+/,"")=="")
	{
		alert(fieldName+' Require');
		field.focus();
		return false;
	}
	else
		return true;
}
function isNotSelected(field,fieldName)
{
	if(field.value.replace(/^\s+/,"")=="" || field.value.replace(/^\s+/,"")=="0")
	{
		alert(fieldName+' Require');
		field.focus();
		return false;
	}
	else
		return true;
}
 
// Check Field For Customer 
 
function checkFormElements(f)
{
 
  
  for (var n=0; n < f.elements.length; n++) {
    var formElement = "";
		formElement =  f.elements[n];
	 	//alert(formElement.className);
		cls=new Array();
		cls=formElement.className.split(' '); 
	  	 
	 
	// if Element is Text Box 
	if(cls[0]=="txtrequired")
	{
 	
		if((formElement.name!='txtnooflead' && formElement.name!='txtstates') || document.getElementById('outbound_service').style.display=='block')
		{
			fieldName=formElement.id.replace('_'," ") 
			flag=isEmpty(formElement,fieldName);
			 if(flag==false)	
				return false;
		} 
			 
	} 
	else if(cls[0]=="txtrequiredsel") // If Element is Selected Box
	{
		 
		 
			fieldName=formElement.id.replace('_'," ")  
			flag=isNotSelected(formElement,fieldName);
			if(flag==false)	
			return false;
		 
			 
	} 
	else if(cls[0]=="txtrequiredemail") // If Element is Selected Box
	{
		 // check Field is Empty
		fieldName=formElement.id.replace('_'," ")  
		flag=isEmpty(formElement,fieldName);
		 if(flag==false)	
			return false;
		// check is Valid Email	
		if(echeck(formElement.value)==false){
			formElement.value=""
			formElement.focus()
			return false
		} 
	} // else if
	else if(cls[0]=="txtrequiredphone") // If Element is Selected Box
	{
		 // check Field is Empty
		fieldName=formElement.id.replace('_'," ")  
		flag=isEmpty(formElement,fieldName);
		 if(flag==false)	
			return false;
		// check is Valid Email	
		 if(formElement.value.length<10)
		 {
			alert(fieldName+" should be in 10 Digits")
			formElement.focus();
			return false;
			 
		 }
	} // else if
	else if(cls[0]=="txtphone") // If Element is Selected Box
	{
		 // check Field is Empty
		fieldName=formElement.id.replace('_'," ")   
		// check is Valid Email	
		 if(formElement.value!="" && formElement.value.length<10)
		 {
			alert(fieldName+" should be in 10 Digits")
			formElement.focus();
			return false;
			 
		 }
	} // else if 
	else if(cls[0]=="txtrequiredchk") // If Element is Selected Box
	{
		// alert(formElement 
		
		if(formElement.name=='chk[]') // if formElement name is frame type
		{
				
				chk=document.frm[formElement.name]
				
				fieldName=formElement.id;
				fieldName=fieldName.substr(0,fieldName.length-2);
				fieldName=fieldName.replace('_'," ")
				   
				 t=0;
				 for (counter = 0; counter < chk.length; counter++)
					{ 
						  
						if (chk[counter].checked==false)
							t++;
							 
					}
					 
					if(t==chk.length)
					{
						alert(fieldName+' required');
						return false;
					}
		}
		 
	} // else if
	
  }	// end for loop
	 
return true;
}

function doSelectAll()
{
	chk=document.frm['chk1[]']
	 for (counter = 0; counter < chk.length; counter++)
		{   
			 chk[counter].checked=true  
		}
}
function doDeeSelectAll()
{
	chk=document.frm['chk1[]']
	 for (counter = 0; counter < chk.length; counter++)
		{   
			 chk[counter].checked=false  
		}
}
 
