var OnLoadScripts = [];
var scriptCount = 0;

function RunOnLoadScripts()
{	
	for(var i=0;i<OnLoadScripts.length;i++)
	{
		eval(OnLoadScripts[i]);
	}
}

function AddOnLoadScript(s,first)
{
	if(first)
	    OnLoadScripts.unshift(s);
	else
	    OnLoadScripts.push(s); 	
}

function domRollover() {
	if (navigator.userAgent.match(/Opera (\S+)/)) 
	{
		var operaVersion = parseInt(navigator.userAgent.match(/Opera (\S+)/)[1]);
	}
	if (!document.getElementById||operaVersion <7) return;
	
	var imgarr=document.getElementsByTagName('img');
	var imgPreload=new Array();
	var imgSrc=new Array();
	var imgClass=new Array();
	
	for (var i=0;i<imgarr.length;i++){
		if (imgarr[i].className.indexOf('domroll')!=-1)
		{
			imgSrc[i]=imgarr[i].getAttribute('src');
			imgClass[i]=imgarr[i].className;
			imgPreload[i]=new Image();
			if (imgClass[i].match(/domroll (\S+)/)) 
			{
				imgPreload[i].src = imgClass[i].match(/domroll (\S+)/)[1]
			}
			imgarr[i].setAttribute('xsrc', imgSrc[i]);
			imgarr[i].onmouseover=function(){this.setAttribute('src',this.className.match(/domroll (\S+)/)[1])}
			imgarr[i].onmouseout=function(){this.setAttribute('src',this.getAttribute('xsrc'))
			}
		}
	}
}
AddOnLoadScript("domRollover()");

function PanelToggle(panel,sender)
{
	// show requested panel and heading if we need to
	if(panel.style.display == "none")
	{
		panel.style.display = "block";
		sender.className = "head active";
	}
	else
	{
	    panel.style.display = "none";
		sender.className = "head";
	}	
}

function BioToggle(bio,sender)
{
	if(bio.style.display == "none")
	{
		bio.style.display = "block";
		sender.className = "fulllink fullactive";
	}
	else
	{
		bio.style.display = "none";
		sender.className = "fulllink";
	}
}

function SubmitForm(formID)
{
	var form = document.getElementById(formID);	
	if(form != null)
		form.submit();
}

function FilterClick(id,value)
{
	document.getElementById(id).value = value;
	SubmitForm("learnPlanForm");
}

function TopicClick(id)
{
	document.getElementById("topic").value = id;
	SubmitForm("learnPlanForm");
}

function SortSelect(select)
{	
	document.getElementById("sort").value = select.options[select.selectedIndex].value; 
	SubmitForm("learnPlanForm");
}

function RateOverlayToggle(overlay)
{
    var show = true;    
    if(overlay.style.display != "none")
        show = false;
    
    var table = getAncestorByClassName(overlay,"rate_table");    
    var divs = table.getElementsByTagName("div");    
    for(var i=0;i<divs.length;i++)
    {
        if(divs[i].className == "info_overlay_large")
            divs[i].style.display = "none";
    }
    
    if(show)
        overlay.style.display = "block";
    
    if(IEVersion() < 7)
    {
        var header = GetRateOverlayChildDiv(overlay,"info_overlay_header");
        header.className += " overlayHeaderIE6";
        header.style.background = "none";
        
        var mid = GetRateOverlayChildDiv(overlay,"info_overlay_mid");
        mid.className += " overlayMidIE6"; 
        mid.style.background = "none"; 

        var footer = GetRateOverlayChildDiv(overlay,"info_overlay_footer");
        footer.className += " overlayFooterIE6";
        footer.style.background = "none";
    }
}

function GetRateOverlayChildDiv(node,id)
{
   var divs = node.getElementsByTagName("div");
   for(var i=0;i<divs.length;i++)
   {
        if(divs[i].id == id)
            return divs[i];
   }
   
   return null;   
}

function togglePresDesc(obj,desc) {
    if(obj.className == 'subject active')  {
        obj.className = 'subject';
        document.getElementById(desc).style.display = 'none';
    } else {
        obj.className = 'subject active';
        document.getElementById(desc).style.display = 'block';
    }
}

