JForm = {}
JForm.aObjForbidden = {};
JForm.aObjForbidden["__EVENTVALIDATION"] = false;
JForm.aObjForbidden["__VIEWSTATE"] = false;
JForm.aObjForbidden["__EVENTTARGET"] = false;
JForm.aObjForbidden["__EVENTVALIDATION"] = false;
JForm.aObjForbidden["__EVENTARGUMENT"] = false;
JForm.GetArrayByFormObject = function(oFormObject)/* Returns an array */
{
	var oForm = oFormObject;				
	if ( oFormObject.keys != null )
	{
		oForm = new Array();
		for ( var j = 0; j < oFormObject.keys.length; j++ )
		    oForm[j] = new JForm.MyObjectForm(oFormObject.keys[j], oFormObject.values[j]);
	}
	var aR = new Array();
	for ( var i = 0; i < oForm.length; i++ )
		aR[oForm[i].Key] = oForm[i].Value;
	return  aR;
}
JForm.MyObjectForm = function(key, value)
{
	this.Key = key;
	this.Value = value;
	return this;
}
JForm.SetFormByFormObject = function(oFormObject)
{
	var oForm = oFormObject;
	oForm = new Array();
	var j = 0;
	for ( var oItem in oFormObject )
	{
	    oForm[j] = new JForm.MyObjectForm(oItem,oFormObject[oItem]);
	    j++;
	}
	for( var i = 0; i < oForm.length; i++ )
	{
		var aF = oForm[i].Key.split(":");
		var sControlF = aF[0];
		var sAttribute = "";
		if ( aF.length > 1 ) 
			sAttribute = aF[1];
		var oControl = document.getElementById( sControlF );
		if ( !oControl ) /* Control not found*/
		{	
			try
			{
				oControl = document.getElementById(document.forms["form1"][sControlF][0].id );
			}
			catch(e)
			{
				alert( "Control '" + sControlF + "' not found");
				return
			}
			if ( !oControl )
			{
				var s=""; 
				for(var k in oControl) 
					s+=k+", ";
				alert( "Control " + sControlF + " not found: " + oControl + " - type:" + typeof( oControl ) + " - properties:" + s );
				return
			}
		}
		if ( sAttribute != "" ) /* ******* Setting Attributes ******* */
		{
			if ( ( sAttribute == "disabled" ) || ( sAttribute == "checked" ) )
				eval( "oControl." + sAttribute + "=oForm[i].Value" );
			else if ( ( sAttribute.toLowerCase() == "onclick" ) || ( sAttribute.toLowerCase() == "onmouseover" ) || ( sAttribute.toLowerCase() == "onmouseout" ) || ( sAttribute.toLowerCase() == "onkeypress" ) || ( sAttribute.toLowerCase() == "onkeydown" ) )
				eval( "oControl." + sAttribute.toLowerCase() + " = function(){" + oForm[i].Value + "}" );
			else
			{
				if ( typeof( oForm[i].Value ) == "string" )
					eval( "oControl." + sAttribute + "='" + oForm[i].Value.replace(/'/g, "&rsquo;") + "'" );
				else
					eval( "oControl." + sAttribute + "='" + oForm[i].Value + "'" );
			}
		}
		else
		{
			if ( oControl.tagName.toUpperCase() == "INPUT" )
			{
				if ( (oControl.type == "text") || (oControl.type == "hidden") || (oControl.type == "button") || (oControl.type == "password") || (oControl.type == "file") )
					oControl.value = oForm[i].Value;
				else if ( ( oControl.type == "checkbox" ) || ( oControl.type == "radio" ) )
				{
					var aControlsByName = document.getElementsByName( oControl.name );
					for ( var h = 0; h < aControlsByName.length; h++ )
						aControlsByName[ h ].checked = false;
					if ( oForm[i].Value != "" )
					{
						var aIdCheckbox = oForm[i].Value.split( "," );
						for ( var k = 0; k < aIdCheckbox.length; k++ )
						{
							var aCh = aIdCheckbox[k].split( ";" );
							document.getElementById( aCh[0] ).checked = (aCh[1]==0?false:true); 
						}
					}					
				}
			}
			else if ( oControl.tagName.toUpperCase() == "SELECT" )
			{
				if (oControl.type == "select-one")
					for ( var k = 0; k < oControl.length; k++ )
						if ( oControl[k].value == oForm[i].Value )
							oControl.selectedIndex = k;
			}
			else if (( oControl.tagName.toUpperCase() == "SPAN" ) || ( oControl.tagName.toUpperCase() == "DIV" ) || ( oControl.tagName.toUpperCase() == "LABEL" ) || ( oControl.tagName.toUpperCase() == "TD" ) || ( oControl.tagName.toUpperCase() == "TR" ) || ( oControl.tagName.toUpperCase() == "TABLE" ) )
				oControl.innerHTML = oForm[i].Value;
			else if ( oControl.tagName.toUpperCase() == "TEXTAREA" )
				oControl.value = oForm[i].Value;
			else if ( oControl.tagName.toUpperCase() == "IMG" )
				oControl.src = oForm[i].Value;
		}
	}
}
/* ***** POST FORM: CLIENT -----> SERVER ***** */
JForm.GetObjectFormByDiv = function(oDiv)
{
    var o = new Object();
    var bStartFormDeveloper = true;
    var oItem;
    var aControls = new Array("input", "select", "textarea");
    for (var oElem in aControls)
    {
        var aE = oDiv.getElementsByTagName(aControls[oElem]);
        for (var i = 0; i < aE.length; i++)
        {
            oItem = aE[i];
            JForm.GetKeyValueByItem(oItem, o, bStartFormDeveloper);
        }
    }
    return o;
}
JForm.GetKeyValueByItem = function(oItem, oKeyValue, bStartFormDeveloper) /* private */
{
    if ((bStartFormDeveloper) && ((JForm.aObjForbidden[oItem.id] == null) || (JForm.aObjForbidden[oItem.id])))
    {
        if ((oItem.type != "button") && (oItem.id.indexOf("hdHelpFile") == -1) && (oItem.id.indexOf("hdTooltipWidth") == -1) && (oItem.id != "") && (oItem.id != ""))
        {
            if (oItem.type == "radio")
            {
                if (oItem.checked)
                {
                    oKeyValue[oItem.name] = oItem.value;
                    oKeyValue[oItem.name+":id"] = oItem.id;
                }
            }
            else
            {
                if (oItem.type == "checkbox")
                {
                    if (oItem.checked)
                        if (oItem.name)
                        {
                            if (oKeyValue[oItem.name]) oKeyValue[oItem.name]+=","+oItem.value;else oKeyValue[oItem.name]=oItem.value;
                        }
                    oKeyValue[oItem.id] = oItem.checked ? 1 : 0;
                }
                else if (oItem.type == "select-multiple")
                {
                    var sList = "";
                    var sListUnselected = "";
                    for (var hh = 0; hh < oItem.length; hh++)
                    {
                        if (oItem[hh].selected)
                            sList += "," + oItem[hh].value;
                        else
                            sListUnselected += "," + oItem[hh].value;
                    }                    
                    oKeyValue[oItem.id] = sList.substring(1);
                    oKeyValue[oItem.id + "_Unselected"] = sListUnselected.substring(1);
                }
                else if (oItem.type == "select-one")
                {
                    oKeyValue[oItem.id] = oItem.value;
                    if (oItem.length > 0)
                    {
                        if (oItem.selectedIndex != -1)
                            oKeyValue[oItem.id + ":text"] = oItem[oItem.selectedIndex].text;
                        else
                            oKeyValue[oItem.id + ":text"] = "";
                    }
                }
                else
                {
                    oKeyValue[oItem.id] = oItem.value;
                }
            }
        }
    }
}
