//apri Web messenger
function apriWebmessenger(){
	desktop = window.open('http://imtunnel.tiscali.it/vulcano/main.jsp?community=tiscali-it&autosearch=true','','location=no,status=no,scrollbars=no,resizable=no,menubar=no,height=230,width=394');
}

// Browser check
var style='<link rel="stylesheet" type="text/css" href="/style/mail.css">';
document.write(style);


var platform = navigator.platform;
var version = navigator.appVersion;
var browser = navigator.appName;
var fullVersion = parseFloat(version.substring(version.indexOf("MSIE")+5,version.length));
var majorVersion = parseInt(''+fullVersion);
if((majorVersion < 6)&&(browser == "Microsoft Internet Explorer")&&(platform == "Win32")) {
document.write('<style type="text/css">');
document.write('.x-button{0px;}');
document.write('.x-button img{vertical-align:bottom;display:inline;}');
document.write('.x-button a{vertical-align:top;display:inline;background-color:#DCDCDC; height:16px;color:#000;font:bold 11px Arial, Helvetica, sans-serif;text-decoration:none;border-top:1px solid #6E6E6E;border-bottom:1px solid #6E6E6E;}');
document.write('#headline{color:#000;width:776px;font-weight:bold;float:left;padding:6px 0px 0px 0px;vertical-align:bottom;}');
document.write('#headline a{text-decoration:none; font-weight:bold;float:left; margin:0px 8px 0px 0px;line-height:14px;}');
document.write('#headline a:hover{text-decoration:underline;}');
document.write('.linkspace{display:inline;}');
document.write('</style>');

}

//Funzione MakeAD da inserire in Testa di Pagina Version 5.2
//Version 5.2 Rich Media
var magic2=Math.floor(Math.random() * 4573285835)
function makeAD (sito, tags, dimw, dimh){
	now = new Date();
	itstime = now.getTime();
	site=sito+"/";
	target=tags+"/ACC_RANDOM="+itstime+"/PAGEID="+magic2;
	document.write('<IFRAME SRC="' + site + 'hserver' + target + '" NORESIZE ');
	document.write('SCROLLING=NO HSPACE=0 VSPACE=0 FRAMEBORDER=0 MARGINHEIGHT=0 MARGINWIDTH=0 WIDTH='+dimw+' HEIGHT='+dimh+'>');
	document.write('<SCR' + 'IPT Language="JAVASCRIPT1.1" SRC="' + site + 'jnserver' + target + '">');
	document.write('</SCR' + 'IPT>');
	document.write('</IFRAME>');
}

function apri(){
	desktop=window.open('/password.html','password','toolbar=no,location=no,status=no,scrollbars=no,menubar=no,resizable=no,width=400,height=260');
}

function OnPhoenixHelp(w,h,where) {
	x = (screen.width - w - 8);
	url="http://www.tiscali.it/helpmail/index.html?where="+where;
	desktop = window.open(url,"centrato","resizable=no,toolbar=no,scrollbars=no,menubar=no,location=no,status=no,width=" + w + ",height=" + h + ",screenY=0,screenX=" + x + ",left=" + x + ",top=0");
}

function Nospaces(checkString){
	var newString = "";
	var i = 0;
	var st = 0;
	if(checkString == null){return null;}
	for (i = 0; i < checkString.length; i++){
		ch = checkString.substring(i, i+1);
		if (ch != " "){newString += ch;}
	}
	return newString;
}

function OnWebMailLoad(){
	var uname=GetCookie("WEBUSER");
	var i;
	if(uname != null){
		i= uname.indexOf("@tiscali.ch");
		if(i>=0){uname = uname.substring(0,i);}
		document.dataentry.username.value = uname;
	}
}

function OnWebMailLogin(){
	var uname=document.dataentry.username.value;
	var options="domain=default&style=default";
	if(document.dataentry.options){options=document.dataentry.options.value;}
	var location="/mail/main";
	if(options != ""){location += "?" + options;}
	uname=Nospaces(uname);
	if((uname!=null) && (uname.length > 0) && document.dataentry.password.value!=''){
		if(uname.indexOf("@")==-1){uname=uname + "@tiscali.ch";}
	}
	else{alert('Inserire userID e password'); return;}
	if(document.dataentry.template){
//		SetCookie("TEMPLATE", document.dataentry.template[document.dataentry.template.selectedIndex].value, null, "/", ".tiscali.it");
		SetCookie("TEMPLATE", document.dataentry.template.value, null, "/", ".tiscali.ch");		
	}
	SetCookie("WEBUSER", uname, null, "/mail", ".tiscali.ch");
	SetCookie("WEBPASS", document.dataentry.password.value,null, "/mail", ".tiscali.ch");
	window.location.href=location;
}

