// 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.id=='Phone_No' && formElement.value=='' && f.elements[n-1].value=='' )
			{
				alert('Either Mobile or Phone No Required')
				return false;
			}
			else if(formElement.id!='Phone_No') {
			fieldName=formElement.id.replace('_'," ") 
			flag=isEmpty(formElement,fieldName);
			 if(flag==false)	
				return false;
			}
		 
	} 
	if(cls[0]=="txtrequiredtext")
	{
		fieldName=formElement.id.replace('_'," ") 
			flag=isEmpty(formElement,fieldName);
			 if(flag==false)	
				return false;
	}
	if(cls[0]=="txtrequiredpass")
	{
 	 
			fieldName=formElement.id.replace('_'," ") 
			flag=isEmpty(formElement,fieldName);
			 if(flag==false)	
				return false;
		 
		 newpass =  f.elements[n-1];
		 if(newpass.value!=formElement.value)
		 {
			 alert("New Password and Cofirm Password does not match")
			 formElement.focus();
			 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]=="txtemail") // If Element is Selected Box
	{
		 // check Field is Empty 
		 if(formElement.value!="" && 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;
					}
		}
		if(formElement.name=='chkterms') // if formElement name is frame type
		{
				
				if(!formElement.checked)
				{
					alert("Terms and Condition 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  
		}
}
 function checkFieldUser()
{
	// check Login Name
	  
	var user_loginname_vc=document.getElementById('user_loginname_vc');
	flag=isEmpty(user_loginname_vc,'Login Name');
	if(flag==false)	
		return false;
	
	
	// check Password
	  
		var user_pass_vc=document.getElementById('user_pass_vc');
		 
		flag=isEmpty(user_pass_vc,'Password');
		if(flag==false)	
			return false;

	 
	// check First Name
		var First_Name=document.getElementById('First_Name');
		flag=isEmpty(First_Name,'First Name');
		if(flag==false)	
			return false;
	
	// check Last Name
		var last_name_vc=document.getElementById('Last_Name');
		flag=isEmpty(last_name_vc,'Last Name');
		if(flag==false)	
			return false;

	// check Address
		var last_name_vc=document.getElementById('Address');
		flag=isEmpty(last_name_vc,'Address');
		if(flag==false)	
			return false;
	
	// check Country
		var selcountry=document.getElementById('selcountry'); 
		flag=isEmpty(last_name_vc,'Address');
		if(flag==false)	
			return false;
	
	// check State
		var state_other=document.getElementById('state_other');
		flag=isEmpty(state_other,'State ');
		if(flag==false)	
			return false;	
	
	// check City
		var city_other=document.getElementById('city_other');
		flag=isEmpty(city_other,'City ');
		if(flag==false)	
			return false;	
	// check Phone No
		var user_phone_vc=document.getElementById('Phone_No');
		flag=isEmpty(user_phone_vc,'Phone No');
		if(flag==false)	
			return false;	
	 
	// check Direction
		var user_mobile_vc=document.getElementById('Mobile_No');
		flag=isEmpty(user_mobile_vc,'Mobile No');
		if(flag==false)	
			return false;
	
	// check Email
		var user_email_vc=document.getElementById('Email_ID');
		flag=isEmpty(user_email_vc,'Email Id');
		if(flag==false)	
			return false;		
	
		if(echeck(user_email_vc.value)==false){
			user_email_vc.value=""
			user_email_vc.focus()
			return false
	}
	
	// Alt Email
	var user_altemail_vc=document.getElementById('Alt_Email');
	if(user_altemail_vc.value!="")	
	{		
		if(echeck(user_altemail_vc.value)==false){
		user_altemail_vc.value=""
		user_altemail_vc.focus()
		return false
		}
	}
	 var chkterms=document.getElementById('chkterms');
	 if(!chkterms.checked)
	 {
		alert("Please Select Terms and Condition");
		chkterms.focus();
		return false
		 
	 }
	return true;
}


// Check Field for forum
function checkForumsField()
{
	
	 
	// check Question
	// check Country
	var selcategory=document.getElementById('selcategory');
	flag=isNotSelected(selcategory,'Category ');
	if(flag==false)	
		return false;
		 
	 
	var forum_question=document.getElementById('forum_question');
	flag=isEmpty(forum_question,'Forum Question ');
	if(flag==false)	
		return false;
	 
	
	var chkterm=document.getElementById('Terms');
	 if(!chkterm.checked)
	 {
		alert('Terms and condition required')
		return false;
		 
		}	
	
	return true; 
	
}
function checkReplyField()
{
	// check Question
	 
	 
	var forum_reply=document.getElementById('forum_reply');
	flag=isEmpty(forum_reply,'Forum reply ');
	if(flag==false)	
		return false;
	
	 
	return true; 
	
}
function checkBlogField()
{
	// check Question
	 
	 
	var blog_title=document.getElementById('blog_title');
	flag=isEmpty(blog_title,'Blog Title ');
	if(flag==false)	
		return false;
	
	var blog_desc=document.getElementById('blog_desc');
	flag=isEmpty(blog_desc,'Blog Description ');
	if(flag==false)	
		return false;
	 
	var chkterm=document.getElementById('Terms');
	 if(!chkterm.checked)
	 {
		alert('Terms and condition required')
		return false;
		 
		}
	return true; 
	
}

function checkCommentField()
{
	// check Login Name
	 
	 
	var txtname=document.getElementById('txtname');
	flag=isEmpty(txtname,'Name ');
	if(flag==false)	
		return false;
	
	
	 
	// check Email
	var txtemail=document.getElementById('txtemail');
	flag=isEmpty(txtemail,'Email Id');
	if(flag==false)	
		return false;		
	if(echeck(txtemail.value)==false){
		txtemail.value=""
		txtemail.focus()
		return false
	}
	
	 
	var comments=document.getElementById('comments');
	flag=isEmpty(comments,'Comment ');
	if(flag==false)	
		return false;
	
	 return true;
	 
	
}

function checkLoginForm()
{
	// check Login Name
	 
	 
	var txtlogin=document.getElementById('txtlogin');
	flag=isEmpty(txtlogin,'Login Name ');
	if(flag==false)	
		return false;
	 
	var txtpwd=document.getElementById('txtpwd');
	flag=isEmpty(txtpwd,'Password ');
	if(flag==false)	
		return false;
	
	 return true;
	 
	
}

function checkPasswdField()
{
	// check Login Name
	 
	 
	var txtoldpwd=document.getElementById('txtoldpwd');
	flag=isEmpty(txtoldpwd,'Old Password ');
	if(flag==false)	
		return false;
	 
	var txtnewpwd=document.getElementById('txtnewpwd');
	flag=isEmpty(txtnewpwd,'New Password ');
	if(flag==false)	
		return false;
	var txtcnewpwd=document.getElementById('txtcnewpwd');
	flag=isEmpty(txtcnewpwd,' Confirm New Password ');
	if(flag==false)	
		return false;	
	if(txtnewpwd.value!=txtcnewpwd.value)
	{
		alert('New and confirm password does not match')
		return false;
		
	}
	
	 return true;
	 
	
}
