/* ***Functions*** getDiscountTextBox() fu(node) - Adds one pecent up fd(node) - Adds one pecent down fu2(node) - Adds one pecent up to textboxes fd2(node) - Adds one pecent down to textboxes fy(node,number) - Adds pecents to rate addRecentage(node,number) - Adds pecents to rate textBox fo(node) - sets old value to discount box fr(node) - Reset. Set pecentage to 0; fr2(node) - Reset. Set base prices; fp(node) - Sets pecentage from dicount textBox to rate fc(node) - Sets needed color to rate's row fspg(node,id) - Show Map for postalGroupCode fsp(node,id) - Show Map for postal Code fsmap(node,id,type) - Show Map fcgm() - Close google Map formatNumber(number); addCommas(string); - puts commans to string as ###,###.## getNumber32(string); getNumber64(string); getElementsByClass(); setClassName; onResult - fires when ajax returns data isArray(obj); */ var currentDiscountTextBox; var currentDiscountTextBoxNodeID; var isInRequest = false; var cache; var url = 'http://app.gowdx.com:49005//';; var gmap; //google map object var gstatus; // gmap status var cachePolylines; var lastClick; var lastNode; function CacheClass(cname, cdata) { var data = cdata; var name = cname; } function getDiscountTextBox(node) { if (currentDiscountTextBoxNodeID == node.id) if (currentDiscountTextBox) return currentDiscountTextBox; var temp = getElementsByClass('m', node, 'input'); if (temp && temp.length > 0) { currentDiscountTextBoxNodeID = node.id; currentDiscountTextBox = temp[0]; return currentDiscountTextBox; } else { alert('Cannot find discount textbox'); } return null; } /*Pecente up*/ function fu(node) { fy(node, +1); } /*Pecente down*/ function fd(node) { fy(node, -1); } /*Pecente up*/ function fu2(nodeId, excludedIndexes) { var node = document.getElementById(nodeId); addRecentage(node, +2, excludedIndexes); } /*Pecente down*/ function fd2(nodeId, excludedIndexes) { var node = document.getElementById(nodeId); addRecentage(node, -2, excludedIndexes); } /*Set Old Value*/ function fo(node) { var control = getDiscountTextBox(node); control.oldValue = getNumber32(control.value); } /**/ function getNumber32(v) { v = parseInt(v); if (isNaN(v)) v = 0; return v; } function getNumber64(v) { // Replace ALL commas v = parseFloat(v.replace(/,/g, '')); //replace(',','')); if (isNaN(v)) v = 0; return Math.round(v * 100) / 100; } /*Reset*/ function fr(node) { var discountTextBox = getDiscountTextBox(node); if (getNumber32(discountTextBox.value) != 0) { discountTextBox.value = 0; fp(node); } } function fr2(nodeId, startIndex, values) { var node = document.getElementById(nodeId); var temp = getElementsByClass('r', node, 'input'); if (isArray(temp) && isArray(values)) { for (var index = startIndex; index < temp.length; index++) { var valueIndex = index - startIndex; if (valueIndex < values.length) temp[index].value = formatNumber(values[valueIndex]); } } } function isArray(obj) { return(typeof(obj.length) == 'undefined') ? false : true; } function formatNumber(number) { if (number == null) return null; return addCommas(number.toFixed(2)); } // moved to global.js // function addCommas(nStr) // { // nStr += ''; // x = nStr.split('.'); // x1 = x[0]; // x2 = x.length > 1 ? '.' + x[1] : ''; // var rgx = /(\d+)(\d{3})/; // while (rgx.test(x1)) { // x1 = x1.replace(rgx, '$1' + ',' + '$2'); // } // return x1 + x2; // } /**/ function fp(node) { var discountTextBox = getDiscountTextBox(node); var oldValue = 1 - getNumber32(discountTextBox.oldValue) / 100; var newValue = 1 - getNumber32(discountTextBox.value) / 100; if (node == null) node = document; var temp = node.getElementsByTagName('div'); var price; if (temp) { for (index = 0; index < temp.length; index++) { price = getNumber64(temp[index].innerText); temp[index].innerText = formatNumber(Math.round((price * newValue / oldValue) * 100) / 100); } discountTextBox.oldValue = newValue * 100; } else { alert('There is no price DIV tags'); } } function fy(node, add) { var discountTextBox = getDiscountTextBox(node); var oldValue = 1 - getNumber32(discountTextBox.value) / 100; var newValue = oldValue - (add / 100); if (node == null) node = document; var temp = node.getElementsByTagName('div'); var price; if (temp) { for (index = 0; index < temp.length; index++) { price = getNumber64(temp[index].innerText); temp[index].innerText = formatNumber(Math.round((price * newValue / oldValue) * 100) / 100); } discountTextBox.oldValue = discountTextBox.value; discountTextBox.value = getNumber32(discountTextBox.value) + add; } else { alert('There is no price DIV tags'); } } function addRecentage(node, add, excludedIndexes) { if (node == null) node = document; var inputs = node.getElementsByTagName('input'); if (inputs) { var price; var priceInputIndex = 0; for (var index = 0; index < inputs.length; index++) { var input = inputs[index]; // Filter price input boxes if ((input.className == 'r') && (input.type == 'text')) { if (!containsValue(excludedIndexes, priceInputIndex)) { price = getNumber64(input.value); input.value = formatNumber(price + price / 100 * add); } priceInputIndex++; } } } } function containsValue(array, value) { if (!array) return false; for (var index = 0; index < array.length; index++) { if (array[index] == value) return true; } return false; } function fc(nodeId) { var node = document.getElementById(nodeId); var styles = new Array('p;p2', 'g;g2'); var currentStyle; for (index = 0; index < styles.length; index++) { currentStyle = styles[index].split(';'); if (node.className == currentStyle[0]) { node.className = currentStyle[1]; break; } else if (node.className == currentStyle[1]) { node.className = currentStyle[0]; break; } } } function setClassName(obj, className) { obj.className = className; } function getElementsByClass(searchClass, node, tag) { var classElements = new Array(); if (node == null) node = document; if (tag == null) tag = '*'; var els = node.getElementsByTagName(tag); var elsLen = els.length; var pattern = new RegExp('(^|\\s)' + searchClass + '(\\s|$)'); for (index = 0, j = 0; index < elsLen; index++) { if (pattern.test(els[index].className)) { classElements[j] = els[index]; j++; } } return classElements; } function findPosX(obj) { var curleft = 0; if (obj.offsetParent) { while (obj.offsetParent) { curleft += obj.offsetLeft; obj = obj.offsetParent; } } else if (obj.x) curleft += obj.x; return curleft; } function findPosY(obj) { var curtop = 0; if (obj.offsetParent) { while (obj.offsetParent) { curtop += obj.offsetTop; obj = obj.offsetParent; } } else if (obj.y) curtop += obj.y; return curtop; } function fspg(node, groupCodeId) { var node = document.getElementById(node); fsmap(node, groupCodeId, 'pgcid'); } function fsp(nodeId, postalCodeId) { var node = document.getElementById(nodeId); fsmap(node, postalCodeId, 'pcid'); } function fsmap(node, id, type) { if (lastClick == id) { fcgm(); return null; } var postalGroupID = id; if (isInRequest == false) { if (gbar) { if (gmap == null) loadGmap(); gbar.style.pixelTop = (findPosY(node) + 25); gbar.style.visibility = 'visible'; lastNode = node; //Check cache if (cache != null && cache.name == postalGroupID) { addOverLayToGmap(cache.data); } else { isInRequest = true; gmap.clearOverlays(); gstatus.innerText = 'Loading data ...'; window.setTimeout(function timer() { Http.get({ url: url + 'googleMapDataPage.aspx?' + type + '=' + postalGroupID, callback: onResult }, postalGroupID); }, 250); } } } lastClick = id; } function fcgm() { if (gbar != null) { gbar.style.visibility = 'hidden'; if (lastNode != null) { lastNode.style.marginBottom = '0px'; lastNode = null; } } lastClick = null; } function onResult(result, postalGroupID) { if (result.status == Http.Status.OK) { addOverLayToGmap(result.responseText); cache = new CacheClass(postalGroupID, result.responseText); isInRequest = false; } } //Load google map function loadGmap() { if (GBrowserIsCompatible()) { gmap = new GMap2(document.getElementById('map')); gstatus = document.getElementById('gstatus'); if (gmap) { gmap.addControl(new GSmallMapControl()); gmap.setCenter(new GLatLng(37.4419, -122.1419), 13); } } } //Adds overlay from script data function addOverLayToGmapOld(script) { if (gmap != null) { gmap.clearOverlays(); // document.body.style.cursor = 'waite'; // try{eval(script);} // catch(err){alert(err)} // document.body.style.cursor = 'point'; } } function addPolylinesToMap(polylines) { gmap.clearOverlays(); if (polylines != null) { for (index = 0; index < polylines.length; index++) { gmap.addOverlay(polylines[index]); } } gstatus.innerText = ''; } function addOverLayToGmap(data) { gmap.clearOverlays(); var polylines = data.split('\n'); var vertexes; var arr; cachePolylines = new Array(); try { for (index = 0; index < polylines.length; index++) { if (polylines[index].length != 0) { vertexes = polylines[index].split(','); arr = new Array(vertexes.length / 2 - 1); var b = 0; for (a = 0; a < vertexes.length; a = a + 2) { if (a > 0) { arr[b] = e(vertexes[a], vertexes[a + 1]); b++; } } arr[arr.length] = e(vertexes[2], vertexes[3]); if (arr.length > 0) { cachePolylines[index] = new GPolyline(arr, '#ff0000', 2, 1); // gmap.addOverlay(); gmap.setCenter(e(vertexes[0], vertexes[1]), 8); } } } } catch (err) { gstatus.innerText = 'Cannot get a map of region'; // alert(err); } //Gets off wait cursor window.setTimeout('addPolylinesToMap(cachePolylines)', 500); isInRequest = false; } function e(x, y) { return new GLatLng(x, y); }