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

//Used for srtValue
function replace(argvalue, x, y) {

  if ((x == y) || (parseInt(y.indexOf(x)) > -1)) {
    errmessage = "replace function error: \n";
    errmessage += "Second argument and third argument could be the same ";
    errmessage += "or third argument contains second argument.\n";
    errmessage += "This will create an infinite loop as it's replaced globally.";
    alert(errmessage);
    return false;
  }
    
  while (argvalue.indexOf(x) != -1) {
    var leading = argvalue.substring(0, argvalue.indexOf(x));
    var trailing = argvalue.substring(argvalue.indexOf(x) + x.length, 
	argvalue.length);
    argvalue = leading + y + trailing;
  }

  return argvalue;

}

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

// admin login validation
function validate_admin()
{
	with(document.adminlogin)
	{
		if(trimAll(username.value)=="")
		{
			alert("Please enter the name.");
			username.focus();
			return false;
		}
		else if(trimAll(password.value) == ""){
			alert("Please enter the password")
			password.focus()
			return false;		
		}
		HiddenMode.value="yes";
		return true;
	}
}

// client login validation
function validate_client()
{
	with(document.clientlogin)
	{
//		if(trimAll(username.value)=="")
//		{
//			alert("Please enter the name.");
//			username.focus();
//			return false;
//		}

		if(trimAll(clientemail.value)=="")
		{
			alert("Please enter the email");
			clientemail.focus();
			return false;
		}
		else if(!(validateEmail(clientemail.value)))
		{
			alert("Please enter valid email address!");
			clientemail.focus(); 
			return false;
		}
		else if(trimAll(password.value) == ""){
			alert("Please enter the password")
			password.focus()
			return false;		
		}
		HiddenMode.value="yes";
		return true;
	}
}

//New Client validation
function client_validate()
{
	with(document.newclientform)
	{
		if(trimAll(contact_email.value) == "")
		{
			alert("Please enter the client email")
			contact_email.focus()
			return false;
		}
		else if(!(validateEmail(contact_email.value)))
		{
			alert("Please enter valid email address!");
			contact_email.focus(); 
			return false;
		}
		else if(trimAll(password.value) == ""){
			alert("Please enter the password")
			password.focus();
			return false;		
		}
		else if(trimAll(clientname.value)=="")
		{
			alert("Please enter the name.");
			clientname.focus();
			return false;
		}
		
		else if(trimAll(contact.value) == ""){
			alert("Please enter the contact name")
			contact.focus()
			return false;		
		}
		else if(trimAll(contact_phone.value) == ""){
			alert("Please enter the contact phone number")
			contact_phone.focus()
			return false;		
		}
		HiddenMode.value="yes";
		return true;
	}
}

// Update client validation
function clientupdate_validate()
{
	with(document.editclientform)
	{
		if((clientname.value)=="")
		{
			alert("Please enter the name.");
			username.focus();
			return false;
		}
		else if((password.value) == ""){
			alert("Please enter the password")
			password.focus()
			return false;		
		}
		else if((contact.value) == ""){
			alert("Please enter the contact name")
			contact.focus()
			return false;		
		}
		else if((contact_phone.value) == ""){
			alert("Please enter the contact phone number")
			contact_phone.focus()
			return false;		
		}
		else if((contact_email.value) == ""){
			alert("Please enter the contact email")
			contact_email.focus()
			return false;		
		}
		else if(!(validateEmail(contact_email.value)))
				{
					alert("Please enter valid email address!");
					contact_email.focus(); 
					return false;
				}
		Hiddenupdate.value="yes";
		return true;
	}
}

//dropdown action for client
function funComAjax(clientid)
{ 
	 with(document.editclientform)
	 {  
		Hiddenstatus.value="yes";
		Hiddenid.value=clientid;
		submit();			
	  }
}


