var movestep = 20;
var TimeoutBeforeStartImagePresentationConst = 20;
var TimeoutBeforeStartImagePresentation = 10;
var TimeoutBeetweenImagesConst = 5;
var TimeoutBeetweenImages = 0;
var currentPicTablePos = 0;
var moveToPicTablePos = 0;
var moveToPicDirection = 0;
var playslideshow = true;
var searchcriteriaurl = "";
var currentSearchEngine = "search-form-post.asp"

function getPageScroll(){
	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	return yScroll;
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) ;
	return arrayPageSize;
}

function OnEditCancel2(EditCancelForm,EditCancelAction) {
	window.document.forms [EditCancelForm].action = EditCancelAction;
	window.document.forms [EditCancelForm].submit(); 
}
	
function GotoURL(object) {
	var value = object.options[object.selectedIndex].value;
	if (value=='') return;
	window.parent.location.href = value;
}

function JSGoToPage(page,params){
	var aurl = "";
	if (page.length >0) aurl+=page;
	if (params.length >0){
		if (aurl.indexOf("?")>=0){
			if (aurl.indexOf("?")==(aurl.length-1)){
				if (params.indexOf("?")==0){
					aurl+=params.substr(1);
				}else{
					aurl+=params;
				}
			}else{
				if (params.indexOf("?")==0){
					aurl+="&"+params.substr(1);
				}else{
					aurl+="&"+params;
				}
			}
		}else{
			if (params.indexOf("?")==0){
				aurl+=params;
			}else{
				aurl+=("?"+params);
			}
		}
	}
	if (aurl.length>0) document.location.href=aurl;
}

function GoToSFP(params){
	JSGoToPage("search-form-post.asp",params);
}

function goToPageNum(pagenum){
	goToPageNumInt(pagenum,document.location.href)
}

function goToPageNumSafe(pagenum){
	if (searchcriteriaurl.length > 0){
		goToPageNumInt(pagenum,searchcriteriaurl);
	}else{
		goToPageNumInt(pagenum,document.location.href);
	}
}

function goToPageNumInt(pagenum,currenturl){
	if (currenturl.lastIndexOf("search-form-post,")>=0){
		var re1 = /search-form-post,\d*\.asp/i
		pageid = currenturl.match(re1).toString();
		if (pageid.length>0){
			pagecategoryid = (pageid.replace("search-form-post,","")).replace(".asp","");
			if (pagecategoryid.length>0){
				currenturl = currenturl.replace(pageid,"search-form-post.asp?categoryid="+pagecategoryid)
			}
		}		
	}
	
	if (currenturl.lastIndexOf("/ogloszenia,")>=0){
		var re1 = /ogloszenia,\d*,.*,.*\.asp/i
		pageid = currenturl.match(re1).toString();
		if (pageid.length>0){
			pagecategoryid = (pageid.replace("search-form-post,","")).replace(".asp","");
			if (pagecategoryid.length>0){
				var elemarray = pagecategoryid.split(",");
				var locCategoryId = "";
				var locMarka = "";
				var locModel = "";
				currenturl = "/"+currentSearchEngine;
				if (elemarray.length > 1) locCategoryId = elemarray[1];
				if (elemarray.length > 2) locMarka = elemarray[2];
				if (elemarray.length > 3) locModel = elemarray[3];
				currenturl = currenturl+"categoryid="+locCategoryId.toString()+"&marka="+locMarka.toString()+"&model="+locModel.toString();
			}
		}	
	}

	var newpageurl = "/"+currentSearchEngine;
	var currentpageparams = "";
	var splitedurl = (currenturl+"?").split("?")
	if (splitedurl.length > 1) currentpageparams = splitedurl[1];
	
	if (currenturl.lastIndexOf("/samochody_luksusowe/")>=0){
		if (currentpageparams.length > 0) currentpageparams += "&"
		currentpageparams += "categoryid=130&islux=1"
	}
	if (currenturl.lastIndexOf("/nieruchomosci_luksusowe/")>=0){
		if (currentpageparams.length > 0) currentpageparams += "&"
		currentpageparams += "categoryid=190&islux=1"
	}
	if (currenturl.lastIndexOf("-ebay")>=0){
		if (currentpageparams.length > 0) currentpageparams += "&"
		currentpageparams += "searchtype=ebay";
		newpageurl = "/search-form-post-ebay.asp";
	}	
	currenturl = newpageurl;
	if (currentpageparams.length > 0) currenturl = currenturl +"?"+currentpageparams;

	var re = /page=\d*&/i;
	if( (currenturl+"&").search(re) > 0){
		currenturl = (currenturl+"&").replace(re,"page="+pagenum+"&");
		currenturl = currenturl.substr(0,currenturl.length-1);
	}else{
		currenturl = currenturl+"&page="+pagenum;
	}
	if (document.getElementById("currenttab")){
		var curtab = document.getElementById("currenttab").value;
		if (curtab.length > 0){
			var re2 = /currenttab=[a-z]*&/i;
			if( (currenturl+"&").search(re2) > 0){
				currenturl = (currenturl+"&").replace(re2,"currenttab="+curtab+"&");
				currenturl = currenturl.substr(0,currenturl.length-1);
			}else{
				currenturl = currenturl+"&currenttab="+curtab;
			}
		}
	}
	var urldataarray = (currenturl+"?").split("?");
	JSGoToPage(urldataarray[0],urldataarray[1]);
}

function GoToKSCAT(params){JSGoToPage("ks-cat.asp",params);}

function SOClickCounter(Id,AdId, AdCategoryId) {
		if(document.images){
			(new Image()).src="/special-offer-click-counter.asp?OPId="+escape(Id)+"&CategoryID="+escape(AdCategoryId)+"&id="+escape(AdId)+"&redirect=0";
		}
		return true;
	}

	
function zglosProblem(aAdID,aCategoryID, xt){
	var showformid = ";8;"
	var txtdata = ";"+xt+";"
	if (txtdata != ";;"){
		if(!(showformid.indexOf(txtdata)>=0)){
			var urllocation = "/nieaktualne-post.asp?adid="+aAdID+"&CategoryID="+aCategoryID+"&Type="+xt+"&x="+Math.random();
			var tmpImage = new Image();
			tmpImage.src = urllocation;
			document.getElementById("IdzglosProblem").style.display = "none";
			document.getElementById("IdzglosProblem").style.display = "none";
			alert('Zgłoszenie zostało wysłane.\nDziękujemy!');
		}else{
			var urllocation='/naduzycie.asp?CategoryID='+aCategoryID+'&Adid='+aAdID+'&Type='+xt;
			var oNewWindow = window.open(urllocation,'pomoc','menubar=no,location=no,toolbar=no,resizable=no,status=yes,width=640,height=480,left=10,top=10;'); 
			oNewWindow.focus();
			document.getElementById("IdzglosProblem").style.display = "none";
			document.getElementById("IdzglosProblem").style.display = "none";
		}
	}else{alert("Wybierz z listy rodzaj zgłoszenia.");}
}

function ShowUserPhone(userid){
	var UserPhoneLink=document.getElementById("UserPhoneLink");
	var UserPhone = document.getElementById("UserPhone");
		if(document.images){
			(new Image()).src="/pp-owners-list-click-counter.asp?UserId="+escape(userid)+"&counterType=detailsphone&url=www.trader.pl/images/t.gif";
		}
		if (UserPhoneLink){
			UserPhoneLink.style.display="none";
		}
	if (UserPhone){
		UserPhone.style.display="block";
	}
}

function UserEmailClickCounter(userid){
		if(document.images){
			(new Image()).src="/pp-owners-list-click-counter.asp?UserId="+escape(userid)+"&counterType=detailsemail";
		}
}

function ShowAgentPhone(userid){
		if(document.images){
			(new Image()).src="/pp-owners-list-click-counter.asp?UserId="+escape(userid)+"&counterType=detailsphone";
		}
	document.getElementById("AgentPhoneLink").style.display="none";
	document.getElementById("AgentPhone").style.display="block";
}

function checkContactForm(){
	if(document.getElementById("email").value!='' || document.getElementById("phone").value!=''){
		return true;
	}else{
		alert("Pole e-mail lub telefon musi byc wypełnione");
		return false;
	}
}

// funkcje z ad-details-display.inc

function moveToMainPic(obrazek){
	TimeoutBeforeStartImagePresentation = TimeoutBeforeStartImagePresentationConst;
	TimeoutBeetweenImages = 0;
	moveToPicDirection = 0;
	moveToMainPicInternal(obrazek);
}

function getDescForPicture(picnum)
{
	var retval = "";
	if (imagetitles.length >=  picnum) retval += imagetitles[picnum];
	if ((imagedescs.length  >=  picnum) && (imagedescs[picnum].length > 0))
	{
		if (retval.length > 0) retval += "\n__________________________\n"
		retval += imagedescs[picnum];
	}
	return retval;
}
function moveToMainPicInternal(obrazek){
	if (document.getElementById("smallPicture_"+currentbigimage))
	{
		document.getElementById("smallPicture_"+currentbigimage).className="smallPicture";
	}
	currentbigimage=obrazek;
	swapPicture(PictureDomain+"/pictures/"+imagenames[obrazek]);
	var desc = getDescForPicture(obrazek);
	if (desc.length > 0) setInfoOnMainPic(desc);
	bigpicture = obrazek; 
	if (document.getElementById("smallPicture_"+obrazek)){
		document.getElementById("smallPicture_"+obrazek).className="smallPictureActive";
	}
	try{
		mainImageChanged();
	}catch(e){;}
			
}

function setInfoOnMainPic(info)
{
	//function showAlert(atemat,atext,toobject)
	document.getElementById("MainPicture1").title = info;
	document.getElementById("MainPicture2").title = info;
	document.getElementById("MainPicture1").alt = info;
	document.getElementById("MainPicture2").alt = info;
}

function swapPicture(newImageUrl)
{
	if (document.getElementById("MainPicture1TD")){
		var leftobj = document.getElementById("MainPicture1TD");
		var rightobj = document.getElementById("MainPicture2TD");
		if (moveToPicDirection == 0){
			leftobj.style.backgroundImage = rightobj.style.backgroundImage;
			document.getElementById("MainPictureDisplayTable").style.left = "0px";
			currentPicTablePos = 0;
			var newpos = -300;
			moveToPicTablePos = newpos;
			rightobj.style.backgroundImage="url("+newImageUrl+")";
		}else{
			document.getElementById("MainPictureDisplayTable").style.left = "-300px";
			currentPicTablePos = -300;
			var newpos = 0;
			moveToPicTablePos = newpos;
			leftobj.style.backgroundImage="url("+newImageUrl+")";	
		}
		changePos();
	}else{
		document.getElementById("bgbigpicture").style.backgroundImage = "url("+newImageUrl+")";
	}
}

