﻿
function getElementById(oID,oDoc)
{
    if( document.getElementById ) 
      {
        return document.getElementById(oID); 
      }
    if (document.all ) 
      {
        return document.all[oID]; 
      }
    if( !oDoc ) { oDoc = document; }
    if (document.layers) 
      {
        if( oDoc.layers[oID] ) 
          { 
            return oDoc.layers[oID]; 
          } 
        else 
          {
            for( var x = 0, y; !y && x < oDoc.layers.length; x++ ) 
            {
              y = getRefToDiv(oID,oDoc.layers[x].document); 
            }
            return y; 
          }
      }
  return document.getElementById(oID);
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function initCarConfig(objCarConfigId)
{
  eval('initCarConfig_' + objCarConfigId + '()');
}

function recallStep(objTabId, stepNum)
{
    var i = 0;
    showTabStep(objTabId, parseInt(stepNum)); 
    setCurrentStep(objTabId, stepNum);
    if (stepNum == 3)
      eval(objTabId + '_getStep_3_State()')
    else
      getStep(objTabId, stepNum);
    var sn = stepNum - 1;
    manageSummaryVisibility(objTabId, eval(objTabId + '_SummaryVisibilities[' + sn + ']'));
    manageObjectVisibility(objTabId, eval(objTabId + '_ObjectVisibilities[' + sn + ']'));
    ////////
    manageOtherDisplays(stepNum)
	////////
    setReloadStep(objTabId, stepNum, '0');
    eval(objTabId + '_ManageNavDisplays()');////////
}


function callPreviousStep(objTabId)
{
	callStep(objTabId, parseInt(eval(objTabId + "_step_current")) - 1);
}

function callNextStep(objTabId)
{
	callStep(objTabId, parseInt(eval(objTabId + "_step_current")) + 1);
}

function callStep(objTabId, stepNum)
{
    if (isBusyWorking(objTabId))
    {
      alert ('We are still processing your request. Please wait...');
      return;
    }
    checkStepChanged(objTabId, getCurrentStep(objTabId)); //For now this has to be called before getReloadStep
    if (!getStepAvailability(objTabId, stepNum))
    {
      var aux = getAllAvailableSteps(objTabId, ', ', ' & ');
      if (aux == '1')
      {
		alert('Please select a make/model/year.');
	  }
	  else
	  {
		alert ('Available steps: ' + replaceStepsByNames(aux));
	  }
      return;
    }
    //var i = 0;
    ////////
    if (document.getElementById("divBuildHeaderText"))
	{
		if (stepNum != 5) 
			document.getElementById("divBuildHeaderText").style.display = '';
	}
	////////
    manageSummaryVisibility(objTabId, eval(objTabId + '_SummaryVisibilities[stepNum - 1]'));
    manageObjectVisibility(objTabId, eval(objTabId + '_ObjectVisibilities[stepNum - 1]'));
    ////////
    manageOtherDisplays(stepNum)
	////////
    switch (getReloadStep(objTabId,stepNum))
    {
        case '0':
          showTabStep(objTabId, stepNum);
          setCurrentStep(objTabId,stepNum);
          break;
        case '1':
          showTabStep(objTabId, stepNum);
          setCurrentStep(objTabId,stepNum);
          getStep(objTabId, stepNum);
          break;
        case '2':
          recallStep(objTabId, stepNum);
          break;
    }
    eval(objTabId + '_ManageNavDisplays()');////////
}

function showTabStep(objID, stepNum)
{
  var i=0;
  for (i = eval(objID + "_step_first"); i < stepNum; i++)
    {
        document.getElementById(objID + "_divStep" + i).style.display = 'none';
        document.getElementById(objID + "_cellStep" + i).className ='gabrielsCarConfigTabInactive';
    }
  document.getElementById(objID + "_cellStep" + stepNum).className = 'gabrielsCarConfigTabActive';
  document.getElementById(objID + "_divStep" + stepNum).style.display = "";
  for (i = stepNum + 1; i <= eval(objID + "_step_total"); i++)
    {
        document.getElementById(objID + "_divStep" + i).style.display = "none";
        document.getElementById(objID + "_cellStep" + i).className = "gabrielsCarConfigTabInactive";
    }
}

function stepOver(objID, stepNum)
{
  if (stepNum == eval(objID + "_step_current")) return;
  document.getElementById(objID + "_cellStep" + stepNum).className = 'gabrielsCarConfigTabOver';
  document.getElementById(objID + "_cellStep" + stepNum).style.cursor = 'pointer';
}

function stepOut(objID, stepNum)
{
  if (stepNum == eval(objID + "_step_current")) return;
  document.getElementById(objID + "_cellStep" + stepNum).className = 'gabrielsCarConfigTabInactive';
}

function getStep(objID, stepNum)
{
   return eval(objID + "_reload_" + stepNum + "()");
}

function getCurrentStep(objID)
{
  return eval(objID + "_step_current");
}

function setCurrentStep(objID, stepNum)
{
  eval(objID + "_step_current = stepNum");
}

function getReloadStep(objStepsId, stepNum)
{ //Values : 
  // 0 = no reload
  // 1 = load
  // 2 = reload
  var x = eval(objStepsId + '_reload') + '';
  return x.charAt(stepNum - 1);
}

function setReloadStep(objStepsId, stepNum, value)
{
  var aux = '';
  var x;
  var i;
  for (i=0; i<stepNum-1; i++)
  {
    x = eval(objStepsId + '_reload') + '';
    aux += x.charAt(i);
  }
  aux += value;
  for (i=stepNum; i<5; i++)
  {
    x = eval(objStepsId + '_reload') + '';
    aux += x.charAt(i);
  }
  eval(objStepsId + '_reload = aux');
}

function isBusyWorking(objStepsId)
{
  return eval(objStepsId + '_busy_working');
}

function getStepAvailability(objStepsId, stepNum)
{
  return eval(objStepsId + '_available[stepNum - 1]');
}

function setStepAvailability(objStepsId, stepNum, value)
{ 
  eval(objStepsId + '_available[stepNum - 1] = value');
}

function setStepAvailabilities(objStepsId, vs1, vs2, vs3, vs4, vs5)
{
  setStepAvailability(objStepsId, 1, vs1);
  setStepAvailability(objStepsId, 2, vs2);
  setStepAvailability(objStepsId, 3, vs3);
  setStepAvailability(objStepsId, 4, vs4);
  setStepAvailability(objStepsId, 5, vs5);
}

function getAllAvailableSteps(objStepId, sep, lastSep)
{
  var i;
  var aux = '';
  for (i=1; i<=5; i++)
  {
    if (getStepAvailability(objStepId,i))
    {
        aux += "," + i;
    }
  }
  if (aux.length > 0) 
  {
    aux = aux.substring(1);
  }
  var auxArr = aux.split(',');
  aux = '';
  for (i=1; i<=auxArr.length; i++)
  {
    if (i == auxArr.length) 
        aux += lastSep + i
    else
        aux += sep + i;
  }
  if (aux.length > 0)
  {
    aux = aux.trim();
    aux = aux.substring(1);
    aux = aux.trim();
  }
  return aux;
}

function replaceStepsByNames(s)
{
    var sOut = '';
    for (i=0; i<s.length; i++)
    {
        switch (s.substring(i,i+1))
        {
            
            case '1':
                sOut += 'make';
                break;
            case '2':
                sOut += 'trims';
                break;
            case '3':
                sOut += 'options';
                break;
            case '4':
                sOut += 'colors';
                break;
            case '5':
                sOut += 'quote';
                break;
            default:
                sOut += s.substring(i,i+1);
        }
    }
    return sOut;
}

function setReloadSteps(objStepsId, value)
{
  var i;
  for (i=1; i<=5; i++)
    setReloadStep(objStepId,i,value); 
}

function getSelectedYear(objStepsId)
{
	if (eval('typeof (' + objStepsId + '_getSelectedYear)') != 'undefined') 
		return eval(objStepsId + '_getSelectedYear()')
	else
		return 0;
}
function getSelectedMakeId(objStepsId)
{
	if (eval('typeof (' + objStepsId + '_getSelectedMakeId)') != 'undefined') 
		return eval(objStepsId + '_getSelectedMakeId()');
	else
		return 0;
}
function getSelectedModelId(objStepsId)
{
	if (eval('typeof (' + objStepsId + '_getSelectedModelId)') != 'undefined') 
		return eval(objStepsId + '_getSelectedModelId()');
	else
		return 0;
}

function checkStepChanged(objStepsId, stepNum)
{
  var i;
  switch (stepNum)
  {
    case 1: 
	  { 
	    var year1 = getHidValues(objStepsId, 'hid_ModelYear');
	    var make1 = getHidValues(objStepsId, 'hid_GbMakeId');
	    var model1 = getHidValues(objStepsId, 'hid_GbModelId');
	    var year2 = getSelectedYear(objStepsId);
	    var make2 = getSelectedMakeId(objStepsId);
	    var model2 = getSelectedModelId(objStepsId);

		if ((year1 != year2) | (make1 != make2) | (model1 != model2))
		{
			var yearmakemodel = year2 + ',' + make2 + ',' + model2;
			if (eval(objStepsId + '_save_1(yearmakemodel' + ',' + 'false)'))
			{
				setReloadStep(objStepsId, 1, '0');
				setStepAvailabilities(objStepsId, true, true, false, false, false);
				for (i=2; i<=5; i++)
					setReloadStep(objStepsId, i, '1');
			}
        }
		break;
	  }
    case 2: 
      {
        if (eval(objStepsId + '_styleId != document.getElementById("frmCarConfig_' + objStepsId + '").hid_StyleId.value'))
          {
            eval(objStepsId + "_save_2();");
            for (i=3;i<=5;i++) 
              setReloadStep(objStepsId, i, '1');
            setStepAvailabilities(objStepsId, true, true, true, false, false);
          }
        break;
      }
    case 3: 
      {  
        if (eval(objStepsId + '_pageChanged') == true)
          {
            eval(objStepsId + '_pageChanged = false');
            for (i=4;i<=5;i++) 
              setReloadStep(objStepsId, i, '1');
            setStepAvailabilities(objStepsId, true, true, true, true, true);
          }
        break;
      }
    case 4: 
      {  
        if (eval(objStepsId + '_isLoadedColorAsOptionMode'))
        {
            //same as step 3
            if (eval(objStepsId + '_pageChanged') == true)
            {
                eval(objStepsId + '_pageChanged = false');
                for (i=4;i<=5;i++) 
                    setReloadStep(objStepsId, i, '1');
                setStepAvailabilities(objStepsId, true, true, true, true, true);
            }
        }
        else
        {
            if (eval(objStepsId + '_extColor != document.getElementById("frmCarConfig_' + objStepsId + '").hid_ExtColorCode.value')
            || eval(objStepsId + '_intColor != document.getElementById("frmCarConfig_' + objStepsId + '").hid_IntColorCode.value'))
            {
                eval(objStepsId + "_save_4();");
                setReloadStep(objStepsId, 5, '1');
                setStepAvailabilities(objStepsId, true, true, true, true, true);
            }
        }
        break; 
      }
    case 5: {  break; }
    default: { return true; break; }
  }
}

function EraseStepInfo(objStepsId, stepNum)
{
  var i;
  switch (stepNum)
  {
    case 1: 
      { 
        break; 
      }
    case 2: 
      {
        break;
      }
    case 3: 
      {  
        break;
      }
    case 4: {  break; }
    case 5: {  break; }
    default: { break; }
  }
}

function getHidValues(objTabId, hidName)
{
  return eval(objTabId + '_getValue(hidName)');
}

function setHidValues(objTabId, hidName, hidValue)
{
  return eval(objTabId + '_setValue(hidName, hidValue)');
}

function setLiveValues(objId, stepFirst, stepTotal, stepCurrent, reload, available)
{
  if ((reload.length == 5) && (available.length == 5))
  {
    var av;
    var avStr = '';
    var i;
    for (i=0; i<5; i++)
    {
      av = (available.charAt(i) == '1');
      avStr = avStr + ',' + av;
    }
    eval('setLiveValues_' + objId + '(stepFirst, stepTotal, stepCurrent, ' + reload + avStr + ')');
  }
}

function saveStep(objTabId, stepNum)
{
  if ((stepNum == 2) || (stepNum == 4))
    eval(objTabId + '_save_' + stepNum + '()');
}

function hideStep(objTabId, stepNum)
{
    document.getElementById(objTabId + '_cellStep' + stepNum).style.display = 'none';
    var aux = document.getElementById(objTabId + '_cellStepSep' + stepNum);
    if (aux)
		aux.style.display = 'none';
	if (stepNum == 1) eval(objTabId + '_step_first = 2');
	if (stepNum == 5) eval(objTabId + '_step_total = 4');
}

//*********************************************
//			Step 2 functions
//*********************************************


function updatePrice(vehicleInfoObjIds,baseInvoice,baseMSRP,destInvoice,destMSRP,optInvoice,optMSRP,totInvoice,totMSRP,pop)
{
  var aux = vehicleInfoObjIds.split(',');
  var s;
  var i;
  for (i=0;i<aux.length;i++)
  {
  s = aux[i] + '_fillRows("' + baseInvoice + '","' + baseMSRP + '","' + destInvoice + '","' + destMSRP + '","' + optInvoice + '","' + optMSRP + '","' + totInvoice + '","' + totMSRP + '");';
  eval(s);
  }
}

    
function updateImage(vehicleInfoObjIds, newURL, show)
{
  if (vehicleInfoObjIds.length == 0) return;
  var aux = vehicleInfoObjIds.split(',');
  var i;
  for (i=0;i<aux.length;i++)
  {
    if (show)
      eval( aux[i] + '_setImage("' + newURL + '", true)');
    else
      eval( aux[i] + '_setImage("' + newURL + '")');
  }
}

function updateName(vehicleInfoObjIds, newName, vehicleNameIds)
{
  var aux = vehicleInfoObjIds.split(',');
  var i;
  for (i=0;i<aux.length;i++)
  {
    eval(aux[i] + '_setTitle("' + newName + '");');
  }
  if (vehicleNameIds != '')
  {
	aux = vehicleNameIds.split(',');
	for (i=0;i<aux.length;i++)
	{
		document.getElementById(aux[i]).innerHTML = newName;
	}
  }
}

function updateTrimNames(objTabId, newTrimMakeName, newTrimModelName, newTrimStyleName)
{
  eval(objTabId + '_updateTrimNames(newTrimMakeName, newTrimModelName, newTrimStyleName)');
}



//*********************************************
//			Step 3 functions
//*********************************************




function toggleOption()
{
}

function removeAllImages(objName, rootUrl)
{
  var i;
  var j = objName.length;
  var allImages = document.getElementsByTagName("img");
  for(i=0; i<allImages.length; i++)
    {
      var oneImage = allImages[i];
      if (oneImage.id.substring(0,j+9) == objName + "_imgItem_")
        {
          oneImage.src = rootUrl + getImageNameByState(0);
          oneImage.alt = "";
        }
    }
}

function setStateImage(objName, rootUrl, optionId, state)
{
  var obj = document.getElementById(objName + "_imgItem_" + optionId);
  if (obj)
  {
    obj.src = rootUrl + getImageNameByState(state);
    obj.alt = getImageAltByState(state);
    return true;
  }
  else
    return false;
}

function getImageNameByState(state)
{
  switch (parseInt(state))
  {
    case 0:
    case 1: {return "img_padding.gif"; break}
    case 2: {return "ico_included.gif"; break}
    case 3: {return "ico_required.gif"; break}
    case 4: {return "ico_notincluded.gif"; break}
    case 5: {return "ico_upgrade.gif"; break}
    default: {return "img_padding.gif"; break}
  }
} 

function getImageAltByState(state)
{
  switch (parseInt(state))
  {
    case 0:
    case 1: {return ""; break}
    case 2: {return "Included with your selection ..."; break}
    case 3: {return "Required by your selection ..."; break}
    case 4: {return "Not Available with your selection ..."; break}
    case 5: {return "Upgraded by your selection ..."; break}
    default: {return ""; break}
  }
} 

function isOptionChecked(state)
{
  if ((parseInt(state) == 0) || (parseInt(state) == 4))
    return false
  else
    return true;
} 

function uncheckAll(objName)
{
  var i;
  var j = objName.length;
  var allInputs = document.getElementsByTagName("input");
  for(i=0; i<allInputs.length; i++)
    {
      var oneInput = allInputs[i];
      if(oneInput.type == "checkbox")
        {
          if (oneInput.id.substring(0,j) == objName)
            {
              if(oneInput.checked)
              {
                oneInput.checked = false;
              }
            }
        }
    }
}

function updateDomItems(objName, optionsStr, rootUrl)
{
  removeAllImages(objName, rootUrl);
  uncheckAll(objName);
  var options = optionsStr.split(';');
  var option;
  var i;
  for (i=0; i<options.length; i++)
  {
    option = options[i].split(',');
    if (option.length == 2)
      {
        if (setStateImage(objName, rootUrl, option[0], option[1]))
        {
            if (isOptionChecked(option[1]))
                checkOption(objName, option[0]);
        }
      }
  }
}

function closePopupInnerHTML()
{
  window.onscroll = ''; //noScroll;
  closePopup();
}

function showPopupInnerHTML(width, innerHTML)
{
  popupWidth = width; //global variable 
  popupHeight = 0; //global variable 
  closePopup();
  sizePopup(width, 3);
  document.getElementById("popup").style.height = "auto";
  document.getElementById("popup").innerHTML = innerHTML;
  showPopup();
  initPopupStay()
}

function initPopupStay()
{
  relocatePopupTimer(popupWidth, 3, 0, 1500)
  if (tooBigPopup())
    window.onscroll = ''; //noScroll;
  else
    window.onscroll = stayPopup;
}

function stayPopup()
{ 
  sizePopup(parseInt(popupWidth), parseInt(popupHeight));
}

function tooBigPopup()
{
	var wh;
	var y;
	var height = parseInt(document.getElementById("popup").style.height);

	if (window.innerWidth==undefined)
	{
		wh=(document.body.clientHeight);
	}
	else
	{
		wh=window.innerHeight;
	}
	y = Math.round((wh / 2) - (height / 2));

	return (y < 10);

}

function relocatePopupTimer(initW, initH, t, timeOut)
{
  if (document.getElementById("popup").scrollHeight > initH)
  {
    popupHeight = document.getElementById("popup").scrollHeight; //global variable
    sizePopup(initW,parseInt(document.getElementById("popup").scrollHeight));
  }
  else
    {
      current += 10;
      if (current >= timeOut)
        alert("Request timed out...")
      else
        setTimeout(function(){relocatePopupTimer(initW, initH, current, timeOut);}, 10);
    }
}

function checkOption(objName, optionId)
{
  document.getElementById(objName + "_checkItem_" + optionId).checked = true;
}

function toggleTree(objName, objCode)
{
     var trTreeChildName = objName + '_trTreeChild' + objCode;
     var imgTreeName = objName + '_imgTree'+objCode;
     if (document.getElementById(trTreeChildName).style.display == '')
       {
         //make it invisible
         document.getElementById(trTreeChildName).style.display = 'none';
         document.getElementById(imgTreeName).src = eval(objName + "_GetImgPlus()");
       }
     else
       {
         //make it visible
         document.getElementById(trTreeChildName).style.display = '';
         document.getElementById(imgTreeName).src = eval(objName + "_GetImgMinus()");
       }
}




//*********************************************
//			Step 4 functions
//*********************************************

function saveSelectedExtColorUrl(objValue, objId, objTabId, imgUrl, colorSeq, isFromOptions)
{
  if (isFromOptions == undefined)
  {
    var i;
    var obj;
    var maxVal = document.getElementById('frmCarConfig_' + objTabId).hid_MaxExtColors.value;
    for (i=0; i<maxVal; i++)
    {
        obj = document.getElementById(objId + '_colorLine' + i);
        if (obj)
            obj.className = 'gabrielsCarConfigListColor';
    }
    obj = document.getElementById(objId + '_colorLine' + colorSeq);
    obj.className = 'gabrielsCarConfigSelectedColor';
    document.getElementById('frmCarConfig_' + objTabId).hid_SelectedExtColorUrl.value = imgUrl;
  
    eval(objTabId + '_extColor ="' + objValue + '"');
    eval(objTabId + '_extColorName ="' + obj.innerHTML + '"');
  
    //this removes the selection from the interior color
    eval(objTabId + '_intColor = ""');
    eval(objTabId + '_intColorName = ""');
  }
}

function selectIntColor(objId, objTabId, intColorCode)
{
  var maxColors = document.getElementById('frmCarConfig_' + objTabId).hid_MaxIntColors.value;
  for (i=0; i<maxColors; i++)
  {
    if (document.getElementById(objId + '_RadioIntItem' + i).value == intColorCode)
    {
      document.getElementById(objId + '_RadioIntItem' + i).checked = true;
      DispSaveIntColorSelected(objId, objTabId,i);
      //getElementById('frmCarConfig_' + objTabId).hid_IntColorCode.value = obj.value;
      return;
    }
  }
}

function DispSaveIntColorSelected(objId, objTabId, intSeq)
{
  var maxVal = document.getElementById('frmCarConfig_' + objTabId).hid_MaxIntColors.value;
  var obj = document.getElementById(objId + '_tdIntItem' + intSeq);
  for (i=0; i<maxVal; i++)
    {
      document.getElementById(objId + '_tdIntItem' + i).className = 'gabrielsCarConfigListColor';
    }
  obj.className = 'gabrielsCarConfigSelectedColor';
  var value = document.getElementById(objId + '_RadioIntItem' + intSeq).value;
  value = objTabId + '_intColor = "' + value + '"';
  eval(value); 
  eval(objTabId + '_intColorName = "' + obj.innerHTML + '"');
}


function showIntColors(objId, objTabId, colorsList, defaultSelect)
{ 
  var colorsArray = colorsList.split(';');
  var colorArray;
  var maxColors = document.getElementById('frmCarConfig_' + objTabId).hid_MaxIntColors.value;
  document.getElementById(objId + '_tdIntColorHeader').style.display = '';
  for (i=0; i<colorsArray.length; i++)
  {
    colorArray = colorsArray[i];
    colorArray = colorArray.split(',');
    document.getElementById(objId + '_trIntColor'+i).style.display = ''; 
    document.getElementById(objId + '_RadioIntItem'+i).value = colorArray[0];
    document.getElementById(objId + '_tdIntItem'+i).innerHTML = colorArray[1];
    document.getElementById(objId + '_tdIntItem'+i).className = 'gabrielsCarConfigListColor';
    //getElementById('tdIntItem'+i).style.background = 'white';
    //getElementById('tdIntItemRadio'+i).style.backgroundColor  = colorArray[2];
    document.getElementById(objId + '_RadioIntItem'+i).checked = false;
  }
  if ((colorsArray.length == 1) && defaultSelect)
  {
    document.getElementById(objId + '_RadioIntItem0').click()
  }
  for (i=colorsArray.length; i<maxColors; i++)
  {
    document.getElementById(objId + '_trIntColor'+i).style.display = 'none'; 
  }
}

function restoreImage(objTabId, vehicleInfoObjIds)
{
  var selectedUrl = document.getElementById('frmCarConfig_' + objTabId).hid_SelectedExtColorUrl.value;
  if (selectedUrl.length > 0)
    {
      updateImage(vehicleInfoObjIds, selectedUrl);
    }
}

function doSelectExtColor(radioObj, objId, objTabId, colorFileNameCar, colorSeq, intColorList, intDefaultSelect, vehicleSummaryIds, vehicleColorIds, colorFileNameCarBig)
{
	radioObj.checked=true; 
	saveSelectedExtColorUrl(radioObj.value, objId, objTabId, colorFileNameCar, colorSeq);
	showIntColors(objId, objTabId , intColorList, intDefaultSelect);
	updateImage(vehicleSummaryIds, colorFileNameCar); 
	updateImage(vehicleColorIds, colorFileNameCarBig);
}

function getElementPosition(obj) 
{
	var curleft = curtop = 0;
	if (obj.offsetParent) 
	{
	    do 
	    {
		    curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} 
		while (obj = obj.offsetParent);
	}
	return [curleft,curtop];
}

function showDivColorHint(e, thisTabId, imageURL)
{
   document.getElementById(thisTabId + 'imgColorHint').src = '';
   var Mxy = getMouseCoord(e);
   var Oxy = getMouseOffsetXY(e);
   var obj = document.getElementById(thisTabId + 'divColorHint');
   
   var obj2 = document.getElementById(thisTabId + 'divCarConfigWrapper');
   var posXY = getElementPosition(obj2);
   
   if (obj.style.display == 'none')
   {
    Mxy[0] = Mxy[0] + 10 - posXY[0];
    Mxy[1] = Mxy[1] + 10 - posXY[1];
    Mxy[0] = 200;
    
    obj.style.position = 'absolute';
    obj.style.top = Mxy[1] + "px";
    obj.style.left = Mxy[0] + "px";
    
    gtsImgLoad(document.getElementById(thisTabId + 'imgColorHint'), imageURL);
    obj.style.display = ''; //obj.innerHTML = Mxy[0] + 'px';
   }
}

function hideDivColorHint(thisTabId)
{
   document.getElementById(thisTabId + 'divColorHint').style.display = 'none'
}



//*******************************************************
//		  Step 5 functions (Review and Get Quote)       *
//*******************************************************



function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}


