var agt = navigator.userAgent.toLowerCase();
var is_ie = (agt.indexOf("msie") != -1);
var is_ie7 = (agt.indexOf("msie 7.0; windows") != -1);
var is_ff = (agt.indexOf("firefox") != -1);
var is_sf = (agt.indexOf("safari") != -1);
var i = 0;
var cssClassName = (is_ie) ? "className" : "class" ;

function SWFfile(iFile,iwidth,iheight){
	if(iwidth){xwidth = ' WIDTH="'+iwidth+'" ';}else{xwidth = '';}
	if(iheight){xheight = ' HEIGHT="'+iheight+'" ';}else{xheight = '';}
	var output = '<OBJECT ' + xwidth + xheight + ' classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0">';
	output += '<PARAM NAME="movie" VALUE="' + iFile + '"><PARAM NAME="quality" VALUE="high">';
	output += '<EMBED SRC="' + iFile + '"' + xwidth + xheight + ' QUALITY="high" TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"></EMBED>';
	output += '</OBJECT>';
	return(output);
}

function gotoURL(ot){
	if(ot == 1){
		window.top.location = adlink+adid+'&goto='+adurl;
	}else{
		var winName = 'gotoURL';
		var winTheme = "toolbar=yes,location=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes";
		window.open(adlink+adid+"&goto="+adurl,winName,winTheme);
	}
}

function spcImg(width,height){
	var spaceImg = "<IMG SRC='/pix/space.gif' WIDTH='"+width+"' HEIGHT='"+height+"' ALIGN='ABSMIDDLE' BORDER='0'>";
	return(spaceImg);
}

// -----POPUP-FENSTER:-----
function wopen(url,popupname,attributes) {
  win = window.open(url,popupname,attributes);
  win.focus();
}

function OpenWnd(theURL,winName,features) {
 	 window.open(theURL,winName,features);
}

function OpenImage(theURL,winName,pixURL) {
	var theURL = pixURL+theURL;
	features = 'toolbar=no,location=yes,status=no,menubar=no,scrollbars=yes,resizable=yes,height=400,width=400';
	window.open(theURL,winName,features);
}

function OpenPrintFile(theURL,winName) {
	features = 'toolbar=yes,location=no,status=no,menubar=yes,scrollbars=yes,resizable=no,height=460,width=700';
	window.open(theURL,winName,features);
}

function checkLoginField(theForm){
	if(theForm.account.value == ""){
		alert("抱歉！\n請輸入帳號");
		theForm.account.focus();
		return false;
	}
	else if(theForm.password.value == ""){
		alert("抱歉！\n請輸入密碼");
		theForm.password.focus();
		return false;
	}
	else{
		return true;
	}
}

function goPages(form){
	// Copyright 2002 July. Design by Ascent, http://webaq.com, please don't remote this line.
	pipi = ""; st = ""; pages = form.jumpMenu.value; PageSelf = location.href;

	if(PageSelf.indexOf("start=") > -1){
		pipiSplit = PageSelf.split("=");
		for(i = 0 ; i < pipiSplit.length ; i++){
			j = i+1;
			if(pipiSplit[i].indexOf("start") > -1){pipi = pipiSplit[j];}
			j++;
		}
		pipiLeng = pipi.length;
		pipiLength = pipiLeng - 1;
		if(pipi.indexOf("&") == pipiLeng){pipi = pipi.substring(0,pipiLength);}
		if(PageSelf.indexOf("&start") > -1){PageSelfSplit = PageSelf.split("&");}else{PageSelfSplit = PageSelf.split("?");}
		PageSelfSplitLength = PageSelfSplit.length;
		if(PageSelfSplitLength > 0){
			for(k = 0 ; k < PageSelfSplitLength ; k++){
				if(PageSelfSplit[k].indexOf("start") > -1){
					sta = (PageSelfSplit[k].length) - (pipi.length);
					st = PageSelfSplit[k].substring(0,sta);
				}
			}
		}
		sp = st+'='+pipi; striLeng = (PageSelf.length) - (sp.length);
		PageSelf = PageSelf.substring(0,striLeng);
	}

	if(PageSelf.indexOf("?") > -1){q = "&";}else{q = "?";}
	self.location = PageSelf+q+"start="+pages;
}

