﻿function newGuid()
{
    var g = "";
    for(var i = 0; i < 32; i++)
    g += Math.floor(Math.random() * 0xF).toString(0xF) + (i == 8 || i == 12 || i == 16 || i == 20 ? "-" : "");
    return g;
}

function openCenteredWindow(url, height, width, name, parms) 
{
   //If the name of the new window is 'newWin', then generate
   //a unique ID for it.  This enables us to open multiple windows
   //for the content instead of reusing the same window
   if (name == 'newWin')
   {
     name = newGuid();
     name = name.split('-')[0];
   }
     
   if (height <= 1) { height = Math.floor(screen.height * height); }
   if (width <= 1) { width = Math.floor(screen.width * width); }
   
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}
     
/* BEGIN Toolbar Methods */
function mladdevents(){
	if(!window.mlrunShim){
		window.mlrunShim = false;
	}
	if(window.mlrunShim == true){
		var Iframe = document.createElement("iframe");
		Iframe.setAttribute("src","about:blank");
		Iframe.setAttribute("scrolling","no");
		Iframe.setAttribute("frameBorder","0");
	}
	var effects_a = new Array();
	var divs = document.getElementsByTagName('div');
	for(var j=0;j<divs.length;j++){
		if(divs[j].className.indexOf('slidetabsmenu') != -1){
			divs[j].className = divs[j].className.replace('slidetabsmenu','slidetabsmenujs');
			divs[j].getElementsByTagName('ul')[0].className = divs[j].className;//just for reference
			var lis = divs[j].getElementsByTagName('li');
			for(var i =0;i<lis.length;i++){
				lis[i].onmouseover = mlover;
				lis[i].onmouseout = mloutSetTimeout;
				if(window.mlrunShim == true){
					lis[i].appendChild(Iframe.cloneNode(false));
				}
				if(lis[i].parentNode.getElementsByTagName('li')[0] == lis[i]){
					lis[i].getElementsByTagName('a')[0].className += 'first';
					if(lis[i].parentNode.className.indexOf('slidetabsmenujs') != -1){
						lis[i].className += 'pixelfix';
					}
				}
				if(lis[i] == findLast(lis[i].parentNode)){
					lis[i].className += 'last';
				}
				if(lis[i].getElementsByTagName('ul').length > 0){
					lis[i].className += ' haschild';
					if(divs[j].className.indexOf('arrow') != -1){
						if(divs[j].className.indexOf('vertical') != -1 || lis[i].parentNode.parentNode.nodeName != 'DIV'){
							lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="vert">&rarr;</span>';
						}
						else{
							lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="horiz">&darr;</span>';
						}
					}
					else if(divs[j].className.indexOf('plus') != -1){
						lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="plus">+</span>';
					}
				}
				else{
					if(divs[j].className.indexOf('arrow') != -1){
						//This accounts for a wierd IE-specific bug in horizontal menus. CSS will set visibility: hidden;. This keeps the menu level(in IE)
						lis[i].getElementsByTagName('a')[0].innerHTML += '<span class="noshow">&darr;</span>';
					}
				}
				var uls = lis[i].getElementsByTagName('ul');
				for(var k=0;k<uls.length;k++){
					var found = 'no';
					for(var z=0;z<effects_a.length;z++){
						if(effects_a[z] == uls[k]){
							found = 'yes';
						}
					}
					if(found == 'no'){
						effects_a[effects_a.length] = uls[k];
						uls[k].style.zIndex = '100';
						mlEffectLoad(uls[k]);
					}
				}
			}
		}
	}
}
function mloutSetTimeout(e){
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.toElement;
	if(reltg){
		var under = ancestor(reltg,this);
		if(under === false && reltg != this){
			window.mlLast = this;
			var parent = this.parentNode;
			while(parent.parentNode && parent.className.indexOf('slidetabsmenujs') == -1){
				parent = parent.parentNode;
			}
			if(parent.className.indexOf('delay') != -1){
				window.mlTimeout = setTimeout(function(){mlout()},600);
			}
			else{
				mlout();
			}
		}
	}
}
function mlout(){
	if(window.mlLast==null)return false;
	var links = window.mlLast.getElementsByTagName('a');
	for(var i = 0;i<links.length;i++){
		links[i].className = links[i].className.replace('hover','');
	}
	var uls = window.mlLast.getElementsByTagName('ul');
	var sib;
	for(var i=0;i<uls.length;i++){
		mlEffectOut(uls[i]);
		window.mlLast.className += ' hide';
		window.mlLast.className = window.mlLast.className.replace('hide hide','hide');
		if(window.mlrunShim == true){
			sib = uls[i];							
			while(sib.nextSibling && sib.nodeName != 'IFRAME'){
				sib = sib.nextSibling
			}
			sib.style.display = 'none';
		}
	}
	window.lastover = null;
	return true;
}
function mlover(e){
	if(!e){
		var the_e = window.event;
	}
	else{
		var the_e = e;
	}
	the_e.cancelBubble = true;
	if(the_e.stopPropagation){
		the_e.stopPropagation();
	}
	clearTimeout(window.mlTimeout);
	if(window.mlLast && window.mlLast != this && ancestor(this,window.mlLast) === false){
		mlout();
	}
	else{
		window.mlLast = null;
	}
	var reltg = (the_e.relatedTarget) ? the_e.relatedTarget : the_e.fromElement;
	var under = ancestor(reltg,this);
	if(under == false){
		var hovered = byClass(this.parentNode,'hover','a');
		for(var i=0;i<hovered.length;i++){
			if(ancestor(this,hovered[i].parentNode) == false){
				window.mlLast = hovered[i].parentNode;
				mlout();
			}
		}
		var ob = this.getElementsByTagName('ul');
		var link = this.getElementsByTagName('a')[0];
		link.className += ' hover';
		if(ob[0]){
			if(window.lastover != ob[0]){
				if(window.mlrunShim == true){
					var sib = ob[0];
					while(sib.nextSibling && sib.nodeName != 'IFRAME'){
						sib = sib.nextSibling
					}
					ob[0].style.display = 'block';
					sib.style.top = ob[0].offsetTop+'px';
					sib.style.left = ob[0].offsetLeft-2+'px';
					sib.style.width = ob[0].offsetWidth+2+'px';
					sib.style.height = ob[0].offsetHeight-2+'px';
					sib.style.display = 'block';
				}
				this.className = this.className.replace(/hide/g,'');
				mlEffectOver(ob[0],this);
				window.lastover = ob[0];
			}
		}
	}
}
function mlSetOpacity(ob,level){
	if(ob){
		var standard = level/10;
		var ie = level*10;
		ob.style.opacity = standard;
		ob.style.filter = "alpha(opacity="+ie+")"
	}
}
function mlIncreaseOpacity(ob){
	var current = ob.style.opacity;
	current = current * 10;
	var upone = current + 1;
	mlSetOpacity(ob,upone);
}
function mlIncreaseHeight(ob){
	var current = parseInt(ob.style.height);
	if(!isNaN(current)){
		var newh = current + 1;
		ob.style.height = newh+'px';
	}
}
function mlIncreaseWidth(ob){
	var current = parseInt(ob.style.width);
	if(!isNaN(current)){
		var newh = current + 1;
		ob.style.width = newh+'px';
	}
}
function mlShake(ob){
	var newp = '5px';
	var old = '';
	if(ob.style.paddingLeft==old){
		ob.style.paddingLeft=newp;
	}
	else{
		ob.style.paddingLeft=old;
	}
}
function mlEffectOver(ob,parent){
	switch(ob.className){
	case 'fade':
		ob.style.display = 'block';
		for(var i = 1;i<=10;i++){
			window.fadeTime = setTimeout(function(){mlIncreaseOpacity(ob)},i*50);
		}
		setTimeout(function(){ob.style.filter = ''},500);
		break;
	case 'shake':
		ob.style.display = 'block';
		var shake = setInterval(function(){mlShake(ob)},50);
		setTimeout(function(){clearInterval(shake)},510);
		break;
	case 'blindv':
		ob.style.display = 'block';
		if(ob.offsetHeight){
			var height = ob.offsetHeight
			ob.style.height = '0px';
			ob.style.overflow = 'hidden';
			for(var i=0;i<height;i++){
				setTimeout(function(){mlIncreaseHeight(ob)},i*3);
			}
			setTimeout(function(){ob.style.overflow='';ob.style.height='auto'},(height-1)*3)//-1 for IE
		}
		break;
	case 'blindh':
		ob.style.display = 'block';
		if(ob.offsetWidth){
			var width = ob.offsetWidth;
			ob.style.width = '0px';
			ob.style.overflow = 'hidden';
			for(var i=0;i<width;i++){
				setTimeout(function(){mlIncreaseWidth(ob)},i*3);
			}
			setTimeout(function(){ob.style.overflow='visible';},width*3)
		}
		break;
	default:
		ob.style.display = 'block';
		break;
	}
}
function mlEffectOut(ob){
	switch(ob.className){
	case 'fade':
		clearTimeout(window.fadeTime);
		mlSetOpacity(ob,0);
		ob.style.display = 'none';
		break;
	case 'shake':
		ob.style.paddingLeft = '';
		ob.style.display = 'none';
		break;
	default:
		ob.style.display = 'none';
		break;
	}
}
function mlEffectLoad(ob){
	var parent = ob.parentNode;
	while(parent.parentNode && parent.className.indexOf('slidetabsmenu') == -1){
		parent = parent.parentNode;
	}
	if(parent.className.indexOf('fade') != -1){
		ob.style.display = 'none';
		ob.className = 'fade';
		mlSetOpacity(ob,0);
	}
	else if(parent.className.indexOf('shake') != -1){
		ob.className = 'shake';
	}
	else if(parent.className.indexOf('blindv') != -1){
		ob.className = 'blindv';
	}
	else if(parent.className.indexOf('blindh') != -1){
		ob.className = 'blindh';
	}
	else if(parent.className.indexOf('box') != -1){
		ob.className = 'box';
	}
	ob.style.display = 'none';
}
function ancestor(child, parent){
	try{
		if(child==null)return false;//Saves checking elsewhere
		for(; child.parentNode; child = child.parentNode){
				if(child.parentNode === parent) return true;
			}
		return false;
	}
	catch(error){
		//Mozilla bug, it  must be a text control which can not be in the menu so we will foolishly assume false
		return false;
	}
}
function byClass(parent,c,tag){
	var all = parent.getElementsByTagName(tag);
	var returna = new Array();
	for(var i=0;i<all.length;i++){
		if(all[i].className.indexOf(c) != -1){
			returna[returna.length] = all[i]
		}
	}
	return returna;
}
function findLast(ob){
	if(ob.lastChild.nodeType == 1){
		return ob.lastChild
	}
	return ob.lastChild.previousSibling;
}
/* END Toolbar Methods */

