BOM = {
	existing: {
		isBoxActive: false,
		isBtnActive: false,
		sel: "#menuExistingCustomerSub",
		open: function () {
			if (!(BOM.existing.isBoxActive)) {
				var inserthis = '<img src="img/dropdown.png" border="0" usemap="#panel"><map name="panel" id="panel"><area shape="rect" coords="33,25,134,39" href="recontractnow.asp" /><area shape="rect" coords="38,44,127,59" href="checkusage.asp" /><area shape="rect" coords="41,92,121,105" href="checkexpiry.asp" /><area shape="rect" coords="23,108,145,126" href="javascript:BOM.openTopUp();" /><area shape="rect" coords="32,130,135,146" href="javascript:BOM.openTopUpiPad();" /></map>';
				jQuery(BOM.existing.sel).html(inserthis);
				jQuery(BOM.existing.sel).fadeIn(400);
				BOM.existing.isBoxActive = true;
				BOM.existing.isBtnActive = true;
			}
		},
		close: function () {
			jQuery(BOM.existing.sel).fadeOut(400);
			BOM.existing.isBoxActive = false;
			BOM.existing.isBtnActive = false;
		},
		check: function (text) {
			if (!(BOM.existing.isBoxActive) || (!(BOM.existing.isBtnActive)) ) {
				BOM.existing.close();
			}
		},
		init: function () {
			$(BOM.existing.sel).hover(function() {
				BOM.existing.isBoxActive = true;
				BOM.existing.isBtnActive = true;
			}, function() {
				BOM.existing.isBoxActive = false;
				tExist = setTimeout('BOM.existing.check("box out")',100);
			});
			$('li#menuExistingCustomer a').hover(function() {
				BOM.existing.open();
			}, function() {
				BOM.existing.isBtnActive = false;
				tExist = setTimeout('BOM.existing.check("button out")',100);
			});
		}
	},
	Signup: {
		'dataplans': JSdata.dataplans,
		'mobileplans': [],
		validateInput: function (input, validateBy) {
			var regx = {
						contact : /(^[689]{1}[0-9]{7}$)/,
						mobile	: /(^[89]{1}[0-9]{7}$)/,
						nric : /^[FGST]{1}[0-9]{7}[A-Z]{1}$/i,
						email: /^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i,
						postalcode: /(^[0-9]{6}$)/,
						unitno: /([-#0-9])/
			};
			var returnVal = null;
			switch(validateBy) {
			case 'mobile':
				returnVal = regx.mobile.test(input);
				break;
			case 'nric':
				returnVal = regx.nric.test(input);
				break;
			case 'contact':
				returnVal = regx.contact.test(input);
				break;
			case 'email':
				returnVal = regx.email.test(input);
				break;
			case 'postalcode':
				returnVal = regx.postalcode.test(input);
				break;
			case 'unitno':
				returnVal = regx.unitno.test(input);
				break;
			default:
				returnVal = null;
				break;
			}
			return returnVal;
		}

	},
	checkusage: function() {
		jQuery('#check_usage input').attr('disabled','disabled');
		jQuery('#check_usage').animate({'opacity':0.5}, 1500);
		jQuery('#SubsContent').append('<div style="position:absolute; left: 48%; top: 250px;"><img src="img/ajax-loader.gif" /></div>');
		$.post('usage.asp',{
			'ic': jQuery('#check_usage input[name="ic"]').val(),
			'mobile': jQuery('#check_usage input[name="mobile"]').val(),
			'source': 'bbmobile'
			},
			function(data){
				var stat = jQuery(data).find('result').attr('stat');
				if (stat == "ok") {
					var datausage = jQuery(data).find('datausage').text();
					var lastupdated = jQuery(data).find('lastupdated').text();
										var roamingdatausage = jQuery(data).find('roamingdatausage').text();
					var nextbill = jQuery(data).find('nextbill').text();
										if (roamingdatausage == '') {
						writethis = '<div id="usage_result"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" class="head1">As at<br /><br /><span class="data">'+lastupdated+'</span></td><td valign="top" class="head2">Local Data Usage<br /><br /><span class="data">'+datausage+'</span> MB<br />(include download and upload usage)</td><td valign="top" class="head3">Your next bill statement will be on<br /><br /><span class="data">'+nextbill+'</span></td></tr></table><div id="notes">Notes:<br />1. Data usage record will be updated once a day and the data may vary from your bill.<br />				2. The above data usage record will not include any data utilized while roaming overseas.<br />3. Only data usage of the mobile/data number login will be shown above.<br />4. Click <a href=".?page=laptop_promotions&amp;goto=1" target="_top">here</a> for your local data usage bundle for BroadBand on Mobile Data Plan.<br />&nbsp;&nbsp;&nbsp;&nbsp;Excess usage will be charged at $0.001/2KB (minimum of $0.005/session).<br />5. Click <a href=".?page=mobile_promotions&amp;goto=1" target="_top">here</a> for your local data usage bundle for BroadBand on Mobile Value-added service.<br />&nbsp;&nbsp;&nbsp;&nbsp;Excess usage will be charged at $0.0054/2KB (minimum of $0.03/session).<br />6. For roaming data rates, please refer to <a href="http://home.singtel.com/consumer/roaming/" target="new">http://home.singtel.com/consumer/roaming/</a></div></div>';												
										} else {
												 writethis = '<div id="usage_result"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><td valign="top" class="head1">Last Data Transaction as at:<br /><br /><span class="data">'+lastupdated+'</span></td><td valign="top" class="head2">Local Data Usage<br /><br /><span class="data">'+datausage+'</span> MB<br />(include download and upload usage)<br /><br />Roaming Data Usage<br /></br /><span class="data">'+roamingdatausage+'</span> MB<br />(include download and upload usage)</td><td valign="top" class="head3">Your next bill statement will be on<br /><br /><span class="data">'+nextbill+'</span></td></tr></table><br /><div id="notes">Notes:<br />1. Data usage record will be updated once a day and the data may vary from your bill.<br />2. Only data usage of the mobile/data number login will be shown above.<br />3. Click <a href=".?page=laptop_promotions&amp;goto=1" target="_top">here</a> for your local data usage bundle for BroadBand on Mobile Data Plan.<br />&nbsp;&nbsp;&nbsp;&nbsp;Excess usage will be charged at $0.001/2KB (minimum of $0.005/session).<br />4. Click <a href=".?page=mobile_promotions&amp;goto=1" target="_top">here</a> for your local data usage bundle for BroadBand on Mobile Value-added service.<br />&nbsp;&nbsp;&nbsp;&nbsp;Excess usage will be charged at $0.0054/2KB (minimum of $0.03/session).<br />5. For roaming data rates, please refer to <a href="http://home.singtel.com/consumer/roaming/" target="new">http://home.singtel.com/consumer/roaming/</a></div></div>';
										}

					jQuery('#SubsContent').fadeOut('fast', function() {
						//Stuff to do *after* the animation takes place;
						jQuery('#SubsContent').html(writethis);
						jQuery(this).fadeIn('fast', function() {
							jQuery('#SubsContent').attr('class','');
						});
					});
				} else {
					writethis =	 '<div id="usage_result">'+jQuery(data).find('message').text()+'</div>';
					jQuery('#SubsContent').fadeOut('fast', function() {
						//Stuff to do *after* the animation takes place;
						jQuery('#SubsContent').html(writethis);
						jQuery(this).fadeIn('fast', function() {
							jQuery('#SubsContent').attr('class','');
						});
					});
				}
		});
		return false;
	},
		
	checkexpiry: function() {
		jQuery('#check_usage input').attr('disabled','disabled');
		jQuery('#check_usage').animate({'opacity':0.5}, 1500);
		jQuery('#SubsContent').append('<div style="position:absolute; left: 48%; top: 250px;"><img src="img/ajax-loader.gif" /></div>');
		jQuery.post('prepaid.asp',{
			'mobile':jQuery('#check_usage input[name="mobile"]').val()
			},
			function(data){
				var stat = jQuery(data).find('result').attr('stat');
				if (stat == "ok") {
					var expirydate = jQuery(data).find('expirydate').text();
					writethis = '<div id="usage_result">Your SingTel Prepaid BroadBand on Mobile will expire at <strong>'+expirydate+' 23:59</strong><br /><br />If you would like to enjoy uninterrupted internet access for a longer period, please top up your Prepaid BroadBand on Mobile account before it expires.</div><div style="padding-left: 0;"><br /><br /><div style="padding-left: 35px;"><br /><br /><div><table id="blurbs"><tr><td class="blurb"><a href="javascript:BOM.openTopUp();"><img src="img/prepaid_card.png" border="0" /><div class="blurb">Laptop Users<br />Top up here</div></a></td><td> </td><td class="blurb"><a href="javascript:BOM.openTopUpiPad();"><img src="img/prepaid_microsim.png" border="0" /><div class="blurb2">iPad Users<br />Top up here</div></a></td></tr></table>	   </div><br /><strong style="font: bold 16px \'Lucida Grande\', \'Trebuchet MS\'">Check your iPad Data Plan and 3 Day Pass expiry and top it up here!</strong></div>';
					jQuery('#SubsContent').fadeOut('fast', function() {
						//Stuff to do *after* the animation takes place;
						jQuery('#SubsContent').html(writethis);
						jQuery(this).fadeIn('fast', function() {
							jQuery('#SubsContent').attr('class','');
						});
					});
				} else {
					writethis =	 '<div id="usage_result">'+jQuery(data).find('message').text()+'<div style="padding-left: 0;"><br /><br /><div><table id="blurbs"><tr><td class="blurb"><a href="javascript:BOM.openTopUp();"><img src="img/prepaid_card.png" border="0" /><div class="blurb">Laptop Users<br />Top up here</div></a></td><td> </td><td class="blurb"><a href="javascript:BOM.openTopUpiPad();"><img src="img/prepaid_microsim.png" border="0" /><div class="blurb2">iPad Users<br />Top up here</div></a></td></tr></table>	</div><br /><strong style="font: bold 16px \'Lucida Grande\', \'Trebuchet MS\'">Check your iPad Data Plan and 3 Day Pass expiry and top it up here!</strong></div></div>';
					jQuery('#SubsContent').fadeOut('fast', function() {
						//Stuff to do *after* the animation takes place;
						jQuery('#SubsContent').html(writethis);
						jQuery(this).fadeIn('fast', function() {
							jQuery('#SubsContent').attr('class','');
						});
					});
				}
		});
		return false;
	},
	openTopUp: function () {
		var docWidth = document.body.clientWidth;
		var docHeight = document.body.clientHeight;
		var winX = (document.all)?window.screenLeft:window.screenX;
		var winY = (document.all)?window.screenTop:window.screenY+100;
		
		// var theTop=(screen.height/2)-(320/2);
		// var theLeft=(screen.width/2)-(700/2);
		theLeft = 5 + winX + ((docWidth - 800)/2);
		theTop = 200 + winY; //150
		BOM.trackPageview("ExistingCust/PrepaidTopUpNow");
		window.open("https://inno.ideas.singtel.com/PrepaidBoM/topup/","prepaidTopup","scrollbars=1,width=800,height=320,toolbar=0,top="+theTop+",left="+theLeft);
		// if (window.focus) {
		//	 if (prepaidTopup !== undefined) {
		//		 prepaidTopup.focus();
		//	 }
		// }
	},
	openTopUpiPad: function () {
		var docWidth = document.body.clientWidth;
		var docHeight = document.body.clientHeight;
		var winX = (document.all)?window.screenLeft:window.screenX;
		var winY = (document.all)?window.screenTop:window.screenY+100;
		
		theLeft = 5 + winX + ((docWidth - 800)/2);
		theTop = 200 + winY; //150
		BOM.trackPageview("ExistingCust/PrepaidTopUpNow");
		window.open("https://inno.ideas.singtel.com/PrepaidBoM/microsim/","iPadTopUp","scrollbars=1,width=800,height=320,toolbar=0,top="+theTop+",left="+theLeft);
	},
	trackPageview: function (absPath) {
		if (pageTracker) {
			pageTracker._trackPageview("/bbmobile/?page=" + absPath);
		} else {
			
		}
	},
	openF1: function () {
		window.open('formulaone.html','formulaone','toolbar=0,scrollbars=0,resizable=0,height=650,width=650');
	},
	openMacBook: function () {
		window.open('macbook.html','macbook','toolbar=0,scrollbars=0,resizable=0,height=525,width=650');
	},
	openCathay: function () {
		window.open('cathay.html','cathay','toolbar=0,scrollbars=0,resizable=0,height=525,width=650');
	}
};
if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
	window.scrollTo(0,1);
	addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false);

	function hideURLbar(){
	window.scrollTo(0,1);
	}
}
function doTNC(winURL) {
		window.open(winURL,"","width=650,height=500,scrollbars=yes,toolbars=no,sizeable=no");
}
// DOM ready
jQuery(function ($) {
	var swfobj = swfobject;
	$(BOM.existing.sel).hover(function() {
		BOM.existing.isBoxActive = true;
		BOM.existing.isBtnActive = true;
	}, function() {
		BOM.existing.isBoxActive = false;
		tExist = setTimeout('BOM.existing.check("box out")',100);
	});
	$('li#menuExistingCustomer a').hover(function() {
		BOM.existing.open();
	}, function() {
		BOM.existing.isBtnActive = false;
		tExist = setTimeout('BOM.existing.check("button out")',100);
	});

	// liner
	// jQuery('#flashliner').flash({
	//	 swf: 'img/liner.swf',
	//	 params: {
	//		 'wmode': 'transparent'
	//	 },
	//	 flashvars: {},
	//	 height: 40,
	//	 width: 190
	// });
	swfobj.embedSWF("img/liner.swf", "flashliner", "190", "40", "9.0.0", "expressInstall.swf",{},{'wmode':'transparent'});
	BOM.flashvars = {};
	if (swfobj.getQueryParamValue("page")) { 
		BOM.flashvars["page"] = swfobj.getQueryParamValue("page");
	}
	if (swfobj.getQueryParamValue("goto")) { 
		BOM.flashvars["goto"] = swfobj.getQueryParamValue("goto");
	}
	if (BOM.Flash) {
		// jQuery('#STContent').empty().flash({
		//	 swf: 'base.swf',
		//	 params: {},
		//	 flashvars: BOM.flashvars,
		//	 height: 500,
		//	 width: 960
		// });
		var randomnumber=Math.floor(Math.random()*1000);
		var swfBase = "base.swf?rnd="+randomnumber+"" ;
		swfobj.embedSWF(swfBase, "STFlash", "960", "500", "9.0.0", "expressInstall.swf", BOM.flashvars);
		
	}
	$("#menuSurfLaptopSub, #menuSurfMobileSub, #menuSurfMobileSub").css('opacity',0);
	// $('#BomMenu').css('display','none');

});

