function reloadImage() {
    var now = new Date();
	if (document.images) {
	for (i = 0; i<document.images.length; i++) {
	document.images[i].src=document.images[i].src +'?'+ now.getTime();
		}
    }
}

function capitalizeMe(obj) {
        val = obj.value;
        newVal = '';
        val = val.split(' ');
        for(var c=0; c < val.length; c++) {
                newVal += val[c].substring(0,1).toUpperCase() +
val[c].substring(1,val[c].length) + ' ';
        }
        obj.value = newVal;
}

function novirgola(string) {
    if (!string) return false;
    var Chars = ",";
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == false)
          return false;
    }
    return true;
}

function goinpage(nome_pagina,nome_campo,dimx,dimy){
dimwidth=dimx;
dimheight=dimy;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	selezione=window.open(''+nome_pagina+'?campo='+nome_campo,'selectelement','location=no,status=no,scrollbars=no,resizable=no,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	selezione.focus();
}

function openme(nome_pagina,dimx,dimy){
dimwidth=dimx;
dimheight=dimy;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	selezione=window.open(''+nome_pagina+'','selectelement','location=no,status=no,scrollbars=no,resizable=no,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	selezione.focus();
}

function replace(string,text,by) {
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;
    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;
    var newstr = string.substring(0,i) + by;
    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);
    return newstr;
}

function Email(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return false;
    else
        return true;
}

function Numero(string) {
    if (!string) return false;
    var Chars = "0123456789-[]()/+\s";
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
} 

function AlphaNumeric(string) {
    if (!string) return false;
    var Chars = "0123456789abcdefghijklmnñopqrstuvwxyz";
    for (var i = 0; i < string.length; i++) {
       if (Chars.indexOf(string.charAt(i)) == -1)
          return false;
    }
    return true;
} 

//Validate
function validateute() 
{
	if (document.forms[0].username.value== "")
	{document.forms[0].username.focus();
	 alert('Scrivere un username');
	 return false;
	}
    if (document.forms[0].username.value.length > 30) 
	{document.forms[0].username.focus();
      alert('Il username non può avere più di 30 caratteri');
      return false;
    }
	if (document.forms[0].password.value== "")
	{document.forms[0].password.focus();
	 alert('Indicare una password');
	 return false;
	}
	if (document.forms[0].repassword.value!=document.forms[0].password.value)
	{document.forms[0].repassword.focus();
	 alert('Password e conferma password devono essere uguali');
	 return false;
	}
    if (document.forms[0].password.value.length < 4)
	{document.forms[0].password.focus();
      alert('La password non può avere meno di 4 caratteri');
      return false;
    }
	if (document.forms[0].nome.value== "")
	{document.forms[0].nome.focus();
	 alert('Indicare un nome');
	 return false;
	}
	if (document.forms[0].cognome.value== "")
	{document.forms[0].cognome.focus();
	 alert('Indicare un cognome');
	 return false;
	}
	var posta=document.forms[0].email1.value
	if (document.forms[0].email1.value== "")
	{document.forms[0].email1.focus();
	 alert('Scrivere almeno un email');
	 return false;
	}
	if((((posta.match(/@/)) && (posta.match(/\./))) == null)||(Email(posta)))
	{document.forms[0].email1.focus();
	 alert('Scrivere un email corretto');
	 return false;
	}
	if (document.forms[0].email2.value != ""){
	var posta2=document.forms[0].email2.value
	if((((posta2.match(/@/)) && (posta2.match(/\./))) == null)||(Email(posta2)))
	{document.forms[0].email2.focus();
	 alert('Scrivere un email corretto');
	 return false;
	}
	}
	if (document.forms[0].telefono1.value== "")
	{document.forms[0].telefono1.focus();
	 alert('Indicare almeno un recapito telefonico');
	 return false;
	}
	if (document.forms[0].telefono1.value != ""){
    if (Numero(document.forms[0].telefono1.value) == false) {
        alert("Il telefono deve essere un numero");
        document.forms[0].telefono1.focus();
        return false;
    }
	    if (document.forms[0].telefono1.value.length<6) {
        alert("Numero di telefono non valido");
        document.forms[0].telefono1.focus();
        return false;
    }
    if (document.forms[0].telefono1.value.length > 20) 
	{document.forms[0].telefono1.focus();
      alert('Il numero di telefono non può avere più di 20 caratteri');
      return false;
    }
	}
	if (document.forms[0].telefono2.value != ""){
    if (Numero(document.forms[0].telefono2.value) == false) {
        alert("Il telefono deve essere un numero");
        document.forms[0].telefono2.focus();
        return false;
    }
	    if (document.forms[0].telefono2.value.length<6) {
        alert("Numero di telefono non valido");
        document.forms[0].telefono2.focus();
        return false;
    }
    if (document.forms[0].telefono2.value.length > 20) 
	{document.forms[0].telefono2.focus();
      alert('Il numero di telefono non può avere più di 20 caratteri');
      return false;
    }
	}
	if (document.forms[0].telefono3.value != ""){
    if (Numero(document.forms[0].telefono3.value) == false) {
        alert("Il telefono deve essere un numero");
        document.forms[0].telefono3.focus();
        return false;
    }
	    if (document.forms[0].telefono3.value.length<6) {
        alert("Numero di telefono non valido");
        document.forms[0].telefono3.focus();
        return false;
    }
    if (document.forms[0].telefono3.value.length > 20) 
	{document.forms[0].telefono3.focus();
      alert('Il numero di telefono non può avere più di 20 caratteri');
      return false;
    }
	}
	return true;
}

function checkreservation() 
{
	if (document.sendres.name.value== "")
	{document.sendres.name.focus();
	 alert('You must indicate a name');
	 return false;
	}
	
	if (document.sendres.lastname.value== "")
	{document.sendres.lastname.focus();
	 alert('You must indicate a last name');
	 return false;
	}
	
	if (document.sendres.address.value== "")
	{document.sendres.address.focus();
	 alert('You must indicate an address');
	 return false;
	}
	
	if (document.sendres.city.value== "")
	{document.sendres.city.focus();
	 alert('You must indicate a city');
	 return false;
	}
	
	if (document.sendres.address.value== "")
	{document.sendres.address.focus();
	 alert('You must indicate an address');
	 return false;
	}

	if ((document.sendres.country.selectedIndex == 0) || (document.sendres.country.selectedIndex == 1))
	{document.sendres.country.focus();
	 alert('You must indicate a country');
	 return false;
	}
	
	if (document.sendres.poc.value== "")
	{document.sendres.poc.focus();
	 alert('You must indicate a postal code');
	 return false;
	}
	
	if (document.sendres.phone.value== "")
	{document.sendres.phone.focus();
	 alert('You must indicate a phone');
	 return false;
	}
	
	var posta=document.sendres.email.value
	if (document.sendres.email.value== "")
	{document.sendres.email.focus();
	 alert('You must indicate an email');
	 return false;
	}
	
	if((((posta.match(/@/)) && (posta.match(/\./))) == null)||(Email(posta)))
	{document.sendres.email.focus();
	 alert('You must write a correct email');
	 return false;
	}
	
	if ((document.sendres.datearrive1.selectedIndex == 0) || (document.sendres.datearrive1.selectedIndex == 1))
	{document.sendres.datearrive1.focus();
	 alert('You must indicate a month');
	 return false;
	}
	
	if ((document.sendres.datearrive2.selectedIndex == 0) || (document.sendres.datearrive2.selectedIndex == 1))
	{document.sendres.datearrive2.focus();
	 alert('You must indicate a day');
	 return false;
	}
	
	if ((document.sendres.datearrive3.selectedIndex == 0) || (document.sendres.datearrive3.selectedIndex == 1))
	{document.sendres.datearrive3.focus();
	 alert('You must indicate a year');
	 return false;
	}
	
	if (document.sendres.adults.value== "")
	{document.sendres.adults.focus();
	 alert('You must indicate a quantity');
	 return false;
	}
	
	if ((document.sendres.contact.selectedIndex == 0) || (document.sendres.contact.selectedIndex == 1))
	{document.sendres.contact.focus();
	 alert('You must indicate a contact mode');
	 return false;
	}
	
	return true;
}


function newWindow(url,name,features){
var newWin = window.open(url,name,features);
}

function popcard(swf){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	finestrino=window.open('/postcards/makecard.php?file='+swf,'finestra','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	finestrino.focus();
}


function popread(query){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	finestrino=window.open('/postcards/viewcard.php?'+query,'finestra','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	finestrino.focus();
}

function popresad(query){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	finestrino=window.open('/reservation/index.php?'+query,'finestra','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	finestrino.focus();
}


function yousure() { 
 if (confirm("cancellare veramente questo record?")) { 
return true; 
 } else { 
return false; 
 } 
}

function yousurecustom(x) { 
 if (confirm(x)) { 
return true; 
 } else { 
return false; 
 } 
}

function popstage(){
dimwidth=550;
dimheight=550;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	stagefin=window.open('addstage.php','stage','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	stagefin.focus();
}

function popvendita(PERC,id){
dimwidth=450;
dimheight=450;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	vendfin=window.open(PERC+'vvendita.php?id=' + id,'vendita','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	stagefin.focus();
}

function popcerch(pag){
dimwidth=550;
dimheight=350;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	cerchfin=window.open(''+pag,'cerchiamo','location=no,status=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	cerchfin.focus();
}

function poppreve(pag){
dimwidth=550;
dimheight=500;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	prevefin=window.open(''+pag,'preventivo','location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	prevefin.focus();
}
function fullsizeimage(image,xwin,ywin,path){

   //if (fullsimage && !fullsimage.closed) {
   //fullsimage.close();
   //}

dimwidth=xwin;
dimheight=ywin;
   x = (800 - dimwidth)/2, y = (600 - dimheight)/2;
   if (screen) {
       x = (screen.availWidth - dimwidth)/2;
       y = (screen.availHeight - dimheight)/2;
   }
	fullsimage = window.open('/images/fakeimage.php','fullimage','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width=5,height=5,screenX=5,screenY=5,top=5,left=5');
	fullsimage.close();
	fullsimage = window.open('/images/fullimage.php?image='+image+'&path='+path,'fullimage','location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+dimwidth+',height='+dimheight+',screenX='+x+',screenY='+y+',top='+y+',left='+x);
	//fullsimage.resizeTo(xwin+11,ywin+33);
	fullsimage.focus();
}


// APRO IL MENU ...
function apri(m)
{
    document.getElementById(m).style.visibility = "Visible";
}
// CHIUDO IL MENU ...
function chiudi(m)
{
    document.getElementById(m).style.visibility = "Hidden";
}

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

