// JavaScript Document
function validchar1(val)
{
	for(i=0;i<val.length;++i)
	{
		if(val.charAt(i) == "!" ||  val.charAt(i) == "#" || val.charAt(i) == "$" || val.charAt(i) == "%" || val.charAt(i) == "^" || val.charAt(i) == "*" || val.charAt(i) == ";"  || val.charAt(i) == "=" || val.charAt(i) == "+" || val.charAt(i) == "|" || val.charAt(i) == "?"  || val.charAt(i) == "\\" )
		{
			return false;
		}
	}
	return true;
}
function validchar(val)
{
	for(i=0;i<val.length;++i)
	{
		if(val.charAt(i) == "!" || val.charAt(i) == "@" ||  val.charAt(i) == "#" || val.charAt(i) == "$" || val.charAt(i) == "%" || val.charAt(i) == "^" || val.charAt(i) == "*" || val.charAt(i) == ";"  || val.charAt(i) == "=" || val.charAt(i) == "+" || val.charAt(i) == "|" || val.charAt(i) == "?"  || val.charAt(i) == "\\" )
		{
			return false;
		}
	}
	return true;
}

// ***********************  Select CategoryList *****************************

function checkSCList(f)
{
if(f.categorylist.value=="0")
	{
		alert("Please select a \"Category\" .");
    	//f.categorylist.focus();
		return false;
	}
 return true;
}

// ***********************  Select SubCategoryList *****************************

function checkSSCList(f)
{
if(f.subcategorylist.value=="0")
	{
		alert("Please select a \"Sub Category\" .");
    	f.subcategorylist.focus();
		return false;
	}
return true;
}


// *************************** Product code/Part No **********************************************

function checkPCode(f)
{

var productcode=f.productcode.value;
	 if(productcode=="")
	    {
	   alert("Product Code should not be Blank.");
	   f.productcode.select();
	   return false;
	     }
	   if(productcode.substring(0,1)==" ")

	      	{
	      		alert("Product Code can not start with Blank Space.");
	      		f.productcode.select();
	      		return false;
	  	   }
	if(!validchar(productcode))
	{

	           alert("Enter valid characters in Product Code");
	           f.productcode.select();
	           return false;

	   }


	  if(productcode.length<3)
	      	{
	      		alert("Please enter a \"Product Code \" with minimum 3 characters.");
	      		f.productcode.select();
	      		return false;

                }
     return true;
  }

  // *************************** Product Name **********************************************
  function checkPName(f)
  {
 var pn=f.productname.value;
  	 if(pn=="")
  	    {
  	   alert("Product Name should not be Blank.");
  	   f.productname.select();
  	   return false;
  	    }
  	 if(pn.substring(0,1)==" ")
  	      	{
  	      		alert("Product Name can not start with Blank Space or Digits.");
  	      		f.productname.select();
  	      		return false;
  	  	     }

  	 if(!validchar(pn))
  	                 {

  	 	           alert("Enter valid characters in Product Name. ");
  	 	          f.productname.select();
  	 	           return false;
  	 	              }


  	 if(pn.length<3)
  	      	    {
  	      		alert("Please enter a \"Product Name \" with minimum 3 characters.");
  	      		f.productname.select();
  	      		return false;
      	         }
    return true;
}


// *************************** Manufacturer **********************************************

function checkManuf(f)
{
 var mf=f.manufacturer.value;
	 if(mf=="")
	     {
	   alert("Manufacturer Name should not be Blank.");
	   f.manufacturer.select();
	   return false;
	      }
	 if(mf.substring(0,1)==" ")
	      	{
	      		alert("Manufacturer Name can not start with Blank Space.");
	      		f.manufacturer.select();
	      		return false;
	  	    }



	 if(mf.length<3)
	      	 {
	      		alert("Please enter a \"Manufacturer Name \" with minimum 3 characters.");
	      		f.manufacturer.select();
	      		return false;
      	     }
 return true;
}
//****************************** Counter for description **********************

