﻿function Comma(number) {
   number = numberFilter(number);
   number = '' + number;
   if (number.length > 3) {
   var mod = number.length % 3;
   var output = (mod > 0 ? (number.substring(0,mod)) : '');
   for (i=0 ; i < Math.floor(number.length / 3); i++) {
   if ((mod == 0) && (i == 0))
   output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
   else
   output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
}
   return (output);
}
   else return number;
}

function stringFilter (string) {
 sfilter = string;
 filteredValues = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
 var i;
 var returnString = "";
 for (i = 0; i < sfilter.length; i++) {
	var c = sfilter.charAt(i);
	if (filteredValues.indexOf(c) != -1) returnString += c;
 }
 return returnString;
}

function numberFilter (string) {
 sfilter = string;
 filteredValues = "1234567890";
 var i;
 var returnString = "";
 for (i = 0; i < sfilter.length; i++) {
	var c = sfilter.charAt(i);
	if (filteredValues.indexOf(c) != -1) returnString += c;
 }
 return returnString;
}

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("");
}

//opens a popup window
function OpenWindow (url,width,height) {
	OpenWin = window.open(url, "CtrlWindow", "status=no,toolbar=no,directories=no,menubar=no,scrollbars=yes,resizable=yes,width="+ width + ",height=" + height + ",left=75,top=75");
}

//returns HTML for shared header with a different
//image dependent on if the user is logged in
function GetHeaderLogin(location) {
	var WorldPerks = get_cookie("WorldPerks");

	if (WorldPerks != "") { 
		if (location == "HOMEPAGE") {
			
			return ('<td><img src="http://www.nwa.com/asia/jp/images/shared/header/topnav_sub_logout_jp_jp.gif" border="0" width="465" height="29" usemap="#topnav_sub_logout_map" alt=""></td>'); 
		} else {
			
			return ('<td><img src="http://www.nwa.com/asia/jp/images/shared/header/topnav_sub_logout_others_jp_jp.gif" border="0" width="465" height="29" usemap="#topnav_sub_logout_map" alt=""></td>'); 
		}
	} else {
		if (location == "HOMEPAGE") {
			
			return ('<td><img src="http://www.nwa.com/asia/jp/images/shared/header/topnav_sub_login_jp_jp.gif" border="0" width="465" height="29" usemap="#topnav_sub_login_map" alt=""></td>'); 
		} else {
			
			return ('<td><img src="http://www.nwa.com/asia/jp/images/shared/header/topnav_sub_login_others_jp_jp.gif" border="0" width="465" height="29" usemap="#topnav_sub_login_map" alt=""></td>'); 
		}
	}

}

function GetWPWelcome() {
	var WorldPerks = get_cookie("WorldPerks");
	if (WorldPerks != "") {
		var cookie_flds = WorldPerks.split('&');	 	
		return ('<span class="wplogin-name">'+cookie_flds[2]+' '+cookie_flds[1]+'</span><br>会員資格： '+cookie_flds[4]+' member<br>\n'+Comma(cookie_flds[6])+' 使用可能マイル残数\n'); 
	} else {
		return ('ワールドパークスへのログインは <a href="https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=jp">こちら</a> から'); 
	}
}

//turn the subnav link row on or off by changing background/text
//color and associated arrow image
function SubNavLink(element, mode) {
	if ((document.getElementById) || (document.all)) {

		//defaults
		var arrowImage = element + "Arrow";	
		var bgColor = '#E5E6EF';
		var txtColor = '#233385';
		var arrowImg = 'arrowRightOn';
	
		//reassign background and text colors dependent on mode
		if (mode == 'over') {
			bgColor = '#CC0000';		
			txtColor = '#FFFFFF';
			arrowImg = 'arrowRightOn';
		} else if (mode == 'out') {
			arrowImg = 'arrowRightOff';			
		} else if (mode == 'over-open') {
			arrowImg = 'arrowDownOn';		
			bgColor = '#CC0000';				
			txtColor = '#FFFFFF';									
		} else if (mode == 'out-open') {
			arrowImg = 'arrowDownOff';							
		}
		//modern browsers
		if (document.getElementById) {	
			var navTxt = document.getElementById(element + "Txt");
			var arrowCell = document.getElementById(element + "ArrowCell");
	
			//change colors, swap image
			document.getElementById(element).style.backgroundColor = bgColor;
			if (arrowCell) { arrowCell.style.backgroundColor = bgColor; }
			if (document.images[arrowImage]) { SwapImage(arrowImage, arrowImg); }		
			if (navTxt) { navTxt.style.color = txtColor; }				
		
		//IE 4	
		} else if (document.all) {
			var navTxt = document.all(element + "Txt");
			var arrowCell = document.all(element + "ArrowCell");		
	
			//change colors, swap image
			document.all(element).style.backgroundColor = bgColor;
			if (arrowCell) { arrowCell.style.backgroundColor = bgColor; }
			if (document.images[arrowImage]) { SwapImage(arrowImage, arrowImg); }		
			if (navTxt) { navTxt.style.color = txtColor; }			
		}
	}
}

//replace a given img src with passed reference
function SwapImage(imgDocID,imgObjName) {
 if (document.images) {
		document.images[imgDocID].src = eval(imgObjName + ".src")
 }
}

/* run-time */

/* preload sub nav arrow images */
if (document.images) {
	 var arrowRightOn = new Image(13,14);
	 arrowRightOn.src = "http://www.nwa.com/images/shared/subnav/arrow_right_on.gif";
	 var arrowRightOff = new Image(13,14);
	 arrowRightOff.src = "http://www.nwa.com/images/shared/subnav/arrow_right_off.gif";
	 var arrowDownOn = new Image(13,14);
	 arrowDownOn.src = "http://www.nwa.com/images/shared/subnav/arrow_down_on.gif";
	 var arrowDownOff = new Image(13,14);
	 arrowDownOff.src = "http://www.nwa.com/images/shared/subnav/arrow_down_off.gif";			 
}

