﻿// JScript File

var dragapproved=false;
var minrestore=0;
var initialwidth,initialheight;
var ie5=document.all&&document.getElementById;
var ns6=document.getElementById&&!document.all;

function iecompattest(){
    return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function drag_drop(e){
    if (ie5&&dragapproved&&event.button==1)
    {
        document.getElementById("dwindow").style.left=tempx+event.clientX-offsetx+"px";
        document.getElementById("dwindow").style.top=tempy+event.clientY-offsety+"px";
    }
    else if (ns6&&dragapproved)
    {
        document.getElementById("dwindow").style.left=tempx+e.clientX-offsetx+"px";
        document.getElementById("dwindow").style.top=tempy+e.clientY-offsety+"px";
    }
}

function initializedrag(e)
{
    offsetx=ie5? event.clientX : e.clientX;
    offsety=ie5? event.clientY : e.clientY;
    //document.getElementById("dwindowcontent").style.display="none" //extra
    tempx=parseInt(document.getElementById("dwindow").style.left);
    tempy=parseInt(document.getElementById("dwindow").style.top);

    dragapproved=true;
    document.getElementById("dwindow").onmousemove=drag_drop;
}


/*

function ShowCustomizationPage(pagename,width,height)
{
    var objpopup;
    objpopup=document.getElementById("dwindow");
    
    //Check if the popup is already created
    if(objpopup==null)
    {
        try
        {
            //For IE
            objpopup=document.createElement("<div id=\"dwindow\" style=\"z-index: 1000; position: absolute; background-color: #EBEBEB; left: 0px; top: 0px; display: none; width:500px; overflow:hidden; border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; \">");
        }
        catch(e)
        {
            //for firefox
            objpopup=document.createElement("div");
            objpopup.setAttribute("id", "dwindow");
            objpopup.setAttribute("style", "z-index: 1000; position: absolute; background-color: #EBEBEB; left: 0px; top: 0px; display: none; width:500px; overflow:hidden; border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid;");
            
//                    objpopup.onmousedown="javascript:initializedrag(event)";
//                    objpopup.onmouseup="javascript:stopdrag()";
//                    objpopup.onselectstart="javascript:return false";
            
        }
            
    }
    
    objpopup.style.display=''
    objpopup.style.width=initialwidth=width+"px"
    objpopup.style.height=initialheight=height+"px"
    objpopup.style.left="300px"
    objpopup.style.top=ns6? window.pageYOffset*1+130+"px" : iecompattest().scrollTop*1+130+"px"
    
    document.body.appendChild(objpopup);
    
    //Create the popup window
    var script;
    
    script='<table width="100%" cellpadding="0" cellspacing="0" >'
    script=script+'    <tr>'
    script=script+'        <td style="background-color:navy; color:White; width:100%; text-align:left; vertical-align:middle; height:20px; padding-left:10px;" onmousedown="initializedrag(event)" onmouseup="stopdrag()" onselectstart="return false"><B>';
    script=script+ document.title + ' - Customization';
    script=script+'        </B></td>';
    script=script+'        <td style="background-color: navy; width:100%; text-align:right; vertical-align:middle; height:20px;" onmousedown="initializedrag(event)" onmouseup="stopdrag()" onselectstart="return false">'
    
    //Check if the customization is for home page
    if(pagename=="HomePage.xml")
    {
        script=script+'            <img src="Images/close.gif" onclick="closepopup();" />'
    }
    else
    {
        script=script+'            <img src="../../Images/close.gif" onclick="closepopup();" />'
    }
    
    script=script+'        </td>'
    script=script+'    </tr>'
    script=script+'    <tr>'
    script=script+'        <td style="width: 100%; height:510px;" colspan="2" >'
    script=script+'            <div id="dwindowcontent" style="height: 100%; width:100%; overflow:hidden;">'
    script=script+'                <iframe id="cframe" src="" width="100%" height="100%" scrolling="auto" frameborder="0" marginheight="0" marginwidth="0"></iframe>'
    script=script+'            </div>'
    script=script+'        </td>'
    script=script+'    </tr>'
    script=script+'</table>'
    
    objpopup.innerHTML=script;
    
    //alert(document.getElementById("cframe").src);
    document.getElementById("cframe").src=null;
    var url;
    
    //Check if the customization is for home page
    if(pagename=="HomePage.xml")
    {
        url="WebPages/Customization/PageTemp.aspx?filename="+pagename;
    }
    else
    {
        url="../../WebPages/Customization/PageTemp.aspx?filename="+pagename;
    }
    
    document.getElementById("cframe").src=url;
    
    //Disable the background
    DisableBackground();
                
}

*/

function ShowCustomizationPage(pagename,width,height,title)
{


/*

    var objpopup;
    objpopup=document.getElementById("dwindow");
    
    //Check if the popup is already created
    if(objpopup==null)
    {
        try
        {
            //For IE
            objpopup=document.createElement("<div id=\"dwindow\" style=\"z-index: 1000; position: absolute; background-color: #EBEBEB; left: 0px; top: 0px; display: none; width:500px; overflow:hidden; border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid; \">");
        }
        catch(e)
        {
            //for firefox
            objpopup=document.createElement("div");
            objpopup.setAttribute("id", "dwindow");
            objpopup.setAttribute("style", "z-index: 1000; position: absolute; background-color: #EBEBEB; left: 0px; top: 0px; display: none; width:500px; overflow:hidden; border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid;");
            
//                    objpopup.onmousedown="javascript:initializedrag(event)";
//                    objpopup.onmouseup="javascript:stopdrag()";
//                    objpopup.onselectstart="javascript:return false";
            
        }
            
    }
    
    objpopup.style.display=''
    objpopup.style.width=initialwidth=width+"px"
    objpopup.style.height=initialheight=300+"px"
    //objpopup.style.left="300px"
    //objpopup.style.top=ns6? window.pageYOffset*1+130+"px" : iecompattest().scrollTop*1+130+"px"
    
    document.body.appendChild(objpopup);
    
    //Create the popup window
    var script;
    
    script='<table width="100%" cellpadding="0" cellspacing="0" >'
    script=script+'    <tr>'
    script=script+'        <td style="width: 100%; height:300px;" colspan="2" >'
    script=script+'            <div id="dwindowcontent" style="height: 100%; width:100%; overflow:hidden;">'
    script=script+'                <iframe id="cframe" src="" width="100%" height="100%" scrolling="auto" frameborder="0" marginheight="0" marginwidth="0"></iframe>'
    script=script+'            </div>'
    script=script+'        </td>'
    script=script+'    </tr>'
    script=script+'</table>'
    
    objpopup.innerHTML=script;
    
    //alert(document.getElementById("cframe").src);
    document.getElementById("cframe").src=null;
    var url;
    
    */
    
    //Check if the customization is for home page
    if(pagename=="HomePage.xml")
    {
        url="WebPages/Customization/PageTemp.aspx?filename="+pagename;
    }
    else
    {
        url="../../WebPages/Customization/PageTemp.aspx?filename="+pagename;
    }
    
    document.getElementById("cframe").src=url;
    
    //Call the Modal popup to display the customization window
    ShowModalPopup('dwindow',title + ' - Customization','l');
                
}


function maximize()
{
    if (minrestore==0)
    {
        minrestore=1 //maximize window
        document.getElementById("maxname").setAttribute("src","restore.gif");
        document.getElementById("dwindow").style.width=ns6? window.innerWidth-20+"px" : iecompattest().clientWidth+"px";
        document.getElementById("dwindow").style.height=ns6? window.innerHeight-20+"px" : iecompattest().clientHeight+"px";
    }
    else
    {
        minrestore=0;//restore window
        document.getElementById("maxname").setAttribute("src","max.gif");
        document.getElementById("dwindow").style.width=initialwidth;
        document.getElementById("dwindow").style.height=initialheight;
    }
    document.getElementById("dwindow").style.left=ns6? window.pageXOffset+"px" : iecompattest().scrollLeft+"px";
    document.getElementById("dwindow").style.top=ns6? window.pageYOffset+"px" : iecompattest().scrollTop+"px";
}

function closepopup()
{
    document.getElementById("cframe").contentWindow.close();
    document.getElementById("dwindowcontent").removeChild(document.getElementById("cframe"));
    document.getElementById("dwindow").style.display="none";
    document.getElementById("dwindow").innerHTML="";
    document.body.removeChild(document.getElementById("dwindow"));
    
    //Make the drop down list invisible since it is shown in front of the popup
    if(document.getElementById("copyToDropDown")!=null)
    {
        document.getElementById("copyToDropDown").style.display='inline';
    }
    if(document.getElementById("MyLibFilter")!=null)
    {
        document.getElementById("MyLibFilter").style.display='inline';
    }
        
    document.body.style.backgroundColor=orgbgcolor;
    document.getElementById("bg_image").style.display="none";

}
function closepopupandreload()
{
    closepopup('dwindow');
    //document.location.reload(true);
    ReloadPageCSSFile();
    //RefreshPage();
}

var xmlHttpObject;

function ReloadPageCSSFile()
{

    //alert("Reloading CSS");
    var objCSS;
    objCSS=document.getElementById("dynamicCSS");
    
    if(objCSS!=null)
    {
        document.body.removeChild(objCSS);
    }
    
    var obj;
    obj=document.createElement("link",obj);
    obj.setAttribute("id","dynamicCSS");
    obj.setAttribute("rel","stylesheet");
    obj.setAttribute("type","text/css");
    
    var date = new Date();
    
    var cssPageCSS;
    
    if(cssFileName=="MyProfile.css")
    {   
        var userId=document.getElementById("PageFooter_hUserId").value;
        cssPageCSS="../../CustomizedCSS/" + userId+cssFileName;
    }
    else
    {
        cssPageCSS=cssFileName;
    }
        
    obj.setAttribute("href",cssPageCSS + "?" + date.getTime());
    
    document.body.appendChild(obj);
    
    //alert("The page CSS file is changed");
    
   //GetChangedCSS();
    
}


function GetChangedCSS()
{ 
        
    xmlHttpObject=null;
    xmlHttpObject=GetXmlHttpObject();
    if (xmlHttpObject==null)
    {
        alert("Browser does not support HTTP Request.");
        return;
    } 
    
    var url="";
    url="Default.aspx"; //cssFileName;
    //url=url+"&sid="+Math.random()
    
    xmlHttpObject.onreadystatechange=stateChangedForCSS;
    
    alert(xmlHttpObject);
    xmlHttpObject.open("GET",url,true);
    xmlHttpObject.send(null);
    return false;

}

function stateChangedForCSS() 
{ 
    if (xmlHttpObject.readyState==4 )
    { 
    
        var objCSS;
        objCSS=document.getElementById("dynamicStyleSheet");
        
        if(objCSS!=null)
        {
            //objCSS.innerHTML=xmlHttpObject.responseText;
        }
        
        if(objCSS!=null)
        {
            document.body.removeChild(objCSS);
        }
        
        var obj;
        obj=document.createElement("style",obj);
        obj.setAttribute("id","dynamicStyleSheet");
        obj.setAttribute("type","text/css");
        
        //obj.setAttribute("rel","stylesheet");
        
        //obj.setAttribute("href",cssFileName);
        
        /*
        var T; 
        T = document.createTextNode(xmlHttpObject.responseText); 
        obj.children.appendChild(T); 
        */
        
        obj.styleSheet.cssText=xmlHttpObject.responseText;

        //obj.innerHTML=xmlHttpObject.responseText;
        
        document.body.appendChild(obj);
        
        alert("The page CSS file is changed.");
       
    } 
} 
     


function GetXmlHttpObject()
{ 
    var objXMLHttp=null;
    if (window.XMLHttpRequest)
    {
        objXMLHttp=new XMLHttpRequest();
    }
    else if (window.ActiveXObject)
    {
        objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    return objXMLHttp;
}


function stopdrag()
{
    dragapproved=false;
    document.getElementById("dwindow").onmousemove=null;
    document.getElementById("dwindowcontent").style.display=""; //extra
    //window.self.location=window.self.location;
}

function DisableBackgroundOld()
{
    //Code for making the background gray
    //Create empty image tag for graying out the background
    var objBlankImage;
    objBlankImage=document.getElementById("bg_image");
    
    //Check if the popup is already created
    if(objBlankImage==null)
    {
        try
        {
            //For IE
            objBlankImage=document.createElement('<img id="bg_image" style="z-index: 900; left: 0px; width: 101%; position: absolute; top: -100px; height: auto; background-color: Silver; display:none; border-right: 0px solid; border-top: 0px solid; border-left: 0px solid; border-bottom: 0px solid;">');
        }
        catch(e)
        {
            //for firefox
            objBlankImage=document.createElement("img");
            objBlankImage.setAttribute("id", "bg_image");
            //objBlankImage.setAttribute("src", "images/activetab.gif");
            objBlankImage.setAttribute("style", "z-index: 900; left: 0px; width: 100%; position: absolute; top: -100px; height: 200%; background-color: Silver; display:block; border-right: 0px solid; border-top: 0px solid; border-left: 0px solid; border-bottom: 0px solid;");
        
        }
    }
    objBlankImage.style.left=document.body.offsetLeft;    
    orgbgcolor = document.body.style.backgroundColor;
    document.body.style.backgroundColor="Silver";
    objBlankImage.style.filter="alpha(opacity=50)";
    objBlankImage.style.MozOpacity="0.5";
    objBlankImage.style.display='block';
    document.body.appendChild(objBlankImage);
    
    //Make the drop down list invisible since it is shown in front of the popup
    if(document.getElementById("copyToDropDown")!=null)
    {
        document.getElementById("copyToDropDown").style.display='none';
    }
    if(document.getElementById("MyLibFilter")!=null)
    {
        document.getElementById("MyLibFilter").style.display='none';
    }
}


function DisableBackground()
{
    //Code for making the background gray
    //Create empty image tag for graying out the background
    var objBlankImage;
    objBlankImage=document.getElementById("bg_image");
    
    //Check if the popup is already created
    if(objBlankImage==null)
    {
        try
        {
            //For IE
            objBlankImage=document.createElement('<div id="bg_image" style="z-index: 900; left: 0px; width: 100%; position: absolute; top: 0px; height: auto; background-color:#333333; display:none; border-right: 0px solid; border-top: 0px solid; border-left: 0px solid; border-bottom: 0px solid;">');
        }
        catch(e)
        {
            //for firefox
            objBlankImage=document.createElement("div");
            objBlankImage.setAttribute("id", "bg_image");
            //objBlankImage.setAttribute("src", "images/activetab.gif");
            objBlankImage.setAttribute("style", "z-index: 900; left: 0px; width: 100%; position: absolute; top: 0px; height: 100%; background-color:#333333; display:block; border-right: 0px solid; border-top: 0px solid; border-left: 0px solid; border-bottom: 0px solid;");
        }
    }
    
    //objBlankImage.style.left=document.body.offsetLeft;    
    orgbgcolor = document.body.style.backgroundColor;
    //document.body.style.backgroundColor="#333333";//"Silver";
    document.body.style.backgroundImage="";
    objBlankImage.style.filter="alpha(opacity=40)";
    //objBlankImage.style.height=document.body.clientHeight + "px";
    objBlankImage.style.MozOpacity="0.5";
    objBlankImage.style.display='block';
    document.body.appendChild(objBlankImage);
    
    
    objBlankImage.style.height=(document.body.offsetHeight)+ 10 +"px";
    
    if(document.all)
    {
	    objBlankImage.style.width=(document.body.offsetWidth)+ (document.body.offsetLeft*2)+"px";
	}
	
}

function RefreshPage()
{
    //document.body.innerHTML=document.body.innerHTML;
    document.getElementById("UpdatePanel1").innerHTML=document.getElementById("UpdatePanel1").innerHTML;
}

