var keyStr= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function changeLoginUndo() {
	document.getElementById('logUeP').style.display='block';
	document.getElementById('logAdsl').style.display='none';
	document.getElementById('linkChangeLogin').innerHTML='Accesso con ADSL';
	document.getElementById('linkChangeLogin').onclick=function() {changeLogin(); return false};
}
function changeLogin() {
	document.getElementById('logUeP').style.display='none';
	document.getElementById('logAdsl').style.display='block';
	document.getElementById('linkChangeLogin').innerHTML='Accesso con Login';
	document.getElementById('linkChangeLogin').onclick=function() {changeLoginUndo(); return false};
}
function switchLogin(idOn) {
	document.getElementById("divUserPwd").style.display=(idOn=="divUserPwd"?"block":"none");
	document.getElementById("divCLI").style.display=(idOn=="divCLI"?"block":"none");
}
function decode64(input) {
	var keyStr= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
	var output = "";
	var chr1, chr2, chr3;
	var enc1, enc2, enc3, enc4;
	var i = 0;
	input=input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
	do {
		enc1=keyStr.indexOf(input.charAt(i++));
		enc2=keyStr.indexOf(input.charAt(i++));
		enc3=keyStr.indexOf(input.charAt(i++));
		enc4=keyStr.indexOf(input.charAt(i++));
		chr1=(enc1 << 2) |( enc2 >> 4);
		chr2=((enc2 & 15)<<4) | (enc3 >> 2);
		chr3=((enc3 & 3) << 6) | enc4;
		output=output + String.fromCharCode(chr1);
		if(enc3!=64) {
			output=output+String.fromCharCode(chr2);
		}
		if(enc4!=64) {
			output=output+String.fromCharCode(chr3);
		}
	} while (i < input.length);
	return output;
}
function checkEnter_155(event) {
	var code=0;
	if(document.layers) code=event.which; else code=event.keyCode;
	if(code==13) document.LoginForm.submit();
}
function Tclear(el) {
	if (el.defaultValue==el.value) el.value = ""
}
function DoSubmit(form) {
	if ((form.ssousername.value!='User Name') && (form.ssousername.value!='') && (form.password.value!='')) {
		form.submit();
	}
}
function DoSubmitAdsl(form) {
	if ((form.cliadsl.value!='Numero ADSL') && (form.cliadsl.value!='')) {
		form.submit();
	}
}
function IsInfostrada() {
	if(location.href.indexOf(URL_INFOSTRADA_155, 0)>-1) return(true);
	return(false);
}
function IsWind() {
	if(location.href.indexOf(URL_WIND_155, 0)>-1) return(true);
	return(false);
}
function getCookie(Name) {
	var search=Name+"=";
	if(document.cookie.length>0) {
		offset=document.cookie.indexOf(search) 
		if(offset!=-1) {
			offset+=search.length;
			end=document.cookie.indexOf(";", offset);
			if(end==-1) end=document.cookie.length;
			return(unescape(document.cookie.substring(offset, end)));
		} 
	}
	return("");
}
function IsLogged() {
	return(getCookie("windeun")!="");
}
function GetUsername() {
	if(!IsLogged()) return("");
	return(decode64(getCookie("windeun")));
}
function GetUsernameInfo() {
	if(!IsLogged()) return("");
	return(decode64(getCookie("aculoginf")));
}
function GetDad() {
	return(DAD_155);
}
function GetRelativeUrl() {
	if(IsInfostrada()||IsWind()) return("/areaclienti/pls/" + GetDad() + "/");
	return("/pls/" + GetDad() + "/");
}
function GetBaseUrl() {
	protocolOffset=location.href.indexOf("//", 0)+2;
	domainOffset=location.href.indexOf("/", protocolOffset);
	return(location.href.substr(0, domainOffset) + "/areaclienti/pls/" + GetDad() + "/");
}
function GetNew155Dad() {
	if (IsWind())
		return('wind');
	else
		return('infostrada');
}
function GetNew155BaseUrl() {
	protocolOffset=location.href.indexOf("//", 0)+2;
	domainOffset=location.href.indexOf("/", protocolOffset);
	return(location.href.substr(0, domainOffset) + "/nuovaAreaClienti/" + GetNew155Dad() + "/");
}
function GetSecureProtocol() {
	return(SECURE_PROTOCOL_155);
}
function GetSecureUrl() {
	protocolOffset=location.href.indexOf("//", 0)+2;
	domainOffset=location.href.indexOf("/", protocolOffset);
	return(GetSecureProtocol() + '://' + location.href.substr(protocolOffset, domainOffset-protocolOffset) + GetRelativeUrl());
}
function GetNew155SecureUrl() {
	protocolOffset=location.href.indexOf("//", 0)+2;
	domainOffset=location.href.indexOf("/", protocolOffset);
	return(location.href.substr(0, domainOffset) + "/nuovaAreaClienti/" + GetNew155Dad() + "/");
	//return(GetSecureProtocol() + '://' + location.href.substr(protocolOffset, domainOffset-protocolOffset)+ "/nuovaAreaClienti/" + GetNew155Dad() + "/");
}
function GetUrlHttps(url) {
	protocolOffset=url.indexOf("//", 0)+2;
	return(GetSecureProtocol() + '://' + url.substr(protocolOffset, url.length-protocolOffset));
}

function NewLoginEnable(){
 return(true);
}

function GetHomePageUrl(){
	var tmpUrl;
	if (NewLoginEnable())
		tmpUrl=GetNew155BaseUrl()+"pages/home.action";
	else	
		tmpUrl=GetBaseUrl()+"w155.home";

	return(tmpUrl);
}
function GetAutenticateUrl(){
	var tmpUrl;
	if (NewLoginEnable())
		tmpUrl=GetNew155SecureUrl()+"login.action"; // "authenticateSso.action";
	else	
		tmpUrl=GetSecureUrl()+"w155.pkg_authentication.login_url";

	return(tmpUrl);
}
function GetAutenticateAdslUrl(){
	var tmpUrl;
	if (NewLoginEnable())
		tmpUrl=GetNew155SecureUrl()+"authenticateAdsl.action";
	else	
		tmpUrl=GetSecureUrl()+"w155.pkg_authentication.login_url_adsl";

	return(tmpUrl);
}
function GetLogOutUrl(){
	var tmpUrl;
	if (NewLoginEnable())
		tmpUrl=GetNew155SecureUrl()+"logoutSso.action";
	else	
		tmpUrl=GetSecureUrl()+"w155.pkg_authentication.logout_url";

	return(tmpUrl);
}

