/* FAQ */ function open_faq_category(div_id) { for (i = 1; i <= 60; i++) { $('#category_' + i).slideUp(); $('#category_' + i + '_arrow').attr('src', 'http://www.bpr-energie.ca/skins/default/media/images/arrow_right.png'); } slide_faq_div(div_id); } function slide_faq_div(div_id) { // Open if (document.getElementById(div_id).style.display == 'none') { $('#' + div_id).slideDown(); $('#' + div_id + '_arrow').attr('src', 'http://www.bpr-energie.ca/skins/default/media/images/arrow_bottom.png'); } // Close else { $('#' + div_id).slideUp(); $('#' + div_id + '_arrow').attr('src', 'http://www.bpr-energie.ca/skins/default/media/images/arrow_right.png'); } } function explode(item, delimiter) { tmp_array = new Array(1); var count = 0; var tempstring = new String(item); while (tempstring.indexOf(delimiter) > 0) { tmp_array[count] = tempstring.substr(0, tempstring.indexOf(delimiter)); tempstring = tempstring.substr(tempstring.indexOf(delimiter) + 1, tempstring.length - tempstring.indexOf(delimiter) + 1); count = count + 1; } tmp_array[count] = tempstring; return tmp_array; } function in_array(what, where) { var out = false; for (i=0; i < where.length; i++) { if (what == where[i]) { out = true; break; } } return out; } function print_1d_array(array) { document.write(""); document.write(""); for (row=0; row < array.length; row++) { document.write(""); } document.write(""); document.write("
" + array[row] + "
"); } function print_2d_array(array) { document.write(""); for (row=0; row < array.length; row++) { document.write(""); for (col=0; col < array[row].length; col++) { document.write(""); } document.write(""); } document.write("
" + array[row][col] + "
"); } function is_array(obj) { return obj && !(obj.propertyIsEnumerable('length')) && typeof obj === 'object' && typeof obj.length === 'number'; } function round_decimals(original_number, decimals) { var result1 = original_number * Math.pow(10, decimals); var result2 = Math.round(result1); var result3 = result2 / Math.pow(10, decimals); return pad_with_zeros(result3, decimals); } function pad_with_zeros(rounded_value, decimal_places) { // Convert the number to a string var value_string = rounded_value.toString(); // Locate the decimal point var decimal_location = value_string.indexOf('.'); // Is there a decimal point? if (decimal_location == -1) { // If no, then all decimal places will be padded with 0s decimal_part_length = 0; // If decimal_places is greater than zero, tack on a decimal point value_string += decimal_places > 0 ? '.' : ''; } else { // If yes, then only the extra decimal places will be padded with 0s decimal_part_length = value_string.length - decimal_location - 1; } // Calculate the number of decimal places that need to be padded with 0s var pad_total = decimal_places - decimal_part_length; if (pad_total > 0) { // Pad the string with 0s for (var counter = 1; counter <= pad_total; counter++) { value_string += '0'; } } return value_string; } function format_float(obj) { var o = document.getElementById(obj); var oo = o.value.replace(',', '.'); if (isFloat(oo)) { o.value = round_decimals(oo, 2); } else { o.value = ''; } } function toInt(n) { return n * 1; } function isFloat(n) { if (n == 0 || n == 0.00) { return false; } // Test for integer if ((n.length > 0) && !(/[^0-9]/).test(n)) { return true; } else { // Test for float if ((n.length > 0) && !(/[^0-9.]/).test(n) && (/\.\d/).test(n)) { return true; } else { return false; } } } function left(str, n) { if (n <= 0) { return ''; } else if (n > String(str).length) { return str; } else { return String(str).substring(0,n); } } function right(str, n) { if (n <= 0) { return ''; } else if (n > String(str).length) { return str; } else { var iLen = String(str).length; return String(str).substring(iLen, iLen - n); } } function mid(str, start, len) { // Make sure start and len are within proper bounds if (start < 0 || len < 0) { return ''; } var iEnd, iLen = String(str).length; if (start + len > iLen) { iEnd = iLen; } else { iEnd = start + len; } return String(str).substring(start,iEnd); } function trim(str, chars) { return ltrim(rtrim(str, chars), chars); } function ltrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("^[" + chars + "]+", "g"), ""); } function rtrim(str, chars) { chars = chars || "\\s"; return str.replace(new RegExp("[" + chars + "]+$", "g"), ""); } function check_email(email) { var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; if (filter.test(email)) { return true; } return false; }