// JavaScript Document

function NewWindow(url,name,ww,hh){
	var atributos = "toolbar=0,location=0,directories=0,dependent,menubar=0,resizable=1,scrollbars=1,status=1"
	nueva_ventana=window.open(url,name,atributos + ",height=" + hh + ",width=" + ww + ",top=100,left=100");
}
function MostrarOcultar(nombreCapa){
	if (document.getElementById(nombreCapa).style.visibility=="hidden"){
	document.getElementById(nombreCapa).style.visibility="visible";}
	else{document.getElementById(nombreCapa).style.visibility="hidden"; }
	if(document.getElementById(nombreCapa).style.display == 'inline') {
			document.getElementById(nombreCapa).style.display = 'none';
		} else {
			document.getElementById(nombreCapa).style.display = 'inline';
		}
} 
function Micropago(file)
{
	var atributos = "toolbar=0,location=0,directories=0,dependent,menubar=0,resizable=1,scrollbars=1,status=1,width=450,height=280,top=100,left=100"
	nueva_ventana=window.open('download.asp?file_id='+file,name,atributos);
}

function MicropagoArticulo(file)
{
	var atributos = "toolbar=0,location=0,directories=0,dependent,menubar=0,resizable=1,scrollbars=1,status=1,width=450,height=280,top=100,left=100"
	nueva_ventana=window.open('download.asp?articulo=true&file_id='+file,name,atributos);
}

function WIndowAlert(titulo,mensaje){
	alert(titulo + " " + mensaje);
}

function Validar(formulario){
	if (!validarDe(formulario.txtDe) || !validarEmail(formulario.txtEmail) || !validarAsunto(formulario.txtAsunto) || !validarTexto(formulario.txtTexto) || !validarVisual(formulario.txtVisualPass)){
		return false;
	}
	else {
		return true;
	}
}

function validarForm(f)
{
	if(!vT(f.item_name,'No ha seleccionada ningún producto') || !vM(f.amount,'No se puede procesar la compra\n Recargue la página ó seleccione que opción desea comprar') || 
		!vT(f.first_name,'Ingrese su nombre') || !vT(f.last_name,'Ingrese su apellido') || !validarEmail(f.email) || !vT(f.address1,'Ingrese su dirección') || 
		!vT(f.state,"Ingrese su Estado ó Provincia") || !vT(f.city,"Ingrese su ciudad") || !vN(f.night_phone_a,"Ingrese su número de teléfono"))
	{
		return false;
	}
	else
	{
		return true;
	}
		
}

function MostrarError(mensaje,error,elemento){
	WIndowAlert("Error: " + error + "\n\n",mensaje);
	elemento.focus();
	return false;
}

function MError(mensaje,elemento){
	WIndowAlert("Error: ",mensaje);
	elemento.focus();
	return false;
}

function validarEmail(elemento){
	if (!checkEmail(elemento.value)){
	return MostrarError("Ingrese una dirección de correo válida","Correo electrónico",elemento);
	}
	return true;
}

function checkEmail(emailStr) {
	var s = emailStr;
	var filter=/^[A-Za-z][A-Za-z0-9_.\-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (filter.test(s))
		return true;
	else
		return false;
}

function checkN(n){
	var filtro=/^[0-9]{7,}$/;
	if(filtro.test(n))
		return true;
	else
		return false;
}

function checkMonto(n){
	var filtro=/^[0-9]{1,}.[0-9]{1,}$/;
	if(filtro.test(n))
		return true;
	else
		return false;
}

function vN(e,t){
	if(!checkN(e.value))
		return MError(t,e);
	else
		return true;
}

function vM(e,t){
	if(!checkMonto(e.value))
		return MError(t,e);
	else
		return true;
}

function vT(e,t){
	if(e.value=="")
		return MError(t,e);
	else
		return true;
}

function validarDe(elemento){
	if (elemento.value=="") {
	return MostrarError("Ingrese su nombre y apellido","Nombre y apellido",elemento);
	}
	return true;
}

function validarAsunto(elemento){
	if (elemento.value=="") {
	return MostrarError("Ingrese el motivo de su comunicación en el campo 'Asunto'","Asunto del mensaje",elemento);
	}
	return true;
}

function validarTexto(elemento){
	if (elemento.value=="") {
	return MostrarError("Ingrese sus comentarios","Comentarios del mensaje",elemento);
	}
	return true;
}

function validarVisual(elemento){
	if (elemento.value=="") {
	return MostrarError("Ingrese el código visual","Código visual",elemento);
	}
	return true;
}

function clientes (url)
{
    var pagina_requerida = false;
    if (window.XMLHttpRequest)
    {
        // Si es Mozilla, Safari etc
        pagina_requerida = new XMLHttpRequest ();
    } else if (window.ActiveXObject)
    {
        // pero si es IE
        try 
        {
            pagina_requerida = new ActiveXObject ("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            // en caso que sea una versión antigua
            try
            {
                pagina_requerida = new ActiveXObject ("Microsoft.XMLHTTP");
            }
            catch (e)
            {
            }
        }
    } 
    else
	{
	    return false;
	}
    pagina_requerida.open ('GET', url, true); // asignamos los métodos open y send
    pagina_requerida.send (null);
}