////////////////// START DRAGGING DIVS FUNCTIONS ///////////////////////
var currentdiv="";
var openedHelp=0;

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 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(url, name, width, height,focused) 
{ 
	
	OpenWin = window.open(url, name, 'width='+width+',height='+height+',toolbar=no,focus=yes,menubar=yes,location=no,scrollbars=yes,resizable=yes,status'); 
	if(focused) OpenWin.focus(); 

} 

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)
{
	
	var maxid=10;
	
	for(i=1;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;
	
}

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 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:changeStatus('"+section+"', '"+sql_table+"', '"+sql_column+"','"+sql_id+"', '"+sql_value+"', '"+tdid+"')\"><img src='"+srcnow+"' width=16 height=16></a>";
	
	$.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)
	{
		
		if(document.getElementById(tdid)) document.getElementById(tdid).innerHTML=newcontent;

	}
	});

}

function putFlashHere( sPath, iWidth, iHeight, sID) {
with (document) {
write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="../download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0/#version=5,0,0,0/default.htm" width="'+iWidth+'" height="'+iHeight+'" id="'+sID+'">');
write('  <param name="movie" value="'+sPath+'" />');
write('  <param name="quality" value="best" />');
write('  <param name="wmode" value="transparent" />');
write('  <param name="menu" value="false" />');
write('  <embed src="'+sPath+'" quality="best" wmode="transparent" menu="false" width="'+iWidth+'" height="'+iHeight+'" swLiveConnect=true name="'+sID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="../www.macromedia.com/go/getflashplayer" />');
write('</object>');
}
}

