if(!document.getElementsByClassName)
{
	/**
	 * Returns all the DOM elements found via the Class Name Criteria.
	 * Optionally you can provide the tag name and the object container to filter the search, otherwise it scans every element starting from document root
	 * @author Stuart Colville -- http://muffinresearch.co.uk --
	 * @method getElementsByClassName
	 * @syntax document.getElementsByClassName(strClass: {String} [, strTag: {String} [, objContElm: {Object}]]);
	 * @example var divs = document.getElementsByClassName("myClass", "div", myContainer);
	 * @param {String} strClass -- attribute "class" of the HTML element
	 * @param {String} [strTag] -- optional, tag of the HTML element otherwise the function searches in every HTML element
	 * @param {Object} [objContElm] -- optional, HTML element that contains the elements to search otherwise the function searches in the whole document
	 * @return {Array} arr -- Array of the HTML elements matching the Class Name Criteria
	 */
	document.getElementsByClassName = function(strClass, strTag, objContElm)
	{
		strTag = strTag || "*";
		objContElm = objContElm || this;
		var objColl = objContElm.getElementsByTagName(strTag);
		if(!objColl.length && strTag == "*" &&  objContElm.all) objColl = objContElm.all;
		var arr = [];
		if(!arr.push){ Array.prototype.push = function(value){ this[this.length] = value; }; }
		var delim = strClass.indexOf('|') != -1  ? '|' : ' ';
		var arrClass = strClass.split(delim);
		for(var i=0, j=objColl.length; i<j; i++)
		{
			var arrObjClass = objColl[i].className.split(' ');
			if(delim == ' ' && arrClass.length > arrObjClass.length) continue;
			var c = 0;
			comparisonLoop:
			for(var k=0, l=arrObjClass.length; k<l; k++)
			{
				for(var m=0, n=arrClass.length; m<n; m++)
				{
					if(arrClass[m] == arrObjClass[k]) c++;
					if((delim == '|' && c == 1) || (delim == ' ' && c == arrClass.length))
					{
						arr.push(objColl[i]);
						break comparisonLoop;
					}
				}
			}
		}
		return arr;
	};
}
if(!window.$$)
{
	/**
	 * Used to shortcut document.getElementsByClassName() function
	 * @author Vito
	 * @method $$
	 * @see document.getElementsByClassName()
	 * @param {String} className -- attribute "class" of the HTML element
	 * @param {String} [tagName] -- optional, tag of the HTML element otherwise the function searches in every HTML element
	 * @param {Object} [objContainer] -- optional, HTML element that contains the elements to search otherwise the function searches in the whole document
	 * @return {Array} elements array -- returns an array of puntuators to the elements
	 */
	function $$(className, tagName, objContainer)
	{
		return (typeof(className) == "string" ? 
				(document.getElementsByClassName ? (document.getElementsByClassName(className, tagName, objContainer) ? document.getElementsByClassName(className, tagName, objContainer): false)
				: "Error on method $$(): method not supported by your browser!")
				: "Error on method $$(): 'className' not valid!");
	};
}
/**
 * X-browser event handler attachment and detachment and detection
 * TH: Switched first true to false per http://www.onlinetools.org/articles/unobtrusivejavascript/chapter4.html
 *
 * @param {Object} obj -- the object to attach event to
 * @param {String} evType -- name of the event -DON'T ADD "on", pass only "mouseover", etc
 * @param {Function} fx -- function to call
 * @param {Boolean} [useCapture] -- optional, used attach the event in capture phase or in bubbling phase
 */
function addEvent(obj, evType, fx, useCapture) {
	if(!useCapture) useCapture = false;
	if(!obj.eventsHolder) obj.eventsHolder = [];
	obj.eventsHolder.push([evType, fx, useCapture]);
	if(obj.attachEvent) {
		obj['e' + evType + fx] = fx;
		obj[evType + fx] = function(){ return obj['e' + evType + fx](window.event); };
		var r = obj.attachEvent("on" + evType, obj[evType + fx]);
		return r;
	}
	else if(obj.addEventListener) {
		obj.addEventListener(evType, fx, useCapture);
		return true;
	}
	else {
		return false;
	}
}
function hasEvent(obj, evType, fx, useCapture) {
	var found = false;
	if(!useCapture) useCapture = false;
	if(!obj.eventsHolder) return found;
	for(var i = 0; i < obj.eventsHolder.length; i++) {
		if(obj.eventsHolder[i][0] == evType && obj.eventsHolder[i][1] == fx && obj.eventsHolder[i][2] == useCapture) {
			found = true;
			break;
		}
	}
	return found;
}
function removeEvent(obj, evType, fx, useCapture) {
	if(!useCapture) useCapture = false;
	if(!obj.eventsHolder) obj.eventsHolder = [];
	for(var i = 0; i < obj.eventsHolder.length; i++) {
		if(obj.eventsHolder[i][0] == evType && obj.eventsHolder[i][1] == fx && obj.eventsHolder[i][2] == useCapture) {
			obj.eventsHolder.splice(i, 1);
			break;
		}
	}
	if(obj.detachEvent) {
		if(!obj[evType + fx]) return;
		var r = obj.detachEvent("on" + evType, obj[evType + fx]);
		obj[evType + fx] = null;
		return r;
	}
	else if(obj.removeEventListener) {
		obj.removeEventListener(evType, fx, useCapture);
		return true;
	}
	else {
		return false;
	}
}
/**
 * Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
 *
 * Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
 *
 * Gets the full width/height because it's different for most browsers.
 */
