﻿function openWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function showFirm(id, lg) {
	openWindow("./sub/firmy/pelnyOpisFirmy.php?idf="+id+"&amp;lang="+lg, "", "width=370, height=300");
}
function my_show_div(obj) {
	 obj = document.getElementById(obj);
	 obj.style.display == 'none' ? obj.style.display = '' : obj.style.display = 'none';
}

function getElementsByClass(searchClass,tag) {
  var classElements = new Array();
  var els = document.getElementsByTagName(tag);
  var elsLen = els.length;
  var pattern = new RegExp("(^|\\s)" + searchClass + "(\\s|$)");
  for (i = 0, j = 0; i < elsLen; i++) {
    if ( pattern.test(els[i].className) ) {
      classElements[j] = els[i];
      j++;
    }
  }
return classElements;
}

function my_divs_init(ajdi) {
	 objs = document.getElementsByTagName('div');

	 for(i = 0, i2 = 0; i < objs.length; i++) {
	 	   if(objs[ i ].id == ajdi) {
		   			objs[ i ].id = ajdi + i2.toString();
					i2++;
		   }
	 }

	 objs = document.getElementsByTagName('a');
	 
	 for(i = 0, i2 = 0; i < objs.length; i++) {
	 	   if(unescape(objs[ i ].href) == "javascript: my_show_div('" + ajdi + "');") {
		   			objs[ i ].href = "javascript: my_show_div('" + ajdi + i2.toString() + "')";
					i2++;
		   }
	 }
}

function zazodz(fieldsName) { // zaznaczenie i odznaczenie checkboxow o wspolnych prefixach
	 chkbx = document.getElementsByName(fieldsName);
	 chkbx_length = chkbx.length;
	 if (document.getElementById('rem_all').checked)
	 	for(i = 0; i < chkbx_length; i++) chkbx[ i ].checked = true;
	 	else for(i = 0; i < chkbx_length; i++) chkbx[ i ].checked = false;
} // function

function czyAll(fieldsName) { // zaznaczenie i odznaczenie opcji wszystkie o wspolnych prefixach
	 chkbx = document.getElementsByName(fieldsName);
	 chkbx_length = chkbx.length;
	 chkbx_checked = 0;
 	 for(i = 0; i < chkbx_length; i++) 
	 	if (chkbx[ i ].checked) chkbx_checked++;
	
	 if (chkbx_checked == chkbx.length)
	 	document.getElementById('rem_all').checked = true;
	 else
	 	document.getElementById('rem_all').checked = false;
} // function


function check_form() {
  if (this.document.forms.rekord.id_kategorii.value == 0) {
    this.window.alert("Nie wybrano kategorii!!!");
  } else this.document.forms.rekord.Submit();
}

function falseSubmit(frm, sbm) {
  if (sbm == 0) { document.getElementById("akcja").value = 0; }

  if (document.getElementById(frm).submit()) document.getElementById(frm).submit();
  this.document.getElementById(frm).Submit();
}


// sprawdzenie poprawnosci podania kolejnosci
function sprawdzPole(formularz, pole)	{

	var blad='';
	validNum=/^[0-9]*$/;
					
    with (formularz) {
		if (pole.value=='') blad+='\n- (pole wymagane)';
		if (pole.value != '' && pole.value.search(validNum) == -1)
			blad+='\n- (dopuszczalne tylko cyfry od 0-9)';
				
		if (blad!='') {
			alert('błąd wypełnienia.\n'+blad);
			pole.value = zmienianaPoz.value;
			return false;
		}  else  {
			 return true;
		   }
	} // while
} // sprawdzPole


function fSubmit(formularz) {
  if (document.getElementById(formularz).submit()) document.getElementById(formularz).submit();
  	else document.getElementById(formularz).Submit();  
}

