// JHD Popup for Lauren Frances
var init_pp = '';
var init_pt = '';


$(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"
		});
		
	}
	
	init_pp = function() {
		
		//Function to Animate Selection (Ladies and Lads Buttons)
		function init_sel() {
			
			//Set Selection Settings
			$('#pp_selection').css({
				"display" : "",
				"position" : "fixed",
				"opacity" : ".0",
				"background-color" : "#fff",
				"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"
			});
			
			//Show Buttons
			$("#pp_selection").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" : "#000000"
		});
		
		//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();
		});
	}
	
	
	init_pt = function() {
		
		//Function to Animate Selection (Ladies and Lads Buttons)
		function init_sel() {
			
			//Set Selection Settings
			$('#pp_content').css({
				"display" : "",
				"position" : "fixed",
				"opacity" : ".0",
				"background-color" : "#fff",
				"filter" : "alpha(opacity = 0)",
			});
			
			//Assign Centering Variables//Fix pp_selection			
			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"
			});
			
			//Show Buttons
			$("#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" : "#000000"
		});
		
		//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();
		});
	}
	
		
	close_pp = function() {
		
		function disable_pp() {
			
			//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();});
		
	}

	close_pp2 = function() {
		
		function disable_pp() {
			
			//Disable Form
			$('#pp_selection').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_selection").animate({
			"opacity" : "0",
			"filter" : "alpha(opacity = 0)"
		}, 600, 'linear', function() {closebg();});
		
	}


	function toggleLabel() {
		var input = $(this);
		setTimeout(function() {
			var def = input.attr('title');
			if (!input.val() || (input.val() == def)) {
				input.prev('span').css('visibility', '');
				if (def) {
					var dummy = $('<label></label>').text(def).css('visibility','hidden').appendTo('body');
					input.prev('span').css('margin-left', dummy.width() + 3 + 'px');
					dummy.remove();
				}
			} else {
				input.prev('span').css('visibility', 'hidden');
			}
		}, 0);
	};
	
	function resetField() {
		var def = $(this).attr('title');
		if (!$(this).val() || ($(this).val() == def)) {
			$(this).val(def);
			$(this).prev('span').css('visibility', '');
		}
	};
	
	$('input, textarea').live('keydown', toggleLabel);
	$('input, textarea').live('paste', toggleLabel);
	$('select').live('change', toggleLabel);
	
	$('input, textarea').live('focusin', function() {
		$(this).prev('span').css('color', '#ccc');
	});
	$('input, textarea').live('focusout', function() {
		$(this).prev('span').css('color', '#999');
	});
	
	$(function() {
		$('input, textarea').each(function() { toggleLabel.call(this); });
	});


});


function valif(form) {
	switch(form) {
		case "suggest_charity":
		
			if (document.suggestion.fname.value == '') {
				alert('Please tell us your first name');
				return false;
			}
			
			if (document.suggestion.lname.value == '') {
				alert('Please tell us your last name');
				return false;
			}
			
			if (document.suggestion.email.value == '') {
				alert('Please tell us your email address');
				return false;
			}
			
			if (document.suggestion.birthday.value == '') {
				alert('Please tell us your birth day');
				return false;
			}
			
			if (document.suggestion.birthmonth.value == '') {
				alert('Please tell us your birth month');
				return false;
			}
			
			if (document.suggestion.birthyear.value == '') {
				alert('Please tell us your birth year');
				return false;
			}
			
			if (document.suggestion.sex.value == '') {
				alert('Please tell us your gender');
				return false;
			}			
			
			if (document.suggestion.zip.value == '') {
				alert('Zip field is blank!');
				return false;
			}
			
			if (document.suggestion.charity_name.value == '') {
				alert('Please tell us your charity suggestion');
				return false;
			}
			
			document.suggestion.submit();
			
		break;
	}
}