function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 
	return window.undefined; 
}
function getViewportWidth() {
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
	return window.undefined; 
}

// we create a trim function with a small reg ex to trim
// white space from the back and front of the value that's to be stored.
// This function is to be used when validating forms
String.prototype.trim = function() {
	return this.replace(/^\s*|\s*$/g, '');
}

var istruz, prod, clamps, mypdf;
var conversione = "";
// Set the validation namespace
var validation = {

	// Function to check weather a field is empty
	// RegEx includes validation to check if they have added multipe white
	// spaces to the text field.
	// if(validation.empty(field){...}
	empty: function ( field ) {
		var re = /^\s*$/;
		return re.test( field.value );
	},
	
	// Function to check weather a field is empty
	// RegEx includes validation to check if they have added multipe white
	// spaces to the text field.
	// if(validation.empty(field){...}
	a_certain_value: function ( field, valore ) {
		return (field.value == valore) ? true : false;		
	},
	
	// Check that the field contains no illegal charactors
	// Allows "_", " " and "." otherwise other charactors are not allowed
	// if(!validation.alpha_numeric(field)){...}
	alpha_numeric: function ( field ) {
		var re = /^[A-Za-z0-9_ \.]+$/
		return re.test( field.value );
	},
	
	// Function to check for a valid email address, includes a check for @ and . in the string
	// if(validation.email(field)){...}
	email: function ( field ) {
		var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/
		return re.test( field.value );
	},
	
	// Function to check for a valid phone number
	// Can include a number, spaces, dashes, and an extention
	// if(!validation.phone_number(field)){...}
	phone_number: function( field ) {
		var re  = /^[\+]?[0-9-\ ]+$/;
		return re.test(field.value);
	},
	
	//validates that the entry is a positive or negative number
	// if(!validation.numeric_no_spaces(field)){...}
	numeric_no_spaces: function ( field ) {
		var re  = /^[0-9]+$/;
		return re.test( field.value );
	},

	//validates that the entry is a positive or negative number
	// if(!validation.numeric_with_spaces(field)){...}
	numeric_with_spaces: function ( field ) {
		var re  = /^[0-9 ]+$/;
		return re.test( field.value );
	},
	
	// Function to check that 2 fields match eachtoher
	// Generally used for when asking confirmation for an email address or password
	// if(validation.password_match(field1,field2){...}
	fields_match: function ( field1 , field2 ) {
		return ( field1.value != field2.value ) ? true : false;
	},
	
	// Function to check the length of a field
	// if (validation.field_length ( field , min , max)) {...}
	field_length: function ( field , min , max ) {
		return ( ( field.value.length < min ) || ( field.value.length > max ) ) ? true : false;
	},
	
	// Function to check the length of a field
	// if (validation.min_length ( field , min )) {...}
	min_length: function ( field , min ) {
		return ( ( field.value.length < min ) ) ? true : false;
	},
	
	// Function to check the length of a field
	// if (validation.field_length ( field , min , max)) {...}
	max_length: function ( field , max ) {
		return ( ( field.value.length != max ) ) ? true : false;
	},
	
	// To check that input type is a word document
	// if(!validation.word(field){...}
	word: function ( field ) {
		var re = /(.doc$)/; // allow only word
		return re.test( field.value );
	},
	
	// Checks that input is an image
	// if(!validation.image(field){...}
	image: function ( field ) {
		var re = /(.jpe?g$)|(.gif$)|(.png$)/; // allow jpg / jpeg / gif / png
		return re.test( field.value );
	},
	
	// Checks that input is an file
	// if(!validation.file(field){...}
	file: function ( field ) {
		var re = /(.pdf$)|(.txt$)|(.csv$)|(.doc$)/; // allow pdf / txt / csv / doc
		return re.test( field.value );
	},
	
	// Checks that input is an file
	// if(!validation.web(field){...}
	web: function ( field ) {
		var re = /(.css$)|(.html$)|(.xhtml$)|(.xml$)|(.js$)|(.php$)/; // allow css / html / xhtml / xml / js / php
		return re.test( field.value );
	},

	// Function to group a bunch of check boxes
	// Use this function is conjunction with is_minimum_checked & is_minimum_selected to group and make an array
	// group = group_it(field.getElementsByTagName('option')) // group = group_it(field);
	group: function ( obj ) {
		return (typeof obj[0] != 'undefined') ? obj : [obj];
	},
	
	// Function to validate that one of the groups are checked
	// first we must make sure that create an array of the elements that we want to check
	// by using the above group_it function
	is_min_checked: function ( grp , min ) {
		var checked = 0, i = grp.length; // 
		do {
			if ( grp[--i].checked ) {
				if ( ++checked >= min ) {
					return false;
				}
			}
		}
		while ( i );
		return true;
	},
	
	// Object/ Namespsace that checks that the min options are selected in a multiple select.
	// to call this function Call function
	// group = group_it(field.getElementsByTagName('option')) this will group the elements
	// validation.is_min_selected(min,field)
	// remember to set the selected variable to 0 to initialize that it starts on 0
	is_min_selected: function ( grp , min ) {
	
		var selected = 0, i = grp.length; // set "selected" to 0 so as to initialize the variable
		do {
			if ( grp[--i].selected ) {
				if ( ++selected >= min ) {
					return false;
				}
			}
		}
		while ( i );
		return true;
	},
	
	// Function to check that a singe checkbox is checked.
	// if(validation.checked(field)){...}
	checked: function ( field ) {
		return ( field.checked ) ? false : true;
	},
	// Function to make sure that an option is selected.
	// if(validate.selected(field)){...};
	selected: function ( field ) {
		return (field.selectedIndex == 0) ? true : false;
	},
	// Function to check for a certain selected index
	// if(validate.selected(field)){...};
	selected_index: function ( field , index) {
		return (field.selectedIndex == index) ? true : false;
	},

	// validate that the user has checked one of the radio buttons
	radio: function ( radio ) {
		// Run a for loop through the array of radio buttons to check if they 1 is checked
   		for ( var i = 0; i < radio.length; i++ ) {
			if ( radio[i].checked ) {
				return true;
       		}
   		}
	},
	
	// Object that converts m to mm
	// IE is we have a date function that spits out 2 as the month of february
	// This funtion will make the value now 02.
	friendly_date: function ( string ) {
		if ( string < 10 ) {
			string='0'+string;
		}
	 	return string;
	}
}

