// Pop-up code for case study pop-ups

var myRequest = null;





function CreateXmlHttpReq(handler) {
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
  } catch(e) {
    try {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  xmlhttp.onreadystatechange = handler;
  
  
  
  
  
  return xmlhttp;
}


function myHandler2() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
		
		document.getElementById("contenuto").innerHTML = myRequest.responseText;
    }
	
}
function myHandler3() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
		//alert('Il ticket è stato chiuso');
		window.location.reload();
    }
	
}

function ajax(dove, par) {
    var r = Math.random();
if(par!=""){	
	document.getElementById("contenuto").innerHTML = '<span align="center"><b>Attendere Prego...</b></span>';

    myRequest = CreateXmlHttpReq(myHandler2);

	myRequest.open("GET","function.php?dove="+ dove +"&par="+ par +"&rand="+escape(r));


    myRequest.send(null);
}

}

function facebox_ajax(dove, par) {
    var r = Math.random();
if(par!=""){	
	//document.getElementById("contenuto").innerHTML = '<span align="center"><b>Attendere Prego...</b></span>';

    myRequest = CreateXmlHttpReq(myHandler3);

	myRequest.open("GET","function.php?dove="+ dove +"&id="+ par +"&rand="+escape(r));


    myRequest.send(null);
}

}
function facebox_ajax_bis(dove, par,str) {
    var r = Math.random();
if(par!=""){	
	//document.getElementById("contenuto").innerHTML = '<span align="center"><b>Attendere Prego...</b></span>';

    myRequest = CreateXmlHttpReq(myHandler3);

	myRequest.open("GET","function.php?dove="+ dove +"&id="+ par +"&str="+ str+"rand="+escape(r));


    myRequest.send(null);
}

}


function myHandlerm() {
    if (myRequest.readyState == 4 && myRequest.status == 200) {
		document.getElementById("label_macchine").innerHTML = "Attrezzatura:";
		document.getElementById("macchine").innerHTML = myRequest.responseText;
    }
	
}
	function popola_macchine(utente){
	
    var r = Math.random();
 	document.getElementById("macchine").innerHTML = '<option>Attendere Prego...</option>';

    myRequest = CreateXmlHttpReq(myHandlerm);

	myRequest.open("GET","function.php?dove=elenco_macchine_utente&utente="+utente+"&rand="+escape(r));


    myRequest.send(null);
	
	}
	
	
	function mostra_div(id_div){
		document.getElementById(id_div).style.display = '';
		}

function lunchboxOpen(lunchID) {
document.getElementById(lunchID).style.display = "block";
document.getElementById(lunchID).innerHTML+="<a href=\"javascript:lunchboxClose('" + lunchID + "');\">Nascondi Cronologia</a>";
}
function lunchboxClose(lunchID) {
document.getElementById(lunchID).style.display = "none";
document.getElementById(lunchID).innerHTML="<a href=\"javascript:lunchboxOpen('" + lunchID + "');\">Cronologia Eventi</a>";
} 

function strpos (haystack, needle, offset) {
	var i = (haystack+'').indexOf(needle, (offset ? offset : 0));
    return i === -1 ? false : i;
}



function controlla_data_ricerca(x){
	var re=document.getElementById('anno').value;
	var rem=document.getElementById('mese').value;
//alert(strpos(re,"anno=2"));
	if((x=="mese")&&((strpos(re,"anno=2"))==false)){ 
	alert('Devi selezionare prima l\'anno');
	return false;
	
	}
	
	if( (x=="giorno")&&( (((strpos(rem,"mese=0"))==false)&&((strpos(rem,"mese=1"))==false))||((strpos(re,"anno=2"))==false) ) ){ 
	alert('Devi selezionare prima Anno e mese\n');
	return false;
	
	}

		else{
        return true;   
		
		}
	}


function pp(URL,w,h) {
var iTop=window.screen.height/2-h/2-10;
var iLeft=window.screen.width/2-w/2-10;
var size = "location=no,scrollbars=no,menubars=no,toolbars=no,resizable=no" + ",left=" + iLeft + ",top=" + iTop + ",width=" + w + ",height=" + h;
popup = window.open(URL,"vedilogo",size);
popup.focus();
}

function db_conoscenze(URL,w,h) {
var iTop=window.screen.height/2-h/2-10;
var iLeft=window.screen.width/2-w/2-10;
var size = "location=no,scrollbars=yes,menubars=no,toolbars=no,resizable=no" + ",left=" + iLeft + ",top=" + iTop + ",width=" + w + ",height=" + h;
popup = window.open(URL,"vedilogo",size);
popup.focus();
}


function home() {
if(document.all)
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://wwww.ibsnet.it/servizi_tecnici/');
}


function popup(url) {	
	var winParams = "width=600,height=490,left=0,top=0,toolbar=0,resizable=1,scrollbars=auto,location=0,status=0"
	popwin = window.open(url,"",winParams);
}

function vai_a(dove){
	dove=dove.split(",");
	
//window.open(dove[0]+".php?dove="+ dove[1]+"&id="+dove[2] ,"popo","resizable=yes,scrollbars=yes,width=400 ,height=500" ) 
	window.open("function.php?dove="+ dove[1]+"&id="+dove[2] ,"facebox","resizable=yes,scrollbars=yes,width=400 ,height=500" ) 
}

