////////////////// START DRAGGING DIVS FUNCTIONS ///////////////////////
var currentdiv="";
var openedHelp=0;

var currentsubdiv=0;
var currentsubdiv2=0;

var startSubdivX=-3; //270
var startSubdivY=39;  //73

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.

var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {

  var el;
  var x, y;

  // If an element id was given, find it. Otherwise use the element being
  // clicked on.

  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.

    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.

  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = topStartPositionForDivs;

  // Update element's z-index.

  dragObj.elNode.style.zIndex = ++dragObj.zIndex;

  // Capture mousemove and mouseup events on the page.

  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}

function dragGo(event) {

  var x, y;

  // Get cursor position with respect to the page.

  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Move drag element by the same amount the cursor has moved.

  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {

  // Stop capturing mousemove and mouseup events.

  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

////////////////// END DRAGGING DIVS FUNCTIONS ///////////////////////
/**************************************************************/

function openDiv(id)
{

	if(currentdiv!="") document.getElementById(currentdiv).style.top="-1000";
	currentdiv=id;

	for (i=0;i<hiddableSelects.length ;i++ )
	{
		var element=hiddableSelects[i];
		if(document.getElementById(element)) document.getElementById(element).style.visibility="hidden";
	}
 
	document.getElementById(id).style.zIndex=2000;

	var scrollTop=document.body.scrollTop;
	document.getElementById(id).style.top=top_position_draggable_divs+scrollTop;

}

function closeDiv(id)
{
 
	document.getElementById(id).style.top="-1000";
	document.getElementById(id).style.zIndex=1;
	
	for (i=0;i<hiddableSelects.length ;i++ )
	{
		var element=hiddableSelects[i];
		if(document.getElementById(element)) document.getElementById(element).style.visibility="visible";
	}

}

function openCloseDraggableDiv(id)
{
 
	var html=document.getElementById("switch_"+id).innerHTML;
	//alert(html);
	
	if(html=="-")
	{
		document.getElementById("inner_"+id).className="hidden";
		document.getElementById("switch_"+id).innerHTML="+";

	}
	else if(html=="+")
	{
		document.getElementById("inner_"+id).className="active";
		document.getElementById("switch_"+id).innerHTML="-";
		
	}
}

var ns = (navigator.appName.indexOf("Netscape") != -1);
var d = document;
function JSFX_FloatDiv(id, sx, sy)
{
	var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
	var px = document.layers ? "" : "px";
	window[id + "_obj"] = el;
	if(d.layers)el.style=el;
	el.cx = el.sx = sx;el.cy = el.sy = sy;
	el.sP=function(x,y){this.style.left=x+px;this.style.top=y+px;};

	el.floatIt=function()
	{
		var pX, pY;
		pX = (this.sx >= 0) ? 0 : ns ? innerWidth : 
		document.documentElement && document.documentElement.clientWidth ? 
		document.documentElement.clientWidth : document.body.clientWidth;
		pY = ns ? pageYOffset : document.documentElement && document.documentElement.scrollTop ? 
		document.documentElement.scrollTop : document.body.scrollTop;
		if(this.sy<0) 
		pY += ns ? innerHeight : document.documentElement && document.documentElement.clientHeight ? 
		document.documentElement.clientHeight : document.body.clientHeight;
		this.cx += (pX + this.sx - this.cx)/8;this.cy += (pY + this.sy - this.cy)/8;
		this.sP(this.cx, this.cy);
		setTimeout(this.id + "_obj.floatIt()", 20);
	}
	return el;
}


function trim(sString) 
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
return sString;
}

function validatePrice(val)
{

	//checking number validation 
	//--------------------------------------------------------- 

	var cur = /^-?\d{1,3}(,\d{3})*(\.\d{1,2})?$/; 
	var anum= /(^-?\d+$)|(^-?\d+\.\d+$)/; 
	var ret = false; 
	
	if(val.indexOf(",")>-1)
	{
		
		val=val.replace(",",".");

	}

	if(val.indexOf(",")>-1) 
	ret = cur.test(val); 
	else 
	ret = anum.test(val); 

	if(!ret) return false;  
	else return true;

}

function is_number(nr)
{
	
	var expr=/\D/g; 
	var result=expr.test(nr);
	
	if(result) return false; 
	else return true;
	
}

function in_array(string, array2)
{
	 
	var r=false;
	for(j=0;j<array2.length;j++)
	{	
		if(array2[j]==string) r=true;
	}

	return r;
}

function getExtensionByName(filename)
{
	
	var text=filename.split(".");
	var len=text.length-1;
	var ext=text[len];

	return ext.toLowerCase();

}

function number_format(number, decimals, dec_point, thousand_sep, p)
{

	var n=(''+(Math.round(number*(p=Math.pow(10,decimals||0)))/p)).split('.');
	for(var i=(n[0]=n[0].split('')).length-3,j=n[0][0]=='-'?1:0; i>j; i-=3)
	{
		n[0].splice(i,0,thousand_sep||',');
	}
	
	var string=n[0].join('')+(n[1]?(dec_point||'.')+n[1]:'');

	if(string.indexOf(",")!=-1)
	{
	var p=string.split(",");
	var l=p.length-1;
	var ext=p[l];
	if(ext.length==1) string+="0";
	}
	else string+=",00";

	return string;

}

function popUp(urlnow, namenow, widthnow, heightnow, activation) 
{ 
	
	newWindow = window.open(urlnow, namenow, 'width='+widthnow+',height='+heightnow+',toolbar=no,focus=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes,status'); 
	if(activation) newWindow.focus(); 

}

function printSite(elementid, sitename, toptext)
{
	
	
	if(document.getElementById(elementid))
	{
		popUp(server+"/print_site.php?id="+elementid+"&sitename="+sitename+"&toptext="+toptext,"eslub",700,500,1);
	}

}

function enlargeImage(id, name, path)
{
	popUp("enlarge_image.php?id="+id+"&name="+escape(name)+"&path="+escape(path),"zdjęcie",500,500,1);

}

function enlargeImageFront(id, name, path)
{

	popUp(server+"/enlarge_image.php?id="+id+"&name="+escape(name)+"&path="+escape(path),"zdjęcie",500,500,1);
}

function check_emailform()
{
	
	var d=document.emailform;
	
	hideNotificationDiv();

	if(!trim(d.f_mail_to.value))
	{
		alert("Podaj adres email odbiorcy");
		d.f_mail_to.focus();
		return false;
	}

	var email=trim(d.f_mail_to.value);
	var expr=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var result=expr.test(email);
	
	if(!result)
	{
		alert("Wprowadź poprawny adres email odbiorcy");
		d.f_mail_to.focus();
		return false;
	}

	if(d.f_mail_copy) if(trim(d.f_mail_copy.value))
	{
		
		var email=trim(d.f_mail_copy.value);
		var expr2=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		var result2=expr2.test(email);
		
		if(!result2)
		{
			alert("Wprowadź poprawny adres email kopii");
			d.f_mail_copy.focus();
			return false;
		}

	}

	if(d.f_mail_hiddencopy) if(trim(d.f_mail_hiddencopy.value))
	{
		
		var email=trim(d.f_mail_hiddencopy.value);
		var expr3=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		var result3=expr2.test(email);
		
		if(!result3)
		{
			alert("Wprowadź poprawny adres email kopii ukrytej");
			d.f_mail_hiddencopy.focus();
			return false;
		}

	}
	
	if(!trim(d.f_mail_subject.value))
	{
		
		alert("Wpisz temat wiadomości");
		d.f_mail_subject.focus();
		return false;

	}

	if(!trim(d.f_mail_message.value))
	{
		
		alert("Wpisz treść wiadomości");
		d.f_mail_message.focus();
		return false;

	}

	return true;
}

function pressTab(id, preffixid, tabname)
{
	
	var maxid=30;
	
	for(i=0;i<=maxid;i++)
	{
		 var idno=preffixid+""+i;
		 if(document.getElementById(idno)) document.getElementById(idno).style.display='none';
		
		var idno="tab_left"+i;
		 if(document.getElementById(idno)) document.getElementById(idno).className='tab_left_off';
		 
			var idno="tab_middle"+i;
		if(document.getElementById(idno)) document.getElementById(idno).className='tab_middle_off';

		var idno="tab_right"+i;
		 if(document.getElementById(idno)) document.getElementById(idno).className='tab_right_off';
	}
	
	var idno=preffixid+""+id;
	if(document.getElementById(idno)) document.getElementById(idno).style.display='block';
	
	var idno="tab_left"+id;
		 if(document.getElementById(idno)) document.getElementById(idno).className='tab_left_on';
		 
			var idno="tab_middle"+id;
		if(document.getElementById(idno)) document.getElementById(idno).className='tab_middle_on';

		var idno="tab_right"+id;
		 if(document.getElementById(idno)) document.getElementById(idno).className='tab_right_on';

	if(document.searchpartform) document.searchpartform.activeTab.value=id;
	if(document.beheerform) document.beheerform.activeTab.value=id;
	if(document.getElementById('tabs_title_container')) document.getElementById('tabs_title_container').innerHTML=tabname;

	//checkContainerHeight();
}

function setlang(lang)
{
	
	var list=document.getElementById("langslist").value;
	list=list.split(",");

	for(i=0;i<list.length-1;i++)
	{
		var idnow=list[i];
		var nameid="name_"+idnow;
		var separatorid="separator_"+idnow;
		var editorid="editor_"+idnow;

		if(document.getElementById(nameid)) document.getElementById(nameid).style.display="none";
		if(document.getElementById(separatorid)) document.getElementById(separatorid).style.display="none";
		if(document.getElementById(editorid)) document.getElementById(editorid).style.display="none";
	}
	
	var nameid="name_"+lang;
	var separatorid="separator_"+lang;
	var editorid="editor_"+lang;

	if(document.getElementById(nameid)) document.getElementById(nameid).style.display="block";
	if(document.getElementById(separatorid)) document.getElementById(separatorid).style.display="block";
	if(document.getElementById(editorid)) document.getElementById(editorid).style.display="block";

}


function hideNotificationDiv()
{
	if(document.getElementById('notificationdiv'))
	{
		document.getElementById('notificationdiv').style.top='-1000';
		document.getElementById('notificationdiv').style.visibility='visible';
	}
}

function showNotificationDiv()
{

	
	if(document.getElementById('notificationdiv'))
	{
		
		var top=document.getElementById('notificationdiv').offsetTop;
		if(top<0) top=110;

		if (browser.isIE) {
			var y =document.body.scrollTop;
		  }
		  if (browser.isNS) {
			var y = window.scrollY;
		  }
		
		document.getElementById('notificationdiv').style.top=top+y;
		document.getElementById('notificationdiv').style.visibility='visible';

	}
}

function changeStatus(section, sql_table, sql_column, sql_id, sql_set_value, tdid)
{

	// change image in list
	if(sql_set_value==0) 
	{
		srcnow="images/cancel.gif";
		var sql_value=1;
	}	
	
	else if(sql_set_value==1) 
	{
		srcnow="images/accept.gif";
		var sql_value=0;
	}
	var newcontent="<a href='javascript://' onclick=\"if(confirm('Czy na pewno zmienić status?')) changeStatus('"+section+"', '"+sql_table+"', '"+sql_column+"','"+sql_id+"', '"+sql_value+"', '"+tdid+"')\"><img src='"+srcnow+"' width=16 height=16></a>";
	
	showNotificationDiv();

	$.ajax({
		   
	type: "POST",
  
	url:	server+"/ajax/set_activation.php",
   
	data: "sql_table="+sql_table+"&sql_column="+sql_column+"&sql_id="+sql_id+"&sql_set_value="+sql_set_value,

	success: function(msg)
	{
		
		hideNotificationDiv();

		if(document.getElementById(tdid)) document.getElementById(tdid).innerHTML=newcontent;

	}
	});

}

function checkSondaAnswer(sondaid, nr)
{
	nr=nr*1;
	
	var is_checked=false;
	var answer=0;

	for(i=0;i<nr;i++)
	{
		
		var id="sonda_answer_"+i;
		if(document.getElementById(id))
		{
			if(document.getElementById(id).checked)
			{
				is_checked=true;
				var answer=i+1;
				break;
			}
		}
	}
	
	if(!is_checked) alert("Wybierz odpowiedź!");
	else
	{
		$.ajax({
		   
		type: "POST",
	  
		url:	server+"/ajax/set_sonda.php",
	   
		data: "sondaid="+sondaid+"&answer="+answer,

		success: function(msg)
		{
	 
			document.location.href=server+"/index.php?sondaid="+sondaid;			

		}
		});
	}
}

function checkNewsletterSubscription()
{
	
	var val=trim(document.getElementById("newslettermail").value);

	if(!val || val=='wpisz e-mail')
	{
		
		alert("Wpisz adres email!");
		document.getElementById("newslettermail").focus();
	}

	else
	{

		var expr=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
		var result=expr.test(val);
		
		if(!result)
		{
			alert("Wprowadź poprawny adres email!");
			document.getElementById("newslettermail").focus();
		}

		else
		{
			$.ajax({
		   
			type: "POST",
		  
			url:	server+"/ajax/set_newsletter.php",
		   
			data: "email="+val,

			success: function(msg)
			{
		 
				if(document.getElementById("newsletter-content")) document.getElementById("newsletter-content").innerHTML=msg;
			}
			});

		}

	}

}

function changePartsAmountPerPage(val)
{
	
	if(document.getElementById('key_perpage')) document.getElementById('key_perpage').value=val;
	
	setNewSearchForParts();
	document.searchpartform.submit();
}

function changePageForParts(e,val, maxval)
{
	
	maxval=maxval*1;

	if(window.event) // IE 
	{ 
		keynum = e.keyCode 
	} 
	else if(e.which) // Netscape/Firefox/Opera 
	{ 
		keynum = e.which 
	} 

	if (keynum==13)
	{
		
		var expr=/\D/g;
		var result=expr.test(val); 
		
		if(result || val<1 || val>maxval || trim(val)=='')
		{
			alert("Wpisz wartość od 1 do "+maxval);	
			document.getElementById("currentpageval").focus();
		}
		else
		{
		
			document.getElementById("key_currentpage").value=val;
			showNotificationDiv();
			freezePartDetailsForSearchForm();
			document.searchpartform.submit();
		}

	}
}

function rewindParts(action, curval, maxval)
{
	
	curval=curval*1;
	maxval=maxval*1;
	
	if(action=='start') curval=1;
	else if(action=='previous') curval-=1;
	else if(action=='next') curval+=1;
	else if(action=='end') curval=maxval;

	document.getElementById("key_currentpage").value=curval;
	showNotificationDiv();
	freezePartDetailsForSearchForm();
	document.searchpartform.submit();
}

function freezePartDetailsForSearchForm()
{
}

function setNewSearchForParts()
{
	if(document.getElementById('key_newsearch')) document.getElementById('key_newsearch').value="yes";
}

function setLinkAsHomePage(text,adressURL)
{

	//FireFox
    if (window.sidebar) 
	{

		//document.write("<a href='javascript:void(0)' onclick='alert(\"Chwyć i przeciągnij ikonę strony w adresie URL na ikonę strony domowej w przeglądarce!\")' title='"+text+"'>"+text+"</a>");
	}
	else 
	{
		document.write("&nbsp;|&nbsp;<a href='javascript:void(0)' onclick=\"this.style.behavior='url(#default#homepage)'; this.setHomePage(server)\" title='"+text+"'>"+text+"</a>");
	 
	}
	
}

function add2favourite(tytul, adres) 
{

    //var tytul = 'siteurl';
    //var adres = 'http://kurs24.pl';

    //FireFox
    if (window.sidebar) { 

        window.sidebar.addPanel(tytul, adres, ""); 

    //IE
    } else if (window.external) {

        window.external.AddFavorite(adres, tytul); 

    //Opera
    } else if (window.opera && window.print) {

        var a = document.createElement('a');
        a.setAttribute('href', adres);
        a.setAttribute('title', tytul);
        a.setAttribute('rel','sidebar');
        a.click();
    }
}

function showSubmenu(menuid, additionalX, additionalY)
{
	
	var id="mainmenu_"+menuid;
	
	var top=parseInt(document.getElementById(id).offsetTop);
	var left=parseInt(document.getElementById(id).offsetLeft);
	var width=parseInt(document.getElementById(id).offsetWith);
	
	

	var brws=navigator.userAgent;
	
	if (brws.indexOf("MSIE 6.0")!=-1)
	{
		//if(additionalY) additionalX=additionalX-274;
		//if(additionalY) additionalY=additionalY-35;
	}

 	if (browser.isNS && brws.indexOf("MSIE 7.0")==-1)
	{	
	
		//left=left-274;
		//top=top-35;
	}

	else if(brws.indexOf("MSIE 7.0")!=-1)
	{
		//left=left+85;
	}


	top=top*1+additionalY*1;
	left=left*1+additionalX*1;	

	var subid="submenu_"+menuid;
	
	if(menuid!=currentsubdiv && currentsubdiv && !additionalX && !additionalY) hideSubmenu(currentsubdiv);

	//if(menuid!=currentsubdiv2 && currentsubdiv2 && additionalX && additionalY) hideSubmenu(currentsubdiv2);
	
	if(document.getElementById(subid))
	{
	
		if(!additionalX && !additionalY) currentsubdiv=menuid;
		if(additionalX && additionalY) currentsubdiv2=menuid;

		document.getElementById(subid).style.top=top+startSubdivY;
		document.getElementById(subid).style.left=left+startSubdivX;
	
	}

}

function hideSubmenu(menuid)
{
		
		if(currentsubdiv2)
		{
			var subid="submenu_"+currentsubdiv2;
			
			if(document.getElementById(subid))
			{
				document.getElementById(subid).style.top=-1000;
				currentsubdiv2=0;
			}

		}

		var subid="submenu_"+currentsubdiv;
		
		if(document.getElementById(subid))
		{
			document.getElementById(subid).style.top=-1000;
			currentsubdiv=0;
		}
}


function activateMenu(menuid, action)
{

	var menuLeft="menu"+menuid+"a";
	var menuMiddle="menu"+menuid+"b";
	var menuRight="menu"+menuid+"c";
	
	if(action=='on')
	{
		
		if(menuid==1) document.getElementById(menuLeft).className='menu_left_last_on';
		else document.getElementById(menuLeft).className='menu_left_on';

		if(document.getElementById(menuMiddle)) document.getElementById(menuMiddle).className='menu_middle_on';

		if(document.getElementById(menuRight))	
		document.getElementById(menuRight).className='menu_right_on';

	}

	if(action=='off')
	{
		
		if(menuid==1) document.getElementById(menuLeft).className='menu_left_off';
		else document.getElementById(menuLeft).className='menu_left_off';

		if(document.getElementById(menuMiddle)) document.getElementById(menuMiddle).className='menu_middle_off';

		if(document.getElementById(menuRight)) document.getElementById(menuRight).className='menu_right_off';
	}

}

function sortparts(sortedby)
{
	
 
	if(document.getElementById('key_sortby')) document.getElementById('key_sortby').value=sortedby;
	freezePartDetailsForSearchForm();
	document.searchpartform.submit();

}

function resetFiltr()
{
	
	if(document.searchpartform)
	{
		document.searchpartform.key_resetfilter.value='1';
		document.searchpartform.submit();
	}
}

function updateCheckboxesList(action)
{
	
	if(!action) return;
	
	var d=document.resultsform;
	
	showNotificationDiv();

	if(action=='setall')
	{
		
		for(i=0;i<d.elements.length;i++)
		{

			var type=d.elements[i].type;
			var checked=d.elements[i].checked;
			if(type=='checkbox' && !checked) d.elements[i].checked=true;

		}
	}
	
	else if(action=='resetall')
	{
		
		for(i=0;i<d.elements.length;i++)
		{

			var type=d.elements[i].type;
			var checked=d.elements[i].checked;
			if(type=='checkbox' && checked) d.elements[i].checked=false;

		}
	}
	
	else if(action=='invertall')
	{
		
		for(i=0;i<d.elements.length;i++)
		{

			var type=d.elements[i].type;
			var checked=d.elements[i].checked;
			if(type=='checkbox' && checked) d.elements[i].checked=false;
			else if(type=='checkbox' && !checked) d.elements[i].checked=true;

		}
	}

	document.getElementById("checkboxesListSelect").selectedIndex=0;

	hideNotificationDiv();
}

function setRow(id)
{
	
	var d=document.resultsform;
	id="idslist_"+id;
	
	if(!document.getElementById(id)) return;

	var checked=d.elements[id].checked;

	if(checked) d.elements[id].checked=false;
	else if(!checked) d.elements[id].checked=true;

}

function performAction()
{
	
	var index=document.getElementById('performActionSelect').selectedIndex;
	
	if(!document.resultsform)
	{
		alert("Lista wynikowa jest pusta!");
		return;
	}
	if(index<1)
	{
		alert("Nie wybrałeś żadnej akcji");
		return;
	}
	else  
	{
		var d=document.resultsform;
		var ischecked=false;
		var checkedCounter=0;
		showNotificationDiv();

		for(i=0;i<d.elements.length;i++)
		{
			var type=d.elements[i].type;
			var checked=d.elements[i].checked;
			var name=d.elements[i].name;
			
			if(name.indexOf("idslist[]")!='-1' && type=='checkbox' && checked)
			{
				ischecked=true;
				checkedCounter++;
			}

		}
		
		hideNotificationDiv();

		if(!ischecked)
		{
			alert("Nie wybrałeś żadnych danych!");
			return;
		}

		var action=document.getElementById('performActionSelect').options[index].value;
		
	 
		if(action=='deleteclients')
		{
			if(confirm("Czy na pewno chcesz nieodwracalnie usunąć wybranych klientów?"))
			{
				d.a.value=action;
				d.submit();
			}
		}
		else if(action=='deleteadds')
		{
			if(confirm("Czy na pewno chcesz nieodwracalnie usunąć wybrane ogłoszenia?"))
			{
				d.a.value=action;
				d.submit();
			}
		}
		else
		{
		d.a.value=action;
		d.submit();
		}
	}

}

function confClientDel(id)
{
	if(confirm("Czy na pewno chcesz usunąć tego klienta?")) document.location.href="management.php?s=clients&a=deleteclients&idslist="+id;
}

function reloadCitiesForAds(elem, fieldid)
{
	
	var index=elem.selectedIndex;
	var wojid=elem.options[index].value;
	
	var el=document.getElementById(fieldid);
	el.options.length=0;
	el.options[0]=new Option("- proszę czekać -", "0", true, false);

	$.ajax({
		   
	type: "POST",
  
	url:	server+"/ajax/reload_cities_for_ads.php",
   
	data: "wojid="+wojid,

	success: function(msg)
	{
				
		var el=document.getElementById(fieldid);
		var lengthnow=msg.length;

		if(!msg)
		{
			el.options.length=0;
			el.options[0]=new Option("- wybierz województwo -", "0", true, false);
		}
		else
		{
			el.options.length=0;
			el.options[0]=new Option("- wybierz miasto -", "0", true, false);
			
			msg=msg.split("|");

			for(i=0; i<msg.length; i++)
			{
				var data=msg[i].split("*");
				var cityid=data[0];
				var cityname=data[1];

				var k=i+1;
				el.options[k]=new Option(cityname, cityname, true, false);
			}
		}
	}
	});
}

function reloadCities(elem, fieldid)
{
	
	var index=elem.selectedIndex;
	var wojid=elem.options[index].value;
	
	var el=document.getElementById(fieldid);
	el.options.length=0;
	el.options[0]=new Option("- proszę czekać -", "0", true, false);

	$.ajax({
		   
	type: "POST",
  
	url:	server+"/ajax/reload_cities.php",
   
	data: "wojid="+wojid,

	success: function(msg)
	{
				
		var el=document.getElementById(fieldid);
		var lengthnow=msg.length;

		if(!msg)
		{
			el.options.length=0;
			el.options[0]=new Option("- wybierz województwo -", "0", true, false);
		}
		else
		{
			el.options.length=0;
			el.options[0]=new Option("- wybierz miasto -", "0", true, false);
			
			msg=msg.split("|");

			for(i=0; i<msg.length; i++)
			{
				var data=msg[i].split("*");
				var cityid=data[0];
				var cityname=data[1];

				var k=i+1;
				el.options[k]=new Option(cityname, cityname, true, false);
			}
		}
	}
	});
}

function reloadCitiesForm(elem, fieldid, loaderid)
{
	
	var index=elem.selectedIndex;
	var wojid=elem.options[index].value;
	
	if(document.getElementById(loaderid)) document.getElementById(loaderid).style.visibility="visible";

	var el=document.getElementById(fieldid);
	el.options.length=0;
	el.options[0]=new Option("- proszę czekać -", "0", true, false);

	$.ajax({
		   
	type: "POST",
  
	url:	server+"/ajax/reload_cities.php",
   
	data: "wojid="+wojid,

	success: function(msg)
	{
	
		msg=msg.split("|");
		var el=document.getElementById(fieldid);

		var lengthnow=msg.length;
		if(lengthnow==1)
		{
			el.options.length=0;
			el.options[0]=new Option("- wybierz województwo -", "0", true, false);
		}
		else
		{
			el.options.length=0;
			el.options[0]=new Option("- wybierz miasto -", "0", true, false);


			for(i=0; i<msg.length; i++)
			{
				var data=msg[i].split("*");
				var cityid=data[0];
				var cityname=data[1];

				var k=i+1;
				el.options[k]=new Option(cityname, cityname, true, false);
			}
		}
		if(document.getElementById(loaderid)) document.getElementById(loaderid).style.visibility="hidden";
	}
	});
}

function getCurrentTime()
{
	
	var currentTime=new Date();
	var hours=currentTime.getHours(); 
	var minutes=currentTime.getMinutes();
	var seconds=currentTime.getSeconds();

	if(hours<10) hours="0"+hours;
	if(minutes<10) minutes="0"+minutes;
	if(seconds<10) seconds="0"+seconds;

	var timestr=hours+":"+minutes+":"+seconds;

	if(document.getElementById("currentHourFiller"))
	{
		document.getElementById("currentHourFiller").innerHTML="&nbsp;&nbsp;&nbsp;godzina:&nbsp;"+timestr;
		setTimeout("getCurrentTime()",1000);
	}
}

function clickBanner(bid, url)
{
	$.ajax({ 
	type: "POST",
	url:	server+"/ajax/manage_banners.php",
	data: "bid="+bid+"&url="+url,
	success: function(msg)
	{
		//popUp(url,"eslub", 600,400,1);
	}
	});
	window.open(url);
}

function clickOgloszenie(oid, url)
{
	$.ajax({
	type: "POST",
	url:	server+"/ajax/manage_ogloszenia.php",
	data: "oid="+oid+"&url="+url,
	success: function(msg)
	{
		//popUp(url,"eslub", 600,400,1);
	}
	});

	document.location.href=url;
}

function clickEvent(oid, url)
{
	$.ajax({
	type: "POST",
	url:	server+"/ajax/manage_wydarzenia.php",
	data: "oid="+oid+"&url="+url,
	success: function(msg)
	{

		//popUp(url,"eslub", 600,400,1);
	}
	});

	document.location.href=url;
}

function clickwww(oid, url)
{
	$.ajax({   
	type: "POST",
	url:	server+"/ajax/manage_ogloszenia.php",
	data: "oid="+oid+"&url="+url+"&action=www",
	success: function(msg)
	{
		//popUp(url,"eslub", 600,400,1);
	}
	});
	window.open(url);
}

function clickemail(oid, email)
{
	$.ajax({	   
	type: "POST",
	url:	server+"/ajax/manage_ogloszenia.php",
	data: "oid="+oid+"&action=email",
	success: function(msg)
	{
		//popUp(url,"eslub", 600,400,1);
	}
	});
	document.location.href='mailto:'+email;
}

function getClicks(type,oid,link,created)
{
	$.ajax({	   
	type: "POST",
	url: server+"/ajax/manage_clicks.php",
	data: "type="+type+"&oid="+oid+"&link="+link+"&created="+created,
	success: function(msg)
	{
		//alert(msg);
	}
	});
}

function addNewComments(oid, branza)
{
	var val=trim(document.getElementById("newcomments").value);
	var user=trim(document.getElementById("newname").value);
	if(!user)
	{
		alert("Wpisz Twoje imię!");
		document.getElementById("newname").focus();
	}
	else if(!val)
	{
		alert("Wpisz treść ogłoszenia!");
		document.getElementById("newcomments").focus();
	}
	else
	{
		
		
		$.ajax({	   
		type: "POST",
		url:	server+"/ajax/manage_ogloszenia.php",
		data: "oid="+oid+"&action=addComments&msg="+val+"&name="+user+"&branza="+branza,
		success: function(msg)
		{
			//alert(msg);
			//document.getElementById("commentsContainer").innerHTML="<b>Dziękujemy!<br>Twój komentarz został przyjęty i czeka na aktywację!</b>";
			document.location.reload(true);
		}
		});
	}
}

function showNotifier(divid)
{
	
	if(divid=='notifierContainer')
	{
		if(document.getElementById("informContainer")) document.getElementById("informContainer").style.display='none';

		if(document.getElementById("favContainer")) document.getElementById("favContainer").style.display='none';

		if(document.getElementById(divid)) document.getElementById(divid).style.display='block';
	}

	if(divid=='informContainer')
	{
		if(document.getElementById("notifierContainer")) document.getElementById("notifierContainer").style.display='none';

		if(document.getElementById("favContainer")) document.getElementById("favContainer").style.display='none';

		if(document.getElementById(divid)) document.getElementById(divid).style.display='block';
	}

	if(divid=='favContainer')
	{
		if(document.getElementById("notifierContainer")) document.getElementById("notifierContainer").style.display='none';

		if(document.getElementById("informContainer")) document.getElementById("informContainer").style.display='none';

		if(document.getElementById(divid)) document.getElementById(divid).style.display='block';
	}
}

function sendNotifyForm()
{
	var d=document.notifyform;

	if(!trim(d.f_name.value))
	{
		alert("Wpisz Twoje imię i nazwisko!");
		d.f_name.focus();
		return false;
	}

	if(!trim(d.f_email.value))
	{
		alert("Wpisz adres email osoby znajomej!");
		d.f_email.focus();
		return false;
	}

	var email=trim(d.f_email.value);
	var expr6=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var result6=expr6.test(email);
	
	if(!result6)
	{
		alert("Wprowadź poprawny adres email!");
		d.f_email.focus();
		return false;
	}

	if(!trim(d.f_notifymsg.value))
	{
		alert("Wpisz Twoją wiadomość!");
		d.f_notifymsg.focus();
		return false;
	}
	return true;
}

function sendInformForm()
{
	var d=document.informform;
	
	if(!trim(d.f_name.value))
	{
		alert("Wpisz Twoje imię i nazwisko!");
		d.f_name.focus();
		return false;
	}

	if(!trim(d.f_email.value))
	{
		alert("Wpisz adres email osoby znajomej!");
		d.f_email.focus();
		return false;
	}

	var email=trim(d.f_email.value);
	var expr6=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var result6=expr6.test(email);
	
	if(!result6)
	{
		alert("Wprowadź poprawny adres email!");
		d.f_email.focus();
		return false;
	}

	if(!trim(d.f_informmsg.value))
	{
		alert("Wpisz Twoją wiadomość!");
		d.f_informmsg.focus();
		return false;
	}

	return true;
}

function sendFavForm()
{
	var d=document.favform;
	if(!trim(d.f_name.value))
	{
		alert("Wpisz nazwę linku!");
		d.f_name.focus();
		return false;
	}

	return true;
}

function formatPostCode(element)
{
	if(document.registerform) var d=document.registerform;
	else if(document.beheerform) var d=document.beheerform;
	else if(document.kioskform) var d=document.kioskform;

	var name=element.name;
	var val=trim(d.elements[name].value);
	if(val.indexOf("-")==-1 && val.length==5)
	{

		var newcode=val[0]+val[1]+"-"+val[2]+val[3]+val[4];
		d.elements[name].value=newcode;
	}
}

function checkContainerHeight(minheight)
{
	if(document.getElementById("container"))
	{
		var height=document.getElementById("container").offsetHeight;
		if(height<minheight) document.getElementById("container").style.height=minheight+"px";
	}
}

function checkLoginForm()
{
	var d=document.logingform;
	
	if(trim(d.email.value)=="" || trim(d.email.value)=="email...")
	{
		alert("Wprowadź adres email!");
		d.email.value="";
		d.email.focus();
		d.email.value="";
		return false;
	}

	if(trim(d.password.value)=="" || trim(d.password.value)=="hasło...")
	{
		alert("Wprowadź hasło!");
		d.password.value="";
		d.password.focus();

		return false;
	}

	var email=trim(d.email.value);
	var expr=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var result=expr.test(email);
	
	if(!result)
	{
		alert("Wprowadź poprawny adres email!");
		d.email.focus();
		return false;
	}

	return true;

}

function checkEmail(el)
{
	var id=el.id;
	if (document.getElementById(id).value=='email...') document.getElementById(id).value="";
	else if (document.getElementById(id).value=='') document.getElementById(id).value="email...";
}

function checkPswd(el,action)
{
	var id=el.id;
	if (action=='on') document.getElementById(id).className="pswd_input";
	else if (action=='off' && !trim(document.getElementById(id).value)) 
	{
		document.getElementById(id).value=trim(document.getElementById(id).value);
		document.getElementById(id).className="pswd_input_off";
	}
}

function reloadEventHours(element)
{
	var index=element.selectedIndex;
	var days=element.options[index].value;
	for(i=1;i<=30;i++)
	{
		if(document.getElementById("hoursrange_"+i))
		{
			if(i<=days) document.getElementById("hoursrange_"+i).style.display="block";
			else
			{
				document.getElementById("f_daysstart_"+i).value="";
				document.getElementById("f_daysend_"+i).value="";
				document.getElementById("hoursrange_"+i).style.display="none";
			}
		}
	}
}

function afterLoging()
{
	alert('Ta funkcjonalność dostępna jest po zalogowaniu się!');
}
