var nbsp = 160;		// non-breaking space char
var node_text = 3;	// DOM text node-type
var emptyString = /^\s*$/ ;
var proceed = 2;  
var global_valfield;	// retain valfield for timer thread

function trim(str) {   return str.replace(/^\s+|\s+$/g, ''); }
function setFocusDelayed() {   global_valfield.focus(); }
function setfocus(valfield) {   // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;   setTimeout( 'setFocusDelayed()', 100 ); }
function msg(fld, msgtype, message) {
  var dispmessage;   if (emptyString.test(message))     dispmessage = String.fromCharCode(nbsp);    
  else      dispmessage = message; 
  var elem = document.getElementById(fld);  elem.firstChild.nodeValue = dispmessage;   elem.className = msgtype; }

function commonCheck    (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server
  var elem = document.getElementById(infofield);
  if (!elem.firstChild) return true;  // not available on this browser 
  if (elem.firstChild.nodeType != node_text) return true;  // infofield is wrong type of node  

  if (emptyString.test(valfield.value)) {
    if (required) {
      msg (infofield, "error", "ERROR: requerido");  
      setfocus(valfield);
      return false;
    }
    else {
      msg (infofield, "warn", "");   // OK
      return true;  
    }
  }
  return proceed;
}
function validatePresent(valfield,   // element to be validated
                         infofield ) // id of element to receive info/error msg
{
  var stat = commonCheck (valfield, infofield, true);
  if (stat != proceed) return stat;

  msg (infofield, "warn", "");  
  return true;
}

function validateEmail  (valfield,   // element to be validated
                         infofield,  // id of element to receive info/error msg
                         required)   // true if required
{
  var stat = commonCheck (valfield, infofield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/  ;
  if (!email.test(tfld)) {
    msg (infofield, "error", "ERROR: E-mail no valido");
    setfocus(valfield);
    return false;
  }

  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/  ;
  if (!email2.test(tfld)) 
    msg (infofield, "warn", "E-mail anormal - Verifique");
  else
    msg (infofield, "warn", "");
  return true;
}


function vinscrip(){
//	alert("Ingrese su nombre y apellido completos.");
//    if (emptyString.test(document.form1.realname.value)) { 

//    VALIDACION DE POPUP BLOQUER
// PONERLO OFF SCREEN  top=5000,left=5000");
// var mine = window.open('','','width=1,height=1,left=0,top=0,scrollbars=no');
// if(mine)
//    var popUpsBlocked = false
// else
//    var popUpsBlocked = true
// mine.close()

	var frealname=document.form1.realname
	var fdireccion=document.form1.direccion
	var femail=document.form1.email
	var flocalidad=document.form1.localidad
	var fregion=document.form1.region
	var ffpago=document.form1.fpago
	if ((frealname.value==null)||(frealname.value=="")){
		alert("Ingrese su nombre y apellido completos.")
		frealname.focus()
		return false 	}
	if ((fdireccion.value==null)||(fdireccion.value=="")){
		alert("Ingrese su direccion completa.")
		fdireccion.focus()
		return false 	}
	if ((femail.value==null)||(femail.value=="")){
		alert("Ingrese su email.")
		femail.focus()
		return false 	}
	if ((flocalidad.value==null)||(flocalidad.value=="")){
		alert("Ingrese su localidad.")
		flocalidad.focus()
		return false 	}
	if ((fregion.value==null)||(fregion.value=="")){
		alert("Ingrese su region.")
		fregion.focus()
		return false 	}

//if (popUpsBlocked == false) {
//	window.open('about:blank','test1', 'top=30,left=30,directories=no,width=790,height=640,location=no, menubar=no,resizable=yes,scrollbars=yes, status=yes,toolbar=no') 
	//}
	return true
 }


function fcontacto(){

	var frealname=document.contactform.nombre
	var fapellido=document.contactform.apellido
	var femail=document.contactform.email
	var fpais=document.contactform.pais
	if ((frealname.value==null)||(frealname.value=="")){
		alert("Ingrese su nombre.")
		frealname.focus()
		return false 	}
	if ((fapellido.value==null)||(fapellido.value=="")){
		alert("Ingrese su apellido completo.")
		fapellido.focus()
		return false 	}
	if ((femail.value==null)||(femail.value=="")){
		alert("Ingrese su email.")
		femail.focus()
		return false 	}
	if ((fpais.value==null)||(fpais.value=="")){
		alert("Ingrese su pais.")
		fpais.focus()
		return false 	}

	window.open('about:blank','test2', 'top=30,left=30,directories=no,width=590,height=440,location=no, menubar=no,resizable=no,scrollbars=no, status=no,toolbar=no')
	return true
 }
 
 function fcontacto(){

	var frealname=document.contactform.nombre
	var fapellido=document.contactform.apellido
	var femail=document.contactform.email
	var fpais=document.contactform.pais
	if ((frealname.value==null)||(frealname.value=="")){
		alert("Ingrese su nombre.")
		frealname.focus()
		return false 	}
	if ((fapellido.value==null)||(fapellido.value=="")){
		alert("Ingrese su apellido completo.")
		fapellido.focus()
		return false 	}
	if ((femail.value==null)||(femail.value=="")){
		alert("Ingrese su email.")
		femail.focus()
		return false 	}
	if ((fpais.value==null)||(fpais.value=="")){
		alert("Ingrese su pais.")
		fpais.focus()
		return false 	}

	window.open('about:blank','test2', 'top=30,left=30,directories=no,width=590,height=440,location=no, menubar=no,resizable=no,scrollbars=no, status=no,toolbar=no')
	return true
 }
 
  function fmasinfo(){

	var frealname=document.contactform.nombre
	var fapellido=document.contactform.apellido
	var femail=document.contactform.email
	var fpais=document.contactform.pais
	var fcurso=document.contactform.selectcurso
	if ((frealname.value==null)||(frealname.value=="")){
		alert("Ingrese su nombre.")
		frealname.focus()
		return false 	}
	if ((fapellido.value==null)||(fapellido.value=="")){
		alert("Ingrese su apellido completo.")
		fapellido.focus()
		return false 	}
	if ((femail.value==null)||(femail.value=="")){
		alert("Ingrese su email.")
		femail.focus()
		return false 	}
	if ((fpais.value==null)||(fpais.value=="")){
		alert("Ingrese su pais.")
		fpais.focus()
		return false 	}


	window.open('about:blank','test2', 'top=30,left=30,directories=no,width=790,height=640,location=no, menubar=no,resizable=yes,scrollbars=yes, status=yes,toolbar=no')
	return true
 }