function allTrim(cValue){
var lDone = false;
while (lDone == false){
  if (cValue.length == 0) {
	 return cValue;
  }
  if (cValue.indexOf(" ") == 0) {
   cValue = cValue.substring(1);
   lDone=false;
   continue;
  }
  else {
   lDone = true;
  }
  if (cValue.lastIndexOf(" ") == cValue.length-1) {
   cValue = cValue.substring(0, cValue.length-1);
   lDone = false;
   continue;
  }
  else {
   lDone = true;
  }
 }
return cValue;
}

// Checks for @, period after @ and text in between in an email address
function checkEmail(str) {

  var at="@";
  var dot=".";
  var lat=str.indexOf(at);
  var lstr=str.length;
  var ldot=str.indexOf(dot);
  var specialCharArray=new Array('~', '!', '%', '^', '*', '+', '=', '{',
     '}', '|', '/', ':', ';', '<', '>', '?', ',', '(', ')', '\\',
     '\'');
  if (str.indexOf(at)==-1){     
     return false;
  }

  if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){    
     return false;
  }
 
  if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){     
      return false;
  }

   if (str.indexOf(at,(lat+1))!=-1){      
      return false;
   }

   if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){     
      return false;
   }

   if (str.indexOf(dot,(lat+2))==-1){     
      return false;
   }
   if (str.indexOf('..')!=-1){      
   		return false;
   }

   if (str.indexOf(" ")!=-1){     
      return false;
   }

   if(str.charAt(str.length-1)=='.') {
	   return false;
	}
  for (i = 0; i < specialCharArray.length; i++) {
    if(str.indexOf(specialCharArray[i])>0){
    	return false;
    }
  }
   	
	return true ;    
 }
// Validates the POB registration form
function checkRegistrationSP(form) {
	var age_yr;
	var incomplete = 0;
	var focus=false;
	
	var alertMsg = "Los siguientes campos son Requeridos:\n\n";
	
	if (allTrim(form.fn.value)== "") {
		incomplete++;
		alertMsg = alertMsg + "Nombre\n";
		if(focus==false)
		{
        focus=true;
         form.fn.focus();
		}
	}
	
	if (allTrim(form.ln.value) == "") {
		incomplete++;
		alertMsg = alertMsg + "Apellido\n";
	     if(focus==false)
		{
        focus=true;
         form.ln.focus();
		}
	}

if (allTrim(form.email.value) == "") {
incomplete++;
alertMsg = alertMsg + "E-mail\n";
 if(focus==false)
		{
        focus=true;
         form.email.focus();
		}
 }

  if (document.getElementById("checkboxId").checked == false || document.getElementById("checkboxId").checked == false) {
incomplete++;
alertMsg = alertMsg + "marcas de fábrica\n";
 }
if (incomplete > 0) {		
		alert(alertMsg);
		return false;
	}
else
if (checkEmail(allTrim(form.email.value)) == false) {
		alert('Por Favor, Introduzca una dirección valida de e-mail.');
		form.email.focus();
		return false;
	}

}

//this function checks the validation the portuguese locale

function checkRegistrationPS(form) {
		var age_yr;
	var incomplete = 0;
	var focus=false;
	
	var alertMsg = "Os seguintes campos são requeridos:\n\n";
	
	if (allTrim(form.fn.value)== "") {
		incomplete++;
		alertMsg = alertMsg + "Nome\n";
		if(focus==false)
		{
        focus=true;
         form.fn.focus();
		}
	}
	
	if (allTrim(form.ln.value) == "") {
		incomplete++;
		alertMsg = alertMsg + "Sobrenome\n";
	     if(focus==false)
		{
        focus=true;
         form.ln.focus();
		}
	}
if (allTrim(form.email.value) == "") {
incomplete++;
alertMsg = alertMsg + "E-mail\n";
 if(focus==false)
		{
        focus=true;
         form.email.focus();
		}
 }

  if (document.getElementById("checkboxId").checked == false || document.getElementById("checkboxId").checked == false) {
incomplete++;
alertMsg = alertMsg + "tipos\n";
 }
if (incomplete > 0) {		
		alert(alertMsg);
		return false;
	}
else
if (checkEmail(allTrim(form.email.value)) == false) {
	alert('Por favor, introduza um e-mail valido.');
		form.email.focus();
		return false;
	}
}
//this function checks the validation the portuguese/spanish locale locale

function checkRegistrationPSSP(form) {
	var age_yr;
	var incomplete = 0;
	var focus=false;
	
	var alertMsg = "Los siguientes campos son Requeridos:\nOs seguintes campos são requeridos:\n\n";
	
	if (allTrim(form.fn.value)== "") {
		incomplete++;
		alertMsg = alertMsg + "Nombre/Nome\n";
		if(focus==false)
		{
        focus=true;
         form.fn.focus();
		}
	}
	
	if (allTrim(form.ln.value) == "") {
		incomplete++;
		alertMsg = alertMsg + "Apellido/Sobrenome\n";
	     if(focus==false)
		{
        focus=true;
         form.ln.focus();
		}
	}
if (allTrim(form.email.value) == "") {
incomplete++;
alertMsg = alertMsg + "E-mail\n";
 if(focus==false)
		{
        focus=true;
         form.email.focus();
		}
 }

if(document.getElementById("checkboxId")){
	if (document.getElementById("checkboxId").checked == false) {
		incomplete++;
		alertMsg = alertMsg + "marcas de fábrica/tipos\n";
	}
}
if (incomplete > 0) {		
	alert(alertMsg);
	return false;
}else
if (checkEmail(allTrim(form.email.value)) == false) {
			alert('Por favor, introduza um e-mail valido.\nPor Favor, Introduzca una dirección valida de e-mail.');
		form.email.focus();
		return false;
	}
}
