function set_select(sel_obj,val){

	var num_sm=sel_obj.length;
	for(ca=0;ca<num_sm;++ca){
   		if(val==sel_obj.options[ca].value){
			sel_obj.options[ca].selected=true;
   		}
 	}
}

function makeRemote(url) {
    remote = window.open(url,"remotewin","status,width=320,height=250");
    if (remote.opener == null) {
      remote.opener = window;
      remote.opener.name = "opener";
    }
  }



function validateEmail( argEmail ) {

	  	var specialchars = ' !#%^&*()=|\/<>?`,:;'

		atPos = argEmail.indexOf('@'); //-1 if none, index starts at 0
		ldotPos = argEmail.lastIndexOf('.'); //search for the last '.'

		//  if no @, if @ is first char, atleast 4 chars after the @, no multiple @ signs allowed
		if ( (atPos == -1) || ((atPos+1) < 2) || ((atPos+1) > ( argEmail.length - 4)) ) {
			alert("The email address entered does not appear to be valid.");
			return false;
		}

		// . is the first char, no more than one @ in the field, atleast 2 chars after the last  .
		if( argEmail.indexOf('.',0) == 0 || (ldotPos+1) > ( argEmail.length - 2) ) {
			alert("The email address entered does not appear to be valid.");
			return false;
		}

		//check for consecutive dots
		dotPos1 = 0;
		for(i=0; (i < argEmail.length); i++) {
			dotPos1 = argEmail.indexOf('.', i)
			if( argEmail.charAt(dotPos1 + 1) == '.' ) {
				alert("No consecutive dots are allowed in an email address");
				return false;

			}
		}

		//check for multiple @ signs
		if( argEmail.indexOf('@', atPos + 1) != -1) {
			alert("Multiple @ signs are not allowed in an email address");
			return false;

		}

		for(i=0; (i < specialchars.length); i++) {
			if( argEmail.indexOf(specialchars.charAt(i)) !=  -1 ) {
				alert("There are invalid characters in the entered email address");
				return false;

			}
		}
		
		return true
}

function validateForgotUserID( frm ) {

	if ( Trim(frm.email.value) == ""  ) {
		alert("Email Address is required.");
		frm.email.focus();
		return false;
	}

	if ( Trim(frm.confirmemail.value) == ""  ) {
		alert("Email Address confirmation is required.");
		frm.confirmemail.focus();
		return false;
	}

	if ( frm.email.value != frm.confirmemail.value  ) {
		alert("Email Address and confirmation do not match.");
		frm.email.focus();
		return false;
	}

	if ( !validateEmail( frm.email.value ) )
		return false;

	return true;
}

function validateForgotPassword( frm ) {

	if ( Trim(frm.username.value) == ""  ) {
		alert("User ID is required.");
		frm.username.focus();
		return false;
	}

	return true;
}


function validateSearchCriteria( frm ) {
	
	if ( Trim(frm.from_price.value) != "" && parseFloat(frm.from_price.value ) != frm.from_price.value ) {
		alert("From price is not numeric");
		frm.from_price.focus();
		return false;
	}

	if ( Trim(frm.to_price.value) != "" && parseFloat(frm.to_price.value ) != frm.to_price.value ) {
		alert("To price is not numeric");
		frm.to_price.focus();		
		return false;
	}

	if ( (( Trim(frm.keyword.value) == "" ) || ( Trim(frm.keyword.value).length < 3 ) ) && Trim(frm.category.value) == "" ) {
		alert( "You must specify a search keyword at least 3 characters long or a category.");
		frm.keyword.focus();
		return false;
	}

	return true;
}

/*
==================================================================
LTrim(string) : Returns a copy of a string without leading spaces.
==================================================================
*/
function LTrim(str)
/*
   PURPOSE: Remove leading blanks from our string.
   IN: str - the string we want to LTrim
*/
{
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(0)) != -1) {
      // We have a string with leading blank(s)...

      var j=0, i = s.length;

      // Iterate from the far left of string until we
      // don't have any more whitespace...
      while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
         j++;

      // Get the substring from the first non-whitespace
      // character to the end of the string...
      s = s.substring(j, i);
   }
   return s;
}

