var dom = true;
if (!document.getElementById) dom = false;
if (!document.getElementById && document.all) {document.getElementById = document.all; dom = true;}
function objekt(what) {return document.getElementById(what);}

// kontrola prazdneho inputu
function isEmpty(e) {
    return ((e == null) || (e.length == 0));
}

// kontrola emailu
function isEmail(mail) {
    re = /^[_a-zA-Z0-9\.\-]+@[_a-zA-Z0-9\.\-]+\.[a-zA-Z]{2,7}$/;
    return mail.search(re) == 0;
}


// prehled
var zatrzeni = "false";
function check(field) {
	if (zatrzeni == "false") {
		for (i = 0; i < field.length; i++) {
			field[i].checked = true;}
			zatrzeni = "true";
		}
	else {
		for (i = 0; i < field.length; i++) {
			field[i].checked = false;
		}
		zatrzeni = "false";
	}
}

function get_reload(form, method) {
  if (!method) {
    method = "GET";
  }
  form.method = method;
  form.submit();
}

/*tab-boxy*/
var dom = true;
if (!document.getElementById) dom = false;
if (!document.getElementById && document.all) {document.getElementById = document.all; dom = true;}
isIE = (document.all && !window.opera) ? true:false;
function objekt(what) {return document.getElementById(what);}

window.onload = init;

function init() {
	//pro menu
	var hash = location.hash.substr(1);
	//switchOff();
	if (hash.indexOf("tab") > -1)	{
		switchOn(hash, 1);
	}
	else {
		//if (objekt("tab1") != null) {
		//	switchOn('tab1');
		//}
	}
	//pro obsah
	var hash2 = location.hash.substr(1);
	switchOff2();
	if (hash2.indexOf("tabmain") > -1)	{
		switchOn2(hash2, 1);
	}
	else {
		if (objekt2("tabmain1") != null) {
			switchOn2('tabmain1');
		}
	}
}
// zneviditelni vsechny divy s id obsahujici tabN, kde N je cislo, u vsech zalozek tabN zrusi tridu
function switchOff() {
	for (i = 1; i < document.getElementsByTagName("div").length + 1; i++) {
		if (objekt("tab" + i) != null) {
			objekt("tab" + i).style.display = "none";
			objekt("tab" + i + "link").className = "";
		}
		if (objekt("features" + i) != null) {
			objekt("features" + i).style.display = "none";
			objekt("features" + i + "link").style.display = "inline";
		}
	}
}

//zviditelni div s predanym id, aktivuje danou zalozku
function switchOn(allowed, reload) {
	switchOff();
	objekt(allowed).style.display = "block";
	objekt(allowed + "link").className = "active";
	if (reload) {
		document.location.href="#"+ allowed;
	}
	return false;
}

//zviditelni div s predanym id, deaktivuje dany odkaz
function featuresOn(allowed) {
	switchOff();
	objekt(allowed + "link").style.display = "none";
	objekt(allowed).style.display = "block";
	return false;
}

//zneviditelni div s predanym id, aktivuje dany odkaz
function featuresOff(hidden) {
	objekt(hidden).style.display = 'none';
	objekt(hidden + "link").style.display = 'inline';
	return false;
}


/*tab-boxy2*/
function objekt2(what2) {return document.getElementById(what2);}

// zneviditelni vsechny divy s id obsahujici tabN, kde N je cislo, u vsech zalozek tabN zrusi tridu
function switchOff2() {
	for (i = 1; i < document.getElementsByTagName("div").length + 1; i++) {
		if (objekt2("tabmain" + i) != null) {
			objekt2("tabmain" + i).style.display = "none";
			objekt2("tabmain" + i + "link").className = "";
		}
		if (objekt2("featuresmain" + i) != null) {
			objekt2("featuresmain" + i).style.display = "none";
			objekt2("featuresmain" + i + "link").style.display = "inline";
		}
	}
}

//zviditelni div s predanym id, aktivuje danou zalozku
function switchOn2(allowed, reload) {
	switchOff2();
	objekt2(allowed).style.display = "block";
	objekt2(allowed + "link").className = "active";
	if (reload) {
		document.location.href="#"+ allowed;
	}
	return false;
}

//zviditelni div s predanym id, deaktivuje dany odkaz
function featuresOn2(allowed) {
	switchOff2();
	objekt2(allowed + "link").style.display = "none";
	objekt2(allowed).style.display = "block";
	return false;
}

//zneviditelni div s predanym id, aktivuje dany odkaz
function featuresOff2(hidden) {
	objekt(hidden).style.display = 'none';
	objekt(hidden + "link").style.display = 'inline';
	return false;
}

function initAjaxRequest() {
  if(typeof XMLHttpRequest != "undefined") {
    return new XMLHttpRequest();
  }
  else if(window.ActiveXObject) {
    var aVersions = ["MSXML2.XMLHttp.6.0", "MSXML2.XMLHttp.3.0"];
    for(var i = 0; i < aVersions.length; i++) {
      try {
        var oXHR = new ActiveXObject(aVersions[i]);
        return oXHR;
      } catch (oError) {
        //Do nothing
      }
    }
  }
  throw new Error("XMLHttp object could not be created.");
}

