var KEY_UP = 38;
var KEY_DOWN = 40;
var KEY_ENTER = 13;
var ELEMENT_NODE = 1;
var KEY_ESCAPE = 27;
var KEY_F4 = 115;

/* called via button to toggle drop down open; does not set focus to any item
*/
function blurcombo(obj,param){
	if (obj.value==''){obj.value=$("#year-range").slider("option", param);
		if (param=='max') $("#year-range").slider("values", 1,$("#year-range").slider("option", "max"));
		else
		if (param=='min') $("#year-range").slider("values", 0,$("#year-range").slider("option", "min"));
	}else{
		if (param=='max') {
			other=document.getElementById('yearfromS').value;
			if (parseInt(obj.value)<parseInt(other)){
				$("#year-range").slider("values", 1,other);
				obj.value=other;
			}
			else
				$("#year-range").slider("values", 1,obj.value);
		}
		else
		if (param=='min'){ 
			other=document.getElementById('yeartoS').value;
			if (parseInt(obj.value)>parseInt(other)){
				$("#year-range").slider("values", 0,other);
				obj.value=other;
			}
			$("#year-range").slider("values", 0,obj.value);
		}
	}
	
}
function blurcombodiv(obj,param){
	//alert(1);
	//obj.style.display="none";
	/*if (param=='max') $("#year-range").slider("values", 1,$("#year-range").slider("option", "max"));
		else
		if (param=='min') $("#year-range").slider("values", 0,$("#year-range").slider("option", "min"));
		*/
}
function openCombo(event,inputId, comboId) {
  var iField = document.getElementById(inputId);
  if (gComboEx == null) {
      gComboEx = document.getElementById(comboId);
  }
  var cb = gComboEx;
  var bComboShow = cb.style.display == "block";
  if (!bComboShow) {
    // position combo and show
    showCombo(iField,cb);
    gItemNum = -1; // no item has focus - combo is open
  }
  else {
    setStyle(cb,"display","none","");
    // reset current item
    gItemNum = -1;
  }
  //set focus into input field  (may want to change this to set focus to first item when opened)
  gFocusItem = iField;
  setTimeout("doFocus();",0);
}

/* position and show the combo
*/
function getY( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetTop;
oElement = oElement.offsetParent;
}
return iReturnValue;
}
function getX( oElement )
{
var iReturnValue = 0;
while( oElement != null ) {
iReturnValue += oElement.offsetLeft;
oElement = oElement.offsetParent;
}
return iReturnValue;
}
function showCombo(iField,cb) {
  // position combo and show
//  var offTop= (iField.offsetTop + iField.offsetHeight) + "px";
  var offTop= (getY(iField) + iField.offsetHeight) + "px";
  //var offLeft = iField.offsetLeft + "px";
  var offLeft = getX(iField) + "px";
  setStyle(cb,"top", offTop, "");
  setStyle(cb,"left", offLeft, "");
  setStyle(cb,"display", "block", "");
  return;
}

var gItemNum = 0;  // global to store the current item selected in the combo
var gComboEx  = null;

function focusCombo(event, iField, comboId) {
  var key=event.keyCode;
  var bEventContinue = true;
  if (gComboEx == null) {
    gComboEx = document.getElementById(comboId);
  }
    var cb = gComboEx;
  if (key == KEY_DOWN || key == KEY_F4) {
    bEventContinue = false;

    var bComboShow = cb.style.display == "block";
    if (!bComboShow) {
      showCombo(iField,cb);
    }
    // set focus to first item
      var items = cb.childNodes;
      var iLen = items.length;
      // find first elem with class == "item"
      var i = 0;
      while(items[i] != null && i<iLen) {
        if (items[i].nodeType == ELEMENT_NODE  && items[i].className == "item") {
          gFocusItem = items[i];
          break;
        }
        i++;
      }

      gItemNum = 0;
      setTimeout("doFocus();",0);
      bEventContinue = false;
    } // end of if key down
    else if (key == KEY_ENTER) {
      //  add the current value to the list if it does not already exist
      bEventContinue = false;
      if (iField.value != null && iField.value.length > 0) {
        focusItem(event,gComboEx, iField);
//		gComboEx.style.display="none";
      }
      // else do nothing no data in input field
    } // end of if KEY_ENTER
    else if (key == KEY_ESCAPE) {
          if (iField.value != null && iField.value.length > 0) {
            bEventContinue=true; // do nothing, let input field handle event
          }
          else {
            bEventContinue = false;
            setStyle(gComboEx,"display","none","");
            // reset current item
            gItemNum = -1;
          }
    }else if(!isNumberKey(event)){
		bEventContinue=false;
	}

  return bEventContinue;
}

function focusItem(event,combo, iField)  {
  var curValue = iField.value;
  var focusItem = null;
  var elems = getItems(combo);
  var eLen = elems.length;
   var bFound = false;
  for (var i=0 ; i<eLen; i++ ) {
    if (elems[i].hasChildNodes() && elems[i].firstChild.nodeValue == curValue) {
      bFound = true;
      focusItem =elems[ i];
      gItemNum = i;
      break;
    }
  }
  if (!bFound) {
    focusItem = addItem(combo,curValue, elems.length);
    gItemNum = elems.length;
  }
  if (focusItem != null) {
    gFocusItem = focusItem;
    if (gComboEx.style.display != "block") {
      // position
      var offTop= (getY(iField) + iField.offsetHeight) + "px";
      var offLeft = getX(iField) + "px";
      setStyle(combo,"top", offTop, "");
      setStyle(combo,"left", offLeft, "");
    }
    else {
      // hide
      setStyle(combo,"display", "none", "");
    }
    setStyle(combo,"display", "block", "");
    setTimeout("doFocus();",0);



  }
  // else - do nothing

}

function addItem(combo, curValue, count) {
  var newDiv = document.createElement("div");
  var newText = document.createTextNode(curValue);
  newDiv.appendChild(newText);
  newDiv.setAttribute("tabindex", "-1");
  newDiv.setAttribute("class", "item");
  newDiv.setAttribute("onclick", "gItemNum=" +count +";");
  newDiv.setAttribute("role", "listitem");
   combo.appendChild(newDiv);
  return newDiv;
}
function addItem2(combo, curValue, count) {
  var newDiv = document.createElement("div");
  var newText = document.createTextNode(curValue);
  newDiv.appendChild(newText);
  newDiv.setAttribute("tabindex", "-1");
  newDiv.setAttribute("class", "item2");
  newDiv.setAttribute("onclick", "gItemNum2=" +count +";");
  newDiv.setAttribute("role", "listitem");
   combo.appendChild(newDiv);
  return newDiv;
}

