
function submitForm(flag,backid,nextid,prefix) {
	if(flag)
		{//1 is the next button
		//if (nextid != 7)	
		document.forms[0].action = prefix + "_" + nextid + ".asp";
		//else 				document.forms[0].action = "puppy_thankyou2.asp";
	
		if (checkForm())	document.forms[0].submit();
		}
	else
		{//0 is the previous button
		if (backid != 0) document.forms[0].action = prefix + "_" + backid + ".asp";
		else document.forms[0].action = prefix + "_optin.asp";
		document.forms[0].submit();
		}
}
	
function submitForm_TGDI(flag,pagename) {
	if(flag)//1 is the next button
		{document.forms[0].action = pagename ;
		if (checkForm())	document.forms[0].submit();
		}
	else //0 is the previous button
		{document.forms[0].action = pagename;
		document.forms[0].submit();
		}
}

//Browser Detect
	bName = navigator.appName;				//get browser name
	bVer = parseInt (navigator.appVersion);	//get browser version
	theBrowser = "null";
	if (bName == "Netscape" && bVer >= 3) theBrowser = "goodbrowser";
	else if (bName == "Netscape" && bVer == 2) theBrowser = "badbrowser"; //for NS 2: unused
	else if (bName == "Microsoft Internet Explorer" && bVer >=3) theBrowser = "goodbrowser"; //for IE4
	else if (bName == "Microsoft Internet Explorer" && bVer >=2) theBrowser = "okbrowser"; //for IE3: unused


//Function used to swap images. Useful for rollovers
	function changeImage(name,control) {
		if (theBrowser == "goodbrowser" && document.images) {
		if (eval("document.images[name]")!=null){
		document.images[name].src = eval(control + ".src");
			}
		}
	}

function textcheck (thefield,errMessage){
	var thefieldvalue = thefield.value;
	thefieldvalue1 = thefieldvalue.replace(/^[\s]+/g,"");
	if (thefieldvalue1 == "") 
	{ 
		alert(errMessage);
		return(false);
	}
	return (true);
}	

function dropdowncheck (thefield,errMessage){
	var thefieldvalue = thefield.options[thefield.selectedIndex].value	
	thefieldvalue1 = thefieldvalue.replace(/^[\s]+/g,"");
	if (thefieldvalue1 == "") 
	{ 
		alert(errMessage);
		return(false);
	}
	return (true);
}	


function dropdowncheck_nomsg (thefield){
	var thefieldvalue = thefield.options[thefield.selectedIndex].value	
	thefieldvalue1 = thefieldvalue.replace(/^[\s]+/g,"");
	if (thefieldvalue1 == "") 
	{ 
		return(false);
	}
	return (true);
}	



//radio buttons
function radiocheck (thefield,errMessage) {
	var i;
	var blnchecked = 0;
	
	for (i=0; i<thefield.length; i++) {
		if (thefield[i].checked) {
			blnchecked = 1;
		}
	}

	if (blnchecked == 0) {
		alert(errMessage);
		return(false);
	}else{
		return(true);
	}
}


function radiocheck_nomsg(thefield) {
	var i;
	var blnchecked = 0;
	
	for (i=0; i<thefield.length; i++) {
		if (thefield[i].checked) {
			blnchecked = 1;
		}
	}

	if (blnchecked == 0) {
		return(false);
	}else{
		return(true);
	}
}



//radio buttons or checkboxes with other text field  
function radiotextcheck (thefield,thetextfield,errNoText,errNoButtonforText,errNoButtons){
	var i;
	var thetextfieldvalue = thetextfield.value;
	var trimStr;
	var blnchecked = 0;
	var blnText = 0;
	
	for (i=0; i<thefield.length; i++) {
		if (thefield[i].checked) {
			blnchecked = 1;
		}
	}
	
	trimStr = thetextfieldvalue.replace(/^[\s]+/g,"");
	
	if (trimStr == ""){
		blnText = 0;	
	}else{
		blnText = 1;
	}	
	
	if ((thefield[thefield.length-1].checked) && (blnText == 0)) {
		alert(errNoText); 
		return(false);
	}
			
	if (!(thefield[thefield.length-1].checked) && (blnText == 1)) {
		alert(errNoButtonforText); 
		return(false);
	}
			
	if 	((blnchecked == 0) && (blnText == 0)){		
		alert(errNoButtons); 
		return(false);
	}

	return(true);
}

