/*
Elatech Co. Ltd.
Date   : #2009-07-25#
Author : Bill Wu
Ajax Function
*/
function createxmlhttp()
{
    var xmlhttp=false;
    try	{
	    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } 
    catch (e) {
	    try {
		    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	    } 
	    catch (e) {
		    xmlhttp = false;
	    }
    }
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
	    xmlhttp = new XMLHttpRequest();
			    if (xmlhttp.overrideMimeType) {//设置MiME类别
		    xmlhttp.overrideMimeType('text/xml');
	    }
    }	
    return xmlhttp;	
}

function elm(str){return document.getElementById(str);}

function echo(container,str){
	elm(container).innerHTML=str;
}

function getxml(url,callback){
	url=url+'?&rnd='+ Math.random()
    var xmlhttp=createxmlhttp();
	if(!xmlhttp)
    {  
		alert("Your browser does not support XMLHTTP.");
        return;
    }
	xmlhttp.onreadystatechange=requestdata;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    function requestdata(){
		if(xmlhttp.readyState==4)
        {	
	        if(xmlhttp.status==200){
				callback(xmlhttp.responseXML);
			}
        }
    }
}

function getdata(url,container,callbackstr)
{    
    url=url+'&rnd='+ Math.random()
    var xmlhttp=createxmlhttp();
    if(!xmlhttp)
    {   alert("Your browser does not support XMLHTTP.");
        return;
    }
    echo(container,"<img src='images/loading.gif'>");
    xmlhttp.onreadystatechange=requestdata;
    xmlhttp.open("GET",url,true);
    xmlhttp.send(null);
    function requestdata(){
        if(xmlhttp.readyState==4)
        {	
	        if(xmlhttp.status==200)
	        {
	            echo(container,xmlhttp.responseText);
	            eval(callbackstr);
	        }else{
		        if(container!=null){echo(container,"ErrorCode:"+xmlhttp.status+"\n"+xmlhttp.responseText)}else{alert("Error Code:"+xmlhttp.status+"\nError Description:\n"+xmlhttp.responseText)}
	        }
        }
		
    }
}
