/*
    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()
	

*/


//
// 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()
{
     method = "getPageScroll";
	var yScroll;

    
	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); 
	    method = null; 
	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(){
		 method = "getPageSize";
	var xScroll, yScroll;

	
	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) ;
	    method = null; 
	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;
	}
	    method = null; 
}

//
// 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%,*";

	//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');
	
	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.height = (screen.height + arrayPageScroll[1]) + 'px';
	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;
	objLightbox.style.zIndex = 100;
	
	
    //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;

	//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';
    method = null; 
}*/

function showLightbox(imgSrc,maxWidth,maxHeight,ImgContainer,orgWidth,orgHeight,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 if(typeof(ImgContainer) != "object")
	{
	  
	   
	   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';
	objFrame.height = (orgHeight + 83) + '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&ref=" + Math.random();
    else
    	objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid + additionalArg + "&ref=" + Math.random();

	//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();
    method = null; 
}

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%';

 	 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();
    method = null; 	
}

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
	if(typeof(objOverlay) != "undefined")
	    objOverlay.style.display = 'none';
	    
	if(typeof(objLoadingImage) != "undefined")
	    objLoadingImage.style.display = 'none';
	//showSWFObjects();
	    method = null; 
}

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 = 10000;
	
	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 = 10000;
	objFrame.style.zIndex = 10000;
    method = null; 
    
   // hideSWFObjects();
}


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';

}

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';


}


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 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";
        }
    }
}