var isNS4=document.layers?true:false;
var isIE=document.all?true:false;
var isNS6=!isIE&&document.getElementById?true:false;
var isDOM = (document.getElementById) ? true : false;
var popup_win=[];

var secs;
var timerID = null;
var timerRunning = false;
var delay = 1000;
var seNewsAperte = "N";
var seSopraBoxNews = "N";

function btSubmit(pForm,pCampo,pValore) {
	document.forms[pForm].elements[pCampo].value = pValore;
	document.forms[pForm].submit();
}

function btFormSubmit(fName) {
	opener.document.forms[fName].submit();
	return false;
}

function btSetVal(pForm,pCampo,pValore) {
	document.forms[pForm].elements[pCampo].value = pValore;
}

function btConfirm(pMsg) {
    return confirm(pMsg,'Violet');
}

function btSleep(naptime){
      var sleeping = true;
      var now = new Date();
      var alarm;
      var startingMSeconds = now.getTime();
      while(sleeping){
         alarm = new Date();
         alarmMSeconds = alarm.getTime();
         if(alarmMSeconds - startingMSeconds > naptime){ sleeping = false; }
      }
   }

function showImagePopUp(pSOP, idFoto){
	var id = 'popup_'+idFoto;
	var popW = 840, popH = 768;
	var winl = (screen.width-popW)/2;
	var wint = (screen.height-popH)/2;
	var eURL = '/index.php?sop=' + encodeURIComponent(pSOP);
	popup_win[idFoto] = window.open(eURL, id, 'status=no,resizable=1,scrollbars=1,width=' + popW + ',height=' + popH + ',top=' + wint + ',left=' + winl);
}

function refreshImagePopup(idFoto){
	popup_win[idFoto].location.href = popup_win[idFoto].location.href
	//popup_win[idFoto].document.getElementById('lightbox_box_scheda').innerHTML = 'CICCIO';
}

function reloadMainPage(pNewURL){
	location.href=pNewURL;
}
/*
function btOpenPopup(pUrl) {
	day = new Date();
	id = day.getTime();
	var pCompleteUrl = pUrl + '&popupid=' + id;
	var popW = 830, popH = 700;
	var winl = (screen.width-popW)/2;
	var wint = (screen.height-popH)/2;
	ww=window.open(pCompleteUrl,id,'status=no,resizable=1,scrollbars=1,width=' + popW + ',height=' + popH + ',top=' + wint + ',left=' + winl);
}
*/

function btOpenPopup(pOP, popW, popH) {
	day = new Date();
	id = day.getTime();
	var winl = (screen.width-popW)/2;
	var wint = (screen.height-popH)/2;
	var eURL = '/index.php?op=' + pOP;
	window.open(eURL,id,'titlebar=no,scrollbars=0,toolbar=0,resizable=1,status=no,width=' + popW + ',height=' + popH + ',top=' + wint + ',left=' + winl);
}

function btOpenPopupS(pSOP, popW, popH) {
	day = new Date();
	id = day.getTime();
	var winl = (screen.width-popW)/2;
	var wint = (screen.height-popH)/2;
	var eURL = '/index.php?sop=' + encodeURIComponent(pSOP);
	window.open(eURL,id,'titlebar=no,scrollbars=0,toolbar=0,resizable=1,status=no,width=' + popW + ',height=' + popH + ',top=' + wint + ',left=' + winl);
}

function btOpenPopupS_scroll(pSOP, popW, popH) {
	day = new Date();
	id = day.getTime();
	var winl = (screen.width-popW)/2;
	var wint = (screen.height-popH)/2;
	var eURL = '/index.php?sop=' + encodeURIComponent(pSOP);
	window.open(eURL,id,'titlebar=no,scrollbars=1,toolbar=0,resizable=1,status=no,width=' + popW + ',height=' + popH + ',top=' + wint + ',left=' + winl);
}

function popup(url) 
{
 params  = 'width='+screen.width;
 params += ', height='+screen.height;
 params += ', top=0, left=0'
 params += ', fullscreen=yes';

 newwin=window.open(url,'_blank', params);
 if (window.focus) {newwin.focus()}
 return false;
}


function btSearchAndClose(pKW) {
	opener.location = '/index.php?op=src_result&kw='+pKW;
	self.close();
}

function setOpacity(id, level) {
    var element = document.getElementById(id);
    element.style.display = 'inline';
    element.style.zoom = 1;
    element.style.opacity = level;
    element.style.MozOpacity = level;
    element.style.KhtmlOpacity = level;
    element.style.filter = "alpha(opacity=" + (level * 100) + ");";
}

function fadeIn(id, steps, duration, interval, fadeOutSteps, fadeOutDuration){
    var fadeInComplete;
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', " + i + ")", i * duration);
      fadeInComplete = i * duration;
    }
    //set the timeout to start after the fade in time and the interval to display the

    //message on the screen have both completed

    setTimeout("fadeOut('" + id + "', " + fadeOutSteps + ", " + fadeOutDuration + ")", fadeInComplete + interval);
}

function fadeOut(id, steps, duration) {
    var fadeOutComplete;
    for (i = 0; i <= 1; i += (1 / steps)) {
      setTimeout("setOpacity('" + id + "', "  + (1 - i) + ")", i * duration);
      fadeOutComplete = i * duration;
    }
    //completely hide the displayed message after the fade effect is complete

    setTimeout("hide('" + id + "')", fadeOutComplete);
}

function hide(id){
    document.getElementById(id).style.display = 'none';
}

function POPUP_addLightboxRow(idFoto){
	xajax_addLightboxRow(idFoto);
}

function makeHistory(newHash) {
  window.location.hash = newHash;
}

// GESTIONE TIMING HOME PAGE
	function InitializeTimer()
	{
	    // Set the length of the timer, in seconds
	    secs = 2;
	    StopTheClock();
	    StartTheTimer();
	}
	
	function StopTheClock()
	{
	    if(timerRunning)
	        clearTimeout(timerID);
	    timerRunning = false;
	}
	
	function StartTheTimer()
	{
	    if (secs==0)
	    {
	        StopTheClock();
	        // Here's where you put something useful that's
	        // supposed to happen after the allotted time.
	        // For example, you could display a message:
	        xajax_rolloverNews();
			InitializeTimer();
	    }
	    else
	    {
	        self.status = secs;
	        secs = secs - 1;
	        timerRunning = true;
	        timerID = self.setTimeout("StartTheTimer()", delay);
	    }
	}


function chkRes(){
	w=screen.width;
	h=screen.height;
	
	imgWidth = w;
	imgHeight = 500 * w / 2000;
	
	document.images['pic1'].width=imgWidth;
	document.images['pic1'].height=imgHeight;
	
	document.getElementById('home_boxes').style.top= (imgHeight + 25) + 'px';
}


function newsBoxOpen() {
	secs=1000;
	if (seNewsAperte == 'N') {
		seNewsAperte = 'Y';
		new Effect.Appear('slidedown_demo', { duration: 0.5});
	}
}

function newsBoxClose() {
	if (seNewsAperte == 'Y') {
		seNewsAperte = 'N';
		secs=2;
		new Effect.Fade('slidedown_demo', { duration: 0.2 });
	}			
}