var chk=true;
function checkChar(txt,f,max)
{
 var i=txt.value.length;
        if(i>=0)
        {
       f.count.value=max-i;
       	}

       	if(f.count.value<0 && chk==true)
          {
			 // alert(f.name);
	         if(f.name=="productform")
                 alert("Product Description sholuld not exceed "+max+" charcters");
             else if(f.name=="addcat")
                 alert("Category Description sholuld not exceed "+max+" charcters");
             else if(f.name=="subcategoryform")
                 alert("Subcategory Description sholuld not exceed "+max+" charcters");
             else if(f.name=="addgroup")
                 alert("Group Description sholuld not exceed "+max+" charcters");
             else if(f.name=="modgroup")
                 alert("Group Description sholuld not exceed "+max+" charcters");
             chk=false;    
             return false;
          }
       if(f.count.value>=0)
         chk=true;
         
   

}



// *************************** Upload Small Image  **********************************************

function checkSImage(f)
{
var img=f.simage.value;

  var ext=img.substr(img.lastIndexOf("."));
    if(ext!="" && ext.toLowerCase()!=".gif" && ext.toLowerCase()!=".jpg" && ext.toLowerCase()!=".jpeg")
       {
       		      alert("Please upload Small Image with extensions .jpg or .gif or .jpeg");
       		     f.simage.select();
       		      return false;
   	   }
 return true;

}

// *************************** Upload Big Image  **********************************************

function checkBImage(f)
{
var img=f.bimage.value;
  var ext=img.substr(img.lastIndexOf("."));
    if(ext!="" && ext.toLowerCase()!=".gif" && ext.toLowerCase()!=".jpg" && ext.toLowerCase()!=".jpeg")
       {
       		      alert("Please upload Big Image with extensions .jpg or .gif or .jpeg");
       		      f.bimage.select();
       		      return false;
   	   }
 return true;

}

// *************************** Upload Specification **********************************************

function checkSpecs(f)
{
var manual=f.manual.value;
  var ext=manual.substr(manual.lastIndexOf("."));
     if(ext!="" && ext.toLowerCase()!=".txt" && ext.toLowerCase()!=".pdf" && ext.toLowerCase()!=".xls" && ext.toLowerCase()!=".doc")
	{
		      alert("Please upload file with extensions .txt or .doc or .pdf or .xls ");
		      f.manual.select();
		      return false;
   	}
 return true;

}

// *************************** Category Name **********************************************

function checkCName(f)
{

var catname=f.categoryname.value;
    if(catname=="")
     {
      alert(" Category Name should not be Blank.");
      f.categoryname.select();
      return false;
      }
      if(catname.substring(0,1)==" "|| !isNaN(catname.substring(0,1)))
         	{
         		alert("Category Name cannot start with Blank Space or Digits.");
         		f.categoryname.select();
         		return false;
     	}



     if(document.addcat.categoryname.value.length<3)
         	{
         		alert("Please enter a \"Category Name\" with minimum 3 characters.");
         		f.categoryname.select();
         		return false;
      	}

     if(!validchar(catname))
	{

	           alert("Enter valid characters in Category Name");
	           f.categoryname.select();
	           return false;

	   }
return true;


 }



//***************************  Description of Category**********************************************

function checkCDesc(f)
{

	var desc=f.categorydesc.value;
	
 if(desc.length>250)
         {
          alert("Category Description sholuld not exceed 250 charcters");
          f.categorydesc.select();
          return false;
         }
   return true;
}
//***************************  Description of Subcategory *********************************************

function checkSCDesc(f)
{

	var desc=f.subcategorydesc.value;
 if(desc.length>250)
          {
          alert("Subcategory Description sholuld not exceed 250 charcters");
          f.subcategorydesc.select();
          return false;
	       }
return true;

}
//***************************  Description of Product **********************************************

function checkPDesc(f)
{

	var desc=f.productdesc.value;
 if(desc.length>250)
          {
          alert("Product Description sholuld not exceed 250 charcters");
          f.productdesc.select();
          return false;
	       }
return true;

}

// *************************** SubCategory Name **********************************************


function checkSCName(f)
{
	 var SCName=f.subcategoryname.value;

	 if(SCName=="")
	  {
	   alert("Subcategory Name should not be Blank.");
	   f.subcategoryname.select();
	   return false;
	   }
	if(SCName.substring(0,1)==" "|| !isNaN(SCName.substring(0,1)))
	      	{
	      		alert("Subcategoryname  cannot start with Blank Space or Digits.");
	      		f.subcategoryname.select();
	      		return false;
	  	}



	if(SCName.length<3)
	      	{
	      	alert("Please enter a \"Subcategory Name \" with minimum 3 characters.");
	      	f.subcategoryname.select();
	      	return false;
      	    }



     if(!validchar(SCName))
	        {

	           alert("Enter valid characters in SubCategory Name");
	           f.subcategoryname.select();
	           return false;

	   }
	return true;
}


