
function replaceAllChar( str, from, to ) {
    var idx = str.indexOf( from );
    while ( idx > -1 ) {
        str = str.replace( from, to );
        idx = str.indexOf( from );
    }
    return str;
}

  function openBrandWin() {
    openInfoWindow("wm_brand.jsp", 'yes', 350, "brandWin" );
  }

  function sizingWindow() {
    openInfoWindow('sizing.jsp', 'yes', 350, "sizeWin");
  }

  function refIdWindow() {
    openrefWindow();
  }

  function openrefWindow() {
    return window.open("http://www.westmarine.com/checkout/ReferenceNumber.htm","Example","height=350,width=500,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
  }

  function refWARewardsWindow() {
    openWARewardsWindow();
  }

  function openWARewardsWindow() {
    return window.open("http://www.westmarine.com/westadvantage/WA_PopWindow.html","Example","height=450,width=450,toolbar=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no");
  }


  function sportifSizingWindow() {

    remote = window.open("http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView?storeId=10001&inc=sportifSizing.jsp","SportifSizing","width=625,height=440,resizable=no,scrollbars=yes");

  }

  function showHighResImage( image, desc ) {

    desc = replaceAllChar( desc, ',',  '' );
    desc = replaceAllChar( desc, '\'', '' );

    remote = window.open( "http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeDynamicView?storeId=10001&inc=high_res.jsp&image="+image+"&desc="+desc,"highres_window","width=600,height=600,resizable=yes,scrollbars=yes");
    if (remote.opener == null){
      remote.opener = window;
      remote.opener.name = "opener";
    }
  }

  function returnWindow() {
    openInfoWindow('no_hassle.jsp', 'yes', 350, "retWin");
  }

  function privacyWindow() {
    openInfoWindow('privacy.jsp', 'yes', 350, "privWin");
  }

  function shippingWindow() {
    openInfoWindow('shipping_charges.jsp', 'yes', 350, "shipWin");
  }

  function sportifShippingWindow() {

    remote = window.open("http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView?storeId=10001&inc=sportif_shipping_charges.jsp","SportifSizing","width=500,height=600,resizable=no,scrollbars=yes");

  }


  function cartWindow() {
    openInfoWindow('cart_help.jsp', 'yes', 350, "cartWin");
  }

  function wmccWindow() {
    wmccWin = openSecureInfoWindow('10percent.jsp', 'no', 175, 'ccWin');
    if (wmccWin.opener == null) {
      wmccWin.opener = window;
    }
    wmccWin.opener.name = "opener";
  }

  function openShippingCouponWin(choice) {
    shipWin = openSecureInfoWindow('shipping_change.jsp', 'no', 275, "shipWin");
    if (shipWin.opener == null) {
      shipWin.opener = window;
    }
    shipWin.opener.name = "opener";
    shipWin.document.targetShipMode = choice;
  }

  function openTellAFriendWindow() {
      remote = window.open("http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView?storeId=10001&inc=tell_a_friend.jsp","TellAFriend","HEIGHT=440,WIDTH=425,SCROLLBARS=no,MENUBAR=no,resizable=yes" );
        if (remote.opener == null) remote.opener = window;
        remote.opener.name = "opener";
  }

  function openInfoWindow(inc_file, scrollable, height, name) {
    return openWinHelper("http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView", inc_file, scrollable, height, name);
  }

  function openSecureInfoWindow(inc_file, scrollable, height, name) {
    return openWinHelper("https://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView", inc_file, scrollable, height, name);
  }


  function openWinHelper(hostname, inc_file, scrollable, height, name) {
    return window.open(hostname + "?storeId=10001&inc=" + inc_file,name,"width=500,height=" + height + ",resizable=no,scrollbars=" + scrollable);
  }

  function gift_message(){
      remote = openSecureInfoWindow('gift_message.jsp', 'yes', 250, "giftmessageWin");

      if (remote.opener == null){
          remote.opener = window;
          remote.opener.name = "opener";
      }
   }

  function openUpsell( template, catentry_id, quantity ){
    remote = window.open( "http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView?storeId=10001&inc="+template+"&catentryId="+catentry_id+"&quantity="+quantity,"mpp_window","width=420,height=470,resizable=no,scrollbars=yes");
    if (remote.opener == null){
      remote.opener = window;
      remote.opener.name = "opener";
    }
  }

  function openPopupWindow(popup, eta ) {
    openPopupWindow( popup, eta, "" );
  }

  function openPopupWindow(popup, eta, partNumber ) {
      url = popup + '.jsp&eta='+ eta + "&partNumber="+partNumber;
      remote = window.open("http://"+document.domain+"/webapp/wcs/stores/servlet/DisplayIncludeView?storeId=10001&inc=" + url,"status_popup","width=215,height=200" );
        if (remote.opener == null) remote.opener = window;
        remote.opener.name = "opener";
  }

  function openLogonHelp() {

  remote = window.open("DisplayIncludeView?storeId=10001&inc=logon_help.jsp","LogonHelp","width=510,height=570,left=300,top=50,scrollbars=yes");
  if (remote.opener == null) {
    remote.opener = window;
  }
  remote.opener.name = "opener";

  }