function switchDevice(device) {
	var searchTab = document.getElementById('searchTab');
	var searchBody = document.getElementById('search');
	
	var advPlusTab = document.getElementById('advPlusTab');
	var advPlusBody = document.getElementById('advMember');
	
	var bookTab = document.getElementById('bookTab');
	var bookBody = document.getElementById('book');

	if (device == 'search') {
	    if (advPlusTab)
		    advPlusTab.className = 'inactive';
		if (advPlusBody)
		    advPlusBody.style.display = 'none';
		    
		if (searchTab)
		    searchTab.className = '';
		if (searchBody)
		    searchBody.style.display = 'block';
		    
		if (bookTab)
		    bookTab.className = 'inactive';
		if (bookBody)
		    bookBody.style.display = 'none';
	}else if (device == 'advPlus') {	    
	    overwriteAdvPlusTab();
	    return false;
	    
	    if (advPlusTab)
		    advPlusTab.className = '';
		if (advPlusBody)
		    advPlusBody.style.display = 'block';
		
		if (searchTab)
		    searchTab.className = 'inactive';
		if (searchBody)
		    searchBody.style.display = 'none';

		if (bookTab)
		    bookTab.className = 'inactive';
		if (bookBody)
		    bookBody.style.display = 'none';
	}else if (device == 'book') {
	    if (advPlusTab)
		    advPlusTab.className = 'inactive';
		if (advPlusBody)
		    advPlusBody.style.display = 'none';
		
		if (searchTab)
		    searchTab.className = 'inactive';
		if (searchBody)
		    searchBody.style.display = 'none';

		if (bookTab)
		    bookTab.className = '';
		if (bookBody)
		    bookBody.style.display = 'block';
	}
	
	return false;
}

function newWindow(theURL,winName,width,height) {
  if (typeof(width) == "undefined") width = '640';
  if (typeof(height) == "undefined") height = '425';
  
  var l = (screen.width - width) / 2;
  var t = (screen.height - height) / 2;
  
  var newWin = window.open(theURL,winName,'scrollbars=yes,width=' + width + ',height=' + height + ',resizable=yes,location=no,menubar=yes,screenX=' + l + ',screenY=' + t + ',top=' + t + ',left=' + l);
  newWin.focus();
  return false;
}

function openHotelVideo(url) {
	window.open(url, '', 'resizable=no,noscrollbars,status=yes'); 
	return false;
}

function openHotelGallery(theURL) {
	window.open(theURL, 'hotelgallery', 'width=655,height=490'); 
	return false;
}

function overwriteAdvPlusTab() {
    var domain = {AU:"www.accorhotels.com.au",NZ:"www.accorhotels.co.nz",FJ:"www.accorhotels.co.nz",CN:"www.accorhotels-asia.com",JP:"www.accorhotels-asia.com",AS:"www.accorhotels-asia.com"};
    var url = "";
	var siteCode = determineSite();
    if (siteCode == "ACC") {
        url = "/advplus/";
    } else {
		var siteCountry = determineCountry();
        url = "http://" + domain[siteCountry] + "/advplus/";
    }                
    window.location.href = url;
    return false;
};

function determineSite() {
	var siteCode = "";
    //Determine site code
    if (/sofitel/i.test(window.location.host)) {
        siteCode = "SOF";
    } else if (/novotel/i.test(window.location.host)) {
        siteCode = "NOV";
    } else if (/grandmercure/i.test(window.location.host) || /mercuregrand/i.test(window.location.host)) {
        siteCode = "MER";
    } else if (/mercure/i.test(window.location.host)) {
        siteCode = "MER";
    } else if (/ibis/i.test(window.location.host)) {
        siteCode = "IBI";
    } else if (/formule1/i.test(window.location.host)) {
        siteCode = "FOR";
    } else if (/allseasons/i.test(window.location.host)) {
        siteCode = "ASE";
    } else {
        siteCode = "ACC";
    }
	
	return siteCode;
};

function determineCountry() {
	var siteCountry = "";
    //Determine site country	
    if ((typeof(gSiteCountry) != "undefined") && (typeof(gSiteCountry) == "string")) {
        //In SSL, we cannot recognize country from URL. So we will check the site country from "siteCountry" variable instead.
        siteCountry = gSiteCountry;
    } else {
        var matches = /\.(\w+)$/.exec(window.location.host.toUpperCase());
        if (matches) {
            switch(matches[1]) {
                case "AU":
                case "NZ":
                case "FJ":
                case "CN":
                case "JP":
                    siteCountry = matches[1];
                    break;
                default:
                    siteCountry = "AS";
            }
        }
    }
	
	return siteCountry;
};
