var pomDate= new Date();
var fotoList;
var fotoListMax=0;
var currentYear= pomDate.getFullYear();
var itemArray=new Array('cdMenuFastCenter','carSignTxt','priceInfo1','priceInfo2','carInfo','cAcc','cStat','cDesc','column2','cdBigFotoList','cdFirmaInfo');
	var escapeCharsUtf = new Array('%u010C', '%u010E', '%u011A', '%u0147', '%u0158', '%u0160', '%u0164', '%u016E', '%u017D', '%u010D', '%u010F', '%u011B', '%u0148', '%u0159', '%u0161', '%u0165', '%u016F', '%u017E', '%u0105', '%u013E');
	var escapeCharsUrl = new Array('%C3%81',       '%C4%8C',        '%C4%8E',        '%C3%89',        '%C4%9A',        '%C3%8D',        '%C5%87',        '%C3%93',         '%C5%98',        '%C5%A0',        '%C5%A4',        '%C3%9A',        '%C5%AE',        '%C3%9D',        '%C5%BD',        '%C3%A1',        '%C4%8D',        '%C4%8F',        '%C3%A9',        '%C4%9B',        '%C3%AD',        '%C5%88',        '%C3%B3',        '%C5%99',        '%C5%A1',        '%C5%A5',        '%C3%BA',        '%C5%AF',        '%C3%BD',        '%C5%BE',        '%C4%BE',       '%0D%0A', '%C2%A0');

function searchCar(){
            var sendForm = document.getElementById('carFormSearch');
            sendForm.submit();
        }
 
 
function searchFirmCar(){
            var sendForm = document.getElementById('carListPopupFrm');
            sendForm.submit();
        }
        
        function fillAccCheckboxes(){
            var accObj = document.getElementById('acc');
            var equip = accObj.value;

            if( equip == null || equip == ""){
                equip = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';  //200 mist
                accObj.value = equip;
            }
            for(var i=0;i<equip.length;i++){
                if(equip.charAt(i)=='1'){
                    var chkId = 'car.accessories.'+(i+1);
                    var currChkBox = document.getElementById(chkId);
                    if(currChkBox){ /* na strance jsou jen nektere polozky vybavy  proto musime kontrolovat zda existuje chkbox s timto id*/
                        currChkBox.checked = true;
                    }
                }
            }
            if(equip.charAt(12)==1 && document.getElementById('car.accessories.12a')!=null){
                document.getElementById('car.accessories.12a').checked = true;
            }
            if(equip.charAt(13)==1 && document.getElementById('car.accessories.13a')!=null){
                document.getElementById('car.accessories.13a').checked = true;
            }
        
            var accObj = document.getElementById('access');
            var equip = accObj.value;

            if( equip == null || equip == ""){
                equip = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000';		//200 mist
                accObj.value = equip;
            }
            for(var i=0;i<equip.length;i++){
                if(equip.charAt(i)!='0'){
                    var chkId = 'car.accessories.'+(i+1);
                    var currChkBox = document.getElementById(chkId);
                    if(currChkBox){ /* na strance jsou jen nektere polozky vybavy  proto musime kontrolovat zda existuje chkbox s timto id*/
                        currChkBox.checked = true;
                    }
                }
            }
            if(equip.charAt(12)==1 && document.getElementById('car.accessories.12a')!=null){
                document.getElementById('car.accessories.12a').checked = true;
            }
            if(equip.charAt(13)==1 && document.getElementById('car.accessories.13a')!=null){
                document.getElementById('car.accessories.13a').checked = true;
            }
        }
        function fillStateCheckboxes(){
            var stateObj = document.getElementById('state');
            var stValue = stateObj.value;
            if( stValue == null || stValue.length == 0){
                stValue = '0000000000000000000000000000000000000000';
                stateObj.value = stValue;
            }
            for(var i=0;i<stValue.length;i++){
                if(stValue.charAt(i)=='1'){
                    var chkId = 'car.state.'+(i+1);
                    var chkTemp = document.getElementById(chkId);
                    if(chkTemp){    /* na strance jsou jen nektere stavy proto musime kontrolovat zda existuje chkbox s timto id*/
                        chkTemp.checked = true;
                    }
                }
             }
        }
        function orderBy(pHow,pDirection){
            var oOrder = document.getElementById('o');
            oOrder.value = pHow;
            var oDirection = document.getElementById('orderDirection');
            oDirection.value = pDirection;
            var sendForm = document.getElementById('carFormSearch');
            if(sendForm != null)
            sendForm.submit();
        }
        function submitSearchAB(){
            /* je treba nastavit do formu podle ceho budeme tridit, to je v inputut s id=orderFirmListBy*/
            var orderOnRuler = document.getElementById('orderFirmListBy');
            var directionOnRuler = document.getElementById('directionFirmListBy');
            if(orderOnRuler && directionOnRuler){
                 var formAB = document.getElementById('firmAB');
                    if(formAB){
                        var orderOnAB = document.getElementById('o_AB');
                        if(orderOnAB){
                            orderOnAB.value = orderOnRuler.value;
                        }
                        var directionOnAB = document.getElementById('orderDirection_AB');
                        if(directionOnAB){
                            directionOnAB.value = directionOnRuler.value;
                        }
                        formAB.submit();
                    }
            }
        }
        function submitSearchAS(){
            /* je treba nastavit do formu podle ceho budeme tridit, to je v inputut s id=orderFirmListBy*/
            var orderOnRuler = document.getElementById('orderFirmListBy');
            var directionOnRuler = document.getElementById('directionFirmListBy');
            if(orderOnRuler && directionOnRuler){
                 var formAS = document.getElementById('firmAS');
                    if(formAS){
                        var orderOnAS = document.getElementById('o_AS');
                        if(orderOnAS){
                            orderOnAS.value = orderOnRuler.value;
                        }
                        var directionOnAS = document.getElementById('orderDirection_AS');
                        if(directionOnAS){
                            directionOnAS.value = directionOnRuler.value;
                        }
                        formAS.submit();
                    }
            }
        }
        function orderFirmsBy(){
            /*podle ceho budeme tridit*/
            var orderOnRuler = document.getElementById('orderFirmListBy');
            if(orderOnRuler){
                /*jaky formular budeme posilat zda autobazary nebo autosalony*/
                var ab_or_as = document.getElementById('ab_or_as');
                if(ab_or_as && ab_or_as.value == 'ab'){
                    submitSearchAB();
                }else if(ab_or_as && ab_or_as.value == 'as'){
                    submitSearchAS()
                }
             }
        }
        function orderByInIframeXXX(pHow, pDirection,uid){
            var oOrder = document.getElementById('o');
            if(oOrder != null){
                oOrder.value = pHow;
            }
            var oDirection = document.getElementById('orderDirection');
            if(oDirection != null){
                oDirection.value = pDirection;
            }
            var ifr = document.getElementById('clpopup');
            if(ifr != null){
                ifr.src = '/xchanger/uni/carListPopup.jsp?uid='+uid+'&o='+pHow+'&orderDirection='+pDirection;
            }
        }
    function loadCarPopupList(pUid){
        var resultSrc = '/xchanger/uni/carListPopup.jsp?uid='+pUid+'&';

         var oOrder = document.getElementById('orderListBy');
         if(oOrder != null && oOrder.value != ''){
                resultSrc = resultSrc + 'o='+oOrder.value+'&';
            }
         var oMax = document.getElementById('max');
         if(oMax != null && oMax.value != ''){
                resultSrc = resultSrc + 'max='+oMax.value+'&';
            }
         var oListForm2 = document.getElementById('listForm2');
            if(oListForm2 != null && oListForm2.checked){
                resultSrc = resultSrc + 'listForm='+oListForm2.value+'&';
            }else{
                resultSrc = resultSrc + 'listForm=list&';
            }
         var date = new Date();
         var timestamp = Date.parse(date);
         resultSrc +='ts='+timestamp;

        var ifr = document.getElementById('clpopup');
            if(ifr != null){
                ifr.src = resultSrc;
            }
    }
    function firmInsertPopup(form){
        if(form == null || form ==""){
            openPage('/xchanger/uni/firmInsert.jsp','firmDetail');
        }else{
            openPage('','firmDetail');
            form.target = 'firmDetail';
            form.action = '/xchanger/uni/firmInsert.jsp';
        }
    }
    function userLoginPopup(){
        form = document.getElementById('loginForm');
        if(form == null || form ==""){
            openPage('/xchanger/uni/carInsert.jsp','firmDetail');
        }else{
            openPage('','firmDetail');
            form.target = 'firmDetail';
            return true;
        }
    }
    function carRequestPopup(){
        openPage('/xchanger/uni/carRequest.jsp','carDetail');
    }
    function carRequestUpdatePopup(reqForm){
        /*var reqForm = document.getElementById('confirmRequestForm');*/
        if(reqForm != null){
            openPage('','carDetail');
            reqForm.target = 'carDetail';
            reqForm.action = '/xchanger/uni/carRequest.jsp';
        }
    }
    function sendToAuthoriseRequest(){
        openPage('/xchanger/uni/carRequest.jsp?tab=2','carDetail');
    }
    function carInsertPopup(){
       openPage('/xchanger/uni/carInsertStart.jsp','carDetail');
    }
    function adShow(){
       openPage('/xchanger/uni/carDetail.jsp?action=C','carDetail'); 
    }

    function carUpdatePopup(){
        var attr = 'width=770,height=600,resizable=no';
        var date = new Date();
        var timestamp = Date.parse(date);
        //window.open('/xchanger/uni/carInsert.jsp?A_D=1&ts='+timestamp,'carIns',attr);
        openPage('/xchanger/uni/carInsert.jsp?A_L=1&ts='+timestamp,'carDetail');
    }
    function carUpdateLogin(){
        var frm = document.getElementById("loginCarUpdateForm");
        if(frm!=null){
           /*kontrola, zda jsou vyplnena prihlasovaci pole*/
            frm.submit();            
        }
    }
