/* Loading CSS and JS at runtime */
function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script')
  fileref.setAttribute("type","text/javascript")
  fileref.setAttribute("src", filename)
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link")
  fileref.setAttribute("rel", "stylesheet")
  fileref.setAttribute("type", "text/css")
  fileref.setAttribute("href", filename)
 }
 if (typeof fileref!="undefined")
  document.getElementsByTagName("head")[0].appendChild(fileref)
}


/* Cookie */
function getCookie( name )
{
	var cname		= name + "=";

	var dc		= document.cookie;

	if( dc.length > 0 )
	{
		begin = dc.indexOf(cname);

		if( begin != -1 )
		{
			begin += cname.length;

			end = dc.indexOf(";", begin);

			if( end == -1 )
			{
				end = dc.length;
			}

			return unescape(dc.substring(begin, end));
		}
	}

	return null;
}


function setCookie( name, value, expires, path, domain, secure )
{
	document.cookie = name + "=" + escape(value) +
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
}	


function delCookie( name, path, domain )
{
	if( getCookie(name) )
	{	
		document.cookie = name + "=" +
		((path == null) ? "" : "; path=" + path) +
		((domain == null) ? "" : "; domain=" + domain) +
		"; expires=Thu, 01-Jan-70 00:00:01 GMT";
	 
	}
}




/* Text resizing */
var firstCall = true;

function resizeAnchors( parent, newFontSize )
{
	var cell 		= document.body;
	anchors = cell.getElementsByTagName('a');
 
	for( a=0; a < anchors.length; a++ )
	
	{
		anchor = anchors[a];
	
				// Skip Objects
				if( (anchor.className.indexOf("noresize") > -1 ) || (anchor.parentNode.className.indexOf("noresize") > -1)
						 || (anchor.parentNode.parentNode.className.indexOf("noresize") > -1)																				 )
				{
					continue
				}				
			anchor.style.fontSize = newFontSize + "px";
	 
	}
}


function changeFontsize( fSize, increment )
{
	var p_fontsize = null;
	
	// Is this the first call?
	if( firstCall )
	{
		firstCall = false;
		if( increment != "" )
		{
			changeFontsize('11', '');
		}
			
	}

	if( document.getElementsByTagName )
	{
		var tags = new Array ( "h1", "h2", "h3", "p", "li" );
 
		for( j=0; j < tags.length; j++ )
		{
			var cell 		= document.body;

			var getElement 	= cell.getElementsByTagName(tags[j]);

			var eachElement, currentFontSize, fontIncrease, newFontSize;

			for( i=0; i<getElement.length; i++ )
			{
				eachElement = getElement[i];
				
				// Skip Objects
		 				
				
				if( eachElement.parentNode.className == "welcome" || eachElement.parentNode.parentNode.className == "welcome" )
				{
					continue
				}

				if( eachElement.parentNode.className == "headerBox" || eachElement.parentNode.parentNode.className == "headerBox" )
				{
					continue
				}
				// Reset the new fontsize each time.
				newFontSize = null;

				if( false == isNaN(parseInt(increment)) )
				{
					 
					currentFontSize		= parseInt(eachElement.style.fontSize);
					fontIncrease		= parseInt(increment);
					newFontSize			= currentFontSize + fontIncrease;
				}
				else if( parseInt(fSize) > 0  )
				{
					newFontSize = parseInt(fSize);
				}
				
				if( true == isNaN(newFontSize) )
				{
					continue;
				}

				if( tags[j] == "li" )
				{
					//eachElement.style.lineHeight = Math.round(newFontSize * 1.2) + "px";
				}
				else
				{
				//	eachElement.style.lineHeight = Math.round(newFontSize * 1.1) + "px";
				}

				if( fSize != "" )
				{
					switch( tags[j] )
					{
						case "h1":
							newFontSize += 9;
							break;

						case "h2":
							newFontSize += 6;
							break;

						case "h3":
							newFontSize += 1;
							break;
					 
						case "h4":
							newFontSize += 0;
							break;

						case "h5":
							newFontSize += 0;
							break;

						case "h6":
							newFontSize += 0;
							break;
					}
				}
 
 				 
				eachElement.style.fontSize = newFontSize + "px";
				 
				// Only save the fontsize if the tag element is a p. All font sizes are based of this element.
				if( (eachElement.tagName.toLowerCase() == 'p') && (parseInt(newFontSize) > 0) )
				{
					p_fontsize = newFontSize;
					setCookie('fontSize', newFontSize);
				}
			}
		}
		
 
	}
	
	
	fontsize = null;
	if( parseInt(fSize) > 0 )
	{
		fontsize = fSize;
	}
	else if( p_fontsize != null )
	{
		fontsize = p_fontsize;
	}
	
	if( fontsize != null )
	{	
 		resizeAnchors(null,newFontSize);	
	}
}

