// Standard routines  (c) 2005,2006 Monahon, MercurySC
// Include on page: <script language=javascript src=at_jscript.js></script>

// document domain problem:
// document.domain = top.document.domain;
// window.alert("document.domain ?= top.document.domain" + document.domain + ", " + top.document.domain);
document.title.innerText="Add More Calling Time to Your Phone Card - BuyMoreMinutes.com, CorporatePhoneCards.com";
if (window.location.toString().indexOf("default")<0) setCookie("BMM",window.location);

// -----------------------------------------------------
// BEGIN of entry navigation routine: Redirect to https:
// -----------------------------------------------------
function loadTopFrameBMM(zFolderPrefix, zTargetPage) {
  // This does it. For https; it ignores the folder prefix
  //window.alert("got into lTF routine");
  var iLocal = window.location.toString().indexOf("localhost");
  //window.alert("got iLocal: " + iLocal);
  if (iLocal > 0) {
    zPrefix = zFolderPrefix;
    //window.alert("set zPrefix Local: " + zPrefix);
  } else {
    zPrefix = 'https://secure207.sectorlink.com/BuyMoreMinutes/';
    //window.alert("set zPrefix https: " + zPrefix);
  } 
  //window.alert("New url: " & zPrefix & zTargetPage);
  window.location= zPrefix + zTargetPage ;
  return zPrefix + zTargetPage;
}
// -----------------------------------------------------
// END of entry nav
// -----------------------------------------------------

// -----------------------------------------------------
// BEGIN of page stats code from: http://www.MercurySC.com/t1/Webcalendar
// -----------------------------------------------------
// File: calendar.js      Author: Bob Monahon (c) 2004, Monahon, MercurySC
    //<!-- PageLoad performance display - coordinates with showStandardFooter -->
    tStartBody= new Date;
    function showMessage(zMsg){
      fm = document.getElementById("footerMessage"); //document.footerMessageForm.footerMessage;
      zWork = fm.innerHTML;                         // fm.value;
      zWork = zWork + zMsg + "<BR>";                // "\n";
      fm.innerHTML = zWork;                         // fm.value = zWork;
    }
    function logUnloadTime() {
      var zType = 'UNLOAD';
      //window.alert("Cookie request for: " + zType);
      var now = new Date;
      var zTypeUsed = zType;
      // if (zTypeUsed=="") {zTypeUsed = "UNLOAD";}
      var cookieText = zTypeUsed + "=" + now + ";" ;
      document.cookie = cookieText;
      //window.alert("Cookie set: " + cookieText);
      //window.alert("Cookie list: " + document.cookie);
    }
    function logUnloadTimeX() {
      var zType = 'UNLOAD';
      //window.alert("XCookie request for: " + zType);
      var now = new Date;
      var zTypeUsed = zType;
      // if (zTypeUsed=="") {zTypeUsed = "UNLOAD";}
      var cookieText = zTypeUsed + "=" + now + ";" ;
      document.cookie = cookieText;
      //window.alert("XCookie set: " + cookieText);
      //window.alert("XCookie list: " + document.cookie);
    }
    function logClickTime() {
      var zType = 'CLICK';
      //window.alert("Cookie request for: " + zType);
      var now = new Date;
      var zTypeUsed = zType;
      // if (zTypeUsed=="") {zTypeUsed = "UNLOAD";}
      var cookieText = zTypeUsed + "=" + now + ";" ;
      document.cookie = cookieText;
      //window.alert("Cookie set: " + cookieText);
      //window.alert("Cookie list: " + document.cookie);
    }
    function logTimeToCookie(zType){
      window.alert("Cookie request for: " + zType);
      var now = new Date;
      var zTypeUsed = zType;
      // if (zTypeUsed=="") {zTypeUsed = "UNLOAD";}
      cookieText = zTypeUsed + "=" + now + ";" ;
      document.cookie += cookieText;
      window.alert("Cookie set: " + cookieText);
    }
    function getCookieVal(cookieName){
      cookieList = document.cookie.split("; ");
      for (i=0; i<cookieList.length; i++) { //>
        cookiePair = cookieList[i].split("=");
        if (cookieName==cookiePair[0]) {
          return cookiePair[1];
        }
      }
      return 0;
    }
    document.onclick=logClickTime; // Any click logs; the last click is the submit-click!
    // document.onunload=logUnloadTime; // didn't work for IE or Mozilla
    window.onunload=logUnloadTimeX;    // This works for Mozilla.


    //<!-- popup window - coordinates with emailBeingSentForm and showStandardFooter -->
    // footPop - does not return the window object to the caller; returns (null) for link href usage
    // winPop - returns the window object to the caller;
    function footPop(zURL, zTarget){
      popUp=window.open('',zTarget,'left=50,top=50,width=800,height=800,dependent=yes,resizable=yes,scrollbars=yes');
      popUp.focus();
      popUp.location=zURL;
    }
    function winPop(zURL, zTarget){
      popUp=window.open(zURL,zTarget,'left=50,top=50,width=800,height=800,dependent=yes,resizable=yes,scrollbars=yes');
      popUp.focus();
      return popUp;
    }
    
    function footPopShort(zURL, zTarget){
      popUp=window.open('',zTarget,'left=50,top=50,width=600,height=200,dependent=yes,resizable=yes,scrollbars=yes');
      popUp.focus();
      popUp.location=zURL;
    }
    function openPopUpWait() {
      footPopShort ('at_890_popup_wait.htm','WAIT_WINDOW');
    }
    function closePopUpWait() {
      footPopShort ('at_890_popup_done.htm','WAIT_WINDOW');
    }
