




function mortage_calculator_box() {
	document.getElementById("calculatedrate").innerHTML = document.getElementById("calculatedrate1").innerHTML
	document.getElementById('box_mortage_calculator_a').style.display='block';
	document.getElementById('det_l1').style.display='none';
	//document.getElementById('test').style.display='none';
}
function mortage_calculator_box_a() {
	document.getElementById('det_l1').style.display='block';
	document.getElementById('box_mortage_calculator_a').style.display='none';
}



function Expand1()
{
	str = document.getElementById("mainValue").value
	simpleValue = document.getElementById("simpleValue").value
    var s = document.getElementById("Mortage");
	propp = property_price.replace(",","");
	
	pro = parseFloat((property_price.replace(",",""))*20/100)
	loanAmount = parseFloat(propp)-parseFloat(pro);
	
	fn = interestDate.split(" ");
	finalDate = fn[0];
	FD = finalDate.split("-");
	newFinalDate = FD[2]+"-"+FD[1]+"-"+FD[0];
	
	increasedInt = parseFloat(interestRate)+1;
	
	var loanAmount = addCommas(loanAmount)
	s.innerHTML = '<br /><span class="Left5"> <img src="images/blue-arrow.png" alt="" onclick="Collapse1()" style="cursor:pointer;"/><b onclick="Collapse1()" id="calculatedrate"> '+str+' </b> </span><span class="Right5"> <img src="images/green-line.gif" alt="" onclick="Collapse1()" class="Excol" /> &#160;<h3 onclick="Collapse1()">Mortage Calculator</h3><img src="images/calculator.gif" alt="" /> </span><br /><br /><form  method="post" action="details.html"><p><label>Loan amount:</label><br /><input name="LoanAmount" type="text" value="'+loanAmount+'" size="20" onfocus="clearvalue(this)" /><span class="SmallText"> (Default amount is based on a 20% deposit) </span><br /><label>Duration (Years):</label><br /><input type="text" name="LoanPeriod" value="40" size="23" onfocus="clearvalue(this)" /><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<input type="button" class="Calculate" value="" onclick="javascript: calculatePayments(this.form);" />&#160;&#160;&#160;&#160;<span class="BigText"> &#8364;' +simpleValue+ ' per month* </span><br /><br /><span class="GreyText"> *Based on an Interest rate of '+parseFloat(increasedInt)+'% ('+interestRate+'% + 1% bank charge) updated on '+newFinalDate+', subject to status,valuation,and deposit.Information provided as a guide only. </span></p></form>';
	s.style.border = "1px solid rgb(207,207,207)";
	s.style.backgroundColor = "rgb(248,247,247)";
	document.getElementById("Con").style.height = "1400px";
	b1 = "e";
}
function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

//====================================================================================================================================================================

function clearvalue(obj){
	obj.value=''
	}

//=====================================================================================================================================================================
function Collapse1()
{
	PreCalculation()
    var s = document.getElementById("Mortage");
	s.innerHTML = '<br /><span class="Left5"> <img src="images/blue-arrow.png" alt="" style="cursor:pointer;" onclick="Expand1()"/><b onclick="Expand1()"> Own this property from &#8364;1,000 P/M* </b></span><span class="Right5"><img src="images/plus.gif" alt="" onclick="Expand1()" class="Excol" /> &#160;<h3 onclick="Expand1()">Mortage Calculator</h3><img src="images/calculator.gif" alt="" /> </span>';
	s.style.border = "0";
	s.style.backgroundColor = "rgb(255,255,255)";
	b1 = "c";
	if (b2 == "c"){
	     document.getElementById("Con").style.height = "1250px";
    }
}


