function checkLogin (){
	var username = $("#username").val();
	var password = $("#password").val();
	var pass = "T";
	var msg = "";
	
	if(username.length < 4){
		pass='F';
		msg+="You must provide a username\n";
	}
	if(password.length < 4){
		pass='F';
		msg+="You must provide a password\n";
	}
	if(pass == 'F'){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

function checkInfo(){
	var name = $("#name").val();
	var rate = $("#rate").val();
	var sort = $("#sort").val();
	var review_link = $("#review_link").val();
	var status = $("#status").val();
	var msg = "";
	
	if(name.length < 1){
		msg += "You must provide a model name.\n";
	}
	if(rate.length < 1){
		msg += "You must provide a model rate.\n";
	}
	if(sort.length < 1){
		msg += "You must provide a model sort order.\n";
	}
	
	if(status.length < 1){
		msg += "You must provide a model status.\n";
	}
	
	if(msg != ""){
		alert(msg);
		return false;
	}else{
		return true;
	}
	
}

function checkAdding(){
	var msg="";
	var name = $("#name").val();
	var rate = $("#rate").val();
	var sort = $("#sort").val();
	if(name.length < 2){
		msg+="This model needs a name.\n";
	}
	
	if(!IsAllowed(sort)){
		msg += "Sort needs to be a numeric value\n";
	}
	
	if(msg != ""){
		alert(msg);
		return false;
	}else{
		return true;
	}
}

function closePop(){
	$("#fade").hide();
}

function openPop(src){
	$("#popImg").attr("src","img/template/0fade.png");
	var img = "img/detail/"+src;
	$("#popImg").attr("src",img);
	var height = $(document).height();
	var width = $(document).width();
	var ww = $(window).width();
	var half = ww / 2;
	var qw = half - 250;
	$('#fade').height(height);
	$('#fade').width(width);
	//$('#popup').vCenter();
	$('#popup').css('left', qw);
	$("#fade").show();
		$(function(){
			// add drag and drop functionality to #box1
			//$("#popup").easydrag(true);
		});
}

function openThumb(src){
	$("#detailImg").html('<a href="javascript: openPop(\''+src+'\');"><img src="img/showcase/'+src+'" border="0"></a><br>Click Image to Enlarge');
}

function sortChange(src,sel){
	var srt = $("#"+sel).val();
	$.post("cgi/imgSort.php", { src: src, sort: srt },
		function(data) {
			//alert("Data Loaded: " + data);
			alert("Updated");
	});
}

function launchMust(){
	var height = $(document).height();
	var width = $(document).width();
	var ww = $(window).width();
	var half = ww / 2;
	var qw = half - 200;
	$('#white60').height(height);
	$('#white60').width(width);
	$('#popup').css('left', qw);
	$("#white60").show();
		$(function(){
			// add drag and drop functionality to #box1
			//$("#popup").easydrag(true);
		});
}

function agree(){
	$("#white60").hide();
	createCookie('mustBe','y',60);
}

/* ------------------------------------------------------------------------------------
	CHECKS IF A STRING CONTAINS AN ALLOWABLE CHARACTER
	EXAMPLE:
		if(!IsAllowed(value)){
			var youSuck = 'true';
		}
--------------------------------------------------------------------------------------- */
function IsAllowed(sText){
	// A LIST OF ALLOWABLE CHARACTERS
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;
 
	for (i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1) {
			IsNumber = false;
		}
	}
	return IsNumber;
}
/* ---------------------------------------------------------------------------- */

function buildCalendar(div){
	var myDate=new Date();
		var minY = myDate.setDate(myDate.getYear());
		var minM = myDate.setDate(myDate.getMonth()-1);
		var minD = myDate.setDate(myDate.getDate()-5);
		
		var maxDate=new Date();
		var maxY = maxDate.setDate(maxDate.getYear()+1);
		var maxM = maxDate.setDate(maxDate.getMonth());
		var maxD = maxDate.setDate(maxDate.getDate());
		
		$("#"+div).datepick({
			showOn: "both",
			maxDate: "2y",
			minDate: new Date(),
			buttonImage: "images/calendar.gif", 
			buttonImageOnly: true,
			//dateFormat: $.datepicker.W3C
			//dateFormat: "mm/dd/yy"
			dateFormat: "yy-mm-dd"
			//dateFormat: "MM d, yy"
			//dateFormat: $.datepicker.COOKIE
		}).addClass("embed").attr("readonly", "readonly");
		
		//focus on the specified div
		$("#"+div).focus();
}

function easeIn(obj){

	$("#btn"+obj).attr("src","img/template/nav/btn"+obj+"OV.gif");
	$("#navStatus"+obj).val("on");
	setTimeout("pulseOne("+obj+")",100);
	setTimeout("pulseTwo("+obj+")",1500);
	//var snd = new Audio("/img/sound/click_x.wav");
	//snd.play();

}
function easeOut(obj){
	$("#btn"+obj).attr("src","img/template/nav/btn"+obj+".gif");
	for (i=1;i<=6;i++){
		$("#navStatus"+obj).val("off");
		$("#shine"+i).stop();
		$("#shine"+i+"a").stop();
	}
	fadeStop(obj);
}
function pulseOne(obj){
	var status = $("#navStatus"+obj).val();
	//$("#debug").html("#shine"+obj);
	if(status == "on"){
		$("#shine"+obj).animate({
			opacity: 1
		  }, 250, function() {
		  	setTimeout("fadeOne("+obj+")",1500);
		  	//fadeOne(obj);
		  });
	  }
}
function pulseTwo(obj){
	var status = $("#navStatus"+obj).val();
	//$("#debug").html("#shine"+obj+"a");
	if(status == "on"){
		$("#shine"+obj+"a").animate({
			opacity: 1
		  }, 250, function() {
		  	//fadeTwo(obj);
		  	setTimeout("fadeTwo("+obj+")",2000);
		  });
	  }
}
function fadeOne(obj){
	$("#shine"+obj).animate({
		opacity: 0
	  }, 500, function() {
		pulseOne(obj);
	  });	
}
function fadeTwo(obj){
	$("#shine"+obj+"a").animate({
		opacity: 0
	  }, 100, function() {
	  	setTimeout("pulseTwo("+obj+")",1500);
	  });	
}
function fadeStop(obj){
	$("#shine"+obj).animate({
		opacity: 0
	  }, 100, function() {
		// Animation complete.
	  });	
	  $("#shine"+obj+"a").animate({
		opacity: 0
	  }, 100, function() {
		// Animation complete.
	  });
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}
/*------------------------------------------------------------------------------------------------
	CHECKS TO SEE IF A STRING IS FORMATTED AS A VALID EMAIL ADDRESS
-------------------------------------------------------------------------------------------------*/
function checkemail(str){
	var testresults = false;
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
		if (filter.test(str)){
			testresults=true;
		}
	return (testresults);
}

function checkNumeric(obj){
	var val = $(obj).val();
	if(!IsAllowed(val)){
		$(obj).val("");
	}
}

/* ---------------------------------------------------------------------------- */
function formatPhone(obj,del,parens){
	/* This function formats a phone number as the user types
		This function takes three values
			obj = the identifier of the calling field
			* = the delimiter to be used
			yes/no = group area code in parenthesis or not 
		EXAMPLE: onkeyup="formatPhone(this,'-','no')" */
	var phone = $(obj).val();
	if(parens == 'yes'){
		phone = phone.substring(0,13);
	}else{
		phone = phone.substring(0,12);
	}
	var phoneLen = phone.length;
	var num = phoneLen - 1;
	var lastChar = phone.charAt(num);
	
	if(lastChar != del){
		if(!IsAllowed(lastChar)){
			phone = phone.replace(lastChar, "");
			$(obj).val(phone);
		}
	}
	
	switch(phoneLen)
	{
		case 1:
			if(parens == 'yes'){
				var C = phone.charAt(num);
				if(C != "("){
					newSTRING = "(" + C;
					$(obj).val(newSTRING);
				}
			}
		break;
		case 4:
			if(parens == 'no'){
				var C = phone.charAt(num);
				if(C != del){
					var newSTRING = phone.substring(0,num);
					newSTRING = newSTRING + del + C;
					$(obj).val(newSTRING);
				}
			}
		break;
		case 5:
			if(parens == 'yes'){
				var C = phone.charAt(num);
				if(C != ")"){
					var newSTRING = phone.substring(0,num);
					newSTRING = newSTRING + ")" + C;
					$(obj).val(newSTRING);
				}
			}
		break;
		case 8:
			if(parens == 'no'){
				var C = phone.charAt(num);
				if(C != del){
					var newSTRING = phone.substring(0,num);
					newSTRING = newSTRING + del + C;
					$(obj).val(newSTRING);
				}
			}
		break;
		case 9:
			if(parens == 'yes'){
				var C = phone.charAt(num);
				if(C != del){
					var newSTRING = phone.substring(0,num);
					newSTRING = newSTRING + del + C;
					$(obj).val(newSTRING);
				}
			}
		break;
		default:
			$(obj).val(phone);
	}

}

function employment(){
	var email = $("#E-mail").val();
	if(!checkemail(email)){
		alert("Please provide a valid email address");
		return false;
	}else{
		return true;
	}
}

