var isIE = (navigator.appName.indexOf("Microsoft") > -1);
var d = document;

if (!levelArray)	var levelArray = new Array();

var isMobile = checkMobile();
var isAndroid = (navigator.userAgent.toLowerCase().search('android') > -1);

function init()
{
	//for navigation
	if (levelArray.length == 0)	getLevel();
	
	if(levelArray && levelArray.length > 0){
		var lv1 = getParam("lv1");
		var lv2 = getParam("lv2");
		if(lv1!="" && lv2!=""){
			levelArray[0] = lv1
			levelArray[1] = lv2;
		}
	}
	
	
	if (levelArray.length > 0)	highlightTopNav();
	if (levelArray.length > 1)	highlightLeftNav();
	
	
	hoverFunction.ini();

}

function getLevel()
{
	var url = location.pathname;
	var array = url.split('/');
		
	for (var i=0; i<array.length; i++)
	{
		if (array[i].indexOf('_') >= 0)
		{
			var array1 = array[i].split('_');
			for (var j=0; j<array1.length; j++)
			{
				levelArray.push(array1[j]);
			}
			
		}
		else
		{
			levelArray.push(array[i]);
			
		}
	}
	
	levelArray.shift();
	levelArray.shift();
	levelArray.shift();
	
	var obj = levelArray[levelArray.length-1];
	if (obj != 'index.shtml')
	{
		levelArray[levelArray.length-1] = obj.replace('.shtml', '');
	}
	else
	{
		levelArray.pop();
	}
}



function highlightTopNav()
{
	var obj = levelArray[0];
	if (!d.getElementById(obj))	return;
	
	if(d.getElementById(levelArray[1]))
		d.getElementById(levelArray[1]).className += ' active';
	
	var btn = d.getElementById(obj);
	btn.className += ' active';
	
	if (!d.getElementById(obj + '_menu'))	return;
	
	var menu = d.getElementById(obj + '_menu');
	menu.style.display = 'block';
}

function highlightLeftNav()
{

	var obj = levelArray[0];
	//if (!d.getElementById(obj)) return;
	
	//set the navigation as display block and active
	//title
	var title = d.getElementById(obj + "_title");
	
	
	if(!title) return;
	
	title.style.display = "block";
	
	//leftMenu
	var leftMenu =  d.getElementById(obj + "_leftMenu");
	leftMenu.style.display = "block";

	//second level
	var obj1 = levelArray[1];
	if (!d.getElementById(obj+"_"+obj1))	return;

	//set active the title
	d.getElementById(obj+"_"+obj1 + "_title").className += ' active';
	d.getElementById(obj+"_"+obj1 + "_top").className += ' active';


}

function getElementByRel(parent, obj)
{
	var a = d.getElementById(parent).getElementsByTagName('a');
	
	for (var i=0; i<a.length; i++)
	{
		if (a[i].rel == obj)
		{
			return a[i];
		}
	}
}

function checkURL(array)
{
	var url = window.top.location.href;
	var id;
	var va = [["/", "/"], ["=", ""]];
	
	for (var item=0; item<va.length; item++)
	{
		for (var i=0; i<array.length; i++)
		{
			if (url.indexOf((va[item][0] + array[i] + va[item][1])) >= 0)
			{
				id = array[i];
				break;
			}
		}
	}
	
	return id;
}