//=====================================================================================================================================================================
function Expand2()
{
    var s = document.getElementById("Email-Friend");
	s.innerHTML = '<img src="images/email.png" onclick="Collapse2();" alt="Email a friend" /><img src="images/green-line.gif" alt="Collapse" class="Min" style="float:right;position:relative;_top:-25px;cursor:pointer;" onclick="Collapse2();"/><b id="E" href="#E" style="position:relative;top:-7px;" onclick="Collapse2();" onclick="Expand2()" onmouseover="ColorChange1(this);" onmouseout="ColorChange2(this);">Email A Friend</b> <br /><form name="friend" action="details.html" method="post" onsubmit="return validate()"><div><label>Your Email Address : </label><br /><input type="text" name="youremail" size="30" /><br /><br /><label>Your Friends Email Address : </label><br /><input type="text" name="friendsEmail" size="30" /><br /><br /><iframe id="captchafrm" src="CaptchaSecurityImages.php?width=100&height=40&characters=5" width="100" height=55 frameborder="0" scrolling="no"></iframe><a href="javascript:void(0)" onclick="refreshcaptcha()">refresh</a><br><input type="text" name="captcha" size="18" style="position:relative;top:-10px"/><br />&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<input type="submit" value="" style="margin-top:9px" class="Send" onmouseover="this.style.backgroundImage="url(images/send-rollov.gif)";" onmouseout="this.style.backgroundImage="url(images/send.gif)";"/></div></form>';
    s.style.border = "1px solid rgb(207,207,207)";
	s.style.backgroundColor = "rgb(244,244,244)";
	document.getElementById("Con").style.height = "1450px";
	b2 = "e";
}


//=====================================================================================================================================================================
function Collapse2()
{
    var s = document.getElementById("Email-Friend");
	s.innerHTML = '<img src="images/email.png" alt="Email a friend" style="cursor:pointer;" onclick="Expand2()"/><b id="E" href="#E" style="position:relative;top:-7px;" onclick="Expand2()" onmouseover="ColorChange1(this);" onmouseout="ColorChange2(this);">Email A Friend</b> ';
	s.style.border = "none";
	s.style.backgroundColor = "rgb(255,255,255)";
	if (b1 == "c"){
	     document.getElementById("Con").style.height = "1250px";
    }
	b2 = "c";
}


//=====================================================================================================================================================================
function ColorChange1(id)
{
    document.getElementById("E").style.color = "rgb(255,130,0)";   
}


//=====================================================================================================================================================================
function ColorChange2(id)
{
    document.getElementById("E").style.color = "rgb(0,102,153)";   
}

var b1 = "c";
var b2 = "c";

//=====================================================================================================================================================================

function calculatePayments(form)
{
InterestRate = interestRate ;//This interest rate is global variable
InterestRate = InterestRate + 1;
	if (parseInt(form.LoanAmount.value) <= 0 || form.LoanAmount.value == "")
	{
		alert ("Loan Amount is not a valid number")
	}
	else if (parseInt(form.LoanPeriod.value) <= 0 || form.LoanPeriod.value == "")
	{
		alert ("Loan Period is not a valid number")
	}
	else if (parseFloat(InterestRate) < 0 || parseFloat(InterestRate) > 15 || InterestRate == "")
	{
		alert ("Interest Rate is not a valid number. Valid range is 0 to 15%")
	}
	else
	{
		// all values valid so calculate the mortgage payments
		LoanAmount = form.LoanAmount.value
		LoanAmount = parseInt(LoanAmount.replace(/,/g,""))
		LoanPeriod = parseInt(form.LoanPeriod.value)
		
		//	form.PayAmtInterestOnly.value = "£ " + parseInt(LoanAmount * (InterestRate / 100) / 12)
		PayAmtInterestOnly = parseInt(LoanAmount * (InterestRate / 100) / 12)

		var PercentRate = ((InterestRate / 12) / 100);
		var C = Math.pow (1 + PercentRate, LoanPeriod * 12);
		var MonthlyRepayment = (LoanAmount * PercentRate * C) /  (C - 1);
		var MonthlyRepayment = MonthlyRepayment.toFixed(0)
		var MonthlyRepayment = addCommas(MonthlyRepayment)
		
		document.getElementById("calculatedrate1").innerHTML="Own this property from &#8364;"+MonthlyRepayment+" P/M*" ;
		document.getElementById("calculatedrate").innerHTML = "Own this property from &#8364;"+MonthlyRepayment+" P/M*" ;
		
		document.getElementById("mortage_calculator_result").innerHTML = "&euro;"+MonthlyRepayment+" per month*";
		

		if (C > 1)
		{
		//	    form.PayAmtCapInterest.value = "£ " + parseInt(MonthlyRepayment);
			PayAmtCapInterest = parseInt(MonthlyRepayment);
		}
		else
		{
		//	    form.PayAmtCapInterest.value = "£ " + parseInt(LoanAmount / (LoanPeriod * 12))
			PayAmtCapInterest = parseInt(LoanAmount / (LoanPeriod * 12))
		}

	} 
	
return false;
}
//=====================================================================================================================================================================

