﻿// JScript 檔

function sFile(iunit, ifield) {
    window.open("../include/UploadFile.aspx?unit=" + iunit + "&field=" + ifield, "", ",height=500,width=480,scrollbars=yes");    
}

function vFile(ifile) {
    window.open("../" + ifile, "");    
}

function rFile(ifield) {
    document.getElementById(ifield).value="";
}

function preView(iurl) {
    window.open(iurl, "");    
}

var obj = document.form1;

function clearalls() {
     var formObj = document.forms[0];
     var formEl = formObj.elements;
     for (var i=0; i<formEl.length; i++)
     {         
           var element = formEl[i];
           if (element.type == 'submit') { continue; }
           if (element.type == 'reset') { continue; }
           if (element.type == 'button') { continue; }
           if (element.type == 'hidden') { continue; }          
           if (element.type == 'text') { element.value = ''; }         
           if (element.type == 'textarea') { element.value = ''; }         
//           if (element.type == 'checkbox') { element.checked = false; }         
//           if (element.type == 'radio') { element.checked = false; }         
//           if (element.type == 'select-multiple') { element.selectedIndex = -1; }         
//           if (element.type == 'select-one') { element.selectedIndex = -1; }     
     } 
     return false;
} 

function Disable(field){
    document.getElementById(field).disabled=true;
}

function checkURL(txt)
{
    data = document.getElementById(txt).match(/(http|ftp|https):\/\/.+/);
    if (!data || !txt) return false;
        return true;
}


function textCounter(field, countfield, maxlimit) {
if (document.getElementById(field).value.length > maxlimit)
document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlimit);
else
document.getElementById(countfield).innerHTML = "(尚可輸入 "+ (maxlimit - document.getElementById(field).value.length) + " 個字)";
}


//----檢查checkbox

function checkCB(name, min, max){ 
var groups = document.getElementById(name); 
var hasChecked = 0; 
min = min || 1; 
max = max || groups.length; 
for(var i=max-1;i>=0;i--) 
if(obj.elements[name+'_'+i].checked) hasChecked++; 
return min <= hasChecked && hasChecked <= max; 
}


/**
 * DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    return false
		 }

 		 return true					
	}

    
//----------------------------------------------ajax----------------------------------------------------------------


            function cat2Result() 
            { 
                var cat2=document.getElementById("ddlCat1");
                B1Ajax.GetCat2List(cat2.value,get_cat2_Result_CallBack);
            }
            
            function get_cat2_Result_CallBack(response)
            {
                if (response.value != null)
                {                    
                    //debugger;
                    document.all("ddlCat2").length=0;　　　　            
　　　　            var ds = response.value;
                    if(ds != null && typeof(ds) == "object" && ds.Tables != null)
                    {                    
                        for(var i=0; i<ds.Tables[0].Rows.length; i++)
　　　　                {
　　　　                    var name=ds.Tables[0].Rows[i].B1c2_name;
　　　　　　                var id=ds.Tables[0].Rows[i].B1c2_sn;
　　　　　　                document.all("ddlCat2").options.add(new Option(name,id));
　　　　                }
                    }
                }                
                return
            }