// on load
jQuery(window).load(function() {
	$('#BomMenu').fadeIn(200, function () {
		if (BOM.Laptop) {
			jQuery("#menuSurfLaptopSub").css('display','block').animate({'opacity': 1}, 250, "linear", function () {
				 jQuery('#STContentBG').fadeIn(1000, function() {
							jQuery('#BomContent').animate({'left': '33px', 'opacity': 0.99}, { "duration": 700 }, "swing");
					});
			});
		} else if (BOM.Mobile) {
			jQuery("#menuSurfMobileSub").css('display','block').animate({'opacity': 1}, 250, "linear", function () {
				jQuery('#STContentBG').fadeIn(1000, function() {
					jQuery('#BomContent').animate({'left': '33px', 'opacity': 0.99}, { "duration": 700 }, "swing");
				});
			});
		} else if (BOM.iPad) {
			jQuery("#menuSurfiPadSub").css('display','block').animate({'opacity': 1}, 250, "linear", function () {
				jQuery('#STContentBG').fadeIn(1000, function() {
					jQuery('#BomContent').animate({'left': '33px', 'opacity': 0.97}, { "duration": 700 }, "swing");
				});
			});
		} else if (BOM.iPadiPad) {
			
		} else {
			jQuery('#STContentBG').fadeIn(1000, function() {
				jQuery('#BomContent').animate({'left': '33px', 'opacity': 0.99}, 800, "linear", function () {
					if((navigator.userAgent.match(/iPhone/i)) || (navigator.userAgent.match(/iPod/i))) {
					
					} else if ((jQuery.url.attr("file") == "checkexpiry.asp") && (jQuery.url.param("mobile") !== undefined)) {
						jQuery('#mobile').attr("value",jQuery.url.param("mobile"));
					 // BOM.checkexpiry();
					}
				});
			});
		}
	});
		var swfo = swfobject;
		if ((swfo.getQueryParamValue("page") == "mobile_promotions") && (swfo.getQueryParamValue("goto") == 1)) {
			var ebRand = Math.random()+'';
			ebRand = ebRand * 1000000;
			var activityParams = escape('ActivityID=66261&f=1');
			var url = 'HTTP://bs.serving-sys.com/BurstingPipe/activity3.swf?ebAS=bs.serving-sys.com&activityParams=' + activityParams + '&rnd=' + ebRand;	   
			$('#STContent').append('<div id="mecTracking"><div id="mecTrackingFlash"></div></div>');
			swfo.embedSWF(url, "mecTrackingFlash", "1", "1", "9.0.0", "expressInstall.swf");
		}			
});
