﻿function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/***************REGULAR IMAGES **********************************/
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7);

if(itsAllGood) {
	if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
		window.attachEvent("onload", fnLoadPngs);
	}
}

function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			var div = document.createElement("DIV");
			div.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizing='scale')"
			div.style.width = img.width + "px";
			div.style.height = img.height + "px";
			img.replaceNode(div);
		}
		img.style.visibility = "visible";
	}
}

/***************BACKGROUND IMAGES **********************************/
var bgsleight	= function() {
	
	function addLoadEvent(func) {
		var oldonload = window.onload;
		if (typeof window.onload != 'function') {
			window.onload = func;
		} else {
			window.onload = function() {
				if (oldonload) {
					oldonload();
				}
				func();
			}
		}
	}
	
	function fnLoadPngs() {
		var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
		var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5 && Number(rslt[1]) < 7);
		for (var i = document.all.length - 1, obj = null; (obj = document.all[i]); i--) {
			if (itsAllGood && obj.currentStyle.backgroundImage.match(/\.png/i) != null) {
				fnFixPng(obj);
				obj.attachEvent("onpropertychange", fnPropertyChanged);
			}
		}
	}

	function fnPropertyChanged() {
		if (window.event.propertyName == "style.backgroundImage") {
			var el = window.event.srcElement;
			if (!el.currentStyle.backgroundImage.match(/images\/x\.gif/i)) {
				var bg	= el.currentStyle.backgroundImage;
				var src = bg.substring(5,bg.length-2);
				el.filters.item(0).src = src;
				el.style.backgroundImage = "url(images/x.gif)";
			}
		}
	}

	function fnFixPng(obj) {
		var bg	= obj.currentStyle.backgroundImage;
		var src = bg.substring(5,bg.length-2);
		obj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
		obj.style.backgroundImage = "url(images/x.gif)";
	}
	
	
	return {	
		init: function() {
			if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
				addLoadEvent(fnLoadPngs);
			}
			
		}
	}
	
}();

bgsleight.init();

var langs = ['en', 'tc', 'sc', 'jp'];
function getPath(){
	var currentLang = langs[0];
	for(x in langs){
		if(location.href.search("/"+langs[x]+"/")!=-1){
			currentLang = langs[x];
		}
	}
	return [location.href.substr(0, location.href.search('/'+currentLang+'/')), currentLang];
}
var temp = getPath();
var currentPath = temp[0];
var currentLang = temp[1];
var currentPathLang = temp[0] + '/' + temp[1] + '/';

navlink=new Array();
navlink.push({secnum:"0",subsecnum:"0",link:"home/index.asp",target:"_self"});
navlink.push({secnum:"1",subsecnum:"0",link:"location/location.asp",target:"_self"});
navlink.push({secnum:"2",subsecnum:"0",link:"shopping/shopping.asp",target:"_self"});
navlink.push({secnum:"3",subsecnum:"0",link:"residences/residences.asp",target:"_self"});
//navlink.push({secnum:"4",subsecnum:"0",link:"mandarinoriental/mandarinoriental.asp",target:"_self"});
navlink.push({secnum:"4",subsecnum:"0",link:"http://www.mandarinoriental.com/macau/",target:"_blank"});
navlink.push({secnum:"5",subsecnum:"0",link:"mo_residence/mo_residence.asp",target:"_self"});
navlink.push({secnum:"1",subsecnum:"1",link:"location/macau.asp",target:"_self"});
navlink.push({secnum:"1",subsecnum:"2",link:"location/ideal.asp",target:"_self"});
navlink.push({secnum:"1",subsecnum:"3",link:"location/view.asp",target:"_self"});
navlink.push({secnum:"2",subsecnum:"1",link:"shopping/overview.asp",target:"_self"});
navlink.push({secnum:"2",subsecnum:"2",link:"shopping/floorplans.asp",target:"_self"});
navlink.push({secnum:"2",subsecnum:"3",link:"shopping/events.asp",target:"_self"});
navlink.push({secnum:"2",subsecnum:"4",link:"shopping/leasing.asp",target:"_self"});
navlink.push({secnum:"2",subsecnum:"5",link:"shopping/contactus.asp",target:"_self"});

function jumpsession(sectionNum,subSectionNum)
{
	for (var i=0;i<navlink.length;i++)
	{
		if (sectionNum==navlink[i].secnum &&  subSectionNum==navlink[i].subsecnum)
		{
			var url='';
			if (navlink[i].link.indexOf('http://')==-1)
				url=currentPathLang+navlink[i].link;
			else
				url=navlink[i].link;
			if (navlink[i].target=='_self')
				location.href=url;
			else if (navlink[i].target=='_blank')
				window.open(url,'popup');
		}
	}
	
}

function jumplang(index){
	location.href = location.href.replace("/"+currentLang+"/", "/"+langs[index-1]+"/");
}

