var travelList = [];

function hideShowSingleTravelFields(mode,i){
	if(mode=='Both' || mode=='Flyght'){
	//mostra tutti
		document.getElementById('travel'+i).style.display='block';	
		document.getElementById('travel2'+i).style.display='block';			
		document.getElementById('citta'+i).disabled=false;
		document.getElementById('stato'+i).disabled=false;
		document.getElementById('arrivo'+i).disabled=false;
		document.getElementById('partenza'+i).disabled=false;
	}else if(mode=='Accomodation'){
	//mostra solo data arrivo e partenza	
		document.getElementById('travel'+i).style.display='none';	
		document.getElementById('travel2'+i).style.display='block';			
		document.getElementById('citta'+i).disabled=true;
		document.getElementById('stato'+i).disabled=true;
		document.getElementById('arrivo'+i).disabled=false;
		document.getElementById('partenza'+i).disabled=false;	
	}else{
	//nascondi tutti
		document.getElementById('travel'+i).style.display='none';	
		document.getElementById('travel2'+i).style.display='none';			
		document.getElementById('citta'+i).disabled=true;
		document.getElementById('stato'+i).disabled=true;
		document.getElementById('arrivo'+i).disabled=true;
		document.getElementById('partenza'+i).disabled=true;
	}
}

function writeSnapshotListOk(id,id_file){
	//AJAX 
	window.location.href="/_php/snapshotSave.php?id="+id;
	//SUCCESS setContentLoader(trgt,cnt)
}
function writeSnapshotPerfListOk(id,id_file){
	//AJAX 
window.location.href="/_php/snapshotPerfSave.php?id="+id_file;
	//SUCCESS setContentLoader(trgt,cnt)
}
var oldForm;
var arrayLng = ['it','en'];
//var arrayLng = ['it','en','es','fr','pl'];

if (window.XMLHttpRequest) // try to create XMLHttpRequest
	rateRequestObject = new XMLHttpRequest();

if (window.ActiveXObject)	// if ActiveXObject use the Microsoft.XMLHTTP
	rateRequestObject = new ActiveXObject("Microsoft.XMLHTTP");


function loadPerformanceComplete(){
	if (rateRequestObject.readyState==4) {
		if (rateRequestObject.responseText.indexOf('invalid') == -1) { 	
			document.getElementById("perfPeriodList").innerHTML=rateRequestObject.responseText;
			ha_votato=false;			
		}else {
			alert("Error!\nTry Again.");
		}
	}	
}
function loadPerformance(m,y){
	ha_votato=true;
	rateRequestObject.open("GET", "/_php/perfList.php?m="+m+"&y="+y , true);
	rateRequestObject.onreadystatechange = loadPerformanceComplete;
	rateRequestObject.send(null); 
}


function passFocus(trgt) { //v3.0
	if(trgt.value=='password') {
		trgt.value='';
	}
	if(trgt.type=='text') {
		trgt.type = 'password';
	}
}
function showHide(id1,id2) { //v3.0
	window.document.getElementById(id1).style.display="block";
	if (id2!=undefined){
		window.document.getElementById(id2).style.display="none";
	}
}
function showHideInline(show,hide){
	window.document.getElementById(show).style.display="inline";			
	window.document.getElementById(hide).style.display="none";							
}
function showHideSwap(showhide){
	if (window.document.getElementById(showhide).style.display=="none") {
		window.document.getElementById(showhide).style.display="block";			
	} else {
		window.document.getElementById(showhide).style.display="none";			
	}
}
function ShowHideLngDiv(lng){
	window.document.getElementById("blocco_"+lng).style.display="block";			
	for(var i=0; i<elencoBlocchi.length; i++){
		if(elencoBlocchi[i]!="blocco_"+lng){
			window.document.getElementById(elencoBlocchi[i]).style.display="none";			
		}		
	}
}
function showForm(id1) { //v3.0
	if(id1!=""){
		window.document.getElementById(id1).style.display="block";
		if (oldForm){
			window.document.getElementById(oldForm).style.display="none";
		}
		oldForm = id1;
		window.document.getElementById("formUpload").style.display="block";
		for(i=0;i<document.getElementsByName('tipofile').length;i++){
			document.getElementsByName('tipofile')[i].checked=false;
		}		
	}	
}

