
	var delim = "~";
	
	// Check numeric fields during input
	function checkIt(evt) {
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		if (charCode > 31 && (charCode < 48 || charCode > 57)) {
			status = "This field accepts numbers only.";
			return false
		}
		status = ""
		return true
	}
	
	// See if an input value has been entered at all
	function isEmpty(inputStr) {
		if (inputStr == null || inputStr == '') {
			return true
		}
		return false
	}
	
	// check for valid characters in a path name
	function InvalidChars(inputStr) {
		var NotAllowed = "\\\/\:";
		
	    for (var i=0; i< inputStr.length; i++) {
	       if (NotAllowed.indexOf(inputStr.charAt(i)) != -1)
	          return false;
	    }
	    return true;	 
	}
	
	function isEmailAddr(email) {
		var result = false;
		var theStr = new String(email);
		var index = theStr.indexOf("@");
		if (index > 0) {
			var pindex = theStr.indexOf(".",index);
			if ((pindex > index+1) && (theStr.length > pindex+1))
			result = true;
		}
	  	return result;
	}

	function ValidateForm(form) {
    	var failed = false;

		if (form.recipient.value == "STOP" ) {
			status = "Make sure that you choose the right Copy Station Store!";
			form.recipient.focus();
			window.scroll(0,0);
			return false;
		}
  
		if (isEmpty(form.first_name.value)) {
			status = "First name is required.";
			form.first_name.focus();
			return false;
		}
		
		if (isEmpty(form.last_name.value)) {
			status = "Last name is required.";
			form.last_name.focus();		
			return false;
		}	
		
		if (isEmpty(form.email.value) && isEmpty(form.phone.value)) {
			status = "You have to give us at least one way to contact you: phone or email";
			form.areacode.focus();
			return false;
		}		
		
		if ((form.email.value.length > 0) && !isEmailAddr(form.email.value)) {
			status = "Please enter a complete email address in the form: yourname@yourdomain.com";
			form.email.focus();
			return false;
		}
			
		if ((form.areacode.value.length != 3) && (form.phone.value.length > 0)) {
			status = "Area code is a three digit number";
			form.areacode.focus();
			return false;
		}
		
		if ((form.alternate_areacode.value.length != 3) && (form.alternate_phone.value.length > 0)) {
			status = "Area code is a three digit number.";
			form.alternate_areacode.focus();
			return false;
		}		
		
		if ((form.phone.value.length != 7) && (form.phone.value.length > 0)) {
			status = "Phone number must have seven digits.";
			form.phone.focus();
			return false;
		}	
		
		if ((form.alternate_phone.value.length != 7) && (form.alternate_phone.value.length > 0)) {
			status = "Area code is a three digit number";
			form.phone.focus();
			return false;
		}
		
		var fn1 = form.file1.value;
		var fn2 = form.file1.value;
		var fn3 = form.file1.value;
		var fn4 = form.file1.value;		
		
		// check that at least one file is uploaded
		if (isEmpty(fn1) && isEmpty(fn2) && isEmpty(fn3) && isEmpty(fn4))  {
			status = "You need to select at least one file to upload!"
			form.file1.focus();
			return false;
		}
		 		
		giveCookie();
	    return true;
	}

	// open mac stuffit warning window 
	function macWindow(openWindow) {
    if (openWindow == 2) {
        windowHandle = window.open('macfile.html','window3','width=270,height=270');
        if (!windowHandle.opener)
            windowHandle.opener = self;
    	}
 	}
	
	function showhelp() {
        windowHandle = window.open('help.html','window3','width=420,height=400,scrollbars=yes,menubar=no,statusbar=no,toolbar=no');
        if (!windowHandle.opener) {
            windowHandle.opener = self;
    	}	
	}		
		
	// name - name of the cookie
	// value - value of the cookie
	// [expires] - expiration date of the cookie (defaults to end of current session)
	// [path] - path for which the cookie is valid (defaults to path of calling document)
	// [domain] - domain for which the cookie is valid (defaults to domain of calling document)
	// [secure] - Boolean value indicating if the cookie transmission requires a secure transmission
	// * an argument defaults when it is assigned null as a placeholder
	// * a null placeholder is not required for trailing omitted arguments
	function setCookie(name, value, expires, path, domain, secure) {
	  var curCookie = name + "=" + escape(value) +
	      ((expires) ? "; expires=" + expires.toGMTString() : "") +
	      ((path) ? "; path=" + path : "") +
	      ((domain) ? "; domain=" + domain : "") +
	      ((secure) ? "; secure" : "");  
	  document.cookie = curCookie;
	}
	
	// name - name of the desired cookie
	// * return string containing value of specified cookie or null if cookie does not exist
	function getCookie(name) {
	  var dc = document.cookie;
	  var prefix = name + "=";
	  var begin = dc.indexOf("; " + prefix);
	  if (begin == -1) {
	    begin = dc.indexOf(prefix);
	    if (begin != 0) return null;
	  } else
	    begin += 2;
	  var end = document.cookie.indexOf(";", begin);
	  if (end == -1)
	    end = dc.length;
	  return unescape(dc.substring(begin + prefix.length, end));
	}
	
	// name - name of the cookie
	// [path] - path of the cookie (must be same as path used to create cookie)
	// [domain] - domain of the cookie (must be same as domain used to create cookie)
	// * path and domain default if assigned null or omitted if no explicit argument proceeds
	function deleteCookie(name, path, domain) {
	  if (getCookie(name)) {
	    document.cookie = name + "=" + 
	    ((path) ? "; path=" + path : "") +
	    ((domain) ? "; domain=" + domain : "") +
	    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
	  }
	}
	
	// date - any instance of the Date object
	// * hand all instances of the Date object to this function for "repairs"
	function fixDate(date) {
	  var base = new Date(0);
	  var skew = base.getTime();
	  if (skew > 0)
	    date.setTime(date.getTime() - skew);
	}
	
