function getObject(name) {
  if (document.getElementById) { //firefox
    this.obj = document.getElementById(name);
  } else if (document.all) {  //ie
    this.obj = document.getElementById(name);
//     this.obj = document.all[name];
  } else if (document.layers) { //
     this.obj = document.layers[name];
  }
  return this.obj;
}
function getOptObject(name)
{
    obj = document.getElementsByName(name);
    return obj;
}
function checkvarempty(name,cname)
{
	pid = getObject(name);
	if (!pid)
	{
		window.alert(cname+' 元件未發現');
		return false;
	}
	if(pid.value==null || pid.value=="")
	{
		window.alert(cname+ ' 輸入欄位為空白');//+pid.value.length
		pid.focus();
		return false;
	}
	return true;
}
function checkoptvarempty(name,cname)
{
	pid = getOptObject(name);
	if (!pid)
	{
		window.alert(cname+' 元件未發現');
		return false;
	}
    len = pid.length;
//    window.alert("len:"+len);
//    window.alert("type:"+pid[0].type+",checked:"+pid[0].checked+",disabled:"+pid[0].disabled+",value:"+pid[0].value);
	ret = false;
    for (i=0;i<len; ++i)
    {
    	if (pid[i].type=="radio" && pid[i].checked==true)
    		ret = true;
    	else if (pid[i].type=="select-one" && pid[i].value!="0")
    		ret = true;
    }
    if (ret == false)
    {
 		window.alert(cname+ ' 輸入欄位為空白');
		pid.focus();
		return false;   	
    }
	return ret;
}
function checkvarlen(name,cname,len)
{
	pid = getObject(name);
	if (pid.value.length < len)
	{
		window.alert(cname+' 輸入欄位長度不足 '+len);//+pid.value.length
		pid.focus();
		return false;
	}
	return true;
}
function getvarvalue(name)
{
	p = getObject(name);
  	if (p.type=="radio")
  	{
  		p=getOptObject(name);
	  	len = p.length;
	    for (i=0;i<len; ++i)
	    {
	    	if (p[i].checked==true)
	    		return p[i].value;
	    }	  		
  	}
  	else
  	{
		return p.value;  		
  	}
}
function openpopwindow(url,w,h,param)
{
	var load = "";
	p = param;
	if (p.length > 0)
	{
		load = window.open(url+param,'','scrollbars=no,menubar=no,height='+w+',width='+h+',resizable=no,toolbar=no,location=no,status=no');
	}
	else
	{
		load = window.open(url,'','scrollbars=no,menubar=no,height='+w+',width='+h+',resizable=no,toolbar=no,location=no,status=no');
	}
	if(load == null){
		alert("此功能需使用彈出視窗！");
		return false;
	}
	return true;
}
function checkinput(name, cname, len)
{
    ret = checkvarempty(name, cname);
    if (ret == false)
            return false;
    ret = checkvarlen(name, cname, len);
    if (ret == false)
            return false;
    return true;	
}
function checkoptinput(name, cname)
{
    ret = checkoptvarempty(name, cname);
    if (ret == false)
            return false;
    return true;	
}
function showmsg(msg)
{
	alert(msg);	
}
function checkvarisequal(nam1, nam2)
{
	p1 = getvarvalue(nam1);
	p2 = getvarvalue(nam2);
	if (p1 == p2)
		return true;
	return false;
}
function gosubmit(fname)
{
   var form = document.getElementById(fname);
     form.submit();
}
function gourl(url, para1)
{
	value = getvarvalue(para1);
	strurl = new String(url);
	if (strurl.indexOf("?", 0) > 0)
		location.href = url+"&para1="+value;
	else
		location.href = url+"?para1="+value;
}
function gourl2(url, para1, para2)
{
	value = getvarvalue(para1);
	value2 = getvarvalue(para2);
	strurl = new String(url);
	if (strurl.indexOf("?", 0) > 0)
		window.location.href = url+"&para1="+value+"&para2="+value2;
	else
		window.location.href = url+"?para1="+value+"&para2="+value2;
}
function isNumeric(strNumber) 
{  
	var newPar=/^(-|\+)?\d+(\.\d+)?$/;
	return newPar.test(strNumber); 
}
function gourl3(url, para1, para2, para3)
{
	value = getvarvalue(para1);
	if (isNumeric(para2))
		value2 = para2;
	else 
		value2 = getvarvalue(para2);
	if (isNumeric(para3))
		v3 = para3;
	else 
		v3 = getvarvalue(para3);
	strurl = new String(url);
	if (strurl.indexOf("?", 0) > 0)
		window.location.href = url+"&para1="+value+"&para2="+value2+"&para3="+v3;
	else
		window.location.href = url+"?para1="+value+"&para2="+value2+"&para3="+v3;
}
function optfillinput(src, dest)
{
	pid = getOptObject(src);
	if (!pid)
	{
		window.alert(src+' 元件未發現');
		return false;
	}
	pid2 = getObject(dest);
	if (!pid2)
	{
		window.alert(dest+' 元件未發現');
		return false;
	}
	if (pid[0].value <= 0)
		return false;
	space=["",
"台北市",
"基隆市",
"台北縣",
"宜蘭縣",
"桃園縣",
"新竹市",
"新竹縣",
"苗栗縣",
"台中市",
"台中縣",
"彰化縣",
"南投縣",
"嘉義市",
"嘉義縣",
"雲林縣",
"台南市",
"台南縣",
"高雄市",
"高雄縣",
"屏東縣",
"花蓮縣",
"台東縣",
"澎湖縣",
"金門縣",
"連江縣",
"南海諸島",
"大陸地區",
"港澳地區",
"歐洲",
"北美洲",
"中南美洲",
"亞洲及大洋洲",
"非洲地區"
];
//	pid2.value = space[pid[0].value];
	v = space[pid[0].value];
	s = pid2.value;
	if (s.indexOf(v)==-1)
		pid2.value = v+s;	
}
function cybsearchset(val)
{
	if (val!="4")
		document.getElementById("opt4").style.display = 'none';
	else
		document.getElementById("opt4").style.display = 'inherit';
}