jQuery(document).ready(

	/*
	This function gets loaded when all the HTML, not including the portlets, is
	loaded.
	*/

	function() {
	}
);

Liferay.Portlet.ready(

	/*
	This function gets loaded after each and every portlet on the page.

	portletId: the current portlet's id
	jQueryObj: the jQuery wrapped object of the current portlet
	*/

	function(portletId, jQueryObj) {
	}
);

jQuery(document).last(

	/*
	This function gets loaded when everything, including the portlets, is on
	the page.
	*/

	function() {
		jQuery('.lr-hoverhelp').cluetip({
			local: true,
			tracking: true,
			cursor: 'pointer',
			arrows: true,    
			attribute: 'onhelp',
			fx: {	// effect and speed for opening clueTips        
				open: 'fadeIn', // can be 'show' or 'slideDown' or 'fadeIn'
				openSpeed: '250'
	    }
		});
	}
);


/***********************************************
* BEGIN IE/OPERA document.getElementById HACK
***********************************************/		
//use browser sniffing to determine if IE or Opera (ugly, but required)
var isOpera, isIE = false;
if(typeof(window.opera) != 'undefined'){isOpera = true;}
if(!isOpera && navigator.userAgent.indexOf('Internet Explorer')){isIE = true;}

//fix both IE and Opera (adjust when they implement this method properly)
if(isOpera || isIE){
  document.nativeGetElementById = document.getElementById;
  //redefine it!
  document.getElementById = function(id){
    var elem = document.nativeGetElementById(id);
    if(elem){
      //verify it is a valid match!
      if(elem.attributes['id'] && elem.attributes['id'].value == id){
        //valid match!
        return elem;
      } else {
        //not a valid match!
        //the non-standard, document.all array has keys for all name'd, and id'd elements
        //start at one, because we know the first match, is wrong!
        for(var i=1;i<document.all[id].length;i++){
          if(document.all[id][i].attributes['id'] && document.all[id][i].attributes['id'].value == id){
            return document.all[id][i];
          }
        }
      }
    }
    return null;
  };
}
/***********************************************
* END IE/OPERA document.getElementById HACK
***********************************************/	

// JavaScript Document
// open a connection for ajax
var request = null;
function createRequest() {
	try {
		request = new XMLHttpRequest(); // try javascript in non MS IE
	} catch (trymicrosoft) {
		try {
			request = new ActiveXobject("Msxm12.XMLHTTP"); // try javascript in MS IE
		} catch (othermiscrosft) {
			try {
				request = new ActiveXObject("Microsoft.XMLHTTP"); // try javascript in MS IE alternative
			} catch (failed) {
				request = null; // if nothing works, go back to null
			}
		}
	}
	if (request == null) {
		alert("Error creating request object!");
	}
}
// search for first name
function getPages(cntUrl){
	if (cntUrl != '') {
		createRequest();
		var url = cntUrl; // where do I connect?
		request.open("GET",url,true); // connect to my url
		request.onreadystatechange = updatePage_searchFirstName;
		request.send(null); // make the connection and get a response, null means that no data is sent, but data is received
	}
}
// update page with search results
function updatePage_searchFirstName(){
	var possibleNames = null;
	if (request.readyState == 4) {
		var possibleNames = request.responseText;
		if (possibleNames != null) { 
			document.getElementById('mrkContent').innerHTML = possibleNames;
		}
	} else {
		var possibleNames = "<br /><div id=box1><span class=header>Retrieving Data ... </span></div>";
		if (possibleNames != null) { 
			document.getElementById('mrkContent').innerHTML = possibleNames;
		}
	}
}


