
//grab pop unders
function grabPopUnders(r__session_id__value, current_page_displayed) 

	{
		
		grab_pop_unders_url = 'http://www.leadstrike.com/offer_engine_interface/get_pop_unders.cfm?' + 'rn=' + Math.random() * 5 + '&unique_customer_id=' + r__session_id__value + '&current_page_displayed=' + current_page_displayed;
  		sendJSONRequest(grab_pop_unders_url);
				
	}
	
function loadPopUnders(jsonData) 

	{
							
		for ( var i=0; i<jsonData.PopURLS.length; i++ )
		
			{
			
				this_pop = window.open(jsonData.PopURLS[i].this_url);
			
				this_pop.blur() ; 
				window.focus();
			
			}
				
	}

// Request from the platinum content page
function requestPlatinumSurveyTableData() {
  platinum_survey_data_url = 'http://www.leadstrike.com/offer_engine_interface/platinum_survey_table_data.cfm?' + 'rn=' + Math.random() * 5;
  sendJSONRequest(platinum_survey_data_url);
}

// Display data on the platinum content page
function displayPlatinumSurveyTableData( jsonData ) {
  $(document).ready(function() { 
    $("#platinumTableBody").append(jsonData.tablecontent);
    $("#platinumTable") 
      .tablesorter({sortList: [[0,0]],widthFixed: true,widgets: ['zebra']}) 
      .tablesorterPager({container: $("#pager")}); 
  });
}

// Create member subscription
function updateSurveyMemberSubscription(id,action) {
  survey_member_subscription_url = 'http://www.leadstrike.com/offer_engine_interface/survey_member_subscription.cfm?action=' + action + '&id=' + id + '&rn=' + Math.random() * 5;
  sendJSONRequest(survey_member_subscription_url);
}

// Log the returning user back in
function loginFromPaypal(id,email,destination) {
  login_from_paypal_url = 'http://www.leadstrike.com/offer_engine_interface/survey_member_paypal_login.cfm?id=' + id + '&email=' + email + '&destination=' + destination + '&rn=' + Math.random() * 5;
  sendJSONRequest(login_from_paypal_url);
}

// Set cookie for returning user
function setCookieUponPaypalReturn(jsonData) {
  document.location.href = '../members/paypal_set_cookie.html?url_unique_session_id=' + jsonData.SessionValue + '&destination=' + jsonData.Destination;
}

// Send returning user to their destination
function redirectFromPaypalToDestination( destination ) {
  // Users who bail from the paypal purchase are redirected back to the platinum signup page
  if ( destination == 'signup' ){
    document.location.href = '/members/platinum.html';
  }
  // Send users who paid straight to the content
  if ( destination == 'platinum' ) {
    document.location.href = '/members/platinum/index.html';
  }
}

// Check subscription status
function isSubscribed() {
	//first check to make sure the cookie has been set, go elsewhere if not the case
	var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
	var the_grab_r_session_id_url_value = 'http://www.leadstrike.com/offer_engine_interface/am_i_subscribed.cfm?' + 'rn=' + Math.random() * 5 + '&unique_session_id=' + the_unique_session_id__cookied_value ;
	sendJSONRequest(the_grab_r_session_id_url_value) ;
}

// Post subscription check
function runAfterSubscriptionCheck(jsonData){
  if ( jsonData.subscribed == 0 ) {
	  document.location.href = 'http://www.ondemandresearch.com/members/platinum.html?' + 'rn=' + Math.random() * 5 ;
	}
}

function displayHeaderHTML(c_id, the_firstname)

	{
		
		var the_header_html_url = 'http://www.leadstrike.com/offer_engine_interface/generate_header_html.cfm?the_c_id=' + c_id + '&the_firstname=' + the_firstname + '&rn=' + Math.random() * 5 ;
																			
		//send this off to get wrapped up with pre-pop values
		sendJSONRequest(the_header_html_url) ;
		
	}
	
function doDisplayHeaderHTML(jsonData)

	{
		
		document.getElementById('div_display_header_html').innerHTML = jsonData.the_display ;
				
	}

function doExitPop()

	{
		
		var the_exit_pop_url = 'http://www.leadstrike.com/offer_engine_interface/generate_exit_pop_url.cfm?the_unique_customer_id=' + '0' + '&rn=' + Math.random() * 5 ;
																			
		//send this off to get wrapped up with pre-pop values
		sendJSONRequest(the_exit_pop_url) ;
		
	}
	
function spawnExitPopWindow(jsonData)

	{
		
		window.open(jsonData.exit_pop_url) ;
		
	}

function sendAutoPostOffers(the_unique_customer_id, the_media_link_id, the_s_id, the_set)

	{
		
		var the_auto_post_url = 'http://www.leadstrike.com/offer_engine_interface/auto_post_these_offers.cfm?the_unique_customer_id=' + the_unique_customer_id + '&the_media_link_id=' + the_media_link_id + '&the_s_id=' + the_s_id + '&the_set=' + the_set + '&rn=' + Math.random() * 5 ;
																			
		//send this off to get wrapped up with pre-pop values
		sendJSONRequest(the_auto_post_url) ;
		
	}

function IsNumeric(sText)

	{
		   
	   var ValidChars = "0123456789.";
	   var IsNumber = true;
	   var Char;	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
	      
	      { 
	      	
		      Char = sText.charAt(i); 
		      
		      if (ValidChars.indexOf(Char) == -1) 
		         
		         {
		        	IsNumber = false;
		         }
	      }
	      
	   return IsNumber;
   
   }
   
function getIPCountry()

	{
			
		var the_ip_to_country_url = 'http://www.leadstrike.com/offer_engine_interface/check_ip_address.cfm?' + 'rn=' + Math.random() * 5 ;
			
		sendJSONRequest(the_ip_to_country_url) ;
	
	}
	
function verifyIPAddress(jsonData)

	{
		
		if ( jsonData.must_leave_site == 1 )
		
			{
				document.location.href = jsonData.bad_redirect_url ;
			}
		
	}
	
function kickOutIfNotLoggedIn()

	{
	
		//first check to make sure the cookie has been set, go elsewhere if not the case
		var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
		
		var the_grab_r_session_id_url_value = 'http://www.leadstrike.com/offer_engine_interface/am_i_logged_in.cfm?' + 'rn=' + Math.random() * 5 + '&unique_session_id=' + the_unique_session_id__cookied_value ;
	
		sendJSONRequest(the_grab_r_session_id_url_value) ;
	
	}
	
function runAfterLoggedInCheck(jsonData)

	{
		
		if ( jsonData.logged_in == 0 )
		
			{
				document.location.href = 'http://www.ondemandresearch.com/members/logout.html?' + 'rn=' + Math.random() * 5 ;
			}
		
	}
	
function fwdToExternalSurvey()

	{
		
		var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
		
		var the_redirect_url = 'http://www.leadstrike.com/testing/send_to_theuseful.cfm?' + 'rn=' + Math.random() * 5 + '&this__unique_session_id=' + the_unique_session_id__cookied_value ;
			
		document.getElementById('div_survey_of_day').innerHTML = '<a href="' + the_redirect_url + '" class="survey-of-the-day" target="_blank"><img src="../images/A/survey-of-the-day.jpg" alt="Survey of the Day" /></a>' ;
	
	}

function urldecode( str ) 

	{
	       
	    var histogram = {};
	    var ret = str.toString();
	    
	    var replacer = function(search, replace, str) {
	        var tmp_arr = [];
	        tmp_arr = str.split(search);
	        return tmp_arr.join(replace);
	    };
	    
	    // The histogram is identical to the one in urlencode.
	    histogram["'"]   = '%27';
	    histogram['(']   = '%28';
	    histogram[')']   = '%29';
	    histogram['*']   = '%2A';
	    histogram['~']   = '%7E';
	    histogram['!']   = '%21';
	    histogram['%20'] = '+';
	    histogram['\u20AC'] = '%80';
	    histogram['\u0081'] = '%81';
	    histogram['\u201A'] = '%82';
	    histogram['\u0192'] = '%83';
	    histogram['\u201E'] = '%84';
	    histogram['\u2026'] = '%85';
	    histogram['\u2020'] = '%86';
	    histogram['\u2021'] = '%87';
	    histogram['\u02C6'] = '%88';
	    histogram['\u2030'] = '%89';
	    histogram['\u0160'] = '%8A';
	    histogram['\u2039'] = '%8B';
	    histogram['\u0152'] = '%8C';
	    histogram['\u008D'] = '%8D';
	    histogram['\u017D'] = '%8E';
	    histogram['\u008F'] = '%8F';
	    histogram['\u0090'] = '%90';
	    histogram['\u2018'] = '%91';
	    histogram['\u2019'] = '%92';
	    histogram['\u201C'] = '%93';
	    histogram['\u201D'] = '%94';
	    histogram['\u2022'] = '%95';
	    histogram['\u2013'] = '%96';
	    histogram['\u2014'] = '%97';
	    histogram['\u02DC'] = '%98';
	    histogram['\u2122'] = '%99';
	    histogram['\u0161'] = '%9A';
	    histogram['\u203A'] = '%9B';
	    histogram['\u0153'] = '%9C';
	    histogram['\u009D'] = '%9D';
	    histogram['\u017E'] = '%9E';
	    histogram['\u0178'] = '%9F';
	
	    for (replace in histogram) {
	        search = histogram[replace]; // Switch order when decoding
	        ret = replacer(search, replace, ret) // Custom replace. No regexing   
	    }
	    
	    // End with decodeURIComponent, which most resembles PHP's encoding functions
	    ret = decodeURIComponent(ret);
	
	    return ret;
	}
	
function doPasswordReminder()

	{
	
		var d = document.member_login_form ;
		
		if ( d.email.value.length < 5 )
		
			{
				alert('Please enter a valid email address!') ;
				d.email.value = '' ;
				d.email.focus() ;
				return false ;
			}
			
		//now check email syntax
		if ( checkEmailSyntax(d.email.value) == false)
		
			{
				d.email.value = '' ;
				d.email.focus() ;
				return false ;
			}		
		
		var the_url_forgot_email = 'http://www.leadstrike.com/offer_engine_interface/member_forgot_email.cfm?' + 'rn=' + Math.random() * 5 + '&the_email=' + d.email.value ;
		
		sendJSONRequest(the_url_forgot_email) ; 
	
	}
	
function doSomethingAfterForgotPasswordSend(jsonData)

	{
	
		var d = document.member_login_form ;
		
		if ( jsonData.password_found == '1' )
		
			{
				d.email.value = '' ;
				alert('We have successfully retrieved your password and emailed it to the email address you supplied!') ;
				document.location.href = 'http://www.ondemandresearch.com/survey/index.html' ;
			}
		
		else
		
			{
				d.email.value = '' ;
				alert('We are sorry, however there is no account information for the email address you supplied!') ;
			}
	
	}

function getPolls()

	{
	
		var the_url_get_polls = 'http://www.leadstrike.com/offer_engine_interface/get_polls.cfm?' + 'rn=' + Math.random() * 5 + '&the_unique_session_id=' + getCookie('unique_session_id') ;
		
		sendJSONRequest(the_url_get_polls) ; 
	
	}
	
function displayPolls(jsonData)

	{
					
		// Where the form will be placed into the page
		parentElement = document.getElementById('div_polls') ;
		parentElement.innerHTML = "" ;		
		
		
		//if none, then display
		if ( jsonData.TheItems.length == 0 )
		
			{
							
				// Create a form
				myForm = document.createElement('FORM') ;
				myForm.method = 'post' ;
				myForm.action = '#' ;
				myForm.setAttribute('name', 'poll_form__' + 'none') ;
				myForm.id = 'poll_form__' + 'none' ;
				
				//add a label
				thisLabel = document.createElement('label') ;
				thisLabel.className = 'label_design' ;
				myForm.appendChild(thisLabel) ;				
				//create the text for the label
				thisText = document.createTextNode('There are currently no more polls for you to fill out today.') ;
				thisLabel.appendChild(thisText) ;

				parentElement.appendChild(myForm) ;
				return false ;
				
			}
			
		//otherwise, keep going...					
		
		for ( var i=0; i<jsonData.TheItems.length; i++)
		
			{
											
				//div so that you can overwrite this area
			 	thisDiv = document.createElement('div') ;
			 	thisDiv.id = 'this_main_container_div_id__' + i ;
				thisDiv.style.display = 'block' ;
				
				// Create a form
				myForm = document.createElement('FORM') ;
				myForm.method = 'post' ;
				myForm.action = '#' ;
				myForm.setAttribute('name', 'poll_form__' + i) ;
				myForm.id = 'poll_form__' + i ;
				
				//add a label
				thisLabel = document.createElement('label') ;
				thisLabel.className = 'label_design' ;
				myForm.appendChild(thisLabel) ;				
				//create the text for the label
				thisText = document.createTextNode(jsonData.TheItems[i].poll_question) ;
				thisLabel.appendChild(thisText) ;
								
				myForm.appendChild(document.createElement('BR')) ;
				myForm.appendChild(document.createElement('BR')) ;
				
				var field__based_name = 'poll_field__' + jsonData.TheItems[i].poll_id ;
				
				for ( var x=0; x<jsonData.TheItems[i].PossibleResponses.length; x++ )
				
					{
												
						//list out your possible responses as radio buttons
						
						// Create a radio selection												
						if(!document.addEventListener) 
						
							{
							 	// IE hack
								radioField= document.createElement("<input name=\"" + field__based_name + "\"/>");
							} 
						
						else 
						
							{
								radioField= document.createElement("input");
							}													 	
					 	
					 	radioField.type = 'radio' ;
					 	radioField.id = field__based_name + '__' + x ;
					 	radioField.name = field__based_name ;
					 	radioField.className = 'form_field_design' ;
					 	radioField.value = jsonData.TheItems[i].PossibleResponses[x].poll_possible_response_id ; 						
					 	
					 	myForm.appendChild(radioField) ;
					 	myForm.appendChild(document.createTextNode(jsonData.TheItems[i].PossibleResponses[x].poll_possible_response)) ;
					 	
					 	myForm.appendChild(document.createElement('BR')) ;					
					
					}				
							
				// Create a submit button	
				var this_temp_holder_value = jsonData.TheItems[i].poll_id + '^' + jsonData.TheItems[i].PossibleResponses.length + '^' + i ;
							
				newButton = document.createElement('INPUT') ;
				newButton.id = this_temp_holder_value ;
				newButton.type = 'button' ;
				newButton.setAttribute('name', 'vote_button__' + i) ;				
				newButton.value = 'Send My Vote!' ;
				newButton.onclick = function() { sendMyVote(this.id); } ;
				myForm.appendChild(newButton) ;
				
				//line breaks please
				thisLineBreak = document.createElement('br') ;
				myForm.appendChild(thisLineBreak) ;
				thisLineBreak = document.createElement('br') ;
				myForm.appendChild(thisLineBreak) ;
				thisLineBreak = document.createElement('br') ;
				myForm.appendChild(thisLineBreak) ;
				
				thisDiv.appendChild(myForm) ;
				parentElement.appendChild(thisDiv) ;
							
			}				
		
	}	
	
function sendMyVote(the_incoming_hat_delimited_string)

	{
											
		var array__the_incoming_hat_delimited_string = the_incoming_hat_delimited_string.split("^") ;
		
		var the__poll_id = array__the_incoming_hat_delimited_string[0] ;
		var the__response_length = array__the_incoming_hat_delimited_string[1] ;
		var the__div = 'this_main_container_div_id__' + array__the_incoming_hat_delimited_string[2] ;
		
		//grab the value I checked off - If I did!
		var value_obtained = '' ; 
				
		for ( var i=0; i<the__response_length; i++ )
		
			{
				
				var the_field = 'poll_field__' + the__poll_id + '__' + i ; 
								
				if ( document.getElementById(the_field).checked == true )
				
					{
						value_obtained = document.getElementById(the_field).value ;
					}
				
			}
		
		//validate first!
		if ( value_obtained == '' )
		
			{
				alert('Please select an answer before voting!') ;
				return false ;
			}
			
		//send it off for real!
		submitMyVoteToServer(the__poll_id, value_obtained, the__div) ;
	
	}
	
function submitMyVoteToServer(poll_id, value_obtained, the_div_to_take_action_on)

	{
	
		//ok, this function is actually going to send the data to the server, THEN it will refresh the screen and present the RESULTS div
		
		var the_url_for_sending_poll_data = 'http://www.leadstrike.com/offer_engine_interface/receive_poll_data.cfm?' + 'rn=' + Math.random() * 5 + '&the_poll_id=' + poll_id + '&the_value_obtained=' + value_obtained + '&the_unique_session_id=' + getCookie('unique_session_id') + '&the_div_to_take_action_on=' + the_div_to_take_action_on ;
						
		sendJSONRequest(the_url_for_sending_poll_data) ;
	
	}
	
