<!--

/* Configuration */
// Collector script location
var GRAP_IP_URL = "https://t1.llanalytics.com/tracking_engine/grapIP.php";

var COLLECTOR_URL = "https://t1.llanalytics.com/tracking_engine/trackEngine.php";

var AUTOMATIC_WEB_FORM_TRACKING_URL = "https://t1.llanalytics.com/tracking_engine/track-activities.php";

if (location.protocol === "https:") {
	var jQuery_LIBRARY_INCLUDE_URL = "https://d2tkczi6ecqjoh.cloudfront.net/scripts/jquery-1.9.1.min.js";

} else {
	var jQuery_LIBRARY_INCLUDE_URL = "http://cdn.leadliaison.com/scripts/jquery-1.9.1.min.js";

}
var Wistia_Shepherd_Lib_URL = "https://fast.wistia.net/static/embed_shepherd-v1.js";

var GET_PROSPECT_DATA_URL = "https://t1.llanalytics.com/tracking_engine/get-prospect-automatic-tracking-data.php?callback=?";

var ACTIVITY_URL = "https://t1.llanalytics.com/tracking_engine/trackActivity.php";

/**/
function grapIP(_callback) {
	/* Create the image */
	IPimg = new Image();
	if(ll_is_empty(_callback)){
		IPimg.onload = ResendRequest;
	} else {
		IPimg.onload = _callback;
	}
	/* Send the request */
	IPimg.src = GRAP_IP_URL + "?rand=" + Math.random();
}
function ll_is_empty(_var){
	return (typeof _var == 'undefined' || !_var || _var == '' || _var == 0);
}
if(typeof ll_api == 'undefined')
var ll_api = {
	log_prospect_activity: function (activity_options, callback){
		try{
			var _data_to_submit = {};
			_data_to_submit.action = 'log_prospect_activity';
			_data_to_submit.activity_options = JSON.stringify ( activity_options );
			
			_data_to_submit = _ll_track_form_submission.append_tracking_data(_data_to_submit);
			
			/**
			 * Send the submitted data to LL side.
			 */
			_ll_track_form_submission.load_prospect_info(function(){
				_ll_track_form_submission.ll_jQuery.getJSON( AUTOMATIC_WEB_FORM_TRACKING_URL + '?callback=?', _data_to_submit).done(function( _response_data ) {
					if (typeof callback != 'undefined' && callback) {
						callback.call (this, _response_data);
					}
				});
			}, null);
			
		}catch(err){ }
	},
	replace_page_urls: function (pages_object, parameter, pre_value){
		if (typeof parameter == 'undefined' || !parameter) {
			parameter = 'lluvid';
		}
		if (typeof pre_value == 'undefined' || !pre_value) {
			pre_value = '';
		}
		try{
			/**
			 * Send the submitted data to LL side.
			 */
			_ll_track_form_submission.load_prospect_info(function(){
				console.log ('_ll_track_form_submission.prospect_info');
				console.log (_ll_track_form_submission.prospect_info);
				if (_ll_track_form_submission.prospect_info && typeof _ll_track_form_submission.prospect_info.ll_unique_visitor_id != 'undefined') {
					var ll_unique_visitor_id = _ll_track_form_submission.prospect_info.ll_unique_visitor_id;
					if (ll_unique_visitor_id > 0) {
						if (typeof pages_object != 'undefined' && pages_object) {
							/*
							if (typeof pages_object.exact != 'undefined' && pages_object.exact) {
								for (i in pages_object.exact) {
									var page = pages_object.exact [i];
									if (page && page != '') {
										var as = _ll_track_form_submission.ll_jQuery ('a[href="' + page + '"]')
										$(as).each (function (){
											var href = $(this).attr ('href');
											if (typeof href != 'undefined' && href && href != '') {
												console.log (href)
											}
										})
									}
								}
							}
							*/
							
							
							if (typeof pages_object.exact != 'undefined' && pages_object.exact) {
								if (typeof pages_object.exact.length != 'undefined' && pages_object.exact.length > 0) {
									if (typeof pages_object.exact.indexOf != 'undefined') {
										var as = _ll_track_form_submission.ll_jQuery('a[href]');
										$(as).each(function () {
											var href = $(this).attr('href');
											if (typeof href != 'undefined' && href && href != '') {
												if (pages_object.exact.indexOf (href) >= 0) {
													//console.log (href)
													var href_new = ll_api.updateQueryStringParameter(href, parameter, pre_value + ll_unique_visitor_id);
													//console.log (href_new)
													if (href_new && href_new != '') {
														$(this).attr('href', href_new);
													}
												}
											}
										})
									}
								}
							}
						}
					}
				}
			}, null);
		}catch(err){ }
	},
	updateQueryStringParameter: function(uri, key, value) {
		var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
		var separator = uri.indexOf('?') !== -1 ? "&" : "?";
		if (uri.match(re)) {
			return uri.replace(re, '$1' + key + "=" + value + '$2');
		} else {
			return uri + separator + key + "=" + value;
		}
	},
	apply_after_tracking_actions: function (is_new_visit){
		if (typeof ll_is_append_prospect_identifier_cookie != 'undefined' && ll_is_append_prospect_identifier_cookie) {
			this.set_prospect_id_to_cookie();
		}
	},
	set_prospect_id_to_cookie: function (value){
		_ll_track_form_submission.load_prospect_info(function(){
			if (_ll_track_form_submission.prospect_info && typeof _ll_track_form_submission.prospect_info.ll_unique_visitor_id != 'undefined') {
				ll_api.createCookie('ll_prospect_id_encoded', _ll_track_form_submission.prospect_info.llprspctid_encoded, 365);
			}
		}, null);
	},
	get_prospect_id_from_cookie: function (){
		return ll_api.readCookie('ll_prospect_id_encoded');
	},
	createCookie: function (name, value, days) {
		var expires = "";
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days*24*60*60*1000));
			expires = "; expires=" + date.toUTCString();
		}
		document.cookie = name + "=" + value + expires + "; path=/";
	},
	readCookie: function (name) {
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	},
	eraseCookie: function (name) {
		createCookie(name,"",-1);
	}
}

