var currentPage = 'news';
var sections = new Array('project','prenatal','architecture','contacts');
function showHide2(show){	
	window.document.getElementById(currentPage).style.display="none";
	window.document.getElementById(show).style.display="block";
	currentPage = show;
}
function starter(){
	for (var i=0;i<sections.length;i++){
		window.document.getElementById(sections[i]).style.display="none";
	}
}
// GLOBAL FUNCTION
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function myshowHide(show,hide){
	document.getElementById(show).style.display="block";
	document.getElementById(hide).style.display="none";
}

//STYLE SWITCHER
function showHide(show,hide){
	if(show=="flash" && GetCookie("flashPulgin")=="false"){
		str_msg_confirm="Per visualizzare la versione originale del sito di CULT hai bisogno del plug-in Macromedia FlashPlayer 7. \nOK PER SCARICARE FLASH PLAYER 7 ";
		res=window.confirm(str_msg_confirm);
		if(res){
			RemoveCookie("show");
			RemoveCookie("hide");
			RemoveCookie("flashPulgin");
			window.location.href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
		}
	} else {
		document.getElementById(show).style.display="block";
		//alert(document.getElementById(show).style.display);
		document.getElementById(hide).style.display="none";
		//alert(document.getElementById(hide).style.display);
		var expdate = new Date();
		expdate.setTime(expdate.getTime() +  (24 * 60 * 60 * 1000 * 365)); 
		SetCookie("show", show, expdate, "/", null, false);
		SetCookie("hide", hide, expdate, "/", null, false);
	}
}

function showHideAndSwap(show,hide,pagina) {
	showHide(show,hide);
	window.location.href=pagina;
} 

function SetCookie(name, value){
   var argv = SetCookie.arguments;
   var argc = SetCookie.arguments.length;
   var expires = (2 < argc) ? argv[2] : null;
   var path = (3 < argc) ? argv[3] : null;
   var domain = (4 < argc) ? argv[4] : null;
   var secure = (5 < argc) ? argv[5] : false;
   document.cookie = name + "=" + escape (value) + ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
}

function GetCookie(name){
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen){
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return getCookieVal(j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) 
			break; 
	}
	return null;
}

function getCookieVal(offset){
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}

function RemoveCookie(name){
	document.cookie = name+"=; path=/";	
}

//FLASH RESIZER
/*function chkW(a) {
	if (a<=900) {
		var tmp = "900";
	} else {
		var tmp = "100%";
	}
	return tmp;
}

function chkH(a) {
	if (a<=575) {
		var tmp = "575";
	} else {
		var tmp = "100%";
	}
	return tmp;
}

function alertSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth ||document.documentElement.clientHeight ) ) {
		myWidth = document.documentElement.clientWidth;
		myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		myWidth = document.body.clientWidth;
		myHeight = document.body.clientHeight;
	}
	if(myWidthOLD != myWidth || myHeightOLD != myHeight) {
		flashResizer(chkW(myWidth),chkH(myHeight));
	}
	myWidthOLD = myWidth;
	myHeightOLD = myHeight;
}
*/
function flashResizer(w,h){
	document.getElementById("flashobj").width=w;
	if (h != "100%"){
		h = h+"px";
	}
	document.getElementById("flashobj").style.height=h;
	document.getElementsByTagName("body")[0].style.height=h;
}

//CHECK PLUG-IN
function flashIsRunning(){
	flashRun=true;
	//alertSize();
}

function flash_is_load(){
	cont++;
	if(cont>50 || flashRun!=0){
		clearInterval(tempo);
		if(flashRun){
			SetCookie("flashPulgin", "true", null, "/", null, false);
		}else{
			SetCookie("flashPulgin", "false", null, "/", null, false);
			showHide('acc','flash');
		}
	}
}

var lsBrowser = navigator.appName;
var navInfo = navigator.userAgent;
var intervallo=100;
var cont=0;
var tempo=0;
var flashRun=0;
var myShow;
var myHide;
var myWidthOLD;
var myHeightOLD;

window.onresize = function(){
	if(GetCookie("show")=='flash'){
	//	alert("resize");
		//alertSize();
	}
}

window.onload = function(){
	starter();
	//MM_preloadImages('/_images/logoCult_f2.gif','/_images/logoSky_f2.gif');
	myShow=GetCookie("show");
	myHide=GetCookie("hide");
	if(myShow!=null && myShow!=''){
		showHide(myShow,myHide);
	}else{
		showHide('flash','acc');
		tempo = setInterval('flash_is_load()', intervallo);		
	}	
	//alertSize();
}

