function remind() {
	alert('For more product information, please login or register as a member.');
	$("#login_email").focus();
}

$(document).ready(function () {

	$("#loginform").submit(function () {
		return formvalid();
	});
	
	$("#regform").submit(function () {
		return regvalid();
	});
	
	$("#forgetform").submit(function () {
		return forgetformvalid();
	});

});

function forgetformvalid() {
	
	if ($("#email").val() == "") {
		alert('Please input your e-mail address');
		return false;
	} else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#email").val())){
			
		} else {
			alert("Invalid E-mail Address! Please re-enter.");
			return false;
		}
	}
	
	return true;
	
}

function formvalid() {
	
	if ($("#login_email").val() == "") {
		alert('Please input your e-mail address');
		return false;
	} else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#login_email").val())){
			
		} else {
			alert("Invalid E-mail Address! Please re-enter.");
			return false;
		}
	}
	if($("#login_password").val() == "") {
		alert("Please input your password");
		$("#login_password").focus();
		return false;
	}
	
	return true;
	
}

function regvalid() {
	
	if($("#name").val() == "") {
		alert("Please input your name");
		$("#name").focus();
		return false;
	}
	if ($("#email").val() == "") {
		alert('Please input your email');
		return false;
	} else {
		if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test($("#email").val())){
			
		} else {
			alert("Invalid E-mail Address! Please re-enter.");
			return false;
		}
	}
	return true;
	
}

function createPopUp(source) {
	
	var opacity = 0;
	var showHeader = false;
		
	if ($('#lightwindow_overlay').length == 0)  {
		
		$("body").append('<div id="lightwindow_overlay" class="lightwindow_overlayBG"></div>');	
		
		/*
		$('#lightwindow_overlay').hide().addClass("lightwindow_overlayBG")
		.css('opacity', opacity)
		.fadeIn();
		*/

	} else {
	
		$('#lightwindow_overlay').show();
	
	}
	

	if ($('#lightwindow_container').length == 0) {
	
		var content = '<div id="lightwindow_container">'

		content += '<div id="lightwindow_body"></div></div>';
	
		$("body").append(content);
	
	}

	$('#lightwindow_close').addClass("lightwindow_close").click(function() { removeAll() });

	$('#lightwindow_container').hide();
	
	
	$.ajax({
		type: "GET",
		url: source,
		async: false,
		cache: false,
		success: function(response){

			//$('#lightwindow_overlay').remove();

			$('#lightwindow_body').html(response);
			
			$('#lightwindow_container .lightwindow_close').click(function() { removeAll() });
			
			$('#lightwindow_container').css({
				top:	getPageScroll()[1] + (getPageHeight() / 10),
				left:	($(window).width() - $('#lightwindow_container').width()) / 2
			}).show();

		}
	});
	
}

function removeAll() {
	$('#lightwindow_container').hide();
	$('#lightwindow_overlay').hide();
}

// getPageScroll() by quirksmode.com
function getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	return new Array(xScroll,yScroll) 
}

// Adapted from getPageSize() by quirksmode.com
function getPageHeight() {
	var windowHeight
	if (self.innerHeight) {	// all except Explorer
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowHeight = document.body.clientHeight;
	}	
	return windowHeight
}
