function  validateString( strValue ) {
 var objRegExp  =  /(^[a-zA-Z]+$)/; 
  return objRegExp.test(strValue);
}

function  validatename(strValue) {
 var objRegExp  =  /(^[a-zA-Z\ ]+$)/; 
  return objRegExp.test(strValue);
}
function  validatehtml(strValue) {
 var objRegExp  =  /(^[a-zA-Z\()_*@\/]+$)/; 
  return objRegExp.test(strValue);
}
function validateNumeric( field ) {
/******************************************************************************
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);
	if(!objRegExp.test(field) || parseFloat(field) <= 0 || trimAll(field) == ""){
		   return 0;
	 }else{
			return 1;
	}
}
function validatephone(field) {
/******************************************************************************
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);
	if(!objRegExp.test(field) || parseFloat(field) <= 0 || trimAll(field) == ""){
		   return 0;
	 }else{
			return 1;
	}
}
function validateNumerical( field ) {
/******************************************************************************
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);
	if(!objRegExp.test(field) || parseFloat(field) == 0 || trimAll(field) == ""){
		   return 0;
	 }else{
			return 1;
	}
}
function  validate_bannerNumeric( field ) {
/******************************************************************************
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);
	if(!objRegExp.test(field) || parseFloat(field) < 0 || trimAll(field) == ""){
		   return 0;
	 }else{
			return 1;
	}
}
function  validate_Numeric( 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 parseCurrency(field)
     {
          var currency = /^\d*(?:\.\d{0,2})?$/;
          
          if(!currency.test(field) || parseFloat(field) <= 0 || trimAll(field) == "")
          {
               return 0;
          }else{
				return 1;
		}
     }

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 popUp(URL,WIDTH,HEIGHT) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,"+WIDTH+","+HEIGHT+"');");
}

function validateEmail(field) {
    var regex=/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i;
    return (regex.test(field)) ? true : false;
}

function validateEmail_old( strValue) {
  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_old( 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_net(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		 //  alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		//   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		//    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		  //  alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		//    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		 //   alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.lastIndexOf(dot) == (str.length-1)){
//		   alert("Invalid E-mail ID")
		    return false
		 }


 		 return true					
	}

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:999-999999999
   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 validateUrl_old(strValue) { 
	var objRegExp=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}$/;
	return objRegExp.test(strValue);
} 

function validateUrl(strValue) { 
	var objRegExp;
	var returnvalue;
	objRegExp = /^([a-z0-9_\-\.]*)([a-z0-9_\-])$/;

	if(objRegExp.test(strValue) == true){
		
		var StringValue = strValue.substring(0,4);
		var strArr = strValue.split(".");
		var ArrLen = strArr.length;
		if((StringValue == "www." || StringValue == "WWW.") && ArrLen == 2){
			returnvalue = false;
		}else if(ArrLen < 2){
			objRegExp=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}$/;

			returnvalue = objRegExp.test(strValue);
			
		}else{
			returnvalue = true;
			
		}
	}else{
			objRegExp=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}|(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}(\/)$/;

			returnvalue = objRegExp.test(strValue);
	}

	return returnvalue;
} 


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

function validURL(url){
    var RegExp = /^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/;
    if(RegExp.test(url)){
        return true;
    }else{
        return false;
    }
} 

function validateUrls(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 validateadUrl(strValue){ 
	var objRegExp;
	var returnvalue;
	objRegExp = /^([a-z0-9_\-\.]*)([a-z0-9_\-])$/;

	if(objRegExp.test(strValue) == true){

		var StringValue = strValue.substring(0,4);
		var strArr = strValue.split(".");
		var ArrLen = strArr.length;
		if((StringValue == "www." || StringValue == "WWW.") && ArrLen == 2){
			returnvalue = false;
		}else if(ArrLen < 2){
			objRegExp=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}$/;

			returnvalue = objRegExp.test(strValue);
		}else{
			returnvalue = true;
		}
	}else{
			objRegExp=/^(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}|(http:\/\/www.|https:\/\/www.|ftp:\/\/www.|www.|http:\/\/|https:\/\/){1}([\w]+)(.[\w]+){1,2}(\/)$/;

			returnvalue = objRegExp.test(strValue);
	}

	return returnvalue;
} 

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 IsvalidURL(imageURL)
{
		

		lengthValue = trimAll(imageURL);
		lengthValue = lengthValue.length;
		if(lengthValue != 0)
		{
		var j = new RegExp();
		j.compile("^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+");             
		lengthValue = trimAll(imageURL);
	
		if (!j.test(lengthValue))
		{
			return false;
		}
		else
		{
			return true;
		}
		}
	
}

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 for validating credit card number

function is_valid_credit_card_number(cardNumber, cardType)//sample card type visa no 4992739871642 
{
	//alert(cardType);
	//alert(cardNumber);
  var isValid = false;
  var ccCheckRegExp = /[^\d ]/;
  isValid = !ccCheckRegExp.test(cardNumber);

  if (isValid)
  {
    var cardNumbersOnly = cardNumber.replace(/ /g,"");
    var cardNumberLength = cardNumbersOnly.length;
    var lengthIsValid = false;
    var prefixIsValid = false;
    var prefixRegExp;

    switch(cardType)
    {
      case "mastercard","MasterCard":
        lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^5[1-5]/;
        break;

      case "visa","Visa":
        lengthIsValid = (cardNumberLength == 16 || cardNumberLength == 13);
        prefixRegExp = /^4/;
        break;

      case "amex","Amex":
        lengthIsValid = (cardNumberLength == 15);
        prefixRegExp = /^3(4|7)/;
        break;
	  case "discover","Discover":
		lengthIsValid = (cardNumberLength == 16);
        prefixRegExp = /^6011/;
        break;  
      default:
        prefixRegExp = /^$/;
        alert("Card type not found");
    }

    prefixIsValid = prefixRegExp.test(cardNumbersOnly);
    isValid = prefixIsValid && lengthIsValid;
  }

  if (isValid)
  {
    var numberProduct;
    var numberProductDigitIndex;
    var checkSumTotal = 0;

    for (digitCounter = cardNumberLength - 1; 
      digitCounter >= 0; 
      digitCounter--)
    {
      checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
      digitCounter--;
      numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
      for (var productDigitCounter = 0;
        productDigitCounter < numberProduct.length; 
        productDigitCounter++)
		{
        checkSumTotal += 
          parseInt(numberProduct.charAt(productDigitCounter));
      }
    }

    isValid = (checkSumTotal % 10 == 0);
  }
  //isValid=true;
   alert(isValid);
  return isValid;
}

//to check for numeric
function IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
		 {
			IsNumber = false;
		 }
      }
   return IsNumber;
}
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 addOption(selectbox,text,value )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
selectbox.options.add(optn);
}
//load states for depends upon the selection of country using ajax starts hare.
function load_states_old(formname,fname)
{
	with(document.forms[formname])
	{
		var countryval = sel_country.value;
		poststr="mode=chosestate&country="+ encodeURI(countryval);
		ajaxpack.postAjaxRequest(fname,poststr, processchoosestate, "txt");
	}
}

function select_states(formname)
{
	ProfileHighlightValidation('countryCode');
	with(document.forms[formname])
	{	
		var countryval = countryCode.value;
		url = "ajax/check_user.php?countryCode="+countryval+"&State="+dftState.value+"&Country="+dftcountry.value+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		
		http_req = null;

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

		if (http_req)
		{
			http_req.onreadystatechange = processchoosestateprofile;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}


function loadstates(formname)
{
	register_highlightvalidation('countryCode');
	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[formname])
	{
		var countryval = sel_country.value;
		url = "ajax/ajax_state_country_action.php?countryCode="+countryval+"&From=Register";
		
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		
		http_req = null;
		
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = processchoosestateregister;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}

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

	if(formname == 'EventAdd'){
		var From	=	"Events";
	}
	else if(formname == 'GarageAdd'){
		var From	=	"Garages";
	}
	with(document.forms[formname])
	{
		var countryval	=	sel_country.value;
		url				=	"ajax/ajax_state_country_action.php?countryCode="+countryval+"&From="+From;

		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url		=	site_url + url;
		}
		
		http_req	=	null;
		
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = processchoosestateregister;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}

function processchoosestateregister()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;
		txt = http_req.responseText;
		document.getElementById('regState').innerHTML = txt;
		document.getElementById('sel_country').className	=	'select_normal';
		document.getElementById('td_country').className		=	'img_right';
		document.getElementById('td_country').innerHTML		=	"";
	}	
}
function processchoosestateprofile()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
			
		document.getElementById('ProfileState').innerHTML = txt;
	}	
}
function removeAllOptions(ctrlname)
{
	document.getElementById(ctrlname).options.length = 0;
}
function processchoosestate()
{
	var myajax=ajaxpack.ajaxobj
	var myfiletype=ajaxpack.filetype	
	if (myajax.readyState == 4){ 
	if (myajax.status==200 || window.location.href.indexOf("http")==-1)
	{ 
		

		if (myfiletype=="txt")
		{
		
			dropdownlistresponse		=GetReuiredIdFromString("<dropdownlist>","</dropdownlist>",myajax.responseText);
			dropdownlistresponsevalue	=GetReuiredIdFromString("<dropdownlistvalue>","</dropdownlistvalue>",myajax.responseText);
			removeAllOptions('sel_state');
			addOption(document.getElementById("sel_state"),"--Select--", "");	
			
			if(dropdownlistresponse == 0)
			{
				document.getElementById("statedisp").style.display="none";
				document.getElementById("statedisptxt").style.display="";
			}
			else 
			{				
				var spiltstr=dropdownlistresponse.split("@@");
				var spiltstrval=dropdownlistresponsevalue.split("@@");
				for(var i=1;i<spiltstr.length;i++)
				{		
					addOption(document.getElementById("sel_state"), spiltstrval[i], spiltstr[i]);
				}
				document.getElementById("statedisptxt").style.display	="none";
				document.getElementById("statedisp").style.display		="";
				
			}
			postbackresponse=GetReuiredIdFromString("<reqid>","</reqid>",myajax.responseText);			
			setTimeout("divoff('loadingTr')",500);			
		}
		else
		myajax.responseXML;
	}
  }
}
function load_cities(formname,fname)
{
	with(document.forms[formname])
	{
		var stateval = sel_state.value;
		poststr="mode=chosecity&state="+ encodeURI(stateval);
		document.getElementById("ImgLoad").style.display="";
		ajaxpack.postAjaxRequest(fname,poststr, processchoosecity, "txt");
	}
}
// Checking for Register page

function checkuserAvailability(FormName)
{	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[FormName])
	{	
		url = "ajax/check_user.php?user_name="+txt_username.value+"&userID="+user_id.value+"&From=Register";
		
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;
	
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = process_username_availabilty;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}

function process_username_availabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.frm_register.hdn_username.value="no";
		}
		else
		{
			document.frm_register.hdn_username.value="yes";
		}
	}	
}
function checkemailAvailability(FormName)
{	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[FormName])
	{	
		url = "ajax/check_user.php?user_email="+txt_email.value+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;

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

		if (http_req)
		{
			if(FormName == 'refer_friend')
			{
				http_req.onreadystatechange = process_email_referavailabilty;
				http_req.open("GET", url, true);
				http_req.send("");
			}
			else
			{
				http_req.onreadystatechange = process_email_availabilty;
				http_req.open("GET", url, true);
				http_req.send("");
			}
		}
	}
}
function process_email_referavailabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.refer_friend.hdn_email.value="no";
		}
		else
		{
			document.refer_friend.hdn_email.value="yes";
		}
	}	
}
function process_email_availabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.frm_register.hdn_email.value="no";
		}
		else
		{
			document.frm_register.hdn_email.value="yes";
		}
	}	
}
function checkreferaluser(FormName)
{	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[FormName])
	{	
		url = "ajax/check_user.php?user_referal="+txt_referal.value+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = process_referal_availabilty;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}

function process_referal_availabilty()
{
	if(http_req.readyState == 4)
	{
		var reftxt,DisplayText;			
		reftxt = http_req.responseText;
		if(trimAll(reftxt)=='')
		{
			document.frm_register.hdn_referal.value="no";}
		else
		{	document.frm_register.hdn_referal.value=reftxt;}
	}	
}

function changeemailAvailability(FormName,userID)
{	
	with(document.forms[FormName])
	{	
		
		url = "ajax/check_user.php?user_email="+email.value+"&userID="+userID+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		emailhttp_req = null;
		
		if (window.XMLHttpRequest)     emailhttp_req = new XMLHttpRequest();
		else if (window.ActiveXObject) emailhttp_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (emailhttp_req)
		{
			emailhttp_req.onreadystatechange = process_chemail_availabilty;
			emailhttp_req.open("GET", url, true);
			emailhttp_req.send("");
		}
	}
}

function process_chemail_availabilty()
{
	if(emailhttp_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = emailhttp_req.responseText;
		
		if(txt==0)
		{
			document.frmprofile.hdn_email.value="no";
		}
		else
		{
			document.frmprofile.hdn_email.value="yes";
		}
	}	
}

function changeuserAvailability(FormName,userID)
{	

	with(document.forms[FormName])
	{	
		
		url = "ajax/check_user.php?user_name="+userName.value+"&userID="+userID+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		emailhttp_req = null;
		
		if (window.XMLHttpRequest)     emailhttp_req = new XMLHttpRequest();
		else if (window.ActiveXObject) emailhttp_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (emailhttp_req)
		{
			if(FormName == 'loginForm'){
				emailhttp_req.onreadystatechange = process_login;
			}else{
				emailhttp_req.onreadystatechange = process_chuser_availabilty;
			}
			emailhttp_req.open("GET", url, true);
			emailhttp_req.send("");
		}
	}
}
function process_login()
{
	if(emailhttp_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = emailhttp_req.responseText;
		
		
		if(txt==0)
		{
			document.loginForm.hdn_user.value="no";
		}
		else
		{
			document.loginForm.hdn_user.value="yes";
		}
	}	
}
function process_chuser_availabilty()
{
	if(emailhttp_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = emailhttp_req.responseText;
		
		if(txt==0)
		{
			document.frmprofile.hdn_user.value="no";
		}
		else
		{
			document.frmprofile.hdn_user.value="yes";
		}
	}	
}

function PasswordAvailability(FormName)
{	
	url			 = document.location.href;
	xend		 = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[FormName])
	{	
		
		url = "ajax/check_user.php?password="+password.value+"&userName="+userName.value+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		emailhttp_req = null;
		
		if (window.XMLHttpRequest)     emailhttp_req = new XMLHttpRequest();
		else if (window.ActiveXObject) emailhttp_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (emailhttp_req)
		{
			emailhttp_req.onreadystatechange = process_password;
			emailhttp_req.open("GET", url, true);
			emailhttp_req.send("");
		}
	}
}
function process_password()
{
	if(emailhttp_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = emailhttp_req.responseText;
		
		temp = txt.split('\getlogin');
		var status = temp[2];
		
		if(temp[1] == 0)
		{
			document.loginForm.hdn_pass.value="no";
			document.loginForm.status.value  =status;
		}
		else
		{
			document.loginForm.hdn_pass.value="yes";
			document.loginForm.status.value  =status;
		}
	}	
}


// Redirect to Payment selection page
function get_back(formname){

	with(document.forms[formname])
	{
			submit();
	}
}
// Redirect to Payment selection page
function call_ca(formname){

	with(document.forms[formname])
	{
		    process.value= paymenttypesel.value;
			action ="https://www.ccavenue.com/shopzone/cc_details.jsp";
			submit();
	}
}
// Redirect to Payment selection page
function call_mail(formname){

	with(document.forms[formname])
	{
		    process.value= paymenttypesel.value;
			submit();
	}
}
// Redirect to Payment selection page
function call_mb(formname){

	with(document.forms[formname])
	{
		    process.value = paymenttypesel.value;
			submit();
	}
}
// Redirect to Payment selection page
function call_gco(auction,formname){

	with(document.forms[formname])
	{
		   process.value= paymenttypesel.value;
			action = auction;
			submit();
	}
}
// Enter key validation for activation page
function enter_key_for_activation_page(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validatecode('activationform');
	  }
}
// Validate Activation Code
function validate_activation(ctrlname)
{
	with(document.activationform){
		if(ctrlname == 'txt_code'){
			if(trimAll(txt_code.value) == ""){
					document.getElementById('txt_code').className='textbox_error';
			}
			else if(hdnactivation.value=="yes")
			{
				document.getElementById('txt_code').className='textbox_error';
			}else{
					document.getElementById('txt_code').className='textbox_right';
			}
		}
	}
}
// Validate Activation Code


function process_activation()
{
	if(achttp_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = achttp_req.responseText;
		if(txt>0)
		{
			document.activationform.hdnactivation.value="yes";
		}
	}	
}


function autoCheck(index)
	{
		if(index!=-1)
			{
				document.openstore.storelogo[index].checked='true';
			}
	}

function showavatar(theURL) {
	
if (document.openstore.hostedImages.value == '*') {
return true;
}
autoCheck(3);
document.images.sample.src=theURL+document.openstore.hostedImages.options[document.openstore.hostedImages.selectedIndex].value;

}

function previewAllCustomLogo(fieldName,radioIndex)
	{
		if(document.getElementById(fieldName).value =='')
		{
			alert('Please enter logo URL');
		}else
		{
		switch(fieldName)
			{
				default:field=document.openstore.logoURL;
				imgField=document.images.custom;
			}

		var fieldValue=field.value;
		if(fieldValue&&imgField)
			{
				autoCheck(radioIndex);
				var imageUrl=field.value;
				var endIndex=imageUrl.length-1;
				imgField.height.value=90;imgField.width.value=310;
				if((imageUrl.indexOf('http://'))>=0)
					{
						imgField.src=imageUrl;
					}
				else
					{
						imgField.src='http://'+imageUrl;
					}
			}
		}
		return;
	}

	var imgRe = /^.+\.(jpg|jpeg|gif|png)$/i;

function previewImage(pathField, previewName)
{
	var path = pathField.value;
    if (path.search(imgRe) != -1)
    {   
        document[previewName].src = 'file://'+path;
    }       
    else    
    {   
        alert("JPG, PNG, and GIFs only!");
    }   
}

	function textCounter(field, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
}

function  containsURLCharacters( strValue ) {
 var objRegExp  =  /(^[a-zA-Z0-9]+$)/; 
  return objRegExp.test(strValue);
}
function  containssubCharacters( strValue ) {
 var objRegExp  =  /(^[a-zA-Z0-9\:\.\/\ ]+$)/;   
 return objRegExp.test(strValue);
}
function  containshtmlCharacters( strValue ) {
 var objRegExp  =   /(^[a-zA-Z0-9\:\/\,\;\'\"\ \|\!\(\)\ ]+$)/; 
 return objRegExp.test(strValue);
}
function text_Counter(field, maxlimit,name) {
if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
}
function  validate_urlcharacters( strValue ) {
 var objRegExp  =  /(^[a-zA-Z0-9\_\ ]+$)/; 
  return objRegExp.test(strValue);
}
//canceling store creation
function goback_estorehome(Formname)
{
	with(document.forms[Formname])
	{
		gobackhome.value="yes";
		submit();
	}
}


//validates open store page

function back_opn(formname)
{
	with(document.forms[formname])
	{
		backmodification.value="Yes";
		submit();
	}
}

// Enter key validation for open store page
function enter_key_for_addcat(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 addcategory('openstore','','');
	  }
}

//Update Sort Order in manage pages
function updatesortorder(Formname)
{
	var Err_Message = "";
	var ControlFocus = false;
	with(document.forms[Formname])
	{
			sortsuccess.value="yes";
			submit();
	}
}
//For Closing the store
function validateclose_store(Formname,stmt)
{
	var agree=confirm(stmt);
	with(document.forms[Formname])
	{
			if (agree) 
			{
				closesuccess.value="yes";
				submit();
			}
			else
			{
				return false ;
			}
			
	}
}

//Back to Manage stores page from promote store page
function goback_managestores(Formname)
{
	with(document.forms[Formname])
	{
		hdnback.value="Yes";
		submit();
	}
}

//Successful template updation
function changetemplate(Formname)
{
	var Err_Message = "";
	var ControlFocus = false;
	with(document.forms[Formname])
	{
		hdnedittemplate.value="Yes";
		submit();
	}
}

//Start Promoting items
function start_promote(Formname)
{
	with(document.forms[Formname])
	{
		startpromote.value="Yes";
		submit();
	}
}

//paging function
var nav4 = window.Event ? true : false;
function page_transfer(pagenumber)
{
	with(document.transaction_form)
	{
	
	HdnPage.value=pagenumber;
	Hidmode.value="paging";
	target="";
	submit();
	}
}

//cancel page creation
function cancel_pagecreation(Formname)
{
	with(document.forms[Formname])
	{
		cancelpageadd.value="Yes";
		submit();
	}
}

//enter key for create page

function fun_edit_image(Formname)
{
	with(document.forms[Formname])
	{
		edit_image.value="yes";
		submit();

	}

}

//validate Entering to shop page from adult warning
function setentry(Formname)
{
	with(document.forms[Formname])
	{
		warningsuccess.value="yes";
		submit();
	}
}

//function called for sorting in shop page while viewing gallery and catgeory page
function sort_list(Formname)
{
	with(document.forms[Formname])
	{
		search_success.value="yes";
		submit();
	}
}


// Validate Referal
function referal_highlightvalidation(CntrlName){
	var Err_Message = "";
	var ControlFocus = false;
	with(document.refer_friend)
	{
		if(CntrlName == 'txt_email')
		{
			if(trimAll(txt_email.value) == "")
			{
				document.getElementById('txt_email').className='textbox_error';
			}else if(!(validateEmail(trimAll(txt_email.value)))){
					document.getElementById('txt_email').className='textbox_error';
			}else{
					document.getElementById('txt_email').className='textbox_right';
			}
		}
			
	}
}


//Go back from payment page
function gobackform(Formname)
{
	with(document.forms[Formname])
	{
		goback.value="yes";
		action= site_url+"Register/";
		submit();
	}
}

function updatePasswordStrength(){
  var password = (document.frm_register.txt_password.value);
  var strength = 0;	 
  
 // ChanceOfGuessing: strings that should not be used in password
  var ChanceOfGuessing = new Array();
  ChanceOfGuessing.push('password'); // does this need to be localized?
  ChanceOfGuessing.push('A3EO1O5V2CR7N');

  var email_words = document.frm_register.txt_email.value.match(/\w+/g); // contiguous words contained in email	  
  if (email_words)
		 ChanceOfGuessing = ChanceOfGuessing.concat(email_words);
	if(document.frm_register.txt_username.value)
	 ChanceOfGuessing.push(document.frm_register.txt_username.value);

  locase_matches = password.match(/[a-z_]/g); // lowercase and '_' matches
  digit_matches = password.match(/[0-9]/g);   // numeric matches
  upcase_matches = password.match(/[A-Z]/g);  // uppercase matches
  special_matches = password.match(/\W/g);    // special matches (not in a-z, A-Z, 0-9, _)
   if (password.length>5)
  { // for less than 5, leave strength at 0 since password too short

		// 1 point for each character more than 5
		strength += password.length - 5;

	// 1 point for each upcase character mixed with lowercase
	if (locase_matches && upcase_matches)
	  strength += upcase_matches.length;

		// 1 point for each numeric character mixed with lowercase
	if (locase_matches && digit_matches)
	  strength += digit_matches.length;

	// 1 point for each special characters
		if (special_matches)
	  strength += special_matches.length;

   // 2 bonus points if mix of letters, numbers and special
	   if ((locase_matches || upcase_matches) && special_matches && digit_matches)
		 strength += 2;
  }

  // Reset strength to 0 if any easy guess in password (easy guess should be more than 3 chars)
  for (var i=0; i < ChanceOfGuessing.length; ++i)
  {
	   if (ChanceOfGuessing[i].length>3 && (password.indexOf(ChanceOfGuessing[i])!=-1))
	   { 
		 strength=0;
		 break;
	   }
   }
  	  if(password.length < 6){
		document.getElementById('txt_password').className='textbox_error';
	  }
	  else
		{
		  document.getElementById('txt_password').className='textbox_right';
		}
	  var pstrength_elem = document.getElementById('password_strength');
	  var pstrength_text = document.getElementById('password_strength_text');
	  if (password.length==0)
	  {
		pstrength_elem.className = 'password_empty';             
		pstrength_text.innerHTML = 'None';
	  }
	 else if (strength<3)
	  {
		pstrength_elem.className = 'password_weak';
		pstrength_text.innerHTML = 'Weak';
	  }
	  else if (strength<7)
	  {
		pstrength_elem.className = 'password_fair';
		pstrength_text.innerHTML = 'Fair';
	  }
	  else if (strength<10)
	  {
		pstrength_elem.className = 'password_good';
		pstrength_text.innerHTML = 'Good';
	  }
	  else
	  {
		pstrength_elem.className = 'password_strong';
		pstrength_text.innerHTML = 'Strong';
	  }
}


function updateAdPasswordStrength()
{
  var password = document.AdvertiserForm.pwd.value;
  var strength = 0;	 

 // ChanceOfGuessing: strings that should not be used in password
  var ChanceOfGuessing = new Array();
  ChanceOfGuessing.push('password'); // does this need to be localized?
  ChanceOfGuessing.push('PHPAUCTION');

  var email_words = document.AdvertiserForm.email.value.match(/\w+/g); // contiguous words contained in email	  
  if (email_words)
		 ChanceOfGuessing = ChanceOfGuessing.concat(email_words);
	if(document.AdvertiserForm.uname.value)
	 ChanceOfGuessing.push(document.AdvertiserForm.uname.value);

  locase_matches = password.match(/[a-z_]/g); // lowercase and '_' matches
  digit_matches = password.match(/[0-9]/g);   // numeric matches
  upcase_matches = password.match(/[A-Z]/g);  // uppercase matches
  special_matches = password.match(/\W/g);    // special matches (not in a-z, A-Z, 0-9, _)
  

  if (password.length>5)
  { // for less than 5, leave strength at 0 since password too short

		// 1 point for each character more than 5
		strength += password.length - 5;

	// 1 point for each upcase character mixed with lowercase
	if (locase_matches && upcase_matches)
	  strength += upcase_matches.length;

		// 1 point for each numeric character mixed with lowercase
	if (locase_matches && digit_matches)
	  strength += digit_matches.length;

	// 1 point for each special characters
		if (special_matches)
	  strength += special_matches.length;

   // 2 bonus points if mix of letters, numbers and special
	   if ((locase_matches || upcase_matches) && special_matches && digit_matches)
		 strength += 2;
  }

  // Reset strength to 0 if any easy guess in password (easy guess should be more than 3 chars)
  for (var i=0; i < ChanceOfGuessing.length; ++i)
  {
	   if (ChanceOfGuessing[i].length>3 && (password.indexOf(ChanceOfGuessing[i])!=-1))
	   { 
		 strength=0;
		 break;
	   }
   }
  

	  var pstrength_elem = document.getElementById('password_strength');
	  var pstrength_text = document.getElementById('password_strength_text');
	  if (password.length==0)
	  {
		pstrength_elem.className = 'password_empty';             
		pstrength_text.innerHTML = 'None';
	  }
	 else if (strength<3)
	  {
		pstrength_elem.className = 'password_weak';
		pstrength_text.innerHTML = 'Weak';
	  }
	  else if (strength<7)
	  {
		pstrength_elem.className = 'password_fair';
		pstrength_text.innerHTML = 'Fair';
	  }
	  else if (strength<10)
	  {
		pstrength_elem.className = 'password_good';
		pstrength_text.innerHTML = 'Good';
	  }
	  else
	  {
		pstrength_elem.className = 'password_strong';
		pstrength_text.innerHTML = 'Strong';
	  }
}

function fun_imagepreview(Formname)
{

   with(document.forms[Formname])
	{
	   Hdn_preview.value="yes";
	   submit();
	}
}
function fun_edit_template(Formname)
{
   with(document.forms[Formname])
	{
	   Edit_template.value="yes";
	   submit();
	}

}

function fun_edit_html(Formname)
{
   with(document.forms[Formname])
	{
	   Hdn_edit_tmpl.value="edit";
	   submit();
	}

}

function highlight_estore_search(CntrlName){
	
	var Err_Message = "";
	var ControlFocus = false;
	with(document.store_search)
	{
		if(CntrlName == 'searchstring')
		{
			if((trimAll(searchstring.value)!="")&&(!validatequotes(searchstring.value)))
			{
				document.getElementById('searchstring').className='textbox_error';
			}else{
					document.getElementById('searchstring').className='textbox_right';
			}
		}
		
	}
}
function fun_provide(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_provide.value="yes";
		submit();
	}
}

function fun_template(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_template.value="preview";
		submit();
	}
}
//onchage form submit for zipcode in catlisting page

function fun_zipsubmit(Formname)
{
	with(document.forms[Formname])
	{
		distance_success.value="save";  
		submit();
	}
}
function preview_save(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_save.value="yes";
		submit();
	}

}
function fun_member(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_cmd.value="save";
		submit();
	}
}



//Functions for checking the check boxes in category listing page starts
function buyingcheckbox(Formname)
{

	with(document.forms[Formname])
	{
		if(buyingoptions.value != "" ) 
		{ 
			buyingoptions_search.checked=true;
		}
	}
}
function Endingcheckbox(Formname)
{

	with(document.forms[Formname])
	{
		if(ending_methods.value != "" ) 
		{ 
			listings.checked=true;
		}
	}
}
function Endinghourcheckbox(Formname)
{

	with(document.forms[Formname])
	{
		if(ending_time.value != "" ) 
		{ 
			listings.checked=true;
		}
	}
}
function conditioncheckbox(Formname)
{

	with(document.forms[Formname])
	{
		if(item_conditions.value != "" ) 
		{ 
			items_condition.checked=true;
		}
	}
}
function pricecheckbox(Formname)
{

	with(document.forms[Formname])
	{
		if((min_price.value != "" ) ||(max_price.value != "" ))
		{ 
			items_price.checked=true;
		}
	}
}

function upload_images(formname,from,to)
{
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	var image = from.value;
	with(document.forms[formname])
	{
		url = "ajax/upload_image.php?imagepath="+image+"&From=Register";
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;

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

		if (http_req)
		{
			http_req.onreadystatechange = response_uploadimage;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}
function response_uploadimage()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		document.getElementById('replaceMe').innerHTML = txt;
	}	
}
//function for deleting pages
function fun_about_delete(FormName)
{
	with(document.forms[FormName])
	{
		var del_confirm=confirm("Are you sure want to delete this Page?");

		if(del_confirm==true)
		{
		Hdn_delete.value="delete";
		submit();
		}

	}

}

//function used for close listing
function fun_close_listing(FormName)
 {
   with(document.forms[FormName])
	{
	  Hdn_close.value="close";
       submit();
	}
 }

//validate Search by Location
function location_highlightvalidation(CntrlName){
	var Err_Message = "";
	var ControlFocus = false;
	with(document.zipform)
	{
		if(CntrlName == 'userZipCode')
		{
			if(trimAll(userZipCode.value)=="")
			{
				document.getElementById('userZipCode').className='textbox_error';
			}else if(!(validateNumeric(trimAll(userZipCode.value)))){
					document.getElementById('userZipCode').className='textbox_error';
			}else{
					document.getElementById('userZipCode').className='textbox_right';
			}
		}
		
		
		
	}
}

function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
}

function fun_upload_banner(Formname)
{
  with(document.forms[Formname])
	{
     if(trimAll(siteUrl.value)=="")
		{
		 alert("Enter the site URl");
         siteUrl.focus();
		 return false;
		}
		else if((validateUrl(siteUrl.value) == false))
		{
		}
		else if(trimAll(bannerTitle.value)=="")
		{
		 alert("Enter the Banner Title");
         bannerTitle.focus();
		 return false;
		}
		else if(trimAll(BannerDescription.value)=="")
		{
			alert("Enter the Banner Description");
			BannerDescription.focus();
		    return false;
		}
		OptionSelected = false;
	    Banner_Length = BannerOption.length;	
		for(var i=0;i < Banner_Length;i++)
		{
			if(BannerOption[i].checked==true)
			{
				OptionSelected=true;
				break;
			}
		}		
	   if(OptionSelected==false)
		{
			alert("Please select a banner image setup mode");
			BannerOption[0].focus();
			return false;
		}
		
		//var image_ary=trimAll(imgUpload.value);
		//alert(image_ary);
		//getImgSize(image_ary);
		//var newImg1 = new Image();
	     //newImg1.src = image_ary;
		 //alert(newImg1.src);
         //alert(newImg1.width + 'x' + newImg1.height);


       if(BannerZone.value=="")
		{
		   alert("Select the target zone for your banner.");
		   BannerZone.focus();
		   return false;
		}
		else 
		{
			Hdn_banner.value="create";
			submit();
		}

 
	}
}
function delete_banner(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_delbanner.value="ban_del";
		submit();
	}
}




function highlight_browse_search(CntrlName){
	var Err_Message = "";
	var ControlFocus = false;
	with(document.categorysearch)
	{
		if(CntrlName == 'searchstring')
		{
			if((trimAll(searchstring.value)!="")&&(!validatequotes(searchstring.value)))
			{
				document.getElementById('searchstring').className='textbox_error';
			}else{
					document.getElementById('searchstring').className='textbox_right';
			}
		}
		
	}
}
//Mark or Unmark the inbox elements
function select_switch(status)
	{
		for (i = 0; i < document.form_inbox.length; i++)
		{
			document.form_inbox.elements[i].checked = status;
		}
	}
//Mark or Unmark the savebox elements
function select_saveswitch(status)
	{
		for (i = 0; i < document.form_savebox.length; i++)
		{
			document.form_savebox.elements[i].checked = status;
		}
	}
//Mark or Unmark the sentbox elements
function select_sentswitch(status)
	{
		for (i = 0; i < document.form_sentbox.length; i++)
		{
			document.form_sentbox.elements[i].checked = status;
		}
	}



// Checking for Private Message page
function checkuserexistance(FormName)
{	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[FormName])
	{	
		url = "ajax/check_user.php?user_referal="+sendTo.value+"&From=Register";
		
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;
	
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = process_username_exist;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}

function process_username_exist()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.compose.user_exist.value="no";
		}
		else
		{
			document.compose.user_exist.value="yes";
		}
	}	
}

//Go back to Members from Private Message
function gobackmembers(Formname)
{
	with(document.forms[Formname])
	{
		action= site_url+"Members/";
		submit();
	}
}
//Go back to Members from Private Message
function gobackinbox(Formname)
{
	with(document.forms[Formname])
	{
		action= site_url+"PrivateMessaging/";
		submit();
	}
}
//Reply from view messsage page
function reply_view(Formname)
{
	
	with(document.forms[Formname])
	{
		action= site_url+"PrivateMessaging/?view=compose&messageId="+messageID.value+"&reply="+senderID.value;
		submit();
	}
}
//to delete the message from message view page
function delete_message(Formname)
{

	with(document.forms[Formname])
	{
	 chk_del_alert=false;
	 if(delete_to.length == undefined )
	 {
		if(delete_to.checked==true)
			{
			  chk_del_alert=true;
			 }
	 }
	 else
	 {
		for(i=0;i<delete_to.length;i++)
		{
		 if(delete_to[i].checked==true)
			{
			  chk_del_alert=true;
			 }
		}
	 }
     if(chk_del_alert==false)
	 {
	   alert("<##del_msg_select##>");
	   return false;
	 }
	 else
	 {
	   if(confirm("<##del_confirm##>"))
	   {
		deletemessage.value="Yes";
		submit();
	   }
	   else
		return false;
	 }
	}

}
function fun_Update_banner(Formname)
{
	with(document.forms[Formname])
	{
		var Err_Message = "";
		var ControlFocus = false;
		OptionSelected = false;
	    Banner_Length = BannerOption.length;	
		for(var i=0;i < Banner_Length;i++)
		{
			if(BannerOption[i].checked==true)
			{
				OptionSelected=true;
				break;
			}
		}		
		if(OptionSelected==false)
		{
			alert("Please select a bannerimage setup mode");
			document.getElementById('option1_id').className='highlight_error';
			BannerOption[0].focus();
			return false;
		}
		else if(imgUpload.value=="")
		{
			alert("Please select an image to upload");
            imgUpload.focus();
			return false;
		}
		else
		{
			Hdn_update_banner.value="updt_banner";
			submit();
		}

	}
}
function update_banner_set(Formname)

{
	with(document.forms[Formname])
	{
		var Err_Message = "";
		var ControlFocus = false;
		if(trimAll(siteUrl.value)=="")
		{
			Err_Message += "Please enter the SiteUrl\n";
			if(ControlFocus == false)
			{
			siteUrl.focus();
			ControlFocus = true;
			document.getElementById('siteUrl').className='textbox_error';
			}
		}
		if(trimAll(bannerTitle.value)=="")
		{
			Err_Message += "Please enter the title\n";
			if(ControlFocus == false)
			{
			bannerTitle.focus();
			ControlFocus = true;
			document.getElementById('bannerTitle').className='textbox_error';
			}
		}
		 if(BannerDescription.value=="")
			{
				Err_Message += "Please enter the description\n";
				if(ControlFocus == false)
				{
				BannerDescription.focus();
				ControlFocus = true;
				document.getElementById('description_id').className='highlight_error';
				return false;
				}
			}
		if(Err_Message != "")
		{
			alert(Err_Message);
		}
	   else
		{
		   Hdn_site_banner.value="site_setup";
		   submit();
		}

	}

}
function highlight_banner(CntrlName)
{
	with(document.bannerForm)
	{
	if(CntrlName=='siteUrl')
		{
			if(trimAll(siteUrl.value) == ""){
				document.getElementById('siteUrl').className='textbox_error';
			}
			else{
				document.getElementById('siteUrl').className='textbox_right';
			}
		}
		if(CntrlName=='bannerTitle')
		{
			if(trimAll(bannerTitle.value) == ""){
				document.getElementById('bannerTitle').className='textbox_error';
			}
			else{
				document.getElementById('bannerTitle').className='textbox_right';
			}
		}
	}
}

function Submit_buyitnow(){
	with(document.BidForm){
		ActivateBuyItNow.value = "Y";
		submit();
	}
}
function Submit_offer(){
	with(document.SEOForm){
		BestOffer.value = "Y";
		submit();
	}
}

function submit_bidback(id){
		document.BidForm.back_confirm.value = id;
		if(id == 'Y'){
		document.BidForm.do_buy.value	     = "";
		}
		document.BidForm.submit();
	
}
// Enter key validation for offer page
function enter_key_for_make_offer(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_offer();
	  }
}


function show_address(Formname)
{
	with(document.forms[Formname])
	{
		document.getElementById('address_display').style.display="";
		document.getElementById('address_hide').style.display="none";

	}
}
function fun_updatedefault(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_update_address.value="default";
		submit();
	}

}

function pagetransfer(pagenumber,Formname)
{
	with(document.forms[Formname])
	{
		HdnPage.value	=	pagenumber;
		Hidmode.value	=	"paging";
		target			=	"";
		//action			= "";
		submit();
	}
}
//Additional paging function
function pageswap(pagenumber,Formname)
{
	with(document.forms[Formname])
	{
	HiddenPage.value=pagenumber;
	Hiddenmode.value="paging";
	submit();
	}
}


function highlight_searchfeedback(CntrlName)
{
	var Err_Message = "";
	var ControlFocus = false;
	with(document.FeedbackForm)
	{
		if(CntrlName=="search")
		{
			if(trimAll(search.value) == "")
			{
				document.getElementById('search').className='textbox_error';
			}
			else
			{
				document.getElementById('search').className='textbox_right';
			}
		}

	}
}


function enter_key_for_reply_feedback(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_replyfeedback();
	  }
}
function valid_additionalpaging(Form_name,Total_Pages){			
		with(document.forms[Form_name]){	
				
			if(!(validateNotEmpty(pageGo.value))){
				alert('Please Enter page number');
				pageGo.focus();
				return false;
			}
			else if(!(parseCurrency(trimAll(pageGo.value)))){
				alert('Please Enter valid page number');
				pageGo.focus();
				return false;
			}
			else if(pageGo.value > Total_Pages){
				alert('The Page doesnot exists');
				pageGo.focus();
				return false;
			}else{			pageswap(pageGo.value,Form_name);	
			return true;							}	
		}						
	}
	function enter_additionalpaging(e,Form_name,Total_Pages)
	{	
		if(nav4) 	
		{		var whichCode = e.which; 	 
		}
	 else
		 { 		
		 var whichCode = event.keyCode;	
		 }		
	if(whichCode == 13) 	{		
		if(valid_additionalpaging(Form_name,Total_Pages) == false)		
			{			
			return false;		
			}	
			}
	}

//function used to ban user



//function for the back button in the banner_bidders page
function fun_ban_back(Formname)
{
	with(document.forms[Formname])
	{
       Hdn_ban_back.value="bid_back";
	   submit();

	}
}


// Function to change the payment status 
function validate_savechanges(Formname)
{
	with(document.forms[Formname])
	{
		success_change.value="Yes";
	   submit();

	}
}

function enter_key_for_question(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_question();
	  }
}

// Function to send the feedabck reminder 
function validate_feedbackreminder(Formname)
{
	with(document.forms[Formname])
	{
       feedback_success.value="Yes";
	   submit();

	}
}
//function used to display the items based upon the selected days

function fun_show_listings(Formname)
{
	with(document.forms[Formname])
	{
		submit();
	}
}



function enter_key_for_help(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_help();
	  }
}


// Validate Contact Us payemnt
function contact_us_highlightvalidation(CntrlName){
	var Err_Message = "";
	var ControlFocus = false;
	with(document.frm_contactus){

		var EmailVal	 = trimAll(txt_email.value);
		var getEArr		 = EmailVal.split('@');
		var domainname	 = getEArr[1];
		
		if(CntrlName == 'txt_name'){
			if(trimAll(txt_name.value) == ""){
					document.getElementById('txt_name').className='textbox_error';
			}else if(!(containsURLCharacters(trimAll(txt_name.value)))){
					document.getElementById('txt_name').className='textbox_error';
			}else{
					document.getElementById('txt_name').className='textbox_right';
			}
		}

		if(CntrlName == 'txt_email'){
			
			if(trimAll(txt_email.value) == ""){
					document.getElementById('txt_email').className='textbox_error';
			}else if(!(validateEmail(trimAll(txt_email.value)))){
					document.getElementById('txt_email').className='textbox_error';
			}
			else{
					document.getElementById('txt_email').className='textbox_right';
			}
		}
		if(CntrlName == 'txt_message'){
			if(trimAll(txt_message.value) == ""){
					document.getElementById('td_message').className='highlight_error';
			}else{
					document.getElementById('td_message').className='right';
			}
		}
		
		
	}
}


/*Validation in Email Resend page Starts*/
function checkresendemailAvailability(FormName)
{	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	
	with(document.forms[FormName])
	{	
		url = "ajax/check_user.php?user_email="+useremail.value+"&userID="+hdnuserId.value+"&From=Register";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;

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

		if (http_req)
		{
				http_req.onreadystatechange = process_email_changeavailabilty;
				http_req.open("GET", url, true);
				http_req.send("");
		}
	}
}
function process_email_changeavailabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		
		if(txt==0)
		{
			document.activationform.hdn_email.value="no";
		}
		else
		{
			document.activationform.hdn_email.value="yes";
		}
	}	
}
function enter_key_emailChange(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 resendactivation('activationform');
	  }
}