function showTextLng(lng){
	setSessionCompliteFnc="changeLngDiv";
	setSessionCompliteParam=lng;		
	setSession("lng",lng);
}

function changeLngDiv(lng){
     if(lng!=''){
        window.document.getElementById("blocco_"+lng).style.display="block";
        for(var i=0; i<arrayLng.length; i++){
            if(arrayLng[i]!=lng){
                window.document.getElementById("blocco_"+arrayLng[i]).style.display="none";			
            }		
        }
	}
}


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_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

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 popupwindow(LarghezzaCont,AltezzaCont,Pagina,nome,scrol,stat) {
	var lsBrowser = navigator.appName;
	var navInfo = navigator.userAgent;
	if (scrol == "yes") {
		if (navInfo == "Mac" && lsBrowser.indexOf("Microsoft") >= 0) {
				aw = 0;
		} else {
		aw = 17;
		}		
	} else {
	aw = 0;
	}		
    var iMyWidth;
    var iMyHeight;
    var LarghezzaPagina;
    var AltezzaPagina;
    LarghezzaPagina = screen.availWidth;
    AltezzaPagina = screen.availHeight;
    LarghezzaCont=LarghezzaCont.toUpperCase()
    AltezzaCont=AltezzaCont.toUpperCase()
    if (LarghezzaCont == "FULL") {
            LarghezzaWindow = screen.availWidth;
        } else {
            LarghezzaWindow = parseInt(LarghezzaCont) + aw;
        }
    if (AltezzaCont == "FULL") {
            AltezzaWindow = screen.availHeight;
        } else {
            AltezzaWindow = AltezzaCont;
        }
    iMyWidth = (LarghezzaPagina/2) - (LarghezzaWindow/2);
    iMyHeight = (AltezzaPagina/2) - (AltezzaWindow/2);
    win = window.open(Pagina,nome,"height=" + AltezzaWindow + ",width="	+ LarghezzaWindow 
	+ ",menubar=0,resizable=0,scrollbars=" + scrol + ",status=" + stat + ",titlebar=0,toolbar=0,left="
	+ iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + "");
    win.focus();
}

/* ajax functions */
var xmlRequestObject = false; // XMLHttpRequest Object
var setSessionCompliteFnc="";
var setSessionCompliteParam="";

if (window.XMLHttpRequest) // try to create XMLHttpRequest
	xmlRequestObject = new XMLHttpRequest();
if (window.ActiveXObject && !(navigator.userAgent.indexOf("MSIE")!=-1 && navigator.userAgent.indexOf("Mac")!=-1 && navigator.appVersion.indexOf("MSIE 5")!=-1) )// if ActiveXObject use the Microsoft.XMLHTTP
	xmlRequestObject = new ActiveXObject("Microsoft.XMLHTTP");

function setSession(name,value){
	if(xmlRequestObject){
		xmlRequestObject.open("GET", "/_php/setSession.php?"+name+"="+value , true);
		xmlRequestObject.onreadystatechange = setSessionComplite;
		xmlRequestObject.send(null);
	}	
}

function setSessionComplite(){
	if (xmlRequestObject.readyState==4) {
		if (xmlRequestObject.responseText.indexOf('invalid') == -1){
				eval(setSessionCompliteFnc)(setSessionCompliteParam);
		}
	}	
}

