var agt = navigator.userAgent.toLowerCase();
var is_netscape = document.layers;
var is_ie = (agt.indexOf("msie") != -1);
var is_konqueror = (agt.indexOf("konqueror") != -1);
var is_netscape7 = (agt.indexOf("netscape") != -1);
var is_mozilla = (agt.indexOf("mozilla") != -1 && agt.indexOf("gecko") != -1);
var is_opera = (agt.indexOf("opera") != -1);

var is_smart = (is_ie || is_mozilla || is_netscape7 || is_konqueror) && !is_opera;

function copy(oSource, oDest, bClearSource, bIgnoreDest) {
	// copy from text to text
	if(oSource.type.substring(0,4) == 'text' && oDest.type.substring(0,4) == 'text') {
		if(!bIgnoreDest)
			oDest.value = oSource.value;
		if(bClearSource == true)
			oSource.value = "";
	}

	// copy from text to select
	if( oSource.type.substring(0,4) == 'text' && oDest.type.substring(0,6) == 'select') {
		if(!bIgnoreDest) {
	        iDestLen = oDest.length;
	        oDest.options[iDestLen] = new Option(oSource.value, oSource.value);
		}
		if(bClearSource == true)
			oSource.value = "";
	}

	//copy from select to select
	if(oSource.type.substring(0,6) == 'select' && oDest.type.substring(0,6) == 'select') {
		iSourceLen = oSource.length;
		if(!bIgnoreDest) {
	        for(i=0;i<iSourceLen;i++) {
	            if(oSource.options[i].selected == true) {
	                iDestLen = oDest.length;
	                oDest.options[iDestLen] = new Option(oSource.options[i].text, oSource.options[i].value);
	            }
	        }
	    }
	    if(bClearSource) {
	        for(i=(iSourceLen - 1);i>=0;i--) {
	            if(oSource.options[i].selected == true) {
	                oSource.options[i] = null;
	            }
	        }
	    }
    }

	//copy from select to text
	if(oSource.type.substring(0,6) == 'select' && oDest.type.substring(0,4) == 'text') {
		iSourceLen = oSource.length;
		if(!bIgnoreDest) {
	        for(i=0;i<iSourceLen;i++) {
	            if(oSource.options[i].selected == true) {
	            	oDest.value = oSource.options[i].value==""?oSource.options[i].text:oSource.options[i].value;
	            }
	        }
	    }
	    if(bClearSource) {
	        for(i=(iSourceLen - 1);i>=0;i--) {
	            if(oSource.options[i].selected == true) {
	                oSource.options[i] = null;
	            }
	        }
	    }
    }

}


function up(selObj) {
    if(selObj.selectedIndex>0) {
        var x = selObj.selectedIndex;
        var tmp = selObj.options[selObj.selectedIndex].text;
        selObj.options[selObj.selectedIndex].text = selObj.options[selObj.selectedIndex-1].text;
        selObj.options[selObj.selectedIndex-1].text = tmp;
        var tmp = selObj.options[selObj.selectedIndex].value;
        selObj.options[selObj.selectedIndex].value = selObj.options[selObj.selectedIndex-1].value;
        selObj.options[selObj.selectedIndex-1].value = tmp;
        selObj.selectedIndex = x - 1;
    }
}


function down(selObj) {
    if(selObj.selectedIndex < selObj.length-1 && selObj.selectedIndex > -1) {
        var x = selObj.selectedIndex;
        var tmp = selObj.options[selObj.selectedIndex].text;
        selObj.options[selObj.selectedIndex].text = selObj.options[selObj.selectedIndex+1].text;
        selObj.options[selObj.selectedIndex+1].text = tmp;
        var tmp = selObj.options[selObj.selectedIndex].value;
        selObj.options[selObj.selectedIndex].value = selObj.options[selObj.selectedIndex+1].value;
        selObj.options[selObj.selectedIndex+1].value = tmp;
        selObj.selectedIndex = x + 1;
    }
}


function selectAll(oSelect) {
	var i;
	for(i=0;i<oSelect.length;i++)
		oSelect.options[i].selected = true;
}


function doActOnAll(frmObject, triggerObj) {
    with(frmObject) {
        for(i=0;i<elements.length;i++) {
            if(elements[i].name && elements[i].name.substr(0, 7) == 'chkDel_') {
                elements[i].checked = triggerObj.checked;
                if(is_smart) {
                    var objRow = elements[i].parentNode.parentNode;
                    for(j=0;j<objRow.childNodes.length;j++)
                        if(objRow.childNodes[j].tagName == 'TD')
                        	objRow.childNodes[j].className = elements[i].checked?"listsel":"list";
                }
            }
        }
    }
}


function highlightRow(obj) {
    if(is_smart) {
        var objRow = obj.parentNode.parentNode;
        for(i=0;i<objRow.childNodes.length;i++)
            if(objRow.childNodes[i].tagName == 'TD')
                objRow.childNodes[i].className = obj.checked?"listsel":"list";
    }
}

function selectByValue(obj, value) {
    for(j=0;j<obj.length;j++)
        if(obj.options[j].value == value)
            obj.options[j].selected = true;
    return true;
}

function selectByText(obj, value) {
    for(j=0;j<obj.length;j++)
        if(obj.options[j].text == value)
            obj.options[j].selected = true;
    return true;
}

function trim(sValue) {
	return sValue.replace(/(\s)*/g, "");
}

function checkRadio(poRadioGroup) {
	var bChecked = false;
	for(i=0;i<poRadioGroup.length;i++) {
		bChecked = bChecked || poRadioGroup[i].checked;
	}
	return bChecked;
}
