/****************************************/
/*			Common Functions			*/
/****************************************/

nn4 = (document.layers) ? true : false;
ie4 = (document.all) ? true : false;
dom = (document.createTextNode)? true : false;

function popup(fileUrl, winW, winH, winN, scrollbars)
{
	var scrollbars = scrollbars? scrollbars : 'yes';
	var winWidth = (winW)? winW : 540;
	var winHeight = (winH)? winH : 750;
	var winName = (winN)? winN : 'popupWin';
	if (nn4 || ie4 || dom) {
		if (screen.width < winWidth + 50) { winWidth = screen.width - 50; scrollbars = 'yes' }
		if (screen.height < winHeight + 100) { winHeight = screen.height - 100; scrollbars = 'yes' }
		posX = Math.round((screen.width - winWidth) / 2);
		posY = Math.round((screen.height - winHeight) / 2);
		posCode = (nn4 || dom)? "screenX="+posX+",screenY="+posY : "left="+posX+",top="+posY;
	} else {
		posCode = "";
	}
	var popupWin = window.open(fileUrl, winName,"menubar=no,toolbar=no,resizable=yes,scrollbars=" + scrollbars + ",status=yes,width=" + winWidth + ",height=" + winHeight + "," + posCode);
	if (popupWin) popupWin.focus();
}

var ua = navigator.userAgent.toLowerCase(); 
var browser = new Object();
	browser.isOpera = (ua.indexOf('opera') != -1);
	browser.isIE = (ua.indexOf('msie') != -1 && !browser.isOpera);
	browser.isMozilla = (ua.indexOf('mozilla') != -1 && !browser.isIE && !browser.isOpera);

function catExpand(name, level, img)
{
	var object = document.getElementById(name);
	if (object.style.display == "none")
	{
		object.style.display = "block";
		img.src = "/ii/c" + level + "_minus" + (img.parentNode.className == "current" && level == 1 ? "-a" : "" ) + ".gif";
		img.alt = "Свернуть раздел";
		img.title = "Свернуть раздел";
	}
	else
	{
		object.style.display = "none";
		img.src = "/ii/c" + level + "_plus" + (img.parentNode.className == "current" && level == 1 ? "-a" : "" ) + ".gif";
		img.alt = "Развернуть раздел";
		img.title = "Развернуть раздел";
	}
}
function dynLinkExpand (name)
{
	var object = document.getElementById(name);
	var img = document.getElementById(name + "i");
	if (object.style.display == "none")
	{
		object.style.display = "block";
		img.src = "/ii/c1_minus.gif";
	}
	else
	{
		object.style.display = "none";
		img.src = "/ii/c1_plus.gif";
	}
}
function radioCheck(name)
{
	if (name) document.getElementById(name).checked = true;
}

/****************************************/
/*			Phone PopUp Class			*/
/****************************************/
var globalTimeout;
var globalObj = 0;

function phonePopup(imageId, prefix)
{
	this.imageId = imageId;
	this.prefix = prefix;
	this.items = new Array();
	this.color = "#666666";
	//this.itemWidth = (browser.isMozilla ? 140 : 179);
	this.itemWidth = 179;

	this.image = document.getElementById(this.imageId);
	this.currItem;

	// make self object
	this.self = "layer_" + this.imageId;
	eval(this.self + '=this');

	// constructor methods list
	this.setEvents = phonePopup_setEvents;
	this.showImage = phonePopup_showImage;
	this.showPopup = phonePopup_showPopup;
	this.hidePopup = phonePopup_hidePopup;
}
function pipe_timeout () {
	if (globalObj)
	{
		clearTimeout(globalTimeout);
		globalObj.style.visibility = "hidden";
		globalObj = 0;		
	}	
}
function phonePopup_setEvents()
{
	for (var i in this.items)
	{
		var item = document.getElementById(this.prefix + "c" + this.items[i]).childNodes.item(0);
			item.onmouseover = new Function(this.self + ".showImage('" + this.items[i] + "', this)");
			item.onmouseout = new Function(this.self + ".hidePopup('" + this.items[i] + "', this)");
			document.getElementById(this.prefix + this.items[i]).style.width = this.itemWidth + "px";
	}
}
function phonePopup_showImage(modelNum, srcObject)
{
	this.currItem = modelNum;
	this.image.src = "/ii/phones/small/" + modelNum + ".jpg";
	this.image.alt = "Nokia " + modelNum;
	this.image.parentNode.href = srcObject.href;
	if (checkElement(this.prefix + modelNum) && browser.isIE) this.showPopup(modelNum);
}
function phonePopup_showPopup(modelNum)
{
	if (globalObj) pipe_timeout();
	try
	{
		var PopupLayer = document.getElementById(this.prefix + modelNum);
			PopupLayer.style.visibility = "visible";		
	}
	catch (x)
	{
		return false;
	}
}
function phonePopup_hidePopup(modelNum, srcObject)
{
	if (checkElement(this.prefix + modelNum))
	{
		var PopupLayer = document.getElementById(this.prefix + modelNum);
		globalObj = PopupLayer;
		globalTimeout = setTimeout("pipe_timeout()",500);
	}
}
function checkElement(elemName)
{
	return (document.getElementById(elemName) ? true : false);
}
