//

// Globals
var VSA_params = "";

function vsaLink(content) {
    return ROOT_URL + "?sessionid=" + SESSION_ID + ((content == "") ? "" : "&" + content) + ((VSA_params == "") ? "" : "&" + VSA_params);
}

function vsaRedirect(content) {
  document.location.href = vsaLink(content);
}

function urlEncode(sStr) {
    return escape(sStr).replace(/\+/g, '%2C').replace(/\"/g,'%22').replace(/\'/g, '%27');
}

function vsaPopup (link, sx, sy, scroll){
    return vsaUrlPopup("popup.asp?sessionid=" + SESSION_ID + "&" + link , sx, sy, scroll);
}

function vsaUrlPopup(url, width, height, scroll) {
    var top      = (screen.height - height) / 2;
    var left     = (screen.width - width)  / 2;

    if (scroll + "" == "undefined" || scroll == true)
	scroll = 1;
    else
	scroll = 0;

    return window.open(url, "", "channelmode=0, directories=0, location=0, menubar=0, resizable=1, scrollbars=" + scroll + ", status=1, titlebar=0, toolbar=0, width=" + width + ", height=" + height + " top=" + top + " left=" + left);
}

function vsaMapLink(batName, sentiers, bureaux) {
    var link = "topicid=16&id=68&parentid=0&from=1_1_1_0_0&mode=0";
    if (batName != "-1")
	link += "&batname=" + batName;
    if (bureaux)
	link += "&display=0";
    if (sentiers)
	link += "&display=2";
    vsaRedirect(link);
}

function vsaMairieMapLink(roomName) {
    var link = "topicid=16&id=111&parentid=0&from=1_1_1_0_0&mode=0";
    link += "&roomname=" + roomName;
    vsaRedirect(link);
}

function editPopup(url) {
    var width = screen.availWidth - 10;
    var height = screen.availHeight - 50;
    var top = 0;
    var left = 0;
    //document.location.href = url;
    window.open(url, "", "channelmode=0, directories=0, location=0, menubar=0, resizable=0, scrollbars=1, status=1, titlebar=0, toolbar=0, width=" + width + ", height=" + height + " top=" + top + " left=" + left);
}

function edit(url) {
    document.location.href = url;
}

/* DATE FUNCTIONS **************/

function getMonthByIndex(idx){
	return ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "août", "septembre", "octobre", "novembre", "décembre"][idx];
}

function getQuantByIndex(idx){
	return ["dimanche", "lundi", "mardi", "mercredi", "jeudi", "vendredi", "samedi"][idx];
}

function getMonthLengthByIndex(idx){
	return [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][idx];
}

/* PRINT FUNCTION ***************/

function initPrint() {
    printImage = new Array();
    for ( var i = 0; i< 2; i ++ ) {
	printImage[i] = new Image();
	printImage[i].src = ROOT_BASE_URL + "/images/print/imprimante_" + i + ".jpg";
    }
}

function showPrint( id ) {
    document.getElementById("printimage").src = printImage[id].src;
}

function vsaPrint(print) {
    if (print) {
	if (document.location.href.indexOf("print") == -1)
	    document.location.href = document.location.href + "&print=1";
	else
	    document.location.href = document.location.href;
    } else {
	self.print();
    }
}

/********************************/

window.onerror = stopError;

function stopError() {
  return true;
}