// -----------------------------------------------------
// BEGIN of cookie code: http://www.webreference.com/js/column8/functions.html
// -----------------------------------------------------
/*
   name - name of the cookie
   value - value of the cookie
   [expires] - expiration date of the cookie
     (defaults to end of current session)
   [path] - path for which the cookie is valid
     (defaults to path of calling document)
   [domain] - domain for which the cookie is valid
     (defaults to domain of calling document)
   [secure] - Boolean value indicating if the cookie transmission requires
     a secure transmission
   * an argument defaults when it is assigned null as a placeholder
   * a null placeholder is not required for trailing omitted arguments
*/
function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}

/*
  name - name of the desired cookie
  return string containing value of specified cookie or null
  if cookie does not exist
*/
function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

/*
   name - name of the cookie
   [path] - path of the cookie (must be same as path used to create cookie)
   [domain] - domain of the cookie (must be same as domain used to
     create cookie)
   path and domain default if assigned null or omitted if no explicit
     argument proceeds
*/
function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

// date - any instance of the Date object
// * hand all instances of the Date object to this function for "repairs"
function fixDate(date) {
  var base = new Date(0);
  var skew = base.getTime();
  if (skew > 0)
    date.setTime(date.getTime() - skew);
}


// -----------------------------------------------------
// End of cookeie code
// -----------------------------------------------------

// 1-word nav utility. Spelling counts -- Remember these keyword!
// Added keep option for editing cc#
function goto(zWord) {
  var zURL;
  zURL = zWord;
  if (zWord=="enter_pin") {zURL = "at_010_phone_card_info.aspx?action=new_pin";} 
  else if (zWord=="recharge") {zURL = "at_010_phone_card_info.aspx?action=Recharge";} 
  else if (zWord=="rates") {zURL = "at_010_phone_card_info.aspx?action=Rates";} 
  else if (zWord=="confirm_pin") {zURL = "at_015_confirm_phone_card_info.aspx";}  
  else if (zWord=="enter_cc")    {zURL = "at_030_cc_info.aspx";}  
  else if (zWord=="enter_cc_keep")    {zURL = "at_030_cc_info.aspx?fill_action=keep";}  
  else if (zWord=="enter_name")  {zURL = "at_033_billing_info.aspx";}  
  else if (zWord=="enter_tax")   {zURL = "at_034_tax_info.aspx";}  
  document.location.href = zURL
}

// Cool utilities: Disable a buttion, change text to "Please wait"
// Also: Find and fill a label with text.
// Used to support the "Processing -- pls wait" messages
// Spelling counts - not found is no action - solve a "problem" where asp.net
//  doesn't put the control to the html if it's not visible...
function disableButton(zButtonName,zText){
  var oCmd = document.getElementById(zButtonName);
  if (oCmd) {
    oCmd.innerText = zText;
    oCmd.className = "buttonGray";  // Well, it looks disabled, anyway...
  }      
}
function fillLabel(zLabelName, zText) {
  try {
    var oLbl = document.getElementById(zLabelName);
    if (oLbl != null) {
      oLbl.innerText = zText;
    }
  }    
  catch(ex) {}
      
}
// General Utilities: replace and quote-string
function replace(inString,oldText,newText) {
  return (inString.split(oldText).join(newText));
} 
function singleQuoted(zWord) {
  return "'" + zWord + "'";
}
function doubleQuoted(zWord) {
  return '"' + zWord + '"';
}


