/************************************************************************************************************************/
//extecion para el objecto Effect para ls efectos horizontales

Object.extend(Effect, {
  PAIRS: {
    'slide'	:  ['SlideDown','SlideUp'],
    'blind'	:  ['BlindDown','BlindUp'],
    'appear': ['Appear','Fade'],
		'blindr': ['BlindDownFromRight','BlindUpFromRight'],
		'slider': ['SlideRightIntoView','SlideRightOutOfView']
  }
});
ejecuarAjaxUpdater = function( url, elm, pars )
{
    var myAjax = new Ajax.Updater(
                                    elm,
                                    url, 
                                    {
                                        method      : 'get', 
                                        parameters  : pars, 
                                        evalScripts : true,
                                        onSuccess   : function()
                                        {
                                            //alert("Se termino")
                                        }
                                    }
                                );
}
/*a�adido por william para ver si se puede agregar la forma horizontal*/
Effect.BlindUpFromRight = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false,
      scaleY: false,
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide();
        effect.element.undoClipping();
      }
    }, arguments[1] || {})
  );
}

Effect.BlindDownFromRight = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({
    scaleContent: false,
    scaleY: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping();
      effect.element.setStyle({width: '0px'});
      effect.element.show();
    },
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || {}));
}
/**********************************************************************/

Effect.SlideRightIntoView = function(element) {
	//element = $(element);
  element.style.width = '0px';
  element.style.overflow = 'hidden';
  element.firstChild.style.position = 'relative';
  Element.show(element);
  //var elementDimensions = element.getDimensions();
  //debug(elementDimensions.height + " - " + elementDimensions.width)
  new Effect.Scale(element, 100,
    { 
    	scaleContent: false,
      scaleY: false,
      scaleMode: 'contents',
      scaleFrom: 0,
      //scaleMode: {originalWidth: elementDimensions.width},
      afterUpdate: function(effect)
      { 
      	//effect.element.firstChild.style.width = (effect.originalWidth - effect.element.clientWidth) + 'px'; 
      	//debug((effect.element.clientWidth) + 'pxx')
      	//effect.element.firstChild.setStyle({width:(effect.element.clientWidth) + 'px' });
      }
    }
  );
}

Effect.SlideRightOutOfView = function(element) {
	//element = $(element);
  element.style.overflow = 'hidden';
  element.firstChild.style.position = 'relative';
  Element.show(element);
  //var elementDimensions = element.getDimensions();
  new Effect.Scale(element, 0,
    { 
    	scaleContent: false,
      scaleY: false,
      //scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
      afterUpdate: function(effect)
      { 
      	//debug((effect.element.clientWidth) + 'pxx')
      	//effect.element.firstChild.style.width = (effect.originalWidth - effect.element.clientWidth) + 'px';
      	//effect.element.firstChild.setStyle({width:(effect.originalWidth - effect.element.clientWidth) + 'px' });
      },
      afterFinish: function(effect)
      { 
      	Element.hide(effect.element); 
      }
    }
  );
}

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

