//z lewego menu
var ie = (document.getElementById);
function rollMSMenu(item) {
	if (document.getElementById("ms_menu_" + item)) {
	   if (document.getElementById("ms_menu_" + item).style.display == "none") {
			 document.getElementById("ms_menu_" + item).style.display = "inline";
			 //document.getElementById("ms_text_" + item).src = "<?= MS_ROOT ?>" + "webpic/open.gif";
			 document.getElementById("text_" + item).className = "open";
	   } else {
			 document.getElementById("ms_menu_" + item).style.display = "none";
			 //document.getElementById("ms_text_" + item).src = "<?= MS_ROOT ?>" + "webpic/closed.gif";
			 document.getElementById("text_" + item).className = "closed";
	   }

	}
}

var ie = (document.getElementById);
function rollMenu(item) {
	if (document.getElementById("menu_" + item)) {
	   if (document.getElementById("menu_" + item).style.display == "none") {
			 document.getElementById("menu_" + item).style.display = "";
			 //document.getElementById("text_" + item).src = "<?= $path_to_menu ?>webpic/open.gif";
			 document.getElementById("text_" + item).className = "open";
	   } else {
			 document.getElementById("menu_" + item).style.display = "none";
			 //document.getElementById("text_" + item).src = "<?= $path_to_menu ?>webpic/closed.gif";
			 document.getElementById("text_" + item).className = "closed";
	   }

	}
}


function gsm_zoompic(pic, width, height, lang, nextPic) {
	var win = window.open("/showpic.php?file=" + pic + '&lang=' + lang, 'zoompic', 'resizable,width=' + (width+5) + ',height=' + (height+5));
   win.focus();
}

function open_popup(id, lang) {
   win = window.open('popup.php?id=' + id + '&lang=' + lang, 'popup', 'scrollbars,resizable,width=320,height=320,');
   win.focus();
}

function open_new_win(link, title, params) {
   win = window.open(link, title, params);
   win.focus();
}

function openWin(url, width, height, scrollbars) {
	scrollbars = scrollbars ? 1 : 0;
   var win = window.open(url, 'win'+width+height, 'scrollbars=' + scrollbars + ',resizable=1,width=' +width+ ',height=' + height);
   win.focus();
}


function invoice_alert() {
	alert("This product may not support all couriers and/or payment methods. The details will be displayed on 'check out' screen.");
}

function askForProduct(lang, id, name) {
	var win = window.open('/' + lang + '/askforproduct?id=' + id + '&name=' + name, 'ask', 'resizable=1,scrollbars=1,width=500,height=430,')
	win.focus()
}

function objById(elemID) {
	var obj;
	if (document.getElementById) {
		obj = document.getElementById(elemID);
	}
	return obj;
}
function hide(obj) {
	obj.style.display = 'none';
}
function show(obj) {
	obj.style.display = 'inline';
}
function toggleHideShow(obj) {
	if(obj != undefined) {
		if(obj.style.display != 'none') {
			hide(obj);
		} else {
			show(obj);
		}
	}
}

ystart=0;
function moveY(obj, timeout) {
	if(obj) {
		if(timeout == undefined) {
			timeout = 50;
		}
	
	
		if (navigator.appName == "Netscape") {
			y=window.pageYOffset;
			doHeight=window.innerHeight;
		} else {
			y=document.body.scrollTop;
			doHeight=document.body.clientHeight;
		}
		
		startY = obj.offsetTop;
	
		ydiff=y-ystart;
		if ((ydiff<(-1))||(ydiff>(1))) {
			movey=Math.round(ydiff/10);
		
		} else {
			movey=0;
		}
		ystart+=movey;
		obj.style.top = startY + movey + "px";

		setTimeout("moveY(objById('"+obj.id+"'),"+timeout+")", timeout);
	}
}


function SwitchTags(tagName) {
	for (var i=0; i<document.getElementsByTagName(tagName).length; i++) {
		if (document.getElementsByTagName(tagName)[i].style.display != 'none')
			document.getElementsByTagName(tagName)[i].style.display = 'none'
		else
			document.getElementsByTagName(tagName)[i].style.display = 'inline'
	}
}

function focusLogin() {
	var href = document.location.href;
	var hashPos = href.indexOf('#');
	if (hashPos >= 0) {
		href = href.substr(0, hashPos);
	}
	document.location.href = href + '#login_form';
	document.getElementById('login_form').auth_login.focus();
}

function submitSubscriptionForm(form) {
	form.check_back.value = form.check.value + form.check.value;
	return true;
}


/* Reklama popup */
window.onload = displayPopupAd;

function displayPopupAd() {
	setTimeout('displayPopupAd2()', 1000);
}

function displayPopupAd2() {
	popupAd = document.getElementById('popup-ad');
	if (!popupAd) return;
	
	setOpacity(popupAd, 1);
	positionPopupAd();
	window.onresize = positionPopupAd;
	
	popupAdOpacity = 1;
	fadeInPopupAdINT = setInterval('fadeInPopupAd()', 50);
}

function fadeInPopupAd() {
	popupAdOpacity += 5;
	
	if (popupAdOpacity > 100) {
		popupAdOpacity = 100;
		clearInterval(fadeInPopupAdINT);
		
		setTimeout("document.getElementById('popup-close').style.display = 'block';", 500);
	}
	
	setOpacity(popupAd, popupAdOpacity);
}

function closePopupAd() {
	popupAd.style.display = "none";
}

function positionPopupAd() {
	var width = 210;
	var height = 240;
	
	var winWidth = window.innerWidth ? window.innerWidth : document.body.clientWidth;
	
	var winHeight = window.innerHeight ? window.innerHeight : (document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight);
	
	//alert(winHeight)
	
	var x = Math.round(winWidth / 2 - width / 2);
	var y = Math.round(winHeight / 2 - height / 2);
	if (x < 0) x = 0;
	if (y < 0) y = 0;
	
	//alert(x + ', ' + y);
	
	popupAd.style.left = x + 'px';
	popupAd.style.top = y + 'px';
}

function setOpacity(elem, percent) {
	elem.style.opacity = percent / 100;
	elem.style.filter = "progid:DXImageTransform.Microsoft.Alpha(opacity=" + percent + ")";
	//elem.style.filter = "alpha(opacity=" + percent + ")";
}