var agt = navigator.userAgent.toLowerCase();
var is_op = (agt.indexOf("opera") != -1);
var is_ie = (agt.indexOf("msie") != -1) && document.all && !is_op;
var is_ie5 = (agt.indexOf("msie 5") != -1) && document.all && !is_op;
var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";

if(screen.width<=640){
document.write('<style>body{font-size:80%}</style>');

}
else{

var ww = (50*screen.width/800);
if (ww < 90) {ww = 100}
   // if(ww > 110){ ww = 110}
   ww = 100 
   //alert(ww)
document.write('<style>body{font-size:'+ww+'%}</style>');

}

function mostra() {
	var stato = document.getElementById("chiudi").style.height
	alert(stato)
	if (stato == "") {
		//document.getElementById("chiudi").style.height = "150px";
		document.getElementById("chiudi").style.overflow = "hidden";
	}
	else {
		//document.getElementById("chiudi").style.height = "";
		document.getElementById("chiudi").style.overflow = "visible";
	}
}


function submitRicAv(){ 

document.getElementsbyName("lastForm")[0].submit();
}

function openWin(id){
var txt = "photo.php?id="+id+""

fin = window.open(txt,'','scrollbars=yes,width=100,height=100')

}

function showTabAvan(){
if (document.all){var disp = ""}
else{var disp = "table"}
  document.getElementById("ricAvFilm").style.display = "none";
  document.getElementById("ricAvLibro").style.display = "none";
     document.getElementById("ricAvRecensioni").style.display = "none";
     document.getElementById("ricAvSaggi").style.display = "none";
     document.getElementById("ricAvTv").style.display = "none";
var sel = document.getElementsByName("nellaSez")[0].value

//document.getElementById("ricAvFilm").style.display = "table"
switch (sel){
   case "film" : 
      document.getElementById("ricAvFilm").style.display = disp;
      break;
   case "libri" : 
       document.getElementById("ricAvLibro").style.display = disp;
      break;
   case "recensioni" : 
       document.getElementById("ricAvRecensioni").style.display = disp;
      break;
     case "saggi" : 
       document.getElementById("ricAvSaggi").style.display = disp;
      break;
      case "tv":
     document.getElementById("ricAvTv").style.display = disp;
      break;
  
}


}

function sendMail(ID){
theUrl = "sendRecens.php?id=" + ID
winny = window.open(theUrl,'','width=550,height=400')
}
function sendSag(ID,tipo){
theUrl = "sendSag.php?id=" + ID + "&tipo="+tipo
winny = window.open(theUrl,'','width=550,height=400')
}


function sistemaHome(){
var maxImg = 440
 if (document.all) {
    var ww = document.body.clientWidth 
    
    }
    else {
    var ww = window.innerWidth
    
    }
 ww = ww - 20; 
 ww = ww / 2;
 if (ww > maxImg){
 document.getElementById('colly01').style.width = "440px";
 document.getElementById('imgSpacer').style.width = "440px";
 
 document.getElementById('colly02').style.width = "100%";

 
 }
 else {
 document.getElementById('colly01').style.width = "50%";
 //document.getElementById('imgSpacer').style.width = "100%";
 
 document.getElementById('colly02').style.width = "50%";

 }

}
function init(){
var cosa = "block"
if (screen.width<=800){
document.getElementById("search02").style.display = cosa
}
else {
document.getElementById("search01").style.display = cosa
}
if(document.skipMe != "1"){fixFastWeb()}
}
function fixFastWeb(){
var obj = document.getElementsByTagName("A")
var lg = obj.length
var x = 0;
do {
    var myUrl = obj[x].href
    //al(myUrl)
    if( myUrl.indexOf("msg.fastwebnet.it/file/") != -1) {
    var newUrl = myUrl.replace("http://ms001msg.fastwebnet.it/file/","") 
   obj[x].setAttribute("HREF" , newUrl)
    } //http://.com/save
    if( myUrl.indexOf("http://www.culturagay.it/") == -1 && myUrl != "" &&  myUrl.indexOf("javascript:") == -1 &&  myUrl.indexOf("culturit-21") == -1 &&  myUrl.indexOf("culturagayit-20") == -1 && myUrl.indexOf("culturagayit-21") == -1 && myUrl.indexOf("facebook") == -1 && myUrl.indexOf("delicious") == -1) {
    obj[x].innerHTML =  obj[x].innerHTML + "<img src='imgs/externalLink.gif' border='0' style='margin-left:3px' />"
    obj[x].title = "link esterno" 
    }
    
x++;
}
while(x < lg)

}


function ricaricaAvanz(ordine){
document.getElementsByName("ordine")[0].value = ordine;
document.forms[1].submit();

}
function pag(nr){
document.getElementsByName("skip")[0].value = nr;
document.forms[1].submit();
}

