/*
┌────────────────────────────────────────────────────────────────────┐
│		UI FUNCTIONS                                                     │
└────────────────────────────────────────────────────────────────────┘
*/
// DIV ___________________________________________________________________________________________
// Show one div, hide rest ID must be "txt_ plus a number (i)
function Show(a) {
	n = 26; // number of hidden layers
	for(i=1;i<=n;i++) {
		document.getElementById('sub'+i).style.display = 'none';
	}
	document.getElementById('sub'+a).style.display = 'inline';
}

// Shows a section of the page by it's Div ID
function ShowDiv(div_id) {
	document.getElementById(div_id).style.display = 'inline';
}

// Hides a section of the page by it's Div ID
function HideDiv(div_id) {
	document.getElementById(div_id).style.display = 'none';
}

// Set focus on a div by it's Div ID
function SetFocus(div_id) {
	window.focus(div_id);
}

// Write text to a div tag (id)
function Write(id, txt) {
	document.getElementById(id).innerHTML = txt;
}

// Change button image on mouseover
function btnMouseover(img_name, img_src) {
	document[img_name].src = img_src;
}

// FORMS _________________________________________________________________________________________
// Selects all text in a form element by it's ID
function SelectAll(id) {
	document.getElementById(id).focus();
	document.getElementById(id).select();
}

// Change text in a form element by it's ID, new text = txt
function WriteFormValue(id, txt) {
	document.getElementById(id).value = txt;
}

// Set focus to a specific fiels based on it's ID
function setFocus(id) {
	document.getElementById(id).focus();
}
// TABLES ________________________________________________________________________________________
// Show a row in a table by its ID
function show_row(trID) {											
	var my_row = document.getElementById(trID);
	try {
		my_row.style.display = 'table-row';
	}
	catch (e) {
		my_row.style.display = 'inline';
	}
}

// Hide a row in a table by its ID
function hide_row(trID){											
	var my_row = document.getElementById(trID);
	my_row.style.display = 'none';
}

// Get the value of a table cell when it's clicked
function getVal(e) {
    var valOne, valTwo;
    var theCell, theRow;

    // get the row that was clicked
    if (!e) var e = window.event;
    if (e.target) theCell = e.target;
    else if (e.srcElement) theCell = e.srcElement;
    if (theCell.nodeType == 3) // defeat Safari bug
        theCell = theCell.parentNode;

    theRow = theCell.parentNode;
    // get the value in the first cell of the row
    valOne = theRow.getElementsByTagName("td")[0].innerHTML;
    // get the value in the second cell of the row
    valTwo = theRow.getElementsByTagName("td")[1].innerHTML;

    alert("First cell: " + valOne + "\nSecond cell: " + valTwo);
}

// BROWSER ___________________________________________________________________________________________
// Go to another webpage, transfer variable
function gotoPage(page, variable){											
	var trans_data = document.getElementById(variable).value;
	window.location = "http://www.whelen.com/outdoor/WEPlan/build-a-spec.php?act="+trans_data;
}

