utilityBrowserVer = parseInt(navigator.appVersion);
function imgOn(imgName) {
if (utilityBrowserVer >= 3) {
imgOnString = eval(imgName + "_on.src");
document.images[imgName].src = imgOnString;
}
}
function imgOff(imgName) {
if (utilityBrowserVer >= 3) {
imgOffString = eval(imgName + "_off.src");
document.images[imgName].src = imgOffString;
}
}
function goToLink(address) {
var linkURL = address.options[address.selectedIndex].value;
window.top.location.href = linkURL;
address.selectedIndex=0;
}
function openWindow(address, width, height) {
var newWindow = window.open(address, 'Popup_Window', 'width=' + width + ',height=' + height + ',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no');
newWindow.focus();
}
/*
* This function launches a new web browser window to a specified width, height and features.
* Features string is a comma separated window's feature needed for this new window. For Instance
* If a new window needs a toolbar the feature string must be "toolbar" like needs scroll bar and
* and toolbar then it must be "toolbar,scrollbars". Note that the order of the feature is not required.
* Also it's case insensitive. Therefore, "scrollbars,toolbar" is identical to "Toolbar,ScrollBars".
*
* NOTE: By default window will be shown at center of screen, if you'd like to display it at a specific coordinates
* pass the left and top properties as a feature string. For instance, to display a window at 100px on X and 100px on Y
* set feature string as "left=100,top=100"
*
* If the features string is ommitted then all the features are turned off. To turn all the features on
* use the word "all" for features instead of specifying each feature.
*
* @address URL to open in new window
* @width width of new window in pixel. Defaults to 400 pixels.
* @height height of new window in pixel. Default to 350 pixels.
* @features feature string to have window features enable. Such as scrollbars,toolbars,menubars etc.
* @name string if new window to be named window.
* @retrun opened Window Instance.
*/
function newWindow(address, width, height,features,name) {
// Find out what features need to be enable
if (features) {
features = features.toLowerCase();
} else {
features = "";
}
if (!name) {
name = "Popup_Window";
}
var toolbar = (features == "all" ? 1 : 0);
var menubar = (features == "all" ? 1 : 0);
var location = (features == "all" ? 1 : 0);
var directories = (features == "all" ? 1 : 0);
var status = (features == "all" ? 1 : 0);
var scrollbars = (features == "all" ? 1 : 0);
var resizable = (features == "all" ? 1 : 0);
if (typeof(width) != "number") {
width=400;
}
if (typeof(height) != "number") {
height=350;
}
var left = ("left=" + ((screen.width-width)/2));
var top = ("top=" + ((screen.height-height)/2));
if (features != "all") {
//split features
var feature = features.split(",");
for (i = 0; i < feature.length; i++) {
if(feature[i] == "toolbar")
toolbar = 1;
else if(feature[i] == "menubar")
menubar = 1;
else if(feature[i] == "location")
location = 1;
else if(feature[i] == "directories")
directories = 1;
else if(feature[i] == "status")
status = 1;
else if(feature[i] == "scrollbars")
scrollbars = 1;
else if(feature[i] == "resizable")
resizable = 1;
else if(feature[i].indexOf("left=") != -1)
left = feature[i];
else if(feature[i].indexOf("top=") != -1)
top = feature[i];
}
}
features = "toolbar=" + toolbar + ",";
features += "menubar=" + menubar + ",";
features += "location=" + location + ",";
features += "directories=" + directories + ",";
features += "status=" + status + ",";
features += "scrollbars=" + scrollbars + ",";
features += "resizable=" + resizable + ",";
features += left + "," + top;
var thisWindow = window.open(address, removeNonAlphaNumericChars(name), 'width=' + width + ',height=' + height + ',"' + features + '"');
thisWindow.focus();
}
/**
* Function to remove all non alpha numeric character except ('_' underscore since it could be use to give predefined window names[_blabk, _top, _self,_media]) from a given string
* and return the modified string. If there are errors return the given string as is
*/
function removeNonAlphaNumericChars(string) {
if (typeof(string) != 'string') {
return string;
}
var modifiedString = "";
var tempChar;
for (i = 0; i < string.length; i++) {
var tempChar = string.charAt(i);
if((tempChar >= '0' && tempChar <= '9') ||
(tempChar >= 'a' && tempChar <= 'z') ||
(tempChar >= 'A' && tempChar <= 'Z') ||
(tempChar == '_'))
{
modifiedString += tempChar;
}
}
if (modifiedString != "") {
return modifiedString;
} else {
return string;
}
}
function confirmWindow(url, text) {
if (confirm(text)) {
window.go = url;
window.location = url;
}
}
/*
** Function to trim spaces from left part of string
*/
function ltrim(str) {
if (typeof(str) != 'string') {
return str;
}
return str.replace(/^\s+/,'');
}
/*
** Function to trim spaces from right part of string
*/
function rtrim(str) {
if (typeof(str) != 'string') {
return str;
}
return str.replace(/\s+$/,'');
}
/*
** Function to trim spaces from left and right part of a string
*/
function trim(str) {
return ltrim(rtrim(str));
}
/*
** This function is called from the "Ship To" drop down on it's onChange event.
** The idea is to popup a dialog box for accepting new nick names when user
** selects the option "Other Address" from the list. Up on success append added nick name to an
** existing list and make it selected.
**
** @selector select object on which this onChange event triggered.
** @formName string representing form name to which this select element belongs to
** @returns nothing.
*/
function ship_to_changed(selector, formName, elementName) {
//Ignore if selected value isn't "Other Address"
var nickName = selector.options[selector.selectedIndex].value;
if (nickName == "Other Address")
{
/*
** Launch a new window to accept a new nick name and pass formName and elementName as queryString parameters.
*/
var winWidth = 325;
var winHeight = 185;
var winLeft = (screen.width-winWidth)/2;
var winTop = (screen.height-winHeight)/2;
newWindow(("/popup/ship_to_popup.jsp?PIPELINE_SESSION_ID=ed50359ec0a85b656872d5dbd1ba76f5" + "?formName=" + formName + "&elementName=" + elementName), winWidth, winHeight);
}
}
/*
** This function is called from "Ship To" popup window.
** It will append the given name if it's unique to an existing list.
** Upon success it returns true.
**
** @name String representing the nick name to add
** @formName String representing form name to which this select element belongs
** @elementName String representing select element name
** @isCaseAware boolean to ignore case sensitivity. Optional as it defualts to true
** @returns one of the following string:
** EMPTY if null value or empty string is passed for name
** EXIST if the given name already exist in the list
** SUCCESS if the given name is added to the list.
** FAILURE if the given name contains special characters '@' and double quotes '"'
*/
function addShipToName(name,formName,elementName, isCaseAware)
{
//lets first check if name is not empty
if (typeof((name = trim(name))) != "string" || name == "") {
return "EMPTY";
}
/*
** Check if the given name contains special characters '@' and '"'
** Since it's not allowed.
*/
if (name.indexOf("@") != -1 || name.indexOf('"') != -1) {
return "FAILURE";
}
//check if it's case sensitive
if (typeof(isCaseAware) != "boolean") {
isCaseAware = true; //Case sensitive
}
if (!isCaseAware) {
name = name.toLowerCase();
}
/*
** Lets check if this name already exist in the list.
*/
var selector = document.forms[formName].elements[elementName];
for(index = 0; index < selector.options.length; index++)
{
var thisName = selector.options[index].value;
if (!isCaseAware) {
thisName = thisName.toLowerCase();
}
if (selector.options[index].value == name) {
return "EXIST";
}
}
//Given name can't be found so lets add it
var count = selector.options.length;
var optionObj = new Option(name);
//Now set text and value since some browser's will leave the value part as empty
optionObj.text = name;
optionObj.value = name;
selector.options[count] = optionObj;
//Now select this added nick name
selector.options.selectedIndex = count; //since index starts at 0
return "SUCCESS"; //indicate success
}
/*
* This function is used to get DHTML object reference.
*/
function getElement(id)
{
if (document.getElementById)
{
return document.getElementById(id);
}
else if(document.layers)
{
return document.layers[id];
}
else if(document.all)
{
return document.all[id];
}
else
return null;
}
function mediaRelationsSignUp(emailAddress, sourceParam) {
emailSignUp(emailAddress, sourceParam);
}
/*
** This function loads a popup page given a user's email address.
** The idea is to popup a dialog box that loads a predetermined page from CheetahMail
** so that the user can select which newsletters they want to receive.
**
** emailAddress: the user's email address
** sourceParam: from which JSP page this function is called.
** returns nothing.
*/
function emailSignUp( emailAddress, sourceParam )
{
// Launch a new window to accept a new nick name and pass formName and elementName as queryString parameters.
var winWidth = 450;
var winHeight = 450;
var winLeft = (screen.width-winWidth)/2;
var winTop = (screen.height-winHeight)/2;
if(sourceParam!=null) {
if (emailAddress !=null) {
newWindow(("http://ebm.e.worldmarket.com/r/regf2?a=0&aid=421327511&" + sourceParam +"&email=" + emailAddress ), winWidth, winHeight, 'resizable,scrollbars','CheetahMail');
} else {
newWindow(("http://ebm.e.worldmarket.com/r/regf2?a=0&aid=421327511&" + sourceParam), winWidth, winHeight, 'resizable,scrollbars','CheetahMail');
}
}
else {
if (emailAddress !=null) {
newWindow(("http://ebm.e.worldmarket.com/r/regf2?a=0&aid=421327511&" + "email=" + emailAddress ), winWidth, winHeight, 'resizable,scrollbars','CheetahMail');
} else {
newWindow(("http://ebm.e.worldmarket.com/r/regf2?a=0&aid=421327511&"), winWidth, winHeight, 'resizable,scrollbars','CheetahMail');
}
}
}
function buildBreadCrumb(pageName, secondaryLinkName, secondaryLinkURL,thirdLinkName, thirdLinkURL ) {
//we assume here that there is more than home to show
if (document.getElementById("breadCrumbs")) {
var breadcrumb = "Home > ";
if(secondaryLinkURL != null) {
breadcrumb += "" + secondaryLinkName + " > ";
}
if(thirdLinkURL != null) {
breadcrumb += "" + thirdLinkName + " > ";
}
breadcrumb += "" + pageName + "";
document.getElementById("breadCrumbs").innerHTML = breadcrumb;
}
}
/*
This function opens a new window.
*/
function openNewWindow(URL, winWidth, winHeight, popUpWin, windowName, leftPos, topPos) {
// Default window width and height, if not passed in.
var w = 800, h = 600;
//Check browser is IE.
if (document.all) {
w = document.body.clientWidth;
h = document.body.clientHeight;
} else {
w = window.innerWidth;
h = window.innerHeight;
}
//Check if window width was passed. If so, use that width.
if (winWidth != null) {
var popW = winWidth;
} else {
var popW = (w - 100);
}
//Check if window height was passed. If so, use that height.
if (winHeight != null) {
var popH=winHeight;
} else {
var popH=(h-100);
}
//Check if window should be opened as popup.
var scrollbars = "yes";
if (popUpWin != null) {
var noPopUp = 'yes';
if (popUpWin.toLowerCase() == 'y' || popUpWin.toLowerCase() == 'yes') {
noPopUp = 'no';
scrollbars = "auto";
}
} else {
var noPopUp = 'yes';
}
// Create the window name, if not passed in.
if (windowName != null) {
// Use the window name passed in.
var winName = windowName;
} else {
//Generate window name with random number (ie 'win274').
var winName = 'win'+Math.floor(Math.random()*1000);
}
// Set the window positions.
if ((leftPos == null) || (leftPos == "undefined")) {
leftPos = (w - popW) / 2;
}
if ((topPos == null) || (topPos == "undefined")) {
topPos = (h - popH) / 2;
}
// Open the new window.
newWindow = window.open(URL,winName,'width='+popW+',height='+popH+',top='+topPos+',left='+leftPos+',menubar='+noPopUp+',location='+noPopUp+',directories='+noPopUp+',fullscreen=no,resizable='+noPopUp+',scrollbars='+scrollbars+',status=no,titlebar=yes,toolbar='+noPopUp);
return newWindow;
}
function buildBreadCrumbAndTitle(pageName, secondaryLinkName, secondaryLinkURL,thirdLinkName, thirdLinkURL) {
buildBreadCrumb(pageName, secondaryLinkName, secondaryLinkURL,thirdLinkName, thirdLinkURL);
var pageTitle = getPageTitle(pageName);
setPageTitle(pageTitle);
}
function buildBreadCrumbTitleAndSubheader(pageName, secondaryLinkName, secondaryLinkURL,thirdLinkName, thirdLinkURL) {
buildBreadCrumbAndTitle(pageName, secondaryLinkName, secondaryLinkURL,thirdLinkName, thirdLinkURL);
var subHdrTxt = getElement('corpPageSubText');
if (subHdrTxt) {
subHdrTxt.innerHTML = pageName;
var subHdr = getElement('corpPageSubHead');
if (subHdr) {
subHdr.style.display = "block";
}
}
}
function getPageTitle(pageName) {
var siteName = "World Market";
var pageSeparator = " at ";
// If no value is passed, just return the site name.
if (pageName == null || trim(pageName) == "" || pageName == "undefined") {
return siteName;
}
return pageName + pageSeparator + siteName;
}
function setPageTitle(pageTitle) {
document.title = pageTitle;
}
function setPopupHeight(paddingOverride) {
var padding = (paddingOverride == null || paddingOverride == 'undefined') ? 40 : paddingOverride;
if (!document.all && document.getElementById) {
if (document.getElementById("popupHeader") && document.getElementById("popupFooter") && document.getElementById("popupContent")) {
var popHeader = document.getElementById("popupHeader");
var popFooter = document.getElementById("popupFooter");
var popContent = document.getElementById("popupContent");
var windowHeight = window.innerHeight;
popContent.style.height = windowHeight - (popHeader.offsetHeight + popFooter.offsetHeight + padding);
}
}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i < a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document;
if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);
}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i < d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i < d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
/*
This function replaces all instances of a value in a string with the following parms.
NOTE: Special characters such as ' and / will need to be passed in as \' and \/.
string = The value to be searched on. (required)
match = The value to find in the string. (required)
replacement = The to replace the match with. (required)
*/
function stringReplace(string, match, replacement) {
var result = '';
var index = 0;
var lastIndex = index;
while (string.length > lastIndex) {
index = string.indexOf(match, lastIndex);
if (index == -1) { break }
result += string.substring(lastIndex, index) + replacement;
lastIndex = index + match.length;
}
result += string.substring(lastIndex, string.length);
return result;
}
function containXSS(input) {
if (input != null) {
if (input.indexOf("<") >= 0 || input.indexOf(">") >= 0 || input.indexOf("%3C") >= 0 || input.indexOf("%3E") >= 0 || input.indexOf("%3c") >= 0 || input.indexOf("%3e") >= 0 || input.indexOf("|") > 0) {
return true;
}
}
return false;
}