// The variable 'country' stores the country directory prefix for ASP
var country = ""

var Ver4 = parseInt(navigator.appVersion) >= 4
var Nav4 = ((navigator.appName == "Netscape") && Ver4)
var IE4 = ((navigator.userAgent.indexOf("MSIE") != -1) && Ver4)



var myWindow
//Pop Up Window
function windowOpen(url,width,height,mb,sp) {

myWindow = window.open(url,"windowRef","width=" + width + ",height=" + height+",top=0,left=0,screenX=20,screenY=20,resizable=0,menubar=" + mb + ",scrollbars="+sp);
self.name="main"
}

//Pop Up Window
function windowOpen2(url,wname,width,height,mb,sp) {
myWindow2 = window.open(url,wname,"width=" + width + ",height=" + height+",top=0,left=0,screenX=0,screenY=0,resizable=0,left=0,top=0,menubar=" + mb + ",scrollbars="+sp);
window.close()
}

//BEGIN FOOD TRACKER CODE

var trackfood = 0
var testlocation=location.href

function foodTrackDiv() {
//alert("here")
if (Nav4) {
var testfile = 0
if (testlocation.search("a7_my_activity") != -1){
testfile=1
} else if (testlocation.search("a7_my_food") != -1) {
testfile=1
}
if (testfile==1){
if (origWidth != window.innerWidth || origHeight != window.innerHeight) {
closefind(2)
}
}
}
}

//END FOOD TRACKER CODE  -

function recipeBuilder() {
//alert("recipebuilder")
var testfile = 0
if (testlocation.search("d6_fr_recipebuilder_edit.asp") != -1){
//alert("recipeBuilder")
serverpage();
  }
if (testlocation.search("d6_fr_recipebuilder_net.asp") != -1){
//alert("recipeBuilder")
serverpage();
  }
if (testlocation.search("netscape.html") != -1){
//alert("recipeBuilder")
serverpage();
  }
}


function loginPopup(setURL) {
  location.href = "https://" + document.domain + "/util/Login.aspx?txtHiddenURL=" + escape(setURL);
}

function loginPopupLocal(setURL) {
  location.href = "https://" + document.domain + "/util/Login.aspx?txtHiddenURL=" + escape(setURL) + "&#LgnMktg";
}

// log out popup
function logoutPopup( showPopup, url ) {
    if (showPopup)
    {
      location.href = "/util/autologin_logout.aspx";
    }
    else
    {
      location.href = url;
    }
}



//****
//This code is used for the User Guide Demos
//****
var pg = "yes"

function openJUG(page) {
var jugName, windowJug

if (page.indexOf("main") >= 0) {
pg = "gateway"
page="gateway"
} else if (page.indexOf("add_food") >= 0) {
pg = "add_food"
} else if (page.indexOf("add_ex") >= 0) {
pg = "add_ex"
} else if (page.indexOf("changing") >= 0) {
pg = "changing"
} else if (page.indexOf("savebank") >= 0) {
pg = "savebank"
} else if (page.indexOf("hints") >= 0) {
pg = "hints"
} else if (page.indexOf("print") >= 0) {
pg = "print"
}

jugName = "/help/j6_he_jug.asp?pg=" + pg + "&page=" + page

windowJug = window.open(jugName,"jug","width=600,height=420,scrollbars=0,toolbar=0,left=100,top=100");

}
//****
//END
//****

//****
//This code is used for the User Guide Demos
//****
var pg = "yes"

function openMUG(page) {
var mugName, windowMug

if (page.indexOf("main") >= 0) {
pg = "gateway"
page = "gateway"
} else if (page.indexOf("about") >= 0) {
pg = "adding"
} else if (page.indexOf("features") >= 0) {
pg = "changing"
} else if (page.indexOf("preferences") >= 0) {
pg = "banking"
} else if (page.indexOf("printing") >= 0) {
pg = "logsave"
} else if (page.indexOf("faqs") >= 0) {
pg = "timesavers"
}

mugName = "/help/j7_he_mug.asp?pg=" + pg + "&page=" + page

windoMug = window.open(mugName,"mug","width=600,height=420,scrollbars=0,toolbar=0,left=100,top=100");

}
//****
//END
//****

//****
//This code is used for the Help popups
//****

  var helpWindow

  //Pop Up Window
  function windowOpenHelp(url) {

  helpWindow = window.open(url,"windowWWhelp","width=600,height=420,top=0,left=0,screenX=0,screenY=0,resizable=0,menubar=0,scrollbars=1,status=1");
  self.name="main"

  }

//****
//END
//****

