	function Show(id) {
	    obj = document.getElementsByTagName("div");
		obj[id].style.display = 'block';
	}
	
	function Hide(id) {
	    obj = document.getElementsByTagName("div");
		obj[id].style.display = 'none';
	}
	
	function popUp(URL, SCROLL, myWIDTH, myHEIGHT, isCenter) {
		if(window.screen)if(isCenter)if(isCenter=="true"){
		    var myLeft = (screen.width-myWIDTH)/2;
		    var myTop = (screen.height-myHEIGHT)/2;
		}
		window.open(URL, '', 'toolbar=0,scrollbars='+SCROLL+',location=0,statusbar=0,menubar=0,resizable=no,width='+myWIDTH+',height='+myHEIGHT+',left='+myLeft+',top='+myTop+', screenX=50,screenY=50,resizable=1');
	}
	
	function changeImages(img_name,img_src) {
		document[img_name].src=img_src;
	}
	
var browser = navigator.appName.toLowerCase();
var agent= navigator.userAgent.toLowerCase();
var version= parseInt(navigator.appVersion);
var is_ie= ((agent.indexOf("msie") != -1) && (agent.indexOf("opera") == -1));
var is_ie3= (is_ie && (version < 4));
var is_ie4= (is_ie && (version == 4) && (agent.indexOf("msie 4")!=-1) );
var is_aol= (agent.indexOf("aol") != -1);
var is_aol3= (is_aol && is_ie3);
var is_aol4= (is_aol && is_ie4);
var is_aol5= (agent.indexOf("aol 5") != -1);
var is_aol6= (agent.indexOf("aol 6") != -1);
var is_comp= (agent.indexOf("compuserve") != -1);
var is_comp2000= (agent.indexOf("cs") != -1);
var is_compie= (is_comp && is_ie);

function reverse(str) {
	var i;
	var ch;
	var ret = "";
	for (i = str.length - 1; i > -1; i--) {
		ch = str.substring(i, i + 1);
		ret = ret + ch;
	}
	return ret;
} //reverse()

function ltrim(str) {
	var nonspace = false;
	var i;
	var ch;
	var ret = "";
	for (i = 0; i < str.length; i++) {
		ch = str.substring(i, i + 1);
		if (ch != " ") {
			ret = ret + ch;
			nonspace = true;
		}
		else {
			if (nonspace) {
				ret = ret + ch;
			}
		}
	}
	return ret;
} //ltrim()

function rtrim(str) {
	return reverse(ltrim(reverse(str)));
} //rtrim()

function trim(str) {
	return ltrim(rtrim(str));
} //trim()

function isLetter(c) {
   var n = c.charCodeAt(0);
   if ((n >= 65 && n <= 90) || (n >= 97 && n <= 122)) {
      return true;
   }
   else {
      return false;
   }
} //isLetter()

function isDigit(c) {
   var n = c.charCodeAt(0);
   if (n >= 48 && n <= 57) {
      return true;
   }
   else {
      return false;
   }
} //isDigit()

function isInteger(str) {
	var ch;
	var ret = true;
	for (var i = 0; i < str.length; i++) {
		ch = str.substring(i, i + 1);
		if (!isDigit(ch)) {
			ret = false;
		}
	}
	return ret;
} //isInteger()

function extraSpaces(str) {
	var currCh = "";
	var prevCh = "";
	var ret = false;
	for (var i = 0; i < str.length; i++) {
		currCh = str.substring(i, i + 1);
		if (currCh == " " && prevCh == " ") {
			ret = true;
		}
		prevCh = currCh;
	}
	return ret;
} //extraSpaces()

