//--- Modal Includes ---//
$(document).ready(function () {
var folderName = window.location.hostname;
var cookieName = folderName + "_ABTesting";
var viewName;
var origin = window.location.origin;
var pathname = window.location.pathname;
var trackingPhoneNumber = getCookiePropertyValue(cookieName, "FailSafeNumber", window.origin); //getQuerystringPram("fs");
//var curentpage = document.location.href.match(/[^\/]+$/)[0];
//var lander = curentpage.substr(0, curentpage.indexOf("."));
//-- change failsafe number on page ---
if ((trackingPhoneNumber != null) && (trackingPhoneNumber != "")) {
$(".trkPhoneNumber").text(function (i, text) {
trackNumber = trackingPhoneNumber.replace(/(\d{3})(\d{3})(\d{4})/, "$1-$2-$3");
$('a[href^="tel:"]').each(function () {
var oldTel = $(this).attr("href"); // Get current url
//var newUrl = $(this).attr("href"); //oldUrl.replace("http://", "https://"); // Create new url
var newTel = trackNumber
$(this).attr("href", newTel); // Set herf value
});
return trackNumber;
});
}
//-- append "pg" + "lnder" values to querystring. --//
var urlandqstring = window.location.search.substring(1);
location.hash = urlandqstring;
if ((cookieName != "") && (cookieName != null)) {
viewName = getCookiePropertyValue(cookieName, "ViewName", window.origin);
location.hash = "pg=" + viewName + "&lander=" + getCookiePropertyValue(cookieName, "Lander", window.origin);
} else {
viewName = getQuerystringPram("vn");
}
//-- set all modals --;
$("#errorModalContainer").load("https://cdn.rmiatl.net/modals/ErrorModal.html");
$("#aboutusModalContainer").load("https://cdn.rmiatl.net/modals/" + folderName + "/AboutUsModal.html");
$("#privacypolicyModalContainer").load("https://cdn.rmiatl.net/modals/" + folderName + "/PrivacyPolicyModal.html");
$("#faqModalContainer").load("https://cdn.rmiatl.net/modals/" + folderName + "/FAQModal.html");
$("#medicalpolicyModalContainer").load("https://cdn.rmiatl.net/modals/" + folderName + "/MedicalPolicyModal.html");
//-- Scroll to anchor tag --//
$('a[href^="#"]').on('click', function (event) {
var target = $(this).attr('href');
var form = $(this).attr('form');
var selector = $(this).attr('selector');
console.log(target + "-target");
console.log(selector + "-selector");
if (selector != null) {
if (selector.length > 0) {
var modal = $(this).attr('modal');
var close = $(this).attr('close');
openBySelector(selector, modal, close);
};
};
if (target.length) {
event.preventDefault();
$('html, body').stop().animate({
scrollTop: 0 //target.offset().top
}, 1000);
}
});
//-- TRMX - bugs rollover --- TODO: move to local js file for terminix or globalize it. pest_node
//$(".pestType").mouseover(function () {
// var bugId = $(this).attr("id");
// var node = $("#" + bugId + "_node");
// //console.log(bugId);
// this.src = this.src.replace("_off", "_on");
// node[0].src = node[0].src.replace("_off", "_on");
// $(this).css("border", "2px solid #009046;");
// console.log(bugId + " - bug id");
// console.log(this.click + " - this.click");
//});
//$(".pestType").click(function () {
// var bugId = $(this).attr("id");
// if (bugId == "termite") {
// $("#PestTermite").val("termite");
// }
// $("#pestsContainer").hide()
// $("#frm_body").show()
//});
//$(".pestType").mouseout(function () {
// var bugId = $(this).attr("id");
// var node = $("#" + bugId + "_node");
// //console.log(bugId);
// this.src = this.src.replace("_on", "_off");
// node[0].src = node[0].src.replace("_on", "_off");
// console.log(bugId.src);
//});
});
//-- Draw functions --//
function draw(elementid, font, fillstyle, text, xaxis,yaxis) {
var c = document.getElementById(elementid);
console.log(c);
var ctx = c.getContext('2d');
console.log(ctx);
ctx.font = font;
ctx.fillStyle = fillstyle;
//ctx.fillText(text, xaxis, yaxis);
ctx.fillText(text, c.width / 2, c.height / 2);
}
//-- Process Cookies --//
function getCookie(name) {
var re = new RegExp(name + "=([^;]+)");
var value = re.exec(document.cookie);
return (value != null) ? unescape(value[1]) : null;
}
function getCookiePropertyValue(cookieName, PropertyName, domain) {
if (cookieName == null) {
cookieName = domain;
}
var cookieData = getCookie(cookieName);
var arrCookieProperties = cookieData.split('&');
//console.log("arrCookieProperties:" + arrCookieProperties);
for (i = 0; i < arrCookieProperties.length; ++i) {
//console.log("property:" + arrCookieProperties[i]);
var KeyValue = arrCookieProperties[i].split('=');
//console.log("Key: " + KeyValue[0] + "| Value:" + KeyValue[1]);
//console.log("PropertyName:" + PropertyName.toLowerCase());
if (PropertyName.toLowerCase() == KeyValue[0].toLowerCase()) {
//console.log("regular value:" + KeyValue[1]);
if (PropertyName.toLowerCase() == 'address') {
return KeyValue[1].replace(/\+/g, ' ');
} else {
return KeyValue[1];
}
break;
}
if ((PropertyName.toLowerCase() == "zip") && (KeyValue[0].toLowerCase() == "zipcode")) {
//console.log("value:" + KeyValue[1]);
return KeyValue[1];
break;
}
}
}
//-- Modals Functions --//
function openModal(selector) {
$(selector).modal('show');
}
function openFormModal(selector, buttonId) {
var form = selector + " input[name=ButtonId]";
$(form).attr("value", buttonId);
console.log($(form).val() + "-ButtonId name");
$(selector).modal('show');
}
function openBySelector(selector, modal, close) {
if (modal == true) {
$(selector).modal('show');
} else {
$(selector).show();
}
if (close != null) {
$(close).hide();
}
}
//-- Process Functions --//
function getQuerystringPram(sParam) {
var sPageURL = window.location.search.substring(1);
var sURLVariables = sPageURL.split('&');
var returnParam;
for (var i = 0; i < sURLVariables.length; i++) {
var sParameterName = sURLVariables[i].split('=');
if (sParameterName[0] == sParam) {
returnParam = sParameterName[1];
break;
}
}
return returnParam;
}
function populateFormfromCookie(cookieName, formId) {
//var formData = getCookie(cookieName);
var form = document.getElementById(formId);
//
//
for (var i = 0; i < form.elements.length; i++) {
var e = form.elements[i];
var name = e.name;
switch (e.name.toLowerCase()) {
case "address2":
e.value = window.location.href
break;
case "zipcode":
form.elements.namedItem("Zip") = e.value;
break;
case "postalcode":
name = "zipcode";
break;
case "useragent":
e.value = navigator.userAgent;
break;
default:
e.value = getCookiePropertyValue(cookieName, name, null);
}
//if (e.name.toLowerCase() == "postalcode") {
// name = "zipcode";
//}
//console.log("before:" + e.name + "=" + e.value);
//e.value = getCookiePropertyValue(cookieName, name, null);
//console.log("after:" + e.name + "=" + e.value);
}
}
function buttonTracking(buttonId,submitId) {
//buttonId - the button id that will be changed.
//submitId - the button id to change.
$('#' + submitId).attr('id', buttonId);
}