// generic methods function IsDecimal(sText) { var regex = /^-?\d+(\.\d+)?$/ return regex.test(sText); } function IsPositiveDecimal(sText) { var regex = /^\d+(\.\d+)?$/ return regex.test(sText); } function IsInteger(sText) { var regex = /^-?\d+$/; // ^\d+$ any string containing one or more digits return regex.test(sText); } function IsPositiveInteger(sText) { var regex = /^\d+$/; // ^\d+$ any string containing one or more digits return regex.test(sText); } function IsFloat(sText) { return sText.length>0 && !(/[^0-9.]/).test(sText) && (/\.\d/).test(sText); } function IsPositiveFloat(sText) { if (IsFloat(sText) || IsInteger(sText)) if (Number(sText) >= 0) return true; return false; } function txtKeywordOnFocus() { document.getElementById("txtKeyword").value = ""; } function CleanQueryString(strRawString) { return strRawString.replace(",","%2C").replace("&","%26").replace(" ","%20"); } function RemoveNewLines(strRawString) { return strRawString.replace("\n", "_|_"); } function validateMandatoryPositiveIntegerGreaterThanZero(fieldId,message) { // ensures that an integer >0 is entered into a text field if (document.getElementById(fieldId).value == "") { alert(message); document.getElementById(fieldId).select(); document.getElementById(fieldId).focus(); return false; } if (!IsPositiveInteger(document.getElementById(fieldId).value)) { alert(message); document.getElementById(fieldId).select(); document.getElementById(fieldId).focus(); return false; } if (document.getElementById(fieldId).value == 0) { alert(message); document.getElementById(fieldId).select(); document.getElementById(fieldId).focus(); return false; } return true; } var InputCheckType = {"Text": 0, "Number": 1, "Date": 3 }; function validateTextFieldText(ctlId, checkType, alertMsg) { if (document.getElementById(ctlId)){ if (document.getElementById(ctlId).value != ""){ if (checkType == InputCheckType.Number){ if (isNaN(document.getElementById(ctlId).value)){ alert(alertMsg); setFocusTo(ctlId); return false; } } else if (checkType == InputCheckType.Date){ if (!isDateF(document.getElementById(ctlId).value, 'd/M/yyyy')){ alert(alertMsg); setFocusTo(ctlId); return false; } } } else { alert(alertMsg); setFocusTo(ctlId); return false; } } return true; } function setFocusTo(fieldId) { try { document.getElementById(fieldId).select(); document.getElementById(fieldId).focus(); } catch(e) { } } // source: http://www.web-source.net/web_development/currency_formatting.htm // author: William Bontrager // extracted: 17 09 2010 function CurrencyFormatted(amount) { var i = parseFloat(amount); if(isNaN(i)) { i = 0.00; } var minus = ''; if(i < 0) { minus = '-'; } i = Math.abs(i); i = parseInt((i + .005) * 100); i = i / 100; s = new String(i); if(s.indexOf('.') < 0) { s += '.00'; } if(s.indexOf('.') == (s.length - 2)) { s += '0'; } s = minus + s; return s; } function CommaFormatted(amount) { var delimiter = ","; // replace comma if desired var a = amount.split('.',2) var d = a[1]; var i = parseInt(a[0]); if(isNaN(i)) { return ''; } var minus = ''; if(i < 0) { minus = '-'; } i = Math.abs(i); var n = new String(i); var a = []; while(n.length > 3) { var nn = n.substr(n.length-3); a.unshift(nn); n = n.substr(0,n.length-3); } if(n.length > 0) { a.unshift(n); } n = a.join(delimiter); if(d.length < 1) { amount = n; } else { amount = n + '.' + d; } amount = minus + amount; return amount; } //end of extraction // -- end of generic methods // search methods function ibtnSearchClicked(debug) { var redirecturl = 'http://www.caregifts.org.au/care/scripts/doaction.aspx'; if (document.getElementById("txtKeyword").value == "" || document.getElementById("txtKeyword").value == strDefaultText) { alert("Please enter one or more keywords with ; or , between them."); document.getElementById("txtKeyword").focus(); document.getElementById("txtKeyword").select(); return false; } if (document.getElementById("ddlSearchOptions")) var strSearchValue = document.getElementById("ddlSearchOptions").options[document.getElementById("ddlSearchOptions").selectedIndex].value; else var strSearchValue = "All-272f1d66c82967de"; redirecturl += '?op=search'; redirecturl += "&searchtype=" + strSearchValue; redirecturl += "&searchvalue=" + CleanQueryString(document.getElementById("txtKeyword").value); if (debug == 1) redirecturl += '&debug=1'; location.href = redirecturl; return false; } function ibtnAdvancedSearchClicked(debug) { if (isWhitespace(document.advancedSearchForm.txtWithAnyOfTheWords.value) && isWhitespace(document.advancedSearchForm.txtWithAllOfTheWords.value) && isWhitespace(document.advancedSearchForm.txtWithTheExactPhrase.value) && isWhitespace(document.advancedSearchForm.txtWithout.value)) { alert('Please enter at least one word or phrase in one of the fields below.'); document.advancedSearchForm.txtWithAnyOfTheWords.select(); document.advancedSearchForm.txtWithAnyOfTheWords.focus(); return false; } var strSearchType = document.getElementById("ddlAdvancedSearchOptions").options[document.getElementById("ddlAdvancedSearchOptions").selectedIndex].value; var redirecturl = 'http://www.caregifts.org.au/care/scripts/doaction.aspx'; redirecturl += '?op=advancedsearch'; redirecturl += "&searchtype=" + strSearchType; if (!isWhitespace(document.advancedSearchForm.txtWithAnyOfTheWords.value)) redirecturl += '&searchwithany=' + CleanQueryString(document.advancedSearchForm.txtWithAnyOfTheWords.value); if (!isWhitespace(document.advancedSearchForm.txtWithAllOfTheWords.value)) redirecturl += '&searchwithall=' + CleanQueryString(document.advancedSearchForm.txtWithAllOfTheWords.value); if (!isWhitespace(document.advancedSearchForm.txtWithTheExactPhrase.value)) redirecturl += '&searchwithexact=' + CleanQueryString(document.advancedSearchForm.txtWithTheExactPhrase.value); if (!isWhitespace(document.advancedSearchForm.txtWithout.value)) redirecturl += '&searchwithout=' + CleanQueryString(document.advancedSearchForm.txtWithout.value); if (debug == 1) redirecturl += '&debug=1'; location.href = redirecturl; return false; } // end of search methods // basket methods function addToBasket(productid, qty, qtyRecipient, departmentid, productcatalogueid, productsubtypeid, promoCode, debug) { var redirecturl = 'http://www.caregifts.org.au/care/scripts/doaction.aspx'; redirecturl += '?op=addtobasket'; redirecturl += '&productid=' + productid; redirecturl += '&departmentid=' + departmentid; redirecturl += '&productcatalogueid=' + productcatalogueid; redirecturl += '&qty=' + qty; redirecturl += '&qtyrecipient=' + qtyRecipient; redirecturl += '&productsubtypeid=' + productsubtypeid; redirecturl += '&promotioncode=' + promoCode; if (debug == 1) redirecturl += '&debug=1'; //alert(redirecturl); location.href = redirecturl; } function addDonationToBasket(productid, qty, departmentid, productcatalogueid, amount, recurringperiod, productsubtypeid, debug) { var redirecturl = 'http://www.caregifts.org.au/care/scripts/doaction.aspx'; redirecturl += '?op=adddonationtobasket'; redirecturl += '&productid=' + productid; redirecturl += '&departmentid=' + departmentid; redirecturl += '&productcatalogueid=' + productcatalogueid; redirecturl += '&qty=' + qty; redirecturl += '&amount=' + amount; redirecturl += '&recurringperiod=' + recurringperiod; redirecturl += '&productsubtypeid=' + productsubtypeid; if (debug == 1) redirecturl += '&debug=1'; location.href = redirecturl; } function removeFromBasket(ordersessionproductid, ispackage) { var redirecturl = 'http://www.caregifts.org.au/care/scripts/doaction.aspx'; if (ispackage == 1) { redirecturl += '?op=removepackagefrombasket'; redirecturl += '&ordersessionproductpackageid=' + ordersessionproductid; } else { redirecturl += '?op=removefrombasket'; redirecturl += '&ordersessionproductid=' + ordersessionproductid; } location.href = redirecturl; } function configureGift(ordersessionproductid,debug) { var redirecturl = 'http://www.caregifts.org.au/care/scripts/doaction.aspx'; redirecturl += '?op=configuregift'; redirecturl += '&ordersessionproductid=' + ordersessionproductid; if (debug == 1) redirecturl += '&debug=1'; location.href = redirecturl; } // end of basket methods