/*******************************************************
 * Functions for e-mail address encryption/decryption. *
 *******************************************************/
/**
 * Encrypt an e-mail address.
 *
 * @param	email_plain
 *			The e-mail address to encrypt.
 * @return	email_encr
 *			The encrypted e-mail address.
 */
function addr_encrypt(email_plain){
	email_plain = "mailto:" + email_plain;
	var email_encr = '';
	email_plain = email_plain.replace('.','#');
	for(i=0; i<email_plain.length; i++){
		email_encr = email_encr + String.fromCharCode(email_plain.charAt(i).charCodeAt(0)+1);
	}
	return email_encr;
}
/**
 * Decrypt an e-mail address that was encrypted using addr_encrypt().
 *
 * @param	email_encr
 *			The encrypted e-mail address to decrypt.
 * @return	email_plain
 *			The decrypted e-mail address.
 */
function addr_decrypt(email_encr){
	//email_encr = unescape(email_encr);
	var email_plain = '';
	for(i=0; i<email_encr.length; i++){
		email_plain = email_plain + String.fromCharCode(email_encr.charAt(i).charCodeAt(0)-1);
	}
	email_plain = email_plain.replace('#','.');
	return email_plain;
}
/**
 * Create a e-mail link in the HTML code using an encrypted e-mail address.
 *
 * @param	email_encr
 *			The e-mail address for the link in encrypted form.
 * @param	link_text
 *			The text to show for the link in the browser window.
 */
function email_link(email_encr, link_text){
	document.write(link_text.link(addr_decrypt(email_encr)));
}



/*****************************************
 * Generates a standard reference with   *
 * e-mail address @mexicanosenbelgica.be *
 ****************************************/

function formatall(etail,ename)
{
	ename = ename.replace('!', '.') ;
	var reg  = /[\/\% ]/;
	while(reg.exec(etail))
	{
		etail = etail.replace(reg, '.') ;
	}
	res_str = "&#109;a&#105;lt&#111;&#58;" + ename + "&#64;" + etail;
	document.write((ename+"&#64;"+etail).link(res_str));
}

/*************************************
 * Functions for language switching. *
 *************************************/
 /**
  *
  */
 function switch_language(){
	 document.write(document.location.pathname);
 }
 
 /**************************************************
 * Funcones para la forma de independecia 2009*
 **************************************************/
 /**
  *
  */
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}

 /**************************************************
 * Funcones para el registro de la independencia2009 *
 **************************************************/
 /**
  *
  */
function bereken(){
V_adultos=document.evento.adultos.value;
V_menores=document.evento.menores.value;

V_precio1=V_adultos*document.evento.prexp1.value;
V_precio3=V_menores*document.evento.prexp3.value;


document.evento.precio1.value=V_precio1;
document.evento.precio3.value=V_precio3;


V_AsistentesTotal = Number(V_adultos) +  Number(V_menores);
V_PrecioTotal = Number(V_precio1) + Number(V_precio3);

document.evento.AsistentesTotal.value=V_AsistentesTotal;
document.evento.PrecioTotal.value=V_PrecioTotal;

}
