function CheckForm1() {
  var text = "";
  
  if(document.agent_contact.phone.value == "") text = text+"- Váš telefón\n";
  if(document.agent_contact.email2.value == "") text = text+"- Váš e-mail\n";
  if(document.agent_contact.message.value == "") text = text+"- Správa\n";
  
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm2() {
  var text = "";
  
  if(document.send_to_friend.email1.value == "") text = text+"- E-mail príjemcu\n";
  if(document.send_to_friend.email2.value == "") text = text+"- Váš e-mail\n";
  if(document.send_to_friend.message.value == "") text = text+"- Správa\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm3() {
  var text = "";
  
  if(document.offer_add.id_type.value == "") text = text+"- Kategória\n";
  if(document.offer_add.id_district.value == "") text = text+"- Kraj\n";
  if(document.offer_add.locality.value == "") text = text+"- Lokalita\n";
  if(document.offer_add.description.value == "") text = text+"- Popis\n";
  if(document.offer_add.name.value == "") text = text+"- Meno\n";
  if(document.offer_add.surname.value == "") text = text+"- Priezvisko\n";
  if(document.offer_add.phone.value == "") text = text+"- Telefón\n";
  if(document.offer_add.email.value == "") text = text+"- E-mail\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm4() {
  var text = "";
  
  if(document.query_add.id_type.value == "") text = text+"- Kategória\n";
  if(document.query_add.id_district.value == "") text = text+"- Kraj\n";
  if(document.query_add.locality.value == "") text = text+"- Lokalita\n";
  if(document.query_add.description.value == "") text = text+"- Popis\n";
  if(document.query_add.name.value == "") text = text+"- Meno\n";
  if(document.query_add.surname.value == "") text = text+"- Priezvisko\n";
  if(document.query_add.phone.value == "") text = text+"- Telefón\n";
  if(document.query_add.email.value == "") text = text+"- E-mail\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function EmailCheck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		return false
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		return false
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		return false
	}
	if (str.indexOf(at,(lat+1))!=-1){
		return false
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		return false
	}
	if (str.indexOf(dot,(lat+2))==-1){
		return false
	}
	if (str.indexOf(" ")!=-1){
		return false
	}
 	return true					
}



function CheckForm5() {
  var text = "";
  
  if(document.regForm.email.value == "") text = text+"- Login (e-mail)\n";
  else
  {
    if(EmailCheck(document.regForm.email.value) == false) text = text+"- Login musí byť v tvare e-mailu\n";
  }
  if(document.regForm.password.value == "") text = text+"- Heslo\n";
  if(document.regForm.password1.value == "") text = text+"- Heslo (znova)\n";
  if(document.regForm.password.value != document.regForm.password1.value) text = text+"- Heslo a Heslo (znova) sa nezhodujú\n";
  if(document.regForm.name.value == "") text = text+"- Meno\n";
  if(document.regForm.surname.value == "") text = text+"- Priezvisko\n";
  if(document.regForm.address.value == "") text = text+"- Adresa\n";
  if(document.regForm.city.value == "") text = text+"- Mesto\n";
  if(document.regForm.postal_code.value == "") text = text+"- PSČ\n";
  if(document.regForm.phone.value == "") text = text+"- Telefón\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm6() {
  var text = "";
  
  if(document.save_search.name.value == "") text = text+"- Názov\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm7() {
  var text = "";
  
  if(document.best_price.name.value == "") text = text+"- Meno a Priezvisko\n";
  if(document.best_price.telefon.value == "") text = text+"- Telefón\n";
  if(document.best_price.email2.value == "") text = text+"- Email\n";  
  if(document.best_price.best_price.value == "") text = text+"- Navrhovaná cena\n";
  if(!IsNumeric(document.best_price.best_price.value)) text = text+"- Cena musí byť číslo\n";
  if(document.best_price.message.value == "") text = text+"- Správa\n";
  if(ValidBotBoot() == false) text = text+"- Kontrolny súčet je nesprávny\n";
  
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else {
     return true; 
  }
  

  
}

function CheckSearchForm8() {
  var text = "";
  if(document.fulltext_search_form.fulltext_input.value == "") text = text+"- 3znaky\n";
  
  if(text != "") {
    text = "Minimálny počet znakov:\n=======================\n"+text+"=======================\nProsím vyplnte aspoň 3 znaky.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm9() {
  var text = "";
  if(document.hire_request.county.value == "") text = text+"- Lokalita\n";
  if(document.hire_request.notes.value == "") text = text+"- Poznámka\n";
  if(document.hire_request.name.value == "") text = text+"- Meno\n";
  if(document.hire_request.surname.value == "") text = text+"- Priezvisko\n";
  if(document.hire_request.phone.value == "") text = text+"- Telefón\n";
  if(document.hire_request.email.value == "") text = text+"- E-mail\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function CheckForm10() {
  var text = "";
  if(document.franchise.county.value == "") text = text+"- Lokalita\n";
  if(document.franchise.notes.value == "") text = text+"- Poznámka\n";
  if(document.franchise.name.value == "") text = text+"- Meno\n";
  if(document.franchise.surname.value == "") text = text+"- Priezvisko\n";
  if(document.franchise.phone.value == "") text = text+"- Telefón\n";
  if(document.franchise.email.value == "") text = text+"- E-mail\n";
  
  if(text != "") {
    text = "Tieto údaje sú povinné:\n=======================\n"+text+"=======================\nProsím vyplňte všetky povinné údaje.";
    alert(text);
    return false;
  } else return true;
}

function IsNumeric(sText)
{
   var ValidChars = "0123456789.,";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }
	
  function DrawBotBoot()
    {
    //var a = Math.ceil(Math.random() * 10);
    //var b = Math.ceil(Math.random() * 10);       
    //var c = a + b 	
        document.write("Spočítajte "+ a + " + " + b +"? ");
        document.write("<input id='checkInput' value="+ c +"  type='hidden' maxlength='2' size='2'/>");
    }   

	
    function ValidBotBoot(){
        var d = document.getElementById('BotBootInput').value;
        if (d == c) return true;        
        return false;
        
    }

    function checkForZero(field) {
        if (field.value == 0 || field.value.length == 0) {
            alert ("Tento údaj nemôže byť 0!");
            field.focus(); }
        else
	    calculatePayment(field.form);
    }

    function cmdCalc_Click(form) {
        if (form.price.value == 0 || form.price.value.length == 0) {
            alert ("Tento údaj nemôže byť 0!");
            form.price.focus(); }
        else if (form.ir.value == 0 || form.ir.value.length == 0) {
            alert ("Úroková sadzba nemôže byť 0!");
            form.ir.focus(); }
        else if (form.term.value == 0 || form.term.value.length == 0) {
            alert ("Trvanie hypotéky nemôže byť 0!");
            form.term.focus(); }
        else
            calculatePayment(form);
    }

    function calculatePayment(form) {
        princ = form.price.value - form.dp.value;
        intRate = (form.ir.value/100) / 12;
        months = form.term.value * 12;
        form.pmt.value = Math.floor((princ*intRate)/(1-Math.pow(1+intRate,(-1*months)))*100)/100;
  	form.principle.value = princ;
	form.payments.value = months;
    }



