/********************************************************************* 
* ValidateData.js.                                                     *
* Form validation functions for validating entire forms (onSubmit)     *
* or on-the-fly validation. (onBlur / onChange)                        *
* Copyright 2006 weblink india Pvt.Ltd.                          *
*********************************************************************/

// Functions for onSubmit form validation.


function BisAlpha(val, len, req) {
// Check for "a-z", "A-Z", " ", and optionally length.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   if (val.value.length != 0) {
      for (i = 0; i < val.value.length; i++) {
         var ch = val.value.charAt(i);
         if ((ch >= "A" && ch <= "Z") || (ch >= "a" && ch <= "z") || (ch == " ")) {
            continue;
         } else {
            alert("Please enter only alphabets");
            val.focus();
            val.select();
            return false;
         }
      }
      if (len != "0") {
         if (val.value.length != len) {
            alert("This field must contain " + len + " alphabets characters.");
            val.focus();
            val.select();
            return false;
         }
      }
   }
   return true;
}
//email validation
function BisEmail(val, req) {
// Check for a properly formatted email address.
   if ((val.value.length == 0) && (req == "R")) {
      alert("This field is required.");
      val.focus();
      val.select();
      return false;
   }
   if (val.value.length != 0) 
   {
		var emailformat = /^.+@.+\..{2,3}$/;
	  	if (!emailformat.test(val.value)) {
         alert("Please enter a valid E-Mail Id.");
         val.focus();
         val.select();
         return false;
      }
   }
    var email = val.value.toLowerCase();
	val.value=email;
   return true;
}
//end email function

//function to trim a string
function Trimmer(controlName) { 
	pVal = controlName.value;
    TRs=0; 
    for (i=0; i<pVal.length; i++) 
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRs++;
		} 
		else 
			{break;} 
    } 

    TRe=pVal.length-1; 
    for (i=TRe; i>TRs-1;i--)
	{ 
        if (pVal.substr(i,1)==" ") 
		{
			TRe--;
		}
		else 
			{break;} 
    } 

    controlName.value=pVal.substr(TRs, TRe-TRs+1); 
} 
//end trim function

//-----------------------------------------------------
//function for date
//compare date
function DateComparison(date1, date2)
{
   var d1,d2,m1,m2,y1,y2;
    var fromdate=date1.split('-');
   var todate=date2.split('-');   
   
   d1=eval(fromdate[0]);
   d2=eval(todate[0]);
   m1=eval(fromdate[1]);
   m2=eval(todate[1]);
   y1=eval(fromdate[2]);
   y2=eval(todate[2]);
  
   //return true if second is greater  or equal to first date
   	if (y2 > y1)
	{
   		return true;
	}
	else
	{
		if(y1 > y2)
		{
			return false;
		}
		else
		{
			if(m2>m1)
			{
				return true;
			}
			else
			{
				if(m1>m2)
				{
					return false;
				}
				else
				{
					if(d2>=d1)
					{
						return true;
					}
					else
					{
						return false;
					}
				}
			}
		}
	}   
 }


//============================================================         
 //function for redirecting the page   

function Validate_Category(val)
{
  var error=0;
  var message='';
  var catvalue;
  //catvalue=val.catname.value;
// alert(catvalue.length);
  
  if(val.catname.value=="")
    {
       val.catname.focus();
       message=message+" Please enter the category name. \n";
	   error=1;
     }
 
  
  if(error==1)
	{
	 alert(message);
	 return false;
	}
	return true;

}

//============================================================         
   
//function for redirecting the page   

function CallPage(PageName)
{
	location.href = PageName;
}
//============================================================    
//function for pagination
//============================================================  

//THIS IS SetPageCounter() FUNCTION TO INCREASE VALUE OF PAGE COUNTER
function SetPageCounterInc()
{
	//document.enableurl.PageCounter.value = document.enableurl.PageCounter.value +1;
	document.FormPage.PageCounter.value = eval(document.FormPage.PageCounter.value) + 1  ;
	document.FormPage.submit();
}
			
	//function to send form to the next page
function NextPageLink(val)
{
		document.FormPage.PageCounter.value = eval(val)  ;
		document.FormPage.submit();	
}
		
