// DETECTOR DE BROWSER //
var dom = document.getElementById ? true:false;
var nn4 = document.layers ? true:false;
var ie4 = document.all ? true:false;
// DETECTOR DE BROWSER //



// CAMBIO DE IMAGENES

var status = 1;
var toc = new Array();

function item(off, over){
	this.off = new Image(); this.off.src = off;
	this.over = new Image(); this.over.src = over;
}
function cache(id, off, over){
	item[id] = new item(off, over);
	toc[toc.length] = id;
}
function over(id){
	document[id].src = item[id].over.src;
}
function out(id){
	document[id].src = item[id].off.src;
}

function IrAPagina(num) {
  document.frmPrincipal.pagina.value = num;
  document.frmPrincipal.submit();
}

function wizard() {
  window.open("../wizard", "wizard", "scrollbars=no,resizable=no,location=no,width=600,height=500,top=100,left=100");
}

function BuscarInternos(){
  if ( document.frmPrincipal.text_interno.value.length ) {
    if (document.frmPrincipal.cantidad_total) document.frmPrincipal.cantidad_total.value = 0 ;
    if (document.frmPrincipal.pagina) document.frmPrincipal.pagina.value = 0 ;
    if (document.frmPrincipal.paginamax) document.frmPrincipal.paginamax.value = 0 ;
    document.frmPrincipal.action       = "resultado_internos.asp"
    document.frmPrincipal.accion.value = "BuscarInternos";
    document.frmPrincipal.submit();
  }else{
    alert("Por favor, ingrese un texto");
    document.frmPrincipal.text_interno.focus();
  }

}

function BuscarInternosAv(){
    document.frmPrincipal.action       = "resultado_internos.asp?nombre=" + document.frmPrincipal.nombre.value + "&idxagencia=" + document.frmPrincipal.idxagencia.value + "&idxsector=" + document.frmPrincipal.idxsector.value + "&idxpuesto=" + document.frmPrincipal.idxpuesto.value + "&idxfuncion=" + document.frmPrincipal.idxfuncion.value + "&interno=" + document.frmPrincipal.interno.value
    document.frmPrincipal.accion.value = "BuscarInternos";
    document.frmPrincipal.submit();
}


function BuscarDocumento(){
  if ( document.frmPrincipal.text_documento.value.length ) {
    if (document.frmPrincipal.cantidad_total) document.frmPrincipal.cantidad_total.value = 0 ;
    if (document.frmPrincipal.pagina) document.frmPrincipal.pagina.value = 0 ;
    if (document.frmPrincipal.paginamax) document.frmPrincipal.paginamax.value = 0 ;
    document.frmPrincipal.action       = "resultado_documentos.asp"
    document.frmPrincipal.accion.value = "BuscarDocumentos";
    document.frmPrincipal.submit();
  }else{
    alert("Por favor, ingrese un texto");
    document.frmPrincipal.text_documento.focus();
  }
}

function BuscarDocumentosAv(){
    document.frmPrincipal.action       = "resultado_documentos.asp?nombre=" + document.frmPrincipal.nombre.value + "&idxcategoria=" + document.frmPrincipal.idxcategoria.value + "&ext=" + document.frmPrincipal.ext.value;
    document.frmPrincipal.accion.value = "BuscarDocumentos";
    document.frmPrincipal.submit();
}


// Formatos: mm-dd-yyyy or mm/dd/yyyy.

function isDate(dateStr) {

  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is the format ok?

  if (matchArray == null) {
    return false;
  }

  month = matchArray[1]; // parse date into variables
  day = matchArray[3];
  year = matchArray[5];

  if (month < 1 || month > 12) { // check month range
    return false;
  }

  if (day < 1 || day > 31) {
    return false;
  }

  if ((month==4 || month==6 || month==9 || month==11) && day==31) {
    return false;
  }

  if (month == 2) { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
    if (day > 29 || (day==29 && !isleap)) {
      return false;
    }
  }
  return true; // date is valid
}

function compareDates(strInput1, strInput2, strUnidad) {
//	Si son fechas válidas, las paso a arrays para compararlas.
	var arrFecha1 = strInput1.split("/");
	var datFechaValida1 = new Date(arrFecha1[2], arrFecha1[1] - 1, arrFecha1[0]);
	var arrFecha2 = strInput2.split("/");
	var datFechaValida2 = new Date(arrFecha2[2], arrFecha2[1] - 1, arrFecha2[0]);
	var intAjuste;

	switch (strUnidad) {
//		El resultado te lo devuelve en años
		case "a":
		case "A":
			intAjuste = 86400000 * 365;
			break;
//		El resultado te lo devuelve en horas
		case "h":
		case "H":
			intAjuste = 86400000 / 24;
			break;
//		El resultado te lo devuelve por default en días
		case "d":
		case "D":
		default:
			intAjuste = 86400000;
			break;
	}

	return ((datFechaValida1 - datFechaValida2) / intAjuste);
}

