function getMail(host, name, obj) 
{
	//window.open('mailto:'+name+'@'+host);
	//return false;
	obj.href = 'mailto:' + name + '@' + host;
	obj.innerHTML = name + '@' + host;
}

//добавление в корзину
function toBasket(shopid)
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
        if (req.readyState == 4){
        	//alert(req.responseText);
            //minib = document.getElementById('minibasket');
            //minib.innerHTML = req.responseJS.basket;
            
            prod = document.getElementById('product'+shopid);
            if(prod)
            {
            	prod.innerHTML = "В корзине";
            }
        }
    }
	req.open(null, '/service/to_basket.php', true);
	req.send( { 'shop_id': shopid } );
}



// функции для всплывающей подсказки
function getSize2() {
	if (self.innerHeight) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
		myScroll = window.pageYOffset;
	} else if (document.documentElement && document.documentElement.clientHeight) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
		myScroll = document.documentElement.scrollTop;
	} else if (document.body) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
		myScroll = document.body.scrollTop;
	}

	if (window.innerHeight && window.scrollMaxY) {	
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight) {
		myScrollWidth = document.body.scrollWidth;
		myScrollHeight = document.body.scrollHeight;
	} else {
		myScrollWidth = document.body.offsetWidth;
		myScrollHeight = document.body.offsetHeight;
	}
}



function show_div(type, name, id)
{
	getSize2();
	//alert(type+"-"+name+"-"+id);
	var inBody = document.getElementsByTagName("body").item(0);
	var inSpinbox = document.createElement("div");
	inSpinbox.setAttribute('id', 'text_win');
	inSpinbox.style.position = 'absolute';
	inSpinbox.style.width = '300px';
	inSpinbox.style.height = '300px';
	inSpinbox.style.left = (myWidth / 2) - 150 + 'px';
	inSpinbox.style.top = ((myHeight / 2) + myScroll) - 150 + 'px';
	inSpinbox.style.backgroundColor = '#ebeef0';
	inSpinbox.style.border = 'solid 1px #666666';
	inSpinbox.style.padding = '10px';
	inSpinbox.style.zIndex = '525';
	inBody.insertBefore(inSpinbox, inBody.firstChild);
	
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
        if (req.readyState == 4){
        	wrapdiv = document.getElementById('wrap');
        	setElementOpacity(wrapdiv, 0.3);
        	document.getElementById('text_win').innerHTML = "<div style='float: left; height 30px;'><b>"+ name +"</b></div><div style='float: right; width: 30px; height 30px;'><a style='cursor: hand; cursor:pointer;' onclick='close_div();'><img alt='Закрыть' src='/images/zoom/closebox.png' border='0'></a></div><div style='overflow-y: scroll; width: 300px; height: 260px; margin-top: 10px;'>"+ req.responseJS.podskazka +"</div>";
        }
    }
	req.open(null, '/service/podskazka.php', true);
	req.send( { 'id': id, 'type': type } );
}

function close_div()
{
	inBody = document.getElementsByTagName("body").item(0);
	element = document.getElementById('text_win');
	inBody.removeChild(element);
	
	wrapdiv = document.getElementById('wrap');
	setElementOpacity(wrapdiv, 1);
}




//для прозрачности
function setElementOpacity(oElem, nOpacity)
{
	var p = getOpacityProperty();
	(setElementOpacity = p=="filter"?new Function('oElem', 'nOpacity', 'nOpacity *= 100;	var oAlpha = oElem.filters["DXImageTransform.Microsoft.alpha"] || oElem.filters.alpha;	if (oAlpha) oAlpha.opacity = nOpacity; else oElem.style.filter += "progid:DXImageTransform.Microsoft.Alpha(opacity="+nOpacity+")";'):p?new Function('oElem', 'nOpacity', 'oElem.style.'+p+' = nOpacity;'):new Function)(oElem, nOpacity);
}


function getOpacityProperty()
{
	var p;
	if (typeof document.body.style.opacity == 'string') p = 'opacity';
	else if (typeof document.body.style.MozOpacity == 'string') p =  'MozOpacity';
	else if (typeof document.body.style.KhtmlOpacity == 'string') p =  'KhtmlOpacity';
	else if (document.body.filters && navigator.appVersion.match(/MSIE ([\d.]+);/)[1]>=5.5) p =  'filter';

	return (getOpacityProperty = new Function("return '"+p+"';"))();
}

function fadeOpacity(sElemId, sRuleName, bBackward)
{
	var elem = document.getElementById(sElemId);
	if (!elem || !getOpacityProperty() || !fadeOpacity.aRules[sRuleName]) return;

	var rule = fadeOpacity.aRules[sRuleName];
	var nOpacity = rule.nStartOpacity;

	if (fadeOpacity.aProc[sElemId]) {clearInterval(fadeOpacity.aProc[sElemId].tId); nOpacity = fadeOpacity.aProc[sElemId].nOpacity;}
	if ((nOpacity==rule.nStartOpacity && bBackward) || (nOpacity==rule.nFinishOpacity && !bBackward)) return;

	fadeOpacity.aProc[sElemId] = {'nOpacity':nOpacity, 'tId':setInterval('fadeOpacity.run("'+sElemId+'")', fadeOpacity.aRules[sRuleName].nDalay), 'sRuleName':sRuleName, 'bBackward':Boolean(bBackward)};
}

