//method returns element for id. Works in IE 6, Firefox.
function _getElement(id) {
	var object = null;
	if( document.layers ) {   
		object = document.layers[id];
	} else if( document.all ) {
		object = document.all[id];
	} else if( document.getElementById ) {
		object = document.getElementById(id);
	}
	return object;
}

//method used in Auction Location Go button. 
//Selected location's value is set as the Form action and form is submitted.
function callSelectedLocation(listboxId, formId){
      var selectListBox = _getElement(listboxId);
      if(selectListBox != null){
            var thisform = _getElement(formId);
            thisform.action = selectListBox.options[selectListBox.selectedIndex].value;
      }
}

//method used in Auction Location drop-down with Go button.
//Style listhead is applied to list items ADESA U.S., ADESA Canada and ADESA Mexico.
//if any new item also needs this style add it to if condition.
function setStyleToLocationList(listboxId){

	var divelem = _getElement(listboxId);
	
	var optionelems = divelem.getElementsByTagName('option');
	
	for(i=0;i<optionelems.length;i++){
		if(optionelems[i].text == 'ADESA U.S.' || optionelems[i].text == 'ADESA Canada' || optionelems[i].text == 'ADESA Mexico'){
			optionelems[i].className="listhead";
		}
	}
}

     //Changing the style of auction countries to bold and make the currently selected item highlighted

      function changeStyleOfAucCountries(listBoxId, hiddenInputId, currentSelectedItem) {
            var selectComp = _getElement(listBoxId);
            var hiddenComp = _getElement(hiddenInputId);
            var currSelectOption = _getElement(currentSelectedItem)
            var countryGroupShortNames = hiddenComp.value.split(",");

                  if(currSelectOption.value == null || 
                              currSelectOption.value.length==0) {
                        selectComp.options[0].selected = true;
                     } else {
                           for (i=0;i<selectComp.length;i++){
                    if(selectComp.options[i].value==currSelectOption.value) {
                    	if(selectComp.options[i].text==null  || selectComp.options[i].text=='' 
                  						|| selectComp.options[i].text=="") {
						     selectComp.options[0].selected = true;              		
                  		}else {
	                        selectComp.options[i].selected=true;
	                    }
                  	}
               	}
             }
            for (i=0;i<selectComp.length;i++){
                  for(j=0;j<countryGroupShortNames.length;j++) {
                  if(selectComp.options[i].value==countryGroupShortNames[j]) {
                        selectComp.options[i].className="listhead";
                        countryGroupShortNames.splice(j,1);
                  }
                  }
            }
          }
//Register keypress for firefox
function init() {
    if (document.addEventListener) {
       document.addEventListener("keypress",keypress,false);
    } else if (document.attachEvent) {
       document.attachEvent("onkeypress", keypress);
    } else {
       document.onkeypress= keypress;
    }
}

//keypress for firefox
function keypress(e)
{
   if (!e) e= event;
}
init();


//Submit the form on pressing enter in this field
function submitOnEnter(myForm,e) {
	var keycode;
	if(window.event) { 
		keycode = e.keyCode 
	} else if(e.which) { 
		keycode = e.which 
	}
	if(keycode == 13){
		myForm.submit();
	}
}