function giveCookie() {
	var now = new Date();
	var oneYearFromNow = now.getTime() + (365 * 24 * 60 * 60 * 1000);
	now.setTime(oneYearFromNow);
	
	setCookie("store", submitfiles.store.selectedIndex, now);
	setCookie("company", submitfiles.company.value, now);
	setCookie("first_name", submitfiles.first_name.value, now);
	setCookie("last_name", submitfiles.last_name.value, now);
	setCookie("address", submitfiles.address.value, now);
	setCookie("address2", submitfiles.address2.value, now);
	setCookie("city", submitfiles.city.value, now);
	setCookie("state", submitfiles.state.selectedIndex, now);
	setCookie("zip_code", submitfiles.zip_code.value, now);
	setCookie("areacode", submitfiles.areacode.value, now);
	setCookie("phone", submitfiles.phone.value, now);
	setCookie("alternate_areacode", submitfiles.alternate_areacode.value, now);
	setCookie("alternate_phone", submitfiles.alternate_phone.value, now);
	setCookie("email", submitfiles.email.value, now);
	return true;
}

function checkCookie() {
	if (getCookie("store") != null) {submitfiles.recipient.SelectedIndex = getCookie("store");}
	if (getCookie("company") != null) {submitfiles.company.value = getCookie("company");}
	if (getCookie("first_name") != null) {submitfiles.first_name.value = getCookie("first_name");}
	if (getCookie("last_name") != null) {submitfiles.last_name.value = getCookie("last_name");}
	if (getCookie("address") != null) {submitfiles.address.value = getCookie("address");}
	if (getCookie("address2") != null) {submitfiles.address2.value = getCookie("address2");}
	if (getCookie("city") != null) {submitfiles.city.value = getCookie("city");}
	if (getCookie("state") != null) {submitfiles.state.selectedIndex = getCookie("state");}
	if (getCookie("zip_code") != null) {submitfiles.zip_code.value = getCookie("zip_code");}
	if (getCookie("areacode") != null) {submitfiles.areacode.value = getCookie("areacode");}
	if (getCookie("phone") != null) {submitfiles.phone.value = getCookie("phone");}
	if (getCookie("alternate_areacode") != null) {submitfiles.alternate_areacode.value = getCookie("alternate_areacode");}
	if (getCookie("alternate_phone") != null) {submitfiles.alternate_phone.value = getCookie("alternate_phone");}
	if (getCookie("email") != null) {submitfiles.email.value = getCookie("email");}	
}

// Functions for date/time due selection
function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function add_days(adate,days) {
    return new Date(adate.getTime() + (days * 86400000));
}

function format_date(adate) {
	var days = new Array('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
    return (adate.getMonth()+1) + '/' + adate.getDate() + '/' + y2k(adate.getYear()) + ' ' + days[adate.getDay()];
}

function show_dates(adate, j) {
    var strNow = format_date(adate); // format date
	submitfiles.days.options[j] = new Option(strNow, j);
}

function UpdateDateTimeDue() {
	// set correct value for date/time due hidden field
	submitfiles.date_due.value = submitfiles.days.options[submitfiles.days.selectedIndex].text + ' ' + submitfiles.times.options[submitfiles.times.selectedIndex].text;	
}