function wantit_search(Formname)
{
	var Err_Message = "";
	var ControlFocus = false;
	with(document.forms[Formname])
	{
		if((trimAll(item_search.value)!="")&&(!validatequotes(item_search.value)))
		{
			Err_Message = "Please enter valid Search String\n";
				if(ControlFocus == false)
				{
					item_search.focus();
					ControlFocus = true;
				}
			document.getElementById('item_search').className='textbox_error';
		}
		if(Err_Message != "")
		{

			alert(Err_Message);
		}
	   else
		{
			success_search.value="Yes";
			submit();
		}
	}
}


/*Validation in WantItNow Search page Ends*/



function errorvalidation(CntrlName)
{
	
		var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
		var Len = document.getElementById(CntrlName).value.length;
		 for (var i = 0; i < Len; i++) 
		 {
				if (iChars.indexOf(document.getElementById(CntrlName).value.charAt(i)) != -1) 
					document.getElementById(CntrlName).className='textbox_error';
				else
					document.getElementById(CntrlName).className='textbox_right';			
		 }
	
}


function newsletter(Formname)
{
	with(document.forms[Formname])
	{

		update_maillist.value="update";
		submit();
		
	}
}



//function for validating the suggest a category

function enter_key_for_suggest_ctgry(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 fun_suggestcat('suggest_catform');
	  }

}

