function showModalPopupViaClient(ev) {
    ev.preventDefault();
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.show();
}
function hideModalPopupViaClient(ev) {
    ev.preventDefault();
    alert("HELLO WORLD!\n");    
    var modalPopupBehavior = $find('programmaticModalPopupBehavior');
    modalPopupBehavior.hide();
}
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++)
  	foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  return foundObj;
}

function doIncludeZone2() {
	var vZone1 = findChild("zone1");
	if (vZone1 != null) {
		vZone1.className = "withZone2";
	}
}

function doMakeTwoColumn() {
	var vBottomColumnHolder = findChild("bottomCalloutHolder");
	if (vBottomColumnHolder != null)
	{
		vBottomColumnHolder.className = "twoColumnContent";
	}
}

function doMakeThreeColumn() {
	var vBottomColumnHolder = findChild("bottomCalloutHolder");
	if (vBottomColumnHolder != null)
	{
		vBottomColumnHolder.className = "threeColumnContent";
	}
}

function doMakeTwoColumnSecondary() {
	var vBottomColumnHolder = findChild("bottomCalloutHolder");
	if (vBottomColumnHolder != null)
	{
		vBottomColumnHolder.className = "twoColumnContentSecondary";
	}
}

function findChild(id, obj) {
	var foundObj = null;

	if (!obj) {
		foundObj = findObj(id);
	}
	else {
		if (obj.nodeType && obj.nodeType == "1" && obj.id && id && obj.id.toLowerCase() == id.toLowerCase()) {
			foundObj = obj;
		}
	}

	if (!foundObj && obj && obj.nodeType && obj.nodeType == "1" &&
		obj.childNodes && obj.childNodes.length
		&& obj.childNodes.length > 0) {
		var myList = obj.childNodes;
		for (var i=0; i<myList.length; i++) {
			foundObj = findChild(id, myList[i]);
			if (foundObj)
				break;
		}
	}
	return foundObj;
}

function setMaxHeight(str) {
    var myWidth = 0, myHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) )  {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    var vPopup = findObj(str);
    if (vPopup && vPopup.style) {
		
		if (navigator.appVersion.indexOf("MSIE 6.0")) {
			var vNewTop = parseInt(vPopup.clientTop) / 2;
			vPopup.style.top = vNewTop + "px";
		}
		
        if (parseInt(vPopup.clientHeight) > parseInt(myHeight)) {
            myHeight = parseInt(myHeight) - 30;
            vPopup.style.height = myHeight + "px";
        }
    }
}

function doFixContentDiv() {
	var myDiv = findChild("contentOptionsMain");
	if (myDiv != null) {
		myDiv.className = "no-navigation";
	}
}

function doFixHeightCustom() {
	var colHeight = 100;
	var ary = new Array("zone2", "zone4", "zone5", "zone6");
	var cols = new Array();
    
	var objColumnMain = findObj("secondaryBodyContent");
    var objHeaderMain = findChild("headerMain", objColumnMain);
    var objHeaderLeftMain = findChild("headerLeftMain", objColumnMain);
    var objHeaderRightMain = findChild("headerRightMain", objColumnMain);

	if (objHeaderMain && objHeaderLeftMain && objHeaderRightMain) {
        if (objHeaderMain.scrollHeight) {
            var i = parseInt(objHeaderMain.scrollHeight);
            if (i <= 20) {
                objHeaderMain.style.lineHeight = "40px";
                i = 40;
            }
            if (i > 20) {
                objHeaderLeftMain.style.height = i + "px";
                objHeaderRightMain.style.height = i + "px";
            }
        }
    }
	
	var objSecondaryNav = findObj("secondaryNav");
	var objBodyColumnMain = findObj("columnBodyMain");
	
	if (objSecondaryNav && objBodyColumnMain && objHeaderMain) {
		if (objSecondaryNav.scrollHeight && objBodyColumnMain.scrollHeight) {
			var secondaryNavHeight = parseInt(objSecondaryNav.scrollHeight);
			var columnBodyMainHeight = parseInt(objBodyColumnMain.scrollHeight) + parseInt(objHeaderMain.scrollHeight) + 50;
			
			if (secondaryNavHeight > columnBodyMainHeight) {
				var newHeight = parseInt(secondaryNavHeight) - parseInt(objHeaderMain.scrollHeight) - 50;
				objBodyColumnMain.style.height = newHeight + "px";
			}
		}
	}

	for (var i=0; i<ary.length; i++) {
		var objColumn = findChild(ary[i]);
		if (objColumn) {
			
		    var objHeader = findChild("header", objColumn);
		    var objHeaderLeft = findChild("headerLeft", objColumn);
		    var objHeaderRight = findChild("headerRight", objColumn);
		    if (objHeader && objHeaderLeft && objHeaderRight) {
		        if (objHeader.scrollHeight) {
		            var x = parseInt(objHeader.scrollHeight);
		            if (x <= 20) {
		                objHeader.style.lineHeight = "40px";
		                x = 40;
		            }
		            if (x >= 40) {
		                objHeaderLeft.style.lineHeight = x + "px";
		                objHeaderLeft.style.height = x + "px";
		                objHeaderRight.style.height = x + "px";
		            }
		        }
		    }
			
			if (ary[i] != "zone2") {
				var objColumnBody = findChild("columnBody", objColumn);
				if (objColumnBody) {
					if (objColumnBody.clientHeight && parseInt(objColumnBody.clientHeight) > colHeight)
						colHeight = parseInt(objColumnBody.clientHeight);
					cols.push(objColumnBody);
				}
			}
		}
	}

	for (var n=0; n<cols.length; n++) {
		var objColumn = cols[n];
		objColumn.style.height = colHeight + "px";
	}
}

