function browseIt()
{
	this.ver = navigator.appVersion.toLowerCase();
	this.verNum = parseInt(this.ver);
	this.agent = navigator.userAgent.toLowerCase();
	this.dom = (document.getElementById ? 1 : 0);
	this.opera = (this.agent.indexOf("opera") > -1 && this.dom ? 1 : 0);
	this.opera7 = (this.opera && this.verNum >= 7);
	this.opera9 = (this.opera && this.verNum >= 9);
	this.ie = (this.ver.indexOf("msie") > -1 && this.dom && !this.opera ? 1 : 0);
	this.ieVer = 0;
	if (this.ie) {
		var pos = this.ver.indexOf("msie");
		if (pos != -1)
			this.ieVer = parseFloat(this.ver.substr(pos + 5));
	}
	this.ie6 = (this.ie && (this.ieVer >= 6));
	this.ie6only = (this.ie && (this.ieVer >= 6) && (this.ieVer < 7));
	this.ie7 = (this.ie && (this.ieVer >= 7));
	this.macOS = (this.agent.indexOf("mac") > -1);
	this.mac = (this.macOS && this.verNum >= 7 ? 1 : 0);
	this.moz = (this.agent.indexOf("gecko") > -1);
	this.ns6 = (this.dom && this.agent.indexOf("netscape") > -1 && this.verNum >= 5 ? 1 : 0);
	this.ff = (this.agent.indexOf("firefox") > -1);
	this.b = (this.ie || this.ns6 || this.opera7 || this.mac || this.moz || this.dom);

	return this;
}

//var px = window.opera ? "" : "px";
var b = new browseIt();

function clearValue(obj,toPwd)
{
	if (obj)
	{
		obj.value = "";
		if (toPwd)
		{
			var parent = obj.parentNode;
			var objId = obj.id;

			if (parent != null)
			{
				var oldInput = parent.innerHTML;

				oldInput = oldInput.replace('type="text"','');
				oldInput = oldInput.replace('onfocus=clearValue(this,1);','onfocus=clearValue(this,0);');
				oldInput = oldInput.replace('onclick=clearValue(this,1);','onclick=clearValue(this,0);');
				oldInput = oldInput.replace('onfocus="clearValue(this,1);"','onfocus="clearValue(this,0);"');
				oldInput = oldInput.replace('onclick="clearValue(this,1);"','onclick="clearValue(this,0);"');

				oldInput = oldInput.replace('>',' type="password">');

				if (oldInput.search(/type=password/i) == -1)
				{
					parent.removeChild(obj);
					parent.innerHTML = oldInput;

					var newObj = document.getElementById(objId)
					if (newObj)
					{
						newObj.focus();
						newObj.focus();
					}
				}
			}
		}
	}
}

function checkKey(e,withCtrl,keys,urls)
{
	var code;
	if (!e) var e = window.event;

	if (withCtrl == 1)
	{
		if (e.keyCode && e.ctrlKey) code = e.keyCode;
		else if (e.which && e.ctrlKey) code = e.which;
	}
	else
	{
		if (e.keyCode) code = e.keyCode;
		else if (e.which) code = e.which;
	}

	//alert(code);
	if (keys.length>0)
	{
		for (i=0; i < keys.length; i++)
		{
			if (code == keys[i])
			{
				if (urls[i])
				{
					//alert(urls[i]);
					window.location = urls[i];
				}
			}
		}
	}
}

function checkKey2(e,id)
{
	var code;

	if (!e) var e = window.event;

	var keyPressObj = (e.srcElement)?e.srcElement:null;
	keyPressObj = (e.target)?e.target:keyPressObj;

	if (e.keyCode)
	{
		code = e.keyCode;
	}
	else if (e.which)
	{
		code = e.which;
	}

	var dontSubmit = 0;
	if (keyPressObj)
		if (keyPressObj.type == "textarea" || keyPressObj.type == "button")
			dontSubmit = 1;

	if (code == 13 && !dontSubmit)
	{
		var submitForm = document.getElementById(id);
		if (submitForm)
		{
			submitForm.submit();
		}
	}

}

function add_click (url,target) {
	if (url) {
	//alert("Debug:"+url);
	//alert("Debug:"+target);
	if (target=="_parent") {
	parent.location.href=url;
	}
	if (target=="_blank") {
	window.open(url);
	}
	if (target=="_self") {
	location.href=url;
	}
	if (target=="_top") {
	top.location.href=url;
	}
	}//end if !url
}

function rollOver(id,file)
{
	var thisObj = document.getElementById(id);
	thisObj.src = file;
}

function replaceContent2(id,url)
{
	//ShowMessage();

	//HTML_AJAX.replace(id,url);
	RequestData(url);
	//replaceContent(id,RequestData(url))
}

