//---------------------------------------------------------------------------------
// Este código es propiedad de SARO Electrónica y Sistemas S. A. de C. V. todos 
// los derechos reservados.  
// Esta es la librería general de funciones propietarias para todos los desarrollos
// WEB-ASP y ASPX
// Funciones:
// CargaSelect(forma, select, valor, texto)
// ObjetoXMLRequest()
//---------------------------------------------------------------------------------

// ------------------------------------------------------------------------------
// Función: CargaSelect
// Acción: se encarga de llenar un select
// Recibe: el nombre del select, la pagina y un arreglo con la información [valor, dato]
// Regresa: Nada
// ------------------------------------------------------------------------------
  function CargaSelect(form,cmbForm,datos, valores){
     //Asignamos a una variable el combobox
     var temp = eval("window." + form + "." + cmbForm + "");

     //Limpiamos el combo.
     for (m = temp.options.length-1; m > -1; m--) {
        temp.options[m] = null;
     }

     for (n = 0; n < datos.length; n++ ){
        if (datos[n] != '') temp.options[n] = new Option(datos[n], valores[n]);
     }
  }

  
// ------------------------------------------------------------------------------
// Función: parseXML
// Acción: realiza el parse de un archivo xml
// Recibe: la pagina y el dato buscado
// Regresa: un arreglo de datos
// ------------------------------------------------------------------------------  
  function parseXML() {
	response  = req.responseXML.documentElement;
	itemDescription = response.getElementsByTagName('description')[0].firstChild.data;
	alert ( itemDescription );
  }
  
// ------------------------------------------------------------------------------
// Función: session_usuario
// Acción: obtiene la session del usuario
// Recibe: nada
// Regresa: el id del usuario
// ------------------------------------------------------------------------------  
  function session_usuario() {
	var xmlHttpX = ObjetoXMLRequest();
    xmlHttpX.open("POST","wsFunciones.asp?funcion=login", false);
    xmlHttpX.send();
    var requestX = xmlHttpX.responseText;
    return requestX
  }

  // ------------------------------------------------------------------------------
// Función: session_usuario_logout
// Acción: obtiene la session del usuario
// Recibe: nada
// Regresa: el id del usuario
// ------------------------------------------------------------------------------  
  function session_usuario_logout() {
	var xmlHttpX = ObjetoXMLRequest();
    xmlHttpX.open("POST","wsFunciones.asp?funcion=logout", false);
    xmlHttpX.send();
    var requestX = xmlHttpX.responseText;
    return requestX
  }
  
// ------------------------------------------------------------------------------
// Función: session_usuario
// Acción: obtiene la session del usuario
// Recibe: correo y password
// Regresa: el id del usuario
// ------------------------------------------------------------------------------  
  function session_usuario(correo, password) {
	var xmlHttpX = ObjetoXMLRequest();
    xmlHttpX.open("POST","wsFunciones.asp?funcion=login&password=" + password + "&correo=" + correo + "", false);
    xmlHttpX.send();
    var requestX = xmlHttpX.responseText;
    return requestX
  }
  
// ------------------------------------------------------------------------------
// Función: folio_nextel
// Acción: obtiene el folio de sesión del usuario
// Recibe:
// Regresa: el folio del usuario
// ------------------------------------------------------------------------------  
  function folio_nextel() {
	var xmlHttpX = ObjetoXMLRequest();
    xmlHttpX.open("POST","wsFunciones.asp?funcion=folio_nextel", false);
    xmlHttpX.send();
    var requestX = xmlHttpX.responseText;
    return requestX
  }
  
