/*
  Author:       Cathy Mayer
  Date:		 	03december2007
  Filename:		CMjavascript.js





/**TIME and DATE SCRIPTS .................................................................
 */
function todayTxt() {
   var Today=new Date();
   return Today.getMonth()+1+"-"+Today.getDate()+"-"+Today.getFullYear();
}



/**ANIMATION SCRIPTS.................................................................
  Returns the x-coordinate of the object with the id.
*/
function xCoord(id) {
    if (document.getElementById) {
        var obj = document.getElementById(id);
        xc = parseInt(obj.style.left);
        return xc;
    }
}
/**
  Returns the y-coordinate of the object with the id.
*/
function yCoord(id) {
    if (document.getElementById) {
        var obj = document.getElementById(id);
        yc = parseInt(obj.style.top);
        return yc;
    }
}
/**
  Places the object with the id at coordinates (x,y).
*/
function placeIt(id, x, y) {
    if (document.getElementById) {
        var obj = document.getElementById(id);
        obj.style.left = x + "px";
        obj.style.top = y + "px";
    }
}
/**
  Moves the object dx pixels to the right and dy
  pixels down.
*/
function shiftIt(id, dx, dy) {
    if (document.getElementById) {
        obj = document.getElementById(id);
        obj.style.left = xCoord(id) + dx + "px";
        obj.style.top = yCoord(id) + dy + "px";
    }
}

/**
  Hides an object with the specified id.
*/
function hideIt(id) {
    if (document.getElementById) {
        var obj = document.getElementById(id);
        obj.style.visibility = "hidden";
    }
}

/**
  Shows an object with the specified id.
*/
function showIt(id) {
    if (document.getElementById) {
        var obj = document.getElementById(id);
        obj.style.visibility = "visible";
    }
}
var dx = 2;
var dy = 2;
var index = 0;
var delay = 20;

function moveAnim() {
    if (index < 290) {
        shiftIt("anim", dx, dy);
        index++;
        setTimeout("moveAnim()", delay);
    } else {
        // Do something at end of loop
    }
}

/**COOKIE SCRIPTS .................................................................
 see page 490 in "New Perspectives in JavaScript" indicates to "create cookie, use the syntax...."
 */

var timeNow = new Date();
var expireDate = new Date(timeNow.getTime() + 60*86400000);


function makeCookie(userDinnerTime, favoriteFood, foodCategory, userName){
	document.cookie = "userDinnerTime ="+userDinnerTime+";expires="+expireDate.toGMTString();
	document.cookie = "favoriteFood ="+favoriteFood+";expires="+expireDate.toGMTString();
	document.cookie = "foodCategory ="+foodCategory+";expires="+expireDate.toGMTString();
	document.cookie = "userName ="+userName+";expires="+expireDate.toGMTString();
}



function findCookie(cookieName) {
    var cookie = null;
    var findVal = cookieName + "=";
    var dc = document.cookie;
    if (dc.length > 0) {
        var start = dc.indexOf(findVal);
        if (start >= 0) {
            start += findVal.length;
            lastVal = dc.indexOf(";", start);
            if (lastVal == -1) {
                lastVal = dc.length;
            }
            cookie = dc.substring(start, lastVal);
        }
    }
    return cookie;
}

userDinnerTime = findCookie("userDinnerTime");
favoriteFood = findCookie("favoriteFood");
foodCategory = findCookie("foodCategory");
userName = findCookie("userName");




/**VALIDATION SCRIPTS.................................................................
 */

function validateUserInfo(){
	var userDinnerTime = document.user_info.userDinnerTime.value;
	var favoriteFood = document.user_info.favoriteFood.value;
	var foodCategory = document.user_info.foodCategory.value;
	var userName = document.user_info.userName.value;
	
	if (userDinnerTime == 0)
        {alert("Please enter the time that you want to serve dinner.");
	return false;}
	else if (favoriteFood == "")
        {alert("Please enter the your favorite food.");
	return false;}
	else if (foodCategory == 0)
    {alert("Please select from one of the categories listed.  Selections from other categories will also be available for viewing.");
	return false;}
		else if (userName == "")
    {alert("Please input your user name.");
	return false;}
	else	{
			makeCookie(userDinnerTime, favoriteFood, foodCategory, userName);
	}
}


