
var urlPattern =  [

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

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

