function validateSell(){
	var err = 0;
	if (document.sell.sale_price.value ==""){
		alert("Please fill in Estimated Sale Price. (Eg. 250000)");
		document.sell.sale_price.focus();
		return false;
	}
	if (!isNumeric(document.sell.sale_price.value)){
		alert("Estimated Sale Price must be numeric.");
		document.sell.sale_price.focus();
		return false;
	}	
	if (document.sell.commission.value ==""){
		alert("Please fill in Agents Commission.");
		document.sell.commission.focus();
		return false;
	}	
	if (!isNumeric(document.sell.commission.value)){
		alert("Agents Commision: Invalid Entry.");
		document.sell.commission.focus();
		return false;
	}		
	if (err == 0){
		document.sell.submit();
	}	
}

function validateBuy(){
	var err = 0;
	if (document.buy.buy_price.value ==""){
		alert("Please fill in Estimated Purchase Price. (Eg. 250000)");
		document.buy.buy_price.focus();
		return false;
	}
	if (!isNumeric(document.buy.buy_price.value)){
		alert("Estimated Purchase Price must be numeric.");
		document.buy.buy_price.focus();
		return false;
	}	
	if (document.buy.buy_discharge[0].checked == false && document.buy.buy_discharge[1].checked == false){
		alert("Will you have a first homebuyers grant?");
		return false;
	}	
	if (err == 0){
		document.buy.submit();
	}	
}

function isNumeric(strText){
	var strcharset = "1234567890."
	for (var i=0;i<strText.length;i++){
		tchar = strText.charAt(i);
		if (strcharset.indexOf(tchar) == -1){
			return false;
		}
	}
	return true;
}	
	
function calStamp(){
	var dBuyPrice;
	var dTemp;
	dBuyPrice = document.buy.buy_price.value;
	dBuyPrice = parseFloat(dBuyPrice);
	dTemp = 0.000;
	if (!isNumeric(dBuyPrice)){
		alert("Estimated Purchase Price must be numeric.");
		document.buy.buy_price.focus();
		return false;
	}else{
		if (dBuyPrice <= 14000){
			dTemp = dTemp + ((1.25/100) * dBuyPrice);
		}
		if (dBuyPrice > 14000 && dBuyPrice <= 30000){
			dTemp = dTemp + 175 + ((1.5/100) * (dBuyPrice-14000));
		}
		if 	(dBuyPrice > 30000 && dBuyPrice <= 80000){
				dTemp = dTemp + 415 + ((1.75/100) * (dBuyPrice-30000));
		}
		if 	(dBuyPrice > 80000 && dBuyPrice <= 300000){
				dTemp = dTemp + 1290 + ((3.5/100) * (dBuyPrice-80000));
		}		
		if 	(dBuyPrice > 300000 && dBuyPrice <= 1000000){
				dTemp = dTemp + 8990 + ((4.5/100) * (dBuyPrice-300000));
		}
		if 	(dBuyPrice > 1000000){
				dTemp = dTemp + 40490 + ((5.5/100) * (dBuyPrice-1000000));
		}						
		document.buy.stamp_duty.value = dTemp;			
	}
}

function calMStamp(){
	var dLoanPrice;
	var dTemp;
	dLoanPrice = document.buy.loan.value;
	dLoanPrice = parseFloat(dLoanPrice);
	if (!isNumeric(dLoanPrice)){
		alert("Estimated Loan Price must be numeric.");
		document.buy.loan.focus();
		return false;
	}else{
		if (dLoanPrice < 1){
			dTemp = 0;
		}
		if (dLoanPrice > 0 && dLoanPrice <= 16000){
			dTemp = 5;
		}
		if (dLoanPrice > 16000){
			dTemp = 5 + ((4/1000) * (dLoanPrice-16000));
		}
		document.buy.m_stamp_duty.value = dTemp;					
	}
}
