// JavaScript Document

/*
*********************************************************************                                                                    *
 *  Com1 (www.com1uk.com), helpdesk@com1uk.com                      *
 *  Registered in England, Wales & India                            *
 *                                                                  *
 *  Site: www.hikingpantsnz.com                                        *
 *                                                                  *
 *  FileName       : form_validation.js								*
 *	Created By     : Salim Khan										*
 *	Created Date   : 27/08/08							            *
 *  Purpose : This file contents the functions called in contact page*
 *                                                                  *
 *  Modified Date  : 25-10-08                                          *
 *  Modified By    : Rupali											* 
 * 	Modification Note 	: Added new functions for order form        *
 *                                                                  *
*********************************************************************
*/

	/*
		Created By : Salim Khan
		Date of Creationg : 27/08/08
		Function Name : checkMail()
		Purpose : This function is used to validate the email address.
	*/


function checkMail()
{
		//this function checks whether the email address added is valid or not.
	
        var x = document.forms[0].txtemail.value;
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (filter.test(x))
        {
                return true;
        }
        else {
                return false;
        }
}

function checkMail1()
{
		//this function checks whether the email address added is valid or not.
	
        var x = document.form1.txtemail1.value;
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (filter.test(x))
        {
                return true;
        }
        else {
                return false;
        }
}


//---------------------------------

	/*
		Created By : Salim Khan
		Date of Creationg : 27/08/08
		Function Name : IsNumeric()
		Purpose : This function is used to check for the Numeric data type.
	*/


function IsNumeric(strString)
   //  check for valid numeric strings
   {
   var strValidChars = " 0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
//---------------------------------

	/*
		Created By : Salim Khan
		Date of Creationg : 27/08/08
		Function Name : checkMail()
		Purpose : This function is called is used to check whether the name field is not empty.
	*/


function check_name()
{
	// this function check whether the user has entered a value or not empty. 
	
  if(document.form1.txtname.value == '')
   {
        document.getElementById("name").style.display='block';
      //document.form1.txtname.focus();
      return false;
    } else if(IsNumeric(document.form1.txtname.value))
	 {
                document.getElementById("name").style.display='block';
                 return false;
   } else
   {
        document.getElementById("name").style.display='none';
      return true;
   }
}

//--------------------------------------------

	/*
		Created By : Salim Khan
		Date of Creationg : 27/08/08
		Function Name : checkMail()
		Purpose : This function is used to check whether the email address field is valid and not empty.
	*/


function check_email()
{
  if(document.form1.txtemail.value == '')
   {

        document.getElementById("email1").style.display='block';
 } else if(checkMail(document.form1.txtemail.value)){
        document.getElementById("email1").style.display='none';
        return true;
   } else
   {
        document.getElementById("email1").style.display='block';
        return false;
   }
}



//------------------------------------------------------

	/*
		Created By : Salim Khan
		Date of Creationg : 27/08/08
		Function Name : checkMail()
		Purpose : This function checks whether the phone no. entered is numeric.
	*/

function check_phone()
{

  if(document.form1.phone.value == '')
   {
   //          document.getElementById("phone_chk").style.display='block';
          document.getElementById("phone_chk1").style.display='none';
     // phone.focus();
      return false;
 } else if(IsNumeric(document.form1.phone.value))
 {
                document.getElementById("phone_chk1").style.display='none';
                document.getElementById("phone_chk").style.display='none';
                 return true;
   } else
   {
             document.getElementById("phone_chk1").style.display='block';
          document.getElementById("phone_chk").style.display='none';
      return false;

   }
}
//---------------------------------------------------


	/*
		Created By : Salim Khan
		Date of Creationg : 27/08/08
		Function Name : checkMail()
		Purpose : This function checks whether the reason  textbox is not empty.
	*/


function check_reason()
{
	
  if(document.form1.txtreason.value == '')
   {
        document.getElementById("reason").style.display='block';
      //document.form1.txtreason.focus();
      return false;
   } else
   {
        document.getElementById("reason").style.display='none';

      return true;

   }
}

//--------------------------------------------

//------function related with order form starts here - added by Rupali ------------//

function check_ordername(value,errorfield)
{
	
  var fieldname=errorfield;
  if(value != "")
  {
	  
      document.getElementById(fieldname).style.display='none';
      return false;
   }
   else
   {
	   document.getElementById(fieldname).style.display='block';
       return false;
   }
}

function checkall_email(value,errorfield)
{
	
   if(value == '')
   {
        document.getElementById(errorfield).style.display='block';
		return false;
   }
   else if(checkorderMail(value))
   {
	    document.getElementById(errorfield).style.display='none';
        return true;
   }
   else
   {    
          
	    document.getElementById(errorfield).style.display='block';
        return false;
   }
}

function checkorderMail(value)
{
	    
	  //this function checks whether the email address added is valid or not.
	    var x = value;
        var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
        if (filter.test(x))
        {
                return true;
        }
        else
		{
                return false;
        }
}

function IsNumeric_order(strString,fieldname)
   //  check for valid numeric strings
   {
	   var strValidChars = " 0123456789.-";
	   var strChar;
	   var blnResult = true;
	
	   if (strString.length == 0) return false;
	
	   //  test strString consists of valid characters listed above
	   for (i = 0; i < strString.length && blnResult == true; i++)
		  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			 {
				 document.getElementById(fieldname).style.display='block';	  
				 blnResult = false;
			 }
		  }
       return blnResult;
   }
//end of function related with order form