function leapto(form) {
	var myindex=form.dest.selectedIndex
	location.href=(form.dest.options[myindex].value);
}

function Cookie(document, name, hours, path, domain, secure)
{
	// All the predefined properties of this object begin with 'N'
	// to distinguish them from other properties which are the values to
	// be stored in the cookie.
    
	name = 'nwa';
	domain = '.nwa.com';
	this.Ndocument = document;
    	this.Nname = name;
    	if (hours)
        	this.Nexpiration = new Date((new Date()).getTime() + hours*3600000);
    	else this.Nexpiration = null;
    	if (path) this.Npath = path; else this.Npath = null;
    	if (domain) this.Ndomain = domain; else this.Ndomain = null;
    	if (secure) this.Nsecure = true; else this.Nsecure = false;
}

// This function is the store() method of the Cookie object
function _Cookie_store()
{
	// First, loop through the properties of the Cookie object and
    	// put together the value of the cookie.  Since cookies use the
    	// equals sign and semicolons as separators, we'll use colons
    	// and ampersands for the individual state variables we store
    	// within a single cookie value.  Note that we escape the value
    	// of each state variable, in case it contains punctuation or other
    	// illegal characters.
    	var cookieval = "";
    	for(var prop in this) {
        	// ignore properties with names that begin with 'N' and also methods
        	if ((prop.charAt(0) == 'N') || ((typeof this[prop]) == 'function'))
            		continue;
        	if (cookieval != "") cookieval += '&';
       		cookieval += prop + ':' + escape(this[prop]);
	}

	// Now that we have the value of the cookie, put together the
    	// complete cookie string, which includes the name, and the various
    	// attributes specified when the Cookie object was created.
    	var cookie = this.Nname + '=' + cookieval;
    	if (this.Nexpiration)
        	cookie += '; expires=' + this.Nexpiration.toGMTString();
    	if (this.Npath) cookie += '; path=' + this.Npath;
    	if (this.Ndomain) cookie += '; domain=' + this.Ndomain;
    	if (this.Nsecure) cookie += '; secure';

    	// Now store the cookie by setting the magic Document.cookie property
    	this.Ndocument.cookie = cookie;
}

	// This function is the load() method of the Cookie object
	function _Cookie_load()
		{
    			// First, get a list of all cookies that pertain to this document.
    			// We do this by reading the magic Document.cookie property
    			var allcookies = this.Ndocument.cookie;
     
			if (allcookies == "") return false;

		  	// Now extract just the named cookie from that list.
    			var start = allcookies.indexOf(this.Nname + '=');
    			if (start == -1) return false;   // cookie not defined for this page.
    			start += this.Nname.length + 1;  // skip name and equals sign.
    			var end = allcookies.indexOf(';', start);
    			if (end == -1) end = allcookies.length;
    			var cookieval = allcookies.substring(start, end);
			// Now that we've extracted the value of the named cookie, we've
    			// got to break that value down into individual state variable
    			// names and values.  The name/value pairs are separated from each
    			// other with ampersands, and the individual names and values are
    			// separated from each other with colons.  We use the split method
    			// to parse everything.
			// THIS CODE WILL NOT WORK WITH IE3.0
   			//var a = cookieval.split('&');
   			var a = ie3split(cookieval,"&");   // break it into array of name/value pairs
   			for(var i=0; i < a.length; i++)        // break each pair into an array
   			{
     				//a[i] = a[i].split(':');    
     				a[i] = ie3split(a[i],":");
   			}
 
			//USE THIS INSTEAD
			// Now that we've parsed the cookie value, set all the names and values
    			// of the state variables in this Cookie object.  Note that we unescape()
    			// the property value, because we called escape() when we stored it.
    			for(var i = 0; i < a.length; i++) {
        			this[a[i][0]] = unescape(a[i][1]);
    			}

		    // We're done, so return the success code
    		return true;
	}

function ie3split(stringtosplit, splitchar)
{
	var orgstring = stringtosplit;
	var ie3splitarray = new Array();
	var j = 0;
	while (orgstring.indexOf(splitchar) != -1)

	{
		ie3splitarray[j] = orgstring.substring(0,orgstring.indexOf(splitchar));
		orgstring=orgstring.substring(orgstring.indexOf(splitchar)+1,orgstring.length);
		j++;
	}
	ie3splitarray[j] = orgstring;
	return ie3splitarray;
}

	// This function is the remove() method of the Cookie object.
	function _Cookie_remove()
	{
    		var cookie;
    		cookie = this.Nname + '=';
    		if (this.Npath) cookie += '; path=' + this.Npath;
    		if (this.Ndomain) cookie += '; domain=' + this.Ndomain;
    		cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';

		this.Ndocument.cookie = cookie;
	}
	


// function added - Raymond 19 AUG 2003
function reloadEnableButton(myForm) {
	if (myForm.AWARDS.value == "YES") {
		enableButton(false,myForm);
	} else {
		enableButton(true,myForm);
	}
}
function enableButton(enable,myForm)
{	
	
	//if (typeof document.getElementById('returnMonth') != 'undefined') {	
	//if (typeof document.getElementById('returnMonth')
	if (myForm.returnMonth) {	
		myForm.returnMonth.options.disabled = (!enable);
		myForm.returnDay.options.disabled = (!enable);
		myForm.classOfService.options.disabled = (!enable);
	}
		
	var obj1 = document.all?document.all.retCalendar:document.getElementById("retCalendar");
	var obj2 = document.all?document.all.multiFgt:document.getElementById("multiFgt");
		
	if (!enable) {

		obj2.onclick = "";
		obj2.href = "javascript:void(0)";
		myForm.returnMonth.disabled = true;
		myForm.returnDay.disabled = true;
		myForm.classOfService.disabled = true;
		myForm.TRIP_TYPE[0].checked = true;
		myForm.TRIP_TYPE[1].disabled = true;
	} else {
		obj2.onclick = "javascript:multiFlight(document.orbot)";
		obj2.href = "javascript:multiFlight(document.orbot)";
	
		if (myForm.returnMonth) {	
			myForm.returnMonth.disabled = false;
			myForm.returnDay.disabled = false;
			myForm.classOfService.disabled = false;
		}
	
		myForm.TRIP_TYPE[1].disabled = false;
	}
	
}