function changePos(){
	
	if (currentPicTablePos!=moveToPicTablePos){
		var newpos = currentPicTablePos;
		if (currentPicTablePos>moveToPicTablePos) {
			newpos = newpos-movestep;
			if (newpos<moveToPicTablePos){
				newpos=moveToPicTablePos;
			}
		}
		if (currentPicTablePos<moveToPicTablePos) {
			newpos = newpos + movestep;
			if (newpos>moveToPicTablePos){
				newpos=moveToicTablePos;
			}
		}
		currentPicTablePos = newpos;
		document.getElementById("MainPictureDisplayTable").style.left = newpos+"px";
		if (currentPicTablePos==moveToPicTablePos){
			var leftobj = document.getElementById("MainPicture1TD");
			var rightobj = document.getElementById("MainPicture2TD");
			if (moveToPicDirection == 0){
				leftobj.style.backgroundImage=rightobj.style.backgroundImage;
			}else{
				rightobj.style.backgroundImage=leftobj.style.backgroundImage;
			}
		}
		setTimeout("changePos()",20);
	}
}

function PrevPicture(){
	TimeoutBeforeStartImagePresentation = TimeoutBeforeStartImagePresentationConst;
	TimeoutBeetweenImages = 0;
	PrevPictureInternal();
}

function PrevPictureInternal(){
	
	moveToPicDirection = 1;
	var nextimageid = currentbigimage-1;
	if (nextimageid<1){
		nextimageid=imagenames.length-1;
	}
	moveToMainPicInternal(nextimageid);
}

function NextPicture(){
	TimeoutBeforeStartImagePresentation = TimeoutBeforeStartImagePresentationConst;
	TimeoutBeetweenImages = 0;
	 NextPictureInternal();
}

function NextPictureInternal(){
	moveToPicDirection = 0;
	var nextimageid = currentbigimage+1;
	if (nextimageid>=imagenames.length){
		nextimageid=1;	
	}
	moveToMainPicInternal(nextimageid);
}
		
function showMaxPic2(picCategoryID){
	var link = "window.open(\"/view-picture2.asp?CategoryId="+picCategoryID+"&FileName=original/"+(imagenames[bigpicture].replace(",","&")).replace(",","&")+"\",\"foto\",\"menubar=no,location=no,toolbar=no,resizable=no,status=no,width=800,height=600,top=0,left=0\");"
	eval(link);
}

function showMaxPic3(){
	if (imagenames.length==2){
		//na pierwszym miejscu w tablicy imagenames zawsze jest jeden niewypełniony element
		// więc jeżemy chcemy sprawdzić czy jest dokładnie jedno zdjęcie musimy się posłużyć powyższym warunkiem
		window.open("/view-picture2.asp?FileName="+imagenames[bigpicture],"bigfotowindow","menubar=no,location=no,toolbar=no,resizable=no,status=no,width=800,height=600,top=0,left=0")
	}
	if (imagenames.length>2){
		window.open("/view-picture2.asp?FileName="+imagenames[bigpicture],"bigfotowindow","menubar=no,location=no,toolbar=no,resizable=no,status=no,width=978,height=600,top=0,left=0")
	}

}

function preloadSingleImage(imagesarray,imgindex){
	if (imgindex<imagesarray.length){
		var imageRecordArray = imagesarray[imgindex];
		if (imageRecordArray.length > 1){
			var imageurl = imageRecordArray[0];
			var imageobj = imageRecordArray[1];
			if (imageurl.length>0){
				imageobj.src = imageurl;
			}
		}
	}
}

function preloadImagesFromArray(imagesarray){
	for (i=0;i<imagesarray.length;i++){
		preloadSingleImage(imagesarray,i);
	}
	automovetonextimage();
}

function waitForPreload(){
	var arrayexists = true;
	try{
		var aimagesarray = imagesarray.slice(0);
	}catch(e){
		arrayexists = true;
	}
	if (arrayexists) {
		
	}
}

function automovetonextimage(){
	if (TimeoutBeforeStartImagePresentation>0){
		TimeoutBeforeStartImagePresentation = TimeoutBeforeStartImagePresentation-1;
	}else{
		if (TimeoutBeetweenImages>0){
			TimeoutBeetweenImages = TimeoutBeetweenImages-1;
		}else{
			TimeoutBeetweenImages = TimeoutBeetweenImagesConst;
			if (playslideshow){
			NextPictureInternal();
			}
		}
	}
	setTimeout("automovetonextimage()",1000);
}

function checkpreload(){
	var arrayexists = true;
	var s = "";
	try{
		var aimagesarray = imagesarray.slice(0);
	}catch(e){
		arrayexists = true;
	}
	if (arrayexists) {
		for (i=0;i<aimagesarray.length;i++){
			var imageRecordArray = aimagesarray[i];
			s += imageRecordArray[0]+imageRecordArray[1].complete +"\n";
		}
	}
}

function preloadImages(imageliststr,imagesarray){
	if (imageliststr.length>0){
		var imagelistarray = imageliststr.split(";");
		for (i=0;i<imagelistarray.length;i++){
			var imgurl = imagelistarray[i];
			if (imgurl.length>0){
				var imageRecordArray = new Array()
				imageRecordArray[0] = imgurl;
				imageRecordArray[1] = new Image();
				imageRecordArray[1].src = imgurl;
				imagesarray[imagesarray.length] = imageRecordArray;
			}
		}
		preloadImagesFromArray(imagesarray);
	}
}

function checkSpeed(){
	movestep = 300;
}
checkSpeed();

function changeOpalevel(){
	document.getElementById('fullviewbackground').className = "fullviewopa80";
}

function setFullImage(){
	waitseconds++;
	if ((fullImage.complete)||(waitseconds>10)){
		document.getElementById('fullviewimagewait').style.display = "none";
		document.getElementById('fullviewimagecontenerimg').src = fullImage.src;
		document.getElementById('fullviewimagecontenerimg').style.display = "block";
		waitseconds = 0;
		clickByMiniatura = false;
	}else{
		setTimeout("setFullImage()",500);
	}	
}

function hideFullSize(sender){
	if (!clickByMiniatura){
		try{
			document.body.onresize = null;
			document.body.onscroll = null;
		}catch(e){;}
		playslideshow = true;
		document.getElementById('fullviewbackground').style.display = "none";
		document.getElementById('fullviewimagewait').style.display = "none";
		document.getElementById('fullviewmaincontener').style.display = "none";
		try{
			document.getElementById('header_2').style.visibility = 'visible';
			document.getElementById('rightFrame').style.visibility = 'visible';
		}catch(e){;}
	}
	clickByMiniatura = false;
}

function doresize(){
	var bg = document.getElementById('fullviewbackground');
	var bgsize = new CPoint(0,0);
	if (document.getElementById("pageBody")){
		bgsize = getObjSize(document.getElementById("pageBody"));
	}else{
		bgsize = getObjSize(document.body);
	}
	bg.style.height = bgsize.Y+"px";
	bg.style.width = bgsize.X+"px";
}

function sfh(o){
	var retstr = "";
	for (var i = 0; i < o.length; i++){
		if ((i%2)==0) retstr += "%";
		retstr += o.substr(i,1);
	}
	retstr = unescape(retstr);
	//enkodowanie znaczkow 
	while (retstr.indexOf("^a")>=0) retstr = retstr.replace("^a",String.fromCharCode(261));
	while (retstr.indexOf("^c")>=0) retstr = retstr.replace("^c",String.fromCharCode(263));
	while (retstr.indexOf("^e")>=0) retstr = retstr.replace("^e",String.fromCharCode(281));
	while (retstr.indexOf("^l")>=0) retstr = retstr.replace("^l",String.fromCharCode(322));
	while (retstr.indexOf("^n")>=0) retstr = retstr.replace("^n",String.fromCharCode(324));
	while (retstr.indexOf("^o")>=0) retstr = retstr.replace("^o",String.fromCharCode(243));
	while (retstr.indexOf("^s")>=0) retstr = retstr.replace("^s",String.fromCharCode(347));
	while (retstr.indexOf("^z")>=0) retstr = retstr.replace("^z",String.fromCharCode(380));
	while (retstr.indexOf("^x")>=0) retstr = retstr.replace("^x",String.fromCharCode(378));
	while (retstr.indexOf("^A")>=0) retstr = retstr.replace("^A",String.fromCharCode(260));
	while (retstr.indexOf("^C")>=0) retstr = retstr.replace("^C",String.fromCharCode(262));
	while (retstr.indexOf("^E")>=0) retstr = retstr.replace("^E",String.fromCharCode(280));
	while (retstr.indexOf("^L")>=0) retstr = retstr.replace("^L",String.fromCharCode(321));
	while (retstr.indexOf("^N")>=0) retstr = retstr.replace("^N",String.fromCharCode(323));
	while (retstr.indexOf("^O")>=0) retstr = retstr.replace("^O",String.fromCharCode(211));
	while (retstr.indexOf("^S")>=0) retstr = retstr.replace("^S",String.fromCharCode(346));
	while (retstr.indexOf("^Z")>=0) retstr = retstr.replace("^Z",String.fromCharCode(379));
	while (retstr.indexOf("^X")>=0) retstr = retstr.replace("^X",String.fromCharCode(377));
	return retstr;
}

// clipoard ajax functions start 
var elemids = "";
function setClipboardItems(clipitems){
	var s = "";
	var clipcount = 0;
	try{
		if (elemids.length>0){
			// czyszczenie wszystkiego
			var elemarray = (elemids+",").split(",");
			for (i=0;i<elemarray.length;i++){
				try{
					var s = elemarray[i];
					if (s.length>0){
						var obj = document.getElementById("clip_"+s);
						obj.src = "/images/icoAddToClipboard.gif";
						obj.value = 0;
						obj.title = "Zapisz to ogłoszenie w schowku";
					}
				}catch(e){;}
			}
		}
	}catch(e){;}
	try{
		if (document.getElementById("clipboardidinput")){
			var obj = document.getElementById("clipboardidinput");
			obj.value = 0;
			var obj2 = document.getElementById("clipboardidlink");
			if (obj2.title != "dodaj ogłoszenie do schowka"){
				obj2.title = "dodaj ogłoszenie do schowka";
				obj2.innerHTML = "do schowka";
				showAlertAdv("","Ogłoszenie zostało usunięte ze schowka","btn_fadeefect|btn_autohide|btn_timerhide",obj2,"","");
			}
		}
	}catch(e){;}
	s = "";
	if (clipitems=="0") clipitems = "";
	if (clipitems.length>0){
		// zaznaczamy elementy ze schowka
		var cliparray = (clipitems+",").split(",");
		for (i=0;i<cliparray.length;i++){
			try{
				var s = cliparray[i];
				if ((s.length>0) && (s!="0")){
					clipcount++;
					try {
						var obj = document.getElementById("clip_"+s);
						obj.src = "/images/icoRemoveFromClipboard.gif";
						obj.value = 1;
						obj.title = "Usuń to ogłoszenie ze schowka";
					}catch(e){;}

					try{
						var obj = document.getElementById("clipboardidinput");
						if (obj.name == s){
							obj.value = 1;
							if (document.getElementById("clipboardidlink")){
								var obj2 = document.getElementById("clipboardidlink");
								if (obj2.title != "usuń ogłoszenie ze schowka"){
									obj2.title = "usuń ogłoszenie ze schowka";
									obj2.innerHTML = "usuń ze schowka";
									showAlertAdv("","Ogłoszenie zostało dodane do schowka","btn_fadeefect|btn_autohide|btn_timerhide",obj2,"","");
								}
							}
						}
					}catch(e){;}
				}
			}catch(e){;}			
		}

	}
	setClipboardCounter(clipitems);
}