//****
//These helper functions support zipcode validator functions (see below)
// Author:      Ashes Mukherjee
// Created on:  07/19/2006 
//****

   // similar to ltrim in VB
   function LTrim(str)
   {
      if (str==null)
      {
        return null;
      }
      for(var i=0;str.charAt(i)==" ";i++);
      return str.substring(i,str.length);
   }

   // similar to rtrim in VB
   function RTrim(str)
   {
      if (str==null)
      {
        return null;
      }
      for(var i=str.length-1;str.charAt(i)==" ";i--);
      return str.substring(0,i+1);
   }

   // combines above two trim functions.
   function Trim(str)
   {
      return LTrim(RTrim(str));
   }

//****
//END
//****

//BEGIN SUBMIT TO MEETING FINDER FUNCTION

  function MeetingFinderSubmit() {
    var zipcode = document.pageform.zipcode.value;

    if (zipcode==""){
      alert("Please enter a postcode.")
      document.pageform.zipcode.focus()
      return false
    }

    document.pageform.action = "/util/mtf/location_results.aspx?pg=0&s=ZIP&z=" + escape(zipcode);
    document.pageform.submit();
  }

  //To be used by Monthly Pass Meeting Finder Zip Code box only. 
  function MPMeetingFinderSubmit() {

    var zipcode = document.pageform.zipcode.value;

    zipcode = Trim(zipcode);
    var regexpStr = "[0-9\ \-]*[0-9]+[0-9\ \-]*";
    var re = new RegExp(regexpStr);
    
    if (zipcode=="" || zipcode.length < 5 || !zipcode.match(re)){
      alert("Please enter a valid postcode.")
      document.pageform.zipcode.focus();
      return false;
    }

    //document.pageform.action = "http://www.qa.weightwatchers.com/util/mtf/dispatcher.aspx?z=" + escape(zipcode);
    //document.pageform.submit();
	location.href="http://www.weightwatchers.com/util/mtf/dispatcher.aspx?z=" + escape(zipcode);
  }

//END SUBMIT TO MEETING FINDER FUNCTION


// for user submit form by enter key add by alan zhang 10/14/2002



//Captures the "ENTER" key for form submission
function ByEnterKey(evt,eleName){
  var oneChar;
  var flag=false;
  if ((parseInt(navigator.appVersion) >4)&& (navigator.appName=="Netscape"))

  {
    oneChar =evt.which;
    if (oneChar==13)
    {
      var strTag="";
      var btnNameNS=eleName;
      if(document.getElementsByName(btnNameNS).item(0))
      {
        document.getElementsByName(btnNameNS).item(0).focus();
      }
      else
      {
      for(i=0; i<document.forms[0].length ; i++)
      { 
        if(!flag)
        {
          if(document.forms[0].elements[i].name.indexOf(":")>0)
          {
          strTag="";
          strTag=document.forms[0].elements[i].name.substr(0,document.forms[0].elements[i].name.lastIndexOf(":"));
          btnNameNS="";
          btnNameNS=strTag+ ":"+btnName;
          if(document.getElementsByName(btnNameNS).item(0))
            {
              flag=true;
              document.getElementsByName(btnNameNS).item(0).focus();
              if (!window.sidebar) {document.getElementsByName(btnNameNS).item(0).click();}
            }
          }
        }
      }
      
      }
    }
  }
  else
  { if(document.all){
    oneChar=window.event.keyCode;
    var temp;
    if (oneChar==13)
    {
      var objElem;
      if(eval("document.all."+eleName))
      {
        objElem=eval("document.all."+eleName);
        
        objElem.focus();
      //if(event.srcElement.tagName == "SELECT" ) { objElem.click(); }
      

if (navigator.platform.indexOf("Mac")>=0 || event.srcElement.tagName == "SELECT") {objElem.click(); }
      }
      else
      {
        for(i=0;i<document.forms[0].elements.length;i++)
        {
          if(!flag)
          {
            if(document.forms[0].elements[i].id)
            {
              if(document.forms[0].elements[i].id.lastIndexOf("_")>0)
              { 
                temp=""
                temp=document.forms[0].elements[i].id.substr(0,document.forms[0].elements[i].id.lastIndexOf("_"));
                objElem=eval("document.all." +temp+"_"+eleName);
                if(objElem)
                {
                  flag=true;

                  objElem.focus();

                  
                  if (navigator.platform.indexOf("Mac")>=0) {objElem.click(); }
                }
              }
            }
          }
        }
      }

    }
    }
  }
return true;
}






