var browser = navigator.appVersion;
var DOM = (document.getElementById) ? 1 : 0;
var IE = (document.all) ? 1 : 0;
var NS4 = (document.layers) ? 1 : 0;
var NS6 = (document.getElementById && !document.all) ? 1 : 0;
var Mac = ((browser.indexOf("PPC") >0) || (browser.indexOf("Mac") >0));
var MacIE = ((Mac) && (IE));
var bodyWidth = 0;
var bodyHeight = 0;

function getBodyAttributes() {
    if (typeof(window.innerWidth)=='number') {
	    bodyWidth = window.innerWidth;
	    bodyHeight = window.innerHeight;
    } else if ( document.documentElement && document.documentElement.clientWidth ) {
	    bodyWidth = document.documentElement.clientWidth;
	    bodyHeight = document.documentElement.clientHeight;
    }
}

function Print() {
	window.print();
}

function openWindow(url,title,parms) {
	window.open(url,title,parms);
}

function launchCalendar(date,field) {
	calWin = window.open("/Utilities/Calendar.aspx?date="+date+"&field="+field, "Calendar", "resizable=no,status=no,menubar=no,toolbar=no,address=no,history=no,scrollbars=no,width=250,height=190"); 
}

function printFriendly(url) {
	printWin = window.open(url, "Print", "resizable=yes,status=no,menubar=yes,toolbar=no,address=no,history=no,scrollbars=yes,width=750,height=600"); 
}

//----------------------------------------------------------------------
// Utf8ToUnicode
//
// Converts UTF8 string into a Unicode string. Does not decanonicalize.
//
// For example: str "a%20test&&" (where && are UTF-8 chars 0xC3 and 0x81)
// will be decoded as "a%20testn" (where n is an 0xF1 - n with a tilde)
// 
//----------------------------------------------------------------------
function Utf8ToUnicode(strUtf8)
{
	var bstr = "";
	var nTotalChars = strUtf8.length;	// total chars to be processed.
	var nOffset = 0;					// processing point on strUtf8
	var nRemainingBytes = nTotalChars;	// how many bytes left to be converted
	var nOutputPosition = 0;
	var iCode, iCode1, iCode2;			// the value of the unicode.
	
	while (nOffset < nTotalChars)
	{
		iCode = strUtf8.charCodeAt(nOffset);
		if ((iCode & 0x80) == 0)			// 1 byte.
		{
			if ( nRemainingBytes < 1 )		// not enough data
				break;

			bstr += String.fromCharCode(iCode & 0x7F);
			nOffset ++;
			nRemainingBytes -= 1;
		}
		else if ((iCode & 0xE0) == 0xC0)	// 2 bytes
		{
			iCode1 =  strUtf8.charCodeAt(nOffset + 1);
			if ( nRemainingBytes < 2 ||			// not enough data
					(iCode1 & 0xC0) != 0x80 )		// invalid pattern
			{
				break;
			}

			bstr += String.fromCharCode(((iCode & 0x3F) << 6) | (	 iCode1 & 0x3F));
			nOffset += 2;
			nRemainingBytes -= 2;
		}
		else if ((iCode & 0xF0) == 0xE0)	// 3 bytes
		{
			iCode1 =  strUtf8.charCodeAt(nOffset + 1);
			iCode2 =  strUtf8.charCodeAt(nOffset + 2);
			if ( nRemainingBytes < 3 ||			// not enough data
					(iCode1 & 0xC0) != 0x80 ||		// invalid pattern
					(iCode2 & 0xC0) != 0x80 )
			{
				break;
			}

			bstr += String.fromCharCode(((iCode & 0x0F) << 12) | 
					((iCode1 & 0x3F) <<  6) |
					(iCode2 & 0x3F));
			nOffset += 3;
			nRemainingBytes -= 3;
		}
		else								// 4 or more bytes -- unsupported
			break;
	}

	if (nRemainingBytes != 0)
	{
		// bad UTF8 string.
		return "";
	}
	
	return bstr;
}

//Editor Functions

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_nbGroup(event, grpName) { //v3.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : args[i+1];
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    if ((nbArr = document[grpName]) != null)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = args[i+1];
      nbArr[nbArr.length] = img;
  } }
}

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];}}
}

// ********* Update for IE ************* 1/15/08
// Javascript IE Active Object Bound Box Removal (GGL)

try 
{
    window.attachEvent("onload", assistIE);     // perform update after onload
}
catch (e)
{
    // nothing
}
function assistIE()
{
    // Updated code to retain FlashVars (CBM)
    var strBrowser = navigator.userAgent.toLowerCase();
    if(strBrowser.indexOf("msie") > -1 && strBrowser.indexOf("mac") < 0){
        var theObjects = document.getElementsByTagName('object');
        var theObjectsLen = theObjects.length;
        for (var i = 0; i < theObjectsLen; i++) {
            if(theObjects[i].outerHTML){
                if(theObjects[i].data){
                    theObjects[i].removeAttribute('data');    
                }
                var theParams = theObjects[i].getElementsByTagName("param");
                var theParamsLength = theParams.length;
                for (var j = 0; j < theParamsLength; j++) {
                    if(theParams[j].name.toLowerCase() == 'flashvars'){
                        var theFlashVars = theParams[j].value;      
                    }
                }
                var theOuterHTML = theObjects[i].outerHTML;
                var re = /<param name="FlashVars" value="">/ig;
                theOuterHTML = theOuterHTML.replace(re,"<param name='FlashVars' value='" + theFlashVars + "'>");
                theObjects[i].outerHTML = theOuterHTML;
            }
        } 
    }
}

window.onunload = function() {
    if (document.getElementsByTagName) {
        var objs = document.getElementsByTagName("object");
        for (i=0; i<objs.length; i++) {
           objs[i].outerHTML = "";  
         } 
     }
}
// ********* End Update for IE ************* 08/07/08

// ********* Code for Mouseover of Rad Panel ************* 2/13/08
// Allow expand onMouseOver radpane expandable elements (GGL)
var lastSelected = "";

function expand(sender, eventArgs)
{
    try {
    // Check the level of the item for level 1
    if (eventArgs.Item.Level == 1)
    {
        // Root level so expand it
        sender.FindItemByText(eventArgs.Item.Text).Expand();
        
        // verify it isn't the selected tree (page we're on)
        if (sender.FindItemByText(this.lastSelected).Selected != true)
        {
            // collapse the last level (unless it is this one aka repeat)
            if (this.lastSelected != eventArgs.Item.Text)
            {
                sender.FindItemByText(this.lastSelected).Collapse();
            } // end if        
        } // end if
        
    } // end if
   } catch(e) {}
    
} // end expandTimer

function groupOut(sender, eventArgs)
{
    // store last selected root item
    if (eventArgs.Item.Level == 1)
    {
        this.lastSelected = eventArgs.Item.Text;
    } // end if
    
}

function debugObject(myObj)
{
    //display ALL properties of that object for reverse engineering telerek
    for(att in myObj){
        alert(att + " = " + myObj[att]);
    }
}