function FormDealers_Validate(thisTabId, theForm, emailSpell)
{
    if (quoteUserInfo_Validate(thisTabId, theForm, emailSpell))
        quoteLeadForm_Submit(thisTabId);
}

function quoteUserInfo_Validate(thisTabId, theForm, emailSpell)
{
//var theForm = document.SelectDealers
if (emailSpell == undefined)
	emailSpell = 'E-mail';
var str = theForm.UserEmail.value;
str=str.replace(/^\s*/, '').replace(/\s*$/, ''); 
theForm.UserEmail.value = str;
  if (theForm.UserFirstName.value == "")
  {
    alert("Please enter your name in the \"First Name\" field.");
    theForm.UserFirstName.focus();
    return (false);
  }

  if (theForm.UserFirstName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"First Name\" field.");
    theForm.UserFirstName.focus();
    return (false);
  }

  if (theForm.UserFirstName.value.length > 40)
  {
    alert("Please enter at most 40 characters in the \"First Name\" field.");
    theForm.UserFirstName.focus();
    return (false);
  }

  if (theForm.UserLastName.value == "")
  {
    alert("Please enter your name in the \"Last Name\" field.");
    theForm.UserLastName.focus();
    return (false);
  }

  if (theForm.UserLastName.value.length < 2)
  {
    alert("Please enter at least 2 characters in the \"Last Name\" field.");
    theForm.UserLastName.focus();
    return (false);
  }

  if (theForm.UserLastName.value.length > 40)
  {
    alert("Please enter at most 40 characters in the \"Last Name\" field.");
    theForm.UserLastName.focus();
    return (false);
  }

  if (theForm.UserEmail.value == "")
  {
    alert("Please enter your " + emailSpell + " address in the \"" + emailSpell + " Address\" field.");
    theForm.UserEmail.focus();
    return (false);
  }

  if (theForm.UserEmail.value.length < 7)
  {
    alert("Please enter at least 7 characters in the \"" + emailSpell + " Address\" field.");
    theForm.UserEmail.focus();
    return (false);
  }

  if (theForm.UserEmail.value.length > 50)
  {
    alert("Please enter at most 50 characters in the \"" + emailSpell + " Address\" field.");
    theForm.UserEmail.focus();
    return (false);
  }

  var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzŸS‘Zs¦zÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏ<ETH>ÑÒÓÔÕÖØÙÚÛÜY´<THORN>ßàáâãäåæçèéêëìíîï<eth>ñòóôõöøùúûüy´<thorn>ÿ0123456789-@#_-+=$().";
  var checkStr = theForm.UserEmail.value;
  var allValid = true;
  for (i = 0;  i < checkStr.length;  i++)
  {
    ch = checkStr.charAt(i);
    for (j = 0;  j < checkOK.length;  j++)
      if (ch == checkOK.charAt(j))
        break;
    if (j == checkOK.length)
    {
      allValid = false;
      break;
    }
  }
  if (!allValid)
  {
    alert("Please enter only letter, digit and \"@#_-+=$().\" characters in the \"" + emailSpell + " Address\" field.");
    theForm.UserEmail.focus();
    return (false);
  }
  
  if (!isEmailAddr(theForm.UserEmail.value))
  {
    alert("Please enter a complete " + emailSpell + " Address in the form: yourname@yourdomain.com");
    theForm.UserEmail.focus();
    return (false);
  }  
  
  if (theForm.UserTelephoneMandatory)
  {
    if (theForm.UserTelephoneMandatory.value == 'true')
    {
		if (theForm.UserTelephone.value == "")
		{
			alert("Please enter your phone number in the \"Phone Number\" field.");
			theForm.UserTelephone.focus();
			return (false);
		}
	}
  }	
  
  if (theForm.UserTelephone)
  {
	if (theForm.UserTelephone.value == "")
	{
		theForm.ToContact.selectedIndex = 1; //E-Mail
	}
	else
	{
	    var checkOK = "0123456789()xX- ";
  		var checkStr = theForm.UserTelephone.value;
  		var allValid = true;
  		for (i = 0;  i < checkStr.length;  i++)
  			{
    		ch = checkStr.charAt(i);
    		for (j = 0;  j < checkOK.length;  j++)
      		if (ch == checkOK.charAt(j))
        	break;
    		if (j == checkOK.length)
    			{
      			allValid = false;
      			break;
    			}
			}
		theForm.UserTelephone.value = checkStr;
  		if (!allValid)
  			{
    		alert("Please enter only digits in \"Telephone\" field. For an extention use \"x or X\" only.");
    		theForm.UserTelephone.focus();
    		return (false);
  			}
  		checkStr = checkStr.toUpperCase();
  		checkStr = checkStr.split("X");
  		if (checkStr.length >= 1)
  		{
  			if (checkStr[0].replace(/[^0-9]/g,'').length < 10)
  			{
  			  alert("Please enter a full phone number (10 digits minimum).");
  			  return (false);
  			} 
  		}
    }
  }
  else
  {
    theForm.ToContact.selectedIndex = 1; //E-Mail
  }
  
    if (theForm.ToContact.value == "")
	{
		alert("Please select \"Contact Method\".");
		theForm.ToContact.focus();
		return (false);
	}

       /*if (theForm.UserTelephone.value < 1 )
  		{
    	alert("Please enter a Telephone Number.");
    	theForm.UserTelephone.focus();
    	return (false);
  		}*/

  if ((theForm.UserComment) && (theForm.UserComment.value != "" ))
  {
  	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ0123456789-@%:')(#_*&+!.$/ ,- ; <=^>\"\t\r\n\f~";
  	var checkStr = theForm.UserComment.value;
  	var allValid = true;
  	var k = checkStr.length;
  	var p = 0;
  	for (i = 0;  i < k;  i++)
  	{   
    	ch = checkStr.charAt(p);
    	for (j = 0;  j < checkOK.length;  j++)
      	if (ch == checkOK.charAt(j))
      	{  	
      		p = p + 1;
        	break;
        }
        if (j == checkOK.length)
      	  checkStr = checkStr.substring(0,p) + checkStr.substring(p+1) 
  	}
  	theForm.UserComment.value = checkStr;
  	if (!allValid)
  	{
    	alert("Please enter only letter, digit, whitespace and \"@%*$/:)(#_&-+!.;,<=^> \" characters in the \"Comments\" field.");
    	document.theForm.UserComment.focus();
    	return (false);
  	}
  }
  
  //if (theForm.UserAddress && theForm.DealersSource.value == 'DX')
  if (theForm.UserAddress && theForm.AddressRequired.value == 'true')
  {
	if (theForm.UserAddress.value.length < 5)
		{
		alert("Please enter at least 5 characters in the \"Address\" field.");
		theForm.UserAddress.focus();
		return (false);
		}
  }

  if (theForm.UserCity && theForm.AddressRequired.value == 'true')
  {
	if (theForm.UserCity.value.length < 2)
		{
		alert("Please enter at least 2 characters in the \"City\" field.");
		theForm.UserCity.focus();
		return (false);
		}
  }
  
  if (theForm.UserState && theForm.AddressRequired.value == 'true')
  {
	if (theForm.UserState.value.length < 2)
		{
		alert("Please enter 2 characters in the \"State\" field.");
		theForm.UserState.focus();
		return (false);
		}
  }
  
  
  if (theForm.UserZip.value.length < 5)
  {
	alert("Please enter a valid zip code.");
	theForm.UserZip.focus();
	return (false);
  }

    if(theForm.DealersSource.value == 'JS'){
		//theForm.Provider.value = jumpStartId;
		theForm.Year.value = theForm.VehicleYear.value;
		theForm.Make.value = theForm.VehicleMake.value;  
		theForm.Model.value = theForm.VehicleModel.value; 
		//theForm.Trim.value = theForm.VehicleTrim.value; 
		theForm.Color.value = theForm.VehicleExtColor.value;
		theForm.Email.value = theForm.UserEmail.value;
		theForm.FName.value = theForm.UserFirstName.value;
		theForm.LName.value = theForm.UserLastName.value;
		theForm.Zipcode.value =  theForm.sendZip.value;
		theForm.DPhone.value = theForm.UserTelephone.value.replace("-", "");

        if (theForm.ToContact.options[theForm.ToContact.selectedIndex].value == "E" ) {
            theForm.PrefMethod.value = "Email";
        }else if(theForm.ToContact.options[theForm.ToContact.selectedIndex].value = "P") {
        	theForm.PrefMethod.value = "Phone";
        }else{
			theForm.PrefMethod.value = "Email";  
        }

        //// need to be asssigned from the front-end form
        theForm.Trim.Value = theForm.selTrimLevel ? theForm.selTrimLevel.value : theForm.VehicleTrim.value;;
		theForm.Transmission.value = theForm.SelTransmission ? theForm.SelTransmission.value : "No Preference";
		theForm.BestTime.value = theForm.SelBestTime ? theForm.SelBestTime : "Evening";
		theForm.Within.value = theForm.SelTimeFrame ? theForm.SelTimeFrame.value : "Within a Month";
		theForm.PaymentMethod.value = theForm.SelPayment ? theForm.SelPayment.value : "Loan";
		
		////
		theForm.Color.value = theForm.SelExtColor ? theForm.SelExtColor.value : "No Preference";
		////
		theForm.IntColor.value = theForm.SelIntColor ? theForm.SelIntColor.value : "";
		theForm.TradeIn.value = theForm.radioTradeIn ? theForm.radioTradeIn.value : "";
		

		//document.SelectDealers.action = "http://leads.arizonabay.com/v2/public/LeadReceiver.cfm";
    }
    else if(theForm.DealersSource.value == 'DX'){ 

        //// need to be asssigned from the front-end form
		theForm.BestTime.value = theForm.SelBestTime ? theForm.SelBestTime : "Evening";
		theForm.Within.value = theForm.SelTimeFrame ? theForm.SelTimeFrame.value : "Within 4 Weeks";
		theForm.PaymentMethod.value = theForm.SelPayment ? theForm.SelPayment.value : "Financing";

    }
            //theForm.IsLocal.value = localZip;
		//theForm.UseJumpStart.value = useJumpStart;
	
	//everything is fine	
	return true;
}

