
submit_utente = false;
var newwin

function popup(page){
	newwin = window.open(page,"abbonati", 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,status=no,width=620,height=450,top=0,left=0');
}
function popupUPG(page){
	mC=new Image();
    mC.src = _clkSetHref('http://www.tiscali.it/img/null.gif','POS1.01', 'I');
	newwin = window.open(page,"abbonati", 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,status=no,width=620,height=450,top=0,left=0');
}
// send page 
function print_page(url){
paginastampa=window.open(url, 'Stampa', 'height=350,width=640,menubar=no,resizable=no,scrollbars=yes,toolbar=no');
}


function sendCB(){
	if (document.getElementById('callback').num_tel.value == "")	alert ("Attenzione!\nVerifica di aver inserito correttamente il numero telefonico.");
	else document.getElementById('callback').submit();
 }
 
 
function showDetailsSp(ch){
	if (ch == 'on'){
		$("#dettagliOn").slideDown("slow");
		document.getElementById('dettagliOff').style.display='none';
	}
	else  {
		$("#dettagliOn").slideUp("fast");
 		document.getElementById('dettagliOff').style.display='';
	}
}

/* header */
function el(element){
	return document.getElementById(element);
}


window.onunload=function(){
	void(0);	// non cancellare, serve per far rieseguire tutto il js quando si preme il back
}


/* mgm */
function invita(f){
	if (f=='login'){
		if ((document.getElementById('manage_mgm').userid.value == '') || (document.getElementById('manage_mgm').password.value == '') ){
			alert ('Attenzione\nVerifica di aver inserito la tua e-mail e la tua password\nGrazie');
		}
		else {
			document.getElementById('manage_mgm').submit();
		}
		//mC=new Image();
    	//mC.src = _clkSetHref('http://www.tiscali.it/img/null.gif','PPH.02', 'I');
	}

	else if (f=='members'){
		if ((document.getElementById('runApplication').senderName.value == '') || (document.getElementById('runApplication').senderMail.value == '') ){
			alert ('Attenzione\nVerifica di aver inserito il tuo nome e la tua e-mail\nGrazie');
		}
		else {
			document.getElementById('runApplication').action='/inc/mgm/gateway.php';
			document.getElementById('runApplication').submit();
		}
		//mC=new Image();
    	//mC.src = _clkSetHref('http://www.tiscali.it/img/null.gif','PPH.01', 'I');
	}
}
// target blank
function target() { 
    for (var i=0; i<document.links.length; i++){
		if(document.links[i].className.indexOf('blank') != -1)document.links[i].target="_blank";
	} 
}
window.onload = target;

/* cookies */
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){
	var today = new Date();
	var expires_date = new Date();
	if (isFinite(expires)){
		expires_date.setTime(today.getTime() + 3600000*24*expires);
	}else{
		expires_date=expires;
		}
        document.cookie=name+"="+escape(value)+((expires)?"; expires="+expires_date.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=Tue, 01-Jan-2002 00:00:01 GMT";
	}
}
function getCookieVal(offset){
	var endstr=document.cookie.indexOf(";",offset);
	if(endstr==-1)endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
}

function checkDomainName(field){
	var d=field.value=field.value.replace(/^([\s\r]*)/,'').replace(/([\s\r]*)$/,'').toLowerCase(),err='';
	if(d.length == ''){
		err="Inserire un dominio valido";
	}
	else if(d.length < 2 ){
		err="Il dominio deve avere una lunghezza minima di 2 caratteri";
	}
	else if(d.length > 63 ){
		err="Il dominio non puo' avere una lunghezza superiore ai 63 caratteri";
	}
	else if(d.indexOf('.') != -1){
		err='Il carattere punto "." non' + " e' consentito (usare solo alfanumerici e " + 'trattino " - ") ';
	}
	else if(d.indexOf('-') == 0 || d.indexOf('-') == d.length-1){
		err="Il dominio non puo' iniziare ne' finire con" + ' il carattere " - " ';
	}
	else if(d.search(/^[0-9a-zA-Z-]+$/) < 0){
		err="Caratteri non consentiti (usare solo alfanumerici e " + 'trattino " - ") ';
	}
	return err;
}		 
	
var host = document.URL.split('/');	


function doSubmit(){
	document.getElementById('showErr').style.display='none';
	if(submit_utente == false){
		var errMsg = checkDomainName(document.dominio.domain_name);
		if(errMsg.length > 0){
			document.getElementById('showErr').style.display='block';
			document.getElementById('showErr').innerHTML=errMsg;
		}
		else{
			submit_utente = true;	
//			document.getElementById('layer_select').style.display='none';
			//document.getElementById('layer_flash').style.display='block';
			if (sharedTipology){
				document.getElementById('dominio').hosting_type.value =	sharedTipology;	  
			}
			if ((host[2] == 'abbonati.tiscali.it') || (host[2] == 'abbonati.dev.tiscali.it')){
				document.getElementById('dominio').action="https://hosting.tiscali.it/abbonati/fullcheck_domain.action";	
			}
			else{
				document.getElementById('dominio').action="https://hosting.tiscali.it/fullcheck_domain.action";
			}
			setTimeout("document.getElementById('dominio').submit()",500);
		}
	}
}

function check_form()
{
	if(document.sendpage.email.value.indexOf('@')<0) {
		alert("Verificare l'email!");
		return;
	}
	if(document.sendpage.ragione_sociale.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.sendpage.nome.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.sendpage.cognome.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.sendpage.qualifica.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.sendpage.citta.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.sendpage.provincia.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.sendpage.telefono.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if((document.sendpage.consenso1.checked == true) && (document.sendpage.consenso2.checked == true))  {
		document.sendpage.submit();
	}
	else{	
		alert("E' necessario dare il consenso al trattamento dei dati personali");
		return;
	}

}	

function check_ass()
{
	if(document.send_request.nome.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.send_request.cognome.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.send_request.telefono.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}		
	if(document.send_request.email.value.indexOf('@')<0) {
		alert("Verificare l'email!");
		return;
	}
	if(document.send_request.azienda.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}
	if(document.send_request.tipo_richiesta.value == '')  {
		alert("I campi contrassegnati con * sono obbligatori");
		return;
	}

	document.send_request.submit();

}

function acquista(t){
 	if (t==0){
 		javascript:showLayer('/layers/servizio_sospeso.php')
 	}
 	else {
 		document.getElementById('attiva').action="https://selfcare.tiscali.it/unit/selfcare/it_selfcare";
 		document.getElementById('attiva').submit();}
}

function goLink(u){

	document.location.href=u;

}

function showDetails(id){

	if ($('#'+id+'On').is(":hidden")){

		$('#'+id+'On').css("visibility","");

		$('#'+id+'On').slideDown("slow");

		mC=new Image();

		mC.src = _clkSetHref('http://www.tiscali.it/img/null.gif','POS4.01', 'I');

		$.scrollTo($('#'+id+'On'), 500 );

		$('#fr_'+id).attr({src: "/img/v003/dot_arrow_down_27.gif"});

	}

	else{

		$('#'+id+'On').slideUp("slow");

		$('#fr_'+id).attr({src: "/img/v003/dot_arrow_right_27.gif"});

	}

}

function cldatiSociali(){
	$("#datiSociali").css({'visibility':'hidden'});
	$("#dsOn").css({'display':''})
	$("#dsOff").css({'display':'none'})
}

function datiSociali(s){
	if (s=='on'){
		u="/inc/etc/datiSociali.php";
		var _url=u+"?"+Math.random()*100000;
		$("#datiSociali").load(_url);
		$("#datiSociali").css({'visibility':'visible','min-height':100});
		$("#dsOff").css({'display':''})
		$("#dsOn").css({'display':'none'})
	}
	else{
		cldatiSociali();
	}
}

/* apertura pop up di retention */
/* apertura pop up di retention */
function retention(){}

function retention_on(s){

bodyW 	= document.documentElement.clientWidth;
marLeft = (bodyW - 600)/2;
bodyH 	= document.documentElement.clientHeight;
marTop 	= (bodyH - 273)/2;
if(s==0){
	var ret = GetCookie("ret");
//	alert ("s= "+s+" - ret= "+ret);
	if(ret == null){
		page = "/retention.php?type=RT";
		SetCookie('ret','1',0,'/','tiscali.it');
		window.open(page,"abbonati", 'toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no,status=no,width=770,height=448,top='+marTop+',left='+marLeft);
		}
	}
	else{
		return false;
	}
}

function uChoice(u){
	if (u == 0) {
		$('body').attr("onunload",'retention(0)');	
	}
	else {
		$('body').attr("onunload",'retention(1)');
	}
}

$(document).ready(function () {
	$("div.hpMain").click(function(){
		uChoice("1");
	});	
	$("a").click(function(){
		uChoice("1");
	});
});
/* end apertura pop up di retention */

function expandSitofono(prod,tec,type){
	bodyW 	= document.documentElement.clientWidth;
	marLeft  = (bodyW - 600)/2;
	bodyH = document.documentElement.clientHeight;
	marTop = (bodyH - 273)/2;
	page = "/inc/etc/help/index.php?prod="+prod+"&tec="+tec+"&type="+type;
	newwin = window.open(page,"abbonati", 'toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no,status=no,width=600,height=347,top='+marTop+',left='+marLeft);
}

function stopTime(){
	clearTimeout(timer);
}

function slider(){
	this.count = 1;
	this.auto = 1;
	this.offSet = 0; 
}
slider.prototype.slide = function(idCont,action,pos,visible,scrolling){
		// id bottoni nomi bottomi
		var idPrev = 'b-prev'+pos;
		var idNext = 'b-next'+pos;		
		// off set spostamento
		var scrollVal = scrolling;
		// numero di elementi per pagina
		var ElxPage = visible;
		// numero totale elementi
		var totalEl = 5;
		//alert(totalEl);
		/*
		incrementa il counter e sposta l'offSet
		viene eseguita solo se riceve il parametro action
		*/
		page = Math.ceil(totalEl / ElxPage);
		if(action != ''){
			
			if(action=='auto'){
				timer = setTimeout("abbonati.slide('sliderOffset1','auto',1,1,988)",20000);
				if(this.auto != 1){
					if(this.count < page){
						this.count++;
						this.offSet -= scrollVal;	
					} 
					else{
						this.count = 1;
						this.offSet += 3952;				
					}
				}			
			}
			else{
				clearTimeout(timer);
				if(action == 'prev' && this.count > 1){
					this.count--;
					this.offSet += scrollVal;
				}
				if(action == 'next' && this.count != page){
					this.count++;
					this.offSet -= scrollVal;					
				}
			}
			if(this.auto == 1){
				this.auto++;	
			}
			else{
				$('#'+idCont).animate({left: this.offSet},500);
			}
			this.auto++;
		}
		//alert(pos)
		pos = this.count;
		
		$('.contBorderPP').bind('click', function() {							  
			location.href=$('#href'+pos+'').attr("href");
		});
		
		// controlli pulsantiera
		if(this.count == 1 || page > 1){
			$('#'+idPrev).attr({src: "/img/v005/btn_previous_slide_off.png"});
			$('#'+idNext).attr({src: "/img/v005/btn_next_slide.png"});	
			$('#l-prev1').css({'cursor':'default'});	
			$('#l-next1').css({'cursor':'pointer'});
		}
		if(this.count > 1 && this.count == page){
			$('#'+idNext).attr({src: "/img/v005/btn_next_slide_off.png"});	
			$('#l-next1').css({'cursor':'default'});			
		}		
		if(this.count > 1){
			$('#'+idPrev).attr({src: "/img/v005/btn_previous_slide.png"});
			$('#l-prev1').css({'cursor':'pointer'});	
		}
		if((totalEl < ElxPage) || (totalEl == ElxPage)){
			$('#'+idNext).attr({src: "/img/v005/btn_next_slide_off.png"});
			$('#'+idPrev).attr({src: "/img/v005/btn_previous_slide_off.png"});
			$('#l-next1,#l-prev1').css({'cursor':'default'});
		}		
}
