//new common.js for Asia started 06/17/08 -- dm

// jQuery function to toggle FAQ arrow state
$(document).ready(function() {
    setHL();
	setNWLogoLink();
	$("#wperks").children().replaceWith("<a href=\"/asia/en/skymiles/\"><span>SkyMiles <sup>&reg;</sup></span></a>");
	$("#wperks_active").children().replaceWith("<a href=\"/asia/en/skymiles/\"><span>SkyMiles <sup>&reg;</sup></span></a>");	
});

// take care of Login/Logout for AsiaEn pages

function setHL() {
                var SkyMiles = get_cookie("WorldPerks");
                if (SkyMiles != "") {
                        $(".headerSecondaryNavigationLink:eq(1)").replaceWith("<a href=\"javascript:logout_skymiles_home_asiaen()\" class=\"headerSecondaryNavigationLink\">Logout</a>");
                } else {
                        $(".headerSecondaryNavigationLink:eq(1)").replaceWith("<a href=\"https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=en\"class=\"headerSecondaryNavigationLink\">Login</a>");
                }
}
function setMyNWAInfoHL() {
                var SkyMiles = get_cookie("WorldPerks");
                if (SkyMiles != "") {
                        $(".headerSecondaryNavigationLinkMyNWAInfo:eq(1)").replaceWith("<a href=\"javascript:logout_skymiles_my_nwa_info()\" class=\"headerSecondaryNavigationLinkMyNWAInfo\">Logout</a>");
                } else {
                        $(".headerSecondaryNavigationLinkMyNWAInfo:eq(1)").replaceWith("<a href=\"https://www.nwa.com/cgi-bin/rwp_acctsum.pro?lang=en\"class=\"headerSecondaryNavigationLinkMyNWAInfo\">Login</a>");
                }
}
function setNWLogoLink () {
	$("#nwLogoDiv").replaceWith("<div class=\"nwLogoDiv\" id=\"nwLogoDiv\" href=\"#\" onClick=\"javascript:HomePage('en');\"></div>");
}
function logout_skymiles_home_asiaen () {
    remove_cookie("WorldPerks");
    remove_cookie("WP_PIN");
   remove_cookie("NWASSOToken");
    remove_cookie("form0");
    remove_cookie("orbot");
    remove_cookie("NWASSOToken");
    alert("You have successfully logged out.");
    if (visitordata.country_code != null) {
        if (visitordata.lang_code != null) {
            location = serverName + "/" + visitordata.country_code + "/" + visitordata.lang_code;
        } else {
            location = serverName + "/" + visitordata.country_code + "/" + en;
        }
    } else {
        location = serverName + "/hk/en";
    }
}

function HomePage(varLangCode)	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {
				location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/home.html";
			}
		}
}

function SkyMilesHome(varLangCode) {
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {
				location.href = serverName + "/asia/" + varLangCode + "/skymiles/";
			}
		}
}
function LandingPagesLoginInfoAsiaEn() {
var SkyMiles = get_cookie("WorldPerks");
if (SkyMiles != "") {
	var cookie_flds = SkyMiles.split('&');
	var TierLevel = cookie_flds[4];
	if (TierLevel.toLowerCase() == "base") {
		TierLevel = '';
	}
                var divstart = '<div class="promotionsBannerWPLoggedIn"><span class="landingPageWPInfo">'+cookie_flds[2]+' '+cookie_flds[1]+'</span><br /><span class="landingPageWPInfo">SkyMiles '+TierLevel+' Member</span><br /><span class="landingPageWPInfo"> '+Comma(cookie_flds[6])+' Available Miles</span></div>';
                return divstart;
}
else {
	var divstart = '<div class="promotionsBannerWPLoggedOut"><a href="https://www.nwa.com/cgi-bin/rmynwainfo.pro?lang=en" class="landingPageWPInfo">Login to view My NWA Info</a> <span class="landingPageWPInfo">&gt;</span></div>';
	return divstart;
	}
}

// Functions harvested from Asia/En

var serverName = "http://www.nwa.com";

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;
}