function newin (url)
{
popWindow = window.open(url,"popWindow","toolbar=no,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no, width=710, height=550")
popWindow.opener = self;
popWindow.focus();
}
function newin (url)
{
popWindow = window.open(url,"popWindow","toolbar=no,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no, width=710, height=550")
popWindow.opener = self;
popWindow.focus();
}

function newin_navigate(url)
{
	popWindow = window.open(url,"popWindow","")
	popWindow.opener = self;
	popWindow.focus();	
}

               function padout(number) { return (number < 10) ? '0' + number : number; }

               function restart() {
                       text_field1.selectedIndex = day-1;
                       text_field2.selectedIndex =( month - month1 + (12 * (month < month1))) + 0;  // Glenn made this change - it worked
                        if (text_field3 != null)
                           text_field3.selectedIndex = text_field2.selectedIndex;
                        mywindow.close();
                }
			//Modified by Mich 08/02/2007
	        function changeReturn(myForm) {
	        		var myForm2 = document.orbot;
  	                myForm2.returnMonth.selectedIndex = myForm2.departMonth.selectedIndex;
	        }
			//End of change
			
	        function moreOptions(myForm) {
	        	checkForm(myForm);
			myForm.SEARCH_TYPE.disabled = true;
	                myForm.action.value="populate";
	                myForm.submit();
  	        }
		
		function multiFlight(myForm) {
			checkForm(myForm);
	                myForm.action.value="populate";
			myForm.SEARCH_TYPE.value = "4";
			myForm.RETDATE.disabled=true;
			myForm.submit();
		}
		
		function lessOptions(myForm) {
			checkForm(myForm);
			myForm.submit();
		}
//Commented out by Mich 08/02/2007	
/*		function DateForm(myForm) {
			var today1 = new Date();
			 curMonth = today1.getMonth() + 1;
			 curDYear  = today1.getFullYear();
			 curRYear  = today1.getFullYear();

			if (myForm.DEPDATE0) {
				if (curMonth > myForm.departMonth.value) {
					curDYear = curDYear + 1;
				}
				myForm.DEPDATE0.value = myForm.departMonth.value + "/" + myForm.departDay.value + "/" + curDYear.toString().substring(2,4);
			}
			if (myForm.RETDATE) {
				if (curMonth > myForm.returnMonth.value) {
					curRYear = curRYear + 1;
				}
				myForm.RETDATE.value = myForm.returnMonth.value + "/" + myForm.returnDay.value + "/" + curRYear.toString().substring(2,4);
			}
		}

		function checkForm(myForm) {
			myForm.action.value = "submit";
			DateForm(myForm);
			for (i=0;i<myForm.length;i++) {
				if (myForm.elements[i].name == "SEARCHON" && myForm.elements[i].type == "radio" && myForm.elements[i].checked) {
					if (myForm.elements[i].value == "awardTravelSearch") {
						myForm.AWARDS.value = "YES";
						myForm.AWARD_LEVEL.value = "261";
						// erase
						myForm.RETDATE.value = "";
						myForm.returnDay.value = "";
						myForm.returnMonth.value = "";
						myForm.FARETYPE.value = "";		
						myForm.RETDATE.disabled=true;
						myForm.returnDay.disabled=true;
						myForm.returnMonth.disabled=true;
						myForm.FARETYPE.value = "ECONOMY";
						//myForm.SEARCH_TYPE.value = "0";
						myForm.SEARCH_TYPE.disabled = true;
						myForm.SEARCHON[0].disabled = true;
						myForm.SEARCHON[1].disabled = true;
						myForm.SEARCHON[2].disabled = true;
					} else {
						myForm.AWARDS.value = "NO";
						//myForm.SEARCHON[1].value = "price";
						myForm.AWARD_LEVEL.value = "";
						myForm.AWARD_LEVEL.disabled=true;
						if (myForm.classOfService[0].selected) {
							myForm.FARETYPE.value = "BUSINESS"
						} else {
							myForm.FARETYPE.value = "ECONOMY"
						}
					}
				}
			}
			
			if (myForm.TRIP_TYPE) {
				if(myForm.TRIP_TYPE[1].checked) {
				// One-way
					myForm.SEARCH_TYPE.value = "0";
					myForm.RETDATE.value = "";
					myForm.returnDay.value = "";
					myForm.returnMonth.value = "";
					myForm.RETDATE.disabled = true;
					myForm.returnDay.disabled = true;
					myForm.returnMonth.disabled = true;
				} else if(myForm.TRIP_TYPE[0].checked) {
					myForm.SEARCH_TYPE.value = "1";
				}
			}

			//disable non-use value
			myForm.departMonth.disabled = true;
			myForm.departDay.disabled = true;
			if (myForm.TRIP_TYPE) {
				myForm.TRIP_TYPE.disabled = true;			
				myForm.returnMonth.disabled = true;
				myForm.returnDay.disabled = true;
				myForm.classOfService.disabled = true;
				myForm.TRIP_TYPE[0].disabled = true;
				myForm.TRIP_TYPE[1].disabled = true;
			}	
			
		}*/
		//End of change
//added by ptogle 29 Dec 2004
var monthArr = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];

