/* survey javascript config */
//url for survey (will pop up in separate browser window)
var survey_url = "https://www.hbogoadvisors.com/R.aspx?a=15";
//what to name the user cookie
var survey_cookie__value = "hbo_survey_102";
//how long to delay before the window appears
var survey_delay_seconds = 15000; // time is in milliseconds 30000 = 30 seconds
//set to true to enable survey, false to disable survey
var enable_flag = false;
// How many days until the cookie expires
var expiresDays = 999;
//end date of campaign. format YYYY, M, DD. 0=JAN, 1=FEB, etc.
var endDate = new Date(2011, 5, 03);
//percentage of randomness
var survey_percentage = 40;

if (endDate)
{
	// calcuate expires days;
	var today = new Date();
	expiresDays = days_between(endDate, today);	
}
/* popup javascript */
var popupStatus = 0;
//loads popup only if it is disabled
function loadPopup(){

  	var isMac = swfobject.ua.mac;
        var isFF = jQuery.browser.mozilla;
        var hasFlash9 = swfobject.hasFlashPlayerVersion('10.0.0');
        if (isMac && isFF && !(hasFlash9)) {
                return false;
        }
    if(popupStatus==0){
	//Set title and text of the message
	JQ('#survey-copy').html("<h1>Have you signed up for HBO GO?</h1><p>If so, tell us what you think. Join the HBO GO Advisory Panel now to share your opinions and to be entered into a sweepstakes.</p>");

	//adds survey_url to link in the message pop - no need to edit
	JQ('#survey-url').attr('href',survey_url);

	//optional: change graphic used for submit button
	JQ('#survey-url img').attr('src','/custom-assets/img/global/button-sign-up.png');
        JQ("#backgroundPopup").css({  "opacity": "0.7"  });
        JQ("#backgroundPopup").fadeIn("slow");
        JQ("#popupContact").fadeIn("slow");
        popupStatus = 1;
    }
}
//disables popup only if it is enabled
function disablePopup(){
    if(popupStatus==1){
        JQ("#backgroundPopup").fadeOut("slow");
        JQ("#popupContact").fadeOut("slow");
        popupStatus = 0;
    }
}

//centering popup
function centerPopup(){
    var windowWidth = JQ(window).width()
    var windowHeight = JQ(window).height();
    var popupHeight = JQ("#popupContact").height();
    var popupWidth = JQ("#popupContact").width();

    //centering
    JQ("#popupContact").css({
       "position": "absolute",
       "top": windowHeight/2-popupHeight/2,
       "left": windowWidth/2-popupWidth/2
    });

    //only need force for IE6
    JQ("#backgroundPopup").css({
    	"height": windowHeight
    });       
}

function days_between(date1, date2) {
//debugger;
    // The number of milliseconds in one day
    var ONE_DAY = 1000 * 60 * 60 * 24

    // Convert both dates to milliseconds
    var date1_ms = date1.getTime()
    var date2_ms = date2.getTime()
    
    if (date2_ms > date1_ms) return 0;

    // Calculate the difference in milliseconds
    var difference_ms = Math.abs(date1_ms - date2_ms)
    
    // Convert back to days and return
    return Math.round(difference_ms/ONE_DAY)

}
