
//loading the page calls the function initiate

//calls to open the popup window on clicking at a href link
function openPopUp(caption, url) {//function called when the user clicks on a popup a href


	try {

			if(document.getElementById("popUpLayout") === null){
				$("body").append("<div id='popUpLayout'></div><div id='popUpWindow'></div>");
				$("#popUpLayout").click(popUpremove);
			}

    	if(caption===null){caption="";}

		var baseURL;
	   if(url.indexOf("?")!= -1){ //ff there is a query string involved
			baseURL = url.substr(0, url.indexOf("?"));
		}else{
	   		baseURL = url;
	   }

	   		var queryString = url.replace(/^[^\?]+\??/,'');

			//window height and width
			//var width = $(document).width(); // or $(window).width()
			//var	height = $(document).height(); // or $(window).height()
			var width = 400; // or $(window).width()
			var	height = 150; // or $(window).height()
			popUpWIDTH = width;
			popUpHEIGHT = height;
			popUpContentW = popUpWIDTH-10 ;
			popUpContentH = popUpHEIGHT-10;


					if($("#popUpWindow").css("display") != "block"){

						$("#popUpWindow").append("<div id='popUpTitle'><div id='popUpBodyTitle'></div><div id='closePopUpBody'; class='tlink3'><a href='#' id='closePopUpBodyButton'><b>close</b></a></div></div><div id='popUpBodyContent' style='width:"+popUpContentW+"px;height:"+popUpContentH+"px;'></div>");

					}

			$("#closePopUpBodyButton").click(popUpremove);


					$("#popUpBodyContent").load(url ,function(){//url is the html page that we passed in a href of index.html

						popUpposition();
						$("#popUpWindow").css({display:"block"});
					});

	} catch(e) {
		//we need to show the error message if any
	}
}

//function t remove the popup window

function popUpremove() {

	$("#closePopUpBodyButton").unbind("click");
	$("#popUpWindow").fadeOut("fast",function(){$('#popUpWindow,#popUpLayout').trigger("unload").unbind().remove();});

	if (typeof document.body.style.maxHeight == "undefined") {//if IE 6
		$("body","html").css({height: "auto", width: "auto"});
		$("html").css("overflow","");
	}
	document.onkeydown = "";
	document.onkeyup = "";
	return false;
}

//function to set the popup window position on body page.

function popUpposition() {
$("#popUpWindow").css({marginLeft: '-' + parseInt((popUpWIDTH / 2),10) + 'px', width: popUpWIDTH + 'px'});

$.browser.msie6 = $.browser.msie && /MSIE 6\.0/i.test(window.navigator.userAgent) && !/MSIE 7\.0/i.test(window.navigator.userAgent);

	if ( !(jQuery.browser.msie6)) { // take away IE6
		$("#popUpWindow").css({marginTop: '-' + parseInt((popUpHEIGHT / 2),10) + 'px'});
	}
}

