
var isIE = navigator.appVersion.match(/MSIE/) == "MSIE";

var disabledWin = {

	elementsBlock : [],
	
	overlayAll : false,

	pathImage : "/images/common/indicator_big.gif",
	
	backgroundColor : "#E1E1E1",

	nameBlockDisabled : "Overlay",
	
	nameBlockDisabledConcat : [],
	
	setElementsBlock : function(value){ 
		
		var insert = true;
		if(this.elementsBlock.length>0){
			for(i=0; i<this.elementsBlock.length; i++){
				if(this.elementsBlock[i]==value){
					insert = false;
					break;
				}
			}
			if(insert){
				this.elementsBlock.unshift(value);
				this.nameBlockDisabledConcat.unshift("Overlay_"+value);
			}
		}else{
			this.elementsBlock.unshift(value);
			this.nameBlockDisabledConcat.unshift("Overlay_"+value);
		}
		
		//debug(this.elementsBlock);
		//debug(this.nameBlockDisabledConcat);
		 
	},
	
	getElementsBlock : function(){ return this.elementsBlock; },
	
	setPathImage : function(value){ this.pathImage = value; },
	
	getPathImage : function(){ return this.pathImage; },
	
	setBackgroundColor : function(value){ this.backgroundColor = value; },
	
	getBackgroundColor : function(){ return this.backgroundColor; },
	
	getArraryConcat : function() {	return this.nameBlockDisabledConcat;  },
	
	getId : function() {	return this.nameBlockDisabled;  },
	
	show : function(modal, load){
		
		if(arguments.length == 3){
			this.setElementsBlock(arguments[2]);
		}else{
			this.overlayAll = true;
		}
			
		if(typeof load == 'undefined')
			load = false;
			
		this.disableScreen(this.getId(), load);
		
	},
	
	hide : function(element){
	
		if(typeof element == 'undefined'){
			if($(this.getId())){
				new Element.remove(this.getId());
				this.overlayAll = false;
				return false;
			}
		}
				
		if(this.elementsBlock.length > 0){
			if($('Overlay_'+element)){
				new Element.remove('Overlay_'+element);
				if(this.elementsBlock.indexOf(element)>=0){
					this.elementsBlock 						= this.elementsBlock.without(element);
					this.nameBlockDisabledConcat	= this.nameBlockDisabledConcat.without("Overlay_"+element);
				}
			}
		}
			
	},

	disableScreen : function(overlayId, load){
		
		if(this.overlayAll){
		
			var objBody		= document.getElementsByTagName("body").item(0);
			this.initLightboxWithObject(objBody, load, overlayId);
			var pageSize	= this.getPageSizeWithObject(objBody);
			
			var objOverlay							= $(overlayId);
			// set height of Overlay to take up whole page and show
			objOverlay.style.top 				= '0';
			objOverlay.style.left 			= '0';
			objOverlay.style.height 		= (pageSize.pageHeight + 'px');
			objOverlay.style.width 			= (pageSize.windowWidth + 'px');
			objOverlay.style.display 		= 'block';	
			
			return false;
			
		}
		
		var a_setToBlock = this.getElementsBlock();
		if(a_setToBlock.length > 0){
		
			var a_nameToBlock = this.getArraryConcat();
			for(i=0; i<a_setToBlock.length; i++){
				
				this.initLightboxWithObject(a_setToBlock[i], load, a_nameToBlock[i]);
				var pageSize = this.getPageSizeWithObject(a_setToBlock[i]);
				
				var objOverlay 						= $(a_nameToBlock[i]);
				// set height of Overlay to take up whole page and show
				objOverlay.style.height		= (pageSize.pageHeight + 'px');
				objOverlay.style.width		= (pageSize.windowWidth + 'px');
				objOverlay.style.display	= 'block';	
				
			}
			
		}

	},
	
	initLightboxWithObject: function(id, load, idNew){ //id=>elemento a insertar / load=>si tiene la forma de cargar / idNew=>el elemento nuevo para bloquear
	
		// Already done, just update zIndex
		if (!$(idNew)) {
			// create overlay div and hardcode some functional styles (aesthetic styles are in CSS file)
			//EN MODO DE EJECUCION CREA UN DIV DE TAMAŅO DE TODO EL SCREEN PARA DAR EL EFECTO DE DESACTIVAR
			//TODA LA PARTE DE ATRAZ
			var objBody 											= $(id);
			var objOverlay 										= document.createElement("div");
			objOverlay.setAttribute('id', idNew);
			//objOverlay.className = "overlay_new_" + className //ESTABLECE  LA CLASE DE FONDO
			
			objOverlay.style.backgroundColor	= this.getBackgroundColor();
			objOverlay.style.filter						= "alpha(opacity=60)";
			objOverlay.style.opacity					= "0.6";
			objOverlay.style.MozOpacity				= "0.6";
			
			objOverlay.style.display					= 'none';
			objOverlay.style.position					= 'absolute';

			objOverlay.style.zIndex						= 10;
		 	objOverlay.style.width						= '100%';
			if(load)
				objOverlay.innerHTML = '<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0"><tr><td align="center" valign="middle"><img src="'+this.getPathImage()+'"></td></tr></table>';
			objBody.insertBefore(objOverlay, objBody.firstChild);

		}
	
	},
	
	getPageSizeWithObject : function(idObject){
	
		var objContent = $(idObject);
		var xScroll, yScroll;
		var windowWidth, windowHeight;
		var pageHeight, pageWidth;
		
		xScroll = objContent.scrollWidth;
		yScroll = objContent.scrollHeight;

		windowWidth = objContent.clientWidth;
		windowHeight = objContent.clientHeight;
  	
		if(xScroll > windowWidth){
			windowWidth = xScroll;
			windowHeight = yScroll;
		}

  	// 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;
  	}
		/*
		debug("pageWidth:"+pageWidth)
		debug("pageHeight:"+pageHeight)
		debug("windowWidth:"+windowWidth)
		debug("windowHeight:"+windowHeight)
		*/
		return {pageWidth: pageWidth ,pageHeight: pageHeight , windowWidth: windowWidth, windowHeight: windowHeight};
	
	}
	
}