function correctSigns(myCheckBox){
    
    var signs = document.getElementById('signs').value;
    var cbValue = myCheckBox.value;
    if(myCheckBox.checked){
        if(firmsCheckedTotal<firmsCheckedLimit){
        	if (signs == "") {
        		signs = cbValue;
        	} else {
        		signs = signs+";"+cbValue;
        	}
            firmsCheckedTotal++;
        }else{
            myCheckBox.checked = false;
        }
    }
    else if(signs.indexOf(cbValue)!=-1){
        var signIndex = signs.indexOf(cbValue);
        var i = signIndex;
        var len = 3;
        if (i == 0) {
         if (signs.length > 3) len = 4;
        } else {
         if (signs.substring(i-1,i) == ";") {
          i--;
         }
        }
        var newSigns = signs.substring(0,i);
        newSigns = newSigns + signs.substring(signIndex+len);
        signs = newSigns;
        if(firmsCheckedTotal>0){
            firmsCheckedTotal--;
        }
    }
    document.getElementById('signs').value = signs;
}

function checkSigns(where){
    where.value = document.getElementById('signs').value;
}
function insertCar(carType){
    var vType = document.getElementById('type');
    var vForm = document.getElementById('chooseTypeForm');
    if (vType != null){
        vType.value = carType;
        if(vForm != null){
            /*alert(vType.value);*/
            vForm.submit();
        }
        else{
            alert ('vForm = null');
        }
    }else{
        alert('vType = null');
    }
}
function closeWindow(){
    window.close();
}
function showComboValue(field){
    var fCombo = document.getElementById('checkCombo');
    if(fCombo != null){
        fCombo.value = field.options[field.selectedIndex].value;
    }
}

function showFotoOnDisk(fileName){
    var big = document.getElementById('bigPreview');
    if(big != null){
        big.src = fileName;
    }
}