//New job validation
function job_validate(limit)
{
	with(document.addjob)
	{
		if(trimAll(client.value)=="")
		{
			alert("Please select the client name.");
			client.focus();
			return false;
		}
		else if(trimAll(jobnumber.value) == ""){
			alert("Please enter the job number")
			jobnumber.focus()
			return false;		
		}
		else if(!validateNumeric(trimAll(jobnumber.value))){
			alert("Please enter the job number numbers only!")
			jobnumber.focus()
			return false;		
		}
		else if(trimAll(jobname.value) == "") {
			alert("Please enter the job name");
			jobname.focus()
			return false;		
		}
		else if(work1.checked==false && work2.checked==false  && work3.checked==false  && work4.checked==false  && work5.checked==false && work6.checked==false && work7.checked==false && work8.checked==false && work9.checked==false && work10.checked==false && work11.checked==false) {
			alert("Please select any one work assigned!");
			work1.focus();
			return false;		
		}
		else if(trimAll(disnumber.value) >= 1 )  
		{
			if(trimAll(document.getElementById("distribution1").value) == "")
				{
					alert("Please enter distribution value!")
					document.getElementById("distribution1").focus();
					return false;		
				}
				else if(trimAll(document.getElementById("Scheduled1").value) == "")
				{
					alert("Please select scheduled date!")
					document.getElementById("Scheduled1").focus();
					return false;		
				}
				else if(trimAll(document.getElementById("selectstatus_1").value) == "")
				{
					alert("Please select status!")
					document.getElementById("selectstatus_1").focus();
					return false;		
				}


			/*else if(trimAll(matreceived1.value) == "")
			{
				alert("Please enter material received!")
				matreceived1.focus();
				return false;		
			}
			else if(trimAll(datreceived1.value) == "")
			{
				alert("Please select received date!")
				datreceived1.focus();
				return false;		
			}
			else if(trimAll(piecount1.value) == "")
			{
				alert("Please enter piece count!")
				piecount1.focus();
				return false;		
			}
			else if(trimAll(liscount1.value) == "")
			{
				alert("Please enter list count!")
				liscount1.focus();
				return false;		
			}
			else if(trimAll(posamount1.value) == "")
			{
				alert("Please enter postage amount!")
				posamount1.focus();
				return false;		
			} else if(!validateNumeric(trimAll(posamount1.value)))
			{
				alert("Please enter postage amount numbers only!")
				posamount1.focus();
				return false;		
			}
			else if(trimAll(posconfirmation1.value)  == "" )
			{
				alert("Please select actual mail date!")
				posconfirmation1.focus();
				return false;
			}*/
		}
		
		HiddenMode.value="yes";
		return true;
		
	}

}


// add notes validation
function notes_validate()
{
	with(document.addnote)
	{
		if(trimAll(notes.value)=="")
		{
			alert("Please enter the notes.");
			notes.focus();
			return false;
		}		
		HiddenMode.value="yes";
		return true;
	}
}

//function used to validate index form  for client starts
function enter_key_for_login_page(e,formname)
{
	if(e.keyCode==13)
	{
	 if (navigator.appName=="Netscape")
	 {
	  e.preventDefault();
	 }
	else
	  e.keyCode=0;
	  validate_client(formname);
	}
}

//function used to validate index form  for admin starts
function enter_key_for_login_page(e,formname)
{
	if(e.keyCode==13)
	{
	 if (navigator.appName=="Netscape")
	 {
	  e.preventDefault();
	 }
	else
	  e.keyCode=0;
	  validate_admin(formname);
	}
}


function operation_validate()
{
	with(document.newclientform)
	{
		if(trimAll(username.value)=="")
		{
			alert("Please enter the name.");
			username.focus();
			return false;
		}
		else if(trimAll(password.value) == ""){
			alert("Please enter the password")
			password.focus()
			return false;		
		}
		else if(trimAll(contact.value) == ""){
			alert("Please enter the contact name")
			contact.focus()
			return false;		
		}
		else if(trimAll(contact_phone.value) == ""){
			alert("Please enter the contact phone number")
			contact_phone.focus()
			return false;		
		}
		else if(trimAll(contact_email.value) == ""){
			alert("Please enter the contact email")
			contact_email.focus()
			return false;		
		}
		else if(!(validateEmail(contact_email.value)))
				{
					alert("Please enter valid email address!");
					contact_email.focus(); 
					return false;
				}
		HiddenMode.value="yes";
		return true;
	}
}

// Update client validation
function operationupdate_validate()
{
	with(document.editclientform)
	{
		if((clientname.value)=="")
		{
			alert("Please enter the name.");
			username.focus();
			return false;
		}
		else if((password.value) == ""){
			alert("Please enter the password")
			password.focus()
			return false;		
		}
		else if((contact.value) == ""){
			alert("Please enter the contact name")
			contact.focus()
			return false;		
		}
		else if((contact_phone.value) == ""){
			alert("Please enter the contact phone number")
			contact_phone.focus()
			return false;		
		}
		else if((contact_email.value) == ""){
			alert("Please enter the contact email")
			contact_email.focus()
			return false;		
		}
		else if(!(validateEmail(contact_email.value)))
				{
					alert("Please enter valid email address!");
					contact_email.focus(); 
					return false;
				}
		Hiddenupdate.value="yes";
		return true;
	}
}


// Operation User login validation
function validate_OperationUsr()
{
	with(document.OperationUsrlogin)
	{
		if(trimAll(username.value)=="")
		{
			alert("Please enter the name.");
			username.focus();
			return false;
		}
		else if(trimAll(password.value) == ""){
			alert("Please enter the password")
			password.focus()
			return false;		
		}
		HiddenMode.value="yes";
		return true;
	}
}

