function disableElement(id)
{
  document.getElementById(id).disabled=true;
}

function enableElement(id)
{
  document.getElementById(id).disabled=false;
}


function checkAmount(id)
{
  var amount = document.getElementById(id).value;
  //var position_slash = amount.indexOf("-");
  if (amount == "" || amount == "0")
  {
    hideDiv('requirements_existing_mortgage_prepared_to_pay_redemption_input');
    hideDiv('requirements_existing_mortgage_prepared_to_pay_redemption_text');
  } else
  {
    showDiv('requirements_existing_mortgage_prepared_to_pay_redemption_input');
    showDiv('requirements_existing_mortgage_prepared_to_pay_redemption_text');
  }
  return true;
}


function checkDeclaration(formObj)
{
	//obj = document.getElementById('applicant_one_fore_name');
	
	//alert('jedu');
  // applicant's one names

	if(document.getElementById('applicant_one_fore_name').value == "")
	{
		alert('Please fill Applicant One forename.');
		document.getElementById('applicant_one_fore_name').focus();
		return false;
	}

	if(document.getElementById('applicant_one_sur_name').value == "")
	{
		alert('Please fill Applicant One surname.');
		document.getElementById('applicant_one_sur_name').focus();
		return false;
	}


  // applicant's one date of Birth
  var day = document.getElementById('applicant_one_DOB_day').options[document.getElementById('applicant_one_DOB_day').selectedIndex].value;	
  var month = document.getElementById('applicant_one_DOB_month').options[document.getElementById('applicant_one_DOB_month').selectedIndex].value;	
  var year = document.getElementById('applicant_one_DOB_year').options[document.getElementById('applicant_one_DOB_year').selectedIndex].value;	
  if(day == "null" || month == "null" || year == "null")
  {
    alert("Please enter Applicant's One Day Of Birth.");
    document.getElementById('applicant_one_DOB_day').focus();
    return false;
  }

    // applicant's two names
  if(document.getElementById('bwap_yes').checked == true)
  { 
    return checkApplicantTwoDeclaration();
  }

  
  
  // Known changes check
  if (document.getElementById('knownchanges_yes').checked==false && document.getElementById('knownchanges_no').checked==false)
  {
    alert('Please provide decision regarding Known Changes.');
    document.getElementById('knownchanges_yes').focus();
    return false;
  }

	if(formObj.declaration_authorise.checked == false)
	{
		alert('Please authorize our declaration by entering a tick in the box.\nWithout your permission we cannot progress your offer in principle.');
		document.getElementById('declaration_authorise').focus();
		return false;
	}
	else
		return true;
}