function displayPollGreyedOut(jsonData)

	{
			
		// Where the form will be placed into the page
		parentElement = document.getElementById(jsonData.TheItems[0].the_div_to_take_action_on) ;
		parentElement.innerHTML = "" ;
		
		// Create a form
		myForm = document.createElement('FORM') ;
		myForm.method = 'post' ;
		myForm.action = '#' ;
		myForm.setAttribute('name', 'poll_form__' + 'greyed_out') ;
		myForm.id = 'poll_form__' + 'greyed_out' ;				
												
		//add a label
		thisLabel = document.createElement('label') ;
		thisLabel.className = 'label_design' ;
		myForm.appendChild(thisLabel) ;				
		//create the text for the label
		thisText = document.createTextNode(jsonData.TheItems[0].poll_question) ;
		thisLabel.appendChild(thisText) ;
		
		myForm.appendChild(document.createElement('BR')) ;
		myForm.appendChild(document.createElement('BR')) ;
		
		//add a label
		thisLabel = document.createElement('label') ;
		thisLabel.className = 'label_design' ;
		myForm.appendChild(thisLabel) ;				
		//create the text for the label
		thisText = document.createTextNode('Realtime Poll Results...') ;
		thisLabel.appendChild(thisText) ;
						
		myForm.appendChild(document.createElement('BR')) ;
		myForm.appendChild(document.createElement('BR')) ;
		
		var field__based_name = 'poll_field__' + jsonData.TheItems[0].poll_id ;
				
		for ( var x=0; x<jsonData.TheItems[0].PossibleResponses.length; x++ )
		
			{
												 	
			 	myForm.appendChild(document.createTextNode(jsonData.TheItems[0].PossibleResponses[x].poll_possible_response + ':' + jsonData.TheItems[0].PossibleResponses[x].the_percentage + '%')) ;			 	
			 	myForm.appendChild(document.createElement('BR')) ;

				var this_width = jsonData.TheItems[0].PossibleResponses[x].the_percentage + 2 ;
				
				if ( this_width > 2 )
				
					{
						this_width = this_width + 20 ;
					}
				
				myImage = document.createElement('img') ;
		 		myImage.setAttribute('src', 'http://www.leadstrike.com/images/bar.gif') ;
		 		myImage.setAttribute('width', this_width) ;
		 		myImage.setAttribute('height', '15') ;
		 		//myImage.className = 'logo' ;	
		 		myForm.appendChild(myImage) ;
				
				myForm.appendChild(document.createElement('BR')) ;	
			
			}			
		
		//line breaks please
		thisLineBreak = document.createElement('br') ;
		myForm.appendChild(thisLineBreak) ;
		thisLineBreak = document.createElement('br') ;
		myForm.appendChild(thisLineBreak) ;
		thisLineBreak = document.createElement('br') ;
		myForm.appendChild(thisLineBreak) ;
			
		parentElement.appendChild(myForm) ;
	
	}

function getSurveyRegistrationPageOffers(the_survey_id)

	{
	
		var the_url_for_reg_page_offers = 'http://www.leadstrike.com/offer_engine_interface/get_reg_page_offers__testing.cfm?' + 'rn=' + Math.random() * 5 + '&the_survey_id=' + the_survey_id ;
		
		sendJSONRequest(the_url_for_reg_page_offers) ; 
	
	}
	
function displaySurveyRegistrationPageOffers(jsonData)

	{
			
		var the_output = '' ;
				
		for ( var to=0; to<jsonData.TheItems.length; to++ )
		
			{
								
				the_output = the_output + '<div class="div_row">' + jsonData.TheItems[to].the_question + '<br>' + jsonData.TheItems[to].offer_layout + '<br><input class="form_field_design" type="radio" name="registration_offer__' + to + '" value="' + jsonData.TheItems[to].offer_id + '" id="registration_offer__yes__' + to + '"> Yes<br><input class="form_field_design" type="radio" name="registration_offer__' + to + '" value="0" id="registration_offer__no__' + to + '"> No</div>' ;
			
				//do this as DOM if u expect it to stick to the page for validation!
			
			}
			
		//reset the value in the form so we know how many sets of these to validate against
		document.wmi_form.num_registration_page_offers.value = to ;
						
		document.getElementById('div_registration_page_offers').innerHTML = the_output ;
	
	}	

function setRSessionIDValueForPage()

	{
	
		//first check to make sure the cookie has been set, go elsewhere if not the case
		var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
		
		var the_grab_r_session_id_url_value = 'http://www.leadstrike.com/offer_engine_interface/get_r_session_id_value.cfm?' + 'rn=' + Math.random() * 5 + '&unique_session_id=' + the_unique_session_id__cookied_value ;
	
		sendJSONRequest(the_grab_r_session_id_url_value) ;
	
	}
	
function doRSessionIDReturn(jsonData)

	{
		r__session_id__value = jsonData.r_session_id ;
		
		getOffersForThisPage() ;
	}
	
function doZipCheck()
	
	{
	
		var d = document.wmi_form ;
		
		if ( d.x_zip.value.length != 5 )
		
			{
				alert('Please make sure you key in a valid 5 digit zip code!')
				d.x_zip.focus() ;
				return false ;				
			}
			
		if ( d.x_zip.value.length == 5 )
		
			{
				var the_url_for_zip_checking = 'http://www.leadstrike.com/offer_engine_interface/get_zip_data.cfm?' + 'rn=' + Math.random() * 5 + '&the_value=' + d.x_zip.value ;
				sendJSONRequest(the_url_for_zip_checking) ; 				
			}
	
	}
	
function doStuffAfterGettingZipData(jsonData)

	{
		
		var d = document.wmi_form ;
		
		if ( jsonData.is_good != 'good' )
		
			{
				alert('The zip code you entered is not a valid US zip code!') ;
				d.x_zip.value = '' ;
				d.x_zip.focus() ;
				return false ;
			}
			
		else if ( jsonData.is_good == 'good' )
		
			{
				d.x_city.value = jsonData.the_city ;
				d.x_state.value = jsonData.the_state ;
				d.primary_phone_1.focus() ;
			}
				
	}

function getRandomizedCaptcha()

	{
	
		var the_url_for_captcha = 'http://www.leadstrike.com/offer_engine_interface/get_captcha.cfm?' + 'rn=' + Math.random() * 5 ;
		
		sendJSONRequest(the_url_for_captcha) ; 
	
	}
	
function doCaptchaReturn(jsonData)

	{
	
		var new_content = '<img src="http://www.leadstrike.com/captcha/images/' + jsonData.captcha_image + '">' ;
		new_content = new_content + '<input type="hidden" name="x__captcha" value="' + jsonData.captcha_value + '">' ;
		
		document.getElementById('div_captcha').innerHTML = new_content ;
			
	}	
		
function doUpperCaseFixing(to_which)
	
	{
	
		if ( to_which == 'First Name' )
		
			{
				var the_string = document.wmi_form.x_firstname.value ;			
				document.wmi_form.x_firstname.value = the_string.toUpperCase() ;
			}
			
		else if ( to_which == 'Last Name' )
		
			{
				var the_string = document.wmi_form.x_lastname.value ;			
				document.wmi_form.x_lastname.value = the_string.toUpperCase() ;
			}		
	
	}
	
function updateMemberAccount()

	{
	
		var mf = document.member_form ;
		
		if ( mf.member_firstname.value == '' )
		
			{
				alert('Required Field: First Name') ;
				mf.member_firstname.focus() ;
				return false ;
			}
			
		if ( mf.member_lastname.value == '' )
		
			{
				alert('Required Field: Last Name') ;
				mf.member_lastname.focus() ;
				return false ;
			}
			
		if ( mf.member_address.value == '' )
		
			{
				alert('Required Field: Address') ;
				mf.member_address.focus() ;
				return false ;
			}
			
		if ( mf.member_city.value == '' )
		
			{
				alert('Required Field: City') ;
				mf.member_city.focus() ;
				return false ;
			}
			
		if ( mf.member_state.value == '' )
		
			{
				alert('Required Field: State') ;
				mf.member_state.focus() ;
				return false ;
			}
			
		if ( mf.member_zip.value == '' )
		
			{
				alert('Required Field: Zip') ;
				mf.member_zip.focus() ;
				return false ;
			}
			
		if ( mf.member_area_code.value.length != 3 )
		
			{
				alert('Required Field: Area Code') ;
				mf.member_area_code.focus() ;
				return false ;
			}
			
		if ( mf.member_exchange.value.length != 3 )
		
			{
				alert('Required Field: Phone Exchange Number') ;
				mf.member_exchange.focus() ;
				return false ;
			}
			
		if ( mf.member_last_4.value.length != 4 )
		
			{
				alert('Required Field: Last 4 Digits of Phone') ;
				mf.member_last_4.focus() ;
				return false ;
			}
			
		if ( mf.member_email.value == '' )
		
			{
				alert('Required Field: E-Mail') ;
				mf.member_email.focus() ;
				return false ;
			}
			
		//check email syntax
		if ( checkEmailSyntax(mf.member_email.value) == false)
		
			{
				mf.member_email.value = '' ;
				mf.member_email.focus() ;
				return false ;
			}
			
		//handle the password RESET if supplied
		var the_password = mf.member_password.value ;
		
		if ( the_password != '' )
		
			{
			
				//trim it
				the_password = leftTrim(the_password) ;
				
				//must be at least 6 chars
				if ( the_password.length < 6 )
				
					{
						alert('If you are re-setting your password, please make sure it it at least 6 characters long!') ;
						mf.member_password.value = '' ;
						mf.member_password.focus() ;
						return false ;
					}
			
			}			
			
		//send it over
		var the_string_to_send_over = 'unique_session_id=' + getCookie('unique_session_id') ;
		the_string_to_send_over = the_string_to_send_over + '&member_firstname=' + mf.member_firstname.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_lastname=' + mf.member_lastname.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_address=' + mf.member_address.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_city=' + mf.member_city.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_state=' + mf.member_state.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_zip=' + mf.member_zip.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_area_code=' + mf.member_area_code.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_exchange=' + mf.member_exchange.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_last_4=' + mf.member_last_4.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_email=' + mf.member_email.value ;
		the_string_to_send_over = the_string_to_send_over + '&member_password=' + the_password ;
		
		var the_url_for_update = 'http://www.leadstrike.com/offer_engine_interface/update_survey_member_account.cfm?' + the_string_to_send_over + '&rn=' + Math.random() * 5 ;
		
		sendJSONRequest(the_url_for_update) ; 
	
	}
	
function whatToDoAfterUpdate(jsonData)

	{
		
		alert('Update Successful!') ;
		document.location.href = 'member-profile.html' ;

	}
	
function fetchMyDataForQSession()

	{
		
		var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
		
		var the_grab_r_session_id_url_value = 'http://www.leadstrike.com/offer_engine_interface/fetch_for_q.cfm?' + 'rn=' + Math.random() * 5 + '&unique_session_id=' + the_unique_session_id__cookied_value ;
	
		sendJSONRequest(the_grab_r_session_id_url_value) ;
		
	}
	
function populateForQ(jsonData)

	{
		
		var the_q_posting_url = 'http://lgn.coolsavings.com/lgn/index.aspx?PID=' + jsonData.PID + '&Token=' + jsonData.the_fetch ;
		
		MyIFrame = document.createElement('iframe') ;
		MyIFrame.setAttribute('src', the_q_posting_url) ;
		MyIFrame.setAttribute('width', '800') ;
		MyIFrame.setAttribute('height', '1600') ;
		MyIFrame.setAttribute('scrolling', ' no') ;
		
		document.getElementById('display_iframe_here').appendChild(MyIFrame) ;
	
	}
	
function checkEmailSyntax(str) 

	{
	
		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		
		
		if (str.indexOf(at)==-1)
		
			{
			   return false
			}
	
		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
		
			{
		    	return false
			}
	
		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		
			{
				return false
			}
	
		 if (str.indexOf(at,(lat+1))!=-1)
		 
		 {
			return false
		 }
	
		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		 
			 {
				return false
			 }
	
		 if (str.indexOf(dot,(lat+2))==-1)
		 
			{
				return false
			}
		
		 if (str.indexOf(" ")!=-1)
		 
		 {
			return false
		 }
	
		 return true					
	}

function doLoginAttempt()

	{
	
		var d = document.member_login_form ; 
		
		if ( d.member_email.value == '' )
		
			{
				alert('Please enter your member email address as your username!') ;
				d.member_email.focus() ;
				return false ;
			}
			
		if ( d.member_password.value == '' )
		
			{
				alert('Please enter your member password!') ;
				d.member_password.focus() ;
				return false ;
			}
			
		//ok, you have those 2 so send them off
		var member_login_string = 'the_member_email=' + d.member_email.value + '&the_member_password=' + d.member_password.value ;
		var the_login_url = 'http://www.leadstrike.com/offer_engine_interface/survey_member_login.cfm?' + member_login_string + '&rn=' + Math.random() * 5 ;

		sendJSONRequest(the_login_url) ;
			
	}
	
function logMeInOrNot(jsonData)

	{
	
		var d = document.member_login_form ;
		var the_good_or_bad = jsonData.Login ;
		
		//if bad
		if ( the_good_or_bad == 'bad' )
		
			{
				alert('Login Failure: ' + jsonData.ReasonWhy) ;
				d.member_email.value = '' ;
				d.member_password.value = '' ;				
				d.member_email.focus();			
			}
			
		else if ( the_good_or_bad == 'good' )
		
			{
			
				//carry the session value over in the URL to set it	
				document.location.href = '../members/set_cookie.html?url_unique_session_id=' + jsonData.SessionValue ;
				
			}		
	
	}
	
function getCookie(cookiename) 

	{
		var cookiestring = ""+document.cookie;
		
		var index1 = cookiestring.indexOf(cookiename);
		
		if (index1 == -1 || cookiename == "") 
		
			{
				return "";
			}
			
		var index2 = cookiestring.indexOf(';',index1);
		
		if (index2 == -1) 
		
			{
				index2=cookiestring.length;
			}
		
		return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
	}
		
function setCookie(name,value,duration)
		
	{
	
		cookiestring = name + "="+escape(value) + ";EXPIRES="+getExpiryDate(duration);
		
		document.cookie=cookiestring;
		
		return true;
			
	}
	
function getExpiryDate(nodays)
	
	{
		
		var UTCstring;
		
		Today = new Date();
		
		nomilli=Date.parse(Today);
		
		Today.setTime(nomilli + nodays * 24 * 60 * 60 * 1000);
		
		UTCstring = Today.toUTCString();
		
		return UTCstring;
		
	}
	
function checkIfLoggedIn()

	{
	
		//first check to make sure the cookie has been set, go elsewhere if not the case
		var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
		
		if ( the_unique_session_id__cookied_value.length == 0 )
		
			{
				document.location.href = '../survey.html' ;
			}
	
	}
	
function getMemberData(what_to_display)

	{
				
		var the_unique_session_id__cookied_value = getCookie('unique_session_id') ; 
		
		if ( the_unique_session_id__cookied_value.length == '' || the_unique_session_id__cookied_value == 'undefined' )
		
			{
				document.location.href = '../survey/index.html' ;
				return false ;
			}
		
		//ok you got this far, so check expiration		
		var the_member_data_url = 'http://www.leadstrike.com/offer_engine_interface/check_if_logged_in.cfm?unique_session_id=' + the_unique_session_id__cookied_value + '&rn=' + Math.random() * 5 + '&what_to_display=' + what_to_display ;
	
		sendJSONRequest(the_member_data_url) ;
	
	}
	
function doSomethingAfterCheckingExpiration(jsonData)

	{
							
		if ( jsonData.what_to_display == 'Just Top Login Name' || jsonData.what_to_display == 'Top Login Name And Member Update Form' || jsonData.what_to_display == 'Top Login Name And Welcome First Name' )
		
			{
				var the_welcome_div_content = '<p>Welcome <a href="member-profile.html">' + jsonData.FirstName + '</a> <a href="logout.html" class="small">(Not you?)</a></p>' ;
				document.getElementById('the_welcome_div_content').innerHTML = the_welcome_div_content ;
			}
			
		/*
		if ( jsonData.what_to_display == 'Top Login Name And Welcome First Name' )
		
			{
				var name_content_hello = '<p>Welcome ' + jsonData.FirstName + '</p>' ;
					document.getElementById('div_welcome_member_name').innerHTML = name_content_hello ;
			}
		*/
		
		if ( jsonData.what_to_display == 'Top Login Name And Member Update Form' )
		
			{
			
				document.member_form.member_firstname.value = jsonData.FirstName ;
				document.member_form.member_lastname.value = jsonData.LastName ;
				document.member_form.member_address.value = jsonData.Address ;
				document.member_form.member_city.value = jsonData.City ;
				document.member_form.member_state.value = jsonData.State ;
				document.member_form.member_zip.value = jsonData.Zip ;
				
				document.member_form.member_area_code.value = jsonData.AreaCode ;
				document.member_form.member_exchange.value = jsonData.Exchange ;
				document.member_form.member_last_4.value = jsonData.Last4 ;
				
				document.member_form.member_email.value = jsonData.Email ;	
			
			}						
			
			// Used on http://ondemandresearch.com/members/platinum.html
			  // Used on http://ondemandresearch.com/members/platinum.html
  
		if ( jsonData.what_to_display == 'Populate Paypal Form' ) 
		
			{
			
				var the_unique_session_id__cookied_value = getCookie('unique_session_id') ;
				
				document.getElementById('pp_first_name').value = jsonData.FirstName ;
				document.getElementById('pp_last_name').value = jsonData.LastName ;
				document.getElementById('pp_address1').value = jsonData.Address ;
				document.getElementById('pp_city').value = jsonData.City ;
				document.getElementById('pp_state').value = jsonData.State ;
				document.getElementById('pp_zip').value = jsonData.Zip ;
				document.getElementById('pp_country').value = jsonData.Exchange ;
				document.getElementById('pp_night_phone_a').value = jsonData.AreaCode ;
				document.getElementById('pp_night_phone_b').value = jsonData.Exchange ;
				document.getElementById('pp_night_phone_c').value = jsonData.Last4 ;
				document.getElementById('pp_email').value = jsonData.Email;
				document.getElementById('pp_cancel_return').value = 'http://ondemandresearch.com/members/paypal-return.html?destination=signup&action=none&email=' + jsonData.Email + '&id=' + jsonData.SurveyMemberId + '&rn=' + Math.random();
				document.getElementById('pp_return').value = 'http://ondemandresearch.com/members/paypal-return.html?destination=platinum&action=subscribe&email=' + jsonData.Email + '&id=' + jsonData.SurveyMemberId + '&rn=' + Math.random();
			
			}  			  			
	    
	}
	