function jumpIcon(num){
	if (num==1){
		window.open('http://residences.mandarinoriental.com', 'outsidelink')
	}else if(num==2){
		window.open(currentPath+'/filemanager/mo_residence/'+currentLang+'/press_release.pdf', 'presspdf')
	}else if(num==3){
		window.open(currentPathLang+'mo_residence/form.asp', 'subscriptionform', 'toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no, width=600, height='+((screen.height<657)?screen.height:657)+'')
	}
}

function jump(action){
	if (action=='mapenlarge'){
		show_enlarge_img(currentPath+'/filemanager/location/'+currentLang+'/map_l.jpg');
	}else if(action=='subscriptionform'){
		window.open(currentPathLang+'shopping/form.asp', 'subscriptionform', 'toolbar=no, menubar=no, scrollbars=no, resizable=no,location=no, status=no, width=600, height='+((screen.height<850)?screen.height:850)+'')
	}
}

function jumpbanner(url){
	var result = {};
	for(var GroupIndex in arrayVar){
		for(var BannerIndex in arrayVar[GroupIndex]){
			if(arrayVar[GroupIndex][BannerIndex][1]==url){
				result = {
					url: arrayVar[GroupIndex][BannerIndex][1],
					target: arrayVar[GroupIndex][BannerIndex][2]
				}
			}
		}
	}
	window.open(result.url, result.target);
}

function show_disclaimer(){
	var thetext;
	if (currentLang=='en')
	{
		thetext = "The Residences & Apartments at Mandarin Oriental, Macau (&quot;The Residences & Apartments&quot;) are not developed, sponsored, owned, offered or sold by Mandarin Oriental Hotel Group or any affiliate thereof (&quot;MOHG&quot;), and MOHG makes no representation, warranty or guaranty of any kind regarding The Residences & Apartments. The developers and owners of The Residences & Apartments use the Mandarin Oriental name and trademarks subject to the terms of revocable licenses from MOHG which may expire or be terminated.<br><br>All information contained herein is for reference or identification only and shall not constitute or be construed as any offer, representation or warranty whether expressly or impliedly by the developers.  All information shall be subject to the terms and conditions of the Sale and Purchase Contract.";
	}
	if (currentLang=='tc')
	{
		thetext = "澳門文華東方府邸及寓所(&quot;文華薈&quot;)並不是由文華東方酒店集團或其分支機構(&quot;MOHG&quot;) 發展、贊助、擁有、供給或銷售，而MOHG並不能就文華薈作出任何的陳述、擔保或保證。文華薈的發展商和所有人使用文華東方的名義或商標，惟需遵守MOHG的可廢止准照中的規定，而該准照是具期限性或可被終止的。<br><br>本文內的所有資料僅供參考或識別之用，並不構成或被視為發展商的任何明示或隱含要約承諾或保證。所有資料均以承諾買賣合約的條款及條件為準。";
	}
	if (currentLang=='sc')
	{
		thetext = "澳门文华东方府邸及寓所(&quot;文华荟&quot;)并不是由文华东方酒店集团或其分支机构(&quot;MOHG&quot;) 发展、赞助、拥有、供给或销售，而MOHG并不能就文华荟作出任何的陈述、担保或保证。文华荟的发展商和所有人使用文华东方的名义或商标，惟需遵守MOHG的可废止准照中的规定，而该准照是具期限性或可被终止的。<br><br>本文内的所有资料仅供参考或识别之用，并不构成或被视为发展商的任何明示或隐含要约承诺或保证。所有资料均以承诺买卖合约的条款及条件为准。";
	}
//alert($('#disclaimerlink').offset().top)
	$('#dhtmldisclaimer').html(thetext);
	$('#dhtmldisclaimer').css('width', "500px");
//	$('#dhtmldisclaimer').css('top', $('#disclaimerlink').offset().top - $('#dhtmldisclaimer').height() - $('#disclaimerlink').height());
//	$('#dhtmldisclaimer').css('left', $('#disclaimerlink').offset().left + $('#disclaimerlink').width() - $('#dhtmldisclaimer').width()- 5);
	$('#dhtmldisclaimer').css('top', $('#bottom_zone').offset().top - $('#dhtmldisclaimer').height() - 20);
	$('#dhtmldisclaimer').css('left', $('#disclaimerlink').offset().left);
	$('#dhtmldisclaimer').css('visibility', 'visible');
}

function hide_disclaimer(){
	$('#dhtmldisclaimer').css('visibility', 'hidden');
}

function emailCheck (emailStr) {
	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
		 even fit the general mould of a valid e-mail address. */
		return false
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	// See if "user" is valid 
	if (user.match(userPat)==null) {
		// user is not valid
		return false
	}
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
		// this is an IP address
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
			return false
			}
		}
		return true
	}
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		return false
	}
	/* domain name seems valid, but now make sure that it ends in a
		   three-letter word (like com, edu, gov) or a two-letter word,
		   representing country (uk, nl), and that there's a hostname preceding 
		   the domain or country. */
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
		domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   return false
	}
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   var errStr="This address is missing a hostname!"
	   return false
	}
	// If we've gotten this far, everything's valid!
	return true;
}

