// Mortage Calculator
function changeDepositPrice(value)
{
	document.forms.mortageCalc.vPrice.value=conv(document.forms.mortageCalc.Price.value)-conv(value);
}

function changePrice(value)
{
	document.forms.mortageCalc.vPrice.value=conv(value) - conv(document.forms.mortageCalc.Price.Deposit);
}

function conv(num)
{
	var s = String(num);
	num = s.replace(/,/g, "");

	if (isNaN(parseFloat(num)))
			return 0;
	else	return parseFloat(num);
}
function CalcMortage()
{
	var rate = conv(document.forms.mortageCalc.Rate.value);
	var amount = conv(document.forms.mortageCalc.Price.value)-conv(document.forms.mortageCalc.Deposit.value);
	var term = conv(document.forms.mortageCalc.Term.value);

	var rate_per_period = rate / (12 * 100);
	var res = amount * rate_per_period / ( 1 - ( 1 / Math.pow( 1 + rate_per_period, term * 12 ) ) );
	document.forms.mortageCalc.PaymentPerMonth.value = Math.round(res*100)/100;
	return false;
}

// Mortage Calculator

function clearContent(field, initContent)
{
	if (field.value==initContent)
	{
		field.value="";
	}
}
function restoreContent(field, initContent)
{
	if (field.value=="")
	{
		field.value = initContent;
	}
}

function getBrowserType()
{
	var tmpImages = document.getElementsByTagName('img');
	var fImage = tmpImages[0];
	brType = 'none';
	
	if(typeof fImage.style.opacity != 'undefined')
	{
		brType = 'w3c';
	}
	else if(typeof fImage.style.MozOpacity != 'undefined')
	{
		brType = 'moz';
	}
	else if(typeof fImage.style.KhtmlOpacity != 'undefined')
	{
		brType = 'khtml';
	}
	else if(typeof fImage.filters == 'object')
	{
		brType = (fImage.filters.length > 0 && typeof fImage.filters.alpha == 'object' && typeof fImage.filters.alpha.opacity == 'number') ? 'ie' : 'none';
	}
	else
	{
		brType = 'none';
	}
}

function turnOffAllPersonPhotos()
{
	var tmpImages = document.getElementsByTagName('img');
	for (var i=0; i<tmpImages.length; i++)
	{
		var tmpImage = tmpImages[i];
		
		var relAttribute = String(tmpImage.getAttribute('rel'));

		// use the string.match() method to catch 'rImage' references in the rel attribute
		if ((relAttribute.toLowerCase().match('person_image')))
		{
			turnOffPersonPhoto(tmpImage);
		}
	}
}		


function turnOnPersonPhoto(imgItem)
{
	switch(brType)
	{
		case 'ie' :
			imgItem.filters.alpha.opacity = 100;
			break;			
		case 'khtml' :
			imgItem.style.KhtmlOpacity = 1;
			break;
			
		case 'moz' : 
			imgItem.style.MozOpacity = 1;
			break;				
		default : 
			imgItem.style.opacity = 1;
	}	
}

function turnOffPersonPhoto(imgItem)
{
	switch(brType)
	{
		case 'ie' :
			imgItem.filters.alpha.opacity = 50;
			break;
			
		case 'khtml' :
			imgItem.style.KhtmlOpacity = 0.5;
			break;
			
		case 'moz' : 
			imgItem.style.MozOpacity = 0.5;
			break;				
		default : 
			imgItem.style.opacity = 0.5;
	}	

}
