
var urlPattern =  [

	'hotelrivoli.it','hotel-le-six.com','hotelviterbo.com','woodlands-hotel.ie','hotelastrid.com','lesjardinsdumarais.com','schlosshotelberlin.com','lepatiosaintantoine.com','hotel-design-secret-de-paris.com','wilsonbcn.com','apollohotel.sk','spa-hotel-imperial.cz','spa-resort-sanssouci.cz','grand-hotel-francais.fr','hotelprincipepio.com','cassidyshotel.com','grand-hotel-dore.com','utripstrosu.cz','riversidehotelkillarney.com','grandcanalhotel.ie','hotelroyalsantinarome.com','kenmarebayholidayhomes.com','umedvidku.cz','apartamentoscandilejas.com','jardinesdesabatini.com','glenroyalhotelkildare.ie','aquapalacehotel.cz','druidsglenresort.com','hotelbarocco.com','killarneycourthotel.com','hotelriminirome.com','pannoniatower.at','hotelliberty.cz','observatoirehotel.com','sandymounthotel.ie','pupp.cz','almabarcelona.com','hotelclaridgerome.com','hotelviktoria.co.at','vista-hotel.cz','hotel-paris-eiffel-cambronne.com','albuquerqueairportwyndhamhotel.com','resortmesa.com','kenmarebayhotel.com','standard-design-hotel-paris.com','hotel-paris-est-lafayette.com','hotelbordeauxaeroport.com','motelinthepines.com','apostrophe-hotel.com','granville-hotel.ie','theurbansuites.com','plazalucchesi.it','muralto.es','donauwalzer.at','almapamplona.com','almasevilla.com','excelmontemario.it','4seasonshotel.ie','airportsleepinn.com','comfortinnfountainhills.com','hotel-ploberger.at','hotelarmando.it','cityhotel-dc.at','renvyle.com','hotelcapuletiverona.it','savoywestend.cz','hoffmeister.cz','gabelhofen.at','regencyhoteldublin.com','blcdesign-hotel-paris.com','hotel-chatnoir-paris.com','castlemartyrresort.ie','4seasonshotelcarlingford.ie','hotel-le-paris-montmartre.com','hotel-paris-lafayette-buffault.com','hotel-paris-nation-bercy.com','das-tyrol.at','excelstpeter.it','/johnf_hotel_berlin','bewleyshotels.com/ballsbridge','bewleyshotels.com/dublin_airport','bewleyshotels.com/leeds','bewleyshotels.com/leopardstown','bewleyshotels.com/manchester_airport','bewleyshotels.com/newlands_cross','chiswick-moran-hotel','red-cow-moran-hotel','silver-springs-moran-hotel','crown-moran-hotel','glenviewhotel.com','clontarfcastle.ie','hotelinfantas.com','kremslehnerhotels.at/init/index.php?option=com_content&task=view&id=14&Itemid=76','kremslehnerhotels.at/init/index.php?option=com_content&task=view&id=12&Itemid=74','kremslehnerhotels.at/init/index.php?option=com_content&task=view&id=13&Itemid=75','royalmarine.ie','hotel-tronchet.com','lougherneresort.com','/velvet_hotel_berlin','/rubin_hotel_hamburg','/moserverdino_hotel_klagenfurt','/nike_hotel_linz','/camino_hotel_stuttgart','/boltzmann_hotel_wien','/wimberger_hotel_wien','/allegra_hotel_zagreb','/kaiserwasser_hotel_wien','t3tirol','buswells','motel.co.uk','camdencourthotel','slieverussell.ie','hotel-paris.cz','brooklodge.com','hotelhastalprague.com','thegibsonhotel.ie','hotelsax.cz','axelhotels.com/buenosaires','hotelcurious.com','cchp.cz','hotel-laerchenhof-seefeld.com','mespilhotel.com','littlelodge-hotel.com','brest-hotel.com','gavarni.com','hotelreginamadrid.com','thecliffhousehotel.com','hoteladriatico.it','arshotels.com/hotels/palazzo-dal-borgo','arshotels.com/hotels/hotel-rivoli','arshotels.com/hotels/hotel-san-gallo','axelhotels.com/barcelona','axelhotels.com/berlin/index.php','hotelmadanis.com','sligoparkhotel.com','hotelauditorium.com','clariondublinairport.com','hotellondraroma.com','fitzpatrickcastle.com','isaacs.ie/isaacs-cork-hotel','clarionhotelifsc.com','hotelamstephansplatz.at','hotelatlantico.es','treacyshotelwaterford.com','hotel-nantes.fr','airporthotelverona.it','hoteleiffeltrocadero.com','buddha-bar-hotel.cz','isaacs.ie/isaacs-dublin-hotel','kilkennyormonde.com','northstarhotel.ie','arshotels.com','kremslehnerhotels.at','axelhotels.com','hotel-carlina.com','archibald.cz','moranhotels.com','gbbhotels.com','bewleyshotels.com','arcotel'
];
var baPath =  [
'hotelrivoli','hotellesix','hotelviterbo','woodlandshotel','hotelastrid','lesjardinsdumarais','schlosshotelberlin','lepatiosaintantoine','secretdeparis','wilsonbcn','apollohotel','spahotelimperial','sparesortsanssouci','grandhotelfrancais','hotelprincipepio','cassidyshotel','grandhoteldore','utripstrosu','riversidehotelkillarney','grandcanalhotel','hotelroyalsantinarome','kenmarebayholidayhomes','umedvidku','apartamentoscandilejas','jardinesdesabatini','glenroyalhotelkildare','aquapalacehotel','druidsglenresort','hotelbarocco','killarneycourthotel','hotelrimini','pannoniatower','hotelliberty','observatoirehotel','sandymounthotel','pupp','almabarcelona','hotelclaridgerome','hotelviktoria','vistahotel','hotelpariseiffelcambronne','albuquerqueairportwyndhamhotel','resortmesa','kenmarebayhotel','standarddesignhotelparis','hotelparisestlafayette','hotelbordeauxaeroport','motelinthepines','apostrophehotel','granvillehotel','theurbansuites','plazalucchesi','muralto','donauwalzer','almapamplona','almasevilla','excelmontemario','4seasonshotel','airportsleepinn','comfortinnfountainhills','hotelploberger','hotelarmando','cityhotel-dc','renvyle','hotelcapuletiverona','savoywestend','hoffmeister','gabelhofen','regencyhoteldublin','blcdesignparis','hotelchatnoirparis','castlemartyrresort','4seasonshotelcarlingford','hotelleparismontmartre','hotelparislafayettebuffault','hotelparisnationbercy','dastyrol','excelstpeter','arcotelhoteljohnf','bewleysballsbridge','bewleysdublinairport','bewleysleeds','bewleyleopardstown','bewleymanchesterairport','bewleynewlandscross','moranhotelschiswick','moranhotelsredcow','moranhotelssilversprings','moranhotelscrown','glenviewhotel','clontarfcastle','hotelinfantas','grabenhotel','hotelregina','hotelroyal','royalmarinehotel','hoteltronchet','lougherneresort','arcotelhotelvelvet','arcotelhotelrubin','arcotelhotelmoserverdino','arcotelhotelnike','arcotelhotelcamino','arcotelhotelboltzmann','arcotelhotelwimberger','arcotelhotelallegra','arcotelhotelkaiserwasser','hotelt3tirol','buswellshotel','belmorecourtmotel','camdencourthotel','slieverussell','hotelparis','brooklodge','hotelhastalprague','thegibsonhotel','hotelsax','axelhotelbuenosaires','hotelcurious','cchp','hotellaerchenhofseefeld','mespilhotel','littlelodge-hotel','brest-hotel','gavarni','hotelreginamadrid','cliffhousehotel','hoteladriatico','ars-palazzo-dal-borgo','ars-hotel-rivoli','ars-hotel-san-gallo','axelhotelbarcelona','axelhotelberlin','hotelmadanis','sligoparkhotel','hotelauditorium','clariondublinairport','hotellondraroma','fitzpatrickcastle','isaacscorkhotel','clarionhotelifsc','hotelamstephansplatz','hotelatlantico','treacyshotelwaterford','hotelnantes','airporthotelverona','hoteleiffeltrocadero','buddha-bar-hotel','isaacsdublinhotel','kilkennyormonde','northstarhotel','arshotels','kremslehnerhotels','axelhotels','hotel-carlina','archibald','moranhotels','gbbhotels','bewleyshotels','arcotelhotels'
];

