﻿//文字欄位輸入檢查
function TextCheckBoolean(txtObj, txtDefault) {
	var re = /\s/g;
    //把有\s字串清空
    var txtObj_Value = txtObj.value.replace(re,escape(''));
	if (txtObj_Value == '' || txtObj_Value == txtDefault) {
		return false;
	}
	return true;
}

//選項按鈕選取檢查
function RadioCheck(radObj, theField) {
	var checked = 0;
	for (var i = 0; i < radObj.length; i++) {
		if (radObj[i].checked) {checked += 1;}
	}

	if (i == 0) {
	    if (radObj.checked) {checked += 1;}
	}

	if (checked == 0) {
	    alert('請選擇' + theField + '！');
	    if (i > 0){radObj[0].focus();}
	    return false;
	    }
	return true;
}

//選項按鈕選取檢查傳回勾選數
function RadioCheckS(radObj) {
	var checked = 0;

    try {

	    for (var i = 0; i < radObj.length; i++) {
		    if (radObj[i].checked) {checked += 1;}
	    }

	    if (i == 0) {
	        if (radObj.checked) {checked += 1;}
	    }
    }
    catch(exception){checked = 0;}

	return checked;
}

//選項按鈕選取檢查
function RadioCheckBoolean(radObj) {
	var checked = 0;
	for (var i = 0; i < radObj.length; i++) {
		if (radObj[i].checked) {checked += 1;}
	}

	if (i == 0) {
	    if (radObj.checked) {checked += 1;}
	}

	if (checked == 0) {
	    if (i > 0){radObj[0].focus();}
	    return false;
	    }
	return true;
}

//選項按鈕選取檢查
function RadioSetVal(radObj) {
	var checked = '';
	for (var i = 0; i < radObj.length; i++) {
		if (radObj[i].checked) {checked = radObj[i].value;}
	}

	if (i == 0) {
	    if (radObj.checked) {checked = radObj.value;}
	}

	return checked;
}


//選單選取檢查
function SelectCheck(selObj, theField) {
	if (selObj.options[selObj.selectedIndex].value == '') {
		alert('請選擇' + theField + '！'); selObj.focus(); return false;
	}
	return true;
}

//文字欄位輸入檢查
function TextCheck(txtObj, theField, txtDefault) {
	var re = /\s/g;
    //把有\s字串清空
    var txtObj_Value = txtObj.value.replace(re,escape(''));
	if (txtObj_Value == '' || txtObj_Value == txtDefault) {
		alert('請輸入' + theField + '！'); txtObj.focus(); return false;
	}
	return true;
}

//多行文字欄位元輸入長度檢查（文字欄位元，長度，欄位名稱）
//function TextLenCheck(txtObj, c, nMinLen, nMaxLen) { 
//	if (txtObj.value.length > nMaxLen) {
//	    alert(theField + '輸入長度過長！'); txtObj.focus(); return false;
//	}
//	if (txtObj.value.length < nMinLen)
//	{
//	    alert(theField + '輸入長度過短！'); txtObj.focus(); return false;
//	}
//	return true;
//}

//多行文字欄位元輸入長度檢查（文字欄位元，長度，欄位名稱）
function TextLenCheck(txtObj, theField, nMinLen, nMaxLen, nLenMsg) { 
	var Alert_Msg = '';
	if (txtObj.value.length > nMaxLen) {
	    
	    if (nLenMsg) {
	        Alert_Msg = '\n\n字數太長,請輸入' + nMaxLen + '字數內！';
	    }
	    if (theField !='')
	    {
	        alert(theField + '請輸入正確！' + Alert_Msg); txtObj.focus();
	    }
	    return false;
	}
	if (txtObj.value.length < nMinLen)
	{
	    if (nLenMsg) {
	        Alert_Msg = '\n\n字數太短,請至少輸入' + nMinLen + '字數！';
	    }
	    if (theField !='')
	    {
	        alert(theField + '請輸入正確！' + Alert_Msg); txtObj.focus();
	    }
	    return false;
	}
	return true;
}

//電子信箱檢查
function EmailCheck(txtObjEmail) {
	var eMail = txtObjEmail.value;
	if (eMail != '') {
		if (eMail.indexOf('@', 0) == -1 || eMail.indexOf('@', 0) == 0 || eMail.indexOf('@', 0) == eMail.length - 1) {
			alert('電子信箱格式有誤 !'); txtObjEmail.focus(); return false;
		}
		if (eMail.indexOf('.', 0) == -1 || eMail.indexOf('.', 0) == 0 || eMail.indexOf('.', 0) == eMail.length - 1) {
			alert('電子信箱格式有誤 !'); txtObjEmail.focus(); return false;
		}
		if (eMail.indexOf('@', eMail.indexOf('@', 0) + 1) != -1) {
			alert('電子信箱格式有誤 !'); txtObjEmail.focus(); return false;
		}
		if (eMail.indexOf('.', eMail.indexOf('@', 0) + 1) == -1 || eMail.indexOf('.', eMail.indexOf('@', 0) + 1) == eMail.indexOf('@', 0) + 1) {
			alert('電子信箱格式有誤 !'); txtObjEmail.focus(); return false;
		}
	}
	return true;
}