function getMonthValue(mon) {
   for (var i=0; i<monthArr.length; i++) {
      if (monthArr[i]==mon) {
         return i;
      }
   }
}

function isNumeric(str) {
   if (str.match(/^\d+$/))
      return true;
   else
      return false;
}

function getChosenYear(typ, mon) {
   var frm = document.orbot;
   var firstMonthOnDropDown = 1;
   if (typ.match(/depart/))
      firstMonthOnDropDown = frm.departMonth.options[0].value;
   else
      firstMonthOnDropDown = frm.returnMonth.options[0].value;
  
   var current = new Date();
   var current_mon = current.getMonth();
   var current_day = current.getDate();
   var current_yr = current.getFullYear();
   chosenYear = current_yr;
   //month is not January and is less than the
   //first month on the dropdown
   //thus, month is after the current year
   if (firstMonthOnDropDown > 1 && mon < firstMonthOnDropDown) {
      chosenYear++;
   }

   return chosenYear;
}

function changeDate(typ) {
   var frm = document.orbot;
   if (typ.toLowerCase()=="depart") {
      //retrieve depart
      var selectedMonthYear = frm.departMonth.value;
      if (!(selectedMonthYear.indexOf(' ')<0)) { //check if Year is available
         var monthYearArr = selectedMonthYear.split(' ');
         var selectedMonth = monthYearArr[0];
         if (isNumeric(selectedMonth)) {
            selectedMonth = monthYearArr[0]/1;
            month = selectedMonth-1;
            year = getChosenYear(typ, selectedMonth);
         } else {
            month = getMonthValue(selectedMonth);
            year = getChosenYear(typ, getMonthValue(selectedMonth)+1);
         }
      } else {
         if (isNumeric(selectedMonthYear)) {
            selectedMonthYear = selectedMonthYear/1; //get the numeric equivalent of the chosen month.
            month = selectedMonthYear-1;
            year = getChosenYear(typ, selectedMonthYear);
         } else {
            month = getMonthValue(selectedMonthYear);
            year = getChosenYear(typ, getMonthValue(selectedMonthYear)+1);
         }
      }
      day = frm.departDay.options[frm.departDay.selectedIndex].text;
   } else {
      //retrieve return
      var selectedMonthYear = frm.returnMonth.value;
      if (!(selectedMonthYear.indexOf(' ')<0)) { //check if Year is available
         var monthYearArr = selectedMonthYear.split(' ');
         var selectedMonth = monthYearArr[0];
         if (isNumeric(selectedMonth)) {
            selectedMonth = monthYearArr[0]/1;
            month = selectedMonth-1;
            year = getChosenYear(typ, selectedMonth);
         } else {
            month = getMonthValue(selectedMonth);
            year = getChosenYear(typ, getMonthValue(selectedMonth)+1);
         }
      } else {
         if (isNumeric(selectedMonthYear)) {
            selectedMonthYear = selectedMonthYear/1; //get the numeric equivalent of the chosen month.
            month = selectedMonthYear-1;
            year = getChosenYear(typ, selectedMonthYear);
         } else {
            month = getMonthValue(selectedMonthYear);
            year = getChosenYear(typ, getMonthValue(selectedMonthYear)+1);
         }
      }
      day = frm.returnDay.options[frm.returnDay.selectedIndex].text;
   }
}
//end of addition

function newWindow(location, myForm, fieldname1,fieldname2,fieldname3,evnt) {
   if (myForm.TRIP_TYPE) {
      if (myForm.TRIP_TYPE[1].disabled == true && location == "2") {
               // nothing to do
      } else {
         //if-else block added by ptogle 29 Dec 2004
         if (fieldname1.name.match(/depart/) != null)
            changeDate('depart');
         else
            changeDate('return');
         text_field1 = fieldname1;
         text_field2 = fieldname2;
         text_field3 = fieldname3;
         var properties = "left=" + (evnt.screenX + 20);
         properties += ",top=" + (evnt.screenY + 1);
         properties += ",titlebar=0,resizable=no,width=205,height=195";

         mywindow=open('http://www.nwa.com/asia/jp/cal_new.html','myname',properties);
         mywindow.location.href = 'http://www.nwa.com/asia/jp/cal_new.html';

         if (mywindow.opener == null) mywindow.opener = self;
         mywindow.focus();
      }
   }
   else {
      //if-else block added by ptogle 29 Dec 2004
      if (fieldname1.name.match(/depart/) != null)
         changeDate('depart');
      else
         changeDate('return');
      text_field1 = fieldname1;
      text_field2 = fieldname2;
      text_field3 = fieldname3;
      var properties = "left=" + (evnt.screenX + 20);
      properties += ",top=" + (evnt.screenY + 1);
      properties += ",titlebar=0,resizable=no,width=205,height=195";

      mywindow=open('http://www.nwa.com/asia/jp/cal_new.html','myname',properties);
      mywindow.location.href = 'http://www.nwa.com/asia/jp/cal_new.html';

      if (mywindow.opener == null) mywindow.opener = self;
      mywindow.focus();
   }
}

		function input_WP_number() {
			var WorldPerks = get_cookie("WorldPerks");
			if (WorldPerks != "") {
				var cookie_flds = WorldPerks.split('&');
				return ('<input type="text" size="7" name="WP" maxlength="12" class="inputText" onBlur="this.value=stringFilter(this.value)" value="'+cookie_flds[0]+'">\n');
			}
			return ('<input type="text" size="7" name="WP" maxlength="12" class="inputText" onBlur="this.value=numberFilter(this.value);">');
		}

      // Added function for checkin prefills
      //function checkinset() {
      //   var WorldPerks = get_cookie("WorldPerks");
      //   if (WorldPerks != "") {
      //      var cookie_flds = WorldPerks.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 setform(s) {
  with (document.forms.wpform) {
     document.forms.wpform.action = "https://www.nwa.com/cgi-bin/rres_info.pro?lang=jp";
     WpNum.value = account.value;
     LastName.value = name.value;
     Pin.value=pin.value;
  }
}

