/*
Pop Class - renders a inline popup window using Divs
	--basic structure of divs required
		<div id="pop_screen"></div> (blank out window)
		<div id="pop"></div> (pop up content)
--------------------------------------------------------------------------------------------------------

V1.00 - 23/02/10 AC
- Created For Simple PopUps
*/

function Pop() {
	this.DivPopScreen = "pop_screen";
	this.DivPop = "pop";
	
	this.CreatePop = CreatePop;
	this.SetDivPopScreen = SetDivPopScreen;
	this.SetDivPop = SetDivPop;
	this.WindowPop = WindowPop;
	this.WindowPopResize = WindowPopResize;
}
	
	function CreatePop(id){
		var screenCreated = false;
		var popCreated = false;
		
		while (screenCreated!=true){
			if(document.getElementById(id+'_screen') == null){
				var divpopscreen = document.createElement('div');
				divpopscreen.setAttribute('id', id +'_screen');
				divpopscreen.setAttribute('className', 'pop_screen');
				document.body.appendChild(divpopscreen);
				this.DivPopScreen = id +'_screen';
				screenCreated=true;
			}else{
				id = id+'-'+Math.floor(Math.random()*11);
			}
		}
		
		while (popCreated!=true){
			if(document.getElementById(id) == null){
				var divpop = document.createElement('div');
				divpop.setAttribute('id', id);
				divpopscreen.setAttribute('className', 'pop');
				document.body.appendChild(divpop);
				this.DivPop = id;
				popCreated=true;
			}else{
				id = id+'-'+Math.floor(Math.random()*11);
			}
		}	
		
		if(screenCreated){document.getElementById(this.DivPopScreen).className ='pop_screen';}
		if(popCreated){document.getElementById(this.DivPop).className ='pop';}
		
	}

	function SetDivPopScreen(id){
		this.DivPopScreen = id;
	}
	
	function SetDivPop(id){
		this.DivPop = id;
	}

	function WindowPop(action){
		var screenEnabled=false;
		var popEnabled=false;
		if(document.getElementById(this.DivPopScreen) != null){
			screenEnabled=true;
		}
		if(document.getElementById(this.DivPop) != null){
			popEnabled=true;
		}
		
		if (action=="show"){
			if(screenEnabled){document.getElementById(this.DivPopScreen).style.display='block';}
			if(popEnabled){document.getElementById(this.DivPop).style.display='block';}
		}else if (action=="hide"){
			if(screenEnabled){document.getElementById(this.DivPopScreen).style.display='none';}
			if(popEnabled){document.getElementById(this.DivPop).style.display='none';}
		}else{
			if(document.getElementById(this.DivPopScreen).style.display=="none"){
				if(screenEnabled){document.getElementById(this.DivPopScreen).style.display='block';}
				if(popEnabled){document.getElementById(this.DivPop).style.display='block';}
			}else{
				if(screenEnabled){document.getElementById(this.DivPopScreen).style.display='none';}
				if(popEnabled){document.getElementById(this.DivPop).style.display='none';}
			}
		}
	}
	
	function WindowPopResize(width, height){
		if (width && height && document.getElementById(this.DivPop) != null){
			var top=0-(height/2) + 'px';
			var left=0-(width/2) + 'px';
			width=width+'px'
			height=height+'px'
			document.getElementById(this.DivPop).style.width=width;
			document.getElementById(this.DivPop).style.height=height;
			document.getElementById(this.DivPop).style.marginLeft=left;
			document.getElementById(this.DivPop).style.marginTop=top;
			document.getElementById(this.DivPop).style.top='50%';
			document.getElementById(this.DivPop).style.left='50%';
		}else{
			alert('Error Resizing Popup. Please enter a width and height');
		}
	}
