/********************************/
/*	Helper Functions			*/
	
function selectDefault(value, selectbox){
	
	if($(selectbox)){
		
		var options = $(selectbox).options;
	
		for (var i = 0; i < $(selectbox).length; i++) 
		{
		
		    if ($(selectbox).options[i].value == value) 
			{
			
	         $(selectbox).options[i].selected = true;

	      	}

	   	}
	
	}
	
}

function ClicktoCall(id){
	var w=370;
	var h=450;
	var leftPos=(screen.width)?(screen.width-w)/2:100;
	var topPos=(screen.height)?(screen.height-h)/2:100;
	var
settings='width='+w+',height='+h+',top='+topPos+',left='+leftPos+',';
	settings =
settings+'location=no,directories=no,menubar=no,toolbar=no,';
	settings =
settings+'status=no,scrollbars=no,resizable=no,dependent=no';
	var
sUrl='http://www.nascomms.com/ccConnect/Dialer.aspx?clientId='+id;
	var ccWindow=window.open(sUrl,'ClickCalling',settings);
	ccWindow.focus();
}

/********************************/
/*	Finance Calculator			*/

calculate_payment = function(p,r,m) {	
	return (p*(r/12)) / (1-(Math.pow((1+(r/12)),-m)))
}

roundTo = function (base,precision) {
	var m = Math.pow(10, precision);
	var a = Math.round(base * m) /m;
	return a;
}
function formatTo(base,precision) {

	var a = roundTo(base,precision);
	var s = a.toString();
	
	var decomalIndex = s.indexOf(".");
	if (precision > 0 && decimalIndex < 0) {
		decimalIndex = s.length;
		s += '.';
	}
	while (decimalIndex + precision + 1 > s.length) {
		s += '0';	
	}
	return s;
}

process_calculator_form = function() {

	var theForm = document.forms["calculator_form"];
	var amount = parseInt(theForm['amount'].value.replace(/^\$+/,""));
	var intrest = parseInt(theForm['intrest'].value.replace(/%$/,""));
	var length = parseInt(theForm['length'].value);
	var repayment = 0;
	var calculate = true;
	if (typeof(amount) != "number" || amount < 1) {
		alert('The ammount field must be a dollar value');	
		calculate = false;
	}
	if (typeof(intrest) != "number" || intrest < 0.1 || intrest > 100) {
		alert('The intrest field must be a percent value');	
		calculate = false;
	}	
	if (typeof(length) != "number" || length < 1) {
		alert('Please enter the length, in number of months');	
		calculate = false;	
	}
	
	if (calculate) {
		repayment = roundTo(calculate_payment(amount,(intrest/100),length),2);
		theForm['repayment'].value = '$' + repayment;
	}
	
	
}

/********************************/
/*	Window Load					*/

window.onload = function(){
	
	/****************************/
	/*	Dropdowns				*/
	
	var menu = new MenuMatic({});
	
	/****************************/
	/*	Front Scroller			*/
	
	if($("dHeroContainer")){ if($("dHeroContainer").hasClass("slideshow")){
		
		var myShow = new Slideshow.KenBurns('dHeroContainer', data_hero, {height: 380, hu: '', width: 1000, delay: 3000, duration: 2000, zoom: 1, captions: true});
		
	}}
	
	/****************************/
	/*	Ad Scroller				*/
	
	if($("dAdContainer")){ if($("dAdContainer").hasClass("slideshow")){
		
		var myShow = new Slideshow.Push('dAdContainer', data_ad, {height: 297, hu: '', width: 650, delay: 3000, duration: 2000, zoom: 1, captions: false});
		
	}}
	
}