/**
   Author: Kelly Rich
   Date  : 12/17/07
   
   JavaScript functions to support the Earth2Art.com website pages.
*/

/**
  Returns the current date
*/
function return_date() {
	var currentDate = new Date();
	var thisDate = currentDate.getDate();
	var thisMonth = currentDate.getMonth();
	var thisYear = currentDate.getFullYear();
	var thisDay = currentDate.getDay();
	var thisHour = currentDate.getHours();
	var thisMinute = currentDate.getMinutes();
	var thisSecond = currentDate.getSeconds();
	
	var monthName = new Array("January", "Feburary", "March", "April", "May", "June",
					  "July", "August", "September", "October", "November", "December");
	
	var dayName = new Array("Sun", "Mon", "Tues", "Wed", "Thurs", "Fri", "Sat");
	
	var timeValue = "" + ((thisHour >12) ? thisHour -12 : thisHour);
	if (timeValue == "0") timeValue = 12;
	timeValue += ((thisMinute < 10) ? ":0" : ":") + thisMinute;  // pad with "0" if less than 10 minutes
	timeValue += ((thisSecond < 10) ? ":0" : ":") + thisSecond;  // pad with "0" if less than 10 seconds
	timeValue += (thisHour >= 12) ? " pm" : " am"
	
	return (dayName[thisDay]+ ", " +monthName[thisMonth] +" "+thisDate+ " -- " +timeValue+ ".");
}

/**
	Validates the Contact Us! form
*/
function checkForm() {
	var maxName = 25;
	
	fname_len = document.form1.fname.value.length;
	lname_len = document.form1.lname.value.length;
	questions = document.form1.questions.value.length;
	phone = document.form1.phone.value.length;
	edress = document.form1.edress.value;
	
    if ( fname_len == 0 || fname_len > maxName) {
        alert("You must enter a first name. 25 Character maximum.");
        return false;
    } else if ( !checkEdress(edress)) {
		alert("You must enter a valid email address. Please re-enter it.");
        return false;
	}

	if  (lname_len == 0) {
		document.form1.lname.value = " ";  // for IE
	}
	if (phone == 0) {
		document.form1.phone.value = " ";  // for IE
	}
    return true;
}

/**
	Validates the entered edress (email address)
*/
function checkEdress(edress) {
    var RegExp = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
    if(RegExp.test(edress)) {
    	return true;
    } else {
		return false;
	}
}

