
//browser detection
NS = (document.layers) ? 1 : 0;
IE = (document.all) ? 1 : 0;

function setCookie(sname,svalue,expiredays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=sname+ "=" +escape(svalue)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}

function getCookie(sname) {
	if (document.cookie.length>0)
	  {
	  var c_start=document.cookie.indexOf(sname + "=");
	  if (c_start!=-1)
	    {
	    c_start=c_start + sname.length+1;
	    var c_end=document.cookie.indexOf(";",c_start);
	    if (c_end==-1) c_end=document.cookie.length;
	    return unescape(document.cookie.substring(c_start,c_end));
	    }
	  }
	return "";
}

      /* ta funkcja to obejscie na BUGa w javascripcie(!), ktory nie radzi sobie z literka o, l i % */
      function ajax_escape(wej) {
			s = new String(wej);
			s= s.replace("%","%u0025");
			s= s.replace(/Ó/g,"%u00D3");
			s= s.replace(/ó/g,"%u00F3");
			s= s.replace(/Ł/g,"%u0141");
			s= s.replace(/ł/g,"%u0142");
			s= s.replace(/Ń/g,"%u0143");
			s= s.replace(/ń/g,"%u0144");
			s= s.replace(/Ć/g,"%u0106");
			s= s.replace(/ć/g,"%u0107");
			out = escape(s);
			return out;
		}


//data
		function jsdate2dbdateWithHours(odate) {
			var sout = odate.getFullYear() + '-';
			if(odate.getMonth().toString().length==1) sout += '0' + odate.getMonth();
			else sout += odate.getMonth();
			sout += '-';
			if(odate.getDate().toString().length==1) sout += '0' + odate.getDate();
			else sout += odate.getDate();
			sout += ' ';
			if(odate.getHours().toString().length==1) sout += '0' + odate.getHours();
			else sout += odate.getHours();
			sout += ':';
			if(odate.getMinutes().toString().length==1) sout += '0' + odate.getMinutes();
			else sout += odate.getMinutes();
			return sout;
		}

		function jsdate2dbdate(odate) {
			var sout = odate.getFullYear() + '-';
			var month = odate.getMonth()+1;
			if(month.toString().length==1) sout += '0' + month;
			else sout += month;
			sout += '-';
			if(odate.getDate().toString().length==1) sout += '0' + odate.getDate().toString();
			else sout += odate.getDate().toString();
			return sout;
		}

//getting objects

function getObject(objectName)
{
	if(objectName==null) return null;
  	var objItem;

  	if (document.all)
    	objItem = document.all[objectName];
  	else
  	{
    	objItem = document.getElementById(objectName);
    	if (objItem==null)
      	objItem= document.getElementsByName(objectName)[0];
    	if (document.getElementsByName(objectName).length>1)
      	objItem=document.getElementsByName(objectName);
  	}

  	if (document.layers) if (document.layers[name])	objItem = document.layers[name];

  	return objItem;
}


//faster for limited scope
function getChildObject(objectName,parentobject,ndigmore)
{
	if(parentobject.id == objectName) return parentobject;
	if(ndigmore==undefined) ndigmore=99;
	if(ndigmore==0) return null;
	var obj,objfrombelow;
	//alert('parentobject  ='+parentobject +' id='+parentobject.id +' nchildren='+parentobject.childNodes.length);
	//if(isFunction(parentobject.hasChildNodes))
   //if(parentobject.hasChildNodes())
   if(parentobject.childNodes.length >= 1)
	//for(obj in parentobject.childNodes)
	for(var i=0;i<parentobject.childNodes.length;i++)
	//if(isObject(obj))
	{
		obj = parentobject.childNodes[i];
		//alert('parentobject id='+parentobject.id+' child='+obj);
		if(obj.id == objectName) return obj;
		objfrombelow = getChildObject(objectName,obj,ndigmore-1);
		if(isObject(objfrombelow)) return objfrombelow;
	}
	return null;
}



function getName (object)
{
	if(!isObject(object)) return null;
  	return (object.name) ? object.name : object.id;
}

function removeChildren(obj) {
   if(obj.hasChildNodes()) {
    	while(obj.childNodes.length >= 1) {
			obj.removeChild(obj.firstChild);
    	}
	}
}



//type checks
function isObject(a) {
 	return (a && typeof a == 'object') || isFunction(a);
}

function isFunction(a) {
	return typeof a == 'function';
}

function isNumber(sText) {
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
   for (i = 0; i < sText.length && IsNumber == true; i++) {
      Char = sText.charAt(i);
      if (ValidChars.indexOf(Char) == -1) {
         IsNumber = false;
      }
   }
   return IsNumber;
}


//sygnum
function sgn(a) {
	if(a>0) return 1;
	if(a<0) return -1;
	return 0;
}

function nl2br(txt){ /* helper, textarea return \n not <br /> */
	return txt.replace(/\n/g, "<br />");
}







function findPos(obj) {
	var nleft = 0;
	var ntop = 0;
	if (obj.offsetParent) {
		nleft = obj.offsetLeft
		ntop = obj.offsetTop
		while (obj = obj.offsetParent) {
			nleft += obj.offsetLeft
			ntop += obj.offsetTop
		}
	}
	return [nleft,ntop];
}

function findSize(obj) {
 	nwidth = obj.offsetWidth;
 	nheight = obj.offsetHeight;
 	return [nwidth,nheight];
}



function getWidth(id) {
  	obj = getObject(id);
	return obj.offsetWidth;
}

function getHeight(id) {
   obj = getObject(id);
	return obj.offsetHeight;
}

function setZposition(id, z) {
  	if(NS) {
     	eval("document." + id).zIndex = z;
  	}
  	else {
     	eval("document.all." + id).style.zIndex = z;
	}
}




var core_functions_loaded = true;