//THIS IS SetPageCounter() FUNCTION TO DECREASE VALUE OF PAGE COUNTER
function SetPageCounterDec()
{
	document.FormPage.PageCounter.value = eval(document.FormPage.PageCounter.value) - 1  ;
	document.FormPage.submit();
}
//============================================================    
function DomainCheck(val)
{
// Check for a properly formatted url.
   
   var email = val.value.toLowerCase();
   var checkemail="";
    if (val.value.length >0) 
     {
	    if(val.value.substr(0,4)=='www.')
		 {
		   alert("Please don't prefix * www * in domain name ");
		    val.focus();
            val.select();
		    return false;
		 }
		
		var emailformat = /^(([-a-z0-9])+(.com|.net|.edu|.org|.gov|.mil|.int|.biz|.pro|.info|.arpa|.aero|.coop|.name|.museum|(\.{1}+[a-z]{2})+((\.{1}+[a-z]{2,3})))+(|(\.{1}+[a-z]{2,3})))$/;
		//var emailformat = /^(([-a-z0-9])+(|(\.{1}+[a-z]{2})|.com|.net|.edu|.org|.gov|.mil|.int|.biz|.pro|.info|.arpa|.aero|.coop|.name|.museum)+(|(\.{1}+[a-z]{2,3})))$/;
		//var emailformat = /^(([-a-z0-9])+(|.com|.net|.edu|.org|.gov|.mil|.int|.biz|.pro|.info|.arpa|.aero|.coop|.name|.museum))$/;
		//var emailformat = /^.+\..{2,3}$/;
	  	if (!emailformat.test(email)) {
         alert("Please enter a valid domain name.");
         val.focus();
         val.select();
         return false;
      }
   }
	val.value=email;
   return true;


}


//======================Validate seller login=================   
function valid_login_seller(val)
{
var error=0;
var message='';
  if(val.loginid.value=="")
    {
       val.loginid.focus();
       message=message+" Please enter the user name. \n";
	   error=1;
	}
  if(val.password.value=="")
    {
        if(error==0)
		 val.password.focus();
       message=message+" Please enter the password. \n";
	   error=1;
	}
	if(error==1)
	{
	 alert(message);
	 return false;
	}
	return true;
}

function valid_form(val)
{
 var error=0;
  var message='';
 
  if(val.nature.value=="") {   val.nature.focus();  message=message+" Please checked nature of the  business. \n";   error=1; }
  if(val.products.value==""){   if(error==0)	 val.products.focus();  message=message+"Products name must be written. \n"; error=1;}
  if(val.description.value=="") { if(error==0) val.description.focus(); message=message+"Please describe your specific/customized requirements. \n"; error=1;}	
  if(val.bulk.value!='Yes'){ if(val.quantity.value==""){if(error==0) val.quantity.focus();message=message+"Please write the estimated quantity of products. \n"; error=1;} }
  if(val.s_organization.value=="") { if(error==0) val.s_organization.focus(); message=message+"Please enter your organization time. \n"; error=1;}
  if(val.s_name.value=="") { if(error==0) val.s_name.focus(); message=message+"Please enter the name of contact person. \n";  error=1;}
  if(val.s_email.value=="") { if(error==0) val.s_email.focus(); message=message+"Please enter the email. \n";  error=1;	}
  if(val.s_email.value!="")	{ var emailformat = /^.+@.+\..{2,3}$/;   if (!emailformat.test(val.s_email.value)) {
	 val.s_email.focus(); message=message+"Please enter a valid E-Mail Id.";
	 error=1;} }
  if(val.s_ccode.value=="") {   if(error==0) val.s_ccode.focus(); message=message+"Please enter the country code. \n";   error=1;}
  if(val.s_acode.value=="") {   if(error==0) val.s_acode.focus(); message=message+"Please enter the state code. \n";   error=1; }
  if(val.s_phone.value=="")  {  if(error==0) val.s_phone.focus();  message=message+"Please enter your phone number. \n";   error=1;	}
  if(val.s_country.value=="")   {  if(error==0)	 val.s_phone.focus();  message=message+"Please select the name of country. \n";   error=1;}	
  if(error==1)	{ alert(message); return false;	} document.enquiry.submit(); return true; 
 }
function valid_opt()
{
 document.frmInvoice.submit();
}
//Print Article 
function ShowLargeImg(image,Wt,Ht)
{
	Ht=eval(Ht);	
	if(Ht>650)
		Ht=650;
	    Ht=Ht;
	Wt=eval(Wt);		
	if(Wt>950)
		Wt=950;
		Wt=Wt;
	window.open("enlargeimage.php?id=" +image+"&height="+Ht+"&width="+Wt, "myWin6","toolbar=no,directories=no,resizable=yes,scrollbars=yes,menubar=no,height="+(Ht+20)+", width="+(Wt+20)+",left=50,top=50");				
}
