﻿var LoginXY = false;
function toggleLogin()
{
	var o = document.getElementById('loginLayer');
	if(o)
	{
		o.style.display = (o.style.display=='')? 'none':'';
		var offset = $("#TDlogin").offset();
		o.style.left = offset.left+'px';
		o.style.top = (offset.top+29) + 'px';
	}
}
var lastFocus = 0;
function enterLogin()
{
	var o = document.getElementById('loginLayer');
	if(o)
	{
			o.style.display = '';		
			switch(lastFocus)
			{
				case 1:
					document.getElementById('EMail').focus();
				break;
				case 2:
					document.getElementById('PWD').focus();
				break;
			}
	}
}
function leaveLogin()
{
	var o = document.getElementById('loginLayer');
	if(o)
	{
			o.style.display = 'none';
	}
	
}

var NavIconNormal = new Array()
NavIconNormal[0] = 'url(/images/menu_01.jpg)';
NavIconNormal[1] = 'url(/images/menu_02.jpg)';
NavIconNormal[2] = 'url(/images/menu_03.jpg)';
NavIconNormal[3] = 'url(/images/menu_04.jpg)';
NavIconNormal[4] = 'url(/images/menu_05.jpg)';

var NavIconLight = new Array()
NavIconLight[0] = 'url(/images/menu_01over.jpg)';
NavIconLight[1] = 'url(/images/menu_02over.jpg)';
NavIconLight[2] = 'url(/images/menu_03over.jpg)';
NavIconLight[3] = 'url(/images/menu_04over.jpg)';
NavIconLight[4] = 'url(/images/menu_05over.jpg)';

var activeIndex = 0;
var activeIndex2 = 0;
var activeTimer = '';
var activeTimer2 = '';
function resetMenu()
{
	for(var i=1;i<=5;i++)
	{
		var o = document.getElementById('TopIcon'+i);		
		o.style.backgroundImage = NavIconNormal[i-1];
		o = document.getElementById('mIndex'+i);
		o.style.display='none';
	}
}
function resetSubMenu()
{
	for(var i=1;i<=9;i++)
	{
		var o = document.getElementById('TopIconS'+i);
		if(o) o.style.backgroundColor='#FFFFFF';
		o = document.getElementById(o.id+'ArrImg');
	if(o) o.style.visibility='visible';

		o = document.getElementById('mIndexS'+i);
		if(o) o.style.display='none';
	}
}

function keepMenu()
{
	clearTimeout(activeTimer);
	var td = document.getElementById('TopIcon'+activeIndex);
	td.style.backgroundImage = NavIconLight[activeIndex-1];
}
function keepMenu2()
{
	clearTimeout(activeTimer);
	clearTimeout(activeTimer2);
	var td = document.getElementById('TopIconS'+activeIndex2);
	td.style.backgroundColor='#D3F3C2';
	var o = document.getElementById(td.id+'ArrImg');
	if(o) o.style.visibility='hidden';
}
function showTopMenu(td,idx)
{
	clearTimeout(activeTimer);
	resetMenu();
	if(activeIndex)
	{
		var a = document.getElementById('mIndex'+activeIndex);
		if(a) a.style.display = 'none';
	}
	td.style.backgroundImage = NavIconLight[idx-1];	
	
	var o = document.getElementById('mIndex'+idx);
	if(o)
	{		
		o.style.display = '';
		var offset = $("#TopIcon"+idx).offset();
		o.style.left = offset.left+'px';
		o.style.top = (offset.top+39) + 'px';
		activeIndex = idx;
	}
}
function showSubMenu(td,idx)
{
	clearTimeout(activeTimer2);
	resetSubMenu();
	if(activeIndex2)
	{
		var a = document.getElementById('mIndexS'+activeIndex2);
		if(a) a.style.display = 'none';
	}
	td.style.backgroundColor = '#D3F3C2';
	var o = document.getElementById(td.id+'ArrImg');
	if(o) o.style.visibility='hidden';

	var o = document.getElementById('mIndexS'+idx);
	if(o)
	{
		o.style.display='';
		var offset= $("#TopIconS"+idx).offset();
		o.style.left = (offset.left +143)+'px';
		o.style.top = offset.top+'px';
		activeIndex2 = idx;
	}
}
function _hideMenu()
{
	if(activeIndex)
	{
		var td = document.getElementById('TopIcon'+activeIndex);
		td.style.backgroundImage = NavIconNormal[activeIndex-1];

		var a = document.getElementById('mIndex'+activeIndex);
		if(a) a.style.display = 'none';
		activeIndex = 0;
		//
		var a = document.getElementById('mIndexS'+activeIndex2);
		if(a) a.style.display = 'none';
		activeIndex2 = 0;
	}
}
function hideTopMenu()
{
	activeTimer = setTimeout("_hideMenu()",100);
}

function hideTopMenu2()
{
	activeTimer2 = setTimeout("_hideMenu2()",100);
}


//<input type="text">欄位驗證 search
//objItem_控制項, strName_控制項中文
function isValidInput(objItem,strName){
	//objItem.value=jTrim(objItem.value);
	if(objItem.value.length==0 || objItem.value=='輸入文字'){
		alert('Please input '+strName+'！');
		objItem.focus();
		return false;
	}
	return true;
}

//<select>欄位驗證 where to buy
//objItem_控制項, strName_控制項中文, bolZero_值可(true)否(false)為0
function isValidSelected(objItem,strName,bolZero){
	if(objItem.options[objItem.selectedIndex].value.length==0){
		alert('Please select '+strName+'!');
		objItem.focus();
		return false;
	}
	if(!bolZero && objItem.options[objItem.selectedIndex].value=='0'){
		alert('Please select '+strName+'!');
		objItem.focus();
		return false;
	}
	return true;
}

function isValidEmail2(objEmail){
	objEmail.value=jTrim(objEmail.value);
	if(objEmail.value.length>0){
		//mailPartten=/^[-_.a-zA-Z0-9]+@([-_a-zA-Z0-9]+\.)+[a-zA-Z0-9]{2,3}$/;
		//mailPartten=/^[a-zA-Z0-9]{1}[\.a-zA-Z0-9_-]*[a-zA-Z0-9]{1}@[a-zA-Z0-9]{1}[\.a-zA-Z0-9_-]*[a-zA-Z0-9]{1}+[\.]{1}[a-zA-Z]+[\.]{0,1}[a-zA-Z]+$/;
		mailPartten=/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/
		if(!mailPartten.test(objEmail.value)){
			return false;
		}
	}
	return true;
}



function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

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];}
}

function login(f)
{
	f.submit();
}

function enterkey(evt) {
  var evt = (evt) ? evt : event
  var charCode = (evt.which) ? evt.which : evt.keyCode
  if (charCode == 13) {
    login(document.frmLogin);
  }
} 
$(document).ready(function() {
	for(var i = 1;i<=5;i++)
	{
		$('#mIndex'+i).bgiframe();
	}
	for(var i = 1;i<=9;i++)
	{
		$('#mIndexS'+i).bgiframe();
	}

	$('#loginLayer').bgiframe();
	document.frmLogin.EMail.onkeypress = enterkey;
	document.frmLogin.PWD.onkeypress = enterkey;
	if(document.getElementById('leftNavMenu')) document.getElementById('leftNavMenu').style.display='';
})