// JavaScript Document

//check form spedizioni
//result.php
function check(){

var error="";
if(document.conferma.nome.value==''){
error+="\nil campo NOME e' obbligatorio";
}


if(document.conferma.comune.value==''){
error+="\nil campo comune e' obbligatorio";
}

if(document.conferma.indirizzo.value==''){
error+="\nil campo indirizzo e' obbligatorio";
}


if(document.conferma.provincia.value==''){
error+="\nil campo provincia e' obbligatorio";
}

if(document.conferma.cap.value.length<5){
error+="\nil campo CAP e' obbligatorio e deve essere di 5 caratteri";
}

if (error != ""){
		msg = "I seguenti campi devono essere compilati:\n";
		msg += "__________________________________\n";
		error += alert(msg + error + "\n");
		return false;
		
}
metodo_pagamento = document.getElementById('payment_method').value;
metodo_pagamento=metodo_pagamento.replace("_"," ");
metodo_pagamento=metodo_pagamento.replace("_"," ");

messaggio_conferma ="Totale Ordine "+document.conferma.tot.value+" euro"+
					"\n\nMetodo di pagamento scelto: "+metodo_pagamento.toUpperCase();

if (confirm(messaggio_conferma)){
}else{
	return false;
}

}

//popup centrale
//come usarlo : onclick="newWindow("pagina.php", 'popup', 600, 500, 1, 1, 0, 0, 0, 1, 0);
function newWindow(a_str_windowURL, a_str_windowName, a_int_windowWidth, a_int_windowHeight, a_bool_scrollbars, a_bool_resizable, a_bool_menubar, a_bool_toolbar, a_bool_addressbar, a_bool_statusbar, a_bool_fullscreen) {
  var int_windowLeft = (screen.width - a_int_windowWidth) / 2;
  var int_windowTop = (screen.height - a_int_windowHeight) / 2;
  var str_windowProperties = 'height=' + a_int_windowHeight + ',width=' + a_int_windowWidth + ',top=' + int_windowTop + ',left=' + int_windowLeft + ',scrollbars=' + a_bool_scrollbars + ',resizable=' + a_bool_resizable + ',menubar=' + a_bool_menubar + ',toolbar=' + a_bool_toolbar + ',location=' + a_bool_addressbar + ',statusbar=' + a_bool_statusbar + ',fullscreen=' + a_bool_fullscreen + '';
  var obj_window = window.open(a_str_windowURL, a_str_windowName, str_windowProperties)
    if (parseInt(navigator.appVersion) >= 4) {
      obj_window.window.focus();
        }
}

function chbg(t,f){
	if (f==1){
 		t.style.background="url('img/index_dx/bg3.gif')";
	}
	else {
		t.style.background="url('img/index_dx/bg2.gif')";
	}
}

/* controllo sul campo consigliaci  index.php*/
function checkConsigliaci (){
			  if (document.consigliaci.commento.value == "") {
            alert("Inserire il commento.")
            document.consigliaci.commento.focus();
						//eval("document.consigliaci.commento.style.backgroundColor='#CCCCFF'");        
            return false}
			  if (document.consigliaci.commento.value == "Inserisci qui il tuo commento") {
            alert("Inserire il commento.")
            document.consigliaci.commento.focus();
						//eval("document.consigliaci.commento.style.backgroundColor='#CCCCFF'");        
            return false}
	}

function cambia_listino() {
	
		page = document.form_master.listino.options[document.form_master.listino.selectedIndex].value;

		if(page=="gadget"){
			self.location="GadgetGallery.php";
		}
		if( page=="stampa_amatoriale" || page=="stampa_professionale"  ){
			self.location="PictureGallery.php?listino="+page;
		}
		if(page=="calendari"){
			self.location="CalendarGallery.php";
		}
		if(page=="effetti"){
			self.location="EffectGallery.php";
		}
		if(page=="stampa_tela"){
			self.location="CanvasGallery.php";
		}
		if(page=="calendari_6_12"){
			self.location="MultiCalendarGallery.php";
		}
		if(page=="calendari_tascabili"){
			self.location="PocketCalendarGallery.php";
		}
		if(page=="calendari_tavolo"){
			self.location="DeskCalendarGallery.php";
		}
		if(page=="tela_composit"){
			self.location="CompositGallery.php";
		}
		if(page=="foto_collage"){
			self.location="FotoCollageGallery.php";
		}
		if(page=="biglietti_inviti"){
			self.location="BigliettiGallery.php";
		}
		if(page=="prodotti_stampaextra"){
			self.location="StampaExtraGallery.php";
		}
		if(page=="myminibook"){
			self.location="MyMiniBookGallery.php";
		}
		
}
//chiude da popup la finestra principale
function targetopener(){
	window.opener.location.reload(); 
	window.close(); 
}