// Remove a session variable
function removeSessionVar() {
	location = "http://www.whelen.com/outdoor/WEPlan/clearSession.php";
	window.location = location
}
function openPopup(proj) {
	var user_name = document.getElementById('user').value;
	var location = "http://www.whelen.com/outdoor/WEPlan/build-a-spec.php?mode=N&act="+user_name+"&proj="+proj;
	buildPopup = window.open(location,'mywindow','width=825,height=610,toolbar=no,location=yes,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
}

// STRINGS ____________________________________________________________________________________________
function upperCase(x) {
	var y=document.getElementById(x).value;
	var n=document.getElementById('aorder').value;
	if(n==0){
		document.getElementById('aorder').value=y;
	}
}

// BUILD-A-SPEC SPECIFIC CODE _________________________________________________________________________ 
function checkSession(){
	var pass = document.getElementById('pass').value;
	if(pass) {showUser(pass)};
}

function SaveAlert_new(){
	if(document.getElementById('project_location').value == "") {
		alert("You have not entered a location");
	}else{
		var x=window.confirm("Would you like to save this project?");
		if (x){
			ProjectSpecs('save');
			ProjectSpecs('new');
		}else{
			ProjectSpecs('new');
		}
	}
}

function SaveAlert_close(){
	var x=window.confirm("Would you like to save this project?");
	if (x){
		ProjectSpecs('save');
		window.close();
	}else{
		window.close();
	}
}

function ProjectSpecs(mode){
	var act         = document.getElementById('user_ID').value;
	var user_name   = document.getElementById('user_name').value;
	var name        = document.getElementById('project_name').value;
	var location    = document.getElementById('project_location').value;
	var sirenString = document.getElementById('jobInfo').value;
	var dB		    = document.getElementById('dB').value;

	sirenString = "";
	for (sirenNumber in Sirens) {
		sirenString += Sirens[sirenNumber].type + "," + Sirens[sirenNumber].center.x.toFixed(4) + "," + Sirens[sirenNumber].center.y.toFixed(4) + "," + Sirens[sirenNumber].color + ":";
	}

	var trans_data  = act +'|' + name +'|' + location +'|' + sirenString;
	if(mode == 'save') {
		
	var newURL = "http://www.whelen.com/outdoor/WEPlan/saveproject.php?act="+trans_data;
		window.open(newURL,'savewindow','width=400,height=200,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,copyhistory=no,resizable=no');
	}
	else if(mode == 'new') {
		var newURL = "http://www.whelen.com/outdoor/WEPlan/build-a-spec.php?mode=N&act="+user_name;
		this.location = newURL;
	}else{
		var newURL = "http://www.whelen.com/outdoor/WEPlan/printproject.php?mode=N&act="+trans_data+"&dB="+dB;
		window.open(newURL,'printwindow','width=400,height=600,toolbar=yes,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,copyhistory=no,resizable=no');
	}
}

function writeInfo(model) {
//alert("ui.js model = "+model);
	switch (model) {
		case 'WPS2901' :
			txt = '<p>One cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 109dBc</li><li>Estimated 70dB range: 1,500 feet</li><li>Estimated 60dB range: 3,000 feet </li></ul>';
			break;
		case 'WPS2902' :
			txt = '<p>Two cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 115dBc</li><li>Estimated 70dB range: 2,400 feet</li><li>Estimated 60dB range: 4,800 feet </li></ul>';
			break;
		case 'WPS2903' :
			txt = '<p>Three cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 119dBc</li><li>Estimated 70dB range: 3,000 feet</li><li>Estimated 60dB range: 6,000 feet </li></ul>';
			break;
		case 'WPS2904' :
			txt = '<p>Four cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 121dBc</li><li>Estimated 70dB range: 3,600 feet</li><li>Estimated 60dB range: 7,000 feet </li></ul>';
			break;
		case 'WPS2905' :
			txt = '<p>Five cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 123dBc</li><li>Estimated 70dB range: 4,200 feet</li><li>Estimated 60dB range: 8,400 feet </li></ul>';
			break;
		case 'WPS2906' :
			txt = '<p>Six cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 125dBc</li><li>Estimated 70dB range: 4,800 feet</li><li>Estimated 60dB range: 9,600 feet </li></ul>';
			break;
		case 'WPS2907' :
			txt = '<p>Seven cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 126dBc</li><li>Estimated 70dB range: 5,100 feet</li><li>Estimated 60dB range: 10,200 feet </li></ul>';
			break;
		case 'WPS2908' :
			txt = '<p>Eight cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 127dBc</li><li>Estimated 70dB range: 5,400 feet</li><li>Estimated 60dB range: 10,800 feet </li></ul>';
			break;
		case 'WPS2909' :
			txt = '<p>Nine cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 128dBc</li><li>Estimated 70dB range: 5,800 feet</li><li>Estimated 60dB range: 11,600 feet </li></ul>';
			break;
		case 'WPS2910' :
			txt = '<p>Ten cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 129dBc</li><li>Estimated 70dB range: 6,100 feet</li><li>Estimated 60dB range: 12,200 feet </li></ul>';
			break;
		case 'OA1' :
			txt = '<p>One cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 108dBc</li><li>Estimated 70dB range: 1,400 feet</li><li>Estimated 60dB range: 2,800 feet </li></ul>';
			break;
		case 'OA2' :
			txt = '<p>Two cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 114dBc</li><li>Estimated 70dB range: 2,200 feet</li><li>Estimated 60dB range: 4,400 feet </li></ul>';
			break;
		case 'OA3' :
			txt = '<p>Three cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 115dBc</li><li>Estimated 70dB range: 2,400 feet</li><li>Estimated 60dB range: 4,800 feet </li></ul>';
			break;
		case 'OA4' :
			txt = '<p>Four cell speaker assembly with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 118dBc</li><li>Estimated 70dB range: 2,800 feet</li><li>Estimated 60dB range: 5,600 feet </li></ul>';
			break;
		case 'WPS4003' :
			txt = '<p>Three speaker cells active with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 127dBc</li><li>Estimated 70dB range: 5,400 feet</li><li>Estimated 60dB range: 10,800 feet </li></ul>';
			break;
		case 'WPS4004' :
			txt = '<p>Four speaker cells active with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 129dBc</li><li>Estimated 70dB range: 6,000 feet</li><li>Estimated 60dB range: 12,000 feet </li></ul>';
			break;
		case 'VORTEXR1' :
			txt = '<p>One speaker cell active with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 120dBc</li><li>Estimated 70dB range: 3,100 feet</li><li>Estimated 60dB range: 6,400 feet </li></ul>';
			break;
		case 'VORTEXR2' :
			txt = '<p>Two speaker cells active with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 126dBc</li><li>Estimated 70dB range: 5,200 feet</li><li>Estimated 60dB range: 10,400 feet </li></ul>';
			break;
		case 'VORTEXR3' :
			txt = '<p>Three speaker cells active with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 127dBc</li><li>Estimated 70dB range: 5,400 feet</li><li>Estimated 60dB range: 10,800 feet </li></ul>';
			break;
		case 'VORTEXR4' :
			txt = '<p>Four speaker cells active with cabinet</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 129dBc</li><li>Estimated 70dB range: 6,000 feet</li><li>Estimated 60dB range: 12,000 feet </li></ul>';
			break;
		case 'HORNET' :
			txt = '<p>One 400 watt speaker</p><ul><li>Acoustic Performance: SPL @ 100&rsquo;: 118dBc</li><li>Estimated 70dB range: 2,800 feet</li><li>Estimated 60dB range: 5,600 feet </li></ul>';
			break;
		default :
			'There is no data for this product'
	}
	Write('prodname', model);
	Write('proddesc', txt);
}