function openPDF(pdflink){
    mypdf = window.parent.open ("","","location=no,menubar=0,resizable=1,width=450,height=450,status=0");
    mypdf.document.write('<html><head><title>PDF</title>');
    mypdf.document.write('</head><body>');
    mypdf.document.write('<EMBED src="/files/catalogue/' + pdflink +'" width="1024" height="768"></EMBED>');
    mypdf.document.write('</body></html>');
    mypdf.document.close();
    mypdf.focus();
    //window.open('files/catalogue/' + pdflink,'','width=400, height=500, toolbar=no, scrollbars=no, resizable=yes, location=no, status=no, menubar=no');
}

function openPDF2(pdflink){
    mypdf = window.parent.open ("" + pdflink + "","","location=no,menubar=0,resizable=1,width=400,height=500,titlebar=no, toolbar=no, scrollbars=no, resizable=yes, location=no, status=no, menubar=no");
    mypdf.focus()
}

function MyDeleteRow(riga){
	franquiAlert(riga,400,300);
}

function franquiAlert(testonellabox,width,height){
	$('alertbox').innerHTML = testonellabox;
	modalBox.sm('box',width,height);
} 

function overIn(imageItem){
	document.getElementById(imageItem).border = '2px';
	document.getElementById(imageItem).style.backgroundColor='#1B5098';
}
function overOut(imageItem){
	document.getElementById(imageItem).border = '2px';
	document.getElementById(imageItem).style.backgroundColor='transparent';	
}


