// JScript 檔

szValidString00	= new String( 'abcdefghijklmnopqrstuvwxyz' );
szValidString01	= new String( '0123456789' );
szValidString02	= new String( '0123456789abcdefghijklmnopqrstuvwxyz#_-' );
szValidString03	= new String( '0123456789abcdefghijklmnopqrstuvwxyz#_- \';' );
NumArray = new Array (1,10,19,28,37,46,55,64,39,73,82,2,11,20,48,29,38,47,56,65,74,83,21,3,12,30);

// 檢查身份証
function CheckId( strId )
{
	var id_input = new Array(10);
	strId = strId.toLowerCase( );
	if( strId.length != 10 )	
		return false;
	for( i = 0 ; i < 10 ; i++ )
		id_input[i] = strId.charAt( i ) ;
	id_input[0] = szValidString00.indexOf( id_input[0] , 0 );
	if( id_input[0] == -1 )
		return false;
	if( id_input[1] != 1 && id_input[1] != 2 )
		return false;
	var result ;
	result =  NumArray[ id_input[0] ];
	for( i = 1 ; i < 10 ; i++ )
	{
		id_input[i] = szValidString01.indexOf( id_input[i] , 0 );
		if( id_input[i] == -1 )
			return false;
		else
			result = result + id_input[i] * ( 9 - i )
	}
	result = result + ( 1 * id_input[9] );
	if( ( result % 10 ) != 0 )
		return false;
	else
		return true ;
}
// 檢查統一編號
function chkIisn( strIisn )
{
	return CheckIisn( strIisn );
}
function CheckIisn( sIisn )
{
	if( sIisn.length != 8 )
		return false;
	var sValidate = '0123456789'
	var val = new Array( 8 );
	var wt = 0;

	for( i=0; i< sIisn.length ; i++ )
	{
		if( sValidate.indexOf( sIisn.charAt( i ) ) == -1 )
			return false;
		val[i] = parseInt( sIisn.charAt( i ) );
	}
	// 權數為1的部分直接相加
	wt = val[0] + val[2] + val[4] + val[7];

	//計算權數
	val[1] = ( val[1] * 2 ) % 10 + Math.floor( val[1] * 2 / 10 );
	val[3] = ( val[3] * 2 ) % 10 + Math.floor( val[3] * 2 / 10 );
	val[5] = ( val[5] * 2 ) % 10 + Math.floor( val[5] * 2 / 10 );
	val[6] = ( val[6] * 4 ) % 10 + Math.floor( val[6] * 4 / 10 );
	wt += val[1] + val[3] + val[5] + val[6]
	if( wt % 10 == 0 )
	{
		return true;
	}else
	{
		//假如營利事業統一編號第7位為"7"
		if( sIisn.charAt( 6 ) == '7' )
		{
			wt = ( wt - val[6] ) + Math.floor( val[6] / 10 )
			if( wt % 10 == 0 )
				return true;
			else
				return false;
		}else
		{
			return false;
		}
	}
}	

// 檢查Email
function CheckMail( strMail )
{
	var bRet = false;
	if( strMail == null || strMail == '' )
		return bRet;
	var sEmail = Trim( strMail );
	var nPos1, nPos2;
	nPos1 = sEmail.indexOf( '@' );
	nPos2 = sEmail.lastIndexOf( '.' );
	if( ( nPos1 < 1 ) || ( nPos2 < 2 )  || ( nPos2-nPos1 < 1 ) )
		bRet = false
	else
		bRet = true
	return bRet;
}

// 檢查是否為有效字元
function IsValidString( srcString , bSpace )
{
	bRet = new Boolean( true );
	var szBuf = new String( srcString.toLowerCase( ) );
	var szBuf2 = new Array( szBuf.length )
	var szSearchString = new String( );
	var i ;
	for( i = 0 ; i < srcString.length ; i++ )
		szBuf2[i] = szBuf.charAt( i );
	if( bSpace == false )
		szSearchString = szValidString02;
	else
		szSearchString = szValidString03;
	for( i = 0 ; i < szBuf.length ; i++ )
	{
		if( szSearchString.indexOf( szBuf2[i] , 0 ) == -1 )
			return false;
	}
	return true;
}

function Trim( srcString )
{
	return srcString.replace( /^\s/ , '' ).replace( /\s*$/ , '' )
}

// 檢查是否有選擇
function chkNotSelect( objRdx )
{
	var i ;
	var bRet = false;
	for( i = 0 ; i < objRdx.length ; i++ )
	{
		if( objRdx[i].checked )
		{
			bRet = true 
			return bRet;
		}
	}
	return bRet ;
}

// 檢查是否有選擇
function chkSelect( objRdx , strErr )
{
	var i ;
	var bRet = false;
	for( i = 0 ; i < objRdx.length ; i++ )
	{
		if( objRdx[i].checked )
		{
			bRet = true 
			return bRet;
		}
	}
	if( strErr.length > 0 )
	{
		alert( strErr );
	}
	return bRet ;
}

// 檢查是否有選擇
function chkSelectA( objRdx , strErr , bFocus)
{
	var i ;
	var bRet = false;
	for( i = 0 ; i < objRdx.length ; i++ )
	{
		if( objRdx[i].checked )
		{
			bRet = true 
			return bRet;
		}
	}
	if( strErr.length > 0 )
	{
		alert( strErr );
	}
	if ( bFocus == true )
	{
		objRdx[0].focus( )
	}
	return bRet ;
}

