var xmlHttp
function ajax()
{//{{{
	 try{xmlHttp=new XMLHttpRequest();}catch(e){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");	}catch(e2)
	 {try	{xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}catch(e3){try{xmlHttp=new ActiveXObject("Msxml2.XMLHTTP.4.0");}
	 catch(e4){xmlHttp=null;alert("xmlHttp init Error!");}}}}
}//}}}
ajax.prototype.getAjax = function(url , callBack , data)
{//{{{
	xmlHttp.onreadystatechange = callBack;
	xmlHttp.open("POST" , url);
	xmlHttp.setRequestHeader("content-length",data.length);
	xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlHttp.send(data);
}//}}}
ajax.prototype.get = function (sId)
{//{{{
    if(!sId)
    {
        return null;
    }
    var returnObj = document.getElementById(sId);
    if(!returnObj && document.all)
    {
        returnObj = document.all[sId];
    }
    return returnObj;
}//}}}
ajax.prototype.getFormValues = function(frm)
{//{{{
    var objFrm;
    if(typeof(frm) == "string")
        objForm = this.get(frm);
    else
        objForm = frm;
    var sXml = "";
    if(objForm&&objForm.tagName == 'FORM')
    {
        
        var formElements = objForm.elements;
        for(var i = 0; i < formElements.length; i ++)
        {
            if(!formElements[i].name)
            continue;
            if(formElements[i].type && (formElements[i].type=='radio' || formElements[i].type == 'checkbox') && formElements[i].checked == false)
            continue;
            if(formElements[i].disabled && formElements[i].disabled == true)
            continue;
            var name = formElements[i].name;
            if(name)
            {
                if(formElements[i].type == 'select-multiple')
                {
                    for(var j = 0; j < formElements[i].length; j ++)
                    {
                        if(formElements[i].options[j].selected == true)
                        sXml += "&" + name + "=" + encodeURIComponent(formElements[i].options[j].value);
                    }
                }
                else
                {
                    sXml += "&" + name + "=" + encodeURIComponent(formElements[i].value);
                }
            }
        }
    }
    return sXml;
}//}}}

function reloadRes()
{//{{{
	if (4 == xmlHttp.readyState)
	{
		resText = xmlHttp.responseText;
		if ("" == resText)
		{
			window.location.reload();
			return true;
		}
		else
		{
			alert(resText);
		}
	}
}//}}}

function ajaxRes()
{//{{{
    if (4 == xmlHttp.readyState)
    {
        resText = xmlHttp.responseText;
        try
        {
            var resObj = eval('(' + resText + ')');
        }
        catch(e)
        {
            alert(resText);
            return true;
        }
        if ("reload" == resObj.action)
        {
            window.location.reload();
            return true;
        }
        else if ("location" == resObj.action)
        {
            window.location.href = resObj.data;
            return true;
        }
        else if ("input" == resObj.action)
        {
            for (var i=0; i < resObj.data.length; i++)
            {
                document.getElementById(resObj.data[i].id).value = resObj.data[i].value;
            }
            return true;
        }

    }
}//}}}

