﻿var intid=-1;
var effectstack=new Array();

 function ShowLessonsWindow(path,startTime)
 {
    var newWindow = window.open('Default3.aspx?Path='+ path + '&startTime=' + startTime,'_blank','height=780px,width=1000px,center=yes,scrollbars=no,dialogHelp=no,titlebar=no,location=no',true);            
    newWindow.focus(); 
    newWindow.moveTo((screen.availWidth - 1000)/2,(screen.availHeight - 780)/2); 
    return false;
 }

function parseStyleHeight(styleheight){
	var height=styleheight.substr(0, styleheight.lastIndexOf('px'));
	var intheight=parseInt(height);
	return intheight;
}

function checkall(){
	for(var i=0;i<effectstack.length;i++){
		var x=effectstack[i];
		var elem=document.getElementById(x.id);
		if(elem.style.display=="none" || elem.style.display==""){
			//elem.style.height=String(x.heightto)+"px";
			effectstack.splice(i, 1);
			continue;
		}
		if(elem.style.height=="auto" || elem.style.height=="")
			elem.style.height=elem.offsetHeight;
		//var cheight=parseInt(elem.style.height);
		var cheight=parseStyleHeight(elem.style.height);
		if(x.grow==true){
			if(cheight+x.delta>=x.heightto){
				elem.style.height=String(x.heightto)+"px";
				elem.style.height="auto";
				effectstack.splice(i, 1);
			}
			else
				//elem.style.height=String(parseInt(elem.style.height)+x.delta)+"px";
				elem.style.height=String(cheight+x.delta)+"px";
		}
		else{
			if(cheight-x.delta<=x.heightto){
				elem.style.height=String(x.heightto)+"px";
				if(x.heightto==0){
					elem.style.display="none";
					elem.style.height="";
				}
				effectstack.splice(i, 1);
			}
			else
				//elem.style.height=String(parseInt(elem.style.height)-x.delta);
				elem.style.height=String(cheight-x.delta)+"px";
		}
	}
	if(effectstack.length==0){
		clearInterval(intid);
		intid=-1;
	}
}


function tryhidenodes(node){
	if(node.className=="submenu"){
		node.style.display="none";
	}
	for(var walk=0;walk<node.childNodes.length;walk++)
		tryhidenodes(node.childNodes[walk]);
}

function tryhideupnodes(thisnode, parent){
	if(parent==null)
		return;
	for(var i=0;i<parent.childNodes.length;i++){
		var node=parent.childNodes[i];
		if(node!==thisnode){
			for(var j=0;j<node.childNodes.length;j++)
				if(node.childNodes[j].className=="submenu")
					node.childNodes[j].style.display="none";
		}
	}
}

function changeMenu(whoid, masterparentid){

	var who=document.getElementById(whoid);
	//alert("height="+String(who.height)+"\nclientheight="+String(who.clientHeight)+"\noffsetheight="+String(who.offsetHeight)+"\nscrollheight="+String(who.scrollHeight)+"\ncssheight="+who.style.height);
	var masterparent=document.getElementById(masterparentid);
	var size;
	if(who.style.display=="none" || who.style.display==""){
		who.style.display="block";		
		//who.style.display="inline-block";      //-
		who.style.height="auto";		
		size=who.offsetHeight;
		effectstack.unshift({delta:65, id:whoid, grow:new Boolean(true), heightto:size});
		who.style.height="0px";	
	}
	else{
		size=who.offsetHeight;
		who.style.display="none";		//-
		who.style.height=String(size)+"px";
		effectstack.unshift({delta:65, id:whoid, grow:new Boolean(false), heightto:0});
		//return;
	}
	
	//alert("height="+String(who.height)+"\nclientheight="+String(who.clientHeight)+"\noffsetheight="+String(who.offsetHeight)+"\nscrollheight="+String(who.scrollHeight)+"\ncssheight="+who.style.height);
	
	//hide other courses and all their children
	
	var menu=document.getElementById("menu0");
	for(var i=0;i<menu.childNodes.length;i++){
		var node=menu.childNodes[i];
		if(node.className.indexOf("coursesStyle")>=0 && node!==masterparent)
			for(var j=0;j<node.childNodes.length;j++){
				if(node.childNodes[j].className=="submenu"){				
					node.children[j].style.display="none"; //-
					//tryhidenodes(node.childNodes[j]); //-					
					effectstack.unshift({delta:65, id:node.childNodes[j].id, grow:new Boolean(false), heightto:0});
				}
			}
			
				
	}
	//hide all the siblings of current element's parent
	//tryhideupnodes(who.parentNode, who.parentNode.parentNode);

	/*function setSizeWrapper(){
		setSize(whoid, size, 30);
	}*/
	
	//intid=setInterval(setSizeWrapper, 50);
	
	if(intid==-1)
		intid=setInterval(checkall, 30);
		
}	