//radio buttons or checkboxes with other text field  
function radiotextcheckdouble (thefield,thetextfield1,thetextfield2,textfield1No,errNoText,errNoButtonforText,errNoButtons){
	var i;
	var thetextfieldvalue1 = thetextfield1.value;
	var thetextfieldvalue2 = thetextfield2.value;
	var trimStr1;
	var blnchecked = 0;
	var blnText1 = 0;
	
	for (i=0; i<thefield.length; i++) {
		if (thefield[i].checked) {
			blnchecked = 1;
		}
	}
	
	trimStr1 = thetextfieldvalue1.replace(/^[\s]+/g,"");
	trimStr2 = thetextfieldvalue2.replace(/^[\s]+/g,"");
	
	if (trimStr1 == ""){
		blnText1 = 0;	
	}else{
		blnText1 = 1;
	}	
	
	if (trimStr2 == ""){
		blnText2 = 0;	
	}else{
		blnText2 = 1;
	}	
	
	//if ((thefield[thefield.length-1].checked) && (blnText == 0)) {
	if (((thefield[textfield1No-1].checked) && (blnText1 == 0)) || ((thefield[thefield.length-1].checked) && (blnText2 == 0))) {
		alert(errNoText); 
		return(false);
	}
			
	if ((!(thefield[textfield1No-1].checked) && (blnText1 == 1)) || (!(thefield[thefield.length-1].checked) && (blnText2 == 1)) ) {
		alert(errNoButtonforText); 
		return(false);
	}
			
	if 	((blnchecked == 0) && (blnText1 == 0) && (blnText2 == 0)){		
		alert(errNoButtons); 
		return(false);
	}

	return(true);
}

