/*         File Contents:

		_select_list_value(selectObj, value)

*/
function _select_list_value(selectObj, value) {
	for (var i = 0; i < selectObj.options.length; i++) {
		if (selectObj.options[i].value == value) { selectObj.selectedIndex = i; break; }
	}
}

var agt            = navigator.userAgent.toLowerCase();
var is_major       = parseInt(navigator.appVersion);
var is_minor       = parseFloat(navigator.appVersion);
var is_nav         = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava')==-1));
var is_nav2        = (is_nav && (is_major == 2));
var is_nav3        = (is_nav && (is_major == 3));
var is_nav4        = (is_nav && (is_major == 4));
var is_nav4up      = (is_nav && (is_major >= 4));
var is_navonly     = (is_nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) );
var is_nav6        = (is_nav && (is_major == 5));
var is_nav6up      = (is_nav && (is_major >= 5));
var is_gecko       = (agt.indexOf('gecko') != -1);
var is_ie          = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3         = (is_ie && (is_major < 4));
var is_ie4         = (is_ie && (is_major == 4) && (agt.indexOf("msie 5")==-1) );
var is_ie4up       = (is_ie && (is_major >= 4));
var is_ie5         = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5_5       = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie5up       = (is_ie && !is_ie3 && !is_ie4);
var is_ie5_5up     = (is_ie && !is_ie3 && !is_ie4 && !is_ie5);


/*
   openWin('mypage.html','popupwin','width=55,height=55')

   toolbar
   displays the browser buttons (forward, back, home, print, etc) 
   location
   displays the field that shows the URL for the window 
   directories
   displays other web browser directory buttons 
   status
   displays the browser status bar at the bottom 
   menubar
   displays the web browser menu bar 
   resizable
   allows user to change the size of the window 
   scrollbars
   provides scroll bars if the content is larger than the window size 
   width=XX
   specifies the width of the window when opened, in pixels 
   height=YY
   specifies the height of the window when opened, in pixels 
*/
function openWin(url,win,options) {
	var popupwin = window.open(url,win,options);

	if (!popupwin) { alert("The popup window has been blocked."); }
	else { popupwin.focus(); }
}

var timeoutHandle;

function startTimeout() {  // Timeout after 1 hour and close "child" windows
  var winTimeout = 3600000;
  timeoutHandle = setTimeout("window.close()", winTimeout)
}

function resetTimeout() {
  clearTimeout(timeoutHandle);
}

function clearSelect(obj) {
  var objOptions = obj.options;
  for (var i=0; i<objOptions.length; i++)
    objOptions[i].selected = false;
}

function getSearchAsArray() {
  if (is_nav4up || is_ie4up) {
    var results = new Array();
    var input = unescape(location.search.substr(1));
    if (input) {
      var srchArray = input.split("&");
      var tempArray = new Array();
      for (var i=0; i<srchArray.length; i++) {
        tempArray = srchArray[i].split("=");
        results[tempArray[0]] = tempArray[1];
      }
    }
    return results;
  }
}

function showAllProps(obj) {
  var objName = "";
  var result = "";
  var objPropCount = 0;
  for (var i in obj) {
    objPropCount += 1;
  }
  if (objPropCount > 0) {
    objName = obj["name"];
    for (var p in obj) {
      result += objName + "." + p + " = " + obj[p] + "\t";
    }
    alert(result);
  }
}

function _onError(form_object, input_object, object_value, error_message) {
  alert(error_message);
  return false;
}

function _checkdollar(object_value) {
  // Returns true if value is a number or is NULL
  // otherwise returns false  
  if (object_value.length == 0)
    return true;

  // Returns true if value is a number defined as
  // having an optional leading + or -.
  // having at most 1 decimal point.
  // otherwise containing only the characters 0-9.
  var start_format = " .+-0123456789$";
  var number_format = " .0123456789";
  var check_char;
  var decimal = false;
  var trailing_blank = false;
  var digits = false;

  // The first character can be + - .  blank or a digit.
  check_char = start_format.indexOf(object_value.charAt(0))

  // Was it a decimal?
  if (check_char == 1) decimal = true;
  else if (check_char < 1)
    return false;

  // Remaining characters can be only . or a digit, but only one decimal.
  for (var i = 1; i < object_value.length; i++) {
    check_char = number_format.indexOf(object_value.charAt(i))
    if (check_char < 0)
      return false;
    else if (check_char == 1) {
      if (decimal) // Second decimal.
        return false;
      else
        decimal = true;
    }
    else if (check_char == 0) {
      if (decimal || digits) // ignore leading blanks
        trailing_blank = true;
    }
    else if (trailing_blank)
      return false;
    else
      digits = true;
  }

  // All tests passed, so...
  return true;
}

