function setCookie(c_name,value,exdays) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate() + exdays);
	var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
	document.cookie=c_name + "=" + c_value;
}

function getCookie(c_name) {
	var i,x,y,ARRcookies=document.cookie.split(";");
	for (i=0;i<ARRcookies.length;i++) {
		x=ARRcookies[i].substr(0,ARRcookies[i].indexOf("="));
		y=ARRcookies[i].substr(ARRcookies[i].indexOf("=")+1);
		x=x.replace(/^\s+|\s+$/g,"");
		if (x==c_name) {
			return unescape(y);
		}
	}
}

function closemobileweb() {
	$('#mobilebanner').hide();
	setCookie('mobileweb',false,7);
	pageTracker._trackEvent('mobileweb','Close','Customer Close the Popup',1);
}

function visitMobile(src) {
	pageTracker._trackEvent(src,'VisitMobile','Customer Click Visit Mobile Link',1);			
	window.open("http://m.onetravel.com/flights");
}

function downloadApp(src) {
	if (src=='iPhone') {
		pageTracker._trackEvent(src,'Download','Customer Click Download',1);		
		window.open("");
	} else if (src=='Android') {
		pageTracker._trackEvent(src,'Download','Customer Click Download',1);		
		window.open("https://market.android.com/details?id=com.onetravel.androidapp");
    }
}


$(document).ready(function() {

if ((navigator.userAgent.match(/SymbianOS/))  || (navigator.userAgent.match(/BlackBerry/)) || (navigator.userAgent.match(/Nokia/)) || (navigator.userAgent.match(/IEMobile/)) || (navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i)) || (navigator.userAgent.match(/Android/))  || (navigator.userAgent.match(/webOS/)) || (navigator.userAgent.match(/MeeGo/)) || (navigator.userAgent.match(/Dolfin/))) {
		var mobileweb=getCookie("mobileweb");
		if (mobileweb==null || mobileweb=="") {
			var mobilewebHtml = '<div style="float:left; clear:both; width:330px;">';
			mobilewebHtml += '<a href="javascript:visitMobile(\'mobileweb\');" ><img src="http://www.onetravel.com/travel/images/mobileweb.png" alt="OneTravel Mobile Website" border="0"/></a>';
			mobilewebHtml += '</div>';
			mobilewebHtml += '<div style="float:right;  width:450px;">';
			mobilewebHtml += '<a href="javascript:closemobileweb();" style="position:relative; float:right; top:10px; right:10px; font-size:65px;">Close [X] </a>';
			mobilewebHtml += '<a href="javascript:visitMobile(\'mobileweb\');" style="font-size:50px; color:#F9A01E;"><br/><br/><br/><br/> Visit OneTravel <br/> Mobile Website<br/></a><br><h2>Download OneTravel app for free on the Android Market.</h2><br><br><a href="javascript:downloadApp(\'Android\');"><img src="http://www.onetravel.com/travel/images/androiddownload.jpg" alt="Download OneTravel app for free on the Android Market" border="0" title=""></a>';
			mobilewebHtml += '</div>';			
			
			$('#mobilebanner').html(mobilewebHtml);
			$('#mobilebanner').show();
			pageTracker._trackEvent('mobileweb','ShowPopup','Popup Open to Customer',1);
		}
	}
  
});

