// remove the registerOverlay call to disable the controlbar
hs.registerOverlay({
	thumbnailId: null,
	overlayId: 'controlbar',
	position: 'top right',
	hideOnMouseOut: true
});
hs.graphicsDir = 'js/highslide/graphics/';
hs.outlineType = 'rounded-white';
// Tell Highslide to use the thumbnail's title for captions
hs.captionEval = 'this.thumb.title';

// array of selects IDS to be hidden before dragbox appears
var hiddableSelects=Array();
var currentdiv="";

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 validateEmail(val)
{
	val=trim(val);
	//var expr=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;
	var expr=/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w+)+$/;
	var result=expr.test(val);
	return result;
}

function validatePswd(pswd)
{
	if(pswd.length<6 || !/[0-9]/.test(pswd)) return false; 
	else return true;
}

function validatePostCode(postcode)
{
	return true; // temporarily disabled!
	var regex = /^[0-9]{2}\-[0-9]{3}$/;
	var result=regex.test(postcode);

	return result;
}

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 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,"mlodapara",700,500,1);
	}

}

function getWindowMeasurements() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return new Array(myWidth,myHeight);
}


function getScrollsPosition()
{

	var x = 0;
	var y = 0;

	if( typeof( window.pageYOffset ) == 'number' )
	{
		x = window.pageXOffset;
		y = window.pageYOffset;
	}
	else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) )
	{
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) )
	{
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}

	return new Array(x,y);

}

function confLogOut()
{
	if(confirm("Czy chcesz się wylogować?"))
	{
		document.location.replace(server+"/wyloguj");
	}
}

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 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 ns = (navigator.appName.indexOf("Netscape") != -1);
var browser = new Browser();

function JSFX_FloatDiv(id, sx, sy)
{
	
	var d = document;
	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 openCloseMenu()
{
	var el=document.getElementById("btn_menu");
	var cla=el.className;
	if(cla=="btn_menu_cms")
	{
		el.className="btn_menu_cms_open";
		document.getElementById("menu_options").style.display="block";
	}
	else
	{
		el.className="btn_menu_cms";
		document.getElementById("menu_options").style.display="none";
	}
}

function checkContentHeight()
{
	//var height=document.getElementById("content").offsetHeight;
	//alert(height);
}

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();
}


// DRAG FUNCTIONS START //
// 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);
  }
}

function openDiv(id)
{

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

	for (i=0;i<hiddableSelects.length ;i++ )
	{
		var element=hiddableSelects[i];
		if(document.getElementById(element)) document.getElementById(element).style.visibility="hidden";
	}
 
	var maxMeasures=getWindowMeasurements();
	var maxHeight=maxMeasures[1];
	var scrolls=getScrollsPosition();
	var scrollY=scrolls[1];

	var divHeight=document.getElementById(id).offsetHeight;
	var top=Math.floor((maxHeight/2)-(divHeight/2))-30+scrollY;

	document.getElementById(id).style.top=top+"px";
	document.getElementById(id).style.zIndex=10000;
}

function closeDiv(id)
{
	document.getElementById(id).style.top="-1000px";
	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="-";
		
	}
}

// DRAG FUNCTIONS END //

function showNotificationDiv(element)
{
	if(document.getElementById(element)) document.getElementById(element).style.display="block";
}

function hideNotificationDiv(element)
{
	if(document.getElementById(element)) document.getElementById(element).style.display="none";
}

function generatePswd(elementid)
{
  
	var prefix1=Array("do","re","mi","fa","so","la","ro");
	var prefix2=Array("*","#");
	var prefix3=Math.floor(Math.random()*99);
	var prefix4=Array("lo","mi","ru","se","ma");

	var index1=Math.floor(Math.random()*6);
	var index2=Math.floor(Math.random()*6);
	var index3=Math.floor(Math.random()*6);
	var index4=Math.floor(Math.random()*2);
	
	var newpwsd=prefix1[index1]+prefix1[index2]+prefix2[index4]+prefix3+prefix1[index3];
	if(elementid) if(document.getElementById(elementid)) document.getElementById(elementid).value=newpwsd;
}

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

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

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();
			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();
	document.searchpartform.submit();
}

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

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 usunąć wybranych klientów?"))
			{
				d.a.value=action;
				d.submit();
			}
		}
		else
		{
			d.a.value=action;
			d.submit();
		}
	}

}