function quoteLeadForm_Submit(thisTabId)
{
    eval(thisTabId + "_getQuote()");
}

function submit_dealers(thisTabId, theForm) 
{
 if (theForm.QuoteDealerList_DealerList)
	intCheckboxCount = theForm.QuoteDealerList_DealerList.length
 else
	return false;

 if (typeof(intCheckboxCount) == "undefined")
 {
   if (theForm.QuoteDealerList_DealerList) {
    blnAtLeastOneChecked = theForm.QuoteDealerList_DealerList.checked;
    document.getElementById('ListOfDealers').value = theForm.QuoteDealerList_DealerList.value;
  	} else {
    blnAtLeastOneChecked = false;	 
	}
 }
 else
 {
  var listD = '';
  for(i=0; i<intCheckboxCount; i++) {
   if (theForm.QuoteDealerList_DealerList[i].checked) {
    listD += '`' + theForm.QuoteDealerList_DealerList[i].value;
    //alert(listD);
	}
  }
  if (listD != '') {
    blnAtLeastOneChecked = true;
    document.getElementById('ListOfDealers').value = listD.substring(1);
  	} else {
    blnAtLeastOneChecked = false;	 
  }
 }
 if (blnAtLeastOneChecked == true) {
	return FormDealers_Validate(thisTabId, theForm);
 } 
 else 
 {
	alert('Please select (a) dealer(s) to request a quote.');
    return false;
 }
}

