﻿// JScript File

    var LastChild=null;
    var LastEle=null;
    var LastClass='';    
	
	/*function popChild(ele,status)
	{	
		var Child=ele.getElementsByTagName("ul")[0];
		if (status=true) {
			Child.style.display='';}
		else 
			{alert(ele);Child.style.display='none';}
	}*/
	
    function toggle(ele,left,width,e,className)
    {	
		var target=(typeof(e.target)=='undefined'?e.srcElement:e.target);
		if(target.tagName.toLowerCase()=='a') return;
	
		//alert(target.tagName.toLowerCase());
		if(ele.getElementsByTagName ("ul")==null) return; 
        try
        {
            if(LastEle!=ele) LastEle.className=LastClass + "-down";
        }
        catch (e) {} 
        
        var Child=ele.getElementsByTagName ("ul")[0];
        
        if(Child.style.display!="none")
            {ShowHide(ele,false,left,width,e);
            ele.className=className + "-down";}
        else
            {ShowHide(ele,true,left,width,e);
            ele.className=className + "-up";}
            
            LastEle=ele;
            LastClass=className;
    }

    function ShowHide(ele,Show,left,width,e)
    {   
    
     try
        {
        if(LastChild!=Child) LastChild.style.display='none';}
        catch (e) {alert(e.message);}
        
        
        var Child=ele.getElementsByTagName ("ul")[0];
        
        if(typeof Child=='undefined') return false;
        
        if(Show==true)
        {
            //if(LastChild==Child) {return false;}
            //setMenuPosition(Child,left,width);
            Child.style.display="";
            var currHeight=parseInt(Child.offsetHeight)-3;
            LastChild=Child;
            showChildElements(Child,false);
            increaseHeight(currHeight,0);
            //storLastActiveMenu(ele);
        }
        else
            Child.style.display='none';
        
        //return cancelEventBubbling(e);
    }
    function showChildElements(ele,isShow)
    {   var childElements=ele.getElementsByTagName("li");
    
        for(var Index=0;Index<childElements.length;Index++)
        {
            childElements[Index].style.display=isShow?"":"none";
        }
    }
    
    function increaseHeight(currHeight,heightIndex)
    {
        try
        {
            LastChild.style.height=heightIndex + "px";
            
            if(heightIndex<currHeight)
            {
                heightIndex+=30;
                heightIndex=heightIndex>=currHeight?currHeight:heightIndex;
                setTimeout("increaseHeight(" + currHeight + "," + heightIndex +")",30);
            }
            else
            {
                showChildElements(LastChild,true);
            }
         }
         catch(e)
         {
            //alert(e.message);
         }
    }
    function setMenuPosition(ele,left,width)
    {   
        //set element width
        if(width==null){}//do nothing
        else if(width=="full")
        {
            ele.style.width=(parseInt(document.body.offsetWidth)+parseInt(document.body.offsetLeft))-findAbcPos(ele)[0]-4 + "px";
        }
        else {ele.style.width=width + "px";}
       
        //set element left position
        if(left!=null)
        {
            ele.style.left=parseInt(left) + parseInt(document.body.offsetLeft) + "px";
        }
        
    }
    function setIFrameHeight(ele)
    {
        ele.style.height=parseInt(ele.document.body.offsetHeight) + parseInt(ele.document.body.scrollHeight) + 10 + "px";
    }
    function findAbcPos(obj)
    {
        var curLeft=curTop=0;
        if(obj.offsetParent)
        {
            curLeft=obj.offsetLeft;
            curTop=obj.offsetTop;
            while(obj=obj.offsetParent)
            {
                curLeft+=obj.offsetLeft;
                curTop+=obj.offsetTop;
            }
        }
        return [curLeft,curTop];
    }

function getEventObject(e)
{
    if(!e)
        return window.event;
    else
        return e;
    
}
function cancelEventBubbling(e)
{
	if (e.cancelBubble) e.cancelBubble=true;
	if (e.preventDefault) e.preventDefault();
	if (e.stopPropagation) e.stopPropagation();
	
	e.returnValue=false;
}
function ShowProfileInfo(eleID,usr)
{
var ele=document.getElementById(eleID);
    ele.src="SelectedProfileInfo.aspx?username="+ usr;
  /*  ele.style.display='';*/
}
function ShowMe(ele)
{

    if(ele.src=="")
    {
        ele.style.display='none';
    }
    else
        ele.style.display='';
}

//----------------------------------------[Avik-->for opening last active menu]----------------------------------------
function showLastActiveMenu(defaultMenuId)
{
    var activeMenuId=null;//readCookie("activeMenuId");
    if(activeMenuId!=null)
    {
        LastEle=document.getElementById(activeMenuId);
        var className=LastEle.className.split("-")[0];
        //toggle(activeMenu,null,null,null,activeMenu.className.split("-")[0]);
    }
    else
    {
        LastEle=document.getElementById(defaultMenuId);
        var className=LastEle.className.split("-")[0];
    }
    
    LastEle.className=className + "-up";
    LastChild=LastEle.getElementsByTagName("ul")[0];
    LastChild.style.display="";
    LastClass=className;
}
function storLastActiveMenu(ele)
{
    if(ele!=null) createCookie("activeMenuId",ele.id,1);
}

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 openReadMoreWindow(strURL,e)
{   
      window.open(strURL);
	  cancelEventBubbling(e)
}