// ------------------------------------------------------------------------------
// Función: session_usuario
// Acción: obtiene la session del usuario
// Recibe: correo y password
// Regresa: el id del usuario
// ------------------------------------------------------------------------------  
  function usuarios_login() {
	var registro = document.getElementById("tblRegistro")
    var datos = document.getElementById("tblDatos")
    var login = document.getElementById("tblLogin")
    var logout = document.getElementById("tblLogout")
    
    registro.style.display = "none";
    datos.style.display = "";
    
    login.style.display = "none";
    logout.style.display = "";
    
    var xmlHttp = ObjetoXMLRequest();
    xmlHttp.open("POST","wsFunciones.asp?funcion=ciudades", false);
    xmlHttp.send();
    var request2 = xmlHttp.responseText;
  
    var arrCCiudades = request2.split("||")
    var arrCidCiudad = arrCCiudades[0].split("*|")
    var arrCNombre = arrCCiudades[1].split("*|")
  
  CargaSelect('usuarios','sEstado2',arrCNombre,arrCidCiudad);
  
    var arrZona = new Array("- Escoge una opcion-","Aeropuerto/Iztapalapa","Azcapotzalco/Tlalnepantla","Centro","Coapa/Xochimilco","Condesa/Roma","Coyoacán","Cuautitlán/Perinorte","Del Valle/Nápoles/Narvarte","Ecatepec/Coacalco","Interlomas","Lindavista/Vallejo","Lomas/Tecamachalco","Mixcoac/Águilas","Perisur/Tlalpan","Polanco/Anzures","San Ángel/Altavista","Santa Fé/Bosques","Satélite/Naucalpan","Zona Rosa/Cuauhtémoc")
    var arrVal = new Array("0","1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19")
    CargaSelect('usuarios', 'sZona2', arrZona, arrVal);
    
    var xmlHttpX = ObjetoXMLRequest();
    xmlHttpX.open("POST","wsFunciones.asp?funcion=usuario_info", false);
    xmlHttpX.send();
    var requestX = xmlHttpX.responseText;
    if (requestX != ""){
        var arrRS = requestX.split("||");
        document.getElementById("loginCorreo").innerHTML = arrRS[8];
        document.getElementById("loginNombre").innerHTML = arrRS[0];
        
        usuarios.txtNombre2.value = arrRS[0];
        usuarios.txtApellido2.value = arrRS[1]
        
        usuarios.sDia2.value = arrRS[4]
        usuarios.sMes2.value = arrRS[3]
        usuarios.sYear2.value = arrRS[2]
        usuarios.sSexo2.value = arrRS[5]
        usuarios.sEstado2.value = arrRS[6]
        if(arrRS[6] == 6) {
            document.getElementById("textZona2").style.color = '#3098CD';
            document.forms["usuarios"].sZona2.disabled = false;
            document.forms["usuarios"].sZona2.style.visibility = 'visible';
        }
        usuarios.sZona2.value = arrRS[7]
        usuarios.txtCorreo2.value = arrRS[8]
        usuarios.txtPassword2.value = arrRS[9]
        usuarios.txtNextel2.value = arrRS[10]
    }
  }
  
// ------------------------------------------------------------------------------
// Función: log_entradas
// Acción: Registra la visita del usuario
// Recibe: Pagina
// Regresa: nada
// ------------------------------------------------------------------------------  
  function log_entradas(pagina) {
	var xmlHttpX = ObjetoXMLRequest();
    xmlHttpX.open("POST","wsFunciones.asp?funcion=logVisitas&pagina=" + pagina + "", false);
    xmlHttpX.send();
    var requestX = xmlHttpX.responseText;
  }
  
// ------------------------------------------------------------------------------
// Función: servicio_nextel
// Acción: Manda la información de cobro a Nextel.
// Recibe: Nada
// Regresa: Nulo en correcto Error en contrario.
// ------------------------------------------------------------------------------  
  function compras_to_nextel() {
      var xmlHttpX = new ObjetoXMLRequest();
      var items = new Array();
      var ptn = new Array();
      xmlHttpX.open("POST","wsFunciones.asp?funcion=Compras_Carrito", false);
      xmlHttpX.send();
      var requestX = xmlHttpX.responseText;
      if(requestX != ""){
          var arrRS = requestX.split("||");
          for(var i_car = 0; i_car < arrRS.length; i_car++){
              if(arrRS[i_car]!=""){
                  var arrRS2 = arrRS[i_car].split("*|*");
                  
                  var objTxt = $('txtTam' + arrRS2[5]);
                  var objCmb = $('txtPTN' + arrRS2[5]);
                  if(objTxt || objCmb){
                      //alert(objTxt.value + objCmb.value);
                  }
              }
          }
      }
      items[0] = '';
      ptn[0] = '';
      servicio_nextel(items, ptn);
      
      parent.location.href="levantarPedido.html";
      
      return null;
  }