function chngFoto(img){
    var fotoPreview = document.getElementById('bigPreview');
    if(fotoPreview != null){
        var smallSizeFotoUrl = img.src;
        var middleSizeFotoUrl = '';
        if(smallSizeFotoUrl != null && smallSizeFotoUrl!=''){
            var checkStr = smallSizeFotoUrl.substring(smallSizeFotoUrl.length-5);
            if(checkStr == 's.jpg'){
                middleSizeFotoUrl = smallSizeFotoUrl.substring(0,smallSizeFotoUrl.length-5)+'m.jpg';
                fotoPreview.src = middleSizeFotoUrl;
            }
        }
    }else{
        return false;
    }
}
function loginUser(){
    var loginFrm = document.getElementById("loginForm");
    var emptyField = 0;
    var loginName = document.getElementById("login_name");
    if(loginName == null || loginName.value==('')){
        emptyField = 1;
    }
    var loginPassword = document.getElementById("login_password");
    if(loginPassword == null || loginPassword.value==('')){
        emptyField = 1;
    }

    if(loginFrm != null && emptyField==0){
        loginFrm.submit();
    }
}
function showFirmDetail(fid,tab){
    var date = new Date();
    var timestamp = Date.parse(date);
    openPage('/xchanger/uni/firmDetail.jsp?fid='+fid+'&ts='+timestamp+'&tab='+tab,'firmDetail');
}
function showCarDetail(cid){
    showCarDetail(cid,'0');
}
function showCarDetail(cid,tabCompare){
    var date = new Date();
    var timestamp = Date.parse(date);
    openPage('/xchanger/uni/carDetail.jsp?cid='+cid+'&ts='+timestamp+'&tab='+tabCompare,'carDetail');
}
function showCarDetailAutoPlus(cid,tab){
    var date = new Date();
    var timestamp = Date.parse(date);
    openPageAutoPlus('/xchanger/uni/carDetailAutoPlus.jsp?cid='+cid+'&ts='+timestamp+'&tab='+tab,'carDetail');
}

function openPage(pWhere, pWindowName){
    var aLeft,aTop
    aLeft=screen.width-770-19;
    aTop=screen.height-560;
    aLeft=(aLeft/2);
    aTop=(aTop/2);
	newwindow = window.open(pWhere,pWindowName,'Left='+aLeft+',Top='+aTop+',Height=575px,Width=750px,Status=1,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=0');
    if (window.focus) {newwindow.focus();}
    return false;

}
function openPageAutoPlus(pWhere, pWindowName){
    var aLeft,aTop
    aLeft=screen.width-950;
    aTop=screen.height-870;
    aLeft=(aLeft/2);
    aTop=(aTop/2);
	newwindow = window.open(pWhere,pWindowName,'Left='+aLeft+',Top='+aTop+',Height=845px,Width=945px,Status=1,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=1');
    if (window.focus) {newwindow.focus();}
    return false;

}

function testURL(newurl){
		//alert(newurl);
		openTestPage(newurl,'carDetail');
	}
	function openTestPage(pWhere, pWindowName){
    var aLeft,aTop
    aLeft=screen.width-770-19;
    aTop=screen.height-560;
    aLeft=(aLeft/2);
    aTop=(aTop/2);
	newwindow = window.open(pWhere,pWindowName,'Left='+aLeft+',Top='+aTop+',Height=575px,Width=750px,Status=1,toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=0');
    if (window.focus) {newwindow.focus();}
    return false;

}


function chngCurrency(elem)
{
 var index = elem.selectedIndex;
 document.getElementById('formCarPriceCurr').options[index].selected=true;
 document.getElementById('formCarLeasCurr').options[index].selected=true;
 document.getElementById('formCarLeasCurr1').options[index].selected=true;
 document.getElementById('formCarPriceLeasCurr1').options[index].selected=true;
 document.getElementById('formCarPriceLeasCurr2').options[index].selected=true;
 document.getElementById('formCarPriceLeasCurr3').options[index].selected=true;
 document.getElementById('formCarPriceLeasCurr4').options[index].selected=true;
}


	function chngFinancing(){
    /*hide all details*/
    var leasingDetails = document.getElementById("leasingDetail");
    if(leasingDetails != null){ leasingDetails.style.display = 'none';}
    var releaseDetails = document.getElementById("releaseDetail");
    if( releaseDetails != null ){releaseDetails.style.display = 'none';}
   /* inputenable('formCarPrice',true);*/

    var finForm = document.getElementById("formCarPricePay");
    if(finForm != null && (finForm.value==1 || finForm.value==5) && carPrice != null){
        leasingDetails.style.display = 'block';
       /* inputenable('formCarPrice',false);*/
    }else if(finForm != null && finForm.value==2){
        releaseDetails.style.display = 'block';
      /*  inputenable('formCarPrice',false);*/
    }
}
	
function chngLeasingPrice(){
    var carPrice = document.getElementById("formCarPrice");
    if(carPrice != null){
        var acontace = document.getElementById("formCarLeasPrice");
        if(acontace != null){
            carPrice.value = acontace.value;
        }
        var pocetSplatek = document.getElementById("formCarLeasCount");
        var splatka = document.getElementById("formCarLeasAnn");
        if(pocetSplatek != null && splatka != null){
            var newPrice = parseInt(acontace.value) + parseInt(pocetSplatek.value * splatka.value);
            carPrice.value = newPrice;
        }
    }
}

function chngPrice()
{
	var carPrice = document.getElementById("formCarPrice");
	var carPriceLeas1 = document.getElementById("formCarPriceLeas1");
	var carPriceLeas2 = document.getElementById("formCarPriceLeas2");
	if(carPrice!=null && carPriceLeas1 !=null && carPriceLeas2!=null)
	{	
	if((carPrice.value != carPriceLeas1.value))
	{
		carPriceLeas1.value = carPrice.value;
		carPriceLeas2.value = carPrice.value;
	}	
	} 
}
function chngPriceLeas(elem)
{
 var priceLeas = document.getElementById("hidden_price_leas");	
 var priceLeas1 = document.getElementById("formCarPriceLeas1");
 var priceLeas2 = document.getElementById("formCarPriceLeas2");
 if(elem!=null && priceLeas!=null)
 {
	priceLeas.value = elem.value;  
	if(priceLeas1!=null)priceLeas1.value=elem.value;
	if(priceLeas2!=null)priceLeas2.value=elem.value;
 }
}

