<!--//

var st = 0;

var ie = (document.all);
var dom = ($);
var ver = parseInt(navigator.appVersion);
var IE = (navigator.appName == "Microsoft Internet Explorer") ? 1 : 0;
var NS = (navigator.appName == "Netscape") ? 1 : 0;
var TopCoord  = 0;
var LeftCoord = 0;
//var nMenu = 8;

function show(n)
{
	clearTimeout(st);

	var obj = getobj('menu'+n);
	var img = document.images['m'+n];
	var top = null;

	TopCoord  = ObjTop(img, -1);
	LeftCoord = ObjLeft(img, 122);

	obj.top  = TopCoord;
	obj.left = LeftCoord;

	if (!document.all) { div = $('menu'+n);}
	else { div = document.all['menu'+n];}
	if (div.style.visibility == 'visible') hide();
	else
	{
		hide();
		if (div.innerHTML.search(/href/) != -1) div.style.visibility='visible';
	}

}
function CheckContent(divText)
{
	if (divText.search(/href/) == -1) return false;
	else return true;
}
function hide()
{
	for (n=1;; n++) {
        var obj = getobj('menu'+n);
        if (!obj) return;

        $('menu'+n).style.visibility='hidden';
        $('menu'+n).top  = -1000;
        $('menu'+n).left = -1000;
	}
}

function getobj(s)
{
     obj = eval("$('" + s + "');");
     if (!obj) return;
     else return obj.style;
}

function ObjLeft(elem, offset)
{
    if ((NS) && (ver==4)) { return elem.x - offset;}
    else
    {
		var X = 0;
		do { X += elem.offsetLeft } while ((elem = elem.offsetParent) != null);
		return X - offset;
	}
}

function ObjTop(elem, offset)
{
	if ((NS) && (ver==4)) { return elem.y + elem.height + offset;}
	else
	{
		if (IE) { var H = elem.height;}
		else { var H = elem.height;}
		var Y = 0;
		do { Y += elem.offsetTop } while ((elem = elem.offsetParent) != null);
	    return Y + H + offset;
    }
}

function placeInput(inp, outp) { $(outp).value = inp;}
function LoadPhones(id) { DoRequest('/gd.php?v=' + id);}

var request;

function DoRequest(url)
{
	if (window.XMLHttpRequest)
	{
		request = new XMLHttpRequest();
		request.onreadystatechange = processRequestChange;
		request.open("GET", url, true);
		request.send(null);
	}
	else if (window.ActiveXObject)
	{
		request = new ActiveXObject("Microsoft.XMLHTTP");
		if (request)
		{
			request.onreadystatechange = processRequestChange;
			request.open("GET", url, true);
			request.send();
		}
	}
}

function Abort() { request.abort();}
function processRequestChange()
{
	abortRequest = window.setTimeout("Abort();", 30000);
	// если выполнен
	if (request.readyState == 4)
	{
		clearTimeout(abortRequest);
		// если успешно
		if (request.status == 200) RequestComplete(request.responseText);
		else alert("Не удалось получить данные:\n" + request.statusText);
	}
	// иначе, если идет загрузка или в процессе - показываем слой "Загружаются данные"
	else if (request.readyState == 3 || request.readyState == 1) RequestProccess(request.readyState);
}

function RequestComplete(text)
{
	$('i2').value = "Выберите модель"
	div = $('menu2');
	div.style.display = "none";
	div.innerHTML = "";
	div.innerHTML = text;
	div.style.display = "block";
}
function RequestProccess(state)
{
	state = (state / 4) * 100;
	$('i2').value = "загрузка " + state + " %"
}
var loadPageID = 0;
var operID = 0;
function LoadPage(pid){loadPageID = pid;}
function SetOperator(oid){operID = oid;}
function LoadForPhone()
{
	part = window.location.search.split("&")
	loc = "";
	for (a in part)
	{
		if (part[a])
		{
			subpart = part[a].split("=");
			if (subpart[0] != "?m" && subpart[0] != "m" && subpart[0] != "?o" && subpart[0] != "o" )
			{
				loc += "&" + subpart[0].replace("?","")+ "=" + subpart[1];
			}
		}
	}
	window.location = window.location.protocol + "//" +
				  	  window.location.host +
				  	  "/" + "?m=" + loadPageID + '&o=' + operID + loc;
}
var searchSection = 0;
function SetSection(value) {searchSection = value;}
function SearchMel(path)
{
	window.location = path + '/?str=' + encodeURIComponent($('sminput').value);
}