/* BEGIN IFrame adjust height */
function getElement(aID)
{
    return (document.getElementById) ?
        document.getElementById(aID) : document.all[aID];
}

function getIFrameDocument(aID){ 
    var rv = null; 
    var frame=getElement(aID);
    // if contentDocument exists, W3C compliant (e.g. Mozilla) 
    if (frame.contentDocument)
        rv = frame.contentDocument;
    else // bad IE  ;)
    {
        rv = document.frames[aID].document;
    }
    return rv;
}

function adjustMyFrameHeight(sFrameID)
{
    var frame = getElement(sFrameID);
    var frameDoc = getIFrameDocument(sFrameID);
    frame.height = frameDoc.body.offsetHeight;
}
/* END IFrame adjust height */

//Highlight selected links in Right NAV
/*<![CDATA[*/
var Lst;

function CngClass(obj){
 if (Lst) 
 {
	Lst.className='';
	Lst.onmouseout=null; //Remove the mouseover event handler
 }
 
 //If this is an image, get the related item
 if (obj.tagName.toLowerCase() == 'img')
 {
	var sItemID = obj.id;
	sItemID = "item" + sItemID.substring(3,sItemID.length);
	obj = document.getElementById(sItemID);
 }
 
 if (obj)
 {
	 //Remove the focus border around the link
	 obj.onmouseout=function(){document.getElementsByTagName('body')[0].focus();}
	 
	 //Set the selected class
	 obj.className='treemainlinkSelectedLink';
	 
	 //Save this link as our Last-Clicked link
	 Lst=obj;
 }
}

