function checkAll(prefix, formName)
{
    _setStateCheckboxes(prefix, formName, 1)
}
    
function uncheckAll(prefix, formName)
{
    _setStateCheckboxes(prefix, formName, 0)
}
        
function _setStateCheckboxes(prefix, formName, on)
{
    eval('var f = document.forms.' + formName)
    controls = f.elements
    l = prefix.length
    s = controls.length
    for (i = 0; i < s; i++)
        if (controls[i].name.substr(0, l) == prefix)
            controls[i].checked = on ? true : false
}

/*
	Set 'checked' status of radio/checkbox in a form by specify value
	radio: single value; checkbox: one or multiple values string separated by '&"
*/
function setCheckedByVal( el, value ) {
    if (!el || (typeof el == 'string')) return;
    el=el.length?el:[el];
    if(el[0].type == 'radio') {
            for(var i=0; i<el.length; i++)
                if(el[i].checked = (el[i].value == value)) break;
    }
    else if(el[0].type == 'checkbox') {
        var myvalues =value.split('&');
        for(var i=0; i<el.length; i++){
            var j=0;
            for(; j<myvalues.length; j++)
                if(el[i].value==myvalues[j]) break;
            el[i].checked = (j < myvalues.length);
        }
    }
}

/*
	Set 'selected' status of select options in a from by specify value
	Now it has not supported multiple selection
*/
function setSelectedByVal( el, val ) {
	if(!el || (el.type != 'select-one')) return;
	for(var i=0;i<el.length;i++) {
		if(el.options[i].value == val ) {
			el.options[i].selected = true;
			break;
		}
	}

}

// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getRadioVal(radioObj) {
    if(!radioObj)
        return "";
    var radioLength = radioObj.length;
    if(radioLength == undefined)
        if(radioObj.checked)
            return radioObj.value;
        else
            return "";
    for(var i = 0; i < radioLength; i++) {
        if(radioObj[i].checked) {
            return radioObj[i].value;
        }
    }
    return "";
}

	
/*
	Let the user confirm before execute the link
*/	
function confirmLink(theLink, theMessage) {
    if (theMessage == undefined) { theMessage = ZORPIA_JS_LANG.SURE_DO_THAT; }
    var is_confirmed = confirm(theMessage);
    if (is_confirmed) {
        var link_href = theLink.href;
        if (link_href.match(/\?/)) {
            link_href += '&is_js_confirmed=1';
        } else {
            link_href += '?is_js_confirmed=1';
        }
        theLink.href = link_href;
    }
    return is_confirmed;
}

// Web Site:  http://dynamicdrive.com
function disableForm(theform) {
    if (document.all || document.getElementById) {
        for (i = 0; i < theform.length; i++) {
            var tempobj = theform.elements[i];
            if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() == "reset" || tempobj.type.toLowerCase() == "image") {
                tempobj.disabled = true;
            }
        }
    }
    return true;
}

// derived from official firefox
function break_long_text_in_firefox() {
    if( (navigator.appName.indexOf('Netscape') == -1) &&
        (navigator.userAgent.indexOf('Firefox') == -1) ) return;

    var D=document; F(document.body); function F(n){var u,r,c,x; if(n.nodeType==3){ u=n.data.search(/\S{10}/); if(u>=0) { r=n.splitText(u+10); n.parentNode.insertBefore(D.createElement("WBR"),r); } }else if(n.tagName!="STYLE" && n.tagName!="SCRIPT"){for (c=0;x=n.childNodes[c];++c){F(x);}} }
}
