$(document).ready(function() {
	$("a.downloader").click(function(){
		retrieveFile($(this).attr("rel"));

		return false;
	});
});


function retrieveFile(filename){

	filename = filename.replace(/^\s|\s$/g, ""); //trims string
                
	if (filename.match(/([^\/\\]+)\.(pdf|m4v|mov|mp4|f4v|flv)$/i) ) {
		var fileExt = filename.split('.').pop();
		$.get('/inc/checkAuth.php', function(data) {
			//alert(data);
			if(data == 'true'){
				if (fileExt == 'pdf'){
					window.location.href='/getfile.php?filename='+filename;
				} else {
					//window.open ("getVideo.php?filename="+filename,"videoPlayer","menubar=0,resizable=1,width=620,height=420");
					$.colorbox({iframe:true,innerWidth:630,innerHeight:430,href:'/getVideo.php?filename='+filename});
				};
			} else {
				$("<div title='Oops! You need to log in!'><p>We\'d love to share this file with you but please log in or register first using the tab under the navigation bar. Our apologies if your old login credentials don\'t work; we\'ve recently re-programmed this feature, so you\'ll need to re-register.</p></div>").dialog();
			}
		});
	};
}

function validate_required(field,alerttxt)
{
	with (field)
	{
		if (value==null||value=="")
		  {alert(alerttxt);return false;}
		else {return true}
	}
}

function loadDirections(location) {
	window.open('directions-' + location + '.html', 'directions_window','location=no, scrollbars=yes, resizable=no, width=710, height=600,left=20, top=20');
	return false;
  }
  
function validate_form(thisform)
{
	with (thisform)
	{
		if (validate_required(Email,"Email must be filled out!")==false)
		  {Email.focus();return false;}
	}
}