function IeCheck(){var agt=navigator.userAgent.toLowerCase();var nIE = (agt.indexOf("msie") != -1);return nIE;};
function WinCheck(){var agt=navigator.userAgent.toLowerCase();var nWin   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );return nWin;};
var tiscali_browser;function fnInit(){if (IeCheck()&&WinCheck()){if (window.external != null){tiscali_browser = window.external.tiscalibrowser;if ( tiscali_browser == "it" ) {document.write('<style type=text/css>.TisHeader {display : none;}</style>');}}}}fnInit();

//VTX Datacomm 10.0 Cookie Reading Functions -- (12-Dec-01)

function CheckT10(){
	if (GetCookie("ssosession")!=null){return true;}
	else return null;
}

function GetStatusT10(){
	if (CheckT10()!= null){document.write('<style type=text/css>.TisLogOut{display:none;}</style>');}
	else{document.write('<style type=text/css>.TisLogIn{display:none;}</style>');}
}

function IdentityT10(){
	if(CheckT10()!= null){document.write(base64decode(GetCookie("whoiswho")));}
	else{document.write('');}
};

function getCookieVal (offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}

function GetCookie (name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if(document.cookie.substring(i, j) == arg)return getCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}

function SetCookie (name,value,expires,path,domain,secure){
	document.cookie = name + "=" + escape (value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
}

function DeleteCookie (name,path,domain){
	if (GetCookie(name)){
		document.cookie = name + "=" + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

/*
 * Interfaces:
 * b64 = base64encode(data);
 * data = base64decode(b64);
 */


var base64EncodeChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var base64DecodeChars = new Array(
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
    -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63,
    52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1,
    -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14,
    15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1,
    -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
    41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1);

function base64encode(str) {
    var out, i, len;
    var c1, c2, c3;

    len = str.length;
    i = 0;
    out = "";
    while(i < len) {
		 c1 = str.charCodeAt(i++) & 0xff;
		 if(i == len)
		 {
		     out += base64EncodeChars.charAt(c1 >> 2);
		     out += base64EncodeChars.charAt((c1 & 0x3) << 4);
		     out += "==";
		     break;
		 }
		 c2 = str.charCodeAt(i++);
		 if(i == len)
		 {
		     out += base64EncodeChars.charAt(c1 >> 2);
		     out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
		     out += base64EncodeChars.charAt((c2 & 0xF) << 2);
		     out += "=";
		     break;
		 }
		 c3 = str.charCodeAt(i++);
		 out += base64EncodeChars.charAt(c1 >> 2);
		 out += base64EncodeChars.charAt(((c1 & 0x3)<< 4) | ((c2 & 0xF0) >> 4));
		 out += base64EncodeChars.charAt(((c2 & 0xF) << 2) | ((c3 & 0xC0) >>6));
		 out += base64EncodeChars.charAt(c3 & 0x3F);
    }
    return out;
}

function base64decode(str) {
    var c1, c2, c3, c4;
    var i, len, out;

    len = str.length;
    i = 0;
    out = "";
    while(i < len) {
		 /* c1 */
		 do {
		     c1 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
		 } while(i < len && c1 == -1);
		 if(c1 == -1)
		     break;

		 /* c2 */
		 do {
		     c2 = base64DecodeChars[str.charCodeAt(i++) & 0xff];
		 } while(i < len && c2 == -1);
		 if(c2 == -1)
		     break;

		 out += String.fromCharCode((c1 << 2) | ((c2 & 0x30) >> 4));

		 /* c3 */
		 do {
		     c3 = str.charCodeAt(i++) & 0xff;
		     if(c3 == 61)
		 		 return out;
		     c3 = base64DecodeChars[c3];
		 } while(i < len && c3 == -1);
		 if(c3 == -1)
		     break;

		 out += String.fromCharCode(((c2 & 0XF) << 4) | ((c3 & 0x3C) >> 2));

		 /* c4 */
		 do {
		     c4 = str.charCodeAt(i++) & 0xff;
		     if(c4 == 61)
		 		 return out;
		     c4 = base64DecodeChars[c4];
		 } while(i < len && c4 == -1);
		 if(c4 == -1)
		     break;
		 out += String.fromCharCode(((c3 & 0x03) << 6) | c4);
    }
    return out;
}