if(typeof _ll_track_form_submission == 'undefined')
var _ll_track_form_submission = {
	ll_jQuery: null,

	ll_trk_no_ck: 0,
	
	prospect_info: {},
	loaded_js_files: {},

	submitted_forms: {},
	viewed_forms: {},
	current_form: {},
	current_form_index: {},
	original_on_submit_functions: {},
	field_email: 'email',
	field_fullname: 'fullname',
	field_firstname: 'firstname',
	field_lastname: 'lastname',
	field_company: 'company',
	
	ll_prospect_info_load_trials: 0,
	
	field_name_identifier_for_email: [],
	field_name_identifier_for_fullname: [],
	field_name_identifier_for_firstname: [],
	field_name_identifier_for_lastname: [],
	field_name_identifier_for_company: [],
	
	field_id_identifier_for_email: [],
	field_id_identifier_for_fullname: [],
	field_id_identifier_for_firstname: [],
	field_id_identifier_for_lastname: [],
	field_id_identifier_for_company: [],

	is_loading_jquery_lib: false,
	is_loaded_jquery_lib: false,
	is_loading_prospect_info: false,
	is_loaded_prospect_info: false,
	
	parse_custom_input_identifier_settings: function(){
		if(typeof ll_fields_map_settings_by_field_name_identifier == 'object'){
			if(typeof ll_fields_map_settings_by_field_name_identifier.email != 'undefined' && ll_fields_map_settings_by_field_name_identifier.email && ll_fields_map_settings_by_field_name_identifier.email != ''){
				this.field_name_identifier_for_email = ll_fields_map_settings_by_field_name_identifier.email.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_name_identifier.fullname != 'undefined' && ll_fields_map_settings_by_field_name_identifier.fullname && ll_fields_map_settings_by_field_name_identifier.fullname != ''){
				this.field_name_identifier_for_fullname = ll_fields_map_settings_by_field_name_identifier.fullname.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_name_identifier.firstname != 'undefined' && ll_fields_map_settings_by_field_name_identifier.firstname && ll_fields_map_settings_by_field_name_identifier.firstname != ''){
				this.field_name_identifier_for_firstname = ll_fields_map_settings_by_field_name_identifier.firstname.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_name_identifier.lastname != 'undefined' && ll_fields_map_settings_by_field_name_identifier.lastname && ll_fields_map_settings_by_field_name_identifier.lastname != ''){
				this.field_name_identifier_for_lastname = ll_fields_map_settings_by_field_name_identifier.lastname.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_name_identifier.company != 'undefined' && ll_fields_map_settings_by_field_name_identifier.company && ll_fields_map_settings_by_field_name_identifier.company != ''){
				this.field_name_identifier_for_company = ll_fields_map_settings_by_field_name_identifier.company.toLowerCase().split (',');
			}
		}
		if(typeof ll_fields_map_settings_by_field_id_identifier == 'object'){
			if(typeof ll_fields_map_settings_by_field_id_identifier.email != 'undefined' && ll_fields_map_settings_by_field_id_identifier.email && ll_fields_map_settings_by_field_id_identifier.email != ''){
				this.field_id_identifier_for_email = ll_fields_map_settings_by_field_id_identifier.email.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_id_identifier.fullname != 'undefined' && ll_fields_map_settings_by_field_id_identifier.fullname && ll_fields_map_settings_by_field_id_identifier.fullname != ''){
				this.field_id_identifier_for_fullname = ll_fields_map_settings_by_field_id_identifier.fullname.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_id_identifier.firstname != 'undefined' && ll_fields_map_settings_by_field_id_identifier.firstname && ll_fields_map_settings_by_field_id_identifier.firstname != ''){
				this.field_id_identifier_for_firstname = ll_fields_map_settings_by_field_id_identifier.firstname.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_id_identifier.lastname != 'undefined' && ll_fields_map_settings_by_field_id_identifier.lastname && ll_fields_map_settings_by_field_id_identifier.lastname != ''){
				this.field_id_identifier_for_lastname = ll_fields_map_settings_by_field_id_identifier.lastname.toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_id_identifier.company != 'undefined' && ll_fields_map_settings_by_field_id_identifier.company && ll_fields_map_settings_by_field_id_identifier.company != ''){
				this.field_id_identifier_for_company = ll_fields_map_settings_by_field_id_identifier.company.toLowerCase().split (',');
			}
		}
	},
	parse_custom_input_identifiers_by_label_settings: function(_form){
		if(typeof ll_fields_map_settings_by_field_label_for_identifier == 'object'){
			var for_email = '';
			var for_fullname = '';
			var for_firstname = '';
			var for_lastname = '';
			var for_company = '';
			if(typeof ll_fields_map_settings_by_field_label_for_identifier.email != 'undefined' && ll_fields_map_settings_by_field_label_for_identifier.email != ''){
				for_email = ll_fields_map_settings_by_field_label_for_identifier.email.trim().toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_label_for_identifier.fullname != 'undefined' && ll_fields_map_settings_by_field_label_for_identifier.fullname != ''){
				for_fullname = ll_fields_map_settings_by_field_label_for_identifier.fullname.trim().toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_label_for_identifier.firstname != 'undefined' && ll_fields_map_settings_by_field_label_for_identifier.firstname != ''){
				for_firstname = ll_fields_map_settings_by_field_label_for_identifier.firstname.trim().toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_label_for_identifier.lastname != 'undefined' && ll_fields_map_settings_by_field_label_for_identifier.lastname != ''){
				for_lastname = ll_fields_map_settings_by_field_label_for_identifier.lastname.trim().toLowerCase().split (',');
			}
			if(typeof ll_fields_map_settings_by_field_label_for_identifier.company != 'undefined' && ll_fields_map_settings_by_field_label_for_identifier.company != ''){
				for_company = ll_fields_map_settings_by_field_label_for_identifier.company.trim().toLowerCase().split (',');
			}
			if(for_email.length > 0 || for_fullname.length > 0 || for_firstname.length > 0 || for_lastname.length > 0 || for_company.length > 0){
				if(_form){
					var _form_labels = _form.getElementsByTagName('label');
					var _form_labels_length = _form_labels.length;
					if(_form_labels_length > 0){
						var __indx
						for(var __indx = 0; __indx < _form_labels_length; __indx ++){
							var _form_label_index = __indx;
							var _form_label = _form_labels[_form_label_index];
							if(typeof _form_label.htmlFor != 'undefined' && _form_label.htmlFor != ''){
								var _form_label_value = _form_label.textContent;
								
								if(typeof _form_label_value != 'undefined'){
									_form_label_value = _form_label_value.trim().toLowerCase();
									if(_form_label_value != ''){
										if (for_email.indexOf( _form_label_value ) > -1) {
											this.field_id_identifier_for_email.push (_form_label.htmlFor.toLowerCase());
										}
										if (for_fullname.indexOf( _form_label_value ) > -1) {
											this.field_id_identifier_for_fullname.push (_form_label.htmlFor.toLowerCase());
										}
										if (for_firstname.indexOf( _form_label_value ) > -1) {
											this.field_id_identifier_for_firstname.push (_form_label.htmlFor.toLowerCase());
										}
										if (for_lastname.indexOf( _form_label_value ) > -1) {
											this.field_id_identifier_for_lastname.push (_form_label.htmlFor.toLowerCase());
										}
										if (for_company.indexOf( _form_label_value ) > -1) {
											this.field_id_identifier_for_company.push (_form_label.htmlFor.toLowerCase());
										}
									}
								}
							}
						}
					}
				} 
			}
		}
	},
	is_exclude_auto_form_tracking: function(_form_original_action, _form){
		var _is_exclude_auto_form = (_form_original_action.indexOf('process-existing-webform.php') != -1
			|| _form_original_action.indexOf('#main_body') != -1
			|| _form_original_action.indexOf('preference-center.php') != -1
			|| _form_original_action.indexOf('process-hosted-external-webform.php') != -1)
		if(!_is_exclude_auto_form){
			if(_form && typeof _form.getAttribute != 'undefined'){
				var _ll_existing_form_id = _form.getAttribute('ll_existing_form_id');
				if(typeof _ll_existing_form_id != 'undefined' && _ll_existing_form_id){
					if(_ll_existing_form_id > 0){
						_is_exclude_auto_form = true;
					}
				}
			}
		}
		return _is_exclude_auto_form;
	},
	/**
	 * Initialize adding the onsubmit event to all the existing webforms.
	 * This method is called once the collector.php file is loaded, and it search the document for any webforms.
	 * If not found any webforms then maybe the document is not loaded yet, so it schedule to call itself again after 3 seconds and so on.
	 * Note: this also means if somehow there is JS code which adds webforms to a page not containing webforms, then these webforms will be tracked too.
	 */
	init: function(){
		try{
			if(typeof document.readyState != 'undefined' && (document.readyState == 'uninitialized' || document.readyState == 'loading' || document.readyState == 'loaded')){
				/**
				 * If the page is still loading, then wait for 2 seconds and try again.
				 * This usually happens on FF when showing the page containing the form within iframe, since the collector.php fiels is loaded before the page complete loading.
				 */
				window.setTimeout(function(){
					_ll_track_form_submission.init();
				}, 2000);
				return;
			}
			/*
			if(typeof ll_use_automatic_form_tracking != 'undefined' && ll_use_automatic_form_tracking == false){
				return;
			}
			*/
			// Parse custom naming identifiers [input name/id]
			this.parse_custom_input_identifier_settings();
			
			var _forms = document.getElementsByTagName('form');
			var _forms_length = _forms.length;
			if(_forms_length > 0){
				var __indx
				for(var __indx = 0; __indx < _forms_length; __indx ++){
					var _is_form_automatic_tracked = false;
				
					var _form_index = __indx;
					var _form = _forms[_form_index];
			
					var _form_elements_length = _form.elements.length;
					if(typeof ll_use_automatic_form_tracking != 'undefined' && ll_use_automatic_form_tracking == false){
						//Do not auto-track the form.
					} else {
						if(_form_elements_length > 0){
							// Parse custom label identifiers linked to inputs with the "for" attribute
							this.parse_custom_input_identifiers_by_label_settings(_form);
							
							var _form_original_action = _form.getAttribute('action');
							if(!_form_original_action || ! _ll_track_form_submission.is_exclude_auto_form_tracking(_form_original_action, _form)){
								/**
								 * Check if the form has at least one valid parameter to be tracked.
								 * Valid parameter means it is [email, fullname or company] which are the tracked parameters.
								 */
								var is_has_at_least_one_tracked_field = false;
								for(var _form_element_index = 0; _form_element_index < _form_elements_length; _form_element_index++){
									var _form_element = _form.elements[_form_element_index];
									var _we_id_lowered = (_form_element.id) ? _form_element.id.toLowerCase() : '';
									var _we_name_lowered = (_form_element.name) ? _form_element.name.toLowerCase() : '';
									
									/**
									 * 1- Check by the element name.
									 */
									if(typeof _we_name_lowered != 'undefined' && _we_name_lowered != ''){
										if (_ll_track_form_submission.field_name_identifier_for_email.indexOf(_we_name_lowered) > -1) {
											is_has_at_least_one_tracked_field = true;
										}
										if (_ll_track_form_submission.field_name_identifier_for_fullname.indexOf(_we_name_lowered) > -1) {
											is_has_at_least_one_tracked_field = true;
										}
										if (_ll_track_form_submission.field_name_identifier_for_firstname.indexOf(_we_name_lowered) > -1) {
											is_has_at_least_one_tracked_field = true;
										}
										if (_ll_track_form_submission.field_name_identifier_for_lastname.indexOf(_we_name_lowered) > -1) {
											is_has_at_least_one_tracked_field = true;
										}
										if (_ll_track_form_submission.field_name_identifier_for_company.indexOf(_we_name_lowered) > -1) {
											is_has_at_least_one_tracked_field = true;
										}
									}
									if(!is_has_at_least_one_tracked_field){
										if(typeof _we_id_lowered != 'undefined' && _we_id_lowered != ''){
											if (_ll_track_form_submission.field_id_identifier_for_email.indexOf(_we_id_lowered) > -1) {
												is_has_at_least_one_tracked_field = true;
											}
											if (_ll_track_form_submission.field_id_identifier_for_fullname.indexOf(_we_id_lowered) > -1) {
												is_has_at_least_one_tracked_field = true;
											}
											if (_ll_track_form_submission.field_id_identifier_for_firstname.indexOf(_we_id_lowered) > -1) {
												is_has_at_least_one_tracked_field = true;
											}
											if (_ll_track_form_submission.field_id_identifier_for_lastname.indexOf(_we_id_lowered) > -1) {
												is_has_at_least_one_tracked_field = true;
											}
											if (_ll_track_form_submission.field_id_identifier_for_company.indexOf(_we_id_lowered) > -1) {
												is_has_at_least_one_tracked_field = true;
											}
										}
									}
									if(!is_has_at_least_one_tracked_field){
										if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_email, _we_name_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_fullname, _we_name_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_firstname, _we_name_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_lastname, _we_name_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_company, _we_name_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_email, _we_id_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_fullname, _we_id_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_firstname, _we_id_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_lastname, _we_id_lowered)){
											is_has_at_least_one_tracked_field = true;
										}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_company, _we_id_lowered)){
											is_has_at_least_one_tracked_field = true;
										}
									}
									if(is_has_at_least_one_tracked_field)
										continue;
								}
								if(is_has_at_least_one_tracked_field){
									/**
									 * Extracting the original form on submit event, and storing into an array to override with our onsubmit event, and call within our on submit event.
									 */
									var _form_on_submission_function = _form.onsubmit;
									if (_form_on_submission_function != null) {
										if(_form_on_submission_function.toString().indexOf('LL_ONSUBMIT_HANDLER') != -1){
											//Already handled by LL.
											continue;
										}
										_ll_track_form_submission.current_form[_form_index] = _form
										_ll_track_form_submission.current_form_index = _form_index;
										var _form_on_submission_function_str = _form_on_submission_function.toString();
										if (_form_on_submission_function_str.search(/this[\)]/))
											_form_on_submission_function_str = _form_on_submission_function_str.replace(/this[\)]/g, '_ll_track_form_submission.current_form[_ll_track_form_submission.current_form_index])');
										if (_form_on_submission_function_str.search(/this[\,]/))
											_form_on_submission_function_str = _form_on_submission_function_str.replace(/this[\,]/g, '_ll_track_form_submission.current_form[_ll_track_form_submission.current_form_index],');
										if (_form_on_submission_function_str.search(/this[\.]/))
											_form_on_submission_function_str = _form_on_submission_function_str.replace(/this[\.]/g, '_ll_track_form_submission.current_form[_ll_track_form_submission.current_form_index].');
										if (_form_on_submission_function_str.search(/this[\s]/))
											_form_on_submission_function_str = _form_on_submission_function_str.replace(/this[\s]/g, '_ll_track_form_submission.current_form[_ll_track_form_submission.current_form_index] ');
										var expr = "_ll_track_form_submission.original_on_submit_functions[_ll_track_form_submission.current_form_index] = " + _form_on_submission_function_str;
										eval(expr);
									}
									/**
									 * Assign the form index to the form object, since the _form_index will always have the last form linked to an onsubmit event.
									 */
									try{_form.ll_form_index = _form_index;}catch(err){ }
									/**
									 * Assign our on submit event.
									 */
									_form.onsubmit = function (event) {
										this.LL_ONSUBMIT_HANDLER = true;
										//Must have the LL_ONSUBMIT_HANDLER here since we are checking if the onsubmit has this code, and in this case we do not track it again.
										if(typeof this.ll_form_index != 'undefined')
											_form_index = this.ll_form_index;
										return _ll_track_form_submission.form_submit(this, _form_index);
									};
									_ll_track_form_submission.view_form(_form);
									_is_form_automatic_tracked = true;
								}
							}
						}
					}
					try{
						ll_prefill_automatic_tracked_form_fields = (typeof ll_prefill_automatic_tracked_form_fields != 'undefined' && ll_prefill_automatic_tracked_form_fields );
						if((_is_form_automatic_tracked && ll_prefill_automatic_tracked_form_fields) || (typeof ll_append_identifier_to_form != 'undefined' && ll_append_identifier_to_form)){
							_ll_track_form_submission.load_prospect_info(function(_form){
								_ll_track_form_submission.load_prospect_info_to_form(_form);
							}, _form);
						}
					}catch(err){ }
				}
			}else{
				/**
				 * If the page doesn't has any webforms, then schedule to check for webforms again after 3 seconds, since maybe the document is not loaded yet.
				 */
				window.setTimeout(function(){
					_ll_track_form_submission.init();
				}, 3000);
				return;
			}
		}catch(err){ }
		if(typeof ll_frequent_try_auto_track_forms != 'undefined' && ll_frequent_try_auto_track_forms){
			window.setTimeout(function(){
				_ll_track_form_submission.init();
			}, 2000);
		}
	},
	/**
	 * Submit webform to LL to process the submitted fields [if the form contains any tracked field which has value filled by the lead].
	 */
	form_submit: function(_form, _form_index){
		var form_final_return = true;
		try{
			_ll_track_form_submission.current_form_index = _form_index;
			/**
			 * If the form had an on submit event, then call here.
			 */
			if (_ll_track_form_submission.original_on_submit_functions[_form_index] != null){
				var _original_submit_return = _ll_track_form_submission.original_on_submit_functions[_form_index]();
				form_final_return = _original_submit_return;

				var check_ll_ignore_original_onsubmit_result = false;
				if(typeof _form.attributes != 'undefined' && typeof _form.attributes['ll_ignore_original_onsubmit_result'] != 'undefined'){
					if (_form.attributes['ll_ignore_original_onsubmit_result'].nodeValue == 'true' || _form.attributes['ll_ignore_original_onsubmit_result'].nodeValue == 1) {
						check_ll_ignore_original_onsubmit_result = true;
					}
				} else {
					if (typeof ll_ignore_original_onsubmit_result != 'undefined') {
						if (ll_ignore_original_onsubmit_result == 'true' || ll_ignore_original_onsubmit_result == 1 || ll_ignore_original_onsubmit_result == true) {
							check_ll_ignore_original_onsubmit_result = true;
						}
					}
				}
				
				if (!check_ll_ignore_original_onsubmit_result) {
					/**
					 * If the original on submit form method returns false, then return false here too.
					 * In most cases this is because the form failed to be validated.
					 */
					if( _original_submit_return == false) {
						return form_final_return;
					}
				}
			}
			/**
			 * If form was not submitted successfully before to LL within the same page hit, then submit.
			 * Else, don't submit.
			 */
			if(!_ll_track_form_submission.submitted_forms[_form_index]){
				var _form_elements_length = _form.elements.length;
				if(_form_elements_length > 0){
					/**
					 * Preparing form global info
					 */
					var _form_original_action = _form.getAttribute('action');
					if(!_form_original_action || ! _ll_track_form_submission.is_exclude_auto_form_tracking(_form_original_action, _form)){
						/**
						 * The form name is the title of the web page.
						 */
						_form_name = this.form_get_name(_form);
						
						var _email = _fullname = _firstname = _lastname = _company = '';
						
						/**
						 * Preparing form fields info
						 */
						for(var _form_element_index = 0; _form_element_index < _form_elements_length; _form_element_index++){
							var _form_element = _form.elements[_form_element_index];
							if(typeof _form_element.value != 'undefined' && _form_element.value != ''){
								var _ll_field_identifier = _ll_track_form_submission.get_ll_field_identifier(_form_element);
								switch(_ll_field_identifier){
									case _ll_track_form_submission.field_email:
										_email = _form_element.value;
										break;
									case _ll_track_form_submission.field_fullname:
										_fullname = _form_element.value;
										break;
									case _ll_track_form_submission.field_firstname:
										_firstname = _form_element.value;
										break;
									case _ll_track_form_submission.field_lastname:
										_lastname = _form_element.value;
										break;
									case _ll_track_form_submission.field_company:
										_company = _form_element.value;
										break;
								}
							}
						}
						//if(_email != '' || _fullname != '' || _firstname != '' || _lastname != '' || _company != '')
						if(_email != '' || _fullname != '' || _firstname != '' || _lastname != ''){
							var _data_to_submit = {};
							/**
							 * Form Info
							 */
							_data_to_submit.form_original_action = _form_original_action;
							_data_to_submit.form_name = _form_name;
							/**
							 * Form elements submitted info
							 */
							_data_to_submit.action = 'automatic_form_submission_track';
							_data_to_submit.email = _email;
							_data_to_submit.fullname = _fullname;
							_data_to_submit.firstname = _firstname;
							_data_to_submit.lastname = _lastname;
							_data_to_submit.company = _company;
							
							_data_to_submit = _ll_track_form_submission.append_tracking_data(_data_to_submit);
							
							/**
							 * Send the submitted data to LL side.
							 */
							_ll_track_form_submission.process_call(AUTOMATIC_WEB_FORM_TRACKING_URL, _data_to_submit, function(){
								_ll_track_form_submission.callback_after_form_submitted(_form, 'submission', _form_index);
							});
							
							if(getBrowserType() == 'Safari'){
								/**
								 * If browser type is Safari, then just schedule the form to submit after 750ms, so it sends the image request
								 * because on Safari the added image will not be rendered from the browser until this event [onsubmit] ends, and if it ends without returning false the img request will not go.
								 */
								_ll_track_form_submission.submitted_forms[_form_index] = true;
								if( _original_submit_return == false) {
									return form_final_return;
								}
								window.setTimeout(function(){
									_form.submit();
								}, 750);
								//return false;
							} else {
								/**
								 * Sleeping for 250ms so that we make sure the request to track the submitted data at LL side is sent.
								 * Because if the form is subitted before the request is sent to LL, the form submission will dismiss the request to LL.
								 */
								_ll_track_form_submission.sleep(750);
							}
						}
					}
				}
			}
		}catch(err){ }
		return form_final_return;
	},
	view_form: function(_form){
		window.setTimeout(function(){
			_ll_track_form_submission.track_view_form(_form);
		}, 3000);
	},
	track_view_form: function(_form){
		try{
			/**
			 * If form was not submitted successfully before to LL within the same page hit, then submit.
			 * Else, don't submit.
			 */
			var _form_index = _form.ll_form_index;
			if(!_ll_track_form_submission.viewed_forms[_form_index]){
				/**
				 * Preparing form global info
				 */
				var _form_original_action = _form.getAttribute('action');
				if(!_form_original_action || ! _ll_track_form_submission.is_exclude_auto_form_tracking(_form_original_action, _form)){
					/**
					 * The form name is the title of the web page.
					 */
					_form_name = this.form_get_name(_form);
					
					var _data_to_submit = {};
					/**
					 * Form Info
					 */
					_data_to_submit.form_original_action = _form_original_action;
					_data_to_submit.form_name = _form_name;
					/**
					 * Form elements submitted info
					 */
					_data_to_submit.action = 'automatic_form_view_track';
					
					_data_to_submit = _ll_track_form_submission.append_tracking_data(_data_to_submit);
					
					/**
					 * Send the submitted data to LL side.
					 */
					_ll_track_form_submission.process_call(AUTOMATIC_WEB_FORM_TRACKING_URL, _data_to_submit, function(){
						_ll_track_form_submission.callback_after_form_submitted(_form, 'view', _form_index);
					});
				}
			}
		}catch(err){ }
	},
	form_get_name: function(_form){
		_form_name = '';
		var _ll_form_identifier = _form.getAttribute("ll_form_identifier");
		if( typeof _ll_form_identifier != "undefined" && _ll_form_identifier != "undefined" && _ll_form_identifier != "null" && _ll_form_identifier != null && _ll_form_identifier){
			_form_name = _ll_form_identifier;
		} else {
			var _form_name_attr = _form.getAttribute("name");
			if( typeof _form_name_attr != "undefined" && _form_name_attr != "undefined" && _form_name_attr != "null" && _form_name_attr != null && _form_name_attr){
				_form_name = _form_name_attr;
			} else {
				var _form_id = _form.getAttribute("id");
				if( typeof _form_id != "undefined" && _form_id != "undefined" && _form_id != "null" && _form_id != null && _form_id){
					_form_name = _form_id;
				}
			}
		}
		return _form_name;
	},
	process_call: function(URL, _data_to_submit, _call_back){
		/* Encode the parameters */
		var _query_string_to_submit = "";
		for (prop in _data_to_submit) {
			if(typeof _data_to_submit[prop] == 'Object' || typeof _data_to_submit[prop] == 'Array' || typeof _data_to_submit[prop] == 'object' || typeof _data_to_submit[prop] == 'array'){
				for(subprop in _data_to_submit[prop]){
					_query_string_to_submit += "&" + encodeURIComponent(prop) + "[]=" + encodeURIComponent(_data_to_submit[prop][subprop]);
				}
			}else{
				_query_string_to_submit += "&" + encodeURIComponent(prop) + "=" + encodeURIComponent(_data_to_submit[prop]);
			}
		}
		_query_string_to_submit = _query_string_to_submit.substring(1);
		/* SM - Added to prevent loading cached files */
		_query_string_to_submit = _query_string_to_submit + "&rand=" + Math.random()
		/* Create the image */
		img = new Image();
		if(typeof _call_back != 'undefined'){
			img.onload = _call_back
		}
		/* Send the request */
		img.src = URL + "?" + _query_string_to_submit;
	},
	append_tracking_data: function(_data_to_submit){
		/**
		 * Hit info.
		 */
		_data_to_submit.llcustid = _ll_hit_data.llcustid;
		_data_to_submit.domain = _ll_hit_data.domain;
		_data_to_submit.page = _ll_hit_data.page;
		_data_to_submit.fullpage = _ll_hit_data.fullpage;
		_data_to_submit.pageTitle = _ll_hit_data.pageTitle;
		_data_to_submit.referrer = _ll_hit_data.referrer;
		_data_to_submit.searchTerm = _ll_hit_data.searchTerm;
		_data_to_submit.searchEngine = _ll_hit_data.searchEngine;
		_data_to_submit.status = _ll_hit_data.status;
		_data_to_submit.brsr_t = _ll_hit_data.brsr_t;
		_data_to_submit.brsr_v = _ll_hit_data.brsr_v;
		_data_to_submit.lead_nrtr = _ll_hit_data.lead_nrtr;
		_data_to_submit.llsubId = _ll_hit_data.llsubId;
		_data_to_submit.llatmn_cmpid = _ll_hit_data.llatmn_cmpid;
		_data_to_submit.lead_nrtr = _ll_hit_data.lead_nrtr;
		_data_to_submit.llstatType = _ll_hit_data.llstatType;
		_data_to_submit.llstatId = _ll_hit_data.llstatId;
		_data_to_submit.outlookContactEmail = _ll_hit_data.outlookContactEmail;
		_data_to_submit.outlookContactName = _ll_hit_data.outlookContactName;
		_data_to_submit.outlookEmailSubject = _ll_hit_data.outlookEmailSubject;
		_data_to_submit.outlookEmailDate = _ll_hit_data.outlookEmailDate;
		_data_to_submit.ll_3p_email = _ll_hit_data.ll_3p_email;
		_data_to_submit.ll_3p_fn = _ll_hit_data.ll_3p_fn;
		_data_to_submit.ll_3p_ln = _ll_hit_data.ll_3p_ln;
		_data_to_submit.ll_3p_co = _ll_hit_data.ll_3p_co;
		_data_to_submit.ll_3p_ls = _ll_hit_data.ll_3p_ls;
		_data_to_submit.ll_3p_tag = _ll_hit_data.ll_3p_tag;
		_data_to_submit.lp_id = _ll_hit_data.lp_id;
		_data_to_submit.lpd_id = _ll_hit_data.lpd_id;
		_data_to_submit.form_id = _ll_hit_data.form_id;
		_data_to_submit.existing_form_id = _ll_hit_data.existing_form_id;
		_data_to_submit.ll_trk_no_ck = _ll_hit_data.ll_trk_no_ck;
		_data_to_submit.llemtrksrc = _ll_hit_data.llemtrksrc;
		_data_to_submit.llsemdrftid = _ll_hit_data.llsemdrftid;
		_data_to_submit.llprspctemencd = _ll_hit_data.llprspctemencd;
		
		return _data_to_submit;
	},
	get_ll_field_identifier: function(_form_element){
		var _we_id_lowered = (_form_element.id) ? _form_element.id.toLowerCase() : '';
		var _we_name_lowered = (_form_element.name) ? _form_element.name.toLowerCase() : '';
		
		if(typeof _we_name_lowered != 'undefined' && _we_name_lowered != ''){
			if (_ll_track_form_submission.field_name_identifier_for_email.indexOf(_we_name_lowered) > -1) {
				return _ll_track_form_submission.field_email;
			}
			if (_ll_track_form_submission.field_name_identifier_for_fullname.indexOf(_we_name_lowered) > -1) {
				return _ll_track_form_submission.field_fullname;
			}
			if (_ll_track_form_submission.field_name_identifier_for_firstname.indexOf(_we_name_lowered) > -1) {
				return _ll_track_form_submission.field_firstname;
			}
			if (_ll_track_form_submission.field_name_identifier_for_lastname.indexOf(_we_name_lowered) > -1) {
				return _ll_track_form_submission.field_lastname;
			}
			if (_ll_track_form_submission.field_name_identifier_for_company.indexOf(_we_name_lowered) > -1) {
				return _ll_track_form_submission.field_company;
			}
		}
		if(typeof _we_id_lowered != 'undefined' && _we_id_lowered != ''){
			if (_ll_track_form_submission.field_id_identifier_for_email.indexOf(_we_id_lowered) > -1) {
				return _ll_track_form_submission.field_email;
			}
			if (_ll_track_form_submission.field_id_identifier_for_fullname.indexOf(_we_id_lowered) > -1) {
				return _ll_track_form_submission.field_fullname;
			}
			if (_ll_track_form_submission.field_id_identifier_for_firstname.indexOf(_we_id_lowered) > -1) {
				return _ll_track_form_submission.field_firstname;
			}
			if (_ll_track_form_submission.field_id_identifier_for_lastname.indexOf(_we_id_lowered) > -1) {
				return _ll_track_form_submission.field_lastname;
			}
			if (_ll_track_form_submission.field_id_identifier_for_company.indexOf(_we_id_lowered) > -1) {
				return _ll_track_form_submission.field_company;
			}
		}
		/**
		 * 1- Check by the element name.
		 */
		if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_email, _we_name_lowered)){
			return _ll_track_form_submission.field_email;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_fullname, _we_name_lowered)){
			return _ll_track_form_submission.field_fullname;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_firstname, _we_name_lowered)){
			return _ll_track_form_submission.field_firstname;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_lastname, _we_name_lowered)){
			return _ll_track_form_submission.field_lastname;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_company, _we_name_lowered)){
			return _ll_track_form_submission.field_company;
		}
		/**
		 * 2- Check by the element id.
		 */
		else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_email, _we_id_lowered)){
			return _ll_track_form_submission.field_email;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_fullname, _we_id_lowered)){
			return _ll_track_form_submission.field_fullname;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_firstname, _we_id_lowered)){
			return _ll_track_form_submission.field_firstname;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_lastname, _we_id_lowered)){
			return _ll_track_form_submission.field_lastname;
		}else if(_ll_track_form_submission.is_field_identified(_ll_track_form_submission.field_company, _we_id_lowered)){
			return _ll_track_form_submission.field_company;
		}
		return '';
	},
	/**
	 * This method is called after the tracked form is submitted to LL.
	 * This method is called only if the original form is submitted using Ajax, or without page full postback or if the submit to LL takes less than the sleep period.
	 */
	callback_after_form_submitted: function(_form, _action, _form_index) {
		if(_action == 'view'){
			_ll_track_form_submission.viewed_forms[_form_index] = true;
		} else if (_action == 'submission'){
			_ll_track_form_submission.submitted_forms[_form_index] = true;
		}
		
		var imageWidth = img.width;
		if (imageWidth == 3) {
			blocked = false;
			if(!ip_guid_are_loaded){
				ip_guid_are_loaded = true;
				//pinging_time_period = 5;
				pinging_time_period = 60;
				InitializeTimer();
			}
		} if (imageWidth == 4) {
			blocked = false;
			if(!ip_guid_are_loaded){
				ip_guid_are_loaded = true;
			}
		}
	},
	/**
	 * 
	 */
	is_field_identified: function(_type, _field_identifier){
		try{
			switch(_type){
				case _ll_track_form_submission.field_email:
					if(_field_identifier == 'email' || _field_identifier == 'mail' || _field_identifier == 'mailaddress' || _field_identifier == 'emailaddress' || _field_identifier == 'mail_address' ||//
							/*	*/ _field_identifier == 'email_address' || _field_identifier == 'lead_email' || _field_identifier == 'leademail' || _field_identifier == 'contact_email' || _field_identifier == 'useremail' ||//
							/*	*/ _field_identifier == 'contactemail' || _field_identifier == 'lead_mail' || _field_identifier == 'leadmail' || _field_identifier == 'contact_mail' ||//
							/*	*/ _field_identifier == 'contactmail' || _field_identifier == 'your-email' || _field_identifier == 'contacts_email' || _field_identifier == 'contact.email' || _field_identifier == 'fields_email')
						return true;
					break;
				case _ll_track_form_submission.field_fullname:
					if(_field_identifier == 'name' || _field_identifier == 'fullname' || _field_identifier == 'full_name' || _field_identifier == 'full-name' ||//
							/*	*/_field_identifier == 'leadname' || _field_identifier == 'lead_name' ||//
							/*	*/ _field_identifier == 'contactname' || _field_identifier == 'contact_name' || _field_identifier == 'your-name' || _field_identifier == 'contacts_name')
						return true;
					break;
				case _ll_track_form_submission.field_firstname:
					if(_field_identifier == 'firstname' || _field_identifier == 'first_name' || _field_identifier == 'first-name' || _field_identifier == 'fname' ||//
							/*	*/_field_identifier == 'f_name' || _field_identifier == 'leadfname' || _field_identifier == 'lead_fname' || _field_identifier == 'userfirstname' ||//
							/*	*/ _field_identifier == 'contactfname' || _field_identifier == 'contact_fname' || _field_identifier == 'contacts_firstname' || _field_identifier == 'contact.firstname' || _field_identifier == 'fields_fname')
						return true;
					break;
				case _ll_track_form_submission.field_lastname:
					if(_field_identifier == 'lastname' || _field_identifier == 'last_name' || _field_identifier == 'last-name' || _field_identifier == 'lname' ||//
							/*	*/_field_identifier == 'l_name' || _field_identifier == 'leadlname' || _field_identifier == 'lead_lname' || _field_identifier == 'userlastname' ||//
							/*	*/ _field_identifier == 'contactlname' || _field_identifier == 'contact_lname' || _field_identifier == 'contacts_lastname' || _field_identifier == 'contact.lastname' || _field_identifier == 'contact.familyname' || _field_identifier == 'fields_lname')
						return true;
					break;
				case _ll_track_form_submission.field_company:
					if(_field_identifier == 'company' || _field_identifier == 'companyname' || _field_identifier == 'company_name' || _field_identifier == 'organization' ||//
							/*	*/_field_identifier == 'organizationname' || _field_identifier == 'organization_name' || _field_identifier == 'your-company' || _field_identifier == 'contacts_company' || _field_identifier == 'fields_business')
						return true;
					break;
			}
		}catch(err){ }
		return false;
	},
	is_jquery_loaded: function (){
		if (typeof jQuery != 'undefined' && typeof jQuery.getJSON != 'undefined') {
			if (typeof jQuery(window).resize != 'undefined' && typeof jQuery(window).scroll != 'undefined' && typeof jQuery(window).fadeIn != 'undefined') {
				return true;
			}
		}
		return false;
	},
	load_prospect_info: function(_callback, _obj){
		try{
			if(ll_is_empty(ip_guid_are_loaded)){
				if (this.ll_prospect_info_load_trials <= 20) {
					this.ll_prospect_info_load_trials++;
					window.setTimeout(function(){
						_ll_track_form_submission.load_prospect_info(_callback, _obj);
					}, 100);
					return false;
				}
			}
			if(!_ll_track_form_submission.is_loaded_jquery_lib){
				if(!_ll_track_form_submission.is_loading_jquery_lib){
					_ll_track_form_submission.is_loading_jquery_lib = true;
					if (_ll_track_form_submission.is_jquery_loaded()) {
						_ll_track_form_submission.ll_jQuery = jQuery;
						
						_ll_track_form_submission.is_loading_jquery_lib = false;
						_ll_track_form_submission.is_loaded_jquery_lib = true;
						_ll_track_form_submission.done_loading_jQuery(_callback, _obj);
					}else{
						_ll_track_form_submission.load_script(jQuery_LIBRARY_INCLUDE_URL, function(){
							//https://api.jquery.com/jquery.noconflict/
							_ll_track_form_submission.ll_jQuery = jQuery.noConflict( true );
							
							_ll_track_form_submission.is_loading_jquery_lib = false;
							_ll_track_form_submission.is_loaded_jquery_lib = true;
							_ll_track_form_submission.done_loading_jQuery(_callback, _obj);
						});
					}
				} else {
					window.setTimeout(function(){
						_ll_track_form_submission.load_prospect_info(_callback, _obj);
					}, 100);
				}
			} else {
				_ll_track_form_submission.done_loading_jQuery(_callback, _obj);
			}
		}catch(err){ }
	},
	done_loading_jQuery: function(_callback, _obj){
		if(!_ll_track_form_submission.is_loaded_prospect_info){
			if(!_ll_track_form_submission.is_loading_prospect_info){
				_ll_track_form_submission.is_loading_prospect_info = true;

				if(typeof ll_trk_no_ck != "undefined"){
					_ll_track_form_submission.ll_trk_no_ck = (ll_trk_no_ck == true || ll_trk_no_ck == 1) ? 1 : 0;
				}
				
				var load_bi_data = (typeof ll_prefill_form_with_ti_data != 'undefined' && ll_prefill_form_with_ti_data) ? '1' : '0';
				_ll_track_form_submission.ll_jQuery.getJSON( GET_PROSPECT_DATA_URL, {
					llcustid: llcustid,
					load_bi_data: load_bi_data,
					ll_trk_no_ck: _ll_track_form_submission.ll_trk_no_ck
				}).done(function( _response_data ) {
					_ll_track_form_submission.is_loaded_prospect_info = true;
					if(typeof _response_data != 'undefined' && _response_data && typeof _response_data.success != 'undefined' && _response_data.success == 1 && typeof _response_data.lead_info != 'undefined'){
						_ll_track_form_submission.prospect_info = _response_data.lead_info
					}
					if(typeof _callback != 'undefined'){
						_callback.call(this, _obj);
					}
				})
			} else {
				window.setTimeout(function(){
					_ll_track_form_submission.done_loading_jQuery(_callback, _obj);
				}, 100);
			}
		} else {
			if(typeof _callback != 'undefined'){
				_callback.call(this, _obj);
			}
		}
	},
	load_prospect_info_to_form: function(_form){
		try{
			if(_ll_track_form_submission.prospect_info){
				if(typeof _ll_track_form_submission.prospect_info.ll_unique_visitor_id != 'undefined' && _ll_track_form_submission.prospect_info.ll_unique_visitor_id > 0){
					var _is_found_lluvid_field = false;
					var _form_elements_length = _form.elements.length;
					if(_form_elements_length > 0){
						for(var _form_element_index = 0; _form_element_index < _form_elements_length; _form_element_index++){
							var _form_element = _form.elements[_form_element_index];
							
							var _we_name_lowered = (_form_element.name) ? _form_element.name.toLowerCase() : '';
							
							if(_we_name_lowered == 'll_unique_visitor_id'){
								if(typeof ll_append_identifier_to_form != 'undefined' && ll_append_identifier_to_form){
									_form_element.value = _ll_track_form_submission.prospect_info.ll_unique_visitor_id;
									_is_found_lluvid_field = true;
								}
							} else if (ll_prefill_automatic_tracked_form_fields) {
								if(typeof _form_element.value == 'undefined' || _form_element.value == ''){
									var _ll_field_identifier = _ll_track_form_submission.get_ll_field_identifier(_form_element);
									switch(_ll_field_identifier){
										case _ll_track_form_submission.field_email:
											if((typeof _ll_track_form_submission.prospect_info.Email != 'undefined' && _ll_track_form_submission.prospect_info.Email != '')){
												_form_element.value = _ll_track_form_submission.prospect_info.Email;
											}
											break;
										case _ll_track_form_submission.field_fullname:
											if((typeof _ll_track_form_submission.prospect_info.FullName != 'undefined' && _ll_track_form_submission.prospect_info.FullName != '')){
												_form_element.value = _ll_track_form_submission.prospect_info.FullName;
											}
											break;
										case _ll_track_form_submission.field_firstname:
											if((typeof _ll_track_form_submission.prospect_info.FirstName != 'undefined' && _ll_track_form_submission.prospect_info.FirstName != '')){
												_form_element.value = _ll_track_form_submission.prospect_info.FirstName;
											}
											break;
										case _ll_track_form_submission.field_lastname:
											if((typeof _ll_track_form_submission.prospect_info.LastName != 'undefined' && _ll_track_form_submission.prospect_info.LastName != '')){
												_form_element.value = _ll_track_form_submission.prospect_info.LastName;
											}
											break;
										case _ll_track_form_submission.field_company:
											if((typeof _ll_track_form_submission.prospect_info.Company != 'undefined' && _ll_track_form_submission.prospect_info.Company != '')){
												_form_element.value = _ll_track_form_submission.prospect_info.Company;
											}
											break;
									}
								}
							}
						}
					}
					//We need to append the ll_unique_visitor_id to the form, so if the form is submitted to the customer backend first, we will get the lead ID at our backend when submitted to our backend so we can identify him
					if(typeof ll_append_identifier_to_form != 'undefined' && ll_append_identifier_to_form){
						if(!_is_found_lluvid_field){
							var input = document.createElement("input");
							input.setAttribute("type", "hidden");
							input.setAttribute("name", "ll_unique_visitor_id");
							input.setAttribute("value", _ll_track_form_submission.prospect_info.ll_unique_visitor_id);
							_form.appendChild(input);
						}
					}
				}
			}
		}catch(err){ }
	},
	/**
	 * Sleep function, which hangs the cpu for period of milliseconds
	 * @param int milliSeconds number of milli seconds to sleep, 1000ms = 1s
	 */
	sleep: function(milliSeconds){
		try{
			var startTime = new Date().getTime(); // get the current time
			while (new Date().getTime() < startTime + milliSeconds){} // hog cpu
		}catch(err){ }
	},
	load_script: function(url, callback) {
		try{
			if(typeof _ll_track_form_submission.loaded_js_files[url] == 'undefined'){
				// Adding the script tag to the head as suggested before
				var head = document.getElementsByTagName('head')[0];
				var script = document.createElement('script');
				script.type = 'text/javascript';
				script.src = url;
			
				// Then bind the event to the callback function.
				// There are several events for cross browser compatibility.
			  	if(typeof callback != 'undefined'){
					script.onreadystatechange = callback;
				}
				script.onload = function(){
			  		_ll_track_form_submission.loaded_js_files[url] = true;
			  		if(typeof callback != 'undefined'){
						callback.call();
					}
				};
			
				// Fire the loading
				head.appendChild(script);
			} else {
		  		if(typeof callback != 'undefined'){
					callback.call();
				}
			}
		}catch(err){ }
	}
}
if(typeof ll_video_tracker == 'undefined')
var ll_video_tracker = {
	init: function(){
		try{
			if(typeof document.readyState == 'undefined' || document.readyState != 'complete'){
				window.setTimeout(function(){ ll_video_tracker.init(); }, 500);
				return;
			}
			if(typeof window.wistiaEmbeds != 'undefined'){
				window.wistiaEmbeds.onFind(function(_wistiaEmbed) {
					ll_video_tracker.process_bind_video_events(_wistiaEmbed)
				});
			}
		}catch(err){ }
	},
	process_bind_video_events: function(_wistiaEmbed){
		if(typeof _wistiaEmbed != 'undefined' && typeof _wistiaEmbed.ll_events_bind == 'undefined' && !_wistiaEmbed.ll_events_bind){
			_wistiaEmbed.ll_events_bind = true;
			_wistiaEmbed.bind('play', function() {
				if(typeof this.video_play_triggered == 'undefined' && !this.video_play_triggered){
					this.video_play_triggered = true;
					ll_video_tracker.process_track_video_activity(_wistiaEmbed, 'video_play');
				}
			});
			_wistiaEmbed.bind('secondchange', function(second) {
				if(typeof this.video_play_more_than_75_triggered == 'undefined' && !this.video_play_more_than_75_triggered){
					var duration = this.duration();
					if(duration > 0){
						if (((second / duration) * 100) >= 75){
							this.video_play_more_than_75_triggered = true;
							ll_video_tracker.process_track_video_activity(_wistiaEmbed, 'video_play_75');
						}
					}
				}
			});
			_wistiaEmbed.bind('conversion', function(type, value) {
				if(typeof value != 'undefined' && value != ''){
					var _additonal_parameters = {};
					_additonal_parameters.turnstile_type = type;
					_additonal_parameters.turnstile_email = value;
					ll_video_tracker.process_track_video_activity(_wistiaEmbed, 'video_conversion', _additonal_parameters);
				}
			});
			
			_ll_track_form_submission.load_prospect_info(function(_wistiaEmbed){
				if(_ll_track_form_submission.prospect_info){
					if(typeof _ll_track_form_submission.prospect_info.ll_unique_visitor_id != 'undefined' && _ll_track_form_submission.prospect_info.ll_unique_visitor_id > 0){
						if((typeof _ll_track_form_submission.prospect_info.Email != 'undefined' && _ll_track_form_submission.prospect_info.Email != '')){
							_wistiaEmbed.email(_ll_track_form_submission.prospect_info.Email);
						}
					}
				}
			}, _wistiaEmbed);
		}
	},
	process_track_video_activity: function(_wistiaEmbed, activity_type, additonal_parameters){
		var _data_to_submit = {};
		_data_to_submit.action = 'video_track';
		_data_to_submit.activity_type = activity_type;
		_data_to_submit.hashed_id = _wistiaEmbed.hashedId();
		_data_to_submit.visitor_key = _wistiaEmbed.visitorKey()
		_data_to_submit.event_key = _wistiaEmbed.eventKey()

		_data_to_submit = _ll_track_form_submission.append_tracking_data(_data_to_submit);
		
		if(typeof additonal_parameters != 'undefined' && additonal_parameters){
			for(var _key in additonal_parameters){
				_data_to_submit[_key] = additonal_parameters[_key];
			}
		}
		_ll_track_form_submission.process_call(AUTOMATIC_WEB_FORM_TRACKING_URL, _data_to_submit, function(){ });
	}
}
/**
 * *************************************************************************
 */