function chngReleasingPrice(){
    var carPrice = document.getElementById("formCarPrice");
    if(carPrice != null){
        var odstupne = document.getElementById("formCarReleasPrice");
        if(odstupne != null){
            carPrice.value = odstupne.value;
        }
        var pocetSplatek = document.getElementById("formCarReleasCount");
        var splatka = document.getElementById("formCarReleasAnn");


       if(pocetSplatek != null && splatka != null){
           var accVar = parseInt(odstupne.value);
           var splatVar = parseInt(pocetSplatek.value * splatka.value);
           var newPrice = accVar + splatVar;
           carPrice.value = newPrice;
        }
    }
}


function inputenable(id,state) {
  var divObj = null;
  if (document.getElementById) {
    divObj = document.getElementById(id);
  } else if(document.all) {
    divObj = document.all(id);
  } else if (document.layers) {
    divObj = document.layers[id];
  }
  if(state && divObj) {
    if (document.all) {
      divObj.readOnly = false;
    } else {
      divObj.removeAttribute("readonly");
    }
  } else if(divObj) {
    if (document.all) {
      divObj.readOnly = true;
    } else {
      divObj.setAttribute("readonly","readonly");
    }
  }
}
function hilightLeasingDetail(){
    var greyBox1 = document.getElementById('greyBox1');
    var greyBox2 = document.getElementById('greyBox2');
    if(greyBox1 != null && greyBox2 != null){
        greyBox1.className = 'glDivGrayContrast';
        greyBox2.className = 'glDivGrayContrast';
    }
}
function dimLeasingDetail(){
    var greyBox1 = document.getElementById('greyBox1');
    var greyBox2 = document.getElementById('greyBox2');
    if(greyBox1 != null && greyBox2 != null){
        greyBox1.className = 'glDivGray';
        greyBox2.className = 'glDivGray';
    }
}

function submitCarDel(){
    var act = document.getElementById('action');
    if(act != null){
        act.value = 'X';
    }
    var frm = document.getElementById('carUpdateForm');
    if(frm != null){
        frm.submit();
    }
}
function showSubmitCarDel(){
    var buttonsDiv = document.getElementById('buttonsDiv');
    var confirmDiv = document.getElementById('confirmDeleteDiv');
    if(buttonsDiv != null){
        buttonsDiv.style.display = "none";
    }
     if(confirmDiv != null){
        confirmDiv.style.display = "block";
    }
}
function cancelSubmitCarDel(){
    var buttonsDiv = document.getElementById('buttonsDiv');
    var confirmDiv = document.getElementById('confirmDeleteDiv');
    if(buttonsDiv != null){
        buttonsDiv.style.display = "block";
    }
     if(confirmDiv != null){
        confirmDiv.style.display = "none";
    }
}
function checkEnter(e){ //e is event object passed from function invocation
    var characterCode;

    if(e && e.which){ //if which property of event object is supported (NN4)
        e = e ;
        characterCode = e.which; //character code is contained in NN4's which property
    }
    else{
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if(characterCode == 13){ //if generated character code is equal to ascii 13 (if enter key)
        var frm = document.getElementById('loginForm');
        if(frm != null){
            frm.submit(); //submit the form
        }
        return false;
    }
    else{
        return true;
    }
}
function showCarListPopup(){
    var frm = document.getElementById('carFormSearch');
    if(frm != null){
        frm.submit();
    }
}
function sendToEmail(){
    var checkResult = chkEmailNotEmptyFields();
    var show_warn = document.getElementById('formIncompleteWarn');
    if(show_warn != null){
        if(checkResult){
            show_warn.style.display = "none";
            /*spojit jmeno a prijmeni do jednoho hidden fieldu*/
            var p_name_tmp = document.getElementById('from_name_tmp');
            var p_name = document.getElementById('from_name');
            var p_surname = document.getElementById('from_surname');
            if(p_name != null && p_surname != null && p_name_tmp != null){
                  p_name.value = p_name_tmp.value + ' ' + p_surname.value;
            }
            var p_frm =  document.getElementById('sendOnEmail');
            if(p_frm != null){
                p_frm.submit();
            }
        }else{
            alert('Not submitted')
            show_warn.style.display = "";
        }
   }
}
function createHiddenControl(form)
{
 var elem = document.createElement("input");
 elem.setAttribute("type","hidden");
 elem.setAttribute("name","hiddenControl");
 form.appendChild(elem);
}

function sendToPropriator(){
    var checkResult = chkToPropriatorNotEmptyFields();

    var show_warn = document.getElementById('formIncompleteWarn');
    if(show_warn != null){
        if(checkResult){
            show_warn.style.display = "none";
            var p_frm =  document.getElementById('sendToPropriator');
            if(p_frm != null){
            	createHiddenControl(p_frm);
                p_frm.submit();
            }
        }else{
            show_warn.style.display = "";
        }
   }
}
function isEmptyField(fieldID){
    var result = false;
    var p_name = document.getElementById(fieldID);
    if(p_name != null){
        if(p_name.value == ''){
           result = true;
        }
    }
    return result;
}


function visiblePassDiv(visible){
    var passDiv = document.getElementById("passDiv");
    var passDivButton = document.getElementById("passDivButton");
    if(passDiv != null && passDivButton != null){
        if(visible == false){
            passDiv.style.display = "none";
            passDivButton.style.display = "";
        }else{
            passDiv.style.display = "";
            passDivButton.style.display = "none";
        }
    }

}

function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
    var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
    var aQueryString = strQueryString.split("&");
    for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
      if (aQueryString[iParam].indexOf(strParamName + "=") > -1 ){
        var aParam = aQueryString[iParam].split("=");
        strReturn = aParam[1];
        break;
      }
    }
  }
  return strReturn;
}



function logVariableXXX(prom){
    var logDiv = document.getElementById('glMenuTabsInfo');
    if(logDiv != null){
        logDiv.innerHTML = logDiv.innerHTML + ' '+prom ;
    }else{
        alert('logDiv je null');
    }
}


function trimString(sInString) {
  sInString = sInString.replace( /^\s+/g, "" );// strip leading
  return sInString.replace( /\s+$/g, "" );// strip trailing
}
function initDynamicScript(jspURL,jspPars){
    var date = new Date();
    var timestamp = Date.parse(date);
    var loader=document.createElement('script');
    loader.type='text/javascript';
    loader.src=jspURL+'?'+jspPars;
    var aBox=document.getElementById("dynamicScript");
    aBox.appendChild(loader);
}