function verImagen(idx) {
  window.open("imagen.asp?idx=" + idx, "verImagen", "resizable=yes,location=no,scrollbars=no,width=200,height=200");
}

function EnviarAmigo(idxseccion, link) {
  window.open("enviar_amigo.asp?idxseccion=" + idxseccion + "&link=" + link, "EnviarAmigo", "resizable=no,location=no,scrollbars=no,width=400,height=215,top=50,left=50");
}

function EnviarAmigo2(idx, idxseccion, titulo, img_cabezal, objeto ) {
  window.open("displayObjeto.asp?idxseccion=" + idxseccion + "&titulo=" + titulo + "&img_cabezal=" + img_cabezal + "&objeto=" + objeto, "EnviarAmigo2", "resizable=no,location=no,scrollbars=yes,width=500,height=500,top=50,left=50");
}

function EnviarAmigo3(idx, idxseccion, titulo, img_cabezal, objeto ) {
  window.open("displayObjeto.asp?idx=" + idx + "&idxseccion=" + idxseccion + "&titulo=" + titulo + "&img_cabezal=" + img_cabezal + "&objeto=" + objeto, "EnviarAmigo2", "resizable=no,location=no,scrollbars=yes,width=500,height=500,top=50,left=50");
}

function divSubSecc(num) {
  document.getElementById('secciones1').style.visibility = 'hidden';
  document.getElementById('secciones2').style.visibility = 'hidden';
  document.getElementById('secciones3').style.visibility = 'hidden';
  document.getElementById('secciones4').style.visibility = 'hidden';

  for(i=0 ; i < document.frmPrincipal.elements.length ; i++) {
    if(document.frmPrincipal.elements[i].type == 'select-one') {
      document.frmPrincipal.elements[i].style.visibility = 'visible';
    }
  }

  if(num) {
    if(document.getElementById('secciones' + num).style.visibility == 'visible') {
      document.getElementById('secciones' + num).style.visibility = 'hidden';
    } else {
      document.getElementById('secciones' + num).style.visibility = 'visible';
      for(i=0 ; i < document.frmPrincipal.elements.length ; i++) {
        if(document.frmPrincipal.elements[i].type == 'select-one') {
          document.frmPrincipal.elements[i].style.visibility = 'hidden';
        }
      }
    }
  }
}

function verPresentacion() {
  window.open("presentacion/index.asp","verPresentacion", "resizable=no,location=no,scrollbars=no,width=799,height=590,top=0,left=0");
}

function calendario(campo, fecha, path) {
  Dia = Mes = Ano = '';
  if(fecha.length) 
  {
  	var strFecha = fecha.split(' ');
  	var tmp 	= new Array();
    tmp 			= strFecha[0].split('-');
    Dia 			= tmp[2];
    Mes 			= tmp[1];
    Ano 			= tmp[0];
  }
  window.open(path + "objetos/calendario.asp?campo=" + campo + "&Dia=" + Dia + "&Mes=" + Mes + "&Ano=" + Ano,"calendario", "resizable=no,location=no,scrollbars=no,width=300,height=300,top=80,left=80");
}

function BorrarCalendario(campo){
	document.getElementById(campo).value = "";
	document.getElementById(campo+"_texto").value = "";
}

function disableField(campo, val) {
  campo.disabled = val? true:false;
}

Array.prototype.search = function (texto)
{
	retorno = -1;
	i=0;
	while(i<this.length && retorno==-1)
	{
		if(this[i] == texto) retorno = i;
		i++;
	}
	return retorno;
}

function trim(valor)
{
	var re = /^(\s)*|(\s)*$/;
	var str = (valor ? valor : this);
	return str.replace(re,'');
}
String.prototype.trim = trim;

function check_email(email){
  var strRegExp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
  return strRegExp.test(email);
}

function fDloadAll() {
  if(window.dloadAll) {
    dloadAll();
  }
}

function windowOpen(url, nombre, ancho, altura) {
	window.open(url, nombre, 'top=150, left=150, toolbar=no, status=no, scrollbars=yes, location=no, width='+ancho+', height='+altura);
}

function fRecordarPassword() {
  windowOpen('recordar_pwd.asp', 'RecordarPassword', 500, 150);
}

function imprimirPedido(idx) {
	window.open("pedidos_imprimir.asp?idx=" + idx,"ImprimirPedido" + idx,"width=480,height=400,menubar=no,scrollbars=yes");
}

function previewPedido(idx) {
	window.open("pedidos_imprimir.asp?notprint=1&idx=" + idx,"previewPedido" + idx,"width=480,height=400,menubar=no,scrollbars=yes");
}

function fCambiarPassword() {
  windowOpen('cambiar_pwd.asp', 'RecordarPassword', 500, 300);
}
