var browser = 3;
	if (document.all) browser = 1;	
	//if (!document.all) browser = 3;	

/*
if (browser != 1) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
*/


function $$(id)
{
	return document.getElementById(id);
}


// Set Netscape up to run the "captureMousePosition" function whenever
// the mouse is moved. For Internet Explorer and Netscape 6, you can capture
// the movement a little easier.
if (document.layers) { // Netscape
    document.captureEvents(Event.MOUSEMOVE);
    document.onmousemove = captureMousePosition;
} else if (document.all) { // Internet Explorer
    document.onmousemove = captureMousePosition;
} else if (document.getElementById) { // Netcsape 6
    document.onmousemove = captureMousePosition;
}
// Global variables
MouseX = 0; // Horizontal position of the mouse on the screen
MouseY = 0; // Vertical position of the mouse on the screen
MouseXMax = 0; // Width of the page
MouseYMax = 0; // Height of the page
ScrollX = 0;
ScrollY = 0;

function captureMousePosition(e) {

try {
    if (document.layers) {
        MouseX = e.pageX;
        MouseY = e.pageY;
        MouseXMax = window.innerWidth+window.pageXOffset;
        MouseYMax = window.innerHeight+window.pageYOffset;
    } else if (document.all) {
    
    //IE 6 "bug" - document.body values fall into document.documentElement for certain docTypes

        MouseX = document.body.scrollLeft;
        
        if (document.documentElement.scrollLeft)
        {
            MouseX = document.documentElement.scrollLeft;
        } else {
            MouseX = document.body.scrollLeft;
        }
        ScrollX = MouseX;
        MouseX += window.event.x;
        
        
        if (document.documentElement.scrollTop)
        {
            MouseY = document.documentElement.scrollTop;
            
        } else {
            MouseY = document.body.scrollTop;
        }        
        ScrollY = MouseY;
	if (window.event.y < document.height) MouseY += window.event.y; else MouseY = window.event.y;
        
        
        MouseYMax = document.body.clientHeight + ScrollY;
        MouseXMax = document.body.clientWidth + ScrollX;
        
    } else if (document.getElementById) {
        // Netscape 6 behaves the same as Netscape 4 in this regard
        MouseX = e.pageX;
        MouseY = e.pageY;
        MouseXMax = window.innerWidth+window.pageXOffset;
        MouseYMax = window.innerHeight+window.pageYOffset;
    }
    
    } catch (e) { }
    //window.status = "xMousePos=" + MouseX + ", yMousePos=" + MouseY + ", xMousePosMax=" + MouseXMax + ", yMousePosMax=" + MouseYMax;
}






function ShowHideObject(id, display)
{
	GetObj(id).style.display = display;
}

function GetObj(id)
{
	switch(browser)
	{
		case 0:
		case 1:
			return document.all[id];
		break;
		case 2:
			return document[id];
		break;
		case 3:
			return document.getElementById(id);
		break;
	}
}


function ShowHideObject(id, visible)
{
	var obj = GetObj(id);
	if (visible)
	{
		obj.style.display = "inline";
	} else {
		obj.style.display = "none";
	}
}




function ParentGetObj(id)
{
	switch(browser)
	{
		case 0:
		case 1:
			return window.opener.document.all[id];
		break;
		case 2:
			return window.opener.document[id];
		break;
		case 3:
			return window.opener.document.getElementById(id);
		break;
	}
}


function ConfirmNew(id, name, callback)
{
    PopupMessage("Create Confirmation", "Are you sure you want to create a new '" + name + "' entry?</p><p class=\"left\"><a href=\"javascript:HideMessage();" + callback + "(" + id + ");\" title=\"Yes\">Yes</a></p><p class\"right\"><a href=\"javascript:HideMessage();\" title=\"Cancel\">Cancel</a>");
}

function ConfirmDelete(id, name, callback)
{
    if (isNaN(id)) id = "'" + id + "'";

    PopupMessage("Delete Confirmation", "Are you sure you want to delete '" + name + "'?</p><p class=\"left\"><a href=\"javascript:HideMessage();" + callback + "(" + id + ");\" title=\"Yes\">Yes</a></p><p class\"right\"><a href=\"javascript:HideMessage();\" title=\"Cancel\">Cancel</a>");
}