function ll_center_messages(message_box){
	document_width = document.body.clientWidth;
	message_box_width = message_box.width();
	message_box.css("left",(document_width/2-message_box_width/2)+"px");
}
function ll_show_success_message(__msg){
	//jQuery('#notifyMsg').html('<div class="message"><p>' + __msg + '</p><div>');
	if (__msg != ''){
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error').hide();
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning').hide();
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success').show();
        _ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success > p').html(__msg);
        _ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success').fadeIn('slow').delay(8000).fadeOut('slow');
        ll_center_messages(_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success'));
    }
}

function ll_show_error_message(__msg){
	//jQuery('#notifyMsg').html('<div class="error"><p>' + __msg + '</p><div>');
	if (__msg != ''){
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success').hide();
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning').hide();
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error').show();
        _ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error > p').html(__msg);
        _ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error').fadeIn('slow').delay(8000).fadeOut('slow');
        ll_center_messages(_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error'));
    }
}

function ll_show_warning_message(__msg){
	//jQuery('#notifyMsg').html('<div class="warning"><p>' + __msg + '</p><div>');
	if (__msg != ''){
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success').hide();
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error').hide();
		_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning').show();
        _ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning > p').html(__msg);
        _ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning').fadeIn('slow').delay(8000).fadeOut('slow');
        ll_center_messages(_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning'));
    }
}

function ll_remove_success_message(){
	//jQuery('#notifyMsg').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success > p').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success').hide();
}

function ll_remove_error_message(){
	//jQuery('#notifyMsg').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error > p').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error').hide();
}

function ll_remove_warning_message(){
	//jQuery('#notifyMsg').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning > p').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning').hide();
}

function ll_remove_all_messages(){
	/*jQuery('#notifyMsg').html('');
	jQuery('#notifyMsg').html('');*/
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success > p').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-success').hide();
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error > p').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-error').hide();
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning > p').html('');
	_ll_track_form_submission.ll_jQuery('.container-ll-dialog .ll-message-warning').hide();
}
/**
 * ******************************************************************************
 */
/* List of search query parameters for different engines */
if(typeof SEARCH_ENGINES == 'undefined')
var SEARCH_ENGINES = {
	a9 :"q",
	altavista :"q",
	aol :"query",
	ask :"q",
	dmoz :"search",
	google :"q",
	bing :"q",
	kanoodle :"query",
	msn :"q",
	teoma :"q",
	yahoo :"p"
};

/*
 * SM - QueryString handler
 */
if(typeof QueryString == 'undefined')
var QueryString = {
	init : function(qs) { // optionally pass a querystring to parse
		this.params = {};

		if (qs == null)
			qs = location.search.substring(1, location.search.length);
		if (qs.length == 0)
			return;

		// Turn <plus> back to <space>
		// See: http://www.w3.org/TR/REC-html40/interact/forms.html#h-17.13.4.1
		qs = qs.replace(/\+/g, ' ');
		var args = qs.split('&'); // parse out name/value pairs separated via
		// &

		// split out each name=value pair
		for ( var i = 0; i < args.length; i++) {
			var pair = args[i].split('=');
			var name = decodeURIComponent(pair[0]);

			var value;
			
			if (pair.length < 2)
				value = '';
			
			else if (pair.length == 2) {
				value = decodeURIComponent(pair[1]);
			} else {
				value = decodeURIComponent(pair[1]);
				for (j = 2; j < pair.length; j++)
					value += "=" + pair[j];
				
			}
			// value = (pair.length == 2)
			// ? decodeURIComponent(pair[1])
			// : name;

			this.params[name] = value;
		}
	},
	get : function(key, default_) {
		if (typeof this.params[key] != 'undefined') {
			return this.params[key];
		} else if (typeof this.params['amp;' + key] != 'undefined') {
			return this.params['amp;' + key];
		} else {
			return default_;
		}
		var value = this.params[key];
		return (value != null) ? value : default_;
	},
	contains : function(key) {
		var value = this.params[key];
		return (value != null);
	}
}


function ll_clean_query_string_parameter_from_url(url, param_key, param_val){
	url = url.replace('&' + param_key + '=' + param_val, '');
	url = url.replace(param_key + '=' + param_val, '');
	url = url.replace('&' + param_key + '=' + encodeURIComponent(param_val), '');
	url = url.replace(param_key + '=' + encodeURIComponent(param_val), '');
	return url;
}

function removeURLParameter(url, parameter) {
	try{
		//prefer to use l.search if you have a location/link object
		var urlparts= url.split('?');   
		if ( urlparts.length >= 2 ) {
	
			var prefix = encodeURIComponent(parameter) + '=';
			var pars = urlparts[1].split(/[&;]/g);
	
			//reverse iteration as may be destructive
			for (var i= pars.length; i-- > 0;) {
				//idiom for string.startsWith
				if (pars[i].lastIndexOf(prefix, 0) !== -1) {  
					pars.splice(i, 1);
				}
			}
			for (var i= pars.length; i-- > 0;) {
				if (pars[i] == 'amp') {  
					pars.splice(i, 1);
				}
			}
			if (pars.length > 0) {
				url= urlparts[0]+'?'+pars.join('&');
			} else {
				url= urlparts[0];
			}
			if (url.endsWith('?')) {
				url = url.substring(0, url.length - 1);
			}
			return url;
		} else {
			return url;
		}
	}catch(err){
	}
	return url;
}

function ll_is_referrer_the_same_domain(ll_referrer, ll_domain){
	if(ll_referrer != '' && ll_domain != ''){
		if(ll_referrer.indexOf('://') < 0){
			ll_referrer = 'http://' + ll_referrer;
		}
		var ll_referrer_domain_match = ll_referrer.match(/:\/\/(.[^/]+)/);
		if(ll_referrer_domain_match){
			var ll_referrer_domain = ll_referrer_domain_match[1];
			if(ll_referrer_domain.indexOf(ll_domain) >= 0){
				return true;
			}
		}
	}
	return false;
}

function getBrowserType() {
	var agt = (navigator.userAgent) ? navigator.userAgent.toLowerCase() : '';
	if (agt.indexOf("msie") != -1 || !!agt.match(/trident.*rv[ :]*11\./))
		return 'IE';
	if (agt.indexOf("chrome") != -1)
		return 'Chrome';
	if (agt.indexOf("opera") != -1)
		return 'Opera';
	if (agt.indexOf("safari") != -1)
		return 'Safari';
	if (agt.indexOf("firefox") != -1)
		return 'Firefox';
	if (agt.indexOf("mozilla") != -1)
		return 'Mozilla';
	if (agt.indexOf('\/') != -1) {
		if (agt.substr(0, agt.indexOf('\/')) != 'mozilla') {
			return navigator.userAgent.substr(0, agt.indexOf('\/'));
		} else
			return 'Netscape';
	} else if (agt.indexOf(' ') != -1)
		return navigator.userAgent.substr(0, agt.indexOf(' '));
	else
		return navigator.appName;
}
/* This function extracts the domain name from a url */
function getDomain() {
	/*
	if(typeof document.domain != 'undefined')
		if(document.domain != null && document.domain != '')
			return document.domain;
	*/
	var url = document.location.href;
	/* Remove the http bit */
	if (url.indexOf("http://") > -1)
		url = url.substring(7);
	else if (url.indexOf("https://") > -1)
		url = url.substring(8);

	/* Remove the www bit */
	if (url.indexOf("www.") == 0)
		url = url.substring(4);
	/* Remove the document path */
	if (url.indexOf("/") > -1)
		url = url.substring(0, url.indexOf("/"));

	return url;
}
/* This function extracts the search term from a referal string */
function searchTerm(referrer, searchEngines) {
	/* Determine the search engine */
	var engine = searchEngine(referrer, searchEngines);

	/* If no engine - no term */
	if (engine == "") {
		return "";
	}

	var search_parameter = searchEngines[engine];
	var query_string_parameter_length = 1 + search_parameter.length + 1;
	/* Extrach the parameter */
	var paramIndex = referrer.indexOf("&" + search_parameter + "=");
	if (paramIndex == -1) {
		paramIndex = referrer.indexOf("?" + search_parameter + "=");
	}
	if (paramIndex == -1 && search_parameter != 'q') {
		var search_parameter = 'q';
		var query_string_parameter_length = 1 + search_parameter.length + 1;
		/* Extrach the parameter */
		var paramIndex = referrer.indexOf("&" + search_parameter + "=");
		if (paramIndex == -1) {
			paramIndex = referrer.indexOf("?" + search_parameter + "=");
		}
	}

	/* If no param - no term */
	if (paramIndex == -1 || (paramIndex + query_string_parameter_length) >= referrer.length) {
		search_parameter = "prev";
		query_string_parameter_length = 1 + search_parameter.length + 1;
		/* Extrach the parameter */
		var paramIndex = referrer.indexOf("&" + search_parameter + "=");
		if (paramIndex == -1) {
			paramIndex = referrer.indexOf("?" + search_parameter + "=");
		}
		
		if (paramIndex == -1 || (paramIndex + query_string_parameter_length) >= referrer.length) {
			return "";
		}else{
			var term = referrer.substring(paramIndex + query_string_parameter_length);
			term = decodeURIComponent(term);
			
			var search_parameter = searchEngines[engine];
			query_string_parameter_length = 1 + search_parameter.length + 1;
			var paramIndex = term.indexOf("&" + search_parameter + "=");
			if (paramIndex == -1) {
				paramIndex = term.indexOf("?" + search_parameter + "=");
			}
			if (paramIndex == -1 || (paramIndex + query_string_parameter_length) >= term.length) {
				return "";
			}else{
				var term = term.substring(paramIndex + query_string_parameter_length);
			}
		}
	}else{
		/* Get the term */
		var term = referrer.substring(paramIndex + query_string_parameter_length);
	}
	var nextParamPos = term.indexOf("&");

	if (nextParamPos > -1) {
		term = term.substring(0, nextParamPos);
	}

	return decodeURIComponent(term);
}


/*
 * This function encodes the input object into a query string and sends it to
 * the input location
 */
function sendData(data, location) {

	/* Encode the parameters */
	var queryString = "";
	for (prop in data) {
		if(typeof data[prop] == 'Object' || typeof data[prop] == 'Array' || typeof data[prop] == 'object' || typeof data[prop] == 'array'){
			for(subprop in data[prop]){
				queryString += "&" + encodeURIComponent(prop) + "[]=" + encodeURIComponent(data[prop][subprop]);
			}
		}else{
			queryString += "&" + encodeURIComponent(prop) + "=" + encodeURIComponent(data[prop]);
		}
	}
	queryString = queryString.substring(1);
	/* SM - Added to prevent loading cached files */
	queryString = queryString + "&rand=" + Math.random()
	/* Create the image */
	img = new Image();
	img.onload = checkIfBlocked;
	/* Send the request */
	if (location.indexOf ('?') != -1) {
		img.src = location + "&" + queryString;
	} else {
		img.src = location + "?" + queryString;
	}
	/* img.onload = checkifloaded ; */
	InitializeTimer();
}

/* GUID Generation */
function S4() {
	return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1)
			.toUpperCase();
}
function guid() {
	return (S4() + S4() + "-" + S4() + "-" + S4() + "-" + S4() + "-" + S4()
			+ S4() + S4());
}

