var Lang = 3; //1=ES, 2=EN, 3=PT
var phone = "0123456789";
var numb = "\.0123456789";
var alpha = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var alphanumb = ",\.\-áíóúñÑ0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var usr = "\_0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
var email = ".\-\_\@0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
var msgs = new Array();
msgs[1] = new Array();
msgs[2] = new Array();
msgs[3] = new Array();

msgs[1][1] = "Por favor, seleccione su";
msgs[1][2] = "Por favor ingrese su";
msgs[1][3] = "Por favor ingrese al menos 2 caracteres en la casilla";
msgs[1][4] = "Por favor ingrese un dato correcto en la casilla";
msgs[1][5] = "Por favor ingrese al menos 3 caracteres en la casilla";
msgs[1][6] = "Por favor ingrese al menos ";
msgs[1][7] = " caracteres en la casilla";
msgs[1][8] = "Por favor ingrese un valor más seguro en la casilla";
msgs[1][9] = "Por favor ingrese al menos 9 caracteres en la casilla";
msgs[1][10] = "";
msgs[1][11] = "Por favor ingrese al menos 7 dígitos en la casilla";
msgs[1][12] = "Por favor ingrese al menos 5 caracteres en la casilla";
msgs[1][13] = "";
msgs[1][14] = "Por favor ingrese como máximo 8 dígitos en la casilla";
msgs[1][15] = "";
msgs[1][16] = "";
msgs[1][17] = " dígitos en la casilla \"";
msgs[1][18] = "";
msgs[1][19] = "";
msgs[1][20] = "Por favor, ingrese solo dígitos en la casilla";
msgs[1][21] = "Por favor ingrese como máximo "
msgs[1][22] = "Por favor ingrese 5 dígitos en la casilla";
msgs[1][23] = "";
msgs[1][24] = "Su ";
msgs[1][25] = " debe tener por lo menos 1 dígitos.";
msgs[1][26] = "Por favor ingrese como mínimo 2 dígitos en la casilla";
msgs[1][27] = "Por favor ingrese como máximo 2 dígitos en la casilla";
msgs[1][28] = "";
msgs[1][29] = "La edad mínima para aplicar en esta oferta es de ";
msgs[1][30] = " años.";
msgs[1][31] = "\" no debe ser igual a su \"";
msgs[1][32] = "\" debe ser igual a su \"";
msgs[1][33] = "Seleccionar";
msgs[1][34] = "Por favor, para participar en esta promoción debes aceptar recibir más información y aceptar sus políticas y condiciones";

msgs[2][1] = "Please, select your";
msgs[2][2] = "Please type your";
msgs[2][3] = "Please type at least 2 characters in the inbox";
msgs[2][4] = "Please type a correct data in the inbox";
msgs[2][5] = "Please type at least 3 characters in the inbox";
msgs[2][6] = "Please type at least ";
msgs[2][7] = " characters in the inbox";
msgs[2][8] = "Please type a more secure value in the inbox";
msgs[2][9] = "Please type at least 9 characters in the inbox";
msgs[2][10] = "";
msgs[2][11] = "Please type at least 7 digits in the inbox";
msgs[2][12] = "Please type at least 5 characters in the inbox";
msgs[2][13] = "";
msgs[2][14] = "Please type at maximum 8 characters in the inbox";
msgs[2][15] = "";
msgs[2][16] = "";
msgs[2][17] = " digits in the inbox \"";
msgs[2][18] = "";
msgs[2][19] = "";
msgs[2][20] = "Please type only digits in the inbox";
msgs[2][21] = "Please type at maximum "
msgs[2][22] = "Please type 5 digits in the inbox";
msgs[2][23] = "";
msgs[2][24] = "Your ";
msgs[2][25] = " must have at least 1 digit.";
msgs[2][26] = "Please type at least 2 digits in the inbox";
msgs[2][27] = "Please type at maximum 2 digits in the inbox";
msgs[2][28] = "";
msgs[2][29] = "The minimum age to apply in this offer is ";
msgs[2][30] = " years old.";
msgs[2][31] = "\" should not be equal to your \"";
msgs[2][32] = "\" should be equal to your \"";
msgs[2][33] = "Select";
msgs[2][34] = "Please, to participate in this promotion you must accept to receive more information and accept its policies and conditions";

