var invisibleClass = 'invisible';
var visibleClass = 'visible';
var forcedRefresh = true;
var alreadyopen = new Array();
var newwin = new Array();

function setClassname(id, classname) {
	if($get(id))
	{
	    document.getElementById(id).className = classname;
	}
}

function getClassname(id) {
	if($get(id))
	{
	    return document.getElementById(id).className;
	}
}

function replaceClassname(id, find, replace) {
    if($get(id))
    {
        setClassname(id, getClassname(id).replace(new RegExp(find), replace));
    }
}

function showHideLayer(currentTab, newTab) {
  replaceClassname(currentTab, visibleClass, invisibleClass);
  replaceClassname(newTab, invisibleClass, visibleClass);
}

function showLayer(currentTab, newTab) {
	replaceClassname(newTab, invisibleClass, visibleClass);
}

function hideLayer(currentTab, newTab){
	replaceClassname(currentTab, visibleClass, invisibleClass);
}

var tier1 = null;
var tier2 = null;

function openNav(id, tier) {
	tier = tier == null ? 1 : tier;
	if(tier == 1) {
		if(id != tier1) {
			if(tier1 != null) setClassname(tier1, invisibleClass);
			if(tier2 != null) setClassname(tier2, invisibleClass);
			setClassname(id, visibleClass);
			tier1 = id;
			tier2 = null;
		}
		else {
			setClassname(id, invisibleClass);
			tier1 = null;
		}
	}
	else if(tier == 2) {
		if(tier2 != id) {
		
			if(tier2 != null) setClassname(tier2, invisibleClass);
			setClassname(id, visibleClass);
			tier2 = id;
		
		}
		else {
			setClassname(id, invisibleClass);
			tier2 = null;
		}
	}
}

/* show hide drop down menus */

var old_menu = null, hide = null;
function hide_menu(id){
	if(id == null) return;
	obj = document.getElementById('dropnav-' + id);
	if(obj) obj.style.visibility = 'hidden';
	clear_timeout();
}

function show_menu(id){
	
	obj = document.getElementById('dropnav-' + id);

	if(obj){
		if(obj.style.visibility == 'visible')
		{
			obj.style.visibility = 'hidden'
		}
		else
		{
			obj.style.visibility = 'visible';
		    obj.className = 'campus_programs_campus_list';		
		}
	}
}

function set_timeout(){
	hide = setTimeout("hide_menu('" + old_menu + "')",700);
}

function clear_timeout(){
	clearTimeout(hide);
}

function maintainprogrammenu(selectedId)
{
	var el = document.getElementById(selectedId);
    var gradlevelElement = el.parentNode;
    gradlevelElement.className = 'visible';
    //alert(gradlevelElement.id);
}

function openCenteredWindow(theURL, winName, features, w, h){
  var winl = parseInt((screen.width - w - 10) / 2);
  var wint = parseInt((screen.height - h - 29) / 2);
  var retval = openWindow(theURL, winName, features + ',height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl);
  if(!theURL) return retval;
}

function openGoogleDirections(url) {
	openCenteredWindow(url,'GooglemapDirections','toolbar=no,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes','820','650');
}
function openLocationMap() {
	openCenteredWindow("Campuses/LocationMap.aspx",'LocationMap','toolbar=no,location=no,status=no,menubar=no,scrollbars=auto,resizable=yes','800','730');
}

function openNewsDetail(newsId) {
	openCenteredWindow("/news-events/DetailPrint.aspx?id=" + newsId,'NewsDetail','toolbar=no,location=no,status=no,menubar=no,scrollbars=1,resizable=yes','780','800');
}



function openWindow(theURL, winName, features){
  if(forcedRefresh == false && alreadyopen[winName] && !newwin[winName].closed){
    newwin[winName].focus();
  }
  else{
    alreadyopen[winName] = 1;	 
    newwin[winName] = window.open(theURL, winName, features);
    newwin[winName].focus();
  }
  if(!theURL) return newwin[winName];
}

function firemodal(modalname){
    try
    {
        //document.getElementById('inquiryDaemonHolder').style.display = 'block';
        $find(modalname).show();
        return false;
    }
    catch(e)
    {
        
    }
} 

function RemoveHomePageFlash()
{
    try
    {    
        $get('homepage_nonflash_content').innerHTML = '<img src="design/img/homepage_nonflash.jpg" alt="" width="870" height="210" />';
    }
    catch(e)
    {
    
    }
}

function LoadHomePageFlash()
{
    try
    {  
        LoadFlash();
    }
    catch(e)
    {
    
    }
}

function ToggleItem(Id, ImageId)
{
    var item = $get(Id);
    var image = $get(ImageId);
    if(item.style.display != 'block')
    {
        item.style.display = 'block';
        image.src = '/design/img/abandonpop/arrowup.gif';
    }
    else 
    {
        item.style.display = 'none';
        image.src = '/design/img/abandonpop/arrow.gif';
    }
}


    function SendScriptErrorEmail(url, status, message)
    {
        try
        {
            EDMC.South.Web.SendError.SendEmailErrorMessage(url, status, message, SucceededCallback);
        }
        catch(err)
        {
            alert("A script error has occurred: " + err.message);
        }
    }
    
    function SucceededCallback(result)
    {
        
    }
    function showYellowRibbonMenu() {
        try
        {
            if ( $("#divYellowRibbon").is(':hidden')) {

                $("#divYellowRibbon").animate({ opacity: "show" }, "slow");
            }
            else {
                $("#divYellowRibbon").animate({ opacity: "hide" }, "slow");
            }
        }
        catch (err) {
           location.href = '/admissions/yellow-ribbon.aspx';
        } 
    }
    function getCookie(name) {
        var start = document.cookie.indexOf(name + "=");
        var len = start + name.length + 1;
        if ((!start) && (name != document.cookie.substring(0, name.length))) {
            return null;
        }
        if (start == -1) return null;
        var end = document.cookie.indexOf(';', len);
        if (end == -1) end = document.cookie.length;
        return unescape(document.cookie.substring(len, end));
    }
    function showSidebarCalendarMenu() {
        try
        {
            if ( $("#divSidebarCalendar").is(':hidden')) {

                $("#divSidebarCalendar").animate({ opacity: "show" }, "slow");
            }
            else {
                $("#divSidebarCalendar").animate({ opacity: "hide" }, "slow");
            }
        }
        catch (err) {
          // location.href = '/degree-programs.aspx';
        } 
    }