function updatePingingTotalPeriod() {
	thisDate = new Date();
	diff = thisDate - startingDate;
	if (diff > ((60 * 60 * 1000) + 30))
		ping = false;
	else
		window.setTimeout("updatePingingTotalPeriod()", ll_delay_factor * 5);
}

function InitializeTimer() {
	/* Set the length of the timer, in seconds */
	secs = pinging_time_period;
	StopTheClock()
	StartTheTimer()
}

function StopTheClock() {
	if (timerRunning)
		clearTimeout(timerID)
	timerRunning = false
}

function StartTheTimer() {
	if (secs == 0) {
		StopTheClock();
		if (ip_guid_are_loaded) {
			/*
			 * Here's where you put something useful that's supposed to happen after
			 * the allotted time.
			 */
			_ll_hit_data.status = "Browsing";
			_ll_hit_data.ll_existing_webforms_ids = '';
			_ll_hit_data.brsr_t = browser_type;
			_ll_hit_data.brsr_v = browser_version;
			if (!blocked && ping > 0) {
				try {
					if (!ll_webforms_totalviews_updated) {
						var ll_existing_webforms_ids = {};
						var ll_webforms = document.getElementsByTagName('form');
						if (ll_webforms.length > 0) {
							var ll_existing_webforms_ids = {};
							for (var ll_webform_index = 0; ll_webform_index < ll_webforms.length; ll_webform_index++) {
								var ll_webform = ll_webforms[ll_webform_index];
								var ll_webform_action = ll_webform.action;
								var ll_re = new RegExp("ll_existing_form_id=([^&]*)", "gi");
								var ll_matches = ll_re.exec(ll_webform_action);
								if (typeof ll_matches != 'undefined' && ll_matches != null && typeof ll_matches [1] != 'undefined') {
									ll_existing_webforms_ids[ll_webform_index] = ll_matches [1];
								} else {
									if (typeof ll_webform.attributes != 'undefined' && typeof ll_webform.attributes['ll_existing_form_id'] != 'undefined') {
										ll_existing_webforms_ids[ll_webform_index] = ll_webform.attributes['ll_existing_form_id'].nodeValue;
									}
								}
							}
							_ll_hit_data.ll_existing_webforms_ids = ll_existing_webforms_ids;
							ll_webforms_totalviews_updated = true;
						}
					}
				} catch (err) {
				}
				sendData(_ll_hit_data, ACTIVITY_URL);
			}
		} else {
			InitializeTimer();
		}
	} else {
		/*self.status = secs*/
		secs = secs - 1
		timerRunning = true
		timerID = self.setTimeout("StartTheTimer()", ll_delay_factor)
	}
}
/* SM - End of timer code */