function setClipboardCounter(clipitems){
	var clipcount = 0;
	if (clipitems=="0") clipitems = "";
	if (clipitems.length>0){
		var cliparray = (clipitems+",").split(",");
		for (i=0;i<cliparray.length;i++){
			var s = cliparray[i];
			if ((s.length>0) && (s!="0")){
				clipcount++;
			}
		}
	}		
	try{
		if (clipcount>0){
			document.getElementById("clipboardcounter").innerHTML = "["+clipcount+"]";
		}else{
			document.getElementById("clipboardcounter").innerHTML = "[-]";
		}
	}catch(e){;}
	
}
function manageclipboard(clipitem)
{
	var clipaction = "";
	var clipid = ""
	try{
		if (clipitem.value == 1){
			clipaction = "remove";
			clipid = clipitem.name;
		}
		if (clipitem.value == 0){
			clipaction = "add";
			clipid = clipitem.name;
		}
	}catch(e){;}

	if (window.XMLHttpRequest) { 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType) {
			http_request.overrideMimeType('text/xml');
		}
	} else if (window.ActiveXObject) { 
		try {
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				http_request = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e) {}
		}
	}
	if (!http_request) {
		alert('Error');
		return false;
	}
	http_request.onreadystatechange = function() { GetClipboard(http_request); };
	url="/clipboard-ajax.asp?acache="+Math.random();
	if ((clipaction.length>0)&&(clipid.length>0)){
		url += "&cmd="+clipaction+"&clipid="+clipid;
	}
	http_request.open('GET', url, true);
	http_request.send(null);
}

function GetClipboard(http_request) {
    if (http_request.readyState == 4) {
        if (http_request.status == 200) {
			var j=0;
            var out = http_request.responseText;
			var outelems = out.split("^");
			try{
				setClipboardItems(out);
			}catch(e){;}

        } else {
            alert('Schowek - wystąpił problem z zapytaniem.');
        }
    }
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return "";
}

function writeCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function setCookiesCounter(){
	var cstr = readCookie("clipboarditems");
	if (cstr.length>0){
		while (cstr.indexOf("%2C")>=0){
			cstr = cstr.replace("%2C",",")
		}
		while (cstr.indexOf("%2c")>=0){
			cstr = cstr.replace("%2c",",")
		}
		setClipboardCounter(cstr);
	}
}

function setClipboardIcons(){
	var cstr = readCookie("clipboarditems");
	if (cstr.length>0){
		while (cstr.indexOf("%2C")>=0){
			cstr = cstr.replace("%2C",",")
		}
		while (cstr.indexOf("%2c")>=0){
			cstr = cstr.replace("%2c",",")
		}
		setClipboardItems(cstr);
	}
}
function clipItemMan(clipitem){
	manageclipboard(clipitem);
}
//setTimeout("setCookiesCounter();",1000)

// clipoard ajax functions stop 

// funkje alerta Layerowego - start 
var AlertUseFadeEfect = false;
var HideTimerVal = 0;
function CPoint(X,Y) {this.X=X;this.Y=Y;}
function CPointToString(){return this.X+"|"+this.Y;}
CPoint.prototype.toString = CPointToString;

function showAlert(atemat,atext,toobject){
	try{
		if (toobject) {
			var posdata = getAbsoluteObjPos(toobject);
			var sizedata = getObjSize(toobject);
		}else{
			var posdata = new CPoint(0,0);
			var sizedata = new CPoint(0,0);
		}
		showAlertAtPos(atemat,atext,'',posdata,sizedata,alertwidth,posstyle)
		showAlertAdv(atemat,atext,'',toobject,'','')
	}catch(e){;}
}

function showAlertAdv(atemat,atext,btnarray,toobject, alertwidth,posstyle){
	try{
		if (toobject) {
			var posdata = getAbsoluteObjPos(toobject);
			var sizedata = getObjSize(toobject);
		}else{
			var posdata = new CPoint(0,0);
			var sizedata = new CPoint(0,0);
		}
		showAlertAtPos(atemat,atext,btnarray,posdata,sizedata,alertwidth,posstyle);
	}catch(e){;}
}

function showAlertAtPos(atemat,atext,btnarray,posdata,sizedata, alertwidth, posstyle){
	try{
		if (document.getElementById("alertobj")){}else{ insertAlertHTML();}
		if (document.getElementById("alertobj")){
			var setpos = false;
			var useTimerHide = false;
			var startPosData = new CPoint(posdata.X,posdata.Y);
			document.getElementById("alertobj").className = "alertobj rowinvisible";
			if (alertwidth.length = 0) alertwidth = 300;
			document.getElementById("alertobjtitle").innerHTML = atemat;
			document.getElementById("alertobjtext").innerHTML = atext;
			if (atemat.length == 0) {
				document.getElementById("alertobjtitlerow").className="rowinvisible";
				document.getElementById("alertobjroundedframe2").className = "alertobjroundedframe2withouttemat";
			}else{
				document.getElementById("alertobjtitlerow").className="rowvisible";
				document.getElementById("alertobjroundedframe2").className = "alertobjroundedframe2";
			}
			var btnshtml ="";
			if	(btnarray.length==0){btnarray = "btn_autohide";}
			if	(btnarray.length>0){
				var barray = (btnarray+"|").split("|");
				for (i=0;i<barray.length;i++){
					var s = barray[i];
					if (s.length>0){
						if (s=="btn_ok") btnshtml += getBtnHtml("ok","btnok_onclick()");
						//if (s=="btn_autohide") btnshtml += "<a href=\"javascript: return null;\" onblur=\"hideAlert();\" id=\"alertautohidebtn\" style=\"border: 0px none White;\"><img src=\"/images/t.gif\" alt=\"\" width=\"1\" height=\"1\" border=\"0\"></a>";
						if (s=="btn_autohide") btnshtml += "<a href=\"javascript: return null;\" onblur=\"hideAlert();\" id=\"alertautohidebtn\" style=\"font-size: 1px; font: 1px;\"><span style=\"display:none;\">&nbsp;</span></a>";
						if (s=="btn_timerhide") useTimerHide = true;
						if (s=="btn_fadeefect") AlertUseFadeEfect = true;
					}
				}
			}
			document.getElementById("alertobj").style.left = "-1000px";
			document.getElementById("alertobj").className = "alertobj visible";			
			document.getElementById("alertobjbuttons").innerHTML = btnshtml;
			if (alertwidth.length>0) document.getElementById("alertobj").style.width = alertwidth+"px";
			asize = getObjSize(document.getElementById("alertobj"));
			document.getElementById("alertobj").className = "alertobj rowinvisible";
			var currentTop = document.body.scrollTop;
			var currentLeft = document.body.scrollLeft;
			var currentWidth = document.body.scrollWidth;
			var currentHeight = document.body.scrollHeight;
			var defaultTopPosition = "";
			var defaultLeftPosition = "";
			if (posstyle.length==0) posstyle = "auto";
			if (posstyle == "auto"){
				if ((posdata.Y-currentTop)>=asize.Y){
					defaultTopPosition = "top";
				}else{
					defaultTopPosition = "bottom"
				}
				defaultLeftPosition = "center";
				if ((posdata.X+asize.X)<currentWidth){
					defaultLeftPosition="left";
				}
				posstyle = defaultTopPosition+"-"+defaultLeftPosition;
			}
			if (posstyle == "top-left"){	
				document.getElementById("dzdcontainer").align="left";
				document.getElementById("dzdtr").className = "rowvisible";
				document.getElementById("dzutr").className = "rowinvisible";
			}
			if (posstyle == "top-right"){
				document.getElementById("dzdcontainer").align="right";
				document.getElementById("dzdtr").className = "rowvisible";
				document.getElementById("dzutr").className = "rowinvisible";		
			}
			if (posstyle == "top-center"){
				document.getElementById("dzdcontainer").align="center";
				document.getElementById("dzdtr").className = "rowvisible";
				document.getElementById("dzutr").className = "rowinvisible";
			}
			if (posstyle == "bottom-left"){	
				document.getElementById("dzucontainer").align="left";
				document.getElementById("dzdtr").className = "rowinvisible";
				document.getElementById("dzutr").className = "rowvisible";
			}
			if (posstyle == "bottom-right"){
				document.getElementById("dzucontainer").align="right";
				document.getElementById("dzdtr").className = "rowinvisible";
				document.getElementById("dzutr").className = "rowvisible";
			}
			if (posstyle == "bottom-center"){
				document.getElementById("dzucontainer").align="center";
				document.getElementById("dzdtr").className = "rowinvisible";
				document.getElementById("dzutr").className = "rowvisible";
			}
			document.getElementById("alertobj").style.left = "-1000px";
			document.getElementById("alertobj").className = "alertobj visible";
			asize = getObjSize(document.getElementById("alertobj"));
			document.getElementById("alertobj").className = "alertobj rowinvisible";
			if (posstyle == "top-left"){posdata.X-=11;posdata.Y-=asize.Y;}
			if (posstyle == "top-right"){posdata.X=posdata.X+sizedata.X-asize.X+11;posdata.Y-=asize.Y;}
			if (posstyle == "top-center"){posdata.X=(posdata.X+Math.round(sizedata.X/2))-Math.round(asize.X/2);posdata.Y-=asize.Y;}
			if (posstyle == "bottom-left"){posdata.X-=11;posdata.Y+=sizedata.Y;}
			if (posstyle == "bottom-right"){posdata.X=posdata.X+sizedata.X-asize.X+11;posdata.Y+=sizedata.Y;}
			if (posstyle == "bottom-center"){posdata.X=(posdata.X+Math.round(sizedata.X/2))-Math.round(asize.X/2);posdata.Y+=sizedata.Y;}
			document.getElementById("alertobj").style.left = posdata.X+"px";
			document.getElementById("alertobj").style.top = posdata.Y+"px";
			showAlert();
			var scrollY = currentTop;
			if (scrollY>posdata.Y) scrollY = posdata.Y;
			if (scrollY>startPosData.Y) scrollY = startPosData.Y;
			if (currentTop>scrollY)  document.body.scrollTop =scrollY;
			if (document.getElementById("alertautohidebtn")){
				document.getElementById("alertautohidebtn").focus();
			}
			if (useTimerHide){hideTimerAlert();}
		}else{;}
	}catch(e){;}
}

function getBtnHtml(title,onclick){return "<div class=\"alertobjbutton\" onclick=\"try{"+onclick+"}catch(e){;}\">"+title+"</div>";}

function checkAbsoluteObjPos(toobject,aPoint){
	try{
		if (toobject) {
			aPoint.X += toobject.offsetLeft;aPoint.Y += toobject.offsetTop;
			if (toobject.offsetParent) checkAbsoluteObjPos(toobject.offsetParent,aPoint);
		}
	}catch(e){;}
}

