﻿// JavaScript Document
function SetBackground(bdiv, subdiv, divheight) {
	var reg_height = $(bdiv).height() - divheight;
	$(subdiv).height(reg_height);
	if (reg_height > 0) {
		$(bdiv).css("margin-top", reg_height * (-1));
	} else
		$(bdiv).css("margin-top", "0");
}
$.fn.center = function () {
	$(this).css("left", ( $(window).width() - $(this).width() ) / 2+$(window).scrollLeft() + "px");
	$(this).css("top", ( $(window).height() - $(this).height() ) / 2+$(window).scrollTop() + "px");
	return $(this);
}
$( function() {
	$("#personal-account,#laydown").click( function() {
		$("#personal-layout").css("display", "block");
		$("#closelaydown").css("display", "block");
		// $("a.arrow").css("background","url(../images/downArrow.jpg) no-repeat
		// right 4px");
		});

	$("#closelaydown").click( function() {
		$("#personal-layout").css("display", "none");
		$("#closelaydown").css("display", "none");
		// $("a.arrow").css("background","url(../images/login-arrow.gif)
		// no-repeat right 4px");
		});
	/*
	 * $("#why-need").hover( function(){
	 * $("#reg-dm-pop").css("display","block"); }, function(){
	 * $("#reg-dm-pop").css("display","none"); });
	 */
	$("#why-need").hover( function() {
		var p = $(this).offset();
		$("#reg-pop").show().css({left:p.left,top:p.top});
	}, function() {
		$("#reg-pop").hide();
	});
	$("#reg-pop").hover( function() {
		$(this).show();
	}, function() {
		$(this).hide();
	});
	/*
	 * $("#why-need").mousemove( function(){
	 * $("#reg-edm-pop").css("display","block"); }); $("#why-need").mouseout(
	 * function(){ $("#reg-edm-pop").css("display","none"); });
	 */
	// SetBackground("#regContainer","#regContainer-content","478");
	// SetBackground("#reg-dm","#reg-dm-content","411");
	// SetBackground("#reg-login","#reg-login-content","411");
	$("#returnforgot").click( function() {
		$("#regforget").css("display", "block");
		$("#reglogin").css("display", "none");
	});

	$("#returnlogin").click( function() {
		$("#reglogin").css("display", "block");
		$("#regforget").css("display", "none");
	});
	
	var loadSuccess = false;
	
	//asthma mmc clinical overview popup
	$("#mmcClinicalFlashShow").click(function(){
		showFlash(mmcswf, mmcswfWidth, mmcswfHeight, 
				mmcPopupId, mmcOverlayId, containerId, containerParentId, flashId, flashvars);
	});
	//asthma mmc clinical overview close
	$("a[forer='mmcClinicalClose']").click(function(){
		$("#mmcPopup, #mmc-overlay").hide();
		if (loadSuccess) {
			$("#mmcFlash").empty();
		}
	});
	
	//asthma mmc vprint popup
	$("#mmcVPrintFlashShow").click(function(){
		showFlash2(mmcswfVPrint, mmcswfWidthVPrint, mmcswfHeightVPrint, 
				mmcPopupIdVPrint, mmcOverlayIdVPrint, containerIdVPrint, 
				containerParentIdVPrint, flashIdVPrint, flashvarsVPrint, paramsVPrint);

		//remove following statement to remove ISI flash
//		showFlash2(mmcswfISI, mmcswfWidthISI, mmcswfHeightISI, 
//				mmcPopupIdISI, mmcOverlayIdISI, containerIdISI, 
//				containerParentIdISI, flashIdISI);
	});
	$("#mmcVPrintJonathanFlashShow").click(function(){
		showFlash2(mmcswfJonathanVPrint, mmcswfWidthVPrint, mmcswfHeightVPrint, 
				mmcPopupIdVPrint, mmcOverlayIdVPrint, containerIdVPrint, 
				containerParentIdVPrint, flashIdVPrint, flashvarsVPrint, paramsJonathanVPrint);

		//remove following statement to remove ISI flash
//		showFlash2(mmcswfISI, mmcswfWidthISI, mmcswfHeightISI, 
//				mmcPopupIdISI, mmcOverlayIdISI, containerIdISI, 
//				containerParentIdISI, flashIdISI);
	});
	
	//asthma mmc vprint close
	$("a[forer='vPrintClose']").click(function(){
		$("#mmcPopup2, #mmc-overlay2").hide();
		if (loadSuccess) {
			$("#mmcFlash-vprint").empty();
			$("#mmcFlashISI").empty();
		}
	});
	
	//asthma efficacy chart popup
	$("#mmcFlashShow,#mmcFlashShowImg").click(function(){
		showFlash(mmcswf2, mmcswfWidth2, mmcswfHeight2, 
				mmcPopupId2, mmcOverlayId2, containerId2, containerParentId2, flashId2);
		showFlash(mmcswf, mmcswfWidth, mmcswfHeight, 
				mmcPopupId, mmcOverlayId, containerId, containerParentId, flashId);
	});
	//asthma efficacy chart close
	$("a[forer='asthmaEfficacyChartClose']").click(function(){
		$("#mmcPopup, #mmc-overlay").hide();
		if (loadSuccess) {
			$("#mmcFlash2").empty();
			$("#mmcFlash").empty();
		}
	});
	
	//asthma efficacy edetail popup
	$("#asthmaMmcFlashShow1,#asthmaMmcFlashShowImg1").click(function() {
		showFlash(mmcswf1, mmcswfWidth1, mmcswfHeight1, 
				mmcPopupId1, mmcOverlayId1, containerId1, containerParentId1, flashId1, flashvars1);
	});
	//asthma efficacy edetail close
	$("a[forer='asthmaEfficacyEdetail']").click(function(){
		$("#mmcPopup1, #mmc-overlay").hide();
		if (loadSuccess) {
			$("#mmcFlash1").empty();
		}
	});
	
	//copd efficacy data chart popup
	$("#copdEfficacyFlashShow,#copdEfficacyFlashShowImg").click(function(){
		showFlash(mmcswf2, mmcswfWidth2, mmcswfHeight2, 
				mmcPopupId2, mmcOverlayId2, containerId2, containerParentId2, flashId2);
		showFlash(mmcswf, mmcswfWidth, mmcswfHeight, 
				mmcPopupId, mmcOverlayId, containerId, containerParentId, flashId);
	});
	//copd efficacy data chart close
	$("a[forer='copdEfficacyData']").click(function(){
		$("#mmcPopup, #mmc-overlay").hide();
		if (loadSuccess) {
			$("#mmcFlash2").empty();
			$("#mmcFlash").empty();
		}
	});
	
	function showFlash(mmcswfParam, mmcswfWidthParam, mmcswfHeightParam, mmcPopupIdParam, 
			mmcOverlayIdParam, containerIdParam, 
			containerParentIdParam, flashIdParam, flashvarsParam, flashParams) {

		$("#" + containerParentIdParam).append("<div id='" + containerIdParam + "'></div>");
		var tempFlashvars = {};
		if (flashvarsParam != null) {
			tempFlashvars = flashvarsParam;
		}
		var tempParams = { allowscriptaccess:"always", menu:"false" };
		if (flashParams != null) {
			tempParams = flashParams;
		}
		swfobject.embedSWF(mmcswfParam, containerIdParam, mmcswfWidthParam, mmcswfHeightParam, "9.0.28",
				"swf/expressInstall.swf", tempFlashvars, tempParams, 
				{ id:flashIdParam, wmode:"transparent" }, 
				function(object) { if (object.success) {loadSuccess = true;}} );
					
		var mmcWidth = $(document).width();
		var mmcHeight = $(document).height();
		var mmcLeft = mmcWidth/2 - 420;
		
		if ($.browser.msie && ($.browser.version == "6.0")) {
			mmcWidth = mmcWidth - 21;
			var mmcLeft = mmcWidth/2 - 420;
		}
		if ( $("#" + mmcPopupIdParam).height() > $(window).height() ) { // height of layer is more than viewport
			$("#" + mmcPopupIdParam).center().css({"position":"absolute","top":$(window).scrollTop()}).show();
		} else { // height of layer is less than viewport
			$("#" + mmcPopupIdParam).center().css({"position":"absolute"}).show();
		}
		$("#" + mmcOverlayIdParam).css({"width":mmcWidth, "height":mmcHeight}).show();
		//if ($("#" + containerParentIdParam).children().length == 0) {
			
		//}
	}
	
	function showFlash2(mmcswfParam, mmcswfWidthParam, mmcswfHeightParam, mmcPopupIdParam, 
			mmcOverlayIdParam, containerIdParam, 
			containerParentIdParam, flashIdParam, flashvarsParam, flashParams) {

		$("#" + containerParentIdParam).append("<div id='" + containerIdParam + "'></div>");
		var tempFlashvars = {};
		if (flashvarsParam != null) {
			tempFlashvars = flashvarsParam;
		}
		var tempParams = { allowscriptaccess:"always", menu:"false" };
		if (flashParams != null) {
			tempParams = flashParams;
		}
		swfobject.embedSWF(mmcswfParam, containerIdParam, mmcswfWidthParam, mmcswfHeightParam, "9.0.28",
				"swf/expressInstall.swf", tempFlashvars, tempParams, 
				{ id:flashIdParam, wmode:"transparent" }, 
				function(object) { if (object.success) {loadSuccess = true;}} );
		$("#externalDiv").show();
	}	
	
	function jsPopWindow() {
		var mmcWidth = $(document).width();
		var mmcHeight = $(document).height();
		var mmcLeft = mmcWidth/2 - 420;
		
		if ($.browser.msie && ($.browser.version == "6.0")) {
			mmcWidth = mmcWidth - 21;
			var mmcLeft = mmcWidth/2 - 420;
		}
		$("#mmcPopup, #mmc-overlay").show();
		$("#mmcPopup").css({"position":"absolute", "left":mmcLeft, "top":"0"});
		$("#mmc-overlay").css({"width":mmcWidth, "height":mmcHeight});
	}
	
	//$("#mmc-overlay").click(function(){
		//$(this).hide();
		//$("#mmcPopup").hide();
	//});
});
