function  validateString( strValue ) {
 var objRegExp  =  /(^[a-zA-Z]+$)/; 
  return objRegExp.test(strValue);
}
function  validateNumeric( strValue ) {
/******************************************************************************
DESCRIPTION: Validates that a string contains only valid numbers.

PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
******************************************************************************/
  var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/; 
 
  //check for numeric characters 
  return objRegExp.test(strValue);
}

function validateInteger( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only 
    valid integer number.
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
******************************************************************************/
  var objRegExp  = /(^-?\d\d*$)/;
 
  //check for integer characters
  return objRegExp.test(strValue);
}

function validateNotEmpty( strValue ) {
/************************************************
DESCRIPTION: Validates that a string is not all
  blank (whitespace) characters.
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/
   var strTemp = strValue;
   strTemp = trimAll(strTemp);
   if(strTemp.length > 0){
     return true;
   }  
   return false;
}

function validateEmail( strValue) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid email pattern. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS: Accounts for email with country appended
  does not validate that email contains valid URL
  type (.com, .gov, etc.) and optionally,
  a valid country suffix.  Since email has many
  forms this expression only tests for near valid
  address.  Some additional validation may be
  required.
*************************************************/
var objRegExp  = /^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,3}(\.[a-z]{2}){0,2})$/i;
  //check for valid email
  return objRegExp.test(strValue);
}

function rightTrim( strValue ) {
/************************************************
DESCRIPTION: Trims trailing whitespace chars.
    
PARAMETERS:
   strValue - String to be trimmed.  
      
RETURNS:
   Source string with right whitespaces removed.
*************************************************/
var objRegExp = /^([\w\W]*)(\b\s*)$/;
 
      if(objRegExp.test(strValue)) {
       //remove trailing a whitespace characters
       strValue = strValue.replace(objRegExp, '$1');
    }
  return strValue;
}

