<!--
kw='';
mode='';
test=false;
function preload() {
	image1= new Image(750,144);
	image1.src = "images/logo_home.jpg";

	image2 = new Image(750,144);
	image2.src = "images/logo_solar.jpg";

	image3 = new Image(750,144);
	image3.src = "images/logo_wind.jpg";
	
	image4= new Image(750,144);
	image4.src = "images/logo_rebates.jpg";

	image5 = new Image(750,144);
	image5.src = "images/logo_links.jpg";

	image6 = new Image(750,144);
	image6.src = "images/logo_contact.jpg";
}
function loadrequest() {
	switch (mode) { 
	   case 's' : 
	      document.getElementById('requested').innerHTML = '<b>Your request has been sent successfully, thank you!<br />We will get back to you as soon as possible.</b>';
	      resshow();
	      break; 
	   case 'f' : 
	      document.getElementById('requested').innerHTML = '<b>We apologise, your request could not be sent.<br />Please try again or ring us at 07 3847 3898/0438 715 258.</b>';
	      resshow();
	      break; 
	   default : 
	      document.getElementById('requested').innerHTML = '';
	} 
}
function validate() {
	if ((document.formmail.realname.value=="") || (document.formmail.realname.value==null)) {
	   alert('Please enter your name');
	   document.formmail.realname.focus();
	   return false;
		}
	if ((document.formmail.email.value=="") || (document.formmail.email.value==null)) {
	   alert('Please enter your email address');
	   document.formmail.email.focus();
	   return false;

		}
	var emailID=document.formmail.email;
	
	if (echeck(emailID.value)==false){
		alert('Invalid email address');
		document.formmail.email.focus();
		return false
		}
	return true;
}
function valreq() {
	if ((document.formquote.firstname.value=="") || (document.formquote.firstname.value==null)) {
	   alert('Please enter your first name');
	   document.formquote.firstname.focus();
	   return false;
		}
	if ((document.formquote.lastname.value=="") || (document.formquote.lastname.value==null)) {
	   alert('Please enter your last name');
	   document.formquote.lastname.focus();
	   return false;
		}
	if ((document.formquote.street.value=="") || (document.formquote.street.value==null)) {
	   alert('Please enter your street address');
	   document.formquote.street.focus();
	   return false;
		}
	if ((document.formquote.town.value=="") || (document.formquote.town.value==null)) {
	   alert('Please enter your suburb/town');
	   document.formquote.town.focus();
	   return false;
		}
	if ((document.formquote.pcode.value=="") || (document.formquote.pcode.value==null)) {
	   alert('Please enter your postal code');
	   document.formquote.pcode.focus();
	   return false;
		}
	if ((document.formquote.email.value=="") || (document.formquote.email.value==null)) {
	   alert('Please enter your email address');
	   document.formquote.email.focus();
	   return false;
		}
	var emailID=document.formquote.email;
	
	if (echeck(emailID.value)==false){
		alert('Invalid email address');
		document.formquote.email.focus();
		return false
		}
	if (((document.formquote.phone.value=="") || (document.formquote.phone.value==null))&&((document.formquote.mobile.value=="") || (document.formquote.mobile.value==null))) {
	   alert('Please enter either a phone or mobile contact number');
	   document.formquote.phone.focus();
	   return false;
		} 

	document.formquote.kw.value='Quotation for a '+kw+' KW Solar Generator';
	return true;
}
// ======================
// validate email address
//=======================
function echeck(str) {
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){

		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }
 		 return true					
	}
	
