
// <!--
//	wp.js 	wp.js  7/17/00  1.1
// this function removes a cookie

var Title;
var LastName;
var FirstName;
var MiddleInitial;
var WPNum;

function remove_cookie (name)
{
   document.cookie = name + "=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=.nwa.com";
}

// 	function to retrieve a cookie by name

function get_cookie(name)
{
   var cname = name + "=";
   var allcookies = document.cookie;
   var pos = allcookies.indexOf(cname);
   if (pos != -1) {
      var start = pos + cname.length;
      var end = allcookies.indexOf(";", start);
      if (end == -1) end = allcookies.length;
      return(unescape(allcookies.substring(start,end)));
   }
   return("");
}

// 	function to logout of skymiles by deleting all cookies

function logout_skymiles ()
{
   remove_cookie("WorldPerks");
   remove_cookie("WP_PIN");
   remove_cookie("form0");
   remove_cookie("form1");
   remove_cookie("orbot");
   remove_cookie("NWASSOToken");
     var edcoregCookie = get_cookie("edcoreg");
    if ( edcoregCookie != "") {
       var ifrm = document.createElement("IFRAME");
       ifrm.setAttribute("src", "http://auctions.nwa.com/cgi-bin/ncommerce3/Logoff?merchant_rn=78954854&url=http://www.nwa.com");
       ifrm.style.width = 1+"px";
       ifrm.style.height = 1+"px";
       ifrm.style.visibility = "hidden";
       document.body.appendChild(ifrm);
       remove_cookie("edcoreg");
    }

   alert("You have successfully logged out of SkyMiles");
   location = "http://www.nwa.com/skymiles/";
}

function logout_skymiles_home ()
{
   remove_cookie("WorldPerks");
   remove_cookie("WP_PIN");
   remove_cookie("form0");
   remove_cookie("form1");
   remove_cookie("orbot");
   remove_cookie("NWASSOToken");
     var edcoregCookie = get_cookie("edcoreg");
    if ( edcoregCookie != "") {
       var ifrm = document.createElement("IFRAME");
       ifrm.setAttribute("src", "http://auctions.nwa.com/cgi-bin/ncommerce3/Logoff?merchant_rn=78954854&url=http://www.nwa.com");
       ifrm.style.width = 1+"px";
       ifrm.style.height = 1+"px";
       ifrm.style.visibility = "hidden";
       document.body.appendChild(ifrm);
       remove_cookie("edcoreg");
    }

   alert("You have successfully logged out of SkyMiles");
   location = "http://www.nwa.com/";
}


// another function to logout of skymiles by deleting all cookies

function logout_reload ()
{
   remove_cookie("WorldPerks");
   remove_cookie("WP_PIN");
   remove_cookie("form0");
   remove_cookie("form1");
   remove_cookie("orbot");
   remove_cookie("NWASSOToken");
     var edcoregCookie = get_cookie("edcoreg");
    if ( edcoregCookie != "") {
       var ifrm = document.createElement("IFRAME");
       ifrm.setAttribute("src", "http://auctions.nwa.com/cgi-bin/ncommerce3/Logoff?merchant_rn=78954854&url=http://www.nwa.com");
       ifrm.style.width = 1+"px";
       ifrm.style.height = 1+"px";
       ifrm.style.visibility = "hidden";
       document.body.appendChild(ifrm);
       remove_cookie("edcoreg");
    }

   window.location.reload (); 
}

// 	function to automagically post SkyMiles account balance form
//	on /skymiles/direct/ hidden form

// GM - -01/30/02 - logout of skymiles elite main page.
// GM -             and, show popup, and reload
function logout_elite_reload()
{
   remove_cookie("WorldPerks");
   remove_cookie("WP_PIN");
   remove_cookie("form0");
   remove_cookie("form1");
   remove_cookie("orbot");
   remove_cookie("NWASSOToken");
     var edcoregCookie = get_cookie("edcoreg");
    if ( edcoregCookie != "") {
       var ifrm = document.createElement("IFRAME");
       ifrm.setAttribute("src", "http://auctions.nwa.com/cgi-bin/ncommerce3/Logoff?merchant_rn=78954854&url=http://www.nwa.com");
       ifrm.style.width = 1+"px";
       ifrm.style.height = 1+"px";
       ifrm.style.visibility = "hidden";
       document.body.appendChild(ifrm);
       remove_cookie("edcoreg");
    }

   alert("You have successfully logged out of SkyMiles");
   window.location.reload ();
}


// KJ - -02/07/02 - logout of skymiles and return to elite main page.
function logout_elite()
{
   remove_cookie("WorldPerks");
   remove_cookie("WP_PIN");
   remove_cookie("form0");
   remove_cookie("form1");
   remove_cookie("orbot");
   remove_cookie("NWASSOToken");
     var edcoregCookie = get_cookie("edcoreg");
    if ( edcoregCookie != "") {
       var ifrm = document.createElement("IFRAME");
       ifrm.setAttribute("src", "http://auctions.nwa.com/cgi-bin/ncommerce3/Logoff?merchant_rn=78954854&url=http://www.nwa.com");
       ifrm.style.width = 1+"px";
       ifrm.style.height = 1+"px";
       ifrm.style.visibility = "hidden";
       document.body.appendChild(ifrm);
       remove_cookie("edcoreg");
    }

   alert("You have successfully logged out of SkyMiles");
   location = "http://www.nwa.com/";
}

