// Valid canadian postal code
var pcodeexp = /^[g,h,j,k,l,m,n,p,t,v][0-9][a-z][0-9][a-z][0-9]$/i ;
var iens6 = document.all || document.getElementById ? true : false;
var ns4 = document.layers ? true : false;
var preloadFlag = false;

//Place focus on the first form element
function placeFocus()
{
	if (document.forms.length > 0)
	{
		var field = document.forms[0];
		for (i = 0; i < field.length; i++)
		{
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
			document.forms[0].elements[i].focus();
			break;
         }
      }
   }
}
function Password_onsubmit() 
{
	if ( document.ForgotPassword.ToEmail.value == "" )
	{
		window.alert("Please enter a valid email address.");
		document.ForgotPassword.ToEmail.focus();
		return false;
	}
	var atsymbol = parseInt(document.ForgotPassword.ToEmail.value.indexOf("@"));
	var periodchar = parseInt(document.ForgotPassword.ToEmail.value.indexOf("."));
	var courriel_len = parseInt(document.ForgotPassword.ToEmail.value.length);
	if (document.ForgotPassword.ToEmail.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address.");
			document.ForgotPassword.ToEmail.focus();
			return (false);
		}
	}
}
function Password_fr_onsubmit() 
{
	if ( document.ForgotPassword.ToEmail.value == "" )
	{
		window.alert("Veuillez indiquer une adresse de courriel valide.");
		document.ForgotPassword.ToEmail.focus();
		return false;
	}
	var atsymbol = parseInt(document.ForgotPassword.ToEmail.value.indexOf("@"));
	var periodchar = parseInt(document.ForgotPassword.ToEmail.value.indexOf("."));
	var courriel_len = parseInt(document.ForgotPassword.ToEmail.value.length);
	if (document.ForgotPassword.ToEmail.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Veuillez indiquer une adresse de courriel valide.");
			document.ForgotPassword.ToEmail.focus();
			return (false);
		}
	}
}
function Register_onsubmit() 
{
 	//Verify the form fields
	if ( document.Register.FName.value == "")
	{
		window.alert("Please enter your first name.");
		document.Register.FName.focus();
		return false;
	}
	if ( document.Register.LName.value == "")
	{
		window.alert("Please enter your last name.");
		document.Register.LName.focus();
		return false;
	}
	if ( document.Register.Province.selectedIndex == 0 )
	{
		window.alert("Please select your province.");
		document.Register.Province.focus();
		return false;
	}
	if ( document.Register.UserName.value == "" )
	{
		window.alert("Please enter a valid email address for your username.");
		document.Register.UserName.focus();
		return false;
	}
	var atsymbol = parseInt(document.Register.UserName.value.indexOf("@"));
	var periodchar = parseInt(document.Register.UserName.value.indexOf("."));
	var courriel_len = parseInt(document.Register.UserName.value.length);
	if (document.Register.UserName.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address for your username.");
			document.Register.UserName.focus();
			return (false);
		}
	}	
	if ( document.Register.Password.value == "" )
	{
		window.alert("Please enter your password.");
		document.Register.Password.focus();
		return false;
	}
	if ( document.Register.Password2.value == "" )
	{
		window.alert("Please confirm your password.");
		document.Register.Password2.focus();
		return false;
	}
	if ( document.Register.Password.value != document.Register.Password2.value )
	{
		window.alert("Entered passwords do not match.");
		document.Register.Password2.focus();
		return false;
	}
}
function Register_fr_onsubmit() 
{
 	//Verify the form fields
	if ( document.Register.FName.value == "")
	{
		window.alert("Veuillez entrer votre prénom.");
		document.Register.FName.focus();
		return false;
	}
	if ( document.Register.LName.value == "")
	{
		window.alert("Veuillez entrer votre nom de famille.");
		document.Register.LName.focus();
		return false;
	}
	if ( document.Register.Province.selectedIndex == 0 )
	{
		window.alert("Veuillez indiquer votre province.");
		document.Register.Province.focus();
		return false;
	}
	if ( document.Register.UserName.value == "" )
	{
		window.alert("Veuillez indiquer une adresse de courriel valide pour votre nom d’utilisateur.");
		document.Register.UserName.focus();
		return false;
	}
	var atsymbol = parseInt(document.Register.UserName.value.indexOf("@"));
	var periodchar = parseInt(document.Register.UserName.value.indexOf("."));
	var courriel_len = parseInt(document.Register.UserName.value.length);
	if (document.Register.UserName.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Veuillez indiquer une adresse de courriel valide pour votre nom d’utilisateur.");
			document.Register.UserName.focus();
			return (false);
		}
	}	
	if ( document.Register.Password.value == "" )
	{
		window.alert("Veuillez indiquer votre mot de passe.");
		document.Register.Password.focus();
		return false;
	}
	if ( document.Register.Password2.value == "" )
	{
		window.alert("Veuillez confirmer votre mot de passe.");
		document.Register.Password2.focus();
		return false;
	}
	if ( document.Register.Password.value != document.Register.Password2.value )
	{
		window.alert("Les mots de passe ne concordent pas.");
		document.Register.Password2.focus();
		return false;
	}
}
function Login_onsubmit() 
{
	if ( document.UserLogin.Username.value == "" )
	{
		window.alert("Please enter your username.");
		document.UserLogin.Username.focus();
		return false;
	}
	if ( document.UserLogin.Password.value == "" )
	{
		window.alert("Please enter your password.");
		document.UserLogin.Password.focus();
		return false;
	}
}
function Login_fr_onsubmit() 
{
	if ( document.UserLogin.Username.value == "" )
	{
		window.alert("Veuillez indiquer votre nom d’utilisateur.");
		document.UserLogin.Username.focus();
		return false;
	}
	if ( document.UserLogin.Password.value == "" )
	{
		window.alert("Veuillez indiquer votre mot de passe.");
		document.UserLogin.Password.focus();
		return false;
	}
}
function EasyMeals_onsubmit() 
{
	if ( document.EasyMealSearch.RecCat.selectedIndex == 0 )
	{
		window.alert("Please select an Easy Meal Solution to continue.");
		document.EasyMealSearch.RecCat.focus();
		return false;
	}
}
function EasyMeals_fr_onsubmit() 
{
	if ( document.EasyMealSearch.RecCat.selectedIndex == 0 )
	{
		window.alert("Pour continuer, choisissez une solution de repas faciles à préparer.");
		document.EasyMealSearch.RecCat.focus();
		return false;
	}
}
function EmailRecipe_onsubmit() 
{
	if ( document.EmailRecipe.ToEmail.value == "" )
	{
		window.alert("Please enter a valid email address for your friend.");
		document.EmailRecipe.ToEmail.focus();
		return false;
	}
	var atsymbol = parseInt(document.EmailRecipe.ToEmail.value.indexOf("@"));
	var periodchar = parseInt(document.EmailRecipe.ToEmail.value.indexOf("."));
	var courriel_len = parseInt(document.EmailRecipe.ToEmail.value.length);
	if (document.EmailRecipe.ToEmail.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address for your friend.");
			document.EmailRecipe.ToEmail.focus();
			return (false);
		}
	}
	if ( document.EmailRecipe.FromEmail.value == "" )
	{
		window.alert("Please enter a valid email address.");
		document.EmailRecipe.FromEmail.focus();
		return false;
	}
	var atsymbol = parseInt(document.EmailRecipe.FromEmail.value.indexOf("@"));
	var periodchar = parseInt(document.EmailRecipe.FromEmail.value.indexOf("."));
	var courriel_len = parseInt(document.EmailRecipe.FromEmail.value.length);
	if (document.EmailRecipe.ToEmail.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address.");
			document.EmailRecipe.FromEmail.focus();
			return (false);
		}
	}
}
function EmailRecipe_fr_onsubmit() 
{
	if ( document.EmailRecipe.ToEmail.value == "" )
	{
		window.alert("Veuillez indiquer une adresse de courriel valide.");
		document.EmailRecipe.ToEmail.focus();
		return false;
	}
	var atsymbol = parseInt(document.EmailRecipe.ToEmail.value.indexOf("@"));
	var periodchar = parseInt(document.EmailRecipe.ToEmail.value.indexOf("."));
	var courriel_len = parseInt(document.EmailRecipe.ToEmail.value.length);
	if (document.EmailRecipe.ToEmail.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Veuillez indiquer une adresse de courriel valide.");
			document.EmailRecipe.ToEmail.focus();
			return (false);
		}
	}
	if ( document.EmailRecipe.FromEmail.value == "" )
	{
		window.alert("Veuillez indiquer une adresse de courriel valide.");
		document.EmailRecipe.FromEmail.focus();
		return false;
	}
	var atsymbol = parseInt(document.EmailRecipe.FromEmail.value.indexOf("@"));
	var periodchar = parseInt(document.EmailRecipe.FromEmail.value.indexOf("."));
	var courriel_len = parseInt(document.EmailRecipe.FromEmail.value.length);
	if (document.EmailRecipe.ToEmail.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Veuillez indiquer une adresse de courriel valide.");
			document.EmailRecipe.FromEmail.focus();
			return (false);
		}
	}
}
function AddShoppingItem_onsubmit() 
{
	if ( document.ShopList.ItemName.value == "" )
	{
		window.alert("Please enter the item description.");
		document.ShopList.ItemName.focus();
		return false;
	}
	if ( document.ShopList.CategoryID.selectedIndex == 0 )
	{
		window.alert("Please select a category.");
		document.ShopList.CategoryID.focus();
		return false;
	}
}
function CreateShopping_onsubmit() 
{
	if ( document.ShopList.ListName.value == "" )
	{
		window.alert("Please enter the name you would like to use when identifying this shopping list.");
		document.ShopList.ListName.focus();
		return false;
	}
}
function CreateShopping_fr_onsubmit() 
{
	if ( document.ShopList.ListName.value == "" )
	{
		window.alert("Veuillez donner un nom à cette liste d’épicerie.");
		document.ShopList.ListName.focus();
		return false;
	}
}

