﻿/*----------------------------------------------------------------------------//
// Javascript pour le popup sondage  -----------------------------------------//
//----------------------------------------------------------------------------//
// Client : Museum
// Date   : 8 octobre 2009
//----------------------------------------------------------------------------*/
function SG_importJavascript(src) {
	document.write("<script type=\"text/javascript\" src=\"" + src + "\"></scr" + "ipt>");
}
function SG_importCss(href, media) {
	document.write('<link rel="stylesheet" type="text/css" media="' + media + '" href="' + href + '" />');
}

/*----------------------------------------------------------------------------*/
// Importations de fichiers
/*----------------------------------------------------------------------------*/
SG_importCss("http://sondage.absolunet.com/museum/includes/popup.sondage.css", "screen");

//Variables globales
var SG_bCookie = true;
var SG_bFrequency = true;

SG_lang = (SG_lang=="en"?"en":"fr");
SG_site = (SG_site!=""?SG_site:"mnm");

var SG_frequency = 100;
var SG_waitingTime = 1;
var SG_sondageBaseUrl = "http://www.surveygizmo.com/s/187903/museum-nature";
var SG_sondageBaseUrlEn = "http://www.surveygizmo.com/s/194278/museum-nature-en";
var SG_sondageId = "SG_PopupSondage";
var SG_idInterval;

// Initialisation du popup sondage
jQuery(document).ready(function(){
	SG_initPopup();
});

// Ecriture du popup
function SG_writePopup() {
	var htmlPopup = "<div id=\""+ SG_sondageId +"\" style=\"display:none\">";
	if (SG_lang == "en") {
		htmlPopup += "<div id=\"TB_BoutonFermer\"><a href=\"javascript:SG_closePopup();\">Close  X</a></div>";
	}
	else {
		htmlPopup += "<div id=\"TB_BoutonFermer\"><a href=\"javascript:SG_closePopup();\">Fermer  X</a></div>";
	}
	
	htmlPopup += "<div id=\"Box_"+ SG_site +"\">";
	htmlPopup += "<div id=\"TB_Entete\"><img src=\"http://sondage.absolunet.com/museum/images/ph_logo_"+ SG_site +".gif\" alt=\"\" id=\"TB_Logo\" /></div>";
	htmlPopup += "<div id=\"TB_ContenuBox\">";

	if (SG_lang == "en") {
	    htmlPopup += "<h2>Survey</h2>";
	    htmlPopup += "<p><strong>Help us improve our website!</strong><br />Would you mind completing a short survey after your visit?<br /><br /><strong>It's easy and there's no obligation</strong><br />Click \"I want to take the survey\" if you would like to take part. A window will open in the background and you can complete the survey once your visit is over.<br /><br /><strong>Thank you for your time!</strong></p>";
	}
	else {
	    htmlPopup += "<h2>Sondage</h2>";
	    htmlPopup += "<p><strong>Aidez-nous à améliorer notre site!</strong><br />Après votre visite voudriez-vous répondre à un court sondage ergonomique?<br /><br /><strong>Facile et sans obligation</strong><br />Cliquez sur le bouton \"Participer\" si vous voulez participer. Une fenêtre s'ouvrira en arrière plan et vous pourrez répondre au questionnaire à la fin de votre visite.<br /><br /><strong>Merci de votre participation!</strong></p>";
	}

	htmlPopup += "</div>";
	htmlPopup += "<div id=\"TB_BoutonBox\">";

	if (SG_lang == "en") {
	    htmlPopup += "<a href=\"javascript:SG_openNewWindow();\" class=\"TB_Gauche\">I want to take the survey</a>";
	    htmlPopup += "<a href=\"javascript:SG_closePopup();\" class=\"TB_Droite\">Not interested</a>";
	}
	else {
	    htmlPopup += "<a href=\"javascript:SG_openNewWindow();\" class=\"TB_Gauche\">Participer</a>";
	    htmlPopup += "<a href=\"javascript:SG_closePopup();\" class=\"TB_Droite\">Non merci</a>";
	}
	
	htmlPopup += "</div>";
	htmlPopup += "</div>";
	htmlPopup += "</div>";
	jQuery("body").append("<div id=\"SG_Overlay\"></div>");
	jQuery("body").append(htmlPopup);
}

/*----------------------------------------------------------------------------*/
// Fonctions utilitaires
/*----------------------------------------------------------------------------*/
function SG_initPopup() {
    if (!SG_checkCookie() || !SG_bCookie) {
        if (SG_getFrequency() || !SG_bFrequency) {
			SG_idInterval = setInterval('SG_startPopup()', 1000);
	    }
    }
}
function SG_startPopup() {
	valueCookie = SG_returnCookie();
    if (valueCookie > 0) {       
	   if (jQuery("#"+SG_sondageId).length == 0 || jQuery("#"+SG_sondageId).css("display") == "none")
            SG_setCookie(valueCookie - 1000);
    }
    else 
        SG_openPopup();
}
function SG_openPopup() {
	//tb_show("", "#TB_inline?height=325&amp;width=400&amp;inlineId=" + SG_sondageId, "");
    //tb_show("", "popup.aspx?site=" + SG_site + "&amp;lang=" + SG_lang + "&amp;KeepThis=true&amp;TB_iframe=true&amp;height=325&amp;width=400");
    SG_writePopup();
	
	var divPopup = jQuery("#"+SG_sondageId);
    var divOverlay = jQuery("#SG_Overlay");
    
	jQuery("body").css({'height' : '100%', 'width' : '100%'});
	jQuery("html").css({'overflow' : 'hidden'});
	
	if(jQuery("#mnm_principal").length > 0)
		jQuery("#mnm_principal").css({'position' : 'absolute', 'top' : '0', 'left' : '0'});
	
    divPopup.show();
    divOverlay.show();
	
	clearInterval(SG_idInterval);
	SG_setCookie("-1");
}

function SG_closePopup() {
    //tb_remove();
    jQuery("#"+SG_sondageId).hide();
    jQuery("#SG_Overlay").hide();
	jQuery("body").css({'height' : 'auto', 'width' : 'auto'});
	jQuery("html").css({'overflow' : ''});
	
	if(jQuery("#mnm_principal").length > 0)
		jQuery("#mnm_principal").css({'position' : 'static', 'top' : 'auto', 'left' : 'auto'});

}

function SG_setCookie(pTime) {
    document.cookie = SG_sondageId + "=" + escape(pTime) + "; path=/";
}

function SG_checkCookie() {
    cookieValue = SG_returnCookie();
    if (cookieValue != "-1")
        return false
    return true;
}

function SG_returnCookie() {
    c_name = SG_sondageId;
    if (document.cookie.length > 0) {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1) {
            c_start = c_start + c_name.length + 1;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        }
    }
    return SG_waitingTime * 1000;
}

function SG_getFrequency() {
    divider = Math.floor(100/SG_frequency);
    randomNumber=Math.floor(Math.random()*divider)+1
    if(randomNumber == 1)
    	return true;
    return false;
}

function SG_openNewWindow() {
    var SG_sondageUrl = "";
    if (SG_lang.toLowerCase() == "en")
        SG_sondageUrl = SG_sondageBaseUrlEn;
    else
        SG_sondageUrl = SG_sondageBaseUrl;
    SG_sondageUrl = SG_sondageUrl + "?site=" + SG_site;
    
    window.open(SG_sondageUrl,'sondageWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,copyhistory=yes,resizable=yes')
    self.focus();
    SG_closePopup();
}