function createFilterBrandsList() {
    document.getElementById("fbrandtd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';
    document.getElementById("fmodeltd").innerHTML = '<select disabled="disabled"><option>Vyberte výrobce</option></select>';
    document.getElementById("fyeartd").innerHTML = '<select disabled="disabled"><option>Vyberte typ</option></select>';
    document.getElementById("fenginetd").innerHTML = '<select disabled="disabled"><option>Vyberte rok</option></select>';

    rt = document.getElementById("filtype");
    filtype = rt.options[rt.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=fbrands&type=" + encodeURI(filtype), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("fbrandtd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createFilterModelsList() {
    document.getElementById("fmodeltd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';
    var yeartd = document.getElementById("fyeartd");
    if (yeartd!=null) yeartd.innerHTML = '<select disabled="disabled"><option>Vyberte typ</option></select>';
    var enginetd = document.getElementById("fenginetd");
    if (enginetd!=null) enginetd.innerHTML = '<select disabled="disabled"><option>Vyberte rok</option></select>';

    rt = document.getElementById("filtype");
    if (rt!=null) filtype = rt.options[rt.selectedIndex].value;
    else filtype=7;

    rt = document.getElementById("filbrand");
    filbrand = rt.options[rt.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=fmodels&type=" + encodeURI(filtype) + "&brand=" + encodeURI(filbrand), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("fmodeltd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createFilterNazvyList(category) {
    document.getElementById("fnazevtd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';

    rt = document.getElementById("filtype");
    if (rt!=null) filtype = rt.options[rt.selectedIndex].value;
    else filtype=7;

    rt = document.getElementById('filbrand');
    filbrand = rt.options[rt.selectedIndex].value;

    rt2 = document.getElementById('filmodel');
    filmodel = rt2.options[rt2.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=fnazvy&type=" + encodeURI(filtype) + "&brand=" + encodeURI(filbrand) + "&model=" + encodeURI(filmodel), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("fnazevtd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createFilterYearsList(category) {
    document.getElementById("fyeartd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';
    document.getElementById("fenginetd").innerHTML = '<select disabled="disabled"><option>Vyberte rok</option></select>';

    rt = document.getElementById("filtype");
    filtype = rt.options[rt.selectedIndex].value;

    rt = document.getElementById('filbrand');
    filbrand = rt.options[rt.selectedIndex].value;

    rt2 = document.getElementById('filmodel');
    filmodel = rt2.options[rt2.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=fyears&type=" + encodeURI(filtype) + "&brand=" + encodeURI(filbrand) + "&model=" + encodeURI(filmodel), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("fyeartd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createFilterEnginesList(category) {
    document.getElementById("fenginetd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';

    rt = document.getElementById("filtype");
    filtype = rt.options[rt.selectedIndex].value;

    rt = document.getElementById('filbrand');
    filbrand = rt.options[rt.selectedIndex].value;

    rt2 = document.getElementById('filmodel');
    filmodel = rt2.options[rt2.selectedIndex].value;

    rt3 = document.getElementById('filyear');
    filyear = rt3.options[rt3.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=fengines&type=" + encodeURI(filtype) + "&brand=" + encodeURI(filbrand) + "&model=" + encodeURI(filmodel) + "&year=" + encodeURI(filyear), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("fenginetd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createPrBrandList() {
    document.getElementById("prbrandtd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';
    document.getElementById("prmodeltd").innerHTML = '<select disabled="disabled"><option>Vyberte výrobce</option></select>';

    rt = document.getElementById("prtype");
    prtype = rt.options[rt.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=prbrands" + "&type=" + encodeURI(prtype), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("prbrandtd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createPrModelsList() {
    document.getElementById("prmodeltd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';

    rt = document.getElementById("prtype");
    prtype = rt.options[rt.selectedIndex].value;

    rt = document.getElementById("prbrand");
    prbrand = rt.options[rt.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=prmodels" + "&type=" + encodeURI(prtype) + "&brand=" + encodeURI(prbrand), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;

                document.getElementById("prmodeltd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}

function createAluModelsList() {
    document.getElementById("alumodeltd").innerHTML = '<img src="/gfx/ajaxwait.gif" alt="wait..."/>';
    document.getElementById("aluvelikosttd").innerHTML = '<select disabled="disabled"></select>';

    rt = document.getElementById("alubrand");
    alubrand = rt.options[rt.selectedIndex].value;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=alumodels" + "&brand=" + encodeURI(alubrand), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;
                document.getElementById("alumodeltd").innerHTML = divTxt;
                createAluVelikostiList();
            }
        }
    };

    oXmlHttp.send(null);
}

function createAluVelikostiList() {
    document.getElementById("aluvelikosttd").innerHTML = '<select disabled="disabled"></select>';

    rt = document.getElementById("alubrand");
    alubrand = rt.options[rt.selectedIndex].value;

    rt = document.getElementById("alumodel");
    if (rt!=null) alumodel = rt.options[rt.selectedIndex].value;
    else alumodel = 0;

    var oXmlHttp = initAjaxRequest();

    oXmlHttp.open("get", "/scripts/ajaxfilters.php?ajax=aluvelikosti" + "&brand=" + encodeURI(alubrand) + "&model=" + encodeURI(alumodel), true);
    oXmlHttp.onreadystatechange = function () {
        if (oXmlHttp.readyState == 4) {
            if (oXmlHttp.status == 200) {
                divTxt = oXmlHttp.responseText;
                document.getElementById("aluvelikosttd").innerHTML = divTxt;
            }
        }
    };

    oXmlHttp.send(null);
}