/*************************************************************************************************************************************************************/

var elementLoad = {

	//idElement : "",
	
	typeElement : true,
	
	innerHTMLDiv : "",
	
	buildElement : function(idElement){
		
		if(!$("loadDiv_" + idElement)){
			
			var notElem = true;
			
			//if(this.idElement == "") this.idElement = "loadDiv_" + (Math.random() * 1000);
			
			var objOverlay = document.createElement("div");
			
			if(idElement == ''){
				var objBody = document.getElementsByTagName("body").item(0);
			}else{
				var objBody = $(idElement);
				var left	= $(idElement).offsetLeft;
				var top		= $(idElement).offsetTop;
				notElem = false;
			}
			
			if(idElement != '')
				objOverlay.setAttribute('id', "loadDiv_" + idElement);
			else
				objOverlay.setAttribute('id', "loadDiv_Body");
			
			objOverlay.style.display					= 'none';
			objOverlay.style.position					= 'absolute';
			objOverlay.style.left							= notElem ? "0" : left;
			objOverlay.style.top							= notElem ? "0" : top;
			objOverlay.style.width						= "auto";
			objOverlay.style.height						= "20px";
			objOverlay.style.backgroundColor	= "red";
			objOverlay.style.color						= "white";
			objOverlay.style.fontFamily				= "Arial, Helvetica, sans-serif";
			objOverlay.style.fontSize					= "12px";
			objOverlay.style.padding					= "2px";
			objOverlay.innerHTML							= this.innerHTMLDiv;
			
			objBody.insertBefore(objOverlay, objBody.firstChild);
			
		}
		
	},
	
	show : function(){
		
		var is_exist = true;
		
		if(arguments.length == 2){
			this.innerHTMLDiv = arguments[1];
		}else{
			this.innerHTMLDiv = "Cargando...";
		}
		
		if(typeof arguments[0] == 'undefined'){
			this.buildElement('');
		}else{
			this.buildElement(arguments[0]);
			is_exist = false;
		}
		
		if(is_exist){
			elm = $("loadDiv_Body");
			elm.style.display = 'block';
		}else{
			elm = $("loadDiv_" + arguments[0]);
			elm.style.display = 'block';
		}
			
	},
	
	hide : function(){
	
		if(typeof arguments[0] == 'undefined'){
			
			if($("loadDiv_Body")){
				
				$("loadDiv_Body").remove();
				
			}
			
		}else{
			
			if($("loadDiv_" + arguments[0])){
				
				$("loadDiv_" + arguments[0]).remove();

			}
			
		}
	
	}
		
}