/*
    Reference taken from the site 
	
	    by Lokesh Dhakar - http://www.huddletogether.com
    
    and updated as per requiremet for the CMS: Image Cropping, Websearch Professional Pvt. Ltd

	Table of Contents
	-----------------
	Configuration
	
	Functions
	- getPageScroll()
	- getPageSize()
	- pause()
	- getKey()
	- listenKey()
	- showLightbox()
	- hideLightbox()
	- initLightbox()
	- addLoadEvent()
	

*/

//Error Handling

onerror=handleErr
var method;



function handleErr(msg,url,l)
{
try {
    txt="Line Number="+ l  + "$#$#Errormessage=" + msg + " $#Method Name=" + method +"$#$# URL:" + url;
    ClickHandler.LogError(txt);
    return true
}
catch (er) {
        
    }
}

//
// Configuration
//

//image to display the busy status
var loadingImage = new Image();
loadingImage.src = '../Private/images/loading.gif';	    	
var savingImage = new Image();
savingImage.src = '../Private/images/saving.gif';		    		
var frmWidth;
//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll()
{
 
	var yScroll;
    method = "getPageScroll";
    
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	 method = "getPageSize";
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//
// pause(numberMillis)
// Pauses code execution for specified time. Uses busy code, not good.
// Code from http://www.faqts.com/knowledge_base/view.phtml/aid/1602
//
function pause(numberMillis) {
    method = "pause";
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//for opening signup page
function makemyControlVisible() {
    if (document.getElementById("divLgControl") != null) {
        document.getElementById("divLgControl").style.display = "block";
    if(document.getElementById("divSignup")!=null)
        document.getElementById("divSignup").style.display = "block";
    }
}
function openPageInLightBoxForSignUp(pageSrc) {

    method = "openPageInLightBox";
    pageSrc = pageSrc.toLowerCase();
    try {
        // to hide all the videos and flash as well
        var embed = document.getElementsByTagName('object');
        if (embed != null) {
            for (var i = 0; i < embed.length; i++) {
                embed[i].style.display = 'none';
                embed[i].style.visibility = 'hidden';
            }

        }

        if (document.getElementById("divLgControl") != null) {
            document.getElementById("divLgControl").style.display = "none";
            document.getElementById("divSignup").style.display = "none";
        }
        //get the DOM objects for loading the page in lightbox
        var objOverlay = document.getElementById('Pageoverlay');
        objOverlay.style.position = 'absolute';
        objOverlay.style.top = '0';
        objOverlay.style.left = '0';
        objOverlay.style.width = '100%';
        objOverlay.style.height = '90%';
        objOverlay.style.zIndex = 0;

        var objLightbox = document.getElementById('Pagelightbox');

        objLightbox.style.width = 'auto';

        var objLoadingImage = document.getElementById('PageloadingImage');
        var objFrame = document.getElementById('PagelightboxFrame');

        // read the page size, window size and the scrolled position
        var arrayPageSize = getPageSize();
        var arrayPageScroll = getPageScroll();

        objOverlay.style.display = 'none';

        // center loadingImage if the loading image is set
        objLoadingImage.src = '../../Private/images/loading.gif';
        objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
        objLoadingImage.style.left = (((arrayPageSize[0] - objLoadingImage.width) / 2) + 'px');
        objLoadingImage.style.display = 'block';


        // A small pause between the image loading and displaying is required with IE,
        // this prevents the previous image displaying for a short burst causing flicker.
        if (navigator.appVersion.indexOf("MSIE") != -1) {
            pause(250);
        }

        // IMPORTANT FOR DESIGNERS
        //setting the height and width of the iframe in which to display the page

        if (pageSrc.indexOf('publicuser') > -1) {
            objFrame.height = '900px';
            objFrame.width = '880px';

            var h = 560;
            var w = 840;
        }
        else if (pageSrc.indexOf('justsignin') > -1 || pageSrc.indexOf('publiclogin') > -1) {
            objFrame.height = '310px';
            objFrame.width = '880px';

            var h = 250;
            var w = 840;
        }
        else if (pageSrc.indexOf('userprofile') > -1) {
            objFrame.height = '900px';
            objFrame.width = '880px';

            var h = 560;
            var w = 840;
        }

        else if (pageSrc.indexOf('memberinformation') > -1) {
            objFrame.height = '750px';
            objFrame.width = '880px';
            var h = 460;
            var w = 840;

        }

        else {
            objFrame.height = '900px';
            objFrame.width = '880px';

            var h = 560;
            var w = 840;
        }

        var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] - h) / 2);
        var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);

        objLightbox.style.left = lightboxLeft + "px";
        objLightbox.style.top = lightboxTop + "px";


        // Setting source of the iframe   
        objFrame.src = pageSrc;
        //hide the busy status
        if (objLoadingImage) {
            objLoadingImage.style.display = 'none';
        }


        arrayPageSize = getPageSize();
        objOverlay.style.height = (arrayPageSize[1] + 'px');

        //display the dimmed interface
        objLightbox.style.display = 'block';
     }
    catch (e) {

    }
}
//end of signup page
// open page in lightbox
// added by santosh
function openPageInLightBox(pageSrc)
{

    method="openPageInLightBox";
     pageSrc = pageSrc.toLowerCase();
    try
    {       
    // to hide all the videos and flash as well
    var embed = document.getElementsByTagName('object');
    if(embed != null)
    {
    for(var i=0; i <embed.length;i++)
    {
        embed[i].style.display = 'none';   
         embed[i].style.visibility = 'hidden'; 
    }  
        
    }
    
    
	//get the DOM objects for loading the page in lightbox
	var objOverlay = document.getElementById('Pageoverlay');
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90%'; 
	objOverlay.style.zIndex = 0;
	
	var objLightbox = document.getElementById('Pagelightbox');

	objLightbox.style.width = 'auto';	
	
	var objLoadingImage = document.getElementById('PageloadingImage');
	var objFrame = document.getElementById('PagelightboxFrame');
	
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
 
	objOverlay.style.display = 'block';
	
	// center loadingImage if the loading image is set
	    objLoadingImage.src = '../../Private/images/loading.gif';
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';

	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	// IMPORTANT FOR DESIGNERS
	//setting the height and width of the iframe in which to display the page
	
	if(pageSrc.indexOf('publicuser')>-1)
	{
    objFrame.height = '900px';	
	objFrame.width = '880px';
	
	var h = 560;
	var w = 840;
	}
	else if(pageSrc.indexOf('justsignin')>-1 || pageSrc.indexOf('publiclogin')>-1)
	{
	    objFrame.height = '310px';	
	    objFrame.width = '880px';
    	
	    var h =250;
	    var w = 840;
	}
	else if(pageSrc.indexOf('userprofile')>-1)
	{
	    objFrame.height = '900px';	
	    objFrame.width = '880px';
	
      	var h = 560;
	    var w = 840;	    
	}

	else if (pageSrc.indexOf('memberinformation') > -1) 
{
	    objFrame.height = '750px';
	    objFrame.width = '880px';
	    var h = 460;
	    var w = 840;
	
	}

	else
	{
	objFrame.height = '900px';	
	objFrame.width = '880px';
	
	var h = 560;
	var w = 840;
	}
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	objLightbox.style.left = lightboxLeft + "px";
	objLightbox.style.top = lightboxTop + "px";


 // if fryshuset main site and browser is firefox, hide the iframe first
    var isSubProject = ClickHandler.getIsSubProject().value;
     if(isSubProject == false)
     {     

           if(navigator.userAgent.toLowerCase().indexOf('firefox')>-1)
           {

                if(pageSrc.indexOf('justsignin')>-1)
{


                    objFrame.style.display = 'none';
}             
           }
     }
	   

    // Setting source of the iframe   
    objFrame.src = pageSrc;
	    
	
	

	

	//hide the busy status
	if (objLoadingImage) {	
		objLoadingImage.style.display = 'none';  
	}		


	arrayPageSize = getPageSize();	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the dimmed interface
	objLightbox.style.display = 'block';

	// Hide all flash while opening form in the lightbox
    if($("div[id$='_SWF']") != null)
    {
    $("div[id$='_SWF']").each(
    function(n)
    {
        $(this).hide();
    }
   )
   }
	
	}
	catch(e)
	{
	    	
	}
}
// method to close the lightbox at public end
function hideLightboxInPublic()
{
     method = "hideLightboxInPublic";
     try{    
      makemyControlVisible();
     // to show all the videos and flash as well
    var embed = document.getElementsByTagName('object');
    if(embed != null)
    {
    for(var i=0; i <embed.length;i++){
        embed[i].style.display = 'block';
        embed[i].style.visibility = 'visible';       
        }
    }
     
    
  
   
   
	// get objects
	objOverlay = document.getElementById('Pageoverlay');
	if(objOverlay == null)
	    objOverlay = parent.document.getElementById('Pageoverlay');
	    
	objLightbox = document.getElementById('Pagelightbox');	
	if(objLightbox == null)
	 objLightbox = parent.document.getElementById('Pagelightbox');
	   
	
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';


    var gControlUpdate;
    if(typeof(IsSigningUpdateRequiredOnClosingLightBox) == "undefined")
        gControlUpdate = window.parent.IsSigningUpdateRequiredOnClosingLightBox;
    else
        gControlUpdate = IsSigningUpdateRequiredOnClosingLightBox;
        
    if(gControlUpdate)
     {       
        if(typeof(IsSigningUpdateRequiredOnClosingLightBox) == "undefined")
            window.parent.IsSigningUpdateRequiredOnClosingLightBox=false;
        else
            gControlUpdate = IsSigningUpdateRequiredOnClosingLightBox=false;
       
         if(parent.window.document.getElementById("signinsignout1_signin")!=null)
         {            
           parent.window.document.getElementById("signinsignout1_signin").style.display ="none";
           parent.window.document.getElementById("signinsignout1_join").style.display ="none";
           parent.window.document.getElementById("signinsignout1_signout").style.display ="block";
           parent.window.document.getElementById("signinsignout1_username").style.display ="block";
            parent.window.document.getElementById("signinsignout1_username").innerHTML = "V&auml;lkommen " + ClickHandler.GetCurrentUserName().value;
         }
         else
         {   
            
          var signincontrolsElems = parent.window.document.getElementsByTagName('a');
              if (!FindSignInControlAndUpdate(signincontrolsElems)) {
                 signincontrolsElems = parent.window.parent.document.getElementsByTagName('a');
                 FindSignInControlAndUpdate(signincontrolsElems);
             }
         }
       }
       
       // finally emptying the source of the iframe 
       var objFrame = document.getElementById('PagelightboxFrame');
       if(objFrame != null)
        objFrame.src = "";

 // to show the flash objects 
     if($("div[id$='_SWF']")   != null)
     {
        $("div[id$='_SWF']").each(
        function(n)
        {
            $(this).show();
        }   
       ) 
     }
       
	}
	catch(e)
	{
	
	}

if(parent.document.getElementById("MemberAlbum1_txtAuthorName")!=null)
 {
     var publicUserInfo=ManageAlbumHandler.GetLoginPublicUserInfo();
     if(publicUserInfo!=null && typeof(publicUserInfo)=="object")
        {
             parent.document.getElementById("MemberAlbum1_txtAuthorName").value=publicUserInfo.value.Rows[0].UserName;
             parent.document.getElementById("MemberAlbum1_txtEmail").value=publicUserInfo.value.Rows[0].UserEmail;
             if(parent.document.getElementById("profileImage")!=null)
                    parent.document.getElementById("profileImage").src=publicUserInfo.value.Rows[0].MemberImage;
            }
    }
 

}
//show light box for user upload image
function openPageInLightBoxForImageUpload(pageSrc)
{
 
   var stuMember=ClickHandler.GetIsAuthenticated();
  if(stuMember.value==false && pageSrc!="publicuser.aspx")
    {
         pageSrc ="../JustSignIn.aspx";
      }
    method="openPageInLightBox";
    
    pageSrc = pageSrc.toLowerCase();
    
	//get the DOM objects for loading the page in lightbox
	var objOverlay = document.getElementById('Pageoverlay');
	if(objOverlay==null)
         objOverlay = parent.document.getElementById('Pageoverlay');
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90%'; 
	objOverlay.style.zIndex = 0;
	
	var objLightbox = document.getElementById('Pagelightbox');
        if(objLightbox==null)
        objLightbox = parent.document.getElementById('Pagelightbox');
	objLightbox.style.width = 'auto';	
	
	var objLoadingImage = document.getElementById('Pageloading');
	if(objLoadingImage==null)
    	objLoadingImage = parent.document.getElementById('Pageloading');
	var objFrame = document.getElementById('PagelightboxFrame');
	if(objFrame==null)
	    objFrame = parent.document.getElementById('PagelightboxFrame');

	var objClose = document.getElementById('PagebtnClose');
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();
 
	objOverlay.style.display = 'block';
	
	// center loadingImage if the loading image is set
	    objLoadingImage.src = '../../Private/images/loading.gif';
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';

	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	// IMPORTANT FOR DESIGNERS
	//setting the height and width of the iframe in which to display the page
	objFrame.height = '600px';	
	objFrame.width = '880px';
	var h = 590;
	var w = 840;
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	objLightbox.style.left = lightboxLeft + "px";
	objLightbox.style.top = lightboxTop + "px";
    // Setting source of the iframe   
    objFrame.src = pageSrc;
	//hide the busy status
	if (objLoadingImage)
	 {	
		objLoadingImage.style.display = 'none';  
	}		
	arrayPageSize = getPageSize();	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the dimmed interface
	objLightbox.style.display = 'block';
	if (objClose != null)
	    objClose.style.display = 'block';
}
function hideLightboxUploadImage()
{
     method = "hideLightboxUpload";
     
     try{    
	// get objects
	objOverlay = document.getElementById('Pageoverlay');
	if(objOverlay == null)
	    objOverlay = parent.document.getElementById('Pageoverlay');
	    
	objLightbox = document.getElementById('Pagelightbox');	
	if(objLightbox == null)
	 objLightbox = parent.document.getElementById('Pagelightbox');
            var objClose = document.getElementById('PagebtnClose'); 
	
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	if (objClose != null)
	    objClose.style.display = 'none';
       
       // finally emptying the source of the iframe 
       var objFrame = document.getElementById('PagelightboxFrame');
       if(objFrame != null)
        objFrame.src = "";
       
	}
	catch(e)
	{
	   alert(e.message);
	}

}

