
function GetXmlHttp( method, url )
{
	if(!method || !url)
	{
		alert("URL:" + url + "; Method:" + method);
		return;
	}
	
	method = method.toUpperCase();
	
	if( method != "POST" && method != "GET" )
	{
		alert(method + "?");
		return;
	}
	
	var xmlHttp = null;
	
	if(window.ActiveXObject)
	{   
		var version = ["Msxml2.XMLHTTP.6.0",
		               "Msxml2.XMLHTTP.5.0",
		               "Msxml2.XMLHTTP.4.0",
		               "Msxml2.XMLHTTP.3.0",
		               "Msxml2.XMLHTTP",
		               "Microsoft.XMLHTTP"];
		
		for( var i=0; i<version.length; i++ )
		{
			try
			{
				xmlHttp = new ActiveXObject( version[i] );
				break;
			}
			catch(e)
			{
			}
		}
	}
	else if(window.XMLHttpRequest)
	{
		try
		{
			xmlHttp = new XMLHttpRequest();
		}
		catch(e)
		{
		}	
	}
	
	
	if( xmlHttp )
	{
		url = url.replace( /\/{1}$/, "" );
		
		if(method === "GET")
		{
			if( url.indexOf("?")!=-1 )
			{
        		url += "&time=" + new Date().getTime();
        	}
        	else
        	{
        		url += "?time=" + new Date().getTime();
        	}
        }
        else if(method === "POST")
        {
            if( url.indexOf("?")!=-1 )
			{
        		url += "&time=" + new Date().getTime();
        	}
        	else
        	{
        		url += "?time=" + new Date().getTime();
        	}
		}
		
		try
		{
		    xmlHttp.open( method, url, true );
			
			if(method === "POST")
		    {
//			    xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
                xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded;charset=utf-8");

		    }
		}
		catch( e )
		{
			alert( "XMLHttp Open is Error !");
		}
	}
	else
	{
		alert("XMLHttp Not Created!");
    }
	
	
	return xmlHttp;
}

//=======================================================
//=======================================================

function AjaxClass( xmlHttp )
{
    var args = arguments;
	
	this.init = function( successCall, errorCall )
	{
	    var v_call = new Call( args,  successCall, errorCall );
	    xmlHttp.onreadystatechange = v_call.call;
	};
	
	this.send = function( parameter )
	{
		xmlHttp.send(parameter);
	};
}

function Call( args, success, error )
{
    this.call = function()
    {   
        if( args[0].readyState == 4 )
		{
			if( args[0].status == 200 )
			{
				if( success )
				    success( args );
			}
			else
			{
				if( error )
					error( args );
			    else
			        alert("Connection Exception !");
			}
		}
    }
}

function system_ajax_exception()
{
    alert("Connection Exception !");
}



//ajax parameter
if( !Object.prototype.toParameters )
{
	Object.prototype.toParameters = function()
	{
		var args = "";
		
		for( var elem in this )
		{
			if( typeof(this[elem]) === "string" || 
				typeof(this[elem]) === "number" || 
				typeof(this[elem]) === "boolean" )
			{ 
				if( args === "" )
				{
					args += ( elem + "=" + this[elem] );
				}
				else
				{
					args += ( "&" + elem + "=" + this[elem] );
				}
			}
		}
		
		return args;
	};
}

//ElementById
//return Object or null
function $( elemId, doc )
{
	if( typeof elemId === "string" )
	{
	    if( doc )
		    return doc.getElementById(elemId);
		else
		    return document.getElementById(elemId);
	}
	else
	{
		return null;
	}
}

//ElementsByName
//return array or null
function $$( elemName, doc )
{
	if( typeof elemName === "string" )
	{
	    if( doc )
	        return doc.getElementsByName( elemName );
	    else
		    return document.getElementsByName( elemName );
	}
	else
	{
		return null;
	}
}
