function popUp(URL,width,height) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,directories=0,location=0,statusbar=0,menubar=0,resizable=0,width="+width+",height="+height+"');");
}

function mostrar(id) {
	popUp("mensaje.php?id="+id,200,200);
}

function show(id)
{
	if($(id).style["display"]!="none")
	{
		$(id).style["display"]="none";
	}else{
		$(id).style["display"]="";
	}
}


// actualizador
function actualizador(id)
{
	var pars="id="+id;
	var myAjax = new Ajax.Updater("divCarrito", "addCarrito.php",{method: 'get', parameters: pars});	
}


// llama a ajax para cerrar sesion
function cerrarSesion()
{
	var myAjax = new Ajax.Request(
		"cerrarSesion.php", 
		{
			method: 'GET', onComplete: window.location="index.php"
		});
}

function $RF(el, radioGroup) { 
    if($(el).type && $(el).type.toLowerCase() == 'radio') { 
        var radioGroup = $(el).name; 
        var el = $(el).form; 
    } else if ($(el).tagName.toLowerCase() != 'form') { 
        return false; 
    } 
    var checked = $(el).getInputs('radio', radioGroup).find( 
        function(re) {return re.checked;} 
    ); 
    return (checked) ? $F(checked) : null; 
}

function checkMailRepeat(){
	var error = false;
	if($('password').value != $('password2').value){
		error = true;
		$('password').style["background"] = "#F00";
		$('password2').style["background"] = "#F00";
	}
	if (error == true) {
            alert('Los campos password deben ser iguales entre si');
        }
	return !error;
}

function checkForm(id) {
        var error = false;
	var pass  = 0;
	var txtPass  = "";
        $$('form#'+id+' .required').each(function(node){
            if (node.value == "") {
                error = true;
                node.style.background = "#F00";
		errRequired="Asegurate de rellenar todos los campos requeridos"
            }
        });
	

        $$('form#'+id+' .email').each(function(node){

            if ((node.value.indexOf(".") < 2) || (node.value.indexOf("@") < 0)) {
                error = true;
                node.style.background = "#F00";
            }
        });
	
	
        $$('form#'+id+' .numeric').each(function(node){
            var strChars = "0123456789.-";
            for (i = 0; i < node.value.length; i++) {
                strChar = node.value.charAt(i);
                if (strChars.indexOf(strChar) == -1) {
                    error = true;
                    node.style.background = "#F00";
                }
            }
        });
        if (error == true) {
            alert('Asegurate de rellenar todos los campos requeridos');
        }
	
	return !error && checkMailRepeat();
    }