/*
function submit_dealers_Ext(theForm) 
{
 if (theForm.QuoteDealerList_DealerList)
	intCheckboxCount = theForm.QuoteDealerList_DealerList.length
 else
	return false;

 if (typeof(intCheckboxCount) == "undefined")
 {
   if (theForm.QuoteDealerList_DealerList) {
    blnAtLeastOneChecked = true;
  	} else {
    blnAtLeastOneChecked = false;	 
	}
 }
 else
 {
  for(i=0; i<intCheckboxCount; i++) {
   if (theForm.QuoteDealerList_DealerList[i].checked) {
    blnAtLeastOneChecked = true;
	break;
   	} else {
    blnAtLeastOneChecked = false;
	}
	}
 }
 if (blnAtLeastOneChecked == true) {
	return FormDealers_Validate(thisTabId, theForm);
 } 
 else 
 {
	alert('Please select a dealer(s) to request a quote.');
    return false;
 }
}
*/

// Get div content
 var getDiv_i
  function getSubmitForm2Div(formName, url, divName)
  {
    document.getElementById(divName).innerHTML = '';
    submitFormToDiv(formName, url, divName);
    return getDivContent(divName);
  }
  
  function getDivContent(divName)
  {
    getDiv_i = 0;
    return timerGetDivContent(divName);
  }
  
  function timerGetDivContent(divName)
  {  
     var timeOut = 5000;
     if (getDiv_i >= timeOut) return "";
     if (document.getElementById(divName).innerHTML == '')
     {
        alert(getDiv_i);
        setTimeout("timerGetDivContent()", 10);
        getDiv_i += 10;
        alert(getDiv_i);
        if (getDiv_i >= timeOut) 
        {
            alert("Request timed out ... Please try again");
            getDiv_i = 0;
            return;
        }
     }
     else
     {
       return "IUE";
       return document.getElementById(divName).innerHTML;
     }
  }
  
  
  
  function switching()
  {
  }
  
  function selectDealerDisplayed(objTabId)
  {
    var objSum = document.getElementById(objTabId + "_divSwitchStep5Summary");
    var objQuo = document.getElementById(objTabId + "_divSwitchStep5Quote");
    if ((objSum.style.display == 'none') && (objQuo.style.display == 'none'))
    {
      return false;
    }
    else
    {
      return (objSum.style.display != 'none');
    }
  }
  
  function selectDealerLoaded(objTabId)
  {
    return !(document.getElementById(objTabId + '_divStep5Quote').innerHTML == '');
  }
  
  
  function showSwitches(objTab)
  {
    var objSum = document.getElementById(objTab + "_divSwitchStep5Summary");
    var objQuo = document.getElementById(objTab + "_divSwitchStep5Quote");
    if ((objSum.style.display == 'none') && (objQuo.style.display == 'none'))
    {
      objSum.style.display = '';
    }
    else
    {
      objSum.style.display = (objSum.style.display == '') ? 'none' : '';
      objQuo.style.display = (objQuo.style.display == '') ? 'none' : '';
    }
  }
  
  function isObjectVisible(stepNum, objId, objTabId, isSummaryObject)
  {
    var auxArr;
    var found = false;
    //alert("objid;objTabId = " + objId + ";" + objTabId);
    if (stepNum <= 0)
        stepNum = getCurrentStep(objTabId);
    stepNum = stepNum - 1; //These arrays are zero-based
    //alert("stepNum = " + stepNum);
    //alert(isSummaryObject);
    if (isSummaryObject)
    {
        auxArr = eval(objTabId + '_SummaryVisibilities[' + stepNum + ']');
    }
    else
    {
        auxArr = eval(objTabId + '_ObjectVisibilities[' + stepNum + ']');
    }
    //alert("auxArr = " + auxArr + " and stepnum=" + stepNum);
    if (auxArr === undefined)
        return true;
    auxArr = auxArr.split(';'); 
    //alert("length = " + auxArr.length);
    if (auxArr.length == 2)
    {
        //alert(auxArr[0]);
        if (auxArr[0] != '') //visibles
        {
        //alert(auxArr[0]);
          var aux1 = auxArr[0].split(',');
          for (i=0; i<aux1.length; i++)
          {
            if (aux1 == objId)
                found = true;
          }
        }
    }
    return found;
  }
  
  function manageSummaryVisibility(objTabId, summaryDisplays)
  {
    //summary displays are : visibles + ";" + non visibles
    var auxArr = summaryDisplays.split(';'); 
    var i;
    if (auxArr.length == 2)
    {
      if (auxArr[0] != '') //visibles
        {
          var aux1 = auxArr[0].split(',');
          for (i=0; i<aux1.length; i++)
          {
            //getElementById(objTabId + '_' + aux1[i]).style.display = '';
            document.getElementById(aux1[i].trim() + '_divVehicleSummary').style.display = '';
          }
        }
      if (auxArr[1] != '') //non visibles
        {
          var aux2 = auxArr[1].split(',');
          var objSum;
          for (i=0; i<aux2.length; i++)
          {
          objSum = aux2[i].trim() + '_divVehicleSummary';
          /*objSum2 = 'carConfig_carConfigSummaryLandscape_divVehicleSummary';
          alert('objSum =' + objSum + '\n' + 'objSum2=' + objSum2 + '\n' + 'objSum.indexOf(objSum2) = ' + objSum.indexOf(objSum2) + '\n'
          + 'getElementById(objSum) = ' + getElementById(objSum) + '\n' + 'getElementById(objSum2) = ' + getElementById(objSum2) + '\n'
          + 'objsum.length =' + objSum.length + '\n' + 'objSum2.length=' + objSum2.length);*/
          
          document.getElementById(objSum).style.display = 'none';
          }
        }
    }
  }
  
  function manageObjectVisibility(objTabId, objDisplays)
  {
    //obj visibilities are : visibles + ";" + non visibles
    var auxArr = objDisplays.split(';');
    var i;
    if (auxArr.length == 2)
    {
      if (auxArr[0] != '')
        {
          var aux1 = auxArr[0].split(',');
          for (i=0; i<aux1.length; i++)
          {
            document.getElementById(aux1[i].trim() + '_divVisibility').style.display = '';
          }
        }
      if (auxArr[1] != '')
        {
          var aux2 = auxArr[1].split(',');
          var objSum;
          for (i=0; i<aux2.length; i++)
          {
          objSum = aux2[i].trim() + '_divVisibility';
          document.getElementById(objSum).style.display = 'none';
          }
        }
    }
  }
  
