﻿function nrCookieToHiddenFormField(){
	// Get Net Results Visitor ID cookie
	var nrvId = $.cookie("__nrvid")
	
	// If the cookie existed / contained a value, then add a hidden form element with the value
	if (nrvId != null){
	    // Find the form on the page containing the input with ID contactFormId 
	    //var form = $("input#contactFormId").parents("form")
	    var form = $("input[name$='contactFormId']").parent();
	    // Add a new hidden input contain the Net Results Visitor ID
		form.append('<input id="__nrvid" name="__nrvid" type="hidden" value="' + nrvId +'" />' );	
	}
}

// Bind the above function to the document ready event, so when the document has loaded the cookie is immediately converted to a form element
$(document).ready(function() {
    nrCookieToHiddenFormField();
});