function multipletextcheck (istart,iother,totalsum,errTextValues,errAllEmpty,errSumNumber,errNoOtherNumber,errNoOtherText){
	var i;
	var trimStr;
	var blnchecked = 0;
	var blnText = 0;
	var trimStr;
	var tempstr;
	
	var tempsum = 0;
			//for (k=1; k<11; k++) {
	for (k=istart; k<iother; k++) {
		trimStr = document.form1.elements[k].value.replace(/^[\s]+/g,"")
		if (trimStr.length > 0)  {
			if (isNaN(document.form1.elements[k].value)){
				blnText = 1;
			} else {
				tempsum = tempsum + Number(document.form1.elements[k].value);
				blnchecked = 1;
			}	
		}
	}
	
	if (blnText == 1) { //we have text not numbers 
		alert(errTextValues)
		return(false);
	}
				
	tempstr = document.form1.elements[iother-1].value.replace(/^[\s]+/g,"")  //elements[10]
	trimStr = document.form1.elements[iother].value.replace(/^[\s]+/g,"")	//elements[11]
	//alert (document.form1.elements[31].name);
	if (trimStr.length == 0) { //we have the other textbox filled but not the number associated with it
		if (tempstr.length > 0){
			alert(errNoOtherNumber)
			return(false);
		}
	}
	
	if (tempstr.length == 0) {//we have the other number filled but not the textbox associated with it
		if (trimStr.length > 0){
			alert(errNoOtherText)
			return(false);
		}
	}
	
	if (blnchecked == 0) {//all fields emty
		alert(errAllEmpty);
		return(false);
	}
	
	if (tempsum < 1 || tempsum > totalsum) {//sum greater than 10 or the sum limit
		alert(errSumNumber)
		//alert("In the tenth question, for your last 10 purchases, entries may only be digits less than or equal to 10. The 'Other' text field must be filled in and must contain letters and/or numbers.")
		return(false);
	}
	
	return(true);			
}
//if (!multipletextcheckdouble (59,77,95,10,errTextValues,errAllEmpty,errSumNumber,errNoOtherNumber,errNoOtherText)){
function multipletextcheckdouble_old (istart,iother1,iother2,totalsum,errTextValues,errAllEmpty,errSumNumber,errNoOtherNumber,errNoOtherText){
	var i;
	var trimStr;
	var blnchecked = 0;
	var blnText = 0;
	var trimStr;
	var tempstr;
	//alert (document.form1.elements[59].name);
	
	//return true;
	var tempsum = 0;
			//for (k=1; k<11; k++) {
	for (k=1; k<iother2; k++) {
		if (!(k == iother1)){
			trimStr = document.form1.elements[k].value.replace(/^[\s]+/g,"")
			if (trimStr.length > 0)  {
				if (isNaN(document.form1.elements[k].value)){
					blnText = 1;
				} else {
					tempsum = tempsum + Number(document.form1.elements[k].value);
					blnchecked = 1;
				}	
			}
		}	
	}
	

	if (blnText == 1) { //we have text not numbers 
		alert(errTextValues)
		return(false);
	}
		//alert(document.form1.elements[iother1-1].name);		
	tempstr1 = document.form1.elements[iother1-1].value.replace(/^[\s]+/g,"")  //other number
	trimStr1 = document.form1.elements[iother1].value.replace(/^[\s]+/g,"")	//other text
	tempstr2 = document.form1.elements[iother2-1].value.replace(/^[\s]+/g,"")  //elements[10]
	trimStr2 = document.form1.elements[iother2].value.replace(/^[\s]+/g,"")	//elements[11]
	//alert (document.form1.elements[31].name);
	if ((trimStr1.length == 0 && tempstr1.length > 0) || (trimStr2.length == 0 && tempstr2.length > 0)){ //we have the other number filled but not the textbox associated with it
		alert(errNoOtherText)
		return(false);
	}
	
	if((tempstr1.length == 0 && trimStr1.length > 0 ) ||  (tempstr2.length == 0 && trimStr2.length > 0 )){//we have the other textbox filled but not the number associated with it
			alert(errNoOtherNumber)//Please enter the number of items you purchased in the space corresponding to the brand you entered
			return(false);
	}
	
	if (blnchecked == 0) {//all fields emty
		alert(errAllEmpty);
		return(false);
	}
	
	if (tempsum < 1 || tempsum > totalsum) {//sum greater than 10 or the sum limit
		alert(errSumNumber)
		//alert("In the tenth question, for your last 10 purchases, entries may only be digits less than or equal to 10. The 'Other' text field must be filled in and must contain letters and/or numbers.")
		return(false);
	}
	
	return(true);			
}
function multipletextcheckdouble (rootfieldname,rootfieldname_other,iother1,iother2,totalsum,errTextValues,errAllEmpty,errSumNumber,errNoOtherNumber,errNoOtherText){
//naming convention for this type of field: rootfieldname1 to rootfieldname + iother2 and 2 other textboxes rootfieldname_other+iother1 	
	var i;
	var trimStr;
	var blnchecked = 0;
	var blnText = 0;
	var trimStr;
	var tempstr; 
	var fieldvalue;
	//alert (document.form1.elements[59].name);
	
	//return true;
	var tempsum = 0;
			//for (k=1; k<11; k++) {
	for (k=1; k<=iother2; k++) {
		trimStr = eval('document.form1.' +rootfieldname+k +'.value.replace(/^[\s]+/g,"")');
		//break;
		if (trimStr.length > 0)  {
			if (isNaN(trimStr)){
				blnText = 1;
			} else {
				tempsum = tempsum + Number(trimStr);
				blnchecked = 1;
			}	
		}
	}
	

	if (blnText == 1) { //we have text not numbers 
		alert(errTextValues)
		return(false);
	}
		//alert(document.form1.elements[iother1-1].name);		
	tempstr1 = eval('document.form1.' +rootfieldname+iother1+'.value.replace(/^[\s]+/g,"")');  //other number
	trimStr1 = eval('document.form1.' +rootfieldname_other+iother1+'.value.replace(/^[\s]+/g,"")')	;//other text
	tempstr2 = eval('document.form1.' +rootfieldname+iother2+'.value.replace(/^[\s]+/g,"")');  //elements[10]
	trimStr2 = eval('document.form1.' +rootfieldname_other+iother2+'.value.replace(/^[\s]+/g,"")');	//elements[11]
	//alert (document.form1.elements[31].name);
	
	if ((trimStr1.length == 0 && tempstr1.length > 0) || (trimStr2.length == 0 && tempstr2.length > 0)){ //we have the other number filled but not the textbox associated with it
		alert(errNoOtherText)
		return(false);
	}
	
	if((tempstr1.length == 0 && trimStr1.length > 0 ) ||  (tempstr2.length == 0 && trimStr2.length > 0 )){//we have the other textbox filled but not the number associated with it
			alert(errNoOtherNumber)//Please enter the number of items you purchased in the space corresponding to the brand you entered
			return(false);
	}
	
	if (blnchecked == 0) {//all fields emty
		alert(errAllEmpty);
		return(false);
	}
	
	if (tempsum < 1) {//sum greater than 10 or the sum limit
		//alert(errSumNumber)
		alert("Please enter the appropriate number in the box beside the brands listed.")
		return(false);
	}
	
	return(true);			
}
function multipletextcheckquad (rootfieldname,rootfieldname_other,iother1,iother2,iother3,iother4,totalsum,errTextValues,errAllEmpty,errSumNumber,errNoOtherNumber,errNoOtherText){
//naming convention for this type of field: rootfieldname1 to rootfieldname + iother2 and 2 other textboxes rootfieldname_other+iother1 	
	var i;
	var trimStr;
	var blnchecked = 0;
	var blnText = 0;
	var trimStr;
	var tempstr; 
	var fieldvalue;
	//alert (document.form1.elements[59].name);
	
	//return true;
	var tempsum = 0;
			//for (k=1; k<11; k++) {
	for (k=1; k<=iother4; k++) {
		trimStr = eval('document.form1.' +rootfieldname+k +'.value.replace(/^[\s]+/g,"")');
		//break;
		if (trimStr.length > 0)  {
			if (isNaN(trimStr)){
				blnText = 1;
			} else {
				tempsum = tempsum + Number(trimStr);
				blnchecked = 1;
			}	
		}
	}
	
	if (blnText == 1) { //we have text not numbers 
		alert(errTextValues)
		return(false);
	}
		//alert(document.form1.elements[iother1-1].name);		
	tempstr1 = eval('document.form1.' +rootfieldname+iother1+'.value.replace(/^[\s]+/g,"")');  //other number
	trimStr1 = eval('document.form1.' +rootfieldname_other+iother1+'.value.replace(/^[\s]+/g,"")')	;//other text
	tempstr2 = eval('document.form1.' +rootfieldname+iother2+'.value.replace(/^[\s]+/g,"")');  //elements[10]
	trimStr2 = eval('document.form1.' +rootfieldname_other+iother2+'.value.replace(/^[\s]+/g,"")');	//elements[11]
	tempstr3 = eval('document.form1.' +rootfieldname+iother3+'.value.replace(/^[\s]+/g,"")');  //other number
	trimStr3 = eval('document.form1.' +rootfieldname_other+iother3+'.value.replace(/^[\s]+/g,"")')	;//other text
	tempstr4 = eval('document.form1.' +rootfieldname+iother4+'.value.replace(/^[\s]+/g,"")');  //other number
	trimStr4 = eval('document.form1.' +rootfieldname_other+iother4+'.value.replace(/^[\s]+/g,"")')	;//other text
	//alert (document.form1.elements[31].name);
	
	if ((trimStr1.length == 0 && tempstr1.length > 0) || (trimStr2.length == 0 && tempstr2.length > 0) || (trimStr3.length == 0 && tempstr3.length > 0) || (trimStr4.length == 0 && tempstr4.length > 0)){ //we have the other number filled but not the textbox associated with it
		alert(errNoOtherText)
		return(false);
	}
	
	if((tempstr1.length == 0 && trimStr1.length > 0 ) ||  (tempstr2.length == 0 && trimStr2.length > 0 ) || (tempstr3.length == 0 && trimStr3.length > 0 ) || (tempstr4.length == 0 && trimStr4.length > 0 )){//we have the other textbox filled but not the number associated with it
			alert(errNoOtherNumber)//Please enter the number of items you purchased in the space corresponding to the brand you entered
			return(false);
	}
	
	if (blnchecked == 0) {//all fields emty
		alert(errAllEmpty);
		return(false);
	}
	
	if (tempsum < 1) {//sum less than 0
		alert(errSumNumber)
		//alert("In the tenth question, for your last 10 purchases, entries may only be digits less than or equal to 10. The 'Other' text field must be filled in and must contain letters and/or numbers.")
		return(false);
	}
	
	return(true);			
}