function chngSelectedCars(chkbox, cid){
    var urlStr = '/xchanger/uni/carsCompareSel.jsp';
    var secondPar = 'cid='+cid+'&sel=';
    var last_checked_cid = document.getElementById('lastCheckedCid');
        if(chkbox.checked){
            secondPar  += '1';
            if(last_checked_cid != null){
                last_checked_cid.value = cid;
            }
        }else{
            secondPar  += '0';
        }
        initDynamicScript(urlStr,secondPar);
}

function showComparedCars(){
    var lastCheckedCar = document.getElementById('lastCheckedCid');
    if(lastCheckedCar != null){
        var last_cid =  lastCheckedCar.value;
        showCarDetail(last_cid,'4');
    }else{
        showCarDetail('','4');
    }
}
function deactivateCarDetailJS(){
    var btnDiv = document.getElementById('cdDetailNavi');
    if(btnDiv){
        btnDiv.style.display = 'none';
    }
}
function fixStateAndAccessoriesLong(){
    var vState = document.getElementById("formCarState");
    var stateLength = 30;
    if((vState != null) && (vState.value.length<stateLength)){
        var stock = '000000000000000000000000000000'; //30x0
       // alert('vState.value.length:'+vState.value.length);
        var cntToAdd = stateLength-vState.value.length;
        var stringToAdd = stock.substr(0,cntToAdd);
       // alert('stringToAdd:'+stringToAdd);
        vState.value += stringToAdd;
    }
    var vAcc = document.getElementById("formCarAcc");
    var accLength = 200;
    if(vAcc != null && vAcc.value.length<accLength){
        var stockAcc = '00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; //200x"0"
        var cntToAddAcc = accLength-vAcc.value.length;
        var stringToAddAcc = stockAcc.substr(0,cntToAddAcc);
        //alert('stringToAddAcc:'+stringToAddAcc);
        vAcc.value += stringToAddAcc;
        //alert('vAcc.value:'+vAcc.value);
    }
}
function chngAgree(){
    var agreeChkb = document.getElementById('chkboxAgree');
    if(agreeChkb != null){
        if(agreeChkb.checked){
            agreeChkb.checked = false;
        }else{
            agreeChkb.checked = true;
        }
    }
}
function showContactTab(tab){
    tab = parseInt(tab);
    if(tab<5){
        /*tady jde o obrazky v hlavicce*/
      hideDiv('reklama_head');
      showDiv('kontakt_head');
    }else if(tab==5){
      hideDiv('kontakt_head');
      showDiv('reklama_head');
    }

     switch(tab){
        case 1:
           hideAllSubContacts();
           showDiv('contact_main');
           clickUnAvailableDiv('contact_top_main');

        break;
        case 2:
            hideAllSubContacts();
            showDiv('contact_about');
            clickUnAvailableDiv('contact_top_about');
        break;
        case 3:
          hideAllSubContacts();
          showDiv('contact_privacy');
          clickUnAvailableDiv('contact_top_privacy');

        break;
        case 4:
           hideAllSubContacts();
           showDiv('contact_legal_statement');
           clickUnAvailableDiv('contact_top_legal_statement');

        break;
        case 5:
           hideAllSubContacts();
           showDiv('contact_reklama');
           clickUnAvailableDiv('contact_top_ad');

        break;
        default:
           hideAllSubContacts();
           showDiv('contact_main');
           clickUnAvailableDiv('contact_top_main');
        break;
     }
}
function showDiv(divId){
    var vDiv = document.getElementById(divId);
    if(vDiv != null){
        vDiv.style.display = "";
    }

}
function hideDiv(divId){
    var vDiv = document.getElementById(divId);
    if(vDiv != null){
        vDiv.style.display = "none";
    }

}
function hideAllSubContacts(){
    hideDiv('contact_main');
    clickAvailableDiv('contact_top_main');
    hideDiv('contact_about');
    clickAvailableDiv('contact_top_about');
    hideDiv('contact_privacy');
    clickAvailableDiv('contact_top_privacy');
    hideDiv('contact_legal_statement');
    clickAvailableDiv('contact_top_legal_statement');
    hideDiv('contact_reklama');
    clickAvailableDiv('contact_top_ad');
}
function clickAvailableDiv(divId){
    var vDiv = document.getElementById(divId);
    if(vDiv != null){
        vDiv.className = 'clickavailable activeSubTitle';
    }
}
function clickUnAvailableDiv(divId){
    var vDiv = document.getElementById(divId);
    if(vDiv != null){
        vDiv.className = 'activeSubTitle';
    }
}
function setCarYearDo(){
    var cmbOd = document.getElementById('formCarYearOd');
    var cmbDo = document.getElementById('formCarYearDo');
    if(cmbOd && cmbDo){
        //alert('cmbOd.selected:'+cmbOd.selected);
        //alert('cmbOd.selectedIndex:'+cmbOd.selectedIndex);
        //alert('cmbOd.selectedValue:'+cmbOd.options[cmbOd.selectedIndex].value);
        for(m=cmbDo.options.length-1;m>0;m--){
            cmbDo.options[m]=null;
        }
        for(i=0;i<cmbOd.selectedIndex;i++){
            cmbDo.options[i] = new Option(cmbOd.options[i].text,cmbOd.options[i].value);
        }
    }else{
        alert('cmbOd je null');
    }
}

