/* scripts.js */
function redirect_to(url){
	if(url){
		window.location=url;
	}
}

function show_hide(id){
	if(document.getElementById(id).style.visibility=="hidden"){
		document.getElementById(id).style.visibility="visible";
	}
	else {
		document.getElementById(id).style.visibility="hidden";
	}
}

function show_hide_display(id,type){
    if(document.getElementById(id).style.display==type){
        document.getElementById(id).style.display="none";
    }
    else {
        document.getElementById(id).style.display=type;
    }
    return true;
}

function blind_in_out_display(id){
    if(document.getElementById(id).style.display=="none"){
        window.location.hash=id+"_hash"; 
        Effect.BlindDown(id, { duration: 0.5});
    }
    else {
        Effect.BlindUp(id, { duration: 0.5});
    }
}

function popup_over_window(action,id_where_to_insert,id_from_content,execFunctionOnClose){
    if(action=="open"){
        document.body.style.overflow="hidden";

        if(document.getElementById("popup_over_window")==undefined){
            document.getElementById(id_where_to_insert).innerHTML=
                '<div id="popup_over_window">'+
                '<div id="popup_over_window_background" style="position:fixed; top:0px; right:0px; left:0px; bottom:0px; z-index:500; width:100%; height:100%; background-color:#000000; opacity:0; -moz-opacity:0; filter:alpha(opacity=0); text-align:center; vertical-align:center;"></div>'+
                '<div id="popup_over_window_close" onclick="popup_over_window(\'close\',\''+id_where_to_insert+'\',\''+id_from_content+'\',\''+execFunctionOnClose+'\')" style="position:fixed; top:5px; right:5px; z-index:510; width:35px; height:35px; text-align:center; vertical-align:center; line-height:35px; font-family:arial; font-weight:bold; color:#EEEEEE; font-size:35px;">X</div>'+
                '<div id="popup_over_window_block" style="position:fixed; top:40px; right:40px; left:40px; bottom:40px; z-index:501; opacity:0; -moz-opacity:0; filter:alpha(opacity=0); text-align:center; vertical-align:center;">'+
                '<table style="margin:auto;"><tr><td style="text-align:center; vertical-align:center; padding:20px; background-color:#FFFFFF; overflow:scroll; max-height:80%;"><div id="popup_over_window_content" style="text-align:left;"></div></td></td></table>'+
                '</div>'+
                '</div>'+
                document.getElementById(id_where_to_insert).innerHTML;
        }
        document.getElementById("popup_over_window_content").innerHTML=document.getElementById(id_from_content).innerHTML;
        document.getElementById(id_from_content).innerHTML='';
        new Effect.Opacity('popup_over_window_background', { from: 0, to: 0.45, duration: 0.5 });
        new Effect.Opacity('popup_over_window_block', { from: 0, to: 1, duration: 0.5 });
    }
    else {
        new Effect.DropOut('popup_over_window_close');
        new Effect.DropOut('popup_over_window_block');
        new Effect.Opacity('popup_over_window_background', { from: 0.35, to: 0, duration: 0.5 });
        document.getElementById(id_from_content).innerHTML=document.getElementById("popup_over_window_content").innerHTML;
        document.getElementById("popup_over_window_content").innerHTML='';
        setTimeout('document.getElementById("'+id_where_to_insert+'").removeChild(document.getElementById("popup_over_window"));'+execFunctionOnClose+';',500);
        //document.getElementById(id_where_to_insert).removeChild(document.getElementById("popup_over_window"));
        document.body.style.overflow="visible";
    }

}

function getXhr(){
	delete xhr;
	if(window.XMLHttpRequest)
		var xhr = new XMLHttpRequest();
	else if(window.ActiveXObject){
		try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
		catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	else {
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest, veuillez le mettre ? jour");
		xhr = false;
	}
	return xhr;
}

function clearMessage(id){
	document.getElementById(id).innerHTML = "";
}

function decode_mailto(str1,str2,num){
	var mailto="";
	for (var i=0;i<num;i++){
		var new_car=str1[i]-str2[i];
		mailto += String.fromCharCode(new_car);
	}
	window.location=mailto;
}

function is_array( mixed_var ) {
    return (mixed_var instanceof Array || mixed_var instanceof Object);
}

function check_uncheck(checkbox_id,state){
    if(is_array(checkbox_id)==true){
        for(i=0;i<checkbox_id.length;i++){
            if(state==undefined){
                if(document.getElementById(checkbox_id[0]).checked==true){
                    state=false;
                }
                else {
                    state=true;
                }
            }
            document.getElementById(checkbox_id[i]).checked=state;
        }
    }
    else {
        if(document.getElementById(checkbox_id).checked==true){
            document.getElementById(checkbox_id).checked=false;
        }
        else {
            document.getElementById(checkbox_id).checked=true;
        }
    }
}

function full_screen(){
    document.body.style.overflow="hidden";
    if(document.getElementById("fullscreen_background")==undefined){
        document.body.innerHTML='<div id="fullscreen_background" style="position:fixed; top:0px; right:0px; left:0px; bottom:0px; z-index:100; width:100%; height:100%; background-color:#84B3D4; opacity:0; -moz-opacity:0; filter:alpha(opacity=0); text-align:center; vertical-align:center; display:none;"></div>'+document.body.innerHTML;
        //new Effect.Opacity('fullscreen_background', { from: 0, to: 1, duration: 0.5 });
    }
    document.getElementById("ajax_content").style.position="fixed";
    document.getElementById("ajax_content").style.top="0px";
    document.getElementById("ajax_content").style.left="0px";
    document.getElementById("ajax_content").style.right="0px";
    document.getElementById("ajax_content").style.bottom="0px";
    document.getElementById("ajax_content").style.padding="0px";
    document.getElementById("ajax_content").style.margin="0px";
    document.getElementById("ajax_content").style.zIndex=600;
}

function restore_from_full_screen(){
    document.body.style.overflow="visible";
    new Effect.Opacity('fullscreen_background', { from: 1, to: 0, duration: 0.5 });
    setTimeout('document.body.removeChild(document.getElementById("fullscreen_background"));',500);
        
    document.getElementById("ajax_content").style.position="static";
    document.getElementById("ajax_content").style.top="auto";
    document.getElementById("ajax_content").style.left="auto";
    document.getElementById("ajax_content").style.right="auto";
    document.getElementById("ajax_content").style.bottom="auto";
}

