function changelan(lan_code,qs){
	var QS = qs;
	var nQS = QS.replace(/&lg=\D{2}/,"");
	var nQS = nQS.replace(/lg=\D{2}/,"");
	var newQs = (nQS!='')?nQS+"&lg="+lan_code:"lg="+lan_code;
	document.location.href="?"+newQs;
}

function led(id, src){
		document.getElementById(id).src=src;
}

function openWindow(nome, url, w, h, scorrimento, status, resizable) {
	var win = null;
	var pagina, nome, LeftPosition, TopPosition, settings;
	nome=nome;
	// scorrimento [yes | no]
	LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
	TopPosition = (screen.height) ? (screen.height-h-(screen.width*5/100))/2 : 0;
	settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scorrimento+', resizable=' +resizable+', status=' +status;
	win = window.open(url,nome,settings);
}
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function view_child(obj) {
	var result = "";
	for (var i in obj) {
		result += 'obj' + "." + i + " = " + obj[i] + "<br>";
	}
	
	var w=window.open();
	w.document.write(result);
	return result;
}
function converti_in_array(obj) {
	var vRecord = new Array();
	if(typeof(obj) == 'object') {
		for(var item in obj) {
			var value = obj[item];
			if(typeof(value) == 'object') { 
				converti_in_array(value);
			} else {
				vRecord[item]=value;
			}
		}
	}
	return vRecord;
}

var coordsXY=[0,0];

function getMousePos(e) {
	//NS
	if (document.layers||document.getElementById&&!document.all) {
		coordsXY[0]=e.pageX;
		coordsXY[1]=e.pageY;
	}
	//IE
	else if (document.all) {
//		window.status=window.event.clientX+" and "+window.event.clientY;
		coordsXY[0]=window.event.clientX;
		coordsXY[1]=window.event.clientY;
	}
}
document.onmousemove=getMousePos;
//--------------------------------------------

function FlagOnMouseOut(lan){
	if(lan!=languagecode){
		document.getElementById('language'+lan).src='images/flags/'+lan+'.png';	
	}
}
function FlagOnMouseOver(lan){
	if(lan!=languagecode){
		document.getElementById('language'+lan).src='images/flags/'+lan+'_off.png';	
	}
}
/*function setLanguage(lan){
	var qs = document.location.search;
	if(qs){
		var nqs = qs.replace(/&lg=\S+/,"");
		var nqs = nqs.replace(/lg=\S+/,"");
		var newqs = (nqs!='?')?nqs+"&lg="+lan:"?lg="+lan;
	}else{
		var newqs='?lg='+lan;	
	}
	var loc=document.location.href.replace(qs,"");
	document.location.href=loc+newqs;
}*/
function switchimg(img){
	changeOpac(0, 'immagineprodotto');
	document.getElementById('immagineprodotto').style.backgroundImage='url(images.php?what=prodotto&img='+img+'&size=l)';
	document.getElementById('zoomprodotto').href='images.php?what=prodotto&img='+img+'&size=xl';
	FadeIn('immagineprodotto',1000);
}
function switchtabprodotto(tab){
	//alert(tab);
	document.getElementById('commentitabbt').className='';
	document.getElementById('modellitabbt').className='';
	document.getElementById('prodottitabbt').className='';
	document.getElementById('downloadtabbt').className='';
	document.getElementById('videotabbt').className='';
	
	document.getElementById('commentitab').style.display='none';
	document.getElementById('modellitab').style.display='none';
	document.getElementById('prodottitab').style.display='none';
	document.getElementById('downloadtab').style.display='none';
	document.getElementById('videotab').style.display='none';
	
	document.getElementById(tab+'tab').style.display='block';
	document.getElementById(tab+'tabbt').className='selected';
}
function switchToPrivate(){

	document.getElementById("customer_type").value='0';
	document.getElementById('titolo_dati').innerHTML=DICTIONARY_titolodatiprivato;
	document.getElementById('tbl_privato').style.display='';
	document.getElementById('tbl_azienda').style.display='none';
}

