//-- GLOBAL JavaScript CODE STARTS
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function submitNewsletter() {
	document.forms.subscriptionForm.action = '/includes/subscriptions/foodtv_subscription_general_submit.asp';
	document.forms.subscriptionForm.target = 'newsletter_results';
	document.forms.subscriptionForm.method = 'post';
	windowReference = window.open('','newsletter_results','width=400,height=350,scrollbars=no,toolbar=yes,menubar=no,resizable=yes');
}			
function validateNewsletter(form){
	if ((form.userEmail.value == "") || (form.userEmail.value.indexOf('@') == -1) || (form.userEmail.value.indexOf('.') == -1)){
		alert("Please enter a valid email address!");
		form.userEmail.focus();
		return false;
	}
		submitNewsletter();
		return true;
}
function validateGlossarySearchForm(form){
	if(form.searchText.value==""){
		alert("Please enter a search string.");
		form.searchText.focus();
		return false;
	}else{
		return true;
	}
}
function validateSearchForm(form){
	var index = form.showOrHostList.selectedIndex;
	if (form.searchString.value=="" && form.showOrHostList.options[index].value=="#"){
		alert("Please enter either a search string or select a show/host from the list.");
		form.searchString.focus();
		return false;
	}
	if (form.searchString.value==""){
		if (form.showOrHostList.options[index].value=="#"){
			alert("Please select a show/host from the list.");
			form.showOrHostList.focus();
			return false;
		}else{
			var selValue=form.showOrHostList.options[index].value;
			if(form.showOrHostList.options[index].value.charAt(0)=="p"){
				form.CiRestriction.value="@personid "+selValue.substr(1, selValue.length);
			}else if(form.showOrHostList.options[index].value.charAt(0)=="t"){
				form.CiRestriction.value="@roottitleid "+selValue.substr(1, selValue.length);
			}else{
				alert("Unrecognized selection!");
				return false;
			}
			return true;
		}
	}else{
		if (form.showOrHostList.options[index].value=="#"){
			form.CiRestriction.value=form.searchString.value;
			return true;
		}else{
			form.CiRestriction.value=form.searchString.value;
			var selValue=form.showOrHostList.options[index].value;
			if(form.showOrHostList.options[index].value.charAt(0)=="p"){
				form.CiRestriction.value="("+form.CiRestriction.value+") and @personid "+selValue.substr(1, selValue.length);
			}else if(form.showOrHostList.options[index].value.charAt(0)=="t"){
				form.CiRestriction.value="("+form.CiRestriction.value+") and @roottitleid "+selValue.substr(1, selValue.length);
			}else{
				alert("Unrecognized selection!");
				return false;
			}
			return true;
		}
	}
	return false;
}
function validateQuickSearchForm(form){
	if(form.searchString.value==""){
		alert("Please enter a search string.");
		form.searchString.focus();
		return false;
	}else{
		form.CiRestriction.value=form.searchString.value;
		return true;
	}
	return false;
}
function validateTopQuickSearchForm(form){
	var index = form.searchTypeList.selectedIndex;
	var uChoice = form.searchTypeList.options[index].value;
	if(form.searchString.value==""){
		alert("Please enter a search string.");
		form.searchString.focus();
		return false;
	}else{
		if (uChoice=="showIndex"){
			form.action="/recipes/search/foodtv_search_titles.idq";
		}else{
			form.action="/recipes/search/foodtv_search.idq";
		}
		form.CiRestriction.value=form.searchString.value;
		return true;
	}
	return false;
}
function validateSearchFormUS(form){
	if(form.searchString.value==""){
		alert("Please enter a search string.");
		form.searchString.focus();
		return false;
	}else{
		form.CiRestriction.value=form.searchString.value+" and @isus True";
		return true;
	}
	return false;
}
function validateAdvSearchForm(form){
	var frmDish = form.resDish.value;
		if(frmDish!== ""){frmDish = " @dish "+frmDish;}
	var frmHost = form.resHost.value;
		if(frmHost!== ""){
			if(frmDish!==""){frmHost = " and @host "+frmHost;
			}else{frmHost = " @host "+frmHost;}
		}
	var frmShow = form.resShow.value;
		if(frmShow!== ""){
			if(frmDish!=="" || frmHost!==""){frmShow = " and @show "+frmShow;
			}else{frmShow = " @show "+frmShow;}
		}
	var frmEpisode = form.resEpisode.value;
		if(frmEpisode !== ""){
			if(frmDish!=="" || frmHost!=="" || frmShow!==""){frmEpisode = " and @episode "+frmEpisode;
			}else{frmEpisode = " @episode "+frmEpisode;}
		}
		
	var frmOther = form.resOther.value;
		if(frmDish!=="" || frmHost!=="" || frmShow!=="" || frmEpisode!==""){
			if(frmOther!==""){frmOther = "("+frmOther+")"+" and ";}
		}

	if(form.resDish.value=="" && form.resHost.value=="" && form.resShow.value=="" && form.resEpisode.value=="" && form.resOther.value==""){
		alert("Please enter something into at least one of the fields.");
		form.resDish.focus();
		return false;
	}else{
		form.CiRestriction.value = frmOther+frmDish+frmHost+frmShow+frmEpisode;
		return true;
	}
	return false;
}
function validateSearch(form){
	var index = form.showOrHostList.selected;
	if (form.searchText =="" && form.showOrHostList.option[index].value =="#"){
		alert("Please enter either a search string or select a show/host from the list.");
		form.searchText.focus();
		return false;
	}
	if (form.searchText ==""){
		if (form.showOrHostList.option[index].value =="#"){
			alert("Please select a show/host from the list.");
			form.showOrHostList.focus();
			return false;
		}    
	}
	return true;
}
function validateThatsTheSpiritPopup(form){
	if(form.txtSearchCriteria.value ==""){
			alert("Please enter your search criteria.");
			form.txtSearchCriteria.focus();
			return false;
	}else{
		var WinId = window.open('','newwin','');
		WinId.location.href = 'http://www.thatsthespirit.com/results.asp?txtdrinkname='+form.txtSearchCriteria.value;
		return false;
	}
}
function validateUnsub(form){
	if ((form.EMail_Address.value == "") || (form.EMail_Address.value.indexOf('@') == -1) || (form.EMail_Address.value.indexOf('.') == -1)){
		alert("Please enter a valid email address!");
		form.EMail_Address.focus();
		form.EMail_Address.select();
		return false;
	}
	return true;
}