// loadIFrame - not used at this time
function loadIframe(iframeName, url) {
  if ( parent.window.frames[iframeName] ) {
    parent.window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}

// getWebSiteName
// Usage: To get the website part of this url; used for XFile page
function getWebSiteName() {
  var zPath = window.location.href;
  var zURL = zPath.split("?");
  var zURLParts = zURL[0].split("/");
  var iLast = zURLParts.length-1;
  zURLParts[iLast]="";
  var zWebSite = zURLParts.join("/");
  return zWebSite;
}

// getPageName
// Usage: To get the pure page part of this url; used for Nav operations
function getPageName() {
  var zPath = window.location.href;
  var zPage = getPageNameFromHref(zPath);
  return zPage;
}

function getPageNameFromHref(zHref) {
  var zPath = zHref;
  //window.alert("getpage zPath: " + zPath);
  var zURL = zPath.split("?");
  //window.alert("getpage zURL: " + zURL);
  var zURLParts = zURL[0].split("/");
  //window.alert("getpage zURLParts: " + zURLParts);
  var iLast = zURLParts.length-1;
  //window.alert("getpage iLast: " + iLast);
  var zPage = zURLParts[iLast];
  //window.alert("getpage zPage: " + zPage);
  return zPage;
}

// getQueryParm(zProperty) 
// Gets the specific query string parm value for the current window;
function getQueryParm(zProperty, zDefault) {
  var zQuery = window.location.search  //.split("?"))[1];
  return getQueryParmFromQueryString(zProperty, zDefault, zQuery);
}  

function getQueryParmFromQueryString(zProperty, zDefault, zQuery) {
  // window.alert("GetQueryParm, Default: " + zProperty + ", " + zDefault);
  // window.alert("GetQueryParm, Query string 1: " + zQuery);
  if (zQuery!="") {
    if (zQuery.charAt(0)=="?") zQuery=zQuery.substring(1,zQuery.length);
    // window.alert("GetQueryParm, zQuery=" + zQuery);
    var zParmList = new Array();  
    zParmList = zQuery.split("&");
    for (var iX in zParmList){
      // window.alert("GetQueryParm, iX,zParmList[iX]=" + iX + ", " + zParmList[iX]);
      var zPair = new Array();
      zPair = zParmList[iX].split("=");
      if (zPair[0]== zProperty ) {
        return zPair[1];
      }
    }
  }
      return zDefault;
}
// Take the full window - Used for Logon page 
// Usage: If a page needs the full window (rather than reside in a frame or frameset)
// In the <HEAD> section: <script>takeFullWindow();</script>
function takeFullWindow() {
  if (window.top.location != window.location) {window.top.location = window.location;}
}

// Pop up a new window - Used for showing a report in a new window.  
// Usage: <a onclick="newWin('zSession.aspx','sess_win');" href="javascript:;">Description</a>
function newWin(zHref, zWinName){
  //popUp=window.open(zHref,zWinName,'left=100,top=100,width=400,height=400,dependent=yes');
  popUp=window.open(zHref,zWinName); // Above was too small. Skip any fancy control.
  popUp.focus();
}


function newWinNoLocationBar(zURL, zTarget){
  popUp=window.open(zURL,zTarget,'left=50,top=50,width=1600,height=700,dependent=yes,resizable=yes,scrollbars=yes');
  popUp.focus();
  maximizeWindow(popUp);
  return popUp;
}
function newWinWithRefresh(zURL, zTarget){
  popUp=newWinNoLocationBar(zURL, zTarget)
  popUp.location.href=zURL;
  popUp.location.reload(true); // Reload from the server. false==from Browser cache.
  return popUp;
}

function closeWin() {window.close();}

function showReportInNewWindow(zReportList,zTarget){
  // <a href="eb_230_single_report_view_fs.aspx?report_id={0}" target="report_win">Vw</a>
  newWinNoLocationBar("eb_230_single_report_view_fs.aspx?report_fs_id="+zReportList,zTarget)
  // Valid targets are: _blank for any new window; or a named window.  For now using Blank.
}

// Used in eb_230_single_report_view_fs.aspx:
function maximizeWindow(oWindow){
  //http://www.irt.org/script/212.htm
  //A href="nicklowe@ukonline.co.uk"&gt;Nick Lowe</A> writes: 
  // have written a simple script that automatically maximises the browser window 
  // when it is loaded within a webpage in both Netscape and Internet Explorer. The 
  // script goes as follows: </P>&lt;script language="JavaScript"&gt; 
  oWindow.moveTo(0,0); 
  //  if (IE) { 
  oWindow.resizeTo(screen.availWidth,screen.availHeight); 
  //  } if (NS) { 
  //  window.outerHeight = screen.availHeight; window.outerWidth = screen.availWidth; 
  //  } &lt;/script&gt; <!-- content end-->
}

function focusOnOpener(){
  try {
    top.window.opener.focus();
  } catch (e) {
    // window.alert(e.description);  // 'window.opener' is null or not an object
  } 
}


/* ------------------------------------------------------------------------------- 
	Convenience shorthand for leaving the site and opening a pop of a certain width
------------------------------------------------------------------------------- */
function popWH(zURL, nWidth, nHeight){
  var zURLUsed;
  zURLUsed = replace(zURL,".stm",".shtml");
  openWindowWH(zURLUsed,nWidth,nHeight);
}

function leaveSite(zURL) {
  popUp=window.open(zURL);   
  popUp.focus();
}








/* ------------------------------------------------------------------------------- 
	Global VARs  
------------------------------------------------------------------------------- */
var NS = (navigator.appName == "Netscape");

/* ------------------------------------------------------------------------------- 
		Function for preventing multiple submit.
		It both submits the form and ensures the form can not be submit again
		by reassigning the funciton to a function that does nothing.
		It also disables the buttons (this part only works in IE).
		f - the form the buttons are in
------------------------------------------------------------------------------- */
function safeSubmit(f) {
	for (i=1; i<f.elements.length; i++) {
		if (f.elements[i].type == 'submit') {
			f.elements[i].disabled = true;
		}
	}
	f.submit();
	safeSubmit = blockIt;
	return false;
}

/* ------------------------------------------------------------------------------- 
		Dummy function that is used in conjunciton with safeSubmit(f) to prevent 
		multiple submits.
------------------------------------------------------------------------------- */
function blockIt(f) {
	return false;
}	


/* ------------------------------------------------------------------------------- 
	Base window opening function
	Functions below override certain properties. This function will open
	a default window with default parameters.
		internalURL  -> if none passed function will exit as it has nowhere to go
		internalName -> defaults to popupWin if none specified
		internalArgs -> string of defaults for window attributes
------------------------------------------------------------------------------- */
function openWindow(internalURL,internalName,internalArgs) {
	if (internalURL == null || internalURL == '') {
		exit;
	}
	if (internalName == null || internalName == '') {
		internalName = 'popupWin';
	}
	if (internalArgs == null || internalArgs == '') {
		internalArgs = 'scrollbars,resizable,toolbar,status,width=640,height=480,left=50,top=50';
	}
	popupWin = window.open(internalURL,internalName,internalArgs);
 	popupWin.focus();
}

/*
	Overrides openWindow with different name attribute
*/
function openWindow640(thisURL) {
	openWindow(thisURL,'popupWin640','');
}

/*
	Overrides openWindow with the width/height passed in
	THIS IS FOR POPOP: Show menubar, not toolbar. Otherwise OK
*/
function openWindowWH(thisURL,thisW,thisH) {
	internalArgs = 'scrollbars,resizable,menubar,status,left=50,top=50,width=' + thisW + ',height=' + thisH;
	openWindow(thisURL,'popupWinWH',internalArgs);
}

/*
	Overrides openWindow with the standard demo window args
*/
function openWindowDemo(thisURL) {
	internalName = 'popupWinDemo';
	internalArgs = 'scrollbars,resizable,toolbar,status,left=50,top=50,width=475,height=570';
  openWindow(thisURL,internalName,internalArgs);
}

/*
	Overrides openWindow with the small demo window args
*/
function openWindowDemoSmall(thisURL) {
	internalName = 'popupWinDemo';
	internalArgs = 'scrollbars,resizable,toolbar,status,left=50,top=50,width=250,height=250';
  openWindow(thisURL,internalName,internalArgs);
}

function openWindowATC(thisURL,thisType,thisWidth,thisHeight,thisArgs,thisName) {
	if (thisType != '') {
		switch (thisType) {
			case 'demo':
				openWindowDemo(thisURL);
				break;
			case 'demosmall':
				openWindowDemo(thisURL);
				break;
			case '640':
				openWindow640(thisURL);
				break;
		}
	} else {
		if ((thisWidth != '') && (thisHeight != '')) {
			openWindowWH(thisURL,thisWidth,thisHeight);
		} else {
			openWindow(thisURL,thisName,thisArgs);
		}
	}
}

/*
	Overrides open single pop
*/
var singlePop;
function openSinglePop(thisURL,thisWidth,thisHeight) {
	var internalArgs = 'left=50,top=50,width=' + thisWidth + ',height=' + thisHeight + ',resizable=1,scrollbars=1';
	if (singlePop != null) {
		newPop = window.open(thisURL,'singlePop',internalArgs);
		singlePop.close();
		singlePop = newPop;
	} else {
		singlePop = window.open(thisURL,'singlePop',internalArgs);
	}	
}


/* ------------------------------------------------------------------------------- 
	Window naming function to establish unique names.
	Replace dashes with underscores.
------------------------------------------------------------------------------- */
function windowNamer(thisURL) {
	var name = 'popupWin_';
	var hash=0;
	for( i=0 ; i<thisURL.length ; i++){	hash+=thisURL.charCodeAt(i);}
	name += (''+hash);
	return(name);
}

function writeWindow(inURL,inType,inWidth,inHeight,inArgs) {
	var tmpName = windowNamer(inURL);
	var linkStr = "<a href=\"#\" onclick=\"javascript:openWindowATC('" + inURL + "','" + inType + "','" + inWidth + "','" + inHeight + "','" + inArgs + "','" + tmpName + "');return false;\">";
	document.write(linkStr);
}

/* ------------------------------------------------------------------------------- 
	This function iterates through the checkboxes on a page and toggles them from 
	on to off.
	WARNING: this function assumes one form per page
		dowhat -> if dowhat is on, it checks all boxes, else it unchecks all
------------------------------------------------------------------------------- */
function ToggleBoxes(dowhat) {
	for (i=0; i<document.forms[0].elements.length; i++) {
		if (document.forms[0].elements[i].type == 'checkbox') {
			if (dowhat == 'on') {
				document.forms[0].elements[i].checked = true;
			} else {
				document.forms[0].elements[i].checked = false;
			}
		}
	}
}

/* ------------------------------------------------------------------------------- 
	Function used to call the print command
------------------------------------------------------------------------------- */
function printit(){
	window.print();
}
	
/* ------------------------------------------------------------------------------- 
	Here begins the help stuff
	Documentation to come!
------------------------------------------------------------------------------- */
var scrX = screen.availWidth;
var scrY = screen.availHeight;
var tgtX = 240;
var win1 = new Array (0, 0, (scrX - tgtX), scrY); 
var win2 = new Array ((scrX - tgtX), 0, tgtX, scrY);
var balloonFlag = -1;
var winTracker;

function ContextOpenHelp(whichPage) {
	//if (!winTracker) {
		window.resizeTo(win1[2],win1[3]);
		window.moveTo(win1[0],win1[1]);
		var winHandle;
		winHandle = window.open('/cgi-bin/webscr?cmd=p/hlp/context/index-outside&page=' + whichPage ,'popHelp','scrollbars=no,resizable=no,menubar=no,location=no,personalbar=no,titlebar=no,toolbar=no,status=yes');
		winHandle.resizeTo(win2[2],win2[3]);
		winHandle.moveTo(win2[0],win2[1]);
		self.focus();
		winHandle.focus();
		winTracker = winHandle;
	/* } else {
		winTracker.focus();
	} */
}

function ContextShowHideHelp (whichDiv) {
	if (balloonFlag > 0) {
		var thisDiv = eval("document.all." + whichDiv);
		var thisX = window.event.x;
		var thisY = window.event.y;
		if (thisDiv.style.visibility == 'hidden') {
			thisDiv.style.visibility = 'visible';
			thisDiv.style.top = thisY;
			thisDiv.style.left = (thisX + 10);
		} else {
			thisDiv.style.visibility = 'hidden';
		}
	}
}

self.name = "superDaddy";

/*-----------------------------------------------------
New JS for CountrySelector on Homepage
------------------------------------------------------*/
function ReloadLocalizedPage(whichCountry) {
	var thisProtocol = document.location.protocol;
	var thisHost = document.location.host;
	var thisPath = document.location.pathname;
	var newLocation = thisProtocol + "//" + thisHost + "/" + whichCountry + thisPath;
	ReloadPage(newLocation);
}
function ReloadPage(whichPage) {
	// Remove alert for production
	//alert(whichPage);
	document.location = whichPage;
	return (false);
}

/*-----------------------------------------------------
ToggleCheck for XPT 
------------------------------------------------------*/
function ToggleCheck(source,country_format) {
	
	if (document.images) {
		document.images.check_image.src = source;
	} else {
		document.all.check_image.src = source;
	}
	document.forms[0].ach_format.value = country_format;
}

/*-----------------------------------------------------
New JS for data submission to SF.com
------------------------------------------------------*/
function submitToSF(frmSFData){
	frmSFData.submit();
}

/*-----------------------------------------------------
Iterates through all the divs and hides all of the ones with ids of "div_XXX",
 and then shows the div with the passed in index.
------------------------------------------------------*/

function displaySubindustry(form, index) {
	var divs = form.getElementsByTagName("DIV");
	for (var i = 0; i < divs.length; i++) {
	     var currentDiv = divs[i];
	     var divId = currentDiv.getAttribute("id");
	     if (divId != null && divId.indexOf("div_") > -1) {
		  currentDiv.style.display = "none";
	      }	
	}
	if (index > -1) {
		var d1 = document.getElementById("div_" + index);
		d1.style.display = '';
			    }  
}

/*-----------------------------------------------------
Character Counter WBN et cetera...
------------------------------------------------------*/

function textCounter(field, countfield, maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
	} else {
		countfield.value = maxlimit - field.value.length;
	}
}