function limitToMade(fromComboId,toComboId){
    var firstYear = 1980;
    var refArray = createArrayNum(currentYear,firstYear);
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    if(fromCombo && toCombo){
        var toComboLowerIndexValue = fromCombo[fromCombo.selectedIndex].value;
        //alert('toComboLowerIndexValue:'+toComboLowerIndexValue);
        if(fromCombo.selectedIndex == 0){
            toComboLowerIndexValue = firstYear;
        }
        var refreshFromCombo=false;
        if(toCombo.options.length==1){
        	refreshFromCombo=true;
        }
        var savedToIndex = toCombo.selectedIndex;
		    var veteran=false;	
        if(fromCombo[fromCombo.selectedIndex].value<firstYear){
        	toComboLowerIndexValue = firstYear;
        	veteran=true;
      	}
		       // alert('toCombo.options.length a: '+toCombo.options.length);
    	    /*clear toCombo*/
      	  for(m=toCombo.options.length-1;m>0;m--){
        	    toCombo.options[m]=null;
        	}
        	//alert('toCombo.options.length b: '+toCombo.options.length);
        	//toCombo.options.length = 0;
        	toComboLowerIndexBoundReached = false;
        	var i=0;
        	if(veteran){
        		toCombo.options[0]=new Option(firstYear,firstYear);		//pouze jedna volba "do roku"
        		for(m=fromCombo.options.length-1;m>0;m--){						//doplneni "od roku" az do currentYear
        	    fromCombo.options[m]=null;
        		}
        		var carYearMadeFrom=createArrayNumMadeFrom(currentYear,1980);
	       		for(m=0;m<carYearMadeFrom.length;m++){
        			fromCombo.options[m] = new Option(carYearMadeFrom[m][1],carYearMadeFrom[m][0]);
        		}
        		fromCombo.selectedIndex = fromCombo.options.length-1;
        	}else{
        		while(!toComboLowerIndexBoundReached && i<refArray.length){
            	//alert('refArray['+i+'][1],refArray[i][0]'+refArray[i][1]+' - '+refArray[i][0]);
            	toCombo.options[i] = new Option(refArray[i][1],refArray[i][0]);
            	if(refArray[i][0] == toComboLowerIndexValue){ /*alert('toComboLowerIndexBoundReached:'+i);*/   toComboLowerIndexBoundReached = true;}
            	i++;
        		}
        	}

        //alert('toCombo.options.length c: '+toCombo.options.length);
        //alert('savedToIndex:'+savedToIndex);
        toCombo.selectedIndex = savedToIndex;
        if(refreshFromCombo){		//patch pri prechodu z "< 1980" na vyssi rok - doplni az do currentYear
        	limitFromMade(fromComboId,toComboId);
        }
    }
}
function limitFromMade(fromComboId,toComboId){
   // alert('limitFromMade');
    var refArray = createArrayNumMadeFrom(currentYear,1980);

    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    if(fromCombo && toCombo){
        //alert('first fromCombo.options.length:'+fromCombo.options.length);
        var fromComboUpperIndexBound = toCombo.selectedIndex;
        var savedFromComboValue = fromCombo[fromCombo.selectedIndex].value;
        var savedFromComboIndex = 0;
        /*clear toCombo*/
        for(m=fromCombo.options.length-1;m>0;m--){
              fromCombo.options[m]=null;
        }
        //fromCombo.options.length = 0;
       // alert('vymazano');
        var myOffset = 1;
        if(fromComboUpperIndexBound == 0){
            /*aby se nedelal jeste jeden prazdny option na zacatku v comboboxu*/
            myOffset = 0;
        }
        for(i=fromComboUpperIndexBound;i<refArray.length;i++){
            //alert('refArray['+i+'][1],refArray[i][0]'+refArray[i][1]+' - '+refArray[i][0])
            fromCombo.options[i-fromComboUpperIndexBound+myOffset] = new Option(refArray[i][1],refArray[i][0]);
            //alert('fromCombo.options.length:'+fromCombo.options.length);
            if(refArray[i][0]==savedFromComboValue){
                 savedFromComboIndex = i-fromComboUpperIndexBound+myOffset;
            }
        }
        //alert('savedFromComboIndex:'+savedFromComboIndex);
        fromCombo.selectedIndex = savedFromComboIndex;
        //alert('fromCombo.options.length:'+fromCombo.options.length);
    }else{
        alert('fromCombo or toCombo = null');
    }

}


function limitToPrice(fromComboId,toComboId){
    /*var refArray = createArray(getCommVariable("carPrice"));*/
    var refArray = carPrice;
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    if(fromCombo && toCombo){
        var toComboLowerIndexBound = fromCombo.selectedIndex;
       /* if(toComboLowerIndexBound==0){
           // return false;
        }*/
        //alert('toComboLowerIndexBound:'+toComboLowerIndexBound);
        var savedToComboValue = toCombo[toCombo.selectedIndex].value;
        //alert('savedToComboValue:'+savedToComboValue);
        savedToComboIndex = 0; /*init*/
        /*clear toCombo*/
        for(m=toCombo.options.length-1;m>0;m--){
              toCombo.options[m]=null;
        }
       // toCombo.options.length = 0;
       //alert('toComboLowerIndexBound:'+toComboLowerIndexBound);
        var myOffset = 1;
        if(toComboLowerIndexBound == 0){
            myOffset = 0;
        }
        for(i=toComboLowerIndexBound;i<refArray.length;i++){
           // alert(refArray[i][1]+' - '+refArray[i][0])
            toCombo.options[i-toComboLowerIndexBound+myOffset] = new Option(refArray[i][1],refArray[i][0]);
            if(refArray[i][0]==savedToComboValue){
                savedToComboIndex = i-toComboLowerIndexBound+myOffset;
                toCombo.selectedIndex = savedToComboIndex;
               // alert('savedToComboIndex selected :'+savedToComboIndex);
            }
        }

    }
}
function limitFromPrice(fromComboId,toComboId){
    /*var refArray = createArray(getCommVariable("carPrice"));*/
    var refArray = carPrice;
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    if(fromCombo && toCombo){
        var fromComboUpperValue = toCombo[toCombo.selectedIndex].value;
        if(toCombo.selectedIndex == 0){
            fromComboUpperValue = refArray[refArray.length-1][0];
        }

        //alert('fromComboUpperValue:'+fromComboUpperValue);
        var savedFromComboIndex = fromCombo.selectedIndex;

        //alert('savedFromComboIndex:'+savedFromComboIndex);

        /*clear toCombo*/
        for(m=fromCombo.options.length-1;m>0;m--){
              fromCombo.options[m]=null;
        }
        fromCombo.options.length = 0;

        fromComboUpperIndexBoundReached = false;
        var i=0;
        while(!fromComboUpperIndexBoundReached){
            fromCombo.options[i] = new Option(refArray[i][1],refArray[i][0]);
            //alert(refArray[i][0]+' == '+fromComboUpperValue);
            if(refArray[i][0] == fromComboUpperValue){ fromComboUpperIndexBoundReached = true; }
            i++;
        }
        fromCombo.selectedIndex = savedFromComboIndex;
    }else{
        alert('fromCombo or toCombo = null');
    }

}

