function createXmlHttpRequestObject() 
{
  var xmlHttp;
  if(window.ActiveXObject)
  {
    try{xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");}
    catch (e) {xmlHttp = false;}
  }
  else
  {
    try{xmlHttp = new XMLHttpRequest();}
    catch (e){xmlHttp = false;}
  }
  if (!xmlHttp)alert("Blad podczas tworzenia obiektu XMLHttpRequest.");
  else return xmlHttp;
}
function getEL(div_id)	
{
	var elem;  
	if(document.getElementById(div_id))elem = document.getElementById(div_id);  
	else if(document.all)elem = document.all[div_id];  
	else if(document.layers)elem = document.layers[div_id];
	else elem = '';
	return elem;
}
function getVL(div_id)	
{
	var elem;  
	if(document.getElementById(div_id))elem = document.getElementById(div_id);  
	else if(document.all)elem = document.all[div_id];  
	else if(document.layers)elem = document.layers[div_id];
	else elem = '';
	if(elem)return elem.value;else return '';
}
function getCH(div_id)	
{
	var elem;  
	if(document.getElementById(div_id))elem = document.getElementById(div_id);  
	else if(document.all)elem = document.all[div_id];  
	else if(document.layers)elem = document.layers[div_id];
	else elem = '';
	if(elem)return elem.checked;else return '';
}
//---trim
String.prototype.trim = function() 
{
	return this.replace(/^\s+|\s+$/g,"");
}
//---
function formack(x)
{
	if(confirm(x))return true;else return false;
}
function submitsearch(form,id,val)
{
	if(testsearch(id,val)==false)return false;
	var fm = getEL(form);
	if(fm)fm.submit();
}
function testsearch(id,val)
{
	var fm = getEL(id);
	if(!fm)return false;
	if(!fm.value)return false;
	if(fm.value==val)return false;
	return true;
}
function disableLinks(el) 
{
  if (getEL && document.getElementsByTagName) 
  {
    if (typeof(el) == 'string') el = getEL(el);
    if(!el)return;
    var anchors = el.getElementsByTagName('a');
    for (var i=0, end=anchors.length; i<end; i++)anchors[i].onclick = function() {return false;}; 
  }
}
function showBig(sciezka)
{
	var warstwa = getEL("foto");
	var tresc = '<div id="fotobox" class="fotobox">';
	tresc += '<div><a onclick="javascript: hideBig();" href="javascript: void(0);" style="color: #ffffff;font-size:11px;font-weight:bold;">zminimalizuj obrazek<br /><br /></a></div>';
	tresc += '<a onclick="javascript: hideBig();" href="javascript: void(0);" title="zminimalizuj obrazek">';
	tresc += '<img src="'+sciezka+'" id="bigimg" class="bigimg" alt="zminimalizuj obrazek" />';
	tresc += '</a>';
	tresc += '</div>';
	
	warstwa.innerHTML = tresc;
	warstwa.style.display = "block";
	getEL("body_tag").style.overflow = "hidden";
}
function hideBig(){
	var warstwa = getEL("foto");
	warstwa.style.display = "none";
	warstwa.innerHTML = "";
	getEL("body_tag").style.overflow = "auto";
}
function submitform(form,x,com,v,dop)
{
	var fm = getEL(form);
	var rez = true;
	if(x)rez = confirm(x);
	if(rez && dop)rez = confirm('Czy na pewno ?');
	var hi = getEL(com);
	if(hi && v)hi.value = v;
	if(fm && rez)fm.submit();
}
function submitform2(form,x,com,v,arg,v2,dop)
{
	var fm = getEL(form);
	var rez = true;
	if(x)rez = confirm(x);
	if(rez && dop)rez = confirm('Czy na pewno ?');
	var hi = getEL(com);
	if(hi && v)hi.value = v;
	hi = getEL(arg);
	if(hi && v)hi.value = v2;
	if(fm && rez)fm.submit();
}
function chg_bck(id,c)
{
	var v = getEL(id);
	if(v && c)v.style.backgroundColor = c;
}

function see_ove(id,num)
{
	var e = getEL(id);
	if(!id)return false;
	var n = num;
	if(!n)n = '0';
	e.className='love'+n;
}
function see_out(id,num)
{
	var e = getEL(id);
	if(!id)return false;
	var n = num;
	if(!n)n = '0';
	e.className='lnor'+n;
}
function ses_ove(id,num)
{
	var e = getEL(id);
	if(!id)return false;
	var n = num;
	if(!n)n = '0';
	e.className='lsov'+n;
}
function ses_out(id,num)
{
	var e = getEL(id);
	if(!id)return false;
	var n = num;
	if(!n)n = '0';
	e.className='lsel'+n;
}
//---
function usee_ove(id)
{
	var e = getEL(id);
	if(!id)return false;
	e.className='love';
}
function usee_out(id)
{
	var e = getEL(id);
	if(!id)return false;
	e.className='lnor';
}
function uses_ove(id)
{
	var e = getEL(id);
	if(!id)return false;
	e.className='lsov';
}
function uses_out(id)
{
	var e = getEL(id);
	if(!id)return false;
	e.className='lsel';
}
//---
function on(co,styl)
{
	var styl2=styl+'_on';
	co.className=styl2;
}
function off(co,styl)
{
	co.className=styl;
}
function set_width(id,width)
{
	var ids = getEL(id);
	if(id)ids.style.width = width;
}
function menu_on(id)
{
	nazwa='m'+id;
	cel = getEL(nazwa);	
	cel.className='menu_oferta_on';
}
function menu_off(id)
{
	nazwa='m'+id;
	cel = getEL(nazwa);
	cel.className='menu_oferta_off';
}
function fill_text(id,tx)
{
	var cel = getEL(id);
	var rez = true;	
	if(cel)
	{
		if(cel.value)rez = confirm('Czy chcesz zamienić treść pola');
		if(rez)cel.value = tx;
	}
}
function clir_fild(id)
{
	var cel = getEL(id);
	if(cel)cel.value = '';
}
function set_link(id,lnk)
{
	var cel = getEL(id);
	if(cel)cel.value = lnk;
}
function set_pic_link(id,lnk,fnm,w,h)
{
	var cel = getEL(id);
	if(cel)
	{
		var s = '<img src="'+lnk+'"';
		if(w)s = s + ' width="'+w+'"';
		if(h)s = s + ' height="'+h+'"';
		s = s + ' alt="'+fnm+'" />';
		if(!lnk)s = '';
		if(cel)cel.value = s;
		copyToClipboard(s);
	}
}
function set_pic(id,lnk,w,h)
{
	var cel = getEL(id);
	if(cel)
	{
		var s = '<img src="'+lnk+'"';
		if(w)s = s + ' width="'+w+'"';
		if(h)s = s + ' height="'+h+'"';
		s = s + ' />';
		if(!lnk)s = '';
		cel.innerHTML = s;
	}
}
function fill_full(id,s,dl)
{
	var scpo = document.body.scrollTop;
	if (scpo == 0)
	{
    if (window.pageYOffset)scpo = window.pageYOffset;
    else scpo = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0;
	}
	var cel = getEL(id);
	if(cel)
	{
		cel.style.paddingTop = scpo;
		cel.innerHTML = s;
	}
}
function show_hide(whichLayer,pic)
{ 
	//alert(whichLayer);
	var elem, vis;  
	if( getEL )elem = getEL( whichLayer );  
	else if( document.all )elem = document.all[whichLayer];  
	else if( document.layers ) elem = document.layers[whichLayer];  
	if(!elem)return;
	vis = elem.style;  
	if(vis.display==''&&elem.offsetWidth!=undefined&&elem.offsetHeight!=undefined)
	{
		vis.display = (elem.offsetWidth!=0&&elem.offsetHeight!=0)?'block':'none';  
	}
	vis.display = (vis.display==''||vis.display=='block')?'none':'block';
	//--- 
	if(pic)
	{
		var p = null;
		if( getEL)p = getEL(pic);  
		else if(document.all)p = document.all[pic];  
		else if(document.layers) p = document.layers[pic];  
		if(p)p.src = (vis.display==''||vis.display=='block')?'images/min.png':'images/plu.png';
	}
}
function hide_hide(whichLayer,pic)
{  
	if(pic)
	{
		var p = null;
		if( getEL)p = getEL(pic);  
		else if(document.all)p = document.all[pic];  
		else if(document.layers) p = document.layers[pic];  
		if(p)p.src = 'images/plu.png';
	}
	//alert(whichLayer);
	var elem, vis;  
	if( getEL )elem = getEL( whichLayer );  
	else if( document.all )elem = document.all[whichLayer];  
	else if( document.layers ) elem = document.layers[whichLayer];  
	if(!elem)return;
	vis = elem.style;  
	vis.display = 'none';
	//---

}
function show_show( whichLayer )
{  
	//alert(whichLayer);
	var elem, vis;  
	if( getEL )elem = getEL( whichLayer );  
	else if( document.all )elem = document.all[whichLayer];  
	else if( document.layers ) elem = document.layers[whichLayer];  
	if(!elem)return;
	vis = elem.style;  
	vis.display = 'block';
}
function show_unvis( whichLayer )
{  
	//alert(whichLayer);
	var elem, vis;  
	if( getEL )elem = getEL( whichLayer );  
	else if( document.all )elem = document.all[whichLayer];  
	else if( document.layers ) elem = document.layers[whichLayer];  
	if(!elem)return;
	vis = elem.style;  
	vis.visibility = 'hidden';
}
function show_vis( whichLayer )
{  
	//alert(whichLayer);
	var elem, vis;  
	if( getEL )elem = getEL( whichLayer );  
	else if( document.all )elem = document.all[whichLayer];  
	else if( document.layers ) elem = document.layers[whichLayer];  
	if(!elem)return;
	vis = elem.style;  
	vis.visibility = 'visible';
}
function darkbody()
{
	document.getElementsByTagName('BODY')[0].style.backgroundColor = '#333333';
}
function hellbody()
{
	document.getElementsByTagName('BODY')[0].style.backgroundColor = '#eeeeee';
}
function checkAll()
{
	var cba = getEL('cball');
	if(!cba)return;
	var cek = cba.checked;
	var inputs=document.getElementsByTagName('input'), i=0, inp, c;
	while(inp=inputs[i++])
	{
		if(inp.type=='checkbox')c=inp.checked = cek;
	}
}
//-----
function setfilter(whichLayer,link)
{
	var elem, vis;  
	if( getEL )elem = getEL( whichLayer );  
	else if( document.all )elem = document.all[whichLayer];  
	else if( document.layers ) elem = document.layers[whichLayer];  
	if(!elem)return; 
	var v = elem.value;
	var newhr = link.replace(/x555x/,v);
	window.location.href = newhr;
}
function clifilter(whichLayer,link)
{
	var newhr = link.replace(/x555x/,'');
	window.location.href = newhr;
}
//---Date validation--------------------------------------
var dtCh= "-";
var minYear=1900;
var maxYear=2100;
function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
//---
function stripCharsInBag(s, bag)
{
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
//---
function daysInFebruary (year)
{
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
//---
function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
//---
function isDate(dtStr)
{
	var daysInMonth = DaysArray(12);
	var pos1=dtStr.indexOf(dtCh);
	var pos2=dtStr.indexOf(dtCh,pos1+1);
	var strYear=dtStr.substring(0,pos1);
	var strMonth=dtStr.substring(pos1+1,pos2);
	var strDay=dtStr.substring(pos2+1);
	strYr=strYear;
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1);
	}
	month=parseInt(strMonth);
	day=parseInt(strDay);
	year=parseInt(strYr);
	if (pos1==-1 || pos2==-1){return false}
	if (strMonth.length<1 || month<1 || month>12){return false}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){return false}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){return false}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){return false}
	//---data < dzisiaj
	var curdat = new Date();
	var cury = parseInt(curdat.getYear());
	var curm = parseInt(curdat.getMonth())+1;
	var curd = parseInt(curdat.getDate());
	var daty = parseInt(strYear);
	var datm = parseInt(strMonth);
	var datd = parseInt(strDay);
	//alert(cury+" "+curm+" "+curd+" "+daty+" "+datm+" "+datd);
	if(cury<daty)return true;else if(cury>daty)return false;
	if(curm<datm)return true;else if(curm>datm)return false
	if(curd<datd)return true;else if(curd>datd)return false;
	if(curd==datd)return true;
	return false;
}
//----------------------------------------------------------------------
function Set_Cookie( name, value, expires, path, domain, secure )
{
	var today = new Date();
	today.setTime( today.getTime() );
	if(expires)
	{
		expires = expires * 1000 * 60;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
	((expires) ? ";expires=" + expires_date.toGMTString() : "" ) +
	((path) ? ";path=" + path : "" ) +
	((domain) ? ";domain=" + domain : "" ) +
	((secure) ? ";secure" : "" );
}
//--------------------
function Delete_Cookie( name, path, domain ) 
{
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
//--------------------
function Get_Cookie( name ) 
{
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}
//----------------------------------------------------------------------
function copyToClipboard(s)
{
	if( window.clipboardData && clipboardData.setData )
	{
		clipboardData.setData("Text", s);
	}
}
//----------------------------------------------------------------------
function show_if_select(ide,ve,target)
{
	var id = getEL(ide);
	var tg = getEL(target);
	if(!id||!tg)return false;
	if(id.value!=ve)tg.style.visibility = 'hidden';else tg.style.visibility = 'visible';
}
//----------------------------------------------------------------------
function hide_liczos_if_select(ide,target)
{
	var id = getEL(ide);
	var tg = getEL(target);
	if(!id||!tg)return false;
	var v = id.value;
	if(v<5||v>7)tg.style.visibility = 'visible';else tg.style.visibility = 'hidden';
}
//----------------------------------------------------------------------
function hide_if_checkbox(ide,target)
{
	var id = getEL(ide);
	var tg = getEL(target);
	if(!id||!tg)return false;
	if(id.checked)tg.style.visibility = "hidden";else tg.style.visibility = "visible";
}
//----------------------------------------------------------------------
function show_if_checkbox(ide,target)
{
	var id = getEL(ide);
	var tg = getEL(target);
	if(!id||!tg)return false;
	if(id.checked==true)tg.style.display = "block";else tg.style.display = "none";
}
//----------------------------------------------------------------------
function strlen(string) 
{
    var str = string + '';
    var i = 0,        chr = '',
        lgth = 0;
 
    if (!this.php_js || !this.php_js.ini || !this.php_js.ini['unicode.semantics'] || this.php_js.ini['unicode.semantics'].local_value.toLowerCase() !== 'on') {
        return string.length;    }
 
    var getWholeChar = function (str, i) {
        var code = str.charCodeAt(i);
        var next = '',            prev = '';
        if (0xD800 <= code && code <= 0xDBFF) { // High surrogate (could change last hex to 0xDB7F to treat high private surrogates as single characters)
            if (str.length <= (i + 1)) {
                throw 'High surrogate without following low surrogate';
            }            next = str.charCodeAt(i + 1);
            if (0xDC00 > next || next > 0xDFFF) {
                throw 'High surrogate without following low surrogate';
            }
            return str.charAt(i) + str.charAt(i + 1);        } else if (0xDC00 <= code && code <= 0xDFFF) { // Low surrogate
            if (i === 0) {
                throw 'Low surrogate without preceding high surrogate';
            }
            prev = str.charCodeAt(i - 1);            if (0xD800 > prev || prev > 0xDBFF) { //(could change last hex to 0xDB7F to treat high private surrogates as single characters)
                throw 'Low surrogate without preceding high surrogate';
            }
            return false; // We can pass over low surrogates now as the second component in a pair which we have already processed
        }        return str.charAt(i);
    };
 
    for (i = 0, lgth = 0; i < str.length; i++) {
        if ((chr = getWholeChar(str, i)) === false) {            continue;
        } // Adapt this line at the top of any loop, passing in the whole string and the current iteration and returning a variable to represent the individual character; purpose is to treat the first part of a surrogate pair as the whole character and then ignore the second part
        lgth++;
    }
    return lgth;
} 
//----------------------------------------------------------------------
function limit_and_cut_field(ide,num,col1,col2)
{
	if(!num)return false;
	var id = getEL(ide);
	var sp = getEL('sp'+ide);
	if(!id)return false;
	var le = strlen(id.value);
	if(le<=num)
	{
		id.style.color = col1;
		if(sp)
		{
			sp.style.color = 'blue';
			if(sp)sp.innerHTML = 'wpisano '+le+' z 1800 znaków';
		}
		return true;
	}
	else 
	{
		if(id.style.color != col2)id.style.color = col2;
		if(sp)sp.style.color = col2;
		if(sp)sp.innerHTML = 'wpisano '+le+' z 1800 znaków  -  prosimy o skrócenie tekstu';
		return true;
	}
	
}
//----------------------------------------------------------------------
function limit_field(ide,num,col1,col2)
{
	if(!num)return false;
	var id = getEL(ide);
	var sp = getEL('sp'+ide);
	if(!id)return false;
	var le = strlen(id.value);
	if(le<=num)
	{
		id.style.color = col1;
		if(sp)
		{
			sp.style.color = 'blue';
			if(sp)sp.innerHTML = 'wpisano '+le+' z 1800 znaków';
		}
		return true;
	}
	else 
	{
		if(id.style.color != col2)id.style.color = col2;
		if(sp)sp.style.color = col2;
		if(sp)sp.innerHTML = 'wpisano '+le+' z 1800 znaków  -  prosimy o skrócenie tekstu';
		return true;
	}
}
//----------------------------------------------------------------------