function Left(str, n)

	{
	   if (n <= 0)
	         return "";
	   else if (n > String(str).length)
	         return str;
	   else
	         return String(str).substring(0,n);
	}
	
function getOffersForThisPage()

	{							
			
		//for Reg Path View, IF this is the last page then just end it, ok!!!
		if ( this_is_the_last_page == 1 )
		
			{
			
				if ( c__url_redirect_when_done != '' )
		
					{
						document.location.href = c__url_redirect_when_done ;
					}
					
				else
				
					{
						document.getElementById('paste_this_where_you_want_your_offers_to_display').innerHTML = '<h1>' + c__print_this_message_when_done + '</h1><br><br><br>' ;
					}
					
				return false ;
			
			}
		
		if ( r__session_id__value.length < 2 )
		
			{
			
				//read the URL vars
				var hash = getUrlVars();
							
				//see if you can find one for 'reg_path_session_id'
				var the_r__session_id__value = hash['set_r_session_id'] ; 
				
				//set if so
				if ( the_r__session_id__value != '' && the_r__session_id__value != undefined )
				
					{
						r__session_id__value = the_r__session_id__value ;
					}
			
			}	
								
		//start posting params
		var p = '' ;
		
		//what about the user's current value of reg_path_session_id r__session_id__value
		p = p + '&r__session_id__value=' + r__session_id__value ;	
		
		//user data for reg path session record
		p = p + '&y__firstname=' + y__firstname + '&y__lastname=' + y__lastname + '&y__address=' + y__address + '&y__city=' + y__city + '&y__state=' + y__state + '&y__zip=' + y__zip + '&y__email=' + y__email + '&y__phone_1=' + y__phone_1 + '&y__phone_2=' + y__phone_2 + '&y__dob=' + y__dob + '&y__gender=' + y__gender + '&y__desired_start=' + y__desired_start + '&y__level_of_education=' + y__level_of_education + '&y__hs_grad_year=' + y__hs_grad_year + '&y__military_status=' + y__military_status + '&y__best_time_to_call=' + y__best_time_to_call + '&y__employer=' + y__employer ;
		
		//page customization
		p = p + '&c__page_display_type=' + c__page_display_type + '&c__max_pages_to_display=' + c__max_pages_to_display + '&c__print_this_message_when_done=' + c__print_this_message_when_done ;											
		
		//query filtering
		p = p + '&f__max_offers=' + f__max_offers + '&f__offer_id=' + f__offer_id + '&f__category_id=' + f__category_id + '&f__gender=' + f__gender + '&f__age=' + f__age + '&f__region=' + f__region + '&f__state=' + f__state + '&f__zip=' + f__zip ;
		
		//pagintation and stuff
		p = p + '&current_page_displayed=' + current_page_displayed + '&f__survey_id=' + f__survey_id + '&pagination__uuid=' + pagination__uuid ;   
		
		//tracking
		p = p + '&t__affiliate_id=' + t__affiliate_id + '&t__rep_id=' + t__rep_id + '&t__media_link_id=' + t__media_link_id + '&t__s_id=' + t__s_id ;
		
		//complete string			
		var o_p_u = 'http://www.leadstrike.com/offer_engine_interface/get_response.cfm?action=get_response&rn=' + Math.random() * 5 + p ;
								
		sendJSONRequest(o_p_u) ;				
						
	}
	
function leftTrim(sString)
	{
	
		while (sString.substring(0,1) == ' ')
		
			{
				sString = sString.substring(1, sString.length);
			}
		
		return sString;
	
	}
	
function disableSubmitButton()

	{
		
		document.getElementById('the_submit_button').value = 'Processing your request.......' ;
		document.getElementById('the_submit_button').disabled = true ;
		
	}
	
function enableSubmitButton()

	{
		document.getElementById('the_submit_button').value = c__submit_button_text ;
		document.getElementById('the_submit_button').disabled = false ;
	}
	
function sendDataToServer()

	{					
	
		//start by disabling the SUBMIT button
		disableSubmitButton() ;
		
		//how many surveys are we streaming over? It's either none or just 1
		var num_survey_streams = 0 ;		
		
		//start off by checking if there was a survey presented on this page, if so then check over all its fields first and stream it over THEN do ur offers
		if ( c__page_display_type == 'Survey' )
		
			{
							
				//autopost on submit of survey page #1
				if ( current_page_displayed == 1 )
				
					{
						sendAutoPostOffers(r__session_id__value, t__media_link_id, t__s_id, 1) ;
					}
				
				num_survey_streams++ ;
				
				//start your SURVEY posting string off first, this is the CONTAINER for the page, offers are merely just embedded/sprinkled inside of this body so do the CONTAINER first!
				var ss = 'include_survey_id=' + f__survey_id + '&' ;			
				
				//find out the name of the hidden field that holds the list of all the fields and their types and their cosmetic labels
				the_hidden_field_containing_all_the_fields_and_their_data = document.getElementById('survey_fields_to_deal_with_first').value.split('^') ;		
				
				//ok so we're going to receive this in the following format: field_type=field_id=field_label
				//loop thru all your field sets
				for ( var this_field_set=0; this_field_set<the_hidden_field_containing_all_the_fields_and_their_data.length; this_field_set++ )
				
					{
					
						var array__field_set = the_hidden_field_containing_all_the_fields_and_their_data[this_field_set].split('=') ;
						
						//don't operate on a blank row
						if ( array__field_set.length > 1 )
						
							{
							
								//ok, so now if you split that, then your FIRST element is your field_type
								var this_field_type = array__field_set[0] ;
								
								//make sure it's not a blank set bcuz of last delim									
								if ( this_field_type == 'text_field' || this_field_type == 'select_menu' || this_field_type == 'comment_box' || this_field_type == 'hidden' )
								
									{
																					
										//loop over the ID list and which is to be split by |
										var the_id_list = array__field_set[1].split("|") ;
										
										for ( var ix=0; ix<the_id_list.length - 1; ix++ )
										
											{
																													
												//if it's required and not supplied then alert() and return false ;
												if ( array__field_set[3] == 1 && document.getElementById(the_id_list[ix]).value == '' && this_field_type != 'hidden' )
										
													{
														alert('Required Field: ' + array__field_set[2]) ;
														document.getElementById(the_id_list[ix]).focus() ;
														enableSubmitButton() ;
														return false ;															
													}																												
																									
												ss = ss + the_id_list[ix] + '=' + encodeURIComponent(document.getElementById(the_id_list[ix]).value) + '&' ;															
											
											}	
											
										//does this field have any special validations against it?!? AND in the above-mentioned formats?!? :)
										if ( array__field_set[4].length > 0 && this_field_type != 'hidden' )
										
											{
												
												//start with E-Mail
												if ( array__field_set[4] == 'E-Mail' )
												
													{
													
														if ( checkEmailSyntax(document.getElementById(the_id_list[0]).value) == false)

															{
																document.getElementById(the_id_list[0]).value = '' ;
																document.getElementById(the_id_list[0]).focus() ;
																enableSubmitButton() ;
																return false ;
															}
													
													}
													
												//now check phone
												if ( array__field_set[4] == 'Phone' )
												
													{
													
														var value__area_code = document.getElementById(the_id_list[0]).value ;
														var value__exchange = document.getElementById(the_id_list[1]).value ;
														var value__last_4 = document.getElementById(the_id_list[2]).value ;
														
														//if it was required then check it
														var check_this_phone = false ;
														
														//if it's required, then you have to check it anyway!
														if ( array__field_set[3] == 1 )
														
															{
																check_this_phone = true ;
															}
															
														//if not required, then check if they entered anything at all in any of them, if so then check against what they DID enter
														if ( check_this_phone == false )
														
															{
															
																if ( value__area_code.length > 0 || value__exchange.length > 0 || value__last_4.length > 0 )
																
																	{
																		check_this_phone = true ;
																	}
															
															}
															
														//do I have to check it???
														if ( check_this_phone == true )
														
															{
																
																if ( value__area_code.length != 3 )
																
																	{
																		alert('Please make sure to enter 3 digits for your area code!') ;
																		document.getElementById(the_id_list[0]).focus() ;
																		enableSubmitButton() ;
																		return false ;
																		
																	}
																	
																if ( value__exchange.length != 3 )
																
																	{
																		alert('Please make sure to enter 3 digits for your phone exchange!') ;
																		document.getElementById(the_id_list[1]).focus() ;
																		enableSubmitButton() ;
																		return false ;
																		
																	}
																	
																if ( value__last_4.length != 4 )
																
																	{
																		alert('Please make sure to enter 4 digits for the last 4 digits of your phone number!') ;
																		document.getElementById(the_id_list[2]).focus() ;
																		enableSubmitButton() ;
																		return false ;
																		
																	}
																
															}
													
													}
												
											}									
																					
									}												
									
								//otherwise if it's checkboxes or radio buttons then it's going to handled differently
								else if ( this_field_type == 'check_boxes' || this_field_type == 'radio_buttons')
								
									{
									
										//init the value
										var the_value = '' ;
										
										//obtain your id list
										var the_id_list = array__field_set[1].split("|") ;
										
										for ( var ix=0; ix<the_id_list.length - 1; ix++ )
										
											{
																						
												var this_value = document.getElementById(the_id_list[ix]).value ;
												var was_checked = document.getElementById(the_id_list[ix]).checked ;
												
												if ( was_checked == true )
												
													{														
														the_value = the_value + this_value + ',' ;															
													}
											
											}
											
										//get rid of the trailing comma @ the end
										if ( the_value.length > 1 )
										
											{
												the_value = Left(the_value, the_value.length - 1 ) ;												
											}
											
										//if it's required and not supplied then alert() and return false ;
										if ( array__field_set[3] == 1 && the_value == '' )
								
											{
												alert('Required Field: ' + array__field_set[2]) ;
												enableSubmitButton() ;
												return false ;															
											}
											
										//now clean up the field name to be what it currently is set to minus the '__0' ;
										the_url_field_name = Left(the_id_list[0], the_id_list[0].length - 3 ) ;	
											
										ss = ss + the_url_field_name + '=' + encodeURIComponent(the_value) + '&' ;
									
									}
							
							}																												
						
					}	
					
				//trim off the last &
				if ( ss.length > 1 )
				
					{
						ss = Left(ss, ss.length - 1) ;
					}	
					
				//set posting URL
				var survey_posting_url = 'http://www.leadstrike.com/offer_engine_interface/receive_lead_data.cfm?rn=' + Math.random() * 5 + '&' + ss + '&this_reg_path_session_id=' + r__session_id__value + '&affiliate_id=' + t__affiliate_id + '&the_media_link_id_value=' + t__media_link_id + '&the_s_id=' + t__s_id + '&current_page_displayed=' + current_page_displayed ;			
									
			}		
		
		//OFFERS
		
		//build a list of offers that were checked off as YES. This is either going to be a) checkboxes or b) radio buttons checked off as YES so u need to be careful here. Build the list so that we don't have to reference all this in future!
		var list__offers_we_are_going_to_stream_over = '' ;
				
		var array__offers = document.getElementById('all_offers_presented').value.split("|") ;
						
		//first off, Offers displayed within a Survey are produced and presented as radio buttons, so deal with this please by first making 100% sure that YES|NO have been filled in by the user!
		if ( c__page_display_type == 'Survey'  || c__page_display_type == 'Featured Offers Presented In Survey Style' )
		
			{
							
				for ( var current_offer=0; current_offer<array__offers.length; current_offer++ )
				
					{
						
						//proceed only if not ''
						if ( array__offers[current_offer] != '' )
						
							{
							
								//set field name						
								var the_field_name__yes = 'registration_offer__yes__' + array__offers[current_offer] ;
								var the_field_name__no = 'registration_offer__no__' + array__offers[current_offer] ;
								
								//presentation format
								var the_field_name__presentation_format = 'presentation_format__offer__' + array__offers[current_offer] ;
								
								if ( document.getElementById(the_field_name__yes).checked == false && document.getElementById(the_field_name__no).checked == false )
								
									{
										alert('Please select YES or NO next to the offers on this page!') ;
										enableSubmitButton() ;
										return false ;						
									}
									
								//add me so far pls
								if ( document.getElementById(the_field_name__yes).checked == true && document.getElementById(the_field_name__presentation_format).value == 'HTML Form' )
								
									{
										
										//add me then!
										list__offers_we_are_going_to_stream_over = list__offers_we_are_going_to_stream_over + document.getElementById(the_field_name__yes).value + '|' ;
																			
									}
																									
							}						
											
					}			
			
			}
			
		//otherwise, it's NOT a survey THEREFORE checkboxes instead of radio buttons!
		else
		
			{
			
				for ( var current_offer=0; current_offer<array__offers.length; current_offer++ )
				
					{
						
						//proceed only if not ''
						if ( array__offers[current_offer] != '' )
						
							{
							
								//set field name						
								var the_field_name__checked = 'include_offer_id__' + array__offers[current_offer] ;
								
								if ( document.getElementById(the_field_name__checked).checked == true )
								
									{
										
										//add me then!
										list__offers_we_are_going_to_stream_over = list__offers_we_are_going_to_stream_over + document.getElementById(the_field_name__checked).value + '|' ;
																		
									}
																
							}						
											
					}
			
			}
			
						
		//now loop over and remove that last pipe | IF it is one
		var list__offers_new = '' ;
		
		var array__offers_to_stream_over = list__offers_we_are_going_to_stream_over.split("|") ;
				
		for ( var i=0; i<array__offers_to_stream_over.length - 1; i++ )
		
			{
				
				if ( array__offers_to_stream_over[i] != '' )
				
					{					
						list__offers_new = list__offers_new + array__offers_to_stream_over[i] + '|' ;							
					}									
								
			}
			
		//get rid of that last '|' !!!
		if ( list__offers_new.length > 01 )
		
			{				
				list__offers_new = Left(list__offers_new, list__offers_new.length - 1) ;				
			}	
				

		//ok, you have built up your list, so get ready to stream each one over!!!
		var array__offers_to_stream_over = list__offers_new.split("|") ;
		
		//How many offers are we streaming over???
		var num_offer_streams = 0 ;
		
		for ( var this_offer_counter=0; this_offer_counter<array__offers_to_stream_over.length; this_offer_counter++ )
										
			{
								
				var current_offer_id_value = array__offers_to_stream_over[this_offer_counter] ;
				
				if ( current_offer_id_value != '' )
				
					{
										
						num_offer_streams++ ;
						
						var ps = 'include_offer_id=' + current_offer_id_value + '&' ; 									
				
						//find out the name of the hidden field that holds the list of all the fields and their types and their cosmetic labels
						var the_hidden_concat_id = 'field__offer_id__' + current_offer_id_value ;
						the_hidden_field_containing_all_the_fields_and_their_data = document.getElementById(the_hidden_concat_id).value.split('^') ;						
						
						//ok so we're going to receive this in the following format: field_type=field_id=field_label
						//loop thru all your field sets
						for ( var this_field_set=0; this_field_set<the_hidden_field_containing_all_the_fields_and_their_data.length; this_field_set++ )
						
							{
							
								var array__field_set = the_hidden_field_containing_all_the_fields_and_their_data[this_field_set].split('=') ;
								
								//don't operate on a blank row
								if ( array__field_set.length > 1 )
								
									{
									
										//ok, so now if you split that, then your FIRST element is your field_type
										var this_field_type = array__field_set[0] ;
										
										//make sure it's not a blank set bcuz of last delim									
										if ( this_field_type == 'text_field' || this_field_type == 'select_menu' || this_field_type == 'comment_box' || this_field_type == 'hidden' )
										
											{
																							
												//loop over the ID list and which is to be split by |
												var the_id_list = array__field_set[1].split("|") ;
												
												for ( var ix=0; ix<the_id_list.length - 1; ix++ )
												
													{
																															
														//if it's required and not supplied then alert() and return false ;
														if ( array__field_set[3] == 1 && document.getElementById(the_id_list[ix]).value == '' && this_field_type != 'hidden' )
												
															{
																alert('Required Field: ' + array__field_set[2]) ;
																document.getElementById(the_id_list[ix]).focus() ;
																enableSubmitButton() ;
																return false ;															
															}																												
																											
														ps = ps + the_id_list[ix] + '=' + encodeURIComponent(document.getElementById(the_id_list[ix]).value) + '&' ;															
													
													}	
													
												//does this field have any special validations against it?!? AND in the above-mentioned formats?!? :)
												if ( array__field_set[4].length > 0 && this_field_type != 'hidden' )
												
													{
														
														//start with E-Mail
														if ( array__field_set[4] == 'E-Mail' )
														
															{
															
																if ( checkEmailSyntax(document.getElementById(the_id_list[0]).value) == false)
		
																	{
																		document.getElementById(the_id_list[0]).value = '' ;
																		document.getElementById(the_id_list[0]).focus() ;
																		enableSubmitButton() ;
																		return false ;
																	}
															
															}
															
														//now check phone
														if ( array__field_set[4] == 'Phone' )
														
															{
															
																var value__area_code = document.getElementById(the_id_list[0]).value ;
																var value__exchange = document.getElementById(the_id_list[1]).value ;
																var value__last_4 = document.getElementById(the_id_list[2]).value ;
																
																//if it was required then check it
																var check_this_phone = false ;
																
																//if it's required, then you have to check it anyway!
																if ( array__field_set[3] == 1 )
																
																	{
																		check_this_phone = true ;
																	}
																	
																//if not required, then check if they entered anything at all in any of them, if so then check against what they DID enter
																if ( check_this_phone == false )
																
																	{
																	
																		if ( value__area_code.length > 0 || value__exchange.length > 0 || value__last_4.length > 0 )
																		
																			{
																				check_this_phone = true ;
																			}
																	
																	}
																	
																//do I have to check it???
																if ( check_this_phone == true )
																
																	{
																		
																		if ( value__area_code.length != 3 )
																		
																			{
																				alert('Please make sure to enter 3 digits for your area code!') ;
																				document.getElementById(the_id_list[0]).focus() ;
																				enableSubmitButton() ;
																				return false ;
																				
																			}
																			
																		if ( value__exchange.length != 3 )
																		
																			{
																				alert('Please make sure to enter 3 digits for your phone exchange!') ;
																				document.getElementById(the_id_list[1]).focus() ;
																				enableSubmitButton() ;
																				return false ;
																				
																			}
																			
																		if ( value__last_4.length != 4 )
																		
																			{
																				alert('Please make sure to enter 4 digits for the last 4 digits of your phone number!') ;
																				document.getElementById(the_id_list[2]).focus() ;
																				enableSubmitButton() ;
																				return false ;
																				
																			}
																		
																	}
															
															}
														
													}									
																							
											}												
											
										//otherwise if it's checkboxes or radio buttons then it's going to handled differently
										else if ( this_field_type == 'check_boxes' || this_field_type == 'radio_buttons')
										
											{
											
												//init the value
												var the_value = '' ;
												
												//obtain your id list
												var the_id_list = array__field_set[1].split("|") ;
												
												for ( var ix=0; ix<the_id_list.length - 1; ix++ )
												
													{
																								
														var this_value = document.getElementById(the_id_list[ix]).value ;
														var was_checked = document.getElementById(the_id_list[ix]).checked ;
														
														if ( was_checked == true )
														
															{														
																the_value = the_value + this_value + ',' ;															
															}
													
													}
													
												//get rid of the trailing comma @ the end
												if ( the_value.length > 1 )
												
													{
														the_value = Left(the_value, the_value.length - 1 ) ;												
													}
													
												//if it's required and not supplied then alert() and return false ;
												if ( array__field_set[3] == 1 && the_value == '' )
										
													{
														alert('Required Field: ' + array__field_set[2]) ;
														enableSubmitButton() ;
														return false ;															
													}
													
												//now clean up the field name to be what it currently is set to minus the '__0' ;
												the_url_field_name = Left(the_id_list[0], the_id_list[0].length - 3 ) ;	
													
												ps = ps + the_url_field_name + '=' + encodeURIComponent(the_value) + '&' ;
											
											}
									
									}																												
								
							}	
							
						//trim off the last &
						if ( ps.length > 1 )
						
							{
								ps = Left(ps, ps.length - 1) ;
							}
							
						//set posting URL
						var p_u = 'http://www.leadstrike.com/offer_engine_interface/receive_lead_data.cfm?rn=' + Math.random() * 5 + '&' + ps + '&this_reg_path_session_id=' + r__session_id__value + '&affiliate_id=' + t__affiliate_id + '&the_media_link_id_value=' + t__media_link_id + '&the_s_id=' + t__s_id ;
						
						//ok, if this is the final one, THEN finalize the page
						if ( ( ( array__offers_to_stream_over.length - 1 ) == this_offer_counter ) && ( num_survey_streams == 0 ) )
						
							{								
								p_u = p_u + '&finalize_the_page=1' ;									
							}						
																																																																	
						//send it off
						sendJSONRequest(p_u) ;					
					
					}				
					
			}
			
		//finalize here
		if ( num_survey_streams == 0 && num_offer_streams == 0 )
		
			{
				finalizePage(1) ;				
			}			
	
		else if ( num_survey_streams == 1 && num_offer_streams == 0  )
		
			{
				survey_posting_url = survey_posting_url + '&finalize_the_page=1' ;
				sendJSONRequest(survey_posting_url) ;						
			}
			
		else if ( num_survey_streams == 1 && num_offer_streams > 0  )
		
			{
				survey_posting_url = survey_posting_url + '&finalize_the_page=1' ;
				sendJSONRequest(survey_posting_url) ;						
			}					
	
	}
	
