// JavaScript Document
function resetFORM(){
	document.getElementById("c_name").value = "your name";
	document.getElementById("c_name2").value = "contact name";
	document.getElementById("bw_pages").value = 1000000;
	document.getElementById("av_cost_bw").value = 0.06;
	document.getElementById("av_cost_print_bw").value = 0.25;
	document.getElementById("c_pages").value = 10000;
	document.getElementById("av_cost_color").value = 0.06;
	document.getElementById("av_cost_print_color").value = 0.70;
	
	var tt1 = 1000000 * 0.06;
	var tt2 = 1000000 * 0.25;
	
	var tt_total_1 = tt1 + tt2;
	
	var aa1 = 10000 * 0.06;
	var aa2 = 10000 * 0.70;
	
	var aa_total_1 = aa1 + aa2;
	
	var start_total1 = tt_total_1 * 0.18;
	var start_total2 = aa_total_1 * 0.18;
	
	var TOTAL2;
	
	TOTAL2 = start_total1 + start_total2;
	
	document.getElementById("cost_per_month1").innerHTML = "R " + tt_total_1.toFixed(2);
	document.getElementById("cost_per_month2").innerHTML = "R " + aa_total_1.toFixed(2);
	document.getElementById("month_savings").innerHTML = "R " + TOTAL2.toFixed(2);		
	}
function fillValues(){
	document.getElementById("c_name").value = "your name";
	document.getElementById("c_name2").value = "contact name";
	document.getElementById("bw_pages").value = 1000000;
	document.getElementById("av_cost_bw").value = 0.06;
	document.getElementById("av_cost_print_bw").value = 0.25;
	document.getElementById("c_pages").value = 10000;
	document.getElementById("av_cost_color").value = 0.06;
	document.getElementById("av_cost_print_color").value = 0.70;
	
	var tt1 = 1000000 * 0.06;
	var tt2 = 1000000 * 0.25;
	
	var tt_total_1 = tt1 + tt2;
	
	var aa1 = 10000 * 0.06;
	var aa2 = 10000 * 0.70;
	
	var aa_total_1 = aa1 + aa2;
	
	var start_total1 = tt_total_1 * 0.18;
	var start_total2 = aa_total_1 * 0.18;
	
	var TOTAL2;
	
	TOTAL2 = start_total1 + start_total2;
	
	document.getElementById("cost_per_month1").innerHTML = "R " + tt_total_1.toFixed(2);
	document.getElementById("cost_per_month2").innerHTML = "R " + aa_total_1.toFixed(2);
	document.getElementById("month_savings").innerHTML = "R " + TOTAL2.toFixed(2);		
	
	}

