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 checkCategory() {
	ok = true;
	if (document.forms.category.cc_name_c.value=="") {
		alert("Wpisz nazwę kategorii");
		ok = false;
	}
	return ok;
}

function checkPublication() {
	ok = true;
	if (document.forms.publication.cp_title_c.value=="") {
		alert("Wpisz tytuł publikacji");
		ok = false;
	}  else 
	if (((document.forms.publication.cd_desc_c.value!="") && (document.forms.publication.cd_plik.value=="")) || 
	((document.forms.publication.cd_desc_c.value=="") && (document.forms.publication.cd_plik.value!=""))) {
		alert("Nowy plik musi być razem z opisem");
		ok = false;
	}
	return ok;
}

function checkDocs() {
	ok = true;
	if (document.forms.docs.cd_desc_c.value=="") {
		alert("Wpisz opis pliku");
		ok = false;
	} else
	if (document.forms.docs._filename.value=="" && document.forms.docs.cd_plik.value=="") {
		alert("Wybierz plik");
		ok = false;
	}
	return ok;
}

function checkNews() {
	ok = true;
	if (document.getElementById('cn_date_d').value=="") {
		alert("Wpisz datę");
		ok = false;
	} else
	if (!ValidateDate(document.getElementById('cn_date_d'))) {
		ok = false;
	} else
	if (document.getElementById('cn_title_c').value=="") {
		alert("Wpisz tytuł");
		ok = false;
	} else
	if (document.getElementById('cn_short_c').value=="") {
		alert("Wpisz krótki tekst");
		ok = false;
	} else
	if (tinyMCE.get('cn_long_t').getContent() == "") {
		alert("Wpisz tekst aktualności");
		ok = false;
	}
	return ok;
}

function checkGallery() {
	ok = true;
	if (document.getElementById('cg_name_c').value=="") {
		alert("Wpisz nazwę");
		ok = false;
	}
	return ok;
}

function checkUsers() {
	ok = true;
	if (document.forms.user.cu_fname_c.value=="") {
		alert("Wpisz imię");
		ok = false;
	} else
	if (document.forms.user.cu_lname_c.value=="") {
		alert("Wpisz nazwisko");
		ok = false;
	} else
	if (document.forms.user.cu_login_c.value=="") {
		alert("Wpisz login");
		ok = false;
	} else
	if (document.forms.user._userID.value=="" && document.forms.user.cu_password_c.value=="") {
		alert("Wpisz hasło");
		ok = false;
	}
	return ok;
}

function checkSearch() {
	ok = true;
	if (document.forms.search.word_search.value=="") {
		alert("Wpisz szukaną frazę");
		ok = false;
	} else
	if (document.forms.search.word_search.value.length < 2) {
		alert("Szukana fraza musi mieć więcej niż 2 znaki");
		ok = false;
	}
	return ok;
}

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

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

