//  gets the dhtml object for browsers
/*
function getTheObject(item) {//DOM
  var obj=null;
  if (document.getElementById){
    obj = document.getElementById(item);
  }
  else{
    if (document.layers){ //NS4
      obj = document.item;
    }
    else { //IE4
      obj = document.all.item;
    }
  }
  return obj;
}
*/
var tt_obj = null, tt_u = "undefined";
var tt_db = (document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body? document.body : null,
tt_n = navigator.userAgent.toLowerCase(),
tt_nv = navigator.appVersion;
var tt_op = !!(window.opera && document.getElementById),
tt_op6 = tt_op && !document.defaultView,
tt_op7 = tt_op && !tt_op6,
tt_ie = tt_n.indexOf("msie") != -1 && document.all && tt_db && !tt_op,
tt_ie6 = tt_ie && parseFloat(tt_nv.substring(tt_nv.indexOf("MSIE")+5)) >= 5.5,
tt_n4 = (document.layers && typeof document.classes != tt_u),
tt_n6 = (!tt_op && document.defaultView && typeof document.defaultView.getComputedStyle != tt_u),
tt_w3c = !tt_ie && !tt_n6 && !tt_op && document.getElementById;

function getTheObject(t_id) {
	return(
		tt_n4? (document.layers[t_id] || null)
		: tt_ie? (document.all[t_id] || null)
		: (document.getElementById(t_id) || null)
	);
}

//  sets the "item" as action, and submits the form
function setActionAndSubmit(item){
    document.forms[0].action.value=item;
    document.forms[0].submit();
}

//  checks if "Enter" key has been pressed, and submits the "actionName"
function checkEnter(e, actionName){
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  if(charCode == 13){
    setActionAndSubmit(actionName);    
  }
  else{
    return true;
  }
}

//  Creates the states selection list.  This function should be called from the "Country" select onchange event. 
//  The array looks like:
//  var statesArray = [["AE",[["AE-ALL","All States/Provinces (United Arab Emirates)"]]],.......

function createStateDropdown(that, state_Select_ID){
  var stateSelectObj = getTheObject(state_Select_ID);
  var countryStr = "";
  
  
  for(var i=0; i<that.options.length; i++){
    if(that.options[i].selected){
	  countryStr = that.options[i].value;

	  break;
	}
  }
 
  for(var i=0;i<statesArray.length;i++){
    if(statesArray[i][0] == countryStr) {
	  var arr = statesArray[i][1];
	  
	  stateSelectObj.options.length = arr.length;
	  for(var j=0; j<arr.length; j++){
        stateSelectObj.options[j].value=arr[j][0];
        stateSelectObj.options[j].text=arr[j][1];
	  }
	  break;
	}
  }
  
}


//  moves selection items from one box to the other 
function move(fbox, tbox) {
  var arrFbox = new Array();
  var arrTbox = new Array();
  var arrLookup = new Array();
  var i;
  for (i = 0; i < tbox.options.length; i++) {
    arrLookup[tbox.options[i].text] = tbox.options[i].value;
    arrTbox[i] = tbox.options[i].text;
  }
  var fLength = 0;
  var tLength = arrTbox.length;
  for(i = 0; i < fbox.options.length; i++) {
    arrLookup[fbox.options[i].text] = fbox.options[i].value;
    if (fbox.options[i].selected && fbox.options[i].value != "") {
      arrTbox[tLength] = fbox.options[i].text;
      tLength++;
    }
    else {
      arrFbox[fLength] = fbox.options[i].text;
      fLength++;
    }
  }
  arrFbox.sort();
  arrTbox.sort();
  fbox.length = 0;
  tbox.length = 0;
  var c;
  for(c = 0; c < arrFbox.length; c++) {
    var no = new Option();
    no.value = arrLookup[arrFbox[c]];
    no.text = arrFbox[c];
    fbox[c] = no;
  }
  for(c = 0; c < arrTbox.length; c++) {
    var no = new Option();
    no.value = arrLookup[arrTbox[c]];
    no.text = arrTbox[c];
    tbox[c] = no;
  }
} 

 
//links to appropriate button classes
function mOverButton(that){
  that.className = "img_button_hover";
}
function mOutButton(that){
  that.className = "img_button";
}
function makeButtonEnabled(buttonId){
  var obj = getTheObject(buttonId);
  if (obj != null)
  {
  	obj.disabled=false;
  	obj.className = "img_button";  
  }	
}
function makeButtonDisabled(buttonId){
  	var obj = getTheObject(buttonId);
  if (obj != null)
  {
 	obj.disabled=true;
  	obj.className = "img_button_disabled";  
  }
}

function makeTextBoxEnabled(boxId) {
  	var obj = getTheObject(boxId);
  	
	if (obj != null) {
		obj.disabled  = false;
  		obj.className = "text_normal";
  		obj.readonly  = false;
	}
}

function makeTextBoxDisabledGreyed(boxId) {
  	var obj = getTheObject(boxId);
  	
	if (obj != null) {
		obj.disabled  = true;
  		obj.className = "text_disabled";
  		obj.readonly  = true;
	}
}

function makeTextBoxDisabled(boxId) {
  	var obj = getTheObject(boxId);
  	
	if (obj != null) {
		obj.disabled  = true;
  		obj.readonly  = true;
	}
}



function replaceAll(wholeStr, oldStr, newStr){
  var intIndexOfMatch = wholeStr.indexOf(oldStr);
  while (intIndexOfMatch != -1){
    wholeStr = wholeStr.replace(oldStr, newStr);
    intIndexOfMatch = wholeStr.indexOf(oldStr);
  }
  return wholeStr;
}

function autofitIframe(id){
  var xx = this.document.getElementById("main_content").scrollHeight;
  if(xx<450){
    xx = 450;
    this.document.getElementById("main_content").style.height = "450px";
  }
  parent.document.getElementById(id).style.height=xx+"px";
}