function pageSelecter(resultTotal,pageSize,idefault){
	// Copyright 2002 July. Design by Ascent, http://webaq.com, please don't remote this line.
	Ends = (resultTotal) / (pageSize);
	Ends = Math.ceil(Ends); j = 1;
	if(Ends > 1){
		bar = '<TABLE BORDER=0 CELLSPACING=0 CELLPADDING=0><FORM><TR><TD CLASS="smalltext" nowrap>'+_GOTONO+' <SELECT ALIGN="ABSMIDDLE" NAME="jumpMenu" onChange="goPages(this.form);">';
		for(i=0;i<Ends;i++){
			st = i * pageSize;
			if(st == idefault){ed = " SELECTED"; np = j;}else{ed = false;}
			bar += "<OPTION VALUE=\""+st+"\""+ed+">"+j+"</OPTION>";
			j++;
		}
		bar += "</SELECT> "+_SPAGE+"</TD></TR></FORM></TABLE>";
		document.write(bar);
	}
}

function checkPasswordFormat(PASSWORD){
	var lenp = PASSWORD.length;

	if(lenp > 0){
		for(var i=0;i<lenp;i++){
			var c = PASSWORD.charAt(i);
			if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")))
			return true;
		}
	}else{
		return false;
	}
}


function checkEmailFormat(email){
	var lene = email.length;

	if(lene > 0){
		for(var i=0;i<lene;i++){
			var c= email.charAt(i);
			if(!((c>="A"&&c<="Z")||(c>="a"&&c<="z")||(c>="0"&&c<="9")||(c=="-")||(c=="_")||(c==".")||(c=="@")))
			return true;
		}
		if((email.indexOf("@")==-1)||(email.indexOf("@")==0)||(email.indexOf("@")==(lene-1)))
			return true;
		if((email.indexOf("@")!=-1)&&(email.substring(email.indexOf("@")+1,lene).indexOf("@")!=-1))
			return true;
		if((email.indexOf(".")==-1)||(email.indexOf(".")==0)||(email.lastIndexOf(".")==(lene-1)))
			return true;

		return false;
	}
}


function clear_field(id,name){
	window.document.forms['editor'].elements[''+id+''].value = "";
	window.document.forms['editor'].elements[''+name+''].value = "";
}


function OnOpen(path){
	features = "toolbar=no,location=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,height=430,width=500";
	window.open(path,"Info",features);
}


function iformSubmit(iform,iaction,ivalue){
	document.forms[''+iform+''].elements[''+iaction+''].value = ivalue;
	document.forms[''+iform+''].submit();
}


function iformSubmitConfirm(iform,iaction,ivalue,isay){
	var idoyou = confirm(isay);
	if(idoyou == true){
		document.forms[''+iform+''].elements[''+iaction+''].value = ivalue;
		document.forms[''+iform+''].submit();
	}
}


//2003-8-19
function login_exec(fn)
{
	if (fn.AccountTmp.value.length == 0) {
		alert("登入系統，請輸入「帳號」！");
		fn.AccountTmp.focus();
		return false;
	}

	if (fn.PasswordTmp.value.length == 0) {
		alert("登入系統，請輸入「密碼」！");
		fn.PasswordTmp.focus();
		return false;
	}

	fn.account.value = fn.AccountTmp.value;
	fn.password.value = fn.PasswordTmp.value;

	fn.AccountTmp.value = "";
	fn.PasswordTmp.value = "";

	fn.submit();
	return true;
}


