var currentSection = "";

// Function highlights the active main nav item by matching
// the contents of the item's SPAN to the supplied text
// for the given page (supplied in the BODY onLoad);

function stripHTML(string) {
  string = string.replace('&amp;','&');
	string = string.replace('&gt;','>');
	string = string.replace(/ /g,'');
  return string;
}

function setNav(main, sub) {
	currentSection = main;
	// Identify the table containing the main nav items
	navTableObj = document.getElementById('mainNavTable');

	// Loop through and look for a match between the
	// text string supplied as an argument and the text
	// of each main nav item. Here we are looping through
	// 20 iterations (20 potential nav items) on the assumption
	// that there will never be more than that (in fact, there
	// should never be more than six or seven). If the loop
	// hits a non-existing nav item, it quits.
	for (i=1; i<=20; i++) {
		// Get the nav item for this increment
		navObj = document.getElementById('mainNav' + i);
		if (!navObj) break; //If the item doesn't exist, stop the loop

		// If the item's text matches the argument, set the highlight
		if (navObj.innerHTML==main) {
			navObj.setAttribute("class","nav main on"); // Set the class to the "on" state
			navObj.setAttribute("onMouseOut",""); // Empty the onMouseOut, so that it can't be turned off

			// These do the same thing as the lines above, but they are for IE6 Mac
			navObj.className = "nav main on";
			navObj.onmouseout = "";
		}
	}

	// If we're supplied with a 'sub' argument, do the same thing
	// for the subnav
	for (i=1; i<=20; i++) {
		// Get the nav item for this increment
		navObj = document.getElementById('subNav' + i);
		if (!navObj) break; //If the item doesn't exist, stop the loop

		// If the item's text matches the argument, set the highlight
		if (stripHTML(navObj.innerHTML)==stripHTML(sub)) {
			navObj.setAttribute("class","nav sub subOn"); // Set the class to the "on" state
			navObj.setAttribute("onMouseOut",""); // Empty the onMouseOut, so that it can't be turned off

			// These do the same thing as the lines above, but they are for IE6 Mac
			navObj.className = "nav sub subOn";
			navObj.onmouseout = "";
		}
	}
}


function goNav(dir) {
	var root = "";
	if (currentSection!="") root += "../";
	//alert( root + dir);
	document.location = root + dir;
}

function openpopup(p_popurl, p_width, p_height) {
	winpopup=window.open(p_popurl,"","width="+p_width+",height="+p_height+",resizable,scrollbars");
}

function adjustIframe(p_iframe) {
	if (p_iframe.contentDocument && p_iframe.contentDocument.body.offsetHeight) {
		p_iframe.height = p_iframe.contentDocument.body.offsetHeight;
	} else if (p_iframe.Document && p_iframe.Document.body.scrollHeight) {
		p_iframe.height = p_iframe.Document.body.scrollHeight;
	}
}

function sendSupportEmail(p_form) {
  for (var i = 0; i<p_form.elements.length; i++) {
  	if (p_form.elements[i].value == "") {
    	alert (p_form.elements[i].name + " is required");
			p_form.elements[i].focus();
			return false;
    }
	}
	var eName = "e" + "Support" + "@" + "3rdmill" + "." + "com";
	var name = escape(p_form.Name.value);
	var comp = "Company: " + escape(p_form.Company.value);
	var cust = "Cutomer Id: " + escape(p_form.CustomerId.value);
	var prod = "Product: " + escape(p_form.Product.value + " - version: " + p_form.Version.value);
	var subj = escape(p_form.Subject.value);
	var mesg = escape(p_form.Message.value);
 	location.href = "mailto:" + eName + "?subject=" + subj + "&body=" + cust + "%0A"  + comp + "%0A" + prod + "%0A%0A" + mesg + "%0A%0A" + name;
}

function sendTrialEmail(p_form) {
  for (var i = 0; i<p_form.elements.length; i++) {
  	if (p_form.elements[i].value == "") {
    	alert (p_form.elements[i].name + " is required");
			p_form.elements[i].focus();
			return false;
    }
	}
	var eName = "e" + "Sales" + "@" + "3rdmill" + "." + "com";
	var name = "Name: " + escape(p_form.Name.value);
	var comp = "Company: " + escape(p_form.Company.value);
	var phone = "Phone Number: " + escape(p_form.Phone.value);
	var prod = "Product: " + escape(p_form.Product.value);
	var subj = "Request for a 30-day trial account";
 	location.href = "mailto:" + eName + "?subject=" + subj + "&body=" + name + "%0A" + comp + "%0A"  + phone + "%0A" + prod;
}

function sendEmail(p_type) {
  if (p_type == "support") {
		var eName = "e" + "Support" + "@" + "3rdmill" + "." + "com";
	} else if (p_type == "sales") {
	  var eName = "e" + "Sales" + "@" + "3rdmill" + "." + "com";
	} else if (p_type == "consulting") {
		var eName = "consulting" + "@" + "3rdmill" + "." + "com";
	} else if (p_type == "careers") {
		var eName = "e" + "Careers" + "@" + "3rdmill" + "." + "com";
	}
	location.href = "mailto:" + eName;
}