function comma(elem) {
	str = new String();
	str = elem.value;
	poz = str.indexOf(",");
	if (poz > -1) {
		str = str.replace(/,/i, ".");
		elem.value = str;
	}
}

roundN = function (n,m) {
return Math.round((n*Math.pow(10,m)))/Math.pow(10,m);
}

function przenies(form, count) {
	zal_id = new Array();
	zal_desc = new Array();
	k = 0;
	for (var i=0; i<=count; i++) {
		chk = eval('document.getElementById(\''+form+'_'+i+'_0\').checked');
		if (chk) {
			zal_id[k] = eval('document.getElementById(\'id_'+i+'\').value');
			zal_desc[k] = eval('document.getElementById(\''+form+'_'+i+'_0\').value');
			k++;
		}
	}
	txt = "";
	ids = "";
	for (var i=0; i < k; i++) {
		txt = txt + zal_desc[i] + "<br>";
		ids = ids + ":" + zal_id[i];
	}
	ids = ids + ":";
	window.opener.document.getElementById('attach').innerHTML = txt;
	window.opener.document.getElementById('attach_link').value = "&vars="+ids;
	window.opener.document.getElementById('atts').value = ids;
}

function checkPrint() {
	ok = true;
	if ((document.getElementById('numer').value=="") || (document.getElementById('rez_od').value=="") || (document.getElementById('rez_do').value=="") || 
		(document.getElementById('data_umowy').value=="") || (document.getElementById('start_umowy').value=="") || (document.getElementById('koniec_umowy').value=="") || 
	(document.getElementById('kwota').value==""))
		ok = false;
	return ok;
}

function checkReserve() {
	ok = true;
	if (document.getElementById('b_c_id_k').value==0) {
		alert("Wybierz klienta");
		ok = false;
	} else
  if (document.getElementById('b_p_id_k').value==0) {
		alert("Wybierz typ wynajmu");
		ok = false;
	}
	return ok;
}

function checkUsers() {
	ok = true;
	if (document.getElementById('cu_fname_c').value=="") {
		alert("Wpisz imię");
		ok = false;
	} else
	if (document.getElementById('cu_lname_c').value=="") {
		alert("Wpisz nazwisko");
		ok = false;
	} else
	if (document.getElementById('cu_login_c').value=="") {
		alert("Wpisz login");
		ok = false;
	} else
	if ((document.getElementById('cu_password_c').value=="") && (document.getElementById('_userID').value=="")) {
		alert("Wpisz hasło");
		ok = false;
	} else
	if ((document.getElementById('cu_password_c').value=="") && (document.getElementById('cu_password_c2').value!="")) {
		alert("Wpisz hasło");
		ok = false;
	} else
	if ((document.getElementById('cu_password_c').value!="") && (document.getElementById('cu_password_c2').value=="")) {
		alert("Wpisz powtórnie hasło");
		ok = false;
	} else
	if ((document.getElementById('cu_password_c').value!="") && (document.getElementById('cu_password_c2').value!="") && (document.getElementById('cu_password_c2').value!=document.getElementById('cu_password_c').value)) {
		alert("Hasła się nie zgadzają");
		ok = false;
	}
	return ok;
}

function CheckAll(ff2, main)
{
  if (!main) var main = 'allbox';
	var dlug = eval("document." + ff2 + ".elements.length");
    for (var i=0; i<dlug; i++) {
		var e = eval("document." + ff2 + ".elements[" + i + "]");
		if (e.name != main)
			e.checked = eval("document.getElementById('"+main+"').checked");
    }
}

function go_to_del_calendar(id, id2, id3, id4) {
	window.location.href='calendar,d,'+id+','+id2+','+id3+','+id4;
}

var dtCh= "-";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Format daty powinien być: RRRR-MM-DD")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Proszę wprowadzić prawidłowy miesi±c")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Proszę wprowadzić prawidłowy dzień")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Proszę wprowadzić prawidłowy rok pomiędzy "+minYear+" i "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Proszę wprowadzić prawidłow± datę")
		return false
	}
return true
}

function ValidateDate(dt){
	//var dt=document.frmSample.txtDate
	if (isDate(dt.value)==false){
		dt.focus()
		return false
	}
    return true
}

function go_to(where) {
	eval("location.href='"+where+"'");
}

function aktualnyCzas() {
	teraz = new Date();
	godzina = teraz.getHours();
	minuta = teraz.getMinutes();
	sekunda = teraz.getSeconds();
	godzina = (godzina < 10) ? "0" + godzina : godzina;
	minuta = (minuta < 10) ? "0" + minuta : minuta;
	sekunda = (sekunda < 10) ? "0" + sekunda : sekunda;
	czas = godzina + ":" + minuta + ":" + sekunda;
	document.getElementById('clock').innerHTML = czas;
	setTimeout("aktualnyCzas()",1000);
}

function colorPicker(r,g,b){
 function setColor(x,y,S,C){
  var el=document.createElement('div')
   with(el.style){
    position='absolute'
    left=x+'px';top=y+'px'
    overflow='hidden'
    width=height=S+'px'
    backgroundColor=el.bc=el.title=C
   }
   el.onclick=function(){
    with(document.getElementById('pg_color_c')){
     value=this.bc;focus()}
   }
  document.getElementById('cPicker').appendChild(el)
  }
  function C(x){x*=5;x=x.toString(16);return x+=x}
  for(r=0;r<4;r++)
  for(g=0;g<4;g++)
  for(b=0;b<4;b++)
   setColor(2+(r>1?50:0)+b*12,2+(r%2*50)+g*12,11,'#'+C(r)+C(g)+C(b))
 }
 function shPicker(t,e,x){
  document.getElementById('pg_color_c').focus()
  e=document.getElementById('cPicker').style
  x=e.display=='block'
  e.display=x?'none':'block'
  t.value=x?'pokaż paletę':'ukryj paletę'
 }
 
 function conf_res() {
	 return confirm('Jesteś pewien?\nUsuwasz tą rezerwację');
 }

