//--------------------------------------------------------------------
//佛山软件产业集团有限公司
//功能    : 表格或页面中创建HTML页面输入元素及事件控制
//作者    : 杨文捷
//版本    : 1.0
//修改日期: 2000-11-24
//------------------------------------------------------------------

var bsBlur = "0 solid";
var bsFocus = "2 inset";
var iTables = 0;
var iCount;
var iRow,iCol


function Element_onblur() {
    window.event.srcElement.style.border = bsBlur;
}

function Element_onfocus() {
    var sID;
    
    window.event.srcElement.style.border = bsFocus;
    sID = window.event.srcElement.id;    
    iRow = parseInt(sID.substring(8,sID.length));             
    //sID = sID.substring(7,sID.length);             
    iCol = sID.substring(0,8);                 
}

function Element_onkeypress(){
    var sID;
    var i;        
    var Ele;
    //alert("DF");
    if(window.event.keyCode==13){
        sID = window.event.srcElement.id;
        //alert(sID);        
        i = sID.substring(8,sID.length);             
        if(i== iCount - 1){
            i= -1;        
        }        
        //alert(iCount);
        Ele = document.all[sID.substring(0,8) + (parseInt(i) + 1)];
        Ele.focus();
        Ele.select();
    }
}


//创建文本元素
function CreateTextEle(sID,sName,sValue,iSize,iMaxLength,bDisabled,bReadOnly,bHasEvents,sStyle,sOther){
    var sTemp;
    
    sTemp = "<INPUT TYPE=TEXT ID=txt_Col" + sID + " NAME=txt_Col" + sName + " VALUE='" + sValue + 
        "' SIZE=" + iSize + " MAXLENGTH=" + iMaxLength + " ";
    if(bDisabled){
        sTemp = sTemp + "Disabled ";
    }
    
    if(bReadOnly){
        sTemp = sTemp + "ReadOnly ";
    }
   
    if(bHasEvents){
        sTemp = sTemp + " onblur = 'return Element_onblur();' onfocus='return Element_onfocus();' onkeypress='return Element_onkeypress();'";
    }
    
    if(sStyle!=""){
        sTemp = sTemp + sStyle + " ";
    }
    else{
        sTemp = sTemp + " style='border:" + bsBlur +  "' ";
    }
    
    sTemp = sTemp + " " + sOther + " " ;
    
    sTemp = sTemp + ">";
    
    //alert(sTemp);
    return sTemp;
    
}

//创建文本元素
function CreateTextEleEX(sID,sName,sValue,iSize,iMaxLength,bDisabled,bReadOnly,bHasEvents,sStyle,sOther){
    var sTemp;
    
    sTemp = "<INPUT TYPE=TEXT ID=txt_Col" + sID + " NAME=txt_Col" + sName + " VALUE='" + sValue + 
        "' SIZE=" + iSize + " MAXLENGTH=" + iMaxLength + " ";
    if(bDisabled){
        sTemp = sTemp + "Disabled ";
    }
    
    if(bReadOnly){
        sTemp = sTemp + "ReadOnly ";
    }
   
    if(bHasEvents){
        sTemp = sTemp + " onblur = 'return Element_onblur();' onfocus='return Element_onfocus();'";
    }
    
    if(sStyle!=""){
        sTemp = sTemp + sStyle + " ";
    }
    else{
        sTemp = sTemp + " style='border:" + bsBlur +  "' ";
    }
    
    sTemp = sTemp + " " + sOther + " " ;
    
    sTemp = sTemp + ">";
    
    return sTemp;
    
}

//创建SELECT元素
function CreateSelectEle(sID,sName,Options,Values,sValue,bDisabled,bHasEvents,sEvents,sOther){
    var i;
    var sTemp;
    
    sTemp = "<SELECT ID=sel_Col" + sID + " NAME=sel_Col" + sName + " ";
    if(bDisabled){
        sTemp = sTemp + " Disabled ";
    }
    sTemp = sTemp + " " + sOther + " " ;
    if(bHasEvents){
        sTemp = sTemp + " onfocus='return Element_onfocus();' " 
    }
    sTemp = sTemp + sEvents + ">";
    for(i=0;i < Options.length;i++){
        if(Values[i]==sValue){
            sTemp = sTemp + "<OPTION VALUE='" + Values[i] + "' SELECTED>";
        }
        else{
            sTemp = sTemp + "<OPTION VALUE='" + Values[i] + "'>";
        }
        sTemp = sTemp + Options[i] + "</OPTION>";
    }    
    sTemp = sTemp + "</SELECT>";    
    return sTemp;   
}

//创建检查框元素
function CreateCheckBoxEle(sID,sName,bChecked,bDisabled,sOther){
    var sTemp;
        
    sTemp = "<INPUT TYPE=CHECKBOX ID=chk_" + sID + " NAME=chk_" + sName + " " ;
    if(bChecked){
        sTemp = sTemp + " CHECKED ";
    }
    
    if(bDisabled){
        sTemp = sTemp + " DISABLED ";
    }
        
    sTemp = sTemp + sOther + " >" ;
    
    return sTemp;       
}

function DropDownOnclick(AsName)
{   
	 document.all('div_sel' + AsName).style.display = 'block';
	 document.all('sel_Col_txt' + AsName).focus();
}
function SelOnSelect(AsName)
{
	document.all('div_sel' + AsName).style.display = 'none';
}
function SelectOnchange(AsName)
{
	document.all('txt_' + AsName).value = document.all('sel_Col_txt' + AsName).value;
}

//创建一个既可以输入又可以选择的元素
//作者：梁健荣
//参数说明：AsName是这个元素的名称，Options是选择项，Values是选择项的值，sValue是显示的值，iWidth是元素的长度。
function CreateSelectAndTextEle(AsName, Options, Values, sValue, iWidth)
{   var sTemp;
	sTemp = "<div id = div_txt" + AsName + " name = div_txt" + AsName + " ><nobr><input type = text style = width:" + (iWidth - 16) + "  name = txt_" + AsName + " id = txt_" + AsName + " value = '" + sValue + "'>";
	sTemp = sTemp + "<img align = absmiddle src = 'Images/Dropdown.gif' class = coolButton onclick = DropDownOnclick(" + AsName + ");></nobr></div>";
	sTemp = sTemp + "<DIV ID= 'div_sel" + AsName + "' Name=div_sel'" + AsName + "' STYLE='POSITION: absolute; Z-INDEX:20; display:none;'>";
	sTemp = sTemp + CreateSelectEle("_txt" + AsName, "_txt" + AsName, Options, Values, sValue, false, false, "", " style = 'width: " + iWidth + ";' onclick = SelOnSelect('" + AsName + "')  onchange = SelectOnchange('" + AsName + "'); onblur = SelOnSelect('" + AsName + "'); size = 9 border = 0") + "</div>";
	return sTemp;
}

function CreateHiddenEle(sID,sName,sValue){
    return "<INPUT TYPE=HIDDEN ID=hid_" + sID + " NAME=hid_" + sName + " VALUE='" + sValue + "'>"
}

