// Pop-up code for case study pop-ups

var myRequest = null;
function CreateXmlHttpReq(handler) {
  var agt = navigator.userAgent.toLowerCase();
  var is_ie5 = (agt.indexOf('msie 5') != -1);
  var xmlhttp = null;
  try {
    xmlhttp = new XMLHttpRequest();
    try {
        // Fix for some version of Mozilla browser.
        http_request.overrideMimeType('text/xml');
    } catch(e) { }
    xmlhttp.onload = handler;
    xmlhttp.onerror = handler;
  } catch(e) {
    var control = (is_ie5) ? "Microsoft.XMLHTTP" : "Msxml2.XMLHTTP";
    xmlhttp = new ActiveXObject(control);
    xmlhttp.onreadystatechange = handler;
  }
  
  return xmlhttp;
}


function myHandler2() {


    if (myRequest.readyState == 4 && myRequest.status == 200) {
        document.getElementById("contenuto").innerHTML = myRequest.responseText;
    }
}

function esempio4(p) {
    var r = Math.random();
	
	document.getElementById("contenuto").innerHTML = '<div align="center"><br /><br /><br /><b>Attendere Prego...</b></div>';

    myRequest = CreateXmlHttpReq(myHandler2);
if(p<10)
	myRequest.open("GET","show.php?p="+escape(p)+"&rand="+escape(r));
	else
	myRequest.open("GET","mailing_list.php"+"?rand="+escape(r));


    myRequest.send(null);
}


function validate()
{
    if ((document.invia_mail.nome.value=="")||(document.invia_mail.email.value==""))
	{
		alert ("Attenzione!\nRiempire i campi obbligatori.")
		return false
	}
	
	 if (document.invia_mail.email.value!=""){
	   EmailAddr = document.invia_mail.email.value;
   Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
   if (Filtro.test(EmailAddr))
      return true;
   else
      {
      alert("Controlla l'indirizzo di e-mail inserito");
      document.invia_mail.email.focus();
      return false;
      }
	}
}


function mostra_menu(tipo){
	if(tipo=="fiscale") 	{
		document.getElementById("menu_cont").innerHTML=('<div style="padding-right:145px"><a href="servizi.php">Servizi Offerti</a><a href="risorse.php">News Fiscali</a><a href="risorse.php">Gazzetta Uffficiale</a> </div> ');
	
	}
	if(tipo=="legale") 	{
		document.getElementById("menu_cont").innerHTML=('<div style="padding-right:44px"><a href="servizi.php">Servizi Offerti</a><a href="risorse.php">News Legali</a></div> ');
	}
	
	//alert(document.location );
}




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 pp(w,y) 
{ 
window.open('','popo',"resizable=no,scrollbars=yes,width="+ w +" ,height="+ y ) 
} 

function home() {
if(document.all)
document.body.style.behavior='url(#default#homepage)';
document.body.setHomePage('http://wwww.studioviglionelibretti.it');
}


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);
}


// ----------------------------------------------------------------------
// Verify contact form before submission
// ----------------------------------------------------------------------

// Check those fields
function validateContactInfo() {
	// 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('contact[email]').value;
    
    // Is the name field blank?
    if (document.getElementById('contact[name]').value == "") {
    	alert("Per Favore Inserisci il Tuo Nome.");
        document.getElementById('contact[name]').focus();
        return false;
    }
    // Is the email field blank?
    else if (document.getElementById('contact[email]').value == "") {
    	alert("Per Favore inserisci il tuo indirizzo eMail.");
        document.getElementById('contact[email]').focus();
        return false;
    }
    // Check if the email is valid
    else if(!objRegExp.test(emailField)) {
		alert("Per favore inserisci un indirizzo email valido.");
        document.getElementById('contact[email]').focus();
		return false;
	}
    // Is the subject field blank?
    else if (document.getElementById('contact[subject]').value == "") {
    	alert("Scegli un soggetto per il tuo messaggio.");
        document.getElementById('contact[subject]').focus();
        return false;
    }
    // Is there any text in the message?   
    else if (document.getElementById('contact[message]').value == "") {
    	alert("Scrivi il tuo messaggio nel campo apposito.");
        document.getElementById('contact[message]').focus();
        return false;
    }
	// Otherwise allow the form to be submitted
	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 getCookie(name) 
{
	var dc = document.cookie;
	var prefix = name + "=";
	 //alert(dc)
	var begin = dc.indexOf("; " + prefix);
	if (begin == -1) 
	{
		begin = dc.indexOf(prefix);
		if (begin != 0) return null;
	} 
	else
	{
		begin += 2;
	}
	var end = document.cookie.indexOf(";", begin);
	if (end == -1)
	{
		end = dc.length;
	}
	return unescape(dc.substring(begin + prefix.length, end));
}

function setCookie(name,value,expires,path)//,domain)//,secure) 
{
	var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : ""); /*+
      ((domain) ? "; domain=" + domain : ""); +
      ((secure) ? "; secure" : "")*/
    // alert(curCookie)
	document.cookie = curCookie;
}

function delCookie(name)
{
	var today = new Date();
	var expired = new Date(today.getTime() - 48 * 60 * 60 * 1000);
	var curCookie = name + "=null; expires=" + expired.toGMTString();
	document.cookie = curCookie;
}

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();
	}
