// 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) == "\\" )
		{
			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("Special characters not allowed 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("Special characters not allowed 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;
}

// **************************** Product Description **********************************************

function checkProductdesc(f)
{
    var desc=f.productdesc.value;
    if(desc.length<3)
     {
        alert("Please enter Product Description of minimum 3 characters.");
        f.productdesc.select();
        return false;
     }
    if(desc.charAt(0)==" ")
     {
        alert("Product Description can not start with blank.");
        f.productdesc.select();
        return false;
     }
    if(desc.length>250)
    {
        alert("Product Description sholuld not exceed 250 charcters");
        f.productdesc.select();
        return false;
    }
return true;
}
// **************************** News Subject **********************************************

function checkSubject(f)
{
    var subval=f.value;
    if(subval==""  || subval.length<3)
    {
        alert("Please enter Subject of minimum 3 characters.");
        f.focus();
        return false;
    }
    if(subval.charAt(0)==" ")
    {
        alert("Subject value can not start with blank.");
        f.focus();
        f.select();
        return false;
    }
    if(subval.length>60)
    {
        alert("News Subject should not exceed 60 characters.");
        f.select();
        return false;
    }
return true;
}

// *************************** News Body **********************************************

function checkBody(f)
{
    var bodyval=f.value;
    if(bodyval=="" || bodyval.length<3)
    {
        alert("Please enter News Body of minimum 3 characters.");
        f.focus();
        return false;
    }
    if(bodyval.charAt(0)==" ")
    {
        alert("News Body value can not start with blank.");
        f.focus();
        f.select();
        return false;
    }

    if(bodyval.length>700)
    {
        alert("News Body should not exceed 700 characters.");
        f.select();
        return false;
    }
return true;
}

// **************************** News Subject **********************************************

function checkmodSub(f)
{
    var subval=f.value;
    if(subval==""  || subval.length<3)
    {
        alert("Please enter Subject of minimum 3 characters.");
        f.focus();
        return false;
    }
    if(subval.charAt(0)==" ")
    {
        alert("Subject value can not start with blank.");
        f.focus();
        f.select();
        return false;
    }
    if(subval.length>60)
    {
        alert("News Subject should not exceed 60 characters.");
        f.select();
        return false;
    }
return true;
}

// *************************** News Body **********************************************

function checkmodBody(f)
{
    var bodyval=f.value;
    if(bodyval=="" || bodyval.length<3)
    {
        alert("Please enter News Body of minimum 3 characters.");
        f.focus();
        return false;
    }
    if(bodyval.charAt(0)==" ")
    {
        alert("News Body value can not start with blank.");
        f.focus();
        f.select();
        return false;
    }

    if(bodyval.length>700)
    {
        alert("News Body should not exceed 700 characters.");
        f.select();
        return false;
    }
return true;
}

//  **********************Check Remarks of Customer **************************

function checkRemarks(f)
{
   var remarks=f.remarks.value;
   if(remarks!="")
   {
        if(remarks.length<3)
         {
            alert("Please enter Customer Remarks of minimum 3 characters.");
            f.remarks.select();
            return false;
         }
        if(remarks.charAt(0)==" ")
         {
            alert("Customer Remarks can not start with blank.");
            f.remarks.select();
            return false;
         }
        if(remarks.length>250)
        {
            alert("Customer Remarks should not exceed 250 charcters");
            f.remarks.select();
            return false;
        }
  }
return true;
}

//  **********************Check Remarks of Admin **************************

function checkAdminRem(f)
{
   var remarks=f.adminremarks.value;
   if(remarks!="")
   {
        if(remarks.length<3)
         {
            alert("Please enter Admin Remarks of minimum 3 characters.");
            f.adminremarks.select();
            return false;
         }
        if(remarks.charAt(0)==" ")
         {
            alert("Admin Remarks can not start with blank.");
            f.adminremarks.select();
            return false;
         }
        if(remarks.length>250)
        {
            alert("Admin Remarks should not exceed 250 charcters");
            f.adminremarks.select();
            return false;
        }
   }
return true;
}
// ******************* Check Date of game  ********************************

function checkGDate(f){

    if(f.date.value=="0"){
        alert("Please select Date.");
        f.date.focus();
        return false;
    }
    if(f.month.value=="0"){
        alert("Please select Month.");
        f.month.focus();
        return false;
    }
    if(f.year.value=="" || isNaN(f.year.value)){
        alert("Please enter Year.");
        f.year.select();
        return false;
    }
    return true;
}

	// *************************** Upload Pictures  **********************************************

	function checkMainPics(f)
	{
	var img=f.value;
	if(img=="")
	{
	alert('Please upload  Picture.');
	f.select();
	return false;
	}

	  var ext=img.substr(img.lastIndexOf("."));
	    if(ext!="" && ext.toLowerCase()!=".gif" && ext.toLowerCase()!=".jpg" && ext.toLowerCase()!=".jpeg")
	       {
			      alert("Please upload Picture with extensions .jpg or .gif or .jpeg");
			     f.select();
			      return false;
		   }
	 return true;

	}

	// *************************** Upload Pictures  **********************************************

	function checkPics(f)
	{
            var img=f.value;
           // if(img=="")
           // {
            //    alert('Please upload  Picture.');
            //    f.select();
            //    return false;
          //  }
            if(img!="")
            {
                var ext=img.substr(img.lastIndexOf("."));
                if(ext!="" && ext.toLowerCase()!=".gif" && ext.toLowerCase()!=".jpg" && ext.toLowerCase()!=".jpeg")
                {
                    alert("Please upload Picture with extensions .jpg or .gif or .jpeg");
                    f.select();
                    return false;
                }
            }
            return true;

	}

//****************************** Brand **********************

function checkBrand(f)
{

var br=f.brand.value;
if(!validchar1(br) && br!="")
{
alert("Please enter Valid characters in your Brand Name.");
f.brand.select();
return false;
}

if(br.substring(0,1)==" ")
{
	alert("Brand Name should not start with a blank space.");
	f.brand.select();
	return false;
}
return true;
}

// *************************** Date Code   *******************************************

function checkDateCode(f)
{
    var dc = f.dateCode.value;

}

// *************************** Quantity  *************************************************

function checkQuantity(f)
{
    if(isNaN(f.quantity.value))
    {
        alert("Enter valid number in 'Quantity in Stock' field.");
        f.quantity.select();
        return false;
    }
    return true;
}

// **************************** Unit   *************************************************

function checkUnit(f)
{

}

// *************************** 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 fst = true;
function checkChar(txt,f,max,msg)
{
 var i=txt.value.length;
        if(i>=0)
        {
       f.count.value=max-i;
       	}

       	if(f.count.value<0 && fst==true)
          {
             alert(msg);
             fst = false;
            return false;
          }
          if(f.count.value>=0){
            fst=true
          }
   return true;

}



// *************************** Upload Small Image  **********************************************

function checkSImage(f)
{
var img=f.simage.value;
//alert("Small Img");
if(img!="")
{
  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;
   	   }
}
else
{
return true;
}

 return true;

}