function doComboNav(event, combo, inputId) {
  var key = event.keyCode;
  var bEventContinue = true;
  if (gComboEx == null) {
    gComboEx = combo;
  }
  if (key == KEY_UP || key==KEY_DOWN) {
    bEventContinue = false;
    var nextItemIdx = 0;
    // simple loop thru childNodes to  find element nodes with class=="item"
    // does NOT  recurse into nodes
    var elems = getItems(gComboEx);
    var eLen = elems.length;
    if (key==KEY_UP) {
      nextItemIdx = gItemNum -1; //nextItemIdx = (gItemNum + (eLen-1)) % eLen;
    }
    else {
      nextItemIdx = (gItemNum +1);   //% eLen;
      if (nextItemIdx == eLen) {
        nextItemIdx = -1;
      }
    }
    gItemNum = nextItemIdx;
    if (gItemNum == -1 ) {
      // set focus to input field
      gFocusItem = document.getElementById(inputId);
    }
    else {
      gFocusItem = elems[nextItemIdx];
    }
    setTimeout("doFocus();",0);

  } // end of if up down arrows
  else if (key == KEY_ENTER || (!event.keyCode && event.button >=0 ) ) {
    //get the value and put into input field
    var elems = getItems(gComboEx);
    var focusItem = elems[gItemNum];
    if (focusItem != null && focusItem.getAttribute("aria-disabled") !="true") {
      var textNode = focusItem.firstChild;  // BIG assumption that only one child
      var data = textNode.nodeValue;
	  if (data>=$("#year-range").slider("option", 'min')&&data<=$("#year-range").slider("values", 1)){
	  	$("#year-range").slider("values", 0,data);  
	  }else{
		 $("#year-range").slider("values", 0,$("#year-range").slider("values", 1));  
	  }
      var iField = document.getElementById(inputId);
      iField.value = data;
      setStyle(gComboEx,"display","none","");
      gItemNum = 0;
      gFocusItem = iField;
      setTimeout("doFocus();", 0);
    }
  }
  else if (key == KEY_ESCAPE ) {
    // close the combobox
    bEventContinue=false;
    setStyle(combo,"display","none","");
    // reset current item
    gItemNum = 0;
    // set focus to input field
    gFocusItem=document.getElementById(inputId);
    setTimeout("doFocus();",0);
  }

  return bEventContinue;
}

function getItems(combo) {
  var elems = new Array();
  // simple loop thru childNodes to find element nodes with class=="item"
  // does NOT  recurse into nodes
  var elems = new Array();
  var items=combo.childNodes;
  var iLen = items.length;
  for (var i=0; i<iLen; i++) {
    if (items[i].nodeType == ELEMENT_NODE && (items[i].className == "item" || items[i].className == "item focus")) {
      elems[elems.length] = items[i];
    }
  }
  return elems;
}
function getItems2(combo) {
  var elems = new Array();
  // simple loop thru childNodes to find element nodes with class=="item"
  // does NOT  recurse into nodes
  var elems = new Array();
  var items=combo.childNodes;
  var iLen = items.length;
  for (var i=0; i<iLen; i++) {
    if (items[i].nodeType == ELEMENT_NODE && (items[i].className == "item2" || items[i].className == "item2 focus")) {
      elems[elems.length] = items[i];
    }
  }
  return elems;
}







/*----------------------------------------------------- helper JS -----------------------------------------------------*/
function setStyle(theObj, styleName, styleValue, priority) {
  var bSuccess = false;

  try {
    if (theObj.style && theObj.style.setProperty) {
      theObj.style.setProperty(styleName, styleValue,priority);
      bSuccess = true;
    }
  } catch (ex) {
    alert('exception caught setting style: ' + ex.message); // cannot do anything try the next method
  }
  if (!bSuccess) {
    try {
      theObj.style[styleName] = styleValue;
      bSuccess = true;
    } catch (exNext) {
      alert('exception caught setting direct style: ' + exNext.message); // cannot do anything
    }
  }
  return bSuccess;
} // end of setStyle

// global to store the item to be focused
gFocusItem =null;
gLastFocusItem = null;
function doFocus()
{
  if (gFocusItem != null) {
    gFocusItem.focus();
    if (gLastFocusItem && gLastFocusItem.className == 'item focus')
      gLastFocusItem.className = 'item';
    if (gFocusItem && gFocusItem.className == 'item')
      gFocusItem.className = 'item focus';
    gLastFocusItem = gFocusItem;
    gFocusItem=null;
  }
}

/*-----------------------------------------------------end helper JS -----------------------------------------------------*/
function openCombo2(event,inputId, comboId) {
  var iField = document.getElementById(inputId);
  if (gComboEx2 == null) {
      gComboEx2 = document.getElementById(comboId);
  }
  var cb = gComboEx2;
  var bComboShow = cb.style.display == "block";
  if (!bComboShow) {
    // position combo and show
    showCombo(iField,cb);
    gItemNum2 = -1; // no item has focus - combo is open
  }
  else {
    setStyle(cb,"display","none","");
    // reset current item
    gItemNum2 = -1;
  }
  //set focus into input field  (may want to change this to set focus to first item when opened)
  gFocusItem2 = iField;
  setTimeout("doFocus2();",0);
}

/* position and show the combo
*/

var gItemNum2 = 0;  // global to store the current item selected in the combo
var gComboEx2  = null;

function focusCombo2(event, iField, comboId) {
  var key=event.keyCode;
  var bEventContinue = true;
  if (gComboEx2 == null) {
    gComboEx2 = document.getElementById(comboId);
  }
    var cb = gComboEx2;
  if (key == KEY_DOWN || key == KEY_F4) {
    bEventContinue = false;

    var bComboShow = cb.style.display == "block";
    if (!bComboShow) {
      showCombo(iField,cb);
    }
    // set focus to first item
      var items = cb.childNodes;
      var iLen = items.length;
      // find first elem with class == "item"
      var i = 0;
      while(items[i] != null && i<iLen) {
        if (items[i].nodeType == ELEMENT_NODE  && items[i].className == "item2") {
          gFocusItem2 = items[i];
          break;
        }
        i++;
      }

      gItemNum2 = 0;
      setTimeout("doFocus2();",0);
      bEventContinue = false;
    } // end of if key down
    else if (key == KEY_ENTER) {
      //  add the current value to the list if it does not already exist
      bEventContinue = false;
      if (iField.value != null && iField.value.length > 0) {
        focusItem2(event,gComboEx2, iField);
      }
      // else do nothing no data in input field
    } // end of if KEY_ENTER
    else if (key == KEY_ESCAPE) {
          if (iField.value != null && iField.value.length > 0) {
            bEventContinue=true; // do nothing, let input field handle event
          }
          else {
            bEventContinue = false;
            setStyle(gComboEx2,"display","none","");
            // reset current item
            gItemNum2 = -1;
          }
    }else if(!isNumberKey(event)){
		bEventContinue=false;
	}

  return bEventContinue;
}