/*-----------------------------------------------------
Parse Image URL for Image PopUp preview WBN
------------------------------------------------------*/

function FillPrefix(val) {
	len = document.forms[0].image_url.value.length;
	str = "";
	str = document.forms[0].image_url.value;
	
	if (len > 0) {
		if (str.search('https:\/\/') != -1) {
			str = str.slice(8);
		}
		else if (str.search('http:\/\/') != -1) {
			str = str.slice(7);
		}
		else {
			str = "";
		}
	}
	document.forms[0].image_url.value = "";
	document.forms[0].image_url.value = val + str;
	document.forms[0].image_url.focus();
}
/*-----------------------------------------------------
removes <!-- and --> from textareas
------------------------------------------------------*/
function removeComment(node) {
	var txt = node.value;
	var ntxt = txt.replace(/\<\!\-\-/g, "");
	var etxt = ntxt.replace(/\-\-\>/g, "");
	node.value=etxt;
}

/*-----------------------------------------------------
resize window to at least 750x555.  created for external/Cart.aml
------------------------------------------------------*/

function resizeShoppingCartWindow() {

	var browserType;
	var iWidth, iHeight;
	var resizeWidth=resizeHeight=0;
	var doc;

	// browser detect specific for this window resizing
	if (document.documentElement && document.documentElement.offsetWidth) {
		browserType="IE";  
		doc=document.documentElement;  // IE6
	} else if (document.body) {
		browserType="IE";  
		doc=document.body; // IE other than 6
	} else if (document.layers) {
		browserType="NN";  // Netscape
	} else if (window.navigator.userAgent.toLowerCase().match("gecko"))  {
		browserType= "gecko";  //Mozilla
	} else 
		return;  // don't try


	if (browserType == "gecko" || browserType == "NN") {
		iWidth=window.innerWidth;
		iHeight=window.innerHeight;
	} else if (browserType == "IE") { 
		iWidth=doc['offsetWidth'];
		iHeight=doc['offsetHeight'];
	} else { // otherwise don't try
		return;
	}

	if (iWidth<780) {
		resizeWidth=780-iWidth;
	}
	if (iHeight<555) {
		resizeHeight=555-iHeight;
	}

	//only do resize if one of the values has changed.
	if (iWidth>0 || iHeight>0) {  
		self.resizeBy(resizeWidth,resizeHeight);
	}
}


