var ref = document.referrer;
var pcookie = leerCookie("IBERIACOM_PERSONALIZATION");

function leerCookie(nombre) {
  var i;
  var a = document.cookie.split(";")
  var n, v;
  var pos;

  for (i=0; i<a.length; i++) {
     pos = a[i].indexOf("=");
     n = a[i].substring(0, pos);
     if (Trim(n) == nombre) {
        return unescape(a[i].substring(1 + pos, a[i].length));
     }
  }
  return null;
}

function Trim(cad){
	var aux="";
	var i,lg = cad.length;
	for (;lg>0 && cad.charAt(lg-1)<=' ';lg--);
	for (i=0;i<lg && cad.charAt(i)<=' ';i++);
	for (;i<lg;i++)
		aux = aux + cad.charAt(i);
	return aux;
}

function welcomeredirect(formulario){
    formulario.action = host + "/welcome.htm"
    if (pcookie != null){
       var valores = pcookie.split("|");
       if (valores.length >= 2){
           formulario.market.value = valores[0];
           formulario.country.value = valores[1];
           formulario.language.value = valores[2];
           formulario.action = host + cgi_ib + "/v3/home.do"
           formulario.method = "post"
       }
    }
    formulario.referer.value = ref;
    formulario.submit()	;
}

function welcomelocalredirect(formulario, market, country, language){
    formulario.action = host + cgi_ib + "/v3/home.do"
    formulario.market.value = market;
    formulario.country.value = country;
    formulario.language.value = language;
    formulario.referer.value = ref;
    formulario.cookiesEnabled.value = navigator.cookieEnabled

    if (pcookie != null){
       var valores = pcookie.split("|");
       if (valores.length >= 2){
           formulario.language.value = valores[2];
       }
    }
    formulario.submit()	;
}