function openLink(link,ltitle,lopts) {
	var NewWin = window.open(link, ltitle, lopts);
	if (window.focus) {
		NewWin.focus();
	}
}
function tellafriend_highlight(CntrlName)
{
	var Err_Message = "";
	var ControlFocus = false;
	with(document.tellfriend_form)
	{
		if(CntrlName=='yourName')
		{
			if(trimAll(yourName.value) == ""){
				document.getElementById('yourName').className='textbox_error';
			}
			else{
				document.getElementById('yourName').className='textbox_right';
			}
		}
		 if(CntrlName=='yourEmail')
		{
			if(trimAll(yourName.value) == ""){
				document.getElementById('yourEmail').className='textbox_error';
			}else{
				document.getElementById('yourEmail').className='textbox_right';
			}
		}
		if(CntrlName=='emailTo0')
		{
			if(trimAll(yourName.value) == ""){
				document.getElementById('emailTo0').className='textbox_error';
			}else{
				document.getElementById('emailTo0').className='textbox_right';
			}
		}
		if(CntrlName=='tokentext')
		{
			if(trimAll(yourName.value) == ""){
				document.getElementById('tokentext').className='textbox_error';
			}else{
				document.getElementById('tokentext').className='textbox_right';
			}
		}
	
	}

}
//Validating adding and editing of New Topics in Discussion Board

