var id_ar = new Array();

/**
 * change a element's backgroundCcolor
 *
 * @param chkID chkID is a unique id.
 * @param color color is backgroundColor.
 * @return void
 */
function chebg(chkID,color){
	Myid = document.getElementById(chkID);
	if(Myid.checked == true){
		var elem = {};
		elem.id = chkID;
		elem.color = color;
		id_ar.push(elem);
		Myid.parentNode.style.backgroundColor = '#d3ddc0';
	}
	else{
		for(var i = 0; i < id_ar.length; i++) {
			if(id_ar[i].id == chkID) {
				id_ar.splice(i, 1);
				break;
			}	
		}
		Myid.parentNode.style.backgroundColor = color;
	}
}


/**
 * change all elements' backgroundColor
 *
 * @return void 
 */
function allChange(){
	
	for(var i = 0; i < id_ar.length; i++){
		//set backgroundcolor
		document.getElementById(id_ar[i].id).parentNode.style.backgroundColor = id_ar[i].color;
	}
	
	//recreate id_ar
	id_ar = new Array();

    for (var i=0; i<document.forms.length; ++i) {
        clearForm(document.forms[i]);
    }
}

function clearForm(form) {
    for(var i=0; i<form.elements.length; ++i) {
        clearElement(form.elements[i]);
    }
}
function clearElement(element) {
    switch(element.type) {
        case "hidden":
        case "submit":
        case "reset":
        case "button":
        case "image":
            return;
        case "file":
            return;
        case "text":
        case "password":
        case "textarea":
            element.value = "";
            return;
        case "checkbox":
        case "radio":
            element.checked = false;
            return;
        case "select-one":
        case "select-multiple":
            element.selectedIndex = 0;
            return;
        default:
    }
}

