///
String.prototype.bool = function () { return (/^true$/i).test(this); };
var intervalID = null;
var fieldNameInitHandlers = {
"customerguid" : function(name, control, type)
{
// eloqua field init
$(control).val(getEloquaGuid());
}
};
var fieldTypeInitHandlers = {
"hidden" : function(name, control, type) {
// hidden field init
},
"default" : function(name, control, type) {
// default field init
}
};
var initFormField = function(scope, name, control, type)
{
if (fieldTypeInitHandlers[type] != null)
{
// invoke type init handler
var f = fieldTypeInitHandlers[type];
f.call(scope, name, control, type);
} else if ( fieldTypeInitHandlers["default"] ) {
// invoke default type init handler
var f = fieldTypeInitHandlers["default"];
f.call(scope, name, control, type);
}
if (fieldNameInitHandlers[name] != null)
{
//invoke name init handler
var f = fieldNameInitHandlers[name];
f.call(scope, name, control, type);
}
};
function setQueryStringValues(name, control, type) {
var value = $.query.get(name);
if (value) {
switch(type)
{
case "checkbox":
if (value.bool() == true)
$(control).attr('checked', 'checked');
else
$(control).attr('checked', '');
break;
case "date":
value = unescape(value);
$(control).val(value);
break;
case "dropdown":
case "textbox":
case "yesno":
default:
$(control).val(value);
break;
}
}
}
function initializeSageFormSend() {
var fields = '';
var values = '';
var array = {};
var isComplete = 0;
$(".submit-button").attr('disabled', 'disabled');
// Checkbox Input Values
$('input[id^=___SageFormField]:not([id$=_checklist]):checkbox').each(function () {
var fieldId = $(this).attr('parent');
array[fieldId] = $(this).attr('checked');
});
// Checkbox List Input Values (includes only checked values)
$('input[id^=___SageFormField][id$=_checklist]:checkbox:checked').each(function () {
var fieldId = $(this).attr('parent');
var value = $(this).attr('value');
if (!array[fieldId]) { array[fieldId] = value; }
else { array[fieldId] += ';%;' + value }
});
// Radio Button Input Values (includes only checked values)
$('input[id^=___SageFormField]:radio:checked').each(function () {
var fieldId = $(this).attr('name');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
// Textbox Input Values (excludes other region textbox from CountryState fields)
$('input[id|=___SageFormField]:text:not([id$=___region])').each(function () {
var fieldId = $(this).attr('id').replace("___SageFormField-", '');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
// Textarea Input Values
$('textarea[id|=___SageFormField]').each(function () {
var fieldId = $(this).attr('id').replace("___SageFormField-", '');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
// Hidden Input Values (use [type=hidden] because :hidden will also include inputs with display:none;)
$('input[id|=___SageFormField][type=hidden]').each(function () {
var fieldId = $(this).attr('id').replace("___SageFormField-", '');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
// Select Input Values (dropdowns, listbox; excludes state/province dropdown from CountryState fields)
$('select[id|=___SageFormField]:not([id$=___state_province])').each(function () {
var fieldId = $(this).attr('id').replace("___SageFormField-", '');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
// Select Input Values for state/province (selects visible only b/c of the other region functionality)
$('select[id|=___SageFormField][id$=___state_province]:visible').each(function () {
var fieldId = $(this).attr('id').replace("___SageFormField-", '').replace("___state_province", '');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
// Textbox Input Values for state/province (selects visible only b/c of the US/CA state/province functionality)
$('input[id|=___SageFormField][id$=___region]:text:visible').each(function () {
var fieldId = $(this).attr('id').replace("___SageFormField-", '').replace("___region", '');
if (array[fieldId] == null) { array[fieldId] = escape($(this).val()); }
});
for (var key in array) {
fields += '&Fields=' + key;
values += '&Values=' + array[key];
}
var jsonData = "FormId=" + $("#___SageFormId").val();
jsonData += "&submitUrl=" + location.href;
jsonData += "&thankYouUrl=" + $("#___ThankYouPage").val();
jsonData += fields;
jsonData += values;
$("body").css('cursor', 'wait');
submitSageForm(jsonData);
}
function submitSageForm(jsonData) {
try {
$.ajax({ url: "/SageCMS/FormRendering/FormService.asmx/SubmitForm",
data: jsonData,
type: "POST",
success: SubmitSageFormSucceeded,
error: SubmitSageFormFailed
});
}
catch (e) {
try { console.log('SubmitSageForm $.ajax call failed: ' + e.message) } catch (e) { }
intervalID = setInterval(function () {
try { initializeSageFormSend(); clearInterval(intervalID); }
catch (e) { try { console.log('SubmitSageForm $.ajax call failed: ' + e.message); } catch (e) { /*Do nothing console logging isn't available*/ } }
}, 1500);
}
}
function SubmitSageFormSucceeded(data, textStatus, XMLHttpRequest) {
var text = navigator.userAgent.indexOf("MSIE", 0) > -1 ? data.text : data.childNodes[0].textContent;
var isInline = $("#___Inline").val().bool();
$('#___SageErrors').html('');
var result = $.parseJSON(text);
if (result.IsValid) {
var typ = $('#___ThankYouPage').val();
if (isInline || !typ) {
$("#___FormSubmitId").val(result.ThankYouFormId);
getThankYouData();
$("#___SageForm").hide();
}
else {
window.location.href = typ + '?fsid=' + result.ThankYouFormId;
}
}
else {
$('#___SageErrors').html($('').html(result.Errors));
$("body").css('cursor', 'default');
$(".submit-button").removeAttr('disabled');
}
}
function SubmitSageFormFailed(result) {
$("body").css('cursor', 'default');
try { console.log('SubmitSageForm call failed: ' + result.status + '' + result.statusText); } catch (e) { }
if (intervalID != null) {
try {
initializeSageFormSend();
}
catch (e) {
try { console.log('SubmitSageForm $.ajax call failed: ' + e.message) } catch (e) { }
intervalID = setInterval(function () {
try { initializeSageFormSend(); clearInterval(intervalID); }
catch (e) { try { console.log('SubmitSageForm $.ajax call failed: ' + e.message); } catch (e) { /*Do nothing console logging isn't available*/ } }
}, 1500);
}
}
}
function DoRenderForm(){
var jsonResult = {"IsSuccessful":false,"Form":null,"Errors":"\u003c!--\u003cspan\u003eThere was no endpoint listening at http://prod.wcf.sagecms.local/FormDelivery/FormDeliveryService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.\u003cbr/\u003e\r\nServer stack trace: \r\n at System.ServiceModel.Channels.HttpChannelUtilities.ProcessGetResponseWebException(WebException webException, HttpWebRequest request, HttpAbortReason abortReason)\r\n at System.ServiceModel.Channels.HttpChannelFactory`1.HttpRequestChannel.HttpChannelRequest.WaitForReply(TimeSpan timeout)\r\n at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Dispatcher.RequestChannelBinder.Request(Message message, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)\r\n at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)\r\n\r\nException rethrown at [0]: \r\n at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)\r\n at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData\u0026 msgData, Int32 type)\r\n at SageCMS.Extensions.FormGateway.FormRenderService.FormDeliveryService.IFormDeliveryService.GetForm(GetFormRequest request)\r\n at SageCMS.Extensions.FormGateway.FormRenderService.FormRender.OnLoad(EventArgs e)\u003c/span\u003e--\u003e\u003cspan\u003eAn error occured on the form.\u003c/span\u003e"}; //script will be replaced in the user control reading this file
if(jsonResult.IsSuccessful) {
$("#___SageForm").html(jsonResult.Form);
$("#___SageErrors").html('');
}
else {
$("#___SageForm").html('');
$("#___SageErrors").html(jsonResult.Errors);
}
}
function countryStateOnChange(selectCountry, regionTextbox, selectStateProvince, stateProvinceLabel) {
var selectedCountry = $(selectCountry).val().toUpperCase();
if (selectedCountry == "CA" || selectedCountry == "US") {
$(regionTextbox).hide();
$(selectStateProvince).children().remove();
if (selectedCountry == "CA") {
$(stateProvinceLabel).text('Province');
$(selectStateProvince).append($('').val("").html("Select Province"));
$.each(caProvinces, function(val, text) {
$(selectStateProvince).append($('').val(val).html(text));
});
}
else if (selectedCountry == "US") {
$(stateProvinceLabel).text('State');
$(selectStateProvince).append($('').val("").html("Select State"));
$.each(usStates, function(val, text) {
$(selectStateProvince).append($('').val(val).html(text));
});
}
$(selectStateProvince).fadeIn(500, null);
}
else {
$(selectStateProvince).hide();
$(stateProvinceLabel).text('Region');
$(regionTextbox).fadeIn(500, null);
}
}
function countryStateInitialValue(selectCountry, regionTextbox, selectStateProvince, stateProvinceLabel, stateProvinceInitialValue) {
if (stateProvinceInitialValue == "") {
return;
}
var selectedCountry = $(selectCountry).val().toUpperCase();
if (selectedCountry == "CA" || selectedCountry == "US") {
$(selectStateProvince).show();
$(selectStateProvince).children().remove();
if (selectedCountry == "CA") {
$(stateProvinceLabel).text('Province');
$(selectStateProvince).append($('').val("").html("Select Province"));
$.each(caProvinces, function(val, text) {
$(selectStateProvince).append($('').val(val).html(text));
});
}
else if (selectedCountry == "US") {
$(stateProvinceLabel).text('State');
$(selectStateProvince).append($('').val("").html("Select State"));
$.each(usStates, function(val, text) {
$(selectStateProvince).append($('').val(val).html(text));
});
}
$(selectStateProvince).fadeIn(500, null);
$(selectStateProvince).val(stateProvinceInitialValue).attr("selected", "selected");
}
else {
$(regionTextbox).show();
$(stateProvinceLabel).text('Region');
$(regionTextbox).fadeIn(500, null);
$(regionTextbox).val(stateProvinceInitialValue);
}
}
function keyCheck(e) {
var evnt = e || window.event;
var target = evnt.target.id ? "#" + evnt.target.id : evnt.target;
var keyID = e.keyCode;
switch(keyID){
case 8: //backspace
case 16: //shift
case 17: //ctrl
case 18: //alt
case 37: //arrow left
case 38: //arrow up
case 39: //arrow right
case 40: //arrow down
case 46: //delete
break;
default:
var textarea = $(target);
if(textarea[0].value.length > (textarea.attr('maxlength') - 1)) { e.preventDefault(); }
break;
}
}
function getEloquaGuid()
{
if (this.GetElqCustomerGUID)
{
return GetElqCustomerGUID();
}
else
{
var eloquaCookieKey = "ELOQUA";
var eloquaGuidKey = "GUID";
var eloqua = jQuery.cookie(eloquaCookieKey);
if (eloqua != null && eloqua != "")
{
var guid = getKey(eloqua, eloquaGuidKey);
if (guid)
{
return guid;
}
else
{
return "Eloqua Guid Not Found In Cookie";
}
}
return "Eloqua Cookie Not Found";
}
}
function getKey(str, findkey) {
kpairs = str.split("&");
for( var c=0; c < kpairs.length; c++)
{
var kp = kpairs[c].split("=", 1);
if (kp.length == 2 && kp[0] == findkey)
{
return kp[1];
}
}
return false;
}
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
// CAUTION: Needed to parenthesize options.path and options.domain
// in the following expressions, otherwise they evaluate to undefined
// in the packed version for some reason...
var path = options.path ? '; path=' + (options.path) : '';
var domain = options.domain ? '; domain=' + (options.domain) : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
};