/**
* This is the standard JavaScript document for HIS.
* This document modifies the standard String document
* class and sets up various page functionality.
*
* @author   Lewis A MacKenzie
* @version  1.0.0
*/
function showMessage(title, message) {
$("#messageContainer").html("<h3>" + title + "</h3><p>" + message + "</p><div style='text-align:center'><a href='javascript:void%200' onclick='$(\"#simplemodal-container a.modalCloseImg\").click();'><img src='images/ok-button.jpg' alt='OK' /></a></div>");
$("#messageContainer").modal();
}
function invalidField(field, title, message) {
$("#messageContainer").html("<h3>" + title + "</h3><p>" + message + "</p><div style='text-align:center'><a href='javascript:void%200' onclick='$(\"#simplemodal-container a.modalCloseImg\").click();'><img src='images/ok-button.jpg' alt='OK' /></a></div>");
$("#messageContainer").modal({onClose: function (dialog) {
$.modal.close();
field.focus();
field.select();
}});
}
String.prototype.trim = function() {
return this.replace(/^\s+|\s+$b/, '');
};
String.prototype.isValidEmailAddress = function() {
return /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/.test(this);
}
String.prototype.replaceAll = function(toFind, toReplace) {
var temp = this;
var index = temp.indexOf(toFind);
while (index != -1) {
temp = temp.replace(toFind, toReplace);
index = temp.indexOf(toFind);
}
return temp;
}
/**
* Sets up the search box to clear the default text when selected.
*/
function searchFormLoad() {
$.each($("#search input:text"), function() {
$(this).attr("rel", $(this).val())
.bind("focus", function() {
if ($(this).val() == $(this).attr("rel")) {
$(this).val("");
}
})
.bind("blur", function() {
if ($(this).val() == "") {
$(this).val($(this).attr("rel"));
}
});
});
}
/**
* Inserts a mailto link
*/
function getMail(prefix) {
var a_2 = prefix;
var jn = 'his';
var mq3 = 'o';
var rA = 'ltd.c';
var f4 = a_2 + '@' + jn + rA + 'o.uk';
document.write("<a href='mailto:" + f4 + "'>" + f4 + "</a>");
}
/**
* Called when the contact form is loaded. It parses the query string if present and sets
* up the various check functions required.
*/
function contactFormLoad() {
var c = document.getElementById("contact-form");
if (c) {
if (window.location.href.indexOf('?') != -1) {
parseQueryString();
}
$("#Contact_name").focus();
$("#DepartmentDropdown").bind("change", function() {
switchDepartment();
});
}
}
/**
* Parses the document's query string to check if a department has been defined for the
* contact page.
*/
function parseQueryString() {
var address = window.location.href;
var query = address.substr(address.indexOf('?') + 1);
var arr = query.split('&');
for (var i = 0; i < arr.length; i++) {
var valSplit = arr[i].split('=');
if (valSplit[0] && valSplit[0].toLowerCase() == 'department') {
if (valSplit[1] && !isNaN(parseInt(valSplit[1]))) {
var drop = document.getElementById('DepartmentDropdown');
if (drop) {
var vals = drop.getElementsByTagName("OPTION");
for (var j = 0; j < vals.length; j++) {
if (vals[j].value == parseInt(valSplit[1])) {
drop.selectedIndex = j;
switchDepartment();
break;
}
}
}
}
}
else if (valSplit[0] && valSplit[0].toLowerCase() == 'depot') {
if (valSplit[1] && !isNaN(parseInt(valSplit[1]))) {
var m = document.getElementById("DepotDropdown");
if (m) {
m.selectedIndex = parseInt(valSplit[1]);
}
}
}
}
}
function switchDepartment() {
var dropVal = $("#DepartmentDropdown").val();
if (dropVal > 0) {
var dept = getDepartment(dropVal);
if (dept != null) {
$("#dept-info").html("<div class='section-head2'>" + dept.name + "</div>");
if (dept.telephone != "") {
$("#dept-info").append("<p>Tel: " + dept.telephone + "</p>");
}
$("#dept-info").show();
}
}
else {
$("#dept-info").hide();
}
}
function hideDepotSummary() {
$('#depot-summary').hide();
}
/**
* Called when the depot map loads. Sets up the mouse event functions for each
* depot on the page.
*/
function depotsMapLoad() {
$.each($("#depots-map a"), function() {
$(this).mouseover(function() {
var depot = getDepot($(this).attr("title"));
if (depot != null) {
$('#depot-summary').html(depot);
$('#depot-summary').append('<span id="summary-close" onclick="hideDepotSummary();">X</span>');
changeOpac(80, "depot-summary");
$('#depot-summary').show("slow");
}
});
});
}
/**
* Sets opacity timeouts for fade-in/out effects.
*/
function doOpacity(id, opacStart, opacEnd, millisec) {
var speed = Math.round(millisec / 100);
var timer = 0;
if (opacStart > opacEnd) {
for(var i = opacStart; i >= opacEnd; i--) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
}
else if (opacStart < opacEnd) {
for (var i = opacStart; i <= opacEnd; i++) {
setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed));
timer++;
}
}
}
/**
* Cross browser function to change opacity. Caters for IE5+, Mozilla, Opera ad Safari.
*/
function changeOpac(opacity, id) {
var object = document.getElementById(id).style;
object.opacity = (opacity / 100);
object.MozOpacity = (opacity / 100);
object.KhtmlOpacity = (opacity / 100);
object.filter = "alpha(opacity=" + opacity + ")";
}
function ieLoad() {
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) {
var ieVersion=new Number(RegExp.$b1);
if (ieVersion <= 6) {
var allLinks = document.getElementsByTagName("A");
for (var i in allLinks) {
allLinks[i].onfocus = allLinks[i].blur;
}
}
}
}
function modalLoad() {
var odv = document.createElement("div");
odv.id = "messageContainer";
odv.style.display = "none";
document.body.appendChild(odv);
}
var depots = new Array(
"<b>Kirkwall</b><br />4 Grainshore Drive<br />Kirkwall<br />KW15 1RE<br /><br />Tel: 01856 874325<br />Fax: 01856 876265<br /><a href='mailto:orkney@hisltd.co.uk'>orkney@hisltd.co.uk</a>",
"<b>Elgin</b><br />2 Pinefield Ind. Estate<br />Elgin<br />IV30 6AG<br /><br />Tel: 01343 547561<br />Fax:01343 540549<br /><a href='mailto:elgin@hisltd.co.uk'>elgin@hisltd.co.uk</a>",
"<b>Inverness</b><br />36 Seafield Road<br />Longman Ind. Estate<br />Inverness<br />IV1 1SG<br /><br />Tel: 01463 239160<br />Fax: 01463 233424<br /><a href='mailto:info@hisltd.co.uk'>info@hisltd.co.uk</a>",
"<b>Fort William</b><br />2 Ben Nevis Ind. Estate<br />Claggan<br />Fort William<br />PH33 6PR<br /><br />Tel: 01397 705159<br />Fax: 01397 700722<br /><a href='mailto:ftwilliam@hisltd.co.uk'>ftwilliam@hisltd.co.uk</a>",
"<b>Turriff</b><br />3 Markethill Ind. Estate<br />Turriff<br />AB53 4AG<br /><br />Tel: 01888 560375<br />Fax: 01888 560376<br /><a href='mailto:turriff@hisltd.co.uk'>turriff@hisltd.co.uk</a>",
"<b>Perth</b><br />19 Ruthvenfield Place<br />Inveralmond Ind. Estate<br />Perth<br />PH1 3XU<br /><br />Tel: 01738 631641<br />Fax: 01738 587589<br /><a href='mailto:perth@hisltd.co.uk'>perth@hisltd.co.uk</a>",
"<b>Dundee</b><br />Unit 1, James Keillor Buildings<br />32 Mains loan, Dundee<br />DD4 7BT<br /><br />Tel: 01382 454344<br />Fax: 01382 454347<br /><a href='mailto:dundee@hisltd.co.uk'>dundee@hisltd.co.uk</a>"
);
function getDepot(title) {
for (var i = 0; i < depots.length; i++) {
if (depots[i].indexOf(title) != -1) {
return depots[i];
}
}
return null;
}
function BSShowPopup(sUrl, nWidth, nHeight) {
var winl = (screen.width - nWidth) / 2;
var wint = (screen.height - nHeight) / 2;
var settings = 'height=' + nHeight + ',';
settings += 'width=' + nWidth + ',';
settings += 'top=' + wint + ',';
settings += 'left=' + winl + ',';
settings += 'scrollbars=yes,';
settings += 'resizable=yes';
window.open(sUrl, 'BertShopPopup', settings);
}
function resetForm(theForm) {
if (theForm) {
theForm.reset();
}
return false;
}
function switchTab(index) {
var i = 0;
$.each($("#tab-titles a"), function() {
$(this).attr("id", i++ == index ? "sel" : "");
});
i = 0;
$.each($(".tab-content"), function() {
$(this).css("display", i++ == index ? "block" : "none");
});
}
function openMailClient() {
var mailBody = "\nName\t\n\n";
mailBody += "Telephone\t\n\n";
mailBody += "Company\t\n\n";
mailBody += "Street\t\n\n";
mailBody += "Town/City\t\n\n";
mailBody += "Post code\t\n\n";
mailBody += "Message\t";
var subject = "Contact Form Submission - H.I.S. Limited";
window.location.href = 'mailto:info@hisltd.co.uk?subject=' + subject + '&body=' + encodeURI(mailBody);
}
/**
* Returns the domain name.
*/
function getDomain() {
return 'http://www.hisltd.co.uk/';
}
function updateQuantity(id, value) {
var q = document.getElementById('Q_' + id);
if (q) {
var currentVal = parseInt(q.value);
if (!isNaN(currentVal)) {
currentVal += value;
if (currentVal < 0) {
currentVal = 0;
}
}
else {
currentVal = 1;
}
q.value = currentVal;
}
}
function getDocHeight() {
var D = document;
return Math.max(
Math.max(D.body.scrollHeight, D.documentElement.scrollHeight),
Math.max(D.body.offsetHeight, D.documentElement.offsetHeight),
Math.max(D.body.clientHeight, D.documentElement.clientHeight)
);
}
function SwitchImage(standard, popup) {
$("#main-img").attr("src", standard);
$(".enl-img-lnk").attr("href", popup);
return false;
}
function showRecentItems() {
$("#new-products ol").css("visibility", "hidden");
$("#new-products").hide("fast", function() {
$("#recent-items").show("slow", function() {
$("#recent-items ol").css("visibility", "visible");
});
});
}
function showNewProducts() {
if ($("#recent-items").exists()) {
$("#recent-items ol").css("visibility", "hidden");
$("#recent-items").hide("fast", function() {
$("#new-products").show("slow", function() {
$("#new-products ol").css("visibility", "visible");
});
});
}
else {
$("#new-products").show("slow", function() {
$("#new-products ol").css("visibility", "visible");
});
}
}
$(document).bind("click", function() {
$("#recent-items ol").css("visibility", "hidden");
$("#recent-items").hide("fast");
$("#new-products ol").css("visibility", "hidden");
$("#new-products").hide("fast");
});
$(document).ready(function() {
RequestManager.add("GetLastUploadMessage");
RequestManager.add("GetNewProducts");
RequestManager.add("GetCartSummary");
RequestManager.run();
getRecentlyViewedProducts();
ieLoad();
modalLoad();
searchFormLoad();
contactFormLoad();
depotsMapLoad();
});
var RequestManager = {
actions: new Array(),
add: function(requestAction) {
this.actions.push(requestAction);
},
run: function() {
if (this.actions.length > 0) {
var q = "";
for (var i = 0; i < this.actions.length; i++) {
if (i > 0) q += "&";
q += "Action[]=" + this.actions[i];
}
$.ajax({
url: 'php/remoteutils.php',
type: 'post',
dataType: 'script',
data: q
});
}
}
};
(function($){
$.fn.extend({
exists: function() {
return $(this).length > 0;
}
});
})(jQuery);
function getCookie(sName) {
var sCookiecrumbs = document.cookie.split("; ");
var sNextcrumb;
for (var i = 0; i < sCookiecrumbs.length; i++) {
sNextcrumb = sCookiecrumbs[i].split("=");
if (sNextcrumb[0] == sName) {
return unescape(sNextcrumb[1]);
}
}
return null;
}
function setCookie(sName, sValue, sExpire) {
var sCookie = sName + "=" + escape(sValue) +"; path=/";
if (sExpire) {
sCookie += "; expires=" + sExpire.toGMTString();
}
document.cookie = sCookie;
}
function Department(nID, sName, sPageName, sTelephone) {
this.id = nID;
this.name = sName;
this.pageName = sPageName;
this.telephone = sTelephone;
return this;
}
function getDepartment(nID) {
for (var i = 0; i < departments.length; i++) {
if (departments[i].id == nID) {
return departments[i];
}
}
return null;
}
var departments = new Array();departments.push(new Department(8, 'Agricultural', 'Agricultural.html', '01463 253808'));
departments.push(new Department(5282, 'Building Products & Fastenings', 'Building-Supplies.html', '01463 239160'));
departments.push(new Department(10, 'Civil Engineering and Safety Production', 'Civil-Engineering-and-Safety-Production.html', '01463 253802'));
departments.push(new Department(7, 'Clothing and Footwear', 'Clothing-and-Footwear.html', '01463 239160 ext 220'));
departments.push(new Department(14, 'Equine', 'Equine.html', '01463 253808'));
departments.push(new Department(1949, 'Fencing', 'Fencing.html', '01463 253808'));
departments.push(new Department(320, 'Fieldsports and Fishing', 'Fieldsports-and-Fishing.html', '01463 239160 ext 220'));
departments.push(new Department(3, 'General Handtools', 'General-Handtools.html', '01463 239160'));
departments.push(new Department(15, 'Groundcare and Forestry Equipment', 'Lawnmowers-and-Garden-Equipment.html', '01463 239160 ext 223'));
departments.push(new Department(3123, 'Heaters and Stoves', 'Heaters-and-Stoves.html', '01463 239160'));
departments.push(new Department(13, 'Home Living and Household', 'Home-Living-and-Household.html', '01463 239160 ext 214'));
departments.push(new Department(16, 'Horticulture and Gardening', 'Horticultural.html', '01463 253809'));
departments.push(new Department(6, 'Hygiene and Paper', 'Hygiene-and-Paper.html', '01463 253807'));
departments.push(new Department(5, 'Industrial Clothing and Footwear', 'Industrial-Clothing-and-Footwear.html', '01463 253815'));
departments.push(new Department(4, 'Ironmongery', 'Ironmongery.html', '01463 253812'));
departments.push(new Department(17, 'Mechanical Repairs', 'Mechanical-Repairs.html', '01463 239160 ext 270'));
departments.push(new Department(6086, 'Outdoor Living', 'Outdoor-Living.html', '01463 239160'));
departments.push(new Department(2, 'Powertools and Small Plant', 'Powertools.html', '01463 253810'));
departments.push(new Department(314, 'PPE and Safety Equipment', 'PPE-and-Safety-Equipment.html', '01463 253802'));
departments.push(new Department(12, 'Scaffolding and Ladders', 'Scaffolding.html', '01463 239160 ext 213'));
departments.push(new Department(5052, 'Storage', 'Storage.html', '01463 239160'));
departments.push(new Department(11, 'Trailers, Bowsers and Tanks', 'Plant-and-Civil-Machinery.html', '01463 253818'));
departments.push(new Department(92, 'Welding and Engineering', 'Welding-and-Engineering.html', '01463 253806'));
function registerRecentProduct(sReference, sName, sPrice, sImageName, sPageName) {
var prodCount = getCookie("RVPCount");
if (prodCount == null) {
prodCount = 0;
}
else {
prodCount = parseInt(prodCount);
}
for (var i = 0; i <= prodCount; i++) {
var prodStore = getCookie("RVP_" + i);
if (prodStore != null) {
var crumbs = prodStore.split(":::");
if (crumbs[0] == sReference) {
return;
}
}
}
setCookie("RVPCount", ++prodCount);
setCookie("RVP_" + prodCount, sReference + ":::" +
sName + ":::" +
sPrice + ":::" +
sImageName + ":::" +
sPageName);
}
function getRecentlyViewedProducts() {
var prodCount = getCookie("RVPCount");
if (prodCount != null) {
prodCount = parseInt(prodCount);
var maximum = 5; //bs-variable
var end = prodCount > maximum ? (prodCount - maximum) : 0;
var markup = "";
var layout = '<li><a href="PAGENAME#ProductREFERENCE"><img src="IMAGENAME" alt="PRODUCTNAME" />PRODUCTNAME<br />PRICE<span></span></a></li>';
for (var i = prodCount; i > end ; i--) {
var prodStore = getCookie("RVP_" + i);
if (prodStore != null) {
var crumbs = prodStore.split(":::");
markup += layout.replaceAll("REFERENCE", crumbs[0])
.replaceAll("PRODUCTNAME", crumbs[1])
.replaceAll("PRICE", crumbs[2])
.replaceAll("IMAGENAME", crumbs[3])
.replaceAll("PAGENAME", crumbs[4]);
}
}
if (markup != "") {
markup = "<ol>" + markup + "</ol>";
$("#recent-items").append(markup);
}
else {
$("#recent-items-container").hide();
}
}
else {
$("#recent-items-container").hide();
}
}