/*
==================================================================
RTrim(string) : Returns a copy of a string without trailing spaces.
==================================================================
*/
function RTrim(str)
/*
   PURPOSE: Remove trailing blanks from our string.
   IN: str - the string we want to RTrim

*/
{
   // We don't want to trip JUST spaces, but also tabs,
   // line feeds, etc.  Add anything else you want to
   // "trim" here in Whitespace
   var whitespace = new String(" \t\n\r");

   var s = new String(str);

   if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
      // We have a string with trailing blank(s)...

      var i = s.length - 1;       // Get length of string

      // Iterate from the far right of string until we
      // don't have any more whitespace...
      while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
         i--;


      // Get the substring from the front of the string to
      // where the last non-whitespace character is...
      s = s.substring(0, i+1);
   }

   return s;
}

/*
=============================================================
Trim(string) : Returns a copy of a string without leading or trailing spaces
=============================================================
*/
function Trim(str)
/*
   PURPOSE: Remove trailing and leading blanks from our string.
   IN: str - the string we want to Trim

   RETVAL: A Trimmed string!
*/
{
   return RTrim(LTrim(str));
}


function check_date(field) {

	var checkstr = "0123456789";
	var DateField = field;
	var Datevalue = "";
	var DateTemp = "";
	var seperator = "/";
	var day;
	var month;
	var year;
	var leap = 0;
	var err = 0;
	var i;

	err = 0;
   DateValue = DateField.value;
   /* Delete all chars except 0..9 */
   for (i = 0; i < DateValue.length; i++) {
	  if (checkstr.indexOf(DateValue.substr(i,1)) >= 0) {
	     DateTemp = DateTemp + DateValue.substr(i,1);
	  }
   }
   
   DateValue = DateTemp;
   
   if ( Trim(DateValue) == "" || DateValue.length < 8 ) {
      alert("Need By is incorrect!");
      DateField.select();
	  DateField.focus();
	  return false;
   }
   
   /* Always change date to 8 digits - string*/
   /* if year is entered as 2-digit / always assume 20xx */
   if (DateValue.length == 6) {
      DateValue = DateValue.substr(0,4) + '20' + DateValue.substr(4,2); }
   if (DateValue.length != 8) {
      err = 19;}
   /* year is wrong if year = 0000 */
   year = DateValue.substr(4,4);
   if (year == 0) {
      err = 20;
   }
   /* Validation of month*/
   month = DateValue.substr(0,2);
   if ((month < 1) || (month > 12)) {
      err = 21;
   }
   /* Validation of day*/
   day = DateValue.substr(2,2);
   if (day < 1) {
     err = 22;
   }
   /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) {
      leap = 1;
   }
   if ((month == 2) && (leap == 1) && (day > 29)) {
      err = 23;
   }
   if ((month == 2) && (leap != 1) && (day > 28)) {
      err = 24;
   }
   /* Validation of other months */
   if ((day > 31) && ((month == "01") || (month == "03") || (month == "05") || (month == "07") || (month == "08") || (month == "10") || (month == "12"))) {
      err = 25;
   }
   if ((day > 30) && ((month == "04") || (month == "06") || (month == "09") || (month == "11"))) {
      err = 26;
   }
   /* if 00 ist entered, no error, deleting the entry */
   if ((day == 0) && (month == 0) && (year == 00)) {
      err = 0; day = ""; month = ""; year = ""; seperator = "";
   }
   
   /* if no error, write the completed date to Input-Field (e.g. 13.12.2001) */
   if (err == 0) {
      DateField.value = month + seperator + day + seperator + year;
	  return true;
   }
   /* Error-message if err != 0 */
   else {
      alert("Need By is incorrect!");
      DateField.select();
	  DateField.focus();
	  return false;
   }
}
