(function ()
{
if (!window.du)
{
window.du = {};
}
defined = function (obj)
{
return (obj != undefined);
};
window.du.$def = defined;
$id = function (s)
{
return (defined(s)) ? (((typeof s == "string") ? (document.getElementById(s)) : (undefined))) : undefined;
};
window.du.$id = $id;
$tag = function (s)
{
return (defined(s)) ? (((typeof s == "string") ? (document.getElementsByTagName(s)) : (undefined))) : undefined;
};
window.du.$tag = $tag;
$name = function (s)
{
return (defined(s)) ? (((typeof s == "string") ? (document.getElementsByName(s)) : (undefined))) : undefined;
};
window.du.$name = $name;
})();
function exeCheckSubmit(ckName, URL, ParaName)
{
try
{
var bDel = false;
var aCheckbox = document.getElementsByName(ckName);
alert(aCheckbox.length);
for (var i = 0; i < aCheckbox.length; i += 1)
{
if (aCheckbox[i].checked)
{
URL += (URL.indexOf("?") == -1 ? "?" : "&");
URL += ParaName + "=" + aCheckbox[i].value;
bDel = true;
}
}
if (bDel) {
document.location.href = URL;
}
}
catch (e) {
}
}
function checkSelect(ckName){
var selected = document.getElementsByName(ckName);
for (var i = 0; i < selected.length; i += 1)
{
if (selected[i].checked)
{
return true;
}
}
return false;
}
function checkAll(id)
{
var bCheck = false;//When haven't checked exist;
var oDiv = document.getElementById(id);
var aInput = oDiv.getElementsByTagName("input");
var aCheckbox = new Array();
for(var i = 0; i < aInput.length; i += 1){
if(aInput[i].type == "checkbox"){
aCheckbox.push(aInput[i]);
}
}
for (var i = 0; i < aCheckbox.length; i += 1)
{
if (!aCheckbox[i].checked) {
bCheck = true;
}
}
if (bCheck)
{
for (var j = 0; j < aCheckbox.length; j += 1)
{
if (aCheckbox[j].type.toLowerCase() == "checkbox") {
aCheckbox[j].checked = true;
}
}
} else
{
for (var k = 0; k < aCheckbox.length; k += 1)
{
if (aCheckbox[k].type.toLowerCase() == "checkbox") {
aCheckbox[k].checked = false;
}
}
}
if(arguments[1]){
eval(arguments[1]);
}
}
function hback()
{
window.history.back();
}
function hlocation(url)
{
window.location.href=url;
}
function btrim() {
try{
var regform = /^\s*|\s*$/gi;
var value = arguments[0];
value = value.replace(regform, "");
return value;
}catch(e){
}
}
function refresh(){
window.location.reload();
}
function isInteger(value) {
var regform = / /g;
var bValid = true;
value = value.replace(regform, "");
if (value.length > 0) {
if (isNaN(value)) {
bValid = false;
}
if (bValid) {
var numbers = "0123456789";
for (var i=0; i<value.length; i++) {
if (numbers.indexOf(value.charAt(i)) == -1) {
bValid = false;
break;
}
}
}
}
return bValid;
}//== Number ==
function isNumerical(value) {
var regform = / /g;
var bValid = true;
value = value.replace(regform, "");
if (value.length > 0) {
if (isNaN(value)) {
bValid = false;
}
if (bValid) {
var numbers = "0123456789-.";
for (var i=0; i<value.length; i++) {
if (numbers.indexOf(value.charAt(i)) == -1) {
bValid = false;
break;
}
}
}
}
return bValid;
}
function queryRequired(id){
try{
var value = $id(id).value;
value = btrim(value);
if(value.length < 1){
$id(id).focus();
alert(arguments[1]);
return false;
}
}catch(e){
window.alert("An error occur \n method at util queryRequired");
return false;
}
}
function showFrame(id){
try{
$id(id).style.display="block";
$id("frame1tr").style.height='260px';
}catch(e){
window.alert(e);
window.alert("toogleFrame method");
}
}
function openWindowDialog(url, width, height,left,toph)
{
var sFeatures;
sFeatures = "dialogHeight:" + height + "px;";
sFeatures = sFeatures + "dialogWidth:" + width + "px;";
sFeatures = sFeatures + "edge: Raised; center: yes; help: no; resizable: no; status: no;";
return window.open(url, "Sales", "scrollbars=yes,status=yes,width=" + width + ",height=" + height + ",left=" + left + ",top=" + toph);
}
function openWindowModalDialog(url, width, height,left,toph)
{
var sFeatures;
sFeatures = "dialogHeight:" + height + "px;";
sFeatures = sFeatures + "dialogWidth:" + width + "px;";
sFeatures = sFeatures+"dialogTop:"+toph+"px;";
sFeatures = sFeatures+"dialogLeft:"+left+"px;";
sFeatures = sFeatures + "edge: Raised; center: yes; help: no; resizable: no; status: no;";
return window.showModalDialog(url, window, sFeatures);
}
function getFloatValueById(id)
{
var value = document.getElementById(id).value;
if(isNaN(value))
{
var arr = value.split(".");
if(arr.length>0)
{
value = arr[0].replace(/\D/g,'');
if(value.length<1)
{
value = 0;
}
var end='';
for(var i=1;i<arr.length;i++)
{
end = end+''+arr[i].replace(/\D/g,'');
}
if(end.length>0)
{
value = value+'.'+end;
}
}
}
document.getElementById(id).value = value;
return value;
}
function getIntValueById(id)
{
var obj=document.getElementById(id);
obj.value = obj.value.replace(/[^\d.]/g,"");
obj.value = obj.value.replace(/^\./g,"");
obj.value = obj.value.replace(/\.{2,}/g,".");
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
if(obj.value.length>0)
{
document.getElementById(id).value=obj.value;
}
return obj.value;
}
function checkInputInt(id,content)
{
var reg = new RegExp("^[0]*[1-9][0-9]*$");
var obj = document.getElementById(id);
var result = reg.test(btrim(obj.value));
if(result == false)
{
window.alert(content);
obj.focus();
obj.select()
return false;
}
}
function checkInput(id,content,length)
{
if(!length)length=1;
var obj = document.getElementById(id);
if(btrim(obj.value).length < length)
{
window.alert(content);
obj.focus();
return false;
}
}
function openKeyValueDialog(url,keyId,valueId){
var rtnValue = openWindowModalDialog(url,600,500,100,280);
if(rtnValue!=null){
if(keyId)
{
document.getElementById(keyId).value = rtnValue.key;
}
if(valueId)
{
document.getElementById(valueId).value = rtnValue.value;
}
}
}
function getRadioValByName(name,attr){
var elements = $name(name);
if(elements){
for(var i = 0; i< elements.length; i++){
if(elements[i].checked){
if(attr == 'value'){
return elements[i].value;
}else if(attr == 'id'){
return elements[i].id;
}
}
}
}
}
function getRadioValueByName(name){
var elements = document.getElementsByName(name);
if(elements){
for(var i=0;i<elements.length;i++){
if(elements[i].checked){
return elements[i].value;
}
}
}
}
function openColorDialog(id){
var url = 'showColorDialog.html';
var rtnValue = openWindowModalDialog(url,800,600,220,80);
if(rtnValue!=null){
$id(id).value = rtnValue;
}
}
function constellationName(date)
{
var rtnStr = "";
if(date!=null&&date.length>7)
{
if(date.length==8)
{
date = date.substr(4,4);
}else if(date.length==10)
{
date = date.substr(5,2) + date.substr(8,2);
}
if(!isNaN(date))
{
date = parseInt(date,10);
if(date>=1222||date<=119)
{
rtnStr = '魔羯座';
}
if(date>=120&&date<=218)
{
rtnStr = '水瓶座';
}
if(date>219&&date<=320)
{
rtnStr = '雙魚座';
}
if(date>=321&&date<=420)
{
rtnStr = '牡羊座';
}
if(date>=421&&date<=520)
{
rtnStr = '金牛座';
}
if(date>=521&&date<=621)
{
rtnStr = '雙子座';
}
if(date>=622&&date<=722)
{
rtnStr = '巨蟹座';
}
if(date>=723&&date<=822)
{
rtnStr = '獅子座';
}
if(date>=823&&date<=922)
{
rtnStr = '處女座';
}
if(date>=923&&date<=1022)
{
rtnStr = '天秤座';
}
if(date>=1023&&date<=1121)
{
rtnStr = '天蠍座';
}
if(date>=1122&&date<=1221)
{
rtnStr = '射手座';
}
}
}
return rtnStr;
}
function getRowInfoByCharWidth(oldValue,maxWidth)
{
var thsSpan = document.getElementById("charSpan");
var oldWidth = 0;
var newWidth = 0;
var charsWidth = 0;
var rowStr = "";
oldValue = oldValue.split("");
for(var i=0;i<oldValue.length;i++){
thsSpan.innerHTML = oldValue[i];
newWidth = thsSpan.offsetWidth;
charsWidth += (newWidth - oldWidth);
if(charsWidth<maxWidth){
rowStr+=oldValue[i];
}else{
rowStr+="...";
break;
}
}
return rowStr;
}
function displayOmittedByName(objName,maxWidth)
{
var objList = $('#'+objName+' .line_text_overflow');
for(var i=0;i<objList.length;i++)
{
objList[i].innerHTML = getRowInfoByCharWidth(objList[i].innerHTML,maxWidth);
}
}
function imgMoveOrOut(obj,moveImg,outImg)
{
if(outImg==""){
obj.src='/include/default/imgs/'+moveImg+'.png';
}
else{
obj.src='/include/default/imgs/'+outImg+'.png';
}
}
/**
* 點擊複製的方法
*/
function copyMethod(id)
{
var txt=$("#"+id).val();
if (window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", txt);
} else if (navigator.userAgent.indexOf("Opera") != -1) {
window.location = txt;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager
.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("您使用的FireFox瀏覽器,複製功能被拒絕！\n請在瀏覽器地址欄輸入“about:config”并回車。\n然後將“signed.applets.codebase_principal_support”雙擊，設置為“true”");
return;
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1']
.createInstance(Components.interfaces.nsIClipboard);
if (!clip)
return;
var trans = Components.classes['@mozilla.org/widget/transferable;1']
.createInstance(Components.interfaces.nsITransferable);
if (!trans)
return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"]
.createInstance(Components.interfaces.nsISupportsString);
var copytext = txt;
str.data = copytext;
trans.setTransferData("text/unicode", str, copytext.length * 2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip)
return false;
clip.setData(trans, null, clipid.kGlobalClipboard);
}
else{
alert("您的瀏覽器不支持一鍵複製");
return;
}
alert("複製連結成功");
}
/**
* 检查发票统编码
*/
function checkInvVatNo()
{
var invn =$("#invn");
var invVatNo=invn.val();
if(invVatNo == null||invVatNo.length==0)
{
return;
}
var logicWeight = "12121241"; // 邏輯乘數(固定值)
if (invVatNo.length != 8)
{
alert('請輸入8位統編');
invn.focus();
return false;
}
var sum = 0; // 乘積之合
var anothersum = 0; // 乘積之合 (最後第二位數字固定使用0或1)
var type2 = invVatNo.charAt(6) == '7';
for (var i = 0; i < logicWeight.length; i++)
{
var subsum = parseInt(invVatNo.charAt(i)) *parseInt(logicWeight.charAt(i));
if (subsum > 9)
{
var tenDigit = subsum.toString().charAt(0);
var  singleDigit = subsum.toString().charAt(1);
subsum = parseInt(tenDigit) + parseInt(singleDigit);
}
var anothersubsum = subsum;
if (type2 && i == 6)
{ // 最後第二位數字固定使用0或1
subsum = 1; // Reset使用1
anothersubsum = 0; // Reset使用0
}
sum += subsum;
anothersum += anothersubsum;
}
var  ok = (sum % 10 == 0); // 被10整除(無餘數)
if (!ok && type2)
{
ok = (anothersum % 10 == 0); // 被10整除(無餘數)
}
if(!ok)
{
alert('統編格式輸入錯誤咯！')
invn.focus();
return false;
}
}
/**
* 创建底部黑色遮罩 传入遮罩的ID
*/
function appendBottom(id,messageId){
var height = document.body.scrollHeight;
if(height < document.body.clientHeight)
height = document.body.clientHeight;
if(height < document.documentElement.clientHeight)
height = document.documentElement.clientHeight;
if(height < document.documentElement.scrollHeight)
height = document.documentElement.scrollHeight;
$("body").append("<div id='"+id+"'></div>");
$("#"+id).css({position:"absolute",top:"0px",left:"0px",background:"#000",filter:"Alpha(opacity=70);",opacity:"0.5",zIndex:"9999"}).width(document.body.clientWidth+"px").height(height+"px");
}
/**
* 居中显示的DIV
*/
function showMessageDiv(html)
{
var d = document.createElement("div");
d.innerHTML=html;
$(d).appendTo('body');
}
/**
* 清空DIV
*/
function reomveDivs(messageId,id)
{
$("#"+messageId).remove();
$("#"+id).remove();
}
/**
* showDivId：需要显示的DIV，targetId：显示的DIV需要挂在的某个物件的下面，这个就是那个物件的ID
*/
function showDivBuottom(showDivId,targetId)
{
if($('#'+showDivId).length>0&&$('#'+targetId).length>0)
{
var offset=$("#"+targetId).offset();
var leftsize=offset.left;
var topsize=offset.top+$("#"+targetId).height()+5;
$("#"+showDivId).offset({top:topsize,left:leftsize});
}
}

