// JHD Popup for Lauren Frances

$(document).ready(function(){ 
			
	//Retreive Functions
	
	function jht_getWinHeight() {
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
			 return window.innerHeight;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
			 return document.documentElement.clientHeight;
			}
		}
	}
	
	
	function jht_getWinWidth() {
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") {
			 return window.innerWidth;
			}
			if (navigator.appName.indexOf("Microsoft")!=-1) {
			 return document.documentElement.clientWidth;
			}
		}
	}
	
	function jht_getBoxHeight(boxid) {
		return document.getElementById(boxid).clientHeight;
	}
	
	function jht_getBoxWidth(boxid) {
		return document.getElementById(boxid).clientWidth;
	}
	
	
	
	//Window Resize Function
	function jht_resize() {		
		
		//Fix pp_selection			
		var bw = jht_getWinWidth();
		var bh = jht_getWinHeight();
		var rw = jht_getBoxWidth("pp_selection");
		var rh = jht_getBoxHeight("pp_selection");
		
		var left_space = ((bw - rw)/2);
		var top_space = ((bh - rh)/2);
		
		$('#pp_selection').css({
			"left" : left_space+"px",
			"top" : top_space+"px"
		});
		
		
		//Fix pp_content			
		var bw = jht_getWinWidth();
		var bh = jht_getWinHeight();
		var rw = jht_getBoxWidth("pp_content");
		var rh = jht_getBoxHeight("pp_content");
		
		var left_space = ((bw - rw)/2);
		var top_space = ((bh - rh)/2);
		
		$('#pp_content').css({
			"left" : left_space+"px",
			"top" : top_space+"px"
		});
		
		
		//Fix Background Size
		$('#pp_background').css({
			"width" : jht_getWinWidth()+"px",
			"height" : jht_getWinHeight()+"px",
			"position" : "fixed"
		});
		
	}
	
	function init_pp() {
		
		//Function to Animate Selection (Ladies and Lads Buttons)
		function init_sel() {
			
			//Set Selection Settings
			$('#pp_selection').css({
				"display" : "",
				"position" : "absolute",
				"opacity" : ".0",
				"filter" : "alpha(opacity = 0)",
			});
			
			//Assign Centering Variables//Fix pp_selection			
			var bw = jht_getWinWidth();
			var bh = jht_getWinHeight();
			var rw = jht_getBoxWidth("pp_selection");
			var rh = jht_getBoxHeight("pp_selection");
			
			var left_space = ((bw - rw)/2);
			var top_space = ((bh - rh)/2);
			
			//Center Selection Box
			$('#pp_selection').css({
				"top" : top_space+"px",
				"left" : left_space+"px"
			});
			
			
			//Assign Button Functions to Begin Showing the Form
			$("#ladies_click").unbind('click');
			$("#ladies_click").click(function() {
				close_sel(0);
			});
			
			$("#lads_click").unbind('click');
			$("#lads_click").click(function() {
				close_sel(1);
			});

			
			//Show Buttons
			$("#pp_selection").animate({
				"opacity" : "1",
				"filter" : "alpha(opacity = 100)"
			}, 600);
			
		}
		
		//Function to Close Selection, and Open Forn (Hide Ladies and Lads Buttons)
		function close_sel(type) {
			//Hide Buttons
			$("#pp_selection").animate({
				"opacity" : "0",
				"filter" : "alpha(opacity = 0)"
			}, 600, 'linear', function() {showForm(type);});
		}
		
		//Function to Animate Form Sequence (Full form)
		function showForm(type) {
			
			//Set Form Settings
			$('#pp_content').css({
				"display" : "",
				"position" : "absolute",
				"opacity" : ".0",
				"filter" : "alpha(opacity = 0)"
			});
			
			//Assign Centering Variables//Fix pp_content			
			var bw = jht_getWinWidth();
			var bh = jht_getWinHeight();
			var rw = jht_getBoxWidth("pp_content");
			var rh = jht_getBoxHeight("pp_content");
			
			var left_space = ((bw - rw)/2);
			var top_space = ((bh - rh)/2);
			
			//Center Selection Box
			$('#pp_content').css({
				"top" : top_space+"px",
				"left" : left_space+"px"
			});
			
			//Hide Unwanted Info (Male or Female)
			if (type == 0) {
				$('#pp_male').css({
					"display" : "none"
				});
			} else {					
				$('#pp_female').css({
					"display" : "none"
				});
			}
			
			//Validate Forms
			$("form#ppform1").submit(function(){
				  var email = $("input#email1").val();
				  if (email==""||email=="Email")
				  {
						document.getElementById("errors1").innerHTML = 'Please enter your email address';
						return false;
				  }else if(email.indexOf("@") < 1){ // very basic check if email address entered is valid
						document.getElementById("errors1").innerHTML = 'Please enter a valid email address';
						return false;				  	
				  }else{
					  close_pp();
					  return true;
				  }
			});
			
			
			$("form#ppform2").submit(function(){
				  var email = $("input#email2").val();
				  if (email==""||email=="Email")
				  {
						document.getElementById("errors2").innerHTML = 'Please enter your email address';
						return false;
				  }else if(email.indexOf("@") < 1){ // very basic check if email address entered is valid
						document.getElementById("errors2").innerHTML = 'Please enter a valid email address';
						return false;				  	
				  }else{
					  close_pp();
					  return true;
				  }
			});
			
			
			//Show Form
			$("#pp_content").animate({
				"opacity" : "1",
				"filter" : "alpha(opacity = 100)"
			}, 600);
		
		}
	
		//Set Background Settings
		$('#pp_background').css({
			"display" : "",
			"width" : jht_getWinWidth()+"px",
			"height" : jht_getWinHeight()+"px",
			"position" : "fixed",
			"opacity" : ".0",
			"filter" : "alpha(opacity = 0)",
			"top" : "0px",
			"left" : "0px",
			"background-color" : "#cf0d80"
		});
		
		//Animate Background Show, and Callback init_sel()
		$("#pp_background").animate({
			"opacity" : ".9",
			"filter" : "alpha(opacity = 90)"
		}, 600, 'linear', function() {init_sel();});
		
		$(window).bind('resize', function() {
			jht_resize();
		});
	}
	
	function close_pp() {
		
		function disable_pp() {
			
			//Disable Selection
			$('#pp_selection').css({
				"display" : "none"
			});
			
			//Disable Form
			$('#pp_content').css({
				"display" : "none"
			});
			
			//Disable BG
			$('#pp_background').css({
				"display" : "none"
			});
			
		}
		
		
		//Function to Hide BG, and then Disable PP
		function closebg() {			
			$("#pp_background").animate({
				"opacity" : "0",
				"filter" : "alpha(opacity = 0)"
			}, 600, 'linear', function() {disable_pp();});
		}
		
		//Hide Form and then Hide Overlay BG
		$("#pp_content").animate({
			"opacity" : "0",
			"filter" : "alpha(opacity = 0)"
		}, 600, 'linear', function() {closebg();});
		
	}
	
	if (start_pp == 1) {
		init_pp();
	}

});