msgs[3][1] = "Por favor, selecione seu";
msgs[3][2] = "Por favor, preencha seu";
msgs[3][3] = "Por favor, digite ao menos 2 caracteres no campo";
msgs[3][4] = "Por favor, preencha o campo ";
msgs[3][5] = "Por favor, digite ao menos 3 caráteres no campo";
msgs[3][6] = "Por favor, digite ao menos ";
msgs[3][7] = " caracteres no campo";
msgs[3][8] = "Por favor, digite um valor mais seguro no campo";
msgs[3][9] = "Por favor digite ao menos 9 caráteres no campo";
msgs[3][10] = "";
msgs[3][11] = "Por favor, digite ao menos 7 dígitos no campo";
msgs[3][12] = "Por favor digite ao menos 5 caracteres no campo";
msgs[3][13] = "";
msgs[3][14] = "Por favor, digite ao máximo 8 caráteres no campo";
msgs[3][15] = "";
msgs[3][16] = "";
msgs[3][17] = " dígitos no campo \"";
msgs[3][18] = "";
msgs[3][19] = "";
msgs[3][20] = "Por favor, digite somente dígitos no campo";
msgs[3][21] = "Por favor, digite ao máximo "
msgs[3][22] = "Por favor, digite 5 dígitos no campo";
msgs[3][23] = "";
msgs[3][24] = "Sua ";
msgs[3][25] = " deve ter ao menos 1 dígito.";
msgs[3][26] = "Por favor, coloque ao menos 2 dígitos no campo";
msgs[3][27] = "Por favor, coloque ao máximo 2 dígitos no campo";
msgs[3][28] = "";
msgs[3][29] = "A idade mínima a aplicar-se nesta oferta  ";
msgs[3][30] = " anos.";
msgs[3][31] = "\" não tem que ser igual a sua \"";
msgs[3][32] = "\" deve ser igual a sua \"";
msgs[3][33] = "Seleto";
msgs[3][34] = "Por favor, para participar desta promoção deve aceitar receber mais informações e aceitar suas políticas e circunstâncias";

function res(t,v){
	var w = "";
	for (i=0; i < t.value.length; i++) {
	x = t.value.charAt(i);
	if (v.indexOf(x,0) != -1)
		w += x;
	}
	t.value = w;
}

function TrimLen( value ) {
	var lft = /\s*((\S+\s*)*)/;
	var rgh = /((\s*\S+)*)\s*/;
	var tmp = value;
	tmp = tmp.replace(lft, "$1");
	tmp = tmp.replace(rgh, "$1");
	return (tmp.length);
}

function UCase(s){
	return s.toUpperCase();
}

function Repeat(value, cant) {
	var validChars = "a{"+cant+"}|b{"+cant+"}|c{"+cant+"}|d{"+cant+"}|e{"+cant+"}|f{"+cant+"}|g{"+cant+"}|h{"+cant+"}|i{"+cant+"}|j{"+cant+"}|k{"+cant+"}|l{"+cant+"}|m{"+cant+"}|n{"+cant+"}|o{"+cant+"}|p{"+cant+"}|q{"+cant+"}|r{"+cant+"}|s{"+cant+"}|t{"+cant+"}|u{"+cant+"}|v{"+cant+"}|w{"+cant+"}|x{"+cant+"}|y{"+cant+"}|z{"+cant+"}|A{"+cant+"}|B{"+cant+"}|C{"+cant+"}|D{"+cant+"}|E{"+cant+"}|F{"+cant+"}|G{"+cant+"}|H{"+cant+"}|I{"+cant+"}|J{"+cant+"}|K{"+cant+"}|L{"+cant+"}|M{"+cant+"}|N{"+cant+"}|O{"+cant+"}|P{"+cant+"}|Q{"+cant+"}|R{"+cant+"}|S{"+cant+"}|T{"+cant+"}|U{"+cant+"}|V{"+cant+"}|W{"+cant+"}|X{"+cant+"}|Y{"+cant+"}|Z{"+cant+"}|0{"+cant+"}|1{"+cant+"}|2{"+cant+"}|3{"+cant+"}|4{"+cant+"}|5{"+cant+"}|6{"+cant+"}|7{"+cant+"}|8{"+cant+"}|9{"+cant+"}|[\$]{"+cant+"}|[\-]{"+cant+"}|#{"+cant+"}|[\/]{"+cant+"}|_{"+cant+"}|={"+cant+"}|[\+]{"+cant+"}|[\@]{"+cant+"}|[\!]{"+cant+"}|[\*]{"+cant+"}|[\|]{"+cant+"}|[\(]{"+cant+"}|[\)]{"+cant+"}|[\.]{"+cant+"}|,{"+cant+"}|%{"+cant+"}|%{"+cant+"}|&{"+cant+"}|[\?]{"+cant+"}|[\[]{"+cant+"}|[\]]{"+cant+"}|[\{]{"+cant+"}|[\}]{"+cant+"}|:{"+cant+"}|;{"+cant+"}|>{"+cant+"}|<{"+cant+"}|[\"]{"+cant+"}";
	var userPattern = new RegExp(validChars);
	return userPattern.test(value);
}

function valSelec (obj) {
  if (obj.value == "-1")  {
    alert(msgs[Lang][1] + " \"" + obj.id + "\".");
    obj.focus();
    return (false);
  }
  return (true);
}

