///////////////////////////////////////////////////////////////////////////////////// // SIMBAD JAVASCRIPT APIs // // Used in FO Modules // // // // © Abside Informatiques 1998-2003 // // Release 5.2003-2 (07/03/2003) // // -------------- History -------------------------- // // See functions History for more details // // -------------- Content ------------------------- // // Utility functions : // // replaceSubstring, isblank, trim, containshex, // // checkField, checkEmail, removeparamandgo, // // removeparam, databasename, getparam, atrightback // // Simbad specific functions : // // simpleQuery, extendedQuery, getjsmsg, getjsmsglang, // // validateFields, rechframes, switchtolang, switchtocurr, // // isOrderAutoCompute, deleteCartLine, goToShoppingCart, // // goBackToList, viewFavOrder, getListPageURL, payment, // // removeOrder // ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// // Global variables & functions // // -------------- Description --------------------- // // These elements are used by all pages and forms displayed with // // a web browser. // // user context and cookie managment // // -------------- History -------------------------- // // - 18/02/2003 : Usage of config document instead of // // profile documents // // - 09/04/2003 : Added list element variables // ///////////////////////////////////////////////////////////////////////////////////// // Giftcard and Favorite orders add-on modules. // filepath of databases read from the general configuration document in the Configuration module. var gcpath = new String("C1256D780043E485"); var favpath= new String(""); // Test if using a Notes client or a web browser. Do not execute if using a Notes client. if (navigator.appName != "Lotus Notes" ) { // Get the cookie's duration from the configuration document var cookielife=7; var myurl; var dbname; myurl=document.URL; index=myurl.indexOf(".nsf"); dbname=myurl.substring(0,index+4); var affcode=getparam(self.location.href,"affiliate"); if (document.cookie.indexOf("SimbadId=")==-1) { // If cookie was not found, create an ID and cookie var inXdays=new Date(); var now=new Date(); inXdays.setDate(inXdays.getDate()+cookielife); var val=now.getTime()+ Math.ceil(Math.random()*1000); // cookie's value is random. Takes the data to the ms + 3 random digits document.cookie="SimbadId=" + val+ "; expires=" + inXdays.toGMTString() + " ; path=/"; if(!document.cookie) { // If cookie still can't be found, There is an error. Return that error to the user var ln=getparam(self.location.href,"lang"); if (ln=="") {ln="1";} alert(getjsmsg('err_cookie',ln)) history.back(); } else { // Executed when cookie is found. Agent is launched to create the new context var usrdb="/C1256CF2004DCD1A"; var agentname="/contexthandler?OpenAgent"; // Get the request parameters var start; var parameters; parameters=""; start=myurl.indexOf("&"); if (start!=-1) { parameters=myurl.substring(start,myurl.length); } myurl=usrdb+agentname+parameters; window.location.replace(myurl+"&load="+escape(location.href)) window.focus(); } } if(affcode !="") { // check if affiliate cookie is set if (document.cookie.indexOf("aff=")==-1) { // If cookie was not found, create a cookie inXdays=new Date(); now=new Date(); inXdays.setDate(inXdays.getDate()+30); // cookie's value is random. Takes the data to the ms + 3 random digits document.cookie="aff=" + affcode + "; expires=" + inXdays.toGMTString() + " ; path=/"; } } } ///////////////////////////////////////////////////////////////////////////////////// // Utility functions // // These general functions may be used in any context // // - 19/02/2003 : Added trim function // ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// // replaceSubstring // // inputString: string to search into // // badString: substring to be replaced in inputString // // goodString: string to replace badString with // // caseSensitive: boolean. // // -------------- Description --------------------- // // This function receives a string (inputString) and replaces every // // occurence of badString in inputString with goodString. // // if caseSensitive is True, replaces only the exact case occurences of // // badString in inputString // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function replaceSubstring(inputString, badString, goodString, caseSensitive) { fixedReplace = ""; UI = inputString; UB = badString; if ((caseSensitive != 1) && (caseSensitive != true)) { UI = inputString.toUpperCase(); UB = badString.toUpperCase(); } badEnd = -1; badLoc = UI.indexOf(UB); if (badLoc != -1) { for (x=1; (badLoc != -1); x++) { fixedReplace = fixedReplace + inputString.substring((badEnd + 1), badLoc) + goodString; badEnd = badLoc + UB.length - 1; badLoc = UI.indexOf(UB, (badLoc + 1)); } fixedReplace = fixedReplace + inputString.substring((badEnd + 1), inputString.length); } else { fixedReplace = inputString; } return fixedReplace; } ///////////////////////////////////////////////////////////////////////////////////// // isblank // // s: string to search into // // -------------- Description --------------------- // // This function receives a string (s) and search for a space, tab // // or newline character. If one is found, returns false. // // -------------- History -------------------------- // // This function has deprecated due to the addition of the trim // // function // ///////////////////////////////////////////////////////////////////////////////////// function isblank(s) { for (var i = 0 ; i < s.length ; i++) { var c = s.charAt(i); if ((c != ' ') && (c != '\n') && (c != '\t')) return false; } return true; } ///////////////////////////////////////////////////////////////////////////////////// // trim // // str: string to search into // // -------------- Description --------------------- // // This function receives a string (str) and search for a substring // // composed of several spaces and trims the string. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function trim(str) { var trimstr = "" if (str.charAt(0) != " ") { trimstr = str.charAt(0) } for (i=1; i < str.length; i++) { j = i - 1 if (str.charAt(i) != " ") { trimstr += str.charAt(i) } else { if (str.charAt(i) == " " && str.charAt(j) != " "){ trimstr += str.charAt(i) } } } if (trimstr.charAt(trimstr.length-1) == " ") { trimstr = trimstr.substring(0, trimstr.length - 1) } return trimstr } ///////////////////////////////////////////////////////////////////////////////////// // containshex // // s: string to search into // // message: message to return in case true // // -------------- Description --------------------- // // This function receives a string (s) and a message to display. // // If a non alphanumeric character is found a message is displayed. // // These characters are searched by their hexadecimal code. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function containshex(s,message) { for (var i = 0 ; i < s.length ; i++) { var c = s.charCodeAt(i); if (!((c ==45 ) || (c ==46) || (c ==95) || ((c>47) && (c<58)) || ((c>6) && (c<91)) || ((c>96) && (c<123)))) { alert(message); return true; } } return false; } ///////////////////////////////////////////////////////////////////////////////////// // checkValue // // name: name of the field to check // // val: value of the field to check // // msg: message to display if value is wrong // // -------------- Description --------------------- // // If value is empty, display the error message. // // -------------- History -------------------------- // // This function has deprecated due to the modification of the // // checkField function // ///////////////////////////////////////////////////////////////////////////////////// function checkValue(name, val, msg) { if (trim(val)=="") { alert( msg ); return false; } return true; } ///////////////////////////////////////////////////////////////////////////////////// // checkField // // field: Field to check upon Form's validation // // msg: message to display if value is wrong // // -------------- Description --------------------- // // Checks the value of a field // // For a select-one field, selected value must never be the first. // // -------------- History -------------------------- // // - 19/02/2003 : Function completely modified. It does not // // call the checkValue function any more // // - 11/03/2003 : Function does not display any message. // ///////////////////////////////////////////////////////////////////////////////////// function checkField(field) { var result = true; switch (field.type) { // Check a text field case "text": if (trim(field.value)=="") { result = false; } break; // Check a text area field case "textarea": if (trim(field.value)=="") { result = false; } break; // Check a single selection drop-down list field case "select-one": if ( field.selectedIndex == 0 ) { result = false; } break; // Check a multiple selection drop-down field case "select-multiple": if ( field.selectedIndex == -1 ) { result = false; } break; // Check a checkbox field case "checkbox": hasChecked = false; p = eval("field.form." + field.name); for (var r=0; r < p.length; r++) { if ( p[r].checked ) { hasChecked = true }; } if (!hasChecked) { result = false; } break; // Check a radio button field case "radio": hasChecked = false; p = eval("field.form." + field.name); for (var r=0; r < p.length; r++) { if ( p[r].checked ) { hasChecked = true }; } if (!hasChecked) { result = false; } break; default: break; } return result; } ///////////////////////////////////////////////////////////////////////////////////// // checkEmail // // email: Field to check upon Form's validation // // mess: message to display is value is wrong // // -------------- Description --------------------- // // Checks whether the email value is of the form: // // user@domain.ext. // // This function does not check the validity of the domain name. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function checkEmail(email,mess) { form=document.forms[0]; var lang=form.languageNumber.value; // If email does not contain a ".", this is not an email address if (email.lastIndexOf(".")==-1) { alert ( mess); return true; } else { domain=email.slice(email.lastIndexOf(".")+1).toLowerCase(); } // Return an error if the domain part is not valid if ((email.indexOf('@')==-1) || (domain.length<2) || (domain.length>3) || (((domain.length==3) && !((domain =="com") || (domain =="edu") || (domain =="org") || (domain =="gov" ) || (domain =="mil") || (domain =="net") || (domain =="int")))) || (email.slice(0,email.indexOf("@"))=="") || isblank(email.slice(0,email.indexOf("@"))) || (containshex(email,getjsmsg("err_car",lang)))) { alert(mess); return true } // Return false is email address is right else return false; } ///////////////////////////////////////////////////////////////////////////////////// // removeparamandgo // // url: URL to parse in order to find the parameter // // param: parameter to find in the URL // // value: value to add in the URL // // -------------- Description --------------------- // // This function replaces a parameter in a URL with a new value // // and changes the location of the window // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function removeparamandgo(url, param,value) { var url2go=url var start=url.indexOf("&"+param); if (start!=-1) { var end= url.indexOf("&",start+1) if (end==-1) {end=url.length;} url2go=url.substring(0,start) + url.substring(end,url.length); } // replace the parameter with the new value in the URL url2go=url2go+"&"+param+"=" + value // change the windows location with the new URL location=url2go } ///////////////////////////////////////////////////////////////////////////////////// // removeparam // // url: URL to parse in order to find the parameter // // param: parameter to find in the URL // // value: value to add in the URL // // -------------- Description --------------------- // // This function replaces a parameter in a URL with a new value // // and returns the new URL // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function removeparam(url, param,value) { var url1=new String(url) var url2go=new String(url1); var start=url1.indexOf("&"+param); if (start!=-1) { var end= url1.indexOf("&",start+1); if (end==-1) {end=url1.length;} url2go=url1.substring(0,start) + url1.substring(end,url1.length); } // if document does not contain ? nor !, create a Domino command by default if ((url2go.indexOf("?")==-1 ) && (url2go.indexOf("!")==-1)) { url2go=url2go+"?opendocument"; } url2go=url2go+"&"+param+"=" + value return(url2go); } ///////////////////////////////////////////////////////////////////////////////////// // databasename // // -------------- Description --------------------- // // This function returns the current database URL without // // the opened element // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function databasename() { var curloc=new String(); var result; curloc=window.location.href; if (curloc.indexOf(".nsf") !=-1) { // database specified by its file name result=curloc.substring(0,curloc.indexOf(".nsf")+4); } else { //la base est spécifiée par son unid curpath=window.location.pathname; result="http://" + window.location.host+"/"+curpath.substring(1,curpath.indexOf("/",1)); } return(result); } ///////////////////////////////////////////////////////////////////////////////////// // getparam // // url: URL to parse in order to find the parameter // // param: parameter to find in the URL // // -------------- Description --------------------- // // This function returns the value of a specified parameter in the // // URL. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function getparam(url, param) { var url1=new String(url) var url2=new String(url1); var start=url1.indexOf("&"+param); if (start!=-1) { var end= url1.indexOf("&",start+1); if (end==-1) {end=url1.length;} return (url1.substring (url1.indexOf("=",start+1)+1,end)); } // if parameter is not found, return empty string return(""); } ///////////////////////////////////////////////////////////////////////////////////// // atRightBack // // aString: string containing the substring to substract // // separator: character or string which separates the left part and // // the returned part of the string // // -------------- Description --------------------- // // This function is used to return the part of the string to the right of // // the rightmost occurence of a pattern // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function atRightBack (aString,separator) { ind=aString.lastIndexOf(separator) return (aString.substring(ind+1,aString.length)) } ///////////////////////////////////////////////////////////////////////////////////// // Simbad specific functions // // These general functions may be used in any context // // - 20/05/2003 : Added payment function // // - 03/06/2003 : Replaced validateOrder function with // // validateFields function. // // - 16/06/2003 : Added removeOrder function // ///////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////// // simpleQuery // // win: window in which result is displayed // // query: text query // // -------------- Description --------------------- // // This function launches a simple query and displays the result in // // the specified window. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function simpleQuery(win, query) { var url; url=databasename()+"/queryview/query?opendocument&query="+escape(query); win.location=url; } ///////////////////////////////////////////////////////////////////////////////////// // extendedQuery // // win: window in which result is displayed // // query: text query // // -------------- Description --------------------- // // This function launches an extended query and displays the result // // in the specified window. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function extendedQuery(win, query) { var url; url=databasename()+"/queryview/query?opendocument&srch=ext&query="+escape(query); win.location=url; } ///////////////////////////////////////////////////////////////////////////////////// // getjsmsg // // msgtoget: id of the message to recover // // langnum: number of the language to display the message // // -------------- Description --------------------- // // This function gets a message in the desired language // // according to its id. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function getjsmsg(msgtoget,langnum) { var result=""; var i = 0; // verify if the message array is available if(msgjs==null) { // return the empty string is array is not available return(result); } else { // if array is available, look for the message for (i=0;;i++) { // browse the first column of the array until message is found if (msgjs[i+","+0]==msgtoget) { // if message is found, return the string in the desired language result=msgjs[i+","+langnum]; break; } if (msgjs[i+","+0]==null) { // if not, then return the empty string result=""; break; } } return(result); } } ///////////////////////////////////////////////////////////////////////////////////// // getjsmess // // -------------- Description --------------------- // // calls the getjsmsglang function // // This function is kept for backward compatibility. // // It is replaced by getjsmsglang. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function getjsmess(msgtoget) { return(getjsmsglang(msgtoget)); } ///////////////////////////////////////////////////////////////////////////////////// // getjsmsglang // // msgtoget: id of the message to recover // // -------------- Description --------------------- // // This function gets a message in the current language // // according to its id. // // -------------- History -------------------------- // ///////////////////////////////////////////////////////////////////////////////////// function getjsmsglang(msgtoget) { form=document.forms[0]; var result=""; var langnum=""; langnum=form.languageNumber.value; // verify if message array is available if(msgjs==null) { // return the empty string is array is not available return(result); } else { // if array is available, look for the message for (i=0;;i++) { if (msgjs[i+","+0]==msgtoget) { result=msgjs[i+","+langnum]; break; } if (msgjs[i+","+0]==null) { result=""; break; } } return(result); } } ///////////////////////////////////////////////////////////////////////////////////// // validateFields // // fieldList: list of field names to check - Array // // -------------- Description --------------------- // // This function checks the order form fields and submits the form // // if all required fields are correctly filled. The required field // // names are passed as an array of values. // // -------------- History -------------------------- // // 03/06/2003: Created by JPA // ///////////////////////////////////////////////////////////////////////////////////// function validateFields(fieldList) { form=document.forms[0]; var lang = form.languageNumber.value; var msg = ""; var result = true; var fields = form.elements; var i = 0; var j = 0; // Check each field which name is found in the array. // browse the array of fieldnames for (i=0;i