/* SM - function to update the browsing status */
function updateHit() {
	if (typeof document.activeElement == 'undefined' || typeof document.activeElement == 'unknown' || document.activeElement == null) {
		/* SM - body did not load yet */
		var temp = setTimeout("updateHit()", 500);
		updatedHit = 0;
		return;
	} else {
		if ((updatedHit == 0) || (typeof updatedHit == "undefined")) {
			updatedHit = 1;
			_ll_hit_data.status = "Hit";
			/* The page title the user is visiting */
			if (document.title == "") {
				_ll_hit_data.pageTitle = document.location.href;
			} else {
				_ll_hit_data.pageTitle = document.title;
			}
			if (!blocked){
				//First Call
				sendData(_ll_hit_data, COLLECTOR_URL);
			}
			InitializeTimer();
		}
	}
}

function updateStatus(status) {
	_ll_hit_data.status = status;
	if (!blocked)
		sendData(_ll_hit_data, COLLECTOR_URL);
}

/* This function extracts the search engine from a referal string */
function searchEngine(referrer, searchEngines) {
	/* Determine the search engine */
	var engine = "";
	for (sEngine in searchEngines) {
		if (referrer.indexOf(sEngine) > -1) {
			engine = sEngine;
			break;
		}
	}

	return engine;
}

