var DOM = false;
var NS4 = false;
var IE = false;
var IE4 = false;
var Mac = false;
var IE4M = false;
var arrImages = [['No Images', '']]
var blnFormSubmit = false;

function ClearDirtyFlag ()
{
	blnFormSubmit = true;
}

function CheckDirtyFlagOnUnload ()
{
	document.onkeydown = CatchKeyDown;
	document.onclick = CatchOnClick;
	window.onbeforeunload = CatchOnBeforeUnLoad;
}

function IsFieldExcluded (Name)
{
	var strExcluded = document.forms[0].ExcludedFromDirtyCheck.value;

	// If there is no field name the do not exclude it
	if (Name.length == 0 || Name == null) { return false; }
		
	if (Name.indexOf(":") > 0)
	{
		Name = Name.substr(Name.indexOf(":")+1);
	}

	if (strExcluded.indexOf(":" + Name.toUpperCase() + ":") >= 0)
	{
		return true;
	}
	
	return false;
}

function CatchOnClick ()
{
	var strName = window.event.srcElement.name + "";
	var strPrefix = strName.substr(0, 3);
	var intStart = strName.indexOf(":");
	var strExcluded = document.forms[0].ExcludedFromDirtyCheck.value;

	// Check to see if the field is excluded	
	if (IsFieldExcluded(strName)) { return; }
	
	// If the user cliked a link and the link is a script
	// then clear the dirty flag, this code needs to be here
	// to support post backs and popup windows
	if (typeof(window.event.srcElement.href) == "string")
	{
		var strHref = window.event.srcElement.href.toLowerCase();
		
		if (strHref.indexOf("javascript") >= 0)
		{
			blnFormSubmit = true;
		}
	}
	
	if (intStart > 0)
	{
		strPrefix = strName.substr(intStart+1, 3);
	}
	
	// See it the control is a text box by checking the profix
	switch (strPrefix)
	{
		case "ddl":
		case "lst":
		case "chk":
		case "rad":
			document.forms[0].DirtyFlag.value = "1";
			break;
			
		default:
			// Do Nothing
			break;
	}
}

function CatchKeyDown ()
{
	var strName = window.event.srcElement.name + "";
	var strPrefix = strName.substr(0, 3);
	var intStart = strName.indexOf(":");

	// Check to see if the field is excluded	
	if (IsFieldExcluded(strName)) { return; }
	
	// Ignore special keys
	switch (window.event.keyCode)
	{
		case 9:		// Tab
		case 33:	// Page Up
		case 34:	// Page Down
		case 35:	// End
		case 36:	// Homw
		case 37:	// Left Arrow
		case 38:	// Up Arrow
		case 39:	// Right Arrow
		case 40:	// Down Arrow
		case 45:	// Insert
		case 112:	// F1
		case 113:	// F2
		case 114:	// F3
		case 115:	// F4
		case 116:	// F5
		case 117:	// F6
		case 118:	// F7
		case 119:	// F8
		case 120:	// F9
		case 121:	// F10
		case 122:	// F11
		case 123:	// F12
			return;
			break;

		default: 
			// DO nothing
			break;
	}
	
	if (intStart > 0)
	{
		strPrefix = strName.substr(intStart+1, 3);
	}

	// See it the control is a text box by checking the profix
	switch (strPrefix)
	{
		case "txt":
		case "ddl":
		case "lst":
		case "chk":
		case "rad":
			blnDirty = true;
			document.forms[0].DirtyFlag.value = "1";
			break;
			
		default:
			// Do Nothing	
	}
}

function CatchOnBeforeUnLoad ()
{
	var eventTarget = document.all("__EVENTTARGET");
	var strTarget;
	
	if (eventTarget == null) { return; }
	
	strTarget = document.all("__EVENTTARGET").value;
	
	if (strTarget.length > 0) { return; }
	
	if (document.forms[0].DirtyFlag.value == "1" && !blnFormSubmit)
	{
		window.event.returnValue = "You have made modifications to this page";
	}
}

function SwapImage(Name)
{
	var i;
	var iImage = -1;
	var img;
	var objImage;
	var strSuffix;
	
	// Get the image object
	if (NS4)
	{
		objImage = document.images[Name];
	}
	else
	{
		if (DOM)
			objImage = document.getElementById(Name);
		else
			objImage = document.all(Name);
	}

	// Get curent image name
	strImage = objImage.src + "";
	strImage = strImage.toLowerCase();
	
	// If the on image is displayed the display the off image
	if (strImage.lastIndexOf("_off.") > 0)
	{
		intStart = strImage.lastIndexOf("_off.");
		strImage = strImage.substr(0, intStart) + "_on." + strImage.substr(intStart + 5)
		strSuffix = "on";
	}
	else if (strImage.lastIndexOf("_on.") > 0)
	{
		intStart = strImage.lastIndexOf("_on.");
		strImage = strImage.substr(0, intStart) + "_off." + strImage.substr(intStart + 4)
		strSuffix = "off";
	}

	objImage.src =  strImage;
	return;
	
	for (i=0;i<arrImages.length;++i)
	{
		if (arrImages[i][0] == Name + strSuffix)
		{
			iImage = i;
		}
	}	

	// The Image has not been loaded then load it
	if (iImage == -1)
	{
		eval("var " + Name + strSuffix + " = new Image();");
		eval(Name + strSuffix + ".src = '" + strImage + "';");
	}

	// Get the image
	var img = eval(Name + Suffix + ".src");

	if (NS4)
	{
		document.images[imgName].src = img;
	}
	else
	{
		if (DOM)
			document.getElementById(imgName).src = img;
		else
			document.all(imgName).src = img;
	}
}

function printWindow()
{	
	if (window.print)
	{
	  window.print();
	}
	else
	{
	  alert("Sorry, your browser cannot print this page.");
	}
}

function checkKey ()
{
  if (window.event.keyCode == 13)
  {
    // kill the keystroke so that nothing happens
    window.event.keyCode = 0;
  }
}

function _GetCookieVal(offset) {
  var endstr = document.cookie.indexOf(";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));  
}

function GetCookie(name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return _GetCookieVal(j);
    i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0)
      break  
  }
  return null;
}

function GetMBACookieMsg() {
  var msg = "Please note that this website uses a cookie to manage your session navigation.\n" + 
            "This cookie is used for management of your current session only and is not used\n" + 
            "for any other purpose. You must allow cookies for this site in order to use the\n" + 
            "features of mba.com.";  
  return msg;          
}

function ShowCareerContent (contentURL, disclaimerURL)
{
	if (contentURL+"" == "-1")
		{ return; }

	var features
	
	features = "";
	features += "toolbar=no,";
	features += "scrollbars=no,";
	features += "height=400,";
	features += "width=650,";
	features += "resizable=yes";

	window.open("../MBASite/Templates/Service/CareerContent/Wcde7297d39a9d.htm" + escape(disclaimerURL) + "&ContentURL=" + escape(contentURL), "CareerContent", features);
}