var meetingZip1,meetingZip2,inputCOUNT,oFormMtf,inputControl1,inputControl2,countryZIPword,genericZip,overloadType
var openInPOPUP = false;
var delimiter = "+";
var strSearchType = null; //city&state ||OR|| zipcode search
var formActionPage = "";

  
function GLOBALmeetingSubmit(){
  if(arguments.length == 1) {
  genericZip = arguments[0];
  submit_mtgFinder_ziponly(genericZip);
  return;
  }
  if(arguments.length == 4 || arguments.length == 5) {
  oFormMtf     = eval("document." + arguments[0] + ";");
  inputControl1  = eval("document." + arguments[0] + "." + arguments[1]);
  countryZIPword = arguments[3];
  
  if(arguments.length == 5) { strSearchType  = arguments[4]; }

  if(strSearchType == "z" || strSearchType == true || strSearchType == null) { inputControl2  = eval("document." + arguments[0] + "." + arguments[2]); }
  if(strSearchType == "cs") { inputControl2  = eval("document." + arguments[0] + "." + arguments[2] + ".options[" + "document." + arguments[0] + "." + arguments[2] + ".selectedIndex];" ); }

  
  }

    //alert("arguments passed: " + arguments.length + "\nArguments expected: " + GLOBALmeetingSubmit.length);
    //test for oneInput
    if(inputControl2 == "undefined" || inputControl2 == null) {
    meetingZip1 = inputControl1.value.split(" ").join("");
    meetingZip2 = "";
    delimiter = "";
    formActionPage = "/util/mtf/location_results.aspx?pg=0&s=ZIP&z=" + escape(meetingZip1);
    inputCOUNT = 1;
    }
    //else test for 2 inputs
    else {
    meetingZip1 = inputControl1.value;
    meetingZip2 = inputControl2.value;
    inputCOUNT = 2;
    if(strSearchType == "z" || strSearchType == true || strSearchType == null)  { formActionPage = "/util/mtf/location_results.aspx?pg=0&s=ZIP&z=" + escape(meetingZip1.split(" ").join("")) + delimiter + escape(meetingZip2.split(" ").join("")); }
    if(strSearchType == "cs") { formActionPage = "/util/mtf/location_results.aspx?pg=0&s=CS&c=" + meetingZip1.split("&").join("~").split(" ").join("%20") + "&st=" + meetingZip2.split("&").join("~").split(" ").join("%20"); }
    }
    
  if (meetingZip1.length == 0 && strSearchType != "cs") {
      alert("Please enter a " + countryZIPword)
      inputControl1.value="";
      inputControl1.focus();
      return false;
    } 
  else if(strSearchType == "cs" && inputControl2.value == "") {
    alert("Please select a " + countryZIPword + " from the drop-down list to continue.");
    }
    else { submit_mtgFinder(); }
}//end function
  
  
function submit_mtgFinder_ziponly(INTgenericZip) {
var mtfWinResults = window.open("/util/mtf/location_results.aspx?pg=0&s=ZIP&z=" + escape(INTgenericZip), "MeetingFinder");
mtfWinResults.focus();
}
  
function submit_mtgFinder(){
if(strSearchType == true) { // strSearchType can be true, for popup results, z for zipcode, cs for citystate searches
var mtfWinResults = window.open(formActionPage, "MeetingFinder");
mtfWinResults.focus();
} 
else { //else strSearchType can be "cs" or "z"
oFormMtf.target = "_top"
oFormMtf.action = formActionPage;
oFormMtf.submit();
return true;
}
}//end function