//radio buttons or checkboxes with 4 other text fields  

function radiotextcheckquad(thefield1, textfield1_1, textfield1_2, textfield2_1, textfield2_2,textfield1No,textfield2No,textfield3No,textfield4No,errNoText,errNoButtonforText,errNoButtons){
	var i;
	var textfield1_1 = textfield1_1.value;
	var textfield1_2 = textfield1_2.value;
	var textfield2_1 = textfield2_1.value;
	var textfield2_2 = textfield2_2.value;
	
	var blnchecked = 0;
	var blnText1 = 0;
	
	for (i=0; i<thefield1.length; i++) {
		if (thefield1[i].checked) {
			blnchecked = 1;
		}
	}
	
		
	trimStr1 = textfield1_1.replace(/^[\s]+/g,"");
	trimStr2 = textfield1_2.replace(/^[\s]+/g,"");
	trimStr3 = textfield2_1.replace(/^[\s]+/g,"");
	trimStr4 = textfield2_2.replace(/^[\s]+/g,"");

	
	if (((thefield1[textfield1No-1].checked) && (trimStr1 == ""))|| ((thefield1[textfield2No-1].checked) && (trimStr2 == "")) || ((thefield1[textfield3No-1].checked) && (trimStr3 == "")) || ((thefield1[textfield4No-1].checked) && (trimStr4 == ""))) {
			alert(errNoText); 
			return(false);
		}
			
		if ((!(thefield1[textfield1No-1].checked) && (trimStr1 != "")) || (!(thefield1[textfield2No-1].checked) && (trimStr2 != ""))|| (!(thefield1[textfield3No-1].checked) && (trimStr3 != "")) || (!(thefield1[textfield4No-1].checked) && (trimStr4 != ""))) {
			alert(errNoButtonforText); 
			return(false);
		}
	
	if 	((blnchecked == 0)){		
			alert(errNoButtons); 
			return(false);
	}

	return(true);
	
}