function displayToClient(jsonData)

	{	
		
		document.getElementById('div_pixels_here').innerHTML = document.getElementById('div_pixels_here').innerHTML + jsonData.Pixel ;
		
		//push out display testing variables and strings, etc if so
		if ( display_output_variables == true )
		
			{
				document.getElementById('div_pixels_here').innerHTML = document.getElementById('div_pixels_here').innerHTML + '<br>Outgoing String: ' + jsonData.outgoing_string ;
				document.getElementById('div_pixels_here').innerHTML = document.getElementById('div_pixels_here').innerHTML + '<br>Response: ' + jsonData.status_response ;
				return false ;
			}
								
		//ok the pixel was just printed out above, give it a full second to load as some clients' pixels are slow THEN you can move on
		//var f = function() {finalizePage(jsonData.finalize_the_page); };
		//setTimeout(f, 2000);
		
		finalizePage(jsonData.finalize_the_page); 
		
	}
	
function finalizePage(are_we_actually_finalizing_the_page)

	{
					
		if ( c__page_display_type == 'Reg Path View' )
		
			{
			
				if ( this_is_the_last_page == 0 )
				
					{
						getOffersForThisPage() ;				
					}
					
				else
				
					{
					
						if ( c__url_redirect_when_done != '' )
				
							{
								document.location.href = c__url_redirect_when_done ;
							}
							
						else
						
							{
								document.getElementById('paste_this_where_you_want_your_offers_to_display').innerHTML = '<h1>' + c__print_this_message_when_done + '</h1><br><br><br>' ;
							}
					
					}
			
			}
			
		else
		
			{
			
				if ( are_we_actually_finalizing_the_page == 1 )
		
					{
																	
						//if type survey, then grab some pop unders
						if ( c__page_display_type == 'Survey' )
						
							{
								
								grabPopUnders(r__session_id__value, current_page_displayed) ;								
								
							}
						
						if ( current_page_displayed < c__max_pages_to_display )
		
							{
								getOffersForThisPage() ; 			
							}
															
						else if ( c__url_redirect_when_done != '' )
						
							{
								
								var this_concat = '?' ;
								
								var the_position_of_the_q_mark = c__url_redirect_when_done.indexOf('?') ;
								
								if ( the_position_of_the_q_mark > -1 )
								
									{
										this_concat = '&' ;
									}
								
								document.location.href = c__url_redirect_when_done + this_concat + 'set_r_session_id=' + r__session_id__value ;
								
							}
							
						else
						
							{
								document.getElementById('paste_this_where_you_want_your_offers_to_display').innerHTML = '<h1>' + c__print_this_message_when_done + '</h1><br><br><br>' ;
							}						
														
					}
			
			}				
		
	}
		
function sendJSONRequest(the_url)

	{
			
		var obj=new JSONscriptRequest(the_url);     
		
		obj.buildScriptTag(); // Build the script tag 
		obj.addScriptTag(); // Execute (add) the script tag
	
	}
	
