function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function redirect() {
	//if (document.location != "http://mail.virgilio.it/" && document.location != "http://mail.virgilio.it/index.html") return; // HP Mail only
	var cookie_paa = getCookie("PAAA_AUTHE");
	var cookie_tinv = getCookie("tinv");
	if (cookie_tinv!=null && cookie_tinv.indexOf('_') !=0) {
		if ( cookie_tinv == 5)
		   document.location.href="http://portale.rossoalice.alice.it/ps/HomePS.do?area=welcomePage";
		else
			 if (cookie_tinv == 1)			 
			   document.location.href="http://communicator.alice.it/asp/login.asp";			  
		else
		   if (cookie_tinv == 6)			   
			   document.location.href="http://webmailvtin.alice.it/cp/ps/Main/login/SSOLogin";
		}
}

function getUrlParameter(param) { var val = ""; var qs = window.location.search; var start = qs.indexOf(param); if (start != -1) {  start += param.length + 1;  var end = qs.indexOf("&", start);  if (end == -1) {   end = qs.length  }  val = qs.substring(start,end); } return val;}

if (getUrlParameter("utype") == "" || getUrlParameter("utype") != "ML") { redirect(); }
