var _objArr = {
	len : function(arr){
		var result = 0;
		if(typeof(arr) != "undefined"){ if(typeof(arr) == "object"){ for(var e in arr){ result++; } } }
		return result;
	},
	hasKey : function(key,arr){
		var result=false;
		if(this.len(arr)>0){for(var e in arr){if(e==key){result=true;break;}}}
		return result;
	},
	hasValue : function(value,arr){
		var result=false;
		if(this.len(arr)>0){for(var e in arr){if(arr[e]==value){result=true;break;}}}
		return result;
	},
	keyPos : function(key,arr){
		result = null;
		if(this.len(arr)>0){var c=0;for(var e in arr){if(e==key){result=c;break;}c++;}}
		return result;
	}
}
function setNewLocation(url){ self.location.href = url; }
function setNewWindow(url){ window.open(url); }
function setOpacity(objId,val){
	if(typeof(document.getElementById(objId))=="object"){
		var _o =document.getElementById(objId).style;
	    _o.opacity = val / 10;
	    _o.MozOpacity = val / 10;
	    _o.KhtmlOpacity = (val / 10);
	    _o.filter = "alpha(opacity=" + (val*10) + ")";
	}
}
function setDisplay(objId,show){
	if(typeof(document.getElementById(objId))== "object"){
		document.getElementById(objId).style.display = (show) ? "block" : "none";
	}
}
function setBgc(objId,color){
	if(typeof(document.getElementById(objId))== "object"){
		document.getElementById(objId).style.background = "#"+color;
	}
}
function setStyle(objId,attr,val){
	if(typeof(document.getElementById(objId))== "object"){
		document.getElementById(objId).style[attr] = val;
	}
}
// FORM FUNCTION
function set_formCache(){
	if( document.forms.length > 0){
		formCache = new Array();
		if(document.forms.length == 1){
			formCache[0] = {elements:new Array()};
			for( var f=0;f < document.forms[0].elements.length;f++){
				if(typeof(document.forms[0].elements[f].name) != "undefined" && typeof(document.forms[0].elements[f].type) != "undefined"){
					formCache[0].elements[f] = {name:document.forms[0].elements[f].name,type:document.forms[0].elements[f].type,value:document.forms[0].elements[f].value};
					if(document.forms[0].elements[f].type.match(/select/i)){
						formCache[0].elements[f].selectedIndex  = document.forms[0].elements[f].selectedIndex;
					}
				}
			}
		}else if(document.forms.length > 1){
			for(var i=0;i<document.forms.length;i++){
				formCache[document.forms[i].name] = {elements:new Array()};
				for( var f=0;f < document.forms[i].elements.length;f++){
					if(typeof(document.forms[i].elements[f].name) != "undefined" && typeof(document.forms[i].elements[f].type) != "undefined"){
						formCache[document.forms[i].name].elements[f] = {name:document.forms[i].elements[f].name,type:document.forms[i].elements[f].type,value:document.forms[i].elements[f].value};
						if(document.forms[i].elements[f].type.match(/select/i)){
							formCache[document.forms[i].name].elements[f].selectedIndex  = document.forms[i].elements[f].selectedIndex;
						}
					}
				}
			}
		}
	}
} 
var _actFormName = "";
function set_formColSelected(formid,eId){
	_actFormName = formid;
	if(typeof(document.forms[_actFormName][eId].name) != "undefined" && typeof(document.forms[_actFormName][eId].type) != "undefined"){
		if(document.forms[_actFormName][eId].type != "checkbox"){
			var colId = eId.split("_");
			if(set_formElmIsActiv(colId[1],0)){
				set_checkBoxStatus(colId[1],true);
			}
		}
	}
}
function set_checkBoxActiv(formid,eId){
	_actFormName = formid;
	if(set_formElmIsActiv(eId,1)){
		if( ! _formElmIsActiv["col_"+eId].isActiv){ formReset(eId); }
	}
}
function set_formElmIsActiv(eId,_option){
	var objChanged = 0;
	if(typeof(_formElmIsActiv) == "undefined"){
		_formElmIsActiv = new Array();
		_formElmIsActiv["col_"+eId] ={isActiv:true};
		objChanged = "col_"+eId;
	}else{
		if(typeof(_formElmIsActiv["col_"+eId]) == "undefined"){
			_formElmIsActiv["col_"+eId] ={isActiv:true};
			objChanged = "col_"+eId;
		}else{
			if(_option == 0 && ! _formElmIsActiv["col_"+eId].isActiv || _option == 1){
				_formElmIsActiv["col_"+eId].isActiv = (_formElmIsActiv["col_"+eId].isActiv) ? false : true;
				objChanged = "col_"+eId;
			}
		}
	}
	if(objChanged != 0){
		document.getElementById(objChanged).style.background = (  _formElmIsActiv[objChanged].isActiv) ? "#ffcc66" : "#e5e5e5";
	}
	return (objChanged != 0) ? true : false; 
}
function set_checkBoxStatus(eId,status){
	for( var f=0;f < document.forms[_actFormName].elements.length;f++){
		if(typeof(document.forms[_actFormName].elements[f].name) != "undefined" && typeof(document.forms[_actFormName].elements[f].type) != "undefined"){
			if(document.forms[_actFormName].elements[f].type == "checkbox" && document.forms[_actFormName].elements[f].value == eId){
				if(status){document.forms[_actFormName].elements[f].checked = "checked";}
				else{document.forms[_actFormName].elements[f].checked = "";}
				break;
			}
		}
	}
}
function formReset(eId){ 
	var val= "";
	if(_objArr.len(document.forms[_actFormName].elements) > 0 ){
		for(var f=0;f < document.forms[_actFormName].elements.length;f++){
			val= "";
			if(typeof(document.forms[_actFormName].elements[f].name) != "undefined" && typeof(document.forms[_actFormName].elements[f].type) != "undefined"){
				if(document.forms[_actFormName].elements[f].type == "text" || document.forms[_actFormName].elements[f].type.match(/select/i)){
					var colId = document.forms[_actFormName].elements[f].name.split("_");
					if(eId != "" && eId == colId[1]){ 
						if(document.forms[_actFormName].elements[f].type == "text"){
							if(typeof(formCache[_actFormName]) != "undefined"){
								if(typeof(formCache[_actFormName].elements[f]) != "undefined"){
									if(formCache[_actFormName].elements[f].name == document.forms[_actFormName].elements[f].name){
										val= formCache[_actFormName].elements[f].value;
									}
								}
							}
							document.forms[_actFormName].elements[f].value = val;
						}else{
							if(typeof(formCache[_actFormName]) != "undefined"){
								if(typeof(formCache[_actFormName].elements[f]) != "undefined"){
									if(formCache[_actFormName].elements[f].name == document.forms[_actFormName].elements[f].name){
										val= formCache[_actFormName].elements[f].selectedIndex;
									}
								}
							}
							document.forms[_actFormName].elements[f].selectedIndex = val;
						}
					}
				}
			}
		}	
	}
}
function set_formResetAll(formid){
	if(_objArr.len(_formElmIsActiv) > 0 ){
		var arrEid = get_activCols();
		if(_objArr.len(arrEid) > 0 ){
			for( var i in arrEid){
				set_checkBoxActiv(formid,(arrEid[i]*1));
				set_checkBoxStatus((arrEid[i]*1),false)
			}
		}
	}
}
function get_activCols(){
	result = new Array();
	var nrid = new Array();
	if(_objArr.len(_formElmIsActiv) > 0 ){
		for( var i in _formElmIsActiv){
			if(_formElmIsActiv[i].isActiv){
				nrid = i.split("_");
				result.push(nrid[1]);
			}
		}
	}
	return result;
}
function showLine(objId,show){
	if(typeof(document.getElementById(objId))=="object"){
		var bgc = "#f5f5f5";
		if(show){
			bgc = "#B4F3AA";
		}else{
			if( typeof(_formElmIsActiv) != "undefined"){
				if( typeof(_formElmIsActiv[objId]) != "undefined"){
					if(_formElmIsActiv[objId].isActiv){ bgc = "#ffcc66"; }
				}
			}
		}
		document.getElementById(objId).style.background = bgc;
	}
}
function set_FormSubmitById(formId){
	if(typeof(document.forms[formId]) != "undefined"){ document.forms[formId].submit();}
}