function getAbsoluteObjPos(toobject){
	aPoint = new CPoint(0,0);
	try{
		checkAbsoluteObjPos(toobject,aPoint);
	}catch(e){;}
	return aPoint;
}

function getObjSize(toobject){
	aPoint = new CPoint(0,0);
	try{	
		if (toobject){
			if ((toobject.style.width).length>1){
				aPoint.X = parseInt(toobject.style.width);
			}else{
				aPoint.X = toobject.offsetWidth;
			}
			if ((toobject.style.height).length>1){
				aPoint.Y = parseInt(toobject.style.height);
			}else{
				aPoint.Y = toobject.offsetHeight;
			}			
		}
	}catch(e){;}
	return aPoint;
}

function btnok_onclick(){hideAlert();}

function insertAlertHTML(){
	try {
		var alerttableHTML = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"  id=\"alertobj\" class=\"alertobj rowinvisible\">";
		alerttableHTML += "	<tr id=\"dzutr\"><td id=\"dzucontainer\"><img src=\"/images/dziobek_u.gif\" alt=\"\" name=\"dzu\" id=\"dzu\" width=\"7\" height=\"7\" border=\"0\" class=\"alertobjsignup\"></td></tr>";
		alerttableHTML += "	<tr><td><div id=\"alertobjroundedframe1\" class=\"alertobjroundedframe1\"><!--  --></div></td></tr>";
		alerttableHTML += "	<tr><td><div id=\"alertobjroundedframe2\" class=\"alertobjroundedframe2\"><!--  --></div></td></tr>";
		alerttableHTML += "	<tr id=\"alertobjtitlerow\"><td id=\"alertobjtitle\" class=\"alertobjtitle\"></td></tr>";
		alerttableHTML += "	<tr><td id=\"alertobjtext\" class=\"alertobjtext\"></td></tr>";
		alerttableHTML += "	<tr><td id=\"alertobjbuttons\" class=\"alertobjbuttons\" align=\"center\"></td></tr>";
		alerttableHTML += "	<tr><td><div id=\"alertobjroundedframe3\" class=\"alertobjroundedframe3\"><!--  --></div></td></tr>";
		alerttableHTML += "	<tr><td><div id=\"alertobjroundedframe1\" class=\"alertobjroundedframe1\"><!--  --></div></td></tr>";
		alerttableHTML += "	<tr id=\"dzdtr\"><td id=\"dzdcontainer\"><img src=\"/images/dziobek_d.gif\" alt=\"\" name=\"dzd\" id=\"dzd\" width=\"7\" height=\"7\" border=\"0\" class=\"alertobjsignup\"></td></tr>";
		alerttableHTML += "</table>";
		document.getElementById("alertcontainer").innerHTML = alerttableHTML;
	}catch(e){;}
}

function showAlert(){
	try{
		HideTimerVal = -1;
		if (!AlertUseFadeEfect){
			document.getElementById("alertobj").className = "alertobj rowvisible";
		}else{
			document.getElementById("alertobj").className = "alertobj rowvisible alertopa10";
			setTimeout("setOpa(20)",200)
		}
	}catch(e){;}	
}

function hideTimerAlert(){
	try{
		HideTimerVal = -1;
		setTimeout("HideTimerVal=100;decHideTimerAlert();", 100);
	}catch(e){;}
}

function decHideTimerAlert(){
	try{
		if (HideTimerVal > 0) {
			HideTimerVal--;
			setTimeout("decHideTimerAlert();", 100);
		}
		if (HideTimerVal==0) {
			hideAlert();
			HideTimerVal=-1;
		}
	}catch(e){;}	
}

function hideAlert(){
	try{
		if (document.getElementById("alertobj").className != "alertobj rowinvisible"){
			if (!AlertUseFadeEfect){
				document.getElementById("alertobj").className = "alertobj rowinvisible";
			}else{
				setUnOpa(90);
			}
		}
	}catch(e){;}
}

function setOpa(opa){
	try{
		if (opa<100){
			var newopa = opa+10;
			var classstr = "alertobj rowvisible alertopa"+opa;
			document.getElementById("alertobj").className = classstr;
			setTimeout("setOpa("+newopa+")",30)
		}
		if (opa==100){
			var classstr = "alertobj rowvisible";
			document.getElementById("alertobj").className = classstr;
		}
	}catch(e){;}
}

function setUnOpa(opa){
	try{
		if (document.getElementById("alertobj").className != "alertobj rowinvisible"){
			if (opa>0){
					var newopa = opa-10;
					var classstr = "alertobj rowvisible alertopa"+opa;
					document.getElementById("alertobj").className = classstr;
					setTimeout("setUnOpa("+newopa+")",30)
			}
			if (opa==0){
				var classstr = "alertobj rowinvisible";
				document.getElementById("alertobj").className = classstr;
			}
		}
	}catch(e){;}
}

// funkje alerta Layerowego - stop 

// funkcje dla selecta dla ie 6 i starsze  - start
var selPrepared = 0;
var selchanged = false;
var winresize = 0;
function restoreselects(){
	for(i = 0; i < document.all.length; i++){
		obj = document.all(i);
		if (obj.className == "selectemublock"){
			obj.style.display = "none";
			obj.style.display = "block";
		}
	}
}

function waitforendresize(a){
	if (a>0) {
		winresize = a;
	}
	if (a==0) {winresize = winresize-1;}
	if (winresize == 0){
		restoreselects();
	}
	setTimeout("waitforendresize(0)",200);
}

function pageresized(){
	waitforendresize(3);
}

function changeSelects(){
	var selArray = new Array();
		window.onresize = pageresized;
		for(i = 0; i < document.all.length; i++){
			obj = document.all(i);
			if (obj.tagName.toUpperCase()=="SELECT"){
				try{
					selArray[selArray.length] = obj;
				}catch(e){;}
			}
		}
		if (selArray.length >0){
			for (j = 0; j < selArray.length; j++){
				if (selArray[j]){
					try{
						prepareSelect(selArray[j]);
					}catch(e){;}
				}
			}
		}
}

function prepareSelect(obj){
	var s = "";
	var objoffset = 11;
	var currenturl = document.location.href;
	try{
		if (obj){
			if ((obj.dataFld != "changed")&&(obj.dataFld != "changedfocused")&&((obj.size==1)||(obj.size==""))){
				selPrepared++;
				tekst = obj.options[obj.selectedIndex].text;
				obj.dataFld = "changed";
				onblur = "try{document.getElementById('selcontainer"+selPrepared+"').style.display='none';document.getElementById('emucontainer"+selPrepared+"').style.display='inline';document.getElementById('emucontainerdiv"+selPrepared+"').innerHTML = document.all("+(obj.sourceIndex+objoffset)+").options[document.all("+(obj.sourceIndex+objoffset)+").selectedIndex].text;}catch(e){;}";
				obj.onblur = "this.dataFld='changed';"+onblur;
				obj.onfocus = "this.dataFld='changedfocused';";
				obj.className = obj.className+" ieselectmargin";
				obj.onmouseout = "if (this.dataFld == 'changed'){"+onblur+"}";
				objSize = getObjSize(obj);
				
				if (objSize.Y == 0) {
					objSize.Y = 25;
				}
				if (obj.offsetWidth==0){
					if ((obj.style.width).length>1){
						objSize.X = parseInt(obj.style.width)+4;
					}else{
						objSize.X = 170;
					}
				}
				if (objSize.X == 0) {
					objSize.X = 170;
				}
				objSize.X = objSize.X;
				sindex = obj.sourceIndex;
				styletext = "position:relative;top: -2;width:"+(objSize.X-6)+"px;display:inline;";
				styletext2 = "position:relative;width: "+(objSize.X-24)+"px;height: "+(objSize.Y-5)+"px"
				onmousemove = "document.getElementById('emucontainer"+selPrepared+"').style.display='none';document.getElementById('selcontainer"+selPrepared+"').style.display='inline';";
				onfocustext = onmousemove+"setTimeout('document.all("+(obj.sourceIndex+objoffset)+").focus();',10);" ;
				onclicktext = onfocustext+"setTimeout('document.all("+(obj.sourceIndex+objoffset)+").click();',100);"
				s="<div class=\"selectemublock\"><table border=\"0\" cellspacing=\"0\" cellpadding=\"0\" class=\"selectemu\" id=\"emucontainer"+selPrepared+"\" style=\""+styletext+"\" onmousemove=\""+onmousemove+"\">";
				s+="<tr><td class=\"emucontainerdivtd\">";
				s+="<div TABINDEX=0 id=\"emucontainerdiv"+selPrepared+"\" class=\"ttselbtntext\" style=\""+styletext2+"\"  onfocus=\""+onfocustext+"\" onclick=\""+onclicktext+"\">"+tekst+"</div>";
				s+="</td><td class=\"emucontbtn\">"+getSelBtnHtml(objSize.X-4,objSize.Y-6,onfocustext)+"</td>";
				s+="</tr></table>";
				s+="<div id=\"selcontainer"+selPrepared+"\" style=\"display:none\">"+obj.outerHTML+"</div></div>";
				obj.outerHTML = s;
				if (currenturl.indexOf("dodebug")>=0){
					alert(s);
				}
			}
		}
	}catch(e){;}
}

function getSelBtnHtml(x,y,onfocustext){
	var s = "<div style=\"float:right;height: "+y+"px; width: 16px;\" class=\"ttselbtn0\" onclick=\""+onfocustext+"\"><div class=\"ttselbtn1\"><div style=\"float:left; width: 14px;height: "+(y-3)+"px;\" class=\"ttselbtn2\"></div></div></div>";
	return s;
}

function getInternetExplorerVersion()
{
  var rv = -1; 
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}


function doChangeSelects(){
	try{
		var currenturl = document.location.href;
		if (currenturl.indexOf("checklayerselect")>=0){
			changeSelects();
		}else{
			if (document.all){
				var mver = getInternetExplorerVersion();
				if ((mver < 7) && (currenturl.indexOf(".interia.")==0)){
					if (currenturl.indexOf("edit-form2")<0){
						changeSelects();
					}
				}
			}
		}
	}catch(e){;}
}
//funkcja porownuje ciagi znakow uwzgledniajac polskie literki, uzywana jako parametr do array.sort()
function sortPL(a,b)
{
	if (a == b)
	{
		return 0;
	}
	else
	{
		var x, y, z;
		z = " !\"#$%&'()*+,-./0123456789:;<=>?@";
		z = z+"AaĄąBbCcĆćDdEeĘęFfGgHhIiJjKkLlŁłMmNnŃńOoÓó";
		z = z+"PpQqRrSsŚśTtUuVvWwXxYyZzŹźŻż[\\]^_`{|}~";
		for (i=0;i<a.length,i<b.length;i++)
		{
			x = a.toString().substr(i,1);
			y = b.toString().substr(i,1);
			if (x==y)
			{
				continue;
			}
			else
			{
				if (z.indexOf(x) < z.indexOf(y))
				{
					return -1;
				}
				else
				{
					return 1;
				}
			}
		}
	}
	if (a.length < b.length)
	{
		return -1;
	}
	else
	{
		return 1;
	}
}