function setFormAction() {
  with (document.forms.wpform) {
     document.forms.wpform.action = document.forms.wpform.wpformopt.value;
     //alert(document.forms.wpform.action);
     WpNum.value = account.value;
     LastName.value = name.value;
     Pin.value=pin.value;
  }
}

		function get_WP_display_info(widthparam) {
			var WorldPerks = get_cookie("WorldPerks");
         var tablewidth = 230;
         if (widthparam > 0) {
            tablewidth = widthparam;
         }
    var wpheadstart = '<table border="0" width="230" cellpadding="3" cellspacing="0" class="formHeader"><tr><td class="formHeader">My NWA Info</td>';
			if (WorldPerks != "") {
				var cookie_flds = WorldPerks.split('&');
        var TierLevel = cookie_flds[4];
        if (TierLevel.toLowerCase() == "platinum") {
            TierLevel = 'プラチナエリート';
			}
        else if (TierLevel.toLowerCase() == "gold") {
            TierLevel = 'ゴールドエリート';
        }
        else if (TierLevel.toLowerCase() == "silver") {
            TierLevel = 'シルバーエリート';
        }
        else { //base
            TierLevel = '一般';
        }
        return(wpheadstart+'<td align="right"><span class="gtLink">&gt;&nbsp;</span><a href="javascript:logout_worldperks_home()">ログアウト</a></td></tr></table>'+
				'<img src="http://www.nwa.com/asia/images/shared/spacer_white.gif" border="0" width="230" height="2" alt=""><br>' +
				'<table border="0" width="230" cellpadding="5" cellspacing="0" class="formTable"><tr><td class="height-55px"><span class="wplogin-name">'+
				cookie_flds[2]+' '+cookie_flds[1]+
				'</span><br>ワールドパークス '+TierLevel+'会員<br>'+Comma(cookie_flds[6])+' 使用可能マイル残数'+ 
				'<br><span class="gtLink">&gt;&nbsp;</span><a href="https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=jp">最新のマイル情報を取得</a></td></tr>'+
				'<tr><td class="height-101px"><span class="gtLink">&gt;&nbsp;</span><a href="https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=jp">会員口座サマリー</a><br>'+
				'<span class="gtLink">&gt;&nbsp;</span><a href="http://www.nwa.com/asia/jp/worldperks/direct/index.html">会員口座情報</a><br>'+
				'<span class="gtLink">&gt;&nbsp;</span><a href="https://www.nwa.com/cgi-bin/rres_info.pro?lang=jp">予約確認・変更</a><br>'+
				'<span class="gtLink">&gt;&nbsp;</span><a href="https://www.nwa.com/cgi-bin/rres_info.pro?lang=jp">リコンファーム</a><br>'+
				'<span class="gtLink">&gt;&nbsp;</span><a href="https://www.nwa.com/prefs/jp/jp/FlightUpdates">旅行に関する通知の設定</a><br>'+
				'<span class="gtLink">&gt;&nbsp;</span><a href="https://www.nwa.com/prefs/jp/jp/NWAEmail">Eメール・エクスプレス登録・変更</a>'+
				'</td></tr></table>');
    }
    return (wpheadstart + 
				'<td><a href="https://www.nwa.com/cgi-bin/jp/wp_enroll.pro"><img src="http://www.nwa.com/asia/jp/images/button_enroll_in_wp_jp_s.gif" width="120" border="0" alt="Enroll in WorldPerks" align="right"></a></td></tr></table>'+
				'<img src="http://www.nwa.com/asia/images/shared/spacer_white.gif" border="0" width="230" height="2" alt=""><br>' +
				'<form method="post" action="https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=jp" name="wpform"><table border="0" width="230" cellpadding="5" cellspacing="0" class="formTable"><tr><td valign="bottom" class="height-40px">'+
				'ワールドパークス<br>会員番号<br><input type="text" size="8" name="account" maxlength="12" class="inputText" tabindex="40">'+
				'<input type="hidden" name="WpNum" value=""><input type="hidden" name="LastName" value=""><input type="hidden" name="Pin" value=""><input type="hidden" name="referer" value="1"><input type="hidden" name="First" value="1"><input type="hidden" name="wp_num"><input type="hidden" name="wp_pin" value=""><input type="hidden" name="Login" value=""> <input type="hidden" name="lang" value="jp">  </td>'+
				'<td valign="bottom" class="height-40px">姓 (Last Name)<br><input type="text" size="8" name="name" maxlength="40" class="inputText" tabindex="41"></td></tr><tr><td colspan="2" class="height-40px">'+
				'<table border="0" cellpadding="0" cellspacing="0"><tr><td class="pad-no-top" valign="bottom">PIN</td><td class="pad-no-top" valign="bottom"><span class="gtLink">&gt;&nbsp;</span><a href="http://www.nwa.com/asia/jp/worldperks/pinhelp.html"><nobr>PIN について</nobr></a></td></tr>'+
				'<tr><td class="pad-no-top"><input type="password" size="5" maxlength="4" name="pin" class="inputText-small" tabindex="42"><input type="checkbox" name="save_pin" value="Y" checked /></td><td class="pad-no-top"><nobr>PINをPCに保存する</nobr></td></tr></table></td></tr><tr><td colspan="2" class="height-40px-bot">'+
				'<select onChange="setFormAction();" name="wpformopt" tabindex="43">'+
				'<option value="https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=jp">会員口座サマリー</option>'+
				'<option value="http://www.nwa.com/asia/jp/worldperks/direct/index.html">会員口座情報</option>'+
				'<option value="https://www.nwa.com/cgi-bin/rres_info.pro?lang=jp">予約確認・変更</option>'+
				'<option value="https://www.nwa.com/cgi-bin/rres_info.pro?lang=jp">リコンファーム</option>'+
				'<option value="https://www.nwa.com/prefs/jp/jp/FlightUpdates">旅行に関する通知の設定</option>'+
				'<option value="https://www.nwa.com/prefs/jp/jp/NWAEmail">Eメール・エクスプレス登録・変更</option></select>'+
				'</td></tr><tr><td colspan="2" class="height-30px">'+
				'<table border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td class="pad-no-top"><input type="image" name="submit" src="http://www.nwa.com/asia/jp/images/button_go.gif" width="25" height="15" border="0" alt="Go" align="right" value="" tabindex="44"><br><img src="http://www.nwa.com/images/clear.gif" border="0" width="1" height="10" alt=""></td></tr></table>' +
				'</td></tr></table></form>');
		}	

		var stylesheet = "http://www.nwa.com/includes/css/styles.css";
		if (document.layers) { stylesheet = "http://www.nwa.com/includes/css/styles_ns4.css"; }		
		document.write('<link rel="stylesheet" type="text/css" href="' + stylesheet + '" />');	
	
		function remove_cookie (name)
		{
		   document.cookie = name + "=; path=/; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=.nwa.com";
		}

		function logout_worldperks_home ()
		{
		   remove_cookie("WorldPerks");
		   remove_cookie("WP_PIN");
                   remove_cookie("orbot");
                   remove_cookie("form0");
		   // alert("You have successfully logged out of WorldPerks");
			alert('ログアウトしました。');
		   location = "http://www.nwa.com/jp/jp/";
		}