function focusItem2(event,combo, iField)  {
  var curValue = iField.value;
  var focusItem = null;
  var elems = getItems2(combo);
  var eLen = elems.length;
   var bFound = false;
  for (var i=0 ; i<eLen; i++ ) {
    if (elems[i].hasChildNodes() && elems[i].firstChild.nodeValue == curValue) {
      bFound = true;
      focusItem =elems[ i];
      gItemNum2 = i;
      break;
    }
  }
  if (!bFound) {
    focusItem = addItem2(combo,curValue, elems.length);
    gItemNum2 = elems.length;
  }
  if (focusItem != null) {
    gFocusItem2 = focusItem;
    if (gComboEx2.style.display != "block") {
      // position
      var offTop= (getY(iField) + iField.offsetHeight) + "px";
      var offLeft = getX(iField) + "px";
      setStyle(combo,"top", offTop, "");
      setStyle(combo,"left", offLeft, "");
    }
    else {
      // hide
      setStyle(combo,"display", "none", "");
    }
    setStyle(combo,"display", "block", "");
    setTimeout("doFocus2();",0);



  }
  // else - do nothing

}
function doComboNav2(event, combo, inputId) {
  var key = event.keyCode;
  var bEventContinue = true;
  if (gComboEx2 == null) {
    gComboEx2 = combo;
  }
  if (key == KEY_UP || key==KEY_DOWN) {
    bEventContinue = false;
    var nextItemIdx = 0;
    // simple loop thru childNodes to  find element nodes with class=="item"
    // does NOT  recurse into nodes
    var elems = getItems2(gComboEx2);
    var eLen = elems.length;
    if (key==KEY_UP) {
      nextItemIdx = gItemNum2 -1; //nextItemIdx = (gItemNum + (eLen-1)) % eLen;
    }
    else {
      nextItemIdx = (gItemNum2 +1);   //% eLen;
      if (nextItemIdx == eLen) {
        nextItemIdx = -1;
      }
    }
    gItemNum2 = nextItemIdx;
    if (gItemNum2 == -1 ) {
      // set focus to input field
      gFocusItem2 = document.getElementById(inputId);
    }
    else {
      gFocusItem2 = elems[nextItemIdx];
    }
    setTimeout("doFocus2();",0);

  } // end of if up down arrows
  else if (key == KEY_ENTER || (!event.keyCode && event.button >=0 ) ) {
    //get the value and put into input field
    var elems = getItems2(gComboEx2);
    var focusItem = elems[gItemNum2];
    if (focusItem != null && focusItem.getAttribute("aria2-disabled") !="true") {
      var textNode = focusItem.firstChild;  // BIG assumption that only one child
      var data = textNode.nodeValue;
	  
	  if (data<=$("#year-range").slider("option", 'max')&&data>=$("#year-range").slider("values", 0)){
	  	$("#year-range").slider("values", 1,data);  
	  }else{
		 $("#year-range").slider("values", 1,$("#year-range").slider("values", 0));  
	  }
      var iField = document.getElementById(inputId);
      iField.value = data;
      setStyle(gComboEx2,"display","none","");
      gItemNum2 = 0;
      gFocusItem2 = iField;
      setTimeout("doFocus2();", 0);
    }
  }
  else if (key == KEY_ESCAPE ) {
    // close the combobox
    bEventContinue=false;
    setStyle(combo,"display","none","");
    // reset current item
    gItemNum2 = 0;
    // set focus to input field
    gFocusItem2=document.getElementById(inputId);
    setTimeout("doFocus2();",0);
  }

  return bEventContinue;
}

/*----------------------------------------------------- helper JS -----------------------------------------------------*/
// global to store the item to be focused
gFocusItem2 =null;
gLastFocusItem2 = null;
function doFocus2()
{
  if (gFocusItem2 != null) {
    gFocusItem2.focus();
    if (gLastFocusItem2 && gLastFocusItem2.className == 'item2 focus')
      gLastFocusItem2.className = 'item2';
    if (gFocusItem2 && gFocusItem2.className == 'item2')
      gFocusItem2.className = 'item2 focus';
    gLastFocusItem2 = gFocusItem2;
    gFocusItem2=null;
  }
}