function numDaysInFeb(year)
{
	if (year % 4 != 0)
    	{return 28;}
	else if (year % 400 == 0)
		{return 29;}
	else if (year % 100 == 0)
		{return 28;}
	else
		{return 29;}
}
		
/*************************************************************\
* isValidDate makes sure that the full date has been entered
* Implements isValidDate to determine validity of date entered
* 
* PARAMETERS:
* inputArray - array of dropdown lists (day, month, year)
*
* RETURN VALUE:
* String - Error value if there's a problem, empty otherwise
**************************************************************/
function isValidDate(day, month, year)
{
	var retVal = "";
	
	if ((day.selectedIndex != 0) && (month.selectedIndex != 0) && (year.selectedIndex != 0))
	{
		return retVal = isActualDate(day, month, year);
	}
	else
	{
		return retVal = "You must enter a day, month, and year to continue.\n\n";
	}
}

/*************************************************************\
* isValidMonthYear makes sure that the date comprised of only
* month and year has been entered
* 
* PARAMETERS:
* inputArray - array of dropdown lists (day, month, year)
*
* RETURN VALUE:
* String - Error value if there's a problem, empty otherwise
**************************************************************/
function isValidMonthYear(month, year)
{
	var retVal = "";
	
	if ((month.selectedIndex != 0) && (year.selectedIndex != 0))
	{
		return retVal;
	}
	else
	{
		return retVal = "You must enter a month and year to continue.\n\n";
	}
}

/*************************************************************\
* isActualDate determines whether the inputed date is a
* valid calendar date.  Applies to dates entered through
* dropdown lists.  First element in each dropdown cannot be
* a usable value.
* 
* PARAMETERS:
* day - dropdown list object containing the day
* month - dropdown list object containing the month
* year - dropdown list object containing the year
*
* RETURN VALUE:
* String - Error value if there's a problem, empty otherwise
**************************************************************/
function isActualDate(day, month, year)
{
	var retVal = "";
	switch (day.selectedIndex)
	{
		case 29:
			if ((month.selectedIndex == 2) && (numDaysInFeb(year.options[year.selectedIndex].value) == 28))
			{
				return retVal = "There are only 28 days in February for the selected year. Please check the number you entered.\n\n";
			}
			break;
		case 31:
			switch (month.selectedIndex)
			{
				case 4:
				case 6:
				case 9:
				case 11:
					return retVal = "There are only 30 days in the selected month. Please check the number you entered.\n\n";
					break;
			}
			break;
	}
	switch (month.selectedIndex)
	{
		case 2:
			if (day.selectedIndex > numDaysInFeb(year.options[year.selectedIndex].value))
			{
				return retVal = "There are only 28 days in February for the selected year. Please check the number you entered.\n\n";
			}
			break;	
		case 4:
		case 6:
		case 9:
		case 11:
			if (day.selectedIndex > 30)
			{
				return retVal = "There are only 30 days in the selected month. Please check the number you entered.\n\n";
			}						
			break;
	}

	if ((day.selectedIndex == 29) && (month.selectedIndex == 2) && (numDaysInFeb(year.options[year.selectedIndex].value) != 29))
	{
		return retVal = "There are only 28 days in February for the selected year. Please check the number you entered.\n\n";
	}

	return retVal = "";
}