/********************************************************************************************************/
/**********************              FUNCION Shots Bitacora            **********************************/
/********************************************************************************************************/
function updatePTN(PTN, Modelo) {
    if(Modelo == 0){
        alert("Debe de ingresar un modelo");
    } else {
        if(PTN.length != 10){
            alert("Debe de ingresar un PTN válido.");
        } else {
                var xmlHttp = new ObjetoXMLRequest();
                xmlHttp.open("POST","wsFunciones.asp?funcion=codigo&item=" + Modelo + "&ptn=" + PTN + "&action=EDITAR", false);
                xmlHttp.send();
                request = xmlHttp.responseText;
                alert(request);
                parent.location.href="seleccion_shots.html";
        }
    }
}

// ------------------------------------------------------------------------------
// Función: servicio_nextel
// Acción: Manda la información de cobro a Nextel.
// Recibe: datos a enviar
// Regresa: respuesta de nextel
// ------------------------------------------------------------------------------  
  function servicio_nextel(items, ptn) {
      request = folio_nextel();
      for(i=0; i<item.length; i++) {
          //1171  5510900152  IN2GO070100001
          var xmlHttp2 = new ObjetoXMLRequest();
          xmlHttp2.open("POST","http://www.nextel.com.mx/NR/NEXTELSite/Includes/DescargaContenido/Envia/IN2GOVER2/agregado.asp?id_shot=" + items[0] + "&ptn=" + ptn[0] + "&Folio_nextel=" + request + "", false);
          xmlHttp2.send();
          request2 = xmlHttp2.responseText;
          //alert(request2 + "-**-" + request);
          return request2;
      }
  }
  
  
// ------------------------------------------------------------------------------
// Función: legal()
// Acción: Muesta la pantalla de compatibilidad o terminos según se indique
// Recibe: La tabla a mostrar
// Regresa: nada
// ------------------------------------------------------------------------------  
  function legal(table) {
      switch(table) {
          case 'compatibilidad':
              document.getElementById("Terminos").style.display = "none";
              document.getElementById("Compatibilidad").style.display = "";
              break;
          case 'terminos':
              document.getElementById("Terminos").style.display = "";
              document.getElementById("Compatibilidad").style.display = "none";
              break;
      }
  }

// ------------------------------------------------------------------------------
// Función: legal()
// Acción: Muesta la pantalla de compatibilidad o terminos según se indique
// Recibe: La tabla a mostrar
// Regresa: nada
// ------------------------------------------------------------------------------  
  function legal_load(select,div) {
      var objSelect = document.getElementById(select);
      var xmlHttp = new ObjetoXMLRequest();
      xmlHttp.open("POST","wsFunciones.asp?funcion=compatibilidad&idmodelo=", false);
      xmlHttp.send();
      var request = xmlHttp.responseText;
      if(request != "") {
          var arrRS = request.split("||");
          for(i=0; i<arrRS.length; i++){
              if(arrRS[i]!=""){
                  var arrRS2 = arrRS[i].split("*|*");
                  objSelect.options[i] = new Option(arrRS2[1], arrRS2[0]);
              }
          }
      }
      document.getElementById(div).innerHTML = "</BR> <B>Selecciona tu equipo</B> </BR> Para ver la compatibilidad";
  }
  
// ------------------------------------------------------------------------------
// Función: legal_onchange
// Acción: Muesta la pantalla de compatibilidad o terminos según se indique
// Recibe: La tabla a mostrar
// Regresa: nada
// ------------------------------------------------------------------------------  
  function legal_onchange(select,div,ex) {
      var arrSN = new Array("No","Sí");
      var arrAudio = new Array("Ninguno","Midi","Midi, Wav","Midi, Wav, Ambe++","Midi, Wav, MP3, AMR, AU");
      var arrImg = new Array("Ninguno","GIF","GIF, JPEG","GIF, JPEG, WBMP","GIF, JPEG, WBMP, PNG");
      var arrVideo = new Array("Ninguno","H.263, MPEG-4, 3GPP, AMR-NB");
      var objSelect = document.getElementById(select);
      var xmlHttp = new ObjetoXMLRequest();
      xmlHttp.open("POST","wsFunciones.asp?funcion=compatibilidad&idmodelo=" + ex.value, false);
      xmlHttp.send();
      var request = xmlHttp.responseText;
      if(request != "") {
          var arrRS = request.split("||");
          for(i=0; i<arrRS.length; i++){
              if(arrRS[i] != ""){
                  var arrRS2 = arrRS[i].split("*|*");
                  document.getElementById(div).innerHTML = "</BR> <B>Pantalla:</B> " + arrRS2[2] + " </BR> <B>Explorador:</B> " + arrRS2[3] + "</BR> <B>Java:</B> " + arrSN[arrRS2[4]] + "</BR> <B>Audio:</B> " + arrAudio[arrRS2[6]] + " </BR> <B>Imagenes:</B> " + arrImg[arrRS2[7]] + " </BR> <B>Video:</B> " + arrVideo[arrRS2[8]] + "";
                  if(arrRS2[9]!=""){
                      document.getElementById("imgModelo").setAttribute("src","modelos/" + arrRS2[9]);
                  } else {
                      document.getElementById("imgModelo").setAttribute("src","modelos/none.jpg");
                  }
              }
          }
      }
  }