var objMainTab = {
		
	typeClassOld : '', 
	
	showMenuContent : function(pars, typeClass){
		
		if(this.typeClassOld != ''){
			
			var elements = $('mainMenu_'+this.typeClassOld).getElementsBySelector('[type="maintTab_'+this.typeClassOld+'"]');
			
			elements[0].removeClassName('mnuActivoIzq');
			elements[1].removeClassName('mnuActivoTxt');
			elements[2].removeClassName('mnuActivoDer');
			
			elements[0].addClassName('mnuInactivoIzq');
			elements[1].addClassName('mnuInactivoTxt');
			elements[2].addClassName('mnuInactivoDer');
			
		}
		
		this.typeClassOld = typeClass;
		
		var elements = $('mainMenu_'+typeClass).getElementsBySelector('[type="maintTab_'+typeClass+'"]');
		
		elements[0].removeClassName('mnuInactivoIzq');
		elements[1].removeClassName('mnuInactivoTxt');
		elements[2].removeClassName('mnuInactivoDer');
		
		elements[0].addClassName('mnuActivoIzq');
		elements[1].addClassName('mnuActivoTxt');
		elements[2].addClassName('mnuActivoDer');
		
		//anterior en : onLoading ; lo hace muy rapido
		$('contentMenu').innerHTML = $('messageLoadMenu').innerHTML;
		
		url = "/crediya/sys.php/user/xmenu";
		pars = "taskId="+pars;
		var myAjax  = new Ajax.Updater(
		"contentMenu",
		url,
		{
			asynchronous:	true,
			method			: 'get',
			parameters	: pars,
			evalScripts	: true,
			onLoading		: function(){
				//$('contentMenu').innerHTML = $('messageLoadMenu').innerHTML;
			},
			onComplete	: function(){
				objMainTab.showMenu();
			}
		});
				
	},
	
	showMenu : function(){
		
		if($('contentMenu').style.display == "none"){
			$('contentImg').innerHTML = "<img src='/images/common/btnOcultar.gif' width='7' height='25' style='cursor:pointer;' onClick='objMainTab.hideMenu()'><img src='/images/common/spacer.gif' width='5' height='5'>";
			Effect.toggle('contentMenu','slider');
			//$('contentMenu').style.display = "";
		}
				
	},
	
	hideMenu : function(){
		
		if($('contentMenu').style.display == ""){
			$('contentImg').innerHTML = "<img src='/images/common/btnMostrar.gif' width='7' height='25' style='cursor:pointer;' onClick='objMainTab.showMenu()'><img src='/images/common/spacer.gif' width='5' height='5'>";
			Effect.toggle('contentMenu','slider');
			//$('contentMenu').style.display = "none";
		}
		
	},
	
	modalDialog : function(url, param, originalRequest){
		
  	if ($('content_win') != null) {
  		
  		Dialog.alert("<br>Por favor primero cierre la ventana..", {windowParameters:{ className: "alphacube",width:200, height:130}});
  	}else {
  	  
  	  var options = Object.extend({
  		  className         : "alphacube", 
				title             : "",
				width             : 800,
				height            : 500,
				resizable         : false, 
				url               : null, 
				showEffectOptions : {duration:0},
				minimizable       : false,
				maximizable       : false,
				closable          : true
				//onload            : Prototype.emptyFunction,
		  }, param || {});
		  
		  if(url != ''){
		    options.url = url;
		  }
		  
		  var contentWin = new Window('content_win', options);
		  
  		contentWin.setDestroyOnClose();
  		
  		if(url == ''){
  		  contentWin.getContent().innerHTML = originalRequest;
		  }
		  
  		contentWin.showCenter(true);  
  		
  	}
		
	},
	
	windowsCloseAll : function(){
	  
	  Windows.closeAll();
	  
	},
	
	returnValueIframe : function(id_frame, metod, param){
	  
	  if(typeof(param) == undefined){
	      param = "";
	  }
	    
	  this.windowsCloseAll();
	  
	  //copia fiel del cubo
		var iframe_f          = document.getElementById(id_frame);
		var iframe_f_window   = iframe_f.contentWindow; //window
	  var iframe_f_document = iframe_f_window.document; //documento
	  cad_eval              = "iframe_f_window." + metod + "("+param+");";
	  return eval(cad_eval);
	  
	},
	
	CallFunctionIframe : function(id_frame, metod, param){
	  
	  if(typeof(param) == 'undefined'){
	    param = "";
	  }
	  
	  //copia fiel del cubo
		var iframe_f          = document.getElementById(id_frame);
		var iframe_f_window   = iframe_f.contentWindow; //window
	  var iframe_f_document = iframe_f_window.document; //documento
	  cad_eval              = "iframe_f_window." + metod + "("+param+");";
	  return eval(cad_eval);
	  
	},
	
	reqBody : function(url, block){
		pars = "?block="+block;
		document.getElementById('contentResultxx').src=(url+pars);
  },
  
  reqBodyByParam : function(url, pars){
    if(typeof(pars) == "undefined") 
      pars = "";
    if(pars!="")
      url = url + "?" + pars;
    
		document.getElementById('contentResultxx').src=(url);
  },
	
	returnReqBody : function(originalRequest){
		disabledWin.hide('contentResult');
		var space = "<img src='/images/common/spacer.gif' width='10' height='10'><img src='/images/common/spacer.gif' width='10' height='10' align='left'>";
		$("contentResult").innerHTML = space + "\n5556666\n" + originalRequest.responseText;
	}
		
}

/**
 * 
*/
var scrollFunction = function(idCTion){
	
	//si se quiere abrir todos los menus comente esta seccion
	var elems = $$("DIV.scrollTable");
	
	elems.each(function(elm, key) {
	  if(elm.style.display == ""){
	  	Effect.toggle(elm,'slide',{duration:.2}); 
	  }
	});
	
	Effect.toggle('contentProcMenu_' + idCTion,'slide',{duration:.2});
	
}

/**
 * 
*/
var cargarChecks = function(parentId, code){
  
  var elements = $(parentId).getElementsBySelector('['+code+']');
  for(i=0; i<elements.length; i++){
    elements[i].checked = !elements[i].checked
  }
  
}

/**
 * elimina de un array el indice indicado con la variable key
*/
var sliceByPos = function(array, key){
  var a_tmp = [];
  for(i=0; i<array.length; i++){
    if(i != key){
      a_tmp[a_tmp.length] = array[i];
    }
  }
  return a_tmp;
}
/***************************************************************************************************************/
/**
 * uso solo para clases de estilos
*/
var stylesClass = {
  add : function(elm, className){
    $(elm).addClassName(className);
  },
  remove : function(elm, className){
    $(elm).removeClassName(className);
  },
  has : function(elm, className){
    return $(elm).hasClassName(className);
  },
  isExist : function(elm, className){
    if(stylesClass.has(elm, className)){
      stylesClass.remove(elm, className);
    }
  }
}

var redondear = function(cantidad, decimales) {
  var cantidad = parseFloat(cantidad);
  var decimales = parseFloat(decimales);
  decimales = (!decimales ? 2 : decimales);
  return Math.round(cantidad * Math.pow(10, decimales)) / Math.pow(10, decimales);
} 

String.prototype.trim = function(){
  var retorno=this.replace(/^\s+/g,"");
  retorno=retorno.replace(/\s+$/g,"");
  return retorno;
}

actHeader = function(variable){
 
  $("kuki").update(variable);
}


var cargarOpcionesMI = function(j){
    
	
	f = $$('.opcionI');
	
	
	
	for(var i=0; i<f.length; i++){
	    
		f[i].removeClassName('textMenuOver');
		
		id = f[i].id;
		//alert(id);
		
		if(id==j){
			f[i].addClassName('textMenuOver');
		}else{
			f[i].addClassName('textMenu');
		}
	}
	
}
/*
var cargarOpcionesMI = function(j){
	
	
	$$( ".opcionI" ).removeClass('textMenuOver');
	
	f = $$('.opcionI');
	for(var i=0; i<f.length; i++){
		f[i].removeClassName('textMenuOver');
		if(i==j){
			f[i].addClassName('textMenuOver');
		}else{
			f[i].addClassName('textMenu');
		}
	}
	
	
		
}
*/