function urlEncodeChar(c){
	var retVal = c;
	var encchars = String.fromCharCode(32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,58,59);
	encchars += String.fromCharCode(60,61,62,63,64,91,92,93,94,95,96,123,124,125,126,127,8364);
	encchars += String.fromCharCode(129,8218,131,8222,8230,8224,8225,136,8240,352,8249,346,356);
	encchars += String.fromCharCode(381,377,144,8216,8217,8220,8221,8226,8211,8212,152,8482,353);
	encchars += String.fromCharCode(8250,347,357,382,378,32,711,728,321,164,260,166,167,168,169);
	encchars += String.fromCharCode(350,171,172,173,174,379,176,177,731,322,180,181,182,183,184);
	encchars += String.fromCharCode(261,351,187,317,733,318,380,340,193,194,258,196,313,262,199);
	encchars += String.fromCharCode(268,201,280,203,282,205,206,270,272,323,327,211,212,336);
	encchars += String.fromCharCode(214215,344,366,218,368,220,221,354,223,341,225,226,259,228);
	encchars += String.fromCharCode(314,263,231,269,233,281,235,283,237,238,271,273,324,328,243);
	encchars += String.fromCharCode(244,337,246,247,345,367,250,369,252,253,355,729);
	var encarray = new Array(
		new Array(String.fromCharCode(32),"+"),
		new Array(String.fromCharCode(33),String.fromCharCode(37)+"21"),
		new Array(String.fromCharCode(92),String.fromCharCode(37)+"22"),
		new Array(String.fromCharCode(35),String.fromCharCode(37)+"23"),
		new Array(String.fromCharCode(36),String.fromCharCode(37)+"24"),
		new Array(String.fromCharCode(37),String.fromCharCode(37)+"25"),
		new Array(String.fromCharCode(38),String.fromCharCode(37)+"26"),
		new Array(String.fromCharCode(39),String.fromCharCode(37)+"27"),
		new Array(String.fromCharCode(40),String.fromCharCode(37)+"28"),
		new Array(String.fromCharCode(41),String.fromCharCode(37)+"29"),
		new Array(String.fromCharCode(42),String.fromCharCode(37)+"2A"),
		new Array(String.fromCharCode(43),String.fromCharCode(37)+"2B"),
		new Array(String.fromCharCode(34),String.fromCharCode(37)+"2C"),
		new Array(String.fromCharCode(45),String.fromCharCode(37)+"2D"),
		new Array(String.fromCharCode(46),String.fromCharCode(37)+"2E"),
		new Array(String.fromCharCode(47),String.fromCharCode(37)+"2F"),
		new Array(String.fromCharCode(58),String.fromCharCode(37)+"3A"),
		new Array(String.fromCharCode(59),String.fromCharCode(37)+"3B"),
		new Array(String.fromCharCode(60),String.fromCharCode(37)+"3C"),
		new Array(String.fromCharCode(61),String.fromCharCode(37)+"3D"),
		new Array(String.fromCharCode(62),String.fromCharCode(37)+"3E"),
		new Array(String.fromCharCode(63),String.fromCharCode(37)+"3F"),
		new Array(String.fromCharCode(64),String.fromCharCode(37)+"40"),
		new Array(String.fromCharCode(91),String.fromCharCode(37)+"5B"),
		new Array(String.fromCharCode(92),String.fromCharCode(37)+"5C"),
		new Array(String.fromCharCode(93),String.fromCharCode(37)+"5D"),
		new Array(String.fromCharCode(94),String.fromCharCode(37)+"5E"),
		new Array(String.fromCharCode(95),String.fromCharCode(37)+"5F"),
		new Array(String.fromCharCode(96),String.fromCharCode(37)+"60"),
		new Array(String.fromCharCode(123),String.fromCharCode(37)+"7B"),
		new Array(String.fromCharCode(44),String.fromCharCode(37)+"7C"),
		new Array(String.fromCharCode(125),String.fromCharCode(37)+"7D"),
		new Array(String.fromCharCode(126),String.fromCharCode(37)+"7E"),
		new Array(String.fromCharCode(127),String.fromCharCode(37)+"7F"),
		new Array(String.fromCharCode(8364),String.fromCharCode(37)+"80"),
		new Array(String.fromCharCode(129),String.fromCharCode(37)+"81"),
		new Array(String.fromCharCode(8218),String.fromCharCode(37)+"82"),
		new Array(String.fromCharCode(131),String.fromCharCode(37)+"83"),
		new Array(String.fromCharCode(8222),String.fromCharCode(37)+"84"),
		new Array(String.fromCharCode(8230),String.fromCharCode(37)+"85"),
		new Array(String.fromCharCode(8224),String.fromCharCode(37)+"86"),
		new Array(String.fromCharCode(8225),String.fromCharCode(37)+"87"),
		new Array(String.fromCharCode(136),String.fromCharCode(37)+"88"),
		new Array(String.fromCharCode(8240),String.fromCharCode(37)+"89"),
		new Array(String.fromCharCode(352),String.fromCharCode(37)+"8A"),
		new Array(String.fromCharCode(8249),String.fromCharCode(37)+"8B"),
		new Array(String.fromCharCode(346),String.fromCharCode(37)+"8C"),
		new Array(String.fromCharCode(356),String.fromCharCode(37)+"8D"),
		new Array(String.fromCharCode(381),String.fromCharCode(37)+"8E"),
		new Array(String.fromCharCode(377),String.fromCharCode(37)+"8F"),
		new Array(String.fromCharCode(144),String.fromCharCode(37)+"90"),
		new Array(String.fromCharCode(8216),String.fromCharCode(37)+"91"),
		new Array(String.fromCharCode(8217),String.fromCharCode(37)+"92"),
		new Array(String.fromCharCode(8220),String.fromCharCode(37)+"93"),
		new Array(String.fromCharCode(8221),String.fromCharCode(37)+"94"),
		new Array(String.fromCharCode(8226),String.fromCharCode(37)+"95"),
		new Array(String.fromCharCode(8211),String.fromCharCode(37)+"96"),
		new Array(String.fromCharCode(8212),String.fromCharCode(37)+"97"),
		new Array(String.fromCharCode(152),String.fromCharCode(37)+"98"),
		new Array(String.fromCharCode(8482),String.fromCharCode(37)+"99"),
		new Array(String.fromCharCode(353),String.fromCharCode(37)+"9A"),
		new Array(String.fromCharCode(8250),String.fromCharCode(37)+"9B"),
		new Array(String.fromCharCode(347),String.fromCharCode(37)+"9C"),
		new Array(String.fromCharCode(357),String.fromCharCode(37)+"9D"),
		new Array(String.fromCharCode(382),String.fromCharCode(37)+"9E"),
		new Array(String.fromCharCode(378),String.fromCharCode(37)+"9F"),
		new Array(String.fromCharCode(32),String.fromCharCode(37)+"A0"),
		new Array(String.fromCharCode(711),String.fromCharCode(37)+"A1"),
		new Array(String.fromCharCode(728),String.fromCharCode(37)+"A2"),
		new Array(String.fromCharCode(321),String.fromCharCode(37)+"A3"),
		new Array(String.fromCharCode(164),String.fromCharCode(37)+"A4"),
		new Array(String.fromCharCode(260),String.fromCharCode(37)+"A5"),
		new Array(String.fromCharCode(166),String.fromCharCode(37)+"A6"),
		new Array(String.fromCharCode(167),String.fromCharCode(37)+"A7"),
		new Array(String.fromCharCode(168),String.fromCharCode(37)+"A8"),
		new Array(String.fromCharCode(169),String.fromCharCode(37)+"A9"),
		new Array(String.fromCharCode(350),String.fromCharCode(37)+"AA"),
		new Array(String.fromCharCode(171),String.fromCharCode(37)+"AB"),
		new Array(String.fromCharCode(172),String.fromCharCode(37)+"AC"),
		new Array(String.fromCharCode(173),String.fromCharCode(37)+"AD"),
		new Array(String.fromCharCode(174),String.fromCharCode(37)+"AE"),
		new Array(String.fromCharCode(379),String.fromCharCode(37)+"AF"),
		new Array(String.fromCharCode(176),String.fromCharCode(37)+"B0"),
		new Array(String.fromCharCode(177),String.fromCharCode(37)+"B1"),
		new Array(String.fromCharCode(731),String.fromCharCode(37)+"B2"),
		new Array(String.fromCharCode(322),String.fromCharCode(37)+"B3"),
		new Array(String.fromCharCode(180),String.fromCharCode(37)+"B4"),
		new Array(String.fromCharCode(181),String.fromCharCode(37)+"B5"),
		new Array(String.fromCharCode(182),String.fromCharCode(37)+"B6"),
		new Array(String.fromCharCode(183),String.fromCharCode(37)+"B7"),
		new Array(String.fromCharCode(184),String.fromCharCode(37)+"B8"),
		new Array(String.fromCharCode(261),String.fromCharCode(37)+"B9"),
		new Array(String.fromCharCode(351),String.fromCharCode(37)+"BA"),
		new Array(String.fromCharCode(187),String.fromCharCode(37)+"BB"),
		new Array(String.fromCharCode(317),String.fromCharCode(37)+"BC"),
		new Array(String.fromCharCode(733),String.fromCharCode(37)+"BD"),
		new Array(String.fromCharCode(318),String.fromCharCode(37)+"BE"),
		new Array(String.fromCharCode(380),String.fromCharCode(37)+"BF"),
		new Array(String.fromCharCode(340),String.fromCharCode(37)+"C0"),
		new Array(String.fromCharCode(193),String.fromCharCode(37)+"C1"),
		new Array(String.fromCharCode(194),String.fromCharCode(37)+"C2"),
		new Array(String.fromCharCode(258),String.fromCharCode(37)+"C3"),
		new Array(String.fromCharCode(196),String.fromCharCode(37)+"C4"),
		new Array(String.fromCharCode(313),String.fromCharCode(37)+"C5"),
		new Array(String.fromCharCode(262),String.fromCharCode(37)+"C6"),
		new Array(String.fromCharCode(199),String.fromCharCode(37)+"C7"),
		new Array(String.fromCharCode(268),String.fromCharCode(37)+"C8"),
		new Array(String.fromCharCode(201),String.fromCharCode(37)+"C9"),
		new Array(String.fromCharCode(280),String.fromCharCode(37)+"CA"),
		new Array(String.fromCharCode(203),String.fromCharCode(37)+"CB"),
		new Array(String.fromCharCode(282),String.fromCharCode(37)+"CC"),
		new Array(String.fromCharCode(205),String.fromCharCode(37)+"CD"),
		new Array(String.fromCharCode(206),String.fromCharCode(37)+"CE"),
		new Array(String.fromCharCode(270),String.fromCharCode(37)+"CF"),
		new Array(String.fromCharCode(272),String.fromCharCode(37)+"D0"),
		new Array(String.fromCharCode(323),String.fromCharCode(37)+"D1"),
		new Array(String.fromCharCode(327),String.fromCharCode(37)+"D2"),
		new Array(String.fromCharCode(211),String.fromCharCode(37)+"D3"),
		new Array(String.fromCharCode(212),String.fromCharCode(37)+"D4"),
		new Array(String.fromCharCode(336),String.fromCharCode(37)+"D5"),
		new Array(String.fromCharCode(214),String.fromCharCode(37)+"D6"),
		new Array(String.fromCharCode(215),String.fromCharCode(37)+"D7"),
		new Array(String.fromCharCode(344),String.fromCharCode(37)+"D8"),
		new Array(String.fromCharCode(366),String.fromCharCode(37)+"D9"),
		new Array(String.fromCharCode(218),String.fromCharCode(37)+"DA"),
		new Array(String.fromCharCode(368),String.fromCharCode(37)+"DB"),
		new Array(String.fromCharCode(220),String.fromCharCode(37)+"DC"),
		new Array(String.fromCharCode(221),String.fromCharCode(37)+"DD"),
		new Array(String.fromCharCode(354),String.fromCharCode(37)+"DE"),
		new Array(String.fromCharCode(223),String.fromCharCode(37)+"DF"),
		new Array(String.fromCharCode(341),String.fromCharCode(37)+"E0"),
		new Array(String.fromCharCode(225),String.fromCharCode(37)+"E1"),
		new Array(String.fromCharCode(226),String.fromCharCode(37)+"E2"),
		new Array(String.fromCharCode(259),String.fromCharCode(37)+"E3"),
		new Array(String.fromCharCode(228),String.fromCharCode(37)+"E4"),
		new Array(String.fromCharCode(314),String.fromCharCode(37)+"E5"),
		new Array(String.fromCharCode(263),String.fromCharCode(37)+"E6"),
		new Array(String.fromCharCode(231),String.fromCharCode(37)+"E7"),
		new Array(String.fromCharCode(269),String.fromCharCode(37)+"E8"),
		new Array(String.fromCharCode(233),String.fromCharCode(37)+"E9"),
		new Array(String.fromCharCode(281),String.fromCharCode(37)+"EA"),
		new Array(String.fromCharCode(235),String.fromCharCode(37)+"EB"),
		new Array(String.fromCharCode(283),String.fromCharCode(37)+"EC"),
		new Array(String.fromCharCode(237),String.fromCharCode(37)+"ED"),
		new Array(String.fromCharCode(238),String.fromCharCode(37)+"EE"),
		new Array(String.fromCharCode(271),String.fromCharCode(37)+"EF"),
		new Array(String.fromCharCode(273),String.fromCharCode(37)+"F0"),
		new Array(String.fromCharCode(324),String.fromCharCode(37)+"F1"),
		new Array(String.fromCharCode(328),String.fromCharCode(37)+"F2"),
		new Array(String.fromCharCode(243),String.fromCharCode(37)+"F3"),
		new Array(String.fromCharCode(244),String.fromCharCode(37)+"F4"),
		new Array(String.fromCharCode(337),String.fromCharCode(37)+"F5"),
		new Array(String.fromCharCode(246),String.fromCharCode(37)+"F6"),
		new Array(String.fromCharCode(247),String.fromCharCode(37)+"F7"),
		new Array(String.fromCharCode(345),String.fromCharCode(37)+"F8"),
		new Array(String.fromCharCode(367),String.fromCharCode(37)+"F9"),
		new Array(String.fromCharCode(250),String.fromCharCode(37)+"FA"),
		new Array(String.fromCharCode(369),String.fromCharCode(37)+"FB"),
		new Array(String.fromCharCode(252),String.fromCharCode(37)+"FC"),
		new Array(String.fromCharCode(253),String.fromCharCode(37)+"FD"),
		new Array(String.fromCharCode(355),String.fromCharCode(37)+"FE"),
		new Array(String.fromCharCode(729),String.fromCharCode(37)+"FF")
	)
	if (encchars.indexOf(c)>0){
		for (i = 0; i < encarray.length; i++){
			carray = encarray[i];
			if (c==carray[0]) retVal = carray[1];
		}
	}
	return retVal;
}