//=====================================================================================================================================================================
function validateComment(){
	if(document.checkComment.name.value == ''){
		alert("Please enter name")	
		document.checkComment.name.focus()
		return false
	}else if(document.checkComment.email.value == ''){
		alert("Please enter email")	
		document.checkComment.email.focus()
		return false
	}else if(!emailCheck(document.checkComment.email.value)){
	document.checkComment.email.focus()
	return false
	}/*else if(document.checkComment.phone.value == ''){
		alert("Please enter phone")	
		document.checkComment.phone.focus()
		return false
	}*/else if(document.checkComment.comments.value == ''){
		alert("Please enter comments")	
		document.checkComment.comments.focus()
		return false
	}



//=============Send data through Ajax
document.getElementById("SubmitBlue").value = "Please wait.."	
xmlHttp=GetXmlHttpObject()
xmlHttp.onreadystatechange=function (){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
	 document.getElementById("enquiryform").reset()
	 document.getElementById("SubmitBlue").value = "Sent";
	 //document.getElementById("SubmitBlue").disabled = true
	 document.getElementById("enquiryform").onsubmit = returnfalse
 } 

}
name = document.checkComment.name.value
email = document.checkComment.email.value
phone = document.checkComment.phone.value
comments = document.checkComment.comments.value
if(document.checkComment.Sendnewsleter.checked){
send = 1
}else{
send = 0
}

id = document.friend.propId.value
 
xmlHttp.open("GET","GetMoreInfo.php?name="+name+"&email="+email+"&phone="+phone+"&comments="+comments+"&send="+send+"&propertyid"+propertyid+"&property_ref_no="+property_ref_no+"&property_title="+property_title+"&property_price="+property_price+"&id="+id+"&rental="+rental,true)
xmlHttp.send(null)
return false;
//====END
return false
}
//=====================================================================================================================================================================

function validate(){
	if(document.friend.youremail.value == ''){
	alert("Please enter your email")
	document.friend.youremail.focus()
	return false
	}else if(!emailCheck(document.friend.youremail.value)){
	document.friend.youremail.focus()
	return false
	}else if(document.friend.friendsEmail.value == ''){	
	alert("Please enter your friendsEmail")
	document.friend.friendsEmail.focus()
	return false
	}else if(!emailCheck(document.friend.friendsEmail.value)){
	document.friend.friendsEmail.focus()
	return false
	}else if(document.friend.captcha.value == '' || document.friend.captcha.value == 'Enter Code'){	
	alert("Please enter the Code")
	document.friend.captcha.focus()
	return false
	}
document.getElementById("emailSubmit").value = "Please wait..";	
	
//=============Send data through Ajax
xmlHttp=GetXmlHttpObject()
xmlHttp.onreadystatechange=function (){
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 {
	 if(xmlHttp.responseText == 1){
		 alert('Security Code Mismatch')
		 document.getElementById("emailSubmit").value = "Send"		 
		 }else{
	 //alert(xmlHttp.responseText)
	 document.getElementById("frnEmail").reset()
  document.getElementById("emailSubmit").value = "Sent";
	 //document.getElementById("SubmitBlue").disabled = true
	 document.getElementById("frnEmail").onsubmit = returnfalse
		 }
 } 

}
myemail = document.friend.youremail.value
friendEmail = document.friend.friendsEmail.value
capthcha = document.friend.captcha.value
propId = document.friend.propId.value

xmlHttp.open("GET","emailFriend.php?myemail="+myemail+"&friendEmail="+friendEmail+"&capthcha="+capthcha+"&Id="+propId,true)
xmlHttp.send(null)
return false;
//====END

}