function whichBrs() {
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1) return 'Opera';
	if (agt.indexOf("staroffice") != -1) return 'StarOffice';
	if (agt.indexOf("webtv") != -1) return 'WebTV';
	if (agt.indexOf("beonex") != -1) return 'Beonex';
	if (agt.indexOf("chimera") != -1) return 'Chimera';
	if (agt.indexOf("netpositive") != -1) return 'NetPositive';
	if (agt.indexOf("phoenix") != -1) return 'Phoenix';
	if (agt.indexOf("firefox") != -1) return 'Firefox';
	if (agt.indexOf("safari") != -1) return 'Safari';
	if (agt.indexOf("skipstone") != -1) return 'SkipStone';
	if (agt.indexOf("msie") != -1) return 'IE';
	if (agt.indexOf("netscape") != -1) return 'Netscape';
	if (agt.indexOf("mozilla/5.0") != -1) return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
	if (agt.substr(0,agt.indexOf('\/')) != 'mozilla') {
	return navigator.userAgent.substr(0,agt.indexOf('\/'));}
	else return 'Netscape';} else if (agt.indexOf(' ') != -1)
	return navigator.userAgent.substr(0,agt.indexOf(' '));
	else return navigator.userAgent;
}


function getReturnData( data , statusCode , statusMessage) {
	 	//AJFORM failed. Submit form normally.
	 	if( statusCode != AJForm.STATUS['SUCCESS'] ) {
	 	 franquiAlert( statusMessage, 400, 300 );
		 return true;
	 	}
	 	//AJFORM succeeded.
	 	else {
               //alert(data)
			   eval(data);
	 	}
}

//funzione che implementa ajax ed esegue l'invio di dati senza ricaricare la pagina
function getData(dataSource){
	
	
	if(XMLHttpRequestObject)
	{
		XMLHttpRequestObject.open("GET", dataSource);
		
		XMLHttpRequestObject.onreadystatechange = function()
		{
			if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200)
			{
				//alert(XMLHttpRequestObject.responseText);
				//document.getElementById('wizard_content').innerHTML = XMLHttpRequestObject.responseText;
				eval(XMLHttpRequestObject.responseText);
			}
		}
		XMLHttpRequestObject.send(null);
	}
}

function checkAdminLogin(){
    if(document.getElementById('loginForm').username.value == 'admin@shiled.net'){
      franquiAlert('You are an administrator, please, insert your password!',400,300);
      document.getElementById('password_nascosta').style.visibility = 'visible';
    }
}

function deleteFromCart(idToDelete){
	getData('/admin/freecart.php?id='+idToDelete);
    }

function openWin(prodotto,finestra){
    if(finestra==1){
        istruz = window.open ("/files/catalogue/switches/"+prodotto+".pdf","istruz","location=no,menubar=0,scrollbars=yes,resizable=1,width=450,height=450,status=0");
        istruz.focus();
        istruz.moveTo(250,100);
		if(prod)
			prod.focus();
        if(clamps){
			clamps.focus();
            //window.clamps.moveBy(0,50);
        }
        
		
    }else if(finestra==2){
        clamps = window.open ("/files/catalogue/switches/"+prodotto+".pdf","clamps","location=no,menubar=0,scrollbars=yes,resizable=1,width=450,height=450,status=0");
        clamps.focus();
		clamps.moveTo(500,150);
		
        if(top.opener.prod)
			top.opener.prod.focus();
        if(window.opener.istruz){
			top.opener.istruz.focus();
            //window.istruz.moveBy(0,50);
        } 
        
    }else{
        prod = window.open ("/files/catalogue/switches/"+prodotto+".pdf","prod","location=no,menubar=0,scrollbars=yes,resizable=1,width=450,height=450,status=0");
		prod.focus();
        prod.moveTo(50,50); 
        
		if(clamps)
            clamps.focus();
		if(istruz){
            istruz.focus();
            //window.istruz.moveBy(0,50);
        }
    }
}
function evidenziaImg(id_img, stato){
	if(stato==1){
		document.getElementById(id_img).style.backgroundColor = 'FFFF99';		
	}else{
		document.getElementById(id_img).style.backgroundColor = 'ffffff';				
	}
}

function MousePosition(evt){
	this.evt = evt;
	
	if(this.evt.pageX || this.evt.pageY)
	{
		this.x = this.evt.pageX;
		this.y = this.evt.pageY;
		
	}
	else if(this.evt.clientX || this.evt.clientY)
	{
		this.x = this.evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		this.y = this.evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}
	return (this.x, this.y);
}

function nascondiDraw(){
	hidePopWin(false);
    }

function nascondiDiv(sensore){

	var el = document.getElementById("overlay_"+sensore);
	if(el.style.visibility == "visible")
			el.style.visibility = "hidden";

	document.getElementById("zoomDraw_"+sensore).src = "/imgs/products/switches/draws/big/blank.jpg";

}