// ------------------------------------------------------------------------------
// Función: login
// Acción: Muesta la pantalla de compatibilidad o terminos según se indique
// Recibe: La tabla a mostrar
// Regresa: nada
// ------------------------------------------------------------------------------  
  function login(form) {
      if ((form.logCorreo.value.length == 0)) {
          alert("Debe de ingresar correo");
      } else if ((form.logPassword.value.length == 0)) {
          alert("Debe de ingresar password");
      } else {
          idusuario = session_usuario(form.logCorreo.value, form.logPassword.value);
          if (idusuario != 0 && idusuario != null && idusuario != "" ){
              switch (form.id) {
                  case "usuario": { usuarios_login(); break }
                  case "loginusuario": { break }
                  default: { alert("No se reconoce el origen"); return "notlog"; break }
              }
              return "login";
          } else {
              alert("Datos incorrectos");
              return "notlog";
          }
      }
  }
  
// -- Fading --------------------------------------------------------------------

// Initially set to yellow - "rgb(100%, 100%, 0%)". Blue component is 
// stepped up 10% every 100 milliseconds until the target colour of white 
// - "rgb(100%, 100%, 100%)" - has been reached.

function fade(bluePercent) {
  $("results").style.backgroundColor = "rgb(100%, 100%, "+bluePercent+"%)";
  bluePercent += 10;
  if (bluePercent<=100) {
    setTimeout("fade("+bluePercent+")", 100/*ms*/);
  }
}

// ------------------------------------------------------------------------------
// Función: promocionHP
// Acción: adquiere el objeto necesario para realizar un request
// Recibe: Nada
// Regresa: Objeto XMLHttpRequest
// ------------------------------------------------------------------------------
function promocionHP(){
    if(session_usuario()==''){
        showPopWin('Harry_Potter_5.html', 550, 460, null);
    } else {
        parent.location.href="harrypotter.html";
    }
}

/**
 * SUBMODAL v1.4
 * Used for displaying DHTML only popups instead of using buggy modal windows.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Contributions by:
 * 	Eric Angel - tab index code
 * 	Scott - hiding/showing selects for IE users
 *	Todd Huss - inserting modal dynamically and anchor classes
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/subModal
 * 
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

// Popup code
var gPopupMask = null;
var gPopupContainer = null;
var gPopFrame = null;
var gReturnFunc;
var gPopupIsShown = false;

var gHideSelects = false;


var gTabIndexes = new Array();
// Pre-defined list of tags we want to disable/enable tabbing into
var gTabbableTags = new Array("A","BUTTON","TEXTAREA","INPUT","IFRAME");	

// If using Mozilla or Firefox, use Tab-key trap.
if (!document.all) {
	document.onkeypress = keyDownHandler;
}



/**
 * Initializes popup code on load.	
 */