var is_mobile = isMobile();
var mobileURL = getMobileURL();
var paramOrCookiePresent = checkForParamVal('sf','true');
if(paramOrCookiePresent) {
	Set_Cookie('sf', 'true');
}
paramOrCookiePresent = Get_Cookie('sf') == 'true' ? true : paramOrCookiePresent;
paramOrCookiePresent = Get_Cookie('SF') == 'true' ? true : paramOrCookiePresent;
//alert(' is_mobile: ' + is_mobile +  ' paramOrCookiePresent: ' + paramOrCookiePresent + ' mobileURL: ' + mobileURL);
setOnLoad();
if(is_mobile && !paramOrCookiePresent && mobileURL!='') {
	if(pageTracker == undefined) {
		var pageTracker = false;
	}
	if(_gaq == undefined) {
		var _gaq = false;
	}

	if(location.search) {
		mobileURL = mobileURL + location.search;
	}
	if(pageTracker) {
		try {
			pageTracker._initData();
			mobileURL = pageTracker._getLinkerUrl(mobileURL);
			location.href=mobileURL;
		} catch(e){} finally{}
	} else 
		if(_gaq) {
			_gaq.push(function() {
  			var pageTracker = _gat._getTrackerByName();
  			location.href = pageTracker._getLinkerUrl(mobileURL);
		});  	

	}
}
function showLinkToMobile(){
	if (is_mobile && mobileURL!='') {  
		return true;
	}
	return false;
}