/*]]>*/

//Hides any treenodes which are empty
function finalizeDocumentTree(totalFolders)
{
	var group = null;
	for (var i=0; i < totalFolders; i++)
	{
		group = document.getElementById('lit_group' + i);
		if (group != null)
		{
			if (group.childNodes.length == 0)
			{
				var folder = document.getElementById('lit_folder' + i);
				if (folder != null)
					folder.style.display = 'none';
			}
		}
		
	}
}

//Hides any treenodes which are empty and opens the remaining ones
function finalizeDocumentTreeOpen(totalFolders)
{
	var group = null;
	for (var i=0; i < totalFolders; i++)
	{
		group = document.getElementById('lit_group' + i);
		if (group != null)
		{
			showHide('lit_group' + i,'lit_icon_' + i,'lit_menuitem' + i,'plus');
			if (group.childNodes.length == 0)
			{
				var folder = document.getElementById('lit_folder' + i);
				if (folder != null)
					folder.style.display = 'none';
			}
		}
		
	}
}

//Hides all executive bios and shows only the selected exec bio
function showHideExecs(execID, iTotalExecs)
{
	for(var i=0; i<iTotalExecs; i++)
	{
		var oExec = document.getElementById("exec" +  i);
		
		if (oExec !== null)
		{
			if (i == execID)
				oExec.style.display = '';
			else
				oExec.style.display = 'none';
		}
	}
}

