//Pembers Core Javascript Functions

/* Finance Calculator */
function doCalc(field) {
		if (isNaN(field.value)) {
			alert("Only numerical values accepted");
			field.value = "";
		} else {
			var price = $("#price").val();
			var deposit = $("#deposit").val();
			var rate = $("#rate").val();
			var term = $("#term").val();
		
			if (price != "" && deposit != "" && rate != "" && term != "") {
				var principle = price - deposit;
				var rate = rate / 100;
		
				var top = principle * (rate / 52);
				var bottom = (1 - Math.pow((1 + rate / 52),(-52*term)))
		
				var weeklypay = Math.round((top / bottom), 2);

				$("#weekly").val(weeklypay);
			}
		}
	}
	
	function resetValues() {
		$("#price").val("");
		$("#deposit").val("");
		$("#rate").val("");
		$("#term").val("");
		$("#weekly").val("");
	}

/* END Finance Calculator */

function clearSearch(field) {
	if (field.value == "Search...") {
		field.value = "";
	}
}

function resetSearch(field) {
	if (field.value == "") {
		field.value = "Search...";	
	}
}

function externalLinks() {  
	if (!document.getElementsByTagName) return;  
 		var anchors = document.getElementsByTagName("a");  
 		for (var i=0; i<anchors.length; i++) {  
   			var anchor = anchors[i];  
   			if (anchor.getAttribute("href") &&  
       		anchor.getAttribute("rel") == "external")  
     		anchor.target = "_blank";  
 			}  
}  
window.onload = externalLinks;