//*************************************************************************
// Archivo de funciones javascripts
// 
// Autor: Carlos Villaran Wiegering
// Creado: 02.10.2005
//*************************************************************************
var wTituloWeb = "FREE";

//*************************************************************************
// Desactiva el Click Derecho
//*************************************************************************
function mouseDown(e) {
	var clickType=1;
	if (parseInt(navigator.appVersion)>3) {
		if (navigator.appName=="Netscape") clickType=e.which;
		else clickType=event.button;

		if (clickType!=1) {
			alert (wTituloWeb+"\nEvento desabilitado");
			return false;
		}
	}
	return true;
}
document.onmousedown = mouseDown;
if (navigator.appName=="Netscape") 
	document.captureEvents(Event.MOUSEDOWN);

//*************************************************************************
// Abre un popup nuevo
//*************************************************************************
function fPopup(mypage, myname, w, h, scroll, pos) {
	var win=null;
	if(pos=="random") {
		LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;
		TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;
	}
	if(pos=="center") {
		LeftPosition=(screen.width)?(screen.width-w)/2:100;
		TopPosition=(screen.height)?(screen.height-h)/2:100;
	}
	else if((pos!="center" && pos!="random") || pos==null) {
		LeftPosition=0;
		TopPosition=20
	}
	settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
	win=window.open(mypage,myname,settings);
}
//*************************************************************************
// Abre una ventana de dialogo
//*************************************************************************
function fDialog(mypage, myname, w, h) {
	if (window.navigator.appVersion.indexOf("MSIE")!=-1) {
		dia = window.showModalDialog(mypage, myname, 'dialogHeight:'+h+'px; dialogWidth:'+w+'px; resizable:no; status:no');
	}
	else {
		fPopup(mypage, myname, w, h, "no", "center");
	}
}
//*************************************************************************
// Valida si exiten caracteres extraños en la cadena
//*************************************************************************
function fCarac_Ext(vCadena){
	forbiddenChars = "- ,./";
	var pass = vCadena;

	for (i=0;i<pass.length;i++) {
		ch = pass.charAt(i);
		if (forbiddenChars.indexOf(ch) !=-1) {
			return false;
		} 
	}
	return true;
} 
//*************************************************************************
// Valida si es un formato valido el email
//*************************************************************************
function fEsEmail(cad) {
	var i = 1;
	var cadLength = cad.length;
	
	// busca un '@'
	while ((i < cadLength) && (cad.charAt(i) != "@"))  i++;
	if ((i >= cadLength) || (cad.charAt(i) != "@"))	{
		return false;
	}
	else {
		i += 2;
	}
	// busca un '.'
	while ((i < cadLength) && (cad.charAt(i) != ".")) { 
		i++;
	}
	// debe haber por lo menos un caracter despues de '.'
	if ((i >= cadLength - 1) || (cad.charAt(i) != ".")) 
		return false;
    else return true;
}