//===========
function checkCaptch(){
document.getElementById('imgx1').src = document.getElementById('imgx1').src+"x=1"
}
//================

function addToShortList(id,spanidnone,spanidblock,phpfile)
{
document.getElementById(spanidnone).style.display = "none"
//document.getElementById("img"+id+"1").style.display = "block"
//************
	xmlhttp = GetXmlHttpObject()

		xmlhttp.onreadystatechange = function (){
			if(xmlhttp.readyState == 4)
			{	

				//document.getElementById("img"+id+"1").style.display = "none"
				document.getElementById(spanidblock).style.display = "block"
				document.getElementById("bg_saved").innerHTML = xmlhttp.responseText
				
				if(phpfile == "delete.php"){
				document.getElementById("Save").style.background = "url(images/bg_save_1.gif) 0 0 no-repeat";
				document.getElementById("Save").style.marginLeft = "10px"
				document.getElementById("Save").style.paddingLeft = "30px"
				}
				else{
				document.getElementById("Save").style.background = "url(images/check.gif) 0 0 no-repeat";				
				document.getElementById("Save").style.marginLeft = "0px"
				document.getElementById("Save").style.paddingLeft = "40px"
				
				
				}
				
				//document.getElementById(obj).innerHTML=xmlhttp.responseText	 	
				
				
				}
				
			}
	xmlhttp.open("GET",phpfile+"?id="+id,true);
	xmlhttp.send(null)
}

//================
function refreshcaptcha(){
	
	document.getElementById("captchafrm").src = "CaptchaMediatorFile.php?width=100&height=40&characters=5"

	}
	
//=======================

function LeftShift(){
	currentIndex = 4;
	clearInterval(IntervalId) 
	if(IE){
	str = "block"
	}else{
	str = "table-cell"
	}

var tem = 0
len = live.length;
IntervalId = setInterval('calculate()',200)
}
//======================================================
function RightShift(){
	currentIndex = 1
	clearInterval(IntervalId) 
	if(IE){
	str = "block"
	}else{
	str = "table-cell"
	}
	
	var tem = 0
len = live.length;
IntervalId = setInterval('calculate1()',200)


}
//=============================================================================


function calculate(){
	if(len > 0){
		temp = live.shift();//UP of live
		queue.push(temp);
		temp1 = queue.shift()//UP of queue
		live.push(temp1);
		swap("img"+currentIndex,temp1,str)
		currentIndex--
		len--
	}else{
	clearInterval(IntervalId) 
	}
}

//================================================================================================================================


function calculate1(){
	if(len > 0){
		temp = live.pop();
		queue.unshift(temp);
		temp1 = queue.pop();
		live.unshift(temp1);
		swap("img"+currentIndex,temp1,str)
		currentIndex++
		len--
	}else{
	clearInterval(IntervalId) 
	}
}
//=================================================================================================================


function swap(src,imgObj){
	prefarr = imgObj.src.split("/");
	
	document.getElementById(src).parentNode.parentNode.getElementsByTagName('A')[1].innerHTML = '<b>'+propType[prefarr[6]]+'</b>'
	
	
	if(rental == 1){
		text =  " Per Month"
		}else{
			text = ' in '+proplocation[prefarr[6]];
			}
	
	document.getElementById(src).parentNode.parentNode.getElementsByTagName('SPAN')[0].innerHTML ='&euro;'+price[prefarr[6]]+text
	//document.getElementById(src).parentNode.parentNode.childNodes[4].innerHTML = '&euro;'+price[prefarr[6]]+' in '+proplocation[prefarr[6]]
	//document.getElementById(src).parentNode.parentNode.childNodes[2].childNodes[0].childNodes[1].innerHTML = proplocation[prefarr[6]]
	document.getElementById(src).parentNode.href = 'details.php?id='+propIds[prefarr[6]]
	document.getElementById(src).parentNode.parentNode.childNodes[2].href = 'details.php?id='+propIds[prefarr[6]]
	
	//
document.getElementById(src).src = imgObj.src
}


//=====================================================================================================================================================================

