var winW; //szeroko¶ć okna
var winH; //wysoko¶ć okna
var scrOfX; //przesunięcie w x
var scrOfY; //przesunięcie w y
//catch mouse event
var cursor;

if (document.addEventListener){
	document.addEventListener('click',function(e){getPosition(e);},true);
	document.addEventListener('mousedown',function(e){getPosition(e);},true);
}else
	document.onclick=getPosition;
	document.onmousedown=getPosition;


function goTo(sURL){
	window.location.href = sURL;
}

String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
/* wyłączenie submitowania po naciśnięciu enter */
function disableEnterKey(e){
	var key;      
	if(window.event)
		key = window.event.keyCode; //IE
	else
		key = e.which; //firefox      

	return (key != 13);
}

function checkCookie(){
	var time=new Date();
	time.setTime(time.getTime()+(60*1000));
	setcookie("testCookie","bla bla",time);
	contents=getcookie("testCookie");
	if(contents=="bla bla"){
		return true;
	}else{
		return false;
	}
}
function setcookie(name,val,exp){
	document.cookie=name+"="+escape(val)+"; expires="+exp.toGMTString()+"; path=/";
}

function getcookie(val){
	var rgx=new RegExp(val+"=([^;]+)");
	var cookie=rgx.exec(document.cookie);
	return(cookie!=null)?unescape(cookie[1]):null;
}


if(typeof(window.external) != 'undefined' && document.attachEvent) {
     document.getElementsByName = function(name, tag) {
           if(!tag) tag = '*';
           var elems=document.getElementsByTagName(tag),x=elems.length,i,res=[];
           for(i=0;i<x;i++){
                 att = elems[i].getAttribute('name');
                 if(att == name) res.push(elems[i]);
           }
           return res;
     }
}

function getPosition(e) {
    e = e || window.event;
    cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
}


function showLoader(){
	getWindowSizes();
	if($("i_loader")!=null){
		$("i_loader").style.display='block';
		$("i_loader").style.position='absolute';
		$("i_loader").style.top=scrOfY+'px';
		$("i_loader").style.left=0+'px';
		$("i_loader").style.background = 'transparent';
		$("i_loader").width=winW+'px';
		$("i_loader").height=winH+'px';
		$("i_loader").style.zIndex=0;
		$("i_loader").style.visibility='visible';
		$("i_loader").innerHTML = '<center><table style="width: '+winW+'px; height: '+winH+'px; min-height: '+winH+'px;" border="0"><tr><td valign="middle" align="center"><table width="300" border="0" bgcolor="#E8E8E8" style="vertical-align: middle;" cellpadding="3" cellspacing="2"><tr><td height="25" valign="top" align="right" style="border: 1px solid black;"><a href="javascript:void(0);" onClick="goTo(\'/index.php\')">'+langComm['abort']+'</a></td></tr><tr><td valign="middle" align="center" height="100" style="border: 1px solid black;"><img src="i/loading.gif" width="32" height="32" alt="" align="middle"/><br />'+langComm['loading']+'</td></tr></table></td></tr></table></center>';
	}
}

function hideLoader(){
	if($("i_loader")!=null){
		$("i_loader").style.visibility='hidden';
		$("i_loader").style.display='none';
		$("i_loader").innerHTML = '';
	}
}


function showData(id, type, map){
	var showmsg = '';
	switch(map){
		case 'gp':
			switch(type){
				case 'fv':
					showmsg = invDataArr[id];
					break;
				case 'send':
					showmsg = sendDataArr[id];
					break;
			}
			break;
		case 'topo':
			switch(type){
				case 'fv':
					showmsg = tinvDataArr[id];
					break;
				case 'send':
					showmsg = tsendDataArr[id];
					break;
			}
			break;
	}
	//getWindowSizes();

	$("i_loader").style.display='block';
	$("i_loader").style.position='absolute';
	$("i_loader").style.top=cursor.y;
	$("i_loader").style.left=cursor.x;
	$("i_loader").style.background = 'transparent';
	$("i_loader").style.width=350;
	$("i_loader").style.height=400;
	$("i_loader").style.zIndex=0;
	$("i_loader").innerHTML = '<center><table width="300" border="0" cellpadding="3" cellspacing="2"><tr><td height="25" valign="top" align="right" style="border: 1px solid black;" bgcolor="#FFFFFF"><a href="javascript:void(0);" onClick="hideLoader();">'+langComm['close']+'</a></td></tr><tr><td valign="middle" align="left" height="100" style="border: 1px solid black; padding-left: 5px;" bgcolor="#FFFFFF">'+showmsg+'</td></tr></table></center>';
}


function clearErrors(){
	$('errors').innerHTML = '';
	$("errors").style.display = 'none';
}

function showErrors(txt){
	$('errors').innerHTML = txt;
	$("errors").style.display = 'block';
}

function getWindowSizes(){
	winW = 0, winH = 0;
	scrOfX = 0, scrOfY = 0;
	if( typeof( window.pageYOffset ) == 'number' && window.pageYOffset>0 ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}


	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winW = window.innerWidth-16;
		winH = window.innerHeight-16;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winW = document.documentElement.clientWidth-20;
		winH = document.documentElement.clientHeight-20;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winW = document.body.clientWidth-20;
		winH = document.body.clientHeight-20;
	}
}

function defined( constant_name )  {
    return (typeof window[constant_name] !== 'undefined');
}

function showHide(text, dispProp){
	if($(text).style.display!=dispProp ){
		$(text).style.display=dispProp;
	}else{
		$(text).style.display='none';
	}
}