function showPulldown(btn, id, mode)
{
	//if (btn.className.indexOf('active') >= 0)	return;
	
	var menu = d.getElementById(id + 'Pulldown');
	
	showLayer(1);
	
	if (mode == 2)
	{
		btn.onclick			= function() {menu.hit = false;	showLayer(0);};
	}
	else
	{
		btn.onmouseover		= function() {menu.hit = true;	showLayer(1);};
		menu.onmouseover	= function() {menu.hit = true;	showLayer(1);};
		btn.onmouseout		= function() {menu.hit = false;	showLayer(0);};
		menu.onmouseout		= function() {menu.hit = false;	showLayer(0);};
	}
	
	function showLayer(over)
	{
		if (over == 1)
		{
			if (btn.id != levelArray[0] && btn.className.indexOf('active') < 0)	btn.className += ' active';
			menu.style.display = 'block';
		}
		else
		{
			if (btn.id != levelArray[0])	btn.className = btn.className.replace('active', '');
			
			setTimeout(function()
			{
				if (!menu.hit)
				{
					menu.style.display = 'none';
					
					if (mode == 2)
					{
						btn.onclick	= function() {showPulldown(btn, 'route', 2);};
					}
					/*else
					{
						btn.onmouseover		= null;
						menu.onmouseover	= null;
						btn.onmouseout		= null;
						menu.onmouseout		= null;
					}*/
				}
			}, 100);
		}
	}
}


function displayDropDownList(id) {
		var btn = d.getElementById(id);
		var btn2 = d.getElementById(id+"List");
		
		btn.hit = true;
		
		if (btn2.style.display != 'block') {
				btn2.style.display = 'block';
				btn.className += ' active';
				
				btn.onmouseover = function() {
					btn.hit = true;	
				}
				
				btn2.onmouseover = function() {
					
					
					btn2.style.display = 'block';
					btn2.hit = true;
					btn.className += ' active';
				}
				
				
				
				btn.onmouseout = function() {
					btn.hit = false;
					//setTimeout(function() {btn2.style.display = 'none';}, 1000);
					if (btn.hit != true) {
						if (btn2.hit != true) {
							
							btn2.style.display = 'none';
							btn.className = btn.className.replace('active', '');
						}
					}
				}
				
				btn2.onmouseout = function() {
					btn.hit = false;
					btn2.hit = false;
					//setTimeout(function() {if (btn2.hit)	btn2.style.display = 'none';}, 2000);
					//btn2.style.display = 'none';
					//setTimeout(function() {if (btn2.hit)	btn2.style.display = 'block';}, 2000);
					
					btn2.style.display = 'none';
					btn.className = btn.className.replace('active', '');
					
				}
		
				
		}
		
		
}

/* Scrollbar */
var listScroll = 
{
	scroller:	null,
	scrollbar:	null,

	init:	function (obj, scroll, autoStart)
	{	
		this.container  = d.getElementById(obj);
		this.div  = this.container.getElementsByTagName('div')[0];
		this.scrollbar  = d.getElementById(scroll);
		this.track = this.scrollbar.getElementsByTagName('div')[0];
		this.scroller = this.scrollbar.getElementsByTagName('div')[1];
		this.timeOutSpeed = 70;
		this.containerH = this.container.offsetHeight;
		this.trackH = this.track.offsetHeight - this.scroller.offsetHeight;
		this.id = 0;
		

		
		this.container.onmouseover	= function() {listScroll.stopScroll();};
	//	this.container.onmouseout	= function() {listScroll.autoScrollStart();};
		
		//scroller  = new Scrolling.Scroller(this.container, this.container.offsetWidth, this.track.offsetHeight);
		scroller  = new Scrolling.Scroller(this.container, this.container.offsetWidth, this.container.offsetHeight);
		scrollbar = new Scrolling.Scrollbar(this.scrollbar, scroller, new Scrolling.ScrollTween());
		
		//if (autoStart)	this.autoScrollMode();
//		if (autoStart)	this.changeList(0);
	},
	


	
	goScroll:	function(num)
	{
		this.num = num;
		
		this.stopScroll();
		this.motion(this.div);
	},
	
	motion:	function(container)
	{
		var num = Number(container.style.top.replace('px', '')) - this.num;
		var endH = Math.round(this.objH/2);
		if (num < -endH)	num += endH;
		if (num > 0)		num -= endH;
		container.style.top = Math.round(num) + 'px';
		//window.status = container.style.top + '  :  ' + endH + '  :  ' + this.objH;
		
		//this.scroller.style.top = (container.scrollTop/((this.objH - this.containerH)/2 + this.containerH))*this.trackH + 'px';
		//this.scroller.style.top = Math.round((-Number(container.style.top.replace('px', ''))/(this.objH/2))*this.trackH) + 'px';
		this.scroller.style.top = Math.round((-Number(container.style.top.replace('px', ''))/(this.objH/2))*this.trackH) + 'px';
		
		this.timeOut = setTimeout(function() {listScroll.motion(container);}, this.timeOutSpeed);
	},
	
	stopScroll:	function()
	{
		clearTimeout(this.timeOut);
		clearTimeout(this.timeOut2);
	},
	

	scrollBarMode:	function()
	{
		//var ul = this.container.getElementsByTagName('ul');
	//	var li = ul[this.id].getElementsByTagName('li');
		//var total = li.length;
	//	var j = 0;
	//	while (j < total/2)
	//	{
	//		li[j].style.display = 'none';
	//		j ++;
	//	}
	//	this.stopScroll();
	}
}