function valRad (obj) {
var displayerr = 1;	
  for(i=0;i<obj.length;i++) {
  	if(obj[i].checked) {
		displayerr = 0;
	}
  } 
  if(displayerr) {
	alert(msgs[Lang][1] + " \"" + obj[0].id + "\".");
    obj[0].focus();
	return (false);
  }		
  return (true);
}

function valFname (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\".");
	obj.value = "";
	obj.focus();
	return (false);
  }  
  if (obj.value.length < 2)  {
    alert(msgs[Lang][3] + " \"" + obj.id + "\".");
    obj.focus();
	return (false);
  }
  if (Repeat(obj.value, 3))  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }
  return (true);
}  

function valLname (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\".");
	obj.value = "";
	obj.focus();
	return (false);
  }   
  if (obj.value.length < 3)  {
    alert(msgs[Lang][5] + " \"" + obj.id + "\".");
    obj.focus();
    return (false);
  }
  if (Repeat(obj.value, 3))   {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }
  return(true);
}

function valTxt (obj, mn, rep) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\".");
	obj.value = "";
	obj.focus();
	return (false);
  }  
  if (obj.value.length < mn)  {
    alert(msgs[Lang][6] + mn + msgs[Lang][7] + " \"" + obj.id + "\".");
    obj.focus();
	return (false);
  }
  if (Repeat(obj.value, rep))  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }
  return (true);
}  


function valEmail (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + ' \"' + obj.id + '\".');
	obj.value = "";
	obj.focus();
	return (false);
  }  
  var exp_email1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/;
  var exp_email2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/;
  if (obj.value != ''){
  		if (!(!exp_email1.test(obj.value) &&   exp_email2.test(obj.value))) {
  				alert(unescape(msgs[Lang][4] + " \"" + obj.id + "\""));
  				obj.focus();
  	    	return false;
  		}
  }
  if (Repeat(obj.value, 5)) {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }
  if (obj.value.length < 6) //antes el minimo era 9, Franz pidio que fuera 14
  {
    //alert(msgs[Lang][9] + " \"" + obj.id + "\".");
	alert(unescape(msgs[Lang][4] + " \"" + obj.id + "\""));
    obj.focus();
    return (false);
  }
  return (true);	
}

function valAddr (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\"");
	obj.value = "";
	obj.focus();
	return (false);
  }       
  if (Repeat(obj.value, 4)) {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  } 
  if (obj.value.length < 5) {
    alert(msgs[Lang][12] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  return (true);
}

function valCity (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\"");
	obj.value = "";
	obj.focus();
	return (false);
  }  
  if (Repeat(obj.value, 3))
  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  } 
  if (obj.value.length < 2)
  {
    alert(msgs[Lang][2] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  return (true);  
}

function valState (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\"");
	obj.value = "";
	obj.focus();
	return (false);
  }  
  if (Repeat(obj.value, 3))
  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  } 
  if (obj.value.length < 2)
  {
    alert(msgs[Lang][3] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  return (true);  
}

function valZcode (obj) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\"");
	obj.value = "";
	obj.focus();
	return (false);
  } 
  if (isNaN(obj.value)) {
	  alert (msgs[Lang][20] + " \"" + obj.id + "\"");
	  obj.focus();
	  return false;
  }
  if (Repeat(obj.value, 4))
  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }
  if (obj.value.length < 5)
  {
    alert(msgs[Lang][22] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  return (true);
}

function valPCod (obj) {
  if(TrimLen(obj.value) == 0){
	alert (msgs[Lang][2] + " " + obj.id + ".");
    obj.value = "";
    obj.focus();
    return false;
  }
  if (isNaN(obj.value)) {
	  alert (msgs[Lang][20] + " " + obj.id + ".");
	  obj.focus();
	  return false;
  }
  if (obj.value.length<1) {
	  alert (msgs[Lang][24] + obj.id + msgs[Lang][25]);
	  obj.focus();
	  return false;
  }  
  return (true);
}

function valPhone2 (obj) {
  if(TrimLen(obj.value) == 0){
	alert (msgs[Lang][2] + " \"" + obj.id + "\".");
    obj.value = "";
    obj.focus();
    return false;
  }  
  if (isNaN(obj.value)) {
	  alert (msgs[Lang][20] + " \"" + obj.id + "\"");
	  obj.focus();
	  return false;
  }
  if (Repeat(obj.value, 5))  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }   
  if (obj.value.length < 7)
  {
    alert(msgs[Lang][11] +" \"" + obj.id + "\".");
    obj.focus();
    return (false);
  }
  if (obj.value.length > 8)
  {
    alert(msgs[Lang][14] + " \"" + obj.id + "\".");
    obj.focus();
    return (false);
  }
  return (true);
}

