// JavaScript Document

$(document).ready(function(){

	//alert('jquery');
	$('#inc_mainnav li').hover(function() {
		//alert('hover');
		$(this).css({'color':'#686464','border-bottom':'1px solid #8A8384'});
	},function(){
		$(this).css({color:'#4c5c51','border-bottom':'1px dotted #8A8384'});
	
	});
	
	$('#home').click(function() {
		$('#featured').load('includes/inc_home.php');
	});
	
	$('#gallery').click(function() {
		$('#featured').load('includes/inc_gallery.php');
	});
	
	$('#contact').click(function() {
		$('#featured').load('includes/inc_frmjoin.php',function() {$('#username').focus();});
		
	});
	
	$('#video').click(function() {
		$('#featured').load('documentary.php');
	});
	
	$('#btnSubmit').live('click', function() {
		doAddFan();
	});
	
	//<input type="button" name="btnSubmit" value="Send Form" onClick="doAddFan();"/>
	
	$('#home').trigger('click');
	
	//$('#home,#gallery,#contact,#video').css({cursor:'pointer' });
	$('#inc_mainnav li').css({cursor:'pointer' }); 	


});

/*
status  The status bar at the bottom of the window. 
toolbar  The standard browser toolbar, with buttons such as Back and Forward. 
location  The Location entry field where you enter the URL. 
menubar  The menu bar of the window 
directories  The standard browser directory buttons, such as What's New and What's Cool 
resizable Allow/Disallow the user to resize the window. 
scrollbars  Enable the scrollbars if the document is bigger than the window 
height Specifies the height of the window in pixels. (example: height='350') 
width  Specifies the width of the window in pixels. 
*/

function popup(url) 
{
 var width  = 900;
 var height = 700;
 var left   = (screen.width  - width)/2;
 var top    = (screen.height - height)/2;
 var params = 'width='+width+', height='+height;
 params += ', top='+top+', left='+left;
 params += ', directories=no';
 params += ', location=no';
 params += ', menubar=no';
 params += ', resizable=no';
 params += ', scrollbars=yes';
 params += ', status=no';
 params += ', toolbar=no';
 newwin=window.open(url,'windowname5', params);
 if (window.focus) {newwin.focus()}
 return false;
}

function doAddFan() {
	var ecount = 0;
    var url = "includes/inc_frmjoin_process.php";
	var namefilter=/^[A-Za-z \'-]+$/;
	//var emailfilter=/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
	//"^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$"
	var emailfilter=/^[a-zA-Z0-9]+[a-zA-Z0-9_-]+@[a-zA-Z0-9]+[a-zA-Z0-9.-]+[a-zA-Z0-9]+.[a-z]{2,4}$/;
	var commentfilter=/^[A-Za-z0-9 \r\n\.\'-]+$/;
	//var commentfilter=/^[A-Za-z0-9 \.\'-]+$/;
	$('#username_error').html('');
	$('#useraddr_error').html('');
	$('#usercomm_error').html('');
	var username = $('#username').val();
	if (username == "") {
		ecount ++;
		$('#username_error').html(' -Please enter your name.');
	}
	else if (username.length > 40) {
		ecount ++;
		$('#username_error').html(' -Name exceeds length limit.');
	}
	else if(!namefilter.test(username)){
		ecount ++;
		$('#username_error').html(' -Name contains invalid characters.');
	}
	var useraddr = $('#useraddr').val();
	if (useraddr == "") {
		ecount ++;
		//document.getElementById('useraddr_error').innerHTML = " -Please enter your email address.";
		$('#useraddr_error').html(' -Please enter your email address.');
	}
	else if (useraddr.length > 40) {
		ecount ++;
		//document.getElementById('useraddr_error').innerHTML = " -Email address exceeds length limit.";
		$('#useraddr_error').html(' -Email address exceeds length limit.');
	}
	else if(!emailfilter.test(useraddr)){
		ecount ++;
		//document.getElementById('useraddr_error').innerHTML = " -Please enter a valid email address.";
		$('#useraddr_error').html(' -Please enter a valid email address.');
	}
	//var usercomm = document.getElementById("usercomm").value;
	var usercomm = $('#usercomm').val();
	if (usercomm == "") {
		ecount ++;
		//document.getElementById('usercomm_error').innerHTML = " -Please enter a comment.";
		$('#usercomm_error').html(' -Please enter a comment.');
	}
    else if (usercomm.length > 255) {
		ecount ++;
		//document.getElementById('usercomm_error').innerHTML = " -Comment exceeds length limit.";
		$('#usercomm_error').html(' -Comment exceeds length limit.');
	}
	else if(!commentfilter.test(usercomm)){
		ecount ++;
		//document.getElementById('usercomm_error').innerHTML = " -Comment contains invalid characters.";
		$('#usercomm_error').html(' -Comment contains invalid characters.');
	}
	if (ecount == 0) {
		var formData = {username:username,useraddr:useraddr,usercomm:usercomm};
		$('#featured').load(
			'includes/inc_frmjoin_process.php',
			formData,
			function(data) {
				$('#featured').html(data);
			});
	}
}

function changeText2(imgid){
	//var imageid = document.getElementById('travel_01');
	//alert(imgid);
	var imagetag = '<img src="/milo/images/'+imgid+'.jpg" />';
	//alert(imagetag);
	document.getElementById('main').innerHTML = imagetag;
	return false;
}