/* Home Video */

function setChildNodes(obj, tagName)
{
	var array = new Array();
	
	for (var i=0; i<obj.childNodes.length; i++)
	{
		if (tagName)
		{
			//alert(obj.childNodes[i].tagName)
			if (obj.childNodes[i].tagName != tagName)	continue;
		}
		if (obj.childNodes[i].toString().toLowerCase().indexOf('text') >= 0)	continue;
		array.push(obj.childNodes[i]);
	}
	
	return array;
}


function createDiv(id, className, txt)
{		
	var div = d.createElement('div');
	if (id)	div.setAttribute('id', id);
	if (className)	div.className = className;
	//if (txt)	div.appendChild(d.createTextNode(txt));
	if (txt)	div.innerHTML = txt;
	return div;
}


function getElementsByClassName(p, c, selected)
{
	var array = new Array();
	var tags = p.getElementsByTagName('*');
	
	for (var i=0; i<tags.length; i++)
	{
		if (!tags[i].className)	continue;
		if (selected)
		{
			if (tags[i].className.indexOf(c) >= 0)	array.push(tags[i]);
		}
		else
		{
			if (tags[i].className == c)	array.push(tags[i]);
		}
	}
	
	return array;
}


function genVideosAll(array, size)
{
	for (var i=0; i<array.length; i++)
	{
		var container = document.getElementById(array[i].id);
		if(typeof container=="undefined" || container==null)
			continue;
		new genVideo(container, array[i].video, array[i].poster, i, size);
	}
}
function genVideo(videoPlayer, videoPath, posterPath, num, size)
{

//	var videoPlayer = d.getElementById(id);
	var w = 284; 
	var h = 213; 
	var self = this;
	if(size!=undefined){
		w = size.width;
		h = size.height;
	}
	
	this.init = function()
	{
		self.playVideo();
	};
	
	this.playVideo = function()
	{
		if (isMobile && !isAndroid)
//		if (!isMobile)
		{	
			videoPlayer.innerHTML = '';
			
			/*var video = videoPlayer.getElementsByTagName('video')[0];
			var source = video.getElementsByTagName('source')[0];
			source.src = videoPath;
			video.poster = posterPath;*/
			
			var video = d.createElement('video');
			video.width = w;
			video.height = h;
			if (posterPath)	video.poster = posterPath;
			video.controls = 'controls';
			//video.autoplay = 'autoplay';
			
			var source=d.createElement('source');
			source.src = videoPath;
			source.type = 'video/mp4';
			
			var object=d.createElement('object');
			object.width = w;
			object.height = h;
			object.classid='clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B';
			object.data = videoPath;
			
			var param=d.createElement('param');
			param.name = 'src';
			param.value = videoPath;
			
			var param2=d.createElement('param');
			param2.name='autoplay';
			param2.value='false';
			
			object.appendChild(param);
			object.appendChild(param2);
			video.appendChild(source);
			video.appendChild(object);
			
			videoPlayer.appendChild(video);
			
			//Fix for iOS3
			var canPlay = video.canPlayType(source.type);
			if (canPlay == 'probably' || canPlay == 'maybe')
			{
				video.src = source.src;
				video.load();
			}
			
			video.load();
			video.play();
			
			video.addEventListener('click', function()
			{
				video.play();
			},false);
		}
		else
		{
			self.genSwfVideo();
		}
	};
	
	this.genSwfVideo = function()
	{	
		/*var div = d.createElement('span');
		div.id = 'videoSWF' + num;
		videoPlayer.appendChild(div);*/
		
		videoPlayer.id = 'videoSWF' + num;
		
		//videoPath = videoPath.replace('.mp4', '.flv');
		
		var flashvars = {};
		flashvars.srcPath = videoPath;
		flashvars.imgPath = posterPath;
		flashvars.videoW = w;
		flashvars.videoH = h;
		flashvars.autoPlay = "false";
		flashvars.downloadPath = "";
		flashvars.controlBarAutoHide = "true";		


		var params = {};
		params.wmode = 'transparent';
		params.menu = "false";
		params.scale = "noScale";
		params.allowFullscreen = "true";
		params.allowScriptAccess = "always";
		params.bgcolor = "#FFFFFF";
		
		

		var attributes = {};
//		attributes.id = "VideoPlayer";

		swfobject.embedSWF('/en/images/swf/flvplayer.swf', 'videoSWF' + num, w, h, '10.0.0', '', flashvars, params, attributes);


/*		var file = '/en/images/swf/flvplayer.swf';
		var flashvars = { file:videoPath,image:posterPath,autostart:'false','controlbar.position':'over','controlbar.idlehide':true};
		var params = { allowfullscreen:'true', allowscriptaccess:'always'};
		var attributes = { id:'videoSWFa', name:'videoSWFa'};
		swfobject.embedSWF(file,'videoSWF', w, h,'9.0.115','false',	flashvars, params, attributes);
*/	};
	
	this.init();
}