/*************************************************************\
* isValidDOBMonthYear determines whether the inputed birthday
* conforms to the puppy/dog age specifications.
* i.e. puppies must be less than one year old, dogs otherwise
* This is same as isValidDOB but is used when only Month and
* YEar are collected from user.
* 
* PARAMETERS:
* inputArray - array of dropdown lists (day, month, year)
* dogOrPuppy - integer specifying the surveyID
*
* RETURN VALUE:
* String - Error value if there's a problem, empty otherwise
**************************************************************/
function isValidDOBMonthYear(month, year, dogOrPuppy)
{
	var day = 1
	month = month.options[month.selectedIndex].value
	month = month - 1;
	year = year.options[year.selectedIndex].value
	var retVal = "";
	if (month+1 == 0 || year == 0)
		return retVal = "";
	
	var now = new Date();

	var dogDate = new Date(year, month, day);

	var diff = Math.floor((now.getTime() - dogDate.getTime()) / (1000 * 60 * 60 * 24 * 365));

	if (diff < 0) return retVal = 1; //"The birth date you have entered is in the future. Please enter the correct date.\n\n";

	if (diff >= 1 && dogOrPuppy == 2)
	{
		return retVal = 2;//"According to the birth date you entered for your dog, he or she is no longer a puppy.\nPlease check that you entered the correct birth date,\nor opt to subscribe to Dog Knows, the newsletter about adult dogs.\n\n";
	}
	else if (diff < 1 && dogOrPuppy == 3)
	{
		return retVal = 3;//"According to the birth date you entered for your dog, he or she is still a puppy.\nPlease check that you entered the correct birth date,\nor opt to subscribe to Puppy Scoops, the newsletter about puppies.\n\n";
	}

	return retVal = "";
}	


/*************************************************************\
* isValidDOB determines whether the inputed birthday conforms
* to the puppy/dog age specifications.
* i.e. puppies must be less than one year old, dogs otherwise
* 
* PARAMETERS:
* inputArray - array of dropdown lists (day, month, year)
* dogOrPuppy - integer specifying the surveyID
*
* RETURN VALUE:
* String - Error value if there's a problem, empty otherwise
**************************************************************/
function isValidDOB(day, month, year, dogOrPuppy)
{
	day = day.options[day.selectedIndex].value
	month = month.options[month.selectedIndex].value
	month = month - 1;
	year = year.options[year.selectedIndex].value
	var retVal = "";
	if (day == 0 || month+1 == 0 || year == 0)
		return retVal = "";
	
	var now = new Date();

	var dogDate = new Date(year, month, day);
	var diff = Math.floor((now.getTime() - dogDate.getTime()) / (1000 * 60 * 60 * 24 * 365));

	if (diff < 0) return retVal = 1; //"The birth date you have entered is in the future. Please enter the correct date.\n\n";

	if (diff >= 1 && dogOrPuppy == 2)
	{
		return retVal = 2;//"According to the birth date you entered for your dog, he or she is no longer a puppy.\nPlease check that you entered the correct birth date,\nor opt to subscribe to Dog Knows, the newsletter about adult dogs.\n\n";
	}
	else if (diff < 1 && dogOrPuppy == 3)
	{
		return retVal = 3;//"According to the birth date you entered for your dog, he or she is still a puppy.\nPlease check that you entered the correct birth date,\nor opt to subscribe to Puppy Scoops, the newsletter about puppies.\n\n";
	}

	return retVal = "";
}	
	
