var xmlProdCat = {
QtyDecimals: 2
};
/************************************************************************************
*** START ADD TO CART FUNCTIONS *****************************************************
************************************************************************************/
function ValidateATCQtyForm(){
return false;
}
/************************************************************************************
*** END ADD TO CART FUNCTIONS *******************************************************
************************************************************************************/
/************************************************************************************
*** START GENERAL FUNCTIONS *********************************************************
************************************************************************************/
// Trim white space from beginning and end of string
function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
// URL Encode a string
function URLEncode(string) {
// The Javascript escape and unescape functions do not correspond
// with what browsers actually do...
var SAFECHARS = "0123456789" + // Numeric
"ABCDEFGHIJKLMNOPQRSTUVWXYZ" + // Alphabetic
"abcdefghijklmnopqrstuvwxyz" +
"-_.!~*'()"; // RFC2396 Mark characters
var HEX = "0123456789ABCDEF";
var plaintext = string
var encoded = "";
for (var i = 0; i < plaintext.length; i++ ) {
var ch = plaintext.charAt(i);
if (ch == " ") {
encoded += "+"; // x-www-urlencoded, rather than %20
} else if (SAFECHARS.indexOf(ch) != -1) {
encoded += ch;
} else {
var charCode = ch.charCodeAt(0);
// Unicode Character cannot be encoded using standard URL encoding. (URL encoding only supports 8-bit characters.) A space (+) will be substituted."
if (charCode > 255) {
encoded += "+";
} else {
encoded += "%";
encoded += HEX.charAt((charCode >> 4) & 0xF);
encoded += HEX.charAt(charCode & 0xF);
}
}
} // for
return encoded;
};
// Is an array?
function isArray() {
return arguments[0] instanceof Array;
}
// Is a regular expression?
function isRegExp() {
return arguments[0] instanceof RegExp;
}
// Is a string?
function isString() {
if (typeof arguments[0] == 'string')
return true;
if (typeof arguments[0] == 'object') {
var criterion = arguments[0].constructor.toString().match(/string/i);
return (criterion != null);
}
return false;
}
// Divide a string in to two parts on a divider
function divide(string, divider) {
var strReplace = genID();
string = string.replace(divider,strReplace);
return Array(string.split(strReplace)[0],string.split(strReplace)[1]);
}
// Create an XMLHttpRequest object
function createRequestObject(){
var request_o;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer"){
request_o = new ActiveXObject("Microsoft.XMLHTTP");
}else{
request_o = new XMLHttpRequest();
}
return request_o;
}
// Decimal to Hexadecimal
function dec2hex(dec) {
var hD="0123456789ABCDEF";
var hex = hD.substr(dec&15,1);
while (dec>15) {
dec >>= 4;
hhex = hD.substr(dec&15,1) + hex;
}
return hex;
}
// Hexadecimal to Decimal
function hex2ddec(hex) {
return parseInt(hex,16);
}
// Generate 32 character hex ID
function genID() {
var id = "";
var i;
for (i = 0; i < 32; i++) {
id = id + dec2hex(Math.round(16*Math.random()));
}
return id;
}
// AJAX call for Lightbox
function GetResults(pagename,key,qstring) {
document.getElementById('popup_search_results').innerHTML = '
Loading page. Please wait...
';
var requestUrl = 'i_i_' + pagename + '?' + qstring + '&key=' + key;
http = createRequestObject();
http.open('get', requestUrl);
http.onreadystatechange = WriteResults;
http.send(null);
}
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 NumbersOnly(myfield, e){
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==27) ) {
return true;
} // no enters or spaces
else if ((key==13) || (key==32)) {
return false;
} // only one deicmal
else if (keychar=='.' && myfield.value.indexOf('.')>-1) {
return false;
}// numbers
else if ((("0123456789.").indexOf(keychar) > -1) && xmlProdCat.QtyDecimals > 0) {
return true;
}
else if (isNaN(myfield.value)){
//alert('isNaN');
myfield.value = '';
return false;
} else {
return false;
}
}
function NumbersOnlyWithDecimal(myfield, e){
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) || (key==9) || (key==27) )
return true;
// no enters or spaces
else if ((key==13) || (key==32))
return false;
// only one deicmal
else if (keychar=='.' && myfield.value.indexOf('.')>-1)
return false;
// numbers
else if ((("0123456789.").indexOf(keychar) > -1))
return true;
else
return false;
}
function getQueryVariable(vQSVar) {
var strQuery = window.location.search.substring(1);
var aVars = strQuery.split('&');
for (var iVar = 0; iVar < aVars.length; iVar++) {
var aQS = aVars[iVar].split('=');
if (aQS[0]==vQSVar) {
return aQS[1];
}
}
}
function isDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
//alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
return false;
}
month = matchArray[1]; // p@rse date into variables
day = matchArray[3];
year = matchArray[5];
if (month < 1 || month > 12) { // check month range
//alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
//alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
//alert("Month "+month+" doesn`t have 31 days!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day > 29 || (day==29 && !isleap)) {
//alert("February " + year + " doesn`t have " + day + " days!");
return false;
}
}
return true; // date is valid
}
function escapeHTML(str){
var div = document.createElement('div');
var text = document.createTextNode(str);
div.appendChild(text);
return div.innerHTML;
}
/************************************************************************************
*** END GENERAL FUNCTIONS *********************************************************
*************************************************************************************/