function enter_key_for_edittopic(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_addtopic('edittopic',1);
	  }

}
//for the smilies in new thread
function geticon(iconid)
{
	document.getElementById("icon").value=iconid;
}




function show_newcomment()
{
	with(document.newcomment)
	{
		document.getElementById("newcommenttable").style.display="";
		message.focus();
		return true;
	
	}
}
//validate New Thread


function highlight_comment(CntrlName)
{
	var Err_Message = "";
	var ControlFocus = false;
	with(document.newcomment)
	{
		if(CntrlName=='comment_title')
		{
			if(trimAll(comment_title.value) == ""){
				document.getElementById('comment_title').className='textbox_error';
			}
			else{
				document.getElementById('comment_title').className='textbox_right';
			}
		}
	}
}


function validate_listing(Formname)
{
	with(document.forms[Formname])
	{
		records_num=Hdn_total.value;
		 chk_records=false;
		for(i=1;i<=records_num-1;i++)
			{
				  if(document.getElementById("listing_status"+i).checked==true)
					{
		              chk_records=true;
					 }
			}
					
			Hdn_listing.value="payment";
			submit();
					
	}
}
function SubmitCurrency(){
	document.currency.submit();
}

function fun_import_purchase(Formname)
{
	with(document.forms[Formname])
	{
		Hidmode.value="";
		Hdn_download.value="update";
		submit();
	}
}

