var ns4 = (document.layers)? true:false
var ie4 = (document.all)? true:false
var dom=(document.getElementById && !document.all)? true:false
var isMac = (navigator.appVersion.indexOf("Mac") != -1); // 
var xPos;
var yPos;
var mainTab=''


//  funzioni show/hide
function nascondo(quale) {
  if (document.getElementById(quale)) {
            try {document.getElementById(quale).style.display="none"
            }
            catch(e) {
                var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
                alert("Unable to get OBJ:\n" + msg);
                return;
            }
  }
}

function vedo(quale) {
  if (document.getElementById(quale)) {
            try {document.getElementById(quale).style.display="block"
            }
            catch(e) {
                var msg = (typeof e == "string") ? e : ((e.message) ? e.message : "Unknown Error");
                alert("Unable to get OBJ:\n" + msg);
                return;
            }
  }

}

// funzione  scrivi in un layer
function scrivi(quale,stringa) {
  if (ie4) {document.all[quale].innerHTML=stringa}
  else if (ns4) {
     with (document.layers[quale].document) {
      open();
      write(stringa);
      close();
    }
	}
	else {document.getElementById(quale).innerHTML=stringa}
}

// per muovere un layer
function moveTo(quale,x,y) {
  if(ie4) {
    document.all[quale].style.left = x+1;
    document.all[quale].style.top = y;
  }
  else if(ns4) {
    document.layers[quale].left = x+1;
    document.layers[quale].top = y;
  }
  else {
    document.getElementById(quale).style.left = x+1;
    document.getElementById(quale).style.top = y;
  }
}



function layerWidth(quale,what) {
  if (dim==1) {dim="auto"}
  if (ie4) {document.all[quale].style.width=dim}
  else if (ns4) {document.layers[quale].document.width=dim}
  else {document.getElementById(quale).style.width=dim}
}





function getIdProperty( id, property )
{
    if (dom)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            if (styleObject[property])
            {
                return styleObject[ property ];
            }
        }
        styleObject = getStyleBySelector( "#" + id );
        return (styleObject != null) ?
            styleObject[property] :
            null;
    }
    else if (ns4)
    {
        return document[id][property];
    }
    else
    {
        return document.all[id].style[property];
    }
}


function setIdProperty( id, property, value )
{
    if (dom)
    {
        var styleObject = document.getElementById( id );
        if (styleObject != null)
        {
            styleObject = styleObject.style;
            styleObject[ property ] = value;
        }

    }
    else if (ns4)
    {
        document[id][property] = value;
    }
    else if (ie4)
    {
         document.all[id].style[property] = value;
    }
}

function setValue( obj, value ){ 
   // if  the  obj  exist
	if (obj){obj.value = value;}
	
}

function getStyleBySelector( selector )
{
    if (!dom)
    {
        return null;
    }
    var sheetList = document.styleSheets;
    var ruleList;
    var i, j;

    /* look through stylesheets in reverse order that
       they appear in the document */
    for (i=sheetList.length-1; i >= 0; i--)
    {
        ruleList = sheetList[i].cssRules;
        for (j=0; j<ruleList.length; j++)
        {
            if (ruleList[j].type == CSSRule.STYLE_RULE &&
                ruleList[j].selectorText == selector)
            {
                return ruleList[j].style;
            }
        }
    }
    return null;
}

	
// becco  piu posozioni
function getPos() {
   curHold="holdspace"
  if (ie4) { 
    xPos=document.images[curHold].offsetLeft;
    yPos=document.images[curHold].offsetTop;
  }
  else if (ns4) { 
    xPos=document.images[curHold].x;
    yPos=document.images[curHold].y;
  }
  else if (dom) { 
    el = document.getElementById(curHold);
    xPos=el.offsetLeft;
    yPos=el.offsetTop;
  }
  return xPos;yPos;
}
	
	
	// variabili per determinare la dimensione disponibile della finestra
var myWidth = 0
var myHeight = 0;

function getWinSize() {
   if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else {
    if( document.documentElement &&
        ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      //IE 6+ in 'standards compliant mode'
      myWidth = document.documentElement.clientWidth;
      myHeight = document.documentElement.clientHeight;
    } else {
      if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
      }
    }
  }
  return myWidth;myHeight;
}