/*-----------------------------------------------------
insertAutoText();
Auto Text function  
------------------------------------------------------*/
function insertAutoText() {
	var memoField = document.forms[0].wbn_memo;
	var selIndex = document.forms[0].auto_text.selectedIndex;
	var autoText;
	
	switch(selIndex) {
		case 0:
			autoText = "{BUYERUSERNAME}";
			break;
		case 1:
			autoText = "{ITEM#}";
			break;
		case 2:
			autoText = "{TITLE}";
			break;
		case 3:
			autoText = "{S_EMAIL}";
			break;
		case 4:
			autoText = "{SELLERUSERNAME}";
			break;
		case 5:
			autoText = "{FAVORITESLIST}";
			break;
	
	} //End switch
	
	//If Internet Explorer...
	if (document.selection) {
		memoField.focus();
		var ieCursorLocation = document.selection.createRange();
			//If cursor is highlighting 1 or more characters
			if (ieCursorLocation.text.length > 0) {
				ieCursorLocation.text = autoText + " " + ieCursorLocation.text;
			}
			//If cursor is blinking in one location and not highlighting any characters
			else {
					ieCursorLocation.text = autoText;
			}
			memoField.focus();
	} //End Internet Explorer if...
	
	//Else if Netscape | Mozilla...
	else if (memoField.selectionStart || memoField.selectionStart == '0') {
		memoField.focus();
		
		var startHere = memoField.selectionStart;
		var endHere = memoField.selectionEnd;
		var nsCursorLocation = endHere;
		var scrollTop = memoField.scrollTop;
			//If cursor is highlighting 1 or more characters
			if (startHere != endHere) {
				memoField.value = memoField.value.substring(0, startHere)
				              + autoText
							  + " "
				              + memoField.value.substring(startHere, endHere) 
				              + memoField.value.substring(endHere, memoField.value.length);
				nsCursorLocation = startHere + autoText.length;
			}
			//If cursor is blinking in one location and not highlighting any characters
			else {
					memoField.value = memoField.value.substring(0, startHere) 
					              + autoText
					              + memoField.value.substring(endHere, memoField.value.length);
					nsCursorLocation = startHere + autoText.length;
			}
		memoField.focus();
		memoField.selectionStart = nsCursorLocation;
		memoField.selectionEnd = nsCursorLocation;
		memoField.scrollTop = scrollTop;
	} //End Netscape | Mozilla Else if...
	
	//Else...
	else {
		memoField.value += autoText;
		memoField.focus();
	} //End else...

}//End insertAutoText();