function fVerf_Mail(Email) {
	var regEmail = /^[\w-]+(?:\.[\w-]+)*@(?:[\w-]+\.)+[a-zA-Z]{2,7}$/;
	return regEmail.test (Email);
}
//*************************************************************************
// Devuelve la fecha actual
//*************************************************************************
function makeArray() {
	var args = makeArray.arguments;
	for (var i = 0; i < args.length; i++) {
		this[i] = args[i];
	}
	this.length = args.length;
}
function fixDate(date) {
	var base = new Date(0);
	var skew = base.getTime();
	if (skew > 0)
		date.setTime(date.getTime() - skew);
}
function getString(date) {
	var months = new makeArray("Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre");
	var days = new makeArray("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");

	//return date.getDate() + "-" + date.getMonth() + "-" + date.getYear();
	return days[date.getDay()] + ", " + date.getDate() + " de " + months[date.getMonth()] + " del " + ((date.getYear() < 100) ? "19" : "") + date.getYear();
}
function fFecha() {
	var cur = new Date();
	fixDate(cur);

	var str = getString(cur);
	document.write(str);
}
//*************************************************************************
// Verifica si es una cadena está vacía.
//*************************************************************************
function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}
//*************************************************************************
// Verifica si es una cadena contiene sólo espacios en blanco,
// tabuladores, o retornos de linea)
//*************************************************************************
function isWhitespace(s) {   
	var i;
	var whitespace = " \t\n\r";
	if (isEmpty(s)) return true;
	for (i = 0; i < s.length; i++) {   
		var c = s.charAt(i);
		// si el caracter en que estoy no aparece en whitespace,
		// entonces retornar falso
		if (whitespace.indexOf(c) == -1) return false;
	}
	return true;
}
//*************************************************************************
// Redondear
//*************************************************************************
function fRedondear(cantidad,numdec) {
	aux = cantidad*Math.pow(10,(numdec+1));
	parte_decimal=aux % 1;
	aux = aux - parte_decimal;
	aux = aux + 5;
	aux = aux / 10;
	parte_decimal = aux % 1;
	aux = aux - parte_decimal;
	aux = aux / Math.pow(10,numdec);
	return aux; 
}
//*************************************************************************
// Formatea el número
//*************************************************************************
function formatNumber(value) {
	lowValue = Math.floor(value);
	var cents = 100*(value-lowValue) + 0.6;
	if (cents > 99) {
		returnNumber = lowValue ++;
		returnNumber += ".00";
	}
	else {
		returnNumber = lowValue + ".";
		returnNumber += Math.floor(cents/10);
		returnNumber += Math.floor(cents%10);
	}
	return returnNumber;
}
//*************************************************************************
// Corta caracateres
//*************************************************************************
function Mid(dato,pos,can) {
	var cadenan = "";
	var total=0; 
	total = ((pos+can)>dato.length) ? dato.length : pos+can ;
	total-=1;
		for ( var i=pos; i<=total; i++)
		{ cadenan+=dato.substring(i,i+1); }
		return(cadenan);
}
//*************************************************************************
// Quita los espacios
//*************************************************************************
function ltrim(str) {
	while(""+str.charAt(0)==" ") {
		str=str.substring(1,str.length);
	}
	return str;
}
function reverse(str) { 
	var reversedstr = "";
	var strArray;
	strArray = str.split("");
	for(var i = str.length -1 ; i >= 0 ; i--) {
		reversedstr += strArray[i];  
	}
	return reversedstr;
}
function trim(str) {
	str = ltrim(str);
	str = reverse(str);
	str = ltrim(str);
	str = reverse(str);
	return str;
}
//*************************************************************************
// Verifica si es número
//*************************************************************************
function fEsNumero(e) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < e.length && IsNumber == true; i++) { 
		Char = e.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}
function fSolo_Numero(nombre) {
	regexp=/^[0-9]+$/
	elemento=document.getElementById(nombre);
	if (elemento.value.match(regexp)==null) {
		elemento.value=elemento.value.substr(0,elemento.value.length-1);
	}
}
//*************************************************************************
// Verifica si es letra
//*************************************************************************
function fEsTexto(c) {
	var lowercaseLetters = "abcdefghijklmnopqrstuvwxyzñ"
	var uppercaseLetters = "ABCDEFGHIJKLMNOPQRSTUVWXYZÑ"
	
	return( ( uppercaseLetters.indexOf( c ) != -1 ) ||
			( lowercaseLetters.indexOf( c ) != -1 ) )
}
//*************************************************************************
// Valida el Código de Usuario
//*************************************************************************
function fVal_Usu(cadena) {
	var letrasminpermitidas = "abcdefghijklmnopqrstuvwxyzñ"
	var letrasmaypermitidas = "ABCDEFGHIJKLMNOPQRSTUVWXYZÑ"
	var otrospermitidos = "0123456789_"
  
	var car_inicial = cadena.charAt(0);
	
	if (fEsTexto(car_inicial)) {
		for (i=0;i<cadena.length;i++) {     
			letra = cadena.substring(i,i+1);
		   
			if ( ( letrasminpermitidas.indexOf( letra ) != -1 ) ||
				( letrasmaypermitidas.indexOf( letra ) != -1 ) ||
				( otrospermitidos.indexOf( letra ) != -1 ) ) {
			} 
			else return false;
	   }
	   return true;
	} 
	else return false;
}
//*************************************************************************
// Redirecciona a la página que debe ser
//*************************************************************************
function fIr_Url(s, c) {
	p = "";	t = "../";
	if (s == 8) r = "ayuda/";
	else r = "servicios/";

	var sec = new makeArray("antivirus/", "webmail/", "discoweb/", "correo/", "album/", "juegos/", "control/" , "chat/", "soporte.htm");

	for (i = 0; i < c; i++) {
		p = p + t;
	}
	url = p + r + sec[s];
	document.location.href = url;
}