function clearStyles(){
	
	
	setCookie('fontSize','');
	delCookie('fontSize');	
		
	if( document.getElementsByTagName )
	{
		var tags = new Array ( "h1", "h2", "h3", "p", "li","a" );
		
		for( j=0; j < tags.length; j++ )
		{
			var cell 		= document.body;

			var getElement 	= cell.getElementsByTagName(tags[j]);

			var eachElement;

			for( i=0; i<getElement.length; i++ )
			{
 
				eachElement = getElement[i];
				eachElement.style.lineHeight ="";
				eachElement.style.fontSize ="";
			}
		}
		
		firstCall= true;
	}
	

}




function tabswitch (selectedId, inactiveId1, inactiveId2){
	var selectedobj = document.getElementById(selectedId);
	var inactiveobj1 = document.getElementById(inactiveId1);
	var inactiveobj2 = document.getElementById(inactiveId2);
	
	selectedobj.className='selected';
	inactiveobj1.className='';
	inactiveobj2.className='';

	var pnlselectedobj = document.getElementById('pnl' + selectedId);
	var pnlinactiveobj1 = document.getElementById('pnl' + inactiveId1);
	var pnlinactiveobj2 = document.getElementById('pnl' + inactiveId2);

	pnlselectedobj.style.visibility='visible';
	pnlselectedobj.style.display='block';
	pnlinactiveobj1.style.visibility='hidden';
	pnlinactiveobj1.style.display='none';
	pnlinactiveobj2.style.visibility='hidden';
	pnlinactiveobj2.style.display='none';

	
}
 
function expandCollapse(childId,caller){
    var childObj = document.getElementById(childId);
	var parentObj  = childObj.parentNode.parentNode;
   	
    if (childObj.style.visibility == "hidden") {
        childObj.style.visibility='visible';
        childObj.style.display='block';
		
		// hide other links of the same level
		var menu_lis = parentObj.getElementsByTagName("ul");
		var ulobj;
		for (i=0;i< menu_lis.length;i++) {
	//		alert(menu_lis [i].id + ' = ' + childId);
			ulobj = menu_lis[i];
		 
		 
			if((ulobj != childObj) && (ulobj.className !='selected')){
				ulobj.style.visibility='hidden';
				ulobj.style.display='none';				
			}
		}				
    }
    else{
        childObj.style.visibility='hidden';
        childObj.style.display='none';
    }
	
	

}


function mainMenuMouseOver(excludeId){
    var i = 0;
    var itemIdName;
    var menuSel = document.getElementById('menuSelId');
    var menuDefSel = document.getElementById('menuDefSelId');
    menuSel.value = 'navigating';
	
	

    for (i  = 1; i < 11; i++){
        itemIdName ='item' + i;
 
        if (itemIdName !=  excludeId){
            var obj = document.getElementById('item' + i);
			if(obj != null){
				// remember the last selected menu
				if (obj.className == 'selected'){
					menuDefSel.value = obj.id;
				}
	           obj.className= '';
 			}
        }
    }
}


function mainMenuMouseOut(){  
    var menuSel = document.getElementById('menuSelId');
    menuSel.value = '';

    var menuDefSel = document.getElementById('menuDefSelId');
	var itemId = menuDefSel.value;
	setTimeout("assignClass('" + itemId + "','selected')", 1000);
}


