function preloadImages() {
	if (document.images) {
		for (var i = 0; i < preloadImages.arguments.length; i++) {
			(new Image()).src = preloadImages.arguments[i];
		}
	}
}
function roll(img_name, img_src){document[img_name].src = img_src;}


var isNav4, isIE4, isNav6 = false;
var range = "";
var styleObj = "";

if (navigator.appVersion.charAt(0) >= 4) {
	if (navigator.appName == "Netscape") {
		if (navigator.appVersion.charAt(0) >= 5) {isNav6 = true;}
		else {isNav4 = true;}
	}
	else {
		isIE4 = true;
		range = "all.";
		styleObj = ".style";
	}
}

function getObject(obj) {
	var theObj;
	if (typeof obj == "string") {
		if (isNav6) {
			theObj = document.getElementById(obj);
			if (theObj != null) theObj = theObj.style;
		}
		else {
			theObj = eval("document." + range + obj);
			if (theObj != null) theObj = eval("theObj" + styleObj);
		}
	}
	else {theObj = obj;}
	return theObj;
}

function show() {
	var theObj;
	for (var i = 0; i < show.arguments.length; i++) {
		theObj = getObject(show.arguments[i]);
		if (theObj != null) {
			theObj.display = "block";
			theObj.visibility = "visible";
		}
	}
}

function hide() {
	var theObj;
	for (var i = 0; i < hide.arguments.length; i++) {
		theObj = getObject(hide.arguments[i]);
		if (theObj != null) {
			theObj.display = "none";
			theObj.visibility = "hidden";
		}
	}
}

/* 
	RECIPES PANELS
*/
function recipeActivate(recipeBox) {
	var recipeCount = 2;
	for (var i = 1; i <= recipeCount; i++)
	{
		var recipeID = i;
		var recipeName = "recipeHdr" + recipeID;
		var recipeAreaName = "recipeList" + recipeID;
		if (recipeBox == recipeID)
		{
			document.getElementById(recipeName).className = "recipeListArrowOn";
			show(recipeAreaName);
		}
		else
		{
			document.getElementById(recipeName).className = "recipeListArrow";
			hide(recipeAreaName);
		}
	}
}



var time=new Date();
var year=time.getYear();
if (year < 2000)
year = year + 1900;

function putYear(){document.write(year);}

function redoPage() {
	if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){ //test for MSIE x.x;
	 	var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
	 	if (ieversion>=6){
			setTimeout("location.href=location.href",1000);			
		}	  		 
	}
}

/*
	TOP NAV ROLLOVERS
*/
function rollOn(navLink) {
	document.getElementById(navLink).style.backgroundImage = 'url(images/nav_roll_home.gif)';
}
function rollOff(navLink) {
	document.getElementById(navLink).style.backgroundImage = 'url(images/shim.gif)';
}




/*
	CHEFS EMAIL VALIDATE
*/
function emailSubmit(){
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var address = document.emailForm.fanEmail.value;
	
	if (reg.test(address) == false) {
		alert('Please specify a valid Email address');
		false;
	}
	
	else
		document.emailForm.submit();
}



/*
	CONTACT FORM VALIDATE
*/
function contactSubmit(){

var firstNameField = "Your First Name";
var lastNameField = "Your Last Name";
var emailField = "Your E-Mail Address";

var firehouseContactForm = document.contactForm;
var whichFields = "";

	whichFields += validateSimpleField(firehouseContactForm.FirstName, firstNameField);
	whichFields += validateSimpleField(firehouseContactForm.LastName, lastNameField);
  	whichFields += validateEmail(firehouseContactForm.email, emailField);
	
	  if (whichFields != "") {
	    alert("Some of the information entered is incorrect:\n" + whichFields);
	    false;
	  }
	  
	  else
	  	document.contactForm.submit();
}

function emailSubmit(){

var emailField = "Your E-Mail Address";
var firehouseContactForm = document.emailForm;
var whichFields = "";

  	whichFields += validateEmail(firehouseContactForm.email, emailField);
	
	  if (whichFields != "") {
	    alert("Some of the information entered is incorrect:\n" + whichFields);
	    false;
	  }
	  
	  else
	  	document.emailForm.submit();
}



function validateSimpleField(fld, fieldType) {
   	var fieldType;
	var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        error = "You didn't enter "+ fieldType +".\n";
    } else if (illegalChars.test(fld.value)) {
        error = fieldType + " contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

  
  
function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}


function validateEmail(fld, fieldType) {
    var error="";
    var tfld = trim(fld.value); // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        error = "You didn't enter "+ fieldType +".\n";
    } else if (!emailFilter.test(tfld)) { //test email for illegal characters
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}



/*
	COOKIES
*/
function set_cookie (name, value, exp_y, exp_m, exp_d, path, domain, secure){
	  var cookie_string = name + "=" + escape (value);		
	  if (exp_y)
	  {
		var expires = new Date (exp_y, exp_m, exp_d);
		cookie_string += "; expires=" + expires.toGMTString();
	  }		
	  if (path)
			cookie_string += "; path=" + escape (path);		
	  if (domain)
			cookie_string += "; domain=" + escape (domain);		  
	  if (secure)
			cookie_string += "; secure";		  
	  document.cookie = cookie_string;
	}

function get_cookie (cookie_name){
  var results = document.cookie.match ('(^|;) ?' + cookie_name + '=([^;]*)(;|$)');

  if (results)
	return (unescape (results[2]));
  else
	return null;
}

	
