﻿// JScript 檔
function SelectRow()
{
	var obj = window.event.srcElement;
	if(obj.tagName=="INPUT")    //this is a checkbox
	{
	    checkRowOfObject(obj);
	}
	else if (obj.tagName=="TD") //this a table cell
	{
	    //get a pointer to the tablerow
	    var row = obj.parentNode;
	    var chk = row.cells[0].firstChild;
	    chk.checked = !chk.checked;
	    if (chk.checked)
	    {
	        row.className="SelectedRow";
	    }
	    else
	    {
	       row.className="";
	    }
	}
}
function checkRowOfObject(obj)
{
    if (obj.checked)
    {
        obj.parentNode.parentNode.className="SelectedRow";
    }
    else
    {
       obj.parentNode.parentNode.className="";
    }
}
function SelectAllRows()
{
   var chkAll = window.event.srcElement; 
   var tbl = chkAll.parentNode.parentNode.parentNode.parentNode;
   
   if (chkAll)
   {
        for(var i=1;i<tbl.rows.length;i++)
        {
            var chk = tbl.rows[i].cells[0].firstChild;
            chk.checked=chkAll.checked;
            checkRowOfObject(chk);
        }
   }
}

function ValidControl(ControlID, Message)
{
    if($get(ControlID).value=="")
    {
        alert(Message);
        $get(ControlID).focus();
        return false;
    }else
        return true;
}

//CompareValidator(HTML控制項ID, 比對字串, 和比對字相符所警示訊息)
//Html控制項值的比對(控制項物件ID, 比對的值, 不符合時警告的文字)
function CompareValidator(ValidatControlID, CompareValue, ErrorMessage)
{
    if($get(ValidatControlID).value == CompareValue)
    {
        alert(ErrorMessage);
        $get(ValidatControlID).focus();
        $get(ValidatControlID).className = "InputError";
        return false;
    }
    else{
        $get(ValidatControlID).className = "Input";
        return true;
    }
}
