function checkString(s) {
		regString = /([a-zA-Z0-9_\- .]+)/;
		if (s == "") {
             		 return 1;
       	}
       	sname = regString.exec(s)
	    if ((sname == null) || (sname[0] != s)) {
    		return 2;
	    }
        return 0;
 }
 function Abre(url,ancho,alto,nombre)
{
  window.open(url,nombre,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width='+ancho+',height='+alto);
}

function chequeo(formu) {
	if(!document.formu.ext-name.checked){
		checkString(document.formu.Nombre);
	}	
	return true;
}

function UpdateThumbnail(name)
{
	window.document.userinfo['thumbnail'].src = './images/avatar/' + name;
}

function showImgSelected(imgId, selectId, imgDir) {
	imgDom = GetElementById(imgId);
	selectDom = GetElementById(selectId);
	imgDom.src = "http://ww2.planetacom.net/planetacom/pagina/"+ imgDir + "/" + selectDom.options[selectDom.selectedIndex].value;
}

function Validate_userinfo()
{
	if ( document.userinfo.Apodo.value == "" ){
		alert( "Por favor ingrese apodo" );
		document.userinfo.Apodo.focus();
		return false;
	}
	if( document.userinfo.Email.value == "" ){
		alert( "Por favor ingrese email" );
		document.userinfo.Email.focus();
		return false;
	}
	if ( document.userinfo.Pass.value == "" ){
		alert( "Por favor ingrese pass" );
		document.userinfo.Pass.focus();
		return false;
	}
	if ( document.userinfo.VPass.value == "" ){
		alert( "Por favor ingrese pass de comprobacion" );
		document.userinfo.VPass.focus();
		return false;
	}
}
function GetElementById(id){
	if (document.getElementById) {
		return (document.getElementById(id));
	} else if (document.all) {
		return (document.all[id]);
	} else {
		if ((navigator.appname.indexOf("Netscape") != -1) && parseInt(navigator.appversion == 4)) {
			return (document.layers[id]);
		}
	}
}


function openWithSelfMain(url,name,width,height){
	var options = "width=" + width + ",height=" + height + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
	new_window = window.open(url, name, options);
	window.self.name = "main";
	new_window.focus();
}

function reemplazarGuion(cadena)
{  
	var re, r, result;  
	re = /_/i;  
	r = cadena.replace(re," ");  
	re = /Espana/i;  
	result = r.replace(re,"Espa\xf1a");  
	return(result);
}
function reemplazarEspacio(cadena){  
	var re, r;  
	re = /\s/i;
	r = cadena.replace(re,"_");  
	re = /Espa\xf1a/i;  
	result = r.replace(re,"Espana");  
	return(result);
}

function MM_openBrWindow(theURL,winName,features){    
	window.open(theURL,winName,features);
}

function chequeaEmail(stremail)
{
    var x = stremail;
    var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
    if (filter.test(x)) return true;
    else return false;
}

function chequeo(userinfo) {        
	if (document.userinfo.NumCategorias.value==0) {        
		alert ("Por favor, seleccione al menos 1 categoria.");
		return false;	
	}
	if (!userinfo.Pais.value)        
	{          
		alert ("Por favor, elija su Pais.");
		return false;        
	}        
	if (!userinfo.Provincia.value) 
	{          
		alert ("Por favor, elija su Provincia.");
		return false;        
	}
	if (userinfo.Profesion.value=="-1") 
	{          
		alert ("Por favor, elija una profesión.");
		return false;        
	}         
	if (document.userinfo.Provincia.options[document.userinfo.Provincia.selectedIndex].value == "cero")
	{          
		alert ("Por favor, debe rellenar el campo Provincia.");
		return false;        
	}
	return true;
}

function validate(subjectId, textareaId) {
	var maxchars = 65535;
	var subjectDom = GetElementById(subjectId);
	var textareaDom = GetElementById(textareaId);
	if (textareaDom.value == "" || subjectDom.value == "") {
		alert("Por favor Complete los campos de tema y mensaje");
		return false;
	}
	if (maxchars != 0) {
		if (textareaDom.value.length > maxchars) {
			alert("Su mensaje es demasiado largo\n\nLongitud de caracteres máx permitida: " + maxchars + "\nLongitud actual de caracteres: " + textareaDom.value.length + "");
			textareaDom.focus();
			return false;
		} else {
			return true; 
		}
	} else {
		return true;
	}
}

function justReturn() {
	return;
}

function CodeUrl(id){
	var text = prompt("Ingrrese el URL del enlace que quiere agregar:", "");
	var dom = GetElementById(id);
	if ( text != null && text != "" ) {
		var text2 = prompt("Ingrese el título del sitio web:", "");
		if ( text2 != null ) {
			if ( text2 == "" ) {
				var result = "<url=" + text + ">" + text + "</url>";
			} else {
				var result = "<url=" + text + ">" + text2 + "</url>";
			}
			dom.value += result;
		}
	}
	dom.focus();
}

function CodeImg(id){
	var text = prompt("Ingrrese el URL de la imágen que quiere agregar:", "");
	var dom = GetElementById(id);
	if ( text != null && text != "" ) {
		var text2 = prompt("Ahora, ingrese la posición de la imágen.\n'R' o 'r' para Derecha, 'L' o 'l' para izquierda, o dejela en blanco.", "");
		while ( ( text2 != "" ) && ( text2 != "r" ) && ( text2 != "R" ) && ( text2 != "l" ) && ( text2 != "L" ) && ( text2 != null ) ) {
			text2 = prompt("ERROR! Ingrese la posición de la imágen.\n'R' o 'r' para Derecha, 'L' o 'l' para izquierda, o dejela en blanco.","");           
		}
		if ( text2 == "l" || text2 == "L" ) { 
			text2 = " align=left";
		} else if ( text2 == "r" || text2 == "R" ) {
			text2 = " align=right";
		} else {
			text2 = "";
		}
		var result = "<img" + text2 + ">" + text + "</img>";
		var dom = GetElementById(id);
		dom.value += result;
	}
	dom.focus();
}

function CodeEmail(id){
	var text = prompt("Ingrese la dirección de email que quiere agregar.", "");
	var dom = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "<email>" + text + "</email>";
		dom.value += result;
	}
	dom.focus();
}