function leftTrim( strValue ) {
/************************************************
DESCRIPTION: Trims leading whitespace chars.
    
PARAMETERS:
   strValue - String to be trimmed
   
RETURNS:
   Source string with left whitespaces removed.
*************************************************/
var objRegExp = /^(\s*)(\b[\w\W]*)$/;
 
      if(objRegExp.test(strValue)) {
       //remove leading a whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}

function trimAll( strValue ) {
/************************************************
DESCRIPTION: Removes leading and trailing spaces.

PARAMETERS: Source string from which spaces will
  be removed;

RETURNS: Source string with whitespaces removed.
*************************************************/ 
 var objRegExp = /^(\s*)$/;

    //check for all spaces
    if(objRegExp.test(strValue)) {
       strValue = strValue.replace(objRegExp, '');
       if( strValue.length == 0)
          return strValue;
    }
    
   //check for leading & trailing spaces
   objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
   if(objRegExp.test(strValue)) {
       //remove leading and trailing whitespace characters
       strValue = strValue.replace(objRegExp, '$2');
    }
  return strValue;
}






function validateCurrency( strValue)  {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid currency format. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp = /(^\$\d{1,3}(,\d{3})*\.\d{2}$)|(^\(\$\d{1,3}(,\d{3})*\.\d{2}\)$)/;

  return objRegExp.test( strValue );
}

function validateTime ( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid 12 hour time format. Seconds are optional.
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.

REMARKS: Returns True for time formats such as:
  HH:MM or HH:MM:SS or HH:MM:SS.mmm (where the
  .mmm is milliseconds as used in SQL Server 
  datetime datatype.  Also, the .mmm portion will 
  accept 1 to 3 digits after the period)
*************************************************/
  var objRegExp = /^([1-9]|1[0-2]):[0-5]\d(:[0-5]\d(\.\d{1,3})?)?$/;

  return objRegExp.test( strValue );

}

function validateState (strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid state abbreviation. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/

var objRegExp = /^(AK|AL|AR|AZ|CA|CO|CT|DC|DE|FL|GA|HI|IA|ID|IL|IN|KS|KY|LA|MA|MD|ME|MI|MN|MO|MS|MT|NB|NC|ND|NH|NJ|NM|NV|NY|OH|OK|OR|PA|RI|SC|SD|TN|TX|UT|VA|VT|WA|WI|WV|WY)$/i; 

  return objRegExp.test(strValue);
}

function validateSSN( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains a 
  valid social security number. 
  
 PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp  = /^\d{3}\-\d{2}\-\d{4}$/;
 
  //check for valid SSN
  return objRegExp.test(strValue);

}



function validateUSPhone( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains valid
  US phone pattern. 
  Ex. (999) 999-9999 or (999)999-9999
  
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
*************************************************/
  var objRegExp  = /^\([1-9]\d{2}\)\s?\d{3}\-\d{4}$/;
 
  //check for valid us phone with or without space between 
  //area code
  return objRegExp.test(strValue); 
}


function validateUSZip( strValue ) {
/************************************************
DESCRIPTION: Validates that a string a United
  States zip code in 5 digit format or zip+4
  format. 99999 or 99999-9999
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.

*************************************************/
var objRegExp  = /(^\d{5}$)|(^\d{5}-\d{4}$)/;
 
  //check for valid US Zipcode
  return objRegExp.test(strValue);
}

function validateUSDate( strValue ) {
/************************************************
DESCRIPTION: Validates that a string contains only 
    valid dates with 2 digit month, 2 digit day, 
    4 digit year. Date separator can be ., -, or /.
    Uses combination of regular expressions and 
    string parsing to validate date.
    Ex. mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
    
PARAMETERS:
   strValue - String to be tested for validity
   
RETURNS:
   True if valid, otherwise false.
   
REMARKS:
   Avoids some of the limitations of the Date.parse()
   method such as the date separator character.
*************************************************/
  var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/
 
  //check to see if in correct format
  if(!objRegExp.test(strValue))
    return false; //doesn't match pattern, bad date
  else{
    var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year
	var intDay = parseInt(arrayDate[1],10); 
	var intYear = parseInt(arrayDate[2],10);
    var intMonth = parseInt(arrayDate[0],10);
	
	//check for valid month
	if(intMonth > 12 || intMonth < 1) {
		return false;
	}
	
    //create a lookup for months not equal to Feb.
    var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
                        '08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}
  
    //check if month value and day value agree
    if(arrayLookup[arrayDate[0]] != null) {
      if(intDay <= arrayLookup[arrayDate[0]] && intDay != 0)
        return true; //found in lookup table, good date
    }
		
    //check for February
	var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
    if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
      return true; //Feb. had valid number of days
  }
  return false; //any other values, bad date
}

function validateValue( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Validates that a string a matches
  a valid regular expression value.
    
PARAMETERS:
   strValue - String to be tested for validity
   strMatchPattern - String containing a valid
      regular expression match pattern.
      
RETURNS:
   True if valid, otherwise false.
*************************************************/
var objRegExp = new RegExp( strMatchPattern);
 
 //check if string matches pattern
 return objRegExp.test(strValue);
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function fun_register()
{
	with(document.register_form)
	{
		if(trimAll(text_name.value)=="")
		{
			alert("Please enter your name");
			text_name.focus();
			return false;
		}
		else if(trimAll(text_title.value)=="")
		{
			alert("Please enter the title");
			text_title.focus();
			return false;
		}
		else if(trimAll(text_company.value)=="")
		{
			alert("Please enter the company");
			text_company.focus();
			return false;
		}
		else if(trimAll(text_address.value)=="")
		{
			alert("Please enter the address");
			text_address.focus();
			return false;
		}
		else if(trimAll(text_city.value)=="")
		{
          alert("Please enter the city");
		  text_city.focus();
		  return false;
		}
		else if(trimAll(text_state.value)=="")
		{
			alert("Please enter the state");
			text_state.focus();
			return false;
		}
		else if(trimAll(text_zip.value)=="")
		{
			alert("Please enter the zip code");
			text_zip.focus();
			return false;
		}
		else if(trimAll(text_country.value)=="")
		{
			alert("Please enter the country");
			text_country.focus();
			return false;
		}
		else if(trimAll(text_telephone.value)=="")
		{
			alert("Please enter the telephone number");
			text_telephone.focus();
			return false;
		}
		else if(trimAll(text_fax.value)=="")
		{
			alert("Please enter the fax number");
			text_fax.focus();
			return false;
		}
		else if(trimAll(text_email.value)=="")
		{
			alert("Please enter the Email address");
			text_email.focus();
			return false;
		}
		else if(trimAll(text_pass.value)=="")
		{
			alert("Please enter the password");
			text_pass.focus();
			return false;
		}
		else if(trimAll(text_repass.value)=="")
		{
			alert("Please re-enter the password");
			text_pass.focus();
			return false;
		}
		else if(trimAll(text_pass.value)!=trimAll(text_repass.value))
		{
			alert("Re-entered password does not match with the password.Please provide correct password");
			text_repass.focus();
			return false;
		}
		else if(!validateEmail(text_email.value))
		{
			alert("Please enter the valid Email address");
			text_email.focus();
			return false;
		}
		else if(PreferredContact.value=="")
		{
			alert("Please select your contact preference");
			PreferredContact.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="register";
			submit();
		}
 		
	}
}
function enter_key_register(e)
{
	if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		fun_register();
	  }
}
function validate_admin_login() 
{
	with(document.adminform_login)
	{
		if(trimAll(adminname.value)=="")
		{ 
			alert("Please enter the Username");
			adminname.focus();
			return false;
		}
		else if(trimAll(adminpassword.value)=="")
		{
			alert("Please enter the passowrd");
			adminpassword.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="login";
			submit();
		}
	}
}

function pagetransfer(pagenumber,Formname)
{
	with(document.forms[Formname])
	{
  
		HdnPage.value	= pagenumber;
		Hidmode.value	= "paging";

		submit();
		
	}
}
	
function validateTinyMCEEditor(){
	
 tinyMCE.triggerSave(true,true); 
 var mytextarea = tinyMCE.activeEditor.getContent();
 if(mytextarea == "") {        
  //alert("Please put in some content!");   
  return false;   
 }  
} 

function fun_sendmessage()
{
	with(document.manage_userform)
	{
		if(select_customers.value=="")
		{
			alert("Please select any customers to send mail");
			select_customers.focus();
			return false;
		}
		else if(trimAll(text_subject.value)=="")
		{
			alert("Please enter the subject");
			text_subject.focus();
			return false;
		}
		else if(validateTinyMCEEditor() == false)
		{
			alert("Please enter the message");
			send_message.focus();
			return false;
		}
		else
		{
           Hdn_mail.value="send";
		   submit();
		}
	}
}

function fun_post()
{
	with(document.faq_form)
	{
		if(trimAll(text_email.value)=="")
		{
			alert("Please enter the Emailaddress");
			text_email.focus();
			return false;
		}
		else if(!validateEmail(text_email.value))
		{
			alert("Please enter valid Email address");
			text_email.focus();
			return false;
		}
		if(trimAll(text_question.value)=="")
		{
			alert("Please post your question");
			text_question.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="question";
			submit();
		}
	}
}


function fun_postanswer()
{
	with(document.answer_postform)
	{
		if(trimAll(text_answer.value)=="")
		{
			alert("Please enter your answer");
			text_answer.focus();
			return false;
		}
		else
		{
			Hdn_post.value="answer";
			submit();
		}
	}
}


function fun_display()
{
  with(document.faq_form)
	{

	  if(document.getElementById("question_id").style.display=="")
         document.getElementById("question_id").style.display="none";
	  else
		  document.getElementById("question_id").style.display="";
	}
}

function fun_login()
{
	with(document.login_form)
	{
		if(trimAll(text_email.value)=="")
		{
			alert("Please enter the Email address");
			text_email.focus();
			return false;
		}
		else if(!validateEmail(text_email.value))
		{
			alert("Please enter the valid Email address");
			text_email.focus();
			return false;
		}
		else
		{
			Hdn_login.value="login";
			submit();
		}
	}
}

function fun_update()
{
	with(document.account_form)
	{
     if(trimAll(text_name.value)=="")
		{
			alert("Please enter your name");
			text_name.focus();
			return false;
		}
		else if(trimAll(text_title.value)=="")
		{
			alert("Please enter the title");
			text_title.focus();
			return false;
		}
		else if(trimAll(text_company.value)=="")
		{
			alert("Please enter the company");
			text_company.focus();
			return false;
		}
		else if(trimAll(text_address.value)=="")
		{
			alert("Please enter the address");
			text_address.focus();
			return false;
		}
		else if(trimAll(text_city.value)=="")
		{
          alert("Please enter the city");
		  text_city.focus();
		  return false;
		}
		else if(trimAll(text_state.value)=="")
		{
			alert("Please enter the state");
			text_state.focus();
			return false;
		}
		else if(trimAll(text_zip.value)=="")
		{
			alert("Please enter the zip code");
			text_zip.focus();
			return false;
		}
		else if(trimAll(text_country.value)=="")
		{
			alert("Please enter the country");
			text_country.focus();
			return false;
		}
		else if(trimAll(text_sales.value)=="")
		{
			alert("Please enter the sales rep servicing your territory");
			text_sales.focus();
			return false;
		}
		else if(trimAll(text_telephone.value)=="")
		{
			alert("Please enter the telephone number");
			text_telephone.focus();
			return false;
		}
		else if(trimAll(text_fax.value)=="")
		{
			alert("Please enter the fax number");
			text_fax.focus();
			return false;
		}
		else if(trimAll(text_email.value)=="")
		{
			alert("Please enter the Email address");
			text_email.focus();
			return false;
		}
		else if(trimAll(text_pass.value)=="")
		{
			alert("Please enter the password");
			text_pass.focus();
			return false;
		}
		else if(!validateEmail(text_email.value))
		{
			alert("Please enter the valid Email address");
			text_email.focus();
			return false;
		}
		else if(trimAll(text_website.value)=="")
		{
			alert("Please enter the company website");
			text_website.focus();
			return false;
		}
		else if(PreferredContact.value=="")
		{
			alert("Please select your contact preference");
			PreferredContact.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="update";
			submit();
		}
	}
}

function fun_changepasswd()
{
   with(document.account_form)
	{
	    if(trimAll(new_pwd.value)=="")
		{
			alert("Please enter your new password");
            new_pwd.focus();
			return false;
		}
		else if(trimAll(cnfmnew_pwd.value)=="")
		{
			alert("Please confirm your new password");
			cnfmnew_pwd.focus();
			return false;

		}
		else if(trimAll(new_pwd.value)!=trimAll(cnfmnew_pwd.value))
		{
			alert("Re-entered password does not match with the password.Please provide correct password");
			cnfmnew_pwd.focus();
			return false;
		}
		else
		{
			Hdn_change.value="update";
			submit();
		}
	}
}

function fun_lostpasswd()
{
	with(document.lostpasswd_form)
	{
		if(trimAll(text_useremail.value)=="")
		{
			 alert("Please enter your emailaddress");
			 text_useremail.focus();
			 return false;
		}
		else if(!validateEmail(text_useremail.value))
		{
          alert("Please enter valid Emailaddress");
		  text_useremail.focus();
		  return false;
		}
		else
		{
			Hdn_lost.value="update";
			submit();
		}
	}
}
function sortbycolumn(formname,val,orderby)
{
	with(document.forms[formname])
	{
		 Hdnsort.value	=	"yes";
		 Hdnsortby.value=	val;
		 if(orderby=='ASC')
			 Hdnorder.value	=	'DESC';
		 if(orderby=='DESC')
			 Hdnorder.value	=	'ASC';
		 else
			  Hdnorder.value=	'DESC';
		 submit();
	}
}

function fun_addnews()
{
	with(document.add_newsform)
	{
		if(trimAll(release_date.value)=="")
		{ 
			alert("Please select the release date");
			release_date.focus();
			return false;
		}
		else if(trimAll(text_partnum.value)=="")
	    {
			alert("Please enter the part number");
			text_partnum.focus();
		    return false;
		}
		else if(trimAll(text_desc.value)=="")
		{
			alert("Please enter the description");
			text_desc.focus();
			return false;
		}
		else if(select_product.value=="")
		{
			alert("Please select the product category");
			select_product.focus();
			return false;
		}
		else if(product_file.value=="")
		{
			alert("Please upload the product news content");
			product_file.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="add";
			submit();
		}
	}
}

function fun_searchcus()
{
	with(document.searchcus_form)
	{
		if((trimAll(search_name.value)=="") && (trimAll(search_cmpny.value)=="")&& (trimAll(search_pdct.value)==""))
		{
			alert("Please enter the search option");
			search_name.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="search";
			submit();
		}
	}
}

function update_news()
{
	with(document.add_newsform)
	{
		if(trimAll(release_date.value)=="")
		{ 
			alert("Please select the release date");
			release_date.focus();
			return false;
		}
		else if(trimAll(text_partnum.value)=="")
	    {
			alert("Please enter the part number");
			text_partnum.focus();
		    return false;
		}
		else if(trimAll(text_desc.value)=="")
		{
			alert("Please enter the description");
			text_desc.focus();
			return false;
		}
		else if(select_product.value=="")
		{
			alert("Please select the product category");
			select_product.focus();
			return false;
		}
		else if(product_file.value=="")
		{
			alert("Please upload the product news content");
			product_file.focus();
			return false;
		}
		else
		{
			Hdn_submit.value="update";
			submit();
		}
	}
}