//end of light box , Puru

function FindSignInControlAndUpdate(signincontrolsElems) {
    var isFound = false;
    for (var counter = 0; counter < signincontrolsElems.length; counter++) {
        if (signincontrolsElems[counter] != null && signincontrolsElems[counter].id != "undefined") {
            if (signincontrolsElems[counter].id.indexOf('signinsignout1_signin') > -1) {
                isFound = true;
                signincontrolsElems[counter].style.display = "none";
            }

            if (signincontrolsElems[counter].id.indexOf('signinsignout1_join') > -1)
                signincontrolsElems[counter].style.display = "none";

            if (signincontrolsElems[counter].id.indexOf('signinsignout1_signout') > -1)
                signincontrolsElems[counter].style.display = "block";

            if (signincontrolsElems[counter].id.indexOf('signinsignout1_username') > -1) {
                signincontrolsElems[counter].innerHTML = "V&auml;lkommen " + ClickHandler.GetCurrentUserName().value;
                signincontrolsElems[counter].style.display = "block";
            }
        }
    }
    return isFound;  

}

//
// showLightbox()
// Calculates the height and width of the crop interface and opens it in iframe then centers and displays.
//
function showLightbox(imgSrc,maxWidth,maxHeight,ImgContainer,orgWidth,orgHeight)
{


    method = "showLightbox";
	// prepare objects
	//frmWidth = parent.frames["Left"].width;
	//resize the description frame to take the whole screen

	//parent.frames["main"].cols="100%,*";
	parent.document.getElementById("main").cols="100%,*";
    var isSubSite = ClickHandler.getIsSubProject().value;
    
	//get the objects for loading the cropping interface
	var objOverlay = document.getElementById('overlay');

	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90%'; // screen.height + 'px'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = 0;
	
	var objLightbox = document.getElementById('lightbox');
	objLightbox.style.width = 'auto';
	
	
	
	var objLoadingImage = document.getElementById('loadingImage');
	var objFrame = document.getElementById('lightboxFrame');
	
	
	// loading image to display the busy status
	//objLoadingImage.src = loadingImage;
	
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

    var tempid = parent.frames["description"].TemplateId;
    var res = ClickHandler.getIsIndex(tempid);
 
 
	objOverlay.style.display = 'block';
	
	// center loadingImage if the loading image is set
	if (objLoadingImage) {
	    if(res.value && !isSubSite)
	        objLoadingImage.src = 'Private/images/loading.gif';	
	    else
	        objLoadingImage.src = '../Private/images/loading.gif';
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}
	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	//setting the height and width of the iframe in which to display the cropping page : crop.aspx
	objFrame.height = (orgHeight + 100) + 'px';
	
	var frameWidth = orgWidth + 5;
	
	if(frameWidth < 224)
	    frameWidth = 224;
		    
	objFrame.width = (frameWidth) + 'px';
	
	var h = (orgHeight + 100);
	var w = frameWidth ;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	objLightbox.style.left = lightboxLeft + "px";
	objLightbox.style.top = lightboxTop + "px";
	
	
	
    //setting the source page for cropping: crop.aspx
    //It takes 6 parameters:
    // * img : the image source file to be cropped
    // * cropw : the width to be cropped, generally set to the maximum width of the panel, read from the parameter passed to this function as maxWidth
    // * croph : the height to be cropped, generally set to the maximum height of the panel, read from the parameter passed to this function as maxHeight
	
	if(orgWidth < maxWidth)
	    maxWidth = orgWidth;
	
	if (orgHeight < maxHeight)
	    maxHeight = orgHeight;
	   
	imgSrc = imgSrc.replace("../../../","../");

   
    if(res.value && !isSubSite)
        Cropsrc = "Private/crop.aspx";
    else
        Cropsrc = "../Private/crop.aspx";

	objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid;

	//hide the busy status
	if (objLoadingImage) {	
		objLoadingImage.style.display = 'none';  
	}
			
	// After crop interface is loaded, update the overlay height as the crop interface might have
	// increased the overall page height.

	arrayPageSize = getPageSize();
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the crop interface
	objLightbox.style.display = 'block';

}