function Validate_AAC_Internet_Form_Express(){
	if (checkExpress(document.frmForumLogin)==true){
		return true;
	}
	return false;
}

function checkExpress(formObj){
	var exprEmail = formObj.EMail_Address.value;
	var exprPin = formObj.txtPin.value;
	if(exprEmail==""){
		alert("Please enter your Email for express entry.");
		formObj.EMail_Address.focus();
		formObj.EMail_Address.select();
		return false;
	}else if(exprPin==""){
		alert("Please enter your PIN number for express entry.");
		formObj.txtPin.focus();
		formObj.txtPin.select();
		return false;
	}else{
		if(checkMail(exprEmail)=="Incorrect"){
			alert("The email address you entered appears to be invalid. Please try again.");
			formObj.EMail_Address.focus();
			formObj.EMail_Address.select();
			return false;
		}else{
			if(validatePinExpr(formObj.txtPin)==true){
				return true;
			}else{
				return false;
			}
		}
	}
	return false;
}

function validatePinExpr(pinFrmObj) {

//alert(pinFrmObj.value);
//return false;

	if(verifyNumeric(pinFrmObj.value)){
		if((pinFrmObj.value.length<4)||(pinFrmObj.value.length>6)){
			alert("Your PIN number must be at least 4 digits and no more than 6.");
			return false;
		}else{
			return true;
		}
	}else{
		alert("Your PIN number can only consist of numbers.");
		pinFrmObj.focus();
		pinFrmObj.select();
		return false;
	}
	return false;
}

function checkMail(emailStr)
{
	var x = emailStr;
	var filter  = /^([a-zA-Z0-9_\.\&\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9])+$/;
	if (filter.test(x)){
		return "Correct";
	}
	else{
		return "Incorrect";
	}
}

function verifyNumeric(numStr){
	var x = numStr;
	var filter = /^([0-9])+$/;
	if(filter.test(x)){
		return true;
	}else{
		return false;
	}
}

/*
function setPageRequest(sPage){
	document.MyRecipeSearchForm.PageRequest.value = sPage;
	document.MyRecipeSearchForm.submit();
	return true;
}  

function getPages(sDirection){
	document.MyRecipeSearchForm.ChangePagingBlock.value = sDirection;
	document.MyRecipeSearchForm.submit();
	return true;
}
*/
//-- GLOBAL JavaScript CODE ENDS