function fun_import_sales(Formname)
{
	with(document.forms[Formname])
	{
		submit();
	}
}
function fun_delete_shipping(delete_code,Formname)
{
	with(document.forms[Formname])
	{
		var del_confirm=confirm("Are you sure want to delete this shipping type?");

		if(del_confirm==true)
		{ 
			
			Hdn_code.value=delete_code;
			Hdn_shipping.value="delete";
			submit();
		}
	}
}
function fun_delete_payment_edit(delete_code,Formname)
{
	with(document.forms[Formname])
	{
	   var del_confirm=confirm("Are you sure want to delete this payment type?");
        
		if(del_confirm==true)
		{
		Hdn_code.value=delete_code;
		Hdn_payment.value="delete";
		submit();
		}
		
	}
}

function fun_add_condition(Formname)
{
	with(document.forms[Formname])
	{
		if(trimAll(condition_code.value) == "")
		{
			alert("Please enter the condition code");
			condition_code.focus();
			return false;
		}
		var Nloop;
		var NError;
		for(Nloop=0;Nloop<NameArr.length;Nloop++){
			if(trimAll(document.getElementById(NameArr[Nloop]).value) == ""){
					
				NError = true;
						
			}
		}
		if(NError == true){
		alert("Please enter conditiontype name.");
				document.getElementById(NameArr[0]).focus();
				ControlFocus = true;
		}
		else if(trimAll(condition_sort.value)=="")
		{
			alert("Please enter the condition sort");
			condition_sort.focus();
			return false;
		}else if(!validateInteger(condition_sort.value)){
			alert("Please enter valid sort value.");
			condition_sort.focus();
			ControlFocus = true;
		}else if(condition_status.value==""){

			alert("Please select the status");
			condition_status.focus();
			return false;
		}
		else
		{
			Hdn_condition_add.value="add";
			submit();
		}
	}
}
function fun_delete_payment(delete_payment,Formname)
{
	with(document.forms[Formname])
	{
		var del_confirm=confirm("Are you sure want to delete this payment type?");
		if(del_confirm==true)
		{
			Hdn_code.value=delete_payment;
			Hdn_payment_delete.value="delete";
			submit();
		}
	}
}
function fun_delete_condition(condition_variable,Formname)
{
	with(document.forms[Formname])
	{  
		var del_confirm=confirm("Are you sure want to delete this condition type?");
		if(del_confirm==true)
		{
		Hdn_condition.value=condition_variable;
		Hdn_condition_delete.value="delete";
		submit();
		}
	}
}