fadeOpacity.addRule = function(sRuleName, nStartOpacity, nFinishOpacity, nDalay){fadeOpacity.aRules[sRuleName]={'nStartOpacity':nStartOpacity, 'nFinishOpacity':nFinishOpacity, 'nDalay':(nDalay || 30),'nDSign':(nFinishOpacity-nStartOpacity > 0?1:-1)};};

fadeOpacity.back = function(sElemId){fadeOpacity(sElemId,fadeOpacity.aProc[sElemId].sRuleName,true);};

fadeOpacity.run = function(sElemId)
{
	var proc = fadeOpacity.aProc[sElemId];
	var rule = fadeOpacity.aRules[proc.sRuleName];

	proc.nOpacity = Math.round(( proc.nOpacity + .1*rule.nDSign*(proc.bBackward?-1:1) )*10)/10;
	setElementOpacity(document.getElementById(sElemId), proc.nOpacity);

	if (proc.nOpacity==rule.nStartOpacity || proc.nOpacity==rule.nFinishOpacity) clearInterval(fadeOpacity.aProc[sElemId].tId);
}
fadeOpacity.aProc = {};
fadeOpacity.aRules = {};







function fdostavka(obj)
{
	if(obj.value)
	{
		if(obj.value == 3)
		{
			document.getElementById("fornnov").style.display = "none";
			document.getElementById("forpochta").style.display = "block";
			
			document.getElementById("ustanovka1").style.display = "none";
			document.getElementById("ustanovka2").style.display = "none";
		}
		else if(obj.value == 2)
		{
			document.getElementById("forpochta").style.display = "none";
			document.getElementById("fornnov").style.display = "block";
			
			document.getElementById("ustanovka1").style.display = "block";
			document.getElementById("ustanovka2").style.display = "block";
		}
		else
		{
			document.getElementById("forpochta").style.display = "none";
			document.getElementById("fornnov").style.display = "none";
			
			document.getElementById("ustanovka1").style.display = "block";
			document.getElementById("ustanovka2").style.display = "block";
		}
	}
}



function open_win(title, htmlcontent, width_cont, height_cont)
{
	if(document.getElementById('text_win')){ close_div(); }
	getSize2();
	divwidth = width_cont + 0;
	divheight = height_cont + 45;
	var inBody = document.getElementsByTagName("body").item(0);
	var inSpinbox = document.createElement("div");
	inSpinbox.setAttribute('id', 'text_win');
	inSpinbox.style.position = 'absolute';
	inSpinbox.style.width = divwidth + 'px';
	inSpinbox.style.height = divheight + 'px';
	
	tmpleftotstup = divwidth / 2;
	tmptopotstup = divheight / 2;
	
	inSpinbox.style.left = (myWidth / 2) - tmpleftotstup + 'px';
	inSpinbox.style.top = ((myHeight / 2) + myScroll) - tmptopotstup + 'px';
	inSpinbox.style.backgroundColor = '#ebeef0';
	inSpinbox.style.border = 'solid 1px #666666';
	inSpinbox.style.padding = '10px';
	inSpinbox.style.zIndex = '525';
	inBody.insertBefore(inSpinbox, inBody.firstChild);
	
	inSpinbox.innerHTML = "<div style='float: left; height 30px;'><b>"+ title +"</b></div><div style='float: right; width: 30px; height 30px;'><a style='cursor: hand; cursor:pointer;' onclick='close_div();'><img alt='Закрыть' src='/images/zoom/closebox.png' border='0'></a></div><div style='clear: both;'></div>"+ htmlcontent;
}


function select_auto()
{
	var req = new JsHttpRequest();
	req.onreadystatechange = function() {
	    if (req.readyState == 4){
	    	open_win("Выбор автомобиля", req.responseJS.markaselect, 200, 100);
		}
	}
	req.open(null, '/service/ajaxphp/select_marka.php', true);
	req.send( { 'markaid': 1 } );
}


function selectmarka2()
{
	tmpblockpos = document.getElementById("selmarka2").selectedIndex;
	modelid = document.getElementById("selmarka2").options[tmpblockpos].value;
	
	if(modelid)
	{
		var req = new JsHttpRequest();
		req.onreadystatechange = function() {
		    if (req.readyState == 4){
		    	//document.getElementById("selmodeldiv").innerHTML = req.responseJS.modelselect;
		    	window.location.reload();
			}
		}
		req.open(null, '/service/ajaxphp/select_model.php', true);
		req.send( { 'markaid': modelid } );
	}
}


function selectmodel_final()
{
	tmpblockpos = document.getElementById("selmodelfinal").selectedIndex;
	modelid = document.getElementById("selmodelfinal").options[tmpblockpos].value;
	
	if(modelid)
	{
		var req = new JsHttpRequest();
		req.onreadystatechange = function() {
		    if (req.readyState == 4){
		    	window.location.reload();
			}
		}
		req.open(null, '/service/ajaxphp/select_model_final.php', true);
		req.send( { 'modelid': modelid } );
	}
}
