var submitted = false;

function validateSubmit() {
    if (submitted) {
        return false;  // don't submit form
    } else {
        submitted = true;
        return true; // submit form
    }
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function popup (url) {
  window.open(url, 'new', 'scrollbars=yes, width=420, height=375');
}

function isEmpty(element) {

	var isChecked;

 	for (i=0; i<element.length;i++) 
	{ 
 		if (element[i].checked == true) {
 			return false;
 		}
 	}

	return true;
}

function clearNoneOfTheAboveBox() {
	var n = document.getElementById("noneOfTheAbove");
	if (n != null) {
		n.checked = false;
	}
}

function clearOtherBoxes(obj) {
    var elements = document.forms[0].elements;
    var i = 0;

    while(elements[i]) {
        if(elements[i] == obj && elements[i].checked == true) {
            elements[i].checked = true;
        } else {
            elements[i].checked = false;
        }
        i++;
    }
}

function getDate() {

   <!-- Hide this from older browsers

  var today = new Date();
  var week, month;

  switch (today.getDay()) {
    case 0:
      week = "Sunday";
      break;
    case 1:
      week = "Monday";
      break;
    case 2:
      week = "Tuesday";
      break;
    case 3:
      week = "Wednesday";
      break;
    case 4:
      week = "Thursday";
      break;
    case 5:
      week = "Friday";
      break;
    case 6:
      week = "Saturday";
      break;
  }

  switch (today.getMonth()) {
    case 0:
      month = "January";
      break;
    case 1:
      month = "February";
      break;
    case 2:
      month = "March";
      break;
    case 3:
      month = "April";
      break;
    case 4:
      month = "May";
      break;
    case 5:
      month = "June";
      break;
    case 6:
      month = "July";
      break;
    case 7:
      month = "August";
      break;
    case 8:
      month = "September";
      break;
    case 9:
      month = "October";
      break;
    case 10:
      month = "November";
      break;
    case 11:
      month = "December";
      break;
  }

  var theYear = today.getYear();

  if (theYear < 2000)
  {
      theYear = theYear + 1900;
  }
  
  document.write (week + ", " + today.getDate() + " " + month + " " + theYear);

  // end hide -->

}



	// knowledge base functions 

var kbWindow = null;
function launchPortal() {
	winOptions = "width=680, height=500, scrollbars=0, resizable=1, status=0, toolbar=0, menubar=0, location=0";
	kbWindow = window.open("http://portal.knowledgebase.net/?cid=9512&c=5109&cpc=YpcsGfSRM6pwT34V2QDT4Fa87UPX0jn7hx3bo4Aau781", "CP9512", winOptions);
	//kbWindow = window.open("http://portal.knowledgebase.net/?cid=5643&c=5109&cpc=dt2wJiVVQ8s0WMQyKUgX6Jd18xTb14qA40Nfr5EdyY0JfnR2", "CP5643", winOptions);
	return false;
}

// BEGIN: Methods used with /help/includes/contactus.ihtml
// These are put here so we can keep all of the KB-related JavaScript in one place.



function askKnowledgeBaseKeyword() {
	var topics = document.kbSearch.kbKeywords.value;	
	askKnowledgeBase(topics);
}

function askKnowledgeBase(topics) {
	launchPortal();
	//kbWindow.location.href = 'http://portal.knowledgebase.net/search.asp?searchtype=allwords&searchby=keywords&c=5109&cid=5643&cpc=dt2wJiVVQ8s0WMQyKUgX6Jd18xTb14qA40Nfr5EdyY0JfnR2&un=&pw=&searchstring='+escape(topics);
	kbWindow.location.href = 'http://portal.knowledgebase.net/search.asp?searchtype=allwords&searchby=keywords&c=5109&cid=9512&cpc=YpcsGfSRM6pwT34V2QDT4Fa87UPX0jn7hx3bo4Aau781&un=&pw=&searchstring='+escape(topics);
	
	kbWindow.focus();
}

// END: Methods used with /help/includes/contactus.ihtml




// create the topicArray
var topicArray = new Array();

topicArray['Survey'] = new Array();
topicArray['Survey'][0] = "Survey (Technical) Problem";
topicArray['Survey'][1] = "Authentication Failed Message";
topicArray['Survey'][2] = "Change Survey Answer";
topicArray['Survey'][3] = "No Answers Applied / Survey content";
topicArray['Survey'][4] = "Why Didn't I Qualify";
topicArray['Survey'][5] = "Why Ask Race, Gender, Age, or Income";
topicArray['Survey'][6] = "No Children That Age";
topicArray['Survey'][7] = "Send More Surveys";
topicArray['Survey'][8] = "Survey Not There / Survey Closed";
topicArray['Survey'][9] = "Survey Too Long / Come back later";

topicArray['Rewards'] = new Array();
topicArray['Rewards'][0] = "How do I redeem my Points";
topicArray['Rewards'][1] = "Points Account Location";
topicArray['Rewards'][2] = "Where Are The Prizes";
topicArray['Rewards'][3] = "Lightspeed Prize Draw";
topicArray['Rewards'][4] = "Didn't Get Points For A Survey";
topicArray['Rewards'][5] = "Lightspeed Points Expire";
topicArray['Rewards'][6] = "Lightspeed Point Value";
topicArray['Rewards'][7] = "Haven't Received My Check/Prize";
topicArray['Rewards'][8] = "Shipping";

topicArray['Registration'] = new Array();
topicArray['Registration'][0] = "Never Received Confirmation Email";
topicArray['Registration'][1] = "Lost My Confirmation Email";
topicArray['Registration'][2] = "Registration Problem";
topicArray['Registration'][3] = "Can't Click On Link In Email";
topicArray['Registration'][4] = "How Do I Register";
topicArray['Registration'][5] = "Who Can Join";
topicArray['Registration'][6] = "Is There A Cost To Join";
topicArray['Registration'][7] = "Two Household Members";

topicArray['Sign In Problems'] = new Array();
topicArray['Sign In Problems'][0] = "Can't Sign In";
topicArray['Sign In Problems'][1] = "Can't Sign Out";
topicArray['Sign In Problems'][2] = "Forgot My Password";
topicArray['Sign In Problems'][3] = "Locked Out";
topicArray['Sign In Problems'][4] = "Have To Sign In Twice";

topicArray['Mini-Poll/Quick Match'] = new Array();
topicArray['Mini-Poll/Quick Match'][0] = "Can't Take Mini-Poll";
topicArray['Mini-Poll/Quick Match'][1] = "Results Of Mini-Poll";
topicArray['Mini-Poll/Quick Match'][2] = "Mini-Poll Isn't There";
topicArray['Mini-Poll/Quick Match'][3] = "Already Took Mini-Poll";
topicArray['Mini-Poll/Quick Match'][4] = "Old Mini-Poll Question";
topicArray['Mini-Poll/Quick Match'][5] = "Quick Match Problem";
topicArray['Mini-Poll/Quick Match'][6] = "Quick Match Isn't There";
topicArray['Mini-Poll/Quick Match'][7] = "Already Took Quick Match";
topicArray['Mini-Poll/Quick Match'][8] = "Didn't Get Points";


topicArray['Privacy'] = new Array();
topicArray['Privacy'][0] = "How Is My Privacy Protected";
topicArray['Privacy'][1] = "Spam emails";
topicArray['Privacy'][2] = "Add To My List Of Trusted Senders";

topicArray['Updating/Changing Info'] = new Array();
topicArray['Updating/Changing Info'][0] = "Change My Email Address";
topicArray['Updating/Changing Info'][1] = "Change My Password";
topicArray['Updating/Changing Info'][2] = "New Mailing Address";
topicArray['Updating/Changing Info'][3] = "Update My Personal Info";

topicArray['General Questions'] = new Array();
topicArray['General Questions'][0] = "Affiliates Program";
topicArray['General Questions'][1] = "Referral Program";

topicArray['Removal Questions'] = new Array();
topicArray['Removal Questions'][0] = "Remove Me";
topicArray['Removal Questions'][1] = "Why Was I Removed?";

// this method takes the name of a "level 1" topic, which is used as a key in the topicArray
// associative array. it is keyed to a numerically-indexed array of its sub-topics.
// the function iterates through the given topics sub-topics and writes them to the
// sub-topic select box.

// It also takes a selected SubTopic and pre-selects it if there's a match. This is so the form
// can be pre-populated if the user is bounced back to it because of a validation error.

function populateSubTopicSelect( topic, subtopic, selected ) { 
 
	// select	= window.document.askQuestion.SubTopic; 
	select	= subtopic;
	string	= ""; 
  
	count	= 0; 
 
	// Clear the old list (above element 0) 
 
	select.options.length = count; 
 
		// Place all matching categories into Options. 
 
	for( i = 0; i < topicArray[topic].length; i++ ) { 
		string = topicArray[topic][i];
		
		isSelected = false;
		if (string == selected) {
			isSelected = true;
		}
		select.options[count++] = new Option( string, string, false, isSelected );

	}  
	var browser=navigator.appName;
	var b_version=navigator.appVersion;
	//alert("browser: "+browser);
	//alert("b_version: "+b_version);
	
	if(browser=="Microsoft Internet Explorer" && b_version.indexOf("MSIE 6.0")!=-1 && selected!=null && selected.length>0) {
		//alert(browser+" "+b_version);
		var subselectIndex = select.options.selectedIndex;
		select.options.selectedIndex = subselectIndex + 1;
	} 
}


	// Created for Omniture
	
	// gender reports
/*	
	function selectGender(form) {
				var s=s_gi('lightspeeduscom');
				if (document.registerForm.gender_id[0].checked) {
					s.eVar1 = "Male";
				}
				if (document.registerForm.gender_id[1].checked) {
					s.eVar1 = "Female";
				}
				s.t();
		}
	
	
		
	// Age/Year reports
	
function selectAge(form) {
				var s=s_gi('lightspeeduscom');
				var i = document.registerForm.birth_year.options.selectedIndex;
				var yearSelected = document.registerForm.birth_year[i].value;
				if(yearSelected != "255") {
					s.eVar2 = yearSelected;
				}
				s.t();
		}	

	// Help page - FAQ, Knowledgebase Base Keyword search reports
	
function linkCode(obj) {
				var s=s_gi('lightspeeduscom');
				s.linkTrackVars='eVar3';
				var keyWordInput = document.kbSearch.kbKeywords.value;
				if(keyWordInput != "") {
					s.eVar3=keyWordInput;
				}
			    s.tl(this, 'o', 'FAQ Search');
}

*/


	// track topic and subtopic selected for email to Lauren
	
//function selectSubTopic(form) {
//				var s=s_gi('lightspeeduscom');
//				var tp1 = document.askQuestion.topic.options.selectedIndex;
//				var topic1Selected = document.askQuestion.topic[tp1].value;
//				
//				var tp2 = document.askQuestion.subtopic.options.selectedIndex;
//				var topic2Selected = document.askQuestion.subtopic[tp2].value;
//				if(topic2Selected != "") {
//					s.eVar4 = topic1Selected + ':' + topic2Selected;
//				}
//				s.t();
//}	


	// form check for form analysis pluggin 
	
	
function openEliteOpinionPage(){
		window.open('http://www.eliteopinion.com/register/join.html?custom=BUCUS00103', 'newwindow', 'width=780, height=620 top=40, left=20, right=20, scrollbars=yes, resizable=yes');
	}
function openMembersPage(){
		window.open('/register/do-not-qualify.html','newwindow', 'width=440, height=60, top=400, left=300, right=300');
	}
	
function doContactUsSubmit(maxlength){
   if(document.askQuestion.comments.value.length > maxlength) {
     alert('You have entered too many characters in the text box.  Please shorten your message.');
     document.askQuestion.comments.focus();
     return false; 
   }
   else {
	 askKnowledgeBase(document.askQuestion.subtopic.value);
	 document.askQuestion.submit();
     return true;
   } 
}

function doContactUsOnLoad(subtopic){
	var selectedIndex = document.askQuestion.topic.options.selectedIndex;
	//alert("topic selectedIndex "+selectedIndex);
	
	if (selectedIndex >= 0) {
		populateSubTopicSelect(document.askQuestion.topic.options[selectedIndex].text,
							   document.askQuestion.subtopic,
							   subtopic);
	}								      	
}