function fun_delete_location(delete_location,Formname)
{
	with(document.forms[Formname])
	{
		var del_confirm=confirm("Are you sure want to delete this location type?");
		if(del_confirm==true)
		{
        Hdn_code.value=delete_location;
		Hdn_location_delete.value="delete";
		submit();
		}
	}
}

function fun_validate_shipping(Formname)
{
	var ControlFocus = false;
	var Err_Message = "";
	with(document.forms[Formname])
	{
		if(trimAll(shipping_code.value) == "")
		{
			Err_Message += "Enter the shipping code\n";
			if(ControlFocus == false){
				shipping_code.focus();
				ControlFocus = true;
			}
		}
		var Nloop;
		var NError;
		for(Nloop=0;Nloop<NameArr.length;Nloop++){
			if(trimAll(document.getElementById(NameArr[Nloop]).value) == ""){
					
				NError = true
						
			}
		}
	if(NError == true){
		Err_Message += "Please enter shipping name.\n";
		if(ControlFocus == false){
				document.getElementById(NameArr[0]).focus();
				ControlFocus = true;
		}
	}
	if(trimAll(ship_status.value)=="")
		{
		 Err_Message += "Please select the status.\n";
		 	if(ControlFocus == false){
				ship_status.focus();
				ControlFocus = true;
			}
		}
	if(Err_Message != "")
		{
			alert(Err_Message);
		}
		
		else
		{
		   Hdn_shipping.value="update";
		   submit();
		}
	}
}
function fun_delete_theme(theme_delete,Formname)
{
	with(document.forms[Formname])
	{

		var del_confirm=confirm("Are you sure want to delete this theme type?");
		if(del_confirm==true)
		{
		Hdn_code.value=theme_delete;
		Hdn_delete_theme.value="delete";
		submit();
		}
	}
}

function clear_state_error()
{	
	document.getElementById('td_state').className ='';
	document.getElementById('td_state').innerHTML = "&nbsp;";
}
function load_states(formname)
{
	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[formname])
	{	
		var countryval = sel_country.value;
		
		url = "ajax/ajax_state_country_action.php?country="+sel_country.value+"&From=usermanager";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		
		http_req = null;

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

		if (http_req)
		{
			http_req.onreadystatechange = processchoosestate_register;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}
function processchoosestate_register()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		document.getElementById('regState').innerHTML = txt;
	}	
}
function fun_update_creditcard(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_credit.value="update";
		submit();
	}
}

function fun_show_reports()
{
	with (document.cardprocessor_form)
	{
	
	   Hdn_show.value ="processor";
	   submit();

	}
}
function fun_update_processor()
{
	with (document.cardprocessor_form)
	{
		
		Hdn_processor.value="update";
		submit();
	}

}

function fun_update_paymentcard(Formname)
{
	with(document.forms[Formname])
	{
		Hdn_payment.value="update";
		submit();
	}
}

function fun_delete_comment(delete_code,Formname)
{
	with(document.forms[Formname])
	{
		var del_confirm=confirm("Are you sure want to delete this Comment?");

		if(del_confirm==true)
		{
			Hdn_code.value=delete_code;
			Hdn_shipping.value="delete";
			submit();
		}
	}
}
function fun_sort(Formname)
{
	with(document.forms[Formname])
		{
		Hdn_sort.value="sort";
		Hdn_sort_order.value="asc";
		submit();
		}
}

function fun_sort_order(Formname,order_sort)
{
	with(document.forms[Formname])
	{
		Hdn_sort.value="sort";
		if(order_sort=="asc")
		Hdn_sort_order.value="desc";
		else
        Hdn_sort_order.value="asc";
		submit();
	}
}
function show_avatar(avatarname,file,Formname,url)
	{
			with(document.forms[Formname])
			{
			document.getElementById('current').style.display="";
			document.getElementById('currentavatar').src=avatarname;
			if(url==1)
			{
			hdnurlavatar.value=file;
			avatar.value="";
			}
			else
			{
			avatar.value=file;
			hdnurlavatar.value="";
			}
			}
		
	}
	function title_sort(Formname,sortval)
	{
			with(document.forms[Formname])
			{
			hdnsort.value=sortval;
			submit();
			}
	}
	
	function valid_paging(Formname,TotalPages){			
		var Err_Message = "";
		with(document.forms[Formname]){	
				
			if(!(validateNotEmpty(page_Go.value))){
				alert('Please enter page number');
				page_Go.focus();
				return false;
			}
			else if((!(validateInteger(trimAll(page_Go.value)))) || (parseInt(page_Go.value) <= 0)) {
				alert('Please enter valid page number');
				page_Go.focus();
				return false;
			}
			else if(page_Go.value > TotalPages){
				alert('Page does not exists');
				page_Go.focus();
				return false;
			}else{			pagetransfer(page_Go.value,Formname);	
			return true;							}	
		}						
	}
	
function enter_paging(e,Formname,TotalPages)
{	
	if(nav4) 	{		var whichCode = e.which; 	 }else{ 		var whichCode = event.keyCode;	}		if(whichCode == 13) 	{		if(valid_paging(Formname,TotalPages) == false)		{			return false;		}	}
}
function show_debugger(imageurl)
{
if(document.getElementById("debugtable").style.display=="none")
{

	document.getElementById("debugtable").style.display="";
	document.getElementById('arrowimage').src=imageurl+'upArrow1.gif';
	document.getElementById("debugtable").focus();
}
else
{
	document.getElementById("debugtable").style.display="none";
	document.getElementById('arrowimage').src=imageurl+'downArrow1.gif';
	
	
}
}function toolTip(text,me) {theObj=me;
theObj.onmousemove=updatePos;
document.getElementById('toolTipBox').innerHTML=text;
document.getElementById('toolTipBox').style.display="block";
window.onscroll=updatePos;
}
function updatePos() {
var ev=arguments[0]?arguments[0]:event;
var x=ev.clientX;
var y=ev.clientY;
diffX=24;
diffY=0;
document.getElementById('toolTipBox').style.top = y-2+diffY+document.body.scrollTop+ "px";
document.getElementById('toolTipBox').style.left = x-2+diffX+document.body.scrollLeft+"px";
theObj.onmouseout=hideMe;
}
function hideMe() {
document.getElementById('toolTipBox').style.display="none";
}

function submit_estoresearch(FormName){
	var Err_Message = "";
	var ControlFocus = false;
	with(document.forms[FormName])
	{
			if(trimAll(searchstring.value)=="")
			{
				Err_Message = "Please enter Store Name\n";
				if(ControlFocus == false)
				{
					searchstring.focus();
					ControlFocus = true;
				}
			}
			

			if(Err_Message != "")
			{
				alert(Err_Message);
			}
			else
			{
				hdnsearchstore.value="Yes";
				submit();
			}
			
			
	}
}

function enter_key_for_homesearch(e){
	if(e.keyCode==13)
	{
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
		{
			e.preventDefault();
		}
		else
			e.keyCode=0;
		home_search('homesearchform');
	}
}
function enter_key_for_browsesearch(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 browse_search('categorysearch');
	  }
}

function enter_key_sendmessage(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 send_message('compose');
	  }
}
function IsvalidImgURL(imageURL)
{
		var exist= imageURL.indexOf('http://');

		if(exist == -1 && (trimAll(imageURL) != ""))
		{
			imageURL ='http://'+imageURL;
		}
		lengthValue = trimAll(imageURL);
		lengthValue = lengthValue.length;
		if(lengthValue != 0)
		{
		var j = new RegExp();
		j.compile("^[A-Za-z]+://[A-Za-z0-9-]+\.[A-Za-z0-9]+");             
		lengthValue = trimAll(imageURL);
		if (!j.test(lengthValue))
		{

			return false;
		}
		else
		{
			return true;
		}
		}
	
}

function verify_select_states(formname)
{
	highlight_address('countryCode');
	
	with(document.forms[formname])
	{	
		var countryval = countryCode.value;
		url = "ajax/check_user.php?countryCode="+countryval+"&State="+dftState.value+"&Country="+dftcountry.value+"&From=Verify";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		
		http_req = null;

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

		if (http_req)
		{
			http_req.onreadystatechange = processverifystate;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}
function processverifystate()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
			
		document.getElementById('verifystate').innerHTML = txt;
	}	
}


function members_select_states(formname)
{
	highlight_address_members('sel_country');
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[formname])
	{	
		var countryval = sel_country.value;
		url = "ajax/ajax_state_country_action.php?countryCode_members="+countryval+"&From=members";
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		
		http_req = null;
		
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = processmembersstate;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}
function processmembersstate()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;
		txt = http_req.responseText;
		document.getElementById('verifystate').innerHTML = txt;
	}	
}
function informationbar(){
	this.displayfreq="always"
	this.content='';
}

informationbar.prototype.setContent=function(data){
	
	this.content=this.content+data
		if(this.content!="")
	document.getElementById("informationbar").style.display="";
	else
		document.getElementById("informationbar").style.display="none";

	document.getElementById("informationbar").innerHTML=this.content;
	
}

informationbar.prototype.animatetoview=function(){
	var barinstance=this
	if (parseInt(this.barref.style.top)<0){
		this.barref.style.top=parseInt(this.barref.style.top)+5+"px"
		setTimeout(function(){barinstance.animatetoview()}, 50)
	}
	else{
		if (document.all && !window.XMLHttpRequest)
		this.barref.style.setExpression("top", 'document.compatMode=="CSS1Compat"? document.documentElement.scrollTop+"px" : body.scrollTop+"px"')
	else
		this.barref.style.top=0
	}
}