var typeIn='';
//selObj=document.forms[0].sel
function getText(key)
{
for(i=0;i<selObj.options.length-1;i++)
{
len=(selObj.options[selObj.options.length -1].innerText+key).length
//alert(selObj.options[i].innerText.substr(0,len))
if(selObj.options[selObj.options.length -1].innerText+key==selObj.options[i].innerText.substr(0,len))
{
selObj.options[i].selected=true
return false
}}
}
function chngOption(key)
{tmp=key
getText(tmp)
selObj[selObj.options.length -1].innerText+=key


}
function newOpt()
{
if(selObj[selObj.options.length -1].selected!=true)
{selObj[selObj.options.length -1].innerText=""}
if(selObj.options[selObj.options.length-1].innerText!=""){
selObj.options[selObj.options.length]= new Option("")
}
}



  /*----------------------------------------------
  The Common functions used for all dropdowns are:
  -----------------------------------------------
  -- function fnKeyDownHandler(getdropdown, e)
  -- function fnLeftToRight(getdropdown)`
  -- function fnRightToLeft(getdropdown)
  -- function fnDelete(getdropdown)
  -- function FindKeyCode(e)
  -- function FindKeyChar(e)
  -- function fnSanityCheck(getdropdown)

  --------------------------- Subrata Chakrabarty */

  function fnKeyDownHandler(getdropdown, e)
  {
	  
    fnSanityCheck(getdropdown);

    // Press [ <- ] and [ -> ] arrow keys on the keyboard to change alignment/flow.
    // ...go to Start : Press  [ <- ] Arrow Key
    // ...go to End : Press [ -> ] Arrow Key
    // (this is useful when the edited-text content exceeds the ListBox-fixed-width)
    // This works best on Internet Explorer, and not on NetscapeFirefoxChrome

    var vEventKeyCode = FindKeyCode(e);

    // Press left/right arrow keys
    if(vEventKeyCode == 37)
    {
    fnLeftToRight(getdropdown);
    }
    if(vEventKeyCode == 39)
    {
    fnRightToLeft(getdropdown);
    }

    // Delete key pressed
    if(vEventKeyCode == 46)
    {
    fnDelete(getdropdown);
    }

    // backspace key pressed
    if(vEventKeyCode == 8 || vEventKeyCode==127)
    {
    if(e.which) //NetscapeFirefoxChrome
    {
      //e.which = ''; //this property has only a getter.
    }
    else //Internet Explorer
    {
      //To prevent backspace from activating the -Back- button of the browser
      e.keyCode = '';
      if(window.event.keyCode)
      {
      window.event.keyCode = '';
      }
    }
	
    return true;
    }

    // Tab key pressed, use code below to reorient to Left-To-Right flow, if needed
    //if(vEventKeyCode == 9)
    //{
    //  fnLeftToRight(getdropdown);
    //}
  }

  function fnLeftToRight(getdropdown)
  {
    getdropdown.style.direction = "ltr";
  }

  function fnRightToLeft(getdropdown)
  {
    getdropdown.style.direction = "rtl";
  }

  function fnDelete(getdropdown)
  {
    if(getdropdown.options.length != 0)
    // if dropdown is not empty
    {
    if (getdropdown.options.selectedIndex == vEditableOptionIndex_A)
    // if option the Editable field
    {
      getdropdown.options[getdropdown.options.selectedIndex].text = '';
      getdropdown.options[getdropdown.options.selectedIndex].value = '';
    }
    }
  }


  /*
  Since Internet Explorer and NetscapeFirefoxChrome have different
  ways of returning the key code, displaying keys
  browser-independently is a bit harder.
  However, you can create a script that displays keys
  for either browser.
  The following function will display each key
  in the status line:

  The "FindKey.." function receives the "event" object
  from the event handler and stores it in the variable "e".
  It checks whether the "e.which" property exists (for NetscapeFirefoxChrome),
  and stores it in the "keycode" variable if present.
  Otherwise, it assumes the browser is Internet Explorer
  and assigns to keycode the "e.keyCode" property.
  */

  function FindKeyCode(e)
  {
    if(e.which)
    {
    keycode=e.which;  //NetscapeFirefoxChrome
    }
    else
    {
    keycode=e.keyCode; //Internet Explorer
    }

    //alert("FindKeyCode"+ keycode);
    return keycode;
  }

  function FindKeyChar(e)
  {
    keycode = FindKeyCode(e);
    if((keycode==8)||(keycode==127))
    {
    character="backspace"
    }
    else if((keycode==46))
    {
    character="delete"
    }
    else
    {
    character=String.fromCharCode(keycode);
    }
    //alert("FindKey"+ character);
    return character;
  }

  function fnSanityCheck(getdropdown)
  {
    if(vEditableOptionIndex_A>(getdropdown.options.length-1))
    {
    alert("PROGRAMMING ERROR: The value of variable vEditableOptionIndex_... cannot be greater than (length of dropdown - 1)");
    return false;
    }
  }
  
  
  /*----------------------------------------------
  Dropdown specific global variables are:
  -----------------------------------------------
  1) vEditableOptionIndex_A   --> this needs to be set by Programmer!! See explanation.
  2) vEditableOptionText_A    --> this needs to be set by Programmer!! See explanation.
  3) vPreviousSelectIndex_A
  4) vSelectIndex_A
  5) vSelectChange_A

  --------------------------- Subrata Chakrabarty */

  /*----------------------------------------------
  The dropdown specific functions
  (which manipulate dropdown specific global variables)
  used by all dropdowns are:
  -----------------------------------------------
  1) function fnChangeHandler_A(getdropdown)
  2) function fnKeyPressHandler_A(getdropdown, e)
  3) function fnKeyUpHandler_A(getdropdown, e)

  --------------------------- Subrata Chakrabarty */

  /*------------------------------------------------
  IMPORTANT: Global Variable required to be SET by programmer
  -------------------------- Subrata Chakrabarty  */

  var vEditableOptionIndex_A = 0;

  // Give Index of Editable option in the dropdown.
  // For eg.
  // if first option is editable then vEditableOptionIndex_A = 0;
  // if second option is editable then vEditableOptionIndex_A = 1;
  // if third option is editable then vEditableOptionIndex_A = 2;
  // if last option is editable then vEditableOptionIndex_A = (length of dropdown - 1).
  // Note: the value of vEditableOptionIndex_A cannot be greater than (length of dropdown - 1)

  var vEditableOptionText_A = "--?--";

  // Give the default text of the Editable option in the dropdown.
  // For eg.
  // if the editable option is <option ...>--?--</option>,
  // then set vEditableOptionText_A = "--?--";

  /*------------------------------------------------
  Global Variables required for
  fnChangeHandler_A(), fnKeyPressHandler_A() and fnKeyUpHandler_A()
  for Editable Dropdowns
  -------------------------- Subrata Chakrabarty  */

  var vPreviousSelectIndex_A = 0;
  // Contains the Previously Selected Index, set to 0 by default

  var vSelectIndex_A = 0;
  // Contains the Currently Selected Index, set to 0 by default

  var vSelectChange_A = 'MANUAL_CLICK';
  // Indicates whether Change in dropdown selected option
  // was due to a Manual Click
  // or due to System properties of dropdown.

  // vSelectChange_A = 'MANUAL_CLICK' indicates that
  // the jump to a non-editable option in the dropdown was due
  // to a Manual click (i.e.,changed on purpose by user).

  // vSelectChange_A = 'AUTO_SYSTEM' indicates that
  // the jump to a non-editable option was due to System properties of dropdown
  // (i.e.,user did not change the option in the dropdown;
  // instead an automatic jump happened due to inbuilt
  // dropdown properties of browser on typing of a character )

  /*------------------------------------------------
  Functions required for  Editable Dropdowns
  -------------------------- Subrata Chakrabarty  */

  function fnChangeHandler_A(getdropdown)
  {
    fnSanityCheck(getdropdown);

    vPreviousSelectIndex_A = vSelectIndex_A;
    // Contains the Previously Selected Index

    vSelectIndex_A = getdropdown.options.selectedIndex;
    // Contains the Currently Selected Index

    if ((vPreviousSelectIndex_A == (vEditableOptionIndex_A)) && (vSelectIndex_A != (vEditableOptionIndex_A))&&(vSelectChange_A != 'MANUAL_CLICK'))
    // To Set value of Index variables - Subrata Chakrabarty
    {
      getdropdown[(vEditableOptionIndex_A)].selected=true;
      vPreviousSelectIndex_A = vSelectIndex_A;
      vSelectIndex_A = getdropdown.options.selectedIndex;
      vSelectChange_A = 'MANUAL_CLICK';
      // Indicates that the Change in dropdown selected
      // option was due to a Manual Click
    }
  }

  function fnKeyPressHandler_A(getdropdown, e)
  {
    fnSanityCheck(getdropdown);

    keycode = FindKeyCode(e);
    keychar = FindKeyChar(e);

    // Check for allowable Characters
    // The various characters allowable for entry into Editable option..
    // may be customized by minor modifications in the code (if condition below)
    // (you need to know the keycode/ASCII value of the  character to be allowed/disallowed.
    // - Subrata Chakrabarty

    if ((keycode>47 && keycode<59)||(keycode>62 && keycode<127) ||(keycode==32))
    {
      var vAllowableCharacter = "yes";
    }
    else
    {
      var vAllowableCharacter = "no";
    }

    //alert(window); alert(window.event);

    if(getdropdown.options.length != 0)
    // if dropdown is not empty
      if (getdropdown.options.selectedIndex == (vEditableOptionIndex_A))
      // if selected option the Editable option of the dropdown
      {

        var vEditString = getdropdown[vEditableOptionIndex_A].value;

        // make Editable option Null if it is being edited for the first time
        if((vAllowableCharacter == "yes")||(keychar=="backspace"))
        {
          if (vEditString == vEditableOptionText_A)
            vEditString = "";
        }
        if (keychar=="backspace")
        // To handle backspace - Subrata Chakrabarty
        {
          vEditString = vEditString.substring(0,vEditString.length-1);
          // Decrease length of string by one from right

          vSelectChange_A = 'MANUAL_CLICK';
          // Indicates that the Change in dropdown selected
          // option was due to a Manual Click

        }
        //alert("EditString2:"+vEditString);

        if (vAllowableCharacter == "yes")
        // To handle addition of a character - Subrata Chakrabarty
        {
          vEditString+=String.fromCharCode(keycode);
          // Concatenate Enter character to Editable string

          // The following portion handles the "automatic Jump" bug
          // The "automatic Jump" bug (Description):
          //   If a alphabet is entered (while editing)
          //   ...which is contained as a first character in one of the read-only options
          //   ..the focus automatically "jumps" to the read-only option
          //   (-- this is a common property of normal dropdowns
          //    ..but..is undesirable while editing).

          var i=0;
          var vEnteredChar = String.fromCharCode(keycode);
          var vUpperCaseEnteredChar = vEnteredChar;
          var vLowerCaseEnteredChar = vEnteredChar;


          if(((keycode)>=97)&&((keycode)<=122))
          // if vEnteredChar lowercase
            vUpperCaseEnteredChar = String.fromCharCode(keycode - 32);
            // This is UpperCase


          if(((keycode)>=65)&&((keycode)<=90))
          // if vEnteredChar is UpperCase
            vLowerCaseEnteredChar = String.fromCharCode(keycode + 32);
            // This is lowercase

          if(e.which) //For NetscapeFirefoxChrome
          {
            // Compare the typed character (into the editable option)
            // with the first character of all the other
            // options (non-editable).

            // To note if the jump to the non-editable option was due
            // to a Manual click (i.e.,changed on purpose by user)
            // or due to System properties of dropdown
            // (i.e.,user did not change the option in the dropdown;
            // instead an automatic jump happened due to inbuilt
            // dropdown properties of browser on typing of a character )

            for (i=0;i<=(getdropdown.options.length-1);i++)
            {
              if(i!=vEditableOptionIndex_A)
              {
                var vReadOnlyString = getdropdown[i].value;
                var vFirstChar = vReadOnlyString.substring(0,1);
                if((vFirstChar == vUpperCaseEnteredChar)||(vFirstChar == vLowerCaseEnteredChar))
                {
                  vSelectChange_A = 'AUTO_SYSTEM';
                  // Indicates that the Change in dropdown selected
                  // option was due to System properties of dropdown
                  break;
                }
                else
                {
                  vSelectChange_A = 'MANUAL_CLICK';
                  // Indicates that the Change in dropdown selected
                  // option was due to a Manual Click
                }
              }
            }
          }
        }

        // Set the new edited string into the Editable option
        getdropdown.options[vEditableOptionIndex_A].text = vEditString;
        getdropdown.options[vEditableOptionIndex_A].value = vEditString;

        return false;
      }
    return true;
  }

  function fnKeyUpHandler_A(getdropdown, e)
  {
    fnSanityCheck(getdropdown);

    if(e.which) // NetscapeFirefoxChrome
    {
      if(vSelectChange_A == 'AUTO_SYSTEM')
      {
        // if editable dropdown option jumped while editing
        // (due to typing of a character which is the first character of some other option)
        // then go back to the editable option.
        getdropdown[(vEditableOptionIndex_A)].selected=true;
      }

      var vEventKeyCode = FindKeyCode(e);
      // if [ <- ] or [ -> ] arrow keys are pressed, select the editable option
      if((vEventKeyCode == 37)||(vEventKeyCode == 39))
      {
        getdropdown[vEditableOptionIndex_A].selected=true;
      }
    }
  }
  
  /*----------------------------------------------
  Dropdown specific global variables are:
  -----------------------------------------------
  1) vEditableOptionIndex_D   --> this needs to be set by Programmer!! See explanation.
  2) vEditableOptionText_D    --> this needs to be set by Programmer!! See explanation.
  3) vPreviousSelectIndex_D
  4) vSelectIndex_D
  5) vSelectChange_D

  --------------------------- Subrata Chakrabarty */

  /*----------------------------------------------
  The dropdown specific functions
  (which manipulate dropdown specific global variables)
  used by all dropdowns are:
  -----------------------------------------------
  1) function fnChangeHandler_D(getdropdown)
  2) function fnKeyPressHandler_D(getdropdown, e)
  3) function fnKeyUpHandler_D(getdropdown, e)

  --------------------------- Subrata Chakrabarty */

  /*------------------------------------------------
  IMPORTANT: Global Variable required to be SET by programmer
  -------------------------- Subrata Chakrabarty  */

  var vEditableOptionIndex_D = 6;

  // Give Index of Editable option in the dropdown.
  // For eg.
  // if first option is editable then vEditableOptionIndex_D = 0;
  // if second option is editable then vEditableOptionIndex_D = 1;
  // if third option is editable then vEditableOptionIndex_D = 2;
  // if last option is editable then vEditableOptionIndex_D = (length of dropdown - 1).
  // Note: the value of vEditableOptionIndex_D cannot be greater than (length of dropdown - 1)

  var vEditableOptionText_D = "--?--";

  // Give the default text of the Editable option in the dropdown.
  // For eg.
  // if the editable option is <option ...>--?--</option>,
  // then set vEditableOptionText_D = "--?--";

  /*------------------------------------------------
  Global Variables required for
  fnChangeHandler_D(), fnKeyPressHandler_D() and fnKeyUpHandler_D()
  for Editable Dropdowns
  -------------------------- Subrata Chakrabarty  */

  var vPreviousSelectIndex_D = 0;
  // Contains the Previously Selected Index, set to 0 by default

  var vSelectIndex_D = 0;
  // Contains the Currently Selected Index, set to 0 by default

  var vSelectChange_D = 'MANUAL_DLICK';
  // Indicates whether Change in dropdown selected option
  // was due to a Manual Click
  // or due to System properties of dropdown.

  // vSelectChange_D = 'MANUAL_DLICK' indicates that
  // the jump to a non-editable option in the dropdown was due
  // to a Manual click (i.e.,changed on purpose by user).

  // vSelectChange_D = 'AUTO_SYSTEM' indicates that
  // the jump to a non-editable option was due to System properties of dropdown
  // (i.e.,user did not change the option in the dropdown;
  // instead an automatic jump happened due to inbuilt
  // dropdown properties of browser on typing of a character )

  /*------------------------------------------------
  Functions required for  Editable Dropdowns
  -------------------------- Subrata Chakrabarty  */

  function fnChangeHandler_D(getdropdown)
  {
    fnSanityCheck(getdropdown);

    vPreviousSelectIndex_D = vSelectIndex_D;
    // Contains the Previously Selected Index

    vSelectIndex_D = getdropdown.options.selectedIndex;
    // Contains the Currently Selected Index

    if ((vPreviousSelectIndex_D == (vEditableOptionIndex_D)) && (vSelectIndex_D != (vEditableOptionIndex_D))&&(vSelectChange_D != 'MANUAL_DLICK'))
    // To Set value of Index variables - Subrata Chakrabarty
    {
      getdropdown[(vEditableOptionIndex_D)].selected=true;
      vPreviousSelectIndex_D = vSelectIndex_D;
      vSelectIndex_D = getdropdown.options.selectedIndex;
      vSelectChange_D = 'MANUAL_DLICK';
      // Indicates that the Change in dropdown selected
      // option was due to a Manual Click
    }
  }

  function fnKeyPressHandler_D(getdropdown, e)
  {
    fnSanityCheck(getdropdown);

    keycode = FindKeyCode(e);
    keychar = FindKeyChar(e);

    // Check for allowable Characters
    // The various characters allowable for entry into Editable option..
    // may be customized by minor modifications in the code (if condition below)
    // (you need to know the keycode/ASCII value of the  character to be allowed/disallowed.
    // - Subrata Chakrabarty

    if ((keycode>47 && keycode<59)||(keycode>62 && keycode<127) ||(keycode==32))
    {
      var vAllowableCharacter = "yes";
    }
    else
    {
      var vAllowableCharacter = "no";
    }

    //alert(window); alert(window.event);

    if(getdropdown.options.length != 0)
    // if dropdown is not empty
      if (getdropdown.options.selectedIndex == (vEditableOptionIndex_D))
      // if selected option the Editable option of the dropdown
      {

        var vEditString = getdropdown[vEditableOptionIndex_D].value;

        // make Editable option Null if it is being edited for the first time
        if((vAllowableCharacter == "yes")||(keychar=="backspace"))
        {
          if (vEditString == vEditableOptionText_D)
            vEditString = "";
        }
        if (keychar=="backspace")
        // To handle backspace - Subrata Chakrabarty
        {
          vEditString = vEditString.substring(0,vEditString.length-1);
          // Decrease length of string by one from right

          vSelectChange_D = 'MANUAL_DLICK';
          // Indicates that the Change in dropdown selected
          // option was due to a Manual Click

        }
        //alert("EditString2:"+vEditString);

        if (vAllowableCharacter == "yes")
        // To handle addition of a character - Subrata Chakrabarty
        {
          vEditString+=String.fromCharCode(keycode);
          // Concatenate Enter character to Editable string

          // The following portion handles the "automatic Jump" bug
          // The "automatic Jump" bug (Description):
          //   If a alphabet is entered (while editing)
          //   ...which is contained as a first character in one of the read-only options
          //   ..the focus automatically "jumps" to the read-only option
          //   (-- this is a common property of normal dropdowns
          //    ..but..is undesirable while editing).

          var i=0;
          var vEnteredChar = String.fromCharCode(keycode);
          var vUpperCaseEnteredChar = vEnteredChar;
          var vLowerCaseEnteredChar = vEnteredChar;


          if(((keycode)>=97)&&((keycode)<=122))
          // if vEnteredChar lowercase
            vUpperCaseEnteredChar = String.fromCharCode(keycode - 32);
            // This is UpperCase


          if(((keycode)>=65)&&((keycode)<=90))
          // if vEnteredChar is UpperCase
            vLowerCaseEnteredChar = String.fromCharCode(keycode + 32);
            // This is lowercase

          if(e.which) //For NetscapeFirefoxChrome
          {
            // Compare the typed character (into the editable option)
            // with the first character of all the other
            // options (non-editable).

            // To note if the jump to the non-editable option was due
            // to a Manual click (i.e.,changed on purpose by user)
            // or due to System properties of dropdown
            // (i.e.,user did not change the option in the dropdown;
            // instead an automatic jump happened due to inbuilt
            // dropdown properties of browser on typing of a character )

            for (i=0;i<=(getdropdown.options.length-1);i++)
            {
              if(i!=vEditableOptionIndex_D)
              {
                var vReadOnlyString = getdropdown[i].value;
                var vFirstChar = vReadOnlyString.substring(0,1);
                if((vFirstChar == vUpperCaseEnteredChar)||(vFirstChar == vLowerCaseEnteredChar))
                {
                  vSelectChange_D = 'AUTO_SYSTEM';
                  // Indicates that the Change in dropdown selected
                  // option was due to System properties of dropdown
                  break;
                }
                else
                {
                  vSelectChange_D = 'MANUAL_DLICK';
                  // Indicates that the Change in dropdown selected
                  // option was due to a Manual Click
                }
              }
            }
          }
        }

        // Set the new edited string into the Editable option
        getdropdown.options[vEditableOptionIndex_D].text = vEditString;
        getdropdown.options[vEditableOptionIndex_D].value = vEditString;

        return false;
      }
    return true;
  }

  function fnKeyUpHandler_D(getdropdown, e)
  {
    fnSanityCheck(getdropdown);

    if(e.which) // NetscapeFirefoxChrome
    {
      if(vSelectChange_D == 'AUTO_SYSTEM')
      {
        // if editable dropdown option jumped while editing
        // (due to typing of a character which is the first character of some other option)
        // then go back to the editable option.
        getdropdown[(vEditableOptionIndex_D)].selected=true;
      }

      var vEventKeyCode = FindKeyCode(e);
      // if [ <- ] or [ -> ] arrow keys are pressed, select the editable option
      if((vEventKeyCode == 37)||(vEventKeyCode == 39))
      {
        getdropdown[vEditableOptionIndex_D].selected=true;
      }
    }
  }
  function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
		 if (charCode<96||charCode>105)
         if (charCode > 31 && (charCode < 48 || charCode > 57)&&charCode!=37&&charCode!=39&&charCode!=46||evt.shiftKey==1)
            return false;

         return true;
      }