function checkCrewDataEdit(){
    mf = document.register;
	tmp = mf.nick.value;
	if (tmp.length<1) {
		alert("Crewname is required.");
		mf.nick.focus();
		return false;
	}
    var corretct_uname=isValidName(tmp);
    if(corretct_uname!=tmp){
   		alert("invalid Crewname "+tmp+"\nuse "+corretct_uname+" instead.\n\nonly alpha numeric characters \nonly - _ symbols are allowed \nname must start and end with letter or number"); 
    	return false;
    }   
   	tmp = mf.nomearte.value;
   	if (tmp.length<1) {
		alert("Nick name is required.");
		mf.nomearte.focus();
		return false;
	}         
/*
	tmp = mf.citta.value;
	if (tmp.length<1) {
		alert("City is required.");
		mf.citta.focus();
		return false;
	}
	tmp = mf.stato;
	if (tmp.selectedIndex == 0) {
		alert("Country is required.");
		mf.stato.focus();
		return false;
	}
*/        
	return true;
}
function checkCrewData(){
	mf = document.register;
	tmp = mf.nick.value;
	if (tmp.length<1) {
		alert("Crewname is required.");
		mf.nick.focus();
		return false;
	}
    var corretct_uname=isValidName(tmp);
    if(corretct_uname!=tmp){
   		alert("invalid Crewname "+tmp+"\nuse "+corretct_uname+" instead.\n\nonly alpha numeric characters \nonly - _ symbols are allowed \nname must start and end with letter or number"); 
    	return false;
    }
   	tmp = mf.nomearte.value;
   	if (tmp.length<1) {
		alert("Nick name is required.");
		mf.nomearte.focus();
		return false;
	}     
    
/*
	tmp = mf.citta.value;
	if (tmp.length<1) {
		alert("City is required.");
		mf.citta.focus();
		return false;
	}
	tmp = mf.stato;
	if (tmp.selectedIndex == 0) {
		alert("Country is required.");
		mf.stato.focus();
		return false;
	}
*/    
	if (!mf.consenso[0].checked) {
		alert("You have to accept privacy policy.");
		mf.consenso[0].focus();
		return false;
	}
	return true;
}
function checkPerfDataEdit(){
	mf = document.register;
	tmp = mf.perf_name.value;
	if (tmp.length<1) {
		alert("Performance name is required.");
		mf.perf_name.focus();
		return false;
	}
	tmp = mf.duration.value;
	if (tmp.length<1) {
		alert("Duration is required.");
		mf.duration.focus();
		return false;
	}
	tmp = mf.chiavi;
	if (tmp.selectedIndex == 0) {
		alert("Typology is required.");
		mf.chiavi.focus();
		return false;
	}
	return true;
}

function checkPerfData(){
	mf = document.register;
	tmp = mf.perf_name.value;
	if (tmp.length<1) {
		alert("Performance name is required.");
		mf.perf_name.focus();
		return false;
	}
	tmp = mf.duration.value;
	if (tmp.length<1) {
		alert("Duration is required.");
		mf.duration.focus();
		return false;
	}
	tmp = mf.chiavi;
	if (tmp.selectedIndex == 0) {
		alert("Typology is required.");
		mf.chiavi.focus();
		return false;
	}
	return true;
}
function checkDataEdit(){
	mf = document.register;
	tmp = mf.nome.value;
	if (tmp.length<1) {
		alert("Name is required.");
		mf.nome.focus();
		return false;
	}
	tmp = mf.cognome.value;
	if (tmp.length<1) {
		alert("Surname is required.");
		mf.cognome.focus();
		return false;
	}
 	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("Birtdate not valid.");
		mf.gg.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("The e-mail format has to be: username@domain.com \r\n'"+mf.email.value+"' is not a valid email.");
			mf.email.focus();
			return false;
		}
	} else {
		if (!(mf.email.value.indexOf("@")>0)) {
			alert("The e-mail format has to be: username@domain.com \r\n'"+mf.email.value+"' is not a valid email.");
			mf.email.focus();
			return false;
		}
	}	
	//lingua
	tmp = mf.lingua;
	if (tmp.selectedIndex == 0) {
		alert("Language is required.");
		mf.lingua.focus();
		return false;
	}
    //pass
	if (mf.passwd.value.length>1) {
        tmp = mf.passwdConfirm.value;
        if (tmp.length<1) {
            alert("Password confirm is required.");
            mf.passwdConfirm.focus();
            return false;
        }else{
            if(mf.passwd.value!=mf.passwdConfirm.value){
                alert("Password confirm doesnt match Password.");
                mf.passwd.focus();
                return false;
            }    
		}
	}
	//username
   	tmp = mf.User_login.value;
   	if (tmp.length<1) {
		alert("Username is required.");
		mf.User_login.focus();
		return false;
	} 
    var corretct_uname=isValidName(tmp);
    if(corretct_uname!=tmp){
   		alert("invalid user name "+tmp+"\nuse "+corretct_uname+" instead.\n\nonly alpha numeric characters \nonly - _ symbols are allowed \nname must start and end with letter or number"); 
    	return false;
    }   
    //nickname - nomearte
   	tmp = mf.nick.value;
   	if (tmp.length<1) {
		alert("Nick name is required.");
		mf.nick.focus();
		return false;
	}     
    //citta
	tmp = mf.citta.value;
	if (tmp.length<1) {
		alert("City is required.");
		mf.citta.focus();
		return false;
	}    
    //stato
	tmp = mf.stato;
	if (tmp.selectedIndex == 0) {
		alert("Country is required.");
		mf.stato.focus();
		return false;
	} 

	return true;
}
	
