// Questo script contiene funzioni di pubblico utilizzo

var popWindow_;
var w;
var h;
var nome;

function popImage(aImage, w, h, nome) {
        if ((popWindow_ == null) || (popWindow_.closed)) {
                sh = (screen.availHeight/2)-(h/2);
              sw = (screen.availWidth/2)-(w/2);
              popWindow_ = window.open("", nome, "height=" + h + ",width=" + w + ",top=" + ((screen.availHeight/2)-(h/2)) + ",left=" + ((screen.availWidth/2)-(w/2)) +",alwaysLowered=0,alwaysRaised=1,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=1,scrollbars=yes,status=0,titlebar=0,toolbar=0,z-lock=0");
              popWindow_.document.write("<html><body bgcolor:#FFFFFF; STYLE=\"margin:0px;\"><center><table height=\"100%\" width=\"100%\"><tr><td align=\"center\" valign=\"center\"><img src=\"" + aImage + "\"></td></tr></table></center></body></html>");
                popWindow_.focus();
        } else {
                popWindow_.location.href=aUrl;
                popWindow_.focus();
        }

}

// Crea una finestra popup con i tasti del browser
function popUrl(aUrl, w, h, nome) {

        if ((popWindow_ == null) || (popWindow_.closed)) {
                popWindow_ = window.open(aUrl, nome, "height=" + h + ",width=" + w + ",top=" + ((screen.availHeight/2)-(h/2)) + ",left=" + ((screen.availWidth/2)-(w/2)) +",location=center,menubar=no,resizable=yes,scrollbars=yes,toolbar=no,fullscreen=0");
                popWindow_.focus();
        } else {
                popWindow_.location.href=aUrl;
                popWindow_.focus();
        }

}

// Crea una finestra popup non ridimensionabile
function popUrlNoresize(aUrl, w, h, nome) {

        if ((popWindow_ == null) || (popWindow_.closed)) {
                sh = (screen.availHeight/2)-(h/2);
              sw = (screen.availWidth/2)-(w/2);
              popWindow_ = window.open(aUrl, nome, "height=" + h + ",width=" + w + ",top=" + ((screen.availHeight/2)-(h/2)) + ",left=" + ((screen.availWidth/2)-(w/2)) +",alwaysLowered=0,alwaysRaised=1,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,status=0,titlebar=0,toolbar=0,z-lock=0");
                popWindow_.focus();
        } else {
                popWindow_.location.href=aUrl;
                popWindow_.focus();
        }

}

// Crea una nuova finestra del browser
function popUrlFull(aUrl, w, h, nome) {

        if ((popWindow_ == null) || (popWindow_.closed)) {
                popWindow_ = window.open(aUrl, nome, "height=" + h + ",width=" + w + ",top=" + ((screen.availHeight/2)-(h/2)) + ",left=" + ((screen.availWidth/2)-(w/2)) +",menubar=yes,resizable=yes,scrollbars=yes,toolbar=yes,location=yes,status=yes");
                popWindow_.focus();
        } else {
                popWindow_.location.href=aUrl;
                popWindow_.focus();
        }

}

// Crea una finestra
function MakeWindow(PageUrl)
        {
                myWindow = window.open(PageUrl,'promo','top=225,left=150,height=100,width=180,alwaysLowered=0,alwaysRaised=1,channelmode=0,dependent=0,directories=0,fullscreen=0,hotkeys=1,location=0,menubar=0,resizable=0,status=0,titlebar=0,toolbar=0,z-lock=0');
                if (!myWindow.opener) myWindow.opener = main;
        }

// Controlla che un dato in input sia un numero valorizzato maggiore o uguale a zero
function checkCartQuantity(obj)
{
 // controllo numerico
 if (isNaN(obj.value)) {
  alert("La quantità inserita non è corretta!");
  obj.value='1';
  return;
 // controllo non vuoto
 } else if (obj.value == '') {
  alert ("Non sono stati immessi valori per la quantità! ");
  obj.value='1';
  return;
 // controllo maggiore o uguale a zero
 } else if (obj.value < 0) {
  alert ("Non sono ammesse quantità negative ! ");
  obj.value='1';
  return;
 }
}

// Controlla che un dato in input sia un numero valorizzato maggiore di zero
function checkChoosenQuantity(obj)
{
 // controllo numerico
 if (isNaN(obj.value)) {
  alert("La quantità inserita non è corretta!");
  obj.value='1';
  return;
 // controllo positivo
 } else if (!(obj.value > 0)&&(obj.value)) {
  alert ("La quantità deve essere positiva! ");
  obj.value='1';
  return;
 }
}

// Crea un'attesa di gap millisecondi
function delay(gap){
var then,now;
then=new Date().getTime();
now=then;
while((now-then)<gap)
 now=new Date().getTime();
}



//inzio funzioni mcganass
//gestisce la chiusura della popup ordini_stato.php quando chiudo con la X si ricarica la home page, quando clicco sui link kiudo popup e vado alla pagina specificata nel link
function aggiorna_pagina(vai)
    {
    if (!vai)
	{
        window.opener.location.href='age_menu.php';
	window.close();
	}
    else
	{
	window.opener.location.href=vai;
	window.close();
	}
    }
//fine funzioni mcganass