function initPopUp() {
	// Add the HTML to the body
	theBody = document.getElementsByTagName('BODY')[0];
	popmask = document.createElement('div');
	popmask.id = 'popupMask';
	popcont = document.createElement('div');
	popcont.id = 'popupContainer';
	popcont.innerHTML = '' +
		'<div id="popupInner">' +
			'<div id="popupTitleBar">' +
				'<div id="popupTitle"></div>' +
				'<div id="popupControls">' +
					'<img src="iconos/close.gif" onclick="hidePopWin(false);" id="popCloseBox" />' +
				'</div>' +
			'</div>' +
			'<iframe src="loading.html" style="width:100%;height:100%;background-color:transparent;" scrolling="auto" frameborder="0" allowtransparency="true" id="popupFrame" name="popupFrame" width="100%" height="100%"></iframe>' +
		'</div>';
	theBody.appendChild(popmask);
	theBody.appendChild(popcont);
	
	gPopupMask = document.getElementById("popupMask");
	gPopupContainer = document.getElementById("popupContainer");
	gPopFrame = document.getElementById("popupFrame");	
	
	// check to see if this is IE version 6 or lower. hide select boxes if so
	// maybe they'll fix this in version 7?
	var brsVersion = parseInt(window.navigator.appVersion.charAt(0), 10);
	if (brsVersion <= 6 && window.navigator.userAgent.indexOf("MSIE") > -1) {
		gHideSelects = true;
	}
	
	// Add onclick handlers to 'a' elements of class submodal or submodal-width-height
	var elms = document.getElementsByTagName('a');
	for (i = 0; i < elms.length; i++) {
		if (elms[i].className.indexOf("submodal") == 0) { 
			// var onclick = 'function (){showPopWin(\''+elms[i].href+'\','+width+', '+height+', null);return false;};';
			// elms[i].onclick = eval(onclick);
			elms[i].onclick = function(){
				// default width and height
				var width = 400;
				var height = 200;
				// Parse out optional width and height from className
				params = this.className.split('-');
				if (params.length == 3) {
					width = parseInt(params[1]);
					height = parseInt(params[2]);
				}
				showPopWin(this.href,width,height,null); return false;
			}
		}
	}
}
addEvent(window, "load", initPopUp);

/**
	* @argument width - int in pixels
	* @argument height - int in pixels
	* @argument url - url to display
	* @argument returnFunc - function to call when returning true from the window.
	* @argument showCloseBox - show the close box - default true
	*/

function showPopWin(url, width, height, returnFunc, showCloseBox) {
	// show or hide the window close widget
	if (showCloseBox == null || showCloseBox == true) {
		document.getElementById("popCloseBox").style.display = "block";
	} else {
		document.getElementById("popCloseBox").style.display = "none";
	}
	gPopupIsShown = true;
	disableTabIndexes();
	gPopupMask.style.display = "block";
	gPopupContainer.style.display = "block";
	// calculate where to place the window on screen
	centerPopWin(width, height);
	
	var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);


	gPopupContainer.style.width = width + "px";
	gPopupContainer.style.height = (height+titleBarHeight) + "px";
	
	setMaskSize();

	// need to set the width of the iframe to the title bar width because of the dropshadow
	// some oddness was occuring and causing the frame to poke outside the border in IE6
	gPopFrame.style.width = parseInt(document.getElementById("popupTitleBar").offsetWidth, 10) + "px";
	gPopFrame.style.height = (height) + "px";
	
	// set the url
	gPopFrame.src = url;
	
	gReturnFunc = returnFunc;
	// for IE
	if (gHideSelects == true) {
		hideSelectBoxes();
	}
	
	window.setTimeout("setPopTitle();", 1000);
}

//
var gi = 0;
function centerPopWin(width, height) {
	if (gPopupIsShown == true) {
		if (width == null || isNaN(width)) {
			width = gPopupContainer.offsetWidth;
		}
		if (height == null) {
			height = gPopupContainer.offsetHeight;
		}
		
		//var theBody = document.documentElement;
		var theBody = document.getElementsByTagName("BODY")[0];
		theBody.style.overflow = "hidden";
		
		var scTop = parseInt(theBody.scrollTop,10);
		var scLeft = parseInt(theBody.scrollLeft,10);
		
		gPopupMask.style.top = scTop + "px";
		gPopupMask.style.left = scLeft + "px";
	
		setMaskSize();
		
		//window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
		
		var titleBarHeight = parseInt(document.getElementById("popupTitleBar").offsetHeight, 10);
		
		var fullHeight = getViewportHeight();
		var fullWidth = getViewportWidth();
        
		
		gPopupContainer.style.top = (scTop + 100 + ((fullHeight - (height+titleBarHeight)) / 2)) + "px";
		gPopupContainer.style.left =  (scLeft + ((fullWidth - width) / 2)) + "px";
		//alert(fullWidth + " " + width + " " + gPopupContainer.style.left);
	}
}
//addEvent(window, "resize", centerPopWin);
//addEvent(window, "scroll", centerPopWin);
//window.onscroll = centerPopWin;

/**
 * Sets the size of the popup mask.
 *
 */
function setMaskSize() {
	var theBody = document.getElementsByTagName("BODY")[0];
			
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight;
	}
	
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
		popWidth = theBody.scrollWidth;
	}
	
	gPopupMask.style.height = popHeight + "px";
	gPopupMask.style.width = popWidth + "px";
}