function checkDeclaration_mainOip(formObj)
{
	//obj = document.getElementById('applicant_one_fore_name');
	
	//alert('jedu');
  // applicant's one names

	if(document.getElementById('requirements_name').value == "")
	{
		alert('Please enter your name.');
		document.getElementById('requirements_name').focus();
		return false;
	}


	email = document.getElementById('requirements_email').value;
	if(!checkEmail(email))
	{
		alert('Please enter your email correctly.');
		document.getElementById('requirements_email').focus();
		return false;
	}

	if(document.getElementById('requirements_proposed_purchase_price').value == "")
	{
		alert('Please enter a Proposed purchase price.');
		document.getElementById('requirements_proposed_purchase_price').focus();
		return false;
	}

	if(document.getElementById('requirements_loan_required').value == "")
	{
		alert('Please enter a Loan Required.');
		document.getElementById('requirements_loan_required').focus();
		return false;
	}




	if(document.getElementById('applicant_one_fore_name').value == "")
	{
		alert('Please fill Applicant One forename.');
		document.getElementById('applicant_one_fore_name').focus();
		return false;
	}

	if(document.getElementById('applicant_one_sur_name').value == "")
	{
		alert('Please fill Applicant One surname.');
		document.getElementById('applicant_one_sur_name').focus();
		return false;
	}


  // applicant's one date of Birth
  var day = document.getElementById('applicant_one_DOB_day').options[document.getElementById('applicant_one_DOB_day').selectedIndex].value;	
  var month = document.getElementById('applicant_one_DOB_month').options[document.getElementById('applicant_one_DOB_month').selectedIndex].value;	
  var year = document.getElementById('applicant_one_DOB_year').options[document.getElementById('applicant_one_DOB_year').selectedIndex].value;	
  if(day == "null" || month == "null" || year == "null")
  {
    alert("Please enter Applicant's One Day Of Birth.");
    document.getElementById('applicant_one_DOB_day').focus();
    return false;
  }

	// applicant's one current address 
	if(document.getElementById('applicant_one_current_address').value == "")
	{
		alert('Please fill Applicant One Current Address.');
		document.getElementById('applicant_one_current_address').focus();
		return false;
	}

	// applicant's one current address 
	if(document.getElementById('applicant_one_postcode').value == "")
	{
		alert('Please fill Applicant One Postcode.');
		document.getElementById('applicant_one_postcode').focus();
		return false;
	}

  // Known changes check
  if (document.getElementById('knownchanges_yes').checked==false && document.getElementById('knownchanges_no').checked==false)
  {
    alert('Please provide decision regarding Known Changes.');
    document.getElementById('knownchanges_yes').focus();
    return false;
  }

  // Please provide at least one CONTACT
  if ( document.getElementById('additional_daytime_telephone').value == '' && document.getElementById('additional_evening_telephone').value == '' && document.getElementById('additional_mobile_telephone').value == '') {
    alert('Please provide at least one contact telephone number.');
    (document.getElementById('additional_daytime_telephone')).focus();
    return false;
  }

	if(formObj.declaration_authorise.checked == false)
	{
		alert('Please authorize our declaration by entering a tick in the box.\nWithout your permission we cannot progress your offer in principle.');
		document.getElementById('declaration_authorise').focus();
		return false;
	}

  // applicant's two names
  if(document.getElementById('bwap_yes').checked == true)
  { 
    return checkApplicantTwoDeclaration();
  }
	
  return true;
}

// check APPLICANTs TWO mandatory fields
function checkApplicantTwoDeclaration()
{
  	if(document.getElementById('applicant_two_fore_name').value == "")
  	{
  		alert('Please fill Applicant Two forename.');
  		document.getElementById('applicant_two_fore_name').focus();
  		return false;
  	}
  	if(document.getElementById('applicant_two_sur_name').value == "")
  	{
  		alert('Please fill Applicant Two surname.');
  		document.getElementById('applicant_two_sur_name').focus();
  		return false;
  	}
    // applicant's one date of Birth
    var day = document.getElementById('applicant_two_DOB_day').options[document.getElementById('applicant_two_DOB_day').selectedIndex].value;	
    var month = document.getElementById('applicant_two_DOB_month').options[document.getElementById('applicant_two_DOB_month').selectedIndex].value;	
    var year = document.getElementById('applicant_two_DOB_year').options[document.getElementById('applicant_two_DOB_year').selectedIndex].value;	
    if(day == "null" || month == "null" || year == "null")
    {
      alert("Please enter Applicant's Two Day Of Birth.");
      document.getElementById('applicant_two_DOB_day').focus();
      return false;
    }
  
  	// applicant's two current address 
  	if(document.getElementById('applicant_two_current_address').value == "")
  	{
  		alert('Please fill Applicant Two Current Address.');
  		document.getElementById('applicant_two_current_address').focus();
  		return false;
  	}

  	// applicant's two current address 
  	if(document.getElementById('applicant_two_postcode').value == "")
  	{
  		alert('Please fill Applicant Two Postcode.');
  		document.getElementById('applicant_two_postcode').focus();
  		return false;
  	}
  
  
    return true;
}

function copyContent(fromId, toId)
{
	if(document.getElementById(fromId))
	{
		fromobj = document.getElementById(fromId);
		contents = fromobj.value;
		toObj = document.getElementById(toId);
		toObj.value = contents;	
	}
	else
	{
		return false;
	}

}

function copySelectedOption(fromId, toId)
{
	if(document.getElementById(fromId))
	{
		fromobj = document.getElementById(fromId);
		toObj = document.getElementById(toId);
		toObj.value = fromobj.options[fromobj.selectedIndex].value;	
	}
	else
	{
		return false;
	}

}

