var windowW;
var windowH;

function popgood(id, gp_id) {
	var url = 'good.php?good_id=' + id + '&amp;gp_id=' + gp_id;
	var name = 'good_popup';
	var w = 600;
	var h = 600;

	if (document.all) {
		windowW = document.body.offsetWidth;
		windowH = document.body.offsetHeight;
	} else {
		windowW = window.innerWidth;
		windowH = window.innerHeight;
	}

	var x, y;
	x = Math.round((windowW-w)/2);
	y = Math.round((windowH-h)/2);
	var win = window.open(url, name, 'resizable=1,channelmode=0,directories=0,fullscreen=0,height='+h+',left='+x+',location=0,menubar=0,scrollbars=1,statusbar=1,titlebar=1,top='+y+',width='+w+'');
	win.focus();

	return false;
}

function popImage(id, w, h) {
	var url = 'image.php?id=' + id;
	var top = (screen.height - h) / 2;
	var left = (screen.width - w) / 2;

	var options = 	'left=' + left +
			',top=' + top +
			',width=' + w +
			',height=' + h +
			',resizable=yes';

	var win = window.open(url, id, options);
	win.focus();

	return false;
}

// some function to operate with cookies

// ExpireTime in hours
function setCookie(cookieName, cookieContent, cookieExpireTime){
    if(cookieExpireTime>0){
	var expDate=new Date()                           // ms.sec.minutes
	expDate.setTime(expDate.getTime()+cookieExpireTime*1000*60*60)
	document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"; expires="+expDate.toGMTString()
    }else{
	document.cookie=cookieName+"="+escape(cookieContent)+"; path="+escape('/')+"";
    }
}

function getCookie(cookieName){
    var ourCookie=document.cookie.split(";")
    if(ourCookie==0)return 0
    if(ourCookie=="")return 0
    var i=0
    var Cookie
    while(i<ourCookie.length){
	Cookie=ourCookie[i].split("=")[0]
	if(Cookie.charAt(0)==" ")
		Cookie=Cookie.substring(1)
	if(Cookie==cookieName){
	    return unescape(ourCookie[i].split("=")[1])
	}
	i++
    }
    return 0
}


function deleteCookie(name, path, domain)
{
	if (getCookie(name))
	{
		document.cookie = name + "=" +
			((path) ? "; path=" + path : "") +
			((domain) ? "; domain=" + domain : "") +
			"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function addtocart(id, page)
{
	var cart = getCookie("cart"); // get cookie
	cart = cart + "/" + id + "." + page;  // add selected good
	setCookie("cart", cart, 24*7); // expire in 7 days
	// redirect to shopcart
	if(name == "good_popup") {
		opener.location.href = "cart.php";
		close();
	} else {
		location.href = "cart.php";
	}
}

function toggleCartpw()
{
	if(document.all['cartpw']) {
		if(document.all['cartpw'].style.display == 'none') {
			document.all['cartpw'].style.display = '';
			document.all['cartperson'].style.display = 'none';
			document.all['cartphone'].style.display = 'none';
			document.all['cartcard'].style.display = 'none';
			document.all['cartadr'].style.display = 'none';
		} else {
			document.all['cartpw'].style.display = 'none';
			document.all['cartperson'].style.display = '';
			document.all['cartphone'].style.display = '';
			document.all['cartcard'].style.display = '';
			document.all['cartadr'].style.display = '';
		}
	}
}

function doOnload()
{
	if(document.all['cartpw']) {
		document.all['cartpw'].style.display = 'none';
	}
}
