﻿
//0 means disabled; 1 means enabled;
var popStatus = 0;
var popAccepted = 0;
var popImportant = 0;

function IsIE6() {
    return ($.browser.msie && parseInt($.browser.version, 10) < 7);
}

//loading popup with jQuery magic!
function loadPopup() {
    if (popStatus == 0) {
        var popupCloserOffsetLeft = parseInt($("#popupMedicalOuter #popupCloser a img").css("width")) - (parseInt($("#popupMedical").css("padding-left")) + parseInt($("#popupMedical").css("padding-right")));
        $("#backgroundPopup").css({ "opacity": "0.7" });
        $("#popupMedical div.roundedcornersprite").css({ "opacity": "0.7" });

        $("#backgroundPopup").fadeIn("slow");
        $("#popupMedical").fadeIn("slow");
        $("#popupMedicalOuter #popupCloser").css("top", parseFloat($("#popupMedical").css("top")) - 48).css("left", parseFloat($("#popupMedical").css("left")) + parseFloat($("#popupMedical").css("width")) - popupCloserOffsetLeft);
        $("#popupMedicalOuter #popupCloser").show(); // fadeIn("slow");

        //fix for citybondhome - pop was displayed over/below the footer when position is set to absolute (from centering function)
        //set z-index of canvas to z-index of popupMedical to display it above the background div
        if (!IsIE6()) {
            $("#popupMedical").css("position", "fixed");
            $("#popupMedicalOuter #popupCloser").css("position", "fixed");
        }

        popStatus = 1;
    }
}

//disabling popup with jQuery magic!
function disablePopup(){
	if(popStatus==1){
	    $("#backgroundPopup").fadeOut("slow");
	    $("#popupMedicalOuter #popupCloser").fadeOut("slow"); $("#popupMedicalOuter #popupCloser").hide();
		$("#popupMedical").fadeOut("slow");
		popStatus = 0;
	}
}

//centering popup
function centerPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupMedical").height();
	var popupWidth = $("#popupMedical").width();
	//centering
	
	$("#popupMedical").css({
		"position": "fixed",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"background-color":"white"
		
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}

function loadAcceptedPopup(){
	//loads popup only if it is disabled
	if(popAccepted==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupAccepted").fadeIn("slow");
		popAccepted = 1;
	}
}

function disableAcceptedPopup(){
	//disables popup only if it is enabled
	if(popAccepted==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#popupAccepted").fadeOut("slow");
		popAccepted = 0;
	}
}

//centering popup
function centerAcceptedPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#popupAccepted").height();
	var popupWidth = $("#popupAccepted").width();
	//centering
	$("#popupAccepted").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"background-color":"white"
		
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
}

function loadImportantPopup(){
	//loads popup only if it is disabled
	if(popAccepted==0){
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#ImportantInfoId").fadeIn("slow");
		popImportant = 1;
	}
}

function disableImportantPopup(){
	//disables popup only if it is enabled
	if(popImportant==1){
		$("#backgroundPopup").fadeOut("slow");
		$("#ImportantInfoId").fadeOut("slow");
		popImportant = 0;
	}
}

//centering popup
function centerImportantPopup(){
	//request data for centering
	var windowWidth = document.documentElement.clientWidth;
	var windowHeight = document.documentElement.clientHeight;
	var popupHeight = $("#ImportantInfoId").height();
	var popupWidth = $("#ImportantInfoId").width();
	//centering
	$("#ImportantInfoId").css({
		"position": "absolute",
		"top": windowHeight/2-popupHeight/2,
		"left": windowWidth/2-popupWidth/2,
		"background-color":"white"
		
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight
	});
	
}

var obj = null;

function checkHover() {
	if (obj) {
		obj.find('div').fadeOut('fast');	
	} //if
} //checkHover

//CONTROL EVENTS IN jQuery
$(document).ready(function () {

    //LOADING POPUP
    //Click the button event!
    $("#button").click(function () {
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });

    $("#button2").click(function () {
        //centering with css
        centerPopup();
        //load popup
        loadPopup();
    });

    $("#button3").click(function () {
            //centering with css
            centerPopupButton3();
            //load popup
            loadPopup();
    });

    //centering popup for Button3 
    function centerPopupButton3() {//request data for centering
        var windowWidth = document.documentElement.clientWidth;
        var windowHeight = document.documentElement.clientHeight;
        //If PQE and IE set height as 150. Added as a fix for IE where opening modaldialog was causing iframe to appear with scrollbars
        var popupHeight = $("#popupMedical").height();
        //alert($("#uqmd").width());
        var popupWidth = $("#popupMedical").width();
        var scrollTop = $(window).scrollTop();
        if (scrollTop == undefined) scrollTop = 0;
        //seoblurbandcontrolcontainer is present only if the control is shown in index page, but not for PQE

        //"position": "absolute",
        //"position": "absolute",
        $("#popupMedical").css({
            "position": "absolute",
            "top": windowHeight / 2 - popupHeight / 2 + scrollTop,
            "left": windowWidth / 2 - popupWidth / 2
        });

        if ($.browser.msie && parseInt($.browser.version, 10) < 7)
            windowHeight = document.body.clientHeight;

        $("#backgroundPopup").css({
            "height": windowHeight,
            "width": windowWidth
        });
    }

    //CLOSING POPUP
    //Click the x event!
    $("#popupMedicalClose").click(function () {
        disablePopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function () {
        disablePopup();
    });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popStatus == 1) {
            disablePopup();
        }
    });

    $("#Accepted").mouseover(function () {
        //centering with css
        centerAcceptedPopup();
        //load popup
        loadAcceptedPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#popupAcceptedClose").click(function () {
        $("#popupAccepted").slideUp();
    });
    //Click out event!
    $("#backgroundPopup").click(function () {
        disableAcceptedPopup();
    });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popAccepted == 1) {
            disableAcceptedPopup();
        }
    });

    $("#ImportantInfo").mouseover(function () {
        //centering with css
        centerImportantPopup();
        //load popup
        loadImportantPopup();
    });

    //CLOSING POPUP
    //Click the x event!
    $("#ImportantInfoClose").click(function () {
        disableImportantPopup();
    });
    //Click out event!
    $("#backgroundPopup").click(function () {
        disableImportantPopup();
    });
    //Press Escape event!
    $(document).keypress(function (e) {
        if (e.keyCode == 27 && popImportant == 1) {
            disableImportantPopup();
        }
    });

});

$(document).ready( function() {
    
        //$('#acceptedConditons').listnav();
        $('#acceptedConditons').listnav({ 
        initLetter: 'a', 
        includeNums : false, //0-9 along with alphabets
        includeAll: true, //option to view All
        flagDisabled: true, //Show alphabets which do not have any item to display in grey color
        noMatchText: '<font color=red>No matches found, please click another letter.</font>', 
        showCounts: false //Show item count on top of each alphabet, on mouse over
        //,cookieName: 'my-main-list'//, 
        //,onClick: function(letter){ alert('You clicked ' + letter); } 
    });

 });