/*-----------------------------------------------------
blockCountry();
 Risk Controls.
------------------------------------------------------*/

function blockCountry() {
var approvedCountryList=document.forms[0].approved_country_list
var blockedCountryList=document.forms[0].blocked_country_list
var approvedCountryArray=new Array();
var blockedCountryArray=new Array();
var approvedCountryArrayLen=0
var blockedCountryArrayLen=0
var option
for(counter=0;counter<approvedCountryList.length;counter++)
	{
	   option=approvedCountryList.options[counter]
	   if(!option.selected)
	   {
	      approvedCountryArray[approvedCountryArrayLen]=approvedCountryList.options[counter].text
	      approvedCountryArrayLen++
	   }
	   else
	   {
	      blockedCountryArray[blockedCountryArrayLen]=approvedCountryList.options[counter].text
	      blockedCountryArrayLen++
	   }
	}

var originalLen=approvedCountryList.length
for(counter=originalLen-1;counter>-1;counter--)
	{
	  approvedCountryList.remove(counter)
	}

var fromOpt;
var len=approvedCountryArray.length
for(approvedCountryArrayLen=0;approvedCountryArrayLen<len;approvedCountryArrayLen++)
	{
	   fromOpt= new Option(approvedCountryArray[approvedCountryArrayLen],approvedCountryArray[approvedCountryArrayLen])
	   approvedCountryList.add(fromOpt)
	}
	
var newOpt;
var len=blockedCountryArray.length
for(blockedCountryArrayLen=0;blockedCountryArrayLen<len;++blockedCountryArrayLen)
	{
	  newOpt= new Option(blockedCountryArray[blockedCountryArrayLen],blockedCountryArray[blockedCountryArrayLen])
	  blockedCountryList.add(newOpt)
	}
} //End blockCountry();