function calcval() {
	if ((document.formcalc.d1.value=="") || (document.formcalc.d1.value==null)) {
	   alert('Please enter the size of proposed solar generator');
	   document.formcalc.d1.focus();
	   return false;
		}
	if(isNaN(document.formcalc.d1.value)){
	   alert('The size of proposed solar generator must be a numeric value');
	   document.formcalc.d1.focus();
	   return false;
		}
	if ((document.formcalc.d2.value=="") || (document.formcalc.d2.value==null)) {
	   alert('Please enter your monthly power usage');
	   document.formcalc.d2.focus();
	   return false;
		}
	if(isNaN(document.formcalc.d2.value)){
	   alert('Your monthly power usage must be a numeric value');
	   document.formcalc.d2.focus();
	   return false;
		}
	if ((document.formcalc.d3.value=="") || (document.formcalc.d3.value==null)) {
	   alert('Please enter your 9.30am and 3.30pm power usage percentage');
	   document.formcalc.d3.focus();
	   return false;
		}
	if(isNaN(document.formcalc.d3.value)){
	   alert('Your 9.30am and 3.30pm power percentage usage must be a numeric value');
	   document.formcalc.d3.focus();
	   return false;
		}
	if (document.formcalc.d3.value>100) {
	   alert('Please enter a percentage value (0-100)');
	   document.formcalc.d3.focus();
	   return false;
		}
	return true;
}

function calculate() {
	var d1=document.formcalc.d1.value;
	var d2=document.formcalc.d2.value;
	var d3=document.formcalc.d3.value;
	kw=d1;
// disable form fields
	//document.formcalc.d1.disabled = true;
	//document.formcalc.d2.disabled = true;
	//document.formcalc.d3.disabled = true;
// calculate results
	var r2=d1*5.5*365;
	var r4=r2*0.95;
	var r4a=r4*25;
	var r3=r2-d2*0.12*d3;
	var r3a=d1*7.8;
	var r1=r3*0.44+(r2-r3)*0.16;
	var r1a=r1*41.625;
	var r5=d2*1.92/(883-5.62*d3);
	var r6=r5*0.7;
	var r7=d2*0.005979;
	var r8=r7*883.3*(1-(d3*0.01))+r7*d3*3.212;
	var r9=d2*0.004185;
	//var r10=r9*883.3*(1-(d3*0.01))+r7*d3*3.212;
	var r10=r8*0.7;
// round results to two decimal points
	r1 = formatMoney(r1);
	r1a = formatMoney(r1a);
	r2 = formatNumber(r2,2);
	r3 = formatNumber(r3,2);
	r3a = formatNumber(r3a,2);
	r4 = formatNumber(r4,2);
	r4a = formatNumber(r4a,2);
	r5 = formatNumber(r5,2);
	r6 = formatNumber(r6,2);
	r7 = formatNumber(r7,2);
	r8 = formatMoney(r8);
	r9 = formatNumber(r9,2);
	r10 = formatMoney(r10);
// set results to display
	document.getElementById('quotetitle').innerHTML = 'Solar Generator Size: <b>'+d1+' KW</b>';
	
	document.getElementById('result1').innerHTML = '$ '+r1;
	document.getElementById('result1a').innerHTML = '$ '+r1a;
	document.getElementById('result2').innerHTML = r2+' KWH';
	document.getElementById('result3').innerHTML = r3+' KWH';
	document.getElementById('result3a').innerHTML = r3a+' m2';
	document.getElementById('result4').innerHTML = r4+' kg';
	document.getElementById('result4a').innerHTML = r4a+' kg';
	document.getElementById('result5').innerHTML = r5+' kw';
	document.getElementById('result6').innerHTML = r6+' kw';
	document.getElementById('result7').innerHTML = r7+' kw';
	document.getElementById('result8').innerHTML = '$ '+r8;
	document.getElementById('result9').innerHTML = r9+' kw';
	document.getElementById('result10').innerHTML = '$ '+r10;

	document.getElementById('sgsize').innerHTML = '<p>Yes, I am interested in receiving a quotation for a <a href="javascript:quote();show()">'+d1+' KW Solar Generator</a>.</p>';
	
	window.scroll(0,300); // horizontal and vertical scroll targets
}

function formatNumber(rnum, rlength) { 
	newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
	if(newnumber>999.5) {
		newnumber += '';
		x = newnumber.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;
	}
    else return newnumber; 
}

