

function update_field_POST(table2edt, field2edt, pk2edt, pkValue2edt){
	document.getElementById('table').value=table2edt;
	document.getElementById('field').value=field2edt.id;
	document.getElementById('field_value').value=field2edt.value;
	document.getElementById('pk').value=pk2edt;
	document.getElementById('pk_value').value=pkValue2edt;
	upd_via_post.submit();
	
}

function switchObj(obj, idobj){
		
	for (i=0; i<obj.length; i++){
			how=(document.getElementById('tr_'+obj[i]).style.display=='none')?'':'none';
			document.getElementById('tr_'+obj[i]).style.display=how;
	}
	
	document.getElementById('head_'+idobj).style.display=how;

	image=document.getElementById('img_'+idobj);
	src=(how=='none')?'images/piu.gif':'images/meno.gif';
	image.src=src;
}

function setStatusMode(m){
	
	switch(m) { 
		case 0: 
		document.getElementById('imageStatus').src='img/verde.gif';
		document.getElementById('tdStatus').innerHTML='&nbsp;Ok...';
		break; 
	
		case 1: 
		document.getElementById('imageStatus').src='img/rosso.gif';
		document.getElementById('tdStatus').innerHTML='&nbsp;...attendere il trasferimento del file...';
		break; 
	}

}


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);
}

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 refresh_obj(id){
/*
	AGGIORNA L' SRC DI UN OGGETTO
*/
	document.getElementById(id).src=document.getElementById(id).src+'?ssid='+Math.random();
}


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 ZoomImage(image, description){
		id_image=Math.random();
		img_description=description;
		showOverPage();
		document.getElementById('overlay').innerHTML=getLoadingImage();
		AyaxRequest('../../../ajax_request.php', 'POST', 'filetocall=zoom_image&image='+image+'&id_image='+id_image, ZoomImageHTML);		
}

function ZoomImageHTML(){
	
	//creo il contenitore
	var objContainer = document.createElement("div");
	objContainer.setAttribute('id','imgContainer');
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.appendChild(objContainer);
	document.getElementById('imgContainer').style.left='0px';
	document.getElementById('imgContainer').style.top='0px';	
	document.getElementById('imgContainer').style.width='0px';	
	document.getElementById('imgContainer').style.height='0px';	
	objContainer.className = 'div_basic';

	// assegno al contenitore il codice html proveniente dal server
	document.getElementById('imgContainer').innerHTML=this.req.responseText;
	
	// assegno all envento onLoad dell' immagine la relativa funzione
	document.getElementById(id_image).onload = function() { imageOnLoad(); }	
//	view_child(document.getElementById(id_image));
	
}

function imageOnMouseOver(){
	
	try{
		if (img_description){
			setAltDiv();
			changeOpac(0, 'altContainer');
			opacity('altContainer', 0, 100, 100);
			id2follow='altContainer';
			document.onmousemove=followmouse;
		}
	}catch(e){alert(e)}
}


function setAltDiv(){
	
	// creo il contenitore per l'alt div
	var objContainer = document.createElement("div");
	objContainer.setAttribute('id','altContainer');
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.appendChild(objContainer);
	
	var immagine=document.getElementById(id_image);

	document.getElementById('altContainer').style.left=mouseX + 'px';
	document.getElementById('altContainer').style.top=mouseY + 'px';
	document.getElementById('altContainer').className = 'div_alt';
	document.getElementById('altContainer').innerHTML=img_description;

}

var id2follow='';
function followmouse(e){
	getMouseCoords(e);
	window.status=mouseX+'-'+mouseY;
	document.getElementById(id2follow).style.left=mouseX+30 + 'px';
	document.getElementById(id2follow).style.top=mouseY +25 + 'px';
	return false;
}


function imageOnMouseOut(){
	try{
		var objBody = document.getElementsByTagName("body").item(0);
		objBody.removeChild(document.getElementById('altContainer'));
		document.onmousemove='';
	}catch(e){	}
}


function imageOnLoad(){
	opacity('image_loader', 100, 0, 100);
	window.setTimeout('setOverlay()',100);
}

function imageOnClick(){
	imageOnMouseOut();	
	hideOverPage();
}


function setOverlay(){
	
	// nascondo l' overlay
	changeOpac(0, id_image);

	// dimensiono l' overlay
	document.getElementById('overlay').style.width=(document.getElementById(id_image).width+20)+'px';
	document.getElementById('overlay').style.height=(document.getElementById(id_image).height+20)+'px';
	document.getElementById('overlay').innerHTML=document.getElementById('imgContainer').innerHTML;
	centerOverlay();
	
	// fade in
	opacity(id_image, 0, 100, 300);
	
	// eventi per l'immagine
	document.getElementById(id_image).onclick = function() { imageOnClick(); }	
	document.getElementById(id_image).onmouseover = function() { imageOnMouseOver(); }	
	document.getElementById(id_image).onmouseout = function() { imageOnMouseOut(); }	
	

	// distruggo il contenitore dell' immagine
	var objBody = document.getElementsByTagName("body").item(0);
	objBody.removeChild(document.getElementById('imgContainer'));

}


function FadeIn(id, t){
	changeOpac(0, id);
	opacity(id, 0, 100, t);
}

function FadeOut(id, t){
	changeOpac(100, id);
	opacity(id, 100, 0, t);
}


function opacity(id, opacStart, opacEnd, millisec) { 

	//speed for each frame 
	var speed = Math.round(millisec / 100); 
	var timer = 0; 

	//determine the direction for the blending, if start and end are the same nothing happens 
	if(opacStart > opacEnd) { 
		for(i = opacStart; i >= opacEnd; i--) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} else if(opacStart < opacEnd) { 
		for(i = opacStart; i <= opacEnd; i++) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
			timer++; 
		} 
	} 
} 

//change the opacity for different browsers 
function changeOpac(opacity, id) { 
	try{
		var object = document.getElementById(id).style; 
		object.opacity = (opacity / 100); 
		object.MozOpacity = (opacity / 100); 
		object.KhtmlOpacity = (opacity / 100); 
		object.filter = "alpha(opacity=" + opacity + ")"; 
	}catch(e){}
}

var mouseX=0;
var mouseY=0;

document.onmousemove=getMouseCoords;
function getMouseCoords(e){
	if (typeof e != "undefined"){
			mouseX=e.pageX;
			mouseY=e.pageY;
	}else if(typeof window.event != "undefined"){
		
			mouseX=event.clientX;
			mouseY=event.clientY;
			
		}
	
}