function checkData() {
	var mf = document.register;
	var tmp;
	tmp = mf.nome.value;
	if (tmp.length<1) {
		alert("Name is required.");
		mf.nome.focus();
		return false;
	}
	tmp = mf.cognome.value;
	if (tmp.length<1) {
		alert("Surname is required.");
		mf.cognome.focus();
		return false;
	}  
	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("Birtdate not valid.");
		mf.gg.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("The e-mail format has to be: username@domain.com \r\n'"+mf.email.value+"' is not a valid email.");
			mf.email.focus();
			return false;
		}
	} else {
		if (!(mf.email.value.indexOf("@")>0)) {
			alert("The e-mail format has to be: username@domain.com \r\n'"+mf.email.value+"' is not a valid email.");
			mf.email.focus();
			return false;
		}
	}	
/*	tmp = mf.sesso;
	if (tmp.selectedIndex == 0) {
		alert("Gender is required.");
		mf.sesso.focus();
		return false;
	}
*/    
	tmp = mf.lingua;
	if (tmp.selectedIndex == 0) {
		alert("Language is required.");
		mf.lingua.focus();
		return false;
	}    	
	tmp = mf.passwd.value;
	if (tmp.length<1) {
		alert("Password is required.");
		mf.passwd.focus();
		return false;
	}
	tmp = mf.passwd2.value;
	if (tmp.length<1) {
		alert("Password confirm is required.");
		mf.passwd2.focus();
		return false;
	}
	if(mf.passwd.value!=mf.passwd2.value){
		alert("Password confirm doesnt match Password.");
        mf.passwd.focus();
    	return false;
    }
     tmp = mf.nick.value;
	if (tmp.length<1) {
		alert("Username is required.");
		mf.nick.focus();
		return false;
	}
    var corretct_uname=isValidName(tmp);
    if(corretct_uname!=tmp){
   		alert("invalid user name "+tmp+"\nuse "+corretct_uname+" instead.\n\nonly alpha numeric characters \nonly - _ symbols are allowed \nname must start and end with letter or number"); 
    	return false;
    }
    //nickname - nomearte
   	tmp = mf.nomearte.value;
   	if (tmp.length<1) {
		alert("Nick name is required.");
		mf.nomearte.focus();
		return false;
	}     
     
   	tmp = mf.citta.value;
	if (tmp.length<1) {
		alert("City is required.");
		mf.citta.focus();
		return false;
	}
	tmp = mf.stato;
	if (tmp.selectedIndex == 0) {
		alert("Country is required.");
		mf.stato.focus();
		return false;
	}    
	if (!mf.consenso[0].checked) {
		alert("You have to accept privacy policy.");
		mf.consenso[0].focus();
		return false;
	}
	return true;
}

