﻿// JScript File 26 Sept 2007 Pritam Baldota
var CookieTimeout="";//20;
//To resize the Style dynamically-FOR - Netscape, Mozilla, IE ONLY
//Author : Pritam Baldota
//Organiztion : Lemon Design, Pune(INDIA)
function setClassStyle(style_index,classname,property,value){
var styles=document.styleSheets;
    if(styles)
    {
        {
            var rules=styles[style_index].cssRules?styles[style_index].cssRules:styles[style_index].rules;
            if(rules)
            {
                for(var j=0;j<rules.length;j++)
                {
                    var class_name=rules[j].selectorText.toLowerCase().replace(/\./g,'');
                    if(class_name==classname.toLowerCase())
                    {
						rules[j].style[property]=value+"px";
                    }
                }
            }
        }
    }
}



//Apply Resize script to set position
function setPos(Postback)
{
    var ex=document.getElementById("CX").value;
    var ey=document.getElementById("CY").value;
    var offset=50;
    var wid=(ex)-parseInt(document.getElementById("internalWindow").style.left)-offset;
    var hei=(ey)-parseInt(document.getElementById("internalWindow").style.top);
    
   if((wid-25)>425)
   {
       setClassStyle(0,"ContentBgQA","width",wid-25);
       setClassStyle(0,"ContentBg","width",wid-25);
   }
   else
   {
       setClassStyle(0,"ContentBgQA","width",425);
       setClassStyle(0,"ContentBg","width",425);
   }
   
   // For all GridView and Note Tasks URL Items GridView's WIDTH
   if((wid-65)>390)
   {
       setClassStyle(0,"MoonGrid","width",wid-65)
       setClassStyle(0,"MoonChildGrid","width",wid-65) 
       var newwid=(wid-65)-300;
       setClassStyle(0,"NoteTaskLink","width",newwid) 
   }
   else
   {
       setClassStyle(0,"MoonGrid","width",390)
       setClassStyle(0,"MoonChildGrid","width",390) 
       setClassStyle(0,"NoteTaskLink","width",260) 
   }
   
    //For Favrite Grid
   if((wid-45)>390)
   {
       var newwid=(wid-45)-95;
       setClassStyle(0,"FavLink","width",newwid) 
   }
   else
   {
       setClassStyle(0,"FavLink","width",295) 
   }   
   /*For File Grid*/
  if((wid-45)>390)
   {
       var newwid=(wid-45)-250;
       setClassStyle(0,"FileLink","width",newwid) 
   }
   else
   {
       setClassStyle(0,"FileLink","width",150) 
   }  
   /*for All GridsWidth*/
   if((hei/2)>210)
   {
       setClassStyle(0,"ContentBg","height",hei/2);
   }
   else
   {
        setClassStyle(0,"ContentBg","height",210);
   }
   /*for Scroll div*/
   if(((hei/2)-20)>200)
   {
       setClassStyle(0,"scroll","height",(hei/2)-20) 
   }
   else
   {
       setClassStyle(0,"scroll","height",200)
   }
   
    /*for Multiline text and SingleLine Text*/
    if((wid-45)>325)
    {
        var textWidth=(wid-45)-100;
        setClassStyle(0,"PanelMultilineTextField","width",textWidth)
        setClassStyle(0,"PanelUrlLabel","width",textWidth)
        
       
        textWidth=(wid-45)-120;
        setClassStyle(0,"AutoHeight","width",textWidth) 
        textWidth=(wid-45)-250;
        
        setClassStyle(0,"PanelTextField","width",textWidth) 
        setClassStyle(0,"PanelInstruction","width",textWidth)
        setClassStyle(0,"Dropdown","width",textWidth) 
    }
    else
    {
          setClassStyle(0,"PanelMultilineTextField","width",250) 
          setClassStyle(0,"PanelTextField","width",180) 
          setClassStyle(0,"PanelInstruction","width",250) 
          setClassStyle(0,"AutoHeight","width",310)
          setClassStyle(0,"Dropdown","width",150) 
    }
   
    /*For Panel Instruction */
    if((wid-45)>288)
    {
        var textWidth=(wid-45)-28;
        setClassStyle(0,"PanelInstruction","width",textWidth) 
    }
    else
    {
        setClassStyle(0,"PanelInstruction","width",288) 
    }
    
    //Update the Server variables to maintain positions
	if(Postback==true)
	{
	   //SetMoonPosition(); 
	   SetPosition();
	}
}

