/*Check Email*/ function ChkEmail( Email ) { var regExp = /^[^@^\s]+@[^\.@^\s]+(\.[^\.@^\s]+)+$/; return Email.match( regExp ); } /* Json Sort */ /* DataAry => [ { 'SN' : '1', 'USER' : '5' }, { 'SN' : '2', 'USER' : '6' }, { } ] SortField => Sort欄位,如 USER SortType => 'D' = DESC , 'A' = 'ASC' */ function SortJsonAry( DataAry, SortField, SortType ) { var valueType = 'Num'; for( var N = 0; N < DataAry.length; N++ ) { if( isNaN( DataAry[N][SortField] ) ) { valueType = 'Text'; break; } } function SortByName( x, y ) { if( valueType == 'Num' ) { // 數字 //return ( ( x[SortField] == y[SortField] ) ? 0 : ( ( x[SortField] > y[SortField] ) ? 1 : -1 ) ); return x[SortField] - y[SortField]; } else if( valueType == 'Text' ) { // 文字 return x[SortField].localeCompare( y[SortField] ); } } DataAry.sort( SortByName ); if( SortType == 'D' ) { DataAry.reverse(); } return DataAry; } /*取得物件資訊*/ function GetObjRectInfo( Obj ) { var ObjRectInfoJson = Obj.getBoundingClientRect(); var ReturnJson = {}; ReturnJson['top'] = Math.floor( ObjRectInfoJson['top'] * 100 ) / 100; ReturnJson['left'] = Math.floor( ObjRectInfoJson['left'] * 100 ) / 100; ReturnJson['bottom'] = Math.floor( ObjRectInfoJson['bottom'] * 100 ) / 100; ReturnJson['right'] = Math.floor( ObjRectInfoJson['right'] * 100 ) / 100; ReturnJson['width'] = Math.floor( ObjRectInfoJson['width'] * 100 ) / 100; ReturnJson['height'] = Math.floor( ObjRectInfoJson['height'] * 100 ) / 100; return ReturnJson; } //某值是否在陣列中 function InArray( Str, Ary ) { if( Ary != null ) { for ( var S = 0; S < Ary.length; S++ ) { THISENTRY = Ary[S].toString(); if( THISENTRY == Str ) { return true; } } } else { return false; } } /*數值格式化 NumberFormat( 123456, 2 )*/ function NumberFormat( numberValue, c ) { var n = numberValue, c = isNaN(c = Math.abs(c)) ? 2 : c, d = ".", t = ",", s = n < 0 ? "-" : "", i = String(parseInt(n = Math.abs(Number(n) || 0).toFixed(c))), j = (j = i.length) > 3 ? j % 3 : 0; return s + (j ? i.substr(0, j) + t : "") + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) + (c ? d + Math.abs(n - i).toFixed(c).slice(2) : ""); } /*判斷是否為陣列*/ function IsArray( ARY ) { return !!ARY && typeof ARY === 'object' && typeof ARY.length === 'number' && typeof ARY.splice === 'function' && !( ARY.propertyIsEnumerable('length') ); } //移除陣列某值 function DelArrayValue( ARR, DELV ) { for( var i = 0; i < ARR.length; i++ ) { if( ARR[i] == DELV ) { ARR.splice( i, 1 ); } } return ARR; } /* 捲軸位置 */ function GetPageScroll() { var yScroll; if ( self.pageYOffset ) { yScroll = self.pageYOffset; } else if ( document.documentElement && document.documentElement.scrollTop ) { yScroll = document.documentElement.scrollTop; } /* Explorer 6 Strict */ else if ( document.body ) { yScroll = document.body.scrollTop; } /* all other Explorers */ var xScroll; if ( self.pageXOffset ) { xScroll = self.pageXOffset; } else if ( document.documentElement && document.documentElement.scrollLeft ) { xScroll = document.documentElement.scrollLeft; } /* Explorer 6 Strict */ else if ( document.body ) { xScroll = document.body.scrollLeft; } /* all other Explorers */ var ARYPAGESCROLL = new Array( xScroll, yScroll ); return ARYPAGESCROLL; } /*視窗及內容大小*/ function GetPageSizeInfo() { var xScroll, yScroll; if( window.innerHeight && window.scrollMaxY ) { xScroll = document.body.scrollWidth; yScroll = window.innerHeight + window.scrollMaxY; } else if( document.body.scrollHeight > document.body.offsetHeight ) { /* all but Explorer Mac */ xScroll = document.body.scrollWidth; yScroll = document.body.scrollHeight; } else { /* Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari */ xScroll = document.body.offsetWidth; yScroll = document.body.offsetHeight; } var windowWidth, windowHeight; if( self.innerHeight ) { /* all except Explorer */ windowWidth = self.innerWidth; windowHeight = self.innerHeight; } else if( document.documentElement && document.documentElement.clientHeight ) { /* Explorer 6 Strict Mode */ windowWidth = document.documentElement.clientWidth + 20; windowHeight = document.documentElement.clientHeight; } else if( document.body ) { /* other Explorers */ windowWidth = document.body.clientWidth; windowHeight = document.body.clientHeight; } /* for small pages with total height less then height of the viewport */ if( yScroll < windowHeight ) { pageHeight = windowHeight; } else { pageHeight = yScroll; } /* for small pages with total width less then width of the viewport */ if( xScroll < windowWidth ) { pageWidth = windowWidth; } else { pageWidth = xScroll; } var ARYPAGESIZE = { 'pageWidth': pageWidth, 'pageHeight': pageHeight, 'windowWidth': windowWidth, 'windowHeight': windowHeight }; return ARYPAGESIZE; } var InputDfClass = new function() { var self = this; /*取得radio checked的值*/ self.GetRadioValue = function ( RadioObj ) { var V = ''; var RadioLength = RadioObj.length; if( RadioLength > 1 ) { for( var N = 0; N < RadioObj.length; N++ ) { if( RadioObj[N].checked == true ) { V = RadioObj[N].value; return V; } } } else { if( RadioObj.checked == true ) { V = RadioObj.value; return V; } } return false; } /*設定radio checked的值*/ self.SetRadioChecked = function( RadioObj, V ) { for( var N = 0; N < RadioObj.length; N++ ) { if( RadioObj[N].value == V ) { RadioObj[N].checked = true; break; } } } /*取得checkbox checked的值*/ self.GetCheckboxValue = function( CheckboxObj ) { var VAry = []; if( CheckboxObj == null ) { return false; } else if( isNaN( CheckboxObj.length ) ) { if( CheckboxObj.checked == true ) { VAry.push( CheckboxObj.value ); } if( VAry.length ) { return VAry; } else { return false; } } else { for( var N = 0; N < CheckboxObj.length; N++ ) { if( CheckboxObj[N].checked == true ) { VAry.push( CheckboxObj[N].value ); } } if( VAry.length ) { return VAry; } else { return false; } } } /*設定checkbox checked*/ self.SetCheckboxChecked = function( CheckboxObj, VAry ) { for( var A = 0; A < CheckboxObj.length; A++ ) { if( InArray( CheckboxObj[A].value, VAry ) ) { CheckboxObj[A].checked = true; } } } } /*開linghtbox*/ function lightbox() { this.ARY_PAGE_SIZE = GetPageSizeInfo(); this.ARY_PAGE_SCROLL = GetPageScroll(); this.objBody = document.getElementsByTagName("body").item(0); this.objOverlay = document.createElement("div"); this.objOverlay_id = 'overlayId'; this.objOverlay_zIndex = '1500'; this.objOverlay_className = 'sys_overlay'; this.objOverlay_backgroundColor = ''; this.objOverlay_innerhtml = ''; this.objLightbox_id = 'lightboxId'; this.objLightbox_zIndex = '1501'; this.objLightbox_width = this.ARY_PAGE_SIZE.windowWidth - 100; this.objLightbox_height = this.ARY_PAGE_SIZE.windowHeight - 100; this.objLightbox_className = 'sys_lightbox'; this.showOverLay = function() { this.lightbox_id_ary = new Array(); this.lightbox_id_ary.push( this.objOverlay_id ); this.lightbox_id_ary.push( this.objLightbox_id ); var LARY = new Array(); LARY = this.lightbox_id_ary; this.objOverlay.setAttribute( 'id', this.objOverlay_id ); this.objOverlay.style.zIndex = this.objOverlay_zIndex; this.objOverlay.className = this.objOverlay_className; this.objOverlay.style.backgroundColor = this.objOverlay_backgroundColor; this.objOverlay.style.height = this.ARY_PAGE_SIZE.pageHeight + 'px'; this.objOverlay.style.left = this.ARY_PAGE_SCROLL[0] + 'px'; this.objOverlay.onclick = function () { CloseLightbox( LARY ) }; this.objBody.insertBefore(this.objOverlay, this.objBody.firstChild); this.objOverlay.style.display = 'block'; this.objBody.style.overflow = 'hidden'; for( var N = 0; N < this.objBody.childNodes.length; N++ ) { if( this.objBody.childNodes[N].nodeType == 1 ) { for( var NN = 0; NN < this.objBody.childNodes[N].attributes.length; NN++ ) { if( this.objBody.childNodes[N].nodeName == 'DIV' && this.objBody.childNodes[N].attributes[NN].name == 'id' && this.objBody.childNodes[N].attributes[NN].value == this.objOverlay_id ) { this.objBody.childNodes[N].innerHTML = this.objOverlay_innerhtml; break; } else if( this.objBody.childNodes[N].nodeName == 'SELECT' ) { this.objBody.childNodes[N].style.visibility = "hidden"; } } } } }; this.showLightBox = function() { var ARY_PAGE_SIZE = GetPageSizeInfo(); var objLightbox = document.createElement("div"); objLightbox.setAttribute( 'id', this.objLightbox_id ); objLightbox.style.zIndex = this.objLightbox_zIndex; objLightbox.style.width = ( this.objLightbox_width == "100%" ) ? this.objLightbox_width : this.objLightbox_width + 'px'; objLightbox.style.height = ( this.objLightbox_height == "100%" ) ? this.objLightbox_height : this.objLightbox_height + 'px'; objLightbox.setAttribute( 'w', this.objLightbox_width ); objLightbox.setAttribute( 'h', this.objLightbox_height ); objLightbox.style.marginTop = '-'+this.objLightbox_height / 2 +'px'; objLightbox.style.marginLeft = '-'+this.objLightbox_width / 2 +'px'; if( this.objLightbox_width != "100%" ) { console.log(this.objLightbox_width); console.log(ARY_PAGE_SIZE); if( ARY_PAGE_SIZE.windowWidth - 20 <= this.objLightbox_width ) { objLightbox.style.width = '100%'; objLightbox.style.height = '100%'; objLightbox.style.marginTop = 'auto'; objLightbox.style.marginLeft = 'auto'; objLightbox.style.top = 'auto'; objLightbox.style.left = 'auto'; } } objLightbox.className = this.objLightbox_className; this.objBody.insertBefore(objLightbox, this.objOverlay.nextSibling); objLightbox.style.display = 'block'; for( var N = 0; N < this.objBody.childNodes.length; N++ ) { if( this.objBody.childNodes[N].nodeType == 1 && this.objBody.childNodes[N].nodeName == 'DIV' ) { for( var NN = 0; NN < this.objBody.childNodes[N].attributes.length; NN++ ) { if( this.objBody.childNodes[N].attributes[NN].name == 'id' && this.objBody.childNodes[N].attributes[NN].value == this.objLightbox_id ) { this.objBody.childNodes[N].innerHTML = this.objLightbox_innerhtml; break; break; } } } } window.addEventListener( "resize", function ( event ) { SetObjLightboxWHFun(); }); ResizeFunAry.push( SetObjLightboxWHFun ); } this.SetObjLightboxWH = function() { var ARY_PAGE_SIZE = GetPageSizeInfo(); var SysOverlayObjAry = document.querySelectorAll( '.sys_overlay' ); for( var S = 0; S < SysOverlayObjAry.length; S++ ) { if( SysOverlayObjAry[S] ) { SysOverlayObjAry[S].style.height = ARY_PAGE_SIZE['pageHeight'] + 'px'; } } var SysLightboxObjAry = document.querySelectorAll( '.sys_lightbox' ); for( var S = 0; S < SysLightboxObjAry.length; S++ ) { if( SysLightboxObjAry[S] ) { var SysLightboxContentType = SysLightboxObjAry[S].getAttribute( 't' ); var DfWdith = SysLightboxObjAry[S].getAttribute( 'w' ); var DfHeight = SysLightboxObjAry[S].getAttribute( 'h' ); if( DfWdith == '100%' || isNaN( DfWdith ) || ARY_PAGE_SIZE['windowWidth'] <= parseInt( DfWdith ) ) { SysLightboxObjAry[S].style.marginLeft = 'auto'; SysLightboxObjAry[S].style.marginTop = 'auto'; SysLightboxObjAry[S].style.width = '100%'; SysLightboxObjAry[S].style.height = '100%'; SysLightboxObjAry[S].style.minWidth = 'auto'; SysLightboxObjAry[S].style.maxWidth = 'auto'; SysLightboxObjAry[S].style.top = 'auto'; SysLightboxObjAry[S].style.left = 'auto'; } else { SysLightboxObjAry[S].style.marginTop = ( DfHeight / 2 * -1 ) + 'px'; SysLightboxObjAry[S].style.marginLeft = ( DfWdith / 2 * -1 ) + 'px'; SysLightboxObjAry[S].style.width = DfWdith+'px'; SysLightboxObjAry[S].style.height = DfHeight+'px'; SysLightboxObjAry[S].style.minWidth = DfWdith+'px'; SysLightboxObjAry[S].style.maxWidth = 'auto'; SysLightboxObjAry[S].style.top = '50%'; SysLightboxObjAry[S].style.left = '50%'; } } } } } /*ResizeLightboxWH*/ function SetObjLightboxWHFun() { var LIGHTBOX = new lightbox(); LIGHTBOX.SetObjLightboxWH(); } /*關lightbox*/ function CloseLightbox( LARY ) { if( ! LARY ) { LARY = new Array( 'overlayId', 'lightboxId' ); } if( IsArray( LARY ) ) { if( document.getElementsByTagName( 'select' ) ) { var SELECTS = document.getElementsByTagName( 'select' ); for ( var i = 0; i < SELECTS.length; i++ ) { SELECTS[i].style.visibility = "visible"; } } if( parent.document.getElementsByTagName( 'select' ) ) { var SELECTS = parent.document.getElementsByTagName( 'select' ); for ( var i = 0; i < SELECTS.length; i++ ) { SELECTS[i].style.visibility = "visible"; } } for( var N = 0; N < LARY.length; N++ ) { if( document.getElementById( LARY[N] ) ) { document.body.style.overflow = ''; document.documentElement.style.overflow = ''; /*IE6,7*/ document.body.removeChild( document.getElementById( LARY[N] ) ); } else if( parent.document.getElementById( LARY[N] ) ) { parent.document.body.style.overflow = ''; parent.document.documentElement.style.overflow = ''; /*IE6,7*/ parent.document.body.removeChild( parent.document.getElementById( LARY[N] ) ); } } } else { top.location.href = LARY; } } /*開linghtbox function*/ function LightboxWindow( SEND_GET, W, H ) { var LIGHTBOX = new lightbox(); if( W ) { LIGHTBOX.objLightbox_width = W; } if( H ) { LIGHTBOX.objLightbox_height = H; } LIGHTBOX.showOverLay(); LIGHTBOX.showLightBox(); LIGHTBOX_OBJ = document.getElementById( LIGHTBOX.objLightbox_id ); LIGHTBOX_OBJ.innerHTML = ""; return LIGHTBOX_OBJ; } /*開Linghtbox*/ function LinghtboxDiv( W, H ) { var LIGHTBOX = new lightbox(); if( W ) { LIGHTBOX.objLightbox_width = W; } if( H ) { LIGHTBOX.objLightbox_height = H; } LIGHTBOX.showOverLay(); LIGHTBOX.showLightBox(); LIGHTBOX_OBJ = document.getElementById( LIGHTBOX.objLightbox_id ); return LIGHTBOX_OBJ; } /*是否為行動裝置*/ function isMobileDevice(){ var mobileDevices = ['Android', 'webOS', 'iPhone', 'iPad', 'iPod', 'BlackBerry', 'Windows Phone'] var isMobileDevice = false; for( var i = 0; i < mobileDevices.length; i++ ){ if( navigator.userAgent.match( mobileDevices[i] ) ) { isMobileDevice = mobileDevices[i]; } } return isMobileDevice } function isMobile() { try { document.createEvent( 'TouchEvent' ); return true; } catch(e) { return false; } } /*取得背景圖適合的backgroundSize*/ function ImageBgStyle( DfJson ) { /* DfJson = { 'ImageWidth', ImageHeight', 'DivWidth', 'DivHeight' } */ var BackgroundSize = 'auto auto'; if( DfJson['ImageWidth'] && DfJson['ImageHeight'] && DfJson['DivWidth'] && DfJson['DivHeight'] ) { if( DfJson['DivHeight'] < DfJson['DivWidth'] ) { if( DfJson['DivHeight'] / DfJson['ImageHeight'] * DfJson['ImageWidth'] >= DfJson['DivWidth'] ) { BackgroundSize = 'auto 100%'; } else { BackgroundSize = '100% auto'; } } else { if( DfJson['DivWidth'] / DfJson['ImageWidth'] * DfJson['ImageHeight'] >= DfJson['DivHeight'] ) { BackgroundSize = '100% auto'; } else { BackgroundSize = 'auto 100%'; } } } return BackgroundSize; } function RemoveContent( ThisObj ) { var NV = ThisObj.value.replace(/\t+/g, ""); ThisObj.value = NV; }