function valida_form_upload() {
	var tot_err=0;
	var tag_trovate=0;
	var tipi_file_trovati=0;
	var form=document.upload_file;
	for(i=0;i<document.getElementsByName('tipofile').length;i++){
		if(document.getElementsByName('tipofile')[i].checked)
			tipi_file_trovati++;
	}	
	if (tipi_file_trovati == 0) {
		alert ("\nPlease, FileType is required");
		document.getElementsByName('tipofile')[0].focus();
		tot_err++;
		return false;
	}
	if (form.titolo.value == "") {
		alert ("\nPlease, Title is required");
		form.titolo.focus();
		tot_err++;
		return false;
	}
	for(i=0;i<document.getElementsByName('tag_req[]').length;i++){
		if(document.getElementsByName('tag_req[]')[i].checked)
			tag_trovate++;
	}
	if(tag_trovate==0){
		alert ("\nPlease, a select a required tag");
		document.getElementsByName('tag_req[]')[0].focus();
		tot_err++;
		return false;		
	}
	if (form.nome.value == "") {
		alert ("\nPlease, a file is required");
		form.nome.focus();
		tot_err++;
		return false;
	}
	//form.submit();
	return true;
}

function controllaform_contact_us(form) {
	if (form_contact_us(form)){
		return true;
	} else {
		return false;
	}
}

function form_contact_us(form) {
	if (form.emailFrom.value == "") {
		alert ("\nPlease, Email is required");
		form.emailFrom.focus();
		return false;
	} else 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(form.emailFrom.value)) {
			alert("Invalid E-mail format");
			form.emailFrom.focus();
			return false;
		}
	} else {
		if (!(form.emailFrom.value.indexOf("@")>0)) {
			alert("Invalid E-mail format");
			form.emailFrom.focus();
			return false;
		}
	}
	if (form.yourMessage.value == "") {
		alert ("\nPlease, Message is required");
		form.yourMessage.focus();
		return false;
	}
	return true;
}

function controllaform_update(form) {
	if (valida_form_update(form)){
		return true;
	} else {
		return false;
	}
}

function valida_form_update(form) {
	var tag_trovate=0;
	if (form.titolo.value == "") {
		alert ("\nPlease, Title is required");
		form.titolo.focus();
		return false;
	}
	if (form.tipofile.value == "") {
		alert ("\nPlease, FileType is required");
		form.tipofile.focus();
		return false;
	}
	for(i=0;i<document.getElementsByName('tag_req[]').length;i++){
		if(document.getElementsByName('tag_req[]')[i].checked)
			tag_trovate++;
	}
	if(tag_trovate==0){
		alert ("\nPlease, a select a required tag");
		document.getElementsByName('tag_req[]')[0].focus();
		return false;		
	}	
	return true;
}

function controllaform_commenti(form) {
	if (valida_form_commenti(form)){
		return true;
	} else {
		return false;
	}
}

function valida_form_commenti(form) {
	if (form.testo.value == "") {
		alert ("\nPlease, Text is required");
		form.testo.focus();
		return false;
	}
	return true;
}
function validaAlVolo(elem){
	var corretct_uname=isValidName(elem.value);
    if(corretct_uname!=elem.value){
   		alert("invalid Username "+elem.value+"\nuse "+corretct_uname+" instead.\n\nonly alpha numeric characters \nonly - _ symbols are allowed \nname must start and end with letter or number"); 
        elem.value=corretct_uname;
    }
	document.getElementById('mypath').innerHTML=corretct_uname;
}

function removeMember(id_a,id_p){
	if(window.confirm("Are you sure to remove selected member from this crew?")){
		window.location.href="/abusers/crew_members.php?id="+id_a+"&id_p="+id_p+"&act=remove";	
	}
}

window.onload = function() {
	caricaFlashAvvio();
	MM_preloadImages('/_images/logoFLxER_f2.gif')
}