function ConfirmDuplicate(id, name, callback)
{
    PopupMessage("Duplicate Confirmation", "Are you sure you want to duplicate '" + name + "'?</p><p class=\"left\"><a href=\"javascript:HideMessage();" + callback + "(" + id + ");\" title=\"Yes\">Yes</a></p><p class\"right\"><a href=\"javascript:HideMessage();\" title=\"Cancel\">Cancel</a>");
}


function PopupMessage(title,text, x, y)
{   
    if (!x) x = MouseX;
    if (!y) y = MouseY;
    
    obj = GetObj("PopupMessage");
    
    var width = parseInt(obj.style.width) + 30;
    if (x + width > MouseXMax) x = MouseXMax - width;
    
    obj.innerHTML = "<h1>" + title + "</h1><p>" + text + "</p>";
    obj.style.left = x + "px";
    obj.style.top = y + "px";
    obj.style.display = "block";
}
function HideMessage()
{
    GetObj("PopupMessage").style.display = "none";
}

function ReplaceEx(source, find, replace)
{
    eval("var ret = source.replace(/" + find + "/g, replace);");
    return ret;
}

function ReplaceExLiteral(source, find, replace)
{
    find = RegExEscape(find);
    
    eval("var ret = source.replace(/" + find + "/g, replace);");
    return ret;
}


function RegExEscape(s) { return s.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1') }



function QuoteText(name)
{
    var text = ReplaceExLiteral(name, "\"", "&gt;");
    //text = RegExReplaceLiteral(text, "'", "\\'")
    return text;
}




function Pause(res, callback)
{
    if (res == 0)
    {
        eval(callback);
        return;
    }
    setTimeout("Pause(0,\"" + callback + "\");", res);
}









function PopupModalWindow(url,width,height,resize,params,name)
{	
	if (name == null) name = "EditWinModal";
	
	screenx = screen.availWidth;
	screeny = screen.availHeight;
	x = null;
	y = null;
	if (width != null)
	{
	    if (width < 1) width = screenx * width;
	    x = (screenx / 2) - (width / 2);
	}
	if (height != null)
	{
	    if (height < 1) height = screeny * height;
	    y = (screeny / 2) - (height / 2);
	}
	
	if (width != null) width = ";dialogWidth:" + Math.round(width);
	if (height != null) height = ";dialogHeight:" + Math.round(height);
	if (resize == null) resize = "yes";
	
	if (x != null) x = ";screenX:" +  Math.round(x) + ";dialogLeft:" + Math.round(x);
	if (y != null) y = ";screenY:" + Math.round(y) + ";dialogTop:" + Math.round(y);

//Create window
	var ret = showModalDialog(url,params,"scrollbars:yes;dependant:yes" + width + height + x + y + ";center:yes;resizable:" + resize);

	return ret;	
}





function PopupWindow(url,width,height,resize,params, name)
{	
	if (name == null) name = "EditWin";
	
	screenx = screen.availWidth;
	screeny = screen.availHeight;
	x = null;
	y = null;
	if (width != null)
	{
	    if (width < 1) width = screenx * width;
	    x = (screenx / 2) - (width / 2);
	}
	if (height != null)
	{
	    if (height < 1) height = screeny * height;
	    y = (screeny / 2) - (height / 2);
	}
	
	if (width != null) width = ",width=" + Math.round(width);
	if (height != null) height = ",height=" + Math.round(height);
	if (resize == null) resize = "yes";
	
	if (x != null) x = ",screenX=" +  Math.round(x) + ",Left=" + Math.round(x);
	if (y != null) y = ",screenY=" + Math.round(y) + ",Top=" + Math.round(y);

//Set parameters
    lparams = new Object();
	if (params != null)
	{
    	aparams = params.split(";");
	    for (i = 0; i < aparams.length; i++)
    	{
	        sparams = aparams[i].split("=");
	        lparams[sparams[0]] = sparams[1];
    	}
    }
    
    //alert("scrollbars=yes,dependant=yes" + width + height + x + y + ",centerscreen=yes,resizable=" + resize);

//Create window
	editWin = window.open(url,name,"scrollbars=yes,dependant=yes" + width + height + x + y + ",centerscreen=yes,resizable=" + resize);
	if (!editWin)
	{
	    alert("Your browser has blocked a popup. Please configure your browser to allow popups on this Website.");
	    return;
	} else {
	    //editWin.focus();
	}
	
	try {
	    editWin.params = lparams	
	} catch (e) {}
}










function PopupHelpTip(index)
{
    if (SimpleGetCookie("PreferenceShowTips") == "no") return;
    
    PopupWindow("../Master/HelpTips.aspx?id=" + index, 500, 400, null, null, "CMSTips");
}

















function GetAllChecked(root)
{
	var navRoot = GetObj(root);
	var chk = ChildGetAllChecked(navRoot);
	
	if (chk.length > 0) chk = chk.substring(0, chk.length - 1);
	
	return chk;
}
function ChildGetAllChecked(navRoot)
{	
	var chk = "";
	
	for (var i=0; i<navRoot.childNodes.length; i++)
	{
		var node = navRoot.childNodes[i];
		
		switch (node.nodeName)
	    {
	        case "INPUT":
	            try {
	                if (node.checked)
	                {
	                    chk += node.value + ",";
	                }
	            } catch (e) { }
	        break;
	        case "P":
	        case "DIV":
	        case "TABLE":
	        case "TD":
	        case "TR":
	        case "TBODY":
	            chk += ChildGetAllChecked(node);
	        break;
	    }
	}
	return chk;
}






function CheckAll(root,value)
{
	navRoot = GetObj(root);
	ChildCheckAll(navRoot, value);
}
function ChildCheckAll(navRoot,value)
{	
	for (var i=0; i<navRoot.childNodes.length; i++)
	{
		var node = navRoot.childNodes[i];
		
		switch (node.nodeName)
	    {
	        case "INPUT":
	            try {
	                node.checked = value;
	            } catch (e) { }
	        break;
	        case "P":
	        case "DIV":
	        case "TABLE":
	        case "TD":
	        case "TR":
	        case "TBODY":
	            ChildCheckAll(node, value);
	        break;
	    }
	}
}










/*--------------------------------------------------------------------------*/
/*  Cookie Functions */
/*--------------------------------------------------------------------------*/
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
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 SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

function SimpleSetCookie(key, value)
{
	var expdate = new Date ();
	FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
	expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000));
		SetCookie(key, value, expdate);		
	return true;
}
function SimpleGetCookie(key)
{
	return GetCookie(key);
}





