function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

/* Functions to unobtrusively open links in new windows when className is "new-window" */

/* Create the new window */
function openInNewWindow(e) {
	var event;
	if (!e) event = window.event;
	else event = e;
	// Abort if a modifier key is pressed
	if (event.shiftKey || event.altKey || event.ctrlKey || event.metaKey) {
		return true;
	}
	else {
		// Change "_blank" to something like "newWindow" to load all links in the same new window
	    var newWindow = window.open(this.getAttribute('href'), '_blank');
		if (newWindow) {
			if (newWindow.focus) {
				newWindow.focus();
			}
			return false;
		}
		return true;
	}
}

/*
Add the openInNewWindow function to the onclick event of links with a class name of "new-window"
*/
function getNewWindowLinks() {
	
	// Check that the browser is DOM compliant
	if (document.getElementById && document.createElement && document.appendChild) {
		// Find all links 
		var links = document.getElementsByTagName('a');
		var link;
		for (var i = 0; i < links.length; i++) {
			link = links[i];
			// Find all links with a class name of "non-html"
			if (/\bnew-window\b/.test(link.className)) {
				// append new window function to onclick & onkeypress events (for accessibility!)
				link.onclick = openInNewWindow;
				link.onkeypress = openInNewWindow;
			}
		}
		objWarningText = null;
	}
}

/*
CLEAR ON FOCUS
*/
function clearText(thefield){
if (thefield.defaultValue==thefield.value)
thefield.value = ""
}


/*
RELOAD IMAGES
*/
function reloadImages(){
	if (document.getElementById("immagineRoll")){
		 setTimeout("changeImages()",3000); 
	}
}

function changeImages(){
	document.getElementById("immagineRoll").src= "images/immagine" + Math.floor(Math.random()*4) + ".jpg"
	reloadImages();
}

function preloadImages(){
	  pic1= new Image(420,149); 
	  pic1.src="images/immagine0.jpg"; 

	  pic2= new Image(420,149); 
	  pic2.src="images/immagine1.jpg"; 

	  pic3= new Image(420,149); 
	  pic3.src="images/immagine2.jpg"; 
}


function getURLParam(strParamName){
  var strReturn = "";
  var strHref = window.location.href;
  if ( strHref.indexOf("?") > -1 ){
	var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
	var aQueryString = strQueryString.split("&");
	for ( var iParam = 0; iParam < aQueryString.length; iParam++ ){
	  if (
aQueryString[iParam].indexOf(strParamName.toLowerCase() + "=") > -1 ){
		var aParam = aQueryString[iParam].split("=");
		strReturn = aParam[1];
		break;
	  }
	}
  }
  return unescape(strReturn);
}

addLoadEvent(getNewWindowLinks);
addLoadEvent(preloadImages);
addLoadEvent(reloadImages);