// *************************** Upload Big Image  **********************************************

function checkBImage(f)
{
//alert("Big Img");
var img=f.bimage.value;
if(img!="")
{
  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;
   	   }
}

else
{
return true;
}
 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;

}

// *************************** Ctegory Type *********************************************

function checkCType(f)
{

    if(f.cattype.value=="0")
    {
        alert("Please select a \"Category Type\"");
        f.cattype.focus();
        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(f.pwd_chk.value=="")
	{
		alert("Please confirm your password");
		f.pwd_chk.select();
		return false;
	}
if(pwd!=CPwd)
	{
		alert("Password Mismatch! Please enter correctly.");
		f.pwd_chk.select();
		return false;
	}
return true;

}

//******************* Checking E Mail Id ********************************************

function checkEmail(f)
{
	var email=f.email.value;
        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);
		}
                for(var i=0;i<email.length;i++)
                {
                    if(email.charAt(i)==" ")
                    {
                        alert("Email should not contain space.");
                        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 Phoneno **************************************************

function checkPhone(f)
{
var phoneno=f.phone.value;

     if(phoneno!="")
      {
	if(phoneno.substring(0,1)==" ")
        {
            alert("Phone No can not start with Blank Space.");
            f.phone.select();
            return false;
        }
        if(phoneno.length<3)
        {
            alert("Please enter  \"Phone No \" with minimum 3 characters.");
            f.phone.select();
            return false;
        }

            if(isNaN(phoneno))
            {
                alert("Invalid Phone Number entered.");
                f.phone.focus();
                f.phone.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==" ") || (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(f.company.value=="")
 {
	alert("Company Name should not be Blank.");
	f.company.select();
	return false;
 }
if(name!="")
{
if(name.charAt(0)==" ")
	      	{
	      		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=="," || 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;
	var addr1=f.address2.value;
 if(addr=="")
	{
		alert("Please enter Address.");
		f.address1.select();
		return false;
	}
if(!validchar1(addr))
{
		alert("Please enter Valid Address.");
		f.address1.select();
		return false;
}

if(!validchar1(addr1))
{
		alert("Please enter Valid Address.");
		f.address2.select();
		return false;
}

if(f.address1.value.substring(0,1)==" ")
{
		alert("Address cannot start with a blank space.");
		f.address1.select();
		return false;
}
if(f.address2.value.substring(0,1)==" ")
{
		alert("Address cannot start with a blank space.");
		f.address2.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==" " || ch=="/" || ch=="." || ch=="," || ch==";" || 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==""))
	  {
	  for(var i=0;i<state.length;i++)
	    {
	        var ch=state.charAt(i);
	         if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z") || ch==" " || ch=="/" || ch=="." || ch=="," || ch==";" || ch=="-"))
	            {
	           alert("Enter valid characters in State Name");
	           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;
   if(zipcode.charAt(0)==" "){
        alert("Zipcode can not start with a blank.");
        f.zipcode.select();
        return false;
   }
   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("Please enter a valid Country code in your Phone Field.");
		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("Please enter a valid Country code in your Phone Field.");
		    f.phonecc.select();
		    return false;
		     }
      }
   return true;
}


//********************* checking Phoneac **************************************************


function checkPhAC(f)
{
var phoneac=f.phoneac.value;
for( var i=0;i<phoneac.length;i++)
	  {
           var ch=phoneac.charAt(i);
	       if(ch!="(" && isNaN(ch) && ch!=")" && ch!="-" && ch!="/" && ch!="+")
                   {
		    alert("Please enter a valid Area Code in your Phone Field.");
	      	    f.phoneac.select();
		    return false;
		    }
	   }

return true;

}

//********************* checking Phoneno **************************************************

function checkPhNo(f)
{
var phoneno=f.phoneno.value;

if(phoneno=="" && f.phonecc.value!="")
	{
		alert("Please enter your Phone no.");
		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!="/" && ch!="+" && ch!="~" && ch!="x" && ch!="X")
                     {
				    alert("Please enter your valid Phone No.");
				    f.phoneno.select();
				    return false;
				     }

      }

      if(phoneno.length<3)
      {
       alert("Please enter your 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!="+" && ch!="-" && ch!="(" && ch!=")" && ch!="/" && ch!=" " && isNaN(ch))
	   {
	  alert("Please enter your valid Mobile no.");
	  f.mobileno.select();
	  return false;
	    }

    }
 return true;
}

//********************* checking Faxcc **************************************************

function checkFaxCC(f)
{
var faxcc=f.faxcc.value;
if(faxcc=="" && f.faxno.value!="")
	  {
		alert("Please enter a valid Country code in your Fax Field.");
		f.faxcc.select();
		return false;
	  }

 for( var i=0;i<faxcc.length;i++)
	  {
           var ch=faxcc.charAt(i);
	       if(ch!="(" && (ch.toLowerCase()=="a" || ch.toLowerCase()=="b" || ch.toLowerCase()=="c"|| ch.toLowerCase()=="d"|| ch.toLowerCase()=="e"|| ch.toLowerCase()=="f"|| ch.toLowerCase()=="g"|| ch.toLowerCase()=="h"|| ch.toLowerCase()=="i"|| ch.toLowerCase()=="j"|| ch.toLowerCase()=="k"|| ch.toLowerCase()=="l"|| ch.toLowerCase()=="m"|| ch.toLowerCase()=="n"|| ch.toLowerCase()=="o"|| ch.toLowerCase()=="p"|| ch.toLowerCase()=="q"|| ch.toLowerCase()=="r"|| ch.toLowerCase()=="s"|| ch.toLowerCase()=="t"|| ch.toLowerCase()=="u"|| ch.toLowerCase()=="v"|| ch.toLowerCase()=="w"|| ch.toLowerCase()=="x"|| ch.toLowerCase()=="y" || ch.toLowerCase()=="z") && ch!=")" && ch!="-" && ch!="+")
                     {
				    alert("Please enter a valid Country code in your Fax Field.");
				    f.faxcc.select();
				    return false;
				     }

      }
   return true;
}


//********************* checking Faxac **************************************************


function checkFaxAC(f)
{
var faxac=f.faxac.value;
if(faxac!="")
{

for( var i=0;i<faxac.length;i++)
	  {
           var ch=faxac.charAt(i);
if(ch!="(" && (ch.toLowerCase()=="a" || ch.toLowerCase()=="b" || ch.toLowerCase()=="c"|| ch.toLowerCase()=="d"|| ch.toLowerCase()=="e"|| ch.toLowerCase()=="f"|| ch.toLowerCase()=="g"|| ch.toLowerCase()=="h"|| ch.toLowerCase()=="i"|| ch.toLowerCase()=="j"|| ch.toLowerCase()=="k"|| ch.toLowerCase()=="l"|| ch.toLowerCase()=="m"|| ch.toLowerCase()=="n"|| ch.toLowerCase()=="o"|| ch.toLowerCase()=="p"|| ch.toLowerCase()=="q"|| ch.toLowerCase()=="r"|| ch.toLowerCase()=="s"|| ch.toLowerCase()=="t"|| ch.toLowerCase()=="u"|| ch.toLowerCase()=="v"|| ch.toLowerCase()=="w"|| ch.toLowerCase()=="x"|| ch.toLowerCase()=="y" || ch.toLowerCase()=="z") && ch!=")" && ch!="-" && ch!="+")
		{
		    alert("Please enter a valid Area Code in your Fax Field.");
		    f.faxac.select();
		    return false;
		}
	}
}
return true;

}

//********************* checking Faxno **************************************************

function checkFaxNo(f)
{
var faxno=f.faxno.value;
if(faxno=="" && f.faxcc.value!="")
	{
		alert("Please enter your Fax no.");
		f.faxno.focus();
		return false;
	}
if(faxno!="")
{
for( var i=0;i<faxno.length;i++)
	  {
           var ch=faxno.charAt(i);
	       if(ch!="(" && (ch.toLowerCase()=="a" || ch.toLowerCase()=="b" || ch.toLowerCase()=="c"|| ch.toLowerCase()=="d"|| ch.toLowerCase()=="e"|| ch.toLowerCase()=="f"|| ch.toLowerCase()=="g"|| ch.toLowerCase()=="h"|| ch.toLowerCase()=="i"|| ch.toLowerCase()=="j"|| ch.toLowerCase()=="k"|| ch.toLowerCase()=="l"|| ch.toLowerCase()=="m"|| ch.toLowerCase()=="n"|| ch.toLowerCase()=="o"|| ch.toLowerCase()=="p"|| ch.toLowerCase()=="q"|| ch.toLowerCase()=="r"|| ch.toLowerCase()=="s"|| ch.toLowerCase()=="t"|| ch.toLowerCase()=="u"|| ch.toLowerCase()=="v"|| ch.toLowerCase()=="w"|| ch.toLowerCase()=="x"|| ch.toLowerCase()=="y" || ch.toLowerCase()=="z") && ch!=")" && ch!="-" && ch!="/")
                     {
				    alert("Please enter your valid Fax No.");
				    f.faxno.select();
				    return false;
				     }

      }

      if(faxno.length<3)
            {
             alert("Please enter your valid Fax No.");
          	f.faxno.select();
         	 return false;
	      }

}
return true;
}




// ******************** Counter for admin remarks in Customer Management ************************

function checkAdminRmk(txt,f,max)
    {
     var i=txt.value.length;

     f.count1.value=max-i;
     if(f.count1.value==0)
          {
         alert("Admin Remarks should not exceed 250 characters");
         f.adminremarks.select();
         return false;
          }
    return true;
    }
 //************** Admin Remarks not more than 250 **************************
 function checkARmk(f)
 {
   var desc=f.adminremarks.value;
 if(desc.length>250)
         {
          alert("Admin Remarks should not exceed 250 characters");
          f.adminremarks.select();
          return false;
         }
   return true;
}

// ******************** Counter for Customer remarks in Customer Management ************************

function checkCustRmk(txt,f,max)
    {
     var i=txt.value.length;
     f.count.value=max-i;
     if(f.count.value==0)
          {
          alert("Customer Remarks should not exceed 250 characters");
		  f.remarks.select();
          return false;
          }
    return true;
    }
  //************** Admin Remarks not more than 250 **************************
 function checkCRmk(f)
 {
   var desc=f.remarks.value;
 if(desc.length>250)
         {
          alert("Customer Remarks should not exceed 250 characters");
          f.remarks.select();
          return false;
         }
   return true;
}

//****************** checking Department ***********************

function checkDept(f)
{
var dept=f.department.value;
if(dept!="")
{
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;
     	        }

	 for(var i=0;i<dept.length;i++)
		    {
		      var ch=dept.charAt(i);
		    if(!((ch>="A" && ch<="Z") || (ch>="a" && ch<="z")|| (ch==" ") || (ch>="0" && ch<="9")|| ch=="-" || ch=="+" || ch=="(" || ch==")" || ch=="&" || ch=="." || ch==";"))
		    {
			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=="." || ch==";"))
	       {
		alert("Invalid characters entered in Designation.");
		f.designation.select();
	        return false;
	        }
	   }
  }//if desg
return true;
}

// *********************** Checking Acessrights ***********************************

function checkAcsRgt(f)
{

          if(f.product.checked!=true && f.customer.checked!=true && f.special.checked!=true && f.news.checked!=true)
             {
             alert("Please select  atleast one Management Module in Access Rights ");
             return false;
             }
    return true;
}

// ******************** Counter for Mail Body************************
var fBody=true;
function checkMBody(txt,f,max)
    {
     var i=txt.value.length;

     f.count.value=max-i;
     if(f.count.value<0 && fBody==true)
          {
         alert("Mail Body should not exceed 7000 charcters");
         //f.messagebody.select();
         fBody=false;
         return false;
          }
      if(f.count.value>=0)
      {
        fBody=true;
      }
    return true;
    }
 //************** Mail Body not more than 7000 **************************
 function checkMBodyMax(f)
 {
   var desc=f.messagebody.value;
 if(desc.length>7000)
         {
           alert("Mail Body should not exceed 7000 charcters");
          f.messagebody.select();
          return false;
         }
   return true;
}

// ******************** Counter for Mail Footer ************************
var fFoo=true;
function checkMFooter(txt,f,max)
    {
     var i=txt.value.length;
     f.count1.value=max-i;
     if(f.count1.value<0 && fFoo==true)
          {
          alert("Mail Footer should not exceed 1000 charcters.");
          fFoo=false;
          return false;
          }
      if(f.count1.value>=0)
      {
        fFoo=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 should not exceed 1000 charcters.");
          f.footer.select();
          return false;
         }
   return true;
}

// ******************** Counter for Mail Purpose ************************
var fPur=true;
function checkMPurpose(txt,f,max)
    {
     var i=txt.value.length;
     f.count2.value=max-i;
     if(f.count2.value<0 && fPur==true)
          {
          alert("Mail Pupose should not exceed 250 charcters.");
          fPur=false;
          return false;
          }
      if(f.count2.value>=0)
      {
        fPur=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
	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("Please do not enter special characters or blank space in Email.");
		f.sendfrom.focus();
		f.sendfrom.select();
		return false;
	}
return true;
}

// *****************************  check Mail 4 preview to *****************************

function checkEmailSF(f)
{


		var str=f.previewto.value;

		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("Please do not enter special characters or blank space in Email.");
			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 should not exceed 250 characters");
          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.phoneno.select();
				    return false;
				     }

      }
return true;
}

// *************************** Customer Group Name **********************************************

function checkGName(f)
{

var catname=f.name.value;
    if(catname=="")
     {
      alert(" Group Name should not be Blank.");
      f.name.select();
      return false;
      }
      if(catname.substring(0,1)==" "|| !isNaN(catname.substring(0,1)))
         	{
         		alert("Group Name cannot start with Blank Space or Digits.");
         		f.name.select();
         		return false;
     	}



     if(f.name.value.length<3)
         	{
         		alert("Please enter a \"Group Name\" with minimum 3 characters.");
         		f.name.select();
         		return false;
      	}

     if(!validchar(catname))
	{

	           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;
}

//********************************** Special Offer Vlidation *********************************************//

//*********************************** Search Check *******************************************************//


function checksearch(f)
		{
                        if(f.value=="")
			{
				alert("Search Field can not be blank.");
				f.focus();
				f.select();
				return false;
			}
			if(f.value.charAt(0)==" ")
			{
                                alert("Search value can not start with blank.");
				f.focus();
				f.select();
				return false;
			}

			if(f.value.length<3)
			{
				alert("Please enter at least 3 characters in the Search Field.");
				f.focus();
				f.select();
				return false;
			}
			var sp = 0;
			for(var i=0;i<f.value.length;i++)
			{
                            if(f.value.charAt(i)==" ") sp++;
			}
			if(sp>0)
			{
                                alert("Search value can not contain blank.");
				f.focus();
				f.select();
				return false;
			}
		}

// ******************** checking Company Name ********************************

function checkcontactCompName(f)
{
var name=f.company.value;
if(name!="")
{
if(name.charAt(0)==" ")
	      	{
	      		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=="," || ch==":"))
          {
         alert("Enter valid characters in Company Name");
         f.company.select();
         return false;
        }

   }
}
return true;
}

//****************************quantity check for cart details *************************

function checkQuantityCartDetails(f)
{
    if(f.value.substring(0,1) ==" ")
    {
        alert("Quantity cannot start with blank space.");
        f.select();
        return false;
    }


    if(isNaN(f.value))
    {
        alert("Enter valid number in 'Quantity' field.");
        f.select();
        return false;
    }

    if(Math.ceil(f.value)<=0)
	    {
	        alert("Quantity feilds cannot have values 0 and less than 0");
	        f.select();
	        return false;
    	}



    return true;
}