function addBookmark(url, title)
{
 if (!url) url = location.href;
 if (!title) title = document.title;

 //Gecko
 if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel (title, url, "");
 //IE4+
 else if (typeof window.external == "object") window.external.AddFavorite(url, title);
 //Opera7+
 else if (window.opera && document.createElement)
 {
   var a = document.createElement('A');
   if (!a) return false; //IF Opera 6
   a.setAttribute('rel','sidebar');
   a.setAttribute('href',url);
   a.setAttribute('title',title);
   a.click();
 }
 else return false;

 return true;
}
function GoM(to)
{
	to = to.replace('aa','');
	to = to.replace('bb','');
	to = to.replace('cc','');
	window.location = to;
}
function Trans(a)
{
	mail = "mailto:spam@spamsite.spamdomen";
	mail = mail.replace("spamdomen","ru")
	mail = mail.replace("spamsite","luchshenet")
	mail = mail.replace("spam","support")
	a.href = mail;
}


function OrderLoad()
{
	id = parseInt(window.location.search.replace("?",""))
	window.location = window.location.protocol + "//" +
				  	  window.location.host +
				  	  "/order.php?" + id + "&m=" + loadPageID + '&o=' + operID;
}

function player()
{
	if (typeof(sa) == "undefined") return;
	for (a in sa) { eval("window.document.fp"+sa[a]+".SetVariable('qs', '"+sa[a]+"')");}
}
function SetParam(pName,id) { $(pName).value = id;}
var borderCangeCount = 0;
var borderCCTimeoutID;
var bourderBlinkTime = 200;
var borderMaxTime = 20;
var chooseNull = false;
function ChooseParams()
{
	vendorID = parseInt($('vendorID').value);
	modelID = parseInt($('modelID').value);
	opsosID = parseInt($('opsosID').value);
	if (!vendorID && !opsosID && !chooseNull)
	{
		borderCangeCount = 0;
		borderCCTimeoutID = setTimeout("ChangeBorder('i1','1px solid red')",bourderBlinkTime)
		return;
	}
	else if(vendorID && !modelID && !chooseNull)
	{
		borderCangeCount = 0;
		borderCCTimeoutID = setTimeout("ChangeBorder('i2','1px solid red')",bourderBlinkTime)
		return;
	}
	document.forms.model_oper.submit();
}
function ChangeBorder(elemID,value)
{
	$(elemID).style.border = value;
	if(value == "1px solid red")
	{
		$(elemID).style.backgroundColor = "#ffffff";
		$(elemID).style.color = "#000000";
		value = "1px solid #287bf5";
		$(elemID).style.border = value;
	}
	else
	{
		$(elemID).style.backgroundColor = "#000000";
		$(elemID).style.color = "#ffffff";
		value = "1px solid red";
	}
	$(elemID).style.display = 'none';
	$(elemID).style.display = 'block';
	borderCCTimeoutID = setTimeout("ChangeBorder('"+elemID+"','"+value+"')",bourderBlinkTime)
	borderCangeCount += 1;
	if (borderCangeCount > borderMaxTime)
	{
		clearTimeout(borderCCTimeoutID);
		$(elemID).style.border = "1px solid #287bf5";
	}
}
function ShowNextPrev(first,last)
{
	$('first').innerHTML = first;
	$('last').innerHTML = last;
}
function Search()
{
	if (parseInt($('searchPlace').value) == 0 && $('searchString').value.replace(/\s{0,}/,'') == "") return alert('Выберите место поиска');
	//return;
	st = $('searchString').value;
	searchPlace = parseInt($('searchPlace').value);
	window.location = "/search/?str=" + encodeURIComponent(st) + "&pid=" + searchPlace;
}

function $(e) {return document.getElementById(e);}
//-->