function checkIfBlocked() {
	var imageWidth = img.width;
	//console.log('imageWidth: ' + imageWidth)
	if (imageWidth == 1){
		blocked = true;
	}else if (imageWidth == 2){
		grapIP();
	}else if (imageWidth == 3) {
		ip_guid_are_loaded = true;
		//pinging_time_period = 5;
		pinging_time_period = 60;
		InitializeTimer();
		ll_api.apply_after_tracking_actions (true);
	} if (imageWidth == 4) {
		ip_guid_are_loaded = true;
		//pinging_time_period = 15;
		pinging_time_period = 60;
		ll_api.apply_after_tracking_actions (false);
	}
}

function ResendRequest() {
	//Second Call
	var resend_data = _ll_hit_data;
	resend_data.is_ip_cookie_grap_done = 1;
	sendData(resend_data, COLLECTOR_URL);
	InitializeTimer();
}

function checkifloaded() {
	loaded = img.width;
	if (loaded) {
		_ll_hit_data.visitor = loaded;
		return true;
	} else {
		return false;
	}
}

/**
 * *************************************************************
 */
if(typeof ip_guid_are_loaded == 'undefined' || !ip_guid_are_loaded){
	ip_guid_are_loaded = false;
}
/* Collect the _ll_hit_data */
var _ll_hit_data = {}
/* The connector id */
QueryString.init();
_ll_hit_data.lead_nrtr = QueryString.get('lead_nrtr', '0');
_ll_hit_data.llsubId = QueryString.get('llsubId', '0');
_ll_hit_data.llatmn_cmpid = QueryString.get('llatmn_cmpid', '0');
_ll_hit_data.llstatId = QueryString.get('llstatId', '0');
_ll_hit_data.llstatType = QueryString.get('llstatType', 'none');

