// Browser Definitions for Menu Functionality
ns4 = (document.layers) ? true:false
ns6 = (document.getElementById) ? true:false
ie4 = (document.all) ? true:false

// -----------------------------------------------------------------------------------------
// FORM VALIDATION FUNCTIONS
// -----------------------------------------------------------------------------------------

function CM_ValidateForm(form_num,email_num) {
if(CM_ReportOutEmail(form_num,email_num) == false) {return false;} else {}
var form_length = document.forms[form_num].elements.length;
var Final = new Array(); Final[0] = "none";
for(var i=0,p=0;i<form_length;i++) {
	if (CM_CheckReq(form_num,i)) {
   	   if (CM_CheckValue(form_num,i)) {
   	    Final[p] = document.forms[form_num].elements[i].name; p++;}}
}if (CM_ReportOutBlank(Final) == false) { return false;} else{ return true;}
}

function CM_CheckReq(form_num,element) {
var this_element_name = document.forms[form_num].elements[element].name;
if (this_element_name.charAt(0) == "*") {return true;} else {return false;}
}

function CM_CheckValue(form_num,element) {
var this_element_value = document.forms[form_num].elements[element].value;
if (this_element_value == null || this_element_value == "") {return true;
} else { return false;} 
}

function CM_CompileErrors(This_Array) { // Compile Errors into variable for Output
var errors = ""; for(var i=0;i<This_Array.length;i++) {
errors += "\n" + This_Array[i];} return errors;
}

function CM_ReportOutBlank(Final) {
var errors = CM_CompileErrors(Final);
if (Final[0] == "none") {return true;} else {
alert("ERROR: The following fields were left blank:\n" + errors + "\n\nPlease make sure to fill out all required\nfields and re-submit the form.");
return false;
}
}

function CM_ReportOutEmail(form_num,email_num) {
if (email_num == -1) {return true;} else{
var email = document.forms[form_num].elements[email_num].value;
if (email.indexOf("@") == -1 || email.indexOf(".") == -1) {
alert("ERROR: E-Mail Address is invalid.\n\nThe email address you entered is either\nblank or is not in the correct format. Please\ncorrect the e-mail address and re-submit the form.");
return false;} else {return true;}
}
}

// -----------------------------------------------------------------------------------------
// MENU CREATION FUNCTIONS
// -----------------------------------------------------------------------------------------
function CM_CreateMenus() {
var num = section.length;
var MenuLayers = new Array(section.length-1); var sec = new Array();
 // Sets Limit for Calculations
for(var i=0;i<num;i++) {

		var sec = eval(section[i]); var section_number = eval(section[i] + '_number');
		var mwidth = eval(section[i] + '_width'); var mheight = eval(section[i] + '_height');
		var mzindex = eval(section[i] + '_zindex');var mleft = eval(section[i] + '_left');
		var mtop = eval(section[i] + '_top');

		// Begin Layer & Tables
		var y = section_number + 1; // Set Limit for Calculations 
		
		var output = '<div id="Menu' + i + '" style="position:absolute; width:' + mwidth + '; height:' + mheight + '; z-index:' + mzindex + '; top:' + mtop + '; left:' + mleft + '; visibility:hidden" onMouseOver="CM_ShowLayer(' + i + ')" onMouseOut="CM_HideLayer(' + i + ')">';
		if (i == 0) { 
		   output += '';
		} else {
		  if (document.all || document.getElementById) { // For IE4 & NS6
		
		  output += '<table width="180" border="0" cellspacing="1" cellpadding="0">';
		  output += '<tr><td bgcolor="#000000">';
		  output += '<table width="100%" border="0" cellspacing="1" cellpadding="1">';

		  for (var x=1;x<y;x++) {
		  	  output += '<tr>';
		  	  output += '<td bgcolor="' + MenuColor + '" onMouseOver="CM_ChangeCell(this,' + i + ',' + x +')" onMouseOut="CM_ReplaceCell(this,' + i + ')" onClick="CM_GetURL(' + i + ',' + x + ')">';
		  	  output += '<font size="' + MenuFontSize + '" color="' + MenuFontColor + '" face="' + MenuFont + '"><b>';

		  	  if (document.layers) {
		  	  	 var section_link = eval(section[i] + '_link[' + x + ']');
				 output += '<A HREF = "' + SiteURL + section_link + '">' + sec[x] + '</A>';
		  	  } else { 
		  	  	output += sec[x];
		  	  	}
 		  	  output += '</font></b>';
	   	  	  output += '</td>';
	   	  	  output += '</tr>';
	 	  } // End second FOR Loop
 	  	  output += '</table></tr></td></table>'; // End Tables
	   	  output += '</div>'; // End Layer
	  	  }
		  else if (document.layers) { // For NS4
		  	   output += '<LAYER ID="Layer' + x + '" onMouseOver="CM_ShowLayer(' + i + ')" onMouseOut="CM_HideLayer(' + i + ')">';
			   output += '<table width="180" border="0" cellspacing="1" cellpadding="0">';
		  	   output += '<tr><td bgcolor="#000000">';
			   output += '<table width="100%" border="0" cellspacing="1" cellpadding="1">';

		  for (var x=1;x<y;x++) {
		  	  output += '<tr>';
		  	  output += '<td bgcolor="' + MenuColor + '">';  
		  	  output += '<font size="' + MenuFontSize + '" color="' + MenuFontColor + '" face="' + MenuFont + '"><b>';
			  output += '<ilayer ID="Ilayer' + x + '" width="100%"><Layer bgColor=' + MenuColor + ' width="100%" onMouseOver="CM_ChangeCell(this,' + i + ',' + x +')" onMouseOut="CM_ReplaceCell(this,' + i + ')" layer.onClick="CM_GetURL(' + i + ',' + x + ')">';
			  var section_link = eval(section[i] + '_link[' + x + ']');
			  output += '<A HREF = "' + SiteURL + section_link + '">' + sec[x] + '</A>';
			  output += '</font></b>';
			  output += '</LAYER></ilayer></td>';
	   	  	  output += '</tr>';
	 	  } // End second FOR Loop
			   
			   output += '</table></td></tr></table></layer>';
			   output += '</div>'; // End Layer
		  	   		  
		  }} // End First IF LOOP
 	   MenuLayers[i] = output; // Write Layer to Array For Later Use
} // End First FOR Loop
var ToHTML = " "; // Set Variable for Output
for (var i=0;i<num;i++) {
	ToHTML += MenuLayers[i]; // Add Array Contents to Output Variable
}
document.write(ToHTML); // Output to HTML document
}

