function sp_f(form) {
    form.Sp1.value = Math.round((Math.round(form.Wdn.options[form.Wdn.selectedIndex].value * form.Hdn.options[form.Hdn.selectedIndex].value * 2 + form.Rdn.options[form.Rdn.selectedIndex].value * 25.4) / Math.round(form.Wd.options[form.Wd.selectedIndex].value * form.Hd.options[form.Hd.selectedIndex].value * 2 + form.Rd.options[form.Rd.selectedIndex].value * 25.4)) * form.Sp.value * 100) / 100;
    form.Sp2.value = Math.round((form.Sp1.value-form.Sp.value) * 100) / 100;
}
function t_calc(form) {
    form.Tw.value = form.Wd.options[form.Wd.selectedIndex].value;
    form.Tw1.value = form.Wdn.options[form.Wdn.selectedIndex].value;
    form.Tw2.value = form.Wdn.options[form.Wdn.selectedIndex].value - form.Wd.options[form.Wd.selectedIndex].value;
    form.Tr.value = Math.round(form.Rd.options[form.Rd.selectedIndex].value);
    form.Tr1.value =  Math.round(form.Rdn.options[form.Rdn.selectedIndex].value);
    form.Tr2.value =  Math.round(form.Rdn.options[form.Rdn.selectedIndex].value) - Math.round(form.Rd.options[form.Rd.selectedIndex].value);
    form.dTr1.value = Math.round(form.Rdn.options[form.Rdn.selectedIndex].value);
    form.Th.value = Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value * 2
    + form.Rd.options[form.Rd.selectedIndex].value * 25.4);
    form.Th1.value = Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
    +form.Rdn.options[form.Rdn.selectedIndex].value*25.4);
    form.Th2.value = Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
    +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
    -Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
    +form.Rd.options[form.Rd.selectedIndex].value*25.4);
    form.Kl.value = (Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
    +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
    -Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
    +form.Rd.options[form.Rd.selectedIndex].value*25.4))/2;
    if((6>=form.Kl.value)&&(form.Kl.value>=-10)) {
        document.getElementById('Ttl').innerHTML = "<h3 style='background:green;'>Наши рекомендации: менять на новый размер можно</h3>";
     } else {
        document.getElementById('Ttl').innerHTML = "<h3 style='background:#c10203;'>Наши рекомендации: менять на новый размер не рекомендуется</h3>";
    }
    form.Sp1.value = Math.round((Math.round(form.Wdn.options[form.Wdn.selectedIndex].value*form.Hdn.options[form.Hdn.selectedIndex].value*2
    +form.Rdn.options[form.Rdn.selectedIndex].value*25.4)
    /Math.round(form.Wd.options[form.Wd.selectedIndex].value*form.Hd.options[form.Hd.selectedIndex].value*2
    +form.Rd.options[form.Rd.selectedIndex].value*25.4))*form.Sp.value*100)/100;
    form.Sp2.value = Math.round((form.Sp1.value-form.Sp.value)*100)/100
    form.Sp4.value = Math.round((1-form.Hdn.options[form.Hdn.selectedIndex].value*0.28)*form.Wdn.options[form.Wdn.selectedIndex].value/12.7)/2
}
function chkIsNum(tg){
    var tgVal=tg.value;
    var tgLen=tgVal.length-1;
    var tgEnd=tgVal.charAt(tgLen);
    var re=/\d/;
    chkRe=re.test(tgEnd);
    if(chkRe){
        tg.value=tgVal;
    }else{
        tg.value=tgVal.substr(0,tgLen);
    }
}
function podbor(frVal,tg){
    ar=["selBrand","selModel","selYear","selModelMod"]
    url="ac.php?d="+Math.random();
    document.getElementById(tg).removeAttribute("disabled");
    axLoad(url,"item="+tg+"&val="+frVal,tg);
    for(i=0;i<ar.length;i++){
        switch(tg){
            case "selModel":ii=1;break;
            case "selYear":ii=2;break;
            case "selModelMod":ii=3;break;
        }
        if(i>ii){
            document.getElementById(ar[i]).innerHTML='<select disabled=\"disabled\"><option value=\"\"></option></select>';
        }
    }
}
function podbor_show(){
    b=document.getElementById("sselBrand").value;
    m=document.getElementById("sselModel").value;
    y=document.getElementById("sselYear").value;
    d=document.getElementById("sselModelMod").value;
    url="?page=podbor&brand="+b+"&model="+m+"&year="+y+"&modif="+d;
    document.location=url;
}
function putImag(val,col,to){
    var url="put.php";
    switch(to){
        case "ins":
            axLoad(url,"val="+val+"&col="+col+"&to="+to,"usrkorzina");
            if(window.confirm("Вы можете открыть корзину покупок или продолжить выбор.\r\n\r\nОткрыть корзину?")==true){
                document.location='?page=korzina';
            }
            break;
        case "del":
            axLoad(url,"val="+val+"&col="+col+"&to="+to+"&tg=0","usrkorzina");
            axLoad(url,"val="+val+"&col="+col+"&to="+to+"&tg=1","korzinatable");
            break;
        case "update":
            axLoad(url,"val="+val+"&col="+col+"&to="+to+"&tg=0","usrkorzina");
            axLoad(url,"val="+val+"&col="+col+"&to="+to+"&tg=1","korzinatable");
            break;
    }
}
function loadSrc(wt){
    // wt - это элемент, который мы изменили, а to - элемент, который нужно загрузить
    // 1. Проверим нижестоящие элементы и установим им пустые значения:
    var tovSrcElemAr=new Array();
    var to=null;
    var url="load.php";
    /*
    tovSrcName
    tovSrcBrand
    tovSrcPriceFrom
    tovSrcPriceTo
    */
    switch(wt){
        case "tovSrcName":
            tovSrcElemAr=new Array('tovSrcBrand');
            break;
/*        case "tovSrcBrand":
            tovSrcElemAr=new Array('tovSrcPriceFrom','tovSrcPriceTo');
            break;
        case "tovSrcPriceFrom":
            tovSrcElemAr=new Array('tovSrcPriceTo');
            break;
*/
    }
    l=tovSrcElemAr.length;
    if(l>0){
        for(i=0;i<l;i++){
            g=tovSrcElemAr[i];
            tg=document.getElementById(g);
            var d;
            if(i==0){
                d="<select id=\""+g+"1\" onchange=\"loadSrc('"+g+"');\"><option>Загрузка...</option></select>";
            }else{
                d="<select id=\""+g+"1\" onchange=\"loadSrc('"+g+"');\"><option style=\"color:gray;\" value=\"\">- - Выберите - -</option></select>";
            }
            tg.innerHTML=d;
        }
        to=tovSrcElemAr[0];
    }
    // 2. Сделаем запрос скрипту и получим результат
    if(to!=null){
        if(document.getElementById(wt)){
           wt=document.getElementById(wt+"1");
        }
        axLoad(url,"val="+wt.value+"&to="+to,to);
    }
}
function grayImg(tgName){
    tgAr=document.getElementsByName(tgName);
    for(i=0;i<tgAr.length;i++){
        tg=tgAr[i];
        ungrayImg(0,tg);
    }
}
function ungrayImg(mode,tg){
    switch(mode){
        default:
            tg.style.opacity="0.95";
            tg.style.filter="alpha(Opacity=95)";
//            tg.style.border="solid 1px #464646";
            break;
        case 1:
            tg.style.opacity="1";
            tg.style.filter="";
//            tg.style.border="solid 1px #b40205";
            break;
    }
}
function moveBtn(dir){
    switch(dir){
        default:dir=1;break;
        case "rt":dir=-1;break;
    }
    cols=dir*380;
    var tg=document.getElementById("div");
    var tgLeft=tg.offsetLeft;
    var tgLength=tg.offsetWidth;
    var a1=document.getElementById("a1");
    var a2=document.getElementById("a2");
    a1.style.display="block";
    a2.style.display="block";
    if(Math.abs(tgLeft)>(tgLength-381)&&dir<0){
        cols=0;
        a2.style.display="none";
    }
    if(Math.abs(tgLeft)<1&&dir>0){
        cols=0;
        a1.style.display="none";
    }
    currPos=tgLeft+cols;
    tg.style.left=currPos+"px";
}
function hlThis(tg,color){
    document.getElementById(tg).style.background=color;
}
function unHlThis(tg,color){
    document.getElementById(tg).style.background=color;
}
function axXml(){
	if(window.XMLHttpRequest){
            return new XMLHttpRequest();
	}else if(window.ActiveXObject){
		var msxmls = new Array(
			'Msxml2.XMLHTTP.5.0',
			'Msxml2.XMLHTTP.4.0',
			'Msxml2.XMLHTTP.3.0',
			'Msxml2.XMLHTTP',
			'Microsoft.XMLHTTP'
		);
		for(i=0;i<msxmls.length;i++) {
			try{
                return new ActiveXObject(msxmls[i]);
			}catch(e){
                //
			}
		}
	}else{
        return null;
    }
}
function axLoad(url,vars,rescnt){
    var xmlhttp = axXml();
	if(xmlhttp){
        xmlhttp.open('POST',url, true);
        xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        xmlhttp.send(vars);
        xmlhttp.onreadystatechange = function(){
            if(xmlhttp.readyState == 4) {
                if(xmlhttp.status == 200 && xmlhttp.responseText.length>1) {
                    var v = xmlhttp.responseText;
                    if(document.getElementById(rescnt)){
                        document.getElementById(rescnt).innerHTML=unescape(v);
                    }
                }
            }
        }
    }
}
