﻿    /*
    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=null;



var orgWidth =1024;
var orgHeight = 650;
var objFrame = null;

//
// 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;
	}
}


function initLightBoxForExtActivityList()
{
    orgWidth =1004;
    orgHeight = 600;
    objFrame = document.getElementById('lightboxFrame');
    var otherFrame = document.getElementById('lightboxFrameActivity');
    if( otherFrame != null )
        otherFrame.style.display='none';
}

function initLightBoxForActivity()
{
    orgWidth =344;
    orgHeight = 390;
    objFrame = document.getElementById('lightboxFrameActivity');
}



function initLightBoxReport(type)
{
    if( type == "ExtEffect")
    {
        orgWidth = 960;
        orgHeight = 600;
        objFrame = document.getElementById('lightBoxExtEffect');
        if( document.getElementById("lightboxFrame")!=null)
            document.getElementById('lightboxFrame').style.display = 'none';        
    }
    else
    {
        orgWidth =1004;
        orgHeight = 600;
        objFrame = document.getElementById('lightboxFrame');
        if( document.getElementById("lightBoxExtEffect")!=null)
            document.getElementById('lightBoxExtEffect').style.display = 'none';      
    }

}
function initLightBoxSettings(type)
{
    if( type == "User")
    {
        orgWidth = 330;
        orgHeight = 209;
        objFrame = document.getElementById('lightboxUser');       
        
    }
    else if( type == "Membership")
    {
        orgWidth = 330;
        orgHeight = 239;
        objFrame = document.getElementById('lightboxUser');       
        
    }
    else if( type == "Objective")
    {
        orgWidth = 324;
        orgHeight = 170;
        objFrame = document.getElementById('lightboxUser');       
        
    }
}

///for superadmin
function initLightBoxForUser(type)
{

    if( type=='SuperAdmin')
    {
        orgWidth =600;
        orgHeight = 500;
        objFrame = document.getElementById('lightboxFrame');
        document.getElementById("lightboxAddCustomer").style.display='none';
        document.getElementById("lightboxEditUser").style.display='none';
        document.getElementById("lightboxAddUser").style.display='none';
        
    }
    else if( type=='Report')
    {
        orgWidth =900;
        orgHeight = 550;
        objFrame = document.getElementById("lightboxAddCustomer");
        document.getElementById("lightboxEditUser").style.display='none';
        document.getElementById("lightboxAddUser").style.display='none';
    }
    else if( type=='Customer')
    {
        orgWidth =350;
        orgHeight = 409;
        objFrame = document.getElementById("lightboxAddCustomer");
        document.getElementById("lightboxEditUser").style.display='none';
        document.getElementById("lightboxAddUser").style.display='none';
    }
    else if( type=='EditUser')
    {
        orgWidth =420;
        orgHeight = 505;
        objFrame = document.getElementById("lightboxEditUser");
        document.getElementById("lightboxAddCustomer").style.display='none';
        document.getElementById("lightboxAddUser").style.display='none';
    }
    else if(type == 'AddUser')
    {
        orgWidth =332   ;
        orgHeight = 231;
        objFrame = document.getElementById("lightboxAddUser");
        document.getElementById("lightboxAddCustomer").style.display='none';
        document.getElementById("lightboxEditUser").style.display='none';
        
    }
        
    
    //objFrame = document.getElementById('lightboxFrame');
}

function initLightBox(strMode)
{
    if(strMode == "CategoryDetail")
    {
        orgWidth=800;
        orgHeight=600;
    }
    
    else if(strMode == "LargeImage")
    {
        orgWidth=250;
        orgHeight=385;
    }
    
      else if(strMode == "ExpressInterest")
    {
        orgWidth=600;
        orgHeight=500;
    }
    
    objFrame = document.getElementById("lightboxFrame");
}


function initLightBoxExpress()
{
   
        orgWidth=600;
        orgHeight=500;
  
    
    objFrame = document.getElementById("lightboxFrame");

}


function initLightBoxLargeImage()
{
   
        orgWidth=250;
        orgHeight=385;
  
    
    objFrame = document.getElementById("lightboxFrame");

}

//
// showLightbox()
// Calculates the height and width of the crop interface and opens it in iframe then centers and displays.
//


function viewdetails(description) {


            

}


function showLightbox(imgSrc)
{


    if( objFrame == null)
	    objFrame = document.getElementById('lightboxFrame');	    
    
  
        
        
    method = "showLightbox";

	var objOverlay = document.getElementById('overlay');
		

	objOverlay.style.position = 'absolute';
	objOverlay.style.top = '0px';
	objOverlay.style.left = '0px';
 	objOverlay.style.width = '100%';
 	
 	objOverlay.style.height = '100%'; //(arrayPageScroll[1] + 'px');
	objOverlay.style.zIndex = '90';

	var objLightbox = document.getElementById('lightbox');

	objLightbox.style.width = 'auto';	


	var objLoadingImage = document.getElementById('loadingImage');
	
	if( objFrame == null)
	    objFrame = document.getElementById('lightboxFrame');	
    
    
    if(objFrame.id == 'lightboxFrame')
    {
        var frame = document.getElementById('lightBoxFrameActivity');
        if( frame != null)
            frame.style.display = 'none';
    }
    else
    {
        if( document.getElementById('lightboxFrame') != null)   
            document.getElementById('lightboxFrame').style.display = 'none';
    }
    
		
    //set iframe scrolling property
//    if( orgWidth==1024)
//    {
//        objFrame.scrolling="auto";        
//    }
//    else
//        objFrame.scrolling="no";
        
        
	// read the page size, window size and the scrolled position
	var arrayPageSize = getPageSize();
	var arrayPageScroll = getPageScroll();

	objOverlay.style.display = 'block';



	if (navigator.appVersion.indexOf("MSIE")!=-1){
		pause(250);
	}
    var frameWidth = orgWidth;
	var minFrameWidth = 244;
	var addFrameHeight = 80;

//	
	if(frameWidth < minFrameWidth)
	    frameWidth = minFrameWidth;
		    
	objFrame.width = (frameWidth) + 'px';
	///changed later
	
	objFrame.height = (orgHeight) + 'px';
	
	var h = (orgHeight + addFrameHeight);
	var w = frameWidth ;
	
	//changd later	
	var frameWidth = orgWidth + 5;
	
	if(frameWidth < 224)
	    frameWidth = 224;
		    	
	var h = (orgHeight + 83);
	var w = frameWidth ;
		
	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';
	////    	objFrame.src = Cropsrc + "?img=" + imgSrc + "&cropw=" + maxWidth + "&croph=" + maxHeight + "&imgw=" + orgWidth + "&imgh=" + orgHeight + "&imgCont=" + ImgContainer + "&templateid=" + tempid + additionalArg;

	  objFrame.src = imgSrc ;	

    objFrame.style.display='block';


	arrayPageSize = getPageSize();

	objOverlay.style.height = (arrayPageSize[1] + 'px');


	objLightbox.style.display = 'block';

}






//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function 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) 
	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;
	
    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 showLoading()
{ 
	var objLoadingImage = document.getElementById('ajaxLoading');
	
    var arrayPageSize = getPageSize();
    var arrayPageScroll = getPageScroll();


	var h = "25";	    
	var w = "100";
		
	var imgTop = arrayPageScroll[1] + ((arrayPageSize[3] -  h) / 2);
	var imgLeft = ((arrayPageSize[0] - 20 - w) / 2);
	

	// 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';
	}	
}

function hideLoading()
{
   
	var objLoadingImage = document.getElementById('ajaxLoading');    
	objLoadingImage.style.display = 'none';
	
}


