DEBUG_ON = false;

$(document).ready(
	function() {
		$("#navCompleteCare a").html($("#navExtraCompleteCare").html());
		$("#navCompleteDataprotect a").html($("#navExtraCompleteDataProtect").html());
		$("#navCompleteOffice a").html($("#navExtraCompleteOffice").html());
		$("#navCompleteVirtual a").html($("#navExtraCompleteVirtual").html());
		
		$(".equalHeightChildren").each(
			function() {
				var maxHeight = 0;
				$(this).children("div").each(
					function() {
						maxHeight = Math.max(maxHeight, $(this).height());
					}
				);
				
				$(this).children("div").height(maxHeight);
			}
		);
		
		$("td[valign=bottom]").addClass("tdbottom");
		$("td[valign=middle]").addClass("tdmiddle");
		$("td[valign=top]").addClass("tdtop");
		
		$("td[align=left]").addClass("tdleft");
		$("td[align=right]").addClass("tdright");
		$("td[align=center]").addClass("tdcenter");

		$(".featurebox").wrapInner("<div class=\"featureboxTop\" />");
		
		/* $("a[target=_modal]").click(
			function() {
				showModal(this.href);
				return false;
			}
		); */
		
		$("a[target=_modal]").ceebox(
			{
				videoWidth: 560,
				videoHeight: 340,
				videoRatio: 560/340,
				titles: false
			}
		);

		if (DEBUG_ON) {
			dbg = document.createElement("textarea");
			dbg.id = "debugBox";
			dbg.value = "";
			dbg.style.position = "absolute";
			dbg.style.bottom = "0px";
			dbg.style.left = "0px";
			dbg.style.width = "100%";
			dbg.style.height = "20%";
			dbg.style.zIndex = "99999";
			document.body.appendChild(dbg);

			dbgClose = document.createElement("span");
			dbgClose.onclick = function () { $(this).hide(); $("#debugBox").hide(); };
			dbgClose.style.position = "absolute";
			dbgClose.style.bottom = "21%";
			dbgClose.style.right = "0px";
			dbgClose.style.color = "red";
			dbgClose.style.zIndex = "100000";
			dbgClose.innerHTML = "Close Me";
			document.body.appendChild(dbgClose);
		}
	}
);

showModal = function(url) {
	var uObj = $.url.setUrl(url);
	if (uObj.attr("host").toLowerCase().indexOf("youtube") >= 0) {
		var v = uObj.param("v");
		objCode = "<object width=\"560\" height=\"340\"><param name=\"movie\" value=\"http://www.youtube.com/v/" + v + "&hl=en_US&fs=1&rel=0&showinfo=0\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube.com/v/" + v + "?fs=1&amp;hl=en_US&amp;rel=0\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"560\" height=\"340\"></embed></object>";
	} else {
	}
}


debug = function(dbgText) {
	if (DEBUG_ON) {
		document.getElementById("debugBox").value += dbgText;
		document.getElementById("debugBox").value += "\n";
		document.getElementById("debugBox").scrollTop = document.getElementById("debugBox").scrollHeight;
	}
}



function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + '$' + num + '.' + cents);
}
 
function getValue(num)
{
    var noJunk = ""
    var withDollar = ""
    var foundDecimal = 0
    var foundAlphaChar = 0
    num += "";
 
    if (num == "") { return(0); }
    for (i=0; i <= num.length; i++)
    {
        var thisChar = num.substring(i, i+1);
        if (thisChar == ".")
        {
          foundDecimal = 1;
          noJunk = noJunk + thisChar;
        }
        if ((thisChar < "0") || (thisChar > "9"))
        {
          if ((thisChar != "$") && (thisChar !=".") && (thisChar != ",") && (thisChar != " ") && (thisChar !="")) foundAlphaChar = 1;
        }
        else
 {
    withDollar = withDollar + thisChar
    noJunk = noJunk + thisChar
 }
 
 if ((thisChar == "$") || (thisChar == ".") || (thisChar == ","))
 {
   withDollar = withDollar + thisChar
 }
  }
     if (foundDecimal) { return parseFloat(noJunk); }
     else if (noJunk.length > 0) { return parseFloat(noJunk); }
     else return 0;
}
 
function downTime()
{   
    //init all variables
	var g5  = getValue(document.downtime.g5.value);
	var g6  = getValue(document.downtime.g6.value);
	var g7  = getValue(document.downtime.g7.value);
	var g8  = getValue(document.downtime.g8.value);
	var g9  = getValue(document.downtime.g9.value);
	var g10 = getValue(document.downtime.g10.value);
	var g11 = getValue(document.downtime.g11.value);
	var g12 = getValue(document.downtime.g12.value);
	var g13 = getValue(document.downtime.g13.value);
	var g14 = getValue(document.downtime.g14.value);
	var g15 = getValue(document.downtime.g15.value);
	
	//guts of the math
	g7  = g5 / 12;
	g8  = g7 * 0.25;
	g9  = g7 + g8;
	g10 = g9 / (30 * 4.333333);
	g11 = (g6 / 52) / 30;
	g12 = g10 + g11;
	g14 = (g12 * g13);
	g16 = g14 * g15;
	g18 = g16 * 12;
	
	//return results
	document.downtime.g7.value  = formatCurrency(g7);
	document.downtime.g8.value  = formatCurrency(g8);
	document.downtime.g9.value  = formatCurrency(g9);
	document.downtime.g10.value = formatCurrency(g10);
	document.downtime.g11.value = formatCurrency(g11);
	document.downtime.g12.value = formatCurrency(g12);
	document.downtime.g14.value = formatCurrency(g14);
	document.downtime.g16.value = formatCurrency(g16);
	document.downtime.g18.value = formatCurrency(g18);
	
    return true;
}


// copied from Mura's global.js and adjusted to force #navUtility to work in IE6
sfHoverUtility = function() {
	if(document.getElementById("navUtility") != undefined){
	var sfEls = document.getElementById("navUtility").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" sfhover";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
			}
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHoverUtility);