function ck_Focus(obj,str){
    if(obj.value == str){obj.value=''};
}

function ck_Blur(obj,str){
    if(obj.value == ''){obj.value=str};
}

// 檢查輸入格式
function KeyLock_CK(cType, bAlert) { //鍵盤鎖定（格式，是否顯示錯誤訊息）
//	cType	格式。I：整數、N：負整數、D：小數、ND：負小數、E：英數。
//	bAlert	是否顯示錯誤訊息。true：顯示、false：不顯示。
//	適用於 onKeyPress 事件。
	var mMsg = '';
	var nKey = event.keyCode;
	switch (cType) {

		case 'I' : { //整數
			if ((nKey > 31 && nKey < 48) || nKey > 57) {
				event.returnValue = false;
				mMsg = '限輸入數字 !';
			}
			break;
		}
		case 'N' : { //負整數
			if ((nKey > 31 && nKey < 45) || (nKey > 45 && nKey < 48) || nKey > 57) {
				event.returnValue = false;
				mMsg = '限輸入數字及負號(-) !';
			}
			break;
		}
		case 'Float' : { //小數
			if ((nKey > 31 && nKey < 46) || (nKey > 46 && nKey < 48) || nKey > 57) {
				event.returnValue = false;
				mMsg = '限輸入數字及小數點(.) !';
			}
			break;
		}
		case 'ND' : { //負小數
			if ((nKey > 31 && nKey < 45) || (nKey > 46 && nKey < 48) || nKey > 57) {
				event.returnValue = false;
				mMsg = '限輸入數字、負號(-)及小數點(.) !';
			}
			break;
		}
		case 'E' : { //英數
			if ((nKey > 31 && nKey < 48) || (nKey > 57 && nKey < 65) || (nKey > 90 && nKey < 97) || nKey > 122) {
				event.returnValue = false;
				mMsg = '限輸入數字及英文字母 !';
			}
			break;
		}
	}
	if (bAlert && mMsg != '') {alert(mMsg);}
}

function tosubmit(frmobj, obj_id, objvalue){
  
  var obj = window.document.getElementById(obj_id);
      obj.value = objvalue;
      frmobj.submit();
}

function frm_location(frmobj, sType, vIsMember, vIsCk) {
    if (vIsMember.toLowerCase() == 'true' || vIsCk == false){
        if (sType.toLowerCase() == 'booking')
        {
            frmobj.action = 'activity_booking.asp';
            frmobj.submit();}
        else if (sType.toLowerCase() == 'contact')
        {
            frmobj.action = 'activity_contact.asp'
            frmobj.submit();}
        else{
            frmobj.action = '';
        }
    }
    else{
        alert('請先登入社區會員!');
    }
    //frmobj.submit();
    //return false;
}

function frm_bookingck(frmobj)
{
    if (!confirm("您確定要報名嗎?")){return false;}
    else{frmobj.ckda.value='YES';frmobj.submit();}
}

function frm_contactck(frmobj)
{
    if (!TextCheck(frmobj.txt_cmtname, "社區名稱",'')) {return false;}
    if (!TextCheck(frmobj.txt_name, "姓名",'')) {return false;}
    if (!TextCheck(frmobj.txt_tel, "聯絡電話",'')) {return false;}
    if (!TextCheck(frmobj.txt_email, "電子信箱",'')) {return false;}
    if (!EmailCheck(frmobj.txt_email)) {return false;}
    if (!TextLenCheck(frmobj.txt_desc, "聯絡內容",20,300,true)) {return false;}
    if (!confirm("您確定要送出嗎?")){return false;}
    else{
        frmobj.ckda.value='YES';frmobj.submit();
    }
}

function frm_albumck(frmobj)
{
    //if (!TextCheck(frmobj.txt_cmtname, "社區名稱",'')) {return false;}
    if (!TextCheck(frmobj.txt_title, "相簿名稱",'')) {return false;}
    if (!TextCheck(frmobj.PDATE, "相簿日期",'')) {return false;}
    if (!TextCheck(frmobj.SDATE, "呈現期間",'')) {return false;}
    if (!TextCheck(frmobj.EDATE, "呈現期間",'')) {return false;}
    //if (!TextCheck(frmobj.txt_desc, "相簿描述",'')) {return false;}
    if (!TextLenCheck(frmobj.txt_desc, "相簿描述", 0, 1000, true)) {return false;}
    if (RadioSetVal(frmobj.is_media) == 'Y') {
        if (!TextCheck(frmobj.txt_media, "影音內容",'')) {return false;}
    }
    frmobj.ckda.value='YES';
    return true;
}