function zoomPic(sensore, evt){
		el = document.getElementById("overlay_"+sensore);
        var laY = new MousePosition(evt);
        myY = laY.y > 330 ? laY.y-350 : laY.y-200;
        el.style.left=200+"px";
		el.style.top = myY + "px";

	   	el.style.visibility = "visible";
		document.getElementById("titoloModal_"+sensore).innerHTML = "<h2>" + sensore + "</h2>";
		//document.getElementById("zoomDraw_"+sensore).src = "/imgs/products/switches/draws/big/" + sensore + ".jpg";
        //document.getElementById("zoomDraw_"+sensore).style.visibility = "visible";

}

function zoomClamp(sensore){
		el = document.getElementById("overlay_"+sensore);
		/*
        var laY = new MousePosition(evt);
		//alert(laY.y);

        myY = laY.y > 330 ? laY.y-400 : laY.y-200;
		el.style.left=200+"px";
		el.style.top = myY + "px";
        */
		el.style.visibility = "visible";
		document.getElementById("titoloModal_"+sensore).innerHTML = "<h2>" + sensore + "</h2>";
		document.getElementById("zoomDraw_"+sensore).src = "/imgs/products/switches/clamps/big/" + sensore + ".png";
		//alert(document.getElementById('zoomDraw').height);			
}

// Cambia immagine nell'Offerta degli Switches ex. http://shield.devel/?switches/detail/FBV

function changePic(step, prodotto, testi){
    var sensore = document.myform.sensori[document.myform.sensori.selectedIndex].value.split("_");
	var connettore = document.myform.connettori[document.myform.connettori.selectedIndex].value.split("_");
	var cavo = document.myform.cavo[document.myform.cavo.selectedIndex].value.split("_");
    var staffe = document.myform.cavo[document.myform.staffe.selectedIndex].value;
	var quantita = document.myform.quantitasingola.value;
	var artesti = testi.split("_");
	switch(step){
		case 1:
            if(sensore!=0){
			document.getElementById('step1').src = "/imgs/products/switches/" + prodotto.toUpperCase() + ".gif";
			document.getElementById('step1').style.visibility = 'visible';
			document.getElementById('step4').src = "/imgs/products/switches/draws/" + prodotto.toUpperCase() + ".gif";
			document.getElementById('step4').style.visibility = 'visible';
			document.getElementById('click4').href = "/imgs/products/switches/draws/big/" + prodotto.toUpperCase() + ".jpg";
			document.getElementById('click4').title = prodotto.toUpperCase();
			document.getElementById('descrizione_sensore').innerHTML = artesti[0] + ": " + sensore[1] + "<br />" + artesti[1] + ": " + sensore[2];
            }
			break;
		case 2:
            if(connettore!=0){
			document.getElementById('step2').src = "/imgs/products/switches/90/" + connettore[1].toUpperCase() + ".jpg";
			document.getElementById('step2').style.visibility = 'visible';
			document.getElementById('descrizione_connettore').innerHTML = artesti[0] + ": " + connettore[1];
            }
			break;
		case 3:
            if(cavo!=0){
    			document.getElementById('descrizione_cavo').innerHTML = artesti[0] + ": " + cavo[1];
            }
    		break;
		case 4:
            if(staffe!=0){
			document.getElementById('step3').src = "/imgs/products/switches/clamps/" + prodotto.toUpperCase() + ".gif";
			document.getElementById('step3').name = prodotto.toUpperCase();
			document.getElementById('click3').href = "/imgs/products/switches/clamps/big/" + prodotto.toUpperCase() + ".png";
			document.getElementById('click3').title = prodotto.toUpperCase();
		//	document.getElementById('step3').style.visibility = 'visible';
            }
            break;
		}
		
	//document.getElementById('codici_ordine').innerHTML = " l'articolo " + sensore[0]  + " " + connettore[0]  + " " + cavo[0];
	//document.getElementById('descrizione_prodotto').innerHTML = "[" + prodotto + " " + sensore[1] + " " + sensore[2] + " " + cavo[0] + " " + connettore[1] + "]";
}


function Time_(){
	aa = new Date();
	bb = aa.getHours();
	mn = aa.getMinutes();
	var ora = ((bb < 10) ? "0" + bb : bb);
	var minuti = ((mn < 10) ? "0" + mn : mn);
	document.getElementById('OraMilano').value=ora+":"+minuti;
	setTimeout('Time()', 10000)
}