function manageOtherDisplays(stepNum)
{/********/
	var objQuote = document.getElementById("carConfigGetZipQuoteExt_divVehicleSummary");
	if (objQuote)
	{
		if (stepNum == 5) 
			objQuote.style.display = 'none';
		else
			objQuote.style.display = '';
	}
  /********/ 
}
  
function initLoadingPopup(url, followMouse, checkBoxPositionRight, thisTabId)
{
  if (!thisTabId)
    thisTabId = '';
  document.getElementById(thisTabId + 'divLoader').innerHTML = '<img src="' + url + '" style="border:0px"/>';
  
  hideLoadingPopup(thisTabId);
  if (document.getElementById)
    {
        if(document.layers)
          if (followMouse) document.captureEvents(Event.MOUSEMOVE); else document.captureEvents(Event.MOUSEUP);
        if (thisTabId != '')
            objDivOffsetPosXY = getElementPosition(document.getElementById(thisTabId + 'divCarConfigWrapper'));
        objDivLoader = document.getElementById(thisTabId + "divLoader");
        if (checkBoxPositionRight)
        {
          if (followMouse) document.onmousemove = moveImageLeft; else document.onmouseup = moveImageLeft;
        }
        else
        {
		  if (followMouse) document.onmousemove = moveImageRight; else document.onmouseup = moveImageRight;
		}
    }
}


function showLoadingPopup(thisTabId)
{
  document.getElementById(thisTabId + 'divLoader').style.display = '';
}
  
var objDivOffsetPosXY = 0;
var objDivLoader;

function moveImage(e)
{
   var Mxy = getMouseCoord(e);
   document.getElementById("divLoader").style.top = Mxy[1] + "px";
   document.getElementById("divLoader").style.left = Mxy[0] + "px";
}

function moveImageRight(e)
{
   var Mxy = getMouseCoord(e);
   Mxy[0] = Mxy[0] + 10 - objDivOffsetPosXY[0];
   Mxy[1] = Mxy[1] + 10 - objDivOffsetPosXY[1];
   objDivLoader.style.top = Mxy[1] + "px";
   objDivLoader.style.left = Mxy[0] + "px";
}

function moveImageLeft(e)
{
   var Mxy = getMouseCoord(e);
   Mxy[0] = Mxy[0] - 40 - objDivOffsetPosXY[0];
   Mxy[1] = Mxy[1] + 10 - objDivOffsetPosXY[1];
   objDivLoader.style.top = Mxy[1] + "px";
   objDivLoader.style.left = Mxy[0] + "px";
}

function getMouseCoord(e) {
  var x;
  var y;
  if( !e ) { e = window.event; }
  if( !e ) { return [0,0]; }
  if( typeof( e.pageX ) == 'number' ) {
    x = e.pageX;
    y = e.pageY;
  } else if( typeof( e.clientX ) == 'number' ) {
    x = e.clientX;
    y = e.clientY;
    if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
      x += document.body.scrollLeft;
      y += document.body.scrollTop;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
      x += document.documentElement.scrollLeft;
      y += document.documentElement.scrollTop;
    }
  } else { return [0,0]; }
  return [x,y];
}

function getMouseOffsetXY(e)
{
    if( !e ) { e = window.event; }
    var offsetX = 0;
    var offsetY = 0;
    if(e) 
    { 
        if( typeof( e.clientX ) == 'number' ) 
        {
            if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) 
            {
                offsetX = document.body.scrollLeft;
                offsetY = document.body.scrollTop;
            } 
            else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) 
            {
                offsetY = document.documentElement.scrollLeft;
                offsetX = document.documentElement.scrollTop;
            }
        }
    }
    return [offsetX, offsetY];
}

////
function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}
////


function hideLoadingPopup(thisTabId)
{
  document.getElementById(thisTabId + 'divLoader').style.display = 'none';
}

function getQuote(objTabId, zipCode)
{ 
  //eval(objTabId + '_show_5()');
  //callStep(objTabId, 5);
  //window.scrollTo(0,0);
  if (getStepAvailability(objTabId,4))
  {
	callStep(objTabId, 5)
  }
  else
  {
	showLoadingPopup(objTabId); 
    eval(objTabId + "_show_Quote('" + zipCode + " ');");
  }
}


function getQuoteZip(objTabId, objZipCode)
{ 
  eval(objTabId + '_show_5("' + objZipCode + '")');
  ////////
  document.getElementById("carConfigGetZipQuoteExt_divVehicleSummary").style.display = 'none';
  ////////
}

