function js_in_array(the_needle, the_haystack)
{
	var the_hay = the_haystack.toString();
	if(the_hay == ''){
		return false;
	}
	var the_pattern = new RegExp(the_needle, 'g');
	var matched = the_pattern.test(the_haystack);
	return matched;
}

function CheckForms(sClassNameChanged,sClassNameNormal,sClassNameFulfilled)
{
	var iFormCount = document.forms.length;
	aFirstValues = new Array; // tablica do przechowywania pierwotnych wartosci elementow
	iChangesCounter = 0; // liczba zmian
	aChangedElements = new Array;
	var exclude = Array ('button', 'submit');
	
	for (i=0; i<iFormCount; i++) {
		for (z=0; z<document.forms[i].elements.length; z++) {
			if ( !js_in_array(document.forms[i].elements[z].type, exclude)){
				sElementId = document.forms[i].elements[z].id;
				aFirstValues[sElementId] = document.forms[i].elements[z].value;
				document.forms[i].elements[z].onchange = function (){CheckElement(this.uniqueID, this.value, this,sClassNameChanged,sClassNameNormal,sClassNameFulfilled,'change'); }
	    		document.forms[i].elements[z].onfocus = function (){CheckElement(this.uniqueID, this.value, this, sClassNameChanged,sClassNameNormal,sClassNameFulfilled,'focus'); }
			}
		}
	}
}

function CheckElement(sId, sValue, oObject, sClassNameChanged,sClassNameNormal,sClassNameFulfilled,condition)
{
	if (!oObject.type) {
		return true;
	}
	//alert(aFirstValues[sId] + " <> " + oObject.type + " < porownuje > " + sValue);
	
	switch(condition) {
	    case 'focus':
	    	if (sValue) {
	            //alert(sClassNameChanged+condition);
	            oObject.className = sClassNameFulfilled;
	    	}
	     	break;
	    case 'change':
	    	if (aFirstValues[sId]!= sValue) {
	            //alert(sClassNameChanged+condition);
	            oObject.className = sClassNameChanged;
	    	} else {
	    		//alert(sClassNameFulfilled);
	            oObject.className = sClassNameFulfilled;
	    	}
	     	break;
    }
}
