var defaultvar;
function php_serialize(obj){
	// SERIALIZZA UN OGGETTO PER LA SPEDIZIONE VIA GET O POST O PER IL SALVATAGGIO COME STRINGA.
    var string = '';

    if (typeof(obj) == 'object') {
        if (obj instanceof Array) {
            string = 'a:';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                tmpstring += php_serialize(obj[key]);
                count++;
            }
            string += count + ':{';
            string += tmpstring;
            string += '}';
        } else if (obj instanceof Object) {
            classname = obj.toString();

            if (classname == '[object Object]') {
                classname = 'StdClass';
            }

            string = 'O:' + classname.length + ':"' + classname + '":';
            tmpstring = '';
            count = 0;
            for (var key in obj) {
                tmpstring += php_serialize(key);
                if (obj[key]) {
                    tmpstring += php_serialize(obj[key]);
                } else {
                    tmpstring += php_serialize('');
                }
                count++;
            }
            string += count + ':{' + tmpstring + '}';
        }
    } else {
        switch (typeof(obj)) {
            case 'number':
                if (obj - Math.floor(obj) != 0) {
                    string += 'd:' + obj + ';';
                } else {
                    string += 'i:' + obj + ';';
                }
                break;
            case 'string':
                string += 's:' + obj.length + ':"' + obj + '";';
                break;
            case 'boolean':
                if (obj) {
                    string += 'b:1;';
                } else {
                    string += 'b:0;';
                }
                break;
        }
    }

    return string;
}
function AddContact(id){
	var contatto=document.getElementById('contatto').value;
	document.getElementById('frm_amici').src='include_content/elenco_contatti.php?id='+id+'&add='+contatto;
	document.getElementById('contatto').value=''
	document.getElementById('dest').value='';
}
function DeleteContact(id){
	if(document.getElementById('frm_amici').contentWindow.vCheckedRecords!=''){
		if (window.confirm("Confermi l' eliminazione dei contatti selezionati?")){
			strCheckedRecords=document.getElementById('frm_amici').contentWindow.vCheckedRecords;
			document.getElementById('frm_amici').src='include_content/elenco_contatti.php?id='+id+'&dlt='+strCheckedRecords;
		}
	}else{
		alert('Non sono stati selezionati contatti da eliminare');
	}
}
function CancellaImmagine(id,pos){
	document.getElementById('frm_of_service').src='include_content/carica_immagine.php?dlt='+id+'&pos='+pos;	
}

function axter(){defaultvar=true}

function showDetails(id){
	if(document.getElementById('dettagli_'+id).style.display=='none'){
		document.getElementById('dettagli_'+id).style.display='';
	}else{
		document.getElementById('dettagli_'+id).style.display='none';
	}
}
function SelCity(prov){
		document.getElementById('frm_of_service').src='query_comuni.php?provincia='+prov+'&amp;sid='+new Date();	
	}
function SelCityDati(prov){
		document.getElementById('frm_of_service').src='query_comuni.php?provincia_dati='+prov+'&amp;sid='+new Date();	
	}
function ResetForm(){
	document.getElementById('regione').value='';
	document.getElementById('provincia_dyn').value='';
	document.getElementById('provincia_dyn').disabled=true;
	document.getElementById('citta_dyn').value='';
	document.getElementById('citta_dyn').disabled=true;
	document.getElementById('categoria').value='';
	document.getElementById('testo').value='';
}
function Ricerc_dis(){
		if(document.getElementById('regione').value==''){
			document.getElementById('cerca').disabled=true;
		}else{
			document.getElementById('cerca').disabled=false;
		}
	}

function Mappa(indirizzo, riv){
	window.open('google.php?indirizzo='+indirizzo+'&rivenditore='+riv,'MappaGoogle','width=525,height=445,left=300,top=150, toolbar=0, menubar=0, scrollbar=0,resizable=1');
}
function getPageResellers(regione,provincia,citta){
	document.location.href='rivenditori.php?getreseller=true&regione='+regione+'&provincia='+provincia+'&citta='+citta;	
}

var last_menu_open='';
function switchMenu(id){
	if(last_menu_open!=id){
		try{
		document.getElementById(last_menu_open).src='img/menu/'+id+'.gif';
		}catch(e){}
		document.getElementById(id).src='img/menu/'+id+'_on.gif';
		last_menu_open=id;
	}
}
function MenuOnMouseOut(id){
	if(last_menu_open!=id){
		document.getElementById(id).src='img/menu/'+id+'.gif';
	}
}
function MenuOnMouseOver(id){
	if(last_menu_open!=id){
		document.getElementById(id).src='img/menu/'+id+'_on.gif';
	}
}
// JavaScript Document
	var last_id_clicked='';
	function SelImage(file,id,how, id_db_default){
		var obj=document.getElementById('img_'+ id);
		
		if (last_id_clicked==''){
			try{
				document.getElementById(id_db_default).className='img_not_selected';
			}catch(e){}
		}else{
		
			document.getElementById(last_id_clicked).className='img_not_selected';
			last_id_clicked='img_'+ id;
		}
		
		obj.className='img_selected';
		document.getElementById('image').value=file;
		if(how==1){
			document.getElementById('path_image').value='default_icons';
		}else{
			document.getElementById('path_image').value='';
		}
		
		last_id_clicked='img_'+ id;

	}
	
	function OverImage(id){
		var obj=document.getElementById('img_'+ id);
		if(last_id_clicked!='img_'+id){
		obj.className='img_onmouseover';
		}
	}
	
	function OutImage(id){
		var obj=document.getElementById('img_'+ id);
		if(last_id_clicked!='img_'+id){
		obj.className='img_not_selected';
		}
	}
	function DltImage(imei, file){
		document.getElementById('frm_hidden').src='include_content/device_config.php?dlt&file='+ file +'&imei='+ imei;
	}
	
	function set_last_id_clicked(id){
		last_id_clicked=id;
		alert(last_id_clicked);		
	}

//
// 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;
}