function getCalendar(id,p,url,globalUrl)
{
	var SendURL = globalUrl+"ajax.php?p="+p+"&"+url;
	//alert(SendURL);
	//window.scrollTo(0,0);
	StatusMessage();

	var loadingM = document.getElementById('loadingSI');
	if (loadingM)
		loadingM.style.display = "block";

	replaceContent2(id,SendURL);
}

function getCalendar2(urlHome,id,p,url,loadingSI)
{
	var SendURL = urlHome + "ajax.php?p="+p+"&"+url;
	//alert(SendURL);
	//window.scrollTo(0,0);
	StatusMessage();

	var loadingM = document.getElementById(loadingSI);
	if (loadingM)
		loadingM.style.display = "block";

	replaceContent2(id,SendURL);
}

function setupMessage()
{
	var loading = document.getElementById('HTML_AJAX_LOADING');
	if (!loading)
	{
		loading = document.createElement('div');
		loading.id = 'HTML_AJAX_LOADING';
		loading.innerHTML = '';
		loading.className = 'HTML_AJAX_Loading';
		loading.count = 0;

		document.body.insertBefore(loading,document.body.firstChild);
	}

	loading.style.display = "none";
}

function StatusMessage()
{
	setupMessage();
	return;

	//var stMessage = document.getElementById('HTML_AJAX_LOADING');
	//if (stMessage == null)
	//{
		//return;
	//}

	//var newPlace = document.getElementById(idContent);

	//if (newPlace != null)
	//{
		//var insertInParent = (newPlace.parentNode)?newPlace.parentNode:newPlace.parent;
		//insertInParent.appendChild(stMessage);
	//}

	//var parentWidth = insertInParent.offsetWidth;

	//stMessage.style.left = "auto";
	//stMessage.style.right = 40 +  "px";
	//stMessage.style.width = 100 +  "px";
	//stMessage.style.height = 20 +  "px";
	//stMessage.style.top = "149px";
	//stMessage.style.display = "block";
}

function ShowHide (id)
{
	var obj = document.getElementById(id);

	if (obj)
	{
		switch (obj.style.display)
		{
			case "none":
				obj.style.display = "block";
				break;

			case "block":
				obj.style.display = "none";
				break;
		}
	}
}

function setValueForInput(valueTxt,fieldId)
{
	var fieldObj = document.getElementById(fieldId);
	if (fieldObj)
	{
		fieldObj.value = valueTxt;
	}
}

function jspsPreloadImages(pImagesArray)
{
	var preloadArray = new Array();
	for (var i = 0; i < pImagesArray.length - 1; i++)
	{
		preloadArray[i] = new Image;
		preloadArray[i].src = pImagesArray[i];
	}
}

function popupW(url,w,h,id)
{
	w=w+20;
	h=h+25;
	window.open(url,'popupWindow'+id,'width='+w+',height='+h+',toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,screenX=150,screenY=150,top=150,left=150');
}


var prevBG = new Array;
var MenuSH = new Array;
var lastId = "";

function OverOutTD(idTd, type)
{
	var tdObj = document.getElementById(idTd);
	var widthTd = tdObj.offsetWidth;
	//var addWidthTd = (tdObj.offsetWidth*30)/100;
	if (tdObj.offsetWidth < 200) {
	   var addWidthTd = 1.5*tdObj.offsetWidth;
	} else {
	    var addWidthTd = 5;
	}
	var widthSub = widthTd + addWidthTd;

	//widthSub = (widthSub<200)?200:widthSub;

	if (tdObj)
	{
		//hideAll(idTd);

		var subObj = document.getElementById('sub_'+idTd);
		var aObj = document.getElementById('a_'+idTd);

		switch (type)
		{
			case "over":
				MenuSH[idTd]=1;
				if (prevBG[idTd]=="" || !prevBG[idTd])
					prevBG[idTd] = tdObj.className;

				//if (subObj)
					//tdObj.style.background = "url('img/bg/menu_over2.gif') no-repeat center top";
				//else
					//tdObj.style.background = "url('img/bg/menu_over1.gif') no-repeat center top";

				tdObj.style.background = "#bf2026";

				if (aObj)
				{
					aObj.className = "overMade";
				}

				if (subObj)
				{
					//subObj.style.width = widthSub + "px";
					if (lastId == idTd)
						subObj.style.marginLeft = "-"+(widthTd+17)+ "px";
						//subObj.style.cssFloat = "left";
					subObj.style.display = "block";
				}
				break;

			case "out":
				MenuSH[idTd]=0;
				setTimeout('outTD("'+idTd+'")',0);
				break;
		}
	}
}

