// 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;
function preloadImages()
{
if (document.images)
{
	pre_btn_order_on = newImage('../images/btn_order-on.gif');
	pre_btn_ctgiftcards_on = newImage('../images/btn_ctgiftcards-on.gif');
	pre_btn_enter_on = newImage('../images/btn_enter-on.gif');
	preloadFlag = true;
}
}
// Code for the popup windows
var popup;
function launchwindow(winURL,winName,w,h,winSpecs)
{
popup = window.open(winURL,winName,
		"Width=" + w + ",Height=" + h + "," + winSpecs);
popup.focus();
}
//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 Login_onsubmit() 
{
 	//Verify the login from the entry form.
	if (document.Login.MaxNum.value.length < 8)
	{
		window.alert("Please enter an 8 digit MAX number.");
		document.Login.MaxNum.focus();
		return false;
	}
	if (document.Login.AreaCode.value.length < 3)
	{
		window.alert("Please enter your area code.");
		document.Login.AreaCode.focus();
		return false;
	}
	if (document.Login.Phone1.value.length < 3)
	{
		window.alert("Please enter the first 3 digits of your phone number.");
		document.Login.Phone1.focus();
		return false;
	}
	if (document.Login.Phone2.value.length < 4)
	{
		window.alert("Please enter the last 4 digits of your phone number");
		document.Login.Phone2.focus();
		return false;
	}
	if ( document.Login.StoreNumber.selectedIndex == 0 )
	{
		window.alert("Please select your location for pick-up.");
		document.Login.StoreNumber.focus();
		return false;
	}
}
function UserInfo_onsubmit() 
{
 	//Verify the checkout form before submitting
	if (document.UserInfo.FName.value.length == "")
	{
		window.alert("Please enter your first name.");
		document.UserInfo.FName.focus();
		return false;
	}
	if (document.UserInfo.LName.value.length == "")
	{
		window.alert("Please enter your last name.");
		document.UserInfo.LName.focus();
		return false;
	}
	if (document.UserInfo.Email.value.length == "")
	{
		window.alert("What email address should we send the order confirmation to?");
		document.UserInfo.Email.focus();
		return false;
	}
	var atsymbol = parseInt(document.UserInfo.Email.value.indexOf("@"));
	var periodchar = parseInt(document.UserInfo.Email.value.indexOf("."));
	var courriel_len = parseInt(document.UserInfo.Email.value.length);
	if (document.UserInfo.Email.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address.");
			document.UserInfo.Email.focus();
			return (false);
		}
	}	
	if (document.UserInfo.Phone.value.length == "")
	{
		window.alert("Please enter your phone number in the event we need to contact you regarding the order.");
		document.UserInfo.Phone.focus();
		return false;
	}
	if (document.UserInfo.StartDate.value.length == "")
	{
		window.alert("What date would you like to pick-up your order?");
		document.UserInfo.StartDate.focus();
		return false;
	}	
	if ( document.UserInfo.PickupTime.selectedIndex == 0 )
	{
		window.alert("What time would you like to pick-up the order?");
		document.UserInfo.PickupTime.focus();
		return false;
	}
	if ( document.UserInfo.AgreeTerms.checked == false)
	{
		alert('You must agree to the terms of this order before submitting.');
		document.UserInfo.AgreeTerms.focus();
		return false;
	}
}
function isValid(pattern, str) 
{
    if ( !pattern.test(str) )
       {
            return false;
       }
    else
            return true;
}
function checkLength(curr, next)
	{
	if (curr.value.length == curr.maxLength && iens6)
		{
		next.focus();
		}
	}	                
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();
	}
}
//-->