function boolArray2Str(boolArray)
{
  var retStr = '';
  for (var i=0; i<boolArray.length; i++)
  {
    retStr += (boolArray[i]) ? "1" : "0";
  }
  return retStr;
}

function validateZip(obj)
{
	 if ((obj.length == 5) && (isFinite(obj * 1.0))) return true;
	 else return false;
}

function validateZipForm(theForm, zipField)
{
	 return validateZip(eval('theForm.' + zipField + '.value'));
}

function SubmitIfEnter(e)
{
    var charCode
    if(e && e.which){
        e = e
        charCode = e.which
    }
    else{
        e = event
        charCode = e.keyCode 
    }

    if(charCode == 13){ 
        return false
    }
    else{
    return true
    }
}

//function under construction
function submitFormToDivResult(formName, destination, divName, errorMessage)
{
	  var form = document.getElementById(formName);
	  var query = buildQueryString(form);
	  var A = new AJAXObject(function(AjaxResponse)
		{
			try 
			{ 
				if (AjaxResponse.length > 5)
				{
					document.getElementById('divName').innerHTML = AjaxResponse;
					return true;
				}
			}
			catch( e )
			{
				alert(errorMessage + '  (' + e.message + ').');
				return false;
			}
			finally 
			{
			}
		});
		try 
		{
			A.GetPage(destination, query);
		} 
		catch( e ) 
		{
		  return false;
		} 
		finally 
		{
		}
		return false;
}

//GET DEALERS
function getQuoteDealersList(maxDealersPerRow, objTabId, year, makeId, makeName, modelName, styleId, zipRequired, imgLoaderUrl, appPath, headerHtml)
{
	if (maxDealersPerRow == undefined) 
		maxDealersPerRow = 2;
	if (objTabId == undefined)
		objTabId = '';
	if (year == undefined)
		year = '';
	if (makeId == undefined)
		makeId = '';
	if (makeName == undefined)
		makeName = '';
	if (modelName == undefined)
		modelName = '';
	if (styleId == undefined)
		styleId = '';
	if (zipRequired == undefined)
		zipRequired = true;
	if (imgLoaderUrl == undefined)
		imgLoaderUrl = '';
	var imgLoaderHTML = '<img src="' + imgLoaderUrl + '" ></img>';
	if (appPath == undefined)
		appPath = '';
	if (headerHtml == undefined)
		headerHtml = '';

	var A = new AJAXObject(function(AjaxResponse)
	{
		try 
		{ 
			if (AjaxResponse.length > 5)
			{
				document.getElementById(objTabId + '_divDealers').innerHTML = AjaxResponse + '<br><table style="border-bottom:solid 1px #cccccc; width:100%"><tr><td>&nbsp;</td></tr></table>';
					if (objTabId != '')
						eval('objTabId' + '_busy_working = false;');
					var objectToShow = document.getElementById(objTabId + '_divGoButton');
					if (objectToShow != undefined)
					    objectToShow.style.display = '';
				}
			}
			catch( e )
			{
				alert('An unexpected error has occurred while loading dealers (' + e.message + ').\n' + 'Please try again later.\n'
				+ 'If the problem persists, we suggest you close this window and re-launch the configurator.');
			}
			finally 
			{
			}
		});
		try 
		{
			if (zipRequired)
			{
				if (!validateZipForm(document.getElementById(objTabId + '_SelectDealers'), 'UserZip'))
				{
					alert('Valid zip code required');
					return;
				}
			}
			document.getElementById(objTabId + '_divFsDealers').style.display = '';
			document.getElementById(objTabId + '_divDealers').innerHTML = imgLoaderHTML + ' Loading Dealers...';
			
			var x = getElementById(objTabId + '_dealersFound');
			if (x) x.innerHTML = '';
			if (objTabId != '')
			{
				eval('objTabId' + '_busy_working = true;');
				var formStr = 'TxtDealerZipCode=' + document.getElementById("UserZip").value + '&hid_GbMakeId=' + getHidValues(objTabId, 'hid_GbMakeId') + '&Hid_ModelYear=' + getHidValues(objTabId, 'hid_ModelYear') + '&Hid_ModelName=' + getHidValues(objTabId, 'hid_ModelName') + '&Hid_Make=' + getHidValues(objTabId, 'hid_Make') + '&hid_StyleId=' + getHidValues(objTabId, 'hid_StyleId') + '&hid_TabId=' + objTabId + '&maxCols=' + maxDealersPerRow + '&headerHtml=' + headerHtml;
				A.GetPage(appPath + 'carConfig/getQuoteDealerList.aspx', formStr);
			}
			else
				A.GetPage(appPath + 'carConfig/getQuoteDealerList.aspx', 'TxtDealerZipCode=' + document.getElementById("UserZip").value + '&hid_GbMakeId=' + makeId + '&Hid_ModelYear=' + year + '&Hid_ModelName=' + modelName + '&Hid_Make=' + makeName + '&hid_StyleId=' + styleId + '&hid_TabId=' + objTabId + '&maxCols=' + maxDealersPerRow + '&headerHtml=' + headerHtml);
		} 
		catch( e ) 
		{
		  if (objTabId != '')
			eval('objTabId' + '_busy_working = false;');
		} 
		finally 
		{
		}
	}	
	
	function getQuoteDealersListTrim(maxDealersPerRow, objTabId, year, makeId, makeName, modelName, styleId, trimName, zipRequired, imgLoaderUrl, appPath, headerHtml)
{
	if (maxDealersPerRow == undefined) 
		maxDealersPerRow = 2;
	if (objTabId == undefined)
		objTabId = '';
	if (year == undefined)
		year = '';
	if (makeId == undefined)
		makeId = '';
	if (makeName == undefined)
		makeName = '';
	if (modelName == undefined)
		modelName = '';
	if (styleId == undefined)
		styleId = '';
	if (trimName == undefined)
		trimName = '';
	if (zipRequired == undefined)
		zipRequired = true;
	if (imgLoaderUrl == undefined)
		imgLoaderUrl = '';
	var imgLoaderHTML = '<img src="' + imgLoaderUrl + '" ></img>';
	if (appPath == undefined)
		appPath = '';
	if (headerHtml == undefined)
		headerHtml = '';

	var A = new AJAXObject(function(AjaxResponse)
	{
		try 
		{ 
			if (AjaxResponse.length > 5)
			{
				document.getElementById(objTabId + '_divDealers').innerHTML = AjaxResponse + '<br><table style="border-bottom:solid 1px #cccccc; width:100%"><tr><td>&nbsp;</td></tr></table>';
					if (objTabId != '')
						eval('objTabId' + '_busy_working = false;');
					var objectToShow = document.getElementById(objTabId + '_divGoButton');
					if (objectToShow != undefined)
					    objectToShow.style.display = '';
				}
			}
			catch( e )
			{
				alert('An unexpected error has occurred while loading dealers (' + e.message + ').\n' + 'Please try again later.\n'
				+ 'If the problem persists, we suggest you close this window and re-launch the configurator.');
			}
			finally 
			{
			}
		});
		try 
		{
			if (zipRequired)
			{
				if (!validateZipForm(document.getElementById(objTabId + '_SelectDealers'), 'UserZip'))
				{
					alert('Valid zip code required');
					return;
				}
			}
			document.getElementById(objTabId + '_divFsDealers').style.display = '';
			document.getElementById(objTabId + '_divDealers').innerHTML = imgLoaderHTML + ' Loading Dealers...';
			
			var x = getElementById(objTabId + '_dealersFound');
			if (x) x.innerHTML = '';
			if (objTabId != '')
			{
				eval('objTabId' + '_busy_working = true;');
				var formStr = 'TxtDealerZipCode=' + document.getElementById("UserZip").value + '&hid_GbMakeId=' + getHidValues(objTabId, 'hid_GbMakeId') + '&Hid_ModelYear=' + getHidValues(objTabId, 'hid_ModelYear') + '&Hid_ModelName=' + getHidValues(objTabId, 'hid_ModelName') + '&Hid_Make=' + getHidValues(objTabId, 'hid_Make') + '&hid_StyleId=' + getHidValues(objTabId, 'hid_StyleId') + '&hid_TabId=' + objTabId + '&maxCols=' + maxDealersPerRow + '&headerHtml=' + headerHtml;
				A.GetPage(appPath + 'carConfig/getQuoteDealerList.aspx', formStr);
			}
			else
				A.GetPage(appPath + 'carConfig/getQuoteDealerList.aspx', 'TxtDealerZipCode=' + document.getElementById("UserZip").value + '&hid_GbMakeId=' + makeId + '&Hid_ModelYear=' + year + '&Hid_ModelName=' + modelName + '&Hid_Make=' + makeName + '&hid_StyleId=' + styleId + '&hid_StyleName=' + trimName + '&hid_TabId=' + objTabId + '&maxCols=' + maxDealersPerRow + '&headerHtml=' + headerHtml);
		} 
		catch( e ) 
		{
		  if (objTabId != '')
			eval('objTabId' + '_busy_working = false;');
		} 
		finally 
		{
		}
	}
//END OF GET DEALERS

//CONFIGURATION SAVING

