
var http_post = false;

function openOrCloseDiv( div, val ) {
	div_id = document.getElementById( div );
	if ( ! div_id ) { 
		return false;
	}
	disp = "";
	if( div_id && div_id.style ) {
		disp = div_id.style.display
	} else {
		disp = "none";
	}
	if( disp != 'none' ) {
		div_id.style.display = 'none';
		is_opened = 0;
	} else {
		div_id.style.display = 'inline';
		is_opened = 1;
	}
	return is_opened;
}

function setDivDisplay( div, dsp ) {
	div_id = document.getElementById( div );
	if ( ! div_id ) { 
		return false;
	}
	cur = div_id.style.display;
	if( dsp /* && cur != '' && cur != 'inline' */ ) {
		div_id.style.display = 'inline';
		is_opened = 1;
	} else if( ! dsp /* && cur != 'none' */ ) {
		div_id.style.display = 'none';
		is_opened = 0;
	}
	return is_opened;
}

function setDivContent( div, cnt ) {
	div_id = document.getElementById( div );
	if( ! div_id ) {
		return
	}
	div_id.innerHTML = cnt;
}

function setImageSource( img_id, src, wdt, hgt, maxW, maxH ) {
	img = document.getElementById( img_id );
	if( ! img ) {
		return
	}
	img.src = src;
	mx = 0; my = 0;
	if( wdt && wdt > 0 ) {
		img.width = wdt;
		mx = ( maxW - wdt ) / 2;
	}
	if( hgt && hgt > 0 ) {
		img.height = hgt;
		my = ( maxH - hgt ) / 2;
	}
	margins = my+"px "+mx+"px "+my+"px "+mx+"px";
	img.style.margin =  margins;
}

function permuteNodeOpenCloseStatus( ent, div, img, cnx ) {
	sts = openOrCloseDiv( div );

	img_id = document.getElementById( img );
	tmp = div.split( '_' );
	nod_idt = tmp[2];

	if( sts == 1 ) {
		img_id.src = './images/less.gif';
	} else {
		img_id.src = './images/more.gif';
	}

	url = "store_node_status.php?entity=" + ent + "&node=" + nod_idt + "&status=" + sts + "&needlogin=" + cnx;
	/* alert( url ); */

	http.open( "GET", url, true );
	/* http.onreadystatechange = handleHttpResponse; */
	http.send( null );
}

//
// Intercepter le changement de page (pour sauver avant !)
//
function beforeUnloadPage() {
	if( something_changed ) {
		mess = js_msg_01;
		return mess;
	} else {
		window.onbeforeunload = null;
	}
}


/**
 * Ajax Loads
 */

/**
 * Function ajaxGetScat
 * @param int town : the current town
 * @param int cat : the selected category
 * @param string selInfo : the option list to edit
 */
function ajaxGetScat(town, cat, selInfo) {
	var sel = document.getElementById(selInfo);
	ajaxReq = new Ajax.Request('_ajax_list_scat.php', {
		method: 'get',
		parameters: 'town='+town+'&cat='+cat,
		onSuccess: function(requete) {
			isWorking = false;
			optlist = requete.responseText.split(";");
			sel.options.length = 0;
			for (i=0;i<optlist.length;i++) {
				if (optlist[i].length>0) {
					curOpt = optlist[i].split("#");
					new_opt = new Option(curOpt[1],curOpt[0]);
					sel.options[i] = new_opt;
				}
			}
		}
	});
	isWorking = true;
}

function upSess(selname, filename) {
	zesel = $(selname).options[$(selname).selectedIndex].value;
	ajaxReq = new Ajax.Request(filename+'.php', {
		method: 'get',
		parameters: 'lnd='+zesel,
		OnSuccess: function(requete) {
			isWorking = false;
		}
	});
	isWorking = true;
}

function ajaxUpdate(filename,params) {
	var ajaxReq = new Ajax.Request(filename, {
		method: 'get',
		parameters: params,
		onSuccess: function(requete) {
			if( requete.responseText != "" ) {
				printInfoNs(requete.responseText);
			}
		}
	});
}