function runOpenStandardsJSONWebServiceAPI(jsonData)

	{
					 						
		//first off, define your user's session
		r__session_id__value = jsonData.r_session_id ;
		
		//refresh the max number of pages that we will cycle through
		c__max_pages_to_display = jsonData.c__max_pages_to_display ;
		
		//set the new page to what is being displayed currently
		current_page_displayed = jsonData.current_page_displayed ;
		
		if ( c__page_display_type == 'Survey'  )
		
			{
								
				var value__survey_fields_to_deal_with_first = '' ;
				var value__all_offers_presented = '' ;
				
				// Where the form will be placed into the page
				parentElement = document.getElementById('paste_this_where_you_want_your_offers_to_display') ;
				parentElement.innerHTML = "" ;
				
				// Create a form
				myForm = document.createElement('form') ;
				myForm.method = 'post' ;
				myForm.action = '#' ;
				myForm.setAttribute('name', 'wmi_form') ;
				myForm.id = 'wmi_form' ;								
				
				//add a label
				thisLabel = document.createElement('H2') ;
				myForm.appendChild(thisLabel) ;				
				//create the text for the label
				thisText = document.createTextNode(jsonData.survey_page_title) ;
				thisLabel.appendChild(thisText) ;							
				
				var list_of_fields = '' ;	
																
				//for as many entities for this survey as returned
				for ( var jl=0; jl<jsonData.Legend.length; jl++ )
				
					{
						
						//jsonData.Legend[jl].page_entity  = Question header
						if ( jsonData.Legend[jl].page_entity == 'Question Header' )
						
							{								
								
								var the_design_to_print = '<p>' + jsonData.Legend[jl].message_if_question + '</p>' ;
								
								myForm.appendChild(document.createTextNode(the_design_to_print)) ;
								
							}						
						
						//jsonData.Legend[jl].page_entity  = Survey Field
						else if ( jsonData.Legend[jl].page_entity == 'Survey Field' )
						
							{
								
								//create new question with a couple line breaks						
								thisDiv = document.createElement('br') ;
								myForm.appendChild(thisDiv) ;									
								
								//find out the Question Header - this will always just be one
								for ( var sq=0; sq<jsonData.Legend[jl].FieldSets.length; sq++ )
								
									{
										
										var list_of_ids_for_this_field_set = '' ;
										
										//add a label
										thisLabel = document.createElement('label') ;
										//thisLabel.className = 'label_design' ;
										myForm.appendChild(thisLabel) ;				
										//create the text for the label
										thisText = document.createTextNode(jsonData.Legend[jl].FieldSets[sq].f_l) ;
										thisLabel.appendChild(thisText) ;										
										
										//create new question with a couple line breaks
										thisDiv = document.createElement('br') ;
										myForm.appendChild(thisDiv) ;
												
										//Now present your form field			 							
			 							if ( jsonData.Legend[jl].FieldSets[sq].f_t == 'text_field' )
			 							
			 								{					 									
			 								
												var list__text_fields = jsonData.Legend[jl].FieldSets[sq].f_n.split("|");
												var list__prepopulated_values = jsonData.Legend[jl].FieldSets[sq].f_v.split("|");
												var list__text_field_length = jsonData.Legend[jl].FieldSets[sq].f_s.split("|");
												var list__max_lengths = jsonData.Legend[jl].FieldSets[sq].m_lens.split("|");
																												
												for ( var tt=0; tt<list__text_fields.length; tt++ )
												
													{
														
														//size
														var the_size = list__text_field_length[i] ;
														
														if ( the_size == '' || the_size == undefined )
														
															{
																the_size = '17' ;
															}
															
														//prepop value
														var the_prepop_value = list__prepopulated_values[tt] ;
														
														if ( the_prepop_value == '' || the_prepop_value == undefined )
														
															{
																the_prepop_value = '' ;
															}
															
														var the_max_length = list__max_lengths[tt] ;
														
														if ( the_max_length == undefined )
														
															{
																the_max_length = '' ;
															}
													
														textField = document.createElement('INPUT') ;
													 	textField.type = 'text' ;
													 	textField.id = list__text_fields[tt] ;
													 	textField.setAttribute('name', list__text_fields[tt]) ;
													 	textField.setAttribute('value', the_prepop_value) ;											 	
													 	textField.setAttribute('size', the_size) ;
													 	textField.setAttribute('maxlength', the_max_length) ;
													 	textField.className = 'form_field_design' ;
																										
														//if there is E-Mail validation against this field, then append it
														if ( jsonData.Legend[jl].FieldSets[sq].f_val == 'E-Mail' )
														
															{
																														
																textField.setAttribute('temp_holder', jsonData.Legend[jl].offer_id) ;
																textField.onblur = function() { checkIfIsDuplicateLead(this.value, this.temp_holder); };
																
															}												
														
													 	myForm.appendChild(textField) ;
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__text_fields[tt] + '|' ;											 	
													 												
													}
			 								
			 								}
			 								
			 							else if ( jsonData.Legend[jl].FieldSets[sq].f_t == 'select_menu' )
			 							
			 								{
			 																					 	
											 	var list__select_field_name = jsonData.Legend[jl].FieldSets[sq].f_n.split("|") ;
		
												//split this guy up at the ^ level, remember the inners are |, but don't be misguided!!!
												var list__arrays_or_arrays__split_value_pairs = jsonData.Legend[jl].FieldSets[sq].f_d_v.split("^") ;
																										
												//loop over select field names as highest!
												for ( var sm=0; sm<list__select_field_name.length; sm++  )
												
													{
																															
														// Create a drop-down list
													 	dropDown = document.createElement('SELECT') ;
													 	dropDown.id = list__select_field_name[sm] ;
													 	dropDown.setAttribute('name', list__select_field_name[sm]) ;
													 	dropDown.className = 'form_field_design' ;															 	
													 	
													 	//now grab the row out of the ^ delimited list which are the name|value pairs
														var this_list = list__arrays_or_arrays__split_value_pairs[sm] ;
														
														//now create new list declaration
														var new_list = this_list.split("|") ;
														
														//does this list contain at least 1 that's going to make the page bleed or the form push everything around???
														var contains_at_least_one_bleeder = false ;
														
														//start with SELECT value=""
														option = document.createElement('option') ;
												  		option.value = '' ;	
												  		option.appendChild(document.createTextNode('Select')) ;
												  		dropDown.appendChild(option) ;
														
														//loop over THIS_LIST which is | in of itself
														for ( var mo=0; mo<new_list.length; mo++ )
														
															{
																																																			
																//ok, now you have something that looks like this MI=Michigan so split that up based on the equals sign as a delimiter = 
																var this_new_split = new_list[mo].split("=") ;
																
																var the_row_value = this_new_split[0] ;
																var the_row_display = this_new_split[1] ;
																
																//if the row display is too big, then Left() function it please
																if ( the_row_display.length >= 85 )
																
																	{
																		the_row_display = Left(the_row_display, 85) + '...' ;
																		contains_at_least_one_bleeder = true ;
																	}
																
																option = document.createElement('option') ;
														  		option.value = the_row_value ;																		  		
														  														  		
																if ( jsonData.Legend[jl].FieldSets[sq].f_v == the_row_value )
																
																	{
																		option.setAttribute('selected', 'true')
																	}																				 																				  	
																  		
														  		option.appendChild(document.createTextNode(the_row_display)) ;
														  		dropDown.appendChild(option) ;																											
																
															}															 	
													 	
													 	myForm.appendChild(dropDown) ;	
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__select_field_name[sm] + '|' ;											 														
														
													}													 	
			 								
			 								}
			 								
			 							else if ( jsonData.Legend[jl].FieldSets[sq].f_t == 'radio_buttons' )
			 							
			 								{
			 										 			 								
			 									var array_values_and_displays = jsonData.Legend[jl].FieldSets[sq].f_d_v.split("|");
												
												for( var rb=0; rb<array_values_and_displays.length; rb++)
												
													{
														//split up that row now!!!
														var valueArrayRowSplit = array_values_and_displays[rb].split("=");
														
														var the_row_value = valueArrayRowSplit[0] ;	
														var the_row_display = valueArrayRowSplit[1] ;	
																									
														// Create a radio selection												
														if(!document.addEventListener) 
														
															{
															 	// IE hack
																radioField= document.createElement("<input name=\"" + jsonData.Legend[jl].FieldSets[sq].f_n + "\"/>");
															} 
														
														else 
														
															{
																radioField= document.createElement("input");
															}													 	
													 	
													 	radioField.type = 'radio' ;
													 	radioField.id = jsonData.Legend[jl].FieldSets[sq].f_n + '__' + rb ;
													 	radioField.name = jsonData.Legend[jl].FieldSets[sq].f_n ;
													 	radioField.className = 'form_field_design' ;
													 	radioField.value = the_row_value ; 	
													 	
													 	if ( jsonData.Legend[jl].FieldSets[sq].f_v == the_row_value )
														
															{
																radioField.defaultChecked = true ;
																radioField.checked = true  ;
															}
													 	
													 	myForm.appendChild(radioField) ;
													 	myForm.appendChild(document.createTextNode(the_row_display)) ;
													 	
													 	myForm.appendChild(document.createElement('BR')) ;	
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[sq].f_n + '__' + rb + '|' ;										 		
														
													}																	 			 	
											 														 					 								
			 								}
			 								
			 							else if ( jsonData.Legend[jl].FieldSets[sq].f_t == 'check_boxes' )
			 							
			 								{
			 									 	
											 	//split this list up just once please
												var array_split_of_value_pairs = jsonData.Legend[jl].FieldSets[sq].f_d_v.split("|");
												
												var array_prechecked_values = jsonData.Legend[jl].FieldSets[sq].f_v.split("|") ;
												
												for( var cb=0; cb<array_split_of_value_pairs.length; cb++)
												
													{
														//split up that row now!!!
														var valueArrayRowSplit = array_split_of_value_pairs[cb].split("=");
														
														var the_row_value = valueArrayRowSplit[0] ;	
														var the_row_display = valueArrayRowSplit[1] ;
														
														//ok, now check against your list of pre-populated values to see if this value is in the list!!!
														var current_checkbox_value_is_in_prechecked_list = false ;
														
														for ( var list_element_i=0; list_element_i<array_prechecked_values.length; list_element_i++ )
														
															{
																//if the current i value MATCHES the same value as that which is about to be presented as the checkbox value, then You're On!!!!
																if ( array_prechecked_values[list_element_i] == the_row_value )
																
																	{
																		current_checkbox_value_is_in_prechecked_list = true ;
																		break ;
																	}
															}	
															
														// Create a checkbox
													 	checkbox = document.createElement('INPUT') ;
													 	checkbox.type = 'checkbox' ;
													 	checkbox.id = jsonData.Legend[jl].FieldSets[sq].f_n + '__' + cb ;
													 	checkbox.setAttribute('name', jsonData.Legend[jl].FieldSets[sq].f_n) ;
													 	checkbox.className = 'form_field_design' ;
													 	checkbox.setAttribute('value', the_row_value) ;
													 	
													 	if ( current_checkbox_value_is_in_prechecked_list == true )
														
															{
																checkbox.setAttribute('checked', 'checked') ;
															}
													 	
													 	myForm.appendChild(checkbox) ;
													 	myForm.appendChild(document.createTextNode(the_row_display)) ;	
													 	
													 	myForm.appendChild(document.createElement('BR')) ;
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[sq].f_n + '__' + cb + '|' ;	
														
													}											
			 								
			 								}
			 								
			 							else if ( jsonData.Legend[jl].FieldSets[sq].f_t == 'comment_box' )
			 							
			 								{
			 									//z = z + generateCommentBox(, , jsonData.Offers[i].FieldSets[f].the_cols, jsonData.Offers[i].FieldSets[f].the_rows, false) ;						 								
			 									// Create a textarea
											 	textArea = document.createElement('TEXTAREA') ;
											 	textArea.id = jsonData.Legend[jl].FieldSets[sq].f_n ;
											 	textArea.setAttribute('name', jsonData.Legend[jl].FieldSets[sq].f_n) ;
											 	textArea.setAttribute('value', jsonData.Legend[jl].FieldSets[sq].f_v) ;
											 	textArea.className = 'form_field_design' ;
											 	myForm.appendChild(textArea) ;
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[sq].f_n + '|' ;
			 								
			 								}	
			 								
			 							else if ( jsonData.Legend[jl].FieldSets[sq].f_t == 'hidden' )
			 							
			 								{
			 									
			 									var array__field_names = jsonData.Legend[jl].FieldSets[sq].f_n.split("|");
												var array__prepopulated_values = jsonData.Legend[jl].FieldSets[sq].f_v.split("|");
																												
												for ( var hf=0; hf<array__field_names.length; hf++ )
												
													{
																															
														//prepop value
														var the_prepop_value = array__prepopulated_values[hf] ;
														
														if ( the_prepop_value == '' || the_prepop_value == undefined )
														
															{
																the_prepop_value = '' ;
															}
													
														hiddenField = document.createElement('INPUT') ;
													 	hiddenField.type = 'hidden' ;
													 	hiddenField.id = array__field_names[hf] ;
													 	hiddenField.setAttribute('name', array__field_names[hf]) ;
													 	hiddenField.setAttribute('value', the_prepop_value) ;															 	
													 	myForm.appendChild(hiddenField) ;
													 	
													 	myForm.appendChild(document.createElement('BR')) ;
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + array__field_names[hf] + '|' ;
													 												
													}
			 								
			 								}
			 										 									 								
			 							//append to list so we know ur there please	 							
			 							value__survey_fields_to_deal_with_first = value__survey_fields_to_deal_with_first + jsonData.Legend[jl].FieldSets[sq].f_t + '=' + list_of_ids_for_this_field_set + '=' + jsonData.Legend[jl].FieldSets[sq].f_l + '=' + jsonData.Legend[jl].FieldSets[sq].f_r + '=' + jsonData.Legend[jl].FieldSets[sq].f_val + '^' ;					 								
			 							
		 							}		 														
								
							}						
						
						//jsonData.Legend[jl].page_entity  = Offer
						else if ( jsonData.Legend[jl].page_entity == 'Offer' )
						
							{
																			
								value__all_offers_presented = value__all_offers_presented + jsonData.Legend[jl].offer_id + '|' ;	
						
								//crank out your div id now and hold it
								var this_main_container_div_id = 'div_container__' + jsonData.Legend[jl].offer_id ;																				
								
								//HTML not Text for your Survey
								IntroQuestionDiv = document.createElement('div') ;
								IntroQuestionDiv.id = 'intro_line_div__' + jsonData.Legend[jl].offer_id ;
								IntroQuestionDiv.innerHTML = jsonData.Legend[jl].lead_in_text_if_offer ;
								IntroQuestionDiv.className = 'dashed_div' ;								
								myForm.appendChild(IntroQuestionDiv) ;						
								
								//then append them to the rowDiv
								myForm.appendChild(document.createElement('BR')) ;
		
								//yes radio button here
								var the_share_radio_button_name = 'registration_offer__' + jsonData.Legend[jl].offer_id ;
								
								// Create a radio selection												
								if(!document.addEventListener) 
								
									{
									 	// IE hack
										radioField= document.createElement("<input name=\"" + the_share_radio_button_name + "\"/>");
									} 
								
								else 
								
									{
										radioField= document.createElement("input");
									}
								
							 	radioField.type = 'radio' ;
							 	radioField.id = 'registration_offer__yes__' + jsonData.Legend[jl].offer_id ;
							 	radioField.setAttribute('name', the_share_radio_button_name) ;
							 	radioField.className = 'form_field_design' ;
							 	radioField.value = jsonData.Legend[jl].offer_id ; 
							 	radioField.onclick = function() { doRadioButtonOpenAndClose('div_container__' + this.value, 'Yes'); };								 	
							 	myForm.appendChild(radioField) ;
							 	myForm.appendChild(document.createTextNode('Yes')) ;					 	
							 	
							 	//line break between radio button selections
							 	myForm.appendChild(document.createElement('BR')) ;					 	
							 	
							 	//no radio button here
							 	// Create a radio selection												
								if(!document.addEventListener) 
								
									{
									 	// IE hack
										radioField= document.createElement("<input name=\"" + the_share_radio_button_name + "\"/>");
									} 
								
								else 
								
									{
										radioField= document.createElement("input");
									}
									
							 	radioField.type = 'radio' ;
							 	radioField.id = 'registration_offer__no__' + jsonData.Legend[jl].offer_id ;
							 	radioField.setAttribute('name', the_share_radio_button_name) ;
							 	radioField.className = 'form_field_design' ;
							 	radioField.value = jsonData.Legend[jl].offer_id ; 
							 	radioField.onclick = function() { doRadioButtonOpenAndClose('div_container__' + this.value, 'No'); };									 	
							 	myForm.appendChild(radioField) ;
							 	myForm.appendChild(document.createTextNode('No')) ;								 			 	
								
								myForm.appendChild(document.createElement('BR')) ;
								myForm.appendChild(document.createElement('BR')) ;	
								
								//OfferDiv container that you can collapse, etc
								offerDiv = document.createElement('div') ;
								offerDiv.id = this_main_container_div_id ;						
								offerDiv.style.display = 'none' ;
								
								IntroQuestionDiv.appendChild(offerDiv) ;
								
								//HTML not Text for your Survey
								TopHTML = document.createElement('div') ;
								TopHTML.id = 'top_html_div__' + jsonData.Legend[jl].offer_id ;
								TopHTML.style.width = '375px' ;
								TopHTML.style.margin = '0px 100px 14px 65px' ;
								TopHTML.innerHTML = jsonData.Legend[jl].offer_layout ;
								offerDiv.appendChild(TopHTML) ;					
								
								//set list of fields to validate for this offer
						 		var list_of_fields = '' ; 	
						 		
						 		//specify what presentation_format this guy is
						 		hiddenField = document.createElement('input') ;
							 	hiddenField.type = 'hidden' ;
							 	hiddenField.id = 'presentation_format__offer__' + jsonData.Legend[jl].offer_id ;
							 	hiddenField.setAttribute('name', 'presentation_type__offer__' + jsonData.Legend[jl].offer_id) ;
							 	hiddenField.setAttribute('value', jsonData.Legend[jl].presentation_format) ;															 	
							 	myForm.appendChild(hiddenField) ;
							 	
						 		
								//if it's Dynamic IFrame
				 				if ( jsonData.Legend[jl].presentation_format == 'Dynamic Iframe' )	
				 				
				 					{
				 			
						 				//present an IFrame
						 				myIframe = document.createElement('iframe') ;
						 				myIframe.id = 'this_iframe__' + jsonData.Legend[jl].offer_id ;	
						 				myIframe.setAttribute('src', jsonData.Legend[jl].dynamic_iframe_url) ;
						 				myIframe.setAttribute('width', '860') ;
						 				myIframe.setAttribute('height', '700') ;
						 				myIframe.setAttribute('scrolling', ' no') ;
						 				
						 				offerDiv.appendChild(myIframe) ;
						 				myForm.appendChild(offerDiv) ;			
						 			
						 			}	
						 			
						 		//else it's an HTML Form
				 				else if ( jsonData.Legend[jl].presentation_format == 'HTML Form' )	
				 				
				 					{
				 														 				 							 					 						 								 									 						
				 						//now you need to loop over your sub node which is the field set array!!!
				 						for ( var f=0; f<jsonData.Legend[jl].FieldSets.length; f++ )
				 						
				 							{
				 							
					 							var list_of_ids_for_this_field_set = '' ;	
					 																		
												if ( jsonData.Legend[jl].FieldSets[f].f_t != 'hidden' )
			 							
					 								{
					 								
					 									//create div row
														rowDiv = document.createElement('div') ;
														rowDiv.className = 'div_row' ;
														
														//add a label
														thisLabel = document.createElement('label') ;
														thisLabel.className = 'label_design' ;
														rowDiv.appendChild(thisLabel) ;	
																	
														//create the text for the label
														var this_field_label = jsonData.Legend[jl].FieldSets[f].f_l ;
														
														if ( jsonData.Legend[jl].FieldSets[f].f_r == 1 )
														
															{
																this_field_label = this_field_label + ' *' ;
															}
														
														thisText = document.createTextNode(this_field_label) ;
														thisLabel.appendChild(thisText) ;
					 									 								
					 								}										
					 										 								 							
					 							//Now present your form field			 							
					 							if ( jsonData.Legend[jl].FieldSets[f].f_t == 'text_field' )
					 							
					 								{					 									
					 								
														var list__text_fields = jsonData.Legend[jl].FieldSets[f].f_n.split("|");
														var list__prepopulated_values = jsonData.Legend[jl].FieldSets[f].f_v.split("|");
														var list__text_field_length = jsonData.Legend[jl].FieldSets[f].f_s.split("|");
														var list__max_lengths = jsonData.Legend[jl].FieldSets[f].m_lens.split("|");
																														
														for ( var tt=0; tt<list__text_fields.length; tt++ )
														
															{
																
																//size
																var the_size = list__text_field_length[i] ;
																
																if ( the_size == '' || the_size == undefined )
																
																	{
																		the_size = '17' ;
																	}
																	
																//prepop value
																var the_prepop_value = list__prepopulated_values[tt] ;
																
																if ( the_prepop_value == '' || the_prepop_value == undefined )
																
																	{
																		the_prepop_value = '' ;
																	}
																	
																var the_max_length = list__max_lengths[tt] ;
																
																if ( the_max_length == undefined )
																
																	{
																		the_max_length = '' ;
																	}
															
																textField = document.createElement('INPUT') ;
															 	textField.type = 'text' ;
															 	textField.id = list__text_fields[tt] ;
															 	textField.setAttribute('name', list__text_fields[tt]) ;
															 	textField.setAttribute('value', the_prepop_value) ;											 	
															 	textField.setAttribute('size', the_size) ;
															 	textField.setAttribute('maxlength', the_max_length) ;
															 	textField.className = 'form_field_design' ;
																												
																//if there is E-Mail validation against this field, then append it
																if ( jsonData.Legend[jl].FieldSets[f].f_val == 'E-Mail' )
																
																	{
																																
																		textField.setAttribute('temp_holder', jsonData.Legend[jl].offer_id) ;
																		textField.onblur = function() { checkIfIsDuplicateLead(this.value, this.temp_holder); };
																		
																	}												
																
															 	rowDiv.appendChild(textField) ;
															 	
															 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__text_fields[tt] + '|' ;											 	
															 												
															}
					 								
					 								}
					 								
					 							else if ( jsonData.Legend[jl].FieldSets[f].f_t == 'select_menu' )
					 							
					 								{
					 																					 	
													 	var list__select_field_name = jsonData.Legend[jl].FieldSets[f].f_n.split("|") ;
				
														//split this guy up at the ^ level, remember the inners are |, but don't be misguided!!!
														var list__arrays_or_arrays__split_value_pairs = jsonData.Legend[jl].FieldSets[f].f_d_v.split("^") ;
																												
														//loop over select field names as highest!
														for ( var sm=0; sm<list__select_field_name.length; sm++  )
														
															{
																																	
																// Create a drop-down list
															 	dropDown = document.createElement('SELECT') ;
															 	dropDown.id = list__select_field_name[sm] ;
															 	dropDown.setAttribute('name', list__select_field_name[sm]) ;
															 	dropDown.className = 'form_field_design' ;															 	
															 	
															 	//now grab the row out of the ^ delimited list which are the name|value pairs
																var this_list = list__arrays_or_arrays__split_value_pairs[sm] ;
																
																//now create new list declaration
																var new_list = this_list.split("|") ;
																
																//does this list contain at least 1 that's going to make the page bleed or the form push everything around???
																var contains_at_least_one_bleeder = false ;
																
																//start with SELECT value=""
																option = document.createElement('option') ;
														  		option.value = '' ;	
														  		option.appendChild(document.createTextNode('Select')) ;
														  		dropDown.appendChild(option) ;
																
																//loop over THIS_LIST which is | in of itself
																for ( var mo=0; mo<new_list.length; mo++ )
																
																	{
																																																					
																		//ok, now you have something that looks like this MI=Michigan so split that up based on the equals sign as a delimiter = 
																		var this_new_split = new_list[mo].split("=") ;
																		
																		var the_row_value = this_new_split[0] ;
																		var the_row_display = this_new_split[1] ;																	
																		
																		option = document.createElement('option') ;
																  		option.value = the_row_value ;																		  		
																  			
																		if ( jsonData.Legend[jl].FieldSets[f].f_v == the_row_value )
																		
																			{
																				option.setAttribute('selected', 'true')
																			}																			 																				  	
																		  		
																  		option.appendChild(document.createTextNode(the_row_display)) ;
																  		dropDown.appendChild(option) ;																											
																		
																	}															 	
															 	
															 	rowDiv.appendChild(dropDown) ;	
															 	
															 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__select_field_name[sm] + '|' ;											 														
																
															}													 	
					 								
					 								}
					 								
					 							else if ( jsonData.Legend[jl].FieldSets[f].f_t == 'radio_buttons' )
					 							
					 								{
					 										 			 								
					 									var array_values_and_displays = jsonData.Legend[jl].FieldSets[f].f_d_v.split("|");
														
														for( var rb=0; rb<array_values_and_displays.length; rb++)
														
															{
																//split up that row now!!!
																var valueArrayRowSplit = array_values_and_displays[rb].split("=");
																
																var the_row_value = valueArrayRowSplit[0] ;	
																var the_row_display = valueArrayRowSplit[1] ;
																
																// Create a radio selection												
																if(!document.addEventListener) 
																
																	{
																	 	// IE hack
																		radioField= document.createElement("<input name=\"" + jsonData.Legend[jl].FieldSets[f].f_n + "\"/>");
																	} 
																
																else 
																
																	{
																		radioField= document.createElement("input");
																	}																	
																											
																// Create a radio selection
															 	radioField.type = 'radio' ;
															 	radioField.id = jsonData.Legend[jl].FieldSets[f].f_n + '__' + rb ;
															 	radioField.setAttribute('name', jsonData.Legend[jl].FieldSets[f].f_n) ;
															 	radioField.className = 'form_field_design' ;
															 	radioField.value = the_row_value ; 	
															 	
															 	if ( jsonData.Legend[jl].FieldSets[f].f_v == the_row_value )
																
																	{
																		//radioField.setAttribute('checked', 'checked') ;
																	}
															 	
															 	rowDiv.appendChild(radioField) ;
															 	rowDiv.appendChild(document.createTextNode(the_row_display)) ;	
															 	
															 	rowDiv.appendChild(document.createElement('BR')) ;	
															 	
															 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[f].f_n + '__' + rb + '|' ;										 		
																
															}																	 			 	
													 														 					 								
					 								}
					 								
					 							else if ( jsonData.Legend[jl].FieldSets[f].f_t == 'check_boxes' )
					 							
					 								{
					 									 	
													 	//split this list up just once please
														var array_split_of_value_pairs = jsonData.Legend[jl].FieldSets[f].f_d_v.split("|");
														
														var array_prechecked_values = jsonData.Legend[jl].FieldSets[f].f_v.split("|") ;
														
														for( var cb=0; cb<array_split_of_value_pairs.length; cb++)
														
															{
																//split up that row now!!!
																var valueArrayRowSplit = array_split_of_value_pairs[cb].split("=");
																
																var the_row_value = valueArrayRowSplit[0] ;	
																var the_row_display = valueArrayRowSplit[1] ;
																
																//ok, now check against your list of pre-populated values to see if this value is in the list!!!
																var current_checkbox_value_is_in_prechecked_list = false ;
																
																for ( var list_element_i=0; list_element_i<array_prechecked_values.length; list_element_i++ )
																
																	{
																		//if the current i value MATCHES the same value as that which is about to be presented as the checkbox value, then You're On!!!!
																		if ( array_prechecked_values[list_element_i] == the_row_value )
																		
																			{
																				current_checkbox_value_is_in_prechecked_list = true ;
																				break ;
																			}
																	}	
																	
																// Create a checkbox
															 	checkbox = document.createElement('INPUT') ;
															 	checkbox.type = 'checkbox' ;
															 	checkbox.id = jsonData.Legend[jl].FieldSets[f].f_n + '__' + cb ;
															 	checkbox.setAttribute('name', jsonData.Legend[jl].FieldSets[f].f_n) ;
															 	checkbox.className = 'form_field_design' ;
															 	checkbox.setAttribute('value', the_row_value) ;
															 	
															 	if ( current_checkbox_value_is_in_prechecked_list == true )
																
																	{
																		checkbox.setAttribute('checked', 'checked') ;
																	}
															 	
															 	rowDiv.appendChild(checkbox) ;
															 	rowDiv.appendChild(document.createTextNode(the_row_display)) ;	
															 	
															 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[f].f_n + '__' + cb + '|' ;	
																
															}											
					 								
					 								}
					 								
					 							else if ( jsonData.Legend[jl].FieldSets[f].f_t == 'comment_box' )
					 							
					 								{
					 									//z = z + generateCommentBox(, , jsonData.Offers[i].FieldSets[f].the_cols, jsonData.Legend[jl].FieldSets[f].the_rows, false) ;						 								
					 									// Create a textarea
													 	textArea = document.createElement('TEXTAREA') ;
													 	textArea.id = jsonData.Offers[i].FieldSets[f].f_n ;
													 	textArea.setAttribute('name', jsonData.Legend[jl].FieldSets[f].f_n) ;
													 	textArea.setAttribute('value', jsonData.Legend[jl].FieldSets[f].f_v) ;
													 	textArea.className = 'form_field_design' ;
													 	rowDiv.appendChild(textArea) ;
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[f].f_n + '|' ;
					 								
					 								}	
					 								
					 							else if ( jsonData.Legend[jl].FieldSets[f].f_t == 'hidden' )
					 							
					 								{
					 									
					 									var array__field_names = jsonData.Legend[jl].FieldSets[f].f_n.split("|");
														var array__prepopulated_values = jsonData.Legend[jl].FieldSets[f].f_v.split("|");
																														
														for ( var hf=0; hf<array__field_names.length; hf++ )
														
															{
																																	
																//prepop value
																var the_prepop_value = array__prepopulated_values[hf] ;
																
																if ( the_prepop_value == '' || the_prepop_value == undefined )
																
																	{
																		the_prepop_value = '' ;
																	}
															
																hiddenField = document.createElement('INPUT') ;
															 	hiddenField.type = 'hidden' ;
															 	hiddenField.id = array__field_names[hf] ;
															 	hiddenField.setAttribute('name', array__field_names[hf]) ;
															 	hiddenField.setAttribute('value', the_prepop_value) ;
															 	offerDiv.appendChild(hiddenField) ;
															 	
															 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + array__field_names[hf] + '|' ;
															 												
															}
					 								
					 								}
					 								
					 							//only append the row div to the Offer IF it's not hidden, bcuz otherwise we never initialized it in the first place
					 							if ( jsonData.Legend[jl].FieldSets[f].f_t != 'hidden' )
					 							
					 								{
					 									offerDiv.appendChild(rowDiv) ;
					 								}					 							
					 							
					 							myForm.appendChild(offerDiv) ;
					 									 								
					 							//append to list so we know ur there please	 							
					 							list_of_fields = list_of_fields + jsonData.Legend[jl].FieldSets[f].f_t + '=' + list_of_ids_for_this_field_set + '=' + jsonData.Legend[jl].FieldSets[f].f_l + '=' + jsonData.Legend[jl].FieldSets[f].f_r + '=' + jsonData.Legend[jl].FieldSets[f].f_val + '^' ;					 								
																													
											}	
								
									}
									
								//list of all fields			
								hiddenField = document.createElement('INPUT') ;
								hiddenField.type = 'hidden' ;
								hiddenField.id = 'field__offer_id__' + jsonData.Legend[jl].offer_id ;
								hiddenField.setAttribute('name', 'field__offer_id__' + jsonData.Legend[jl].offer_id) ;
								hiddenField.setAttribute('value', list_of_fields) ;															 	
								myForm.appendChild(hiddenField) ;
																
								myForm.appendChild(document.createElement('BR')) ;
								
							}
					
					}							
					
				myForm.appendChild(document.createElement('BR')) ;
				myForm.appendChild(document.createElement('BR')) ;	
					
		 		myForm.appendChild(document.createElement('BR')) ;
		 		myForm.appendChild(document.createElement('BR')) ;		
				 					 				 
				// Create a submit button
				newButton = document.createElement('INPUT') ;
				newButton.id = 'the_submit_button' ;
				newButton.type = 'button' ;
				newButton.setAttribute('name', 'submit_button') ;
				newButton.value = c__submit_button_text ;
				newButton.onclick = sendDataToServer ;
				myForm.appendChild(newButton) ;	
				
				//You're going to build a list of all the survey questions so u can deal with it
				hiddenField = document.createElement('input') ;
				hiddenField.type = 'hidden' ;
				hiddenField.id = 'survey_fields_to_deal_with_first' ;
				hiddenField.setAttribute('name', 'survey_fields_to_deal_with_first') ;
				hiddenField.setAttribute('value', value__survey_fields_to_deal_with_first) ;															 	
				myForm.appendChild(hiddenField) ;
								
				//You're going to build a list of all the offers that were presented and pass this as 1 single variable
				hiddenField = document.createElement('INPUT') ;
				hiddenField.type = 'hidden' ;
				hiddenField.id = 'all_offers_presented' ;
				hiddenField.setAttribute('name', 'all_offers_presented') ;
				hiddenField.setAttribute('value', value__all_offers_presented) ;															 	
				myForm.appendChild(hiddenField) ;
											
			}		 		
		 		 
		 else if ( c__page_display_type == 'Featured Offers Presented In Survey Style'  )
		 
		 	{
		 					 			
				//remember *all* offers presented!!!
				var value__all_offers_presented = '' ;		
				
				// Where the form will be placed into the page
				parentElement = document.getElementById('paste_this_where_you_want_your_offers_to_display') ;
				parentElement.innerHTML = "" ;
								
				// Create a form
				myForm = document.createElement('FORM') ;
				myForm.method = 'post' ;
				myForm.action = '#' ;
				myForm.setAttribute('name', 'wmi_form') ;
				myForm.id = 'wmi_form' ;		 		 		 		 		 		 
				
				//for as many offers as returned
				for ( var i=0; i<jsonData.Offers.length; i++ )
				
					{											
				
						value__all_offers_presented = value__all_offers_presented + jsonData.Offers[i].offer_id + '|' ;	
						
						//crank out your div id now and hold it
						var this_main_container_div_id = 'div_container__' + jsonData.Offers[i].offer_id ;
																		
						
						//HTML not Text for your Survey
						IntroQuestionDiv = document.createElement('div') ;
						IntroQuestionDiv.id = 'intro_line_div__' + jsonData.Offers[i].offer_id ;
						IntroQuestionDiv.innerHTML = jsonData.Offers[i].offer_question ;
						IntroQuestionDiv.className = 'intro_line_div' ;								
						myForm.appendChild(IntroQuestionDiv) ;						
						
						//then append them to the rowDiv
						myForm.appendChild(document.createElement('BR')) ;

						//yes radio button here
						var the_share_radio_button_name = 'registration_offer__' + jsonData.Offers[i].offer_id ;
						
						// Create a radio selection												
						if(!document.addEventListener) 
						
							{
							 	// IE hack
								radioField= document.createElement("<input name=\"" + the_share_radio_button_name + "\"/>");
							} 
						
						else 
						
							{
								radioField= document.createElement("input");
							}
						
					 	radioField.type = 'radio' ;
					 	radioField.id = 'registration_offer__yes__' + jsonData.Offers[i].offer_id ;
					 	radioField.setAttribute('name', the_share_radio_button_name) ;
					 	radioField.className = 'form_field_design' ;
					 	radioField.value = jsonData.Offers[i].offer_id ; 
					 	radioField.onclick = function() { doRadioButtonOpenAndClose('div_container__' + this.value, 'Yes'); };								 	
					 	myForm.appendChild(radioField) ;
					 	myForm.appendChild(document.createTextNode('Yes')) ;					 	
					 	
					 	//line break between radio button selections
					 	myForm.appendChild(document.createElement('BR')) ;					 	
					 	
					 	//no radio button here
					 	// Create a radio selection												
						if(!document.addEventListener) 
						
							{
							 	// IE hack
								radioField= document.createElement("<input name=\"" + the_share_radio_button_name + "\"/>");
							} 
						
						else 
						
							{
								radioField= document.createElement("input");
							}
							
					 	radioField.type = 'radio' ;
					 	radioField.id = 'registration_offer__no__' + jsonData.Offers[i].offer_id ;
					 	radioField.setAttribute('name', the_share_radio_button_name) ;
					 	radioField.className = 'form_field_design' ;
					 	radioField.value = jsonData.Offers[i].offer_id ; 
					 	radioField.onclick = function() { doRadioButtonOpenAndClose('div_container__' + this.value, 'No'); };									 	
					 	myForm.appendChild(radioField) ;
					 	myForm.appendChild(document.createTextNode('No')) ;								 			 	
						
						myForm.appendChild(document.createElement('BR')) ;
						myForm.appendChild(document.createElement('BR')) ;	
						
						//OfferDiv container that you can collapse, etc
						offerDiv = document.createElement('div') ;
						offerDiv.id = this_main_container_div_id ;						
						offerDiv.style.display = 'none' ;
						
						IntroQuestionDiv.appendChild(offerDiv) ;
						
						//HTML not Text for your Survey
						TopHTML = document.createElement('div') ;
						TopHTML.id = 'top_html_div__' + jsonData.Offers[i].offer_id ;
						TopHTML.style.width = '375px' ;
						TopHTML.style.margin = '0px 100px 0px' ;
						TopHTML.innerHTML = jsonData.Offers[i].offer_layout ;
						offerDiv.appendChild(TopHTML) ;					
						
						//set list of fields to validate for this offer
				 		var list_of_fields = '' ; 	
				 		
				 		//specify what presentation_format this guy is
				 		hiddenField = document.createElement('input') ;
					 	hiddenField.type = 'hidden' ;
					 	hiddenField.id = 'presentation_format__offer__' + jsonData.Offers[i].offer_id ;
					 	hiddenField.setAttribute('name', 'presentation_type__offer__' + jsonData.Offers[i].offer_id) ;
					 	hiddenField.setAttribute('value', jsonData.Offers[i].presentation_format) ;															 	
					 	myForm.appendChild(hiddenField) ;			 		
				 		
				 		//if it's Dynamic IFrame
				 		if ( jsonData.Offers[i].presentation_format == 'Dynamic Iframe' )				 		
				 		
				 			{
				 			
				 				//present an IFrame
				 				myIframe = document.createElement('iframe') ;
				 				myIframe.id = 'this_iframe__' + jsonData.Offers[i].offer_id ;	
				 				myIframe.setAttribute('src', jsonData.Offers[i].dynamic_iframe_url) ;
				 				myIframe.setAttribute('width', '860') ;
				 				myIframe.setAttribute('height', '700') ;
				 				myIframe.setAttribute('scrolling', ' no') ;
				 				
				 				offerDiv.appendChild(myIframe) ;
				 				myForm.appendChild(offerDiv) ;			
				 			
				 			}	
				 			
				 		else if ( jsonData.Offers[i].presentation_format == 'Dynamic Linkout' )
				 		
				 			{
				 			}			 			
				 			
				 		//else it's an HTML Form
				 		else if ( jsonData.Offers[i].presentation_format == 'HTML Form' )
				 		
				 			{						 																										
						 				 							 					 						 								 									 						
		 						//now you need to loop over your sub node which is the field set array!!!
		 						for ( var f=0; f<jsonData.Offers[i].FieldSets.length; f++ )
		 						
		 							{
		 							
			 							var list_of_ids_for_this_field_set = '' ;
			 							
			 							if ( jsonData.Offers[i].FieldSets[f].f_t != 'hidden' )
			 							
			 								{
			 								
			 									//create div row
												rowDiv = document.createElement('div') ;
												rowDiv.className = 'div_row' ;
												
												//add a label
												thisLabel = document.createElement('label') ;
												thisLabel.className = 'label_design' ;
												rowDiv.appendChild(thisLabel) ;	
															
												//create the text for the label
												var this_field_label = jsonData.Offers[i].FieldSets[f].f_l ; 
												
												if ( jsonData.Offers[i].FieldSets[f].f_r == 1 )
												
													{
														this_field_label = this_field_label + ' *' ;
													}
												
												thisText = document.createTextNode(this_field_label) ;
												thisLabel.appendChild(thisText) ;
			 									 								
			 								}	 							
			 										 								 							
			 							//Now present your form field			 							
			 							if ( jsonData.Offers[i].FieldSets[f].f_t == 'text_field' )
			 							
			 								{					 									
			 								
												var list__text_fields = jsonData.Offers[i].FieldSets[f].f_n.split("|");
												var list__prepopulated_values = jsonData.Offers[i].FieldSets[f].f_v.split("|");
												var list__text_field_length = jsonData.Offers[i].FieldSets[f].f_s.split("|");
												var list__max_lengths = jsonData.Offers[i].FieldSets[f].m_lens.split("|");
																												
												for ( var tt=0; tt<list__text_fields.length; tt++ )
												
													{
														
														//size
														var the_size = list__text_field_length[i] ;
														
														if ( the_size == '' || the_size == undefined )
														
															{
																the_size = '17' ;
															}
															
														//prepop value
														var the_prepop_value = list__prepopulated_values[tt] ;
														
														if ( the_prepop_value == '' || the_prepop_value == undefined )
														
															{
																the_prepop_value = '' ;
															}
															
														var the_max_length = list__max_lengths[tt] ;
														
														if ( the_max_length == undefined )
														
															{
																the_max_length = '' ;
															}
													
														textField = document.createElement('INPUT') ;
													 	textField.type = 'text' ;
													 	textField.id = list__text_fields[tt] ;
													 	textField.setAttribute('name', list__text_fields[tt]) ;
													 	textField.setAttribute('value', the_prepop_value) ;											 	
													 	textField.setAttribute('size', the_size) ;
													 	textField.setAttribute('maxlength', the_max_length) ;
													 	textField.className = 'form_field_design' ;
																										
														//if there is E-Mail validation against this field, then append it
														if ( jsonData.Offers[i].FieldSets[f].f_val == 'E-Mail' )
														
															{
																														
																textField.setAttribute('temp_holder', jsonData.Offers[i].offer_id) ;
																textField.onblur = function() { checkIfIsDuplicateLead(this.value, this.temp_holder); };
																
															}												
														
													 	rowDiv.appendChild(textField) ;
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__text_fields[tt] + '|' ;											 	
													 												
													}
			 								
			 								}
			 								
			 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'select_menu' )
			 							
			 								{
			 																					 	
											 	var list__select_field_name = jsonData.Offers[i].FieldSets[f].f_n.split("|") ;
		
												//split this guy up at the ^ level, remember the inners are |, but don't be misguided!!!
												var list__arrays_or_arrays__split_value_pairs = jsonData.Offers[i].FieldSets[f].f_d_v.split("^") ;
																										
												//loop over select field names as highest!
												for ( var sm=0; sm<list__select_field_name.length; sm++  )
												
													{
																															
														// Create a drop-down list
													 	dropDown = document.createElement('SELECT') ;
													 	dropDown.id = list__select_field_name[sm] ;
													 	dropDown.setAttribute('name', list__select_field_name[sm]) ;
													 	dropDown.className = 'form_field_design' ;															 	
													 	
													 	//now grab the row out of the ^ delimited list which are the name|value pairs
														var this_list = list__arrays_or_arrays__split_value_pairs[sm] ;
														
														//now create new list declaration
														var new_list = this_list.split("|") ;
														
														//does this list contain at least 1 that's going to make the page bleed or the form push everything around???
														var contains_at_least_one_bleeder = false ;
														
														//start with SELECT value=""
														option = document.createElement('option') ;
												  		option.value = '' ;	
												  		option.appendChild(document.createTextNode('Select')) ;
												  		dropDown.appendChild(option) ;
														
														//loop over THIS_LIST which is | in of itself
														for ( var mo=0; mo<new_list.length; mo++ )
														
															{
																																																			
																//ok, now you have something that looks like this MI=Michigan so split that up based on the equals sign as a delimiter = 
																var this_new_split = new_list[mo].split("=") ;
																
																var the_row_value = this_new_split[0] ;
																var the_row_display = this_new_split[1] ;
																
																option = document.createElement('option') ;
														  		option.value = the_row_value ;																		  		
														  														  		
																if ( jsonData.Offers[i].FieldSets[f].f_v == the_row_value )
																
																	{
																		option.setAttribute('selected', 'true')
																	}																				 																				  	
																  		
														  		option.appendChild(document.createTextNode(the_row_display)) ;
														  		dropDown.appendChild(option) ;																											
																
															}															 	
													 	
													 	rowDiv.appendChild(dropDown) ;	
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__select_field_name[sm] + '|' ;											 														
														
													}													 	
			 								
			 								}
			 								
			 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'radio_buttons' )
			 							
			 								{
			 										 			 								
			 									var array_values_and_displays = jsonData.Offers[i].FieldSets[f].f_d_v.split("|");
												
												for( var rb=0; rb<array_values_and_displays.length; rb++)
												
													{
														//split up that row now!!!
														var valueArrayRowSplit = array_values_and_displays[rb].split("=");
														
														var the_row_value = valueArrayRowSplit[0] ;	
														var the_row_display = valueArrayRowSplit[1] ;	
																									
														// Create a radio selection
													 	
														// Create a radio selection												
															if(!document.addEventListener) 
															
																{
																 	// IE hack
																	radioField= document.createElement("<input name=\"" + jsonData.Offers[i].FieldSets[f].f_n + "\"/>");
																} 
															
															else 
															
																{
																	radioField= document.createElement("input");
																}

													 	radioField.type = 'radio' ;
													 	radioField.id = jsonData.Offers[i].FieldSets[f].f_n + '__' + rb ;
													 	radioField.setAttribute('name', jsonData.Offers[i].FieldSets[f].f_n) ;
													 	radioField.className = 'form_field_design' ;
													 	radioField.value = the_row_value ; 	
													 	
													 	if ( jsonData.Offers[i].FieldSets[f].f_v == the_row_value )
														
															{																
																radioField.defaultChecked = true ;
																radioField.checked = true  ;
															}
													 	
													 	rowDiv.appendChild(radioField) ;
													 	rowDiv.appendChild(document.createTextNode(the_row_display)) ;	
													 	
													 	rowDiv.appendChild(document.createElement('BR')) ;	
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Offers[i].FieldSets[f].f_n + '__' + rb + '|' ;										 		
														
													}																	 			 	
											 														 					 								
			 								}
			 								
			 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'check_boxes' )
			 							
			 								{
			 									 	
											 	//split this list up just once please
												var array_split_of_value_pairs = jsonData.Offers[i].FieldSets[f].f_d_v.split("|");
												
												var array_prechecked_values = jsonData.Offers[i].FieldSets[f].f_v.split("|") ;
												
												for( var cb=0; cb<array_split_of_value_pairs.length; cb++)
												
													{
														//split up that row now!!!
														var valueArrayRowSplit = array_split_of_value_pairs[cb].split("=");
														
														var the_row_value = valueArrayRowSplit[0] ;	
														var the_row_display = valueArrayRowSplit[1] ;
														
														//ok, now check against your list of pre-populated values to see if this value is in the list!!!
														var current_checkbox_value_is_in_prechecked_list = false ;
														
														for ( var list_element_i=0; list_element_i<array_prechecked_values.length; list_element_i++ )
														
															{
																//if the current i value MATCHES the same value as that which is about to be presented as the checkbox value, then You're On!!!!
																if ( array_prechecked_values[list_element_i] == the_row_value )
																
																	{
																		current_checkbox_value_is_in_prechecked_list = true ;
																		break ;
																	}
															}	
															
														// Create a checkbox
													 	checkbox = document.createElement('INPUT') ;
													 	checkbox.type = 'checkbox' ;
													 	checkbox.id = jsonData.Offers[i].FieldSets[f].f_n + '__' + cb ;
													 	checkbox.setAttribute('name', jsonData.Offers[i].FieldSets[f].f_n) ;
													 	checkbox.className = 'form_field_design' ;
													 	checkbox.setAttribute('value', the_row_value) ;
													 	
													 	if ( current_checkbox_value_is_in_prechecked_list == true )
														
															{
																checkbox.setAttribute('checked', 'checked') ;
															}
													 	
													 	rowDiv.appendChild(checkbox) ;
													 	rowDiv.appendChild(document.createTextNode(the_row_display)) ;	
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Offers[i].FieldSets[f].f_n + '__' + cb + '|' ;	
														
													}											
			 								
			 								}
			 								
			 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'comment_box' )
			 							
			 								{
			 									//z = z + generateCommentBox(, , jsonData.Offers[i].FieldSets[f].the_cols, jsonData.Offers[i].FieldSets[f].the_rows, false) ;						 								
			 									// Create a textarea
											 	textArea = document.createElement('TEXTAREA') ;
											 	textArea.id = jsonData.Offers[i].FieldSets[f].f_n ;
											 	textArea.setAttribute('name', jsonData.Offers[i].FieldSets[f].f_n) ;
											 	textArea.setAttribute('value', jsonData.Offers[i].FieldSets[f].f_v) ;
											 	textArea.className = 'form_field_design' ;
											 	rowDiv.appendChild(textArea) ;
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Offers[i].FieldSets[f].f_n + '|' ;
			 								
			 								}	
			 								
			 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'hidden' )
			 							
			 								{
			 									
			 									var array__field_names = jsonData.Offers[i].FieldSets[f].f_n.split("|");
												var array__prepopulated_values = jsonData.Offers[i].FieldSets[f].f_v.split("|");
																												
												for ( var hf=0; hf<array__field_names.length; hf++ )
												
													{
																															
														//prepop value
														var the_prepop_value = array__prepopulated_values[hf] ;
														
														if ( the_prepop_value == '' || the_prepop_value == undefined )
														
															{
																the_prepop_value = '' ;
															}
													
														hiddenField = document.createElement('INPUT') ;
													 	hiddenField.type = 'hidden' ;
													 	hiddenField.id = array__field_names[hf] ;
													 	hiddenField.setAttribute('name', array__field_names[hf]) ;
													 	hiddenField.setAttribute('value', the_prepop_value) ;															 	
													 	offerDiv.appendChild(hiddenField) ;
													 	
													 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + array__field_names[hf] + '|' ;
													 												
													}
			 								
			 								}
			 								
			 							//only append the row div to the Offer IF it's not hidden, bcuz otherwise we never initialized it in the first place
			 							if ( jsonData.Offers[i].FieldSets[f].f_t != 'hidden' )
			 							
			 								{
			 									offerDiv.appendChild(rowDiv) ;
			 								}
			 							
			 							myForm.appendChild(offerDiv) ;
			 									 								
			 							//append to list so we know ur there please	 							
			 							list_of_fields = list_of_fields + jsonData.Offers[i].FieldSets[f].f_t + '=' + list_of_ids_for_this_field_set + '=' + jsonData.Offers[i].FieldSets[f].f_l + '=' + jsonData.Offers[i].FieldSets[f].f_r + '=' + jsonData.Offers[i].FieldSets[f].f_val + '^' ;					 								
								
									}
 							
								
							}	
						
						//list of all fields			
						hiddenField = document.createElement('INPUT') ;
						hiddenField.type = 'hidden' ;
						hiddenField.id = 'field__offer_id__' + jsonData.Offers[i].offer_id ;
						hiddenField.setAttribute('name', 'field__offer_id__' + jsonData.Offers[i].offer_id) ;
						hiddenField.setAttribute('value', list_of_fields) ;															 	
						myForm.appendChild(hiddenField) ;
						
						//myForm.appendChild(document.createElement('BR')) ;	 				
						
					}
															
				myForm.appendChild(document.createElement('BR')) ;			
				
				// Create a submit button
				newButton = document.createElement('INPUT') ;
				newButton.id = 'the_submit_button' ;
				newButton.type = 'button' ;
				newButton.setAttribute('name', 'submit_button') ;
				newButton.value = c__submit_button_text ;
				newButton.onclick = sendDataToServer ;
				myForm.appendChild(newButton) ;	
				
				//You're going to build a list of all the offers that were presented and pass this as 1 single variable
				hiddenField = document.createElement('INPUT') ;
				hiddenField.type = 'hidden' ;
				hiddenField.id = 'all_offers_presented' ;
				hiddenField.setAttribute('name', 'all_offers_presented') ;
				hiddenField.setAttribute('value', value__all_offers_presented) ;															 	
				myForm.appendChild(hiddenField) ;
		 							 			 	
		 	}
		 	
		 else if ( c__page_display_type == 'Reg Path View'  )
		 
		 	{
		 					 		
		 		//set this
		 		pagination__uuid = jsonData.pagination__uuid ; 
		 		this_is_the_last_page = jsonData.this_is_the_last_page ;
		 				 		
		 		//remember *all* offers presented!!!
				var value__all_offers_presented = '' ;
				
				// Where the form will be placed into the page
				parentElement = document.getElementById('paste_this_where_you_want_your_offers_to_display') ;
				parentElement.innerHTML = "" ;
				
				// Create a form
				myForm = document.createElement('FORM') ;
				myForm.method = 'post' ;
				myForm.action = '#' ;
				myForm.setAttribute('name', 'wmi_form') ;
				myForm.id = 'wmi_form' ;		 		 		 		 		 		 
				 
				 //for as many offers as returned
				 for ( var i=0; i<jsonData.Offers.length; i++ )
				 
				 	{
				 		
				 		value__all_offers_presented = value__all_offers_presented + jsonData.Offers[i].offer_id + '|' ;	
				 		
				 		//crank out your div id now and hold it
				 		var this_main_container_div_id = 'div_container__' + jsonData.Offers[i].offer_id ;
				 						 						 	
					 	//present the image
				 		myImage = document.createElement('IMG') ;
				 		myImage.setAttribute('src', 'http://www.leadstrike.com/template_files/offer_images/' + jsonData.Offers[i].offer_thumbnail) ;
				 		myImage.className = 'logo' ;	
				 		myForm.appendChild(myImage) ;	
				 		
				 		//present the I am Interested Checkbox
				 		// Create a checkbox
					 	checkbox = document.createElement('INPUT') ;
					 	checkbox.type = 'checkbox' ;
					 	checkbox.id = 'include_offer_id__' + jsonData.Offers[i].offer_id ;
					 	checkbox.setAttribute('name', 'include_offer_id') ;
					 	checkbox.setAttribute('value', jsonData.Offers[i].offer_id) ;
					 	//default for this view is OPEN
					 	checkbox.setAttribute('checked', 'checked') ;
					 	//hide it bcuz it's just an open form
					 	checkbox.style.display = 'none' ;
					 	//checkbox.onclick = function() { displayHTMLQuestionsCheckboxes('div_container__' + this.value, this.checked); };
					 	myForm.appendChild(checkbox) ;	
					 						 	
					 	thisQuestion = document.createElement('label') ;	
						thisText = document.createTextNode(' ' + jsonData.Offers[i].offer_question) ;
						thisQuestion.appendChild(thisText) ;
						myForm.appendChild(thisQuestion) ;					 	
					 	
					 	myForm.appendChild(document.createElement('BR')) ;
					 	myForm.appendChild(document.createElement('BR')) ;
					 	myForm.appendChild(document.createElement('BR')) ;					 	
					 	
					 	//OfferDiv container that you can collapse, etc
					 	thisDiv = document.createElement('div') ;
					 	thisDiv.id = this_main_container_div_id ;
						thisDiv.style.display = 'block' ;
						//myForm.appendChild(thisDiv) ;
				 		 						 									 		
				 		
				 		//set list of fields to validate for this offer
				 		var list_of_fields = '' ; 
				 		
				 		//specify what presentation_format this guy is
				 		hiddenField = document.createElement('input') ;
					 	hiddenField.type = 'hidden' ;
					 	hiddenField.id = 'presentation_format__offer__' + jsonData.Offers[i].offer_id ;
					 	hiddenField.setAttribute('name', 'presentation_type__offer__' + jsonData.Offers[i].offer_id) ;
					 	hiddenField.setAttribute('value', 'HTML Form') ;															 	
					 	myForm.appendChild(hiddenField) ;
				 				 							 					 						 								 									 						
 						//now you need to loop over your sub node which is the field set array!!!
 						for ( var f=0; f<jsonData.Offers[i].FieldSets.length; f++ )
 						
 							{
 							
	 							//only show a divider line break if it's NOT a hidden field
	 							if ( jsonData.Offers[i].FieldSets[f].f_t != 'hidden' )
	 							
	 								{
	 									
	 									//create div row
										rowDiv = document.createElement('div') ;
										rowDiv.className = 'div_row' ;
										
	 								}
	 								
	 							else
	 							
	 								{
	 									rowDiv = document.createElement('div') ;
	 									rowDiv.style.display = 'none' ;
	 								}
	 							
	 							
	 							var list_of_ids_for_this_field_set = '' ;	 							
																
								//add a label
								thisLabel = document.createElement('label') ;
								thisLabel.className = 'label_design' ;
								rowDiv.appendChild(thisLabel) ;				
								//create the text for the label
								thisText = document.createTextNode(jsonData.Offers[i].FieldSets[f].f_l) ;
								thisLabel.appendChild(thisText) ;
	 										 								 							
	 							//Now present your form field			 							
	 							if ( jsonData.Offers[i].FieldSets[f].f_t == 'text_field' )
	 							
	 								{					 									
	 								
										var list__text_fields = jsonData.Offers[i].FieldSets[f].f_n.split("|");
										var list__prepopulated_values = jsonData.Offers[i].FieldSets[f].f_v.split("|");
										var list__text_field_length = jsonData.Offers[i].FieldSets[f].f_s.split("|");
										var list__max_lengths = jsonData.Offers[i].FieldSets[f].m_lens.split("|"); 
																										
										for ( var tt=0; tt<list__text_fields.length; tt++ )
										
											{
												
												//size
												var the_size = list__text_field_length[i] ;
												
												if ( the_size == '' || the_size == undefined )
												
													{
														the_size = '17' ;
													}
													
												//prepop value
												var the_prepop_value = list__prepopulated_values[tt] ;
												
												if ( the_prepop_value == '' || the_prepop_value == undefined )
												
													{
														the_prepop_value = '' ;
													}
													
												var the_max_length = list__max_lengths[tt] ;
												
												if ( the_max_length == undefined )
												
													{
														the_max_length = '' ;
													}
											
												textField = document.createElement('INPUT') ;
											 	textField.type = 'text' ;
											 	textField.id = list__text_fields[tt] ;
											 	textField.setAttribute('name', list__text_fields[tt]) ;
											 	textField.setAttribute('value', the_prepop_value) ;											 	
											 	textField.setAttribute('size', the_size) ;
											 	textField.setAttribute('maxlength', the_max_length) ;
											 	textField.className = 'form_field_design' ;
											 	
											 	//if there is E-Mail validation against this field, then append it
												if ( jsonData.Offers[i].FieldSets[f].f_val == 'E-Mail' )
												
													{
																												
														textField.setAttribute('temp_holder', jsonData.Offers[i].offer_id) ;
														textField.onblur = function() { checkIfIsDuplicateLead(this.value, this.temp_holder); };
														
													}
											 	
											 	rowDiv.appendChild(textField) ;
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__text_fields[tt] + '|' ;
											 												
											}
	 								
	 								}
	 								
	 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'select_menu' )
	 							
	 								{
	 																					 	
									 	var list__select_field_name = jsonData.Offers[i].FieldSets[f].f_n.split("|") ;

										//split this guy up at the ^ level, remember the inners are |, but don't be misguided!!!
										var list__arrays_or_arrays__split_value_pairs = jsonData.Offers[i].FieldSets[f].f_d_v.split("^") ;
																								
										//loop over select field names as highest!
										for ( var sm=0; sm<list__select_field_name.length; sm++  )
										
											{
																													
												// Create a drop-down list
											 	dropDown = document.createElement('SELECT') ;
											 	dropDown.id = list__select_field_name[sm] ;
											 	dropDown.setAttribute('name', list__select_field_name[sm]) ;
											 	dropDown.className = 'form_field_design' ;															 	
											 	
											 	//now grab the row out of the ^ delimited list which are the name|value pairs
												var this_list = list__arrays_or_arrays__split_value_pairs[sm] ;
												
												//now create new list declaration
												var new_list = this_list.split("|") ;
												
												//does this list contain at least 1 that's going to make the page bleed or the form push everything around???
												var contains_at_least_one_bleeder = false ;
												
												//start with SELECT value=""
												option = document.createElement('option') ;
										  		option.value = '' ;	
										  		option.appendChild(document.createTextNode('Select')) ;
										  		dropDown.appendChild(option) ;
												
												//loop over THIS_LIST which is | in of itself
												for ( var mo=0; mo<new_list.length; mo++ )
												
													{
																																																	
														//ok, now you have something that looks like this MI=Michigan so split that up based on the equals sign as a delimiter = 
														var this_new_split = new_list[mo].split("=") ;
														
														var the_row_value = this_new_split[0] ;
														var the_row_display = this_new_split[1] ;
														
														//if the row display is too big, then Left() function it please
														if ( the_row_display.length >= 85 )
														
															{
																the_row_display = Left(the_row_display, 85) + '...' ;
																contains_at_least_one_bleeder = true ;
															}
														
														option = document.createElement('option') ;
												  		option.value = the_row_value ;																		  		
												  														  		
														if ( jsonData.Offers[i].FieldSets[f].f_v == the_row_value )
														
															{
																option.setAttribute('selected', 'true')
															}																				 																				  	
														  		
												  		option.appendChild(document.createTextNode(the_row_display)) ;
												  		dropDown.appendChild(option) ;																											
														
													}															 	
											 	
											 	rowDiv.appendChild(dropDown) ;
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + list__select_field_name[sm] + '|' ;											 														
												
											}													 	
	 								
	 								}
	 								
	 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'radio_buttons' )
			 							
	 								{
	 										 			 								
	 									var array_values_and_displays = jsonData.Offers[i].FieldSets[f].f_n.split("|") ;
										
										for( var rb=0; rb<array_values_and_displays.length; rb++)
										
											{
												//split up that row now!!!
												var valueArrayRowSplit = array_values_and_displays[rb].split("=");
												
												var the_row_value = valueArrayRowSplit[0] ;	
												var the_row_display = valueArrayRowSplit[1] ;	
																							
												// Create a radio selection												
												if(!document.addEventListener) 
												
													{
													 	// IE hack
														radioField= document.createElement("<input name=\"" + jsonData.Offers[i].FieldSets[f].f_n + "\"/>");
													} 
												
												else 
												
													{
														radioField= document.createElement("input");
													}													 	
											 	
											 	radioField.type = 'radio' ;
											 	radioField.id = jsonData.Legend[jl].FieldSets[sq].f_n + '__' + rb ;
											 	radioField.name = jsonData.Legend[jl].FieldSets[sq].f_n ;
											 	radioField.className = 'form_field_design' ;
											 	radioField.value = the_row_value ; 	
											 	
											 	if ( jsonData.Legend[jl].FieldSets[sq].f_v == the_row_value )
												
													{
														radioField.defaultChecked = true ;
														radioField.checked = true  ;
													}
											 	
											 	rowDiv.appendChild(radioField) ;
											 	rowDiv.appendChild(document.createTextNode(the_row_display)) ;
											 	
											 	rowDiv.appendChild(document.createElement('BR')) ;	
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Legend[jl].FieldSets[sq].f_n + '__' + rb + '|' ;										 		
												
											}																	 			 	
									 														 					 								
	 								}
	 								
	 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'check_boxes' )
	 							
	 								{
	 									 	
									 	//split this list up just once please
										var array_split_of_value_pairs = jsonData.Offers[i].FieldSets[f].f_d_v.split("|");
										
										var array_prechecked_values = jsonData.Offers[i].FieldSets[f].f_v.split("|") ;
										
										for( var cb=0; cb<array_split_of_value_pairs.length; cb++)
										
											{
												//split up that row now!!!
												var valueArrayRowSplit = array_split_of_value_pairs[cb].split("=");
												
												var the_row_value = valueArrayRowSplit[0] ;	
												var the_row_display = valueArrayRowSplit[1] ;
												
												//ok, now check against your list of pre-populated values to see if this value is in the list!!!
												var current_checkbox_value_is_in_prechecked_list = false ;
												
												for ( var list_element_i=0; list_element_i<array_prechecked_values.length; list_element_i++ )
												
													{
														//if the current i value MATCHES the same value as that which is about to be presented as the checkbox value, then You're On!!!!
														if ( array_prechecked_values[list_element_i] == the_row_value )
														
															{
																current_checkbox_value_is_in_prechecked_list = true ;
																break ;
															}
													}	
													
												// Create a checkbox
											 	checkbox = document.createElement('INPUT') ;
											 	checkbox.type = 'checkbox' ;
											 	checkbox.id = jsonData.Offers[i].FieldSets[f].f_n + '__' + cb ;
											 	checkbox.setAttribute('name', jsonData.Offers[i].FieldSets[f].f_n) ;
											 	checkbox.className = 'form_field_design' ;
											 	checkbox.setAttribute('value', the_row_value) ;
											 	
											 	if ( current_checkbox_value_is_in_prechecked_list == true )
												
													{
														checkbox.setAttribute('checked', 'checked') ;
													}
											 	
											 	rowDiv.appendChild(checkbox) ;											 	
											 	rowDiv.appendChild(document.createTextNode(the_row_display)) ;	
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Offers[i].FieldSets[f].f_n + '__' + cb + '|' ;	
												
											}											
	 								
	 								}
	 								
	 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'comment_box' )
	 							
	 								{
	 									//z = z + generateCommentBox(, , jsonData.Offers[i].FieldSets[f].the_cols, jsonData.Offers[i].FieldSets[f].the_rows, false) ;						 								
	 									// Create a textarea
									 	textArea = document.createElement('TEXTAREA') ;
									 	textArea.id = jsonData.Offers[i].FieldSets[f].f_n ;
									 	textArea.setAttribute('name', jsonData.Offers[i].FieldSets[f].f_n) ;
									 	textArea.setAttribute('value', jsonData.Offers[i].FieldSets[f].f_v) ;
									 	textArea.className = 'form_field_design' ;
									 	rowDiv.appendChild(textArea) ;
									 	
									 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + jsonData.Offers[i].FieldSets[f].f_n + '|' ;
	 								
	 								}	
	 								
	 							else if ( jsonData.Offers[i].FieldSets[f].f_t == 'hidden' )
	 							
	 								{
	 									
	 									var array__field_names = jsonData.Offers[i].FieldSets[f].f_n.split("|");
										var array__prepopulated_values = jsonData.Offers[i].FieldSets[f].f_v.split("|");
																										
										for ( var hf=0; hf<array__field_names.length; hf++ )
										
											{
																													
												//prepop value
												var the_prepop_value = array__prepopulated_values[hf] ;
												
												if ( the_prepop_value == '' || the_prepop_value == undefined )
												
													{
														the_prepop_value = '' ;
													}
											
												hiddenField = document.createElement('INPUT') ;
											 	hiddenField.type = 'hidden' ;
											 	hiddenField.id = array__field_names[hf] ;
											 	hiddenField.setAttribute('name', array__field_names[hf]) ;
											 	hiddenField.setAttribute('value', the_prepop_value) ;	
											 	rowDiv.appendChild(hiddenField) ;	
											 	
											 	list_of_ids_for_this_field_set = list_of_ids_for_this_field_set + array__field_names[hf] + '|' ;
											 												
											}
	 								
	 								}
	 									 								
	 							thisDiv.appendChild(rowDiv) ;		 							
	 									 								
	 							//append to list so we know ur there please	 							
	 							list_of_fields = list_of_fields + jsonData.Offers[i].FieldSets[f].f_t + '=' + list_of_ids_for_this_field_set + '=' + jsonData.Offers[i].FieldSets[f].f_l + '=' + jsonData.Offers[i].FieldSets[f].f_r + '=' + jsonData.Offers[i].FieldSets[f].f_val + '^' ;					 								
	 							 						
 							}	
 							
 						myForm.appendChild(document.createElement('BR')) ;
 						myForm.appendChild(document.createElement('BR')) ;
 						myForm.appendChild(document.createElement('BR')) ;
 							
 						// Create a submit button
						newButton = document.createElement('INPUT') ;
						newButton.id = 'the_submit_button' ;
						newButton.type = 'button' ;
						newButton.setAttribute('name', 'submit_button') ;
						newButton.value = c__submit_button_text ;
						newButton.onclick = sendDataToServer ;
						thisDiv.appendChild(newButton) ;
						
						myForm.appendChild(thisDiv) ;
 							
 						myForm.appendChild(document.createElement('BR')) ;	
 						myForm.appendChild(document.createElement('BR')) ;	
 						myForm.appendChild(document.createElement('BR')) ;	
 						myForm.appendChild(document.createElement('BR')) ;	
 						myForm.appendChild(document.createElement('BR')) ;			
				 					 				 					
 					 
						//list of all fields			
						hiddenField = document.createElement('INPUT') ;
						hiddenField.type = 'hidden' ;
						hiddenField.id = 'field__offer_id__' + jsonData.Offers[i].offer_id ;
						hiddenField.setAttribute('name', 'field__offer_id__' + jsonData.Offers[i].offer_id) ;
						hiddenField.setAttribute('value', list_of_fields) ;															 	
						myForm.appendChild(hiddenField) ;
						
				 		myForm.appendChild(document.createElement('BR')) ;
				 		myForm.appendChild(document.createElement('BR')) ;
				 		myForm.appendChild(document.createElement('BR')) ;				 			 				
				 		
			 		}				 	
			 	
			 	// Create a submit button
				newButton = document.createElement('INPUT') ;
				newButton.type = 'button' ;
				newButton.setAttribute('name', 'submit_button') ;
				newButton.value = 'Skip >>' ;
				newButton.onclick = skipThis ;
				myForm.appendChild(newButton) ;	
				
				//You're going to build a list of all the survey questions so u can deal with it
				hiddenField = document.createElement('input') ;
				hiddenField.type = 'hidden' ;
				hiddenField.id = 'survey_fields_to_deal_with_first' ;
				hiddenField.setAttribute('name', 'survey_fields_to_deal_with_first') ;
				hiddenField.setAttribute('value', '') ;															 	
				myForm.appendChild(hiddenField) ;
							
				//You're going to build a list of all the offers that were presented and pass this as 1 single variable
				hiddenField = document.createElement('INPUT') ;
				hiddenField.type = 'hidden' ;
				hiddenField.id = 'all_offers_presented' ;
				hiddenField.setAttribute('name', 'all_offers_presented') ;
				hiddenField.setAttribute('value', value__all_offers_presented) ;															 	
				myForm.appendChild(hiddenField) ;
		 							 			 	
		 	}
		 	
		 //We are now doing Survey List View to pull like Custom Coreg View
		 else if ( c__page_display_type == 'Survey List View'  )
		 
			{
				
				var hide_the_logos = true ;
						 		
				//remember *all* offers presented!!!
				var value__all_offers_presented = '' ;
				
				// Where the form will be placed into the page
				parentElement = document.getElementById('paste_this_where_you_want_your_offers_to_display') ;
				parentElement.innerHTML = "" ;
				
				// Create a form
				myForm = document.createElement('FORM') ;
				myForm.method = 'post' ;
				myForm.action = '#' ;
				myForm.setAttribute('name', 'wmi_form') ;
				myForm.id = 'wmi_form' ;		 		 		 		 		 		 
				 
				//for as many offers as returned
				for ( var i=0; i<jsonData.Offers.length; i++ )
				 
					{
						 		
						value__all_offers_presented = value__all_offers_presented + jsonData.Offers[i].offer_id + '|' ;	
						
						//crank out your div id now and hold it
						var this_main_container_div_id = 'div_container__' + jsonData.Offers[i].offer_id ;												 			
						 		
						//present the I am Interested Checkbox
						// Create a checkbox
						checkbox = document.createElement('INPUT') ;
						checkbox.type = 'checkbox' ;
						checkbox.id = 'include_offer_id__' + jsonData.Offers[i].offer_id ;
						checkbox.setAttribute('name', 'include_offer_id') ;
						checkbox.setAttribute('value', jsonData.Offers[i].offer_id) ;
						checkbox.onclick = function() { displayHTMLQuestionsCheckboxes('div_container__' + this.value, this.checked); };
						myForm.appendChild(checkbox) ;	
											 	
						/*
						thisQuestion = document.createElement('label') ;	
						thisText = document.createTextNode(' ' + jsonData.Offers[i].offer_question) ;
						thisQuestion.appendChild(thisText) ;
						myForm.appendChild(thisQuestion) ;	
						*/
						
						//HTML not Text for your Survey
						IntroQuestionDiv = document.createElement('span') ;
						IntroQuestionDiv.id = 'top_html_div__' + jsonData.Offers[i].offer_id ;
						IntroQuestionDiv.innerHTML = '&nbsp;' + jsonData.Offers[i].offer_question ;
						myForm.appendChild(IntroQuestionDiv) ;				 	
						
						myForm.appendChild(document.createElement('BR')) ;	
						myForm.appendChild(document.createElement('BR')) ;									
						
						//OfferDiv container that you can collapse, etc
						thisDiv = document.createElement('div') ;
						thisDiv.id = this_main_container_div_id ;
						thisDiv.style.display = 'none' ;
						thisDiv.innerHTML = jsonData.Offers[i].offer_layout ;
						myForm.appendChild(thisDiv) ;
						
						if ( jsonData.Offers[i].offer_layout.length > 1 )
						
							{
								thisDiv.appendChild(document.createElement('BR')) ;							
							}	
						
						//present your survey link button here!!!
						newButton = document.createElement('INPUT') ;
						newButton.type = 'button' ;
						newButton.setAttribute('name', jsonData.Offers[i].field__redirect_url) ;
						newButton.setAttribute('temp_holder', jsonData.Offers[i].field__redirect_url) ;
						newButton.id = 'survey_this__' + jsonData.Offers[i].survey_id ;
						newButton.value = 'Complete This Survey!' ;
						newButton.onclick = function() { goThere(this.temp_holder, this.name); };
						thisDiv.appendChild(newButton) ;								
										
						myForm.appendChild(document.createElement('BR')) ;		 				
					 		
					}	
					
				//You're going to build a list of all the survey questions so u can deal with it
				hiddenField = document.createElement('input') ;
				hiddenField.type = 'hidden' ;
				hiddenField.id = 'survey_fields_to_deal_with_first' ;
				hiddenField.setAttribute('name', 'survey_fields_to_deal_with_first') ;
				hiddenField.setAttribute('value', '') ;															 	
				myForm.appendChild(hiddenField) ;				 						 			 					 				 
					 							 			 	
			}		 		 		 	
				 	
		//generate pixel holding area
		var this_div = document.createElement("div");
		this_div.id = "the_pixel_div";
		this_div.innerHTML = "";
		myForm.appendChild(this_div);
				
		//stream it out to the DIV
		parentElement.appendChild(myForm) ;	
				
		//please go to #TOP
		document.location.href = '#top' ;
	
	}
	