// *******************  Checking Log In Id **********************************

function checkLoginId(f)
{
	var loginId=f.loginid.value;

if(loginId=="")
	   {
		alert("Login Id should not be Blank.");
		f.loginid.select();
		return false;
	   }
if(loginId.substring(0,1)==" "|| !isNaN(loginId.substring(0,1)))
	      	{
	      		alert("Login Id can not start with Blank Space or Digits.");
	      		f.loginid.select();
	      		return false;
	  	   }

if(!check4Name(loginId))
	{
		alert("Login Id should not have invalid characters");
		f.loginid.select();
		return false;
	}

return true;
}

//******************* Checking Password ******************************************

function checkPwd(f)
{
var pwd=f.pwd.value;
if(pwd=="")
	{
		alert("Password should not be Blank.");
		f.pwd.select();
		return false;
	}
if(pwd.length<3)
	{
		alert("Password should be atleast 3 characters");
		f.pwd.select();
		return false;
	}
return true;
}

//******************* Checking  Old Password ******************************************

function checkOldPwd(f)
{
var pwd=f.oldpwd.value;
if(pwd=="")
	{
		alert("Old Password should not be Blank.");
		f.oldpwd.select();
		return false;
	}
if(pwd.length<3)
	{
		alert("Old Password should be atleast 3 characters");
		f.oldpwd.select();
		return false;
	}
return true;
}
//*****************Confirm Password************************************************

function checkCPwd(f)
{
var pwd=f.pwd.value;
var CPwd=f.pwd_chk.value;
if(CPwd.value=="")
	{
		alert("Please confirm your password");
		f.pwd_chk.select();
		return false;
	}
if(pwd!=CPwd)
	{
		alert("Password Mismatch!");
		f.pwd_chk.select();
		return false;
	}
return true;

}

//******************* Checking E Mail Id ********************************************

function checkEmail(f)
{
	var email=f.email.value;
        var l=email.length;
var ch;
 // alert(l); 
  for(var i=0;i<l;i++)
   {
    ch=email.charAt(i);
    if(ch==" ")
   {
    alert("E-Mail should not contain any space");
    f.email.focus();
    return false;
   }
  }
     
        var posat=email.indexOf("@");
		var lposat=email.lastIndexOf("@");
		var posdot=email.indexOf(".");
		var lposdot=email.lastIndexOf(".");

		if(email == "")
		{

			alert("Email should not be Blank. ");
			f.email.focus();
			f.email.select();
			return(false);
		}
		if (posat == -1)
		{
			alert("Invalid email address entered.");
			f.email.focus();
			f.email.select();
			return(false);
		}
		if(posat == 0)
		{
			alert("Invalid email entered : Email address cannot start with @ ");
			f.email.focus();
			f.email.select();
			return(false);
		}
		if(posat != lposat)
		{
			alert("Invalid email entered : Email address cannot have multiple @ ");
			f.email.focus();
			f.email.select();
			return(false);
		}

		if (posdot == -1)
		{
			alert("Invalid email address entered.");
			f.email.focus();
			f.email.select();
			return(false);
		}
		if (posdot == 0)
		{
			alert("Invalid email entered : Email address cannot start with . ");
			f.email.focus();
			f.email.select();
			return(false);
		}
		if(lposdot-lposat < 3)
		{
			alert("Invalid email address entered.");
			f.email.focus();
			f.email.select();
			return false;
		}

		if(lposdot == email.length-1)
		{
			alert("Email address cannot end with a . ")
			f.email.focus();
			f.email.select();
			return false;
		}

		if (!validchar1(email))
		{
			alert("Please do not enter special characters or Blank Space in Email.");
			f.email.focus();
			f.email.select();
			return false;
		}
return true;
}


// **************** checking  to allow a-z,0-9," " ********************************

function check4Name(str)
{

	for( var i=0;i<str.length;i++)
	    {
	      var ch=str.charAt(i);
	    if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z")|| (ch==" ") || (ch>="0" && ch<="9")))

	     return false;
         }
  return true;
}

// ****************** checking Salutation ********************************************