function checkData()
{

	mf=document.register;

	tmp = mf.nick.value;
	if(tmp.length < 1)
	{	alert("Inserisci il Nickname.");
		mf.nick.focus();
		return false;
	};

	if(tmp.length > 12 || tmp.length < 4 )
	{	alert("Inserisci un Nickname compreso tra i 4 e i 12 caratteri.");
		mf.nick.focus();
		return false;
	};

// email control
	if(window.RegExp)
	{
		var rexp=new RegExp("^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.([a-zA-Z]){2,4})$");
		if(!rexp.test(mf.email.value)) 
		{
			alert("L\'e-mail deve avere questo formato: username@dominio.it \r\n\""+mf.email.value+"\" non è un indirizzo valido. Verificalo e prova di nuovo.");
			mf.email.focus();
			return false;
		};
	}else
	{
		if(!(mf.email.value.indexOf("@") > 0))
		{
			alert("L\'e-mail deve avere questo formato: username@do.ma.in \r\n'"+mf.email.value+"' non è un indirizzo valido. Verificalo e prova di nuovo.");
			mf.email.focus();
	      	return false;
		}
	}

	tmp = mf.nome.value;
	if(tmp.length < 1)
	{	alert("Inserisci il Nome");
		mf.nome.focus();
		return false;
	};


	tmp = mf.cognome.value;
	if(tmp.length < 1)
	{	alert("Inserisci il Cognome");
		mf.cognome.focus();
		return false;
	};
	

//  return true if the input date is valid, false otherwise
	day = mf.gg.value;
	month = mf.mm.value-1; //The month needs to be a 0 (zero) for Jan, up to 11 to Dec.
	year = mf.aaaa.value;

	dteDate=new Date(year,month,day);

	if (!((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear())))
	{
		alert("Inserisci una data valida.");
		mf.gg.focus();
		return false;

	};
	
	tmp = mf.citta.value;
	if(tmp.length < 1)
	{	alert("Inserisci la Citta'.");
		mf.citta.focus();
		return false;
	};	

	tmp = mf.prov;
	if(tmp.selectedIndex==0)
	{	alert("Seleziona la Provincia.");
		mf.prov.focus();
		return false;
	};	
	
	if(!mf.sesso[0].checked && !mf.sesso[1].checked){
		alert("Specifica il Sesso.");
		mf.sesso[0].focus();
		return false;
	};
	
	if(!mf.abbonato[0].checked && !mf.abbonato[1].checked){
		alert("Specifica se sei Abbonato.");
		mf.abbonato[0].focus();
		return false;
	};

	if(!mf.consenso[0].checked){
		alert("Per registrarti devi aderire alle condizioni di trattamento dei dati personali.");
		mf.consenso[0].focus();
		return false;
	};
	return true;
}

function checkDataEdit(){

	mf=document.register;

	tmp = mf.passwd.value;
	tmp2 = mf.passwd2.value;
	if(tmp.length > 0){
		if(tmp.length > 12 || tmp.length < 4 ){
			alert("Inserisci una Password compresa tra i 4 e i 12 caratteri.");
			return false;
		}else{		
			if(tmp!=tmp2){
				alert("Verifica che la password fornita coincida con la password di conferma.");
				return false;
			}
		}
	}

// email control
	if(window.RegExp){
		var rexp=new RegExp("^[_a-zA-Z0-9-]+(\\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*(\\.([a-zA-Z]){2,4})$");
		if(!rexp.test(mf.email.value)){
			alert("L\'e-mail deve avere questo formato: username@dominio.it \r\n\""+mf.email.value+"\" non è un indirizzo valido. Verificalo e prova di nuovo.");
			mf.email.focus();
			return false;
		}
	}else{
		if(!(mf.email.value.indexOf("@") > 0)){
			alert("L\'e-mail deve avere questo formato: username@dominio.it \r\n'"+mf.email.value+"' non è un indirizzo valido. Verificalo e prova di nuovo.");
			mf.email.focus();
	      		return false;
		}
	}

	tmp = mf.nome.value;
	if(tmp.length < 1){
		alert("Inserisci il Nome");
		mf.nome.focus();
		return false;
	}


	tmp = mf.cognome.value;
	if(tmp.length < 1){
		alert("Inserisci il Cognome");
		mf.cognome.focus();
		return false;
	}
	

//  return true if the input date is valid, false otherwise
	day = mf.gg.value;
	month = mf.mm.value-1; //The month needs to be a 0 (zero) for Jan, up to 11 to Dec.
	year = mf.aaaa.value;

	dteDate=new Date(year,month,day);

	if (!((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()))){
		alert("Inserisci una data valida.");
		mf.gg.focus();
		return false;
	}
	
	tmp = mf.citta.value;
	if(tmp.length < 1){
		alert("Inserisci la Citta'.");
		mf.citta.focus();
		return false;
	}	

	/*tmp = mf.prov;
	if(tmp.selectedIndex==0){
		alert("Seleziona la Provincia.");
		mf.prov.focus();
		return false;
	}*/	
	
	if(!mf.sesso[0].checked && !mf.sesso[1].checked){
		alert("Specifica il Sesso.");
		mf.sesso[0].focus();
		return false;
	}
	
	if(!mf.abbonato[0].checked && !mf.abbonato[1].checked){
		alert("Specifica se sei Abbonato.");
		mf.abbonato[0].focus();
		return false;
	}
	return true;
}

function checkMsg(){
	if(document.posta.commento.value.length <= 1){
		alert("Inserisci il testo del commento.");
		return false;
	}else{
		return true;
	}
}

function checkOut(Obj){
	if(Obj.options[Obj.selectedIndex].value!="17"){
		document.getElementById("divtestata").style.display="none";
	}else{
		document.getElementById("divtestata").style.display="block";		
	}
}