function CM_ShowLayer(MenuNum) {
if (ns6) {document.getElementById('Menu' + MenuNum).style.visibility = "visible";} // Ns6 Browser
else if (ie4) {document.all["Menu" + MenuNum].style.visibility = "visible";} // IE Browser
else if (ns4) {
document.layers['Menu' + MenuNum].visibility = "show";} // Netscape 4 Compensation
return true;
}

function CM_HideLayer(MenuNum) {
if (ns6) {document.getElementById('Menu' + MenuNum).style.visibility = "hidden";} // Ns6 Browser
else if (ie4) {document.all["Menu" + MenuNum].style.visibility = "hidden";} // IE Browser
else if (ns4) {
document.layers['Menu' + MenuNum].visibility = "hide";} // Netscape 4 Compensation
return true;
}

function CM_ChangeCell(cell,MenuNum,LinkNum) {
var CurrentSection = section[MenuNum];
cell.bgColor = MenuHighlightColor; 
if(ie4) {cell.style.cursor = 'hand';}
else if (ns6) {cell.style.cursor = 'pointer';}
parent.status = eval(CurrentSection + "[" + LinkNum + "]");;
return true;
}

function CM_ReplaceCell(cell,MenuNum) { 
cell.bgColor = MenuColor;
parent.status ='Done';
return true;
}

function CM_GetURL(MenuNum,LinkNum){
var CurrentSection = section[MenuNum];
var CurrentLink = eval(CurrentSection + "_link[" + LinkNum + "]");
document.location.href = SiteURL + CurrentLink;
}

// -----------------------------------------------------------------------------------------
// MISCELLANEOUS FUNCTIONS
// -----------------------------------------------------------------------------------------

function CM_CheckBrowser(){
ns4 = (document.layers) ? true:false
ns6 = (document.getElementById) ? true:false
ie4 = (document.all) ? true:false
}

function CheckIfPopup() {
if(!ie4 && !ns6) {
CM_InWindow('upgrade_advise.html','Upgrade','width=290,height=330');
} else {}
}

function CM_LoadPage(pageURL){ 
if((pageURL.options[pageURL.selectedIndex].value) == 'empty') {}
else {location.href = pageURL.options[pageURL.selectedIndex].value
}}

function CM_LoadFile(fileName,filetype){ 
if((fileName.options[fileName.selectedIndex].value) == "empty") {
} else {
location.href = fileName.options[fileName.selectedIndex].value + filetype;
}
}

function CM_InWindow(URL,name,specs) { //v2.0
  window.open(URL,name,specs);
}

function CM_Loader(){var Image_Counter = new Array(); 
var counter =  Image_Counter.length; var Image_Paths = CM_Loader.arguments;
for(var i=0;i<Image_Paths.length;i++) {
Image_Counter[counter] = new Image();Image_Counter[counter++].src = Image_Paths[i];}}

function CM_Swap(current_image,new_image) {
document[current_image].src = new_image;
return true;
}