function postWP()
{
    var WP_num = get_WP_member_num();
    var WP_PIN = get_WP_pin();
    if (WP_PIN != "" && WP_num != "")
    {
        document.wpbalance.account.value=WP_num;
    	document.wpbalance.pin.value=WP_PIN;
    	document.wpbalance.save_pin.value="Y";
     	document.wpbalance.save_pin.checked="TRUE";
    	document.wpbalance.submit();
    } else {
	location = "https://www.nwa.com/skymiles/milea/mileage.shtml";
    }
}

// 	function to automagically post SkyMiles account history form
//	on /skymiles/direct/ hidden form

function postWP_hst()
{
    var WP_num = get_WP_member_num();
    var WP_PIN = get_WP_pin();
    if (WP_PIN != "" && WP_num != "")
    {
        document.wphistory.account.value=WP_num;
    	document.wphistory.pin.value=WP_PIN;
    	document.wphistory.save_pin.value="Y";
     	document.wphistory.save_pin.checked="TRUE";
    	document.wphistory.submit();
    } else {
	location = "https://www.nwa.com/skymiles/accthst/accthst.shtml";
    }
}

//	function to retrieve WP member name from SkyMiles Cookie

function get_WP_member_name()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	return(cookie_flds[2] + " " + cookie_flds[1] + ",");
    }
    return("");
}

function get_WP_member_last_name()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
      var cookie_flds = SkyMiles.split('&');
      return(cookie_flds[1]);
    }
    return("");
}

//	function to retrieve WP member balance from SkyMiles Cookie
//      JR - 05/25/00 - added

function get_WP_member_balance()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	var WPBalance = cookie_flds[6];
	return (WPBalance);

    }
    return("");
}
//	function to retrieve WP member title & last name from SkyMiles Cookie
//      JR - 05/24/00 - added to output title + last (i.e. Mr Smith)

function get_WP_member_title_name()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	return(cookie_flds[3] + cookie_flds[1]);
    }
    return("");
}

//	function to retrieve WP member title from SkyMiles Cookie

function get_WP_member_title()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	return(cookie_flds[3]);
    }
    return(",");
}

//	function to retrieve WP member number from SkyMiles Cookie

function get_WP_member_num()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	return(cookie_flds[0]);
    }
    return("");
}

//	function to retrieve WP member PIN from WP_PIN cookie

function get_WP_pin()
{
    var SkyMiles = get_cookie("WP_PIN");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	return(cookie_flds[0]);
    }
    return("");
}

//	function to build SkyMiles Logout request in sidebar

function sidebar_logout()
{
    var cookie_str = get_cookie("WorldPerks");
    if (cookie_str != "")
    {
    	document.write("<TR><TD BGCOLOR=FFFFCC><IMG SRC=https://www.nwa.com/images/red_hr.gif ");
    	document.write("Height=1 Width=130 Valign=top><BR> ");
    	document.write("<IMG SRC=https://www.nwa.com/images/clear.gif Height=3 Width=1><BR> ");
    	document.write("<A HREF=javascript:logout_skymiles();><b>Logout</b></A> ");
    	document.write("of SkyMiles");
    	document.write("<BR><IMG SRC=https://www.nwa.com/images/clear.gif Height=3 Width=1><BR> ");
    	document.write("<IMG SRC=https://www.nwa.com/images/red_hr.gif Height=1 Width=130 ");
    	document.write("Valign=bottom></TD></TR>");
    }
}

//	function to retrieve WP member's elite tier standing
//	JR - 04/18/00

// KJ - 02/07/02 - build SkyMiles Logout request in elite site's sidebar
function sidebar_logout_elite ()
{
    var cookie_str = get_cookie("WorldPerks");
    if (cookie_str != "")
    {
        document.write("<TR><TD BGCOLOR=FFFFCC>");
        document.write("<B><A HREF=javascript:logout_elite();>Logout</A></B>");
        document.write(" of SkyMiles<BR>");
        document.write("<BR><IMG SRC=/images/red_hr.gif WIDTH=130 HEIGHT=1 ");
        document.write("VALIGN=BOTTOM></TD></TR>");
    }
}

function get_WP_tier()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');
    	return(cookie_flds[4]);
    }
    return ("");
}

//	function to retrieve names, etc.
//	JR - 06/22/00

function get_WP_info()
{
    var SkyMiles = get_cookie("WorldPerks");
    if (SkyMiles != "")
    {
    	var cookie_flds = SkyMiles.split('&');

	WPNum = cookie_flds[0];
	LastName = cookie_flds[1];
	FirstName = cookie_flds[2];
	Balance = cookie_flds[5];
	Title = cookie_flds[3];

    	return(1);
    }
    return (0);
}

// the following function displays f_name, l_name and wp_num in the input
// box internet check-in page if skymiles cookie exists. 
// KJ, 1/14/04   GB updated from 3 to 1 function 1/21/04
function checkinset() {
   var SkyMiles = get_cookie("WorldPerks");
   if (SkyMiles != "") {
      var cookie_flds = SkyMiles.split('&');
      document.form0.FirstName.value = cookie_flds[2];
      document.form0.LastName.value = cookie_flds[1];
      document.form0.WP.value = cookie_flds[0];
   }
   // start flyout code
   DQM_handleOnload();
}
function isNumber(wpNum,wpField) {
   try{
      wpField.value = numberFilter(wpNum);
   }catch(e){}
}
//-->

// for checking of last name
// Mich Te - 10/10/08
function isString(lname,lnameField) {
  lnameField.value = stringFilter(lname);
}
