var timer1 = 0;

function delayedHide(id) {
	timer1 = 0;
	timer1 = setTimeout("hideElement('" +id+ "')", 2000);
}

function hideElement(id) {
	document.getElementById(id).style.visibility='hidden';
}

function showElement(id) {
	clearTimeout(timer1);
	timer1 = 0;
	document.getElementById(id).style.visibility='visible';
}

function hideMessage() {
	Effect.Fade('message');
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function subscribe(form) {
	var myForm = form;
	var regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
	if (!(regex.test(myForm.email.value))) {
	   alert("Incorrect email format. Please submit a valid email address.");
	   return false;
	}else{
		new Ajax.Updater('updateBox', 'subscribe.php', {asynchronous:true, evalScripts:true, parameters:Form.serialize(myForm)});
		return false;
	}
}


function getEmail() {
	if (( document.signup.useremail.value.length == 0) || ( document.signup.useremail.value.indexOf("@") == -1)  || ( document.signup.useremail.value.indexOf(".") == -1)) {
		alert("You MUST submit a valid email address.");
		document.signup.useremail.focus();
		return false;
		// needs better validation
	}else{
		var email = document.signup.useremail.value;
		var page = "newsletter.php?mode=add&email=" + email;
		window.open(page,'_blank','width=500,height=300');
	}
}

var myWindow;
function removeEmail(url) {
    var width = 500;
    var height = 300;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + 
        ",status,resizable,left=" + left + ",top=" + top + 
        ",screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "RichardsBBQandGrillDailySpecials", windowFeatures);
}

function editItemPos(d, e) {
	var posX = e.clientX - 200;
	var posY = e.clientY + 30;
	var editbox = document.getElementById('editItem');
	//var newY = editbox.style.top;
	//var newX = editbox.style.left;
	//alert("x=" +posX+ " y=" +posY);
	editbox.style.pixelLeft = posX;
	editbox.style.pixelTop = posY;
	//newbox.style.visibility = 'visible';

}

function editCatPos(d, e) {
	var posX = e.clientX - 200;
	var posY = e.clientY + 30;
	var editbox = document.getElementById('editCat');
	editbox.style.pixelLeft = posX;
	editbox.style.pixelTop = posY;

}

function funcCatPos(d, e) {
	var posX = e.clientX;
	var posY = e.clientY;
	var func = document.getElementById(d);
	func.style.pixelLeft = posX;
	func.style.pixelTop = posY;
}

function changePos() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  document.getElementById('editItem').style.pixelLeft = myWidth / 3;
  document.getElementById('editItem').style.pixelTop = myHeight / 3;
  //window.alert( 'Width = ' + myWidth);
  //window.alert( 'Height = ' + myHeight);
}

function validate(form) {
	var myForm = document.newItem;
	if ( myForm.name.value.length < 1) {
		alert("Please enter a name for the item.");
		myForm.name.focus();
		return false;
		// needs better validation
	}
}

function validateEmail(form) {
	var myForm = form;
	
	// Email
	if (( myForm.email.value.indexOf("@") == -1)  || ( myForm.email.value.indexOf(".") == -1) || ( myForm.email.value.indexOf(" ") != -1)) {
		alert("Please submit a valid email address.");
		myForm.email.focus();
		return false;
		// needs better validation
	}else{
		var regex = /^(([\-\w]+)\.?)+@(([\-\w]+)\.?)+\.[a-zA-Z]{2,4}$/;
        if (!(regex.test(myForm.email.value))) {
           alert("Incorrect email format. Please submit a valid email address.");
           return false;
        }else{
			new Ajax.Updater('updateBox', 'subscribe.php', {asynchronous:true, evalScripts:true, parameters:Form.serialize(form)});
		}
	}

}