function urlEncode(s)
{
	ret = "";
	if (s.length>0){
		for (var i=1;i<=s.length;i++) ret = ret+urlEncodeChar(s.charAt(i-1));
	}
	return ret;
}
// funkcje dla selecta dla ie 6 i starsze  - stop 

// rss client functions start 
var RssTitle = "";
var RssUrl = "";
var MoreUrl = "";

function getRssReader(){
	var RssReader;
	if (window.XMLHttpRequest) { 
		RssReader = new XMLHttpRequest();
		if (RssReader.overrideMimeType) {
			RssReader.overrideMimeType("text/xml");
		}
	} else if (window.ActiveXObject) { 
		try {
				RssReader = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					RssReader = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {;}
			}
	}
	return RssReader;
}

function getRssData(url){
	var RssReader =  getRssReader();
	if (RssReader) {
		RssReader.onreadystatechange = function() { retrieveRssData(RssReader); };
		//prompt('','/rss/rssgetter.asp?rssurl='+urlEncode(url))
		RssReader.open('GET', '/rss/rss-getter.asp?rssurl='+urlEncode(url), true);
		
		RssReader.send(null);
	}else{alert("Nie można utworzyć obiektu komunikacji AJAX")};
}

function retrieveRssData(RssReader){
	if (RssReader.readyState <= 3) {
	}
	if (RssReader.readyState == 4) {
      	if (RssReader.status == 200) {
			var xmlDoc=RssReader.responseXML.documentElement;
			processRssResponse(xmlDoc);
		}else{
			alert("Nie można przetworzyć zapytania AJAX - "+RssReader.status)
		}
	}
}

function HtmlStrip(stringwithhtml)
{
  var re = new RegExp("<.*?>","ig");
  return stringwithhtml.replace(re,"");
}

function processRssResponse(xmlDoc){
	var resultHTML = "";
	var items = new Array();
	var s = "";
	var rssitem;
	for (i=0;i<xmlDoc.childNodes.length;i++)
	{
		childNode = xmlDoc.childNodes[i];
		if (childNode.tagName == "channel")
		{
			for (j=0;j<childNode.childNodes.length;j++)
			{
				channelNode = childNode.childNodes[j];
				if (channelNode.tagName == "item"){
					rssitem = new rssItem;
					for (k=0;k<channelNode.childNodes.length;k++){
						itemNode = channelNode.childNodes[k];
						if (itemNode.tagName != undefined)
						{
							if (itemNode.tagName.toLowerCase() == "title"){
								if (itemNode.text){
									rssitem.title = itemNode.text;
								}else{rssitem.title = itemNode.textContent}
							}
							if (itemNode.tagName.toLowerCase() == "link"){
								if (itemNode.text){
									rssitem.url = itemNode.text;
								}else{rssitem.url = itemNode.textContent}
							}
							if (itemNode.tagName.toLowerCase() == "description"){
								var desc = "";
								if (itemNode.text){
									desc = itemNode.text;
								}else{
									var desc = itemNode.textContent;
								}
									desc = HtmlStrip(desc);
									rssitem.description = desc;
							}
							if (itemNode.tagName.toLowerCase() == "enclosure"){
								pictureNode = itemNode.attributes.getNamedItem("url");
								if (pictureNode.text){
									rssitem.picture = pictureNode.text;
								}else{rssitem.picture = pictureNode.textContent}
							}
							if (itemNode.tagName.toLowerCase() == "pubdate"){
								curdate = new Date(Date.parse(itemNode.text));
								rssitem.pubdate = curdate;
							}
						}
					}
					items[items.length] = rssitem;
				}
				
			}
		}
	}
	displayRssItems(items);
}

function displayRssItems(rssItems){
	var retVal = "";
	var titleMaxLen = 45;
	for (i = 0;(i < rssItems.length) && (i < 5); i++ ){
		rssitem = rssItems[i];
		retVal += "<div class=\"rssItem\">";
		var s = "";
		var title = "";
		if (rssitem.title.length > 0){
			s = rssitem.title;
			title = s;
			if (s.length > titleMaxLen){
				s = s.substr(0,titleMaxLen)
				s = s.substr(0,s.lastIndexOf(" "));
				s += " ...";
			}
			if (rssitem.url.length > 0){
				s = "<a href=\""+rssitem.url+"\" target=\"_blank\" onmouseout=\"javascript:hideRssInfo("+i+");\" onmouseover=\"javascript:showRssInfo("+i+");\">"+s+"</a>"
			}
			retVal += "<div class=\"rssTitle\" id=\"rssTitle_"+i+"\"><img src=\"/images/pl/reklama/red_arrow.gif\" align=\"baseline\" class=\"rssTitlePointer\">"+s+"</div>\n"
		}
		if (rssitem.description.length > 0){
			s = rssitem.description;
			retVal += "<div class=\"rssDescription\" id=\"rssDescription_"+i+"\">";
			retVal += "<div class=\"rssDescriptionTitle\">"+title+"</div>";
			if (rssitem.picture.length > 0){
				s = "<table class=\"rssDescription_table\"><tr><td valign=\"top\"><img src=\""+rssitem.picture+"\" width=\"60\" class=\"rssPicture\"></td><td valign=\"top\">"+s+"</td></tr></table>"
			}
			
			retVal +=s+"</div>\n"
		}
		retVal += "</div>\n"
	}
	insertRssReader();
	document.getElementById("rssreader").innerHTML = retVal;
}

function rssItem(){
	this.title = "";
	this.description = "";
	this.url = "";
	this.picture = "";
	this.pubdate = null;
	this.info = function()
	{
		var retVal = "";
		retVal += "title: ["+this.title+"]\n";
		retVal += "description: ["+this.description+"]\n";
		retVal += "url: ["+this.url+"]\n";
		retVal += "picture: ["+this.picture+"]\n";
		return retVal
	} 
}


function showRssInfo(i){
	var alertPos = getAbsoluteObjPos(document.getElementById("rssTitle_"+i));
	//alertPos.X = 500;
	//alertPos.Y = 500;
	var titleHeight = getObjSize(document.getElementById("rssTitle_"+i));
	var displayposy = (alertPos.Y+titleHeight.Y+10)+"px" ;
	var displayposx = (alertPos.X+10)+"px" ;
	
	//alert("alertPos = "+alertPos.toString()+"\ndisplayposy="+displayposy+"\ndisplayposx="+displayposx)
	document.getElementById("rssInfoContainer").innerHTML = document.getElementById("rssDescription_"+i).innerHTML;
	document.getElementById("rssInfoContainer").style.top = displayposy;
	document.getElementById("rssInfoContainer").style.left = displayposx;
	document.getElementById("rssInfoContainer").style.display = "block";
}

function hideRssInfo(i){
	document.getElementById("rssInfoContainer").style.display = "none";
}