/***********************************************
* AnyLink Drop Down Menu- © Dynamic Drive (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/		
var menuwidth='165px'; //default menu width
var menubgcolor='396BA7'; //'13436D';  //menu bgcolor
var disappeardelay=250;  //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="no"; //hide menu when user clicks within menu?

/////No further editing needed

var ie4=document.all;
var ns6=document.getElementById&&!document.all;

if (ie4||ns6) {
	document.write('<div id="navMenu" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+';opacity:.85;filter:alpha(opacity=85);" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>');
}

function getposOffset(what, offsettype){
	var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
	var parentEl=what.offsetParent;
	while (parentEl!=null){
		totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
		parentEl=parentEl.offsetParent;
	}
	return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
	if (ie4||ns6)
		dropmenuobj.style.left=dropmenuobj.style.top="-500px";
	if (menuwidth!=""){
		dropmenuobj.widthobj=dropmenuobj.style;
		dropmenuobj.widthobj.width=menuwidth;
	}
	if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
		obj.visibility=visible;
	else if (e.type=="click")
		obj.visibility=hidden;
}

function iecompattest() {
	return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function clearbrowseredge(obj, whichedge){
	var edgeoffset=0
	if (whichedge=="rightedge"){
		var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15;
		dropmenuobj.contentmeasure=dropmenuobj.offsetWidth;
		if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure) {
			edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth;
		}
	} else {
		var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset;
		var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18;
			dropmenuobj.contentmeasure=dropmenuobj.offsetHeight;
		if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
			edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight;
		if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
			edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge;
		}
	}
	return edgeoffset;
}

function populatemenu(what){
	if (ie4||ns6) {
		dropmenuobj.innerHTML=what.join("");
	}
}


function dropdownmenu(obj, e, menucontents, menuwidth){

	if (window.event) event.cancelBubble=true;
	else if (e.stopPropagation) e.stopPropagation()
	clearhidemenu();
	dropmenuobj=document.getElementById? document.getElementById("navMenu") : navMenu;
	populatemenu(menucontents);
	if (ie4||ns6){
		showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth);
		dropmenuobj.x=getposOffset(obj, "left");
		dropmenuobj.y=getposOffset(obj, "top");
		dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px";
		dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px";
	}
	return clickreturnvalue();
}

function clickreturnvalue(){
	if (ie4||ns6) return false;
	else return true;
}

function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
		return true;
	return false;
}

function dynamichide(e){
	if (ie4&&!dropmenuobj.contains(e.toElement))
		delayhidemenu();
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		delayhidemenu();
}

function hidemenu(e){
	if (typeof dropmenuobj!="undefined"){
		if (ie4||ns6)
			dropmenuobj.style.visibility="hidden";
	}
}

function delayhidemenu(){
	if (ie4||ns6)
		delayhide=setTimeout("hidemenu()",disappeardelay);
}

function clearhidemenu(){
	if (typeof delayhide!="undefined")
		clearTimeout(delayhide);
}

if (hidemenu_onclick=="yes")
	document.onclick=hidemenu;
	
/***********************************************
* END AnyLink Drop Down Menu
***********************************************/



/***********************************************
* BEGIN TABS
***********************************************/
var loadstatustext="<p>Requesting Data</p>";

var defaultcontentarray=new Object();

function loadpage(name, containerid, targetobj) {

	if(!name || document.getElementById(name) == null ||  !containerid || document.getElementById(containerid) == null) {
		return;
	}
	
	var ullist=targetobj.parentNode.parentNode.getElementsByTagName("li");
	for (var i=0; i<ullist.length; i++) {
		ullist[i].className="";  //deselect all tabs
	}
	targetobj.parentNode.className = "selected";  //highlight currently clicked on tab
	if (name.indexOf("#default")!=-1) { //if simply show default content within container
		document.getElementById(containerid).innerHTML=defaultcontentarray[containerid];
		return;
	}
	document.getElementById(containerid).innerHTML=loadstatustext;
	
	document.getElementById(containerid).innerHTML = document.getElementById(name).innerHTML;
}


function expandtab(tabcontentid, tabnumber){ //interface for selecting a tab (plus expand corresponding content)
	var thetab=document.getElementById(tabcontentid).getElementsByTagName("a")[tabnumber];
	if (thetab.getAttribute("rel")) {
		loadpage(thetab.getAttribute("name"), thetab.getAttribute("rel"), thetab);
	}
}

function savedefaultcontent(contentid){// save default tab content
	if (typeof defaultcontentarray[contentid]=="undefined" && document.getElementById(contentid) != null) { //if default content hasn't already been saved
		defaultcontentarray[contentid] = document.getElementById(contentid).innerHTML;
	}
}

function startTabs() {

	var _origHref = document.location.href;
	var _baseHref = _origHref;
	var __selected = new Object();

	if(_origHref.indexOf("#") != -1) {
		_baseHref = _origHref.substring(0, _origHref.indexOf("#"));
		__selected.name = _origHref.substring(_origHref.indexOf("#") + 1);
	}
	
	for (var i = 0; i < arguments.length; i++) { //loop through passed UL ids
		
		var ulobj = document.getElementById(arguments[i]);
		var ulist = ulobj.getElementsByTagName("li"); //array containing the LI elements within UL
		
		for (var x = 0; x < ulist.length; x++){ //loop through each LI element
		
			var ulistlink = ulist[x].getElementsByTagName("a")[0];
			
			if (ulistlink.getAttribute("rel")) {
			
				savedefaultcontent(ulistlink.getAttribute("rel")); //save default tab content
			
				ulistlink.onclick = function() {
				
					var _name = this.getAttribute("name");
					if(_name && _name != "undefined") {
						document.location.href = _baseHref + ((_name.substring(0, 1) != "#")?"#":"") + _name;
					} else {
						document.location.href = _baseHref + "#";
					}
					loadpage(_name, this.getAttribute("rel"), this);
					return false;
				}
				if (ulist[x].className=="selected") {
					loadpage(ulistlink.getAttribute("name"), ulistlink.getAttribute("rel"), ulistlink); //auto load currenly selected tab content
				}
			}
			
			if(__selected.name && __selected.name != "undefined" && __selected.name == ulistlink.getAttribute("name")) {
				__selected.href = ulistlink.getAttribute("href");
				__selected.rel = ulistlink.getAttribute("rel");
				__selected.link = ulistlink;
				__selected.preset = true;
			}
			
		}//end loop through each LI element
	} //loop through passed UL ids
	if(__selected.preset) {
		loadpage(__selected.name, __selected.rel, __selected.link) //auto load currenly selected tab content
	}
}
/***********************************************
* END TABS
***********************************************/