function limitFromPower(fromComboId,toComboId){
    var refArray = carPower;
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    if(fromCombo && toCombo){
        var fromComboUpperValue = toCombo[toCombo.selectedIndex].value;
        if(toCombo.selectedIndex == 0){
            fromComboUpperValue = refArray[refArray.length-1][0];
        }

        var savedFromComboIndex = fromCombo.selectedIndex;

        //alert('savedFromComboIndex:'+savedFromComboIndex);

        /*clear toCombo*/
        for(m=fromCombo.options.length-1;m>0;m--){
              fromCombo.options[m]=null;
        }
        fromCombo.options.length = 0;

        fromComboUpperIndexBoundReached = false;
        var i=0;
        while(!fromComboUpperIndexBoundReached){
            fromCombo.options[i] = new Option(refArray[i][1],refArray[i][0]);
            if(refArray[i][0] == fromComboUpperValue){ fromComboUpperIndexBoundReached = true; }
            i++;
        }
        fromCombo.selectedIndex = savedFromComboIndex;
    }else{
        alert('fromCombo or toCombo = null');
    }

}
function limitToPower(fromComboId,toComboId){
    var refArray = carPower;
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    if(fromCombo && toCombo){
        var toComboLowerIndexBound = fromCombo.selectedIndex;
       /* if(toComboLowerIndexBound==0){
           // return false;
        }*/
        //alert('toComboLowerIndexBound:'+toComboLowerIndexBound);
        var savedToComboValue = toCombo[toCombo.selectedIndex].value;
        //alert('savedToComboValue:'+savedToComboValue);
        savedToComboIndex = 0; /*init*/
        /*clear toCombo*/
        for(m=toCombo.options.length-1;m>0;m--){
              toCombo.options[m]=null;
        }
       //alert('toComboLowerIndexBound:'+toComboLowerIndexBound);
        var myOffset = 1;
        if(toComboLowerIndexBound == 0){
            myOffset = 0;
        }
        for(i=toComboLowerIndexBound;i<refArray.length;i++){
            toCombo.options[i-toComboLowerIndexBound+myOffset] = new Option(refArray[i][1],refArray[i][0]);
            if(refArray[i][0]==savedToComboValue){
                savedToComboIndex = i-toComboLowerIndexBound+myOffset;
                toCombo.selectedIndex = savedToComboIndex;
               // alert('savedToComboIndex selected :'+savedToComboIndex);
            }
        }

    }
}

function limitFromCapacity(fromComboId,toComboId,carTypeComboId){
    var refArray = carCapacity;
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    var ctypeCombo = document.getElementById(carTypeComboId);
    var carTypeVal = ctypeCombo[ctypeCombo.selectedIndex].value;
    if(fromCombo && toCombo){
        var fromComboUpperValue = toCombo[toCombo.selectedIndex].value;
        if(toCombo.selectedIndex == 0){
            fromComboUpperValue = refArray[refArray.length-1][0];
        }

        var savedFromComboIndex = fromCombo.selectedIndex;

        //alert('savedFromComboIndex:'+savedFromComboIndex);

        /*clear toCombo*/
        for(m=fromCombo.options.length-1;m>0;m--){
              fromCombo.options[m]=null;
        }
        fromCombo.options.length = 0;

        fromComboUpperIndexBoundReached = false;
        var i=0;
        var j=0;
        while(!fromComboUpperIndexBoundReached){
        	
        	if(refArray[i][2].indexOf(carTypeVal)!=-1)
        	{
             fromCombo.options[j] = new Option(refArray[i][1],refArray[i][0]);
             j++;
        	}
            if(refArray[i][0] == fromComboUpperValue){ fromComboUpperIndexBoundReached = true; }
            i++;
        }
        fromCombo.selectedIndex = savedFromComboIndex;
    }else{
        alert('fromCombo or toCombo = null');
    }

}

function limitToCapacity(fromComboId,toComboId,carTypeComboId){
    var refArray = carCapacity;
    var fromCombo = document.getElementById(fromComboId);
    var toCombo = document.getElementById(toComboId);
    var ctypeCombo = document.getElementById(carTypeComboId);
    var carTypeVal = ctypeCombo[ctypeCombo.selectedIndex].value;
    if(fromCombo && toCombo){
        var toComboLowerValue = fromCombo[fromCombo.selectedIndex].value;
        if(fromCombo.selectedIndex == 0){
            toComboLowerValue = refArray[0][0];
        }

        var savedToComboVal = toCombo[toCombo.selectedIndex].value;

        //alert('savedFromComboIndex:'+savedFromComboIndex);

        /*clear toCombo*/
        for(m=toCombo.options.length-1;m>0;m--){
              toCombo.options[m]=null;
        }
        toCombo.options.length = 0;

        toComboLowerIndexBoundReached = false;
        var i=0;
        var j=0;
        while(i < refArray.length){
        	if(!toComboLowerIndexBoundReached && refArray[i][0] == toComboLowerValue){ toComboLowerIndexBoundReached = true; }
        	
        	if(toComboLowerIndexBoundReached || i==0)
        	{
        	 if(refArray[i][2].indexOf(carTypeVal)!=-1)
        	 {
              toCombo.options[j] = new Option(refArray[i][1],refArray[i][0]);
              if(toCombo[j].value == savedToComboVal) toCombo.selectedIndex=j;
              j++;
        	 }
        	}
           i++;
        }
    }else{
    	alert('fromCombo or toCombo = null');
    }
}

