/************************
* Author: Todd Langford
* Copyright 2011
************************/

/* Initialize Variables */
var popupStatus = 0;

function loadPopup(id) {  
	if(popupStatus==0) {  
		$("#backgroundPopup").css({ "opacity": "0.7" });  
		$("#backgroundPopup").fadeIn("fast");  
		$("#"+id).fadeIn("fast");  
		popupStatus = 1;  
		$("#backgroundPopup").click(function() { disablePopup(id); });
	} 
}  

function disablePopup(id) {  
	if(popupStatus==1){  
		$("#backgroundPopup").fadeOut("fast");  
		$("#"+id).fadeOut("fast");  
		popupStatus = 0;  
	}  
}  

function centerPopup(id) {  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight; 
	var popupHeight = $("#"+id).height(); 
	var popupWidth = $("#"+id).width(); 
	var topvar;
	if (popupHeight > windowHeight) { 
		$("#"+id).height("90%");
		topvar = 20;
		//alert('Bigger than window');
	} else {
		topvar = windowHeight/2-popupHeight/2;
		//alert('Less than window');
	}
	//alert("topvar: "+topvar);
	if (popupWidth > windowWidth) popupWidth = windowWidth;
	$("#"+id).css({  
		"position": "fixed",  
		"top": topvar,  
		"left": windowWidth/2-popupWidth/2  
	});  
	$("#backgroundPopup").css({  
		"height": windowHeight  
	});  
}  

function openPopup(id) {
	centerPopup(id);
	loadPopup(id);
}

//Display innerHTML of id
function dspHTML(html,id) {
	document.getElementById(id).innerHTML = html;
}

//Hide or Show Divs
function switchit(divID) {
	
	var item = document.getElementById(divID);
	if (item) {
		item.style.display=(item.style.display=='none')?'block':'none';
	}
}

function hidediv(divID) {
	
	if (document.getElementById(divID)) 
	{
		var item = document.getElementById(divID);
		item.style.display='none';
	}

}

function showdiv(divID) {
	
	if (document.getElementById(divID)) 
	{
		var item = document.getElementById(divID);
		item.style.display='block';
	}
}

var popupStatus = 0;



function openPopup2(id) {
	centerPopup(id);
	loadPopup(id);
}

//Display innerHTML of id
function dspHTML(html,id) {
	document.getElementById(id).innerHTML = html;
}

//Hide or Show Divs
function switchit(divID) {
	
	var item = document.getElementById(divID);
	if (item) {
		item.style.display=(item.style.display=='none')?'block':'none';
	}
}

function hidediv(divID) {
	
	if (document.getElementById(divID)) 
	{
		var item = document.getElementById(divID);
		item.style.display='none';
	}

}

function showdiv(divID) {
	
	if (document.getElementById(divID)) 
	{
		var item = document.getElementById(divID);
		item.style.display='block';
	}
}