function assignClass(objId, value){
    var menuSel = document.getElementById('menuSelId');
    if (menuSel != null){
		if(menuSel.value == ''){
			var obj = document.getElementById(objId);
			if (obj != null){
				obj.className=value;
			}
		}   
	}
}

// Resizing related functions
if( typeof addLoadEvent != "undefined" )
{
	addLoadEvent(onload_fontSize);
}


function onload_fontSize()
{
	fontSize = getCookie('fontSize');
 
 	if (fontSize==null){
	}
	else if (fontSize == ''){
			clearStyles();
	}
	else if( fontSize != null )
	{
		changeFontsize(parseInt(fontSize), '');
	}
}

function addLoadEvent( func )
{
	var oldonload = window.onload;

	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			oldonload();
			func();
		}
	}

}



/* Set visibility of sub menus */
function setListVisibleShow (id){
	var obj = document.getElementById(id);
		obj.style.visibility='visible';
		obj.style.display='block';
}

function setListVisibleHide (id){
	 var menuSel = document.getElementById('vmenuSelId');
	 if ((menuSel.value == '') || (menuSel.value != id)){
		var obj = document.getElementById(id);
		obj.style.visibility='hidden';
		obj.style.display='none';
	}


}
function setListVisibleHide2 (id){
	 var menuSel = document.getElementById('vmenuSelId2');
	 if ((menuSel.value == '') || (menuSel.value != id)){
		var obj = document.getElementById(id);
		obj.style.visibility='hidden';
		obj.style.display='none';
	}
}

function setListVisible (id){
	var obj = document.getElementById(id);
	if (obj.style.visibility=='visible'){
		obj.style.visibility='hidden';
		obj.style.display='none';
	}
	else{
		obj.style.visibility='visible';
		obj.style.display='block';
	}
}

function getNewHTTPObject()
{
        var xmlhttp;

        /** Special IE only code ... */
        /*@cc_on
          @if (@_jscript_version >= 5)
              try
              {
                  xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              }
              catch (e)
              {
                  try
                  {
                      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                  }
                  catch (E)
                  {
                      xmlhttp = false;
                  }
             }
          @else
             xmlhttp = false;
        @end @*/

        /** Every other browser on the planet */
        if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
        {
            try
            {
                xmlhttp = new XMLHttpRequest();
            }
            catch (e)
            {
                xmlhttp = false;
            }
        }

        return xmlhttp;
}


function GetSemesterPlan(value){
 			
	var http = getNewHTTPObject();
    var url = "http://webstaging.zu.ac.ae/WWWGetData/GetCourseCatalog.aspx";
	var params = value;
	
	if (location.href.indexOf("www.zu.ac.ae") > -1){
		url = "http://www.zu.ac.ae/WWWGetData/GetCourseCatalog.aspx";
	}
	else if (location.href.indexOf("localhost") > -1){
 
		url = "http://localhost/WWWGetData/GetCourseCatalog.aspx";
	}
		 	http.open("POST", url, true);
	


	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");


	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		var render = document.getElementById('coursecatalog');
 
		render.innerHTML = http.responseText;
	 
	}
	}
 
	http.send(params); 
 
}


function GetCourseDetails(value){
	var http = getNewHTTPObject();
    var url = "http://webstaging.zu.ac.ae/WWWGetData/GetCourseDetails.aspx";
	var params = value;
	
	if (location.href.indexOf("www.zu.ac.ae") > -1){
		url = "http://www.zu.ac.ae/WWWGetData/GetCourseDetails.aspx";
	}
	else if (location.href.indexOf("localhost") > -1){
 
		url = "http://localhost/WWWGetData/GetCourseDetails.aspx";
	}
	 	
	http.open("POST", url, true);
	


	//Send the proper header information along with the request
	http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	http.setRequestHeader("Content-length", params.length);
	http.setRequestHeader("Connection", "close");


	http.onreadystatechange = function() {//Call a function when the state changes.
	if(http.readyState == 4 && http.status == 200) {
		var render = document.getElementById('coursecatalog');
 		render.innerHTML = http.responseText;
		}
	}
 
	http.send(params); 
 
}



