// JavaScript Document


// funcion utilizada en publicite
function check_ingrese()
{
	var xmail, xnom, v_control;
	
	xnom=document.f_ingrese.nombre.value;
	var resultado = check_nombre(xnom);
	if (!resultado)
		return false;
		
	xmail=document.f_ingrese.mail.value;
	var resultado = check_mail(xmail);
	if (!resultado)
	{
		alert( "Verifique su mail. Parece haber algun error." );
		return false;
	}

	var v_control=document.f_ingrese.control.value;
	if ( !validar_codigo( v_control ) )
	{
		alert ( "Ha ingresado mal el numero de control." );
		clavevisual();
		cambiarimagenesclave();
		return false;
	}

return true;
}
 


// funcion utilizada en publicite
function check_mailing()
{
	var xmail, xnom, xdescripcion, v_control;
	
	xnom=document.f_mailing.nombre.value;
	var resultado = check_nombre(xnom);
	if (!resultado)
		return false;
		
	xmail=document.f_mailing.mail.value;
	var resultado = check_mail(xmail);
	if (!resultado)
	{
		alert( "Verifique su mail. Parece haber algun error." );
		return false;
	}

	xdescripcion=document.f_mailing.mensaje.value;
	if ( xdescripcion.length < 10 ) 
	{
		alert ( "Por favor, detalle mejor su consulta. " );
		return false;
	}


	var v_control=document.f_mailing.control.value;
	if ( !validar_codigo( v_control ) )
	{
		alert ( "Ha ingresado mal el numero de control." );
		clavevisual();
		cambiarimagenesclave();
		return false;
	}

return true;
}
 
 
function check_mail(dir) 
{
	if ( dir.length < 8 )
		return false;
	if ( ( dir.indexOf("@") == -1  ) || ( dir.indexOf(" ")  > -1  ) || ( dir.indexOf(".") == -1 )  )
		return false;
	
return true
}

//da como inválido un nombre que sea de menos de 3 digitos.
function check_nombre(nom) 
{
	if ( nom.length < 3 )
	{
		alert( "Su nombre es importante para comunicarnos con usted." );
		return false
	}
	
return true
}

// Pequeña ventana popup. Sin toolbar, sin menu, sin navegacion, sin status, sin scrollbar ni modificable
// Muestra una imagen
function popwindow(imagen,ancho,alto,titulo,gifdecargando) {
	var ancho_total, alto_total, altura_cargando, left_cargando;
	ancho_total=ancho+0;
	alto_total=alto+50;
	altura_cargando=parseInt(alto/2);
	left_cargando=parseInt(ancho/4);
	ventanita=window.open("","foto","toolbar=no,location=no,directories=no, status=no,titlebar= yes,menubar=no,resizable=no,left=0,top=0,scrollbars=no,width="+ancho_total+",height="+alto_total+",left=50, top=100");
	ventanita.document.open();
	ventanita.document.write("<html><head><title>"+titulo+"</title></head>");
	ventanita.document.write("<body bgcolor='#999999' leftmargin='0' topmargin='0' marginheight='0' marginwidth='0' onBlur='self.close()'>");
	ventanita.document.write("<div id='cargando' style='z-index:1; position:absolute; top:"+altura_cargando+"; left:"+left_cargando+"'>Cargando ");
	ventanita.document.write("<img src='"+gifdecargando+"'></div>");
	ventanita.document.write("<div id='cargado' style='z-index:2; position:absolute; top:0'>");
	ventanita.document.write("<img src='"+imagen+"' width='"+ancho+"' height='"+alto+"' alt='"+titulo+"' title='"+titulo+"'>");
	ventanita.document.write("<form><div align='center'><input type='button' value='Cerrar' ");
//	ventanita.document.write(" onclick='cerrar_ventana()'>");
	ventanita.document.write(" onclick='self.close()'>");
	ventanita.document.write("</div></form>");
	ventanita.document.write("</div>");
	ventanita.document.write("</body></html>");

	ventanita.document.close();
	ventanita.focus();
}

// Cerrar ventana. Para cerrar sin pedir confirmación
// llamar a la fn así: <a href="#" onClick="cerrar()">
function cerrar_ventana() {
var ventana = window.self;
ventana.opener = window.self;
ventana.close();
}



function abrir_ventana(url, name, w, h) {
	popupWin = window.open(url, name, 'toolbar=no, location=no, status=no, menubar=no, scrollbar=no, resizable=no, titlebar=yes, width=' + w + ',height=' + h);
}