function formatMoney(nStr) {
	nStr = nStr.toFixed(2); 
	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 quote() {
if (test) {

	var id='';
	var sz='';
// determind quote id and size
	if (kw<1.2) {
		id = 'q1';
		sz = 1.05;
	}
	else {
		if (kw<1.6) {
			id = 'q2';
			sz = 1.4;
		}
		else {
			if (kw<1.9) {
				id = 'q3';
				sz = 1.75;
			}
			else {
				if (kw<2.3) {
					id = 'q4';
					sz = 2.1;
				}
				else {
					if (kw<2.3) {
						id = 'q4';
						sz = 2.1;
					}
					else {
						if (kw<2.6) {
							id = 'q5';
							sz = 2.45;
						}
						else {
							if (kw<3) {
								id = 'q6';
								sz = 2.8;
							}
							else {
								if (kw<3.3) {
									id = 'q7';
									sz = 3.15;
								}
								else {
									if (kw<3.7) {
										id = 'q8';
										sz = 3.5;
									}
									else {
										id = 'q9';
										sz = 3.7;
									}
								}
							}
						}
					}
				}
			}
		}
	}
// set up quotation for size
	var qty='';
	var desc='';
	var costs='';
	switch (id)
	{
	   case "q1" :
		  qty='6';
		  desc='1100W grid connected inverter: SMA SB1100, LCD display, 1210W maximum DC input, 240V output, dimensions 434W x 295H x 214D, weight 22kg, 5 years warranty.';
		  costs='1,050.00:1,250.00';
	      break;
	   case "q2" :
	      qty='8';
	      desc='1700W grid connected inverter: SMA SB1700, LCD display, 1850W maximum DC input, 240V output, dimensions 434W x 295H x 214D, weight 25kg, 5 years warranty.';
	      costs='1,400.00:1,600.00';
	      break;
	   case "q3" :
	      qty='10';
	      desc='1700W grid connected inverter: SMA SB1700, LCD display, 1850W maximum DC input, 240V output, dimensions 434W x 295H x 214D, weight 25kg, 5 years warranty.';
	      costs='1,750.00:1,950.00';
	      break;
	   case "q4" :
	      qty='12';
	      desc='2500W grid connected inverter: SMA SB2500, LCD display, 2700W maximum DC input, 240V output, dimensions 434W x 295H x 214D, weight 30kg, 5 years warranty.';
	      costs='2,100.00:2,300.00';
	      break;
	   case "q5" :
		  qty='14';
		  desc='2500W grid connected inverter: SMA SB2500, LCD display, 2700W maximum DC input, 240V output, dimensions 434W x 295H x 214D, weight 30kg, 5 years warranty.';
		  costs='2,450.00:2,650.00';
	      break;
	   case "q6" :
	      qty='16';
	      desc='2500W grid connected inverter: SMA SB2500, LCD display, 2700W maximum DC input, 240V output, dimensions 434W x 295H x 214D, weight 30kg, 5 years warranty.';
	      costs='1,800.00:3,000.00';
	      break;
	   case "q7" :
	      qty='18';
	      desc='3300W grid connected inverter: SMA SB3300, LCD display, 3820W maximum DC input, 240V output, dimensions 450W x 352H x 236D, weight 41kg, 5 years warranty.';
	      costs='3,150.00:3,350.00';
	      break;
	   case "q8" :
	      qty='20';
	      desc='3300W grid connected inverter: SMA SB3300, LCD display, 3820W maximum DC input, 240V output, dimensions 450W x 352H x 236D, weight 41kg, 5 years warranty.';
	      costs='3,500.00:3,700.00';
	      break;
	   default :
		  qty='';
		  desc='';
		  costs='';
	}
// set quotation fields to form
	document.formquote.quoteid.value = id;
	document.formquote.quotesz.value = sz;
	document.formquote.quoteqty.value = qty;
	document.formquote.quotedesc.value = desc;
	document.formquote.quotecosts.value = costs;
}
}

// -->