function copyDependents(fromId, toId, showId)
{
	if(document.getElementById(fromId))
	{
		fromobj = document.getElementById(fromId);
		contents = fromobj.innerHTML;
		toObj = document.getElementById(toId);
		toObj.innerHTML = contents;	
		showDiv(showId);
	}
	else
	{
		return false;
	}
}

function showDiv(divId)
{
  //alert('processing showDiv()');
	if(document.getElementById(divId))
	{
	 
		obj = document.getElementById(divId);
		obj.style.display = 'block';
		return true;
	}
	else
	{
		return false;
	}
}

function showSpan(spanId)
{
	if(document.getElementById(spanId))
	{
		obj = document.getElementById(spanId);
		obj.style.display = '';
		return true;
	}
	else
	{
		return false;
	}
}
function hideDiv(divId)
{
	if(document.getElementById(divId))
	{
		obj = document.getElementById(divId);
		obj.style.display = 'none';
		return true;
	}
	else
	{
		return false;
	}
}

function bankToggleDiv(value, divId)
{
	if(value == "other")
	{
		showSpan(divId);
	}
	else
	{
		hideDiv(divId);
	}

}

function selfEmpToggleDiv(value, divId)
{
	if(value == "Self Employed")
	{
		showDiv('applicant_one_selfempdetails');
	}
	else
	{
		hideDiv('applicant_one_selfempdetails');
		hideDiv('applicant_one_normal_emplyed_income');
		showDiv('applicant_one_normal_income');
	}

	if(value == "Employed")
	{
		showDiv('applicant_one_normal_emplyed_income');
		hideDiv('applicant_one_normal_income');
	}
	else
	{
		hideDiv('applicant_one_normal_emplyed_income');
		showDiv('applicant_one_normal_income');
	}
  
  //showDiv('applicant_one_normal_income');
  return true;
}

function selfEmpApp2ToggleDiv(value, divId)
{
	if(value == "Self Employed")
	{
		showDiv('applicant_two_selfempdetails');
	}
	else
	{
		hideDiv('applicant_two_selfempdetails');
		hideDiv('applicant_two_normal_emplyed_income');
		showDiv('applicant_two_normal_income');
	}

	if(value == "Employed")
	{
		showDiv('applicant_two_normal_emplyed_income');
		hideDiv('applicant_two_normal_income');
	}
	else
	{
		hideDiv('applicant_two_normal_emplyed_income');
		showDiv('applicant_two_normal_income');
	}
  
  //showDiv('applicant_one_normal_income');
  return true;
}


function calculate_one() {
     day = document.getElementById("applicant_one_moved_in_day").options[document.getElementById("applicant_one_moved_in_day").selectedIndex].value;
     month = document.getElementById("applicant_one_moved_in_month").options[document.getElementById("applicant_one_moved_in_month").selectedIndex].value;
     year = document.getElementById("applicant_one_moved_in_year").options[document.getElementById("applicant_one_moved_in_year").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      showDiv('applicant_notice');
      showDiv('applicant_one_previous_address');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        showDiv('applicant_notice');
        showDiv('applicant_one_previous_address');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        showDiv('applicant_notice');
        showDiv('applicant_one_previous_address');
        return true;
      }
    hideDiv('applicant_notice');
    hideDiv('applicant_one_previous_address');
    return false;
}

function calculate_one_2() {
     day = document.getElementById("applicant_one_previous_moved_in_day").options[document.getElementById("applicant_one_previous_moved_in_day").selectedIndex].value;
     month = document.getElementById("applicant_one_previous_moved_in_month").options[document.getElementById("applicant_one_previous_moved_in_month").selectedIndex].value;
     year = document.getElementById("applicant_one_previous_moved_in_year").options[document.getElementById("applicant_one_previous_moved_in_year").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      //showDiv('applicant_notice');
      showDiv('applicant_one_previous_address2');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        //showDiv('applicant_notice');
        showDiv('applicant_one_previous_address2');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        //showDiv('applicant_notice');
        showDiv('applicant_one_previous_address2');
        return true;
      }
    //hideDiv('applicant_notice');
    hideDiv('applicant_one_previous_address2');
    return false;
}

