/**
  * Archivo de Acciones y Eventos Javascript
  */

function dar_Salida()
{
	if(confirm('Realmente Desea Salir?'))
	{
		location.href = '../index.php?logOutUser=true';
	}
}

function goBem() {
	location.href = 'bem.php';
}

/**
  *  Clase ResizeHeightObj()
  */
function ResizeHeightObj(idObjRes, idObjDrag)
{
   this.resObj = document.getElementById(idObjRes);
   this.dragObj = document.getElementById(idObjDrag);
   this.startHeight = 0;
   this.cursorStart = 0;
   this.appendUrl = '/inc/images/';
   this.curState = "down";
   this.curPosY = 0;  
   this.min = 15;
   this.max = 500;
}


ResizeHeightObj.prototype.init = function () {
   rObj = this.resObj;
   dgObj = this.dragObj;
   
   if(!rObj || !dgObj) return false;
   
   // Asignamos la imagen de para ajustar alto
   //dgObj.style.backgroundImage = 'resize_' + this.curState + '.gif';
   dgObj.style.backgroundImage = 'url("'+ this.appendUrl +'resize_' + this.curState + '.gif")';
   dgObj.style.backgroundRepeat = 'no-repeat';
   dgObj.style.backgroundPosition = 'center 1px';   
   
   // asignamos el alto inicial del Objeto
   rObj.style.height = rObj.clientHeight;
   this.startHeight = rObj.clientHeight;
   
   // asignamos los eventos del Objeto Dragable
   dgObj.resObj = this;
   document.resObj = this;
   dgObj.onmouseover = overResize;
   dgObj.onmouseout  = outResize;   
   dgObj.onmousedown = DragStart;
}

function DragStart(evt)
{
   if(!evt)
      evt = window.event;
   
   var cObj = this.resObj;
   var x,y;
  
   y = evt.clientY;   
  
  // valores Iniciales
  cObj.cursorStart = y; 
  cObj.resObj.style.height = cObj.resObj.clientHeight;
  cObj.startHeight = cObj.resObj.clientHeight;
  
  // Aplicamos el estilo presionado del separador
  this.style.backgroundImage = 'url("' + cObj.appendUrl + 'resize_press.gif")';
  
  if (document.all) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",   dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  } else {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    evt.preventDefault();
  }
}

function dragGo(evt) {

  if(!evt)
      evt = window.event;
  
  var x, y;
    
  cObj = document.resObj;
  var tObj = cObj.resObj;
  
  y = evt.clientY;
  
  // Ajustamos el alto de la celda
  var nHeight = parseInt(cObj.startHeight + y - cObj.cursorStart);
  if( (nHeight > cObj.min) && (nHeight < cObj.max) )
     tObj.style.height = parseInt(cObj.startHeight + y - cObj.cursorStart) + "px";

  if (document.all) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  } else 
    evt.preventDefault();
    
  //var Status = document.getElementById('status');
  //Status.innerHTML = "CurHeight: " + tObj.style.height;
}

