var PATHM=""

function PopUp(pagina,w,h) { 
	numcas=Math.ceil(((80) * Math.random( ) + 1)) 
	window.open(pagina, "PopUp",'scrollbars=yes,status=no,menubar=no,resizable=yes,width='+w+',height='+h);
}

function inviaemail() { 
	if ((document.FrmPage.S.value!="") && (document.FrmPage.B.value!="")){
	document.FrmPage.action=PATHM+"emailme.asp"
	document.FrmPage.submit()}
	else{alert("Bisogna specificare entrambe i campi per inviare una email!")}
}

function ACRONYM(index){
	var stringa;
	switch(parseInt(index)){
	case 0:	stringa="Vota anche tu il Sondaggio del mese!"
			break
	case 1:	stringa="Scrivi alla Memobase un messaggio personale"
			break
	case 2:	stringa="Firma il libro dei visitatori"
			break
	case 3:	stringa="Consulta i Links per ulteriori approfondimenti"
			break
	case 4:	stringa="Segnala questo sito ai tuoi amici"
			break
	case 5:	stringa="La Memobase garantisce almeno una Newsletter al mese...Le Newsletter della memobase cercheranno di anticipare i nuovi articoli che compariranno sul sito informandovi qualche giorno prima della comparsa degli stessi e direttamente nella vostra casella di posta elettronica. Vi accompagneremo in questo viaggio nei misteri della mente alla scoperta dei suoi segreti con curiosità, test, tecniche di memoria e  tanto altro. Alcuni argomenti verranno inviati solo attraverso le newsletter e non compariranno sul sito."
			break
	case 6:	stringa="Ricorda di riportare la tua email se desideri avere una risposta"
			break
	case 7:	stringa="Puoi cercare nelle pagine memobase... oppure scegliere un motore di ricerca"
			break
	}
		var NAV=window.navigator.appName
		if (NAV.lastIndexOf("Explorer")>0)
		{	document.write("<acronym title='"+stringa+"'/>")
		}
}

function GO(INDEX)
{
	if (parseInt(INDEX)>0) document.location.href=PATHM+"RunAsp.asp?ID="+INDEX;
}
function GoToURL(IDMENU,ID){
	var w
	var h
	var D=document.menu;
	var INDEX;
	var NAV=window.navigator.appName

	switch (IDMENU){
		case 1: INDEX=D.Rilassamento[ID].value
				break
		case 2: INDEX=D.Stress[ID].value
				break
		case 3: INDEX=D.Consigli[ID].value
				break
		case 4: INDEX=D.Premesse[ID].value
				break
		case 5: INDEX=D.mnemotecniche[ID].value
				break
		case 6: INDEX=D.Curiosita[ID].value
				break
		case 7: INDEX=D.comunita[ID].value
				break
		case 8: INDEX=D.Giochi[ID].value
				break
		case 9: INDEX=D.Test[ID].value
				break
	}
	var ID_OW=0;
	if (NAV.lastIndexOf("Explorer")>0)
		switch (IDMENU){
			case 1: ID_OW=D.Rilassamento[ID].id
					break
			case 2: ID_OW=D.Stress[ID].id
					break
			case 3: ID_OW=D.Consigli[ID].id
					break
			case 4: ID_OW=D.Premesse[ID].id
					break
			case 5: ID_OW=D.mnemotecniche[ID].id
					break
			case 6: ID_OW=D.Curiosita[ID].id
					break
			case 7: ID_OW=D.comunita[ID].id
					break
			case 8: ID_OW=D.Giochi[ID].id
					break
			case 9: ID_OW=D.Test[ID].id
					break
		}
	if (ID_OW>0){
			if (parseInt(INDEX)>0){
				w=ID_OW.substr(0,2)+0 
				h=ID_OW.substr(2,2)+0
				PopUp(PATHM+"RunAsp.asp?ID="+parseInt(INDEX),w,h)
			}
	}
	else{if (parseInt(INDEX)>0) document.location.href=PATHM+"RunAsp.asp?ID="+INDEX}
}

function ctrl() {
	var f = document.menu
	var c="true"
	
	if (f.emailaddress.value.indexOf("@") == -1) {
		alert("E' necessario inserire un indirizzo E-Mail valido.")
		f.emailaddress.focus()
		c="false"
	}
	
	if (f.emailaddress.value.indexOf(".") == -1) {
		alert("E' necessario inserire un indirizzo E-Mail valido.")
		f.emailaddress.focus()
		c="false"
	}
	if (c == "true") {
					  PopUp(PATHM+"mailing.asp?action="+f.Action.value+"&emailaddress="+f.emailaddress.value,500,300)
	}

}

function viewList(q,w)
{
	var Findw=w
	Findw=Findw.replace(/(\s+)/g,"")
	if ((w!="") && (Findw.length>2)){
		if (document.FrmPage.R1[0].checked) {window.location.href(PATHM+"ricx.asp?motore=" + w)}
		if (document.FrmPage.R1[1].checked) {vaiURL(q,w)}
	}
	else{alert("Inserire una frase da cercare!")}
}