function WorldClock_(zone)
{
  now=new Date();
  ofst=now.getTimezoneOffset()/60;
  secs=now.getSeconds();
  sec=-1.57+Math.PI*secs/30;
  mins=now.getMinutes();
  min=-1.57+Math.PI*mins/30;
  hr=(now.getHours() + parseInt(ofst)) + parseInt(zone);
  hrs=-1.575+Math.PI*hr/6+Math.PI*parseInt(now.getMinutes())/360;
  if (hr < 0) hr+=24;
  if (hr > 23) hr-=24;						
  
  return ((hr < 10)?"0"+hr:hr)+':'+((mins < 10)?"0"+mins:mins);
}

function applyOpacity(elem, opacity)
{
	// DOM 2.0
	if( typeof( elem.style.opacity ) != "undefined" )
		elem.style.opacity = opacity / 100;
	// Gecko
	else if( typeof( elem.style.MozOpacity ) != "undefined" )
		elem.style.MozOpacity = opacity / 100;
	// Konqueror and Safari
	else if( typeof( elem.style.KhtmlOpacity ) != "undefined" )
		elem.style.KhtmlOpacity = opacity / 100;
	// IE
	else if( typeof( elem.style.filter ) != "undefined" )
		elem.style.filter = "alpha(opacity=" + opacity + ")";
}

function TimeWorld()
{	
	TimeDataLondra = WorldClock(0,0);
	document.getElementById('OraLondra').innerHTML = TimeDataLondra.substring(0,5);
    document.getElementById('oraLN').innerHTML = "London";
	document.getElementById('OraLondra').title = TimeDataLondra.substring(6);
	
	TimeDataMilano = WorldClock(3600000,1);			  
	document.getElementById('OraMilano').innerHTML = TimeDataMilano.substring(0,5);
    document.getElementById('oraML').innerHTML = "Milano";
    document.getElementById('OraMilano').title = TimeDataMilano.substring(6);

	TimeDataChicago = WorldClock(-21600000,2);
	document.getElementById('OraChicago').innerHTML = TimeDataChicago.substring(0,5);
    document.getElementById('oraCH').innerHTML = "Chicago";
	document.getElementById('OraChicago').title = TimeDataChicago.substring(6);

	TimeDataNY = WorldClock(-18000000,2);
	document.getElementById('OraNewYork').innerHTML = TimeDataNY.substring(0,5);
    document.getElementById('oraNY').innerHTML = "New York";
	document.getElementById('OraNewYork').title = TimeDataNY.substring(6);

	TimeDataLA = WorldClock(-28800000,2);
	document.getElementById('OraLosAngeles').innerHTML = TimeDataLA.substring(0,5);
    document.getElementById('oraLA').innerHTML = "Los Angeles";
	document.getElementById('OraLosAngeles').title = TimeDataLA.substring(6);

	TimeDataHK = WorldClock(28800000,3);
	document.getElementById('OraHongKong').innerHTML = TimeDataHK.substring(0,5);
    document.getElementById('oraHK').innerHTML = "Hong Kong";
	document.getElementById('OraHongKong').title = TimeDataHK.substring(6);

	TimeDataTokyo = WorldClock(32400000,3);
	document.getElementById('OraTokyo').innerHTML = TimeDataTokyo.substring(0,5);
    document.getElementById('oraTK').innerHTML = "Tokyo";
	document.getElementById('OraTokyo').title = TimeDataTokyo.substring(6);

  setTimeout('TimeWorld()',10000);
}

// Dati per il calcolo dell'ora legale nelle varie cittÃƒÂ  del select
var dataZones = new Array(
                          /* +00 London   */ new Array(-1, 0, 2, 1, 0, 0, -1, 0, 9, 1, 0, 0, 1, 3600000),
                          /* +01 Roma     */ new Array(-1, 0, 2, 2, 0, 0, -1, 0, 9, 2, 0, 0, 1, 3600000),
                          /* -05 New York */ new Array(1, 0, 3, 2, 0, 0, -1, 0, 9, 1, 0, 0, 1, 3600000),
                          /* +09 Tokyo    */ new Array()
                         );
 
 
function formatDate(dt)
{
  var minutes = dt.getUTCMinutes();
  var seconds = dt.getUTCSeconds();
  var day = dt.getUTCDate();
  var month = dt.getUTCMonth() + 1;
  var year = dt.getUTCFullYear();
  
  var strTime = dt.getUTCHours();
  
  if (strTime < 10) strTime = "0" + strTime; 
  strTime += ((minutes < 10) ? ":0" : ":") + minutes;
  /* strTime += ((seconds < 10) ? ":0" : ":") + seconds; */
  
  strDate = ((day < 10) ? "0" : "") + day + "/" + ((month < 10) ? "0" : "") + month + "/" + year;
  
 	strTimeDate = strTime + " " + strDate;
 
  return(strTimeDate);
}