function checkSal(f)
{
// alert('test');
 var l = f.salutation.length;
 //alert(l);
 var s = 0;
	for(i=0;i<l;i++)
	{
		if(f.salutation[i].checked==true)
		{
			s=1;
			break;
		}
	}
	//alert(s);
	if(s==0)
	{
		alert("Please select Salutation.");
		return false;
	}
return true;
}

// ****************  checking Name *********************************************************


function checkName(f)
{
var name=f.name.value;
if(name=="")
	   {
		alert("Name should not be Blank.");
		f.name.select();
		return false;
	   }
if(name.substring(0,1)==" "|| !isNaN(name.substring(0,1)))
	      	{
	      		alert("Name cannot start with Blank Space or Digits.");
	      		f.name.select();
	      		return false;
	  	   }
if(name.length<3)
	      	 {
	      		alert("Please enter a \" Name \" with minimum 3 characters.");
	      		f.name.select();
	      		return false;
      	     }

for( var i=0;i<name.length;i++)
  {
      var ch=name.charAt(i);
      if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z")|| (ch==" ")))
        {
         alert("Enter valid characters in Name");
         f.name.select();
         return false;
        }

   }

return true;
}

// ******************** checking Company Name ********************************

function checkCompName(f)
{
var name=f.company.value;
if(name=="")
	   {
		alert("Company Name should not be Blank.");
		f.company.select();
		return false;
	   }
if(name.substring(0,1)==" ")
	      	{
	      		alert("Company Name cannot start with Blank Space ");
	      		f.company.select();
	      		return false;
	  	   }
if(name.length<3)
	      	 {
	      		alert("Please enter a \" Company Name \" with minimum 3 characters.");
	      		f.company.select();
	      		return false;
      	     }

for( var i=0;i<name.length;i++)
  {
      var ch=name.charAt(i);
       if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z") || (ch>=0 && ch<=9) || ch==" "|| ch=="."||ch=="-"||ch=="("||ch==")"|| ch=="&" || ch=="," || ch==":"))
          {
         alert("Enter valid characters in Company Name");
         f.company.select();
         return false;
        }

   }

return true;
}

// ******************* chechking Address *****************************************************

function checkAddress(f)
{
	var addr=f.address1.value;
 if(addr=="")
	{
		alert("Please enter Address.");
		f.address1.select();
		return false;
	}
return true;
}
// ************************** checking City ***************************************************

function checkCity(f)
{
var city=f.city.value;

if(city!=""){
if(city.substring(0,1)==" "|| !isNaN(city.substring(0,1)))
	      	{
	      		alert("City Name cannot start with Blank Space or Digits.");
	      		f.city.select();
	      		return false;
	  	    }
if(city.length<3)
	      	 {
	      		alert("Please enter a \" City Name \" with minimum 3 characters.");
	      		f.city.select();
	      		return false;
      	     }
for( var i=0;i<city.length;i++)
  {
      var ch=city.charAt(i);
       if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z") || ch==" "))
          {
         alert("Enter valid characters in City Name");
         f.city.select();
         return false;
          }

   }
}
  return true;
}

// *************************** Checking State ****************************************************

function checkState(f)
{
var state=f.state.value;
if(state!="")
{
 if(state.substring(0,1)==" "|| !isNaN(state.substring(0,1)))
	      	{
	      		alert("State Name cannot start with Blank Space or Digits.");
	      		f.state.select();
	      		return false;
	  	    }
if(state.length<2)
	      	 {
	      		alert("Please enter a \" State Name \" with minimum 2 characters.");
	      		f.state.select();
	      		return false;
      	     }
if(!(state==""))
	  {
	  if(!(isNaN(state)))
	  	    {
	  	  alert("Digits are not allowed in State.");
	  	  f.state.select();
	  	  return false;
	         }
	 }
}
return true;
}

//**************************** Checking Country ************************************

function checkCountry(f)
{
	var country=f.country.value;
  if(country=="0")
	{
		alert("Please select Country.");
		f.country.focus();
		return false;
	}
return true;
}

// ************************* checking Zipcode ****************************************

function checkZip(f)
{
	var zipcode=f.zipcode.value;

   for( var i=0;i<zipcode.length;i++)
	    {
	      var ch=zipcode.charAt(i);
	    if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z")|| (ch==" ") || (ch>="0" && ch<="9")|| ch=="-" || ch=="(" || ch==")"))
	    {
			alert("Please enter valid Zipcode.");
            f.zipcode.select();
	       return false;
	      }
         }
 return true;
}