function newin (url)
{
popWindow = window.open(url,"popWindow","toolbar=no,directories=no,status=no,scrollbars=yes,resizable=no,menubar=no, width=730, height=550")
popWindow.opener = self;
popWindow.focus();
}
// End append

//default stylesheet name
var stylesheet = "http://www.nwa.com/includes/css/styles.css";

//netscape 4 browsers use a different stylesheet
if (document.layers) {
	stylesheet = "http://www.nwa.com/includes/css/styles_ns4.css";
}

document.write('<link rel="stylesheet" type="text/css" href="' + stylesheet + '" />');		

function pnrFilter (string) {
   sfilter = string;
   var i;
   var returnString = "";
   for (i = 0; i < sfilter.length; i++) {
      var c = sfilter.charAt(i);
      if (c == "0") { returnString += "O"; }
      else if (c == "1") { returnString += "I"; }
      else { returnString += c; }
   }
   return returnString;
}

function setCheckInType() {
    var optnum = document.forms.form0.checkInType.selectedIndex;
    var checkInTypeArr=['RL','WP','ET'];
    var checkInType=checkInTypeArr[optnum];
	document.forms.form0.RL.value = "";
	document.forms.form0.ET.value = "";
	if (optnum==0){
		document.getElementById('RL').style.display="inline";
		document.getElementById('WP').style.display="none";
		document.getElementById('ET').style.display="none";
		document.forms.form0.WP.value = "";
		document.forms.form0.RL.focus();
	}
	else if (optnum==1){
		document.getElementById('WP').style.display="inline";
		document.getElementById('RL').style.display="none";
		document.getElementById('ET').style.display="none";
		document.forms.form0.WP.focus();
	}
        else if (optnum==2){
		document.getElementById('WP').style.display="none";
		document.getElementById('RL').style.display="none";
		document.getElementById('ET').style.display="inline";
		document.forms.form0.WP.value = "";
		document.forms.form0.ET.focus();
	}
}

function checkinset() {
	var WorldPerks = get_cookie("WorldPerks");
	if (WorldPerks != "") {
		var cookie_flds=WorldPerks.split('&');
		document.form0.LastName.value=cookie_flds[1];
		document.form0.WP.value=cookie_flds[0];
 	}
	if (document.form0.WP.value == ""){
		if (document.form0.checkInType) {
		    document.form0.checkInType.selectedIndex="0";
		    document.getElementById('WP').style.display="none";
		    document.getElementById('RL').style.display="inline";
		    document.getElementById('ET').style.display="none";
		}
	}
	else{
		if (document.form0.checkInType) {
		    document.form0.checkInType.selectedIndex="1";
		    document.getElementById('WP').style.display="inline";
		    document.getElementById('RL').style.display="none";
		    document.getElementById('ET').style.display="none";
                }
	}
        DQM_handleOnload();
}

