
function tabs(z, s)
{
    z.each(function zf(z) {$(z).className = 'tabsTi';});
    $(z[0]).className = 'tabsTa';

    s.each(function sf(s) {$(s).style.display = 'none';});
    $(s[0]).style.display = 'block';

    sh();
    return true;
}

function search_field(field, mode)
{
	var word = 'Search';
	switch(mode) {
		case 0:	if ('' == field.value) {field.value=word;}
			break
		case 1:	if (word == field.value) {field.value='';}
			break;
		default: // 3
			if (word != field.q.value && '' != field.q.value) {return true;}
	}
	return false;
}


function send_demand()
{
	if ('' != document.getElementById('contact').value) {
		if ('' != document.getElementById('phone').value) {
			return true;
		} else {
			alert('Пожалуйста заполните поле Телефон');
		}
	} else {
		alert('Пожалуйста заполните поле Контактное лицо');
	}

	return false;
}

function form(action, method, target, submit)
{
	if ('undefined' == typeof(method)) {
		method = 'post';
	}
	var targ = '';
	if ('undefined' != typeof(target)) {
		targ = ' target="' + target + '"';
	}
	var subm = '';
	if ('undefined' != typeof(submit)) {
		subm = ' onsubmit="'+submit+'" '
	}
	document.write('<form method="'+method+'" action="'+action+'" '+targ+' '+subm+' enctype="multipart/form-data" autocomplete="off">');
	return;
}

function ov(tr)
{
	//for (i=-1;++i<tr.childNodes.length;) {tr.childNodes[i].style.backgroundColor = '#7C8DA3';}
	tr.style.backgroundColor = '#2b4357';
	return;
}

function ou(tr)
{
	//for (i=-1;++i<tr.childNodes.length;) {tr.childNodes[i].style.backgroundColor = '';}
	tr.style.backgroundColor = '';
	return;
}

function pm(o, a)
{
	var x = o.parentNode.firstChild;
	var val = parseInt(x.value);

	if (a) {
		x.value = !isNaN(++val)? val : 1;
	} else {
		x.value = !isNaN(--val)? val : 0;
		if (val <= 0) x.value = 0;
	}
	return;
}

function pozReset()
{
	var count = document.getElementsByName('count');
	for (i = -1; ++i < 101;) {
		try {document.getElementById('v'+i).value = '';} catch(e) {return;}
	}
	return;
}

function diss()
{
	if ('' == document.getElementById('surname').value) {
		alert('Заполните обязательное поле: Фамилия');
	} else {
		if ('' == document.getElementById('name').value) {
			alert('Заполните обязательное поле: Имя');
		} else {
			if ('' == document.getElementById('fathername').value) {
				alert('Заполните обязательное поле: Отчество');
			} else {
				if ('' == document.getElementById('email').value) {
					alert('Заполните обязательное поле: E-Mail');
				} else {
					document.getElementById('dis').submit();
				}
			}
		}
	}

	return false;
}

function postView(w, h, img, txt)
{
	var scrnx = screen.width/2 - w/2;
	var scrny = screen.height/2 - h/2;


	if ((typeof txt) == 'undefined' ) {
		txt = '';
	}

	window.open('/'+escape(img)+'&text='+escape(txt),'popUp','width='+w+',height='+h+',scrollbars=no,menubar=no,toolbar=no,status=no,left='+scrnx+',top='+scrny);
	return false;
}

function sh(w)
{

$('globRgt2in1').style.height = 'auto';
$('glf1sr').style.height = 'auto';
//return;

    //if (2 == w) {
        var glh = $('glf1sr').getHeight() + $('hmbg').getHeight();
        var isrh = $('globRgt2in1').getHeight();
        if (-1 != navigator.userAgent.indexOf('pera/9.2') && -1 != location.href.indexOf('catalog')) {$('globRgt2in1').style.height = '2250px';$('glf1sr').style.height = (2250 - $('hmbg').getHeight()) + 'px';return;}
        if (-1 != navigator.userAgent.indexOf('pera/9.2') && -1 != location.href.indexOf('shop')) {$('globRgt2in1').style.height = '4250px';$('glf1sr').style.height = (4250 - $('hmbg').getHeight()) + 'px';return;}
        if (-1 != navigator.userAgent.indexOf('MSIE 6.') && -1 != location.href.indexOf('catalog')) {$('globRgt2in1').style.height = '2250px';$('glf1sr').style.height = (2365) + 'px';return;}
        if (-1 != navigator.userAgent.indexOf('MSIE 6.') && -1 != location.href.indexOf('shop')) {$('globRgt2in1').style.height = '8900px';$('glf1sr').style.height = (8685 ) + 'px';return;}
        if (glh > isrh) {$('globRgt2in1').style.height = (glh) + 'px';} else {$('glf1sr').style.height = ((isrh) - $('hmbg').getHeight()) + 'px';}
        return;
    //}
    var grh = $('globRgt').getHeight();var glh = $('glf1sr').getHeight();
    if (w) {$('globRgt2in1').style.height = (grh - 150) + 'px';}
    if (grh > glh) {$('glf1sr').style.height = (grh - $('hmbg').getHeight() - 150) + 'px';}
    return;
}
//window.onload = sh;

function sop()
{

}