//********************* checking Phonecc **************************************************

function checkPhCC(f)
{
var phonecc=f.phonecc.value;
 if(phonecc=="")
	  {
		alert("Phone field should not be empty.");
		f.phonecc.focus();
		return false;
	  }

 for( var i=0;i<phonecc.length;i++)
	  {
           var ch=phonecc.charAt(i);
	       if(ch!="(" && isNaN(ch) && ch!=")" && ch!="-" && ch!="+")
                     {
				    alert("Enter enter valid Country code in Phone No.");
				    f.phonecc.select();
				    return false;
				     }

      }
   return true;
}


//********************* checking Phoneac **************************************************


function checkPhAC(f)
{
var phoneac=f.phoneac.value;
if(isNaN(phoneac))
	{
		    alert("Please enter valid Area Code in Phone No");
			f.phoneac.focus();
			return false;
	}

return true;

}

//********************* checking Phoneno **************************************************

function checkPhNo(f)
{
var phoneno=f.phoneno.value;

if(phoneno=="")
	{
		alert("Phone field should not be empty.");
		f.phoneno.focus();
		return false;
	}

for( var i=0;i<phoneno.length;i++)
	  {
           var ch=phoneno.charAt(i);
	       if(ch!="(" && isNaN(ch) && ch!=")" && ch!="-" && ch!="/")
                     {
				    alert("Enter enter valid Phone No.");
				    f.phoneno.select();
				    return false;
				     }

      }
return true;
}

//********************* checking Mobile No *************************************************

function checkMob(f)
{
var str=f.mobileno.value;
for( var i=0;i<str.length;i++)
  {
  var ch=str.charAt(i);
  if(ch!="+" && isNaN(ch) && ch!="-" && ch!="(" && ch!=")" && ch!="/")
	   {
	  alert("Enter valid Mobile no.");
	  f.mobileno.select();
	  return false;
	    }

    }
 return true;
}

//********************* checking Faxcc **************************************************

function checkFaxCC(f)
{
var faxcc=f.faxcc.value;


 for( var i=0;i<faxcc.length;i++)
	  {
           var ch=faxcc.charAt(i);
	       if(ch!="(" && isNaN(ch) && ch!=")" && ch!="-" && ch!="+")
                     {
				    alert("Enter valid Country code in Fax No.");
				    f.faxcc.select();
				    return false;
				     }

      }
   return true;
}


//********************* checking Faxac **************************************************


function checkFaxAC(f)
{
var faxac=f.faxac.value;
if(faxac!="")
{
if(isNaN(faxac))
	{
		    alert("Please enter valid Area Code in Fax No.");
			f.faxac.focus();
			return false;
	}
}
return true;

}

//********************* checking Faxno **************************************************

function checkFaxNo(f)
{
var faxno=f.faxno.value;

if(faxno!="")
{
for( var i=0;i<faxno.length;i++)
	  {
           var ch=faxno.charAt(i);
	       if(ch!="(" && isNaN(ch) && ch!=")" && ch!="-" && ch!="/")
                     {
				    alert("Enter enter valid Fax No.");
				    f.faxno.select();
				    return false;
				     }

      }

}
return true;
}




// ******************** Counter for admin remarks in Customer Management ************************
var chk1=true;
function checkAdminRmk(txt,f,max)
    {
     var i=txt.value.length;

     f.count1.value=max-i;
     if(f.count1.value<0 && chk1==true)
          {
         alert("Admin Remarks sholuld not exceed 250 charcters");
         f.adminremarks.select();
         chk1=false;
         return false;
          }
       if(f.count1.value>=0)
        chk1=true;
    return true;
    }
 //************** Admin Remarks not more than 250 **************************
 function checkARmk(f)
 {
   var desc=f.adminremarks.value;
 if(desc.length>250)
         {
          alert("Admin Remarks sholuld not exceed 250 charcters");
          f.adminremarks.select();
          return false;
         }
   return true;
}

