function starttestimonial(){
	currenttestimonial++;
	$("#testimonial"+currenttestimonial).fadeIn("slow");
	setTimeout("nexttestimonial()", 10000);	
}

function nexttestimonial(){
	$("#testimonial"+currenttestimonial).fadeOut("slow", function(){
		currenttestimonial++;
		if(currenttestimonial>totaltestimonials){
			currenttestimonial=1;	
		}
		$("#testimonial"+currenttestimonial).fadeIn("slow");	
		setTimeout("nexttestimonial()", 10000);
	});
}

function calculateroi(){
	var doc=document;
	var electricalrate=doc.getElementById('electricalrate').value;
	var numcomputers=doc.getElementById('numcomputers').value;
	if(doc.getElementById('monitor').checked==1){
		var monitor=doc.getElementById('monitor').value;
	}else{
		var monitor=0;
	}
	if(doc.getElementById('speakers').checked==1){
		var speakers=doc.getElementById('speakers').value;
	}else{
		var speakers=0;
	}
	if(doc.getElementById('printer').checked==1){
		var printer=doc.getElementById('printer').value;
	}else{
		var printer=0;
	}
	if(doc.getElementById('faxmachine').checked==1){
		var faxmachine=doc.getElementById('faxmachine').value;
	}else{
		var faxmachine=0;
	}
	if(doc.getElementById('modem').checked==1){
		var modem=doc.getElementById('modem').value;
	}else{
		var modem=0;
	}
	if(doc.getElementById('phonecharger').checked==1){
		var phonecharger=doc.getElementById('phonecharger').value;
	}else{
		var phonecharger=0;
	}
	if(doc.getElementById('spaceheater').checked==1){
		var spaceheater=doc.getElementById('spaceheater').value;
	}else{
		var spaceheater=0;
	}
	if(doc.getElementById('deskfan').checked==1){
		var deskfan=doc.getElementById('deskfan').value;
	}else{
		var deskfan=0;
	}
	
	var totalwattage=parseInt(monitor)+parseInt(speakers)+parseInt(printer)+parseInt(faxmachine)+parseInt(modem)+parseInt(phonecharger)+parseInt(spaceheater)+parseInt(deskfan);
	var savings=(((totalwattage*5)*50)*numcomputers)*(electricalrate/100);
	
	doc.getElementById('annualsavings').innerHTML='$'+addCommas(savings.toFixed(2));
	doc.getElementById('5yrsavings').innerHTML='$'+addCommas((savings*5).toFixed(2));
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}

function newslettersubscribe(email_address){
	var doc=document;
	$.ajax({
		url: "includes/subscribe.php",
		global: false,
		type: "POST",
		data: {
			email_address : doc.getElementById('emailnewsletter').value
		},
		dataType: "html",
		async:true,
		success: function(response){
			if(response==0){
				document.getElementById('emailnewsletter').style.color='#d46f6f';
				document.getElementById('emailnewsletter').value='Invalid Email Address';
				setTimeout("document.getElementById('emailnewsletter').style.color='#999999'; document.getElementById('emailnewsletter').value='Email Newsletter';", 3000);
			}
			if(response==1){
				document.getElementById('emailnewsletter').style.color='#589212';
				document.getElementById('emailnewsletter').value='Thank You!';
				setTimeout("document.getElementById('emailnewsletter').style.color='#999999'; document.getElementById('emailnewsletter').value='Email Newsletter';", 3000);
			}
		}
	});
}

function featurecount(id){
	var doc=document;
	doc.getElementById(id).style.background="url('images/featurecount.png')";
}

function featurecounthover(id){
	var doc=document;
	doc.getElementById(id).style.background="url('images/featurecount_hover.png')";
}

function featurebackground(count){
	var doc=document;
	doc.getElementById('featurecount'+currentfeature).style.color='#FFFFFF';
	currentfeature=count;
	doc.getElementById('featurecount'+count).style.color='#7cc305';
	$("#featurebackground").fadeOut("fast", function(){
		doc.getElementById('featurebackground').style.background="url('images/feature/feature"+count+".jpg') center";
		doc.getElementById('featurebackground').style.backgroundSize="100% auto";
		$("#featurebackground").fadeIn("fast");
	});
}

function featureprevious(){
	var doc=document;
	doc.getElementById('featurecount'+currentfeature).style.color='#FFFFFF';
	currentfeature--;
	if(currentfeature<=0){
		currentfeature=totalfeatures;
	}
	featurebackground(currentfeature);
}

function featurenext(){
	var doc=document;
	doc.getElementById('featurecount'+currentfeature).style.color='#FFFFFF';
	currentfeature++;
	if(currentfeature>totalfeatures){
		currentfeature=1;
		featurebackground(currentfeature);
	}
	featurebackground(currentfeature);
}

function autofeature(){
	featurenext();
	window.featuretimer=setTimeout("autofeature()", 7000);
	timerset=1;
}