function dragStop(evt) {
  
  if(!evt)
      evt = window.event;
  
  cObj = document.resObj;
  var tObj = cObj.resObj;

  // Desaplicamos el estilo presionado del Botón
  cObj.dragObj.style.backgroundImage = 'url("' + cObj.appendUrl + 'resize_' + cObj.curState + '.gif")';

  if (document.all) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",   dragStop);
  }
  else {
    document.removeEventListener("mousemove", dragGo,   true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

function overResize(evt)
{
   if(!evt)
      evt = window.event;         
   
   //var Status = document.getElementById('status');
   
   this.style.backgroundImage = 'url("' + this.resObj.appendUrl + 'resize_over.gif")';
   this.style.cursor = 'n-resize';
}

function outResize(evt)
{
   if(!evt)
      evt = window.event;         
   
   //var Status = document.getElementById('status');
   
   this.style.backgroundImage = 'url("'+ this.resObj.appendUrl +'resize_' + this.resObj.curState + '.gif")';
   this.style.cursor = 'default';
}
// Fin de la Clase ResizeHeightObj

// Nuevo Objeto para crear Tabs Windows

function TabObject() {	
	this.id_sel_actual  = 'null';
	this.id_pag_actual  = 'null';
	this.className      = 'tabDefault';
	this.classNameHover = 'tabDefaultHover';
	this.classNameSelec = 'tabDefaultSelec';
	this.pages = new Array();
	this.selectors = new Array();
	this.registrarPagina = regCntrls;
}

function regCntrls(id_sel,id_pag) {
	
	this.pages.push(id_pag);
	this.selectors.push(id_sel);
	
	var selElem         = document.getElementById(id_sel);
	if(!selElem)
		alert('El elemento con id: ' + id_sel + ' no existe!');		
	selElem.pPagSel     = this;
	selElem.idPageC     = id_pag;
	selElem.onclick     = changeTabPage;
	selElem.onmouseover = selHoverTab;
	selElem.onmouseout  = selHoveOutTab;
	selElem.className   = this.className;
	
	if(document.getElementById(id_pag).style.display != 'none' && this.id_pag_actual == 'null') {
		selElem.className += ' ' + this.classNameSelec;
		this.id_pag_actual = id_pag;
		this.id_sel_actual = id_sel;
	}
	
	if(this.id_pag_actual != 'null' && this.id_pag_actual != id_pag) {
		document.getElementById(id_pag).style.display = 'none';
	}
}

// Función que se ejecuta al seleccionar un tab
function changeTabPage() {
	var tObj = this.pPagSel;
	if(this.idPageC != tObj.id_pag_actual) {
		
		// Cambiamos el estado del Objeto anterior
		document.getElementById(tObj.id_pag_actual).style.display = 'none';
		var lstSel = document.getElementById(tObj.id_sel_actual);
		lstSel.className = lstSel.className.replace(tObj.classNameSelec,'');
		
		// Asignamos el estado del Nuevo Objeto
		tObj.id_pag_actual = this.idPageC;
		tObj.id_sel_actual = this.id;
		if(typeof(tObj.onchange)=='function')
			tObj.onchange(this.idPageC);
				
		document.getElementById(tObj.id_pag_actual).style.display = 'block';
		this.className += ' ' + tObj.classNameSelec; 
	}
}

function selHoverTab() {
	this.className += ' ' + this.pPagSel.classNameHover;
}

function selHoveOutTab() {
	this.className = this.className.replace(this.pPagSel.classNameHover,'');
}

function selTabPage(idSel) {
	thisTab = document.getElementById(idSel);
	var tObj = thisTab.pPagSel;
	if(this.idPageC != tObj.id_pag_actual) {
		
		// Cambiamos el estado del Objeto anterior
		document.getElementById(tObj.id_pag_actual).style.display = 'none';
		var lstSel = document.getElementById(tObj.id_sel_actual);
		lstSel.className = lstSel.className.replace(tObj.classNameSelec,'');
		
		// Asignamos el estado del Nuevo Objeto
		tObj.id_pag_actual = thisTab.idPageC;
		tObj.id_sel_actual = thisTab.id;
		if(typeof(tObj.onchange)=='function')
			tObj.onchange(thisTab.idPageC);
				
		document.getElementById(tObj.id_pag_actual).style.display = 'block';
		thisTab.className += ' ' + tObj.classNameSelec; 
	}
}

function setIframeSize(idCont,idFrame,offX,offY) {
	tX = document.getElementById(idCont).clientWidth;
	tY = document.getElementById(idCont).clientHeight;	
	
	//alert("X= " + tX + "Y= " + tY);
	
	if($(idFrame)) {	
		$(idFrame).width  = tX - offX;
		$(idFrame).height = tY - offY;		
		//alert($(idFrame).width + " - " + $(idFrame).height);
	}
}

function checkDates(idCntrlMin,idCntrlMax,bAllowSoloFechaMin) {
	dMin = $(idCntrlMin + "_dia").value;
	mMin = $(idCntrlMin + "_mes").value;
	aMin = $(idCntrlMin + "_year").value;
	
	dMax = $(idCntrlMax + "_dia").value;
	mMax = $(idCntrlMax + "_mes").value;
	aMax = $(idCntrlMax + "_year").value;
	
	fchMin = new Date();
	fchMin.setFullYear(aMin,mMin-1,dMin);
	
	fchMax = new Date();
	fchMax.setFullYear(aMax,mMax-1,dMax);
	
	if(fchMax >= fchMin) {
		return true;
	} else {
		
		if(fchMin.getFullYear() && fchMax.getFullYear()) return false;
		
		if(bAllowSoloFechaMin && (fchMin.getFullYear() || fchMax.getFullYear())) {
			return true;
		}else {
			return false;
		}
	}	
}

function getImageIndx() {
	var theImages = new Array() // do not change this
	theImages[0] = 'imagenes/img1.jpg'
	theImages[1] = 'imagenes/img3.jpg'	
	theImages[2] = 'imagenes/img4.jpg'
	var j = 0
	var p = theImages.length;
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	   preBuffer[i] = new Image()
	   preBuffer[i].src = theImages[i]
	}
	var whichImage = Math.round(Math.random()*(p-1));
	document.getElementById('banner_1').style.backgroundImage = "url('" + theImages[whichImage] + "')";
}

function getImageIndxMods() {
	var theImages = new Array() // do not change this
	theImages[0] = '../imagenes/img1.jpg'
	theImages[1] = '../imagenes/img3.jpg'	
	theImages[2] = '../imagenes/img4.jpg'
	var j = 0
	var p = theImages.length;
	var preBuffer = new Array()
	for (i = 0; i < p; i++){
	   preBuffer[i] = new Image()
	   preBuffer[i].src = theImages[i]
	}
	var whichImage = Math.round(Math.random()*(p-1));
	document.getElementById('banner_1').style.backgroundImage = "url('" + theImages[whichImage] + "')";
}