function displayHTMLQuestionsCheckboxes(the_element, checked_or_not)
		
	{
		if ( checked_or_not == false )
		
			{
				document.getElementById(the_element).style.display = 'none' ;
			}
			
		if ( checked_or_not == true )
		
			{
				document.getElementById(the_element).style.display = 'block' ;
			}
	}
	
function goThere(go_where, url_value)

	{
			
		if ( go_where == 'in_house_survey' )
		
			{
				document.location.href = url_value  ;
			}
			
		else
		
			{
				
				window.open(url_value)  ;
				
			}
	
	}
	
//JSON Stuff
function JSONscriptRequest(fullUrl) 

	{
	    // REST request path
	    this.fullUrl = fullUrl; 
	    // Keep IE from caching requests
	    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
	    // Get the DOM location to put the script tag
	    this.headLoc = document.getElementsByTagName("head").item(0);
	    // Generate a unique script tag id
	    this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
	}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
//
JSONscriptRequest.prototype.buildScriptTag = function () {

    // Create the script tag
    this.scriptObj = document.createElement("script");
    
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
// 
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
//
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

//initialize 
r__session_id__value = '' ;
current_page_displayed = '0' ;

//initialize media_link_id and s_id
t__media_link_id = '' ;
t__s_id = '' ;

//try and set them if that is the case
//read the URL vars
var hash = getUrlVars();

//set these so we can pass thru URL
var the_hashed_media_link_id_value = hash['url_media_link_id'] ;

if ( the_hashed_media_link_id_value != undefined )

	{
		
		if ( IsNumeric(the_hashed_media_link_id_value) == true )
		
			{
				t__media_link_id = the_hashed_media_link_id_value ;
			}
	}
	
//do same for s_id
var the_hashed_s_id_value = hash['url_s_id'] ;

if ( the_hashed_s_id_value != undefined )

	{
		
		t__s_id = the_hashed_s_id_value ;
	}

//search box params - don't touch these
y__desired_start = '' ;	
y__level_of_education = '' ;
y__hs_grad_year = '' ;
y__military_status = '' ;
y__best_time_to_call = '' ;
y__employer = '' ;

//de-bugging stuff
display_output_variables = false ;

pagination__uuid = '' ;
this_is_the_last_page = '0' ;

//if they already did pass us set_r_session_id in the URL, then take it and re-set the value of r__session_id__value
function getUrlVars()

	{    
	
		var vars = [], hash;    
		var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');     
		
		for ( var i = 0; i < hashes.length; i++)    
		
			{        
			
				hash = hashes[i].split('=');        
				vars.push(hash[0]);        
				vars[hash[0]] = hash[1];    
				
			}     
			
		return vars;
		
	}	
	
function skipThis()

	{
	
		getOffersForThisPage();
	
	}	
	
function checkIfIsDuplicateLead(the_email, the_offer_id)

	{
			
		//First, make sure they actually even passed us an email address!!!
		if ( the_email.length < 1 )
		
			{
				alert('Please enter a valid email address!') ;
				return false ;
			}
			
		//Now, run the email syntax checker against this email address because there's not sense in sending it off to the server if it's just a bunch of garbage
		var email_syntax_is_good = checkEmailSyntax(the_email) ; 
		
		if ( email_syntax_is_good == false )
		
			{
				alert('The email you entered, ' + the_email + ', is not valid!') ;
				return false ;
			}
		
		//create your posting string
		var the_dupe_check_posting_string = 'http://www.leadstrike.com/offer_engine_interface/check_if_lead_is_dupe.cfm?' + 'rn=' + Math.random() * 5 + '&email_to_check=' + the_email + '&offer_id_to_check_against=' + the_offer_id ;
		
		sendJSONRequest(the_dupe_check_posting_string) ;
	
	}
	
//handle the above
function doCheckDuplicateResponse(jsonData)

	{
				
		if ( jsonData.response == 1 )
		
			{
				alert('Please note the email, ' + jsonData.email_to_check + ', you have entered has already been used for this offer!') ;
			}
		
	}
	
function doRadioButtonOpenAndClose(the_div_to_work_on, yes_or_no)

	{
	
		if ( yes_or_no == 'Yes' )
		
			{
				document.getElementById(the_div_to_work_on).style.display = 'block' ;
			}
			
		else
		
			{
				document.getElementById(the_div_to_work_on).style.display = 'none' ;
			}
	
	}