function PreCalculation()
{
propp = property_price.replace(/,/g,"");
pro = parseFloat((property_price.replace(/,/g,""))*20/100)
loanAmount = parseFloat(propp)-parseFloat(pro);

	
InterestRate = interestRate ;//This interest rate is global variable
InterestRate = InterestRate + 1;
		// all values valid so calculate the mortgage payments
		
		LoanAmount =loanAmount
		
		LoanPeriod = 40
		
		//	form.PayAmtInterestOnly.value = "£ " + parseInt(LoanAmount * (InterestRate / 100) / 12)
		PayAmtInterestOnly = parseInt(LoanAmount * (InterestRate / 100) / 12)

		var PercentRate = ((InterestRate / 12) / 100);
		var C = Math.pow (1 + PercentRate, LoanPeriod * 12);
		var MonthlyRepayment = (LoanAmount * PercentRate * C) /  (C - 1);
		var MonthlyRepayment = MonthlyRepayment.toFixed(0)
		var MonthlyRepayment = addCommas(MonthlyRepayment)
		
		document.getElementById("calculatedrate1").innerHTML="Own this property from &#8364;"+MonthlyRepayment+" P/M*" 
		document.getElementById("calculatedrate1").value = document.getElementById("calculatedrate").innerHTML;
		document.getElementById("mortage_calculator_result").innerHTML = "&euro;"+MonthlyRepayment+" per month*";
		LoanAmount = addCommas(loanAmount)
		document.getElementById("LoanAmount").value =LoanAmount;
		document.getElementById("LoanPeriod").value =LoanPeriod;
		
		/* Information provided as a guide only--- *Interest rate of "+InterestRate+"% subject to status,valuation,and deposit.*/

		var gag = "<p><small>*Based on EURIBOR Interest rate of "+InterestRate.toPrecision(4)+"% ("+interestRate+"% + 1% typical bank rate) Updated "+interestDate+" subject to status,valuation,and deposit. Information provided as a guide only</small></p>";
		document.getElementById("zen").innerHTML = gag;
		
		

		if (C > 1)
		{
		//	    form.PayAmtCapInterest.value = "£ " + parseInt(MonthlyRepayment);
			PayAmtCapInterest = parseInt(MonthlyRepayment);
		}
		else
		{
		//	    form.PayAmtCapInterest.value = "£ " + parseInt(LoanAmount / (LoanPeriod * 12))
			PayAmtCapInterest = parseInt(LoanAmount / (LoanPeriod * 12))
		}

	 
}
//=====================================================================================================================================================================

function LeftShiftThumb(){
	currentIndexThumb = 4;
	if(IE){
	str = "block"
	}else{
	str = "table-cell"
	}
	
	clearInterval(IntervalIdThumb) 
var temThumb = 0
lenThumb = liveThumb.length;
IntervalIdThumb = setInterval('calculateThumb()',200)
}
//======================================================

function RightShiftThumb(){
	currentIndexThumb = 1
	clearInterval(IntervalIdThumb) 
	if(IE){
	str = "block"
	}else{
	str = "table-cell"
	}
	
	var temThumb = 0
lenThumb = liveThumb.length;
IntervalIdThumb = setInterval('calculate1Thumb()',200)


}
//=============================================================================

function calculateThumb(){
	if(lenThumb > 0){
		tempThumb = liveThumb.shift();//UP of live
		queueThumb.push(tempThumb);
		
		temp1Thumb = queueThumb.shift()//UP of queue
		liveThumb.push(temp1Thumb);
		swap("imgThumb"+currentIndexThumb,temp1Thumb,str)
		currentIndexThumb--
		lenThumb--
	}else{
	clearInterval(IntervalIdThumb) 
	}
}

//================================================================================================================================

function calculate1Thumb(){
	if(lenThumb > 0){
		tempThumb = liveThumb.pop();
		queueThumb.unshift(tempThumb);
		temp1Thumb = queueThumb.pop();
		liveThumb.unshift(temp1Thumb);
		swap("imgThumb"+currentIndexThumb,temp1Thumb,str)
		currentIndexThumb++
		lenThumb--
	}else{
	clearInterval(IntervalIdThumb) 
	}
}
//=================================================================================================================











