$(document).ready(function($) {
/** SCID Tracking **/
// Set the cookie if the parameter exists
// Parse the URL
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
// Give the URL parameters variable names
var scid_cookie = getParameterByName('scid');
var cookieDate = new Date();
cookieDate.setTime(cookieDate.getTime()+(240*60*60*1000)); // save for 10 days
// Set the cookies
if (scid_cookie != null && scid_cookie != '' ){
document.cookie = "scid="+scid_cookie+"; expires="+cookieDate.toGMTString()+";path=/";
}
// Get the SCID Value
function getCookie(name) {
var cookieArr = document.cookie.split(";");
for(var i = 0; i < cookieArr.length; i++) {
var cookiePair = cookieArr[i].split("=");
if(name == cookiePair[0].trim()) {
return decodeURIComponent(cookiePair[1]);
}
}
return null;
}
if (document.cookie.indexOf('scid') >= 0 ){
var scid_value = getCookie('scid');
// change booking url here
$('a[href*="marriott.com"]').each(function() {
var link_href = $(this).attr('href');
if (link_href.indexOf("?") >= 0) {
$(this).attr('href', link_href + '&scid=' + scid_value );
} else {
$(this).attr('href', link_href + '?scid=' + scid_value );
}
})
// change form id here
$('.book-form').each(function() {
$(this).prepend('');
})
}
/* END SCID */
});