function doFixMainBodyHeight() {
	var objSecondaryNav = findChild("secondaryNav");
	var objColumnBodyMain = findChild("columnBodyMain");
	var objHeaderMain = findChild("headerMain");
	var str = "";
	if (objSecondaryNav.scrollHeight && objColumnBodyMain.scrollHeight && objHeaderMain.scrollHeight) {
	    var secondaryNavHeight = parseInt(objSecondaryNav.scrollHeight);
	    var columnBodyMainHeight = parseInt(objColumnBodyMain.scrollHeight); 
	    var headerAndPaddingHeight = parseInt(objHeaderMain.scrollHeight) + 40; // the +40 is for the padding.
	    if (secondaryNavHeight >= (columnBodyMainHeight + headerAndPaddingHeight)) {
	        var newHeight = secondaryNavHeight - headerAndPaddingHeight;
	        objColumnBodyMain.style.height = newHeight + "px";
	    }
	}
}

function setStyleRecursive(vNode, aStyle, vNodeName) {
    if (vNode != null && vNode.nodeType && vNode.nodeType == 1 && vNode.nodeName && vNode.nodeName == vNodeName) {
        if (vNode.style) {
            for(var key in aStyle) {
                vNode.style[key] = aStyle[key];
            }
        }
    }
    if (vNode.childNodes) {
        var objChildren = vNode.childNodes;
        for(var i=0; i<objChildren.length; i++) {
            setStyleRecursive(objChildren[i], aStyle, vNodeName);
        }
    }
}

function setStyle(vParent, vTagName, aStyle) {
    var objParent = findChild(vParent);
    if (objParent != null) {
        setStyleRecursive(objParent, aStyle, vTagName);
    }
}

function getFirstItem(node, lastChild) {
    var objLastChild = lastChild;
    if (node.nodeType && node.nodeType == 1 && node.nodeName && node.nodeName == "LI") {
        objLastChild = node;
    }
    else {
        if (node.childNodes) {
        var objChildren = node.childNodes;
            for(var i=0; i<objChildren.length; i++) {
                if (objChildren[i].nodeType && objChildren[i].nodeType == 1) {
                    objLastChild = getFirstItem(objChildren[i], objLastChild);
                }
                if (objLastChild != null) {
                    break;
                }
            }
        }
    }
    return objLastChild;
}

function getLastItem(node, lastChild) {
    var objLastChild = lastChild;
    if (node.nodeType && node.nodeType == 1 && node.nodeName && node.nodeName == "LI") {
        objLastChild = node;
    }
    if (node.childNodes) {
    var objChildren = node.childNodes;
        for(var i=0; i<objChildren.length; i++) {
            if (objChildren[i].nodeType && objChildren[i].nodeType == 1) {
                objLastChild = getLastItem(objChildren[i], objLastChild);
            }
        }
    }
    return objLastChild;
}