function readPrefCookie() {

    /* Checks if user is logged in */
    if (!(get_cookie("WorldPerks"))) {
        return;
    }

    var cookPairs= new Array;
    var ca = document.cookie.split(';');
    var checkCheckInMMR = 0;
	var mDepart= 0;
    var mReturn= 0;
	var dDepart= 0;
    var dReturn= 0;
	var today = new Date();
	var departFlag = false;
	var currentDay = today.getDate();
	var currentMonth = today.getMonth();
	var currentYear = today.getFullYear();
	currentMonth += 1;

    //loop through all forms on page
    for (var h=0;h < document.forms.length; h++) {
		// loop only if it is check-in or MMR box
		if (checkCheckInMMR == 3) {
			break;
		}
        var fName =  document.forms[h].name;
        if (fName == "form0" || fName == "orbot") {
			checkCheckInMMR++;
            // loop through cookies if this cookie name is the same as the form name
            for (var i=0 ; i < ca.length; i++) {
                var c = ca[i];
                while (c.charAt(0)==' ') c = c.substring(1,c.length)
                {
                    if (c.indexOf(fName) == 0)
                    {
                        cookPairs =  c.substring(fName.length,c.length).split('&');
                    }
                }
                // loop through cookie Param/Value pairs
                for (var j=0;j < cookPairs.length; j++) {
                    cookParams = new Array;
                    cookParams = cookPairs[j].split('||');
                    // compare the Form element name, to the Param Name in our cookie
                    // and set the Form element Value = Cookie Param Value
                    for (var k=0; k<document.forms[h].elements.length; k++) {
                        if (cookParams[0] ==  document.forms[h].elements[k].name) {
                            if (cookParams[1] != "") {
                                switch (document.forms[h].elements[k].type) {
                                    case "checkbox":
                                        if (cookParams[1]=="true")
                                        document.forms[h].elements[k].checked =  cookParams[1];
                                        break;
                                    case "radio":
                                        if (cookParams[1]==document.forms[h].elements[k].value) {
                                            document.forms[h].elements[k].checked =  true;
                                        }
                                        break;
                                    case "select-one":
										switch (cookParams[0]) {
											case "departMonth":
												mDepart = cookParams[1];
												break;
											case "departDay":
												dDepart = cookParams[1];
												break;
											case "returnMonth":
												mReturn = cookParams[1];
												break;
											case "returnDay":
												dReturn = cookParams[1];
												break;
											default :
												if (cookParams[0] == "checkInType") {
													document.forms[h].elements[k].selectedIndex = cookParams[1];
												}
												else {
													document.forms[h].elements[k].value =  cookParams[1];
												}
												break;
                                            }
									default :
										if (cookParams[0] == "departMonth" || cookParams[0] == "departDay" ||
											cookParams[0] == "returnMonth" || cookParams[0] == "returnDay")
										{
                                            break;
                                        }
                                        else if (cookParams[0] == "checkInType") {
                                            break;
                                        }
										else if (!cookParams[1]) {
                                            break;
                                        }
                                        else {
                                            document.forms[h].elements[k].value = cookParams[1];
                                        }
                                        break;
                                }//switch
                            }//if
                        }//if
                    }//for
                }//for
            }//for
        }//if
    }//for
	var dMonth = document.orbot.departMonth;
	var dDay = document.orbot.departDay;
	var rMonth = document.orbot.returnMonth;
	var rDay = document.orbot.returnDay;
        if (dMonth && dDay && rMonth && rDay){
	/* If conditions not satisfied, show default dates */
	if (mDepart == currentMonth && dDepart >= currentDay) {
		dMonth.value = mDepart;
		dDay.value = dDepart;
	}
	else if (mDepart > currentMonth) {
		dMonth.value = mDepart;
		dDay.value = dDepart;
	}
	else {
		departFlag = true;
	}
	/* If condition not satisfied, calculate correct additional days */
	if (mReturn > currentMonth && mReturn > mDepart && departFlag == false) {
		rMonth.value = mReturn;
		rDay.value = dReturn;
		departFlag = true;
	}
	/* Calculate correct Return month and day */
	if (departFlag == false) {
		var tempDayRet = dDay.selectedIndex + 7;
		if ((mDepart == 2) && ((currentYear%4) == 0)) { //Feb leap year
			if (tempDayRet > 28) {
				rDay.selectedIndex = tempDayRet - 29;
				departFlag=true;
			}
		}
		else if ((mDepart == 2) && ((currentYear%4) != 0)) { //Feb not leap year
			if (tempDayRet > 27) {
				rDay.selectedIndex = tempDayRet - 28;
				departFlag=true;
			}
		}
		else if ((mDepart == 1) || (mDepart == 3) ||(mDepart == 5) ||(mDepart == 7) ||
			(mDepart == 8) ||(mDepart == 10) || (mDepart == 12)) //Months with 31 days
		{
			if (tempDayRet > 30) {
				rDay.selectedIndex = tempDayRet - 31;
				departFlag=true;
			}
		}
		else { //Months with 30 days
			if (tempDayRet > 29) {
				rDay.selectedIndex = tempDayRet - 30;
				departFlag=true;
			}
		}
		if (departFlag == true) {
			var tempMonthRet = dMonth.selectedIndex + 1;
			if (tempMonthRet > 11) {
				rMonth.selectedIndex = 0;
			}
			else {
				rMonth.selectedIndex = tempMonthRet;
			}
		}
		else {
			rDay.selectedIndex = tempDayRet;
			rMonth.selectedIndex = dMonth.selectedIndex;
		}
	}
        }
	/* If WP # is not selected, reset MMR and check-in */
	setCheckInType();
    checkReturn();
	/* When this is an award, disable return date and class of service */	
	if ((document.orbot.SEARCHON[2])&&(document.orbot.SEARCHON[2].checked)) {
		enableButton(false,document.orbot)
	}
}//function

function setPrefCookie(theForm) {

    /* Checks if user is logged in */
    if (!(get_cookie("WorldPerks"))) {
        return;
    }

	/* Refresh cookie first */
	remove_cookie(theForm.name);

	var cookVal =  theForm.name +"=";
	var exdate=new Date()
	exdate.setTime(exdate.getTime()+(150*24*60*60*1000));
	var expires = "; expires="+exdate.toGMTString();
	expires += "; path=/; domain=.nwa.com;";
	for(i=0; i<theForm.elements.length; i++){
		switch (theForm.elements[i].type)
		{
			case "hidden":
				break;
			case "text" :
				if (theForm.elements[i].name != "WP" && theForm.elements[i].name != "RL" && theForm.elements[i].name != "ET") {
					cookVal +=  '&' + theForm.elements[i].name + '||' +  theForm.elements[i].value;
				}
				break;
			case "textarea":
				cookVal += '&' + theForm.elements[i].name + '||' +  theForm.elements[i].value;
				break;
			case "checkbox":
				cookVal += '&' + theForm.elements[i].name + '||' +  theForm.elements[i].checked;
				break;
			case "select-one":
				if (theForm.elements[i].name == "checkInType") {
					cookVal += '&' + theForm.elements[i].name + '||' + theForm.elements[i].selectedIndex;
				} 
				else {
					cookVal += '&' + theForm.elements[i].name + '||' + theForm.elements[i].options[theForm.elements[i].selectedIndex].value ;
				}
				break;
			case "radio":
				if (theForm.elements[i].checked == true)
				{
					cookVal += '&' + theForm.elements[i].name + '||' + theForm.elements[i].value;
				}
				else{
					//nothing
					break;
				}
				break;
			default:
				break;
		}//switch
	}//for
	document.cookie= cookVal +  expires;
}//setPrefCookie

