var primariga = "Benvenuto nel sito Ciccsoft! E\' la prima volta che entri in questo sito!";

//-----------------------------
// GESTIONE DEL COOKIE
//-----------------------------
function pacchetto() {
	var datadioggi = new Date();
	var giornooggi = (datadioggi.getDate()<10 ? "0" : "") + datadioggi.getDate() + "";
	var meseoggi = (datadioggi.getMonth()<10 ? "0" : "") + (datadioggi.getMonth()+1) + "";
	var annooggi = datadioggi.getYear() + "";
	var nomecookie = "txf=";

	var quantick = document.cookie.length;
	var x = 0;
	while (x <= quantick) {
		var y = (x + 4);
		if (document.cookie.substring(x,y) == "txf=") {
			var giorno1 = document.cookie.substring((y),(y+2));
			var mese1 = document.cookie.substring((y+2),(y+4));
			var anno1 = document.cookie.substring((y+4),(y+8));

			var giorno2 = document.cookie.substring((y+8),(y+10));
			var mese2 = document.cookie.substring((y+10),(y+12));
			var anno2 = document.cookie.substring((y+12),(y+16));

			if ((giorno2 == giornooggi) && (mese2 == meseoggi)) {
				primariga = "Bentornato su Ciccsoft! La tua ultima visita è stata il " + giorno1 + '-' + mese1 + '-' + anno1;
				nomecookie += giorno1 + mese1 + anno1 + giorno2 + mese2 + anno2;
			}
			else {
				primariga = "Bentornato su Ciccsoft! La tua ultima visita è stata il " + giorno2 + '-' + mese2 + '-' + anno2;
				nomecookie += giorno2 + mese2 + anno2 + giornooggi + meseoggi + annooggi;
			}

			nomecookie += "; expires=";
			datadioggi.setDate(datadioggi.getDate() + 365);
			nomecookie += datadioggi.toGMTString();
			document.cookie = nomecookie;
			return true;
		}		

		x = document.cookie.indexOf(' ',x) + 1;
		if (x == 0) {
			nomecookie += giornooggi + meseoggi + annooggi + giornooggi + meseoggi + annooggi;
			nomecookie += "; expires=";
			datadioggi.setDate(datadioggi.getDate() + 365);
			nomecookie += datadioggi.toGMTString();
			document.cookie = nomecookie;
			return true;
		}
	}
	return null;
}
pacchetto();

//-----------------------------
// TESTO NELLA BARRA DI STATO
//-----------------------------
var count = 0;
var outtext;
function cambiaSB() {
	if (count == 8) {outtext = " ";count++;}
	if (count == 7) {outtext = "Aggiornato Sabato 29 Gennaio 2000";count++;}
	if (count == 6) {outtext = " ";count++;}
	if (count == 5) {outtext = "... e molto altro!!";count++;}
	if (count == 4) {outtext = "- Ricerca diretta sui principali motori di ricerca";count++;}
	if (count == 3) {outtext = "- La possibilità di inviare e-mail direttamente dal Web";count++;}
	if (count == 2) {outtext = "- Programmi gratis";count++;}
	if (count == 1) {outtext = "The X-Fails ti mette a disposizione numerosi servizi:";count++;}
	if (count == 0) {outtext = primariga;count++;}
	if (count == 9) count = 0;
	window.status = outtext;
	setTimeout(cambiaSB,2500);
}
cambiaSB();

//-------------------
// MOTORE DI RICERCA
//-------------------
function ricerca() {
	var count;
	var word = "";
	var words = document.mdr.parola.value;
	if (words == "") return;
	var len = words.length;
	for (count=0; count<len; count++) {
		if (words.charAt(count) != ' ') word += words.charAt(count);
		else word += "%2B";
	}
	if (document.mdr.sel[0].checked) window.open("http://search4.virgilio.it/search/cgi/search.cgi?db=v&ly=vs&vrs=0&qs=" + word + "&op=or");
	if (document.mdr.sel[1].checked) window.open("http://www.altavista.com/cgi-bin/query?pg=q&q=" + word + "&kl=XX&stype=stext&search.x=34&search.y=7");
	if (document.mdr.sel[2].checked) window.open("http://it.search.yahoo.com/search/it?p=" + word);
	if (document.mdr.sel[3].checked) window.open("http://search.excite.com/search.gw?search=" + word);
	if (document.mdr.sel[4].checked) window.open("http://www.lycos.it/cgi-bin/pursuit?mtemp=main.sites&etemp=error&query=" + word + "&cat=it&npl=matchmode%3Dand%26adv%3D1&maxhits=10");
	if (document.mdr.sel[5].checked) window.open("http://www.hotbot.com/?MT=" + word + "&SM=MC&DV=0&LG=any&DC=10&DE=2&BT=H&Search.x=48&Search.y=13");
	if (document.mdr.sel[6].checked) window.open("http://search-arianna.iol.it/abin/search?extlist=arianna&query=" + word + "&FormsButton1=Trova%21");
}