function popup(url,name,width,height,resize,centered)
{		
	var screenHeight = screen.availHeight;
	var screenWidth = screen.availWidth;
	var top = (screenHeight/2) - (height/2);
	var left = (screenWidth/2) - (width/2);
	
	if(resize)
		resize = "yes";
	else
		resize = "no";
	
	var params = "menubar=no,resizable=" + resize + ",width=" + width + ",height=" + height; 
	
	if(centered)
		params += ",top=" + top + ",left=" + left;

	window.open(url,name,params);
}


function getAncestorByClassName(node,cname)
{
    // starts with the provided node and looks up the 
    // DOM tree to get an element with specific CSS class name.
    if(node.tagName != "BODY")
    {
        if(node.className == cname)        
            return node;
        else
            return getAncestorByClassName(node.parentNode,cname);
    }
    
    return null;
}

function getChildByClassName(node,cname)
{
//    for(var i=0;i< node.childNodes.length;i++)
//    {
//        
//        
//        if(node.childNodes[i].
//        if(node.childNodes[i].className == cname)        
//            return node.childNodes[i];
//        else
//            return getDescendantByClassName(node.childNodes[i],cname);
//    }
//    
    for(var cnode=node.firstChild;cnode!=null;cnode=cnode.nextSibling)
    {
        if(cnode.nodeType==1)
        { 
            if(cnode.className == cname)        
                return cnode;
        }
    }
}


function getAncestorByTagName(node,tname)
{
    // starts with the provided node and looks up the 
    // DOM tree to get an element with specific tag name.
    if(node.tagName != "BODY")
    {
        if(node.tagName == tname)        
            return node;
        else
            return getAncestorByClassName(node.parentNode,tname);
    }
    
    return null;
}

//var nn = null;
//function initPasswordField(input)
//{
//    if(input.value == "Password")
//    {
//        input.value = "";
//        nn = input.cloneNode(true); 
//        nn.type = "password"; 
//        input.parentNode.replaceChild(nn,input); 
//        setTimeout("nn.focus()", 100);

//    }
//}

function JoinNowClick()
{
    if(document.getElementById("agree").checked)
    {
        window.open("https://umnas3.umonitor.com/becu/welcome.do");
    }
    else
    {
        alert("Please indicate your acceptance of the Electronic Communications Disclosure to begin application.");
    }
}

function setFeedbackField(textarea)
{
    if(textarea.value == "Please type your comments/questions here.")
        textarea.value = "";
}

function launchSurvey()
{
	//Opens survey overlay
	var cookie = readCookie('becusurvey');
	var url = document.location.search;
	var qs = url.substring(url.indexOf('?')+1);
	var randomnumber=Math.floor(Math.random()*101);
	
	//If we want to limit this survey to just members (via OLB) remove the comments.
	//Otherwise, comment out the if statement below
	if (cookie != null && cookie != "")
	{
	}
	else
	{
	    if (qs == 'var=olb')
	    {
	    //    if (randomnumber<=30)
	    //    {
	            SetCookie('becusurvey','yes');
	            zBox_GetBox('survey').Show();;return false;
	    //    }
	    }
	}
}

function choosePanel()
{
    var cookie = readCookie('becuhome');

	if (cookie != null && cookie != "")
	{
	    if (cookie == '1')
	    {
	        SetCookie('becuhome','2');
            return 1;
	    }
	    if (cookie == '2')
	    {
	        SetCookie('becuhome','3');
            return 2;
	    }
	    if (cookie == '3')
	    {
	        SetCookie('becuhome','1');
            return 0;
	    }
	}
	else
	{
	    SetCookie('becuhome','1');
	    return 0;
	}
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    
    for (var i = 0; i < ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') c = c.substring(1, c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
    }
    return null;
}

function SetCookie(sName, sValue)
{
  // Expires the cookie in one month
  var date = new Date();
  date.setMonth(date.getMonth()+1);
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + date.toGMTString();
}