/*-----------------------------------------------------
unblockCountry();
  Risk Controls.
------------------------------------------------------*/

function unblockCountry() {
var approvedCountryList=document.forms[0].approved_country_list
var blockedCountryList=document.forms[0].blocked_country_list
var approvedCountryArray= new Array();
var blockedCountryArray=new Array();
var approvedCountryArrayLen=0
var blockedCountryArrayLen=0
var option
for(counter=0;counter<blockedCountryList.length;counter++)
	{
	   option=blockedCountryList.options[counter]
	   if(!option.selected)
	   {
	      approvedCountryArray[approvedCountryArrayLen]=blockedCountryList.options[counter].text
	      approvedCountryArrayLen++
	   }
	   else
	   {
	      blockedCountryArray[blockedCountryArrayLen]=blockedCountryList.options[counter].text
	      blockedCountryArrayLen++
	   }
	}
	
var originalLen=blockedCountryList.length
for(counter=originalLen-1;counter>-1;counter--)
	{
	  blockedCountryList.remove(counter)
	}

var fromOpt;
var len=approvedCountryArray.length
for(approvedCountryArrayLen=0;approvedCountryArrayLen<len;approvedCountryArrayLen++)
	{
	   fromOpt= new Option(approvedCountryArray[approvedCountryArrayLen],approvedCountryArray[approvedCountryArrayLen])
	   blockedCountryList.add(fromOpt)
	}
	
var newOpt;
var len=blockedCountryArray.length
for(blockedCountryArrayLen=0;blockedCountryArrayLen<len;++blockedCountryArrayLen)
	{
	   newOpt= new Option(blockedCountryArray[blockedCountryArrayLen],blockedCountryArray[blockedCountryArrayLen])
	   approvedCountryList.add(newOpt)
	}
}