//Giving this function a different name so it doesn't look weird when used in the another section
function showHideDiv(divID, iTotalDivs)
{
	showHideExecs(divID, iTotalDivs);
}

//Renders a Flash Object/Embed control
function CreateFlashControl(DivID, CLSID, ObjectID, WIDTH, HEIGHT, URL, align, allowScriptAccess, quality, scale, wmode, bgcolor, altImgURL)
{
	var b = document.getElementById(DivID);
	var d = "<OBJECT CLASSID=\"" + CLSID + "\""; 
	d += "align=\"" + align + "\"";
	d += "WIDTH=\"" + WIDTH + "\" HEIGHT=\"" + HEIGHT + "\" NAME=\"" + ObjectID + "\" ID=\"" + ObjectID + "\">";
	d += "<PARAM NAME=\"Movie\" VALUE=\"" + URL + "\">";
	d += "<PARAM NAME=\"allowScriptAccess\" VALUE=\"" + allowScriptAccess + "\" />";
	d += "<PARAM NAME=\"quality\" VALUE=\"" + quality + "\" />";
	d += "<PARAM NAME=\"scale\" VALUE=\"" + scale + "\" />";
	d += "<PARAM NAME=\"wmode\" VALUE=\"" + wmode + "\" />";
	d += "<PARAM NAME=\"bgcolor\" VALUE=\"" + bgcolor + "\" />";

	//If this browser understands the mimeTypes property and recognizes the MIME Type //\"application/x-shockwave-flash\"...
	if (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"])
		d += "<EMBED src=\"" + URL + "\" quality=\"" + quality + "\" scale=\"" + scale + "\" wmode=\"" + wmode + "\" bgcolor=\"" + bgcolor + "\" width=\"" + WIDTH + "\" height=\"" + HEIGHT + "\" name=\"" + ObjectID + "\" align=\"" + align + "\" allowScriptAccess=\"" + allowScriptAccess + "\" type=\"application/x-shockwave-flash\" />";
	else
		d +=  "<img src=\"" + altImgURL + "\" width=\"" + WIDTH + "\" height=\"" + HEIGHT + "\" alt=\"\" />";
	
	d+= "</OBJECT>";

	//create a stub DIV to hold the HTML we generated.  Append this element to our primary DIV tag
	var x = document.createElement('div');
	x.setAttribute('id', 'mydiv');
	x.innerHTML = d;
	
	b.appendChild(x);
}

// Used for the web part tree menu. Expands/collapses tree nodes
// || By Perry Molendijk - &Acirc;&copy;2002 Inflexions (WA) Pty Ltd ||
function showHide(divId, iconId, linkId, listType) {    
	// get the 'div' element you want to show or hide.
	var showHideDiv = document.getElementById(divId);

	// get the +/- icon associate with current group.
	var iconTag = document.getElementById(iconId);
	
	// get the link tag that was clicked.
	var currentLink = document.getElementById(linkId);
	
	// var to hold source for the plus and minus icons.
	var iconSrc = '/_layouts/images/spacer.jpg';
	
	// var to hold string used for alt and title attributes.
	var altTitleText = '';
	if (listType == 'plus'){
		if(showHideDiv.style.display == '')  {
			showHideDiv.style.display = 'none';
			iconSrc = '/_layouts/images/icon_plus.gif';
			altTitleText = 'Click to expand';
		}
		else  {
			showHideDiv.style.display = '';
			iconSrc = '/_layouts/images/icon_minus.gif';
			altTitleText = 'Click to minimise';
		}
	}	
	else if (listType == 'arrow'){
		if(showHideDiv.style.display == '')  {
			showHideDiv.style.display = 'none';
			iconSrc = '/_layouts/images/icon_arrow_off.gif';
			altTitleText = 'Click to expand';
		}
		else  {
			showHideDiv.style.display = '';
			iconSrc = '/_layouts/images/icon_arrow_on.gif';
			altTitleText = 'Click to minimise';
		}
	}	
	iconTag.setAttribute("src",iconSrc);
	iconTag.setAttribute("alt",altTitleText);
	iconTag.setAttribute("title",altTitleText);
	currentLink.setAttribute("title",altTitleText);
}
