$(document).ready(function() {
	
	$(".external_link").each(function(){
		
		$(this).click(function(){
			
			var answer = confirm("By clicking OK you will be leaving the CFG Community Bank site.")
			if (answer){
				return true;
			}
			else{
				return false;
			}			
			
		});
		
	});
	
	if($("#search_box").val() != 'Search'){
		
		$("#search_box").css('color','#000000');
		
	}
	
	$("#search_box").focus(function(){
	
		if($("#search_box").val() == 'Search'){
			
			$("#search_box").val('');
			$("#search_box").css('color','#000000');
			
		}
		
	});
	
});

function submitLocation(){

	$("#whichLocation").val($(".generatedInput").val());
	document.chooseOffice2.submit();				

}

	
	function getSize() {
	  var myWidth = 0, myHeight = 0;
	  if( typeof( window.innerWidth ) == 'number' ) {
	    //Non-IE
	    myWidth = window.innerWidth;
	    myHeight = window.innerHeight;
	  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	    //IE 6+ in 'standards compliant mode'
	    myWidth = document.documentElement.clientWidth;
	    myHeight = document.documentElement.clientHeight;
	  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	    //IE 4 compatible
	    myWidth = document.body.clientWidth;
	    myHeight = document.body.clientHeight;
	  }
	
	  return myWidth;
	  
	}  
	
	
function mortgage(){

	var term = $(".generatedInput").val();
	if(isNaN($("#calc_amount").val()) || $("#calc_amount").val() == ''){

		alert("Please select a numeric amount.");
		
	}else if(isNaN($("#calc_rate").val()) || $("#calc_rate").val() == ''){

		alert("Please select a numeric rate.");
		
	}else if(isNaN(term)){
		
		alert("Please select a term.");
		
	}else if(($("#calc_rate").val())>99 || ($("#calc_rate").val())<0){
		
		alert("Please enter a rate between 0 and 99");
		
	}else{
			
		var L,P,n,c,dp;
		L = parseInt($("#calc_amount").val());
		n = parseInt($(".generatedInput").val())* 12;
		c = parseFloat($("#calc_rate").val())/1200;
		//dp = 1 - parseFloat($("#mcDown").val())/100;
		//L = L * dp;
		P = (L*(c*Math.pow(1+c,n)))/(Math.pow(1+c,n)-1);		
		
		if(!isNaN(P)){
			
			$("#lightbox_total").html(formatCurrency(P)+"/mo");
			
		}
		
	}
	
 

}

function formatCurrency(num) {
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
num = "0";
sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();
if(cents<10)
cents = "0" + cents;
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
num = num.substring(0,num.length-(4*i+3))+','+
num.substring(num.length-(4*i+3));
return (((sign)?'':'-') + '$' + num + '.' + cents);
}