/**
 * @argument callReturnFunc - bool - determines if we call the return function specified
 * @argument returnVal - anything - return value 
 */
function hidePopWin(callReturnFunc) {
	gPopupIsShown = false;
	var theBody = document.getElementsByTagName("BODY")[0];
	theBody.style.overflow = "";
	restoreTabIndexes();
	if (gPopupMask == null) {
		return;
	}
	gPopupMask.style.display = "none";
	gPopupContainer.style.display = "none";
	if (callReturnFunc == true && gReturnFunc != null) {
		gReturnFunc(window.frames["popupFrame"].returnVal);
	}
	gPopFrame.src = 'loading.html';
	// display all select boxes
	if (gHideSelects == true) {
		displaySelectBoxes();
	}
}

/**
 * Sets the popup title based on the title of the html document it contains.
 * Uses a timeout to keep checking until the title is valid.
 */
function setPopTitle() {
	return;
	if (window.frames["popupFrame"].document.title == null) {
		window.setTimeout("setPopTitle();", 10);
	} else {
		document.getElementById("popupTitle").innerHTML = window.frames["popupFrame"].document.title;
	}
}

// Tab key trap. iff popup is shown and key was [TAB], suppress it.
// @argument e - event - keyboard event that caused this function to be called.
function keyDownHandler(e) {
    if (gPopupIsShown && e.keyCode == 9)  return false;
}

// For IE.  Go through predefined tags and disable tabbing into them.
function disableTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				gTabIndexes[i] = tagElements[k].tabIndex;
				tagElements[k].tabIndex="-1";
				i++;
			}
		}
	}
}

// For IE. Restore tab-indexes.
function restoreTabIndexes() {
	if (document.all) {
		var i = 0;
		for (var j = 0; j < gTabbableTags.length; j++) {
			var tagElements = document.getElementsByTagName(gTabbableTags[j]);
			for (var k = 0 ; k < tagElements.length; k++) {
				tagElements[k].tabIndex = gTabIndexes[i];
				tagElements[k].tabEnabled = true;
				i++;
			}
		}
	}
}


/**
* Hides all drop down form select boxes on the screen so they do not appear above the mask layer.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*
* Thanks for the code Scott!
*/
function hideSelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
				document.forms[i].elements[e].style.visibility="hidden";
			}
		}
	}
}

/**
* Makes all drop down form select boxes on the screen visible so they do not reappear after the dialog is closed.
* IE has a problem with wanted select form tags to always be the topmost z-index or layer
*/
function displaySelectBoxes() {
	for(var i = 0; i < document.forms.length; i++) {
		for(var e = 0; e < document.forms[i].length; e++){
			if(document.forms[i].elements[e].tagName == "SELECT") {
			document.forms[i].elements[e].style.visibility="visible";
			}
		}
	}
}

// -- Generic functions ---------------------------------------------------------

// ------------------------------------------------------------------------------
// Función: ObjetoXMLRequest
// Acción: adquiere el objeto necesario para realizar un request
// Recibe: Nada
// Regresa: Objeto XMLHttpRequest
// ------------------------------------------------------------------------------
function ObjetoXMLRequest() {
      try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
      try { return new ActiveXObject("Msxml3.XMLHTTP"); } catch (e) {}
      try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
      try { return new XMLHttpRequest(); } catch(e) {}
      alert("XMLHttpRequest not supported");
      return null;
}

function $(id) {
  return document.getElementById(id);
}

// -- Generic functions ---------------------------------------------------------

/**
 * COMMON DHTML FUNCTIONS
 * These are handy functions I use all the time.
 *
 * By Seth Banks (webmaster at subimage dot com)
 * http://www.subimage.com/
 *
 * Up to date code can be found at http://www.subimage.com/dhtml/
 *
 * This code is free for you to use anywhere, just keep this comment block.
 */

/**
 * X-browser event handler attachment and detachment
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @argument obj - the object to attach event to
 * @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
 * @argument fn - function to call
 */
function addEvent(obj, evType, fn){
 if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
 } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
 } else {
    return false;
 }
}
function removeEvent(obj, evType, fn, useCapture){
  if (obj.removeEventListener){
    obj.removeEventListener(evType, fn, useCapture);
    return true;
  } else if (obj.detachEvent){
    var r = obj.detachEvent("on"+evType, fn);
    return r;
  } else {
    alert("Handler could not be removed");
  }
}

/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}