/* PLANMANAGER SUPPORT LOGIC */
  var planManagerPopupWindow  = null;
  var stillProcessing         = false;
      
  function Notify(p_winHandle) {
    planManagerPopupWindow = p_winHandle;
  }
  
  function openPlanManager(aDeepLink) 
  {
      var windowWidth  = 780;
      var windowHeight = screen.height * .85;
      var leftPos = (screen.width-windowWidth)/2;
      var topPos  = (screen.height-windowHeight)/2-30;
      
      if(stillProcessing) 
          return;
          
      stillProcessing = true;
      aDeepLink = (aDeepLink == null || aDeepLink == "") ? "default":aDeepLink;
        
    if(null == planManagerPopupWindow) 
    {
        var planManagerUrl = "/plan/mgr/PlanManager.aspx?deepLink=" + aDeepLink;
      planManagerPopupWindow = window.open(planManagerUrl,"planManagerPopupWindow","left=" + leftPos + ",top=" + topPos + ",width=" + windowWidth + ",height=" + windowHeight + ",status=no,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
    }
    else 
    {
      try
        {
          planManagerPopupWindow.focus();
          planManagerPopupWindow.Notify(aDeepLink);
            }
            catch(exception)
            {
                planManagerPopupWindow = null;
                stillProcessing = false; 
                openPlanManager(aDeepLink); 
            }
    }
    stillProcessing = false;
  }
  
      //SWITCH GUIDE LOGIC
      function PlanManagerIsActive() {
                return (planManagerPopupWindow != null)
            }
            function DoDefaultAction() {
                return true;
            }
            function CancelDefaultAction() {
                return false;
            }
            function ConfirmTheSwitch(switchMessage) {
                var confirmSwitch = confirm(switchMessage);
              if(confirmSwitch) {
                  planManagerPopupWindow.close();
                  return true;
              }
              else {
                  return CancelDefaultAction();
              }
            }
          function CaptureButtonClicksFor(arrayOfButtonIDs) 
          {
              for(i=0; i<=arrayOfButtonIDs.length-1; i++)
              {
                  var aSwitchButton = document.getElementById(arrayOfButtonIDs[i]);
                  if(aSwitchButton != null) { 
                      aSwitchButton.onclick = SwitchPlans;
                  }
              }
          }
          //END SWITCH-GUIDE LOGIC
//END







//---------------------------------:::Jscript Object Oriented Classes:::------------------------------
/*JSmith - Oct.29.2003*/

/*Filter Class
 Usage:
  var regExp = /^([0-9]{5})$/;
  var myFilter = new Filter(regExp,"Sorry! Please Enter a Valid Zipcode")
  var checkZip = myFilter.isValid("10462")
*/
function Filter(oRegEx,strError) {
  this.filter = oRegEx;
  this.ErrorMessage = strError || "error";
  this.isValid = function(strValueToTest) {
      return this.filter.test(strValueToTest)
    }
  }


/*Private itemsCollection*/
function itemsCollections() {
  this.private_ArrayZipQuery = new Array();
  this.Add = function(strZipValue) {
    if(strZipValue != "") {
      this.private_ArrayZipQuery[this.private_ArrayZipQuery.length] = strZipValue;
    }
  }
  this.Count = function() { return this.private_ArrayZipQuery.length}
  this.Index = function(IntPos) { return this.private_ArrayZipQuery[parseInt(IntPos)]}
}

/* Print signup Confirmation pages */
 function printSignupConfirmation()
        {
            document.forms[0].action = "confirmation.aspx?print=true";
            document.forms[0].target = "_new";
            document.forms[0].submit();
        }

/*Meetings Finder Class
Usage:
  var filter = /^(([a-zA-Z]{1,3}[0-9]{1,3})(\+)?([0-9]{1,3}[a-zA-Z]{1,3})?)?([0-9]{5})?$/;
  var ZipQuery = new MTFZipSearch();
  ZipQuery.Items.Add("LL20");
  ZipQuery.Items.Add("8RA");
  ZipQuery.Validation = new Filter(filter,"Please enter a valid post/zip code.");
  ZipQuery.Execute(document);
*/
function MTFZipSearch() {
  this.Items = new itemsCollections();
  this.UseValidation = "";
  this.ProcessingPage = "/util/mtf/location_results.aspx";
  this.Dispose = function() {
    this.Items.private_ArrayZipQuery.length = 0;
    strZipQuery = null;
  }
        
  this.Execute = function(oTargetResults) {
    var relativeMTFPath = unescape(this.ProcessingPage + "?pg=0%26s=ZIP%26z=");
    var strZipQuery = ""
      for(i=0;i<=this.Items.private_ArrayZipQuery.length-1;i++) {
        strZipQuery = strZipQuery + this.Items.private_ArrayZipQuery[i] + "+";
      }
    strZipQuery = strZipQuery.substr(0,strZipQuery.lastIndexOf("+"));
          //Check for validation
          if(typeof this.Validation == "object") {
            if(this.Items.private_ArrayZipQuery.length <= 0) { alert(this.Validation.ErrorMessage); this.Dispose(); return; }
            if(!this.Validation.isValid(strZipQuery)) {alert(this.Validation.ErrorMessage); this.Dispose(); return;}
            }
          if(typeof this.Validation == "string") {
            if(this.Validation.length >= 1) {
              if(this.Items.private_ArrayZipQuery.length <= 0) {alert(this.Validation); this.Dispose(); return;}
            }
          }
    oTargetResults.location.href = relativeMTFPath + strZipQuery;
    //alert(relativeMTFPath + strZipQuery);
    this.Dispose();
  }
}
//------End Classes-----------------------------------------------------------------------------






