﻿var globalVariable;
var popupStatus = 0;
var flag = 0;

//Apply Popup window using css and jquery
//loading popup with jQuery magic!
function loadMattsPopup(){
	//loads popup only if it is disabled
	if(popupStatus==0){
		$("#mainbackground").css({
			"opacity": "0.2",
			"filter": "alpha(opacity = 20)"
			
		});
		$("#backgroundPopup").css({
			"opacity": "0.7"
		});
		$("#backgroundPopup").fadeIn("slow");
		$("#popupContact").fadeIn("slow");
		popupStatus = 1;
	}
}

//disabling popup with jQuery magic!
function disableMattsPopup(){
	//disables popup only if it is enabled
	if(popupStatus==1){
		$("#mainbackground").css({
			"opacity": ""			
			
		});
		$("#backgroundPopup").fadeOut("slow");
		$("#popupContact").fadeOut("slow");
		popupStatus = 0;
	}
}

//centering popup
function centerMattsPopup(){
//New code added on 3 sep

var appname=navigator.appName;
	//document.writeln(appname);
	var windowWidth;
	var windowHeight;
	if (appname=="Microsoft Internet Explorer")
	{
		if (document.body && document.body.offsetWidth) {
			windowWidth = document.body.offsetWidth;
			windowHeight = document.body.offsetHeight;
			}
			if (document.compatMode=='CSS1Compat' &&
			    document.documentElement &&
			    document.documentElement.offsetWidth ) {
				windowWidth = document.documentElement.offsetWidth;
				windowHeight = document.documentElement.offsetHeight;
			}
	}
	else
	{
	 windowWidth = window.innerWidth;//document.documentElement.clientWidth;
	 windowHeight = window.innerHeight;//document.documentElement.clientHeight;
	}	 
	
	var popupHeight = $("#popupContact").height();
	var popupWidth = $("#popupContact").width();
	
	// Getting position from Top
	var topMenu = document.getElementById("topMenu");
		
	var posX = 0;
    var posY = 0;
             
    while(topMenu != null){
      posX += topMenu.offsetLeft;
      posY += topMenu.offsetTop;
      topMenu = topMenu.offsetParent;
    }
	
	//var mainDiv= document.getElementById("mainDiv").width;
	
	//centering
	$("#popupContact").css({					
		"top": posY,		
		//"left": windowWidth/3-((popupWidth/3))
		"left": (990/2),		
		"margin-left":-(popupWidth/2)
	});
	//only need force for IE6
	
	$("#backgroundPopup").css({
		"height": windowHeight,
		"width":windowWidth
	});
	
}



 $(document).ready(function(){
	
	
	//CLOSING POPUP
	//Click the x event!
	$("#popupContactClose").click(function(){
		disableMattsPopup();
		document.getElementById('iframeOpen').style.height='230px';
		document.getElementById('iframeOpen').style.width='490px';
		document.getElementById('popupContact').style.width='490px';
	});
	//Click out event!
	$("#backgroundPopup").click(function(){
		disableMattsPopup();
	});
	//Press Escape event!
	$(document).keypress(function(e){
		if(e.keyCode==27 && popupStatus==1){
			disableMattsPopup();
		}
	});
	
	/*if (flag == 1) {
		var name;
		var path;
		//debugger;
		flag = 2;
		name = window.location.href;
		path = name.substring(0,name.indexOf("?"))
		//window.location.href = path;
		//window.location.reload();
	}*/
	//window.location.reload();
});

	//CLOSING POPUP

function getQueryVariable(variable) {     
var query = window.location.search.substring(1);     
var vars = query.split("&");     
for (var i = 0; i < vars.length; i++) 
{         
var pair = vars[i].split("=");         
if (pair[0] == variable) 
{             
return pair[1];         
}     
}     
return null; 
}
	
function OpenMattsPopUp()
{   
        
	  	centerMattsPopup();
		//load popup
		loadMattsPopup();
		document.getElementById("iframeOpen").src="/includes/MattsMention.htm" ;
}


	    
function OpenPopUpM(file)
{   	
       
	   this.parent.document.getElementById("iframeOpen").src="/includes/MattsMention.htm?file=" + file;
		
}