informationbar.close=function(){
	document.getElementById("informationbar").style.display="none"
	if (this.displayfreq=="session")
		document.cookie="infobarshown=1;path=/"
}

informationbar.prototype.setfrequency=function(type){
	this.displayfreq=type
}

informationbar.prototype.initialize=function(){
	if (this.displayfreq=="session" && document.cookie.indexOf("infobarshown")==-1 || this.displayfreq=="always"){
		this.barref=document.getElementById("informationbar")
		this.barheight=parseInt(this.barref.offsetHeight)
		this.barref.style.top=this.barheight*(-1)+"px"
		this.animatetoview()
	}
}
window.onunload=function(){
	this.barref=null
}



function wOpen(pURL, pName, w, h, scroll, text, specialSettings){
	xLeft=(screen.width)?(screen.width-w)/2:0;
	xTop=(screen.height)?(screen.height-h)/2:0;
	xSettings = 'height='+h+',width='+w+',top='+xTop+',left='+xLeft+',scrollbars='+scroll+specialSettings
	hwnd = window.open(pURL,pName,xSettings);
	if(hwnd.window.focus){hwnd.window.focus();}
	if(text != "") hwnd.document.write(text);
	hwnd.document.close();
	return hwnd;
}

var autoSwapping = false;
function swpImg(val, auto){
	
	if (auto){
		for (j=0; j < imgCount; j++){
			if (!images[j].complete) return;
		}
	}
	if (!auto && autoSwapping) autoSwapping = false;
	imgNow+=val;
        if (imgNow == imgCount) imgNow = 0; 
        	else if (imgNow < 0) imgNow = imgCount-1;
	document.imgProd.src = images[imgNow].src;
	document.imgProd.alt = images[imgNow].alt;

	document.getElementById('imagenumber').innerHTML = imgNow + 1 ;
}

function autoSwap(){
	if(autoSwapping){
		swpImg(1, true);
		setTimeout("autoSwap()", 2000);
	}
}

var nav4 = window.Event ? true : false;

function convButton(from,to,rate) {
	var fromVal = new String;
	var toVal;
	var i;
	var ss;
	
	for (i=0; i<from.value.length; i++) {
		ss = from.value.substr(i,1);
		if (ss == "." || (ss >= "0" && ss <= "9")) {
			fromVal += ss;
		}
	}
	
	toVal = Math.round(rate * fromVal * 100)/100;
	toVal = toVal.toString();
	
	if (toVal.indexOf(".") == toVal.length - 2 && toVal.length > 1) {
		toVal += "0";
	}
	to.value = toVal;
}
function stopSwap()
{
	document.playon.src = site_url+'auctionimages/images/player/PlayerPlay.gif';
	document.stopon.src = site_url+'auctionimages/images/player/iconPlayerStop.gif';
	autoSwapping = false;
}
function startSwap()
{
	document.playon.src = site_url+'auctionimages/images/player/iconPlayerPlay.gif';
	document.stopon.src = site_url+'auctionimages/images/player/PlayerStop.gif';
	autoSwapping = true;
	autoSwap();
}
function showToolTip(e,text){
	if(document.all)e = event;
	
	var obj = document.getElementById('bubble_tooltip');
	var obj2 = document.getElementById('bubble_tooltip_content');
	obj2.innerHTML = text;
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX - 100;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
}	

function hideToolTip()
{
	document.getElementById('bubble_tooltip').style.display = 'none';
	
}
// this clears the values from the shipping methods
function clearit(){
	var len = document.getElementById('shippingTypeCodes').length;
	var shipsel;
	for(var i = 0; i < len; i++){
		if(document.getElementById('shippingTypeCodes').options[i].selected == true){
			shipsel = true;
		}
	}
	if(shipsel == true){
		document.PostListing.shipOther.value = "";
	}
}

function other(){
	if(trimAll(document.PostListing.shipOther.value) != ""){
		var len = document.getElementById('shippingTypeCodes').length;
		for(var i = 0; i < len; i++){
		document.getElementById('shippingTypeCodes').options[i].selected = false;
		}
	}
}
function Shipother(){
		var len = document.getElementById('shippingTypeCodes').length;
		for(var i = 0; i < len; i++){
		document.getElementById('shippingTypeCodes').options[i].selected = false;
		}
	
}
function SwapImg(Name,ImgSrc) {
	eval('document.images["' + Name + '"].src = "' + ImgSrc + '"');
}


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

 if(mytextarea == "") {        
  //alert("Please put in some content!");   
  return false;   
 }  
} 

function  validatequotes(strValue){
 var objRegExp  =  /(^[a-zA-Z0-9\,\#\/\.\-\/\\$\%\&\;\:\_\@\[\]\{\}\(\)\`\~\^\+\=\|\?\!\ ]+$)/;  
 
  //check for special characters 
  return objRegExp.test(strValue);
}



// Enter key validation for lostpassword page

function post_back(){
	document.PostListing.submit();
}

function event_back(){
	document.EventAdd.submit();
}

function create_listing(){
	
	document.PostListing.post_confirm.value = "YES";
	document.PostListing.submit();

}
function preview_back(){
	document.PostListing.categorypost.value = "YES";
	document.PostListing.submit();
}

function enter_key_for_post_page(e)
	{
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	    {
			e.preventDefault();
	    }else{
			e.keyCode=0;
		 
		}

		post_validation();
	  }
}

 function parseOptIntegers(field)
     {
		  field = trimAll(field);
          var currency = /^\d*(?:\.\d{0,2})?$/;
          
		if(!validate_Numeric(field)  && trimAll(field) != "")
		{
			return 0;
		}
		if(!currency.test(field) || (parseFloat(field) < 0 && trimAll(field) != ""))
          {
               return 0;
          }else{
				return 1;
		}
     }	
function parseIntegers(field)
 {
	field = trimAll(field);
	var currency = /^\d*(?:\.\d{0,2})?$/;
	if(!validate_Numeric(field))
	{
		return 0;
	}
	if(!currency.test(field) || parseFloat(field) <= 0 || trimAll(field) == "")
	{
		return 0;
	}else{
			return 1;
	}
 }


function LimitKeywords(limit){
 post_highlightvalidation('listingKeywords');
 if(document.PostListing.listingKeywords.value.length > limit)
 document.PostListing.listingKeywords.value = document.PostListing.listingKeywords.value.substr(0, limit);
 return 0;
}
function LimitShortDesc(limit)
{
  post_highlightvalidation('ShortDescription');
 if(document.PostListing.ShortDescription.value.length > limit)
 document.PostListing.ShortDescription.value = document.PostListing.ShortDescription.value.substr(0, limit);
 return 0;
}
//Validating post page

// Enter key validation for activation page


function in_array(what,where){
   var a=false;
	   for(var i=0;i<where.length;i++){
			if(what == where[i]){
				a=true;
				 break;
			}
		}
    return a;
}

function in_arraycount(what,where){
   var a=0;
	   for(var i=0;i<where.length;i++){
		if(what == where[i]){
			 a++;
			 break;
		}
		}
    return a;
}


//Check the category exists or not
function checkcategoryAvailability(FormName)
{	
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[FormName])
	{	
		url = "ajax/check_category.php?CategoryID="+CategoryID.value+"&From=Register";
		
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;
	
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = process_category_availabilty;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}

function process_category_availabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.postForm.hdn_category.value="no";
		}
		else
		{
			document.postForm.hdn_category.value="yes";
		}
	}	
}

function removeoldimages(sellerid){
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.PostListing)
	{	
		url = "ajax/disabletmp-images.php?userID="+sellerid+"&From=Register";
		
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		http_req = null;
	
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = process_images;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}
function process_images()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.PostListing.DisableTemp.value="no";
		}
		else
		{
			document.PostListing.DisableTemp.value="yes";
		}
	}	
}

function validate_qna(){
	with(document.postForm){
		if(message.value == ""){
			alert("Please enter your question.");
			message.focus();
		}else{
			Hdn_sell.value = "ask";
			submit();
		}
	}
}

function MakeSizeAdjustment(oTextArea)
{
	if (navigator.appName.indexOf("Microsoft Internet Explorer") == 0)
	{
		return;
	}

	while (oTextArea.scrollHeight > oTextArea.offsetHeight)
	{
		oTextArea.rows++;
	}
}
function advertiser_state1(formname)
{
	AdvertiserRegHighlight('countryCode');
	var posturl;
	var url;
	
	with(document.forms[formname])
	{	
		posturl = "ajax/check_user.php?countryCode="+countryCode.value+"&From=Advertiser";
		
		//Does URL begin with http?
		if (posturl.substring(0, 4) != 'http') 
		{
			posturl = site_url + posturl;
		}
		
		http_req = null;

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

		if (http_req)
		{
			http_req.onreadystatechange = AdvertiserRegisterState;
			http_req.open("GET", posturl, true);
			http_req.send("");
		}
	}
}

function AdvertiserRegisterState()
{	
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		
		//alert(txt);
		document.getElementById('AdvertiserState').innerHTML = "";
		document.getElementById('AdvertiserState').innerHTML = txt;
	}
}
function checkAduserAvailability(FormName)
{	
	with(document.forms[FormName])
	{	
		posturl = "ajax/check_user.php?aduser_name="+uname.value+"&userID="+user_id.value+"&From=Register";
		
		//Does URL begin with http?
		if (posturl.substring(0, 4) != 'http') 
		{
			posturl = site_url + posturl;
		}
		
		http_req = null;
	
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = process_adusername_availabilty;
			http_req.open("GET", posturl, true);
			http_req.send("");
		}
	}
}
function AdemailAvailability(FormName)
{	
	
	with(document.forms[FormName])
	{	
		posturl = "ajax/check_user.php?aduser_email="+login_email.value+"&userID="+user_id.value+"&From=Register";
		//Does URL begin with http?
		if (posturl.substring(0, 4) != 'http') 
		{
			posturl = site_url + posturl;
		}
		http_req = null;

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

		if (http_req)
		{
			
				http_req.onreadystatechange = process_ademail_availabilty;
				http_req.open("GET", posturl, true);
				http_req.send("");
			
		}
	}
}
function process_adusername_availabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		
		if(txt==0)
		{
			document.AdvertiserForm.AdUser.value ="no";
		}
		else
		{
			document.AdvertiserForm.AdUser.value ="yes";
		}
	}	
}