function isEmail(email) {
	var IndexOfAt = email.indexOf("@");
	var LastIndexOfAt = email.lastIndexOf("@");
	var badchar = false;
        var str = email.substring(IndexOfAt + 1, email.length);
 		
		//email address has exactly one @ char
		if ((IndexOfAt == -1) || (IndexOfAt != LastIndexOfAt)) {
			return false;
		}

		//@ char in the email can not be the first or the last char
		if ((IndexOfAt == 0) || (LastIndexOfAt == email.length - 1)) {
			return false;
		}

		//must have at least one dot
		if (email.indexOf(".") == -1) {
			return false;
		}

		//dot can not be the last char
		if (email.lastIndexOf(".") == email.length - 1) {
			return false;
		}

		//illegal combinations: @. ..
		if (email.indexOf("@.") != -1 || email.indexOf("..") != -1) {
			return false;
		}

		//can not have apostriphy in domain name
		if (str.indexOf("'") != -1) {
			return false;
		}

		//must be at least 5 chars
		if (email.length < 5) {
			return false;
		}

		// check for bad characters
		for (var i = 0; i < email.length; i++) {
			ch = email.substring(i, i + 1)
			if ((ch >= "A" && ch <= "Z") ||
				(ch >= "a" && ch <= "z") ||
				(ch == "@") || (ch == ".") || (ch == "'") ||
				(ch == "_") || (ch == "-") ||
				(ch >= "0" && ch <= "9"))
			{
				ch = ch; //valid ranges - do nothing
			}
			else {
				badchar = true;
			}
		}
		if (badchar) {
			return false;
		}
		//at this point weve passed all email validations successfully
		return true;
} //isEmail()

function listSelected(lst, val) {
   var i;
   var counter = 0;
   //count how many selections are made in the list
   for (i=0; i<lst.options.length; i++) {
      if (lst.options[i].selected == true && lst.options[i].value != val) {
         counter++;
      }
   }
   //return
   if (counter > 0) {
      return true;
   }
   else {
      return false;
   }
} //listSelected()

