var br=navigator.userAgent.toLowerCase();
var browserIsIE = br.indexOf('msie')>=0?true:false;
//alert(browserIsIE)
function prl(imgs)
{
	//alert(imgs.length);
	for (i=0 ; i<imgs.length ; i++)
	{
		this["image"+i] = new Image();
		this["image"+i].src = imgs[i];
		
	}
}

function openWin(tid, mid, action, id, w, h, scrollbars, resizable)
{

	if(window.screen)
	{
		aw=screen.availWidth;
		ah=screen.availHeight;
	}
	else
	{
		aw=710;
		ah=450;
	}
	if (h > 710)
		h = 710;
	
	if (aw<w)
		w = aw - 40;
	if ((ah-80)<h)
		h = ah - 80;
		
ustawienia=
 "left=" + (aw-w)/2 + ","
 +"top=" + (ah-h)/2 + ","
 +"screenX=" + (aw-w)/2 + ","
 +"screenY=" + (ah-h)/2 + ","
 +"width=" + (w+2) + ","
 +"height=" + (h+2) + ","
 +"innerWidth=" + w + ","
 +"innerHeight=" + h + ","
 +"toolbar=no,"
 +"location=no,"
 +"directories=no,"
 +"status=no,"
 +"menubar=no,"
 

if (scrollbars==1) ustawienia += "scrollbars=yes,"
else ustawienia += "scrollbars=no,"

if (resizable==1) ustawienia+="resizable=yes"
else ustawienia+="resizable=no"


if (!id || id == "")
	id=0;
url = 'popup.php?tid=' + tid + '&mid=' + mid + '&action=' + action + '&id=' + id;
	
	window.open(url,'popup',ustawienia);
}
//--------------------------------------------------------------------------------
function setNLVal(inp, n)
{
	if (n==0) {
		if (inp.value == "tu wpisz swój adres email")
			inp.value = "";
	} else if (inp.value == "")
			inp.value = "tu wpisz swój adres email";
}
//----------------------------------------------------------------------------------
function subscribe(email)
{
	var emailPattern = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/; 
	if (!emailPattern.test(email)) {
		alert('Proszę wprowadzić prawidłowy adres email');
		return;
	} else {
		xajax_subscribe(email);
	}
}
//----------------------------------------------------------------------------------
imgWin = null;
function openImage(file, w, h, name)
{
if(window.screen){
 aw=screen.availWidth;
 ah=screen.availHeight;
}else{
 aw=640;
 ah=450;
}

	//if (h > 710)
	//	h = 710;
	
	scrollbars=0;
	resizable=0;
	
	if ((aw-40)<w)
	{
		w = aw - 40;
		scrollbars=1;
	}
	if ((ah-80)<h)
	{
		scrollbars=1;
		h = ah - 80;
	}


if(imgWin==null || imgWin.closed){
 ustawienia=
 "left=" + (aw-w)/2 + ","
 +"top=" + (ah-h)/2 + ","
 +"screenX=" + (aw-w)/2 + ","
 +"screenY=" + (ah-h)/2 + ","
 +"width=" + (w+2) + ","
 +"height=" + (h+2) + ","
 +"innerWidth=" + w + ","
 +"innerHeight=" + h + ","
 +"toolbar=no,"
 +"location=no,"
 +"directories=no,"
 +"status=no,"
 +"menubar=no,";
 
if (scrollbars==1) ustawienia += "scrollbars=yes,"
else ustawienia += "scrollbars=no,";

if (resizable==1) ustawienia+="resizable=yes"
else ustawienia+="resizable=no";

 imgWin = window.open("",'obrazek',ustawienia);
}
imgWin.document.open();
imgWin.document.clear();
imgWin.document.write(
"<html><head><title>" + name + "</title>\n"
+"<link rel='stylesheet' type='text/css' href='user/css/sheet.css'>"
+"</head><BODY leftmargin=0 topmargin=0 marginwidth=0 marginheight=0>\n"
+"<table width='100%' height='100%' border='0' cellspacing='0' cellpadding='0' align='center'><tr><td align='center'>"
+"<a href='javascript:window.close()'><img src='"+ file +"' border=0 alt='Kliknij na obrazek by zamknąa okno'></a>"
+"</td></tr></table>\n"
+"</body></html>"
);
imgWin.document.close();
imgWin.focus();
}

//--------------------------------------------------------------------------------


function openPage(doc, id, w, h, scrollbars, resizable)
{

	if(window.screen)
	{
		aw=screen.availWidth;
		ah=screen.availHeight;
	}
	else
	{
		aw=710;
		ah=450;
	}
	if (h > 710)
		h = 710;
		
ustawienia=
 "left=" + (aw-w)/2 + ","
 +"top=" + (ah-h)/2 + ","
 +"screenX=" + (aw-w)/2 + ","
 +"screenY=" + (ah-h)/2 + ","
 +"width=" + (w+2) + ","
 +"height=" + (h+2) + ","
 +"innerWidth=" + w + ","
 +"innerHeight=" + h + ","
 +"toolbar=no,"
 +"location=no,"
 +"directories=no,"
 +"status=no,"
 +"menubar=no,"
 
if (scrollbars==1)
{
	ustawienia += "scrollbars=yes,"
}
else
	ustawienia += "scrollbars=no,"
 
if (resizable==1)
	ustawienia += "resizable=yes"
else
	ustawienia += "resizable=no"

	url = doc
	if (id && id!=0)
	url += '?id=' + id;
	
	window.open(url,'popup',ustawienia);
}

//--------------------------------------------------------------------------------
var marked_row = new Array;

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
	
    var theCells = null;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function

//function no_error()
//{ return true; }
//window.onerror=no_error();


function setCookie(NameOfCookie, value, expiredays) 
{
	var ExpireDate = new Date ();
	ExpireDate.setTime(ExpireDate.getTime() + (expiredays * 24 * 3600 * 1000));
	document.cookie = NameOfCookie + '=' + escape(value) + ((expiredays == null) ? '' : '; expires=' + ExpireDate.toGMTString());
}

function getCookie(NameOfCookie)
{
	if (document.cookie.length > 0) 
	{ 
		begin = document.cookie.indexOf(NameOfCookie+'='); 
		if (begin != -1)
		{ 
			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(';', begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end));
		} 
	}
	return null; 
}

function delCookie(NameOfCookie) 
{
	if (getCookie(NameOfCookie))
	{
		document.cookie = NameOfCookie + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}