function getWidth(quale) { 
if(document.getElementById) {
  curW=document.getElementById(quale).offsetWidth
}
if(ns4)curW=document.layers[quale].document.width
return curW
}
function getHeight(quale) { 
if(document.getElementById) {
	curH=document.getElementById(quale).offsetHeight 
return curH 
}
} 

//stampa  pagina
function printPage() {
  var agt=navigator.userAgent.toLowerCase();
  if (window.print) {
    setTimeout('window.print();',200);
	}
	else if (agt.indexOf("mac") != -1) {
    alert("Press 'Cmd+p' on your keyboard to print article.");
	}
	else {
    alert("Press 'Ctrl+p' on your keyboard to print article.")
	}
}
  
  
function goTo(brand,subP){
  location.href='/site/'+brand+'/modelli.php?brand='+brand+'&page=prodotti&sub='+subP+'&lang='+lang
}

function archiviaItems()   {
        var conf=confirm("Do you want to archive this Items?")
		if(conf == true){
        document.edit.archivio.value=1;
       	document.edit.submit()
	}
}


function detectMouseCoordinates(e){ 
    xPos=0; 
    yPos=0; 
    if(!e) var e=window.event; 
    if(e.pageX||e.pageY){ 
          xPos=e.pageX; 
          yPos=e.pageY; 
    } 

    else if(e.clientX||e.clientY){ 
          xPos = e.clientX + document.documentElement.scrollLeft; 
          yPos = e.clientY + document.documentElement.scrollTop; 
    } 
    return xPos;yPos;
} 


// utilizzato per i contatti
function vaiConta(url){
    document.forms[0].action=url
    document.forms[0].submit();
}


//popup
function openPop(brand,subP){
  var win_opts = "location=0,scrollbars=auto,status=0,resizable=0,directories=0,menubar=0,width=300,height=250,top="+0+",left="+0+",screenY="+0+",screenX="+0; 
  path="/site/"+brand+"/pop.php?brand="+brand+"&page=pop&sub="+subP+"&lang="+lang
  var win = open(path,"immaWin",win_opts) ;
}



function openDatiPos(w,h,path,deltaH,deltaW,event) {
  fromTop=0
  fromLeft=0
  detectMouseCoordinates(event)
  if(deltaH>0){fromTop=yPos+deltaH;} 
  if(deltaW>0){fromLeft=xPos+deltaW;}
  var win_opts = "location=0,scrollbars=1,status=1,resizable=1,directories=0,menubar=0,top="+fromTop+",left="+fromLeft+",screenY="+fromTop+",screenX="+fromLeft; 
  var all_opts = win_opts + ',width=' + w + ',height=' + h ;
  var win = open(path,"",all_opts) ;
}

// funzione che serve per scrivere un immagine in un pop-up
function scriviWin(tit,imma,w,h) {
  var win_opts = "location=0,scrollbars=0,status=0,resizable=0,directories=0,menubar=0"; 
  var all_opts = win_opts + ',width=' + w + ',height=' + h ;
  var win = open("","immaWin",all_opts) ;
  with (win.document) {
    open("text/html", "replace");
    write("<HTML><HEAD><TITLE>"+tit+"</TITLE></HEAD><BODY marginwidth=\"0\" marginheight=\"0\" leftmargin=\"0\" topmargin=\"0\" bottommargin=\"0\" rightmargin=\"0\"><img src='"+imma+"' border='0'></BODY></HTML>");
    close();
  }
}

function openDati(w,h,path) {
  var win_opts = "location=0,scrollbars=1,status=1,resizable=1,directories=0,menubar=0,top="+0+",left="+0+",screenY="+0+",screenX="+0; 
  var all_opts = win_opts + ',width=' + w + ',height=' + h ;
  var win = open(path,"",all_opts) ;
}

//apre  una pagina dalla  form  di edit  anche se non ho l'id;
function viewPrintFromForm(w,h,path) {
  if(document.getElementById('Id'))path+=document.getElementById('Id').value
  var win_opts = "location=0,scrollbars=1,status=1,resizable=1,directories=0,menubar=0,top="+0+",left="+0+",screenY="+0+",screenX="+0; 
  var all_opts = win_opts + ',width=' + w + ',height=' + h ;
  var win = open(path,"",all_opts) ;
}