// flashPopUp function 
function flashPopUp(container,magnitude)
{
    var theFlash;       
    theFlash = container.getElementsByTagName("embed")[0];           
         
    var popUpFlashHeight = 1000;
    var popUpFlashWidth = 1000; 
     
    if(theFlash.maxwidth)
    {
        popUpFlashWidth = theFlash.maxwidth;
    }
        
    if(theFlash.maxHeight)
    {
        popUpFlashheight = theFlash.maxheight;
    }     
          
    if(magnitude && theFlash.width)
    {
         popUpFlashWidth = magnitude * parseInt(theFlash.width);
    }      
    
    if(magnitude && theFlash.height)
    {
         popUpFlashHeight = magnitude * parseInt(theFlash.height);
    }      
                
    var newWindow = window.open('showFlashPopUp.aspx?flashWidth=' + popUpFlashWidth +'&flashHeight=' + popUpFlashHeight + '&flashPath=' + theFlash.src ,'Items','height='+ popUpFlashHeight + 'px,width=' + popUpFlashWidth + 'px,center=yes,scrollbars=yes,dialogHelp=no,titlebar=no',true);            
    newWindow.focus();
    newWindow.moveTo((screen.availWidth - parseInt(popUpFlashWidth))/2,(screen.availHeight - parseInt(popUpFlashHeight))/2);             
    return false;
}

function makeBigStart(container)
{
  var the_image;       
  the_image = container.getElementsByTagName("embed")[0];
  the_image.height = parseInt(the_image.height) + 20;
  the_image.width = parseInt(the_image.width) + 20;       
  if (parseInt(the_image.height) < parseInt(the_image.maxheight))
  {
        setTimeout(makeBig(the_image), 5);
  }  
}

function makeBig(item)
{
    return function()
    {
        var theImage;       
        theImage = item;
        theImage.height = parseInt(theImage.height) + 20;
        theImage.width = parseInt(theImage.width) + 20;    
         
        if (parseInt(theImage.height)< parseInt(theImage.maxheight))
        {
            setTimeout(makeBig(theImage), 5);
        }  
    }
}

function makeSmallStart(container)
{
  var the_image;  
  the_image = container.getElementsByTagName("embed")[0];
  the_image.height = the_image.height - 20;
  the_image.width = the_image.width - 20;          
  if (parseInt(the_image.height) > parseInt(the_image.minheight))
  {
    setTimeout(makeSmall(the_image),5);
  }
}

function makeSmall(item)
{
    return function()
    { 
        var the_image;  
        the_image =item;
        the_image.height = the_image.height - 20;
        the_image.width = the_image.width - 20;          
        if (parseInt(the_image.height) > parseInt(the_image.minheight))
        {
            setTimeout(makeSmall(the_image),5);
        }
     }
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

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 eraseCookie(name) {
	createCookie(name,"",-1);
}

function ShowHelpWindow(noReturn)
{
    var newWindow = window.open('UserHelp.aspx','help','height=750px,width=1000px,center=yes,scrollbars=yes,dialogHelp=no,titlebar=no',true);            
    newWindow.focus();   
    if(!noReturn)
        return false;
}

function CopyContentToDiv(sourceControlId,divControlId)
{
    var sourceControl =  document.getElementById(sourceControlId);
    var destControl  = document.getElementById(divControlId);

    destControl.innerHTML = sourceControl.value; 
    destControl.style.display = "block";
    return false;
}
 
function ShowHideControl(controlId, showVisibilty)
{
    var theControl = document.getElementById(controlId);
    if((theControl.style.display == "") || (theControl.style.display == "none"))
    {
        theControl.style.display = "block";
        if(showVisibilty) return true;
    }    
    else
    {
        theControl.style.display = "none";
        if(showVisibilty) return false;
    }    
    return false;
} 
 