//nuova funzione numberOnly con filtraggio , .
function numberOnly(evt) {
    /*
	evt = (evt) ? evt : ((window.event) ? event : null);
    if (evt) {
       var elem = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
       if (elem) {
           var charCode = (evt.charCode) ? evt.charCode : 
               ((evt.which) ? evt.which : evt.keyCode);
           if ((charCode < 32 ) || 
               (charCode > 44 && charCode < 46) || 
               (charCode > 47 && charCode < 58)) {
               return true;
           } else {
               return false;
           }
       }
    }
	*/
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
{alert("Solo Numeri sono permessi");
return false;}

return true;
}
/*
Nuova funzione solo numeri
*/



function IsNumeric(sText)

{

	var n = new Number(sText);
	
	if(!isNaN(n)==true){
		return true;
	}else {
		alert("In questo campo sono permessi sono numeri");
		return false;
	}
 }



//colora i td al passaggio del mouse (giallo)

function Color(t){
	t.style.background='lightyellow';
}

function Decolor(t){
	t.style.background='White';
}

//ordinamento gadget in galleria
function OrdinaGadgetPer(page,categoria,visualizza){
	
	page = document.orderform.ordina_per.options[document.orderform.ordina_per.selectedIndex].value;
	
	if(visualizza == ""){
		self.location="fotogadget/"+categoria+"/"+page;
	}else{
		self.location="fotogadget/"+categoria+"/"+page+"/"+visualizza;
	}	
}

//ordinamento puzzle in categoria fotopuzzle
function OrdinaPuzzlePer(page,visualizza){
	
	page = document.orderform.ordina_per.options[document.orderform.ordina_per.selectedIndex].value;
	
	if(visualizza == ""){
		self.location="prodotti/foto_puzzle.php?ordina="+page;
	}else{
		self.location="prodotti/foto_puzzle.php?ordina="+page+"&visualizza="+visualizza;
	}	
}

//ordinamento prodotti album/cornici
function OrdinaProdottiPer(page,categoria){
	page = document.orderform.ordina_per.options[document.orderform.ordina_per.selectedIndex].value;
	self.location=""+categoria+"/?ordina="+page;
}

//http://trentrichardson.com/Impromptu/index.php
//Popup aggiunta al carrello prodotti
function impromptu_ok(){
			$.prompt('Prodotto aggiunto con successo nel carrello.<br>Come preferisci proseguire?',{ 			
				submit: mycallbackfunc,
				buttons: { 'Vai al Carrello': true, 'Continua il tuo Shopping': false }, focus: 0 }
			);
};

function impromptu_no(){
			$.prompt('Impossibile Aggiungere il prodotto contattare l\'assistenza');
};

function impromptu_close(){
			 $.prompt('Prodotto aggiunto con successo nel carrello.',{ 			
				submit: mycallbackfuncOk,
				buttons: { 'OK': true}, focus: 0 }
			);
			
};


//azione su pulsante
function mycallbackfunc(v,m){
	  if(v==true){
	  	//location.replace("http://www.12print.it/upload/result.php");
		 window.location="http://www.12print.it/upload/result.php";	 
	  }
	  
	  return true;
}

//azione su pulsante
function mycallbackfuncOk(v,m){
	  if(v==true){
		parent.$.fancybox.close();
	  }
	  return true;
}

//Messagio di errore per segnalazione errore
function impromptu_error(text){
		var text;
		$.prompt(text);
};