// HTA Consulting Javascript

// Preload Images
function MM_preloadImages() { //v3.0
  var d=document;
  if(d.images){ 
  	if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments;
	for(i=0; i<a.length; i++)
    	if (a[i].indexOf("#")!=0){
			d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];
		}
	}
}

// Fitted Window
function popWin(youRL, windowName, features){
	window.open (youRL, windowName, features);
}

// Drop Menu Jump Page
function jumpPage(newLoc){
	newPage = newLoc.options[newLoc.selectedIndex].value;
	if (newPage !="") {
		window.location = newPage;
	}
}

// Image/Text Swap

var w3c = (document.getElementById) ? 1:0;
var ns4 = (document.layers) ? 1:0;
var ie4 = (document.all) ? 1:0;

function imgSwap(img,state){

	if(state == "on"){

		document.getElementById(img).style.borderColor = "#D9D9D9";

		tempArray = img.split("_");

		linkName = "link_" + tempArray[1];

		var nsLayer = eval("document." + linkName);

		!ns4?document.getElementById(linkName).style.color = "#FFFFFF":nsLayer.document.color = "#FFFFFF";
		!ns4?document.getElementById(linkName).style.backgroundColor = "#B21107":nsLayer.document.backgroundColor = "#B21107";

	}else{

		document.getElementById(img).style.borderColor = "#FFFFFF";

		tempArray = img.split("_");

		linkName = "link_" + tempArray[1];
		// on mouse out on text
		!ns4?document.getElementById(linkName).style.color = "#B21107":void(0);
		!ns4?document.getElementById(linkName).style.backgroundColor = "#D9D9D9":void(0);

	}

}

// DOM Pop-up window
function showWindow(winName,state){
	var navHeight = 145;
	var prodImgHeight = 180;
	tempArray = winName.split("_");
	var yLoc = navHeight+prodImgHeight+20+(140*tempArray[1]);
	if(state=="on"){
		var nsLayer = eval("document."+winName);
		!ns4?document.getElementById(winName).style.visibility = "visible":nsLayer.document.visibility = "visible";
		!ns4?document.getElementById(winName).style.top = yLoc+"px":nsLayer.document.top = yLoc+"px";
	}else{
		//setTimeout("hideWindow("+winName+")", 5);
		document.getElementById(winName).style.visibility = "hidden";
	}
}

function hideWindow(winName){
	document.getElementById(winName).style.visibility = "hidden";
}

// Validate form

function isblank(s) {
	for (var i=0; i<s.length; i++){
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '')) return false;
	}
	return true;
}

function validate(f) {
	var msg;
	var empty_fields = "";
	var errors = "";
	var notrated = "";
	var validemail = true;
	
	for (var i=0; i<f.length; i++){
		var e = f.elements[i];
		
		if (((e.type == "text") || (e.type == "textarea") || e.type == "select-one") && !e.optional){
			// Check if field is empty
			if ((e.value == null) || e.value == "" || isblank(e.value)) {
				empty_fields += "\n        " + e.name;
				continue;
			}
			// Check e-mail fields
			if (e.name.indexOf("email")){
				var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
				if (!filter.test(e.value)){
					validemail = false;
				}
			}
			
			// Check for numeric fields
			var tempName = e.name;
			var tempArray = tempName.split("_");
			if (e.numeric || (e.min != null) || (e.max != null)){
				var v = parseFloat(e.value);
				if ((isNaN(v) || ((e.min != null) && (v < e.min)) || ((e.max != null) && (v > e.max))) && tempArray[0] != "rate") {
					errors += "- Please make a valid entry for the field " + e.name + ".\n";
				}
			}
		}
	}
	
	if(!empty_fields && !errors) return true;
	
	msg = "This form was not sent due to the following error(s).\n";
	msg += "Please correct these errors and try again.\n\n--------------------------------------\n\n";
	
	if (empty_fields){
		msg += "- The following required field(s) are empty:" + empty_fields + "\n";
		if (errors) msg += "\n" + errors;
	}
	
	if (!validemail){
		msg += "- Please enter a valid e-mail address";
	}
	
	alert(msg);
	return false;
}

// Show/Hide

function dispWin(identifier) {

		var contentID	= "win" + identifier;

		if (document.getElementById(contentID).style.display == "none")
		{
			document.getElementById(contentID).style.display="block";
			document.getElementById(contentID).style.visibility="visible";
		} else {
			document.getElementById(contentID).style.display="none";
			document.getElementById(contentID).style.visibility="hidden";

		}
		
	}
	
// Check Flash

function getFlashVersion() {

   var agent = navigator.userAgent.toLowerCase();
       flashVersion = 0; 
   if (agent.indexOf("mozilla/3") != -1 && agent.indexOf("msie") == -1) {
      flashVersion = 0;
   }
   // NS3+, Opera3+, IE5+ Mac (support plugin array):  check for Flash plugin in plugin array
   if (navigator.plugins != null && navigator.plugins.length > 0) {
      var flashPlugin = navigator.plugins['Shockwave Flash']; 
      if (typeof flashPlugin == 'object') {
            for (i=25;i>0;i--) {
                  if (flashPlugin.description.indexOf(i+'.') != -1){ 
                           flashVersion = i;
              }
            }
      }
    }
	
	if (flashVersion<8){
		window.location = "noflash.php";	
	}
	
}

function gotoURL(object) {
	window.location.href = object.options[object.selectedIndex].value;	
}