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;
	}
}

// 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, '');
}


function $(v) { return(document.getElementById(v)); } function $S(v) { return($(v).style); } function agent(v) { return(Math.max(navigator.userAgent.toLowerCase().indexOf(v),0)); } function isset(v) { return((typeof(v)=='undefined' || v.length==0)?false:true); } function XYwin(v) { var z=agent('msie')?Array(document.body.clientHeight,document.body.clientWidth):Array(window.innerHeight,window.innerWidth); return(isset(v)?z[v]:z); } function sexyTOG() { document.onclick=function(){ $S('sexyBG').display='none'; $S('sexyBOX').display='none'; document.onclick=function(){}; }; } function sexyBOX(v,b) { setTimeout("sexyTOG()",100); $S('sexyBG').height=XYwin(0)+'px'; $S('sexyBG').display='block'; $('sexyBOX').innerHTML=v+'<div class="sexyX">(click outside box to close)'+"<\/div>"; $S('sexyBOX').left=Math.round((XYwin(1)-b)/2)+'px'; $S('sexyBOX').width=b+'px'; $S('sexyBOX').display='block'; }

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/pdf_catalogo/' + pdflink +'" width="1024" height="768"></EMBED>');
    mypdf.document.write('</body></html>');
    mypdf.document.close();
    mypdf.focus();
    //window.open('files/pdf_catalogo/' + pdflink,'','width=400, height=500, toolbar=no, scrollbars=no, resizable=yes, location=no, status=no, menubar=no');
}

function MyDeleteRow(riga){
	alert(riga);
}
 
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'] ) {
	 	 alert( statusMessage );
		 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'){
      alert('You are an administrator, please, insert your password!');
      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 ("","","location=no,menubar=0,scrollbars=yes,resizable=1,width=450,height=450,status=0");
        istruz.document.write('<html><head><title>PDF</title>');
        istruz.document.write('</head><body>');
        istruz.document.write('<EMBED src="/newcat/'+prodotto+'.pdf" width="1024" height="768"></EMBED>');
        istruz.document.write('</body></html>');
        istruz.document.close();
        istruz.focus();
        if(prod)
          prod.focus();
        if(clamps){
            clamps.focus();
            clamps.moveBy(0,50);
            }
        istruz.moveBy(0,50);
    }else if(finestra==2){
        clamps = window.open ("","","location=no,menubar=0,scrollbars=yes,resizable=1,width=450,height=450,status=0");
        clamps.document.write('<html><head><title>PDF</title>');
        clamps.document.write('</head><body>');
        clamps.document.write('<EMBED src="/newcat/'+prodotto+'.pdf" width="1024" height="768"></EMBED>');
        clamps.document.write('</body></html>');
        clamps.document.close();
        clamps.focus();
        if(prod)
          prod.focus();
        if(istruz){
            istruz.focus();
            istruz.moveBy(0,50);
        }
        clamps.moveBy(500,0);
    }else{
        prod = window.open ("","","location=no,menubar=0,scrollbars=yes,resizable=1,width=450,height=450,status=0");
        prod.document.write('<html><head><title>PDF</title>');
        prod.document.write('</head><body>');
        prod.document.write('<EMBED src="/newcat/'+prodotto+'.pdf" width="1024" height="768"></EMBED>');
        prod.document.write('</body></html>');
        prod.document.close();
        if(istruz){
            istruz.focus();
            istruz.moveBy(0,50);
        }
        if(clamps)
            clamps.focus();
        prod.focus();
        prod.moveBy(500,0);
    }
}
function evidenziaImg(id_img, stato){
	if(stato==1){
		document.getElementById(id_img).style.borderWidth = '3px';
		document.getElementById(id_img).style.borderColor = 'ffd700';		
	}else{
		document.getElementById(id_img).style.borderWidth = '1px';
		document.getElementById(id_img).style.borderColor = '000000';				
	}
}

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/draws/bigger/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/draws/bigger/" + 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/pics/clamps/bigger/" + sensore + ".png";
		//alert(document.getElementById('zoomDraw').height);			
}

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/pics/" + prodotto.toUpperCase() + ".gif";
			document.getElementById('step1').style.visibility = 'visible';
			document.getElementById('step4').src = "/imgs/draws/" + prodotto.toUpperCase() + ".gif";
			document.getElementById('step4').style.visibility = 'visible';
			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/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/pics/clamps/" + prodotto.toUpperCase() + ".gif";
			document.getElementById('step3').name = 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()
{	
	TimeDataMilano = WorldClock(3600000,1);			  
	document.getElementById('OraMilano').innerHTML = TimeDataMilano.substring(0,5);
    document.getElementById('oraML').innerHTML = "Roma";
    document.getElementById('OraMilano').title = TimeDataMilano.substring(6);


	TimeDataLondra = WorldClock(0,0);
	document.getElementById('OraLondra').innerHTML = TimeDataLondra.substring(0,5);
    document.getElementById('oraLN').innerHTML = "Londra";
	document.getElementById('OraLondra').title = TimeDataLondra.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);

	
TimeDataTokyo = WorldClock(32400000,3);
	document.getElementById('OraTokyo').innerHTML = TimeDataTokyo.substring(0,5);
    document.getElementById('oraTK').innerHTML = "Tokyo";
	document.getElementById('OraTokyo').title = TimeDataTokyo.substring(6);



	TimeDataLA = WorldClock(25200000,1);
	document.getElementById('OraLosAngeles').innerHTML = TimeDataLA.substring(0,5);
    document.getElementById('oraLA').innerHTML = "Taipei";
	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);

		
	TimeDataChicago = WorldClock(-28800000,1);
	document.getElementById('OraChicago').innerHTML = TimeDataChicago.substring(0,5);
    document.getElementById('oraCH').innerHTML = "San Francisco";
	document.getElementById('OraChicago').title = TimeDataChicago.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();
    }

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);
};