function isEmailValid(theField)
	{	
		var bag = " ";
		theFieldvalue = stripCharsInBag(theField.value, bag);
		//theField.value = cleanString;
		var emailCheck = /^([a-zA-Z0-9_\.-])+\@(([a-zA-Z0-9_\-])+\.)+([a-zA-Z0-9])+$/;
		//var re = /^[A-Za-z0-9_-][\.A-Za-z0-9_-]*[A-Za-z0-9_]@[^_-\.]+\.[A-Za-z0-9_-][\.A-Za-z0-9_-]*$/;
		//var re2 = /^[A-Za-z0-9_-]@[^_-\.]+\.[A-Za-z0-9_-][\.A-Za-z0-9_-]*$/;
		//var result = re.test(cleanString);
		//var result2 = re2.test(cleanString);
		//var returnResult = result || result2;
		returnResult = emailCheck.test(theFieldvalue);
		if(!returnResult)
		{
			theField.focus();
		}
		return returnResult;
	}

	function DoEmailAddressesMatch(emailAddress1, emailAddress2)
	{
		var retVal = "";
		if (emailAddress1.value == emailAddress2.value)
		{
			return retVal = "";
	    }
		else
		{
			return retVal = "Please make sure Email Address matches Confirm Email Address";
	    }
	}
	
	function stripCharsInBag (s, bag)
	{   var i;
	    var returnString = "";
			
	    // Search through string's characters one by one.
	    // If character is in bag, append to returnString.
			
	    for (i = 0; i < s.length; i++)
	    {   
	        // Check that current character isn't whitespace.
	        var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
	    }
	   return returnString;
	}	
		
/*
		checkZIPCode
		Return true is zip code is valid
		*/
		function checkZIPCode(str){  				
		//var re1 = /^[0-9][0-9][0-9][0-9][0-9]$/;		//XXXXX		
		//var re1= ("^\d{5}$") 					
		var re1 = /^\d{5}$/;
		returnResult = re1.test(str);
		return returnResult;
	}

	function checkDogCatRadio(ownCatYes, ownCatNo)
	{
		var retVal = "";

		if (ownCatYes.checked || ownCatNo.checked)
		{
			return retVal = "";
	    }
		else
		{
			return retVal = "Please indicate whether you own a cat";
	    }
	}
	
	function checkAgreeToRules(agreeToRules)
	{
		var retVal = "";

		if (agreeToRules.checked)
		{
			return retVal = "";
	    }
		else
		{
			return retVal = "You must agree to rules to enter Sweepstakes";
	    }
	}

function Popup(mypage, myname, w, h, sc)
	{
		var newHeight = h;
		var newWidth = w;
			
		// for MACs
		if ((navigator.platform.indexOf("Mac") >= 0) && (navigator.appName != "Netscape"))
		{
			newHeight = h - 34;
		}
		else if (navigator.platform.indexOf("Mac") >= 0)
		{
			newHeight = h - 57;
		}
		
		//alert (navigator.appVersion);
		// for browser versions greater than 4 and not AOL
		if ((parseInt(navigator.appVersion) >= 4) && (navigator.appVersion.indexOf("AOL") == -1))
		{
			//alert("ie");
			var offsetW = (screen.width - w) / 2;
			var offsetH = (screen.height - h) / 2;
			winprops = 'height='+ newHeight +',width='+ newWidth +',top='+ offsetH +',left='+ offsetW + ',scrollbars='+sc+',resizable=1'
			win = window.open(mypage, myname, winprops)
			win.window.focus();
		}
			
		// traps everything else
		else
		{
			newHeight += 25;
			newWidth +=  25;
			//newHeight = 100;
			//newWidth = 100; 
			//alert("aol");
			winprops = 'height=' + newHeight + ',width=' + newWidth + ',scrollbars='+sc+',resizable=1';
			win = window.open(mypage, myname, winprops);
		}
	} 	
	
function confirmation(optoutpage)
{
	if (!confirm('To participate in this promotion, you must be 13 years of age or older.\n If you are 13 years of age or older click OK to proceed.'))
		{
			window.location = optoutpage;//"/" + optoutpage;
		}
}

function checkboxcheck(thefield,errMessage)

{
	if (!thefield.checked) {
		alert(errMessage);
		return(false);
	}else{
		return(true);
	}
}