function CodeQuote(id){
	var text = prompt("Iingrese el texto que quiere que esté acotado.", "");
	var dom = GetElementById(id);
	if ( text != null && text != "" ) {
		var result = "<quote>" + text + "</quote>";
		dom.value += result;
	}
	dom.focus();
}

function CodeText(id){
	var textareaDom = GetElementById(id);
	var textDom = GetElementById(id + "Addtext");
	var fontDom = GetElementById(id + "Font");
	var colorDom = GetElementById(id + "Color");
	var sizeDom = GetElementById(id + "Size");
	var hiddenTextDomStyle = GetElementById("hiddenText").style;
	var textDomValue = textDom.value;
	var fontDomValue = fontDom.options[fontDom.options.selectedIndex].value;
	var colorDomValue = colorDom.options[colorDom.options.selectedIndex].value;
	var sizeDomValue = sizeDom.options[sizeDom.options.selectedIndex].value;
	if ( textDomValue == "" ) {
		alert("Por favor ingrese el texto dentro del cuadro de texto.");
		textDom.focus();
	} else {
		if ( fontDomValue != "FONT") {
			textDomValue = "<font=" + fontDomValue + ">" + textDomValue + "</font>";
			fontDom.options[0].selected = true;
		}
		if ( colorDomValue != "COLOR") {
			textDomValue = "<font color=" + colorDomValue + ">" + textDomValue + "</font>";
			colorDom.options[0].selected = true;
		}
		if ( sizeDomValue != "SIZE") {
			textDomValue = "<font size=" + sizeDomValue + ">" + textDomValue + "</font>";
			sizeDom.options[0].selected = true;
		}
		if ( GetElementById(id + "Bold").checked == true ) {
			textDomValue = "<b>" + textDomValue + "</b>";
			GetElementById(id + "Bold").checked = false;
		}
		if ( GetElementById(id + "Italic").checked == true ) {
			textDomValue = "<i>" + textDomValue + "</i>";
			GetElementById(id + "Italic").checked = false;
		}
		if ( GetElementById(id + "Underline").checked == true ) {
			textDomValue = "<u>" + textDomValue + "</u>";
			GetElementById(id + "Underline").checked = false;
		}
		textareaDom.value += textDomValue;
		textDom.value = "";
		hiddenTextDomStyle.color = "#000000";
		hiddenTextDomStyle.fontFamily = "";
		hiddenTextDomStyle.fontStyle = "normal";
		hiddenTextDomStyle.fontSize = "12px";
		hiddenTextDomStyle.fontWeight = "normal";
		hiddenTextDomStyle.textDecoration = "none";
		hiddenTextDomStyle.visibility = "hidden";
		textareaDom.focus();
	}
}