function insertRssReader(){
	var s = "";
	s += "	<table class=\"rss-table\" width=\"280\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
	s += "		<tbody>";
	s += "			<tr><td class=\"rss-table-title\" valign=\"top\" width=\"100%\">";
	s += "				<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td width=\"100%\"  class=\"rss-table-title-info\">"+RssTitle+"</td><td class=\"rss-table-title-subinfo\"><span class=\"rss-table-title-subinfo_a\"><a href=\""+RssUrl+"\">RSS</a>&nbsp;</span><a href=\""+RssUrl+"\"><img src=\"/images/rss-icon.gif\" border=\"0\" align=\"absmiddle\" alt=\"\"></a>&nbsp;&nbsp;</td></tr></table>";
	s += "			</td></tr>";
	s += "			<tr><td><div id=\"rssreader\" class=\"rssReaderData\"></div>";
	s += "			<div class=\"RssMore\"><a href=\""+MoreUrl+"\" target=\"_blank\">więcej</a>&nbsp;</div>";
	s += "			</td></tr>";
	s += "			<tr><td class=\"rss-table-end\" align=\"right\"><img src=\"/images/t.gif\" alt=\"\"></td></tr>";
	s += "		</tbody>";
	s += "	</table>";
	s += "<div id=\"rssInfoContainer\" style=\"position: absolute;display: none;\" ></div>";
	if (document.getElementById("rssClient")){
		document.getElementById("rssClient").innerHTML = s;
	}

}

function insertRss(locRssTitle,locRssUrl,locMoreUrl){
	RssTitle = locRssTitle;
	RssUrl = locRssUrl;
	MoreUrl = locMoreUrl;
	getRssData(locRssUrl);
}
// rss client functions stop 

// funkcje z głownej strony domiporta - start
function PrzepiszDzielnice(){
	dzielnica2=document.getElementById('Dzielnica2');
	var tmp="";
	for (i=0;i<dzielnica2.length;i++){
		if(dzielnica2[i].selected){
			if (tmp!=""){
				tmp+=",";
			}
			tmp+=dzielnica2[i].value;
		}
	}
	document.getElementById('Dzielnica').value=tmp;
}

function CheckOperacja(){
	if (document.getElementById('CategoryId').value!=""){
		CategoryId=document.getElementById('CategoryId').value;
		var selarrayTRN = new Array();
		for (i=0;i<OperacjaListValue[CategoryId].length;i++)
		{
			selarrayTRN[i] = new Array(OperacjaListName[CategoryId][i],OperacjaListValue[CategoryId][i],(i==0),"TRN");
		}
		fillSelect(selarrayTRN, "TRN");
		setSize("TRN");
	}
}

function CheckMiasto(){
	miasto=document.forms['form']['Miasto'].value;
	miasto=miasto.toLowerCase();
	if(myMiasto.toLowerCase()!=miasto){
		if (my_dzielnice[miasto]==null){
			document.getElementById("Dzielnica").style.display="block";
			document.getElementById("Dzielnica2").style.display="none";

		}else{
			document.getElementById("Dzielnica").style.display="none";
			document.getElementById("Dzielnica2").style.display="block";
			document.getElementById('Dzielnica2').length=0;			
			for (i=0;i<my_dzielnice[miasto].length;i++){

				document.getElementById('Dzielnica2').options[i]=new Option(my_dzielnice[miasto][i], my_dzielnice[miasto][i]);
				if(SelectedDzielnica==my_dzielnice[miasto][i]){
					document.forms['form']['tmpDzielnica'][i].selected=1;
				}
			}
		}
	}
	if (myMiasto!=document.getElementById('Miasto').value){
		myMiasto=document.getElementById('Miasto').value;
	}
}
// funkcje z głownej strony domiporta - stop

// funkcje przeniesione z validateforms - start
if (document.layers) {
  document.captureEvents(Event.KEYDOWN);
  document.captureEvents(Event.KEYPRESS);
  document.captureEvents(Event.KEYUP);
}

document.onkeydown = traderValidateForms;
document.onkeypress = traderValidateForms;
document.onkeyup = traderValidateForms;

var validTraderDate = "xxxx-xx-xx";
var validTraderTime = "xx:xx:xx";
var validTraderDateTime = "xxxx-xx-xx xx:xx:xx";

function getValidClassName(target)
{
	var retVal = "";
	var className = target.className;
	if (className && className.length > 0)
	{
		className = className.toLowerCase();
		var classArray = (className+" ").split(" ");
		for (i = 0; i < classArray.length ; i++)
		{
			s = classArray[i].toLowerCase();
			if (s.indexOf("integer")==0) retVal  = s;
			if (s.indexOf("float")==0) retVal  = s;
			if (s.indexOf("buildyear")==0) retVal  = s;
			if (s.indexOf("date")==0) retVal  = s;
			if (s.indexOf("datetime")==0) retVal  = s;
			if (s.indexOf("time")==0) retVal  = s;
			if (s.indexOf("string")==0) retVal  = s;
			if (s.indexOf("inputemail")==0) retVal  = s;
		}
	}
	return retVal;
}

function traderValidateForms(e) {
	var target
		if (document.all){
			target = window.event.srcElement;
		}else{
			target = e.target
		};
		
		var className = getValidClassName(target);
		aRange=getRange(target);
		if (className.substr(0, 7) == "integer"){
			var tmpMaxSize = getTraderValidNumber(className);
			var value = target.value;
			if (value.length > 0){
				value = getTraderValidNumber(value);
				if (!isNaN(parseInt(aRange.to))){
					value = checkValue(value,aRange.to);
				}
				if (!isNaN(parseInt(value))) {
					if (target.value != parseInt(value)) {
						target.value = parseInt(value);
					}
				}else{target.value = ""}
			}
		}
					
		if (className.substr(0, 9) == "buildyear"){
			var value = target.value;
			value = checkBuildYear(value)
			if (target.value != value) target.value = value;
		}
		
		if (className.substr(0, 5) == "float"){
			var value = target.value;
			value = value.replace(",",".");
			value = getTraderValidNumber(value);
			
			if (!isNaN(parseFloat(aRange.to))){
				value = checkValue(value,aRange.to);
			}
			if (!isNaN(parseFloat(value))) {
				if (target.value != value) target.value = value;
			}else{
				target.value = "";
			}
		}
		
		if (className.substr(0, 4) == "date"){
			var value = target.value;
			value = checkTraderDateTimeMask(validTraderDate,value)
			if (target.value != value) target.value = value;
		}
		
		if (className.substr(0, 8) == "datetime"){
			var value = target.value;
			value = checkTraderDateTimeMask(validTraderDateTime,value)
			if (target.value != value) target.value = value;
		}
		
		if (className.substr(0, 4) == "time"){
			var value = target.value;
			value = checkTraderDateTimeMask(validTraderTime,value)
			if (target.value != value) target.value = value;
		}

		if (className.substr(0, 6) == "string"){
			var tmpMaxSize = getTraderValidNumber(className)
			if (!isNaN(parseInt(tmpMaxSize))){
				var maxSize = parseInt(tmpMaxSize);
				var value = target.value;
				if (value.length > maxSize) target.value = value.substr(0,maxSize);
			}
		}	
}

function getTraderValidNumber(value){
	var c;
	var retval = "";
	for (var i = 0; i<value.length; i++){
		c = value.substr(i,1);
		if ("0123456789.".indexOf(c) >= 0) retval = retval.concat(c);
	}
	value = retval;
	retval = "";
	var commaexists = false;
	for (var i = (value.length-1); i>=0; i--){
		c = value.substr(i,1);
		if ((c!=".") || (!commaexists)) retval = c+""+retval;
		if (c == ".") commaexists = true;
	}		
	return retval;
}


function getTraderValidDateTimeChars(value){
	var c;
	var retval = "";
	var goodstring = "0123456789-: "
	for (var i = 0; i<value.length; i++){
		c = value.substr(i,1);
		if (goodstring.indexOf(c) >= 0) retval = retval.concat(c);
	}				
	return retval;
}

function checkBuildYear(value){
	if (value.length > 0){
		var aYear = ((1900+(((new Date()).getYear())%1900)).toString()).substr(2,2);
		var rexpstr = "^((18\\d\\d|19\\d\\d|20"+aYear+")|(18\\d|19\\d|20"+aYear.substr(0,1)+")|(18\\d|19\\d|20"+aYear.substr(0,1)+"\\d)|(18|19|20)|(1|2))";
		var re = new RegExp(rexpstr);
		var matchar = value.match(re);
		if (matchar){
			if (matchar.length > 0) {retval = matchar[0]}  else {retval = ""};
		}else{retval = "";}
	}else{retval = ""}
	return retval;
}

function changeDTToMask(value){
	var c;
	var retval = "";
	for (var i = 0; i<value.length; i++){
		c = value.substr(i,1);
		if ("0123456789".indexOf(c) >= 0) {
			retval = retval.concat("x")}else{retval = retval.concat(c)
		}
	}
	return retval;
}

function checkTraderDateTimeMask(mask,value){
	var tmpval = value;
	var validformat=/^\d{4}\-\d{1,2}\-\d{1,2}$/
	if (!validformat.test(value)){
		var retval = "";
		tmpvalmask = "";
		for (var i = 1; i<=tmpval.length;i++){
			tmpvalmask = changeDTToMask(tmpval);
			if (mask.substr(0,i) == tmpvalmask.substr(0,i)) retval = tmpval.substr(0,i)
		} 
	} else retval = value
	return retval;
} 

function checkValue(value,maxvalue){
	var retval = "";
	var c;
	if ((value.length > 0)&&(!isNaN(parseFloat(value)))) {
		value = parseFloat(value); 
		if (value > maxvalue) {
			for (var i = 0; i<value.toString().length; i++){
				c = value.toString().substr(i,1);
				if  (parseFloat(retval.concat(c))<=maxvalue){
					retval = retval.concat(c);
				}
			}
		}else{
			retval = value;
		}
	}
	return retval;
}

function getRange(obj){
	if (document.getElementById("test")) document.getElementById("test").value = "aaa";
	var range = new CRange();
	if (obj){
		var tmp = "";
		var rangestr = "";
		var cname = getValidClassName(obj)
		
		if (cname.length>0){
			cname = cname.replace("\t"," ");
			cname = cname.replace("\t"," ");
			cname = cname.replace("\t"," ");
			cnamear = (cname+" ").split(" ");
			for (i=0;i<cnamear.length;i++){
				tmp = (cnamear[i]).toLowerCase();
				if (tmp.length>0){if (tmp.indexOf("integer")==0) rangestr = tmp.replace("integer","");}
				if (tmp.length>0){if (tmp.indexOf("float")==0) rangestr = tmp.replace("float","");}
				if (tmp.length>0){if (tmp.indexOf("buildyear")==0) rangestr = tmp.replace("buildyear","");}
				if (tmp.length>0){if (tmp.indexOf("date")==0) rangestr = tmp.replace("date","");}
				if (tmp.length>0){if (tmp.indexOf("datetime")==0) rangestr = tmp.replace("datetime","");}
				if (tmp.length>0){if (tmp.indexOf("time")==0) rangestr = tmp.replace("time","");}
				if (tmp.length>0){if (tmp.indexOf("string")==0) rangestr = tmp.replace("string","");}
				if (tmp.length>0){if (tmp.indexOf("inputemail")==0) rangestr = tmp.replace("inputemail","");}
			}
		}
		if (rangestr.length>0){
			if (rangestr.indexOf("^")>=0){
				rangestrar = rangestr.split("^");
				range.from = rangestrar[0];
				range.to = rangestrar[1];
			}else{
				range.to = rangestr;
			}
		}
	}
	if (document.getElementById("test")) document.getElementById("test").value = range.toString();
	return range
}

