/* (c) QuickSoft 2005 */

function is_allowed_control_char(ev) {
	var iKeyCode = ev.which||ev.keyCode;

    //alert(iKeyCode);

 	if ((iKeyCode > 36 && iKeyCode < 41) || (iKeyCode > 34 && iKeyCode < 37)) return true;
 	if (ev.ctrlKey && (iKeyCode == 67 || iKeyCode == 86 || iKeyCode == 88 || iKeyCode == 90)) return true;
 	if ((iKeyCode == 8)) return true;
 	if ((iKeyCode == 9)) return true;
 	// || (iKeyCode == 46)

	return false;
}

function is_digit(kod) {
	return ((kod>47) && (kod<58));
}

function is_myslnik(kod) {
	if (String.fromCharCode(kod) == "-") return true;
	return (kod == 189);
}

function is_dot(kod) {
	if (String.fromCharCode(kod) == ".") return true;
	else return false;
}

function is_plus(kod) {
	if (String.fromCharCode(kod) == "+") return true;
	else return false;
}

function is_nawias(kod) {
	if ((String.fromCharCode(kod) == "(") || (String.fromCharCode(kod) == ")")) return true;
	else return false;
}

function is_spacja(kod) {
	if (String.fromCharCode(kod) == " ") return true;
	else return false;
}


function onkeypress_kod_checker(e, inp) {
	if (is_allowed_control_char(e)) return true;

    var iKeyCode = e.which||e.keyCode;
    var len = inp.value.length;

 	if (len < 2) return is_digit(iKeyCode);
 	else if (len == 2) return is_myslnik(iKeyCode);
 	else if (len < 6) return is_digit(iKeyCode);
	else return false;
}

function onkeypress_data_checker(e, inp) {
	if (is_allowed_control_char(e)) return true;

    var iKeyCode = e.which||e.keyCode;
    var len = inp.value.length;
    
    //for (var i in inp) { alert(i + "-" + inp[i]); } 
    
 	if (len < 2) return is_digit(iKeyCode);
 	else if (len == 2) return is_dot(iKeyCode);
 	else if (len < 5) return is_digit(iKeyCode);
 	else if (len == 5) return is_dot(iKeyCode);
 	else if (len < 10) return is_digit(iKeyCode);
	else return false;
}

function onkeypress_rok_checker(e, inp) {
	if (is_allowed_control_char(e)) return true;

    var iKeyCode = e.which||e.keyCode;
    var len = inp.value.length;
    
 	return is_digit(iKeyCode);
}

function onkeypress_kwota_checker(e, inp) {
	if (is_allowed_control_char(e)) return true;

    var iKeyCode = e.which||e.keyCode;
    var len = inp.value.length;
    
 	return (is_digit(iKeyCode) || is_dot(iKeyCode));
}

function onkeypress_telefon_checker(e, inp) {
	if (is_allowed_control_char(e)) return true;

    var iKeyCode = e.which||e.keyCode;
    
 	return (is_digit(iKeyCode) || is_myslnik(iKeyCode) || is_nawias(iKeyCode) || is_spacja(iKeyCode) || is_plus(iKeyCode));
}

function showEmailDiv(obj) {
	document.getElementById("email_div").style.display = 'block';
}

function hideEmailDiv(obj) {
	document.getElementById("email_div").style.display = 'none';
}

function bodyOnLoad() {
	if (document.getElementById("email_div") == undefined) return;

	hideEmailDiv(document.getElementById("prechoice_1"));
	
	if (document.getElementById("prechoice_1").checked) { return; }
	else if (document.getElementById("prechoice_2").checked) {
		showEmailDiv(document.getElementById("prechoice_2"));
	}
		
	return;
}