function calculate_one_3() {
     day = document.getElementById("applicant_one_previous_moved_in_day2").options[document.getElementById("applicant_one_previous_moved_in_day2").selectedIndex].value;
     month = document.getElementById("applicant_one_previous_moved_in_month2").options[document.getElementById("applicant_one_previous_moved_in_month2").selectedIndex].value;
     year = document.getElementById("applicant_one_previous_moved_in_year2").options[document.getElementById("applicant_one_previous_moved_in_year2").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      //showDiv('applicant_notice');
      showDiv('applicant_one_previous_address3');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        //showDiv('applicant_notice');
        showDiv('applicant_one_previous_address3');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        //showDiv('applicant_notice');
        showDiv('applicant_one_previous_address3');
        return true;
      }
    //hideDiv('applicant_notice');
    hideDiv('applicant_one_previous_address3');
    return false;
}

function calculate_one_4() {
     day = document.getElementById("applicant_one_previous_moved_in_day3").options[document.getElementById("applicant_one_previous_moved_in_day3").selectedIndex].value;
     month = document.getElementById("applicant_one_previous_moved_in_month3").options[document.getElementById("applicant_one_previous_moved_in_month3").selectedIndex].value;
     year = document.getElementById("applicant_one_previous_moved_in_year3").options[document.getElementById("applicant_one_previous_moved_in_year3").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      //showDiv('applicant_notice');
      showDiv('applicant_one_previous_address4');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        //showDiv('applicant_notice');
        showDiv('applicant_one_previous_address4');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        //showDiv('applicant_notice');
        showDiv('applicant_one_previous_address4');
        return true;
      }
    //hideDiv('applicant_notice');
    hideDiv('applicant_one_previous_address4');
    return false;
}