//2003-10-30 design by ascent
function aqua_bg_bot(m,txt)
{
	switch(m)
	{
		case 1: bgl="normal-cap-left.jpg"; bgf="normal-fill.jpg"; bgr="normal-cap-right.jpg"; break;
		case 2: bgl="hilite-cap-left.jpg"; bgf="hilite-fill.jpg"; bgr="hilite-cap-right.jpg"; break;
		default: bgl="hilite-cap-left.jpg"; bgf="hilite-fill.jpg"; bgr="hilite-cap-right.jpg";
	}
	document.write('<table border=0 cellspacing=0 cellpadding=0 align=right><tr>');
	document.write('<td background=/pub/image/etc/'+bgl+'><img src=/pub/image/0.gif width=11 height=23></td>');
	document.write('<td background=/pub/image/etc/'+bgf+' width=20 align=center nowrap><b>'+txt+'</b></td>');
	document.write('<td background=/pub/image/etc/'+bgr+'><img src=/pub/image/0.gif width=11 height=23></td>');
	document.write('<td><img src=/pub/image/0.gif width=6 height=1></td>');
	document.write('</tr></table>');
}

//2003-11-19 to highlight which is the active one, when there're more than one language selector in a page
function highlight_active_selector(s,t,c)
{
	for(f=0; f<document.forms.length; f++){
		for(e=0; e<document.forms[f].elements.length; e++){
			if (document.forms[f].elements[e].name==s){
				document.forms[f].elements[e].style.backgroundColor = "#ffffff";
			}
		}
	}
	t.style.backgroundColor = c;
}


function AQ_swapImgRestore()
{
  var i, x, a=document.AQ_sr;
  for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function AQ_preloadImages()
{
  var d=document;
  if(d.images)
  {
  	if(!d.AQ_p){d.AQ_p=new Array();}
		var i, j=d.AQ_p.length, a=AQ_preloadImages.arguments;
		for(i=0; i<a.length; i++)
		{
			if(a[i].indexOf("#")!=0)
			{
				d.AQ_p[j]=new Image;
				d.AQ_p[j++].src=a[i];
			}
		}
	}
}


function AQ_findObj(n, d)
{
  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=AQ_findObj(n,d.layers[i].document); return x;
}


function AQ_swapImage()
{
	var i,j=0,x,a=AQ_swapImage.arguments; document.AQ_sr=new Array;
	for(i=0;i<(a.length-2);i+=3)
	if ((x=AQ_findObj(a[i]))!=null){document.AQ_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function AQ_jumpMenu(targ,selObj,restore)
{
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function navi_image_filter(imagename, thehref, mode, imgd)
{
	var imgdf = "";
	if(imgd == "on"){imgdf="d";}
	imagename = (mode + imagename);
	var img_filter = "<a href='"+thehref+"' onMouseOut='AQ_swapImgRestore()' onMouseOver=\"AQ_swapImage('Img"+imagename+"','','" + ImageFolder + imagename + "o.gif',1)\"><img name='Img" + imagename + "' border='0' src='" + ImageFolder+imagename + imgdf + ".gif' align=absmiddle></a>";
	return img_filter;
	//alert(img_filter);
}

function field_focus (field, aktiv)
{
	if(!document.layers && field)
	{
		field.style.border  = aktiv ? "1px solid #4A536A" : "1px solid #CCCCCC";
		field.style.color   = aktiv ? "#000000" : "#999999";
	}
	//onFocus="javascript:field_focus (this, 1); return true;" onBlur="javascript:field_focus (this); return true;"
}


function table_row_display_on () {
	if (is_ie) {
		return 'block';
	} else {
		return 'table-row';
	}
}

/*@cc_on
function nbar()
{
  var N = document.getElementById( 'navigation' ).childNodes;
  var L = N.length;
  var n = null;

  do { --L; n = N[ L ]; with ( n ) { if ( nodeName == 'LI' ) {
    onmouseover = function() { this.className = 'over'; }
    onmouseout  = function() { this.className = ''; }
  } } } while ( L > 0 );
}
@*/