function frm_album_imgck(frmobj)
{
    if (!TextCheck(frmobj.txt_img_title, "相片名稱",'')) {return false;}
    if (!TextCheck(frmobj.PDATE, "相片日期",'')) {return false;}
    if (!TextCheck(frmobj.txt_img_desc, "相片描述",'')) {return false;}
    if (frmobj.FILE1.value.length == 0) {alert("請先上傳相片!");return false;}
    frmobj.ckda.value='YES';
    return true;
}

//open 視窗
function js_Open(url,name,width,height,k)
    {
     if (width > 0) {
        LeftPosition = (screen.width) ? (screen.width-width)/2 : 0;}
     else{
        width = screen.width-10;
        LeftPosition= 0;
     }
     if (height > 0) {
        TopPosition  = (screen.availHeight) ? (screen.availHeight-height)/2 : 0 ;}
     else{
        height = screen.availHeight-10;
        TopPosition= 0;
     }
     window.open(url,name,'top='+ TopPosition+',left='+ LeftPosition+ ',width='+width+',height='+height+',resizable=1,scrollbars='+k+',status=0');
    }
//-->

function frm_delck(frmobj,objID,objIDVal)
{
    if (!confirm("您確定刪除嗎?")){return false;}
    else{
    frmobj.ckda.value='DEL';
    objID.value = objIDVal;
    frmobj.submit();}
}


function frm_location_delck(frmobj,objID,objIDVal,frmurl)
{
    if (!confirm("您確定刪除嗎?")){return false;}
    else{
    var url = frmobj.action;
    frmobj.ckda.value='DEL';
    objID.value = objIDVal;
    frmobj.action=frmurl;
    frmobj.submit();
    frmobj.action = url;
    }
}

var gif_checked1 = 0;
var gif_checked2 = 0;
var gif_checked_length = 0;
var gif_ex_checked_length = 0;

function order_send(frm_obj)
{
 gif_checked1 = 0;
 gif_checked2 = 0;
 gif_checked_length = 0;
 gif_ex_checked_length = 0;


 var giftobj = frm_obj.gift_id;
 var giftobj_ex1 = frm_obj.gift_ex_1;
 var giftobj_ex2 = frm_obj.gift_ex_2;

 var vlength = giftobj.length;

 for (var i = 0; i < vlength; i++) {
    var giftobj_ex_checked = false;
    if (giftobj_ex1[i].checked) {gif_checked1 += 1;giftobj_ex_checked=true;}
    if (giftobj_ex2[i].checked) {gif_checked2 += 1;giftobj_ex_checked=true;}
    if (giftobj_ex_checked == true){gif_ex_checked_length +=1;}
 }
 
 if (i == 0){
    gif_checked_length = 1;
    var giftobj_ex_checked = false;
    if (giftobj_ex1.checked) {gif_checked1 += 1;giftobj_ex_checked=true;}
    if (giftobj_ex2.checked) {gif_checked2 += 1;giftobj_ex_checked=true;}
    if (giftobj_ex_checked == true){gif_ex_checked_length +=1;}
  }
  else{gif_checked_length = vlength;}
 
}

//ajax active物件判斷
function js_createXMLHttpRequest(){

    if(window.ActiveXObject){

        var Js_xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    else{
        var Js_xmlHttp = new XMLHttpRequest();
    }

    return Js_xmlHttp;

}

//var ajax_ID, xmlHttp;
function Ajax_XMLHttpRequest(tagID, ty, vsno) {
    
    try{
        var ajax_ID = window.document.getElementById(tagID);
            if (tagID == 'span_ajax_1') {
                ajax_ID.style.height = 194;}
            else if (tagID == 'span_ajax_2') {
                ajax_ID.style.height = 150;}
            else if (tagID == 'span_ajax_3') {ajax_ID.style.height = 100;}

        var strData = "code=65001"
        var xmlHttp = js_createXMLHttpRequest();
            xmlHttp.open('POST','../common/Share_XMLHttpRequest.asp?ty=' + ty + '&sno=' + vsno,false) ;
            xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
            //xmlHttp.onreadystatechange = Ajax_Show();
            xmlHttp.send(strData) ;
            if(xmlHttp.readyState == 4)
            {
                var getStatus = unescape(xmlHttp.responseText) ;
                    ajax_ID.innerHTML = getStatus;
            }else{
                ajax_ID.innerHTML = 'loading....';
            }
	    }
	 catch(exception){}
}


//function Ajax_Show() {
//    if(xmlHttp.readyState == 4)
//    {
//        var getStatus = unescape(xmlHttp.responseText) ;
//            ajax_ID.innerHTML = getStatus;
//    }else{
//        ajax_ID.innerHTML = 'loading....';
//    }
//}