/* 檢查是否符合yy/mm/dd形式 */
function checkYMD(motoText)
{
	data = motoText.match(/^(\d\d)\/(\d\d)\/(\d\d)$/);
	if (!data) return false;
	mm = eval(RegExp.$2);
	dd = eval(RegExp.$3);
	if ((mm < 1) || (mm > 12)) { alert("月份異常"); return false; }
	if ((dd < 1) || (dd > 31)) { alert("日期異常"); return false; }
	return true;
}

// When mouse move to table, Chang it color
function setPointer(theRow, thePointerColor, theNormalBgColor)
{
    var theCells = null;

    if (thePointerColor == '' || typeof(theRow.style) == 'undefined') {
        return false;
    }
    if (typeof(document.getElementsByTagName) != 'undefined') {
        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    var rowCellsCnt  = theCells.length;
    var currentColor = null;
    var newColor     = null;
    // Opera does not return valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined' && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].setAttribute('bgcolor', newColor, 0);
        } // end for
    }
    else {
        currentColor = theCells[0].style.backgroundColor;
        newColor     = (currentColor.toLowerCase() == thePointerColor.toLowerCase())
                     ? theNormalBgColor
                     : thePointerColor;
        for (var c = 0; c < rowCellsCnt; c++) {
            theCells[c].style.backgroundColor = newColor;
        }
    }

    return true;
}
// end of the 'setPointer()' function

//Ajax功能
// 依據不同的瀏覽器，取得 XMLHttpRequest 物件
function createAJAX() 
{
	if (window.ActiveXObject) {
		try {
			return new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				return new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e2) {
				return null;
			}
		}
	} else if (window.XMLHttpRequest) {
			return new XMLHttpRequest();
	} else {
			return null;
	}
}

// 非同步送出資料
function ajaxSendRequest(uri) 
{
	ajax = createAJAX() ;
	if (!ajax) {
		alert ('使用不相容 XMLHttpRequest 的瀏覽器');
		return 0;
	}
	ajax.onreadystatechange = onRcvData;
	ajax.open ("GET", uri, true);
	ajax.send ("");
}

// 確認輸入格式 Cindy
function AdminCheckIsNaN(vTitle,vValue) 
{
		//alert(isNaN(vValue));
	if (isNaN(vValue)){
		alert ('"'+vTitle+'" 請輸入數字 !');
		return false;
	}
}

//list頁 選擇多筆 Cindy
function topclick(obj){
	checkcount=(obj.elements.length)-1;
	if(obj.top.checked == true){
		for(i = 0; i < checkcount; i++){
			obj.elements[i+1].checked = true;
		}				
	}else if(obj.top.checked == false){
		for(i = 0; i < checkcount; i++){
			obj.elements[i+1].checked = false;
		}				
	}
}

//list頁 批次執行 Cindy
function batchAction(obj,vValue){
	if(vValue!="nothing"){
		switch(vValue){
			case "enableyes":
				vTitle="顯示";
				break;
			case "enableno":
				vTitle="取消顯示";
				break;
			case "delbatch":
				vTitle="刪除";
				break;
			default:
				alert("Batch Error !");
				return false;
				break;
		}
		if(vTitle!=""){
			chk = confirm("你確定要 '"+vTitle+"' 選擇的資料嗎 ?\n\n");
			if(!chk){
				return false;
			}else{
				obj.submit(); 
				return true;
			}
		}
	}
}

//確認Mail格式 Cindy
function checkEmail(e_mail, mstr) {
	var rejectedDomain=new Array()
	var index=0;
	//rejectedDomain[index++]="hotmail"
	//rejectedDomain[index++]="rocketmail"
	//rejectedDomain[index++]="yahoo"
	rejectedDomain[index++]="zdnetmail"

	var rejected=false
	var testresults=true
	var str=e_mail
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(str)){
		var tempstring = str.split("@")
		tempstring = tempstring[1].split(".")
		for (i=0; i<rejectedDomain.length; i++) {
			if (tempstring[0]==rejectedDomain[i])
			rejected=true
		}
		if (rejected) {
			var message="Please input a more official email address!\n"
			message += "The following addresses are not allowed:\n"
			for (i=0; i<rejectedDomain.length; i++) {
				message += "\t" + rejectedDomain[i] + "\n"
			}
			alert(message)
			testresults=false
		}
	} else {
		alert(mstr)
		testresults=false
	}
	return (testresults)
}

//確認上傳檔案格式 Cindy
function checkFileType(vTitle, vType) {
	var rejectedDomain=new Array()
	var index=0;
	//rejectedDomain[index++]="hotmail"
	//rejectedDomain[index++]="rocketmail"
	//rejectedDomain[index++]="yahoo"
	rejectedDomain[index++]="zdnetmail"

	var rejected=false
	var testresults=true
	var str=e_mail
	
	switch(vType){
		case "img":
			var filter=("gif", "jpg", "jpeg", "png", "swf" );
			break;
		case "txt":
			var filter=("doc", "xls", "txt", "pdf", "ppt", "zip");
			break;
		case "html":
			var filter=("html", "htm", "xml" );
			break;
		case "mov":
			var filter=("doc", "xls", "txt", "pdf", "gif", "jpg", "zip", "rar", "ppt","html", "htm", "xml", "jpeg", "png" );
			break;
		default:
			var filter=array("pdf", "gif", "jpg", "jpeg", "png", "swf" );
			break;
	}
	var filter=/^.+@.+\..{2,3}$/
	if (filter.test(str)){
		var tempstring = str.split("@")
		tempstring = tempstring[1].split(".")
		for (i=0; i<rejectedDomain.length; i++) {
			if (tempstring[0]==rejectedDomain[i])
			rejected=true
		}
		if (rejected) {
			var message="Please input a more official email address!\n"
			message += "The following addresses are not allowed:\n"
			for (i=0; i<rejectedDomain.length; i++) {
				message += "\t" + rejectedDomain[i] + "\n"
			}
			alert(message)
			testresults=false
		}
	} else {
		alert(mstr)
		testresults=false
	}
	return (testresults)
}