function setOnLoad() {
	var oldOnload = window.onload;
	
	//safariLog('typeof(window.onload): ' + typeof(window.onload));
	
	if (typeof(window.onload) != "function") {
		window.onload = writeMobileURL;
	} else {
		window.onload = function() {
			//safariLog('setting on load with existing onload mobileURL: ' + mobileURL);
			oldOnload();
			writeMobileURL;
		}
	}
}

function writeMobileURL(){
	var elem = document.getElementById('link_to_ba_mobile');
	if(elem) {
		if (is_mobile && mobileURL!='') {
			elem.style.display ="block";
			elem.onclick = toMobileSite;
			//safariLog('mobileURL: ' + mobileURL);
		} else {
			//safariLog('display none: ');
			elem.style.display ="none";		
		}
	}
}
function toMobileSite(){
	//safariLog('toMobileSite: ' + mobileURL);
	Delete_Cookie("sf");
	location.href=mobileURL;
	return false;
}
function getMobileURL(){
	var s = top.location.href;
	for ( var i=0, len=urlPattern.length; i<len; ++i ){
		if(s.indexOf(urlPattern[i])>=0) {
			//alert(mS[property]);
			return 'http://m.bookassist.com/' +  baPath[i];
		}
	}
    return '';
}
function isMobile(){
	var agent=navigator.userAgent.toLowerCase();
	var is_iphone = (agent.indexOf('iphone')!=-1);
	var is_ipod = (agent.indexOf('ipod')!=-1);
	var is_android = (agent.indexOf('android')!=-1);
	var is_mobile = (is_iphone || is_ipod || is_android);
	//safariLog('is_mobile: ' + is_mobile);
	return is_mobile;
}
function checkForParamVal(paramName, paramVal){
	var s = '';
	if(top.location) {
		s = top.location.href;
		//alert('s: ' + s + ' regex: ' + '[&\?]'+paramName+'=([^&]*)');
		var re = new RegExp('[&\?]'+paramName+'=([^&]*)');
		var found = s.match(re);
		if(found) {
			if(found.length>1) {
				return true;
			}
		}
	}
	return false;
}
function Set_Cookie(name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	/*
		if the expires variable is set, make the correct
		expires time, the current script below will set
		it for x number of days, to make it for hours,
		delete * 24, for minutes, delete * 60 * 24
	*/
	if ( expires ) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date( today.getTime() + (expires) );
	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
		( ( path ) ? ";path=" + path : "" ) +
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this fixes an issue with the old method, ambiguous values
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f

	for ( i = 0; i < a_all_cookies.length; i++ ) {
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );

		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');

		//if(window.console){
		//	window.console.log('cookie_name: ' + cookie_name );
		//}
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			//if(window.console){
			//	window.console.log('cookie_value: ' + cookie_value );
			//}
			
			
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) {
		return null;
	}
}
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
	( ( path ) ? ";path=" + path : "") +
	( ( domain ) ? ";domain=" + domain : "" ) +
	";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function safariLog(text){
	if(window.console){
		window.console.log(text);
	}
}
	

