// $Id: misc.js,v 1.4 2006/07/26 13:03:10 tkepski Exp $

function PopupWindow(url,width,height,name){
    if (name==null){
      name = new String(Math.round(Math.random()*10000000));
    }

    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2 - 18;

    var win = window.open(url,name,"toolbar=no,location=no,directories=no,"+
      "status=no,menubar=no,scrollbars=no,resizable=no,"+
      "copyhistory=no, width="+width+",height="+height+",left="+left+",top="+top);
}

function PopupOffer(url,width,height,name){
    if (name==null){
      name = new String(Math.round(Math.random()*10000000));
    }

    var left = (screen.width - width)/2;
    var top = (screen.height - height)/2 - 18;

    var win = window.open(url,name,"toolbar=no,location=no,directories=no,"+
      "status=yes,menubar=no,scrollbars=yes,"+
      "copyhistory=no,width="+width+",height="+height+",left="+left+",top="+top);
}


function PopupImage(url,width,height,title,name)
{
    if (name==null){
      name = new String(Math.round(Math.random()*10000000));
    }
    var windowheight = height+40;
    var windowwidth = width+20;

    var left = (screen.width - windowwidth)/2;
    var top = (screen.height - windowheight)/2 - 18;
    
    var scrollbars = "no";
    
    if (left<0) { scrollbars = "yes"; left = 32; windowwidth = screen.width - 2*left; }
    if (top<0) { scrollbars = "yes"; top = 32; windowheight =  screen.height - 2*top - 18; top = top - 18; }

    var win = window.open("",name,"toolbar=no,location=no,directories=no,"+
        "status=no,menubar=no,scrollbars=" + scrollbars + ",resizable=no,"+
        "copyhistory=no, width="+windowwidth+",height="+windowheight+",left=" + left + ",top=" + top);
    win.document.write("\<HEAD\>\<link rel=\"stylesheet\" type=\"text\/css\" href=\"\/style.css\"\/\>\<meta http-equiv=\"pragma\" content=\"no-cache\"\>\<TITLE\>"+title+"\<\/TITLE\>");
    win.document.write("\<link rel=\"STYLESHEET\" type=\"text/css\" href=\"css/style.css\"\>");
    win.document.write("\<\/HEAD\>");
    win.document.write("\<BODY topmargin=0 leftmargin=0\>\<center\>\<img src=\""+url+"\" width=\""+width+"\" height=\""+height+"\" border=0 vspace=\"10\" hspace=\"10\"\>\<BR\>\<a href=\"javascript:window.close();\" class=\"popup\"\>Close\<\/a\>\<\/center\>\<\/BODY\><\/HTML\>");
}

function jmShowHelp(url)
{
    var width  = 750;
    var height = 580;
    var left   = (screen.width - width)/2;
    var top    = (screen.height - height)/2

    var win = window.open(url,null,"toolbar=no,location=no,directories=no,"+
      "status=no,menubar=no,scrollbars=yes,resizable=yes,"+
      "copyhistory=no, width="+width+",height="+height+",left=" + left + ",top=" + top);
   
    return false;
}

function confrm(points){
	return confirm("Ta akcja spowoduje pobranie " + points + " punktów kredytowych z Twojego konta.\nCzy chesz kontynuować?");
}

function countDown(objName, counter){
	if (counter <  0) return;
	if (counter == 0) {
		document.getElementById(objName).innerHTML = "KONIEC";
		return;
	}
	var h = Math.floor(counter/3600);
	var m = Math.floor((counter-h*3600)/60);
	var s = counter - h * 3600 - m * 60;
		
	document.getElementById(objName).innerHTML = normalize(h) + ":" + normalize(m) + ":" + normalize(s);
	var f;
	eval("f = function() { countDown('" + objName + "'," + (counter-1) + " ); }");
	setTimeout(f , 1000);
}

function normalize(s){
	if (s < 10) return "0" + s;
	return s;
}