function saveCarConfig(objTabId, appPath, configName, popupWidth, modeLogin, siteKey)
{
  
  var A = new AJAXObject(function(AjaxResponse)
    {
        showPopupInnerHTML(popupWidth, AjaxResponse)
    });
  
  saveStep(objTabId, eval(objTabId + '_step_current'));
  var modeStr = 'mode=12';
  var formStr = 'qsfirst=' + eval(objTabId + '_step_first') + '&qstotal=' + eval(objTabId + '_step_total') + '&qscurrent=' + eval(objTabId + '_step_current') + '&qsreload=' + boolArray2Str(eval(objTabId + '_reload')) +  '&qsavailable=' + boolArray2Str(eval(objTabId + '_available'));  
  formStr = formStr + '&StyleId=' + getHidValues(objTabId, 'hid_StyleId');
  formStr = formStr + '&GbStyleState=' + getHidValues(objTabId, 'hid_GbStyleState');
  formStr = formStr + '&StyleState=' + getHidValues(objTabId, 'hid_StyleState');
  formStr = formStr + '&ExtColor=' + getHidValues(objTabId, 'hid_ExtColorCode');
  formStr = formStr + '&IntColor=' + getHidValues(objTabId, 'hid_IntColorCode');
  formStr = formStr + '&senderTabId=' + objTabId; 
  formStr = formStr + '&SavedName=' + configName;
  if (modeLogin)
  { 
	formStr += '&' + buildQueryString(document.getElementById('popupForm'));
	modeStr = 'mode=22';
  }
  if (siteKey)
  {
	var siteKeyStr = (siteKey == '') ? '' : '&siteKey=' + siteKey;
	formStr += siteKeyStr;
  }
  A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?' + modeStr, formStr);
}

function delSavedCarConfig(appPath, objLink, configName, popupWidth, siteKey)
{
  var A = new AJAXObject(function(AjaxResponse)
    {
        if (AjaxResponse.length > 0)
        {
			var ajaxArray = AjaxResponse.split("|");
			if (ajaxArray.length >= 2)
			{
				showPopupInnerHTML(popupWidth, ajaxArray[1]);
				document.getElementById('div' + configName).innerHTML = ajaxArray[0];
				document.getElementById('a_' + configName).href = 'javascript:alert("deleted!")';
				document.getElementById('a_img_' + configName).href = 'javascript:alert("deleted!")';
			}
			else
			{
				showPopupInnerHTML(popupWidth, AjaxResponse);
				alert("2" + document.getElementbyId('a_' + configName));
			}
		}
    });
  var formStr = ''
  if (configName != '')
	formStr = 'SavedName=' + configName;
  if (siteKey)
  {
	var siteKeyStr = (siteKey == '') ? '' : 'siteKey=' + siteKey;
	formStr += (formStr=='') ? siteKeyStr : '&' + siteKeyStr;
  }
  A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=10', formStr);
}

  
  function getSavedCarConfig(objTabId, savedName, appPath, siteKey)
  {
   var A = new AJAXObject(function(AjaxResponse)
    {
      try 
      { 
        if (AjaxResponse.length > 5)
        {
          if (AjaxResponse.substring(0,5) == "[-OK]")
          {
              var ajaxArray = AjaxResponse.split("|");
              if (ajaxArray.length == 19)
                {
                  eval(objTabId + '_save_Info_1_reset(ajaxArray[11], ajaxArray[12], ajaxArray[14])');
                  eval(objTabId + '_updateTrimNames(ajaxArray[13], ajaxArray[15], ajaxArray[16])');
                  updateImage(ajaxArray[18], ajaxArray[17]);
                  eval(objTabId + '_setSerializedValue(ajaxArray[8])');
                  eval(objTabId + '_setGabrielsSerializedValue(ajaxArray[7])');
                  
                  setHidValues(objTabId, 'hid_StyleId', ajaxArray[1]);
                  setHidValues(objTabId, 'hid_ExtColorCode', ajaxArray[9]);
                  setHidValues(objTabId, 'hid_IntColorCode', ajaxArray[10]);
                  
                  setLiveValues(objTabId, ajaxArray[2], ajaxArray[3], ajaxArray[4], ajaxArray[5], ajaxArray[6]);
                  recallStep(objTabId, ajaxArray[4]);

                }
          }
          else if (AjaxResponse.substring(0,5) == "[-KO]")
          {
				var ajaxArray = AjaxResponse.split("|");
				if (ajaxArray.length == 3)
					showPopupInnerHTML(parseInt(ajaxArray[1]), ajaxArray[2]);
          }
          else
          {
            alert(AjaxResponse);
          }
        }
      }
      catch( e )
      {
        alert('An unexpected error has occurred (' + e.message + ').\n' + 'Please try again later.\n'
            + 'If the problem persists, we suggest you close this window and re-launch the configurator.');
      }
      finally 
      {
      }
    });
   try 
   {
     var formStr = '';
     if (siteKey)
	 {
		formStr = (siteKey == '') ? '' : 'siteKey=' + siteKey;
	 }
     A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=11&SavedName=' + savedName, formStr);
   } 
   catch( e ) 
   {
   } 
   finally 
   {
   }
  }
  
  
  function carConfigLogin(objTabId, savedName, appPath, siteKey)
  {
   var A = new AJAXObject(function(AjaxResponse)
    {
      try 
      { 
        if (AjaxResponse.length > 5)
        {
          if (AjaxResponse.substring(0,5) == "[-OK]")
          {
              var ajaxArray = AjaxResponse.split("|");
              if (ajaxArray.length == 19)
                {
                  eval(objTabId + '_save_Info_1_reset(ajaxArray[11], ajaxArray[12], ajaxArray[14])');
                  eval(objTabId + '_updateTrimNames(ajaxArray[13], ajaxArray[15], ajaxArray[16])');
                  updateImage(ajaxArray[18], ajaxArray[17]);
                  eval(objTabId + '_setSerializedValue(ajaxArray[8])');
                  eval(objTabId + '_setGabrielsSerializedValue(ajaxArray[7])');
                  
                  setHidValues(objTabId, 'hid_StyleId', ajaxArray[1]);
                  setHidValues(objTabId, 'hid_ExtColorCode', ajaxArray[9]);
                  setHidValues(objTabId, 'hid_IntColorCode', ajaxArray[10]);
                  
                  setLiveValues(objTabId, ajaxArray[2], ajaxArray[3], ajaxArray[4], ajaxArray[5], ajaxArray[6]);
                  //callStep3('carConfig_carConfigSteps');
                  recallStep(objTabId, ajaxArray[4]);
                  //alert(ajaxArray[9]); alert(ajaxArray[10]);
                  //callStep5('carConfig_carConfigSteps');
                  //eval('carConfig_carConfigSteps' + '_getStep_3_State()');
                  //carConfig_carConfigSteps_setSerializedValue(ajaxArray[8]);
                  //carConfig_carConfigSteps_setGabrielsSerializedValue(ajaxArray[7]);
                  //eval('carConfig_carConfigStep3_toggle("")');
                }
          }
          else
          {
            alert(AjaxResponse);
          }
        }
      }
      catch( e )
      {
        alert('An unexpected error has occurred (' + e.message + ').\n' + 'Please try again later.\n'
            + 'If the problem persists, we suggest you close this window and re-launch the configurator.');
      }
      finally 
      {
      }
    });
   try 
   {
     var formStr = '';
     if (siteKey)
	 {
		formStr = (siteKey == '') ? '' : '&siteKey=' + siteKey;
	 }
     A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=11&SavedName=' + savedName, formStr);
   } 
   catch( e ) 
   {
   } 
   finally 
   {
   }
  }

//END OF CONFIGURATION SAVING

//NEW LEAD FORM

function manage_Reload_LeadForm(tabStepsId)
{
    var quoteLeadFormLoaded = document.getElementById(tabStepsId + '_quoteLeadFormLoaded');
    if (quoteLeadFormLoaded)
        reload_LeadForm();
}

//END OF NEW LEAD FORM

//UTILITIES//
function manageKeyByRegex(e, inputObj, pattern, flag, strToEval, maxlength)
{
	var charCode = getKey(e);
	if ((charCode == 8) || (charCode == 127)) return true;
	if (isKeyEnter(charCode))
	{ 
		eval(strToEval);
		return false;
    }
    var r = new RegExp(pattern,flag);
    var maxLengthTest = maxlength ? inputObj.value.length < parseInt(maxlength) : true; 
    return maxLengthTest && r.test(String.fromCharCode(charCode));
}
//END OF UTILITIES//

//getModule functions
function ccbc1()
{
    document.getElementById("divContent").innerHTML = '';
    submitFormToDiv("carConfigBuildCompact1", "<%=Utility.appPath%>clientModules/carConfigBuildCompact.aspx?getModel=1", "divContent");
    getContent();
}
  //var timeOut = 5000;
  //var i = 0;
  function getContent()
  {
    timerGetContent();
  }
  function timerGetContent()
  {  
     if (i >= timeOut) return;
     if (document.getElementById("divContent").innerHTML == '')
     {
        setTimeout("timerGetContent()",10);
        i += 10;
        if (i >= timeOut) 
        {
            alert("Request timed out ... Please try again");
            i = 0;
            return;
        }
     }
     else
     {
       window.parent.gotoStep2(document.getElementById("divContent").innerHTML);
     }
  }
//

//REPAIRPAL ESTIMATE SAVING

function saveCarRepair(objTabId, appPath, configName, popupWidth, modeLogin, siteKey)
{
  
  var A = new AJAXObject(function(AjaxResponse)
    {
        showPopupInnerHTML(popupWidth, AjaxResponse)
    });
  
  //saveStep(objTabId, eval(objTabId + '_step_current'));
  var modeStr = 'mode=12';
  var formStr = 'qsfirst=' + eval(objTabId + '_step_first') + '&qstotal=' + eval(objTabId + '_step_total') + '&qscurrent=' + eval(objTabId + '_step_current') + '&qsreload=' + boolArray2Str(eval(objTabId + '_reload')) +  '&qsavailable=' + boolArray2Str(eval(objTabId + '_available'));  
  formStr = formStr + '&StyleId=' + getHidValues(objTabId, 'hid_StyleId');
  formStr = formStr + '&GbStyleState=' + getHidValues(objTabId, 'hid_GbStyleState');
  formStr = formStr + '&StyleState=' + getHidValues(objTabId, 'hid_StyleState');
  formStr = formStr + '&ExtColor=' + getHidValues(objTabId, 'hid_ExtColorCode');
  formStr = formStr + '&IntColor=' + getHidValues(objTabId, 'hid_IntColorCode');
  formStr = formStr + '&senderTabId=' + objTabId; 
  formStr = formStr + '&SavedName=' + configName;
  if (modeLogin)
  { 
	formStr += '&' + buildQueryString(document.getElementById('popupForm'));
	modeStr = 'mode=22';
  }
  if (siteKey)
  {
	var siteKeyStr = (siteKey == '') ? '' : '&siteKey=' + siteKey;
	formStr += siteKeyStr;
  }
  A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?' + modeStr, formStr);
}