function url(x,w)
        {
        if (x==0) return "http://search.virgilio.it/search/cgi/search.cgi?db=v&ly=vs&vrs=0&qs=" + w + "&op=and&"
        if (x==1) return "http://it.search.yahoo.com/search/it?p=" + w
        if (x==2) return "http://www.goto.com/d/search/p/go/?Partner=go_home&Keywords=" + w
        if (x==3) return "http://it.altavista.com/q?pg=q&q=" + w + "&kl=it&what=it&search.x=14&search.y=13"
        if (x==4) return "http://cerca.lycos.it/cgi-bin/pursuit?matchmode=and&mtemp=main&etemp=error&query=" + w + "&cat=loc&type=all&lang=any&idx=all&maxhits=10&x=38&y=12"
        if (x==5) return "http://www.excite.it/cerca/web/risultati?c=web&sort=doc&search=" + w + "&lang=it&sort=doc&showSummary=true&look=excite_it&start=0&perPage=10"
        if (x==6) return "http://www.godado.it/godado.pperl?sid=7252548534-979212585&af=0&l=6&Keywords=" + w + "&p1=1&w1=21&URL=&Godado%21.x=30&Godado%21.y=6"
        if (x==7) return "http://search-arianna.iol.it/abin/search?query="+ w + "&CHIAVE_MP=&chiave=&categoria=&radiobutton=italia"
        if (x==8) return "http://search.supereva.it/cgi-bin/gsearch.chm?sefull=1&motore=1&q=" + w
        if (x==9) return "http://www.tecnoseek.it/dsearch.cgi?db=default&uid=&keyword=" + w + "&mh=10&sb=15&so=descend&view_records=Cerca"
        return ""
        }

function vaiURL(q,w) {
	WindowName="MySearch";
	settings="toolbar=yes,location=yes,directories=yes,"+"status=yes,menubar=yes,scrollbars=yes,"+"resizable=yes,width=800,height=600";
	MyNewWindow=window.open(url(q,w),WindowName,settings);
	return 0
}


function attiva(){
	document.FrmPage.R1[1].checked = true
}


function colora(nome)
{
   if (nome=="where"){document.FrmPage.where.style.backgroundColor='#D6A529'}
   else {document.FrmPage.where.style.backgroundColor='white'}
}

function Valuevoto(voto){
   for(i=0; i<document.FrmPage.all.length; i++) {
   if ((document.FrmPage.all(i).tagName=="INPUT")&& (document.FrmPage.all(i).name=='voto_sond') && (document.FrmPage.all(i).checked==true))
     { voto=document.FrmPage.all(i).value}
   }
   return voto
}
function PopUp_Sondaggio(pagina,w,h) {
var voto=""
voto=Valuevoto(voto)
if (voto == ""){alert("Devi esprimere una preferenza per votare")}
else{
var username=getCookie('MBvisitor')

	if (username == null){
		pagina=pagina+"?voto_sond="+ voto
		window.open(pagina, 'PopUp','scrollbars=yes,status=no,menubar=no,resizable=yes,width='+w+',height='+h);
		doSetCookie()
	}
	else{alert("Hai già votato!\nPuoi votare domani!\nGrazie!")}
	}
}

function getCookie(Name) {
	var value=null
	var MBCookie = document.cookie;
	var search = Name + "="
	var endPos

	if (MBCookie.length > 0) {
		var beginPos=MBCookie.indexOf(search)
		if (beginPos!= -1) {
			beginPos= beginPos + search.length;
			endPos = MBCookie.indexOf(";", beginPos);
			value=unescape(MBCookie.substring(beginPos, endPos))
			if (endPos == -1){
				endPos  = MBCookie.length;
				value=unescape(MBCookie.substring(beginPos, endPos))
			}
		}
		return value
	}
}

function SetCookie (name, value) {
	var expireDate=new Date()
	var expireString=""
	expireDate.setTime(expireDate.getTime()+(1000*60*60*24*1))
	expireString="expires=" + expireDate.toGMTString()
	document.cookie=name+"="+escape(value)+";"+expireString+";"
}

function whoareyou(){youare=getCookie("MBvisitor"); alert(youare)}

function doSetCookie(){
	var username=getCookie('MBvisitor')
	var i
	var STR="0123456789abcdefghilmnopqrstuvzxywjkABCDEFGHILMNOPQRSTUVZXYWJK"
	var myarray = new Array();
	if (username == undefined){
		username=""
		for (i = 0; i < 62; i++){myarray[i] = STR.charAt(i)}
		for (i = 0; i < 6; i++){username = username + myarray[Math.round
		((61 * Math.random() + 1))]}
	}
	SetCookie("MBvisitor", username)
}