var IE4 = (document.all) ? true : false;
var NS4 = (document.layers) ? true : false;
var NS6 = (!IE4 && document.getElementById) ? true : false;
var MAC = (navigator.userAgent.indexOf('Mac') > -1)
var layerAct = '';

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x, o;  
  if (!d) d=document; 
  if ((p=n.indexOf("?"))>0&&parent.frames.length) {
  	d=parent.frames[n.substring(p+1)].document; 
	n=n.substring(0,p);}
  if (!(x=d[n])&&d.all) 
  	x=d.all[n]; 
  for (i=0;!x&&i<d.forms.length;i++) 
    x=d.forms[i][n];
  for (i=0;!x&&d.layers&&i<d.layers.length;i++) {
	alert("layer: " + i);
    x=MM_findObj(n,d.layers[i].document);
  };
return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_showHideLayers() { //v3.0	
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v;}
    obj.visibility=v; }
}

function MM_openBrWindow(theURL,winName,features) {
	window.open(theURL,winName,features);
}
function AbrirVentana(sHRef,nWidth,nHeight,sScrolls, sName) {
var nLeft
var nTop
	nLeft = (screen.width - nWidth) / 2;
	nTop = (screen.height - nHeight) / 2 - 20;
	return window.open(sHRef,sName,'width='+nWidth+',height='+nHeight+',left='+nLeft+',top='+nTop+',scrollbars='+sScrolls);
}

function ShowHideLayer(layer, opcion, trans){
	if (NS6) {
		objeto = document.getElementById(layer);
		estilo = objeto.style;
		estilo.visibility = opcion;
		estilo.zIndex = 500;
		}
	if (IE4) {
		objeto = document.getElementById(layer);
		estilo = objeto.style;
		if (!MAC && trans!='no') {
		estilo.filter = 'blendTrans(duration=1)';
		objeto.filters.blendTrans.Apply();
		objeto.filters.blendTrans.Play();
		}
		estilo.visibility = opcion;
		estilo.zIndex = 500;
		}
}

function ShowLayerMouse(e){
	if (layerAct == '') return;
	objeto = document.getElementById(layerAct);
	layerAct = '';
	estilo = objeto.style;
	if (IE4) {
		X = document.body.clientWidth - event.clientX;
		if (X < objeto.clientWidth) {estilo.left = document.body.clientWidth - objeto.clientWidth} else {estilo.left = event.clientX};
		Y = document.body.clientHeight - event.clientY;
		if (Y < objeto.clientHeight)
			estilo.top = document.body.clientHeight - objeto.clientHeight + document.body.scrollTop
		else
			estilo.top = event.clientY;
		estilo.filter = 'blendTrans(duration=1)';
		objeto.filters.blendTrans.Apply();
		objeto.filters.blendTrans.Play();
	} else if (NS6) {
		X = document.width - e.pageX;
		if (X < objeto.offsetWidth) {estilo.left = document.width - objeto.offsetWidth} else {estilo.left = e.pageX};
		Y = document.height - e.pageY;
		if (Y < objeto.offsetHeight) {estilo.top = document.height - objeto.offsetHeight} else {estilo.top = e.pageY};
	}
	estilo.visibility = 'visible';
	estilo.zIndex = 500;
}


function trim(mObj) {
var sAux = mObj.value;
	while (sAux.length > 0 && sAux.charAt(0) == " ") sAux = sAux.substr(1);
	while (sAux.length > 0 && sAux.charAt(sAux.length - 1) == " ") sAux = sAux.substr(0, sAux.length - 1);
	mObj.value = sAux;
};

function EmailValido(sEmail) {
	if (window.RegExp) {
		var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
		var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
		var reg1 = new RegExp(reg1str);
		var reg2 = new RegExp(reg2str);
		if (!reg1.test(sEmail) && reg2.test(sEmail)) {
			return true
		} else {
			return false
		};
	} else if(str.indexOf("@") >= 0) {
		return true
	} else {
		return false
	}
}

function PasswordValido(sPass) {
	if (sPass.length < 5) {
		return false
	} else {
		return true
	}
}

function FechaValida(fecha) {
	var s = fecha.split("/");
	if (s.length != 3) return false;
	var dia = s[0];
	var mes = s[1];
	var anio = s[2];
	var d = new Date(anio, mes-1, dia)
	if (anio != d.getFullYear() || mes-1 != d.getMonth() || dia != d.getDate()) {
		return false;
	} else {
		return true;
	};
};

function textoauto(texto){
	obj = document.getElementById('txtauto')
	obj.innerHTML = texto
}

function mapOver(sDiv, on, clLeft, clTop, clRight, clBottom) {
	var whichEl;
	if (IE4 || NS6) {
		whichEl = document.getElementById(sDiv).style
	} else if (NS4) {
		whichEl = document.elMenu.document[sDiv]
	} else {
		return
	};
	if (!on) { whichEl.visibility = 'hidden'; return };
	if (NS4) {
		whichEl.clip.left = clLeft;
		whichEl.clip.top = clTop;
		whichEl.clip.right = clRight;
		whichEl.clip.bottom = clBottom;
	} else {
		whichEl.clip = 'rect(' + clTop + ' ' + clRight + ' ' + clBottom + ' ' + clLeft + ')';
	}
	whichEl.visibility = 'visible' 
}
function SeleccionarFoto(foto, campo) {
	var mFoto = new Array(foto)
	var a= window.showModalDialog('../administracion/fotobrowser.asp?file='+foto, mFoto, 'dialogWidth:506px;dialogHeight:400px;status:no;help:no;scroll:no');
	if (mFoto[0] != foto && mFoto[0] != "") campo.value = mFoto[0];
}

function SubirFoto(foto, campo) {
	AbrirVentana('../administracion/fileupload.asp?dir=' + foto + '&campo=' + campo, 500, 372, 'no', 'upload');
}
function button_over(eButton) {
	eButton.style.backgroundColor = "#B5BDD6";
	eButton.style.borderColor = "darkblue";
}

function button_out(eButton) {
	eButton.style.backgroundColor = "menu";
	eButton.style.borderColor = "menu";
}
function verSpan(nombre, imagen) {
	var span = document.getElementById(nombre);
	var img = document.getElementById(imagen);
	if(span.style.display=="block") {
		span.style.display="none";
		if (imagen!=0) {
			img.src = 'images/mas.gif';
		}
	} else {
		span.style.display="block";
		if (imagen!=0) {
			img.src = 'images/menos.gif';		
		}
	}
}
	
function trimValor(cadena) {
	while (cadena.charAt(0)==" ") {
		cadena = cadena.substring(1, cadena.length);
	}
	return cadena;
}