// 檢查是否為空白
function chkEmpty( objTxt , strErr )
{
	if( Trim( objTxt.value ).length == 0 )
	{
		if( strErr.length > 0 )
		{
			alert( strErr );
		}
		return false;
	}else
	{
		return true;
	}
}

// 檢查是否為空白，並Focus
function chkEmptyA( objTxt , strErr , bFocus)
{
	if( Trim( objTxt.value ).length == 0 )
	{
		if( strErr.length > 0 )
		{
			alert( strErr );
		}
		if ( bFocus == true )
		{
			objTxt.focus( )
		}
		return false;
	}else
	{
		return true;
	}
}


function getChecked( objItem )
{
    var i, sRet = '';
    if( objItem.length )
    {
        for( i=0 ; i<objItem.length ; i++ )
        {
            if( objItem[i].checked )
            {
                if( sRet.length > 0 ) 
                    sRet += ',';
                sRet += objItem[i].value;
            }
        }
    }else
    {
        if( objItem.checked )
            sRet += objItem.value;
    }
    return sRet;
}
function getCheckItem(obj)
{
	if(!obj)
		return "";
	var ret = "";
	if(obj.length)
	{
		var i;
		for(i=0 ; i<obj.length ; i++)
		{
			if(obj[i].checked)
			{
				if(ret.length != 0)
					ret += ",";
				ret += obj[i].value;
			}
		}
	}else
	{
		if(obj.checked)
			ret = obj.value;
	}
	return ret;
}
function getCheckItemA(obj, seprator)
{
	if(!obj)
		return "";
	var ret = "";
	if(obj.length)
	{
		var i;
		for(i=0 ; i<obj.length ; i++)
		{
			if(obj[i].checked)
			{
				if(ret.length != 0)
					ret += seprator;
				ret += obj[i].value;
			}
		}
	}else
	{
		if(obj.checked)
			ret = obj.value;
	}
	return ret;
}

function openwindow1(url)
{
    window.open(url, '_blank', '');
}
function openwindow2(url, name)
{
    window.open(url, name, '');
}
function openwindow3(url, name, style)
{
    window.open(url, name, style);
}


/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/
var offsetfrommouse=[15,-25]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset  圖的xy
var displayduration=0; //duration in seconds image should remain visible. 0 for always.  不移保持不動
var currentimageheight = 450;	// maximum image size.  大圖size
var ctt;
var w_interval=2000;
if (document.getElementById || document.all)
{
	document.write('<div id="trailimageid" style="position:absolute">');
	document.write('</div>');
}
function gettrailobj()
{
	if (document.getElementById)
		return document.getElementById("trailimageid").style
	else if (document.all)
		return document.all.trailimagid.style
}
function gettrailobjnostyle()
{
	if (document.getElementById)
		return document.getElementById("trailimageid")
	else if (document.all)
		return document.all.trailimagid
}
function truebody()//???????
{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}
function showtrail(imagename, imagenum, license, caption, showthumb, brand, imageid)
{
	//var cval=getCookie('dp_sel');
	//if(cval!='off')
	//{
		if (imageid > 0)
		{
			var width = 400; //getImageWidth(imageid);
			var height =400; //  getImageHeight(imageid);
		}
		document.onmousemove=followmouse;
		newHTML = '<div style="padding: 5px; overflow: hidden; background-color: #FFF; border: 1px solid #888;" >';
		if (showthumb > 0)
		{
			newHTML = newHTML + '<div align="center" style="overflow: hidden; padding: 8px 2px 2px 2px;"><img src="' + imagename + '" width="240" border="0" ></div>';
		}
		var lencaption = caption.length;
		var len = 85;
		if (caption)
		{
		  var trunc = caption;
		  if (trunc.length > len)
		  {
			trunc = trunc.substring(0, len);
			trunc = trunc.replace(/\w+$/, '');
			caption = trunc;
		  }
		}
		gettrailobjnostyle().innerHTML = newHTML;
	//		alert(newHTML);

		ctt==setTimeout("set_visible()",w_interval);
//	}
}

function set_visible()
{
	gettrailobj().visibility="visible";
}
function hidetrail()
{
//	var cval=getCookie('dp_sel');
//	if(ctt) clearTimeout(ctt);
//	if(cval!='off')
//	{
		gettrailobj().visibility="hidden";
		document.onmousemove=""
		gettrailobj().left="-500px"
//	}
}

function followmouse(e)
{
	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
	if (typeof e != "undefined")
	{
		if (docwidth - e.pageX < 400)
		{
			xcoord = e.pageX - xcoord - 515; // Move to the left side of the cursor
		} 
		else 
		{
			xcoord += e.pageX;
		}
		if (docheight - e.pageY < (currentimageheight + 110))
		{
			ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
		} else
		{
			ycoord += e.pageY;
		}
	} 
	else if (typeof window.event != "undefined")
	{
		if (docwidth - event.clientX < 400)
		{
			xcoord = event.clientX + truebody().scrollLeft - xcoord - 515; // Move to the left side of the cursor
		} 
		else 
		{
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110))
		{
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		}
		else 
		{
			ycoord += truebody().scrollTop + event.clientY;
		}
	}
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}