function nwati(varLangCode) {
    if (visitordata.country_code != null) {
        if (visitordata.country_code == "asia") {
            location.href = serverName + "/asia";
        } else {
            location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/talk/index.html";
        }
    }
}

	function emailexpress(varLangCode)
	{
		serverName = "https://www.nwa.com";
		if (varLangCode == "sc")
		{
			location.href = serverName + "/prefs/cn/sc/NWAEmail";
		}
		else if (varLangCode == "kr")
		{
			location.href = serverName + "/prefs/kr/kr/NWAEmail";
		}
		else if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} 
			else {
				location.href = serverName + "/prefs/" + visitordata.country_code + "/" + varLangCode + "/NWAEmail";
			}
		}
	}
function Reservations(type, lang)
{
	// lang : EN_US
	//varLangCode: en, sc, tc, kr
	var country_code_cap = visitordata.country_code.toUpperCase();
	var lang_code_bkeng = "";
	if (lang == "EN_US"){
		lang_code_bkeng = "en";
	}
	else if (lang == "KO"){
		lang_code_bkeng = "ko";
	}
	else if (lang == "ZH_TW" || lang == "ZH_CN"){
		lang_code_bkeng = "zh";
	}
	else if (lang == "JA"){
		lang_code_bkeng = "ja";
	}
	
	if (visitordata.country_code != null) {
		if (visitordata.country_code == "asia" || visitordata.country_code == "") {
			location.href = serverName + "/booknwa";
		} else {			
			if (type == "WWR") { //WWR - Shop for flight
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					location.href = "http://www.nwa.com/asia/en/bookingform.html";
				}
				else {
					location.href = "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng;
				}
			}
			else if (type == "PKC")
			{ // PKC
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					location.href = "http://asiares.nwa.com/?siteCode=AP&lang=en&awardtravelsearch&discountCommand.perkChoiceSelected=true";
				}
				else{
					location.href =  "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng + "&awardtravelsearch&discountCommand.perkChoiceSelected=true";
				}
			}
			else 
			{ // ATR - Award Travel Reservations
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					location.href = "http://asiares.nwa.com/?siteCode=AP&lang=en&searchRequest.worldPerksAwardFlight=on";
				}
				else{
					location.href =  "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng + "&searchRequest.worldPerksAwardFlight=on&searchBy=awardtravelsearch";
				}
			}
			
		}
	}
	else {
			location.href = serverName + "/booknwa";
	}
}
	function Octopus(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {
				if (varLangCode == "kr") {
					location.href = serverName + "/kr/kr/travel/octopus/index.html";
				} else {
					location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/travel/octopus/index.html";
				}
			}
		}
	}
	
	
	function gprequest(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = "https://www.nwa.com/asia";
			} else {
				location.href = "https://www.nwa.com/" + visitordata.country_code + "/" + varLangCode + "/grouprequest/";
			}
		}
	}

		function NwaTimeTable(varLangCode)
        {
                if (varLangCode != null) {
                	
					if (varLangCode == "jp") {
						location.href = "http://www.nwa.com/jp/jp/travel/timetable/ ";
					}
					else {       
						location.href = serverName + "/asia/" + varLangCode + "/timetable/index.html";
					} 
                }
                else
                    location.href = serverName + "/alliance/";
		}
        function FlightAlert(varLangCode)
        {
                if (visitordata.country_code != null && varLangCode != null) {
                        if (visitordata.country_code == "asia") {
                                location.href = serverName + "/asia";
                        } else {
                                location.href = "https://www.nwa.com/prefs/" + visitordata.country_code + "/" + varLangCode + "/FlightUpdates";
                        }
                }
                else
                        location.href = serverName + "/alliance/";
        }
	function bizperks(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {
				location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/bizperks.html";
			}
		}
		
	}

	function Nwapr(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {				
				location.href = serverName + "/asia/" + varLangCode + "/deals";
			}
		}
	}
		function checkin(varLangCode) {

		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {
				location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/checkin/index.html";
			}
		}
	}

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 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;
	}
	
// 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;
        }
		
new Cookie();
Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;

