/*--------------------------------------------------------------------*/
/*----------------------------- AJAX ---------------------------------*/
/*--------------------------------------------------------------------*/
var myRequest = null;
var myDiv = null;

function 
CreateXmlHttpReq2(handler) 
 {
 var xmlhttp = null;
 try 
  {
  xmlhttp = new XMLHttpRequest();
  } 
 catch(e) 
  {
  try 
   {
   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
   } 
  catch(e) 
   {
   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
   }
  }
 xmlhttp.onreadystatechange = handler;
 return xmlhttp;
 } // CreateXmlHttpReq2
function 
myHandler2(the_div) 
 {
    if(myRequest.readyState == 4 && myRequest.status == 200) 
  {
        e = document.getElementById(myDiv);
//alert(myRequest.responseText);
        e.innerHTML = myRequest.responseText;
  }
 }
function 
get_cont(url, the_div) 
 {
// url = Utf8.decode(url);
//alert(url);
//alert(the_div);
 myDiv = the_div;
 if(document.getElementById(myDiv).style.display == "none")
    document.getElementById(myDiv).style.display = "block";
 myRequest = CreateXmlHttpReq2(myHandler2);
 myRequest.open("GET", url);
 myRequest.send(null);
 }
function 
get_cont_post(url, args, the_div) 
 {
// url = Utf8.decode(url);
//alert(url);
//alert(args);
//alert(the_div);
 myDiv = the_div;
 if(document.getElementById(myDiv).style.display == "none")
    document.getElementById(myDiv).style.display = "block";
 myRequest = CreateXmlHttpReq2(myHandler2);
 myRequest.open("POST", url, true);
 //myRequest.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
 myRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
 myRequest.setRequestHeader("Content-length", args.length);
 myRequest.send(args);
 }

function 
put_cont (idnazione)
 {
// alert(idnazione);
 document.getElementById("form_trade").style.display = "block";
 get_cont("http://www.moleskine.com/php/mt_templates/ajax_trade.php?id=" +  idnazione, "from_ajax");
 }
/*------------------------------- fine AJAX ----------------------------------*/
function 
clearfield(el, str)
	{
	if(el.value == str)
		el.value = "";
	}
function
countClickTrade(sLogScript, sURL, sId) 
	{
/*	if (typeof this.target == 'undefined' || this.target != '_blank') {
		this.setAttribute('target', '_blank');
	}
*/
	var elImage = document.createElement('img');
	elImage.setAttribute('id', 'count_' + parseInt(Math.random()*99999999));
	elImage.setAttribute('alt', 'Counter');
/*	var sEncoder = encodeURIComponent||escape, aURL = this.href.split('#');
	var sURL = sEncoder(aURL[0]).replace(/\+/g,'%2B');
*/
	elImage.setAttribute('src', sLogScript + '?trade_url=' + sURL + '&trade=' + sId + '&cb=' + parseInt(Math.random()*99999999));
	elImage.style.display = 'none';
	document.body.appendChild(elImage);
	return true;
	}



// Javascript gestione lingue
// <![CDATA[

function aprichiudi( targetId ){
  if (document.getElementById){
		target = document.getElementById( targetId );
			if (target.style.display == "none"){
				target.style.display = "block";
			} else {
				target.style.display = "none";
				
			}
	}
}
// ]]>

/**
*
*  UTF-8 data encode / decode
*  http://www.webtoolkit.info/
*
**/

var Utf8 = {

	// public method for url encoding
	encode : function (string) {
		string = string.replace(/\r\n/g,"\n");
		var utftext = "";

		for (var n = 0; n < string.length; n++) {

			var c = string.charCodeAt(n);

			if (c < 128) {
				utftext += String.fromCharCode(c);
			}
			else if((c > 127) && (c < 2048)) {
				utftext += String.fromCharCode((c >> 6) | 192);
				utftext += String.fromCharCode((c & 63) | 128);
			}
			else {
				utftext += String.fromCharCode((c >> 12) | 224);
				utftext += String.fromCharCode(((c >> 6) & 63) | 128);
				utftext += String.fromCharCode((c & 63) | 128);
			}

		}

		return utftext;
	},

	// public method for url decoding
	decode : function (utftext) {
		var string = "";
		var i = 0;
		var c = c1 = c2 = 0;

		while ( i < utftext.length ) {

			c = utftext.charCodeAt(i);

			if (c < 128) {
				string += String.fromCharCode(c);
				i++;
			}
			else if((c > 191) && (c < 224)) {
				c2 = utftext.charCodeAt(i+1);
				string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
				i += 2;
			}
			else {
				c2 = utftext.charCodeAt(i+1);
				c3 = utftext.charCodeAt(i+2);
				string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
				i += 3;
			}

		}

		return string;
	}

}


