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);
	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();
}

