/*
    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 preventDrag(event) {
    if (event.type == 'dragenter' || event.type == 'dragover' || event.type == 'drop' || event.type == 'dragstart' || event.type == 'drag') {
        if (event.stopPropagation) //(Mozilla)
        {
            event.preventDefault();
            event.stopPropagation();
        }
        return false; //(IE)
    }
}

function handleErr(msg,url,l)
{
    txt="Line Number="+ l  + "$#$#Errormessage=" + msg + " $#Method Name=" + method +"$#$# URL:" + url;
    if(method!='noTrace')
        ClickHandler.LogError(txt);
    return true
}

//
// 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;
}


function pause(numberMillis) {
    method = "pause";
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	
	while (true) {
		now = new Date();
		if (now.getTime() > exitTime)
			return;
	}
}

//
// 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,fName,imgAttribute)
{
    method = "showLightbox";
	// prepare objects
	//frmWidth = parent.frames["Left"].width;
	//resize the description frame to take the whole screen
	parent.document.getElementById("main").cols="100%,*";

	//get the objects for loading the cropping interface
	// var objwrapper = document.getElementById('weather-info');
	var objOverlay = document.getElementById('overlay');
	
	

	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0px';
	objOverlay.style.left = '0px';
 	objOverlay.style.width = '100%';
 	
 	//$('overlay').setStyle({height:screen.height +'px'});
 	objOverlay.style.height = '100%'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = '90';
	
	//objwrapper.appendChild(objOverlay);
	var objLightbox = document.getElementById('lightbox');

	objLightbox.style.width = 'auto';
	
	//	 objwrapper.appendChild(objLightbox);
	
	var objLoadingImage = document.getElementById('loadingImage');
//	var objFrameVideo = document.getElementById('videolightboxFrame');
//	objFrameVideo.style.display="none";
	var objFrame = document.getElementById('lightboxFrame');
	objFrame.style.display='block';
	
	// 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
	
	//starts of the update code
	
    var frameWidth = orgWidth + 5;
	var minFrameWidth = 244;
	var addFrameHeight = 50;
	
	
	if(imgAttribute!=null)
	{
	    if((imgAttribute.minWidth < imgAttribute.maxWidth) || (imgAttribute.minHeight < imgAttribute.maxHeight))
	    {
	        minFrameWidth = 275;
	        addFrameHeight = 70;
	    }
	}  
	else
	{
	   var myImgObj = ClickHandler.GetImageAttributes(tempid.toString(),ImgContainer).value;
	   
	   if(myImgObj == null)
	   {
	    minFrameWidth = 275;
	    addFrameHeight = 70;
	   }
	    
	    else
	    {
	        if((myImgObj.MinWidth < myImgObj.MaxWidth) || (myImgObj.MinHeight < myImgObj.MaxHeight))
	        {
	            minFrameWidth = 275;
	            addFrameHeight = 70;
	        }
	    }
	}
	
	if(frameWidth < minFrameWidth)
	    frameWidth = minFrameWidth;
		    
	objFrame.width = (frameWidth) + 'px';
	objFrame.height = (orgHeight + addFrameHeight) + 'px';
	
	var h = (orgHeight + addFrameHeight);
	var w = frameWidth ;
	
	//end of the updated code
	
	//start of the old code
//	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 ;
	
	//end of the old code
	
	if(h < arrayPageSize[3])	
	    var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	else
	    var lightboxTop = arrayPageScroll[1] + ((h - arrayPageSize[3]) / 2);
	 //var lightboxTop = pageScroll.y + (pageSize.winHeight / 5)
	var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
	
	
	
	objLightbox.style.left = lightboxLeft+'px';
	//objLightbox.setStyle({left:lightboxLeft+'px'});
	objLightbox.style.top = lightboxTop+'px';
	//objLightbox.setStyle('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/crop.aspx";
    else
        Cropsrc = "../Private/crop.aspx";
    
     var additionalArg = "";
     if(imgAttribute!= null)
        additionalArg = "&minW=" + imgAttribute.minWidth + "&minH = " + imgAttribute.minHeight + "&maxW=" + imgAttribute.maxWidth + "&maxH=" + imgAttribute.maxHeight; 
    
    if(parent.frames["description"].IsLargeImage != null && parent.frames["description"].IsLargeImage)
        objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid + additionalArg + "&ShowLarge=Large" + "&alt=" + fName ;
    else
    	objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid + additionalArg + "&alt=" + fName;

	//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';
	
	hideSWFObjects();

}

//
// 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.document.getElementById("main").cols="*,245";
	showSWFObjects();

}

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');
	
	var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();

	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 || uAgent.toLowerCase().indexOf("safari") != -1)
 	 {
 	    objOverlay.style.height = (screen.height + parent.frames.description.document.documentElement.offsetHeight) + 'px';
 	 }
 	else
 	    objOverlay.style.height = (screen.height + 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 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');
	
		objLoadingImage.style.left = imgLeft + 'px';
		objLoadingImage.style.display = 'block';
	}
	
	hideSWFObjects();
}

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';
	showSWFObjects();
	
}

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');

	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)
	        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;
	objLightbox.style.top = lightboxTop;
	
	
	
    //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/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';
	hideSWFObjects();
}
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;
	objLightbox.style.top = lightboxTop;
	
	
	
    //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';
hideSWFObjects();

}

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";
	showSWFObjects();
}

function hideIFramePages()
{
     method = "hideLightbox";
	// get objects
	var objOverlay = document.getElementById('overlay');
	var objLightbox = document.getElementById('lightbox');
	var objFrame = document.getElementById('lightboxFrame');
	
	// hide lightbox and overlay
	objOverlay.style.display = 'none';
	objLightbox.style.display = 'none';
	objFrame.src = "about:blank";
	
	// resize the frame back
	//parent.document.getElementById("main").cols="*,245";
showSWFObjects();
}


function showIFramePages(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 = '90';
	//objOverlay.style.opacity= 0.5;
	
	//new Effect.Appear(objOverlay, { duration:0.2, from: 0, to: 0.8 });
	
	
	var objLightbox = document.getElementById('lightbox');
	objLightbox.style.width = 'auto';
	
	
	
	var objFrame = document.getElementById('lightboxFrame');
//	var objFrameVideo = document.getElementById('videolightboxFrame');
//	objFrameVideo.style.display="none";
	
	// 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.style.display = 'block';
	objFrame.src = pageSrc;
//	objFrame.scrolling = "auto";

		
	// After crop interface is loaded, update the overlay height as the crop interface might have
	// increased the overall page height.
	//arrayPageScroll = getPageScroll();
	objOverlay.style.height = (screen.height + arrayPageSize[1]) + 'px';

	//display the crop interface
	objLightbox.style.display = 'block';
	objLightbox.style.zIndex = 500;
	
	objFrame.style.zIndex = 500;
	
	hideSWFObjects();
	
//	var fObj = document.getElementById('flashObj');
//	if(fObj != null)
//	    fObj.style.visibility='hidden';
//	

}


function hideSWFObjects()
{
//    var objs = document.getElementsByTagName("div");
//    for(i=0;i<objs.length;i++)
//    {
//        if(objs[i].id.indexOf("_SWF")>-1)
//        {
//         
//            if(objs[i].innerHTML.toLowerCase().indexOf("<object")>-1)
//                objs[i].style.display="none";
//        }
//    }
//    var player;
//    try{
//     player=$f(0);  
//    if(player != null) 
//        player.unload();
//   }
//   catch(e)
//   {
//    player = null;
//   }
}

function showSWFObjects()
{
//    var objs = document.getElementsByTagName("div");
//    for(i=0;i<objs.length;i++)
//    {
//        if(objs[i].id.indexOf("_SWF")>-1)
//        {
//         
//            if(objs[i].innerHTML.toLowerCase().indexOf("<object")>-1)
//                objs[i].style.display="block";
//        }
//    }
}

//Slider
function showLightboxForSlider(imgSrc,maxWidth,maxHeight,ImgContainer,orgWidth,orgHeight,imgAttribute)
{
    method = "showLightboxForSlider";
 // prepare objects
 //frmWidth = parent.frames["Left"].width;
 //resize the description frame to take the whole screen
 parent.document.getElementById("main").cols="100%,*";

 //get the objects for loading the cropping interface
 // var objwrapper = document.getElementById('weather-info');
 var objOverlay = document.getElementById('overlay');
 
 

 objOverlay.style.position = 'absolute';
 objOverlay.style.top = '0px';
 objOverlay.style.left = '0px';
  objOverlay.style.width = '100%';
  
  //$('overlay').setStyle({height:screen.height +'px'});
  objOverlay.style.height = '100%'; //(arrayPageScroll[1] + 'px');
 objOverlay.style.zIndex = '90';
 
 //objwrapper.appendChild(objOverlay);
 var objLightbox = document.getElementById('lightbox');

 objLightbox.style.width = 'auto';
 
 //  objwrapper.appendChild(objLightbox);
 
 var objLoadingImage = document.getElementById('loadingImage');
 var objFrame = document.getElementById('lightboxFrame');
 objFrame.style.display='block';
 
 // 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
 
 //starts of the update code
 
    var frameWidth = orgWidth + 5;
 var minFrameWidth = 244;
 var addFrameHeight = 80;
 
 
 if(imgAttribute!=null)
 {
     if((imgAttribute.minWidth < imgAttribute.maxWidth) || (imgAttribute.minHeight < imgAttribute.maxHeight))
     {
         minFrameWidth = 275;
         addFrameHeight = 100;
     }
 }  
 else
 {
    var myImgObj = ClickHandler.GetImageAttributes(tempid.toString(),ImgContainer).value;
    
    if(myImgObj == null)
    {
     minFrameWidth = 275;
     addFrameHeight = 100;
    }
     
     else
     {
         if((myImgObj.MinWidth < myImgObj.MaxWidth) || (myImgObj.MinHeight < myImgObj.MaxHeight))
         {
             minFrameWidth = 275;
             addFrameHeight = 100;
         }
     }
 }
 
 if(frameWidth < minFrameWidth)
     frameWidth = minFrameWidth;
      
 objFrame.width = (frameWidth) + 'px';
 objFrame.height = (orgHeight + addFrameHeight) + 'px';
 
 var h = (orgHeight + addFrameHeight);
 var w = frameWidth ;
 
 //end of the updated code
 
 //start of the old code
// 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 ;
 
 //end of the old code
 
 if(h < arrayPageSize[3]) 
     var lightboxTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
 else
     var lightboxTop = arrayPageScroll[1] + ((h - arrayPageSize[3]) / 2);
  //var lightboxTop = pageScroll.y + (pageSize.winHeight / 5)
 var lightboxLeft = ((arrayPageSize[0] - 20 - w) / 2);
 
 
 
 objLightbox.style.left = lightboxLeft+'px';
 //objLightbox.setStyle({left:lightboxLeft+'px'});
 objLightbox.style.top = lightboxTop+'px';
 //objLightbox.setStyle('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/crop.aspx";
    else
        Cropsrc = "../Private/crop.aspx";
    
     var additionalArg = "";
     if(imgAttribute!= null)
        additionalArg = "&minW=" + imgAttribute.minWidth + "&minH = " + imgAttribute.minHeight + "&maxW=" + imgAttribute.maxWidth + "&maxH=" + imgAttribute.maxHeight; 
    if(typeof(ImgContainer) == "object")
        additionalArg =additionalArg + "&imgContObj=" + ImgContainer.id;
    if(parent.frames["description"].IsLargeImage != null && parent.frames["description"].IsLargeImage)
        objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid + additionalArg + "&ShowLarge=Large";
    else
     objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid + additionalArg;

 //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 OpenLinkInLightBox(page) {
           var fol = ClickHandler.getSiteFolder();
//            var imageThumbFolder = ClickHandlerAdmin.getImageThumbNailFolder(filename);

    method = "OpenLinkInLightBox";
    if (ClickHandler.getIsIndex(TemplateId))
        openPageInLightBox(fol.value + '/' + page);
    else
        // openPageInLightBox('../' + page);
        openPageInLightBox(page);
        //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;
}


// open page in lightbox
// added by santosh
function openPageInLightBox(pageSrc) {
    method = "openPageInLightBox";
    var isIndex = ClickHandler.getIsIndex(TemplateId).value;
    pageSrc = pageSrc.toLowerCase();
    if (isIndex == false)
        pageSrc = "../" + pageSrc;
    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();
	
	try
	{
	  objFrame.height = parseInt(arrayPageSize[1])  ;
//	  objLightbox.height = parseInt(arrayPageSize[1]) + 100 ;
//	  objOverlay.height = parseInt(arrayPageSize[1]) + 100 ;
	}
	catch(e)
	{
	}
	
 
	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
//	{
//	objFrame.height = '900px';	
//	objFrame.width = '880px';
//	
//	var h = 560;
//	var w = 840;
//	}
   	var h = 310;
   	var w = 880;
	
	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

// method to close the lightbox at public end
function hideLightboxInPublic() {

 
     method = "hideLightboxInPublic";
     try{    
     
     // 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)
	{

	}

}
function openImageInLightBox(imgSrc) {

    method="openImageInLightBox";
    imgSrc = imgSrc.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'; 
            }   
        }
        var tempid = parent.frames["description"].TemplateId;
        var res = ClickHandler.getIsIndex(tempid).value;
        
        var objLightbox = document.getElementById('lightbox');
        objLightbox.style.width = 'auto';
        
        if(document.getElementById('closeDiv') != null)
        {
            objLightbox.removeChild(document.getElementById('closeDiv'));
        }
        //make close button
        var closeDiv = document.createElement('div');
        closeDiv.setAttribute('id','closeDiv');
        closeDiv.setAttribute('style','position:absolute;right:5px;top:5px;');
        var closeAnc = document.createElement('a');
        closeAnc.setAttribute('href','javascript:void(0);');
        closeAnc.setAttribute('onclick','hideLightbox()');
        var closeImg = new Image();
        if(res)
            closeImg.setAttribute('src','Images/cancel.png');
        else
            closeImg.setAttribute('src','../Images/cancel.png');
        closeAnc.appendChild(closeImg);
        closeDiv.appendChild(closeAnc);  
        objLightbox.appendChild(closeDiv);
        
	    //get the DOM objects for loading the page in lightbox
	    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%'; 
	    objOverlay.style.zIndex = 0;
    	
	    	
    	
    	
	    var objLoadingImage = document.getElementById('loadingImage');
	    var objFrame = document.getElementById('lightboxFrame');

	    // read the page size, window size and the scrolled position
	    var arrayPageSize = getPageSize();
	    var arrayPageScroll = getPageScroll();
    	
	    try
	    {
	      objFrame.height = '500';
	    }
	    catch(e)
	    {
	    }
    	
     
	    objOverlay.style.display = 'block';
    	
	    // center loadingImage if the loading image is set

		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);
	    }
    	
        var h = 510;
   	    var w = 480;
    	
	    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(res)
            imgSrc = imgSrc.replace("../","");
        // Setting source of the iframe   
        objFrame.src = imgSrc;
        
        if (navigator.appVersion.indexOf("MSIE")==-1){
            objFrame.style.padding = '20px';
            objFrame.style.background = '#FFF';
        }
        else{
            objFrame.style.paddingRight = '20px';
            objFrame.style.paddingBottom = '20px';
            objFrame.style.paddingLeft = '10px';
            objFrame.style.paddingTop = '10px';
        }

	    //hide the busy status
	    if (objLoadingImage) {	
		    objLoadingImage.style.display = 'none';  
	    }		
	    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)
	{
	   
	}
}