_ll_hit_data.outlookContactEmail = QueryString.get('em', '');
_ll_hit_data.outlookContactName = QueryString.get('cn', '');
_ll_hit_data.outlookEmailSubject = QueryString.get('sub', '');
_ll_hit_data.outlookEmailDate = QueryString.get('dt', '');

_ll_hit_data.ll_3p_email = QueryString.get('ll_3p_email', '');
_ll_hit_data.ll_3p_fn = QueryString.get('ll_3p_fn', '');
_ll_hit_data.ll_3p_ln = QueryString.get('ll_3p_ln', '');
_ll_hit_data.ll_3p_co = QueryString.get('ll_3p_co', '');
_ll_hit_data.ll_3p_ls = QueryString.get('ll_3p_ls', '');
_ll_hit_data.ll_3p_tag = QueryString.get('ll_3p_tag', '');
_ll_hit_data.llemtrksrc = QueryString.get('llemtrksrc', '');
_ll_hit_data.llsemdrftid = QueryString.get('llsemdrftid', '');
_ll_hit_data.llprspctemencd = QueryString.get('llprspctemencd', '');

//LL Abstract Campaign ID
try{
	if(typeof llacmpid != "undefined"){
		_ll_hit_data.llacmpid_tc = llacmpid;
	} else {
		_ll_hit_data.llacmpid_qs = QueryString.get('llacmpid', '');
	}
}catch(err){
}
//LL Landing Page ID
if(typeof landing_page_id != "undefined"){
	_ll_hit_data.lp_id = landing_page_id;
}
//LL Landing Page ID
if(typeof ll_trk_no_ck != "undefined"){
	_ll_hit_data.ll_trk_no_ck = (ll_trk_no_ck == true || ll_trk_no_ck == 1) ? 1 : 0
} else {
	_ll_hit_data.ll_trk_no_ck = 0;
}
//LL Landing Page Draft ID
if(typeof landing_page_draft_id != "undefined"){
	_ll_hit_data.lpd_id = landing_page_draft_id;
}
//LL Hosted Form ID
if(typeof form_id != "undefined"){
	_ll_hit_data.form_id = form_id;
}
if(typeof ignore_lp_page_view != "undefined"){
	_ll_hit_data.ignore_lpv = ignore_lp_page_view;
}

