$(document).ready(function(){
	//global vars
	var searchBoxes = $(".text");
	var searchBox1 = $("#agents");
	var searchBox2 = $("#cph");
	var searchBox3 = $("#cpa");
	var searchBox4 = $("#cpc");
	var searchBox5 = $("#rsc");
	var resultsBoxes = $(".roiFormField");
	var resultsBox1 = $("#cph_hour");
	//var searchBox2Default = "Search the web...";
	
	$("#formWrapper").dropShadow({left: 4, top: 4, opacity: 0.40, blur: 3});
	$("#agents").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#cpa").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#cph").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#cpc").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#rsc").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#submitBtn").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#clearBtn").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	$("#demoBtn").dropShadow({left: 2, top: 2, opacity: 0.25, blur: 2});
	

	
	//Effects for both searchbox
	searchBoxes.focus(function(e){
		$(this).addClass("active");
	});
	searchBoxes.blur(function(e){
		$(this).removeClass("active");
	});
	
	//Searchbox1, set focus when document is ready
	searchBox1.focus();
	
	$("form").submit(function() {
	$("#resultsBottom").fadeIn("slow");
	$("#roiDetails").fadeIn("slow");
	}); 
	
});

// This function performs two actions:
// Action 1: Adding space of 15px in NN browser by displaying element with id='spacer1' (It's not needed in IE) 
// Action 2: Aligning large background image on the page: 
//           The whole Content Area is moved to the left (It's not noticable for the user's eyes) 
//  		 After aligning with CSS styles a shift of 6px for IE and 8px for NN is still needed 
function changeSpace() {
	var isNav = (navigator.appName == "Netscape");
	var elem = document.getElementById("spacer1");
	var container = document.getElementById("container");
			
	if(isNav && elem && container){
	elem.style.display = "block";
	container.style.marginLeft = -8 + "px";
	}
}
		

function formatNumber(num,dec,thou,pnt,curr1,curr2,n1,n2)  {
	var x = Math.round(num * Math.pow(10,dec));
	if (x >= 0) n1=n2='';var y = (''+Math.abs(x)).split('');var z = y.length - dec; if (z<0) z--; for(var i = z; i < 0; i++) y.unshift('0'); if (z<0) z = 1; y.splice(z, 0, pnt); if(y[0] == pnt) y.unshift('0'); while (z > 3) {z-=3; y.splice(z,0,thou);}var r = curr1+n1+y.join('')+n2+curr2;return r;
}


function calculateROI() {
//-- NUMBER OF CALLS PER HOUR PER AGENT --\\
// # agents * # calls per hour per agent
document.roiForm.cph_hr.value =  formatNumber((document.roiForm.agents.value * document.roiForm.cph.value),'',',','','','','','');
// * 7 works hours per day
document.roiForm.cph_day.value =  formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 7),'',',','','','','','');
// * 20 work days per month
document.roiForm.cph_month.value =  formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 140),'',',','','','','','');
// * 12 work months per year
document.roiForm.cph_annual.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 1680),'',',','','','','','');

// COST PER AGENT PER HOUR \\
document.roiForm.cpa_hr.value =  formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * document.roiForm.cpa.value),'',',','','$','','','');
document.roiForm.cpa_day.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 7 * document.roiForm.cpa.value),'',',','','$','','','');
document.roiForm.cpa_month.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 140 * document.roiForm.cpa.value),'',',','','$','','','');
document.roiForm.cpa_annual.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 1680 * document.roiForm.cpa.value),'',',','','$','','','');

//-- COST PER CALL --\\
document.roiForm.cpc_hr.value =  formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * document.roiForm.cpc.value),'',',','','$','','','');
document.roiForm.cpc_day.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 7 * document.roiForm.cpc.value),'',',','','$','','','');
document.roiForm.cpc_month.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 140 * document.roiForm.cpc.value),'',',','','$','','','');
document.roiForm.cpc_annual.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 1680 * document.roiForm.cpc.value),'',',','','$','','','');

//-- REDUCED SECONDS PER CALL --\\
document.roiForm.rsc_hr.value =  formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * document.roiForm.rsc.value),'',',','','','','','');
document.roiForm.rsc_day.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 7 * document.roiForm.rsc.value),'',',','','','','','');
document.roiForm.rsc_month.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 140 * document.roiForm.rsc.value),'',',','','','','','');
document.roiForm.rsc_annual.value = formatNumber((document.roiForm.agents.value * document.roiForm.cph.value * 1680 * document.roiForm.rsc.value),'',',','','','','','');

//-- REDUCED CALL LENGTH (HOURS) --\\
// Day
document.roiForm.rcl_day.value = formatNumber(((document.roiForm.agents.value * document.roiForm.cph.value * 7 * document.roiForm.rsc.value)/60/60),2,',','.','','','','');
// Month
document.roiForm.rcl_month.value = formatNumber(((document.roiForm.agents.value * document.roiForm.cph.value * 140 * document.roiForm.rsc.value)/60/60),2,',','.','','','','');
// Year
document.roiForm.rcl_annual.value = formatNumber(((document.roiForm.agents.value * document.roiForm.cph.value * 1680 * document.roiForm.rsc.value)/60/60),2,',','.','','','','');

//-- SAVINGS PER AGENT PER CALL --\\
// Day
document.roiForm.spa_day.value = formatNumber(((document.roiForm.cpa.value * document.roiForm.agents.value * document.roiForm.cph.value * 7 * document.roiForm.rsc.value)/60/60),2,',','.','$','','','');
// Month
document.roiForm.spa_month.value = formatNumber(((document.roiForm.cpa.value * document.roiForm.agents.value * document.roiForm.cph.value * 140 * document.roiForm.rsc.value)/60/60),2,',','.','$','','','');
// Year
document.roiForm.spa_annual.value = formatNumber(((document.roiForm.cpa.value * document.roiForm.agents.value * document.roiForm.cph.value * 1680 * document.roiForm.rsc.value)/60/60),2,',','.','$','','',''); 
//-- AGENT ANNUAL SALARY --\
document.roiForm.annualSalary.value = formatNumber((document.roiForm.cpa.value * 1680),2,',','.','$','','',''); 
}

function demoFill() {
	document.roiForm.agents.value = 345;
	document.roiForm.cpa.value =  10;	
	document.roiForm.cph.value =  10;
	document.roiForm.cpc.value = 1;		
	document.roiForm.rsc.value = 10;
	
}