function controlla_richiesta() {
     // Variabili associate ai campi del modulo
     var descrizione = document.getElementById('descrizione').value;

     //var citta = document.modulo.citta.options[document.modulo.citta.selectedIndex].value;

     // Espressione regolare dell'email
   
        //Effettua il controllo sul campo NOME
        if ((descrizione == "") || (descrizione == "undefined")) {
           alert("Il campo descrizione è obbligatorio.");
           document.getElementById('descrizione').focus();
           return false;
        }

        //INVIA IL MODULO
        else {
			
			var annulla = window.confirm("Sei sicuro di voler inviare questa richiesta?");         
			if (annulla) {
				document.richiesta.action = "utenti.php?dove=invia";
            document.richiesta.submit();
           
        }
        else {
              return annulla;        
        }
			
			

        }
  }


// ----------------------------------------------------------------------
// Verify contact form before submission
// ----------------------------------------------------------------------

// Check those fields
function validateReg() {
	// Pattern for valid e-mail address
    var objRegExp  = /(^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$)/;
    var emailField = document.getElementById('email').value;
  
    // Is the name field blank?
    if (document.getElementById('username').value == "") {
    	alert("Per Favore Scegli uno Username.");
        document.getElementById('username').focus();
		return false;
    } 
	
	else if(document.getElementById('username').value.length<5){ 
		alert('L\'Username deve essere composto da almeno 5 numeri o lettere');
		 document.getElementById('username').focus();
		return false;
	}
	//else if(document.getElementById('username').value != ""){
			//if(!ajax("controlla_username",document.getElementById('username').value)) return false;
						
		//}
	else if (document.getElementById('nome').value == "") {
    	alert("Per favore inserisci il tuo nome.");
        document.getElementById('nome').focus();
        return false;
    }
    else if (document.getElementById('cognome').value == "") {
    	alert("Per favore inserisci il tuo cognome.");
        document.getElementById('cognome').focus();
        return false;
    }   
    // Is the email field blank?
    else if ((document.getElementById('email').value == "")&&(document.getElementById('telefono').value == "")) {
    	alert("E' necessario inserire un indirizzo email o un numero telefonico al quale potremo comunicare la password di accesso al sistema.");
        document.getElementById('email').focus();
        return false;
    }
    // Check if the email is valid
    else if(document.getElementById('email').value != ""){
		if(!objRegExp.test(emailField)) {
		alert("Per favore inserisci un indirizzo email valido.");
        document.getElementById('email').focus();
		return false;
		}
	}
	
	else {
        return true;
    }
}





// ----------------------------------------------------------------------
// Make cursor style of same-page links "default"
// ----------------------------------------------------------------------

function f () {
	return false;
}

// Check links against current URL
function checkForCurrentLinks() {
	var hrefs = document.getElementsByTagName("a");	
	for (var i = 0; i < hrefs.length; i ++)
	try {
		if (hrefs[i].href == location.href) {
			hrefs[i].style.cursor = "default";
			hrefs[i].onclick = f;
		}
	}
	catch(e){}
 }


// ----------------------------------------------------------------------
// Toggle DIV view on and off
// ----------------------------------------------------------------------

function toggle(curId,newId) {
	if (document.getElementById) {
		if (document.getElementById(curId).style.display == '') {
			document.getElementById(curId).style.display = 'none';
			document.getElementById(newId).style.display = '';
		}
	} else {
		return;
	}
}

function toggleViz(objId) {
	if (document.getElementById) {
		if (document.getElementById(objId).style.display == '') {
			document.getElementById(objId).style.display = 'none';
		} else {
			document.getElementById(objId).style.display = '';
		}
	} else {
		return;
	}
}

function set_cookie_step(str){
	 var today = new Date();
 var expire = new Date();
 
 expire.setTime(today.getTime() + 3600000*24*365);//il cookie dura un anno
 document.cookie = "PerPagina="+escape(str)+ ";expires="+expire.toGMTString();
 location.reload();
	}
	
	function makeurl(url, par){
		
		var qst=location.search.substr(1);
var dati = new Array()
var i;
var querystring;
dati=qst.split("&");
for(i=0;i<15;i++){
	
	if(typeof(dati[i])==undefined)
	querystring=querystring;
	else
	querystring+=dati[i]+"&";
	
	}
	window.top.location=url+"?"+querystring+"&"+par;
//window.top.location=url+"?"+dati[0]+"&"+dati[1]+"&"+dati[2]+"&"+dati[3]+"&"+dati[4]+"&"+dati[5]+"&"+dati[6]+"&"+par;

alert('11');
}

function prova2(){
	var GETDATA = new Array();

// Get the string that follows the "?" in the window's location.
var sGet = window.location.search;
if (sGet) // if has a value...
{
    // Drop the leading "?"
    sGet = sGet.substr(1);
    
    // Generate a string array of the name value pairs.
    // Each array element will have the form "foo=bar"
    var sNVPairs = sGet.split("&");
    
    // Now, for each name-value pair, we need to extract
    // the name and value.
    for (var i = 0; i < sNVPairs.length; i++)
    {
        // So, sNVPairs[i] contains the current element...
        // Split it at the equals sign.
        var sNV = sNVPairs[i].split("=");
        
        // Assign the pair to the GETDATA array.
        var sName = sNV[0];
        var sValue = sNV[1];
        GETDATA[sName] = sValue;
		alert(sName);
    }
}

// Finally, assign the value to foo.

	
	}
	
function prova(url, par){
	var str = window.location.search.substr(1);
  var param = str.split(/\&/);
  var qstr="";
  var nom_val ;
  for(var i=0; i<param.length; i++) {
    nom_val = param[i].split(/\=/);
    //alert("nome="+nom_val[0]+"  valore="+nom_val[1]);
	 qstr=qstr+nomi_val;
  }
  
  alert(qstr);
  //alert(nom_val.toString())
  	//window.top.location=url+"?"+querystring+"&"+par;
}

function passa(url, valore){
	
	location=url+valore;
	//alert(url+valore);
	}