//End unblockCountry();


 
/*-----------------------------------------------------
submitAllOptions();
  Risk Controls.
------------------------------------------------------*/

function submitAllOptions() {
var blockedCountryList=document.forms[0].blocked_country_list
for(counter=0;counter<blockedCountryList.length;counter++)
	{
	    blockedCountryList.options[counter].selected=true
	}
}

//End submitAllOptions();


/*-----------------------------------------------------
function transfer( source, dest )
  Risk Controls.
------------------------------------------------------*/

function transfer( source, dest )
{
	for (i = source.length -1; i > -1; i--)
	{
		if( source[i].selected)
		{
			dest[dest.length] = new Option(source[i].text, source[i].value);
			source[i] = null ;
		}
	}
}


/*------------------------------------------------
/	VT Session Refresh
/	Alert the user that the session is 
/	timing out and refreshes session 
/	if desired
--------------------------------------------------*/
function sessionAlert(timeout, limit, cancelpage)
{
	var timeout = timeout/60/1000;
	var limit = limit/60/1000;
	var result;
	var message = "You have been inactive for " + timeout + " minutes and will be automatically logged out in " + limit + " minutes. Would you like to reset the time-out clock and continue working?";

	result = confirm(message);
	
	if (result)
	{
		// So backend form validation is skipped
		if (document.forms[0].refresh)
			document.forms[0].refresh.value = "1";
		document.forms[0].submit();
	}
	else // If user doesn't want timeout refreshed
	{
		window.location.replace(cancelpage);
	}
}


/*------------------------------------------------
/	Submits form when shipping address changes
/	writes a hidden form field to pass to backend 
/	putting the hidden form field here so hidden form
/ 	field doesn't get added twice
--------------------------------------------------*/

function appendQString(url, qstring)
{
	var str = url;
	var newurl;
	
	if (str.indexOf("?") == -1)
		newurl = str + "?" + qstring;
	else
		newurl = str + "&" + qstring;
	
	return newurl;
}


/*  
For China, ebay integration flow and Send Money flow.
We need to popup  a child window which will take user to 
Bank website. It should work with SP2, which by default
blocks unsolicited popups. So on page 1, I call openBankWindow() which 
opens a blank popup and refreshes parent page tp page2. On page2, there is an 
onload handler, which calls openNewWindowAndSubmit(). This function does not open 
another popup but submits the thirdPartyForm to bankWin popup opened by page 1.
The trick to get it working was to call openOffCenteredWindow() within 
openNewWindowAndSubmit() a second time otherwise bankWin becomes
an undefined object.
TODO: after 31.0 move it over to a separate file and use the new components to include
it in aml/cml
*/
var bankWin;
function openOffCenteredWindow(url, height, width, name, parms) 
				{
				   var left = Math.floor( ((screen.width - width) / 2) + width/2 - 200);
				   var top = Math.floor( ((screen.height - height) / 2) - height);
				   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
				   if (parms) { winParms += "," + parms; }
				   var win = window.open(url, name, winParms);
				   return win;
				}
				
				function openBankWindow(url)
				{
				if (url){ bankWin = openOffCenteredWindow(url,500,800,'bankWin','scrollbars,resizable,toolbar,status');}
				else { bankWin = openOffCenteredWindow('',500,800,'bankWin','scrollbars,resizable,toolbar,status');}
					if (bankWin) {
						bankWin.focus();
					}	
				}
				
				function openNewWindowAndSubmit(flagToCheckForSubmitOrNot)
				{
					bankWin = openOffCenteredWindow('',500,800,'bankWin','scrollbars,resizable,toolbar,status');
				
					if (bankWin) {
						bankWin.focus();
						if (flagToCheckForSubmitOrNot) {
							 document.thirdPartyForm.target='bankWin';
							 }
						}	
					if (flagToCheckForSubmitOrNot) {
						document.thirdPartyForm.submit();
					}
				}