function formattaForm(ind){
var y = 0
var campi = new Array;
var inidic = new Array;
switch (ind){
   case 0 : 
        campi[0] = "titolo"
        campi[1] = "titolooriginale"
        campi[2] = "soggetti"
        inidic[0] = 0 
        inidic[1] =  0
        inidic[2] =  0
        var nomCk = "tut"
      break;
   case 1 : 
        campi[0] = "titolo"
        campi[1] = "titolooriginale"
        campi[2] = "temi"
        inidic[0] = 1 
        inidic[1] =  1
        inidic[2] =  0
        var nomCk = "tut2"
      break;
   case 2 : 
        campi[0] = "titolo"
        
        campi[1] = "corpo"
        inidic[0] = 2 
        inidic[1] =  0
        var nomCk = "tut3"
      break;

}


do {
if (document.getElementsByName(nomCk)[y].checked == true ){
var prendo = document.getElementsByName(campi[y])[inidic[y]].value
arrayPrendo = prendo.split(" ");
x = 0 
var txt = ""
do{
txt = txt + arrayPrendo[x] + "%" ;
x = x + 1;
}
while (x < arrayPrendo.length)
document.getElementsByName(campi[y])[inidic[y]].value = txt
}
y = y  + 1
}
while (y < 3)
}

function sblocca(chi,da,modalit){
var stato = document.getElementById(chi).readOnly 
if (stato == true){
    document.getElementById(chi).readOnly = false;
    if (modalit == 1){
    document.getElementById(da).innerHTML = "blocca";
    var daImg = "img" + da
    document.getElementById(daImg).src = "imgs/lockOpen.gif";
    }
    document.getElementById(chi).focus();
}
else {
    document.getElementById(chi).readOnly = true;
    if (modalit == 1){
    document.getElementById(da).innerHTML = "modifica";
    var daImg = "img" + da
    document.getElementById(daImg).src = "imgs/lockClose.gif";
    }
   }
}
function isEmail(str) {
 
  var supported = 0;
  if (window.RegExp) {
    var tempStr = "a";
    var tempReg = new RegExp(tempStr);
    if (tempReg.test(tempStr)) supported = 1;
  }
  if (!supported) 
    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return (!r1.test(str) && r2.test(str));
}

function valMail(mai){

 var risultato = isEmail(mai)
 if (risultato == false){
 alert("ATTENZIONE!! \n E-mail non valida!" );
 return false
 
 }
 else {
 return true;
 }
 }
 
 
function caricaDati(pagina,id,pg){
if (is_ie) {
      xmlhttp = new ActiveXObject(control);
}
else {


var xmlhttp =  new XMLHttpRequest();
}


xmlhttp.open('POST', pagina , true);
xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
xmlhttp.onreadystatechange = function() {
          if (xmlhttp.readyState == 4) {
              if (xmlhttp.status == 200)
                  scriviRisultato(xmlhttp.responseXML);
              /*else
                  target.submit();
          
          */}
      }
vai = "pagina="+pg
xmlhttp.send(vai);
id = "id=11"+id;
//xmlhttp.send(id);
}
function scriviRisultato(responseXML){
//document.getElementsByTagName('BODY')[0].innerHTML = responseXML.getElementsByTagName('debug')[0].firstChild.data
document.getElementById("visite").innerHTML = responseXML.getElementsByTagName('visite')[0].firstChild.data
}



//------------------------------------------------------------------------
// Communication with server
//------------------------------------------------------------------------

function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  if (is_ie) {
    // Guaranteed to be ie5 or ie6
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";

    try {
      xmlhttp = new ActiveXObject(control);
      xmlhttp.onreadystatechange = handler;
    } catch (ex) {
      // TODO: better help message
      alert("You need to enable active scripting and activeX controls");  
    }

  } else {

    // Mozilla
    xmlhttp = new XMLHttpRequest();
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;

  }

  return xmlhttp;
}

// XMLHttp send POST request
function XmlHttpPOST(xmlhttp, url, data) {
  try {

    xmlhttp.open("POST", url, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
    xmlhttp.send(data);

  } catch (ex) {
    // do nothing
  }
}

// XMLHttp send GEt request
function XmlHttpGET(xmlhttp, url) {
  try {
    xmlhttp.open("GET", url, true); 
    xmlhttp.send(null);

  } catch (ex) {
    // do nothing
  }
}
function controlla(theForm){
var nomeFr = theForm.name
var txt = ""
var ck = true
var fine = theForm.elements.length 
var x = 0
    do{
        if (theForm.elements[x].getAttribute("req") == "req"){
            
            switch (theForm.elements[x].getAttribute("type")){
            case "text":
                if ((theForm.elements[x].value=="") || (theForm.elements[x].value == theForm.elements[x].getAttribute('placeholder'))){ 
                    txt += "<li>devi compilare il campo " + theForm.elements[x].getAttribute("placeholder") + "</li>";
                   
                    ck =  false;
                }
            break;
                                    
            
        }
    }
    if (theForm.elements[x].getAttribute("ismail") == "ismail"){
        if(!isEmail(theForm.elements[x].value)){
         			txt += "<li>indirizzo e-mail non corretto</li>";
			 ck =  false;
             }
    }
x++;
}
while(x < fine)


 if (!ck) {
	document.getElementById("errori").innerHTML = "<b style='color:red'>Attenzione sono presenti degli errori:</b><ul>" + txt +"</ul>"
 }
  
    return ck
}