//
// hideLightbox()
// hides the crop interface and resize the main frame back to normal
//

function hideLightbox()
{

     method = "hideLightbox";
	// get objects
	objOverlay = document.getElementById('overlay');
	objLightbox = document.getElementById('lightbox');
	
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	
	// resize the frame back
	parent.frames["main"].cols="*,254";

}

function hideLoading()
{
     method = "hideLoading";
     
	// get objects
	if(parent.document.getElementById("main") != null && rightMenuOpened)
	{
	    if(parent.frames["Left"].location.href != "about:blank")
	        parent.document.getElementById("main").cols="*,254";
	}
	objOverlay = document.getElementById('overlay');
	var objLoadingImage = document.getElementById('loadingImage');
    window.status="Done";
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLoadingImage.style.display = 'none';
	
}

var rightMenuOpened = false;
function showLoading()
{
     method = "showLoading";
	 // prepare objects
 
 //resize the description frame to take the whole screen
 //frmWidth = parent.frames["Left"].width;
 
 var myFrame = parent.document.getElementById("main");
 if(myFrame != null && typeof(myFrame) != "undefined")
 {
    if(myFrame.cols != "100%,*")
         rightMenuOpened = true;
    else
        rightMenuOpened = false; 
    myFrame.cols="100%,*";
 }
 
    
 //get the objects for loading the cropping interface
 var objOverlay = document.getElementById('overlay');
 //var objLightbox = document.getElementById('lightbox');
 var objLoadingImage = document.getElementById('loadingImage');
 
 objOverlay.style.position = 'absolute';
 objOverlay.style.top = '0';
 objOverlay.style.left = '0';
  objOverlay.style.width = '100%';
  ///debugger;
   var uAgent =  navigator.userAgent;
   if(uAgent.indexOf("Firefox") != -1)
   {
      objOverlay.style.height = (screen.height + parent.frames.description.document.documentElement.offsetHeight) + 'px';
   }
  else
      objOverlay.style.height = screen.height + myFrame.document.body.scrollHeight + 'px'; //(arrayPageScroll[1] + 'px');
 
 // loading image to display the busy status
 
 var tempid = parent.frames["description"].TemplateId;
    var res = ClickHandler.getIsIndex(tempid);
    if(res.value)
      savingImage.src = 'Private/images/saving.gif'; 
       
 objLoadingImage.src = savingImage.src;
 window.status="Saving...";
 
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();


 var h = savingImage.height ;
     
 var w = savingImage.width ;
 
 var imgTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
 var imgLeft = ((arrayPageSize[0] - 20 - w) / 2);
 


//display the overlay
 objOverlay.style.display = 'block';
 

 // read the page size, window size and the scrolled position

 // center loadingImage if the loading image is set
 if (objLoadingImage) {
  objLoadingImage.style.top = imgTop + 'px'; //(arrayPageScroll[1] + (Math.round((screen.height + savingImage.height) / 2)-222) + 'px');
//  if(screen.width >1024)
//      objLoadingImage.style.left = ((Math.round((screen.width + savingImage.width) / 2)-200) + 'px');
//  else
//      objLoadingImage.style.left = ((Math.round((screen.width + savingImage.width) / 2)-100) + 'px');
  
  objLoadingImage.style.left = imgLeft + 'px';
  objLoadingImage.style.display = 'block';
 }
	
	
}



