var url = document.location.href;
var xend = url.lastIndexOf("/") + 1;
var base_url = url.substring(0, xend);


var submitted = false;
var error = false;
var error_message = "";

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 validateEmail( strValue) {
  var objRegExp  = /^([a-z0-9])([a-z0-9_\-]*)([\.]{0,1}([a-z0-9_\-]*))@([a-z0-9_\-]+)([\.]{1})([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);
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
	} 
	return this
}

function isDate(dtStr)
{
	if(dtStr=='')
	{
		alert("Please enter date");
		return false;
	}
	else
	{
	var daysInMonth = DaysArray(12);	
	var pos1=dtStr.indexOf(dtCh);	
	var pos2=dtStr.indexOf(dtCh,pos1+1);	
	var strDay=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strYear=dtStr.substring(pos2+1);	
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
	{
		alert("The date format should be : dd/mm/yyyy");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
	return true
	}
}


function ValidateForm(datevalue){
	
	var dt=datevalue;
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
 }

/*********paramasivan script starts************/

/*function validateUrl(strValue) 
	{ 
	var objRegExp=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}$/;
	return objRegExp.test(strValue);
	} */

/*********paramasivan script ends************/


function validateUrl(strValue) {
    var v = new RegExp();
    v.compile("^[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+$");
    if (!v.test(strValue)) {
        return false;
    }
	else return true;
}

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 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 removeCurrency( strValue ) {
/************************************************
DESCRIPTION: Removes currency formatting from 
  source string.
  
PARAMETERS: 
  strValue - Source string from which currency formatting
     will be removed;

RETURNS: Source string with commas removed.
*************************************************/
  var objRegExp = /\(/;
  var strMinus = '';
 
  //check if negative
  if(objRegExp.test(strValue)){
    strMinus = '-';
  }
  
  objRegExp = /\)|\(|[,]/g;
  strValue = strValue.replace(objRegExp,'');
  if(strValue.indexOf('$') >= 0){
    strValue = strValue.substring(1, strValue.length);
  }
  return strMinus + strValue;
}

function addCurrency( strValue ) {
/************************************************
DESCRIPTION: Formats a number as currency.

PARAMETERS: 
  strValue - Source string to be formatted

REMARKS: Assumes number passed is a valid 
  numeric value in the rounded to 2 decimal 
  places.  If not, returns original value.
*************************************************/
  var objRegExp = /-?[0-9]+\.[0-9]{2}$/;
   
    if( objRegExp.test(strValue)) {
      objRegExp.compile('^-');
      strValue = addCommas(strValue);
      if (objRegExp.test(strValue)){
        strValue = '($' + strValue.replace(objRegExp,'') + ')';
      }
      else {
        strValue = '$' + strValue;
      }
      return  strValue;
    }
    else
      return strValue;
}

function removeCommas( strValue ) {
/************************************************
DESCRIPTION: Removes commas from source string.

PARAMETERS: 
  strValue - Source string from which commas will 
    be removed;

RETURNS: Source string with commas removed.
*************************************************/
  var objRegExp = /,/g; //search for commas globally
 
  //replace all matches with empty strings
  return strValue.replace(objRegExp,'');
}

function addCommas( strValue ) {
/************************************************
DESCRIPTION: Inserts commas into numeric string.

PARAMETERS: 
  strValue - source string containing commas.
  
RETURNS: String modified with comma grouping if
  source was all numeric, otherwise source is 
  returned.
  
REMARKS: Used with integers or numbers with
  2 or less decimal places.
*************************************************/
  var objRegExp  = new RegExp('(-?[0-9]+)([0-9]{3})'); 

    //check for match to search criteria
    while(objRegExp.test(strValue)) {
       //replace original string with first group match, 
       //a comma, then second group match
       strValue = strValue.replace(objRegExp, '$1,$2');
    }
  return strValue;
}

function removeCharacters( strValue, strMatchPattern ) {
/************************************************
DESCRIPTION: Removes characters from a source string
  based upon matches of the supplied pattern.

PARAMETERS: 
  strValue - source string containing number.
  
RETURNS: String modified with characters
  matching search pattern removed
  
USAGE:  strNoSpaces = removeCharacters( ' sfdf  dfd', 
                                '\s*')
*************************************************/
 var objRegExp =  new RegExp( strMatchPattern, 'gi' );
 
 //replace passed pattern matches with blanks
  return strValue.replace(objRegExp,'');
}

function validate_admin_login()
{
	with(document.FormAdminLogin)
	{
		if(trimAll(adminname.value)=="")
		{
			alert("Please enter the username");
			adminname.value="";
			adminname.focus();
			return false;
		}
		else if(trimAll(adminpassword.value)=="")
		{
			alert("Please enter the password");
			adminpassword.value="";
			adminpassword.focus();
			return false;
		}
	}
}

function fun_start()
{
	with(document.start_form)
	{
		if(chk_terms.checked==false)
		{
			alert("You must agree to Terms and conditions before getting started");
			chk_terms.focus();
			return false;
		}
		else
		{
			document.location='add-sample.php';
		}
	}
}


function fun_addsample(sample_count)
{
	with(document.add_sampleform)
	{
		if(trimAll(text_samplenum.value)=="")
		{
          alert("Please enter the sample number");
		  text_samplenum.focus();
		  return false;
		}
		if(trimAll(text_sampledesc.value)=="")
		{
		  alert("Please enter the sample description");
		  text_sampledesc.focus();
		  return false;
		}
		if(sample_count==0)
		{
			if(chk_terms.checked==false)
			{
				alert("You must agree to Terms and conditions before getting started");
				chk_terms.focus();
				return false;
			}
		}
		Hdn_sample.value="add";
		submit();
	}
}
function highlight_validation(CntrlName)
{
	with(document.add_sampleform)
	{
		document.getElementById("text_samplenum").className="textbox250";
		document.getElementById("text_sampledesc").className="textarea";
		if(CntrlName=="text_samplenum")
		{
		document.getElementById("text_samplenum").className="textbox250_error";
		}

		if(CntrlName=="text_sampledesc")
		{
		document.getElementById("text_sampledesc").className="textarea_error";
		}
	}
}
function enter_key_for_frm_sample(e)
{
  if(e.keyCode==13)
  {
	if (navigator.appName=="Netscape")
   {
	e.preventDefault();
   }
   else
	e.keyCode=0;
	 fun_addsample();
  }
}

function enter_key_for_frm_shipping(e){
  if(e.keyCode==13)
  {
	if (navigator.appName=="Netscape")
   {
	e.preventDefault();
   }
   else
	e.keyCode=0;
	 validate_shipping();
  }
}

function validate_category()
{
	with(document.FormCategory)
	{
		if(trimAll(category.value)=="")
		{
			alert("Please enter the category");
			category.value="";
			category.focus();
			return false;
		}
	}
}
function fun_addtest()
{
	
	with(document.addtest_form)
	{
		if(trimAll(text_code.value)=="")
		{
			alert("Please enter the test code");
			text_code.focus();
			return false;
		}
		else if(test_category.value=="")
		{
			alert("Please select the Category");
			test_category.focus();
			return false;
		}
		else if(trimAll(text_desc.value)=="")
		{
			alert("Please enter the test description");
			text_desc.focus();
			return false;
		}
		else if(trimAll(text_duration.value)=="")
		{
			alert("Please enter the test duration");
			text_duration.focus();
			return false;
		}
	}
}
function disp_test_list(catid)
{
	var rowid="testtr"+catid;
	if(document.getElementById(rowid).style.display=="none")
		document.getElementById(rowid).style.display="";
	else if(document.getElementById(rowid).style.display=="")
		document.getElementById(rowid).style.display="none";
}

function fun_selecttest()
{
	with(document.test_selectform)
	{
	
		 cat_num  = Hdn_cat.value;
		 chk_watch=false;
	  for(j=1;j<cat_num;j++)
		{
		   test_num =document.getElementById("Hdn_cat_sub_count"+j).value;
		   for(i=1;i<test_num;i++)
			{
		        if(document.getElementById("check_test"+j+i).checked==true)
				{
				  chk_watch=true;
				 }
			}
           
		}
		
           if(chk_watch==false)
			{
			   alert("Please select atleast one test to proceed");
			   return false;
			}
			else
			{  
			  Hdn_select.value="add";
			  submit();
			}
	}
}

function fun_verify()
{
   with(document.verify_testform)
	{
	 rad_verifylen =rad_verify.length;
    
	 Hdn_verify.value = "update";
	 submit();
	 
	 }
}

function fun_update()
{
   with(document.verify_testform)
	{
	 rad_verifylen =rad_verify.length;
	 Hdn_update.value = "continue";
	 submit();
	 
	 }
}
function fun_cart(TotSample)
{
	with(document.test_cartform)
	{
		if(TotSample<=0 && rad_cart[1].checked==true)
		{
			alert("There is no sample added for the test. Please add a sample and try again.");
			return false;
		}
		else
		{
			Hdn_cart.value = "update";
			submit();
		}
	}
}

function fun_delcart(sample_id)
{
   with(document.test_cartform)
	{
      var del_confirm=confirm("Are you sure to delete this sample?");
	  if(del_confirm ==true)
		{
		  Hdn_test.value = "delete";
		 // Hdn_code.value=test_code;
		  Hdn_sample.value=sample_id;
		  submit();
		}
	 
	 }
}
function validate_shipping()
{
	with(document.FormShipping)
	{
		if(trimAll(text_first.value)=="")
		{
			alert("Please enter your first name");
			text_first.value="";
			text_first.focus();
			return false;
		}
		if(trimAll(text_last.value)=="")
		{
			alert("Please enter your last name");
			text_last.value="";
			text_last.focus();
			return false;
		}
		else if(trimAll(address1.value)=="")
		{
			alert("Please enter address 1");
			address1.value="";
			address1.focus();
			return false;
		}
		else if(trimAll(city.value)=="")
		{
			alert("Please enter your city");
			city.value="";
			city.focus();
			return false;
		}
		else if(state.value=="")
		{
			alert("Please enter your state");
			state.value="";
			state.focus();
			return false;
		}
		else if(trimAll(country.value)=="")
		{
			alert("Please enter your country");
			country.value="";
			country.focus();
			return false;
		}
		else if(trimAll(zip.value)=="")
		{
			alert("Please enter the zip code");
			zip.value="";
			zip.focus();
			return false;
		}
		else if(trimAll(text_email.value)=="")
		{
			alert("Please enter the Email address");
			text_email.value="";
			text_email.focus();
			return false;
		}
		else if(!validateEmail(text_email.value))
		{
			alert("Please enter the Valid Email address");
			text_email.value="";
			text_email.focus();
			return false;
		}
		else if(trimAll(phone.value)=="")
		{
			alert("Please enter the Phone nember");
			phone.value="";
			phone.focus();
			return false;
		}
		else if(trimAll(company.value)=="")
		{
            alert("Please enter the Company Name");
			company.value="";
			company.focus();
			return false;
		}
		else if((chk_email.checked==false) && (chk_fax.checked==false) && (chk_mail.checked==false) && trimAll(ship_other.value)=="")
			{
				alert("Please choose an option to receive your Test Results");
				chk_email.focus();
				return false;
			}
		 else if(chk_fax.checked==true && trimAll(text_fax.value)=="")
			{
              alert("Please enter the fax number");
			  text_fax.focus();
			  return false;
			}
		 else if(trimAll(width.value)=="")
			{
			alert("Please enter the width");
			width.value="";
			width.focus();
			return false;
			}
		else if(trimAll(height.value)=="")
		{
			alert("Please enter the height");
			height.value="";
			height.focus();
			return false;
		}
		else if(trimAll(length.value)=="")
		{
			alert("Please enter the length");
			length.value="";
			length.focus();
			return false;
		}
		else if(trimAll(weight.value)=="")
		{
			alert("Please enter the weight");
			weight.value="";
			weight.focus();
			return false;
		}
		else
		{
			browser = navigator.appName;
			ie = "Microsoft Internet Explorer";
			os = navigator.platform;
			if (browser ==  ie)
			{
				var totheight = document.getElementById("totcontent").offsetHeight;
				var totwidth = document.getElementById("totcontent").offsetWidth;
			}
			else
			{
				var totheight = document.getElementById("totcontent").clientHeight;
				var totwidth = document.getElementById("totcontent").clientWidth;
			}
			document.getElementById('totaldiv').style.height=totheight;
			document.getElementById('totaldiv').style.width=totwidth;	
			document.getElementById('totaldiv').className="totaldiv_bg";
			document.getElementById('processback').className="shipping_bg";
			document.getElementById('processback').style.display="";
			document.getElementById('country').style.display="none";
			document.getElementById('state').style.display="none";
			strPostRegData = "address1="+address1.value+"&address2="+address2.value+"&city="+city.value+"&state="+state.value+"&country="+country.value+"&zip="+zip.value+"&width="+width.value+"&height="+height.value+"&weight="+weight.value+"&length="+length.value;
			url="ajax/shippingprocess.php";
			
			//Does URL begin with http?
			if(url.substring(0, 4) != 'http')
			{
				url = base_url + url;
			}
			if(window.XMLHttpRequest)
				http_req = new XMLHttpRequest();
			else if(window.ActiveXObject)
				http_req = new ActiveXObject("Microsoft.XMLHTTP");
			if(http_req)
			{
				http_req.onreadystatechange = function()
				{
					if(http_req.readyState== 4)
					{
						var strResponseTxt= trimAll(http_req.responseText);
						var array = strResponseTxt.split("<=>");
						var finalvalue = array[array.length - 1];
						var finalvalue1 = finalvalue.toLowerCase();


						document.getElementById("text_first").className	="textbox220";
						document.getElementById("text_last").className	="textbox220";
						document.getElementById("address1").className	="textbox220";
						document.getElementById("address2").className	="textbox220";
						document.getElementById("city").className		="textbox220";
						document.getElementById("zip").className		="textbox220";
						document.getElementById("text_email").className	="textbox220";
						document.getElementById("company").className	="textbox220";
						document.getElementById("width").className		="textbox220";
						document.getElementById("height").className		="textbox220";
						document.getElementById("length").className		="textbox220";
						document.getElementById("weight").className		="textbox220";
						document.getElementById("state").className		="select220";
						document.getElementById("country").className	="select220";
						document.getElementById("phone").className		="textbox220";
						document.getElementById("ship_other").className	="textbox220";
						document.getElementById("text_fax").className	="textbox220";

						document.getElementById('SelectShippingTd').innerHTML=strResponseTxt;
						document.getElementById('totaldiv').className="";
						document.getElementById('processback').className="";
						document.getElementById('totaldiv').style.height='';
						document.getElementById('processback').style.display="none";

						document.getElementById('country').style.display="";
						document.getElementById('state').style.display="";


						if(finalvalue1=="Error")
						{
							document.getElementById('SelectShippingTd').className="error_message";
						}
						else
						{
							document.getElementById('shippingdetail1').focus();
							document.getElementById('FirstSubmit').style.display='none';
						}
					}
				};
				http_req.open("POST", url, true);
				http_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
				http_req.send(strPostRegData);
			}
		}
	}
}
function highlight_shipping(CntrlName)
{
  with(document.FormShipping)
	{
	  document.getElementById("text_first").className  ="textbox220";
	  document.getElementById("text_last").className   ="textbox220";
	  document.getElementById("address1").className    ="textbox220";
	  document.getElementById("address2").className    ="textbox220";
	  document.getElementById("city").className        ="textbox220";
	  document.getElementById("zip").className         ="textbox220";
	  document.getElementById("text_email").className  ="textbox220";
	  document.getElementById("company").className     ="textbox220";
	  document.getElementById("width").className       ="textbox220";
	  document.getElementById("height").className      ="textbox220";
	  document.getElementById("length").className      ="textbox220";
	  document.getElementById("weight").className      ="textbox220";
	  document.getElementById("state").className       ="select220";
	  document.getElementById("country").className     ="select220";
	  document.getElementById("phone").className       ="textbox220";
	  document.getElementById("ship_other").className  ="textbox220";
	  document.getElementById("text_fax").className  ="textbox220";

	  	if(CntrlName=="state" || CntrlName=="country")
			document.getElementById(CntrlName).className="select220_error";
		else
			document.getElementById(CntrlName).className="textbox220_error";
	}
}
function pagetransfer(pagenumber,Formname)
{
	with(document.forms[Formname])
	{
  
		HdnPage.value	= pagenumber;
		Hidmode.value	= "paging";

		submit();
		
	}
}
function validateShppingDetails(totradio)
{
	with(document.FormShipping)
	{
		for(var i=1;i<=totradio;i++)
		{
			var ischecked	= "false";
			var shippingradio = "shippingdetail"+i;
			if(document.getElementById(shippingradio).checked==true)
			{
				ischecked = "true";
				document.getElementById('HdnShippingDet').value=document.getElementById(shippingradio).value;
			}
		}
		submit();
	}
}
function print_label(labelname,ship_id)
{
	with(document.FormShippingSuccess)
	{
		window.open(base_url+"popupprintlabel.php?labelname="+labelname+"&ship_id="+ship_id,'popupprintlabel', 'menubar=no,status=no,width=900,height=650,toolbar=no,left=10,top=10,scrollbars=yes');
	}
}
function print_label_function(ship_id)
{
	document.getElementById('buttontr').style.display="none";
	window.print();
	//document.getElementById('buttontr').style.display="";
	//parent.window.location.reload(); 
	//window.opener.location.href ='payment.php?ship_id='+ship_id;
	//self.close();
}

function print_details(sess_id)
{
	window.open(base_url+"popupdetails.php?sess_id="+sess_id,'popupprintlabel','menubar=no,status=no,width=900,height=650,toolbar=no,left=10,top=10,scrollbars=yes');
}
function funcValidateCreditCardNum(CreditCardNum)
{
	var ccNumb=CreditCardNum;
	var valid = "0123456789";
	var len = ccNumb.length;  
	var iCCN = parseInt(ccNumb);  
	
	var sCCN = ccNumb.toString();  
	sCCN = sCCN.replace (/^\s+|\s+$/g,'');  
	var iTotal = 0;  
	var bNum = true;  
	var bResult = false;  
	var temp;  // temp variable for parsing string
	var calc;  // used for calculation of each digit


	// ccNumb is a number and the proper length - let's see if it is a valid card number
	if(len >= 13 && len <=16)
	{  // 15 or 16 for Amex or V/MC					
			for(var i=len;i>0;i--)
				{  // LOOP throught the digits of the card
					  calc = parseInt(iCCN) % 10;  // right most digit
					  calc = parseInt(calc);  // assure it is an integer
					  iTotal += calc;  // running total of the card number as we loop - Do Nothing to first digit
					  i--;  // decrement the count - move to the next digit in the card
					  iCCN = iCCN / 10;                               // subtracts right most digit from ccNumb
					  calc = parseInt(iCCN) % 10 ;    // NEXT right most digit
					  calc = calc *2;                                 // multiply the digit by two
					  // Instead of some screwy method of converting 16 to a string and then parsing 1 and 6 and then adding them to make 7,
					  // I use a simple switch statement to change the value of calc2 to 7 if 16 is the multiple.
					  switch(calc)
					  {
						case 10: calc = 1; break;       //5*2=10 & 1+0 = 1
						case 12: calc = 3; break;       //6*2=12 & 1+2 = 3
						case 14: calc = 5; break;       //7*2=14 & 1+4 = 5
						case 16: calc = 7; break;       //8*2=16 & 1+6 = 7
						case 18: calc = 9; break;       //9*2=18 & 1+8 = 9
						default: calc = calc;           //4*2= 8 &   8 = 8  -same for all lower numbers
					  }                                               
					iCCN = iCCN / 10;  // subtracts right most digit from ccNum
					iTotal += calc;  // running total of the card number as we loop
				}  // END OF LOOP
		  if(! ((iTotal%10)==0))
			{
				return false;
			}	
	}	
	else
	{
		return false;
	}
}
function validate_payment()
{
  with(document.payment_form)
	{
        var now	= new Date();
	    var current_year	=now.getFullYear();
	    var current_month	=now.getMonth();
		if(trimAll(text_first.value)=="")
		{
			alert("Please enter the first name");
			text_first.focus();
			return false;
		}
		if(trimAll(text_last.value)=="")
		{
			alert("Please enter the last name");
			text_last.focus();
			return false;
		}
		if(trimAll(text_address1.value)=="")
		{
			alert("Please enter the Address");
			text_address1.focus();
			return false;
		}
		if(trimAll(text_city.value)=="")
		{
			alert("Please enter the City");
			text_city.focus();
			return false;
		}
		if(trimAll(select_state.value)=="")
		{
			alert("Please select the State");
			select_state.focus();
			return false;
		}
		if(trimAll(select_country.value)=="")
		{
			alert("Please select the Country");
			select_country.focus();
			return false;
		}
		if(trimAll(text_zip.value)=="")
		{
			alert("Please enter the Zipcode");
			text_zip.focus();
			return false;
		}
		if(trimAll(text_phone.value)=="")
		{
			alert("Please enter the Phone number");
			text_phone.focus();
			return false;
		}
		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 if(select_card.value=="")
		{
          alert("Please select the card type");
			text_email.focus();
			return false;
		}
		else if(trimAll(text_card.value)=="")
		{
			alert("Please enter the card number");
			text_card.focus();
			return false;
		}
		else if(expiry_month.value=="")
		{
           alert("Please select Card expiration month");
           expiry_month.focus();
		   return false;
		}
		else if(expiry_year.value=="")
		{
           alert("Please select Card expiration Year");
           expiry_year.focus();
		   return false;
		}
		else if(trimAll(text_ccv.value)=="")
		{
          alert("Please enter the card verification number");
		  text_ccv.focus();
		  return false;
		}
		else if((expiry_year.value == current_year)&&(expiry_month.value <= current_month))
		{
			alert("Please provide valid Expiry details");
			expiry_year.focus();
			return false;
		}
		if(chk_terms.checked==false)
		{
			alert("You must agree to Terms and conditions");
			chk_terms.focus();
			return false;
		}
		else
		{
			Hdn_payment.value="update";
			submit();
		}

	}
}
function highlight_payment(CntrlName)
{
  with(document.payment_form)
	{
	  document.getElementById("text_first").className       ="textbox220";
	  document.getElementById("text_last").className        ="textbox220";
	  document.getElementById("text_address1").className    ="textbox220";
	  document.getElementById("text_address2").className    ="textbox220";
	  document.getElementById("text_city").className        ="textbox220";
	  document.getElementById("text_zip").className         ="textbox220";
	  document.getElementById("text_phone").className       ="textbox220";
	  document.getElementById("text_email").className       ="textbox220";
	  document.getElementById("text_card").className        ="textbox220";
	  document.getElementById("text_ccv").className         ="textbox220";
	  document.getElementById("select_state").className     ="select220";
	  document.getElementById("select_country").className   ="select220";
	  document.getElementById("select_card").className      ="select220";
	  document.getElementById("expiry_month").className      ="selectexp";
	  document.getElementById("expiry_year").className      ="selectexp";
      
	  if(CntrlName=="text_first")
		{
		document.getElementById("text_first").className="textbox220_error";
		}
		if(CntrlName=="text_last")
		{
		document.getElementById("text_last").className="textbox220_error";
		}
		if(CntrlName=="text_address1")
		{
		document.getElementById("text_address1").className="textbox220_error";
		}
		if(CntrlName=="text_address2")
		{
		document.getElementById("text_address2").className="textbox220_error";
		}
		if(CntrlName=="text_city")
		{
		document.getElementById("text_city").className="textbox220_error";
		}
		if(CntrlName=="text_zip")
		{
		document.getElementById("text_zip").className="textbox220_error";
		}
		if(CntrlName=="text_phone")
		{
		document.getElementById("text_phone").className="textbox220_error";
		}
		if(CntrlName=="text_ccv")
		{
		document.getElementById("text_ccv").className="textbox220_error";
		}
		if(CntrlName=="text_card")
		{
		document.getElementById("text_card").className="textbox220_error";
		}
		if(CntrlName=="text_email")
		{
		document.getElementById("text_email").className="textbox220_error";
		}
		if(CntrlName=="select_state")
		{
		document.getElementById("select_state").className="select220_error";
		}
		if(CntrlName=="select_country")
		{
		document.getElementById("select_country").className="select220_error";
		}
		if(CntrlName=="select_card")
		{
		document.getElementById("select_card").className="select220_error";
		}
		if(CntrlName=="expiry_month")
		{
		document.getElementById("expiry_month").className="selectexp_error";
		}
		if(CntrlName=="expiry_year")
		{
		document.getElementById("expiry_year").className="selectexp_error";
		}
	}
}
function enter_key_for_frm_payment(e){
  if(e.keyCode==13)
  {
	if (navigator.appName=="Netscape")
   {
	e.preventDefault();
   }
   else
	e.keyCode=0;
	 validate_payment();
  }
}
function fun_update()
{
	with(document.add_sampleform)
	{
		Hdn_edit.value= "update";
		submit();
	}
}

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_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_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_shipment(ship_id)
{
	with(document.payment_form)
	{
		/*url ="ajax/paymentprocess.php?mode=add&ship_id="+ship_id.value;
			if(url.substring(0, 4) != 'http') 
			{
				url = base_url + url;
			}
			  http_req1 = null;

			  if (window.XMLHttpRequest)     http_req1 = new XMLHttpRequest();
			  else if (window.ActiveXObject) http_req1 = new ActiveXObject("Microsoft.XMLHTTP");

			if(http_req1)
			{
				http_req1.onreadystatechange = Add_paymentprocess;
				http_req1.open("GET", url, true);
				http_req1.send("");
			} */
			Hdn_information.value="shipping";
		submit();
	}
}
function  Add_paymentprocess()
{
	with(document.payment_form)
	{
		if(http_req1.readyState == 4)
		{
			var ResposeInfo,temp;
			ResposeInfo = http_req1.responseText;
		}
	}
}
function fun_dispother()
{
	with(document.FormShipping)
	{
		if(document.getElementById("other_option").style.display=="")
		  document.getElementById("other_option").style.display="none";
		else
			document.getElementById("other_option").style.display="";

		document.getElementById('chk_email').checked=false;
		document.getElementById('chk_mail').checked=false;
		document.getElementById('chk_fax').checked=false;
		document.getElementById("disp_fax").style.display="none";
	}
}

function fun_dispfax()
{
	with(document.FormShipping)
	{
		if(document.getElementById("disp_fax").style.display=="")
		  document.getElementById("disp_fax").style.display="none";
		else
			document.getElementById("disp_fax").style.display="";
	}
	document.getElementById('chk_email').checked=false;
	document.getElementById('chk_mail').checked=false;
	document.getElementById('chk_other').checked=false;
	document.getElementById("other_option").style.display="none";
}

function fun_distinct_check(chk_value)
{
	with(document.FormShipping)
	{
		document.getElementById('chk_fax').checked=false;
		document.getElementById('chk_other').checked=false;
		document.getElementById("other_option").style.display="none";
		document.getElementById("disp_fax").style.display="none";
		if(chk_value=='chk_email')
			document.getElementById('chk_mail').checked=false;
		else if(chk_value=='chk_mail')
			document.getElementById('chk_email').checked=false;
	}
}

function validate_skip_shipping()
{
	with(document.FormShipping)
	{
		if(trimAll(text_first.value)=="")
		{
			alert("Please enter your first name");
			text_first.value="";
			text_first.focus();
			return false;
		}
		if(trimAll(text_last.value)=="")
		{
			alert("Please enter your last name");
			text_last.value="";
			text_last.focus();
			return false;
		}
		else if(trimAll(address1.value)=="")
		{
			alert("Please enter address 1");
			address1.value="";
			address1.focus();
			return false;
		}
		else if(trimAll(city.value)=="")
		{
			alert("Please enter your city");
			city.value="";
			city.focus();
			return false;
		}
		else if(state.value=="")
		{
			alert("Please enter your state");
			state.value="";
			state.focus();
			return false;
		}
		else if(trimAll(country.value)=="")
		{
			alert("Please enter your country");
			country.value="";
			country.focus();
			return false;
		}
		else if(trimAll(zip.value)=="")
		{
			alert("Please enter the zip code");
			zip.value="";
			zip.focus();
			return false;
		}
		else if(trimAll(text_email.value)=="")
		{
			alert("Please enter the Email address");
			text_email.value="";
			text_email.focus();
			return false;
		}
		else if(!validateEmail(text_email.value))
		{
			alert("Please enter the Valid Email address");
			text_email.value="";
			text_email.focus();
			return false;
		}
		else if(trimAll(phone.value)=="")
		{
			alert("Please enter the Phone nember");
			phone.value="";
			phone.focus();
			return false;
		}
		else if((chk_email.checked==false) && (chk_fax.checked==false) && (chk_mail.checked==false) && trimAll(ship_other.value)=="")
			{
				alert("Please choose an option to receive your Test Results");
				chk_email.focus();
				return false;
			}
		 else if(chk_fax.checked==true && trimAll(text_fax.value)=="")
			{
              alert("Please enter the fax number");
			  text_fax.focus();
			  return false;
			}
		else
		{
			
			hdn_skp_shipping.value="skip";
			submit();
		}
	}
}

function fun_contact()
{
	with(document.contact_form)
	{
		if(trimAll(text_name.value)=="")
		{
			alert("Please enter your name");
			text_name.focus();
			return false;
		}
		else 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 Valid Email address");
			text_email.focus();
			return false;
		}
	   else if(trimAll(text_message.value)=="")
		{
		   alert("Please enter your message");
		   text_message.focus();
		   return false;
		}
		else
		{
			Hdn_send.value="submit";
			submit();
		}
	}
}

function enter_key_for_contact(e)
{
  if(e.keyCode==13)
  {
	if (navigator.appName=="Netscape")
   {
	e.preventDefault();
   }
   else
	e.keyCode=0;
	 fun_contact();
  }
}

function highlight_contact(CntrlName)
{
	with(document.contact_form)
	{
		document.getElementById("text_name").className="textbox250";
		document.getElementById("text_email").className="textbox250";
		document.getElementById("text_sub").className="textbox250";
		document.getElementById("text_message").className="textarea";
		if(CntrlName=="text_name")
		{
		document.getElementById("text_name").className="textbox250_error";
		}
        if(CntrlName=="text_email")
		{
		document.getElementById("text_email").className="textbox250_error";
		}
		if(CntrlName=="text_sub")
		{
		document.getElementById("text_sub").className="textbox250_error";
		}
		if(CntrlName=="text_message")
		{
		document.getElementById("text_message").className="textarea_error";
		}
	}
}