// // Copyright 2000, Point2 Intenet Systems, Inc. All rights reserved. // $Id: utils_generic.js 80303 2006-01-31 19:45:22Z nting $ // function printVersion() { var url = "" + document.location; var cleanurl; var urlYes; if(url.indexOf("#") == -1) { cleanurl=url; } else { cleanurl=url.substring(0,url.indexOf("#")); } if(cleanurl.indexOf("?") == -1) { urlYes = cleanurl + '?printable=yes'; } else { urlYes = cleanurl + '&printable=yes'; } newWin = window.open(urlYes,"printMe","resizeable=yes,scrollbars=yes,location=no,menubar=yes,toolbar=yes,height=600,width=660").focus(); } function printVersionSameWin() { var url = "" + document.location; var cleanurl; var urlYes; if(url.indexOf("#") == -1) { cleanurl=url; } else { cleanurl=url.substring(0,url.indexOf("#")); } if(cleanurl.indexOf("?") == -1) { urlYes = cleanurl + '?printable=yes'; } else { urlYes = cleanurl + '&printable=yes'; } document.location=""+urlYes; } function Is() { var agt=navigator.userAgent.toLowerCase(); // *** BROWSER VERSION *** // Note: On IE5, these return 4, so use is.ie5up to detect IE5. this.major = parseInt(navigator.appVersion); this.minor = parseFloat(navigator.appVersion); this.nav = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1) && (agt.indexOf('webtv')==-1)); this.nav2 = (this.nav && (this.major == 2)); this.nav3 = (this.nav && (this.major == 3)); this.nav4 = (this.nav && (this.major == 4)); this.nav4up = (this.nav && (this.major >= 4)); this.navonly = (this.nav && ((agt.indexOf(";nav") != -1) || (agt.indexOf("; nav") != -1)) ); this.nav5 = (this.nav && (this.major == 5)); this.nav5up = (this.nav && (this.major >= 5)); this.ie = (agt.indexOf("msie") != -1); this.ie3 = (this.ie && (this.major < 4)); this.ie4 = (this.ie && (this.major == 4) && (agt.indexOf("msie 4")!=-1) ); this.ie4up = (this.ie && (this.major >= 4)); this.ie5 = (this.ie && (this.major == 4) && (agt.indexOf("msie 5")!=-1) ); this.ie5up = (this.ie && !this.ie3 && !this.ie4); this.ie6 = (this.ie && (this.major == 4) && (agt.indexOf("msie 6")!=-1) ); this.ie6up = (this.ie && !this.ie3 && !this.ie4 && !this.ie5); } var is = new Is(); //function popwindow(src, name, toolbar, status, scrollbars, location, width, height, resizable, menubar, left, top){ function popwindow(src, name, toolbar, status, scrollbars, location, width, height, resizable, menubar){ popWindow=window.open(src, name ,"toolbar="+toolbar+",status="+status+",scrollbars="+scrollbars+",location="+location+",width="+width+",height="+height+",resizable="+resizable+",menubar="+menubar); if (popWindow.focus){ popWindow.focus(); } } function P2_preloadImage(nameArg, srcArg) { if (document.images) { if (typeof(document.P2images) == 'undefined') { document.P2images = new Object(); } eval('document.P2images.' + nameArg + ' = new Image();'); eval('document.P2images.' + nameArg + '.src = "' + srcArg + '";'); } } function P2_imageSwap(daImage, daSrc) { var objStr, obj; if (document.images) { if (typeof(daImage) == 'string') { objStr = 'document.' + daImage; obj = eval(objStr); obj.src = daSrc; } else if ((typeof(daImage) == 'object') && daImage && daImage.src) { daImage.src = daSrc; } } } // This is the function that the MLString text box and images call. function P2_clickLanguageImage(formName, tagID, newLanguage, imageRoot) { var dataValuePointer = null; var dataValue = null; var dataCurrentLanguage = null; var dataTemp = null; // assign variables for the actual value (via the pointer value), the current language hidden field, and the temp field. eval("dataValuePointer=document.forms." + formName + "." + tagID + "pointer;"); eval("dataValue=document.forms." + formName + "." + dataValuePointer.value + ";"); eval("dataCurrentLanguage=document.forms." + formName + "." + tagID + "currlanguage;"); eval("dataTemp=document.forms." + formName + "." + tagID + "temp;"); // check validity of the variables we just found if ((dataValue == null) || (dataCurrentLanguage == null) || (dataTemp == null)) { alert("BIG JAVASCRIPT ERROR -- COULD NOT ASSIGN VALUES PROPERLY"); return false; } var currentLang = dataCurrentLanguage.value; var image = document.images["image" + tagID + "_" + currentLang]; // process ONCHANGE if (newLanguage == null) { // alter graphic if (dataTemp.value == "") { image.src = imageRoot + "-" + currentLang + "-on.gif"; } else { image.src = imageRoot + "-" + currentLang + "-on-filled.gif"; } // compute value of the MLString hidden field dataValue.value = addLanguageString(dataValue.value, dataCurrentLanguage.value, dataTemp.value); return true; } // process ONCLICK else { // alter image of current language if (dataTemp.value == "") { image.src = imageRoot + "-" + currentLang + "-off.gif"; } else { image.src = imageRoot + "-" + currentLang + "-off-filled.gif"; } // alter image of new language var newImage = null; eval("newImage = document.images.image" + tagID + "_" + newLanguage); if (retrieveLanguageString(dataValue.value, newLanguage) == "") { newImage.src = imageRoot + "-" + newLanguage + "-on.gif"; } else { newImage.src = imageRoot + "-" + newLanguage + "-on-filled.gif"; } // store the value of the MLString in the hidden field dataValue.value = addLanguageString(dataValue.value, dataCurrentLanguage.value, dataTemp.value); // put new value into the text box for a particular language that the user sees on the screen dataTemp.value = retrieveLanguageString(dataValue.value, newLanguage); // put new value into currlanguage hidden field dataCurrentLanguage.value = newLanguage; return false; } } // This method retrieves a language string from a given encoded string. The encoded string is encoded like: // en|This%2dis%2dthe%2dencoded%2dstring|fr|mon%2dfrancais| // The encoded string is the same type of encoding as com.point2.phoenix.util.MLString function retrieveLanguageString(encodedString, lang) { if (encodedString == null || encodedString == "") { return ""; } stringArray = encodedString.split('|'); for (i = 0; i < stringArray.length-1; i += 2) { if (stringArray[i] == lang) { return mlDecode(stringArray[i+1]); } } return ""; } // This method adds the string and the language to the given encoded string, returning the new encoded string function addLanguageString(encodedString, lang, str) { if (encodedString == null || encodedString == "") { if (str != null && str != "") { return lang + '|' + mlEncode(str) + '|'; } else { return ""; } } var returnString = new String(); stringArray = encodedString.split('|'); for (i = 0; i < stringArray.length-1; i += 2) { if (stringArray[i] == lang) { // do nothing - we'll add the new one later } else { returnString = returnString + stringArray[i] + '|' + stringArray[i+1] + '|'; } } // append the new one to the end if (str != null && str != "") { returnString = returnString + lang + '|' + mlEncode(str) + '|'; } return returnString; } var ENCODING_SEPARATOR = "|"; var ENCODING_REPLACEMENT = "+"; var ENCODING_REPLACEMENT_ESCAPE = "\\"; // Changes the ENCODING_SEPARATOR symbol to the ENCODING_REPLACEMENT. Also // escapes any ENCODING_REPLACEMENT characters in the original string. // MUST MATCH MLString.encode()!!! function mlEncode(str) { var sb = new String(); if(str==null) { return sb; } for (i = 0; i < str.length; i++) { if (str.charAt(i) == ENCODING_SEPARATOR) { sb = sb + ENCODING_REPLACEMENT; } else if (str.charAt(i) == ENCODING_REPLACEMENT) { sb = sb + ENCODING_REPLACEMENT_ESCAPE; sb = sb + ENCODING_REPLACEMENT; } else { sb = sb + str.charAt(i); } } return sb; } // Changes the ENCODING_REPLACEMENT character back to the ENCODING_SEPARATOR // character, unless it is escaped. // MUST MATCH MLString.decode()!!! function mlDecode(str) { var sb = new String(); for (i = 0; i < str.length; i++) { if (str.charAt(i) == ENCODING_REPLACEMENT_ESCAPE) { if (i == str.length-1) { sb = sb + ENCODING_REPLACEMENT_ESCAPE; } else { if (str.charAt(i+1) == ENCODING_REPLACEMENT) { sb = sb + ENCODING_REPLACEMENT; i += 1; } else { sb = sb + ENCODING_REPLACEMENT_ESCAPE; } } } else if (str.charAt(i) == ENCODING_REPLACEMENT) { sb = sb + ENCODING_SEPARATOR; } else { sb = sb + str.charAt(i); } } return sb; } // Simply appends the currency ID to the currency amount. For use with the // p2:moneyinputtext tag (INTERNAL USE ONLY) function newCurrency(currencyHidden, currencyText, currencySelect ) { if(currencyText != null && currencySelect != null && currencyHidden != null) { amount = trim(currencyText.value); currency = currencySelect.options[currencySelect.selectedIndex].value; if(amount == "" || currency == "") { currencyHidden.value = null; } else { currencyHidden.value = amount + " " + currency; } } } //function to remove white space from a string function trim(str) { strings = ""; for(i=0; i0) fromList.options[i-1].selected = true; fromList.options[i] = null; i--; } } } // This function transfers an item (OPTION) from one SELECT list to another and sort the items. function P2_selectSwapSort(fromList, toList) { toList.selectedIndex = -1; // loop through the OPTIONs of fromList to see if they are SELECTED for (i=1; i0) fromList.options[i-1].selected = true; fromList.options[i] = null; i--; } } // sort both list; var temp=new Object(); for(i=1; i fromList.options[j].text) { temp = fromList.options[i].text; fromList.options[i].text = fromList.options[j].text; fromList.options[j].text = temp; temp = fromList.options[i].value; fromList.options[i].value = fromList.options[j].value; fromList.options[j].value = temp; temp = fromList.options[i].selected; fromList.options[i].selected = fromList.options[j].selected; fromList.options[j].selected = temp; } } } for(i=0; i toList.options[j].text) { temp = toList.options[i].text; toList.options[i].text = toList.options[j].text; toList.options[j].text = temp; temp = toList.options[i].value; toList.options[i].value = toList.options[j].value; toList.options[j].value = temp; temp = toList.options[i].selected; toList.options[i].selected = toList.options[j].selected; toList.options[j].selected = temp; } } } } // This function moves list items function P2_moveListItem(theList, increment) { if(increment<0) { // move up for (i=1; i=1; i--) { if (theList.options[i].selected) { if( i+increment >= theList.options.length) return; // swap var oldVal = theList.options[i + increment].value; var oldText = theList.options[i + increment].text; theList.options[i + increment].value = theList.options[i].value; theList.options[i + increment].text = theList.options[i].text; theList.options[i + increment].selected = true; theList.options[i].value = oldVal; theList.options[i].text = oldText; theList.options[i].selected = false; } } } } // This function prepares or checks form values when the user presses 'submit.' // The functions this performs are: // 1. Find a SELECT tag that needs all of its attributes to be SELECTED function submitForm(f) { // loop through the form and find all SELECT fields that have are submit-all for (var i=0; i0) result = result + '&'; result = result + theElementName + '=' + escape(document.forms[theForm].elements[i].value); } } return result; } // sets the options for a select box, from an array // @param theSelect the select box to fill // @param theValues the array of Option objects to use function setSelectOptions(theSelect, theValues) { // remove old options from theSelect for(i=theSelect.options.length; i>=theValues.length; i--) { theSelect.options[i] = null; } // populate theSelect with theValues for(i=0; i