var visitordata = new Cookie(document, "nwa", 240, "/");
visitordata.load();
var myURL = self.location.toString();
myURL = myURL.substring(myURL.indexOf(location.host) + location.host.length,myURL.length);
var myCountry = myURL.substring(1, myURL.indexOf("/",1));
var myLang = "";
if (myURL.indexOf("/en/") > -1) {
        myLang = "en";
} else if (myURL.indexOf("/kr/") > -1) {
        myLang = "kr";
} else if (myURL.indexOf("/sc/") > -1) {
        myLang = "sc";
} else if (myURL.indexOf("/tc/") > -1) {
        myLang = "tc";
}

if (myCountry != "cn" && myCountry != "gs" && myCountry != "hk" && myCountry != "id" && myCountry != "jp" && myCountry != "kr" && myCountry != "my" && myCountry != "ph" && myCountry != "sg" && myCountry != "tw" && myCountry != "th") {
        myCountry = "asia";
}

if (visitordata.country_code == null || !visitordata.country_code || (visitordata.country_code != myCountry && myCountry != "asia")) {
        var visitordata = new Cookie(document, "nwa", 240, "/");
        visitordata.country_code = myCountry;
        visitordata.lang_code = myLang;
        visitordata.store();
}

function NwaCareer(varLangCode)
{
        if (visitordata.country_code != null && varLangCode != null) {
	if (visitordata.country_code == "asia") {
		location.href = serverName + "/asia";
	} else {
	                location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/corpinfo/career/index.html";
	}
        }
        else
        {
                location.href = serverName + "/alliance/";
        }
        
}

// Function appened on 1/9/2003
function Newsc(varLangCode)
{
	if (visitordata.country_code != null) {
		if (visitordata.country_code == "asia") {
			location.href = serverName + "/asia";
		} else {
			location.href = "/" + visitordata.country_code + "/" + varLangCode + "/corpinfo/newsc/index.html";
		}
	}
	
}

function buyandgiftmiles(varLangCode) {
 if (visitordata.country_code=="jp" && varLangCode=="en") {
 location.href="https://buymiles.nwa.com/purchase.asp?lang=EJP";
 }
 else if (visitordata.country_code=="jp" && varLangCode=="ja") {
 location.href="https://buymiles.nwa.com/purchase.asp?lang=JPN";
 }
 else if ((visitordata.country_code=="tw" || visitordata.country_code=="hk") && varLangCode=="tc") {
 location.href="https://buymiles.nwa.com/purchase.asp?lang=TCH";
 }
 else if (visitordata.country_code=="cn" && varLangCode=="sc") {
 location.href="https://buymiles.nwa.com/purchase.asp?lang=SCH";
 }
 else if (visitordata.country_code=="kr" && varLangCode=="kr") {
 location.href="https://buymiles.nwa.com/purchase.asp?lang=KOR";
 }
 else {
 location.href="https://buymiles.nwa.com/purchase.asp?lang=EAS";
 }
}


 function bdate(bdate1) {
     var strmonth = bdate1.Month.value + "";
     var strday = bdate1.Day.value + "";
     var stryear = bdate1.Year.value + "";
     bdate1.BirthDate.value = (strmonth + strday + stryear);
     return true;
 }
 
 function multiFlightAsia(myForm) {
	 //document.orbot.offsite.value = false;
	 //document.orbot.rtOption.value = "multicity";
	 //myForm.submit();
	 
	 var typeRoundTrip = document.getElementById('rtOption');
	 var typeOneWay = document.getElementById('owOption');
	 var offsiteValue = document.orbot.offsite;
	 offsiteValue.value = false;
	 typeRoundTrip.value="multicity";

	 myForm.submit();
 }
 
 function moreOptionsAsia(myForm) {
	var tripMethodByPrice = document.getElementById('searchBy');
	var offsiteValue = document.orbot.offsite;
	offsiteValue.value = false;

	if (document.orbot.siteCode.value != "AP") {
		tripMethodByPrice.value = "schedulesearch";
	}
	 myForm.submit();
 }

 // Reads 'nwa' cookie to get the lang and country code. Then retruns MYNWAInfo URL for the page requested as input.