function switchToCompany(){

	document.getElementById("customer_type").value='1';
	document.getElementById('titolo_dati').innerHTML=DICTIONARY_titolodatiazienda;
	document.getElementById('tbl_privato').style.display='none';
	document.getElementById('tbl_azienda').style.display='';
}

function logout(){
	parent.document.getElementById("creditocarrello").innerHTML = '';
	parent.document.getElementById("creditoresiduo").style.display='none';
	document.getElementById('profilolink').innerHTML=DICTIONARY_accedi;
	document.getElementById('profilolink').href='javascript:Accedi()';
	document.getElementById("totcarteuro").innerHTML="0,00";
	document.getElementById('totcart').innerHTML="0";
	hideOverPageWithoutShadow("overlayprofilo");
	Accedi();
	document.getElementById('frm_of_service').src='index.php?logout';
}
      function html_entity_decode(str)
      {
      try
      {
      var tarea=document.createElement('textarea');
      tarea.innerHTML = str; return tarea.value;
      tarea.parentNode.removeChild(tarea);
      }
      catch(e)
      {
      //for IE add <div id="htmlconverter" style="display:none;"></div> to the page
      document.getElementById("htmlconverter").innerHTML = '<textarea id="innerConverter">' + str + '</textarea>';
      var content = document.getElementById("innerConverter").value;
      document.getElementById("htmlconverter").innerHTML = "";
      return content;
      }
      }
function rimuoviricercapertesto(){
	testuale = '';
	ChangePage(1);
}
function rimuoviricercapercodice(){
	codiceprodotto='';
	ChangePage(1);
}
function rimuoviricercaperapplicazione(){
	costruttore = '';
	modello = '';
	ChangePage(1);
}
function cambiapagamento(){
	if(paytypechange==false){
		document.getElementById('shadowselect').style.display='inline';
		//var objOverlay = document.createElement("div");
		//objOverlay.setAttribute('id','shadowselectnew');
		//var objBody = document.getElementsByTagName("body").item(0);
		//objBody.appendChild(objOverlay);
		/*document.getElementById('shadowselect').style.minHeight='100%';
		document.getElementById('shadowselect').style.width='100%';
		document.getElementById('shadowselect').style.left='0px';
		document.getElementById('shadowselect').style.top='0px';*/
		document.getElementById('shadowselect').onclick = function(){cambiapagamento();}
		//view_child(document.getElementById('pagamentosel'));
		//view_child(document.getElementById('shadowselect'));
		//document.getElementById('overlayshadow').style.zIndex=1;
		//document.getElementById('overlayanteprimaordine').style.zIndex=2;
		document.getElementById('pagamentosel').className='graphicDDLList view';
		paytypechange=true;
	}else{
		//var objBody = document.getElementsByTagName("body").item(0);
		//objBody.removeChild(document.getElementById('shadowselectnew'));	
		document.getElementById('shadowselect').style.display='none';
		document.getElementById('pagamentosel').className='graphicDDLList';	
		paytypechange=false;
	}
}
function setpaytype(value){
	paytype=value;
	document.getElementById('pagamentodettaglio').innerHTML=document.getElementById('paytype'+paytype).innerHTML;
	if(paytypechange==true)
		cambiapagamento();
}

function modificadatispedizione(){
	if(datispedchange==false){
		document.getElementById('shadowselect').style.display='inline';
		document.getElementById('shadowselect').style.minHeight='100%';
		document.getElementById('shadowselect').style.width='100%';
		document.getElementById('shadowselect').style.left='0px';
		document.getElementById('shadowselect').style.top='0px';
		document.getElementById('shadowselect').onclick = function(){modificadatispedizione();}
		//document.getElementById('overlayshadow').style.zIndex=1;
		//document.getElementById('overlayanteprimaordine').style.zIndex=2;
		document.getElementById('modificaspedizione').style.display='inline';
		datispedchange=true;
	}else{
		document.getElementById('shadowselect').style.display='none';
		document.getElementById('modificaspedizione').style.display='none';
		datispedchange=false;
	}
}
function stampaordine(idordine,httpserver){
	openWindow('ORDINE'+idordine,httpserver+'/include/ajax/stampaordine.php?idordine='+idordine,700,600,'yes','no','no');
}