function CodeSmilie(id, smilieCode) {
	var revisedMessage;
	var textareaDom = GetElementById(id);
	revisedMessage = textareaDom.value + smilieCode;
	textareaDom.value = revisedMessage;
	textareaDom.focus();
	return;
}

function setVisible(id){
	GetElementById(id).style.visibility = "visible";
}

function setHidden(id){
	GetElementById(id).style.visibility = "hidden";
}

function makeBold(id){
	var eleStyle = GetElementById(id).style;
	if (eleStyle.fontWeight != "bold") {
		eleStyle.fontWeight = "bold";
	} else {
		eleStyle.fontWeight = "normal";
	}
}

function makeItalic(id){
	var eleStyle = GetElementById(id).style;
	if (eleStyle.fontStyle != "italic") {
		eleStyle.fontStyle = "italic";
	} else {
		eleStyle.fontStyle = "normal";
	}
}

function makeUnderline(id){
	var eleStyle = GetElementById(id).style;
	if (eleStyle.textDecoration != "underline") {
		eleStyle.textDecoration = "underline";
	} else {
		eleStyle.textDecoration = "none";
	}
}
function openWithSelfMain(url,name,width,height){
	var options = "width=" + width + ",height=" + height + "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no";
	new_window = window.open(url, name, options);
	window.self.name = "main";
	new_window.focus();
}

function init() {

}

function setElementColor(id, color){
	GetElementById(id).style.color = "#" + color;
}

function setElementFont(id, font){
	GetElementById(id).style.fontFamily = font;
}

function setElementSize(id, size){
	GetElementById(id).style.fontSize = size;
}

function changeDisplay(id){
	var elestyle = GetElementById(id).style;
	if (elestyle.display == "") {
		elestyle.display = "none";
	} else {
		elestyle.display = "block";
	}
}

function setVisible(id){
	GetElementById(id).style.visibility = "visible";
}

function setHidden(id){
	GetElementById(id).style.visibility = "hidden";
}

function makeBold(id){
	var eleStyle = GetElementById(id).style;
	if (eleStyle.fontWeight != "bold") {
		eleStyle.fontWeight = "bold";
	} else {
		eleStyle.fontWeight = "normal";
	}
}

function makeItalic(id){
	var eleStyle = GetElementById(id).style;
	if (eleStyle.fontStyle != "italic") {
		eleStyle.fontStyle = "italic";
	} else {
		eleStyle.fontStyle = "normal";
	}
}

function makeUnderline(id){
	var eleStyle = GetElementById(id).style;
	if (eleStyle.textDecoration != "underline") {
		eleStyle.textDecoration = "underline";
	} else {
		eleStyle.textDecoration = "none";
	}
}

function appendSelectOption(selectMenuId, optionName, optionValue){
	var selectMenu = GetElementById(selectMenuId);
	var newoption = new Option(optionName, optionValue);
	selectMenu.options[selectMenu.length] = newoption;
	selectMenu.options[selectMenu.length].selected = true;
}

function disableElement(target){
	var targetDom = GetElementById(target);
	if (targetDom.disabled != true) {
		targetDom.disabled = true;
	} else {
		targetDom.disabled = false;
	}
}
function CheckAll(formname, switchid) {
	var ele = document.forms[formname].elements;
	var switch_cbox = GetElementById(switchid);
	for (var i = 0; i < ele.length; i++) {
		var e = ele[i];
		if ( (e.name != switch_cbox.name) && (e.type == 'checkbox') ) {
			e.checked = switch_cbox.checked;
		}
	}
}


window.onload=init;