/**********************************************/
 
function getDataTime(dtZone, currData, off)
{
  var dt, dayWeek =  currData[off + 1], d;
  var year = dtZone.getUTCFullYear();
  var month = currData[off + 2];
  var code = currData[off];
 
  if (code > 0)
    {
      dt = new Date(Date.UTC(year, month, 1));
      var ud = dt.getUTCDay();
 
      if (ud <= dayWeek) d = (dayWeek - ud) + 1;
      else d = 8 - (ud - dayWeek);
 
      for ( n = 1 ; n < code ; n++ ) d += 7;
    }
  else if (code == 0) d = dayWeek;
  else if (code == -1)
    {
      if (month == 1) d = (!(year % 4) && (year % 100 || !(year % 400))) ? 29 : 28;
      else d = (month == 3 || month == 5 || month == 8 || month == 10) ? 30 : 31;
 
      dt = new Date(Date.UTC(year, month, d));
      var ud = dt.getUTCDay();
 
      if (ud >= dayWeek) d -= (ud - dayWeek);
      else d -= (7 - (dayWeek - ud));
    }
 
  return(Date.UTC(year, month, d, currData[off + 3], currData[off + 4]) + currData[off + 5]);
}
 
/**********************************************/

function getTimezoneTime(timeMS, timeSel)
{
  // Membro dell'array data corrispondente alla selezione corrente del fuso orario
  var currData = dataZones[timeSel];
 
  if (currData.length > 0)
    {
      var dtZone = new Date(timeMS);
      var dt1 = getDataTime(dtZone, currData, 0);
      var dt2 = getDataTime(dtZone, currData, 6);
 
      var dst = 1 - currData[12];
      if (timeMS >= dt1 && timeMS < dt2) dst = currData[12];
 
      if (dst)
        {
          timeMS += currData[13];
        }
    }
 
  return(new Date(timeMS));
}

/**********************************************/
 
function WorldClock(TimeZone,TimeZoneSel)
{
  // Ora locale
  var localTime = new Date();
 
  var localMS = localTime.getTime() - (localTime.getTimezoneOffset() * 60000);
 
  // Ottieni il time UTC in millisecondi + il fuso orario della selezione corrente
  var timeZoneMS = localTime.getTime() + parseFloat(TimeZone);
  var timeZoneTime = getTimezoneTime(timeZoneMS, TimeZoneSel);
 
  var strZone = formatDate(timeZoneTime);
 
	return strZone; 
}

function SimpleSwap(el,which){
	el.src=el.getAttribute(which || "origsrc");
}

function SimpleSwapSetup(){
  var x = document.getElementsByTagName("img");
  for (var i=0;i<x.length;i++){
    var oversrc = x[i].getAttribute("oversrc");
    if (!oversrc) continue;
      
    // preload image
    // comment the next two lines to disable image pre-loading
    x[i].oversrc_img = new Image();
    x[i].oversrc_img.src=oversrc;
    // set event handlers
    x[i].onmouseover = new Function("SimpleSwap(this,'oversrc');");
    x[i].onmouseout = new Function("SimpleSwap(this);");
    // save original src
    x[i].setAttribute("origsrc",x[i].src);
  }
}


function ConvertiInEuro()
{
	var numerico = document.getElementById('valuta').value
	if (isNaN(numerico))
	{ 
		numerico = numerico.substring(0,(numerico.length-1));
		document.getElementById('valuta').value = numerico;
	}
  conversione = "IN";
  document.getElementById('euro').value = document.getElementById('valuta').value / document.getElementById('valutasel').value;
  if (document.getElementById('euro').value == 0)
    document.getElementById('euro').value = ''
  return true;
}

function ConvertiDaEuro()
{
	var numerico = document.getElementById('euro').value
	if (isNaN(numerico))
	{ 
		numerico = numerico.substring(0,(numerico.length-1));
		document.getElementById('euro').value = numerico;
	}
  conversione = "DA";
  document.getElementById('valuta').value = formatvalue(document.getElementById('euro').value * document.getElementById('valutasel').value);
  if (document.getElementById('valuta').value == 0)
    document.getElementById('valuta').value = ''
  return true;
}