function checkReturn(){
    if ((document.orbot) && (document.orbot.TRIP_TYPE)){
		if (document.orbot.TRIP_TYPE[0].checked)
		{
			document.orbot.returnMonth.disabled=false;
			document.orbot.returnDay.disabled=false;
		}
		else{
			document.orbot.returnMonth.disabled=true;
			document.orbot.returnDay.disabled=true;
		}
    }
}

//Added by Mich 08/02/2007

function futureDate(daysOut){
	var today = new Date();
	var todayInMS = today.getTime(); // today in MilliSeconds
	var nextDate = todayInMS + (60 * 60 * 24 * daysOut * 1000);
	return new Date(nextDate);
}

function setDate1() {
	var date1 = cal1.getSelectedDates()[0];
	departMonth.selectedIndex=date1.getMonth();
	departDay.selectedIndex=date1.getDate()-1;
	cal1.hide();
	changeReturn();
}

function setDate2() {
	var date2 = cal2.getSelectedDates()[0];
	returnMonth.selectedIndex=date2.getMonth();
	returnDay.selectedIndex=date2.getDate()-1;
	cal2.hide();
	//showTimeSelector();
}

function changeDate1() {

	var monthValues = document.orbot.departMonth.value.split(' ');                                
	var month = this.departMonth.selectedIndex;
	var day = this.departDay.selectedIndex ;
	var year= parseInt(monthValues[1]);
	cal1.setYear(year);
	cal1.setMonth(month);
	cal1.select((month+1) + "/" + (day+1) + "/" + year);
	cal1.render();
}
function changeDate2() {
	var month = this.returnMonth.selectedIndex;
	var day = this.returnDay.selectedIndex ;
	var monthValues = document.orbot.returnMonth.value.split(' ');//example: Jan 2007
	var year= parseInt(monthValues[1]);
	cal2.setYear(year);
	cal2.setMonth(month);
	cal2.select((month+1) + "/" + (day+1) + "/" + year);
	for (var i = 0 ; i < cal2.pages.length; i++){
		if (cal1.getSelectedDates()[0] < today.getDate){	
			cal2.pages[i].minDate=today.getDate();
		}
		else{
			cal2.pages[i].minDate=cal1.getSelectedDates()[0];
		}
		cal2.pages[i].maxDate=futureDate(352);
	}
	cal2.render();
}

function showCalendar1() {
        cal2.hide();
        var cont1 = document.getElementById('container1')
       if (IE){
        cont1.style.top = (link1.offsetTop+400) + "px";
        cont1.style.left = (link1.offsetLeft+260) + "px";
       } else{
        cont1.style.top = (link1.offsetTop+40) + "px";
        cont1.style.left = (link1.offsetLeft+270) + "px";
       
       }
        cal1.outerContainer.style.display='inline';
}

function showCalendar2() {
        cal1.hide();
        var cont2 = document.getElementById('container2')
        if (IE){
			cont2.style.top = (link1.offsetTop+430) + "px";
			cont2.style.left = (link1.offsetLeft+260) + "px";
       	} else{
			cont2.style.top = (link1.offsetTop+60) + "px";
			cont2.style.left = (link1.offsetLeft+270) + "px";
       	}
        cal2.outerContainer.style.display='inline';
}

function init() {
	this.today = new Date();
	var departDate = futureDate(7);
	var returnDate = futureDate(14);

	var departDateMonth = departDate.getMonth();
	var departDateDay = departDate.getDate();
	var departDateYear = departDate.getFullYear();

	this.link1 = document.getElementById('dateLink1');
	this.link2 = document.getElementById('dateLink2');

	this.departMonth = document.getElementById('departMonth');
	this.departDay = document.getElementById('departDay');

	this.departMonth.selectedIndex = departDateMonth;
	this.departDay.selectedIndex = departDateDay-1;

	var returnDateMonth = returnDate.getMonth();
	var returnDateDay = returnDate.getDate();
	var returnDateYear = returnDate.getFullYear();

	this.returnMonth = document.getElementById('returnMonth');
	this.returnDay = document.getElementById('returnDay');

	this.returnMonth.selectedIndex = returnDateMonth;
	this.returnDay.selectedIndex = returnDateDay-1;
	

	cal1 = new YAHOO.widget.Calendar2up("cal1","container1",(departDateMonth+1)+"/"+departDateYear,(departDateMonth+1)+"/"+departDateDay+"/"+departDateYear);
	cal1.title = "Departure date:";
	cal1.setChildFunction("onSelect",setDate1);
	for (var i = 0 ; i < cal1.pages.length; i++){
                                cal1.pages[i].minDate=today;
                                cal1.pages[i].maxDate=futureDate(352);
	}
	cal1.render();
	cal2 = new YAHOO.widget.Calendar2up("cal2","container2",(returnDateMonth+1)+"/"+returnDateYear,(returnDateMonth+1)+"/"+returnDateDay+"/"+returnDateYear);
	cal2.title = "Return date:";
	cal2.setChildFunction("onSelect",setDate2);
	for (var i = 0 ; i < cal2.pages.length; i++){
                                cal2.pages[i].minDate=today;
                                cal2.pages[i].maxDate=futureDate(352);
	}
	cal2.render();
}
//End of change