function todaysDate() {
//returns todays date in m/d/yyyy format
   var d = new Date();
   return (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getYear();
} //todaysDate()

function surveyControl(controlName,controlPrefix,controlRequired,controlSelected) {
   this.controlName = controlName;
   this.controlPrefix = controlPrefix;
   this.controlRequired = controlRequired;
   this.controlSelected = controlSelected;
} //constructor for surveyControl

function isGoldenQuestionBlank( sQuestionType, sQuestionId ) {
	var blnFlag = false;
	
	if( sQuestionType == 'dropdown' ) {
		//if nothing is selected return false
		if( ( eval( 'document.forms[0].' + sQuestionId + '.selectedIndex' ) > 0 ) )
			blnFlag = true;
	}
	if( sQuestionType == 'radiobuttongroup' || sQuestionType == 'checkboxgroup' ){
	
	    var questionGroup=document.getElementsByName(sQuestionId);
	    if(questionGroup!=null)
	    {
	    var questionGroupLength=questionGroup.length;
		for( var i = 0;i < questionGroupLength; i++ ){
			//if atleast one is selected return true
			
			if( questionGroup[i].checked )
				blnFlag = true;
		}
		}
	}
	return blnFlag;
}

function surveyOK(frm) {
	if( !isGoldenQuestionBlank( 'radiobuttongroup', '73' ) )
	    {return false;}
	if( !isGoldenQuestionBlank( 'radiobuttongroup', '1290' ) )
		{return false;}
	if( !isGoldenQuestionBlank( 'radiobuttongroup', '1291' ) )
		{return false;}
			
	return true;

} //surveyOK

function isSnuggleName(str) {
      var ch;
      var n;
      var ret = true;
      for (var i = 0; i < str.length; i++) {
         ch = str.substring(i, i + 1);
         n = ch.charCodeAt(0);
         //32=space, 39=apostrophe, 44=comma, 45=hyphen, 46=period
         if (isLetter(ch) || n == 32 || n == 39 || n == 44 || n == 45 || n == 46) {
            ch = ch; //valid ranges - do nothing
         }
         else {
            ret = false;
         }
      }
      return ret;
   } //isSnuggleName()

function isSnuggleAddress(str) {
      var ch;
      var n;
      var ret = true;

      for (var i = 0; i < str.length; i++) {
         ch = str.substring(i, i + 1);
         n = ch.charCodeAt(0);
         //32=space, 39=apostrophe, 44=comma, 45=hyphen, 46=period
         if (isDigit(ch) || isLetter(ch) || n == 32 || n == 39 || n == 44 || n == 45 || n == 46) {
            ch = ch; //valid ranges - do nothing
         }
         else {
            ret = false;
         }
      }
      return ret;
   } //isSnuggleAddress()

   function validate(frm) {

      //prefix
      if (!listSelected(frm.title, 0)) {
         alert('Please select Salutation.');
         frm.title.focus();
         return false;
      }

      //First Name
      if (trim(frm.firstname.value) == '') {
         alert('Please enter First Name.');
         frm.firstname.focus();
         return false;
      }
      if (!isSnuggleName(frm.firstname.value)) {
         alert('First Name can contain only letters, spaces, dashes, apostrophes, commas and periods. Please re-enter.');
         frm.firstname.focus();
         return false;
      }
      if (extraSpaces(trim(frm.firstname.value))) {
         alert('Parts of First Name should be separated by single space. Multiple spaces are not allowed. Please re-enter.');
         frm.firstname.focus();
         return false;
      }

      //Last Name
      if (trim(frm.lastname.value) == '') {
         alert('Please enter Last Name.');
         frm.lastname.focus();
         return false;
      }
      if (!isSnuggleName(frm.lastname.value)) {
         alert('Last Name can contain only letters, spaces, dashes, apostrophes, commas and periods. Please re-enter.');
         frm.lastname.focus();
         return false;
      }
      if (extraSpaces(trim(frm.lastname.value))) {
         alert('Parts of Last Name should be separated by single space. Multiple spaces are not allowed. Please re-enter.');
         frm.lastname.focus();
         return false;
      }

      //Address 1
      if (trim(frm.address1.value) == '') {
         alert('Please enter Street Address.');
         frm.address1.focus();
         return false;
      }
      if (!isSnuggleAddress(frm.address1.value)) {
         alert('Street Address can contain only digits, letters, spaces, dashes, apostrophes, commas and periods. Please re-enter.');
         frm.address1.focus();
         return false;
      }
	  if (extraSpaces(trim(frm.address1.value))) {
	     alert('Parts of Street Address should be separated by single space. Multiple spaces are not allowed. Please re-enter.');
	     frm.address1.focus();
	     return false;
      }

      //Address 2
      if (trim(frm.addr2.value) != '') {
		if (!isSnuggleAddress(frm.addr2.value)) {
		   alert('Apt/Suite Address can contain only digits, letters, spaces, dashes, apostrophes, commas and periods. Please re-enter.');
		   frm.addr2.focus();
		   return false;
		}
		if (extraSpaces(trim(frm.addr2.value))) {
		   alert('Parts of Apt/Suite Address should be separated by single space. Multiple spaces are not allowed. Please re-enter.');
		   frm.addr2.focus();
		   return false;
		}
		frm.address2.value = frm.addr2.value;
      }

      //City
      if (trim(frm.city.value) == '') {
         alert('Please enter City.');
         frm.city.focus();
         return false;
      }
      if (!isSnuggleName(frm.city.value)) {
         alert('City can contain only letters, spaces, dashes, apostrophes, commas and periods. Please re-enter.');
         frm.city.focus();
         return false;
      }
	  if (extraSpaces(trim(frm.city.value))) {
	     alert('Parts of City should be separated by single space. Multiple spaces are not allowed. Please re-enter.');
	     frm.city.focus();
	     return false;
	  }

      //State
      if (!listSelected(frm.state, 0)) {
         alert('Please select State.');
         frm.state.focus();
         return false;
      }

      //Zip
      if (trim(frm.zip.value) == '') {
         alert('Please enter Zip Code.');
         frm.zip.focus();
         return false;
      }
      if (frm.zip.value.length != 5) {
         alert("Format of Zip Code is invalid. Valid format is '12345'. Please re-enter.");
         frm.zip.focus();
         return false;
      }
      if (!isInteger(trim(frm.zip.value))) {
         alert("Format of Zip Code is invalid. Valid format is '12345'. Please re-enter.");
         frm.zip.focus();
         return false;
      }

      //Email
      if (trim(frm.email.value) == '') {
         alert('Please enter Email.');
         frm.email.focus();
         return false;
      }
      if (!isEmail(frm.email.value)) {
         alert('Email is invalid. Please re-enter.');
         frm.email.focus();
         return false;
      }
// new codes for birthdate
	  if ( (frm.MonthBirth.selectedIndex == 0 ) 
	|| (frm.DayBirth.selectedIndex == 0 )  
	|| (frm.YearBirth.selectedIndex == 0 ) )
	{	
		alert('Your Date of Birth is invalid. Please re-enter.');
		frm.MonthBirth.focus();
        return false;
	}
	//validate Date Of Birth
	var iday = frm.DayBirth[frm.DayBirth.selectedIndex].value
	var imonth = frm.MonthBirth[frm.MonthBirth.selectedIndex].value
	var iyear = frm.YearBirth[frm.YearBirth.selectedIndex].value
	if( !validateDateOfBirth( imonth, iday, iyear ) )
	{
		alert('Your Date of Birth is invalid. Please re-enter.');
		frm.MonthBirth.focus();
        return false;
	}
	//validate Age
	if( !validateAgebyRules( imonth, iday, iyear, 13 ) )
	{		
		alert('You must be 13 years or older to participate.');
		frm.MonthBirth.focus();
		return false;
    }
// end

      //validate survey questions
      if (!surveyOK(frm)) {
         alert('Please answer required questions.');
         return false;
      }

      //at this point everything is valid
      return true;

   } //validate()



   function doSubmit(frm) {
      if (validate(frm)) {
		 validateOptIn(frm);
		 fixAddress2(frm);
		 fixDateofBirth(frm);
         frm.submit();
         
      }
      else {
         return false;
      }
   }

function validateDateOfBirth(imonth, iday, iyear)
{
  var isValid = true;
  var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
  var enteredDate = new Date(iyear.toString() + " " + m_names[imonth - 1].toString() + " " + iday.toString());
  
  if (enteredDate.getDate() != iday)
  {
    isValid = false;
  }
  return isValid;
}   
   
function validateAgebyRules(imonth, iday, iyear, iage)
{
	var isValid = true;
	var m_names = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
	var enteredDOB = new Date(iyear.toString() + " " + m_names[imonth - 1].toString() + " " + iday.toString());
	var currentDate = new Date()
	var currentYear = currentDate.getFullYear()
	var currentMonth = currentDate.getMonth()
	var currentDay = currentDate.getDate()
	
	if( ( currentYear - iyear ) < parseInt( iage ) )
		isValid = false;
	if( ( currentYear - iyear ) > parseInt( iage ) )
		isValid = true;
	if( ( currentYear - iyear ) == parseInt( iage ) )
	{	
		if( parseInt( currentMonth  + 1 ) < parseInt( imonth ) )
			isValid = false;
		if( parseInt( currentMonth  + 1 ) > parseInt( imonth ) )
			isValid = true;
		if( parseInt( currentMonth  + 1 ) == parseInt( imonth ) )
		{
			if( parseInt( currentDay  ) < parseInt( iday ) )
				isValid = false;
			if( parseInt( currentDay  ) >= parseInt( iday ) )
				isValid = true;
		}
	}
	return isValid;
}   
   
function validateOptIn(frm)
{	
	frm.optin.value=""
	if( frm.optinallBrands.checked )
		frm.optin.value = "allBrands ,"
	if( frm.optinSnuggleOnly.checked )
		frm.optin.value += "Snuggle Only"
	if( frm.optin.value.charAt( frm.optin.value.length - 1 ) == "," )
		frm.optin.value = frm.optin.value.substr( 0, ( frm.optin.value.length - 1) )
	if( frm.optin.value == "" )
		frm.optin.value="NONE"
	
}

function fixAddress2(frm)
{
	if( trim( frm.addr2.value ) == "" )
		frm.address2.value = "NONE";
	else
		frm.address2.value = frm.addr2.value;
}

function fixDateofBirth(frm)
{
	frm.dateofbirth.value = frm.MonthBirth[frm.MonthBirth.selectedIndex].value + "/" + frm.DayBirth[frm.DayBirth.selectedIndex].value + "/" + frm.YearBirth[frm.YearBirth.selectedIndex].value;
	
}