function getObjInnerText (obj) { 
if (obj){
return (obj.innerText) ? obj.innerText 

: (obj.textContent) ? obj.textContent 

: ""; 
}else{
return "";
}
} 

function includeJs(file) 
{ 

  if (typeof(jQuery)=='undefined') {
		 document.write("<scr" + "ipt type=\"text/javascript\" src=\""+file+"\"></scr" + "ipt>");
    } 
} 

includeJs(API_HTTP+"_PARAMETERS/jquery/js/jquery-1.3.2.min.js");
includeJs(API_HTTP+"_PARAMETERS/jquery/js/jquery-ui-1.7.2.custom.min.js");
includeJs(API_HTTP+"_PARAMETERS/jquery/js/jquery.combobox.js");

function GetSlider(pcaption,name,pleftValue,pleftLimit,prightValue,prightLimit,id,iscons,issold,container,type,pref){
	//alert(trrrrr);
	if (begunpath=='0'||begunpath==0){ var pathtrack=API_HTTP+"_PARAMETERS/jscripts/trackbar";}
	else {var pathtrack=TMP_PATH+"/trackbar";}
	//alert(pathtrack);
	var onms="";
	if (!type)type=0;
	var pdual=false;
	if (name!=('trbzipS'+pref)&&name!='trbzipSNew'){
	 pdual=true;
	}
	
	if (id){
     if (name!=('trbyearS'+pref)&&name!='trbyearSNew'){
	 //onms="onmouseup=\"UpdateFilter('"+id+"','"+iscons+"','"+issold+"');\"";
	 }else{
	 	onms="";//onmouseup=\"doMake('MakeS','ModelS','yearfromS','yeartoS','dealer',2,'TypeS','CondS');\"";
		}
    }
	var interval=1;
    if (name=='trbmileage'||name==('trbmileageS'+pref)||name=='trbmileageSNew') interval=5000;
	else
	if (name=='trbprice'||name==('trbpriceS'+pref)||name=='trbpriceSNew') interval=3000;
	else 
	if (name==('trbzipS'+pref)||name=='trbzipSNew') interval=100;
if (name=='trbyear')
			setVals('yearfrom','yearto',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name==('trbyearS'+pref))
			setVals('yearfromS'+pref,'yeartoS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbyearSNew')
			setVals('yearfromSNew','yeartoSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbmileage') 
			setVals('min_mileage','max_mileage',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name=='trbprice') 
			setVals('min_price','max_price',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name==('trbmileageS'+pref)) 
			setVals('mileagelS'+pref,'mileagerS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbmileageSNew') 
			setVals('mileagelSNew','mileagerSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name==('trbpriceS'+pref)) 
			setVals('pricelS'+pref,'pricerS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbpriceSNew') 
			setVals('pricelSNew','pricerSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name==('trbzipS'+pref)) 
			setVals('zip_rangeS'+pref,'zip_rangeS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbzipSNew') 
			setVals('zip_rangeSNew','zip_rangeSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
	trackbar.getObject(name).init({
	onMove : function() {
		if (name=='trbyear')
			setVals('yearfrom','yearto',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name==('trbyearS'+pref))
			setVals('yearfromS'+pref,'yeartoS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name=='trbyearSNew')
			setVals('yearfromSNew','yeartoSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name=='trbmileage') 
			setVals('min_mileage','max_mileage',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name=='trbprice') 
			setVals('min_price','max_price',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name==('trbmileageS'+pref)) 
			setVals('mileagelS'+pref,'mileagerS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name=='trbmileageSNew') 
			setVals('mileagelSNew','mileagerSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else 
		if (name==('trbpriceS'+pref)) 
			setVals('pricelS'+pref,'pricerS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbpriceSNew') 
			setVals('pricelSNew','pricerSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name==('trbzipS'+pref)) 
			setVals('zip_rangeS'+pref,'zip_rangeS'+pref,this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		else
		if (name=='trbzipSNew') 
			setVals('zip_rangeSNew','zip_rangeSNew',this.leftValue, this.rightValue,this.leftLimit, this.rightLimit);
		
	},
	width : 100, 
	leftLimit : pleftLimit,
	leftValue : pleftValue,
	rightLimit : prightLimit, 
	typeInterval:type,
	rightValue : prightValue, 
	dual : pdual,
	roundUp :  interval, 
	
	caption : pcaption,
	path: pathtrack,
	update: onms,
	hehe : ":-)"
},container);
}
function resetAll(Makeid,Modelid,Typeid){
  var dmake=document.getElementById(Makeid);
  var dmodel=document.getElementById(Modelid);
  var dtype=document.getElementById(Typeid);
  if (dmake) {
	makeval=dmake.value;

	//dmake.selectedIndex=0;
	modelval=dmodel.value; 
	//if (dmodel.selectedIndex>0) 
	dmodel.disabled=false;
  }
  if (dmodel) {
	typeval=dtype.value; 
	dtype.disabled=false;
	/*modelval=dmodel.value; 
	if (dmodel.selectedIndex>0) dmodel.disabled=false;
	//dmodel.selectedIndex=0;
	*/
  }
 /* if (dtype) {
	typeval=dtype.value; 
	if (dtype.selectedIndex>0) dtype.disabled=false;
	//dmype.selectedIndex=0;
  }*/
}
function doMakeD(make,model,yearfrom,yearto,dealer,showall,trim,cond)
	{
var number=make;
var number=make.replace('MakeS','');
if (!trim) trim='Type';
//alert(make+'||'+model+'||'+yearfrom+'||'+yearto+'||'+dealer+'||'+showall);
	var s = document.getElementById(make);
	s.disabled = false;
var sModel = document.getElementById(model);
	sModel.disabled = true;
var sCond=null;
if (cond)
  sCond=document.getElementById(cond);
  if (Site_design!='tmp_015'){
	var sType = document.getElementById(trim);
  }else{
	  var sType=false;
  }

	if (sType)
		sType.disabled = true;
	selmake=getObjInnerText(s.options[0]);
	selmodel=getObjInnerText(sModel.options[0]);
	seltype='';
	if (sType)
	 seltype=getObjInnerText(sType.options[0]);
	var yr='';
	//alert(showall);
	var yrf='';
	var yrt='';
	if (showall==2){
	if (yearfrom&&document.getElementById(yearfrom)) yrf=document.getElementById(yearfrom).value;
	if (yearto&&document.getElementById(yearto)) yrt=document.getElementById(yearto).value;
	var condval='';
	//alert(sCond);
	
	
    if (sCond) condval=sCond.value;
	//alert(Site_design);
	//alert(API_HTTP);
	
		requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_make_d.php?q='+document.getElementById(make).value+
	           '&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+model+'&qma='+make+'&showall='+showall+'&selmake='+selmake+'&selmodel='+selmodel+'&seltype='+seltype+'&nbr='+number) ;
	
	}
	}
	function doMake(make,model,yearfrom,yearto,dealer,showall,trim,cond)
	{
var number=make;
var number=make.replace('MakeS','');
if (!trim) trim='Type';
//alert(make+'||'+model+'||'+yearfrom+'||'+yearto+'||'+dealer+'||'+showall);
	var s = document.getElementById(make);
	s.disabled = false;
var sModel = document.getElementById(model);
	sModel.disabled = true;
var sCond=null;
if (cond)
  sCond=document.getElementById(cond);
  if (Site_design!='tmp_015'){
	var sType = document.getElementById(trim);
  }else{
	  var sType=false;
  }

	if (sType)
		sType.disabled = true;
	selmake=getObjInnerText(s.options[0]);
	selmodel=getObjInnerText(sModel.options[0]);
	seltype='';
	if (sType)
	 seltype=getObjInnerText(sType.options[0]);
	var yr='';
	//alert(showall);
	var yrf='';
	var yrt='';
	if (showall==2){
	if (yearfrom&&document.getElementById(yearfrom)) yrf=document.getElementById(yearfrom).value;
	if (yearto&&document.getElementById(yearto)) yrt=document.getElementById(yearto).value;
	var condval='';
	//alert(sCond);
	
	
    if (sCond) condval=sCond.value;
	//alert(Site_design);
	//alert(API_HTTP);
	if (Site_design=='tmp_015'){
		requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_make_nd.php?q='+document.getElementById(make).value+
	           '&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+model+'&qma='+make+'&showall='+showall+'&selmake='+selmake+'&selmodel='+selmodel+'&seltype='+seltype) ;
	}else {
		requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_make.php?q='+document.getElementById(make).value+
	           '&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+model+'&qma='+make+'&showall='+showall+'&selmake='+selmake+'&selmodel='+selmodel+'&seltype='+seltype+'&nbr='+number) ;
	}
	}
	}
	 function doCondition()
	{
	var cond_field = document.getElementById('Condition');
	var d = new Date();
    var curr_year = d.getFullYear();
	if (cond_field)
	{
	var yr = document.getElementById('Year');
	var k=cond_field.options.length; for (k; k >= 1; k--) { cond_field.options[k]=null; }
		if (yr.value >= curr_year)
		{
		cond_field.options[0] = new Option("New","NEW");
		cond_field.options[2] = new Option("Used","USED");
		cond_field.options[1] = new Option("Certified Pre-Owned","CERTIFIED PRE-OWNED");
		}
		else
		{
		cond_field.options[0] = new Option("Used","USED");
		cond_field.options[1] = new Option("Certified Pre-Owned","CERTIFIED PRE-OWNED");
		}
	}
	}
function EchoCar()
	{
		var rezult_div=document.getElementById('result');
    var car = '' + document.getElementById('year').value +' '+ document.getElementById('Make').value +' '+ document.getElementById('model').value+' '+document.getElementById('Type').value;
    if(rezult_div) {rezult_div.innerHTML =
                        'Selected Car -<b>'+car;}
	}
function requestDataAjax(href) {
//	alert(href);
    span = document.body.appendChild(document.createElement("SPAN"));
    span.style.display = 'none';
    span.innerHTML = 'text<s'+'cript></'+'script>';
    setTimeout(function()
        {   var s = span.getElementsByTagName("script")[0];
            s.language = "JavaScript";
            if (s.setAttribute){
                s.setAttribute('src', href);
            }else{
                s.src = href;
            }
         //   alert(s.src);
           //document.body.removeChild(span);
        }
    , 10);
}
function doLoad(make,model,yearfrom,yearto,dealer,showall,trim,cond) {
		//result_d =  document.getElementById('result_div');
		//debug_d  = document.getElementById('debug_div');
		//encodeURI(FieldValue);
	var yr='';
	var yrf='';
	var yrt='';
	if (!showall) showall=1
	if (yearfrom) yrf=document.getElementById(yearfrom).value;
	if (yearto) yrt=document.getElementById(yearto).value;
	selmodel=getObjInnerText(document.getElementById(model).options[0]);
	seltype='';
	var typename='Type';
	if (trim) typename=trim;
	//if (model=='ModelS') typename='TypeS';
	var sCond=null;
	if (cond)
		sCond=document.getElementById(cond);
	var condval='';
    if (sCond) condval=sCond.value;
	if (document.getElementById(typename))
		seltype=getObjInnerText(document.getElementById(typename).options[0]);
	if (Site_design=='tmp_015'){
			requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_model_nd.php?q='+document.getElementById(make).value+
	           '&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+model+'&qt='+typename+'&showall='+showall+'&selmodel='+selmodel+'&seltype='+seltype) ;
	 }else {
			requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_model.php?q='+document.getElementById(make).value+
	           '&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+model+'&qt='+typename+'&showall='+showall+'&selmodel='+selmodel+'&seltype='+seltype) ;
	 }

    }
function doLoadTrim(make,model,trim,yearfrom,yearto,dealer,showall,cond) {
		//result_d =  document.getElementById('result_div');
		//debug_d  = document.getElementById('debug_div');
		//encodeURI(FieldValue);
	var yr='';
	var yrf='';
	var yrt='';
	if (!showall) showall=1
	if (yearfrom) yrf=document.getElementById(yearfrom).value;
	if (yearto) yrt=document.getElementById(yearto).value;
	var sCond=null;
	if (cond)
		sCond=document.getElementById(cond);
	var condval='';
    if (sCond) condval=sCond.value;
	//selmodel=document.getElementById(model).options[0].innerText;
	if (document.getElementById(trim)){
	seltype=getObjInnerText(document.getElementById(trim).options[0]);
	if (Site_design=='tmp_015'){
			requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_trim_nd.php?q='+document.getElementById(model).value+
	           '&qa='+document.getElementById(make).value+'&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+trim+'&showall='+showall+'&seltype='+seltype) ;
	 }else {
			requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_trim.php?q='+document.getElementById(model).value+
	           '&qa='+document.getElementById(make).value+'&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+trim+'&showall='+showall+'&seltype='+seltype) ;
	}
	}
	
    }
	function doLoadBody(make,model,style,yearfrom,yearto,dealer,showall,cond) {
		//result_d =  document.getElementById('result_div');
		//debug_d  = document.getElementById('debug_div');
		//encodeURI(FieldValue);
	var yr='';
	var yrf='';
	var yrt='';
	if (!showall) showall=1
	if (yearfrom) yrf=document.getElementById(yearfrom).value;
	if (yearto) yrt=document.getElementById(yearto).value;
	var sCond=null;
	if (cond)
		sCond=document.getElementById(cond);
	var condval='';
    if (sCond) condval=sCond.value;
	//selmodel=document.getElementById(model).options[0].innerText;
	if (document.getElementById(style)){
	seltype=getObjInnerText(document.getElementById(style).options[0]);
	
			requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_body.php?q='+document.getElementById(model).value+
	           '&qa='+document.getElementById(make).value+'&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+style+'&showall='+showall+'&seltype='+seltype) ;
	
	}
	
    }
//--------------------------------------------------------------------------------
//<? global $dl; if ($dl->Site_design=='tmp_015'){?>
function doChangeYear(make,model,yearfrom,yearto,dealer,showall,trim,cond){
/*	var yr='';
	if (!showall) showall=1
	if (yearfrom) yrf=$("#year-range").slider('option', 'min');//document.getElementById(yearfrom).value;
	if (yearto) yrt=$("#year-range").slider('option', 'max');//document.getElementById(yearto).value;
	var sCond=null;
	if (cond)
		sCond=document.getElementById(cond);
	var condval='';
    if (sCond) condval=sCond.value;
	selyear=getObjInnerText(document.getElementById('YearS').options[0]);
	seltype=document.getElementById(trim).value;
	maval=document.getElementById(make).value;
	moval=document.getElementById(model).value;
	
			requestDataAjax('<?=API_HTTP;?>_AJAX/vehicle/vehicle.get_year.php?q='+document.getElementById(model).value+
	           '&dealer_id='+document.getElementById(dealer).value+'&yrf='+yrf+'&yrt='+yrt+'&condval='+condval+'&qm='+seltype+'&showall='+showall+'&seltype='+seltype+'&q='+moval+'&qa='+maval+'&selyear='+selyear) ;

*/
}
function IsNumeric(strString) {
var strValidChars = '0123456789.';
var strChar;
var blnResult = true;

if (strString.length == 0) return false;

//check if strString consists of valid characters listed above
for (i = 0; i < strString.length && blnResult == true; i++) {
strChar = strString.charAt(i);
if (strValidChars.indexOf(strChar) == -1) {
blnResult = false;
}
}
return blnResult;
}
function doYear(yearfrom,yearto){

	/*
  if (IsNumeric(yearfrom)&&IsNumeric(yearto)){

    var curmin=$("#year-range").slider("values", 0 );
	var curmax=$("#year-range").slider("values", 1 );
	  if (yearfrom>=curmin){
		  $("#year-range").slider("values", 1,yearto); 
		  $("#year-range").slider("values", 0,yearfrom); 
	  }else{
		  $("#year-range").slider("values", 0,yearfrom); 
		  $("#year-range").slider("values", 1,yearto); 
	  }
	
    $("#yearfromS").val(yearfrom);
	$("#yeartoS").val(yearto);

  }else{
  var year=document.getElementById('YearS').value;
  if (year){
      var curmin=$("#year-range").slider("values", 0 );
	  var curmax=$("#year-range").slider("values", 1 );
	  if (year>=curmin){
		  $("#year-range").slider("values", 1,year); 
		  $("#year-range").slider("values", 0,year); 
	  }else{
		  $("#year-range").slider("values", 0,year); 
		  $("#year-range").slider("values", 1,year); 
	  }
	  $("#yearfromS").val(year);
	  $("#yeartoS").val(year);
  	  
  }
  }
  */
}
	//<? }?>
//--------------------------------------------------------------------------------
function doLoadType(force) {
	 result_d = document.getElementById('result_div');
	 debug_d  = document.getElementById('debug_div');
	 seltype=getObjInnerText(document.getElementById('Type').options[0]);
	 requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_trim.php?q='+document.getElementById('Model').value+'&seltype='+seltype);
    }
function doLoadTypeJ(force) {
	  
	 result_d = document.getElementById('result_div');
	 debug_d  = document.getElementById('debug_div');
	 seltype=getObjInnerText(document.getElementById('Type'+force).options[0]);
	 alert(API_HTTP+'_AJAX/vehicle/vehicle.get_trim.php?q='+document.getElementById('Model'+force).value+'&seltype='+seltype);
	 requestDataAjax(API_HTTP+'_AJAX/vehicle/vehicle.get_trim.php?q='+document.getElementById('Model'+force).value+'&seltype='+seltype);
    }
    function  ShowVehicle()
	{
  	 debug_d  = document.getElementById('debug_div');
     if(debug_d) {
	 debug_d.innerHTML = '<b>Vehicle RESULT :</b><br> Make :'+document.getElementById('Make').value+' MODEL : '+document.getElementById('Model').value+' TRIM  : '+(document.getElementById('Type').value);}
	}
	
    var timeout = null;
    function doLoadUp() {
        if (timeout) clearTimeout(timeout);
        timeout = setTimeout(doLoad, 1000);
    }
	function convertUrlSim(srcurl){
	var res=srcurl.replace(/_--_/g,'||');
	res=res.replace(/_/g,'+');
	res=res.replace(/\//g,'_');
	res=res.replace(/^_/g,'/');
	res=res.replace(/_$/g,'');
	//if (res[0]=='_')res[0]='/';
	//if (res[res.length-1]=='_') res=res.substr(count($res)-1);
	return res+'.html';
}
function doSearchSimp(pref,msg){
	if (document.getElementById('CondS'+pref))
	var condS=document.getElementById('CondS'+pref).value;
	if (document.getElementById('MakeS'+pref))
	var makeS=document.getElementById('MakeS'+pref).value;
	if (document.getElementById('ModelS'+pref))
	var modelS=document.getElementById('ModelS'+pref).value;
	if (document.getElementById('BodyS'+pref))
	var bodyS=document.getElementById('BodyS'+pref).value;
	if (document.getElementById('edtkeywords'))
	var keyS=document.getElementById('edtkeywords').value;
	if (document.getElementById('YearS'+pref))
	var yearS=document.getElementById('YearS'+pref).value;
	var url='/vehicle';
	if (yearS) url+='/'+yearS+'/'+yearS;
	if (makeS) url+='/'+makeS;
	if (modelS) url+='/'+modelS;
	if (bodyS) url+='/'+bodyS;
	if (keyS&&keyS!=msg) url+='/filter/keywords/'+keyS;


	if (url=='/vehicle') url='/vehicle';

	

	document.location.href=convertUrlSim(url.replace(/\s/g,'_'));

	

}