function act(name,img){	
	var myimg=eval("window.document."+img);
	if(window.document.getElementById(name).style.display!="none"){
		window.document.getElementById(name).style.display="none";
		myimg.src='/2006/images/folder_f2.gif';
	}else{
	window.document.getElementById(name).style.display="block";
		myimg.src='/2006/images/folder_f2.gif';
	}
}
function showHide(name){	
	if(window.document.getElementById(name).style.display!="none"){
		window.document.getElementById(name).style.display="none";
	}else{
		window.document.getElementById(name).style.display="block";
	}
}
function getCookieVal(offset){
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
	  
   return unescape(document.cookie.substring(offset, endstr));
}
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 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 chkpage(loc,pag){
	chkres=0;
	loc=loc.toLowerCase();
	pag=pag.toLowerCase();
	//lingua=lingua.toLowerCase();
	if (pag.indexOf("/it/") != -1 || pag.indexOf("/en/") != -1){
		chkres="http://edizioni.fotografiafestival.it"+pag;
	//} else if (pag.indexOf("/en/") != -1){
		//chkres="http://edizioni.fotografiafestival.it"+pag.replace("/en/","/it/") ;
	} else {
		chkres="http://edizioni.fotografiafestival.it/";
	}
	return chkres;
}

function setActiveStyleSheetAndSwap(title,pagina) {
//	alert("pagina:"+pagina+"\ncss:"+title+"\nlng:"+lng);
// verifico se devo fare una redirezione
	var ridirez=chkpage(window.location.href,pagina);
	SetCookie("style", title, null, "/", null, false);
	if(ridirez!=0){
		window.location.href=ridirez;
	}else{
		fc_setStyle(title);
	}
} 
function setActiveStyleSheetFlash(title) {
//	var pagina=window.location.href.substring(window.location.href.lastIndexOf("/")+1);
	var pagina=window.location.href;
	pagina = pagina.replace("http://edizioni.fotografiafestival.it","")
//	alert("pagina:"+pagina+"\ncss:"+title+"\nlng:"+lng);
	setActiveStyleSheetAndSwap(title,pagina)
}
function disabledStyleSheet(title) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
}

function fc_setStyle(st){
//	alert("pagina:"+st);
	if(st==null || st=="" || st=="empty.css"){
		disabledStyleSheet('alternativo');
	//	document.getElementsByTagName("link")[0].href="empty.css";
		//st="empty.css";
	}else{
//	if(window.location.href.indexOf("/2006/")>0 && st=='flash.css'){
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = false;
			}
		}
		if(st=='flash.css'){
			document.getElementById("acc").style.display="none";
			document.getElementById("flash").style.display="block";
		//	document.getElementById("flashobj").style.height="576px";
			//document.getElementsByTagName("link")[0].href="/2006/_css/" + st;
		}else if(st=='acc.css'){
			document.getElementById("flash").style.display="none";
			document.getElementById("acc").style.display="block";
		//	document.getElementById("flashobj").style.height="0px";
			//document.getElementsByTagName("link")[0].href="/2006/_css/" + st;
		}
	//else{
		//document.getElementsByTagName("link")[0].href="/2006/_css/" + st;
	//}
		
	}
}

function setActiveStyleSheet(title) {
//	alert(GetCookie("flash"));
	if(title=='flash.css' && GetCookie("flash")=="false"){
			str_msg_confirm="Per visualizzare la versione originale del sito del Festival di FotoGrafia hai bisogno del plug-in Macromedia FlashPlayer 7. \nOK PER SCARICARE FLASH PLAYER 7 ";
			res=window.confirm(str_msg_confirm);
			if(res){
				window.location.href="http://www.macromedia.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
			}
	}else if(title=='' || title==null){
		fc_setStyle("empty.css");
		SetCookie("style", "empty.css", null, "/", null, false);		
	}else{
		fc_setStyle(title);
		SetCookie("style", title, null, "/", null, false);
	}
}

function isExplorer(){
	if (navigator.userAgent && navigator.userAgent.indexOf("MSIE")>=0 && (navigator.appVersion.indexOf("Win") != -1)) {
	// 	document.flashobj.SetVariable('_root.strBR','explorer');
		document.getElementById("flashobj").SetVariable("_root.strBR","explorer");
	}else{
		strBR='';
	//  document.flashobj.SetVariable('_root.strBR','altro');
		document.getElementById("flashobj").SetVariable("_root.strBR","altro");
	}
}

function key_control(){
	if(window.event.keyCode==13){
		setActiveStyleSheet(); return false;
	}
}
function key_control_flash(){
	if(window.event.keyCode==13){
	setActiveStyleSheet('flash.css'); return false;
	}
}
function key_control_acc(){
	if(window.event.keyCode==13){
	setActiveStyleSheet('acc.css'); return false;
	}
}
		
function popupwindowNoScroll(LarghezzaWindow,AltezzaWindow,Pagina) {
	
	var iMyWidth;
	var iMyHeight;
	var LarghezzaPagina;
	var AltezzaPagina;
	
	LarghezzaPagina = screen.availWidth;
	AltezzaPagina = screen.availHeight;

	LarghezzaWindow=LarghezzaWindow.toUpperCase()
	AltezzaWindow=AltezzaWindow.toUpperCase()	

	if (LarghezzaWindow == "FULL") {
			LarghezzaWindow = screen.availWidth;
		}
	if (AltezzaWindow == "FULL") {
			AltezzaWindow = screen.availHeight;
		}
	iMyWidth = (LarghezzaPagina/2) - (LarghezzaWindow/2); 
	iMyHeight = (AltezzaPagina/2) - (AltezzaWindow/2);
	win = window.open(Pagina,"","height=" + (AltezzaWindow - 30) + ",width=" + (LarghezzaWindow - 10) + ",menubar=0,resizable=no,scrollbars=no,status=0,titlebar=0,toolbar=0,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + "");
	win.focus();
}

function uploadFile(variabile,formato){
	popupwindowNoScroll('300','100','/2006/_asp/file.asp?fvar=' + variabile);
}
function verificaUpload(){
	err="";
	nfile1=window.document.form1.inputFile1.value;
	nfile2=window.document.form1.inputFile2.value;
	if(window.document.form1.formnome.value==''){
		err+="-NOME\n";
	}
	if(window.document.form1.formcognnome.value==''){
		err+="-COGNOME\n";
	}
	if(window.document.form1.formemail.value==''){
		err+="-EMAIL\n";
	}
	if(nfile1.substr((nfile1.lastIndexOf('.')+1)).toUpperCase()!='JPG'){
		err+="-FOTO 1\n";
	}	
	if(nfile2.substr((nfile2.lastIndexOf('.')+1)).toUpperCase()!='JPG'){
		err+="-FOTO 2\n";
	}	
	if(window.document.form1.formprivacy.checked!=true){
		err+="-REGOLAMENTO\n";
	}
	if(err!=""){
		alert("I Campi:\n"+err+"\nsono obbligatori.");
		return false;
	}else{
		return true;
	}
}