function Is () {   
  var agt=navigator.userAgent.toLowerCase();

  this.major = parseInt(navigator.appVersion);
  this.minor = parseFloat(navigator.appVersion);

  this.nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1));
  this.nav4up = (this.nav && (this.major >= 4));
  this.nav5up = (this.nav && (this.major >= 5));

  this.ie = (agt.indexOf("msie") != -1);
  this.ie3 = (this.ie && (this.major < 4));
  this.ie4 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")==-1) );
  this.ie4up = (this.ie  && (this.major >= 4));
  this.ie5 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5.0")!=-1) );
  this.ie5up = (this.ie  && !this.ie3 && !this.ie4);

  this.aol   = (agt.indexOf("aol") != -1);
  this.aol4up  = (this.aol && this.ie4up);

  this.win = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
  this.mac = (agt.indexOf("mac")!=-1);
}

var is;
var isIE3Mac = false;

if ((navigator.appVersion.indexOf("Mac")!=-1) && (navigator.userAgent.indexOf("MSIE")!=-1) && (parseInt(navigator.appVersion)==3)) { isIE3Mac = true; }
else { is = new Is(); }

var browserOK = false;
if (!isIE3Mac && (is.nav4up || is.ie4up)) { browserOK = true; }
var currentSelectedImage = "";

function imgOn(img) {
  if (browserOK) {
    if (img != currentSelectedImage) {
      currentSelectedImage = img;
      var pathString = eval("document." + img + ".src");
      var pathArray = new Array();
      var fileNameArray = new Array();
      var tempString = "";
      pathArray = pathString.split("/");
      fileNameArray = pathArray[pathArray.length-1].split(".");
      for (var i=0; i<pathArray.length-1; i++) { tempString += pathArray[i] + "/"; }
      tempString += fileNameArray[0] + "_dn." + fileNameArray[1];
      eval("document." + img + ".src = '" + tempString + "'");
    }
  }
}

function imgOff(img) {
  if (browserOK) {
    if (img == currentSelectedImage) {
      currentSelectedImage = "";
      var pathString = eval("document." + img + ".src");
      var pathArray = new Array();
      var fileNameArray = new Array();
      var fileNameSubString = "";
      var tempString = "";
      pathArray = pathString.split("/");
      fileNameArray = pathArray[pathArray.length-1].split(".");
      fileNameSubString = fileNameArray[0].substring(0,fileNameArray[0].length-3);
      for (var i=0; i<pathArray.length-1; i++) { tempString += pathArray[i] + "/"; }
      tempString += fileNameSubString + "." + fileNameArray[1];
      eval("document." + img + ".src = '" + tempString + "'");
    }
  }
}

// Added on 04/29/2002
function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 

// Added on 11/18/2002

function replace(string,text,by) {
// Replaces text with by in string
    var i = string.indexOf(text);
    if (string.length == 0) return string;
    if ((!i) && (text != string.substring(0,text.length))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+text.length < string.length)
        newstr += replace(string.substring(i+text.length,string.length),text,by);

    return newstr;
}

function _checkPhone(obj_value, country) {
  var phone_regex;
  
  //check UK formatting
  if (country == "UK") 
  {
  	phone_regex = /^0\d{3}[\s-]\d{3}[\s-]\d{4}$/;
  
  	if ( obj_value.match(phone_regex) ) { return true; }
  	//alert("UK NO Match");
  	return false;
  }
  else
  {
  	phone_regex = /^(1[\s\-])?(\(\d{3}\)|\d{3})[-\s]?\d{3}[-\s]?\d{4}$/;
  	if ( obj_value.match(phone_regex) ) { return true; }
  	//alert("US NO Match");
  	return false;
  }

}

function _checkZip(obj_value, country) {

  if (country == "UK") 
  {
  	zip_regex = /^[a-zA-Z]{2}\d{2}[\s-]\d[a-zA-Z]{2}$/;
  	
  	if ( obj_value.match(zip_regex) ) { return true; }
  	//alert("UK NO Match");
  	return false;
  }
  else
  {
  	zip_regex = /^\d{5}([-\s]\d{4})?$/;
  	if ( obj_value.match(zip_regex) ) { return true; }
  	//alert("US NO Match");
  	return false;
  }

}

function confirmMessage(message) {
	if (confirm(message)) { return true; } else { return false; }
}