function fixSecondaryNav() {
    var objSecondaryNav = findChild("secondaryNav");
    var str = "";

    var objLastChild = getLastItem(objSecondaryNav, null);
    if (objLastChild != null) {
        objLastChild.className = (objLastChild.className == "opened") ? "openedbottom" : "bottom";
    }

    var objFirstChild = getFirstItem(objSecondaryNav, null);
    if (objFirstChild != null) {
        objFirstChild.className = (objFirstChild.className == "opened" || objFirstChild.className == "openedbottom") ? "openedtop" : "top";
    }

}

function doFixSubDisciplineList(controlID, newValue) {
    var varProgramOptions = (this.vProgramOptions != null) ? this.vProgramOptions : window["ProgramOptions"];
    var objSubDisciplineList = findChild(controlID);
    if (objSubDisciplineList != null) {
        for (var i=objSubDisciplineList.options.length - 1; i >= 0; i--) {
            objSubDisciplineList.options[i] = null;
        }

        var vSubOption = new Option("-- Discipline --", "");
        vSubOption.selected = true;
        objSubDisciplineList.options.add(vSubOption);
        for (var n=0; n<varProgramOptions[newValue].length; n++) {
            objSubDisciplineList.options.add(varProgramOptions[newValue][n]);
        }
    }
}

// Line for Microsoft .NET AJAX code 
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

/*********************************************************************************************
	Popup window function
*********************************************************************************************/
function newWindow(url, width, height)
{
    var popWin = window.open(url, '_blank', 'width=' + width + ',height=' + height + ',scrollbars=1,resizable=1');
    if (popWin != null)
    {
        popWin.focus();
    }
}

function setCookieShowInquiryDaemon(){
    document.cookie = 'daemonpopup=true';
}

function removeCookieHideInquiryDaemon(){
    document.cookie = 'daemonpopup=removed';
}
	
function firemodal(modalname){
    try
    {
        //document.getElementById('inquiryDaemonHolder').style.display = 'block';
        $find(modalname).show();
        return false;
    }
    catch(e)
    {
        
    }
} 

    function CloseAllExpanded()
    {
         var closeDiv1 = document.getElementById('chatLiveExpanded');  
         var closeDiv2 = document.getElementById('callBackExpanded');
         var closeDiv3 = document.getElementById('viewBookExpanded');  
    
         CloseDiv(closeDiv1);
         CloseDiv(closeDiv2);
         CloseDiv(closeDiv3); 
    }
    
    function ShowAll()
    {
         var openDiv1 = document.getElementById('chatLiveButton');  
         var openDiv2 = document.getElementById('callBackButton');
         var openDiv3 = document.getElementById('viewBook');  
         
         OpenDiv(openDiv1);
         OpenDiv(openDiv2);
         OpenDiv(openDiv3);
    }
    
    function CloseDiv(control)
    {
        control.style.visibility = 'hidden';
        control.style.display = 'none';        
    }    
    function OpenDiv(control)
    {
        control.style.visibility = 'visible';
        control.style.display = 'block';
    }
    
    function ExpandItem(closeId,openId)
    {            
        CloseAllExpanded();
        ShowAll();
        var closeDiv = document.getElementById(closeId);
        var openDiv = document.getElementById(openId);
        
        OpenDiv(openDiv);
        CloseDiv(closeDiv);
    }
    
    function addToFavorites(url,title) 
    { 
        if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
          window.external.AddFavorite(url,title);
          } else if (navigator.appName == "Netscape") {
            window.sidebar.addPanel(title,url,"");
          } else {
            alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
          }
    
        //if (window.external) { window.external.AddFavorite(urlAddress,pageName) 
        //} else { alert("Sorry! Your browser doesn't support this function."); 
        //} 
    }

    function GetFirstLevelDirectory()
    {
        var thisUrl = document.URL.toString().toLowerCase();
        
        thisUrl = thisUrl.replace("http://", "");
        thisUrl = thisUrl.replace("www.", "");
        thisUrl = thisUrl.replace(document.domain, "");

        var directories = thisUrl.split('/');
        for(i=0; i<directories.length; i++)
        {
            if(directories[i].indexOf('.')<0 && directories[i] != "")
            {
              return directories[i];
            }           
        }
        return "";
    }
  
    function SendScriptErrorEmail(url, status, message)
    {
        try
        {
            EDMC.ArtInstitute.Web.SendError.SendEmailErrorMessage(url, status, message, SucceededCallback);
        }
        catch(err)
        {
            //alert("A script error has occurred");
        }
    }
    
    function SucceededCallback(result)
    {
        
    }
    