//	Vyměna barvy pozadí
function setBgColor (id, color) {

	if (document.layers)
		document[id].bgColor = color == 'transparent' ? null : color;
	else if (document.all)
		document.all[id].style.backgroundColor = color;
	else if (document.getElementById)
		document.getElementById(id).style.backgroundColor = color;

}

//	Vyměna obrázku pozadí
function setBgImage (id, imageURL) {

	if (document.layers)
		document[id].background.src = imageURL == 'none' ? null : imageURL;
	else if (document.all)
		document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
	else if (document.getElementById)
		document.getElementById(id).style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';

}

function check_email(adresa) {
//	re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
	re = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	return adresa.search(re) == 0;
}

//	Zobrazování polí pro vyplnění údaje o firmě
function ukaz_ruceni(cim) {
    if(cim == "ne") {
		document.getElementById('ruc_0').style.display='none';
		document.getElementById('ruc_1').style.display='none';
	    document.getElementById('ruc_2').style.display='none';
	    document.getElementById('ruc_3').style.display='none';
	    document.getElementById('ruc_4').style.display='none';
	    document.getElementById('ruc_5').style.display='none';
    }
	if(cim == "ano") {
		document.getElementById('ruc_0').style.display='';
		document.getElementById('ruc_1').style.display='';
	    document.getElementById('ruc_2').style.display='';
	    document.getElementById('ruc_3').style.display='';
	    document.getElementById('ruc_4').style.display='none';
	    document.getElementById('ruc_5').style.display='none';
	}
}

//	Zobrazování polí pro vyplnění údaje o firmě
function ukaz_typ_ruceni(cim) {
    if(cim == "n") {
		document.getElementById('ruc_1').style.display='';
	    document.getElementById('ruc_2').style.display='';
	    document.getElementById('ruc_3').style.display='';
	    document.getElementById('ruc_4').style.display='none';
	    document.getElementById('ruc_5').style.display='none';
    } else if(cim == "a") {
		document.getElementById('ruc_1').style.display='none';
	    document.getElementById('ruc_2').style.display='none';
	    document.getElementById('ruc_3').style.display='none';
	    document.getElementById('ruc_4').style.display='';
	    document.getElementById('ruc_5').style.display='';
    } else if(cim == "an") {
		document.getElementById('ruc_1').style.display='';
	    document.getElementById('ruc_2').style.display='';
	    document.getElementById('ruc_3').style.display='';
	    document.getElementById('ruc_4').style.display='';
	    document.getElementById('ruc_5').style.display='';
	}
}


function isDate(day, month, year) {
	if (month < 1 || month > 12) return false;
	if (day < 1 || day > 31) return false;
	if ((month==4 || month==6 || month==9 || month==11) && day==31) return false;
	if (month == 2) {
		var leap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !leap)) return false;
	}
	return true;
}


function verifyRC(rc) {

	var regvyraz1=new RegExp(/^\s*(\d\d)(\d\d)(\d\d)[ /]*(\d\d\d)(\d?)\s*$/);
	var i=0; //inicializace - počet nalezených shod
	var subvyrazy=""; //řetězec pro zapamatování subvýrazů
	while(result1=regvyraz1.exec(rc))
	{
		for(var j=0;result1[j];j++) {
		   if(j==1) var year = result1[j];
		   if(j==2) var month = result1[j];
		   if(j==3) var day = result1[j];
		   if(j==4) var ext = result1[j];
		   if(j==5) var c = result1[j];
		}

		if(!regvyraz1.global) break; //opatření proti zacyklení
		i++; //inkrementace počtu nalezených shod
	}


	// do roku 1954 přidělovaná devítimístná RČ nelze ověřit
	if (c === '') {
		return year < 54;
	}

	// kontrolní číslice
	var mod = eval(year + month + day + ext + "") % 11;
//	document.scoring.mobil.value = mod + "\n";
	if (typeof mod == "number" && mod == 10) mod = 0;
	if (typeof mod != "number" || mod != c) {
		return false;
	}

	// kontrola data
	if(year < 54) {
		year += year + 2000;
	} else {
		year += year + 1900;
	}

	// k měsíci může být připočteno 20, 50 nebo 70
	if (month > 70 && year > 2003) {
		month -= 70;
	} else if (month > 50) {
		month -= 50;
	} else if (month > 20 && year > 2003) {
		month -= 20;
	}

	if (!isDate(day, month, year)) {
		return false;
	} else {
		// cislo je OK
		document.scoring.validRC.value = year + month + day + ext + c + "";
		return true;
	}

}


function scoringForm() {

	mail = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	tel = /^[\+][0-9]{3}[ ][0-9]{9}$/;
	rc = /^\s*(\d\d)(\d\d)(\d\d)[ /]*(\d\d\d)(\d?)\s*$/;
	tel2 = /^\s*(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)(\d)\s*$/;

	if ( document.scoring.jmeno.value == "" ) {
		alert("Vyplňte prosím Vaše jméno.");
		document.scoring.jmeno.focus();
		return false;
	}

	if ( document.scoring.prijmeni.value == "" ) {
		alert("Vyplňte prosím Vaše příjmení.");
		document.scoring.prijmeni.focus();
		return false;
	}

	if ( document.scoring.rc.value == "" ) {
		alert("Vyplňte prosím Vaše rodné číslo.");
		document.scoring.rc.focus();
		return false;
	}
/*
	if ( verifyRC(document.scoring.rc.value) == false ) {
		alert("Vyplněné rodné číslo není platné.");
		document.scoring.rc.focus();
		document.scoring.rc.select();
		return false;
	}
*/
	if ( document.scoring.obec.value == "" ) {
		alert("Vyplňte prosím obec Vašeho bydliště.");
		document.scoring.obec.focus();
		return false;
	}

	if ( document.scoring.castka.value == "" ) {
		alert("Vyplňte prosím Vámi požadovanou částku.");
		document.scoring.castka.focus();
		return false;
	}

	if (document.scoring.mobil.value == "") {
		alert ("Vyplňte prosím číslo Vašeho mobilního telefonu.");
		document.scoring.mobil.focus();
		return false;
	}

	if (document.scoring.ruceni[1].checked) {

		if (document.scoring.typ_ruceni[0].checked) {

			if (document.scoring.n_cena.value == "") {
				alert ("Vyplňte prosím tržní cenu nemovitosti.");
				document.scoring.n_cena.focus();
				return false;
			}

		}

		if(document.scoring.typ_ruceni[1].checked) {

			if (document.scoring.a_cena.value == "") {
				alert ("Vyplňte prosím tržní cenu automobilu.");
				document.scoring.a_cena.focus();
				return false;
			}

		}

	}

	dotaz = window.confirm("Jste si jistí, že všechny údaje jsou správně vyplněny?");
	if (dotaz == true) {
		document.scoring.submit();
	} else {
		return false;
	}

}

function sendmail() {

	if(document.napiste.jmeno.value == "") {
		alert("Vyplňte, prosím, Vaše jméno a příjmení!");
		document.napiste.jmeno.focus();
		return false;
	}
	if(document.napiste.email.value == "") {
		alert("Vyplňte, prosím, Vaši emailovou adresu!");
		document.napiste.email.focus();
		return false;
	}
	if (!check_email(document.napiste.email.value) ) {
	   alert("Vaše emailová adresa není vyplněna správně!");
	   document.napiste.email.focus();
	   return false;
	}
	if(document.napiste.zprava.value == "") {
		alert("Teď už nám jen něco napište! :-)");
		document.napiste.zprava.focus();
		return false;
	}
	document.napiste.submit();

}

function jdinastranu(adresa) {
	location.href = adresa;
}