function outTD(idTd)
{
	if (MenuSH[idTd]==0)
	{
		var tdObj = document.getElementById(idTd);
		if (prevBG[idTd])
		{
			if (tdObj.className != "level1 current") {
				tdObj.style.background = "";
			}
			tdObj.className = prevBG[idTd];
			prevBG[idTd] = "";
		}

		var subObj = document.getElementById('sub_'+idTd);
		if (subObj)
		{
			subObj.style.display = "none";
		}

		var aObj = document.getElementById('a_'+idTd);
		if (aObj && tdObj.className != "level1 current")
		{
			aObj.className = "outMade";
		}
	}
}

function hideAll(currentTd)
{
	for (i=0; i < MainDivs.length; i++)
	{
		if (MainDivs[i])
		{
			if (MainDivs[i]!=currentTd)
			{
				var obj = document.getElementById(MainDivs[i]);
				if (obj)
				{
					if (prevBG[MainDivs[i]] && prevBG[MainDivs[i]]!="")
					{
						obj.style.background = prevBG[MainDivs[i]];
						prevBG[MainDivs[i]] = "";
					}
				}

				var subObj = document.getElementById('sub_'+MainDivs[i]);
				if (subObj)
				{
					subObj.style.display = "none";
				}

				var aObj = document.getElementById('a_'+MainDivs[i]);
				if (aObj)
				{
					aObj.className = "outMade";
				}
			}

			lastId = MainDivs[i];
		}
	}
}

var itemInBasket = new Array;

function addToBasket(id,SendURL,action)
{
	if (itemInBasket[id])
	{
		if (action == "add") {
			SendURL = SendURL.replace(/a=add/gi, "a=del");
		}
	} else {
		if (action == "del") {
			SendURL = SendURL.replace(/a=del/gi, "a=add");
		}
	}
	//var inpObj = document.getElementById('total_'+id);
	//if (inpObj)
	SendURL = SendURL + '&id_item_public=' + id;

	colorValue = document.getElementById('colorValue');
	if (colorValue) {
		colorValue = colorValue.value.replace('#','');
		SendURL = SendURL + '&colorValue=' + colorValue;
	}

	arrayCiId = id.split('_');
	if (arrayCiId[3]) {
	    totalId = 'total['+arrayCiId[1]+']['+arrayCiId[2]+'_'+arrayCiId[3]+']';
	} else {
	   totalId = 'total['+arrayCiId[1]+']['+arrayCiId[2]+']';
	}
	totalObj = document.getElementById(totalId);
	if (totalObj) {
	    if (arrayCiId[3]) {
		  SendURL = SendURL + '&total['+arrayCiId[1]+']['+arrayCiId[2]+'_'+arrayCiId[3]+']=' + totalObj.value;
	    } else {
	        SendURL = SendURL + '&total['+arrayCiId[1]+']['+arrayCiId[2]+']=' + totalObj.value;
	    }
	}
	//StatusMessage();

	//statusObj = document.getElementById('status_'+idItem);

	//statusObj.style.display = "block";
	//HTML_AJAX.onError = function(e)
	//{
		//if (confirm("Some errors on server\r\n Repeat request?'"))
			//HTML_AJAX.grab(SendURL, callback);
	//}
	replaceContent2('',SendURL);
	//HTML_AJAX.grab(SendURL, callback);
}

function setResultToBasket(id,result) {
		//setBg(id,1,urlHome);
		if (itemInBasket[id])
		{
			//changeIcon(idItem,2,urlHome);
			itemInBasket[id] = 0;
		}
		else
		{
			//changeIcon(idItem,1,urlHome);
			itemInBasket[id] = 1;
		}

		//var priceBasketSection = document.getElementById('priceBasketSection');
		//if (priceBasketSection)
			//if (priceBasketSection.style.display=="none")
				//priceBasketSection.style.display = "block";

		var priceField = document.getElementById('basketInfo');
		if (priceField) {
			priceField.innerHTML = result;
		}

		var priceField2 = document.getElementById('basketInfo2');
		if (priceField2) {
			priceField2.innerHTML = result;
		}

		loadingFORM(2);
}

function goToSelectUrl(selectObj)
{
	var index = selectObj.selectedIndex;

	if (selectObj[index].value)
		window.document.location = selectObj[index].value;
}

function setColor(idImg,color) {

	colorImg = document.getElementById('color');
	colorValue = document.getElementById('colorValue');

	if (colorImg && colorValue) {
		setColorImg = document.getElementById('color_' + idImg);
		//divColorImg = document.getElementById('div_' + idImg);

		if (setColorImg) {
			colorImg.src = setColorImg.src;
			//divColorImg.className = "colorCurrent";
			colorValue.value = color;
		}
	}

}