/* The page the user is visiting */
var tempPage = document.location.href;

// SM - have to remove the querystring parameter(s)
tempPage = removeURLParameter(tempPage, 'lead_nrtr');
tempPage = removeURLParameter(tempPage, 'llsubId');
tempPage = removeURLParameter(tempPage, 'llstatId');
tempPage = removeURLParameter(tempPage, 'llstatType');
tempPage = removeURLParameter(tempPage, 'llatmn_cmpid');
tempPage = removeURLParameter(tempPage, 'em');
tempPage = removeURLParameter(tempPage, 'cn');
tempPage = removeURLParameter(tempPage, 'sub');
tempPage = removeURLParameter(tempPage, 'dt');
tempPage = removeURLParameter(tempPage, 'll_3p_email');
tempPage = removeURLParameter(tempPage, 'll_3p_fn');
tempPage = removeURLParameter(tempPage, 'll_3p_ln');
tempPage = removeURLParameter(tempPage, 'll_3p_co');
tempPage = removeURLParameter(tempPage, 'll_3p_ls');
tempPage = removeURLParameter(tempPage, 'll_3p_tag');
tempPage = removeURLParameter(tempPage, 'llemtrksrc');
tempPage = removeURLParameter(tempPage, 'llsemdrftid');
tempPage = removeURLParameter(tempPage, 'llprspctemencd');
tempPage = tempPage.replace('&&', '&');
tempPage = tempPage.replace('?&', '?');

if(tempPage.indexOf('&', tempPage.length - 1) !== -1){
	tempPage = tempPage.substring(0, tempPage.length - 1);
}
if(tempPage.indexOf('?', tempPage.length - 1) !== -1){
	tempPage = tempPage.substring(0, tempPage.length - 1);
}

_ll_hit_data.page = tempPage;
_ll_hit_data.fullpage = document.location.href;

/* The domain name of the site */
_ll_hit_data.domain = getDomain();

/* The refering page */
_ll_hit_data.referrer = document.referrer;

/* The search engine terms/words used to find the page */
_ll_hit_data.searchTerm = searchTerm(_ll_hit_data.referrer, SEARCH_ENGINES);

/* The search engine */
_ll_hit_data.searchEngine = searchEngine(_ll_hit_data.referrer, SEARCH_ENGINES);

/* The customers id */
_ll_hit_data.llcustid = llcustid;

/* The unique id */
//_ll_hit_data.lluniqck = llCookies[lluniqck];

if(ll_is_referrer_the_same_domain(_ll_hit_data.referrer, _ll_hit_data.domain)){
	_ll_hit_data.referrer = ''
}

browser_type = getBrowserType();
browser_version = navigator.appVersion;

_ll_hit_data.brsr_t = browser_type;
_ll_hit_data.brsr_v = browser_version;

/**/

if(typeof ll_is_append_prospect_identifier_to_urls != 'undefined' && ll_is_append_prospect_identifier_to_urls){
	if(typeof ll_append_prospect_identifier_to_urls != 'undefined' && ll_is_append_prospect_identifier_to_urls) {
		var parameter = '';
		if (typeof ll_append_prospect_identifier_to_urls.parameter != 'undefined' && ll_append_prospect_identifier_to_urls.parameter && ll_append_prospect_identifier_to_urls.parameter != '') {
			parameter = ll_append_prospect_identifier_to_urls.parameter;
		}
		var pre_value = '';
		if (typeof ll_append_prospect_identifier_to_urls.pre_value != 'undefined' && ll_append_prospect_identifier_to_urls.pre_value && ll_append_prospect_identifier_to_urls.pre_value != '') {
			pre_value = ll_append_prospect_identifier_to_urls.pre_value;
		}
		ll_api.replace_page_urls(ll_append_prospect_identifier_to_urls, parameter, pre_value);
	}
}ll_tracking_code = true;
blocked = false;


/* COOKIES */
//var lluniqck = "lluniqck";
/*
var llCookies = {
	init : function() {
		var allCookies = document.cookie.split('; ');
		for ( var i = 0; i < allCookies.length; i++) {
			var cookiePair = allCookies[i].split('=');
			this[cookiePair[0]] = cookiePair[1];
		}
	},
	create : function(name, value, days) {
		if (days) {
			var date = new Date();
			date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
			var expires = "; expires=" + date.toGMTString();
		} else
			var expires = "";
		document.cookie = name + "=" + value + expires + "; path=/";
		this[name] = value;
	},
	exist : function(name) {
		if (typeof (this[name]) == 'undefined') {
			return false;
		} else {
			return true;
		}
	},
	erase : function(name) {
		this.create(name, '', -1);
		this[name] = undefined;
	}
};
llCookies.init();
*/
/*if (!llCookies.exist(lluniqck)) {
	llCookies.create(lluniqck, guid(), 3660);
}*/


/* SM - image to send _ll_hit_data */
var img;

var updatedHit;

/*
 * SM - Timer for sending browsing status SM - Timer code
 */
var secs
var timerID = null
var timerRunning = false
var ll_delay_factor = 1000

pinging_time_period = 60;
ping = true;
startingDate = new Date();

window.setTimeout("updatePingingTotalPeriod()", ll_delay_factor * 5);


ll_webforms_totalviews_updated = false;


/* Send "Hit" flag */
updateHit();
/**
 * Automatic webform tracking.
 * Adding an event listener to all the existing webforms within the page, and parse the submitted data, and if found any of the LL standard fields [Name, Email or Company] within the form:
 * Then send these fields to LL side to update the lead info with them and add a web form submission activity history record for this lead.
 * By default Automatic form tracking is turned on, to turn it off, the user has to set the ll_use_automatic_form_tracking flag into false within the tracking code.
 * Moved setting the ll_use_automatic_form_tracking to the init function after the page is loaded, so if the setting of this flag to false is done after adding the tracking code, it disables the tracking of auto webforms
 */
try{
	_ll_track_form_submission.init();
}catch(err){ }

/**
 * Automatic Wistia video tracking.
 * By default Automatic video tracking is turned on, to turn it off, the user has to set the ll_use_wistia_video_tracking flag into false within the tracking code.
 */
try{
	if(typeof ll_use_wistia_video_tracking == 'undefined' || ll_use_wistia_video_tracking != false){
		//ll_video_tracker.init();
		_ll_track_form_submission.load_script(Wistia_Shepherd_Lib_URL, function(){
			ll_video_tracker.init();
		});
	}
}catch(err){ }

if (!String.prototype.trim) {
   String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
}
//-->