// ******************** Counter for Customer remarks in Customer Management ************************
var chk2=true;
function checkCustRmk(txt,f,max)
    {
     var i=txt.value.length;
     f.count.value=max-i;
     if(f.count.value<0 && chk2==true)
          {
          alert("Customer Remarks sholuld not exceed 250 charcters");
		  f.remarks.select();
      chk2=false;
          return false;
          }
      if(f.count.value>=0)
        chk2=true;    
          
    return true;
    }
  //************** Admin Remarks not more than 250 **************************
 function checkCRmk(f)
 {
   var desc=f.remarks.value;
 if(desc.length>250)
         {
          alert("Customer Remarks sholuld not exceed 250 charcters");
          f.remarks.select();
          return false;
         }
   return true;
}

//****************** checking Department ***********************

function checkDept(f)
{
var dept=f.department.value;
if(dept=="")
	{
		alert("Department cannot be Blank.");
		f.department.focus();
		return false;
	}
if(dept.substring(0,1)==" " || !isNaN(dept.substring(0,1)))
	         	{
	         		alert("Department Name cannot start with Blank Space or Digits.");
	         		f.department.select();
	         		return false;
     	        }
	if(!validchar1(dept))
	{
		alert("Invalid characters entered in Department.");
		f.department.select();
		return false;
	}

return true;
}


// ********************* checking Designation *************************
function checkDesg(f)
{
var desg=f.designation.value;
if(desg!="")
{
if(desg.substring(0,1)==" " || !isNaN(desg.substring(0,1)))
	         	{
	         		alert("Designation  cannot start with Blank Space or Digits.");
	         		f.designation.select();
	         		return false;
				}
     for( var i=0;i<desg.length;i++)
	    {
	      var ch=desg.charAt(i);
	    if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z")|| (ch==" ") || (ch>="0" && ch<="9")|| ch=="-" || ch=="+" || ch=="(" || ch==")" || ch=="&") || ch==".")
	       {
			alert("Invalid characters entered in Department.");
		    f.designation.select();
	       return false;
	        }
	   }
  }//if desg
return true;
}

// *********************** Checking Acessrights ***********************************

function checkAcsRgt(f)
{

          if(f.product.checked!=true && f.dealer.checked!=true && f.newarrival.checked!=true && f.mail1.checked!=true && f.poll.checked!=true)
             {
             alert("Please select  atleast one Management Module in Access Rights ");
             return false;
             }
    return true;
}

// ******************** Counter for Mail Body************************
var chk3=true;
function checkMBody(txt,f,max)
    {
     var i=txt.value.length;

     f.count.value=max-i;
     if(f.count.value<0 && chk3==true)
          {
         alert("Mail Body sholuld not exceed 7000 charcters");
         f.messagebody.select();
         chk3=false;
         return false;
          }
      if(f.count.value>=0)
        chk3=true;    
    return true;
    }
 //************** Mail Body not more than 7000 **************************
 function checkMBodyMax(f)
 {
   var desc=f.messagebody.value;
 if(desc.length>7000)
         {
           alert("Mail Body sholuld not exceed 7000 charcters");
          f.messagebody.select();
          return false;
         }
   return true;
}

// ******************** Counter for Mail Footer ************************
var chk4=true;
function checkMFooter(txt,f,max)
    {
     var i=txt.value.length;
     f.count1.value=max-i;
     if(f.count1.value<0 && chk4==true)
          {
          alert("Mail Footer sholuld not exceed 1000 charcters.");
		  f.footer.select();
		  chk4=false;
          return false;
          }
         if(f.count1.value>=0)
        chk4=true;    
    return true;
    }
  //************** Mail Footer Remarks not more than 1000 **************************
 function checkMFooterMax(f)
 {
   var desc=f.footer.value;
 if(desc.length>1000)
         {
          alert("Mail Footer sholuld not exceed 1000 charcters.");
          f.footer.select();
          return false;
         }
   return true;
}

// ******************** Counter for Mail Purpose ************************
var chk5=true;
function checkMPurpose(txt,f,max)
    {
     var i=txt.value.length;
     f.count2.value=max-i;
     if(f.count2.value<0 && chk5==true)
          {
          alert("Mail Pupose sholuld not exceed 250 charcters.");
		  f.purpose.select();
		  chk5=false;
          return false;
          }
        if(f.count2.value>=0)
        chk5=true;     
    return true;
    }
  //************** Mail purpose Remarks not more than 250 **************************
 function checkMPurposeMax(f)
 {
   var desc=f.purpose.value;
 if(desc.length>250)
         {
          alert("Mail Purpose sholuld not exceed 250 charcters.");
          f.purpose.select();
          return false;
         }
   return true;
}

