﻿// JScript File

function getPopupObject(myId)
{
   if (document.getElementById(myId))
   {
     return document.getElementById(myId);
   }
   else
   {
     return window.document[myId]; 
	}     
}

function showPopup(id)
{
	var popup=getPopupObject(id);

	if (popup)
	{	
		popup.style.visibility='hidden';	
        //Checking to see if it is in the right place.
		if (popup.name!='moved')
		{
	        popup.name='moved';
	        //Trying to get Popups to position correctly
            var a=getElementPosition(id);
	        var left=a.left;
	        var top=a.top;
	        var b=getElementPosition('mapimage');
	        var imgleft=b.left;
	        var imgtop=b.top;
	        popup.style.left=left+imgleft+"px";
		    popup.style.top=top+imgtop+"px";
		}
		
		popup.style.visibility='visible';
	}
}

function hidePopup(id)
{

        delayhidePopup(id);

}

function delayhidePopup(id)
{
    var popup=getPopupObject(id);
	popup.style.visibility='hidden';
}



function changelinkclass(id)
{
    var link="Link" + id;
    var arrow="Arrow" + id;
    changeClass(link, 'MenuLevel0_ItemSelected');
    changeClass(arrow, 'MenuLevel0_ArrowSelected');
}
    
function returnlinkclass(id)
{
    var link="Link" + id;
    var arrow="Arrow" + id;
    changeClass(link, 'MenuLevel0_Item');
    changeClass(arrow, 'MenuLevel0_Arrow');
}


function changeClass(Elem, myClass) {
	var elem;
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	elem.className = myClass;
}

function pausecomp(millis)
{
var date = new Date();
var curDate = null;

do { curDate = new Date(); }
while(curDate-date < millis);
} 


function getElementPosition(elemID) {
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    while (offsetTrail) {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 && 
        typeof document.body.leftMargin != "undefined") {
        offsetLeft += document.body.leftMargin;
        offsetTop += document.body.topMargin;
    }
    return {left:offsetLeft, top:offsetTop};
}



//This section Controls the div slide over
//Variable for Hidden Div
var Hide = "";
var HideVarHt = 0;
var HideHt = "";
var HideWd = 0;

//Variables for Showing Div
var Showing = "";
var ShowingVarHt = "";
var ShowingHt = "";
var ShowingVarTop = 0;
var ShowingTop = 0;
var ShowingWd = 0;

//Scroll Control Variables
var ScrollDirection = 'Down';
var SwapDelay = 1;//delaysetting in milliseconds
var PixelsPerLine = 1;//number of pixels

var browserName=navigator.appName;

function setup(HiddenDivID,ShowingDivID) 
{
	//Get the ht of the left column
	var LeftCol = getPopupObject('dnn_LeftColumn');
	
	//Set the Hide to the Hidden Div
	Hide=getPopupObject(HiddenDivID);
	
	//Set the Max Ht of the left column
	HideHt = LeftCol.offsetHeight;
	HideWd = Hide.offsetWidth;
	
	//Set the Hidden to 0px hight
	Hide.style.height = '0px';
	
	//Set Showing to the Showing Div
	Showing=getPopupObject(ShowingDivID);
	var ShowingHtTemp = Showing.offsetHeight;
    ShowingWd = Showing.offsetWidth;
    
    
    

    
    //Set the showing and hidden ht
	if( ShowingHtTemp>HideHt )
	{
	    HideHt = LeftCol.offsetHeight;
	    ShowingHt = LeftCol.offsetHeight;
	    ShowingVarHt = LeftCol.offsetHeight;
	    Showing.style.height = ShowingHtTemp+'px';
	}
	else
	{
	    ShowingHt = LeftCol.offsetHeight;
	    ShowingVarHt = LeftCol.offsetHeight;
	    Showing.style.height = ShowingHt+'px';
	}
	
	
	//Set the absolute position of the showing on top of the hidden
    var a=getElementPosition(HiddenDivID);
    var left=a.left;
    ShowingVarTop = a.top;
    ShowingTop = a.top;
    Showing.style.left=left+"px";
    Showing.style.top=ShowingTop+"px";
    
    //Set the Width of the Showing

    if (browserName == "Microsoft Internet Explorer" )
    {
        ShowingWd = HideWd - 20;
    }
    else
    {
        ShowingWd = HideWd -42;
    }

    Showing.style.width= ShowingWd +"px";
	
}