function checkAdemailAvailability(FormName)
{	
	
	with(document.forms[FormName])
	{	
		posturl = "ajax/check_user.php?aduser_email="+email.value+"&userID="+user_id.value+"&From=Register";
		//Does URL begin with http?
		if (posturl.substring(0, 4) != 'http') 
		{
			posturl = site_url + posturl;
		}
		http_req = null;

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

		if (http_req)
		{
			
				http_req.onreadystatechange = process_ademail_availabilty;
				http_req.open("GET", posturl, true);
				http_req.send("");
			
		}
	}
}
function process_ademail_availabilty()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		if(txt==0)
		{
			document.AdvertiserForm.Ademail.value="no";
		}
		else
		{
			document.AdvertiserForm.Ademail.value="yes";
		}
	}	
}

function Adloginhighlight(CntrlName){
	with(document.AdvertiserForm){
		if(CntrlName == 'login_email'){
			if(trimAll(login_email.value) == ""){
					document.getElementById('login_email').className='textbox_error';
			}else if(!(validateEmail(trimAll(login_email.value)))){
					document.getElementById('login_email').className='textbox_error';
			}else if(trimAll(Ademail.value) == "no"){
					document.getElementById('login_email').className='textbox_error';
			}else{
					document.getElementById('login_email').className='textbox_right';
			}
		}

		if(CntrlName == 'login_password'){
			if(trimAll(login_password.value) == ""){
				document.getElementById('login_password').className='textbox_error';
			}else{
				document.getElementById('login_password').className='textbox_right';
			}
		}
	}
}
// Enter key validation for advertisers register page
function enter_key_for_adlogin(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_adlogin();
	  }
}

function enter_key_for_category(e){
	  if(e.keyCode==13)
	  {
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
	   {
		e.preventDefault();
	   }
	   else
		e.keyCode=0;
		 validate_category();
	  }
}
function hitlens_embedded(newid,user_id,page_name,file_name,ip_address,current_date,catId,item,rootpath) {
		var pid = newid;
		var uid = user_id;
		var PAGENAME = escape(page_name);
		var FILENAME = file_name;
		var ip = ip_address;
		var st=	current_date;
		
		var pagedate  = new Date()
		var monthname =new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");

		if(pagedate.getDate() <= 9)
			var currentdate = '0' + pagedate.getDate();
		else
			var currentdate = pagedate.getDate();

		if(pagedate.getMonth() <= 9)
			var currentmonth = '0' + pagedate.getMonth();
		else
			var currentmonth = pagedate.getMonth();

		cdt = pagedate.getFullYear() + "-"+ currentmonth +"-" +currentdate+"---"+pagedate.getHours()+":"+pagedate.getMinutes()+":"+pagedate.getSeconds();


		var detect = navigator.userAgent.toLowerCase();
		var OS,browser,version,total,thestring;
		if (checkIt('konqueror'))
		{
			browser = "Konqueror";
			OS = "Linux";
		}
		else if (checkIt('safari')) browser = "Safari"
		else if (checkIt('omniweb')) browser = "OmniWeb"
		else if (checkIt('opera')) browser = "Opera"
		else if (checkIt('webtv')) browser = "WebTV";
		else if (checkIt('icab')) browser = "iCab"
		else if (checkIt('msie')) browser = "IE"
		else if (!checkIt('compatible'))
		{
			browser = "Netscape Navigator"
			version = detect.charAt(8);
		}
		else browser = "An unknown browser";
		//if (!version) version = detect.charAt(place + thestring.length);
		if (!OS)
		{
			if (checkIt('linux')) OS = "Linux";
			else if (checkIt('x11')) OS = "Unix";
			else if (checkIt('mac')) OS = "Mac"
			else if (checkIt('win')) OS = "Windows"
			else OS = "an unknown operating system";
		}
				var shw=screen.height+'*'+screen.width;
				var rf=document.referrer;
		LLL= "?p="+PAGENAME+"&pid="+pid+"&fn="+FILENAME+"&uid="+uid+"&ip="+ip+"&st="+st+"&cdt="+cdt+"&os="+OS+"&brow="+browser+"&shw="+shw+"&rf="+rf+"&cat="+catId+"&listing="+item;

				var text="<a href="+rootpath+"includes/page_hits.php"+LLL+">";
				text=text+"<img src='"+rootpath+"includes/page_hits.php"+LLL+"' width='1' height='1' border='0' align='left'>";
				text=text+"</a>";
				return text;
	}

	function checkIt(string)
	{
		var detect = navigator.userAgent.toLowerCase();
		place = detect.indexOf(string) + 1;
		thestring = string;
		return place;
	}



function isCurrency(f)
{
	var nNum = 0;			
	var nDollarSign = 0;	
	var nDecimal = 0;		
	var nCommas = 0;		
	var txtLen;				
	var xTxt;				
	var sDollarVal;			
	var bComma;				
	var decPos;				
	var nNumCount = 0;		
	var i;					
	var x;					

	xTxt = f;
	//alert(xTxt);

	txtLen = xTxt.length
	//alert(txtLen);

	for(i = 0; i < txtLen; i++)
	{
		x = xTxt.substr(i, 1);
		if(x == "$")

			nDollarSign = nDollarSign + 1; 
		else if(x == ".")
			nDecimal = nDecimal + 1; 
		else if(x == ",")
			nCommas = nCommas + 1; 
		else if(parseInt(x) >= 0 || parseInt(x) <= 9)
			nNum = nNum + 1; 
		else
		{
			//alert("error");
			return false;
		} 

	} 

	if(nDollarSign > 0)
	{
		//alert("ERROR! \n\nYou have entered more then one dollar sign!\nPlease only enter one!");
		return false;

	} 
	if(nDecimal > 1)
	{
		//alert("ERROR! \n\nYou have entered more then one decimal point!\nPlease only enter one!");
		return false;
	} 

	
	if(nDecimal == 1){

		decPos = (txtLen - 1) - xTxt.indexOf(".");
		if(decPos > 2)
		{
			//alert("ERROR! \n\nThe decimal point you entered is not in the correct position!");
			return false;
		} 
	} 
	if(nCommas == 0)
	{
		return true;
	}
	else
	{
		nNum = nNum - decPos;
	
		if(xTxt.indexOf("$", 0) == 0)
			sDollarVal = xTxt.substr(1, (nNum + nCommas));
		else
			sDollarVal = xTxt.substr(0, (nNum + nCommas));

		if(sDollarVal.lastIndexOf("0", 0) == 0 )
		{
			//alert("ERROR! \n\nYou cannot start the dollar amount out with a zero!");
			return false;
		}
		else if(sDollarVal.lastIndexOf(",", 0) == 0)
		{
			//alert("ERROR! \n\nYou cannot start the dollar amount out with a comma!");
			return false;
		}
		else if(sDollarVal.indexOf(",", (sDollarVal.length - 1)) == (sDollarVal.length - 1))
		{
			//alert("ERROR! \n\nYou cannot end the dollar amount with a comma!");
			return false;
		}
		else
		{
			bComma = false;
			for(i = 0; i < sDollarVal.length; i++)
			{
				x = sDollarVal.substr(i, 1);
				if(parseInt(x) >= 0 || parseInt(x) <= 9)
				{
					nNumCount = nNumCount + 1;
				if(nNumCount > 3)
				{
					//alert("ERROR! \n\nYou have a mis-placed comma!");
					return false;
					} 
				}
				else
				{
					if(nNumCount != 3 && bComma)
					{
						//alert("ERROR! \n\nYou have a mis-placed comma!");
						return false;

					} 

					nNumCount = 0;
					bComma = true;

				} 

			} 

			if(nNumCount != 3 && bComma)
			{
				//alert("ERROR! \n\nYou have a mis-placed comma!");
				return false;
			} 
		} 
	} 

	return true;

}
function round(number,X) {
// rounds number to X decimal places, defaults to 2
    X = (!X ? 2 : X);
    return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
}

//get expiration for edit membership in manage users
function get_expirtaion(formname)
{
	url = document.location.href;
	xend = url.lastIndexOf("/") + 1;
	var base_url = url.substring(0, xend);
	with(document.forms[formname])
	{	
		var memcode = membershipCode.value;
		var expdate = hdnexpirationDate.value;
		url = "ajax/check_expiration.php?memCode="+memcode+"&expdate="+expdate;
		
		
		//Does URL begin with http?
		if (url.substring(0, 4) != 'http') 
		{
			url = site_url + url;
		}
		
		http_req = null;
		
		if (window.XMLHttpRequest)     http_req = new XMLHttpRequest();
		else if (window.ActiveXObject) http_req = new ActiveXObject("Microsoft.XMLHTTP");

		if (http_req)
		{
			http_req.onreadystatechange = processexpiration;
			http_req.open("GET", url, true);
			http_req.send("");
		}
	}
}
function processexpiration()
{
	if(http_req.readyState == 4)
	{
		var txt,DisplayText;			
		txt = http_req.responseText;
		var resdate= txt.split("#");
		document.expirationForm.expirationDate.value = resdate[0];
		document.resetForm.resetDate.value = resdate[1];
	}	
}
//enter key search for estore search
function enter_key_for_search_store(e){
	if(e.keyCode==13)
	{
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
		{
			e.preventDefault();
		}
		else
			e.keyCode=0;
		submit_estoresearch('searchstore');
	}
}
function enter_key_for_search_homestore(e){
	if(e.keyCode==13)
	{
		if (navigator.appName=="Netscape" || navigator.appName == "Opera")
		{
			e.preventDefault();
		}
		else
			e.keyCode=0;
		submit_estoresearch('estoreshome');
	}
}