function ricercapermodellospecifico(costruttore,modello){
	document.frmcerca.costruttore.value = costruttore;
	document.frmcerca.modello.value = modello;
	//view_child(document.frmcerca);
	//document.frmcerca.submit();
	ricercaurl();
}
function pefertititocarrello(){
	document.getElementById('frm_of_service').src='include/ajax/preferiti.php?setcart=true';
}
function carrellotopreferiti(){
	document.getElementById('frm_of_service').src='include/ajax/preferiti.php?setpreferiti=true';
}
function utf8_encode ( argString ) {
    // Encodes an ISO-8859-1 string to UTF-8  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/utf8_encode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: sowberry
    // +    tweaked by: Jack
    // +   bugfixed by: Onno Marsman
    // +   improved by: Yves Sucaet
    // +   bugfixed by: Onno Marsman
    // +   bugfixed by: Ulrich
    // *     example 1: utf8_encode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var string = (argString+''); // .replace(/\r\n/g, "\n").replace(/\r/g, "\n");
 
    var utftext = "";
    var start, end;
    var stringl = 0;
 
    start = end = 0;
    stringl = string.length;
    for (var n = 0; n < stringl; n++) {
        var c1 = string.charCodeAt(n);
        var enc = null;
 
        if (c1 < 128) {
            end++;
        } else if (c1 > 127 && c1 < 2048) {
            enc = String.fromCharCode((c1 >> 6) | 192) + String.fromCharCode((c1 & 63) | 128);
        } else {
            enc = String.fromCharCode((c1 >> 12) | 224) + String.fromCharCode(((c1 >> 6) & 63) | 128) + String.fromCharCode((c1 & 63) | 128);
        }
        if (enc !== null) {
            if (end > start) {
                utftext += string.substring(start, end);
            }
            utftext += enc;
            start = end = n+1;
        }
    }
 
    if (end > start) {
        utftext += string.substring(start, string.length);
    }
 
    return utftext;
}
function utf8_decode ( str_data ) {
    // Converts a UTF-8 encoded string to ISO-8859-1  
    // 
    // version: 1008.1718
    // discuss at: http://phpjs.org/functions/utf8_decode
    // +   original by: Webtoolkit.info (http://www.webtoolkit.info/)
    // +      input by: Aman Gupta
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Norman "zEh" Fuchs
    // +   bugfixed by: hitwork
    // +   bugfixed by: Onno Marsman
    // +      input by: Brett Zamir (http://brett-zamir.me)
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // *     example 1: utf8_decode('Kevin van Zonneveld');
    // *     returns 1: 'Kevin van Zonneveld'
    var tmp_arr = [], i = 0, ac = 0, c1 = 0, c2 = 0, c3 = 0;
    
    str_data += '';
    
    while ( i < str_data.length ) {
        c1 = str_data.charCodeAt(i);
        if (c1 < 128) {
            tmp_arr[ac++] = String.fromCharCode(c1);
            i++;
        } else if ((c1 > 191) && (c1 < 224)) {
            c2 = str_data.charCodeAt(i+1);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 31) << 6) | (c2 & 63));
            i += 2;
        } else {
            c2 = str_data.charCodeAt(i+1);
            c3 = str_data.charCodeAt(i+2);
            tmp_arr[ac++] = String.fromCharCode(((c1 & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
            i += 3;
        }
    }
 
    return tmp_arr.join('');
}

function visualizzaprodottiuniversali(){
	document.frmcerca.universale.value=1;
	ricercaurl();
}

function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\0/g,'\0');
str=str.replace(/\\\\/g,'\\');
return str;
}