function ValidateDateInput(input, inputname){
	var validformat=/^\d{4}\-\d{1,2}\-\d{1,2}$/ 
	var returnval=false
	if (!validformat.test(input.value))
		alert("Nieprawidłowy format daty w polu "+inputname+". Proszę wpisać w formacie RRRR-MM-DD")
	else{ 

	var monthfield=input.value.split("-")[1]
	var dayfield=input.value.split("-")[2]
	var yearfield=input.value.split("-")[0]
	var dayobj = new Date(yearfield, monthfield-1, dayfield)

	if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
		alert("Nieprawidłowa data w polu "+inputname)
	else
		returnval=true
	}
	return returnval;
}

function CRange(from,to) {
	if (from){
		this.from=from;
	}else{this.from=""}
	if (to){
		this.to=to;
	}else{this.to=""}
}
function CRangeToString(){return this.from+"^"+this.to;}
CRange.prototype.toString = CRangeToString;

function internalValidateForm(form){
	var ret = true;
	if (form){
		if (form.elements){
			var elem;
			var aRange;
			var msg = "";
			for (i=0;((i<form.elements.length)&&(msg==""));i++){
				elem = form.elements[i];
				if (elem){
					if (elem.type.toLowerCase()=="text"){
						aRange = getRange(elem);
						var basetype = "";							
						var cname = getValidClassName(elem);
						if (cname.length>0){
							cname = cname.replace("\t"," ");
							cname = cname.replace("\t"," ");
							cname = cname.replace("\t"," ");
							cnamear = (cname+" ").split(" ");
							for (i=0;i<cnamear.length;i++){
								tmp = (cnamear[i]).toLowerCase();
								if (tmp.length>0){if (tmp.indexOf("integer")==0) basetype="integer";}
								if (tmp.length>0){if (tmp.indexOf("float")==0) basetype="float";}
								if (tmp.length>0){if (tmp.indexOf("buildyear")==0) basetype="buildyear";}
								if (tmp.length>0){if (tmp.indexOf("date")==0) basetype="date";}
								if (tmp.length>0){if (tmp.indexOf("datetime")==0) basetype="datetime";}
								if (tmp.length>0){if (tmp.indexOf("time")==0) basetype="time";}
								if (tmp.length>0){if (tmp.indexOf("string")==0) basetype="string";}
								if (tmp.length>0){if (tmp.indexOf("inputemail")==0) basetype="inputemail";}
							}
						}							
						if (basetype!=""){
							if ((aRange.toString()).length > 1){
								if (aRange.from.length>0) {
									if ((";integer;float;buildyear;").indexOf(";"+basetype+";") > 0){
										if (parseFloat(elem.value) < parseFloat(aRange.from)) msg += "wartość tego pola musi być większa od: "+aRange.from+"\n";
									}

									if ((";date;datetime;time;").indexOf(";"+basetype+";") > 0){
										if (elem.value < aRange.from) msg += "wartość tego pola musi być większa od: "+aRange.from+"\n";
									}

									if ((";string;inputemail;").indexOf(";"+basetype+";") > 0){
										if (elem.value.length < aRange.from) msg += "ilość znaków tego pola musi być większa od: "+aRange.from+"\n";
									}
								}
								if (aRange.to.length>0) {
									if ((";integer;float;buildyear;").indexOf(";"+basetype+";") > 0){
										if (parseFloat(elem.value) > parseFloat(aRange.to)) msg += "wartość tego pola musi być mniejsza niż: "+aRange.to+"\n";
									}

									if ((";date;datetime;time;").indexOf(";"+basetype+";") > 0){
										if (elem.value > aRange.to) msg += "wartość tego pola musi być mniejsza niż: "+aRange.to+"\n";
									}

									if ((";string;inputemail;").indexOf(";"+basetype+";") > 0){
										if (elem.value.length > aRange.to) msg += "ilość znaków tego pola musi być mniejsza niż: "+aRange.to+"\n";
									}
								}
							}
						}
					}
				}
			}
			if (msg!=""){
				ret = false;
				try{
					showAlertAdv("Błąd formularza",msg,"btn_fadeefect|btn_autohide|btn_timerhide",elem,"","");
				}catch(e){;}
			}
		}
	}
	return ret;
}
	
function setCenaMetra(inputCenaName, inputPowierzchniaName){
	var Powierzchnia = document.getElementById(inputPowierzchniaName);
	var Cena = document.getElementById(inputCenaName);
	var Cena_metra = document.getElementById("Cena_metra");
	var Cena_currency = document.getElementById("Cena_currency");
	var Cena_metra_currency =  document.getElementById("Cena_metra_currency");

	if (Powierzchnia && Cena){
		if (Powierzchnia.value!=0 && Powierzchnia.value && Cena.value){
			Cena_metra.value = Math.round(Cena.value.replace(",", ".")/Powierzchnia.value.replace(",", "."));
			Cena_metra_currency.value = Cena_currency.value
		}else{
			Cena_metra.value="";
			Cena_metra_currency.value="";
		}
	}
}
// funkcje przeniesione z validateforms - stop

// funkcje typu 'dodaj url do'
function shareFacebook() { 
	window.open('http://www.facebook.pl/share.php?u=' + encodeURIComponent(location.href)+ '&t=' + encodeURIComponent(document.title), 'Facebook'); 
}



function likeFacebookPront(serviceName, pageType) {
	document.write ('<iframe src="http://www.facebook.com/plugins/like.php?');
	document.write ('href=' + encodeURIComponent(location.href) + '&amp;');
	document.write ('layout=button_count&amp;');
	document.write ('show_faces=false&amp;');
	document.write ('width=450&amp;');
	document.write ('action=like&amp;');
	document.write ('font=verdana&amp;');
	document.write ('colorscheme=light&amp;');
	document.write ('fb_ref=' + serviceName + '&amp;');
	document.write ('fb_source=' + pageType + '&amp;');
	document.write ('height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:21px;" allowTransparency="true">');
	document.write ('</iframe>');
}

function wykop(){
	window.open('http://www.wykop.pl/dodaj/link/url,'+encodeURIComponent(location.href)+',title,'+encodeURIComponent(document.title)+',desc,')
}

function flaker(){
	window.open('http://flaker.pl/add2flaker.php?url=' + encodeURIComponent(location.href), 'flaker'); 
}

function blip(cenaInt){
	window.open('http://www.blip.pl/dashboard?body=' + encodeURIComponent(document.title) + ',cena:' + cenaInt + encodeURIComponent(location.href), 'blip'); 
}

function sledzik(){
	window.open('http://nasza-klasa.pl/sledzik?shout=' + encodeURIComponent(location.href), 'sledzik'); 
}

function pinger(cenaInt){
	window.open('http://pinger.pl/share?title=' + encodeURIComponent(document.title) + ',cena:' + cenaInt + '&content=' + encodeURIComponent(location.href), 'pinger'); 
}

function delicious(){
	window.open('http://delicious.com/post?url=' + encodeURIComponent(location.href), 'delicious'); 
}

function technorati(){
	window.open('http://technorati.com/faves?add=' + encodeURIComponent(location.href), 'technorati'); 
}

function googleBookmarks(){
	window.open('http://www.google.com/bookmarks/mark?op=edit&bkmk=' + encodeURIComponent(location.href), 'googleBookmarks'); 
}

function digg(){
	window.open('http://digg.com/submit?url=' + encodeURIComponent(location.href), 'digg'); 
}

function twitter(){
	window.open('http://twitter.com/home?status=' + encodeURIComponent(location.href), 'twitter'); 
}

function gadugadu(){
	var imgStr = '';
	if (document.getElementById('imageSrc')){imgStr = document.getElementById('imageSrc').href}
	window.open('http://www.gg.pl/polec?url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title) + '&img=' + encodeURIComponent(imgStr))
}

function swithBlock(cloud, elementMenu, status){
	if(status){
		cloud.style.display='block';
		elementMenu.style.borderColor = '#DDDCE1 #DDDCE1 #FFFFFF';
	}else{
		cloud.style.display='none';
		elementMenu.style.borderColor = '#FFFFFF #FFFFFF #FFFFFF';
	}
}

function maxLiczbaZnakow(elementFormy, maxDlugoscTekstu, nazwaDIV){
		var maxlength = maxDlugoscTekstu;
		var StrLen=elementFormy.value.length;
		if (nazwaDIV){
	  		var ileZostaloZnakowDiv = document.getElementById(nazwaDIV);
		}
	  
	  	if (StrLen==1 && elementFormy.value.substring(0,1)==" "){
	    	elementFormy.value="";
	    	StrLen=0;
	  	}
	  
	  	if (StrLen>maxlength ){
	    	elementFormy.value=elementFormy.value.substring(0,maxlength);
	    	CharsLeft=0;
	  	}else{
	    	CharsLeft=maxlength-StrLen;
	  	}
	  
		if (nazwaDIV){  
			ileZostaloZnakowDiv.innerHTML=CharsLeft;
		}
	}

function changeDisplay(imputElemId, elmeId, buttonzobaczId){
	var elem = document.getElementById(elmeId);
	var imputElem = document.getElementById(imputElemId);
	var buttonzobacz = document.getElementById(buttonzobaczId);
	//alert('imputElemId: ' + imputElemId + '; elmeId: ' + elmeId +'; buttonzobaczId: ' +  buttonzobaczId)
	if (elem){
		var actualDisplay = elem.style.display;
		if (actualDisplay == 'block'){
			actualDisplay = 'none'
		}else{
			actualDisplay = 'block'
		}
		elem.style.display = actualDisplay;
		if (imputElem){
			imputElem.style.display='none';
		}
		if (buttonzobacz){
			buttonzobacz.style.border=0;
			buttonzobacz.style.display='none';
		}
	}
}

function wylaczprzycisk(divReplace, divON, url){
	document.getElementById(divReplace).innerHTML = document.getElementById(divON).innerHTML;
	document.location = url;
}

var allreadyclickedelements = "";

function wylaczprzyciskNew(actionid, url){
	if (allreadyclickedelements.indexOf(";"+actionid+";") >= 0){
		alert("Uwaga! Akcja jest już w trakcie wykonywania");
	}else{
		allreadyclickedelements += ";"+actionid+";";
		document.location.href = url;
	}
}

function cloud_old(toOpen, toClose){
	var objToOpen = document.getElementById(toOpen);
	var objToCose = document.getElementById(toClose);
	objToCose.style.display = 'none';
	objToOpen.style.display = 'inline';
}

function cloud()
{
	var hc = $('.forcloud').hasClass('more');
	if (hc === true){
		$('.cloud').removeAttr('style');
		$('.forcloud').removeClass('more');
		$('.forcloud').addClass('less');
		$('a',$('.forcloud')).html("... mniej");
	} else {
		$('.cloud').attr('style','overflow:hidden; height:60px');
		$('.forcloud').addClass('more');
		$('.forcloud').removeClass('less');
		$('a',$('.forcloud')).html("... więcej");
	}
}