// ***********************  Mail subject ********************************

function checkMSubject(f)
{
	if(f.subject.value=="")
		{
			alert("Please enter \"Subject\" ");
			f.subject.focus();
			return false;
		}
		if (f.subject.value.length < 3)
		{
			alert("Please enter a \"Subject\" with minimum 3 characters.");
			f.subject.focus();
			f.subject.select();
			return (false);
		}
		if (f.subject.value.substring(0,1)==" ")
		{
			alert("Subject cannot start with blank space.");
			f.subject.focus();
			f.subject.select();
			return (false);
		}
		/*if (!isNaN(f.subject.value))
		{
			alert("Subject cannot be only digits.");
			f.subject.focus();
			f.subject.select();
			return (false);
		}*/
return true;
}

// **********************   Message Body *********************************

function checkMsgBody(f)
{
if(f.messagebody.value=="")
	{
		alert("Please enter \"Message Body\" ");
		f.messagebody.focus();
		return false;
	}
	if (f.messagebody.value.length < 3)
	{
		alert("Please enter a \"Message Body\" with minimum 3 characters.");
		f.messagebody.focus();
		f.messagebody.select();
		return (false);
	}
return true;
}

//**************************  Email checking for sendfrom ***********************

function checkEmailSF(f)
{
var str=f.sendfrom.value
//alert(str);
 var l=str.length;
var ch;
 // alert(l); 
  for(var i=0;i<l;i++)
   {
    ch=str.charAt(i);
    if(ch==" ")
   {
    alert("E-Mail should not contain any space");
    f.sendfrom.focus();
    return false;
   }
  }
	var posat=str.indexOf("@");
	var lposat=str.lastIndexOf("@");
	var posdot=str.indexOf(".");
	var lposdot=str.lastIndexOf(".");

	if(f.sendfrom.value == "")
	{
		alert("Blank Email: Please Enter Valid Email ");
		f.sendfrom.focus();
		f.sendfrom.select();
		return(false);
	}
	if (posat == -1)
	{
		alert("Invalid email address entered.");
		f.sendfrom.focus();
		f.sendfrom.select();
		return(false);
	}
	if(posat == 0)
	{
		alert("Invalid email entered : Email address cannot start with @ ");
		f.sendfrom.focus();
		f.sendfrom.select();
		return(false);
	}
	if(posat != lposat)
	{
		alert("Invalid email entered : Email address cannot have multiple @ ");
		f.sendfrom.focus();
		f.sendfrom.select();
		return(false);
	}

	if (posdot == -1)
	{
		alert("Invalid email address entered.");
		f.sendfrom.focus();
		f.sendfrom.select();
		return(false);
	}
	if (posdot == 0)
	{
		alert("Invalid email entered : Email address cannot start with . ");
		f.sendfrom.focus();
		f.sendfrom.select();
		return(false);
	}
	if((posdot < posat) || (posdot-posat < 3))
	{
		alert("Invalid email address entered.");
		f.sendfrom.focus();
		f.sendfrom.select();
		return false;
	}

	if(lposdot == str.length-1)
	{
		alert("Email address cannot end with a . ")
		f.sendfrom.focus();
		f.sendfrom.select();
		return false;
	}

	if (!validchar1(str))
	{
		//alert("Invalid email address entered.");
		alert("Invalid characters entered in the from fields.");
		f.sendfrom.focus();
		f.sendfrom.select();
		return false;
	}
return true;
}

// *****************************  check Mail 4 preview to *****************************