var maxZIndex = 0;
//
function ZIndex()
{
	var allElems = document.getElementsByTagName?document.getElementsByTagName("*"):document.all; // or test for that too
	
	for(var i=0;i<allElems.length;i++) {
	var elem = allElems[i];
	var cStyle = null;
	if (elem.currentStyle) {cStyle = elem.currentStyle;}
	else if (document.defaultView && document.defaultView.getComputedStyle) {
	cStyle = document.defaultView.getComputedStyle(elem,"");
	}
	var sNum;
	if (cStyle) {
	sNum = Number(cStyle.zIndex);
	} else {
	sNum = Number(elem.style.zIndex);
	}
	if (!isNaN(sNum)) {
	maxZIndex = Math.max(maxZIndex,sNum);
	}
	}

}

var PrevPoss="";
	function SavePosition()
	{
			var ele=document.getElementById("internalWindow");
			var Wid=xWidth(ele);
			var Hei=xHeight(ele);
			var left=xLeft(ele);;
			var top=xTop(ele);
			
			PrevPoss=left+"$$"+top+"$$"+Wid+"$$"+Hei;//+"$$"+GetMoonVisibilityValue();

	}
	
function SetPosition()
	{
		SavePosition();
		document.getElementById("ctl00_Test1_PostionHidden").value=PrevPoss;
		__doPostBack("ctl00_Test1_PnlMoonNavigator",document.getElementById("ctl00_Test1_PostionHidden").value+"");
	}
	
function RestoreMoon()
{
	var hiddValue=document.getElementById("ctl00_Test1_PostionHidden");
	/*if(hiddValue.value=="")
	{
		//For First load of Page in Browser.
		visible(0,'ctl00_Test1_PnlHelpMain');
	}
	*/
	try{
	var myarr=hiddValue.value.split("$$");
			document.getElementById("internalWindow").style.width=myarr[2]+"px";//"500px";
			document.getElementById("internalWindow").style.height=myarr[3]+"px";//"450px";
			document.getElementById("internalWindow").style.left= myarr[0]+"px";//"100px";
			document.getElementById("internalWindow").style.top=myarr[1]+"px";//"100px";
			document.getElementById("innerTable").style.height=(parseInt(document.getElementById("internalWindow").style.height)-90)+"px";
			document.getElementById("trs").style.height=parseInt(document.getElementById("innerTable").style.height)-150+"px";
			var add=parseInt(myarr[2])+parseInt(myarr[0]);
			document.getElementById("CX").value=add;
			add=add=parseInt(myarr[3])+parseInt(myarr[1]);
			document.getElementById("CY").value=add;
			//Set the visibility status of the moon
			//SetMoonVisibilityValue(myarr[4]);
			TriggerMoonEvent();
			setPos(false);
	}catch(err)
	{
	 
	}
}

function RestorePrev()
	{
	
			var myarr=PrevPoss.split("$$");
			document.getElementById("internalWindow").style.width=myarr[2]+"px";//"500px";
			document.getElementById("internalWindow").style.height=myarr[3]+"px";//"450px";
			document.getElementById("internalWindow").style.left= myarr[0]+"px";//"100px";
			document.getElementById("internalWindow").style.top=myarr[1]+"px";//"100px";
			document.getElementById("innerTable").style.height=(parseInt(document.getElementById("internalWindow").style.height)-90)+"px";
			document.getElementById("trs").style.height=parseInt(document.getElementById("innerTable").style.height)-150+"px";
			var add=parseInt(myarr[2])+parseInt(myarr[0]);
			document.getElementById("CX").value=add;
			add=add=parseInt(myarr[3])+parseInt(myarr[1]);
			document.getElementById("CY").value=add;
			setPos(false);
	}
	
	function MaxPos()
	{
			SavePosition();
			document.getElementById("internalWindow").style.left="0px";
			document.getElementById("internalWindow").style.top="0px";
			document.getElementById("internalWindow").style.width=xClientWidth();
			document.getElementById("internalWindow").style.height=xClientHeight();
			document.getElementById("innerTable").style.height=(parseInt(document.getElementById("internalWindow").style.height)-90)+"px";
			document.getElementById("trs").style.height=parseInt(document.getElementById("innerTable").style.height)-150+"px";
			document.getElementById("CX").value=xClientWidth();
			document.getElementById("CY").value=xClientHeight();
			setPos(false);
			
	}
	