function calculate_two() {
 
     day = document.getElementById("applicant_two_moved_in_day").options[document.getElementById("applicant_two_moved_in_day").selectedIndex].value;

     month = document.getElementById("applicant_two_moved_in_month").options[document.getElementById("applicant_two_moved_in_month").selectedIndex].value;
 //document.write(month);
     year = document.getElementById("applicant_two_moved_in_year").options[document.getElementById("applicant_two_moved_in_year").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    
    if ( (act_year-year) < 3 ) 
    {
      // add showing all other components
      showDiv('applicant_two_notice');
      showDiv('applicant_two_previous_address');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        // add showing all other components
      showDiv('applicant_two_notice');
      showDiv('applicant_two_previous_address');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        // add showing all other components
      showDiv('applicant_two_notice');
      showDiv('applicant_two_previous_address');

        return true;
      }

    // add showing all other components
      hideDiv('applicant_two_notice');
      hideDiv('applicant_two_previous_address');

    return false;
}

function calculate_two_2() {
     day = document.getElementById("applicant_two_previous_moved_in_day").options[document.getElementById("applicant_two_previous_moved_in_day").selectedIndex].value;
     month = document.getElementById("applicant_two_previous_moved_in_month").options[document.getElementById("applicant_two_previous_moved_in_month").selectedIndex].value;
    //document.write(month);
     year = document.getElementById("applicant_two_previous_moved_in_year").options[document.getElementById("applicant_two_previous_moved_in_year").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      //showDiv('applicant_notice');
      showDiv('applicant_two_previous_address2');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        //showDiv('applicant_notice');
        showDiv('applicant_two_previous_address2');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        //showDiv('applicant_notice');
        showDiv('applicant_two_previous_address2');
        return true;
      }
    //hideDiv('applicant_notice');
    hideDiv('applicant_two_previous_address2');
    return false;
}

function calculate_two_3() {
    
     day = document.getElementById("applicant_two_previous_moved_in_day2").options[document.getElementById("applicant_two_previous_moved_in_day2").selectedIndex].value;
     month = document.getElementById("applicant_two_previous_moved_in_month2").options[document.getElementById("applicant_two_previous_moved_in_month2").selectedIndex].value;
    //document.write(month);
     year = document.getElementById("applicant_two_previous_moved_in_year2").options[document.getElementById("applicant_two_previous_moved_in_year2").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      //showDiv('applicant_notice');
      showDiv('applicant_two_previous_address3');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        //showDiv('applicant_notice');
        showDiv('applicant_two_previous_address3');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        //showDiv('applicant_notice');
        showDiv('applicant_two_previous_address3');
        return true;
      }
    //hideDiv('applicant_notice');
    hideDiv('applicant_two_previous_address3');
    return false;
}

function calculate_two_4() {
     day = document.getElementById("applicant_two_previous_moved_in_day3").options[document.getElementById("applicant_two_previous_moved_in_day3").selectedIndex].value;
     month = document.getElementById("applicant_two_previous_moved_in_month3").options[document.getElementById("applicant_two_previous_moved_in_month3").selectedIndex].value;
    //document.write(month);
     year = document.getElementById("applicant_two_previous_moved_in_year3").options[document.getElementById("applicant_two_previous_moved_in_year3").selectedIndex].value;
    // get actuall date
    var date = new Date();
    act_day = date.getDate();
    act_month = date.getMonth() + 1;
    act_year = date.getFullYear();
    if ( (act_year-year) < 3 ) 
    {
      //showDiv('applicant_notice');
      showDiv('applicant_two_previous_address4');
      return true; 
    }
    if ( (act_year-year)==3 && (act_month<month))
      {
        //showDiv('applicant_notice');
        showDiv('applicant_two_previous_address4');
        return true;
      }
    if ( (act_year-year)==3 && (act_month==month) && (act_day<=day))
     {
        //showDiv('applicant_notice');
        showDiv('applicant_two_previous_address4');
        return true;
      }
    //hideDiv('applicant_notice');
    hideDiv('applicant_two_previous_address4');
    return false;
}

function dependentsToggleDiv(value, divId, inputSpanId, applicant)
{
	
	if(value == "more")
	{
		obj = document.getElementById(inputSpanId);
		obj.innerHTML = "";
		hideDiv(divId);
		showSpan(applicant + "_dependents10plus");
		return true;
	}
	else
	{
		hideDiv(applicant + "_dependents10plus");
	}
	
	if(value != "null" && value > 0)
	{
		if(value > 20)
		{
			alert("You can't have more than 20 dependants!");
			showSpan(applicant + "_dependents10plus");
			return false;
		}
		obj = document.getElementById(inputSpanId);
		obj.innerHTML = "";
		for(i=0;i<value;i++)
		{
			j = i + 1;
			obj.innerHTML += "<div style='padding-bottom:3px'><input type='text' name='" + applicant + "_dependant_age_" + j + "' size='3' maxlength='2'> years old<div>";
		}
		showDiv(divId);
	}
	else
	{
		hideDiv(divId);	
	}

}

function showRent(select, applicant_div1, applicant_div2)
{
  if ( document.getElementById(select).selectedIndex == 2 || document.getElementById(select).selectedIndex == 3 ) {  
    showDiv(applicant_div1);                                            
    showDiv(applicant_div2);
    return true;
  } else {
    hideDiv(applicant_div1);                                            
    hideDiv(applicant_div2);
    return true;
  }
  return false;
}


function check()
{
  foreName = document.getElementById('fore_name');
  if (foreName == "") {
    alert('Please fill your name.');
    return false;
    }
  return true;

}

// function checks correct of email
function checkEmail(adresa){
   var pozice_zavinace = adresa.indexOf("@");
   var pozice_tecky = adresa.indexOf(".");
    if (pozice_zavinace < 0)
        return false;
    if (pozice_tecky < 0)
        return false;
    var cast_pred_zavinacem = adresa.substring(0,pozice_zavinace);
    var cast_po_zavinaci = adresa.substring(pozice_zavinace+1,adresa.length);
    if (cast_po_zavinaci.indexOf("@") >= 0)
        return false;
    if (cast_pred_zavinacem.length <= 0)
        return false;
    if (cast_po_zavinaci.length <= 0)
        return false;

    // ... pr(ípadné další kontroly ...

    return true;
}
