﻿var popupStatus = 0;

function showDosageCalc(){
    loadPopup('/en/tools/dosage-calculator.htm', 'large', false);
}

function showDosageCalcFR(){
    loadPopup('/fr/tools/dosage-calculator.htm', 'large', false);
}

function showExit(){
    $("#popup-icons").css({"display" : "none"});
    loadPopup('/en/exit.aspx', 'small', false);
}

function showExitFR(){
    $("#popup-icons").css({"display" : "none"});
    loadPopup('/fr/exit.aspx', 'small', false);
}

function showPop(url, size){
    $("#popup-icons").css({"display" : "block"});
    loadPopup(url, '', false);
}

function showPopNoIcons(url, size){
    $("#popup-icons").css({"display" : "none"});
    loadPopup(url, size, false);
}

function showPopNoIconsSSL(url, size){
    $("#popup-icons").css({"display" : "none"});
    loadPopup(url, size, true);
}

//Loading popup with jQuery magic!
function loadPopup(url, size, isSSL){

	//loads popup only if it is disabled
	if (size == "small"){
	    $("#ifrmPopup").attr({width: "600", height: "400" });
	    $("#popupContact").css({"width" : "600px", "height" : "440px"});
	}
	else if (size == "large"){
	    $("#ifrmPopup").attr({width: "800", height: "630" });
	    $("#popupContact").css({"width" : "800px", "height" : "675px"});   
	}
	else if (size == "coupon"){
	    $("#ifrmPopup").attr({width: "550", height: "630" });
	    $("#popupContact").css({"width" : "550px", "height" : "675px"});
	}
	else{
	    $("#ifrmPopup").attr({width: "690", height: "455" });
	    $("#popupContact").css({"width" : "690px", "height" : "525px"});   
	}
	
	centerPopup();
	
	if(popupStatus==0){
	
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		
		if(isSSL)
		    $("#ifrmPopup").attr("src", "https://" + window.location.href.split("/")[2] + url); //Load URL with SSL (https:)
	    else
	        $("#ifrmPopup").attr("src", url); //Load URL standard (http:)
	        
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		
		popupStatus = 1;
		
	}
	
}

function disablePopup(){

	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
	
}

//Centering popup
function centerPopup(){
	
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();

	$("#popupContact").css({
		"position": "absolute",
		"top": 0,
		"left": windowWidth/2-popupWidth/2
	});
	
	//only need force for IE6
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}


function printDocument(){  
    frames["documentframe"].focus();  
    frames["documentframe"].print();  
}

function openWindow(url,windowName,height,width){
	SmallWin = window.open(url, windowName,'scrollbars=no,resizable,height='+height+',width='+width+',screenX=25,screenY=25');
	if (window.focus)
		SmallWin.focus();
}

function openWindow1(url,windowName,height,width){
	SmallWin = window.open(url, windowName,'scrollbars=yes,resizable,height='+height+',width='+width+',screenX=25,screenY=25');
	if (window.focus)
		SmallWin.focus();
}

//JR 20091123: Opens a new window in the center of the screen with no tool/menu bars.
function openWindowCentered(url, windowName, height, width){

    var top = Math.floor( (screen.height - height) / 2);
    var left = Math.floor( (screen.width - width) / 2);
    
//    //Add 20 to height for IE to accomodate the Links area when menubar=yes
//    if(navigator.appVersion.indexOf("MSIE") != -1)
//        height+=20;
        
    SmallWin = window.open(url, windowName, 'scrollbars=no, resizable=no, menubar=no, toolbar=no, status=no, height='+height+', width='+width+', left='+left+', top='+top);
    
	if (window.focus)
		SmallWin.focus();

}