function getMyNWAInfoURL(pageName) {

    var urlValue = get_cookie('nwa');
    location.href = "/prefs/ap/en/" + pageName;

    if (urlValue) {
        var x = urlValue.split('&');
        var countryCode = "";
        var langCode = "";
        for (var i=0; i < x.length; i++) {

             var y = x[i].split(':');
             if (y.length >= 2) {
                if (y[0] == 'country_code') countryCode = y[1];
                if (y[0] == 'lang_code') langCode = y[1];
             }

        } // End of For Loop

       if (langCode != "" && countryCode != "")
          location.href = "/prefs/" + countryCode + "/" + langCode + "/" + pageName;


    } // End of if (urlValue)

} // End of funtion

// Reads 'nwa' cookie and returns the contact us link for specific country and language
function getContactUsURL() {

    var urlValue = get_cookie('nwa');
    location.href = "/cn/en/talk/contact.html";

    if (urlValue) {
       var x = urlValue.split('&');
       var countryCode = "";
       var langCode = "";
       for (var i=0; i < x.length; i++) {

           var y = x[i].split(':');
           if (y.length >= 2) {
              if (y[0] == 'country_code') countryCode = y[1];
              if (y[0] == 'lang_code') langCode = y[1];
           }

       } // End of For Loop

       if (langCode != "" && countryCode != "") {
          if (langCode == "jp" && countryCode == "jp")
             location.href = "/" + countryCode + "/" + langCode + "/contactus/index.html";
          else
             location.href = "/" + countryCode + "/" + langCode + "/talk/contact.html";
       }

    } // End of if (urlValue)

}  // End of funtion
function getCoordsWPLogoAsiaEn(event){
    pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("wpLogoDiv").offsetLeft;
    pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("wpLogoDiv").offsetTop;
	
	if (pos_y >= '30') {
		if (pos_x <= '82') {
			var url = "http://www.nwa.com/";
				location.href = "http://www.nwa.com/"+visitordata.country_code+"/"+visitordata.lang_code+"/";
		}		
		else {
			var url = "http://www.nwa.com/";
			if (visitordata.lang_code != null && visitordata.lang_code != "en") {
				url += "asia/"+visitordata.lang_code+"/skymiles/";
				location.href = url;
			}	
			else if (visitordata.lang_code == "en") {
				url += "asia/en/skymiles/";
				location.href = url;
			}
		}
	}
}	
function getCoordsWPLogo_LL(event){
    pos_x = event.offsetX?(event.offsetX):event.pageX-document.getElementById("wpLogoDiv").offsetLeft;
    pos_y = event.offsetY?(event.offsetY):event.pageY-document.getElementById("wpLogoDiv").offsetTop;
	try {
		console.log("pos_x = " + pos_x + "; pos_y = " + pos_y);
	}
	catch(err) {}
	
	if (pos_x <= '95') {
		location.href = "http://www.nwa.com/"+visitordata.country_code+"/"+visitordata.lang_code+"/";
	}
	/*
	else {	
		var url = "http://www.nwa.com/";
		if (visitordata.lang_code != null && visitordata.lang_code != "en") {
			url += "asia/"+visitordata.lang_code+"/skymiles/";
			location.href = url;
		}
		else if (visitordata.lang_code == "en") {
			url += "asia/en/skymiles/";
			location.href = url;
		}
		else {
			url += "skymiles/";
			location.href = url;
		}
	}
	*/
}
function ReservationsPopup(type, lang)
{
	// lang : EN_US
	//varLangCode: en, sc, tc, kr
	var country_code_cap = visitordata.country_code.toUpperCase();
	var lang_code_bkeng = "";
	if (lang == "EN_US"){
		lang_code_bkeng = "en";
	}
	else if (lang == "KO"){
		lang_code_bkeng = "ko";
	}
	else if (lang == "ZH_TW" || lang == "ZH_CN"){
		lang_code_bkeng = "zh";
	}
	else if (lang == "JA"){
		lang_code_bkeng = "ja";
	}

	var url = "";
	
	if (visitordata.country_code != null) {
		if (visitordata.country_code == "asia" || visitordata.country_code == "") {
			url = serverName + "/booknwa";
		} else {			
			if (type == "WWR") { //WWR - Shop for flight
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					url = "http://www.nwa.com/asia/en/bookingform.html";
				}
				else {
					url = "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng;
				}
			}
			else if (type == "PKC")
			{ // PKC
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					url = "http://asiares.nwa.com/?siteCode=AP&lang=en&awardtravelsearch&discountCommand.perkChoiceSelected=true";
				}
				else{
					url =  "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng + "&awardtravelsearch&discountCommand.perkChoiceSelected=true";
				}
			}
			else 
			{ // ATR - Award Travel Reservations
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					url = "http://asiares.nwa.com/?siteCode=AP&lang=en&searchRequest.worldPerksAwardFlight=on";
				}
				else{
					url =  "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng + "&searchRequest.worldPerksAwardFlight=on&searchBy=awardtravelsearch";
				}
			}
			
		}
	}
	else {
			url = serverName + "/booknwa";
	}

	OpenFullWindow (url, 800, 600);
}