function OptIn_onsubmit() 
{
 	//Verify the form fields
	if ( document.OptIn.FName.value == "")
	{
		window.alert("Please enter your first name.");
		document.OptIn.FName.focus();
		return false;
	}
	if ( document.OptIn.LName.value == "")
	{
		window.alert("Please enter your last name.");
		document.OptIn.LName.focus();
		return false;
	}
	if ( document.OptIn.Email.value == "" )
	{
		window.alert("Please enter a valid email address.");
		document.OptIn.Email.focus();
		return false;
	}
	var atsymbol = parseInt(document.OptIn.Email.value.indexOf("@"));
	var periodchar = parseInt(document.OptIn.Email.value.indexOf("."));
	var courriel_len = parseInt(document.OptIn.Email.value.length);
	if (document.OptIn.Email.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address.");
			document.OptIn.Email.focus();
			return (false);
		}
	}	
}
function OptIn_fr_onsubmit() 
{
 	//Verify the form fields
	if ( document.OptIn.FName.value == "")
	{
		window.alert("Veuillez entrer votre prénom.");
		document.OptIn.FName.focus();
		return false;
	}
	if ( document.OptIn.LName.value == "")
	{
		window.alert("Veuillez entrer votre nom de famille.");
		document.OptIn.LName.focus();
		return false;
	}
	if ( document.OptIn.Email.value == "" )
	{
		window.alert("Veuillez indiquer une adresse de courriel valide.");
		document.OptIn.Email.focus();
		return false;
	}
	var atsymbol = parseInt(document.OptIn.Email.value.indexOf("@"));
	var periodchar = parseInt(document.OptIn.Email.value.indexOf("."));
	var courriel_len = parseInt(document.OptIn.Email.value.length);
	if (document.OptIn.Email.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Veuillez indiquer une adresse de courriel valide.");
			document.OptIn.Email.focus();
			return (false);
		}
	}	
}
function isValid(pattern, str) 
{
    if ( !pattern.test(str) )
       {
            return false;
       }
    else
            return true;
}
	                
function ltrim( cStr )
{
	cStr	=	String(cStr);
	if ( cStr == "0" || cStr == 'null' || cStr.substr(0,3) == '000' )
		return "";
	var oReg = /^(\s+)/;
	return cStr.replace(oReg,'');
}


function rtrim( cStr )
{
	cStr	=	String(cStr);
	var oReg = /(\s+)$/;
	return cStr.replace(oReg,'');
}


function alltrim( cStr )
{
	if (String(cStr) == 'null' )
		return "";
	else
		return ltrim(rtrim(cStr));
}

function strtran( cStr )
{
	cStr	=	String(cStr);
	if ( cStr == '')
		return "";
		
	var oReg = /\s/g;
	return cStr.replace(oReg,'');

}

function checkLength(curr, next)
{
if (curr.value.length == curr.maxLength && iens6)
	{
	next.focus();
	}
}
//-->