/*function genSWFVideos(widthValue, heightValue)
{

	$('video').each(function(i){
							   
		var src=$('source').attr('src');
		alert(src);
		$(this).parent().attr('id','videobox_'+i);

		var str = src.indexOf('/en/images/homeVideos/');
		var str1 = src.indexOf('.mp4');

		var videoPath = src.substring(str, str1) + '.mp4';
		var posterPath = $(this).attr('poster');

		var flashvars = {};
		flashvars.srcPath = videoPath;
		flashvars.imgPath = posterPath;
		flashvars.videoW = widthValue;
		flashvars.videoH = heightValue;
		flashvars.autoPlay = "false";
		flashvars.downloadPath = "";
		flashvars.controlBarAutoHide = "true";		


		var params = {};
		params.wmode = 'transparent';
		params.menu = "false";
		params.scale = "noScale";
		params.allowFullscreen = "true";
		params.allowScriptAccess = "always";
		params.bgcolor = "#FFFFFF";
		
		

		var attributes = {};
		attributes.id = "VideoPlayer";

		swfobject.embedSWF('/en/images/swf/flvplayer.swf', 'videobox_' + i, widthValue, heightValue, '10.0.0', '', flashvars, params, attributes);

	});
	
}*/


/*
function genSWFVideos2()
{
	
	if (checkIpad()) {
		
	} else {
	
	var videoWrapper = d.getElementById('videoWrapper');
	//alert(videoWrapper.getElementsByTagName('div')[0].getElementsByTagName('div')[0].id);
	//var container = videoWrapper.getElementsByTagName('div')[0].getElementsByTagName('div')[0];
	
	
	var container = setChildNodes(videoWrapper, 'DIV');
	container = setChildNodes(container, 'DIV');
	var total = container.length;

	//Gen Flash Player
	for (var i=0; i<total; i++)
	{	
		
		var div = createDiv('videoSWF_' + i);
		var videoHTML = container[i].innerHTML;
		//alert(container[i].getElementsByTagName('div')[0].innerHTML);
		//alert(container[i].getElementsByTagName('div')[0].innerHTML);
		div.innerHTML = videoHTML;
		
	//	container[i].innerHTML = '';
		//alert(container[i].id);
		container[i].appendChild(div);
		

		//if (!isIE)
		//{
		//	var videoPath = container[i].getElementsByTagName('source')[0].src.replace('.mp4', '.flv');
		//	var posterPath = container[i].poster;
		
		//}
		//else
		//{
	
			var str = videoHTML.indexOf('/en/images/homeVideos/');
			var str1 = videoHTML.indexOf('.mp4');

			var videoPath = videoHTML.substring(str, str1) + '.flv';
			var posterPath = '/en/images/homeVideos/' + levelArray[1] + '/video_' + (i + 1) + '.gif';

		//}
		
		//alert(videoPath);
		
		var flashvars = {};
		flashvars.swfPath = '/en/images/swf/SkinOverAllNoCaption.swf';
		flashvars.preview = posterPath;
		flashvars.flv = videoPath;
		
		var params = {};
		params.allowscriptaccess = 'always';
		params.allowfullscreen = 'true';
		params.wmode = 'transparent';
		
		var attributes = {};
		
		swfobject.embedSWF('/en/images/swf/flvplayer.swf', ('videobox_' + i), 290, 240, '10.0.0', '', flashvars, params, attributes);
	}
	}
	
}
*/