function valPhone (obj, rep, mn, mx) {
  if(TrimLen(obj.value) == 0){
	alert (msgs[Lang][2] + " \"" + obj.id + "\".");
    obj.value = "";
    obj.focus();
    return false;
  }  
  if (isNaN(obj.value)) {
	  alert (msgs[Lang][20] + " \"" + obj.id + "\"");
	  obj.focus();
	  return false;
  }
  if (Repeat(obj.value, rep))  {
    alert(msgs[Lang][4] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }   
  if (obj.value.length < mn)
  {
    alert(msgs[Lang][6] + mn + msgs[Lang][17] + obj.id + "\".");
    obj.focus();
    return (false);
  }
  if (obj.value.length > mx)
  {
    alert(msgs[Lang][21] + mx + msgs[Lang][17] + obj.id + "\".");
    obj.focus();
    return (false);
  }
  return (true);
}

function valAge (obj, age) {
  if (obj.value.length < 2)
  {
    alert(msgs[Lang][26] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  if (obj.value.length > 2)
  {
    alert(msgs[Lang][27] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  if (isNaN(obj.value))
  {
    alert(msgs[Lang][20] + " \"" + obj.id + "\"");
    obj.focus();
    return (false);
  }
  if (obj.value < age)
  {
    alert(msgs[Lang][29] + age + msgs[Lang][30]);
	obj.focus();
    return (false);
  }
  return (true);
}

function valPass (obj, mn, mx) {
  if (TrimLen(obj.value) == 0) {
	alert (msgs[Lang][2] + " \"" + obj.id + "\"");
	obj.value = "";
	obj.focus();
	return (false);
  }  
  if (obj.value.length < mn)  {
    alert(msgs[Lang][6] + mn + msgs[Lang][7] + " \"" + obj.id + "\"");
    obj.focus();
	return (false);
  }
  if (obj.value.length > mx)  {
    alert(msgs[Lang][21] + mx + msgs[Lang][7] + " \"" + obj.id + "\"");
    obj.focus();
	return (false);
  }  
  if (Repeat(obj.value, 2))  {
    alert(msgs[Lang][8] + " \"" + obj.id + "\"");
	obj.focus();
	return (false);
  }
  return (true);
}

function valRept (obj1, obj2) {
  if (UCase(obj1.value) == UCase(obj2.value))
  {
    alert(msgs[Lang][24] + "\"" + obj1.id + msgs[Lang][31] + obj2.id + "\".");
    obj2.focus();
    return (false);
  }
  return (true);
}

function valConf (obj1, obj2) {
  if (UCase(obj1.value) != UCase(obj2.value))
  {
    alert(msgs[Lang][24] + "\"" + obj1.id + msgs[Lang][32] + obj2.id + "\".");
    obj2.focus();
    return (false);
  }
  return (true);
}

function idPais(code)
{
	for (var i = 1; i < cantPais; i++) {
		if (vecPais[i] == code) {
			return i;
		}
	}
	return 0;
}

function idList(code, vec, cant)
{
	for (var i = 1; i <= cant; i++) {
		if (vec[i] == code) {
			return i;
		}
	}
	return 0;
}

function clearSelectTop(obj)
{
	for (var i = obj.options.length - 1; i >= 0; i--){
		obj.options[i] = null;				
	}
	obj.selectedIndex = -1;				
}

function include(file) {
  var script  = document.createElement('script');
  script.src  = file;
  script.type = 'text/javascript';
  //document.getElementsByTagName('head').item(0).appendChild(script);
  //document.getElementsByTagName('head')[0].appendChild(script);
  //document.body.insertBefore(script);
  document.body.appendChild(script);
}

function updateRegion(id_pais, obj, objdest, vec) 
{ 
	include(folderJss + '/'+ obj[obj.selectedIndex].value + '.js');
	var regions = 0;
	var i = 0;
	if (obj[obj.selectedIndex].value != '-1') {
		regions = vec[id_pais];
		for (i = objdest.options.length; i >= 0; i--) {
			objdest.options[i] = null;
		}
		var option = document.createElement('OPTION');
		option.setAttribute('value', "-1");
		option.setAttribute('selected', "selected");
		var text = document.createTextNode(msgs[Lang][33]);
		option.appendChild(text);
		objdest.appendChild(option);		
		for (i = 1; i < regions.length; i++) {
			var option = document.createElement('OPTION');
			option.setAttribute('value', regions[i]);
			var text = document.createTextNode(regions[i]);
			option.appendChild(text);
			objdest.appendChild(option);
		}		
	}	
}

function valChk (obj) {
  if (!obj.checked)
  {
    alert(msgs[Lang][34]);
    obj.focus();
    return (false);
  }
  return (true);
}


