 //<![CDATA[
function expandmenulist(obj)
{
	var curvis;
	curvis = document.getElementById(obj).style.display;
	if (curvis == "none") document.getElementById(obj).style.display = "block";
	else document.getElementById(obj).style.display = "none";
};

function showdiv(obj)
{
	document.getElementById(obj).style.display = "block";
}

function hidediv(obj)
{
	document.getElementById(obj).style.display = "none";
}
function FbAlert()
{
	new Boxy("<div align='center' style='width:200px;' id='fb_alert'><\/div>", {modal: true, center:true,unloadOnHide:true});
}

function GetDataFb(action,data,ret,loader)
{
	FbAlert();
	
	if (loader == undefined)
    {
    	
    }
	else
    {
        LocalSetHTML("fb_alert","<img src='http://www.superdc.ru/img/"+loader+".gif' border='0' />");
    }

    JsHttpRequest.query(
                'http://www.superdc.ru/mdse.php?feedbackajax', // backend
                {
                    'MDSE_action': action,
                    'MDSE_data': data
                },
                function(result, errors) {
                    LocalSetHTML(ret,result["Response"]["Ret"]);
                    eval(result["Response"]["Java"]);
                },
                true  // disable caching
               );    
}
function LocalGetValue(divid)
{
	return document.getElementById(divid).value;
}

function LocalSetValue(divid,value)
{
	document.getElementById(divid).value = value;
}
var LOADER = '<div id="ajax_load"><img src="http://www.superdc.ru/img\/ajax.gif" border="0" valign="middle"\/><\/div>';

function GetData(action,data,ret,mini)
{
    document.getElementById(ret).innerHTML = LOADER;
    
    JsHttpRequest.query(
                'http://www.superdc.ru/mdse.php?marketajax', // backend
                {
                    'MDSE_action': action,
                    'MDSE_data': data
                },
                function(result, errors) {
                    LocalSetHTML(ret,result["Response"]["Ret"]);
                    eval(result["Response"]["Java"]);
                },
                true  // disable caching
               );    
}
function Alert(text)
{
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
	showdiv("alert");
	showdiv("alertdata");
	LocalSetHTML("alertdata",text+"<div id='alert_ok'><a href='javascript:hidediv(\"alert\");hidediv(\"alertdata\");'>Ок<\/a><\/div>");
}

function SendForm()
{
	if (document.getElementById("last_name").value.length < 3){Alert('Заполните поле Фамилия');return false;}
	if (document.getElementById("first_name").value.length < 3){Alert('Заполните поле Имя');return false;}
	if (document.getElementById("parent_name").value.length < 3){Alert('Заполните поле Отчество');return false;}
	if (document.getElementById("phone").value.length < 3){Alert('Заполните поле <br>Контактный телефон');return false;}
	if (document.getElementById("email").value.length < 3){Alert('Заполните поле E-mail');return false;}
	
	GetData("market","do<#>ordersend<|>last_name<#>"+LocalGetValue("last_name")+"<|>first_name<#>"+LocalGetValue("first_name")+"<|>parent_name<#>"+LocalGetValue("parent_name")+"<|>phone<#>"+LocalGetValue("phone")+"<|>email<#>"+LocalGetValue("email")+"","content1");	

}


function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function addLoadEvent(func)
{	
	var oldonload = window.onload;
	if (typeof window.onload != 'function'){
    	window.onload = func;
	} else {
		window.onload = function(){
		oldonload();
		func();
		}
	}

}
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

function ResizeOverlay()
{
	var arrayPageSize = getPageSize();

	document.getElementById("overlay_basket").style.height = arrayPageSize[1] + 'px';	
}

addLoadEvent(ResizeOverlay);

function LocalGetHTML(divid)
{
	return document.getElementById(divid).innerHTML;
}

function LocalSetHTML(divid,value)
{
	document.getElementById(divid).innerHTML = value;
}

function updatebasket()
{
	GetData('market','do<#>basketupdate','basket');
}

function colplus(id)
{
	now = parseFloat(LocalGetHTML(id));
	now = now+1;
	LocalSetHTML(id,now);
}

function colminus(id)
{
	now = parseFloat(LocalGetHTML(id));
	now = now-1;
	if (now < 1) {now = 1;}
	LocalSetHTML(id,now);
}

function basketmin(id)
{
	count = basket[id][1];
	count--;
	if (count < 1){count = 1;}
	basket[id][1] = count;
	basket[id][2] = basket[id][1]*basket[id][0];
	GetData('market','do<#>set<|>id<#>'+id+'<|>count<#>'+count,'load_'+id);
	redrawbasketline(id);
	
}

function basketmax(id)
{
	count = basket[id][1];
	count++;
	basket[id][1] = count;	
	basket[id][2] = basket[id][1]*basket[id][0];	
	GetData('market','do<#>set<|>id<#>'+id+'<|>count<#>'+count,'load_'+id);
	redrawbasketline(id);
}
function basketmin2(id)
{
	count = basket[id][1];
	count--;
	if (count < 1){count = 1;}
	basket[id][1] = count;
	basket[id][2] = basket[id][1]*basket[id][0];
	GetData('market','do<#>set2<|>id<#>'+id+'<|>count<#>'+count,'load_'+id);
	redrawbasketline(id);
	
}

function basketmax2(id)
{
	count = basket[id][1];
	count++;
	basket[id][1] = count;	
	basket[id][2] = basket[id][1]*basket[id][0];	
	GetData('market','do<#>set2<|>id<#>'+id+'<|>count<#>'+count,'load_'+id);
	redrawbasketline(id);
}
function redrawbasketline(id)
{
	LocalSetHTML('count_'+id,basket[id][1]);
	LocalSetHTML('summ_'+id,basket[id][2]);
	redrawallsumm();
}

function redrawallsumm()
{
	summ = 0;
	for ( var i in basket )
	{
	    summ += basket[i][2];
	}
	LocalSetHTML('fullsumm','<strong>'+summ+' руб.<\/strong>');
}
$(document).ready(function () {
                        $("a#tip_dvs").simpletip({ 
                            offset: [-40, 12]
                        });
                        var api = $("a#tip_dvs").simpletip();
                        api.update('<div class="tip_text">Двигатели первой комплектности с навесными агрегатами (КПП всегда идет в комплекте), проверенные на стенде, цена указана за ДВС + КПП. Отдельно КПП и ДВС не продаются.</div>');
                        $("a#tip_dvs").simpletip({ 
                            offset: [-40, 12]
                        });
                        $("a#tip_noskat").simpletip({ 
                            offset: [-60, 15]
                        });
                        var api = $("a#tip_noskat").simpletip();
                        api.update('<div class="tip_text">В состав НОСКАТ входят:  оба радиатора, дифузоры с вентиляторами, фары, повороты, бампер (туманки в зависимости от комплектации), усилитель бампера, телевизор, решетка радиатора.</div>');
                    });
//]]>