function showAccessory(whereObj,accDesc){
    //alert(accDesc.length);
    if(accDesc.length > 15){
        //alert('more than 20');
        var childEl = document.createElement("div");
        whereObj.appendChild(childEl);
        var txtNode = document.createTextNode(accDesc);
        childEl.appendChild(txtNode);
    }
}
function chCountry(cmbox){
    window.location.href="index.jsp?country="+cmbox.options[cmbox.selectedIndex].value;
}
function unCheckAllCars()
{
    frm = document.getElementById('carFormSearch');
    if(frm){
        count = frm.elements.length;
        for (i=0; i < count; i++)
        {
           var elId = frm.elements[i].id;
            if(elId.indexOf('chk_')>-1){
                frm.elements[i].checked = 0;
            }
        }
        initDynamicScript('/xchanger/uni/carsCompareSel.jsp','del=all');
    }
}
function chStyle(element, cssClass){
    element.className = cssClass;
}
function extendedSearch(){
    var frm_used = document.getElementById('findUsed');
    if(frm_used){
        frm_used.action = '/xchanger/uni/carUsedFind.jsp?det=1';
    }
    frm_used.submit();
}
 function extendedSearchNew(){
    var frm_new = document.getElementById('findNew');
    if(frm_new){
        frm_new.action = '/xchanger/uni/carNewFind.jsp?det=1';
    }
    frm_new.submit();
}
function extendedSearch(searchUrl){
    var frm_used = document.getElementById('findUsed');
    if(frm_used){
        frm_used.action = searchUrl+'?det=1';
    }
    frm_used.submit();
}
 function extendedSearchNew(searchUrl){
    var frm_new = document.getElementById('findNew');
    if(frm_new){
        frm_new.action = searchUrl+'?det=1';
    }
    frm_new.submit();
}
function getSelectIndex(pSelect,pSearchedValue){
    var result = -1;
    if(pSelect.options){
        for(var i=0;i< pSelect.options.length;i++){
            if(pSelect.options[i].value == pSearchedValue){
               result = i;
            }
        }
    }
    return result;
}
function chngComboByInput(parentID,fieldID){
    var father = getObj(parentID);
    var combo = getObj(fieldID);
    if(combo != null && father != null){
        var inputSon = document.createElement('input');
        inputSon.type='text';
        inputSon.ID = 'formCarModelInsert';
        inputSon.name = 'signtype';
        inputSon.className = 'glFormInputSelect';
        father.replaceChild(inputSon,combo);
        inputSon.focus();
    }
}
function showReqestRules(showRules){
    var conditionDiv = getObj('carRequestCondition');
    var contentOne = getObj('pageContent1');

    if(conditionDiv != null && contentOne != null){
        if(showRules == 1){
            contentOne.style.display = 'none';
            conditionDiv.style.display = '';

        }
        else {
            contentOne.style.display = '';
            conditionDiv.style.display = 'none';
        }
    }else{
        alert('conditionDiv =  null');
    }
}

function ResultDec(encoded)
{
	var HEXCHARS = "0123456789ABCDEFabcdef"; 
	var plaintext = encoded;var i = 0;while(i < escapeCharsUrl.length){var re2=new RegExp(escapeCharsUrl[i],"igm");plaintext=plaintext.replace(re2,unescapeChars[i]);i++;}var resulttext="";var i = 0;
	while (i < plaintext.length){var ch = plaintext.charAt(i);if (ch == "+") {resulttext += " ";i++;} else if (ch == "%") {if (i < (plaintext.length-2)&& HEXCHARS.indexOf(plaintext.charAt(i+1)) != -1 && HEXCHARS.indexOf(plaintext.charAt(i+2)) != -1 ) {resulttext += unescape( plaintext.substr(i,3) );i += 3;} else {/*alert( 'Bad escape combination near '+i+'...' + plaintext.substr(i) );*/i++;}} else {resulttext += ch;i++;}}
   	return resulttext;
}

function parseDetMessage() {
    var fotoListObj = req.responseXML.getElementsByTagName("fotolist");
    fotoList=new Array();
    if(fotoListObj){
    for(var i=0;i<fotoListObj.length;i++)
		{
			fotoList[i]=eval("new Array("+ResultDec(fotoListObj[i].firstChild.nodeValue)+")");
		}
	}
    var fotoListMaxObj =req.responseXML.getElementsByTagName("fotolistMax");
	fotoListMax=fotoListMaxObj[0].firstChild.nodeValue;
	for(i=0;i<itemArray.length;i++){
	    var srcObj =req.responseXML.getElementsByTagName(itemArray[i]);
   		if(srcObj[0].firstChild){
	   		document.getElementById(itemArray[i]).innerHTML="";
			srcString=ResultDec(srcObj[0].firstChild.nodeValue);
			if(srcString==" "){
				//document.getElementById(itemArray[i]).style.display='none';
				document.getElementById(itemArray[i]).innerHTML="";
				if(document.getElementById(itemArray[i]+"Title"))
					document.getElementById(itemArray[i]+"Title").style.display='none';
			}else{
				if(document.getElementById(itemArray[i]+"Title"))
					document.getElementById(itemArray[i]+"Title").style.display='block';
				//document.getElementById(itemArray[i]).style.display='block';
				document.getElementById(itemArray[i]).innerHTML=srcString;
			}
		}
	}
	
		if((pCid!="")&&(pTh!="")){
			document.getElementById('prevHref').innerHTML=pagingThumbPrev;
			document.getElementById('prevHref').onclick=document.getElementById('click'+pCid).onclick;			
			document.getElementById('prevThumb').src=pTh;
			document.getElementById('prevHref').style.display="block";
		}else{
			if(pCid!=""){
				document.getElementById('prevHref').innerHTML=pagingPrev;
				document.getElementById('prevHref').href=pCid;
			}else{
				document.getElementById('prevHref').style.display="none";
			}
		}
		if((nCid!="")&&(nTh!="")){
			document.getElementById('nextHref').innerHTML=pagingThumbNext;
			document.getElementById('nextHref').onclick=document.getElementById('click'+nCid).onclick;
			document.getElementById('nextThumb').src=nTh;
			document.getElementById('nextHref').style.display="block";
		}else{
			if(nCid!=""){
				document.getElementById('nextHref').innerHTML=pagingNext;
				document.getElementById('nextHref').href=nCid;
			}else{
				document.getElementById('nextHref').style.display="none";
			}
		}
    preLoadBigImage();
	detLoading(0);
	document.getElementById('detailDiv').style.display='block';
    chMenuTabs(1,3);
}