showHintBox=showHintBoxForVar=function( S,T,W, d,E,b ) {
  d=document;E=d.documentElement;b=d.body;if(!E)return;
  S.h=document.getElementById('plakietkaDiv')
  S.h=S.h.cloneNode(true);
	//if T string was not sent look for title tag and if it's not found give it default string
	S.h.innerHTML = !T ? (S.title?S.title:'&nbsp;value not defined&nbsp;'):unescape( T );
	//set properties essential for div positioning
	with( S.h.style ) { position='absolute'; zIndex=2; top=left=0;}
	//the heart of the script - enable onmousemove event
	S.onmousemove=function(e,l,t,mX, mY,c,h,w){
		e=e||event;
		var di=15; friction=.3;
		with( this.h.style ) {
			//show div
			display='block'; visibility='visible';
			mX = e.clientX+( E.scrollLeft || b.scrollLeft );
			mY = e.clientY+( E.scrollTop  || b.scrollTop  );
			c = clientSize();
			l=parseInt(left),	t=parseInt(top),	h=this.h.offsetHeight,	w=this.h.offsetWidth
			if( c[0]-mX-w < di )
				left=(l > mX-di-w?l+(mX-di-w-l)*friction:mX-di-w)+'px';
			else
				left= (l > mX-w-di && l < mX+di?l+(mX+di-l)*friction: mX+di)+'px';

			if( c[1]-mY-h < di )
				top=(t>mY-di-h?t+(mY-di-h-t)*friction:mY-di-h)+'px';
			else
				top=(t > mY-h-di && t < mY+di?t+(mY+di-t)*friction:mY+di)+'px';
		} return!1;
	}
	//add hiding
	S.onmouseout=function(){
		with( this ) {
			//remove div from document's node tree
	  	if(h)b.removeChild( h );
	  	//stop catching mouse position
			onmousemove=h=null;
		}
		return!1;
  }
  //add div to the document
	b.appendChild(S.h);
}

function clientSize() {
	if (window.innerHeight >= 0) {
		return [window.innerWidth, window.innerHeight];
	} else if (document.documentElement) {
		return [document.documentElement.clientWidth,		document.documentElement.clientHeight]
	} else if (document.body.clientHeight >= 0) {
		return [document.body.clientWidth,document.body.clientHeight]
	} else {
		return [0, 0]
	}
}


function pokazDivEdytowany(idDiv) {
	
	 var objs = getElementsByClass('tblRekordEdit', 'div');

	 for(i = 0; i < objs.length; i++) {
		 objs[i].style.visibility = 'hidden';
		 objs[i].innerHTML = '';
	 }

	document.getElementById('rekordEdit_'+idDiv).style.visibility = 'visible';
	document.getElementById('rekordEdit_'+idDiv).innerHTML = '<div class="insideRekordEdit"><b>Trwa wczytywanie...</b><br/>Proszę o cierpliwość.</div>';	
}

var up;
function pokazPodmenu(pId) {
	if (up) clearTimeout(up);
	document.getElementById('podmenu_'+pId).style.top = document.getElementById('HItem_'+pId).offsetTop + 16 + "px";
	parentLeft = document.getElementById('HItem_'+pId).offsetLeft;
	(parentLeft + 171 > 356)? pLeft = 356 - 171 : pLeft = parentLeft;
	document.getElementById('podmenu_'+pId).style.left = pLeft+"px";	
	document.getElementById('podmenu_'+pId).style.visibility = 'visible';
	document.getElementById('podmenu_'+pId).style.display = 'block';
	
}
function schowajPodmenu(pId) {
	up = setTimeout("schowajTruePodmenu("+pId+")", 250);
}
function schowajTruePodmenu(pId) {
	document.getElementById('podmenu_'+pId).style.visibility = 'hidden';
	document.getElementById('podmenu_'+pId).style.display = 'none';	
}

function highlightStars(ida, nr) {
	for (s = 1; s <= nr; s++)
		document.getElementById("star_"+ida+"_"+s).src = './gfx/staron.gif';
}

function turnoffStars(ida, nr) {
	for (s = 1; s <= nr; s++)
		document.getElementById("star_"+ida+"_"+s).src = './gfx/staroff.gif';	
}


// do sklepu
  function nowaWartosc(fieldname, wartosc){
  	document.getElementById(fieldname).value = wartosc;
  }

