// JavaScript Document
// stie-scripts.js
// Author: BitCrafter Media Corporation - www.bitcrafter.com

// This function is called to toggle the visibility state of the top main navigation
// items. First it identifies and hides any submenu DD not associated with the currently  
// selected main navigation button, then it sets the visibility state of is own associated
// menu DD to unhidden.

function toggleHide(divID, btn) {
	var activeBtn = btn;
	var navArray = ['about', 'services', 'quote'];
	var navLen = navArray.length;
	var item = document.getElementById(divID);
	
	// if the btn flag sent is set to 100, you're toggling a page element, do the following...
	
	if (activeBtn = 100) {
			// ... show its hidden page DIV for testImonials
			if (item) {
			item.className=(item.className=='hidden')?'unhidden testBox':'hidden';
		}
		
	} else {  // if not a page element, it's a navigation toggle
	
	// cycle though all current main menu buttons toggeling their css visibility state
		for (var x = 0; x < navLen; x++) {
			// based on the main nav button selected, either hide its submenu item, or...
			if (x != activeBtn) {
				document.getElementById(navArray[x]).className = "hidden";
				}
			else {
				// ... show its submenu item
				if (item) {
					item.className=(item.className=='hidden')?'unhidden':'hidden';
				}
			}
		}
	}
}

// resize the browser window to full screen
function maxWindow() {

	window.moveTo(0,0);

	window.resizeTo(screen.width, screen.height);
}

var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var fulldate = month + "/" + day + "/" + year;

function getDate() {
	document.getElementById("date").value = fulldate; 
}

function checkEmpty() {
	if (document.getElementById("date").value == "") {
		getDate()
	}
}

function validate() {

}

function checkButton(buttonName, textName, flag) {

	var numButtons = eval("document.tabForm." + buttonName + ".length;");
	
	// onFocus flag that sets correct checkecd button for written option
	if (flag == 1) {
		eval("document.tabForm." + buttonName + "[" + (numButtons - 1) + "].checked = true;");
	
	// flag is zero - checking which button selected and if text field has value
	} else {

		var textValue = eval("document.tabForm." + textName + ".value");
		
		for (var i=0; i < numButtons; i++) {
		
			var buttonChecked = eval("document.tabForm." + buttonName + "[" + i + "].checked");
			
			// if the last button, set focus to text area
			if (buttonChecked == true) {
				
				//which button is it, the last correct one?
				if (i == (numButtons - 1)) {
					eval("document.tabForm." + textName + ".focus()");
					
				} else {
					eval("document.tabForm." + textName + ".value = '';");
				}
			}
		}
	}
}

function checkButtonBlur(buttonName, textName) {

	var numButtons = eval("document.tabForm." + buttonName + ".length;");
	var textValue = eval("document.tabForm." + textName + ".value");
	
	// onFocus flag that sets correct checkecd button for written option
	if (textValue == "") {
		eval("document.tabForm." + buttonName + "[" + (numButtons - 1) + "].checked = false;");
	}
}

function setCheckBoxFocus(checkName, textName, flag) {

	if (flag == 1) {
		eval("document.tabForm." + checkName + ".checked = true;");
		
	} else {
		var checkState = eval("document.tabForm." + checkName + ".checked;");
		if (checkState == false) {
			eval("document.tabForm." + textName + ".value = '';");
		} else {
			eval("document.tabForm." + textName + ".focus()");
		}
	}
}

function setCheckBoxBlur(checkName, textName) {

	var textValue = eval("document.tabForm." + textName + ".value;");
	var checkedState = eval("document.tabForm." + checkName + ".checked;");

	if (textValue == "" && checkedState == true) {
		eval("document.tabForm." + checkName + ".checked = false;");
	}
}