/* 
    Functions to maintain moon's visibility state 
    Author : Pritam Baldota
    Company: Lemon Design Pune(INDIA)
*/
function ToggleMoonVisibilityState(triggerEvent)
{
    if(Get_Cookie("UserLoggedIn")==null || Get_Cookie("UserLoggedIn")==false)
    {
        Delete_Cookie("MyMoonVisibilityStatus","/","");
        document.getElementById("myMoonButton").style.display="none";
        document.getElementById("internalWindow").style.display="none";
        return true;
    }
try{

        var CookVal=Get_Cookie("MyMoonVisibilityStatus");
        if(CookVal=="block" || CookVal==null)
        {
            Set_Cookie("MyMoonVisibilityStatus","none",CookieTimeout,"/","","");
        }
        else if(CookVal=="none")
        {
            Set_Cookie("MyMoonVisibilityStatus","block",CookieTimeout,"/","","");
        }
        }catch(err){
            Set_Cookie("MyMoonVisibilityStatus","none",CookieTimeout,"/","","");
        }
        if(triggerEvent==true)
        {
            TriggerMoonEvent();            
        }
       
}

function GetMoonVisibilityValue()
{
    return Get_Cookie("MyMoonVisibilityStatus");
}
function SetMoonVisibilityValue(val)
{
    if(val=="none" || val=="block")
    {
        Set_Cookie("MyMoonVisibilityStatus",val,CookieTimeout,"/","","");   
    }
    else 
    {
        Set_Cookie("MyMoonVisibilityStatus","none",CookieTimeout,"/","","");
    }
}
function TriggerMoonEvent()
{
    if(Get_Cookie("MyMoonVisibilityStatus")==null)
    {
        document.getElementById("internalWindow").style.display="none";
        document.getElementById("myMoonButton").style.display="none";
        Set_Cookie("MyMoonVisibilityStatus","none",CookieTimeout,"/","","");
    }
    else
    {
        if(Get_Cookie("UserLoggedIn")!=null)
        {
            //Check for Valid Session
            if(IsValidSession()==true)
            {
             document.getElementById("myMoonButton").style.display="block";
             document.getElementById("internalWindow").style.display=Get_Cookie("MyMoonVisibilityStatus");
            }else
            {
                LogoutUser();
            }
        }
        else
        {
        document.getElementById("myMoonButton").style.display="none";
        document.getElementById("internalWindow").style.display="none";
        }
    }
}

function LoginUser(sid)
{
    //Set the Login Cookie
    Set_Cookie("UserLoggedIn","true",CookieTimeout,"/","","");
    Set_Cookie("Session",sid,CookieTimeout,"/","","");
    if(Get_Cookie("MyMoonVisibilityStatus")==null)
    {
        Set_Cookie("MyMoonVisibilityStatus","none",CookieTimeout,"/","","");
    }
}
function LogoutUser()
{
      Delete_Cookie("UserLoggedIn","/","");
      Delete_Cookie("MyMoonVisibilityStatus","/","");
      Delete_Cookie("Session","/","");
}

/****
Session Maintain
****/
function IsValidSession()
{
    if(Get_Cookie("Session")==CurrentSession())
    {
        return true;
    }
    return false;
}

function GetSessionCookie()
{
    return Get_Cookie("Session");
}
function CurrentSession()
{
    if(document.getElementById("ctl00_SessionHid").value);
    return document.getElementById("ctl00_SessionHid").value;
}
function SetCurrentSession(sid)
{
    if(Get_Cookie("Session")==null)
    {
        Set_Cookie("Session",sid,CookieTimeout,"/","","");
    }
    else
    {
        if(Get_Cookie("Session")!=CurrentSession())
        {
            LogoutUser();
        }
    }
}