function validNumber(fieldVal){
    if(! fieldVal.match(/\b\d+\b/)){ //toets net vir nommers
    alert('ERROR: Only numbers are allowed');
    return false;
    }
	return true;
	}
	function Clickheretoprint()
	{ 
	  var disp_setting="toolbar=yes,location=no,directories=yes,menubar=yes,"; 
		  disp_setting+="scrollbars=yes,width=420, height=550, left=100, top=25"; 
	  var content_vlue = document.getElementById("print_content").innerHTML; 
	  
	  var docprint=window.open("","",disp_setting); 
	   docprint.document.open(); 
	   docprint.document.write('<html><head><title>Inel Power System</title>'); 
	   docprint.document.write('</head><body style="font-family:Arial; font-size:10px;" onLoad="self.print()"><center>');          
	   docprint.document.write(content_vlue);          
	   docprint.document.write('</center></body></html>'); 
	   docprint.document.close(); 
	   docprint.focus(); 
	}
	function calculateValues(){		
	var themessage = "";	
	if (document.getElementById("c_name").value == "") {
		themessage += "- Your name\n";
	}
	if (document.getElementById("c_name2").value == "") {
		themessage += "- Contact name\n";
	}
	if (document.getElementById("bw_pages").value == "") {
		themessage += "- Black and White, Pages printed per month\n";
	}
	if (document.getElementById("av_cost_bw").value == "") {
		themessage += "- Black and White, Average cost of paper\n";
	}
	if (document.getElementById("av_cost_print_bw").value == "") {
		themessage += "- Black and White, Average cost of Printed page\n";
	}
	
	if (document.getElementById("c_pages").value == "") {
		themessage += "- Colour, Pages printed per month\n";
	}
	if (document.getElementById("av_cost_color").value == "") {
		themessage += "- Colour, Average cost of paper\n";
	}
	if (document.getElementById("av_cost_print_color").value == "") {
		themessage += "- Colour, Average cost of Printed page\n";
	}
	
	//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	
	if (themessage == "") {
		//return true;
		
		//Black and white Variables
	
			// value cost of page
			var bw_pageValue1 = document.getElementById("av_cost_bw").value;
			// value for printed page
			var bw_pageValue2 = document.getElementById("av_cost_print_bw").value;
			// collect value for black and white
			var bw_quantity = document.getElementById("bw_pages").value;
			// total pages for black and white
			var bw_prints;
			//convert pages printed value to Integer
			bw_prints = parseInt(bw_quantity);
			//value for black and white calculation1
			var bw_calc1;
			//value for black and white calculation2
			var bw_calc2;
			//total amount for black and white
			var bw_total;
			
			// FINAL total
			var finalBW;
			var finalCOLOR;
			var TOTAL;
			
		// Color Variables
		
			// value cost of page
			var color_pageValue1 = document.getElementById("av_cost_color").value;
			// value for printed page
			var color_pageValue2 = document.getElementById("av_cost_print_color").value;
			// collect value for black and white
			var color_quantity = document.getElementById("c_pages").value;
			// total pages for black and white
			var color_prints;
			//convert pages printed value to Integer
			color_prints = parseInt(color_quantity);
			//value for black and white calculation1
			var color_calc1;
			//value for black and white calculation2
			var color_calc2;
			//total amount for black and white
			var color_total;
			
			
			// check user details
			if (document.getElementById("c_name").value == ""){
					document.getElementById("customerName").innerHTML = "Please fill in this field."	
			}else {
				document.getElementById("customerName").innerHTML = document.getElementById("c_name").value;	
			}
			if (document.getElementById("c_name2").value == ""){		
					document.getElementById("contactName").innerHTML = "Please fill in this field."	
			}else {
				document.getElementById("contactName").innerHTML = document.getElementById("c_name2").value;
			}
			if (document.getElementById("c_number").value == ""){
					document.getElementById("contactNumber").innerHTML = "Please fill in this field."
			}else {
				document.getElementById("contactNumber").innerHTML = document.getElementById("c_number").value;
			}
			
			// check printed pages for BLACK AND WHITE
				if(bw_quantity.length == 0){	
					document.getElementById("print_printed1").innerHTML = "Please fill in the quantity of pages printed for Black and White";
					alert("Please fill in the quantity of pages printed for Black and White");
				}else {
					//alert("success");
					bw_calc1 = bw_pageValue1 * bw_prints;
					bw_calc2 = bw_pageValue2 * bw_prints;
					bw_total = bw_calc1 + bw_calc2;
					document.getElementById("print_printed1").innerHTML = bw_quantity;
					document.getElementById("avg_bw1").innerHTML = "R " + bw_pageValue1;
					document.getElementById("avg_bw2").innerHTML = "R " + bw_pageValue2;
					document.getElementById("cost_per_month1").innerHTML = "R " + bw_total.toFixed(2);
					document.getElementById("print_cost_per_month1").innerHTML = "R " + bw_total.toFixed(2);
					}
				
			// check printed pages for COLOR
				if(color_quantity.length == 0){	
					document.getElementById("print_printed2").innerHTML  = "Please fill in the quantity of pages printed for Colour";
					alert("Please fill in the quantity of pages printed for Colour");
				}else {
					//alert("success");
					color_calc1 = color_pageValue1 * color_prints;
					color_calc2 = color_pageValue2 * color_prints;
					color_total = color_calc1 + color_calc2;
					document.getElementById("print_printed2").innerHTML = color_quantity;
					document.getElementById("avg_color1").innerHTML = "R " + color_pageValue1;
					document.getElementById("avg_color2").innerHTML = "R " + color_pageValue2;
					document.getElementById("cost_per_month2").innerHTML = "R " + color_total.toFixed(2);
					document.getElementById("print_cost_per_month2").innerHTML = "R " + color_total.toFixed(2);
					}
					
				finalBW = bw_total * 0.18;
				finalCOLOR = color_total * 0.18;
				TOTAL = finalBW + finalCOLOR;
				
				document.getElementById("month_savings").innerHTML = "R " + TOTAL.toFixed(2);;			
				document.getElementById("print_month_savings").innerHTML = "R " + TOTAL.toFixed(2);		
			//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
		
		
	} else {
		alert("Please fill in the following fields: \n" + themessage);
		return false;
	}		
}
