/* author: www.auto.pl */
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);

var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);

function textRange(area,ogr){
 var ile = area.value.length;
	if(ile > ogr)
	 { wpisz('0','div' + area.name);
			 area.value =	area.value.substring(0,ogr);	}
	else { ile=ogr-ile; 	wpisz('pozostało:<b> '+ile+'</b> znaków do wprowadzenia.','div' + area.name); }
}
/* sprawdza poprawnosc Emaila */
function checkEmail(theElement)
{
 theElement.value = theElement.value.replace(/[ ]/g,'');
 var email_regex =/^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,4})$/;
 if ( theElement.value.match(email_regex) ){
  return '';
 }else{
  return '&em=';
  }
}
/* ustawia wartosc selecta w formularzu */
function setSelect(formName,elemName,elemValue)
{
  var frm=window.document.forms[formName].elements[elemName];
  var k=0;
  for(i=frm.options.length-1;i>=0;i--)
   {
    if (frm.options[i].value==elemValue){
     k=i;
    }
   } 
  frm.options[k].selected=true;
}

function setStyle(elemName,className)
{
 document.getElementById(elemName).className=className;
}

function Init()
{ window.moveTo( parseInt(screen.availWidth/2) - parseInt((document.body.clientWidth+10)/2) , parseInt(screen.availHeight/2) - parseInt((document.body.clientHeight+30)/2)); }
function setEquip(Tab,wartosc)
{
 wartosc=wartosc.toString(2);
 wartosc=strRevers(wartosc);
 var frm=document.f2;
 var tmp=0;
 for(i=0;i<wartosc.length;i++)
  {
   if ( wartosc.charAt(i)=="1" ){
    tmp=Math.pow(2,i);
	 for(n=0;n<Tab.length;n++){
	  if ( (tmp==Tab[n][3])&&(Tab[n][3]!='-')&&(Tab[n][3]!='') ){
	   frm.elements[Tab[n][0]].checked=1;
	   }
	 }
   }
}
}
function strRevers(orgStr)
{var tmpStr="";
for(i=orgStr.length-1; i>=0;i--)
{tmpStr+=orgStr.charAt(i)	}
return tmpStr;	}
function getIEVersion() {
var ua = navigator.userAgent
var IEOffset = ua.indexOf("MSIE ")
if(IEOffset<=0)
 return 1
else	
 return parseFloat(ua.substring(IEOffset + 5, ua.indexOf(";", IEOffset)))
}
function showHelp(idHelp)
 { 
   var wysokosc=165;
   if(!is_ie){
    wysokosc+=80;
   }
   var opcje="width=320,height="+wysokosc+",status=no,toolbar=no,menubar=no; resize=no;scrollbar=no";
   var linkost="../common/help.php?idh=" + idHelp;
   myHelpWin = window.open(linkost,"winHelp",opcje); }

function checkCcm(theElem)
 {
  theElem.value=theElem.value.replace(/[^0-9]/g,''); // usuwa wszystko co nie jest liczb±
  var liczba=parseInt(theElem.value);
  if (liczba<500)
   { alert("Prawdopodobnie wpisałe¶ zł± pojemno¶ć."); }
 }
 
function checkPln1(theElem)
 {
  theElem.value=theElem.value.replace(/[^0-9]/g,''); // usuwa wszystko co nie jest liczb±
 }

function checkKm(theElem)
 {
  theElem.value=theElem.value.replace(/[^0-9]/g,''); // usuwa wszystko co nie jest liczb±
  var liczba=parseInt(theElem.value);
  if (liczba<1000)
   { alert("Prawdopodobnie wpisałe¶ zł± liczbę kilomertów."); }
 }
 
function checkPln(theElem)
 {
  theElem.value=theElem.value.replace(/[^0-9]/g,''); // usuwa wszystko co nie jest liczb±
  var liczba=parseInt(theElem.value);
  if (liczba<1000)
   { alert("Prawdopodobnie wpisałe¶ zł± cenę."); }
 }

function usunLitery(theElem)
 {
  theElem.value=theElem.value.replace(/[^0-9]/g,''); // usuwa wszystko co nie jest liczb±
 }
function usunLiczby(theElem){
theElem.value=theElem.value.replace(/[^a-zA-Z±¶ćˇńóęˇĘŻ¬ĆŃÓ ]/g,''); // usuwa wszystko co nie jest liczb±
}
function checkKg(theElem)
 {
  theElem.value=theElem.value.replace(/[^0-9]/g,''); // usuwa wszystko co nie jest liczb±
  var liczba=parseInt(theElem.value);
  if (liczba<100)
   { alert("Prawdopodobnie wpisałe¶ zł± liczbę kilogramów."); }
 }