function setCatalogSel(sid)
{

    var s ='psec';
	new Ajax.Request('/?getItem='+sid, {
		method: 'post',
		onCreate: function() {

		    $('sMdot').innerHTML = '- Загрузка... Пожалуйста подождите -';
/*
$('sMdot').innerHTML = '';
		  theSelect=document.createElement("select");
                    theOption=document.createElement("option");
                    theText=document.createTextNode(" - Загрузка, пожалуйста подождите - ");
                    theOption.appendChild(theText);
                    theOption.setAttribute("value","loading");
                    theSelect.appendChild(theOption);
                    theSelect.value = 'loading';
                    $('sMdot').appendChild(theSelect);
*/
			$(s).disabled	= 'disabled';
			$(s).setAttribute('disabled', 'disabled');
		},
		onSuccess: function(transport) {

                         $('sMdot').innerHTML = transport.responseText;
			$(s).disabled	= '';
			$(s).removeAttribute("disabled");
		},
		onFailure: function() {
			$('sMdot').innerHTML = '<b>Произошла непредвиденная ошибка<br />Служба временно отключена.</b>';
		},
		parameters: {sid: sid}
	});
}


function getRecord()
{
    var $id = $F('mdot');
    if (!$id) {return;}
    new Ajax.Request('/?getRecord', {
        method: 'post',
        onCreate: function() {
            $('psec').disabled= 'disabled';$('psec').setAttribute('disabled', 'disabled');
            $('mdot').disabled= 'disabled';$('mdot').setAttribute('disabled', 'disabled');
            //$('getRec').disabled= 'disabled';$('getRec').setAttribute('disabled', 'disabled');
        },
        onSuccess: function(transport) {
            $('setRecord').innerHTML = transport.responseText;
            $('psec').disabled= '';$('psec').removeAttribute("disabled");
            $('mdot').disabled= '';$('mdot').removeAttribute("disabled");
            //$('getRec').disabled= '';$('getRec').removeAttribute("disabled");
            sh(2);setTimeout('sh(2)', 1000);
        },
        onFailure: function() {
            $('setRecord').innerHTML = '<b>Произошла непредвиденная ошибка<br />Служба временно отключена.</b>';
        },
        parameters: {id: $id}
    });
}


function setKamazSel(sid)
{

    var s ='ksec';
	new Ajax.Request('/?getKItem='+sid, {
		method: 'post',
		onCreate: function() {
		    $('sKdot').innerHTML = '- Загрузка... Пожалуйста подождите -';
			$(s).disabled	= 'disabled';$(s).setAttribute('disabled', 'disabled');
		},
		onSuccess: function(transport) {
                         $('sKdot').innerHTML = transport.responseText;
			$(s).disabled	= '';$(s).removeAttribute("disabled");
		},
		onFailure: function() {
			$('sKdot').innerHTML = '<b>Произошла непредвиденная ошибка<br />Служба временно отключена.</b>';
		},
		parameters: {sid: sid}
	});
}


function getKamaz()
{
    var $id = $F('kdot');
    if (!$id) {return;}
    new Ajax.Request('/?getKRecord', {
        method: 'post',
        onCreate: function() {
            $('ksec').disabled= 'disabled';$('ksec').setAttribute('disabled', 'disabled');
            $('kdot').disabled= 'disabled';$('kdot').setAttribute('disabled', 'disabled');
            //$('getKam').disabled= 'disabled';$('getKam').setAttribute('disabled', 'disabled');
        },
        onSuccess: function(transport) {
            $('setKamaz').innerHTML = transport.responseText;
            $('ksec').disabled= '';$('ksec').removeAttribute("disabled");
            $('kdot').disabled= '';$('kdot').removeAttribute("disabled");
            //$('getKam').disabled= '';$('getKam').removeAttribute("disabled");
            sh(2);setTimeout('sh(2)', 1000);
        },
        onFailure: function() {
            $('setKamaz').innerHTML = '<b>Произошла непредвиденная ошибка<br />Служба временно отключена.</b>';
        },
        parameters: {id: $id}
    });
}

var $ac = null;
function _ac() {$ac=new Ajax.Autocompleter("mdot", "qResult", "/?getSearch", {paramName: 'mdot', parameters: '&sid=' + $('psec').value, minChars: 2, indicator: 'indicator'});}

function ac(sid) {
    if (0 > sid) {
        if (-100 == sid) {ajax_list_externalFile = '/?getSearch&sid=0';}
        else if (-200 == sid) {ajax_list_externalFile = '/?getKSearch&sid=0';}
        return;
    }
    ajax_list_externalFile = '/?getSearch&sid=' + sid;
    return;
}


function leftBasket()
{

    new Ajax.Request('/basket/?upBasket', {
        method: 'post',
        onCreate: function() {
        		return;
        },
        onSuccess: function(transport) {
		$('boxBasket').innerHTML = transport.responseText;
		sh(2);setTimeout('sh(2)', 1000);
        },
        onFailure: function() {
        },
        parameters: {up : 1}
    });

    return;
}

function upBasket()
{

    new Ajax.Request('/basket/?upBasket', {
        method: 'post',
        onCreate: function() {
        		return;
        },
        onSuccess: function(transport) {
		$('boxBasket').innerHTML = transport.responseText;
		sh(2);setTimeout('sh(2)', 1000);
        },
        onFailure: function() {
        },
        parameters: {
		up	: 1,
		idx	: $F('id'),
		countx: $F('count')
        }
    });
	return;
}


function winBasket()
{
	var winOpen = window.open('/basket/', 'basket', 'width=900,height=600,screenX=100,screenY=100,left=100,top=100,scrollbars,resizible');
	if ('object' != typeof(winOpen)) {
		return true;
	}
	return false;
}
