function OpenDebugWindow() { var debug_win debug_win = window.open('debug/debug_output.asp', 'debug_win' + '765277025','width=700,height=600,toolbar=yes,location=no,menubar=yes,resizable=yes,status=no,scrollbars=yes'); if (!debug_win.opener) debug_win.opener = window.self; debug_win.focus(); return; } function emailCheck (emailStr) { // The following pattern is used to check if the entered e-mail address // fits the user@domain format. It also is used to separate the username // from the domain. var emailPat = /^(.+)@(.+)$/ // The following string represents the pattern for matching all special // characters. We don't want to allow special characters in the address. // These characters include ( ) < > @ , ; : \ " . [ ] var specialChars = "\\(\\)<>@,;:\\\\\\\"\\.\\[\\]" // The following string represents the range of characters allowed in a // username or domainname. It really states which chars aren't allowed. var validChars = "\[^\\s" + specialChars + "\]" // The following pattern applies if the "user" is a quoted string (in // which case, there are no rules about which characters are allowed // and which aren't; anything goes). E.g. "jiminy cricket"@disney.com // is a legal e-mail address. var quotedUser = "(\"[^\"]*\")" // The following pattern applies for domains that are IP addresses, // rather than symbolic names. E.g. joe@[123.124.233.4] is a legal // e-mail address. NOTE: The square brackets are required. var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/ // The following string represents an atom (basically a series of // non-special characters.) var atom = validChars + '+' // The following string represents one word in the typical username. // For example, in john.doe@somewhere.com, john and doe are words. // Basically, a word is either an atom or quoted string. var word = "(" + atom + "|" + quotedUser + ")" // The following pattern describes the structure of the user var userPat = new RegExp("^" + word + "(\\." + word + ")*$") // The following pattern describes the structure of a normal symbolic // domain, as opposed to ipDomainPat, shown above. var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$") // Finally, let's start trying to figure out if the supplied address is // valid. // Begin with the coarse pattern to simply break up user@domain into // different pieces that are easy to analyze. var matchArray = emailStr.match(emailPat) if (matchArray == null) { //Too many/few @'s or something; basically, this address doesn't //even fit the general mould of a valid e-mail address. alert("Email address seems incorrect (check @ and .'s)") return false } var user = matchArray[1] var domain = matchArray[2] // See if "user" is valid if (user.match(userPat) == null) { // user is not valid alert("The email address doesn't seem to be valid.") return false } // if the e-mail address is at an IP address (as opposed to a symbolic // host name) make sure the IP address is valid. var IPArray = domain.match(ipDomainPat) if (IPArray != null) { // this is an IP address for (var i = 1 ; i <= 4; i++) { if (IPArray[i] > 255) { alert("Email destination IP address is invalid!") return false } } return true } // Domain is symbolic name var domainArray = domain.match(domainPat) if (domainArray == null) { alert("The email domain name doesn't seem to be valid.") return false } // domain name seems valid, but now make sure that it ends in a // three or four-letter word (like com, edu, gov, info) or a two-letter word, // representing country (uk, nl), and that there's a hostname preceding // the domain or country. // Now we need to break up the domain to get a count of how many atoms // it consists of. var atomPat = new RegExp(atom,"g") var domArr = domain.match(atomPat) var len = domArr.length if (domArr[domArr.length - 1].length < 2 || domArr[domArr.length-1].length > 4) { // the address must end in a two letter or three or four letter word. alert("The email address must end in a three or four-letter domain, or two letter country.") return false } // Make sure there's a host name preceding the domain. if (len < 2) { var errStr = "This email address is missing a hostname!" alert(errStr) return false } // If we've gotten this far, everything's valid! return true; } function CapitaliseEntry(frmObj) { // Function to allow only positive numeric decimal values to be allowed in a field. // Should be called on the onKeyDown, onKeyUp, onChange or onBlur event. var index; var tmpStr; var tmpChar; var preString; var postString; var strlen; tmpStr = frmObj.value.toLowerCase(); strLen = tmpStr.length; if (strLen > 0) { for (index = 0; index < strLen; index++) { if (index == 0) { tmpChar = tmpStr.substring(0,1).toUpperCase(); postString = tmpStr.substring(1,strLen); tmpStr = tmpChar + postString; } else { tmpChar = tmpStr.substring(index, index+1); if (tmpChar == " " && index < (strLen-1)) { tmpChar = tmpStr.substring(index+1, index+2).toUpperCase(); preString = tmpStr.substring(0, index+1); postString = tmpStr.substring(index+2,strLen); tmpStr = preString + tmpChar + postString; } } } } frmObj.value = tmpStr; } function chkpostcode(postcode, country) { var UcasePostCode; var lenPostCode; var j; var firstbit; var lenfirstbit; var secondbit; var lensecondbit; var nonalpha = /[^A-Z0-9]/; var nonchar = /[^A-Z]/; var badchars = /[C,I,K,M,O,V]/; //Only check the postcode if the customer is in the UK. if ((country.toUpperCase() == 'UNITED KINGDOM') || (country.toUpperCase() == 'UK') || (country.toUpperCase() == 'GREAT BRITAIN') || (country.toUpperCase() == 'GB') || (country.toUpperCase() == 'BRITISH ISLES')) { //Convert the postcode to upper case UcasePostCode = postcode.toUpperCase(); //Strip out all the spaces UcasePostCode = UcasePostCode.replace(" ",""); //Get the length of this string and if possible, //chop off the last three characters lenPostCode = UcasePostCode.length; if ((lenPostCode < 5) || (lenPostCode > 7)) { alert("You entered an incorrect length for the postcode. Please try again."); return(false); } else { firstbit = UcasePostCode.substr(0,lenPostCode - 3); lenfirstbit = firstbit.length; if ((lenfirstbit < 2) || (lenfirstbit > 4)) { alert("You entered an incorrect length for the postcode. Please try again."); return(false); } //Leave the wild card stuff for later //First character must be a char - not a number. if (firstbit.charAt(0).match(nonchar) == null) //Did NOT find any non A-Z characters. { //Check the rest of the characters are either digits or alphas for (j = 1; j < lenfirstbit; j++) { if (firstbit.charAt(j).match(nonalpha) != null) { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } } //Now work on the rest of the 'firstbit' switch (lenfirstbit) { case 2: // Format must be 'AN' if (firstbit.charAt(1).match(/\D/) != null) { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } break; case 3: // Format must be 'ANN', 'AAN' or 'ANA'. // Only 'AAN' need be checked as we know the // first char is alpha, // and all other chars are alpha or digit. //Check for the second and third characters if (firstbit.charAt(1).match(nonalpha) != null) //Found a nonalpha character { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } if (firstbit.charAt(1).match(/\D/) != null) // Found only characters { //3rd character must be N if (firstbit.charAt(2).match(/\D/) != null) { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } } break; case 4: // Format must be 'AANN' or 'AANA'. // So the second char must be alpha // and the third char must be a digit. if (firstbit.charAt(1).match(nonchar) != null || firstbit.charAt(2).match(/\D/) != null) { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } break; } //Now deal with the second part of the postcode switch (lenPostCode) { case 7: lensecondbit = lenPostCode - 4; break; case 6: lensecondbit = lenPostCode - 3; break; case 5: lensecondbit = lenPostCode - 2; break; } secondbit = UcasePostCode.substr(lenfirstbit,lensecondbit); if (secondbit.length < 3) { alert("You entered an incorrect length for the postcode. Please try again."); return(false); } //Format of 2nd part must be NAA if ( (secondbit.charAt(0).match(/\D/) != null) || (secondbit.charAt(1).match(nonchar) != null) || (secondbit.charAt(2).match(nonchar) != null) ) { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } // The AA bit must not contain C, I, K, M, O or V. if ( (secondbit.charAt(1).match(badchars) != null) || (secondbit.charAt(2).match(badchars) != null) ) { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } return(true); } else { alert("You entered an incorrect format for the postcode. Please try again."); return(false); } } } else { //Convert the postcode to upper case UcasePostCode = postcode.toUpperCase(); //Strip out all the spaces UcasePostCode = UcasePostCode.replace(" ",""); //Get the length of this string and if possible, //chop off the last three characters lenPostCode = UcasePostCode.length; if (lenPostCode < 4) { alert("You entered an incorrect length for the postcode. Please try again."); return(false); } else return(true); } } function restorebasket(yorn) { if (yorn == 'Y') { document.location.href = 'webstore/secure/restore_basket.asp'; } } var mydate = new Date(); var theYear = mydate.getFullYear(); var day = mydate.getDay(); var month = mydate.getMonth(); var daym = mydate.getDate(); if (daym < 10) daym = "0" + daym; var montharray = new Array("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"); var today = daym + " " + montharray[month] + " " + theYear; function checkdate(objName) { var datefield = objName; if (chkdate(objName) == false) { datefield.select(); alert("That date is invalid. Please try again."); datefield.focus(); return false; } if (doDateCheck(today, objName) == false) { objName.focus(); return (false); } return true; } function chkdate(objName) { var strDatestyle = "EU"; var strDate; var strDateArray; var strDay; var strMonth; var strYear; var intday; var intMonth; var intYear; var booFound = false; var datefield = objName; var strSeparatorArray = new Array("-"," ","/","."); var intElementNr; var err = 0; var strMonthArray = new Array(12); strMonthArray[0] = "Jan"; strMonthArray[1] = "Feb"; strMonthArray[2] = "Mar"; strMonthArray[3] = "Apr"; strMonthArray[4] = "May"; strMonthArray[5] = "Jun"; strMonthArray[6] = "Jul"; strMonthArray[7] = "Aug"; strMonthArray[8] = "Sep"; strMonthArray[9] = "Oct"; strMonthArray[10] = "Nov"; strMonthArray[11] = "Dec"; strDate = datefield.value; if (strDate.length == 0) return true; else if (strDate.length < 6) return false; for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) { if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) { strDateArray = strDate.split(strSeparatorArray[intElementNr]); if (strDateArray.length != 3) { err = 1; return false; } else { strDay = strDateArray[0]; strMonth = strDateArray[1]; strYear = strDateArray[2]; } booFound = true; } } if (booFound == false) { if (strDate.length>5) { strDay = strDate.substr(0, 2); strMonth = strDate.substr(2, 2); strYear = strDate.substr(4); } } if (strYear.length == 2) { strYear = '20' + strYear; } intday = parseInt(strDay, 10); if (isNaN(intday)) { err = 2; return false; } intMonth = parseInt(strMonth, 10); if (isNaN(intMonth)) { for (i = 0;i<12;i++) { if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) { intMonth = i+1; strMonth = strMonthArray[i]; i = 12; } } if (isNaN(intMonth)) { err = 3; return false; } } intYear = parseInt(strYear, 10); if (isNaN(intYear)) { err = 4; return false; } if (intMonth>12 || intMonth<1) { err = 5; return false; } if ((intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth == 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intday > 31 || intday < 1)) { err = 6; return false; } if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intday > 30 || intday < 1)) { err = 7; return false; } if (intMonth == 2) { if (intday < 1) { err = 8; return false; } if (LeapYear(intYear) == true) { if (intday > 29) { err = 9; return false; } } else { if (intday > 28) { err = 10; return false; } } } datefield.value = intday + " " + strMonthArray[intMonth-1] + " " + strYear; return true; } function LeapYear(intYear) { if (intYear % 100 == 0) { if (intYear % 400 == 0) { return true; } } else { if ((intYear % 4) == 0) { return true; } } return false; } function doDateCheck(today, reqd) { if (reqd.value == "") { alert("Please enter a Required date"); return false; } vtoday = new Date(today); vreqd = new Date(reqd.value); if (vtoday <= vreqd) { return true; } else { alert("The required date cannot be in the past"); return false; } } //var isDOM = (document.getElementById ? true : false); //var isIE4 = ((document.all && !isDOM) ? true : false); //var isNS4 = (document.layers ? true : false); //function getElementByID(id) //{ // if (isDOM) // return document.getElementById(id); // if (isIE4) // return document.all[id]; // if (isNS4) // return document.layers[id]; //} function NumericOnlyValue(strStringToEdit) { var strTrimmedString = new String(strStringToEdit); strTrimmedString = strTrimmedString.replace(/\D*/g, ""); return (strTrimmedString); } function Trim(strStringToTrim) { var strTrimmedString = new String(strStringToTrim); strTrimmedString = strTrimmedString.replace(/^ */, ""); strTrimmedString = strTrimmedString.replace(/ *$/, ""); return (strTrimmedString); } function RemoveSpaces(strStringToTrim) { var strTrimmedString = new String(strStringToTrim); strTrimmedString = strTrimmedString.replace(/ */g, ""); return (strTrimmedString); } function TopNavMouseOver(strCurrentApplicationArea) { if (document.getElementById('tn' + strCurrentApplicationArea).className != 'TopNavButtonActive') SetTopNavigationMenuTabsHover(strCurrentApplicationArea); } function TopNavMouseOut(strCurrentApplicationArea) { if (document.getElementById('tn' + strCurrentApplicationArea).className != 'TopNavButtonActive') UnSetTopNavigationMenuTabs(strCurrentApplicationArea); } function UnSetTopNavigationMenuTabs(strCurrentApplicationArea) { document.getElementById('tn' + strCurrentApplicationArea).className = 'TopNavButton'; document.getElementById('fn' + strCurrentApplicationArea).className = 'TopNavButtonFont'; } function SetTopNavigationMenuTabsHover(strCurrentApplicationArea) { document.getElementById('tn' + strCurrentApplicationArea).className = 'TopNavButtonHover'; document.getElementById('fn' + strCurrentApplicationArea).className = 'TopNavButtonFont'; } function SetTopNavigationMenuTabs(strCurrentApplicationArea) { if (document.getElementById('tn' + strCurrentApplicationArea)) { document.getElementById('tn'+strCurrentApplicationArea).className = 'TopNavButtonActive'; document.getElementById('fn'+strCurrentApplicationArea).className = 'TopNavButtonFontActive'; if (strCurrentApplicationArea == 'Checkout'){ //Disable the checkout button functionality if in the checkout process. //This is required more so when store replenishment/home delivery feature is on. //document.getElementById('tn'+strCurrentApplicationArea).firstChild.disabled = true; document.getElementById('tn'+strCurrentApplicationArea).firstChild.href = '#'; document.getElementById('tn'+strCurrentApplicationArea).firstChild.style.cursor = 'default'; } } } function DateAdd(intval, numb, base) { /*intval is YYYY, M, D, H, N, S as in VBscript; numb is amount +/-; base is javascript date object*/ switch(intval) { case "M": base.setMonth(base.getMonth() + numb); break; case "YYYY": base.setFullYear(base.getFullYear() + numb); break; case "D": base.setDate(base.getDate() + numb); break; case "H": base.setHours(base.getHours() + numb); break; case "N": base.setMinutes(base.getMinutes() + numb); break; case "S": base.setSeconds(base.getSeconds() + numb); break; default: } return base } function DateDiff(interval, start, end) { var iOut = 0, rounding=true; var bufferA = Date.parse(start); var bufferB = Date.parse(end ); // check that the start parameter is a valid Date. if ( isNaN (bufferA) || isNaN (bufferB) ) { return 0; } // check that an interval parameter was not numeric. if ( interval.charAt == 'undefined' ) { // the user specified an incorrect interval, handle the error. return 0; } var number = bufferB-bufferA; // what kind of add to do? switch (interval.charAt(0)) { case 'd': case 'D': iOut = parseInt(number / 86400000) + parseInt((number % 86400000) / 43200001); break ; case 'h': case 'H': iOut = parseInt(number / 3600000 ) + parseInt((number % 3600000) / 1800001); break ; case 'm': case 'M': iOut = parseInt(number / 60000 ) + parseInt((number % 60000) / 30001); break ; case 's': case 'S': iOut = parseInt(number / 1000 ) + parseInt((number % 1000) / 501); break ; default: // If we get to here then the interval parameter // didn't meet the d,h,m,s criteria. Handle // the error. return 0; } return iOut ; } function NewWindow(mypage,myname,w,h,scroll){ // LeftPosition = (screen.width) ? (screen.width-w)/2 : 0; // TopPosition = (screen.height) ? (screen.height-h)/2 : 0; LeftPosition = 100; TopPosition = 100; settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=no' win = window.open(mypage,myname,settings) if(win.window.focus){win.window.focus();} } function NewWindowResizeable(mypage,myname,w,h,scroll){ LeftPosition = 100; TopPosition = 100; settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable=yes' win = window.open(mypage,myname,settings) if(win.window.focus){win.window.focus();} } function leftTrim(sString) { while (sString.substring(0,1) == ' ') { sString = sString.substring(1, sString.length); } return sString; } function rightTrim(sString) { while (sString.substring(sString.length-1, sString.length) == ' ') { sString = sString.substring(0,sString.length-1); } return sString; } function trimAll(sString) { while (sString.substring(0,1) == ' ') { sString = sString.substring(1, sString.length); } while (sString.substring(sString.length-1, sString.length) == ' ') { sString = sString.substring(0,sString.length-1); } return sString; } //Browser detection functionality var isMac, isWindows, isIE, isNN, isIE5, isSafari, isFirefox, isMozilla isMac = (navigator.appVersion.indexOf("Mac") != -1); isWindows = (navigator.appVersion.indexOf("Windows") != -1); isIE = (navigator.appName == "Microsoft Internet Explorer") isNN = (navigator.appName == "Netscape") isIE5 = (navigator.appVersion.indexOf("MSIE 5") != -1) isSafari = (navigator.appVersion.indexOf("Safari") != -1); isFirefox = (navigator.userAgent.indexOf("Firefox") != -1); isMozilla = (navigator.userAgent.indexOf("Gecko") != -1 && navigator.userAgent.indexOf("Netscape") == -1 && navigator.userAgent.indexOf("Firefox") == -1 && navigator.userAgent.indexOf("Safari") == -1); //alert("isMac=" + isMac + " isWindows=" + isWindows + "isIE=" + isIE + " isNN=" + isNN + " isSafari=" + isSafari + " isFirefox=" + isFirefox);