//-------------------------------
// SERVIZIO DI POSTA ELETTRONICA
//-------------------------------
function inviaMsg() {
	var outstr = "mailto:";
	if (document.mailer.Destinatario.value == "") {
		alert('Non hai scritto il Destinatario!');
		document.mailer.action = "";
		return false;
	}
	if (document.mailer.Destinatario.value.indexOf('@') == -1) {
		alert('L\' indirizzo specificato non è corretto!');
		document.mailer.action = "";
		return false;
	}
	if (document.mailer.Destinatario.value.indexOf('.') == -1) {
		alert('L\' indirizzo specificato non è corretto!');
		document.mailer.action = "";
		return false;
	}
	if (document.mailer.Messaggio.value == "") {
		alert('Non hai scritto il messaggio!');
		document.mailer.action = "";
		return false;
	}
	outstr += document.mailer.Destinatario.value;
	document.mailer.action = outstr;
	return true;
}

//-------------------
// ELENCO TELEFONICO
//-------------------
function telefono() {
	var strgt = "";

	var nomegt = document.gt.nome.value;
	var cognomegt = document.gt.cognome.value;
	var cittagt = document.gt.citta.value;

	if ((cognomegt == "") || (cittagt == "")) return;

	strgt = "http://elenco.virgilio.it/pb/jsp/search.jsp?fcg=A&fno=E&cg=" + cognomegt + "&no=" + nomegt + "&co=" + cittagt + "&pv=";
	window.open(strgt);
}

//-------------------
// SHAREWARE
//-------------------
function shareware() {
	var swcont;
	var prglen;
	var strsw = "http://shareware.cnet.com/shareware/1,10269,0-121777-501-0-1-1,00.html?&tag=&qt=";
	var programma = document.sw.prog.value;

	if (programma == "") return;

	prglen = programma.length;
	for (swcont=0; swcont<prglen; swcont++) {
		if (programma.charAt(swcont) != ' ') strsw += programma.charAt(swcont);
		else strsw += "+";
	}
	strsw += "&cn=&ca=121777";
	window.open(strsw);
}

//-------------------
// MAPPE
//-------------------
function mps() {
	var mpcont;
	var cittamap = document.mappa.cittamappa.value;
	var viamap = document.mappa.via.value;
	var statomap = document.mappa.stato.value;
	var strmap = "http://maps.excite.com/address_results/?a=";

	if ((cittamap=="")&&(viamap=="")&&(statomap=="")) return;

	mplen = viamap.length;
	for (mpcont=0; mpcont<mplen; mpcont++) {
		if (viamap.charAt(mpcont) != ' ') strmap += viamap.charAt(mpcont);
		else strmap += "+";
	}

	strmap += "&csz=";
	mplen = cittamap.length;
	for (mpcont=0; mpcont<mplen; mpcont++) {
		if (cittamap.charAt(mpcont) != ' ') strmap += cittamap.charAt(mpcont);
		else strmap += "+";
	}

	strmap += "&cn=";
	mplen = statomap.length;
	for (mpcont=0; mpcont<mplen; mpcont++) {
		if (statomap.charAt(mpcont) != ' ') strmap += statomap.charAt(mpcont);
		else strmap += "+";
	}

	window.open(strmap);
}

//-------------------
// SUPERENALOTTO
//-------------------
function superEna() {
	var numeri = new Array();
	var secont;
	var subcont = 0;
	var seout = "";

	for (secont=0; secont<6; secont++) {
		numeri[secont] = ((Math.random() * 90) + 1) + "";
		for (subcont=secont; subcont>0; subcont--) {
			if ((numeri[secont].substring(0, numeri[secont].indexOf('.'))) == (numeri[subcont].substring(0, numeri[subcont].indexOf('.')))) {
				numeri[secont] = ((Math.random() * 90) + 1) + "";
				subcont=secont;
			}
		}
		seout += numeri[secont];
		seout = seout.substring(0, seout.indexOf('.'));
		(secont < 5) ? seout += " - " : seout += "";
	}
	document.secol.colonna.value = seout;
	document.secol.colonna.blur();
}

//-------------------
// INVIO SMS
//-------------------
function inviaSms() {
	var ndt = document.sms.NUM.value;
	var pref = ndt.substring(0,4);
	if ((pref!="0335")&&(pref!="0338")&&(pref!="0339")&&(pref!="0347")&&(pref!="0348")&&(pref!="0349")&&(pref!="0328")&&(pref!="0329")) {
		alert("Numero di telefono errato");
		document.sms.action = "";
		return false;
	}
	if (document.sms.MESS.value == "") {
		alert("Non hai scritto il messaggio");
		document.sms.action = "";
		return false;
	}
	var sped = confirm("Il numero di telefono impostato è: \"" + ndt + "\"\n\nIl messaggio è: \n\"" + document.sms.MESS.value + "\"\n\nInviare il messaggio?");
	if (sped) {
		document.sms.action = "http://www.sms.it/cgi-bin/free.pl";
		return true;
	} else {
		alert("Operazione annullata");
		document.sms.action = "";
		return false;
	}
}

//-------------------
// Nome - Numero
//-------------------
function fnumtnom() {
	var noditel = "http://elenco.virgilio.it/pb/jsp/search_nt.jsp?nt=";
	if (document.numnom.telno.value == "") return;
	noditel += document.numnom.telno.value;
	noditel += "&ela=S";
	window.open(noditel);
}