function Converti() 
{
  if (conversione == "DA")
    {
      ConvertiDaEuro();
    }
  else if (conversione == "IN")
    {
      ConvertiInEuro()
    }    
  else
    clearvalute();
  return true;
}

function formatvalue(input) 
{
  var rsize = 12;
  var invalid = "**************************";
  var nines = "999999999999999999999999";
  var strin = "" + input;
  var fltin = parseFloat(strin);
  if (strin.length <= rsize) 
    return strin;
  if (strin.indexOf("e") != -1 || fltin > parseFloat(nines.substring(0,rsize)+".4"))
    return invalid.substring(0, rsize);
  var rounded = "" + (fltin + (fltin - parseFloat(strin.substring(0, rsize))));
  return rounded.substring(0, rsize);   
}

function clearvalute() 
{
  document.getElementById('euro').value = '';
  document.getElementById('valuta').value = ''
  return true;
}

function zoomma(what,type){
	showPopWin('/plugin/zoom.php?what='+what+'&type='+type, 550, 450, returnRefresh);
	}

function returnRefresh(){
        window.document.location.reload();
    }
    
function showLabelEditor(id,e,lbl_table){
	if(e.ctrlKey==true){
		//showPopWin('/editLabels.php?id='+id, 800, 650, returnRefresh);
		e.returnValue=false;
		if (window.showModalDialog) {
			window.showModalDialog('/admin/editLabels.php?id='+id+'&tbl='+lbl_table,'myTranslation','dialogWidth:600px;dialogHeight:350px;scroll:0;resizable=0');
			//window.open('/editLabels.php?id='+id,'myTranslation','height=350,width=600,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0 ,modal=yes');
		} else {
			window.open('/admin/editLabels.php?id='+id+'&tbl='+lbl_table,'myTranslation','height=350,width=600,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,modal=yes');
		}
		returnRefresh();	
		}
}

function insertNews(item_type){
		if (window.showModalDialog) {
			window.showModalDialog('/admin/insertNews.php?item_type='+item_type,'myTranslation','dialogWidth:650px;dialogHeight:800px;scroll:0;resizable=0');
		} else {
			window.open('/admin/insertNews.php?item_type='+item_type,'myTranslation','height=800,width=650,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,modal=yes');
		}
		window.document.location.href = '?news/index/'+item_type;
}

function insertFaq(){
		if (window.showModalDialog) {
			window.showModalDialog('/admin/insertFaq.php','myTranslation','dialogWidth:650px;dialogHeight:800px;scroll:0;resizable=0');
		} else {
			window.open('/admin/insertFaq.php','myTranslation','height=800,width=650,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,modal=yes');
		}
		window.document.location.href = '?faq';
}

function insertJobopp(){
		if (window.showModalDialog) {
			window.showModalDialog('/admin/insertJobopp.php','myTranslation','dialogWidth:650px;dialogHeight:800px;scroll:0;resizable=0');
		} else {
			window.open('/admin/insertJobopp.php','myTranslation','height=800,width=650,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,modal=yes');
		}
		window.document.location.href = '?contactus/jobopp';
}


function changePicture(id,item_type){
		if (window.showModalDialog) {
			window.showModalDialog('/admin/changePicture.php?id='+id,'myTranslation','dialogWidth:650px;dialogHeight:250px;scroll:0;resizable=0');
		} else {
			window.open('/admin/changePicture.php?id='+id,'myTranslation','height=250,width=650,toolbar=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,modal=yes');
		}
		window.document.location.href = '?news/index/'+item_type;
}


var PreSimpleSwapOnload =(window.onload)? window.onload : function(){};
window.onload = function(){PreSimpleSwapOnload(); SimpleSwapSetup();}

var XMLHttpRequestObject = false;
if (window.XMLHttpRequest)
{
	XMLHttpRequestObject = new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
	XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function cerca(testo){
    //alert(testo);
    window.location.href.value = "?switches";  //?search/"; //index/" +  testo.replace(' ','+');
}
// Used to Shortcut document.getElementById() function
var $ = function(id)
{
	if(typeof(id) == "string")
		return document.getElementById(id);
};

// Used to Shortcut document.getElementsByName() function
var $n = function(elemName)
{
	if(typeof(elemName) == "string")
		return document.getElementsByName(elemName);
};

// Used to Shortcut document.getElementsByTagName() function
var $t = function(tagName)
{
	if(typeof(tagName) == "string")
		return document.getElementsByTagName(tagName);
};

function showHideElement(elem){
	var el = document.getElementById(elem + '_body');
	var el_opener = document.getElementById(elem + '_opener');
	if ( el.style.display != 'none' ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}