function showIFramePages2(pageSrc,pageHeight,pageWidth)
{
    method = "showIFramePages";

	//get the objects for loading the cropping interface
	var objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90'; //screen.height + 'px'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = 0.5;
	
	var objLightbox = document.getElementById('lightbox');
	objLightbox.style.width = 'auto';
	
	
	
	var objFrame = document.getElementById('lightboxFrame');
	
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.display = 'block';
	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	//setting the height and width of the iframe in which to display the cropping page : crop.aspx
	objFrame.height = (pageHeight + 35) + 'px';
	objFrame.width = (pageWidth + 2) + 'px';
	var h = (pageHeight + 35 );
	var w = (pageWidth + 2) ;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	objLightbox.style.left = lightboxLeft+'px';
	objLightbox.style.top = lightboxTop+'px';
	
	
	objFrame.src = pageSrc;

		
	// After crop interface is loaded, update the overlay height as the crop interface might have
	// increased the overall page height.

	arrayPageSize = getPageSize();
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the crop interface
	objLightbox.style.display = 'block';
	objLightbox.style.zIndex = 500;
	objFrame.style.zIndex = 500;

}
function showLightboxForInherit(imgSrc,maxWidth,maxHeight,ImgContainer,orgWidth,orgHeight,info)
{

     method = "showLightbox";
 	// prepare objects
	//frmWidth = parent.frames["Left"].width;
	//resize the description frame to take the whole screen
	parent.frames["main"].cols="100%,*";

	//get the objects for loading the cropping interface
	var objOverlay = document.getElementById('overlay');
    var isSubSite = ClickHandler.getIsSubProject().value;
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90%'; // screen.height + 'px'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = 0;
	
	var objLightbox = document.getElementById('lightbox');
	objLightbox.style.width = 'auto';
	
	
	
	var objLoadingImage = document.getElementById('loadingImage');
	var objFrame = document.getElementById('lightboxFrame');
	
	
	// loading image to display the busy status
	//objLoadingImage.src = loadingImage;
	
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

    var tempid = parent.frames["description"].TemplateId;
    var res = ClickHandler.getIsIndex(tempid);
 
 
	objOverlay.style.display = 'block';
	
	// center loadingImage if the loading image is set
	if (objLoadingImage) {
	    if(res.value && !isSubSite)
	        objLoadingImage.src = 'Private/images/loading.gif';	
	    else
	        objLoadingImage.src = '../Private/images/loading.gif';
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}
	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	//setting the height and width of the iframe in which to display the cropping page : crop.aspx
	objFrame.height = (orgHeight + 83) + 'px';
	
	var frameWidth = orgWidth + 5;
	
	if(frameWidth < 224)
	    frameWidth = 224;
		    
	objFrame.width = (frameWidth) + 'px';
	
	var h = (orgHeight + 83);
	var w = frameWidth ;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	objLightbox.style.left = lightboxLeft + "px";
	objLightbox.style.top = lightboxTop + "px"; 
	
	
	
    //setting the source page for cropping: crop.aspx
    //It takes 6 parameters:
    // * img : the image source file to be cropped
    // * cropw : the width to be cropped, generally set to the maximum width of the panel, read from the parameter passed to this function as maxWidth
    // * croph : the height to be cropped, generally set to the maximum height of the panel, read from the parameter passed to this function as maxHeight
	
	if(orgWidth < maxWidth)
	    maxWidth = orgWidth;
	
	if (orgHeight < maxHeight)
	    maxHeight = orgHeight;
	   
	imgSrc = imgSrc.replace("../../../","../");

   
    if(res.value && !isSubSite)
        Cropsrc = "Private/crop.aspx";
    else
        Cropsrc = "../Private/crop.aspx";
    
	objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid +"&myInfo="+info ;

	//hide the busy status
	if (objLoadingImage) {	
		objLoadingImage.style.display = 'none';  
	}
			
	// After crop interface is loaded, update the overlay height as the crop interface might have
	// increased the overall page height.

	arrayPageSize = getPageSize();
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the crop interface
	objLightbox.style.display = 'block';

}
function multipleShowLightbox(imgSrc,maxWidth,maxHeight,orgWidth,orgHeight,templateId,duplicateOf,containerId)
{

    method = "showLightbox";
   	// prepare objects
	//frmWidth = parent.frames["Left"].width;
	//resize the description frame to take the whole screen
	if(parent.frames["main"]!=null)
parent.frames["main"].cols="100%,*";

	//get the objects for loading the cropping interface
	var objOverlay = document.getElementById('Moverlay');
    
	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0';
	objOverlay.style.left = '0';
 	objOverlay.style.width = '100%';
 	objOverlay.style.height = '90%'; // screen.height + 'px'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = 0;
	
	var objLightbox = document.getElementById('Mlightbox');
	objLightbox.style.width = 'auto';
	var objLoadingImage = document.getElementById('MloadingImage');
	var objFrame = document.getElementById('MlightboxFrame');
	objFrame.src=null;
	
	// loading image to display the busy status
	//objLoadingImage.src = loadingImage;
	
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

   // var tempid = parent.frames["description"].TemplateId;
  //  var res = ClickHandler.getIsIndex(tempid);
 	objOverlay.style.display = 'block';
	
	// center loadingImage if the loading image is set
	if (objLoadingImage) {
//	    if(res.value)
//	        objLoadingImage.src = 'Private/images/loading.gif';	
//	    else
	        objLoadingImage.src = '../Private/images/loading.gif';
		objLoadingImage.style.top = (arrayPageScroll[1] + ((arrayPageSize[3] - 35 - objLoadingImage.height) / 2) + 'px');
		objLoadingImage.style.left = (((arrayPageSize[0] - objLoadingImage.width) / 2) + 'px');
		objLoadingImage.style.display = 'block';
	}
	
	// A small pause between the image loading and displaying is required with IE,
	// this prevents the previous image displaying for a short burst causing flicker.
	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
	
	//setting the height and width of the iframe in which to display the cropping page : crop.aspx
	objFrame.height = (orgHeight + 83) + 'px';
	
	var frameWidth = orgWidth + 5;
	
	if(frameWidth < 224)
	    frameWidth = 224;
		    
	objFrame.width = (frameWidth) + 'px';
	
	var h = (orgHeight + 83);
	var w = frameWidth ;
	
	var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	objLightbox.style.left = lightboxLeft + "px";
	objLightbox.style.top = lightboxTop + "px";
	
	
	
    //setting the source page for cropping: crop.aspx
    //It takes 6 parameters:
    // * img : the image source file to be cropped
    // * cropw : the width to be cropped, generally set to the maximum width of the panel, read from the parameter passed to this function as maxWidth
    // * croph : the height to be cropped, generally set to the maximum height of the panel, read from the parameter passed to this function as maxHeight
	
	if(orgWidth < maxWidth)
	    maxWidth = orgWidth;
	
	if (orgHeight < maxHeight)
	    maxHeight = orgHeight;
	   
	imgSrc = imgSrc.replace("../../../","../");

   
//    if(res.value)
//        Cropsrc = "Private/MultipleCrop.aspx";
//    else
if(templateId==null)
    Cropsrc = "../Private/WidgetMultipleCrop.aspx";
else

        Cropsrc = "../Private/MultipleCrop.aspx";
    
	objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight +"&templateid=" + templateId +"&duplicateOf="+duplicateOf+ "&containerId="+containerId;

	//hide the busy status
	if (objLoadingImage) {	
		objLoadingImage.style.display = 'none';  
	}
			
	// After crop interface is loaded, update the overlay height as the crop interface might have
	// increased the overall page height.

	arrayPageSize = getPageSize();
	
	objOverlay.style.height = (arrayPageSize[1] + 'px');

	//display the crop interface
	objLightbox.style.display = 'block';


}

function hideMultipleLightbox()
{
     method = "hideMultipleLightbox";
	// get objects
	objMultpleOverlay = document.getElementById('Moverlay');
	objMultplLightbox = document.getElementById('Mlightbox');
	
	// hide lightbox and overlay
	objMultpleOverlay.style.display = 'none';
	objMultplLightbox.style.display = 'none';
	// resize the frame back
	if(parent.frames["main"]!=null)
	parent.frames["main"].cols="*,254";
}

function OpenLinkInLightBox(page) {
    method = "OpenLinkInLightBox";
    if (IsRootPage(page))
        openPageInLightBox('../' + page);
    else
        openPageInLightBox('../' + ClickHandler.getFolder().value + '/' + page);
}
// If Page is located at root then subfolder will not be needed, So expand this logic as per your need.
function IsRootPage(page) {
    if (page.toLowerCase().indexOf('publicuser.aspx') > -1)
        return true;
    else 
        return false;
}