function hidewithouttoggle()
{
    Showing.style.visibility='hidden';
    Showing.style.display='none';
    Hide.style.height = HideHt+ 'px';
}

function toggle() 
{
	if (ScrollDirection == 'Down') //slide down
	{
	    //alert('HideVarHt:' + HideVarHt + '   ShowingVarHt:' + ShowingVarHt);
		
		//Set the hidden div height to HideVarHt		
		Hide.style.height = HideVarHt+'px';
		Showing.style.height = ShowingVarHt+'px';
		Showing.style.top= ShowingVarTop+'px';
		
		//add remaining pixels to hidden if less than PixelsPerLine
		if (((HideHt-HideVarHt) < PixelsPerLine) && (HideVarHt !== HideHt)) 
		{
			HideVarHt = HideHt;
			
		}
		//add PixelsPerLine pixels to the height of hidden
		//delete z=PixelsPerLine pixels from the height of showing
		else 
		{
			HideVarHt = HideVarHt+PixelsPerLine;
			ShowingVarHt = ShowingVarHt-PixelsPerLine;
			ShowingVarTop = ShowingVarTop+PixelsPerLine;//used to push down div
		}
		
		//call the toggle function if VariableHt of Hidden is less than Max Ht of Hidden
		//with the delay of y milliseconds
		if (HideVarHt <= HideHt) 
		{
			setTimeout('toggle()',SwapDelay);
		}
		
		//Reset the Scroll direction on finished
		if (HideVarHt > HideHt) 
		{
			HideVarHt = HideHt;
			ShowingVarHt = 0;
			Showing.style.height = ShowingVarHt+'px';
			Showing.style.visibility='hidden';
			Showing.style.display='none';
			ScrollDirection = 'Up';
		}
	} 
	else //slide up
    {
        //alert('HideVarHt:' + HideVarHt + '   ShowingVarHt:' + ShowingVarHt);
    
		//Set the hidden div height to HideVarHt
		Hide.style.height = HideVarHt+'px';
		Showing.style.height = ShowingVarHt+'px';
		
		//subtract PixelsPerLine pixels to the height of hidden
		//add PixelsPerLine pixels to the showing
		HideVarHt = HideVarHt-PixelsPerLine;
		ShowingVarHt = ShowingVarHt+PixelsPerLine;
		
		//call the toggle function if 
		//with the delay of y milliseconds
		if ((HideHt-HideVarHt) <= HideHt) 
		{
			setTimeout('toggle()',SwapDelay);
		}
		
		//
		if ((HideHt-HideVarHt) > HideHt) 
		{
			HideVarHt = 0;
			Hide.style.height = HideVarHt+'px';
			//Showing.style.visibility='visible';
			ScrollDirection = 'Down';
		}
	}
}

function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}


function keywordsearch()
{
    var text=document.getElementById('KeywordSearch').value;
    
    if (text != '')
    {
        document.getElementById('Form').action='DegreeProgramSearch/DegreeSearchResultsComplex/tabid/463/Default.aspx';
        document.getElementById('Form').submit();
    }
    else
    {
        alert('Please enter search terms.');
    }
}

function getQueryVariable(variable) 
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) 
        {
            var pair = vars[i].split("=");
            if (pair[0] == variable) 
                {
                    return pair[1];
                }
        }
    alert('Query Variable ' + variable + ' not found');
} 