function checkEmailPT(f)
{


var str=f.previewto.value;
 var l=str.length;
var ch;
 // alert(l); 
  for(var i=0;i<l;i++)
   {
    ch=str.charAt(i);
    if(ch==" ")
   {
    alert("E-Mail should not contain any space");
    return false;
   }
  }

		var posat=str.indexOf("@");
		var lposat=str.lastIndexOf("@");
		var posdot=str.indexOf(".");
		var lposdot=str.lastIndexOf(".");

		if(f.previewto.value =="")
		{
			alert("Blank Email: Please Enter Valid Email ");
			f.previewto.focus();
			f.previewto.select();
			return(false);
		}
		if (posat == -1)
		{
			alert("Invalid email address entered.");
			f.previewto.focus();
			f.previewto.select();
			return(false);
		}
		if(posat == 0)
		{
			alert("Invalid email entered : Email address cannot start with @ ");
			f.previewto.focus();
			f.previewto.select();
			return(false);
		}
		if(posat != lposat)
		{
			alert("Invalid email entered : Email address cannot have multiple @ ");
			f.previewto.focus();
			f.previewto.select();
			return(false);
		}

		if (posdot == -1)
		{
			alert("Invalid email address entered.");
			f.previewto.focus();
			f.previewto.select();
			return(false);
		}
		if (posdot == 0)
		{
			alert("Invalid email entered : Email address cannot start with . ");
			f.previewto.focus();
			f.previewto.select();
			return(false);
		}
		if((posdot < posat) || (posdot-posat < 3))
		{
			alert("Invalid email address entered.");
			f.previewto.focus();
			f.previewto.select();
			return false;
		}

		if(lposdot == str.length-1)
		{
			alert("Email address cannot end with a . ")
			f.previewto.focus();
			f.previewto.select();
			return false;
		}

		if (!validchar1(str))
		{
			alert("Invalid email address entered.");
			alert("Invalid characters entered in the \"Preview To\" fields..");
			f.previewto.focus();
			f.previewto.select();
			return false;
		}

return true;

 }

 // ****************** checking opinion poll answer ********************************************

 function checkOpinion(f)
 {

 var l = f.opinion.length;
 //alert(l);
 var s = 0;
	for(i=0;i<l;i++)
	{
		if(f.opinion[i].checked==true)
		{
			s=1;
			break;
		}
	}
	//alert(s);
	if(s==0)
	{
		alert("Choose Your option before proceed.");
		return false;
	}
return true;
}

// **************************  check remarks for FRONT (Contact Us form )****************************

 function checkRmk(f)
 {
   var desc=f.remarks.value;
   if(desc=="")
     {
     alert("Please give your valuable remarks.");
      f.remarks.select();
      return false;
     }
 if(desc.length>250)
         {
          alert("Customer Remarks sholuld not exceed 250 charcters");
          f.remarks.select();
          return false;
         }
   return true;
}
//********************* checking Phoneno **************************************************

function checkCPhNo(f)
{
var phoneno=f.phoneno.value;

for( var i=0;i<phoneno.length;i++)
	  {
           var ch=phoneno.charAt(i);
	       if(ch!="(" && isNaN(ch) && ch!=")" && ch!="-" && ch!="/")
                     {
				    alert("Enter enter valid Phone No.");
				    f.phonecc.select();
				    return false;
				     }

      }
return true;
}

// *************************** Customer Group Name **********************************************

function checkGName(f)
{

var groupname=f.name.value;
    if(groupname=="")
     {
      alert(" Group Name should not be Blank.");
      f.name.select();
      return false;
      }
      if(groupname.substring(0,1)==" "|| !isNaN(groupname.substring(0,1)))
         	{
         		alert("Group Name cannot start with Blank Space or Digits.");
         		f.name.select();
         		return false;
     	}



     if(groupname.length<3)
         	{
         		alert("Please enter a \"Group Name\" with minimum 3 characters.");
         		f.name.select();
         		return false;
      	}

     if(!validchar(groupname))
	{

	           alert("Enter valid characters in Group Name");
	           f.name.select();
	           return false;

	   }
return true;


 }



//*************************** Customer Group  Description **********************************************

function checkGDesc(f)
{

	var desc=f.desc.value;
 if(desc.length>250)
         {
          alert("Group Description sholuld not exceed 250 charcters");
          f.desc.select();
          return false;
         }
   return true;
}
//***************************** remarks counter for front********************************
var chkRemrks=true;
function checkRemarks(txt,f,max)
{
 var i=txt.value.length;
        if(i>=0)
        {
       f.count.value=max-i;
       	}

       	if(f.count.value<0 && chkRemrks==true)
          {
		
            alert("Remarks sholuld not exceed "+max+" charcters");
             chkRemrks=false;    
             return false;
          }
       if(f.count.value>=0)
         chkRemrks=true;
         
   

}

//**************************** remarks not exceeding 250 **********************
function checkRemarksLimit(f)
{
var rmk=f.remarks.value;

if(rmk.length>250)
         {
          alert("Remarks sholuld not exceed 250 charcters");
          f.remarks.select();
          return false;
         }
   return true;
}