//opens a popup window
function OpenFullWindow (url,width,height) {
	OpenWin = window.open(url, "CtrlWindow", "location=yes,status=yes,toolbar=yes,directories=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+ width + ",height=" + height + ",left=75,top=75");
}

//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");
}

//directs the customer to the correct agents site
function AgentGo()
        {
                if (visitordata.country_code != null) {
                        if (visitordata.country_code == "asia") {
                                location.href = serverName + "/asia";
                        } else {
                                location.href = "http://agents.nwa.com/" + visitordata.country_code;
                        }
                }
        }














function HomePage(varLangCode)	{

		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else if (visitordata.country_code == "au") {
location.href = serverName + "/asia/delta-sydney/";
			} else if (visitordata.country_code == "vn") {
location.href = serverName + "/asia/vietnam/";
			} else {
				location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/home.html";
			}
		}
}



function nwati(varLangCode) {

    if (visitordata.country_code != null) {
        if (visitordata.country_code == "asia") {
            location.href = serverName + "/asia";
		} else if (visitordata.country_code == "au") {
location.href = serverName + "/asia/delta-sydney/talk/";
		} else if (visitordata.country_code == "vn") {
location.href = serverName + "/asia/vietnam/talk/";
        } else {
            location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/talk/index.html";
        }
    }
}

function Reservations(type, lang)
{
	// lang : EN_US
	//varLangCode: en, sc, tc, kr
	var country_code_cap = visitordata.country_code.toUpperCase();

if((visitordata.country_code == "au" || visitordata.country_code == "vn") && type != "ATR"){
	nwati(visitordata.lang_code);
	return;
}

	var lang_code_bkeng = "";
	if (lang == "EN_US"){
		lang_code_bkeng = "en";
	}
	else if (lang == "KO"){
		lang_code_bkeng = "ko";
	}
	else if (lang == "ZH_TW" || lang == "ZH_CN"){
		lang_code_bkeng = "zh";
	}
	else if (lang == "JA"){
		lang_code_bkeng = "ja";
	}
	
	if (visitordata.country_code != null) {
		if (visitordata.country_code == "asia" || visitordata.country_code == "") {
			location.href = serverName + "/booknwa";
		} else {			
			if (type == "WWR") { //WWR - Shop for flight
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					location.href = "http://www.nwa.com/asia/en/bookingform.html";
				}
				else {
					location.href = "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng;
				}
			}
			else if (type == "PKC")
			{ // PKC
				if (visitordata.country_code == "my" || visitordata.country_code == "id") {
					location.href = "http://asiares.nwa.com/?siteCode=AP&lang=en&awardtravelsearch&discountCommand.perkChoiceSelected=true";
				}
				else{
					location.href =  "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng + "&awardtravelsearch&discountCommand.perkChoiceSelected=true";
				}
			}
			else 
			{ // ATR - Award Travel Reservations
				if (visitordata.country_code == "my" || visitordata.country_code == "id" || visitordata.country_code == "au" || visitordata.country_code == "vn") {
					location.href = "http://asiares.nwa.com/?siteCode=AP&lang=en&searchRequest.worldPerksAwardFlight=on";
				}
				else{
					location.href =  "http://asiares.nwa.com/?siteCode=" + country_code_cap + "&lang=" + lang_code_bkeng + "&searchRequest.worldPerksAwardFlight=on&searchBy=awardtravelsearch";
				}
			}
			
		}
	}
	else {
			location.href = serverName + "/booknwa";
	}
}

	function Nwapr(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {				
location.href = serverName + "/asia/" + varLangCode + "/deals";
			}
		}
	}
	
	
		function checkin(varLangCode) {

		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else if (visitordata.country_code == "au" || visitordata.country_code == "vn") {
				location.href = serverName + "/asia/" + varLangCode + "/checkin/index.html";
			}
			else {
				location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/checkin/index.html";
			}
		}
	}

	function bizperks(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			}
			
			else if (visitordata.country_code == "au") {
				location.href = serverName + "/asia/delta-sydney/bizperks.html";
			} else if (visitordata.country_code == "vn") {
				location.href = serverName + "/asia/vietnam/bizperks.html";
			}
			
			else {
				location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/bizperks.html";
			}
		}
		
	}


	function Octopus(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			} else {
				if (varLangCode == "kr") {
					location.href = serverName + "/kr/kr/travel/octopus/index.html";
				}
				
				else if (visitordata.country_code == "au") {
					location.href = serverName + "/ph/en/travel/octopus/index.html";
				} else if (visitordata.country_code == "vn") {
					location.href = serverName + "/th/en/travel/octopus/index.html";
				}
				
				else {
					location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/travel/octopus/index.html";
				}
			}
		}
	}

	function gprequest(varLangCode)
	{
		if (visitordata.country_code != null) {
			if (visitordata.country_code == "asia") {
				location.href = "https://www.nwa.com/asia";
			}
			
			else if (visitordata.country_code == "au") {
				location.href = "https://www.nwa.com/asia/delta-sydney/grouprequest/";
			} else if (visitordata.country_code == "vn") {
				location.href = "https://www.nwa.com/asia/vietnam/grouprequest/";
			}
			
			else {
				location.href = "https://www.nwa.com/" + visitordata.country_code + "/" + varLangCode + "/grouprequest/";
			}
		}
	}