//check ipad
function checkIpad()
{
	if((navigator.userAgent.match(/iPhone/i)) ||  (navigator.userAgent.match(/iPod/i)) ||  (navigator.userAgent.match(/iPad/i)))
	{
		return true;
	}
	
	return false;
}


var AECommon = {};
AECommon.popupWin = null;
AECommon.popupBase = function(theURL, settings, win_w, win_h){
	try{
		if (!this.popupWin)
		{
			this.popupWin = window.open(theURL,"aeonPopup",settings, true);
		}
		else
		{
			if((typeof isIE == "boolean") && (isIE)){
				this.popupWin.close();
				this.popupWin = window.open(theURL,"aeonPopup",settings, true);
			}else{
				if(this.popupWin.closed)
					this.popupWin = window.open(theURL,"aeonPopup",settings, true);
				this.popupWin.location.href = theURL;
			}
		}
		
		if((typeof isIE == "boolean") && (isIE==false)){
			this.popupWin.resizeTo(win_w, win_h);
		}		
		this.popupWin.focus(); 
	}catch(e){
		alert(e);
	} 
}

function popup(theURL, winName, settings) { 
	if(!theURL) return;
	winName = winName || "";
	settings = settings || "";	
	
	if(settings.match(/toolbar=/gim)==null){
		if(settings.length>0) settings += ",";
		settings += "toolbar=no";
	}	
	window.open(theURL,winName,settings);
}
// Pop up box
function popup_Cal(theURL,winName) {  
	win_w = 428;
	win_h = 605;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_forms(theURL,winName) {  
	win_w = 975;
	win_h = 580;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_login(theURL,winName) {  
	win_w = 980;
	win_h = 800;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_contactform(theURL,winName) {  
	win_w = 650;
	win_h = 720;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_luckydrawform(theURL,winName) {  
	win_w = 550;
	win_h = 720;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_giftcard(theURL,winName) {  
	win_w = 980;
	win_h = 800;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_whatsnews(theURL,winName) {  
	win_w = 830;
	win_h = 650;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_images(theURL,winName) {  
	win_w = "";
	win_h = 580;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_tac(theURL,winName) {  
	win_w = 512;
	win_h = 600;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_large(theURL,winName) {  
	win_w = 980;
	win_h = 800;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_medium(theURL,winName) {  
	win_w = 800;
	win_h = 600;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_small(theURL,winName) {  
	win_w = 640;
	win_h = 480;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

function popup_imagesPop(theURL,winName) {  
	win_w = 645;
	win_h = 760;
	loc_x = (window.screen.width - win_w)/2;
	loc_y = (window.screen.height - win_h)/2;
	s = 1;
	r = 1;
	settings = 'height=' + win_h + ',width=' + win_w + ',top=' + loc_y + ',left=' + loc_x + ',scrollbars=' + s + ',resizable=' + r;
	AECommon.popupBase(theURL, settings, win_w, win_h);
}

/* mouse over */
var hoverFunction={};
hoverFunction.ini=function(){
	$('.hoverFunction').hover(function(){
		$(this).addClass('active');
		$('img.hoverImg',this).eq(0).addClass('hideImg');
		$('img.hoverImg',this).eq(1).removeClass('hideImg');
		$('td.title_recommendation a',this).addClass('active');
	},function(){
		$(this).removeClass('active');
		$('img.hoverImg',this).eq(1).addClass('hideImg');
		$('img.hoverImg',this).eq(0).removeClass('hideImg');
		$('td.title_recommendation a',this).removeClass('active');
	});
}

/* mouse over change image */
function changeImg(img_name,img_src) {
		document[img_name].src=img_src;
}

function iPx(){
	if((navigator.userAgent.match(/iPhone/i)) ||  (navigator.userAgent.match(/iPod/i)) ||  (navigator.userAgent.match(/iPad/i)))
		return true;
	return false;
}


function getParam(name){
	try{
		var start = location.search.indexOf("?"+name+"=");
		if (start < 0) start = location.search.indexOf("&"+name+"=");
		if (start < 0) return "";
		start += name.length+2;
		var end = location.search.indexOf("&",start)-1;
		if (end < 0) end=location.search.length;
		var result = location.search.substring(start,end);
		var result = "";
		for(var i=start;i<=end;i++){
			var c = location.search.charAt(i);
			result = result+(c=="+"?" ":c);
		}
		//alert(unescape(result));
		return unescape(result);
	}catch(e){
		return "";
	}
}

function selectOptionByValue(id, value){
	try{
		var element = document.getElementById(id);
		if(!element || element==null || element.options.length <= 0) return;
		
		for(var i=0;i<element.options.length;i++){
			if(element.options[i].value != value) continue;
			
			element.selectedIndex = i;
			break;
		}
	}catch(e){
	}
}

/* lightbox */

var lightbox={};
lightbox.status=0;
lightbox.contentId=false;
lightbox.selector='a[rel=lightbox]';
lightbox.width=472;
lightbox.height=300;
lightbox.ini=function(){
	//$(lightbox.selector).click(function(e){
	//	e.preventDefault();	
	//	lightbox.open(e.target.parentNode);
	//});
};
lightbox.open=function(element){
	if(element=="undefined" || element==null) return;
	lightbox.status=1;
	lightbox.overlay();

	$('<div id="lightbox" />').appendTo('body').css({
		'width':lightbox.width,
		'height':lightbox.height,
		'z-index':11000
	}).append('<div class="close"><a href="#">Close</a></div>').center();
	
	$('#lightbox .close').click(function(e){
		e.preventDefault();
		lightbox.close();
	});
	
	if(element.title)
		$('#lightbox .title').html(element.title);

	$('#lightbox').append('<div id="lightbox_content" />');

	if(element.href.indexOf('#')>-1){
		var id=element.href.substring(element.href.indexOf('#')+1);
		lightbox.contentId=id;
		var $content=$('#'+id);

		$content.css({display: 'block'});
		$content.appendTo('#lightbox_content').show();
		$('#lightbox').width($content.width()).height($content.height()+50).center();
		$(window).unbind('scroll').scroll(lightbox.relocate).resize(lightbox.relocate);
	}
}
lightbox.openWithLoanType = function(loanType){
	var popupApplyLoan = document.getElementById("popupApplyLoan");
	popupApplyLoan.href = "javascript:popup_login('/AeonApplication/"+loanType+"?method=display&lang=en','');";
	lightbox.open(document.getElementById("btn_applyNow"));
}
lightbox.openwithCashAdvance = function(){
	lightbox.open(document.getElementById("btn_applyNow"));
}
lightbox.openLightbox = function(id){

	var a = document.getElementById(id+"_a");
	lightbox.open(a);
}

lightbox.openWithCardCode = function(cardCode){
	var popupApplyCreaitCard = document.getElementById("popupApplyCreaitCard");
	popupApplyCreaitCard.href = popupApplyCreaitCard.href.replace(/(cardType=)(.*)$/i, "cardType="+cardCode+"', '');");
	
	lightbox.open(document.getElementById("btn_applyNow"));
}
lightbox.relocate=function(){
	if(lightbox.status==1){
		lightbox.overlay();
		var $lightbox=$('#lightbox').center();
	}
}

lightbox.overlay=function(){

	var w_width=$(document).width();
	var w_height=$(document).height();
	
	if($.browser.msie && parseInt($.browser.version)==6)
		w_width=w_width-8;
			
	$('#overlay').remove();
	$('<div id="overlay" />').appendTo('body').css({
		'width':w_width,
		'height':w_height
	}).click(lightbox.close);
			
	// IE6 select box fix
	if ($.browser.msie && parseInt($.browser.version)<=6){
		$('select').css('visibility','hidden');
		$('.popup select').css('visibility','visible');
	}
	
	$('body').css('overflow-x','hidden');
}

lightbox.close=function(){
	
	if(lightbox.contentId!=false){
		$('#'+lightbox.contentId).hide().appendTo('body');
		lightbox.contentId=false;
	}
	
	
	$('#overlay, #lightbox').remove();
	
	// IE6 select box fix
	if ($.browser.msie && parseInt($.browser.version)<=6)
		$('select').css('visibility','visible');
		
	lightbox.status=0;

	$('body').css('overflow-x','visible');
}
jQuery.fn.center = function () {
	
	var top=( $(window).height() - this.height() ) / 2+$(window).scrollTop();
	var left=( $(window).width() - this.width() ) / 2+$(window).scrollLeft();
	
    this.css("position","absolute");
    this.css("top", top + "px");
    this.css("left", left + "px");
    return this;
}

jQuery.fn.cleanOuterHTML = function() {
	return $("<p/>").append(this.eq(0).clone()).html();
}



function showHideLink(id) {
		   var e = document.getElementById(id);
		   if(e.style.display == 'block')
			  e.style.display = 'none';
		   else
			  e.style.display = 'block';
		}


function checkMobile()
{
	var pda_user_agent_list = new Array("2.0 MMP", "240320", "AvantGo","BlackBerry", "Blazer",
			"Cellphone", "Danger", "DoCoMo", "Elaine/3.0", "EudoraWeb", "hiptop", "IEMobile", "KYOCERA/WX310K", "LG/U990",
			"MIDP-2.0", "MMEF20", "MOT-V", "NetFront", "Newt", "Nintendo Wii", "Nitro", "Nokia",
			"Opera Mini", "Opera Mobi",
			"Palm", "Playstation Portable", "portalmmm", "Proxinet", "ProxiNet",
			"SHARP-TQ-GX10", "Small", "SonyEricsson", "Symbian OS", "SymbianOS", "TS21i-10", "UP.Browser", "UP.Link",
			"Windows CE", "WinWAP", "Android", "iPhone", "iPod", "iPad", "Windows Phone", "HTC"/*, "GTB"*/);
	var pda_app_name_list = new Array("Microsoft Pocket Internet Explorer");

	var user_agent = navigator.userAgent.toString();
	for (var i=0; i<pda_user_agent_list.length; i++) {
		if (user_agent.indexOf(pda_user_agent_list[i]) >= 0) {
			return true;
		}
	}
	var appName = navigator.appName.toString();
	for (var i=0; i<pda_app_name_list.length; i++) {
		if (user_agent.indexOf(pda_app_name_list[i]) >= 0) {
			return true;
		}
	}
	
	return false;
}

