var PompanetteSharedUtils = {
//hold any runtime variables
runtime_: {
dyn: {},
cartInfo: {}
},
init: function() {
PompanetteSharedUtils.cart.init();
var redir = "//pompanette.com/";
if (location.href.toLowerCase().indexOf(redir.toLowerCase()) > -1) {
location.replace(location.href.replace(new RegExp(redir, "i"), "//www.pompanette.com/"));
}
},
format: {
currency: function(val) {
return "$" + $.currency(val);
}
},
search: {
displayForm: function() {
var sHTML = '
' +
'
#TITLE#
' +
'
' +
' ' + obj.contentTitle + ' for: ' +
' #dealerfor#' +
'
' +
'
' +
' Name: ' +
' #name#' +
'
' +
'
' +
' Address: ' +
' #address#' +
'
' +
'
' +
' City: ' +
' #city#' +
'
' +
'
' +
' State: ' +
' #state#' +
'
' +
'
' +
' Country: ' +
' #country#' +
'
' +
'
' +
' Zip: ' +
' #zip#' +
'
' +
'
' +
' Phone: ' +
' #phone#' +
'
' +
'
' +
' Fax: ' +
' #fax#' +
'
' +
'
' +
' Website: ' +
' #website#' +
'
' +
'
';
var rt = PompanetteSharedUtils.runtime_.dyn = obj;
var elTitle = document.getElementById("viewtitle");
if (elTitle) {
elTitle.innerHTML = obj.viewTitle;
}
CookieUtils.set("viewid", rt.id);
PompanetteSharedUtils.showViewEntriesUI (rt.subsite, "viewcontents", rt.viewName, null, "javascript:void PompanetteSharedUtils.loadDynContents(#INDEX#);");
},
loadDynContents: function(idx) {
var rt = PompanetteSharedUtils.runtime_.dyn;
var obj = rt.entries[idx];
var elTarget = document.getElementById("viewcolcontents");
if (obj && elTarget) {
var sSource = rt.template;
sSource = sSource.replace("#TITLE#", rt.contentTitle);
var aHide = [];
for (var ii = 0; ii < obj.entrydata.length; ii++) {
var data = obj.entrydata[ii];
var nam = data['@name'];
var txt = data.text[0];
if (txt.length == 0) aHide.push(nam);
sSource = sSource.replace('#' + nam + '#', txt);
}
elTarget.innerHTML = sSource;
for (var ii = 0; ii < aHide.length; ii++) {
var el = document.getElementById("entry_" + aHide[ii]);
if (el) el.style.display = "none";
}
}
},
displayNewsItems: function (subsite) {
if (typeof subsite == "undefined") subsite = "pompanettehome";
var elNews = document.getElementById("newsItems");
if (typeof elNews != "undefined" && elNews != null) {
var sUrl = BigSummitUtils.getBaseUrl() + "/getNewsItems.js?Open&k=" + subsite;
$.getJSON(sUrl, function(json) {
var newsItems = json.items;
var c_TEMPLATE = "";
sHtml += "ID | Description | Quantity | Price | Total |
";
for (var ii = 0; ii < json.items.length; ii++) {
if (hasDocid == false) json.items[ii].quantity = items[ii].quantity;
var sDesc = json.items[ii].title;
if (currentSubsite != json.items[ii].subsite) {
sDesc += " (" + json.items[ii].subsite + ")";
}
sHtml += "";
sHtml += "" + json.items[ii].id + " | ";
sHtml += "" + sDesc + " | ";
if (bAllowUpdating) {
sHtml += "" +
"" +
"" +
" " +
"" +
" | " + json.items[ii].quantity + " | ";
} else {
sHtml += " | " + json.items[ii].quantity + " | ";
}
sHtml += "" + PompanetteSharedUtils.format.currency(json.items[ii].price) + " | ";
var lTemp = Math.round((json.items[ii].price*100)*json.items[ii].quantity)/100; //due to floating point issues with some browsers, need to do this...
lTotal = (Math.round(100*lTotal) + Math.round(100*lTemp))/100; //due to floating point issues with some browsers, need to do this...
sHtml += "" + PompanetteSharedUtils.format.currency(lTemp) + " | ";
sHtml += "
";
}
//code for shipping and handling
sHtml += "
|
";
sHtml += " | " + json.shipping[0].title + " | " + json.shipping[0].price + " |
";
sHtml += " | " + json.handling[0].title + " | " + PompanetteSharedUtils.format.currency(json.handling[0].price) + " |
";
var elAmt_items = document.getElementById("Card_Amount_items");
if (elAmt_items) elAmt_items.value = lTotal;
//set the total in a cookie to be used later...
PompanetteSharedUtils.cookies.setCurrentTotal(lTotal);
var elAmt_handling = document.getElementById("Card_Amount_handling");
if (elAmt_handling) elAmt_handling.value = json.handling[0].price;
lTotal = (Math.round(100*lTotal) + Math.round(100*json.handling[0].price))/100; //due to floating point issues with some browsers, need to do this...
sHtml += " " + PompanetteSharedUtils.format.currency(lTotal) + " |
";
sHtml += "
";
var elContainer = document.createElement("div");
elContainer.className = "Wrapper";
elContainer.innerHTML = sHtml;
var el = document.getElementById("cartcontents");
while (el.hasChildNodes()) el.removeChild(el.firstChild);
el.appendChild(elContainer);
var elAmt = document.getElementById("Card_Amount");
if (elAmt) elAmt.value = lTotal;
if (elCheckoutButton) elCheckoutButton.style.display = "inline";
}
PompanetteSharedUtils.loadHoverActiveImages("hoveractive");
});
}
},
updateCatalogCommercialLinks: function() {
var update_ = function(id) {
var el = document.getElementById(id);
if (el && el.href && el.href.indexOf("_commercial") == -1) {
el.href = el.href.replace(/_catalog/g, "_catalog_commercial");
}
};
update_("nav_item_catalog");
update_("nav_item_products");
},
showViewEntriesUI: function (subsite, id, view, selected, linktemplate) {
if (typeof view == "undefined" || view == null) {
var x = CookieUtils.get("viewid");
if (x == "new_catalog") {
view = "Products_new_lookup";
} else {
view = "Products_lookup";
}
}
linktemplate = linktemplate || "#BASE#/#VIEW#/#UNID#?OpenDocument";
if (typeof selected == "undefined" || selected == null) selected = "**NONESELECTED**";
var sBase = BigSummitUtils.getBaseUrl();
var sUrl = sBase + "/" + view + "?ReadViewEntries&OutputFormat=json&Count=10000&RestrictToCategory=[" + subsite + "]";
$.getJSON(sUrl, function(json) {
var elContainer = document.createElement("div");
elContainer.className = "Wrapper";
var entries = json.viewentry;
var iSelected = -1;
var sOverallCategory = "";
var oCategory = null;
var oDocument = null;
var iCategory = -1;
var oDocumentContainer = null;
PompanetteSharedUtils.runtime_.dyn.entries = entries;
if (!entries) return;
for (var ii = 0; ii < entries.length; ii++) {
var sCategory = entries[ii].entrydata[1].text[0];
var sInfo = entries[ii].entrydata[2].text[0];
if (sInfo == "" && entries[ii].entrydata[10]) {
sInfo = entries[ii].entrydata[10].text[0];
}
if (sInfo == "" && entries[ii].entrydata[2]) {
sInfo = entries[ii].entrydata[3].text[0];
}
var sUnid = entries[ii]["@unid"];
//the category is different, need new div
if (sCategory != sOverallCategory) {
sOverallCategory = sCategory;
iCategory++;
oCategory = document.createElement("div");
oCategory.className = "ViewEntryCategory " + PompanetteSharedUtils._viewCatPrefix + iCategory;
var oLink = document.createElement("a");
oLink.className = "ViewCategory";
if (sInfo.length == 0) {
oLink.setAttribute("href", "../0/" + sUnid + "?Open");
} else {
oLink.setAttribute("href", "javascript:void PompanetteSharedUtils.toggleViewCategory(" + iCategory + ")");
}
oLink.innerHTML = sCategory;
oCategory.appendChild(oLink);
if (oDocument != null) oDocument.className += " noseparator";
if (oDocumentContainer != null) elContainer.appendChild(oDocumentContainer);
elContainer.appendChild(oCategory);
oDocumentContainer = document.createElement("div");
oDocumentContainer.className = PompanetteSharedUtils._viewDocPrefix + iCategory;
oDocumentContainer.style.display = "none";
}
//if this unid is selected, we want to how the correct category
var selcss = "";
if (selected == sUnid) {
iSelected = iCategory;
selcss = " ViewEntryDocumentSelected ";
}
//now that we're done with the category, let's show the docs...
var sProduct = entries[ii].entrydata[2].text[0];
var sTitle = entries[ii].entrydata[3].text[0];
var oDocument = document.createElement("div");
oDocument.className = "ViewEntryDocument " + selcss;
var oLink = document.createElement("a");
var sLink = linktemplate.replace("#BASE#", sBase).replace("#VIEW#", view).replace("#UNID#", sUnid).replace("#INDEX#", ii);
oLink.setAttribute("href", sLink);
if (sTitle.length == 0 && sProduct.length == 0 && entries[ii].entrydata[3]) sTitle = entries[ii].entrydata[3].text[0];
oLink.innerHTML = ( (sProduct.length < 2 || sTitle.length < 2) ? sProduct + sTitle : sProduct + " - " + sTitle );
oDocument.appendChild(oLink);
oDocumentContainer.appendChild(oDocument);
}
if (oDocument != null) oDocument.className += " noseparator";
elContainer.appendChild(oDocumentContainer);
document.getElementById(id).innerHTML = "";
document.getElementById(id).appendChild(elContainer);
//select the appropriate category (if necessary)
if (iSelected >= 0) {
PompanetteSharedUtils.toggleViewCategory(iSelected);
} else {
var loc = window.location.href + "§ion=&";
loc = loc.split("§ion=")[1];
loc = loc.split("&")[0];
if (loc.length > 0) PompanetteSharedUtils.toggleViewCategory(loc);
}
});
},
toggleViewCategory: function (idx) {
var ii = 0;
while (true) {
var elCat = BigSummitUtils.getElementsByClassName(PompanetteSharedUtils._viewCatPrefix + ii, "div");
if (elCat.length == 0) break;
elCat = elCat[0];
var isSelected = (idx === ii);
if (!isSelected) {
try {
isSelected = (idx.toLowerCase && elCat.childNodes[0].innerHTML.toLowerCase() === idx.toLowerCase());
} catch (ee) { if (console) console.log(ee);}
}
if (isSelected) {
if (elCat.className.indexOf("ViewEntryCategorySelected") > -1) {
idx = -1;
} else {
elCat.className += " ViewEntryCategorySelected";
}
}
if (!isSelected) {
elCat.className = elCat.className.replace(/ViewEntryCategorySelected/gi,"");
}
var elDocs = BigSummitUtils.getElementsByClassName(PompanetteSharedUtils._viewDocPrefix + ii, "div");
for (var jj = 0; jj < elDocs.length; jj++) {
//elDocs[jj].style.display = ((idx == ii) ? "" : "none");
var elBox = $('.' + PompanetteSharedUtils._viewDocPrefix + ii);
var speed = 300;
if (isSelected) {
elBox.slideDown(speed);
} else {
elBox.slideUp(speed);
}
}
ii++;
}
},
loadHoverActiveImages: function (sname) {
var elImgs= BigSummitUtils.getElementsByClassName(sname,"img");
for (var ii = 0; ii < elImgs.length; ii++) {
var sExt = "jpg";
if (elImgs[ii].src.indexOf(".gif") > -1) {
sExt = "gif";
}
eval('elImgs[ii].onmouseover = function() { this.src = this.src.replace(/\\.' + sExt + '/,"_active.' + sExt + '"); };');
eval('elImgs[ii].onmouseout = function() { this.src = this.src.replace(/\\_active\\.' + sExt + '/,".' + sExt + '"); };');
var elNew = document.createElement("img");
elNew.src = eval('elImgs[ii].src.replace(/\\.' + sExt + '/,"_active.' + sExt + '");');
elNew.style.display = "none";
document.body.appendChild(elNew);
}
},
cookies: {
_currentSubsite: "CSubsite",
setCurrentSubsite: function (sname) {
CookieUtils.set(PompanetteSharedUtils.cookies._currentSubsite, sname);
},
getCurrentSubsite: function () {
return CookieUtils.get(PompanetteSharedUtils.cookies._currentSubsite);
},
_currentTotal: "CTotal",
setCurrentTotal: function (total) {
CookieUtils.set(PompanetteSharedUtils.cookies._currentTotal, total);
},
getCurrentTotal: function () {
return CookieUtils.get(PompanetteSharedUtils.cookies._currentTotal);
}
},
dialog: {
warning: function (smsg, stitle, itimeout, iwidth) {
$.modaldialog.warning(smsg, { stitle: stitle, width: iwidth, timeout: itimeout } );
//alert(smsg);
},
success: function (smsg, stitle, itimeout, iwidth) {
$.modaldialog.success(smsg, { title: stitle, width: iwidth, timeout: itimeout } );
//alert(smsg);
},
error: function (smsg, stitle, itimeout, iwidth) {
$.modaldialog.error(smsg, { title: stitle, width: iwidth, timeout: itimeout } );
//alert(smsg);
},
question: function (smsg, stitle, itimeout, iwidth) {
$.modaldialog.prompt(smsg, { title: stitle, width: iwidth, timeout: itimeout } );
//confirm(smsg);
}
},
cart: {
init: function() {
PompanetteSharedUtils.cart.cookie.get();
},
getItems: function() {
return PompanetteSharedUtils.cart._items;
},
checkout: function() {
try {
//if the total isn't more than the minimum, then we cannot proceed.
var min = PompanetteSharedUtils.runtime_.cartInfo.minimum[0].price;
if (min > 0 && min > parseFloat(PompanetteSharedUtils.cookies.getCurrentTotal(), 10)) {
PompanetteSharedUtils.dialog.error('We\'re sorry, but we cannot complete this order.