function logout_skymiles_home_asiaen () {
    remove_cookie("WorldPerks");
    remove_cookie("WP_PIN");
   remove_cookie("NWASSOToken");
    remove_cookie("form0");
    remove_cookie("orbot");
    remove_cookie("NWASSOToken");
    alert("You have successfully logged out.");
    if (visitordata.country_code != null) {
    	
    	
        if (visitordata.lang_code != null && visitordata.country_code == "au") {
			location.href = serverName + "/asia/delta-sydney/";
		} else if (visitordata.lang_code != null && visitordata.country_code == "vn") {
			location.href = serverName + "/asia/vietnam/";
		}
        else if (visitordata.lang_code != null) {
            location = serverName + "/" + visitordata.country_code + "/" + visitordata.lang_code;
        }
         else {
            location = serverName + "/" + visitordata.country_code + "/" + en;
        }
    } else {
        location = serverName + "/hk/en";
    }
}


function NwaCareer(varLangCode)
{
        if (visitordata.country_code != null && varLangCode != null) {
			if (visitordata.country_code == "asia") {
				location.href = serverName + "/asia";
			}
			
			else if (visitordata.country_code == "au") {
				location.href = serverName + "/asia/delta-sydney/corpinfo/career/index.html";
			} else if (visitordata.country_code == "vn") {
				location.href = serverName + "/asia/vietnam/corpinfo/career/index.html";
			}
			
			else {
		        location.href = serverName + "/" + visitordata.country_code + "/" + varLangCode + "/corpinfo/career/index.html";
			}
        }
        else
        {
                location.href = serverName + "/alliance/";
        }
        
}

function Newsc(varLangCode)
{
	if (visitordata.country_code != null) {
		if (visitordata.country_code == "asia") {
			location.href = serverName + "/asia";
		}
		
		else if (visitordata.country_code == "au") {
			location.href = serverName + "/asia/delta-sydney/corpinfo/newsc/index.html";
		} else if (visitordata.country_code == "vn") {
			location.href = serverName + "/asia/vietnam/corpinfo/newsc/index.html";
		}		
		
		else {
			location.href = "/" + visitordata.country_code + "/" + varLangCode + "/corpinfo/newsc/index.html";
		}
	}
	
}
