// JavaScript
//
//  pageranker.js
//	rev001
//
function getObject(obj) {
	var theObj;
	if(document.all) {
		if(typeof obj=="string") {
			return document.all(obj);
		} else {
			return obj.style;
		}
	}
	if(document.getElementById) {
		if(typeof obj=="string") {
			return document.getElementById(obj);
		} else {
			return obj.style;
		}
	}
	return null;
}
function o() {
	var elements=new Array();
	for(var i=0;i<arguments.length;i++) {
		var element=arguments[i];
		if(typeof element=='string') element=document.getElementById(element);
		if(arguments.length==1) return element;
		elements.push(element);
	}
	return elements;
}
//----------------------------------------------------------------
function abc_menu(letra) {
	var alfabeto='abcdefghijklmnopqrstuvwxyz';
	//Iluminamos la letra marcada
	for(i=0;i<27;i++) o('abc_'+i).className='abc_off';
	o('abc_'+(alfabeto.indexOf(letra)+1)).className='abc_on';
	//Rellenamos la tabla inferior
	html='';
	if(letra=='#') {
		for(i=0;i<10;i++) html+=' <a href="index.php?m=listado&l='+i+'">'+i+'</a> ';
	} else {
		for(i=0;i<26;i++) html+=' <a href="index.php?m=listado&l='+letra+alfabeto.charAt(i)+'">'+letra.toUpperCase()+alfabeto.charAt(i)+'</a>';
	}
	o('sub').innerHTML=html;
}
//----------------------------------------------------------------
//Abre nueva ventana centrada en el centro de la pantalla
function ventana(theURL,winName,winWidth,winHeight) {
    var w = (screen.width - winWidth)/2;
    var h = (screen.height - winHeight)/2 - 50;
	if((winHeight%2)==1) {
		features = 'directories=no,location=no,menubar=no,scrollbars=yes,status=yes,toolbar=no,resizable=yes,width='+winWidth+',height='+winHeight+',top='+h+',left='+w;
	} else {
		features = 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width='+winWidth+',height='+winHeight+',top='+h+',left='+w;
	}
    window.open(theURL,winName,features);
}
//----------------------------------------------------------------
function submitOnce(theform) {
	if (document.all || document.getElementById) {
		for(i=0 ; i < theform.length ; i++) {
			var tempobj = theform.elements[i];
			if(tempobj.type.toLowerCase()=="submit"||tempobj.type.toLowerCase()=="reset") {
				tempobj.disabled=true;
			}
		}
	}
}
//----------------------------------------------------------------
//Contador de caracteres.
function contar(entrada,salida,texto,caracteres) {
	var entradaObj=o(entrada);
	var salidaObj=o(salida);
	var longitud=caracteres - entradaObj.value.length;
	if(longitud <= 0) {
		longitud=0;
		texto='&nbsp;'+texto+'&nbsp;';
		entradaObj.value=entradaObj.value.substr(0,caracteres);
	}
	salidaObj.innerHTML = texto.replace("{CHAR}",longitud);
}
//----------------------------------------------------------------
function validate(obj,modo,porDefecto, min) {
	var texto = obj.value;
	do {
		texto = texto.replace(/\|\|/,"|");
	} while(/\|\|/.test(texto));
	if(modo=="url") {
		if(texto.substr(0,7)!="http://" && texto.substr(0,8)!="https://") texto = "http://" + texto;
		texto = texto.replace(/ /,"");
	}
	if(modo=="email") {
		if(!/(.+)@(.+)\.(.+)/.test(texto)) texto = porDefecto;
		if(/[\s]+/.test(texto)) texto = porDefecto;
		if(texto.indexOf('@') != texto.lastIndexOf('@')) texto = porDefecto;
		var dominio = texto.substring(1+texto.lastIndexOf('.'));
		if( dominio.length>3 || dominio.length<2) texto = porDefecto;
	}
	if(modo=="icq") {
		do {
			texto = texto.replace(/[^0-9]/,"");
		} while(/[^0-9]/.test(texto));
	}
	if(modo=="number") {
		do {
			texto = texto.replace(/[^0-9]/,"");
		} while(/[^0-9]/.test(texto));
		if(texto=='') texto = porDefecto;
	}
	if(modo=="numberMin") {
		do {
			texto = texto.replace(/[^0-9]/,"");
		} while(/[^0-9]/.test(texto));
		if(texto=='') texto = porDefecto;
		if(parseInt(texto) < min) texto = porDefecto;
	}
	if(modo=="text") {
		if(texto=='') texto = porDefecto;
	}
	obj.value = texto;
}
//----------------------------------------------------------------
// Interactive Rating System using AJAX
// v1.0
// (c) Emilio José Jiménez Jiménez
//----------------------------------------------------------------
function getXmlHttpRequestObject() {
	if(window.XMLHttpRequest) {
		return new XMLHttpRequest(); //Not IE
	} else if(window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP"); //IE
	} else {
		alert("Your browser doesn't support the XmlHttpRequest object. Better upgrade to Firefox.");
	}
}
var ej3irs_request=getXmlHttpRequestObject();
var ej3irs_divID=null;
var ej3irs_url=null;
function ej3irs_IRS(divID,url,init) {
	ej3irs_divID=divID;
	ej3irs_url=url;
	ej3irs_init=init;
	html='<table id="'+divID+'_stars" width="77" style="background-image: url(imagenes/stars'+ej3irs_init+'.gif); cursor: pointer;" onMouseOver="return overlib(\'Select your rate, now is <img src=imagenes/rating'+(2*init)+'.gif align=absmiddle>\',CENTER);" onMouseOut="this.style.backgroundImage=\'url(imagenes/stars'+ej3irs_init+'.gif)\'; return nd();" cellpadding="0" cellspacing="0" border="0" alt="Rate it!!"><tr>';
	html+='<td width="6px" height="19px" onMouseOver="o(\''+divID+'_stars\').style.backgroundImage=\'url(imagenes/stars0.gif)\';" onClick="ej3irs_setRating(0); return nd();">&nbsp;</td>';
	html+='<td width="13px" onMouseOver="o(\''+divID+'_stars\').style.backgroundImage=\'url(imagenes/stars1.gif)\';" onClick="ej3irs_setRating(1); return nd();">&nbsp;</td>';
	html+='<td width="13px" onMouseOver="o(\''+divID+'_stars\').style.backgroundImage=\'url(imagenes/stars2.gif)\';" onClick="ej3irs_setRating(2); return nd();">&nbsp;</td>';
	html+='<td width="13px" onMouseOver="o(\''+divID+'_stars\').style.backgroundImage=\'url(imagenes/stars3.gif)\';" onClick="ej3irs_setRating(3); return nd();">&nbsp;</td>';
	html+='<td width="13px" onMouseOver="o(\''+divID+'_stars\').style.backgroundImage=\'url(imagenes/stars4.gif)\';" onClick="ej3irs_setRating(4); return nd();">&nbsp;</td>';
	html+='<td width="19px" onMouseOver="o(\''+divID+'_stars\').style.backgroundImage=\'url(imagenes/stars5.gif)\';" onClick="ej3irs_setRating(5); return nd();">&nbsp;</td>';
	html+='</tr></table>';
	o(ej3irs_divID).innerHTML=html;
}
function ej3irs_setRating(rating) {
	if(ej3irs_request.readyState==4 || ej3irs_request.readyState==0) {
		ej3irs_request.open("GET",ej3irs_url+rating,true);
		ej3irs_request.onreadystatechange=ej3irs_update;
		ej3irs_request.send(null);
	}
}
function ej3irs_update() {
	if(ej3irs_request.readyState==4) {
		o(ej3irs_divID).innerHTML=ej3irs_request.responseText;
	}
}
//----------------------------------------------------------------