function allowOtherSelection(elid,allowtext,otherid)
{
	var val=document.getElementById(elid).options[document.getElementById( elid).selectedIndex].text;
	
	if(val==allowtext)
	{
		document.getElementById(otherid).disabled=false;
		document.getElementById(otherid).style.color="#000";
		document.getElementById(otherid).value="";
		document.getElementById(otherid).focus();
	}
	else
	{
		document.getElementById(otherid).disabled=true;
		document.getElementById(otherid).style.color="#a0a0a0";
		document.getElementById(otherid).value="- brak -";

	}
}

function allowOtherSelectionArrays(fieldslist,otherid)
{
	var allowed=true;
	
	fieldslist=fieldslist.split("|");
	
	for(i=0;i<fieldslist.length;i++)
	{
		var fieldid=fieldslist[i];
		if(document.getElementById(fieldid).selectedIndex<1)
		{
			allowed=false;
		}
	}

	if(allowed)
	{
		document.getElementById(otherid).selectedIndex=0;
		document.getElementById(otherid).disabled=true;
		document.getElementById(otherid).style.color="#a0a0a0";
	}
	else
	{
		document.getElementById(otherid).disabled=false;
		document.getElementById(otherid).style.color="#000";
	}
}

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 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 reloadCitiesFormKomis(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_for_komis.php",
	data: "wojid="+wojid,
	success: function(msg)
	{
		
		if(msg) msg=msg.split("|");
		var el=document.getElementById(fieldid);

		var lengthnow=msg.length;
		if(!lengthnow)
		{
			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 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 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ę!");
}

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 getRidPL(text)
{
	text=text.replace("ą","a");
	text=text.replace("ć","c");
	text=text.replace("ę","e");
	text=text.replace("ł","l");
	text=text.replace("ń","n");
	text=text.replace("ó","o");
	text=text.replace("ś","s");
	text=text.replace("ż","z");
	text=text.replace("ź","z");

	text=text.replace("Ą","A");
	text=text.replace("Ć","C");
	text=text.replace("Ę","E");
	text=text.replace("Ł","L");
	text=text.replace("Ń","N");
	text=text.replace("Ó","O");
	text=text.replace("Ś","S");
	text=text.replace("Ż","Z");
	text=text.replace("Ź","Z");
	
	return text;
}

function prepareURL(str)
{
	if(!str) return "";
	str=getRidPL(str);
	
	var signs=new Array('/',',',';','-','?','&','%','!','@','#','$','^','(',')',"'",'"');

	for(i=0;i<signs.lenght;i++)
	{
		str=str.replace(signs[i],"")
	}

	str=str.replace("       ","_");
	str=str.replace("      ","_");
	str=str.replace("     ","_");
	str=str.replace("    ","_");
	str=str.replace("   ","_");
	str=str.replace("  ","-");
	str=str.replace(/\./g,"-");
	str=str.replace(/ /g,"-");
	str=str.replace(/_/g,"-");
	str=str.replace(/\//g,"-");
	str=str.replace("--","-");
	str=str.replace("--","-");
	
	return str.toLowerCase();
}

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 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 checkTopSearching()
{
	var d=document.topsearchform;
	if(!trim(d.key_name.value) && d.key_cat.selectedIndex<1 && d.key_woj.selectedIndex<1)
	{
		alert("Wybierz przynajmniej jedno kryterium wyszukiwania!");
		return false;
	}

	var link=server+"/produkty";
	if(d.key_cat.selectedIndex>0)
	{
		var catname=d.key_cat.options[d.key_cat.selectedIndex].text;
		link+="/"+trim(prepareURL(catname));
	}
	
	if(d.key_woj.selectedIndex>0)
	{
		var wojname=d.key_woj.options[d.key_woj.selectedIndex].text;
		link+="/"+trim(prepareURL(wojname));
	}
	
	d.action=link;
	return true;
}

function confDelPost(tid, wid, pid)
{
	if(confirm("Czy na pewno chcesz usunąć ten post?")) document.location.href=server+"/forum/usun-post/"+tid+"/"+wid+"/"+pid;
}

function confirmDelMyFav(id, tabcounter)
{
	if(confirm("Czy na pewno chcesz usunąć ten link?")) document.location.href=server+"/moje-ulubione/usun/"+id+"/"+tabcounter;
}

function confDelKomisSlubny(id)
{
	if(confirm("Czy na pewno chcesz usunąć wybrane ogłoszenie z komisu ślubnego?")) document.location.href=server+"/komis-slubny/usun/"+id;
}