function BreakoutFrames(child)
{
    return;
    eval("var exists = parent." + child);
    if (exists)
    {
        parent.document.location.href = document.location.href;
    }
}




//SetCookie ("ccpath", "http://www.hidaho.com/colorcenter/", expdate);
//SetCookie ("ccname", "hIdaho Design ColorCenter", expdate);
//SetCookie ("tempvar", "This is a temporary cookie.");
//SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
//SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
//SetCookie ("goner", "This cookie must die!");
//document.write (document.cookie + "<br>");
//DeleteCookie ("goner");
//document.write (document.cookie + "<br>");
//document.write ("ccpath = " + GetCookie("ccpath") + "<br>");
//document.write ("ccname = " + GetCookie("ccname") + "<br>");
//document.write ("tempvar = " + GetCookie("tempvar") + "<br>");









//Used for executing newly updated AJAX ASP.NET HTML Dumps

function execJS(node)
{
  var bSaf = (navigator.userAgent.indexOf('Safari') != -1);
  var bOpera = (navigator.userAgent.indexOf('Opera') != -1);
  var bMoz = (navigator.appName == 'Netscape');

  if (!node) return;

  /* IE wants it uppercase */
  var st = node.getElementsByTagName('SCRIPT');
  var strExec;

  for(var i=0;i<st.length; i++)
  {
    strExec = null;
  
    if (bSaf) {
      strExec = st[i].innerHTML;
      st[i].innerHTML = "";
    } else if (bOpera) {
      strExec = st[i].text;
      st[i].text = "";
    } else if (bMoz) {
      strExec = st[i].textContent;
      st[i].textContent = "";
    } else {
      strExec = st[i].text;
      st[i].text = "";
    }


      var x = document.createElement("script");
      x.type = "text/javascript";
   
    if (strExec != null && strExec != "")
    {
    //try {
    
      // In IE we must use .text!
      if ((bSaf) || (bOpera) || (bMoz))
        x.innerHTML = strExec;
      else x.text = strExec;
    
      
      if (strExec.indexOf("<!--") != -1 && strExec.indexOf("__doPostBack") != -1)
      {
        //NB: Ignore ASP.NET Javascript
      }
      else
      {
        var heads = document.getElementsByTagName("head");
        if (heads.length > 0 && x) heads[0].appendChild(x);  
      
    //} catch(e) { }
      }
    
    } else {
        //x.src = st[i].src;
    }
    
    
  }
};