(function(){
	jQuery.fn.mb_length = function(){
		var escapedStr = encodeURI(jQuery(this).val());
		if (escapedStr.indexOf("%") != -1) {
			var count = escapedStr.split("%").length - 1;
			if (count == 0) count++;
			var tmp = escapedStr.length - (count * 3);
			count = count + tmp;
		}else{
			count = escapedStr.length
		}
		return count;
	}
	jQuery.fn.mb_left = function(total, trimTotal){
		jQuery(this).val(jQuery(this).val().substr(0, trimTotal));
		if(jQuery(this).mb_length() > total){
			jQuery(this).mb_left(total, trimTotal - 10);
		}
		return jQuery(this).val(jQuery(this).val().substr(0, trimTotal));
	}
	
	jQuery.fn.TextareaWordCounter = function(options){
		var NameString = jQuery(this).attr('class').replace(options.ElementClass, '').replace('_', '');
		var TheOption = false;
		if(! (NameString=='DisplayID' || NameString=="") && options[NameString]){	TheOption = options[NameString];	}
		if(options.DisplayID == "")	options.DisplayID = 'JqMessageCounterDisplay';
		return this.each(function(){	
			new jQuery.fn.TextareaWordCounterCore.run(this, NameString, options.DisplayID, TheOption);
		});
	}
	jQuery.fn.TextareaWordCounterCore = {
		run: function(me, NameString, DisplayID, options){
			var defaults = {	max: 1000, textarea: false,	display:{	left: '(',right:' characters left)',ele:false	}	};
			var settings = (options==false)?defaults:jQuery.extend({}, defaults, options);
			settings.display.ele = jQuery("#"+DisplayID+'_'+NameString);
			settings.textarea = jQuery(me);
			settings.display.ele.html(settings.display.left+settings.max+settings.display.right);
			jQuery(me).bind('keyup', function(){
				var val = settings.textarea.val();
				settings.textarea.mb_left(settings.max, settings.max);
				settings.display.ele.html(settings.display.left+(settings.max-settings.textarea.mb_length())+settings.display.right);
			});
			jQuery.fn.TextareaWordCounterCore.SettingsArray.push(settings);
		},
		SettingsArray: [],
		reset: function(){
			for(var x in this.SettingsArray){
				var settings = this.SettingsArray[x];
				settings.display.ele.html(settings.display.left+settings.max+settings.display.right);
			}
		},
		check: function(){
			var ErrorArray = [];
			for(var x in this.SettingsArray){
				var settings = this.SettingsArray[x];
				if(settings.max <= settings.textarea.mb_length()){
					settings.display.ele.css({color: '#F00'});
				}
			}
			return (ErrorArray.length==0);
		}
	}

	jQuery.fn.InputChecker = function(options){
		return this.each(function(){	
			var NameString = jQuery(this).attr('class').replace(options.ElementClass, '').replace('_', '');
			var TheOption = false;
			new jQuery.fn.InputCheckerCore.run(this, NameString, options);
		});
	}
	jQuery.fn.InputCheckerCore = {
		run: function(me, NameString, options){
			if(! (NameString=='DisplayID' || NameString=="") && typeof options[NameString]!="undefined"){	TheOption = options[NameString];	}
			var defaults = {	input: false, display: false, DisplayID:false, check:false, msg:'Error', MessagePrefix:options.MessagePrefix	};
			var settings = (TheOption==false)?defaults:jQuery.extend({}, defaults, TheOption);
			settings.display = (settings.DisplayID)?jQuery('#'+settings.DisplayID):jQuery(me).parent().parent();
			settings.input = jQuery('input[name="'+me.name+'"]');
			var InputName = settings.input.attr('name');
			if(typeof jQuery.fn.InputCheckerCore.SettingsNames[InputName]=='undefined'){
				jQuery.fn.InputCheckerCore.SettingsNames[InputName] = jQuery.fn.InputCheckerCore.SettingsArray.length;
				jQuery.fn.InputCheckerCore.SettingsArray.push(settings);
			}
		},
		SettingsNames: {},
		SettingsArray: [],
		check: function(){
			var ErrorArray = [];
			for(var x in this.SettingsArray){
				var settings = this.SettingsArray[x];
				if(settings.check){
					if(! settings.check(settings.input)){	ErrorArray.push(settings);	}
				}else{
					switch(settings.input.attr('type').toLowerCase()){
						case 'text': if(settings.input.val()==''){	ErrorArray.push(settings);	}	break;
						case 'radio':if(! settings.input.is(":checked")){	ErrorArray.push(settings);	}	break;
					}
				}
			}
			for(var x in ErrorArray){
				ErrorArray[x].display.addClass('error').append(settings.MessagePrefix + '<span class="ErrorMsg" style="">'+ErrorArray[x].msg+'</span>');
			}
			return (ErrorArray.length==0);
		},
		reset: function(){
			for(var x in this.SettingsArray){
				var settings = this.SettingsArray[x];
				settings.display.removeClass('error')
					.find('.ErrorMsg').remove().end()
					.find('.ErrorSpacer').remove().end();
			}
		}
	}
})(jQuery);