function delSavedCarRepair(appPath, objLink, configName, popupWidth, siteKey)
{
  var A = new AJAXObject(function(AjaxResponse)
    {
        if (AjaxResponse.length > 0)
        {
			var ajaxArray = AjaxResponse.split("|");
			if (ajaxArray.length >= 2)
			{
				showPopupInnerHTML(popupWidth, ajaxArray[1]);
				document.getElementById('div' + configName).innerHTML = ajaxArray[0];
				document.getElementById('a_' + configName).href = 'javascript:alert("deleted!")';
				document.getElementById('a_img_' + configName).href = 'javascript:alert("deleted!")';
			}
			else
			{
				showPopupInnerHTML(popupWidth, AjaxResponse);
				alert("2" + document.getElementbyId('a_' + configName));
			}
		}
    });
  var formStr = ''
  if (configName != '')
	formStr = 'SavedName=' + configName;
  if (siteKey)
  {
	var siteKeyStr = (siteKey == '') ? '' : 'siteKey=' + siteKey;
	formStr += (formStr=='') ? siteKeyStr : '&' + siteKeyStr;
  }
  A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=10', formStr);
}

  
  function getSavedCarRepair(objTabId, savedName, appPath, siteKey)
  {
   var A = new AJAXObject(function(AjaxResponse)
    {
      try 
      { 
        if (AjaxResponse.length > 5)
        {
          if (AjaxResponse.substring(0,5) == "[-OK]")
          {
              var ajaxArray = AjaxResponse.split("|");
              if (ajaxArray.length == 19)
                {
                  eval(objTabId + '_save_Info_1_reset(ajaxArray[11], ajaxArray[12], ajaxArray[14])');
                  eval(objTabId + '_updateTrimNames(ajaxArray[13], ajaxArray[15], ajaxArray[16])');
                  updateImage(ajaxArray[18], ajaxArray[17]);
                  eval(objTabId + '_setSerializedValue(ajaxArray[8])');
                  eval(objTabId + '_setGabrielsSerializedValue(ajaxArray[7])');
                  
                  setHidValues(objTabId, 'hid_StyleId', ajaxArray[1]);
                  setHidValues(objTabId, 'hid_ExtColorCode', ajaxArray[9]);
                  setHidValues(objTabId, 'hid_IntColorCode', ajaxArray[10]);
                  
                  setLiveValues(objTabId, ajaxArray[2], ajaxArray[3], ajaxArray[4], ajaxArray[5], ajaxArray[6]);
                  recallStep(objTabId, ajaxArray[4]);

                }
          }
          else if (AjaxResponse.substring(0,5) == "[-KO]")
          {
				var ajaxArray = AjaxResponse.split("|");
				if (ajaxArray.length == 3)
					showPopupInnerHTML(parseInt(ajaxArray[1]), ajaxArray[2]);
          }
          else
          {
            alert(AjaxResponse);
          }
        }
      }
      catch( e )
      {
        alert('An unexpected error has occurred (' + e.message + ').\n' + 'Please try again later.\n'
            + 'If the problem persists, we suggest you close this window and re-launch the configurator.');
      }
      finally 
      {
      }
    });
   try 
   {
     var formStr = '';
     if (siteKey)
	 {
		formStr = (siteKey == '') ? '' : 'siteKey=' + siteKey;
	 }
     A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=11&SavedName=' + savedName, formStr);
   } 
   catch( e ) 
   {
   } 
   finally 
   {
   }
  }
  
 /////////////////////////
 // REPAIRPAL SAVING, add by William@10-15-2009
          
 function saveRepairEstimate( appPath, repairDetail , repairParameter)
{
  
  var A = new AJAXObject(function(AjaxResponse)
    {
        showPopupInnerHTML(popupWidth, AjaxResponse)
    });
  /*
  saveStep(objTabId, eval(objTabId + '_step_current'));
  var modeStr = 'mode=12';
  var formStr = 'qsfirst=' + eval(objTabId + '_step_first') + '&qstotal=' + eval(objTabId + '_step_total') + '&qscurrent=' + eval(objTabId + '_step_current') + '&qsreload=' + boolArray2Str(eval(objTabId + '_reload')) +  '&qsavailable=' + boolArray2Str(eval(objTabId + '_available'));  
  formStr = formStr + '&StyleId=' + getHidValues(objTabId, 'hid_StyleId');
  formStr = formStr + '&GbStyleState=' + getHidValues(objTabId, 'hid_GbStyleState');
  formStr = formStr + '&StyleState=' + getHidValues(objTabId, 'hid_StyleState');
  formStr = formStr + '&ExtColor=' + getHidValues(objTabId, 'hid_ExtColorCode');
  formStr = formStr + '&IntColor=' + getHidValues(objTabId, 'hid_IntColorCode');
  formStr = formStr + '&senderTabId=' + objTabId; 
  formStr = formStr + '&SavedName=' + configName;
  if (modeLogin)
  { 
	formStr += '&' + buildQueryString(document.getElementById('popupForm'));
	modeStr = 'mode=22';
  }
  if (siteKey)
  {
	var siteKeyStr = (siteKey == '') ? '' : '&siteKey=' + siteKey;
	formStr += siteKeyStr;
  } */
  A.GetPage(appPath + 'carConfig/getRepairSaving.aspx?make='+make+'&model='+model+'&year='+year+'&zip='+zip+'&service='+service);
}

function delSavedRepairEstimate(appPath, objLink, configName, popupWidth, siteKey)
{
  var A = new AJAXObject(function(AjaxResponse)
    {
        if (AjaxResponse.length > 0)
        {
			var ajaxArray = AjaxResponse.split("|");
			if (ajaxArray.length >= 2)
			{
				showPopupInnerHTML(popupWidth, ajaxArray[1]);
				document.getElementById('div' + configName).innerHTML = ajaxArray[0];
				document.getElementById('a_' + configName).href = 'javascript:alert("deleted!")';
				document.getElementById('a_img_' + configName).href = 'javascript:alert("deleted!")';
			}
			else
			{
				showPopupInnerHTML(popupWidth, AjaxResponse);
				alert("2" + document.getElementbyId('a_' + configName));
			}
		}
    });
  var formStr = ''
  if (configName != '')
	formStr = 'SavedName=' + configName;
  if (siteKey)
  {
	var siteKeyStr = (siteKey == '') ? '' : 'siteKey=' + siteKey;
	formStr += (formStr=='') ? siteKeyStr : '&' + siteKeyStr;
  }
  A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=10', formStr);
}

  
  function getSavedRepairEstimate(objTabId, savedName, appPath, siteKey)
  {
   var A = new AJAXObject(function(AjaxResponse)
    {
      try 
      { 
        if (AjaxResponse.length > 5)
        {
          if (AjaxResponse.substring(0,5) == "[-OK]")
          {
              var ajaxArray = AjaxResponse.split("|");
              if (ajaxArray.length == 19)
                {
                  eval(objTabId + '_save_Info_1_reset(ajaxArray[11], ajaxArray[12], ajaxArray[14])');
                  eval(objTabId + '_updateTrimNames(ajaxArray[13], ajaxArray[15], ajaxArray[16])');
                  updateImage(ajaxArray[18], ajaxArray[17]);
                  eval(objTabId + '_setSerializedValue(ajaxArray[8])');
                  eval(objTabId + '_setGabrielsSerializedValue(ajaxArray[7])');
                  
                  setHidValues(objTabId, 'hid_StyleId', ajaxArray[1]);
                  setHidValues(objTabId, 'hid_ExtColorCode', ajaxArray[9]);
                  setHidValues(objTabId, 'hid_IntColorCode', ajaxArray[10]);
                  
                  setLiveValues(objTabId, ajaxArray[2], ajaxArray[3], ajaxArray[4], ajaxArray[5], ajaxArray[6]);
                  recallStep(objTabId, ajaxArray[4]);

                }
          }
          else if (AjaxResponse.substring(0,5) == "[-KO]")
          {
				var ajaxArray = AjaxResponse.split("|");
				if (ajaxArray.length == 3)
					showPopupInnerHTML(parseInt(ajaxArray[1]), ajaxArray[2]);
          }
          else
          {
            alert(AjaxResponse);
          }
        }
      }
      catch( e )
      {
        alert('An unexpected error has occurred (' + e.message + ').\n' + 'Please try again later.\n'
            + 'If the problem persists, we suggest you close this window and re-launch the configurator.');
      }
      finally 
      {
      }
    });
   try 
   {
     var formStr = '';
     if (siteKey)
	 {
		formStr = (siteKey == '') ? '' : 'siteKey=' + siteKey;
	 }
     A.GetPage(appPath + 'carConfig/getConfigSaving.aspx?mode=11&SavedName=' + savedName, formStr);
   } 
   catch( e ) 
   {
   } 
   finally 
   {
   }
  }
//END OF CONFIGURATION SAVING
