// 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;

// 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 CalendarEntry_onsubmit() 
{
 	//Verify the login from the entry form.
	if (document.Entry.CalendarCode.value.length < 3)
	{
		window.alert("Please enter your calendar code.");
		document.Entry.CalendarCode.focus();
		return false;
	}
	if ( document.Entry.EntryName.value == "")
	{
		window.alert("Please enter your name.");
		document.Entry.EntryName.focus();
		return false;
	}
	if ( document.Entry.Phone.value == "")
	{
		window.alert("Please enter your phone number.");
		document.Entry.Phone.focus();
		return false;
	}
	if ( document.Entry.Email.value == "" )
	{
		window.alert("Please enter a valid email address.");
		document.Entry.Email.focus();
		return false;
	}
	var atsymbol = parseInt(document.Entry.Email.value.indexOf("@"));
	var periodchar = parseInt(document.Entry.Email.value.indexOf("."));
	var courriel_len = parseInt(document.Entry.Email.value.length);
	if (document.Entry.Email.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Please enter a valid email address");
			document.Entry.Email.focus();
			return (false);
		}
	}
	if ( document.Entry.Rules.checked == false)
	{
		alert('Before entering the contest you must read, agree and accept the contest Rules and Regulations.');
		document.Entry.Rules.focus();
		return false;
	}
}
function CalendarEntryFR_onsubmit() 
{
	//Verify the login from the entry form.
	if (document.Entry.CalendarCode.value.length < 3)
	{
		window.alert("Veuillez entrer le code de votre calendrier.");
		document.Entry.CalendarCode.focus();
		return false;
	}
	if ( document.Entry.EntryName.value == "")
	{
		window.alert("Veuillez entrer votre nom.");
		document.Entry.EntryName.focus();
		return false;
	}
	if ( document.Entry.Phone.value == "")
	{
		window.alert("Veuillez entrer votre numéro de téléphone.");
		document.Entry.Phone.focus();
		return false;
	}
	if ( document.Entry.Email.value == "" )
	{
		window.alert("Veuillez entrer votre adresse courriel.");
		document.Entry.Email.focus();
		return false;
	}
	var atsymbol = parseInt(document.Entry.Email.value.indexOf("@"));
	var periodchar = parseInt(document.Entry.Email.value.indexOf("."));
	var courriel_len = parseInt(document.Entry.Email.value.length);
	if (document.Entry.Email.value != "")
	{
		if (atsymbol < 0 || periodchar < 0 || periodchar == (atsymbol + 1) || (courriel_len - 1) == periodchar )  
		{
			alert("Veuillez entrer votre adresse courriel.");
			document.Entry.Email.focus();
			return (false);
		}
	}
	if ( document.Entry.Rules.checked == false)
	{
		alert('Pour participer au concours, vous devez lire et accepter les règlements.');
		document.Entry.Rules.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();
	}
}
//-->
