/*global oldhandler, absolute_local_script_url, sef_links_enabled, is_backend_transaction, Navigator, absolute_image_url, absolute_local_script_ssl_url, g_disable_default_module_load*/
var IE = document.all ? true : false;
var img = new Image();
var loading = false;
var filename = "";
var dialog_titles = new Array();
var function_error_messages = new Array();
var function_titles = new Array();
var page_changing_event = false;
function _addEvent(e, evt, handler) {
if (evt == "ready") {
evt = "DOMContentLoaded";
}
if (typeof handler !== 'function') {
return;
}
if (e.addEventListener) {
e.addEventListener(evt, handler, false);
} else if (e.attachEvent) {
if (e.DOMContentLoaded) {
e.attachEvent("on" + evt, handler);
} else {
if (evt == "DOMContentLoaded") {
handler();
}
}
} else {
var oldHandler = e["on" + evt];
function newHandler(event) {
handler.call(e, event);
if (typeof oldhandler === 'function')
oldhandler.call(e, event);
}
}
}
var _events = ["load", "resize", "scroll", "ready", "click", "mousedown", "change", "blur", "keypress"];
var _elsvLib = function (item) {
function eventWorker(item, event) {
this.add = function (handler) {
_addEvent(item, event, handler);
};
}
for (var i = 0; i < _events.length; i++) {
this[_events[i]] = (new eventWorker(item, _events[i])).add;
}
};
var eslvLib = function (item) {
return new _elsvLib(item);
};
function stopSubmitOnEnterForForm(e) {
var the_event = e || window.event;
var keycode = the_event.keyCode || the_event.which || the_event.charCode;
if (keycode == 13) {
the_event.cancelBubble = true;
the_event.returnValue = false;
if (the_event.stopPropagation) {
the_event.stopPropagation();
the_event.preventDefault();
}
return false;
}
}
function LayerRestore(layer, restore_html) {
this.layer = layer;
this.restore_html = restore_html;
}
var layer_restore = new Array();
var add_to_cart_layer_restore = new Array();
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/, '');
};
String.prototype.lpad = function (length, strToPad) {
originalstr = this.toString();
while (originalstr.length < length)
originalstr = strToPad + originalstr;
return originalstr;
};
String.prototype.rpad = function (length, strToPad) {
originalstr = this.toString();
while (originalstr.length < length)
originalstr = originalstr + strToPad;
return originalstr;
};
$ = function (n, d) {
if (d == null) {
d = document;
}
findObj(n, d);
};
function getBrowserCompatibility() {
var browser = navigator.appName;
var b_version = navigator.appVersion;
var version = parseFloat(b_version);
var message = null;
if (browser == "Netscape") {
if (version <= 4) {
message = "WARNING: Your current browser may not be able to optimally display or browse active content on this website. We strongly recommend that you upgrade your browser to the latest version. You are running [" + browser + " version: " + version + "]. Minimum required version: 4";
}
} else if (browser == "Microsoft Internet Explorer") {
var regexp = /MSIE.[\d]+\.[\d]+/gi;
version = b_version.match(regexp);
regexp = /[\d]+\.[\d]+/gi;
version = version[0].match(regexp);
version = parseFloat(version[0]);
if (version < 6) {
message = "WARNING: Your current browser may not be able to optimally display or browse active content on this website. We strongly recommend that you upgrade your browser to the latest version. You are running [" + browser + " version: " + version + "]. Minimum required version: 6";
}
}
if (message != null) {
alert(message);
}
}
function setWindowNameToSession(window_name_from_session) {
if (window_name_from_session == "") {
if (window.name == "") {
window.name = "eSolve Control Panel";
}
mlayer = null;
xmlHttp = new ajaxObject(absolute_local_script_url + 'getmodule.php', mlayer, updateLayer);
xmlHttp.update("id=ajax_set_windows_name_to_session.php&window_name=" + window.name, 'GET');
}
}
function setWindowNameWarningDispalyedToSession(window_name_from_session) {
mlayer = null;
xmlHttp = new ajaxObject(absolute_local_script_url + 'getmodule.php', mlayer, updateLayer);
xmlHttp.update("id=ajax_set_windows_name_to_session.php&window_name=" + window.name + "&warning_shown=1", 'GET');
}
// If NS -- that is, !IE -- then set up for mouse capture
//if (!IE) document.captureEvents(Event.MOUSEMOVE)
// Set-up to use getMouseXY function onMouseMove
document.onmousemove = getMouseXY;
// Temporary variables to hold mouse x-y pos.s
var tempX = 0, tempY = 0;
var scrOfX = 0, scrOfY = 0;
// Main function to retrieve mouse x-y pos.s
function getScrollXY() {
if (typeof (window.pageYOffset) == 'number') {
//Netscape compliant
scrOfY = window.pageYOffset;
scrOfX = window.pageXOffset;
} else if (document.body && (document.body.scrollLeft || document.body.scrollTop)) {
//DOM compliant
scrOfY = document.body.scrollTop;
scrOfX = document.body.scrollLeft;
} else if (document.documentElement && (document.documentElement.scrollLeft || document.documentElement.scrollTop)) {
//IE6 standards compliant mode
scrOfY = document.documentElement.scrollTop;
scrOfX = document.documentElement.scrollLeft;
}
return true;
}
function getDocumentHeight() {
var height = 0;
height = document.documentElement.clientHeight;
if (height > 0) {
/* Height has been set */
} else {
height = document.height;
}
if (height == 0) {
height = 600;
/* Was unable to find the height. Setting avrg height based on stats */
}
return height;
}
function getDocumentWidth() {
var width = 0;
width = document.documentElement.clientWidth;
if (width > 0) {
/* Width has been set */
} else {
width = document.width;
}
if (width == 0) {
width = 900;
/* Was unable to find the width. Setting avrg width based on stats */
}
return width;
}
function getMouseXY(e) {
tempX = 0;
tempY = 0;
srcOfY = 0;
srcOfX = 0;
getScrollXY();
if (IE) { // grab the x-y pos.s if browser is IE
tempX = event.clientX + scrOfX;
tempY = event.clientY + scrOfY;
} else { // grab the x-y pos.s if browser is NS
tempX = e.pageX;
tempY = e.pageY;
}
// catch possible negative values in NS4
if (tempX < 0) {
tempX = 0;
}
if (tempY < 0) {
tempY = 0;
}
return true;
}
var toScroll = 0;
var hasScrolled = 0;
var scrollInc = 50;
var scrolldelay = null;
function stopScroll() {
if (scrolldelay != null) {
clearTimeout(scrolldelay);
toScroll = 0;
hasScrolled = 0;
scrollInc = 50;
}
}
function pageScroll() {
if ((toScroll - hasScrolled) < scrollInc) {
scrollInc = (toScroll - hasScrolled);
}
window.scrollBy(0, scrollInc); // horizontal and vertical scroll increments
hasScrolled = hasScrolled + scrollInc;
if (hasScrolled >= toScroll) {
stopScroll();
} else {
scrolldelay = setTimeout('pageScroll()', 2); // scrolls every 100 milliseconds
}
}
function jumpScroll() {
window.scroll(0, 150); // horizontal and vertical scroll targets
}
function addCSSClassToElement(element, class_name) {
if (element != null) {
var reg_exp = new RegExp('' + class_name + '', 'g');
if (reg_exp.test(element.className)) {
} else {
element.className = element.className + (element.className.trim() == "" ? "" : " ") + class_name;
}
}
}
function removeCSSClassFromElement(element, class_name) {
if (element != null) {
var reg_exp = new RegExp('[\ ]*' + class_name + '', 'g');
if (reg_exp.test(element.className)) {
element.className = element.className.replace(reg_exp, "");
}
}
}
function RemoveMessage(num, must_scroll) {
d = document;
mylayer = findObj("message" + num);
if (mylayer != null) {
mylayer.parentNode.removeChild(mylayer);
mylayer = null;
if (must_scroll) {
toScroll = scrOfY;
pageScroll();
} else {
toScroll = 0;
hasScrolled = 0;
scrollInc = 50;
}
}
if (window.layer_restore.length > 0) {
if (window.layer_restore[num] != null) {
restoreObj = layer_restore[num];
restoreObj.layer.innerHTML = restoreObj.restore_html;
window.layer_restore.splice(num, 1);
}
}
}
function ShowMessage(num, msg, must_center, width, height) {
d = document;
var previous_layer = findObj("message" + num);
RemoveMessage(num, 0);
if ((width == "") || (width == 0) || (width == null)) {
width = 200;
}
if (msg.length != 0) {
var mylayer = d.createElement("DIV");
mylayer.id = "message" + num;
mylayer.className = "show_message_container";
mylayer.style.visibility = "hidden";
mylayer.style.position = "absolute";
if (IE) {
mylayer.style.filter = "alpha(opacity=100);";
} else {
mylayer.style.opacity = 1;
}
mylayer.zIndex = 999;
mylayer.innerHTML = '
';
/* IMPORTANT: If you are going to create a diaglog box and that box contains fields, appending this new
* layer as a child of the boday tag will cause the submit without any data fields. Input
* fields must be part of a form tag
*/
var form = findObj("frm");
if (form) {
form.appendChild(mylayer);
} else {
d.body.appendChild(mylayer);
}
//Locate the newly added div layer
mylayer = findObj("message" + num);
if (previous_layer != null) {
mylayer.style.top = previous_layer.style.top;
mylayer.style.left = previous_layer.style.left;
mylayer.style.width = previous_layer.style.width;
mylayer.style.height = previous_layer.style.height;
} else {
if (must_center) {
var tempTop = 0;
if ((width > 0) && (height > 0)) {
tempTop = tempY - (height / 2);
if (tempTop < 0) {
tempTop = 10;
}
mylayer.style.top = tempTop.toString() + "px";
mylayer.style.left = ((getDocumentWidth() / 2) - (width / 2)).toString() + "px";
} else {
tempTop = tempY;
mylayer.style.top = tempTop.toString() + "px";
mylayer.style.left = ((getDocumentWidth() / 2) - 100).toString() + "px";
}
mylayer.style.width = width.toString() + "px";
} else {
mylayer.style.top = tempY.toString() + "px";
a_width = mylayer.clientWidth;
mylayer.style.left = tempX - (a_width / 2).toString() + "px";
mylayer.style.width = width.toString() + "px";
}
}
mylayer.style.visibility = "visible";
}
}
function ConfirmationBox(msg, method, yay_button_caption, nay_button_caption, width, height) {
var buttons = '
|   | | ';
var box_msg = msg + buttons;
ShowMessage(1, box_msg, false, width, height);
}
function EmailFriend(num, mfrom, cnt) {
d = document;
var code = findObj("code_" + cnt);
var sef_name = findObj("sef_name_" + cnt);
var group_code = findObj("group_code_" + cnt);
var use_code = "";
if (group_code != null) {
if (group_code.value != "") {
use_code = group_code.value;
}
} else {
use_code = code.value;
}
var description = findObj("description_" + cnt);
var host = findObj("host");
var module = findObj("module");
var price = findObj("price_" + cnt);
if (sef_links_enabled) {
if (sef_name != null) {
var url = host.value + "item/" + sef_name.value;
} else {
var url = host.value + "item/" + use_code;
}
} else {
var url = host.value + "getmodule.php?id=listitems.php&dowhat=details&code=" + urlEncode(use_code);
}
message = "Hi.I think this item may interest you.
Item: " + use_code + "
Description: " + description.value + "
";
mlink = "Link: Website";
encoded_message = escape(encodeURI(message + mlink));
msg = '';
msg += '
';
msg += '';
msg += 'Your name: | ';
msg += ' | ';
msg += '';
msg += ' ';
msg += '';
msg += ' ';
msg += ' | ';
msg += '
';
msg += '';
msg += 'Recipient email address: | ';
msg += ' | ';
msg += '';
msg += ' ';
msg += '';
msg += ' ';
msg += ' | ';
msg += '
';
msg += '';
msg += 'Message: | ';
msg += ' | ';
msg += '';
msg += ' ';
msg += message + mlink;
msg += '';
msg += ' ';
msg += ' | ';
msg += '
';
msg += '';
msg += 'Verification image: | ';
msg += ' | ';
msg += '';
msg += '';
msg += ' | ';
msg += '
';
msg += '';
msg += 'Please retype the number displayed above: | ';
msg += ' | ';
msg += '';
msg += ' ';
msg += '';
msg += ' ';
msg += ' | ';
msg += '
';
msg += '';
msg += ' | ';
msg += ' | ';
msg += '';
msg += '';
msg += ' Send';
msg += ' ';
msg += ' | ';
msg += '
';
msg += '
';
msg += '
';
ShowMessage(num, msg, true, 500, 400);
getRIV('riv_layer');
}
function EmailGeneral(num, mfrom, mto, cnt) {
d = document;
RemoveMessage(num, 0);
var mylayer = d.createElement("DIV");
mylayer.id = "message" + num;
mylayer.style.position = "absolute";
mylayer.style.top = tempY.toString() + "px";
mylayer.style.left = ((findObj('control_panel').clientWidth / 2)).toString() + "px";
mylayer.style.color = "#000000";
mylayer.style.background = "#FFFFFF";
mylayer.style.zIndex = 10;
mylayer.style.padding = "5px";
mylayer.style.paddingRight = "5px";
d.body.appendChild(mylayer);
msg = '';
msg += '
';
msg += '
';
msg += '
';
mylayer.innerHTML = '';
if (!is_backend_transaction) {
getRIV('riv_layer');
}
}
function findObj(n, d) { //v4.01
var p, i, x;
if (n != null) {
if (!d)
d = document;
if ((p == n.indexOf("?")) > 0 && parent.frames.length) {
d = parent.frames[n.substring(p + 1)].document;
n = n.substring(0, p);
}
if (!(x == d[n]) && d.all.length)
x = d.all[n];
for (i = 0; !x && i < d.forms.length; i++)
x = d.forms[i][n];
for (i = 0; !x && d.layers && i < d.layers.length; i++)
x = findObj(n, d.layers[i].document);
if (!x && d.getElementById)
x = d.getElementById(n);
return x;
} else {
return null;
}
}
function showBigImage(mfilename, width, height, image) {
var a_image = findObj("item_details_image");
var a_image_src = a_image.src;
filename = mfilename;
img = null;
img = new Image();
if (filename.indexOf("/stock/", 0) == -1) {
var img_big = "images/stock/big/" + filename;
img.src = "images/stock/small/" + filename;
} else {
var img_big = filename.replace("small/", "big/");
img.src = filename;
}
if (a_image != null) {
var thumb_src = a_image.src;
thumb_src = thumb_src.replace("small/", "thumb/");
image.src = thumb_src;
image.onclick = function () {
showBigImage(a_image_src, width, height, image)
};
a_image.src = img.src;
a_image.onclick = function () {
ShowMessage(1, '
', 1, width, height);
};
}
}
function showBigImageLightbox(mfilename, width, height, image) {
var a_image = findObj("item_details_image");
var a_lightbox = findObj("item_details_lightbox");
var a_image_src = a_image.src;
var filename = mfilename;
var img = new Image();
if (filename.indexOf("/stock/", 0) == -1) {
var img_big = "images/stock/big/" + filename;
img.src = "images/stock/small/" + filename;
} else {
var img_big = filename.replace("small/", "big/");
img.src = filename;
}
if ((a_image != null) && (a_lightbox != null)) {
var thumb_src = a_image.src;
thumb_src = thumb_src.replace("small/", "thumb/");
image.src = thumb_src;
image.onclick = function () {
showBigImageLightbox(a_image_src, width, height, image)
};
a_image.src = img.src;
a_lightbox.href = img_big;
}
}
function MM_reloadPage(init) { //reloads the window if Nav4 resized
if (init == true)
with (navigator) {
if ((appName == "Netscape") && (parseInt(appVersion) == 4)) {
document.MM_pgW = innerWidth;
document.MM_pgH = innerHeight;
onresize = MM_reloadPage;
}
}
else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH)
location.reload();
}
function changeMenuId(id) {
var dowhat = findObj("dowhat");
var mmenu_id = findObj("menu_id");
var mid = findObj("id");
var dowhat_search = findObj("dowhat_search");
var searchphrase = findObj("searchphrase");
var page = findObj("page");
if (page != null) {
page.value = 1;
}
var total_row_count = findObj("total_row_count");
if (total_row_count) {
total_row_count.value = 0;
}
var from_record = findObj("from_record");
if (from_record != null) {
from_record.value = 0;
}
if (mid != null) {
mid.value = 0;
}
if (mmenu_id != null) {
if (dowhat_search) {
dowhat_search.value = "";
searchphrase.value = "";
}
dowhat.value = "list";
mmenu_id.value = id;
if (window.sef_links_enabled) {
mySubmit('', absolute_local_script_url + 'sef/form_handler.php?page=listitems');
} else {
mySubmit('', absolute_local_script_url + 'getmodule.php?id=listitems.php');
}
}
}
function showItemLoading() {
var items_loading_layer = findObj("items_loading");
if (items_loading_layer) {
items_loading_layer.style.visibility = "visible";
}
}
function fullTextSearch() {
var searchphrase = findObj("searchphrase");
document.location = "/search/full/" + encodeURIComponent(searchphrase.value);
}
function changeId(id, msearch) {
var allow_submit = true;
var dowhat = findObj("dowhat");
var mid = findObj("id");
var loading = findObj("loading");
var page = findObj("page");
var process_step = findObj("process_step");
if (page != null) {
page.value = 1;
}
var from_record = findObj("from_record");
if (from_record != null) {
from_record.value = 0;
}
var searchphrase = findObj("searchphrase");
var dowhat_search = findObj("dowhat_search");
if (dowhat_search != null) {
dowhat_search.value = msearch;
}
var total_row_count = findObj("total_row_count");
if (total_row_count) {
total_row_count.value = 0;
}
if (msearch == "") {
if (searchphrase != null) {
searchphrase.value = "";
}
} else if (msearch == "clear_search") {
var mmenu_id = findObj("menu_id");
searchphrase.value = "";
mmenu_id.value = "";
}
if (process_step) {
process_step.value = 0;
}
if (loading) {
if (IE) { //Internet Explorer
loading.style.filter = "alpha(opacity=100);";
} else { //Safari & Mozilla
loading.style.opacity = 1;
}
var Opacity = 70;
if (IE) {
//loading.filters["alpha"].opacity = Opacity;
loading.style.filter = "alpha(opacity=" + Opacity + ");";
} else {
loading.style.opacity = (Opacity / 100);
}
}
if ((mid != null) || (msearch == "search")) {
dowhat.value = "list";
if (mid != null) {
mid.value = id;
}
if (msearch == "search") {
if (searchphrase.value.trim() == "") {
allow_submit = false;
}
}
if (allow_submit) {
document.location = "/search/any/" + encodeURIComponent(searchphrase.value);
}
}
}
function onChangeLanguage() {
if (sef_links_enabled) {
mySubmit('', absolute_local_script_url + 'sef/form_handler.php?page=index.php');
} else {
mySubmit('', 'index.php');
}
}
function onChangeCurrency() {
if (sef_links_enabled) {
mySubmit('', absolute_local_script_url + 'sef/form_handler.php?page=listitems');
} else {
mySubmit('', 'getmodule.php?id=listitems.php');
}
}
function getElementsByClassName(cl) {
var retnode = [];
var myclass = new RegExp('\\b' + cl + '\\b');
var elem = document.getElementsByTagName('*');
for (var i = 0; i < elem.length; i++) {
var classes = elem[i].className;
if (myclass.test(classes))
retnode.push(elem[i]);
}
return retnode;
}
function hideByClass(class_name) {
var elements = getElementsByClassName(class_name);
if (elements.length > 0) {
for (i = 0; i < elements.length; i++) {
elements[i].style.visibility = "hidden";
}
}
}
function showByClass(class_name) {
var elements = getElementsByClassName(class_name);
if (elements.length > 0) {
for (i = 0; i < elements.length; i++) {
elements[i].style.visibility = "visible";
}
}
}
function onEditChange(cnt) {
hideByClass("buttons");
var code = findObj("code_" + cnt);
var qty = findObj("qty_" + cnt);
var price = findObj("price_" + cnt);
var use_vat_p = findObj("use_vat_p_" + cnt);
var category_id = findObj("category_id_" + cnt);
var subcategory_id = findObj("subcategory_id_" + cnt);
if (category_id == null) {
category_id = findObj("menu_id");
subcategory_id = findObj("id");
}
var total_layer = findObj("total_layer_" + cnt);
var discount = findObj("discount_" + cnt);
var user_conversion_rate = findObj("user_conversion_rate");
var user_currency_symbol = findObj("user_currency_symbol");
var discount_system = findObj("discount_system");
var total_format = findObj("total_format");
var sign = "-";
var total = 0.00;
var testvalue = 0.00;
var total_discounted = 0.00;
var discount_percentage = 0.00;
var discount_value = 0.00;
var use_price = 0.00;
if (qty.value > 0) {
if ((qty != null) && (price != null) && (total_layer != null)) {
use_vat_p = Number(use_vat_p.value);
price = Number(price.value);
user_conversion_rate = Number(user_conversion_rate.value);
qty = Number(qty.value);
use_price = price;
if (discount_system.value == "qty") {
testvalue = qty;
} else {
testvalue = qty * price;
}
var Discount = GetDiscount(code.value, category_id.value, subcategory_id.value, testvalue);
var discount_is_percentage = false;
discount_is_percentage = ((Discount.discount != 0) || (Discount.default_discount != 0));
if (!CheckDiscountConditions(Discount.discount_id, Discount.discount_type, Discount.apply_condition_on)) {
if (discount_is_percentage) {
if (Discount.default_discount > 0) {
Discount.discount = Discount.default_discount;
} else {
Discount.discount = 0;
}
} else {
use_price = Discount.default_discounted_price;
}
}
if (!discount_is_percentage) {
use_price = Discount.discounted_price;
if (use_price == 0) {
use_price = price;
discount_is_percentage = true;
}
}
total = qty * use_price * user_conversion_rate * use_vat_p;
if (discount_is_percentage) {
discount_percentage = Discount.discount;
discount.value = discount_percentage;
discount_value = total * (discount_percentage / 100);
} else {
total = qty * price * user_conversion_rate * use_vat_p;
total_discounted = qty * use_price * user_conversion_rate * use_vat_p;
discount_value = total - total_discounted;
if (total > total_discounted) {
discount_percentage = 100 - ((total_discounted / total) * 100);
} else {
if (total != total_discounted) {
discount_percentage = (100 - (1 / (total_discounted / total) * 100));
sign = "+";
} else {
discount_percentage = 0;
}
}
}
if (total_format) {
if (total_format.value == 1) {
total_layer.innerHTML = user_currency_symbol.value + " " + (total - discount_value).toFixed(2);
}
} else {
if (discount_value != 0) {
total_layer.innerHTML = user_currency_symbol.value + " " + total.toFixed(2) + "
" + sign + " " + discount_percentage.toFixed(2) + "%
" + user_currency_symbol.value + " " + (total - discount_value).toFixed(2);
} else {
total_layer.innerHTML = user_currency_symbol.value + " " + total.toFixed(2) + "
";
}
}
}
}
showByClass("buttons");
}
function onSelectChange(cnt) {
hideByClass("buttons");
var qty = findObj("qty_" + cnt);
var price = findObj("price_" + cnt);
var use_vat_p = findObj("use_vat_p_" + cnt);
var code = findObj("code_" + cnt);
var category_id = findObj("category_id_" + cnt);
var subcategory_id = findObj("subcategory_id_" + cnt);
if (category_id == null) {
category_id = findObj("menu_id");
subcategory_id = findObj("id");
}
var total_layer = findObj("total_layer_" + cnt);
var mlayer = findObj("qty_layer_" + cnt);
var discount = findObj("discount_" + cnt);
var user_conversion_rate = findObj("user_conversion_rate");
var user_currency_symbol = findObj("user_currency_symbol");
var discount_system = findObj("discount_system");
var sign = "-";
var total = 0.00;
var testvalue = 0.00;
var total_discounted = 0.00;
var discount_percentage = 0.00;
var discount_value = 0.00;
var use_price = 0.00;
if ((qty == null) || (qty == "undefined")) {
qty = new Object();
qty.selectedIndex = 0;
qty.options = new Array("1");
qty.value = 1;
} else {
if (qty.nodeName.toUpperCase() == "INPUT") {
var qty_value = qty.value;
qty = new Object();
qty.selectedIndex = 0;
qty.options = new Array(qty_value);
qty.value = qty_value;
} else {
qty.value = (((qty.value == 0) || (qty.value == "")) ? 1 : qty.value);
}
}
if (qty != null) {
if ((qty.selectedIndex > 0) && (qty.options[qty.selectedIndex].value == "x")) {
if (mlayer != null) {
mlayer.innerHTML = "";
qty = findObj("qty_" + cnt);
if (qty != null) {
qty.focus();
}
}
} else {
if ((qty != null) && (price != null) && (use_vat_p != null) && (user_conversion_rate != null) && (total_layer != null)) {
use_vat_p = Number(use_vat_p.value);
price = Number(price.value);
user_conversion_rate = Number(user_conversion_rate.value);
qty = Number(qty.value);
use_price = price;
if (discount_system.value == "qty") {
testvalue = qty;
} else {
testvalue = qty * price;
}
var Discount = GetDiscount(code.value, category_id.value, subcategory_id.value, testvalue);
var discount_is_percentage = false;
discount_is_percentage = ((Discount.discount != 0) || (Discount.default_discount != 0));
if (!CheckDiscountConditions(Discount.discount_id, Discount.discount_type, Discount.apply_condition_on)) {
if (discount_is_percentage) {
if (Discount.default_discount > 0) {
Discount.discount = Discount.default_discount;
} else {
Discount.discount = 0;
}
} else {
use_price = Discount.default_discounted_price;
}
}
if (!discount_is_percentage) {
use_price = Discount.discounted_price;
if (use_price == 0) {
use_price = price;
discount_is_percentage = true;
}
}
total = qty * use_price * user_conversion_rate * use_vat_p;
if (discount_is_percentage) {
discount_percentage = Discount.discount;
discount.value = discount_percentage;
discount_value = total * (discount_percentage / 100);
} else {
total = qty * price * user_conversion_rate * use_vat_p;
total_discounted = qty * use_price * user_conversion_rate * use_vat_p;
discount_value = total - total_discounted;
if (total > total_discounted) {
discount_percentage = 100 - ((total_discounted / total) * 100);
} else {
if (total != total_discounted) {
discount_percentage = (100 - (1 / (total_discounted / total) * 100));
sign = "+";
} else {
discount_percentage = 0;
}
}
}
if (discount_value != 0) {
total_layer.innerHTML = user_currency_symbol.value + " " + total.toFixed(2) + "
" + sign + " " + discount_percentage.toFixed(2) + "%
" + user_currency_symbol.value + " " + (total - discount_value).toFixed(2);
} else {
total_layer.innerHTML = user_currency_symbol.value + " " + total.toFixed(2) + "
";
}
}
}
}
showByClass("buttons");
}
function pageChange(mdowhat, maction, up_or_down, pagination_identifier, page_select) {
if (window.page_changing_event == false) {
window.page_changing_event = true;
var may_submit = true;
var page = findObj(pagination_identifier);
if (up_or_down == -1) {
if (page_select != null) {
if (isNaN(page_select)) {
page.value = page_select.options[page_select.selectedIndex].value;
} else {
if (page) {
page.value = page_select;
}
}
}
} else if (up_or_down == 0) { //Previous Pages
page.value = "prev";
} else if (up_or_down == 1) { //Next Pages
page.value = "next";
}
if (may_submit) {
mySubmit(mdowhat, maction);
}
}
}
function pageShowAll(total_records, confirmed, obj) {
var rows_limit = findObj('rows_limit');
if (rows_limit) {
if (!confirmed) {
if (total_records > 100) {
ConfirmationBox('Please note that this page contains more than 100 items and may take some time to load. Are you sure you want to show all?', 'pageShowAll(' + total_records + ', true)', 'Yes, show all', 'No, cancel', '250', 30);
} else {
rows_limit.value = total_records;
mySubmit('', '');
}
} else {
rows_limit.value = total_records;
mySubmit('', '');
}
}
}
function autoPageChange(url) {
if ((url.length == 0) || (url == 'undefined')) {
this.location = "index.php?lm=" . Date.now();
} else {
this.location = url;
}
}
function timedAutoRedirect(url) {
setTimeout('autoPageChange(\'' + url + '\')', 2000);
}
function setButtonLoadState(mlayer) {
setLoadingImage(mlayer);
}
function killReturnKey(evt, sym_submit, method) {
//IMPORTANT: Do not use this method on a search box that makes use of preemptive_div_search.js
var mchar = "";
if (IE) {
mchar = evt.keyCode;
} else {
mchar = evt.charCode || evt.keyCode;
}
if (mchar == 13) {
if (IE) {
evt.returnValue = false;
evt.cancel = true;
} else {
evt.preventDefault();
}
if (sym_submit) {
eval(method);
}
return false;
}
}
function checkEvent(myevent, is_numeric, no_spaces, char_inclusion_list) {
char_inclusion_list = (typeof char_inclusion_list === 'undefined') ? [] : char_inclusion_list;
var mchar = 0;
if (IE) {
mchar = myevent.keyCode;
} else {
if (myevent.charCode > 0) {
mchar = myevent.charCode;
} else if (myevent.keyCode > 0) {
mchar = myevent.keyCode;
} else {
mchar = myevent.charCode + myevent.keyCode;
}
}
//alert(mchar);
if (mchar != 0) {
if (is_numeric) {
if ((mchar == 43) ||
(mchar == 46) || ((mchar > 47) && (mchar < 58)) ||
((mchar > 36) && (mchar < 41)) ||
(mchar == 8) ||
(mchar == 9) ||
(mchar == 35) ||
(mchar == 36) ||
(mchar == 45)) {
return true;
} else if ((char_inclusion_list.length > 0) && (char_inclusion_list.indexOf(mchar) >= 0)) { //Checks which characters to allow regardless of the result
return true;
} else {
return false;
}
} else if (no_spaces) {
if ((((mchar > 47) && (mchar < 91)) ||
((mchar > 96) && (mchar < 123)) ||
((mchar > 36) && (mchar < 41)) ||
(mchar == 33) ||
(mchar == 41) ||
(mchar == 43) ||
(mchar == 45) ||
(mchar == 44) ||
(mchar == 8) ||
(mchar == 9) ||
(mchar == 46) ||
(mchar == 35) ||
(mchar == 36) ||
(mchar == 95) ||
(mchar == 0)) &&
(!((mchar > 57) && (mchar < 63)))) {
return true;
} else if ((char_inclusion_list.length > 0) && (char_inclusion_list.indexOf(mchar) >= 0)) { //Checks which characters to allow regardless of the result
return true;
} else {
return false;
}
} else
if ((((mchar > 47) && (mchar < 91)) ||
((mchar > 96) && (mchar < 123)) ||
((mchar > 36) && (mchar < 41)) ||
(mchar == 32) ||
(mchar == 33) ||
(mchar == 41) ||
(mchar == 43) ||
(mchar == 45) ||
(mchar == 44) ||
(mchar == 8) ||
(mchar == 13) ||
(mchar == 46) ||
(mchar == 9) ||
(mchar == 35) ||
(mchar == 36) ||
(mchar == 0)) &&
(!((mchar > 57) && (mchar < 63)))) {
return true;
} else if ((char_inclusion_list.length > 0) && (char_inclusion_list.indexOf(mchar) >= 0)) { //Checks which characters to allow regardless of the result
return true;
} else {
return false;
}
} else {
return true;
}
}
function killUnwantedKeys(taObj, myevent, is_numeric, no_spaces, char_inclusion_list) {
char_inclusion_list = (typeof char_inclusion_list === 'undefined') ? [] : char_inclusion_list;
if (checkEvent(myevent, is_numeric, no_spaces, char_inclusion_list)) {
var preserve_whitespace = (taObj.getAttribute("data-preserve-whitespace") ? (taObj.getAttribute("data-preserve-whitespace") == "true") : false);
if (!preserve_whitespace) {
//Remove redundant whitespace chars. spaces, tabs etc.
var re = new RegExp(/\s{2,}/g);
if (re.test(taObj.value)) {
taObj.value = taObj.value.replace(re, ' ');
myevent.preventDefault();
}
}
} else {
if (IE) {
myevent.returnValue = false;
} else {
myevent.preventDefault();
}
}
}
var IndexArray = new Array();
function RemoveRec(itemindex) {
var itm = findObj("itemindex");
for (var i = 0; i <= IndexArray.length; i++) {
if (IndexArray[i] == itemindex) {
IndexArray.splice(i, 1);
}
}
itm.value = IndexArray;
}
function AddRec(itemindex) {
var itm = findObj("itemindex");
for (var i = 0; i < IndexArray.length; i++) {
if (IndexArray[i] == itemindex) {
return "";
}
}
IndexArray.push(itemindex);
itm.value = IndexArray;
}
function onSelectCheckBoxChange(obj, cnt) {
if (obj.checked) {
AddRec(cnt);
} else {
RemoveRec(cnt);
}
}
function selectAll(obj, cnt) {
IndexArray = new Array();
for (var i = 1; i <= cnt; i++) {
select_checkbox = findObj("select_" + i);
if (select_checkbox != null) {
select_checkbox.checked = obj.checked;
if (obj.checked){
IndexArray.push(i);
}
}
}
updateItemIndex(cnt);
}
function updateItemIndex(cnt) {
var itemindex = findObj("itemindex");
var index = "";
var add_comma = false;
if (itemindex != null) {
itemindex.value = "";
for (i = 1; i <= cnt; i++) {
select_checkbox = findObj("select_" + i);
if (select_checkbox != null) {
if (select_checkbox.checked) {
index += (add_comma ? "," : "") + i;
add_comma = true;
}
}
}
}
itemindex.value = index;
}
function editItem(mdowhat) {
var dowhat = findObj("dowhat");
var itm = findObj("itemindex");
if ((dowhat != null) && (itm != null)) {
dowhat.value = mdowhat;
itm.value = IndexArray;
if ((mdowhat == "edit") || (mdowhat == "edit_checkout")) {
document.frm.action = absolute_local_script_url + "getmodule.php?id=ajax_cartposting.php";
}
document.frm.submit();
}
}
function validateColourSize(colours_id_field, sizes_id_field, enable_colours, enable_sizes) {
var colours_r = "";
var sizes_r = "";
var colours_id = findObj(colours_id_field);
var sizes_id = findObj(sizes_id_field);
if (colours_id != null) {
if (enable_colours) {
colours_r = "R";
if (colours_id.value == 0) {
colours_id.value = "";
}
}
if (!(validateForm(colours_id_field, '', colours_r))) {
return false;
}
}
if (sizes_id != null) {
if (enable_sizes) {
sizes_r = "R";
if (sizes_id.value == 0) {
sizes_id.value = "";
}
}
if (!(validateForm(sizes_id_field, '', sizes_r))) {
return false;
}
}
return true;
}
function moreInfo(layer_name) {
var mlayer = findObj(layer_name);
if (mlayer) {
if ((mlayer.style.visibility == "hidden") || (mlayer.style.visibility == "")) {
mlayer.style.visibility = "visible";
mlayer.style.height = "60px";
} else {
mlayer.style.visibility = "hidden";
mlayer.style.height = "0px";
}
}
}
function getCart(sel, mdowhat, mlayer) {
var layer = findObj(mlayer);
if (layer != null) {
window.add_to_cart_layer_restore[sel] = new LayerRestore(layer, layer.innerHTML);
}
getCartMain(sel, mdowhat, mlayer);
}
function selectColour(mcolours_id, mcolour_chart_id, mdowhat, cnt) {
var colours_id = findObj("colours_id_" + cnt);
var colour_chart_id = findObj("colour_chart_id");
mcolours_id = (mcolours_id == "" ? 0 : mcolours_id);
mcolour_chart_id = (mcolour_chart_id == "" ? 0 : mcolours_id);
colours_id.value = mcolours_id;
colour_chart_id.value = mcolour_chart_id;
getColours('select', '', mcolours_id, mcolour_chart_id, 'selected_colour_layer');
}
/*---------------Validation------------------*/
function validateForm() { //v4.0
var i, p, q, nm, test, num, min, max, errors = '', args = validateForm.arguments;
for (i = 0; i < (args.length - 2); i += 3) {
test = args[i + 2];
val = findObj(args[i]);
if (val) {
nm = val.name;
if (val.alt) {
msg = val.alt;
} else {
msg = "";
}
if ((val = val.value) != "") {
if (test.indexOf('isEmail') != -1) {
p = val.indexOf('@');
if (p < 1 || p == (val.length - 1))
errors += '- ' + nm + ' must contain an e-mail address.\n';
} else if (test != 'R') {
num = parseFloat(val);
if (isNaN(val))
errors += '- ' + nm + ' must contain a number.\n';
if (test.indexOf('inRange') != -1) {
p = test.indexOf(':');
min = test.substring(8, p);
max = test.substring(p + 1);
if (num < min || max < num)
errors += '- ' + nm + ' must contain a number between ' + min + ' and ' + max + '.\n';
}
}
} else if (test.charAt(0) == 'R')
errors += (msg != '' ? '- ' + msg + '\n' : '- ' + nm + ' is required.\n');
}
}
if (errors) {
alert('The following error(s) occurred:\n' + errors);
}
return (errors == '');
}
/*------------------END----------------------*/
/*-----------------FaceBook----------------------*/
function fbs_click() {
u = location.href;
t = document.title;
window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436');
return false;
}
/*------------------END----------------------*/
/*--------- REMEMBER ME CHECKBOX ------------*/
function newCookie(name, value, days) {
var days = 365; // the number at the left reflects the number of days for the cookie to last
// modify it according to your needs
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
} else
var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameSG = name + "=";
var nuller = '';
if (document.cookie.indexOf(nameSG) == -1)
return nuller;
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ')
c = c.substring(1, c.length);
if (c.indexOf(nameSG) == 0)
return c.substring(nameSG.length, c.length);
}
return null;
}
function eraseCookie(name) {
newCookie(name, "", 1);
}
function saveLogin(path) {
var email = findObj("Email");
if (!email) {
email = findObj("Email_Inc");
}
var password = findObj("Password");
if (!password) {
password = findObj("Password_Inc");
}
newCookie('esolve_Email_' + path, email.value); // add a new cookie as shown at left for every
newCookie('esolve_Password_' + path, password.value); // field you wish to have the script remember
}
function saveLoginNoPassword(path) {
var email = findObj("Email");
if (!email) {
email = findObj("Email_Inc");
}
newCookie('esolve_Email_' + path, email.value); // add a new cookie as shown at left for every
}
function deleteLogin(path) {
eraseCookie('esolve_Email_' + path); // make sure to add the eraseCookie function for every field
eraseCookie('esolve_Password_' + path);
var email = findObj("Email");
if (!email) {
email = findObj("Email_Inc");
}
var password = findObj("Password");
if (!password) {
password = findObj("Password_Inc");
}
email.value = ''; // add a line for every field
password.value = '';
}
function restoreLogin(path) {
var email = findObj("Email");
if (!email) {
email = findObj("Email_Inc");
}
var password = findObj("Password");
if (!password) {
password = findObj("Password_Inc");
}
var rememberme = findObj("remember_me");
if (!rememberme) {
rememberme = findObj("remember_me_inc");
}
if (email) {
var email_address_cookie = "";
email_address_cookie = readCookie("esolve_Email_" + path); // Change the names of the fields at right to match the ones in your form.
if (email_address_cookie != "") {
email.value = email_address_cookie;
}
}
if (password) {
var password_cookie = "";
password_cookie = readCookie("esolve_Password_" + path); // Change the names of the fields at right to match the ones in your form.
if (password_cookie != "") {
password.value = password_cookie;
}
}
if (rememberme) {
if ((email.value != "") && (password.value != "")) {
rememberme.checked = true;
}
}
}
/*------------------END----------------------*/
/*-----------------AJAX----------------------*/
function ajaxObject(url, layer, callbackFunction) {
var that = this;
this.updating = false;
this.abort = function () {
if (that.updating) {
that.updating = false;
that.AJAX.abort();
that.AJAX = null;
}
};
this.update = function (passData, postMethod) {
if (that.updating) {
return false;
}
that.AJAX = null;
if (window.XMLHttpRequest) {
that.AJAX = new XMLHttpRequest();
} else {
that.AJAX = new ActiveXObject("Microsoft.XMLHTTP");
}
if (that.AJAX == null) {
return false;
} else {
that.AJAX.onreadystatechange = function () {
if (that.AJAX.readyState == 4) {
that.updating = false;
that.callback(that.AJAX.responseText, that.AJAX.status, that.AJAX.responseXML, layerCall);
that.AJAX = null;
}
};
that.updating = new Date();
if (/post/i.test(postMethod)) {
var id = passData.match(/id=ajax_[\s\S]+\.php/);
if (id != null) {
var uri = urlCall + '?' + id + '×tamp=' + that.updating.getTime();
that.AJAX.open("POST", uri, true);
that.AJAX.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
that.AJAX.setRequestHeader("Content-Length", passData.length);
that.AJAX.send(passData);
}
} else {
var uri = urlCall + '?' + passData + '×tamp=' + (that.updating.getTime());
that.AJAX.open("GET", uri, true);
that.AJAX.send(null);
}
return true;
}
};
var urlCall = url;
var layerCall = layer;
this.callback = callbackFunction || function () {
};
}
function locateScriptPostion(script_location) {
var index_start_1 = script_location.script_text.indexOf(" 0) && (index_start_2 > 0)) {
script_location.found = true;
script_location.script_code = script_location.script_text.substring(index_end_1, index_start_2);
} else {
script_location.found = false;
}
script_location.position = index_start_2 + 8;
return script_location;
}
function locateScripts(str) {
var expression = /