// stores the reference to the XMLHttpRequest object
var xmlHttp = createXmlHttpRequestObject(); 

// retrieves the XMLHttpRequest object
function createXmlHttpRequestObject() 
{	
  // will store the reference to the XMLHttpRequest object
  var xmlHttp;
  
// if running Internet Explorer
  if(window.ActiveXObject) 
  {
    try
    {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // if running Mozilla or other browsers
  else
  {
    try 
    {
      xmlHttp = new XMLHttpRequest();
    }
    catch (e) 
    {
      xmlHttp = false;
    }
  }
  // return the created object or display an error message
  if (!xmlHttp)
 
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

// make asynchronous HTTP request using the XMLHttpRequest object 
function close_show()
{
	try {
		if(aa) clearTimeout(aa);
	} catch (e) {}
}
function show_type(ty)
{
	if (ty == document.getElementById("global_ty").value) return false;
	fc = document.getElementById("global_fc").value;
	aa = setTimeout('run_show("'+fc+'","'+ty+'")', 400);
}
function show_func(fc)
{
	if (fc == document.getElementById("global_fc").value) return false;
	ty = document.getElementById("global_ty").value;
	aa = setTimeout('run_show("'+fc+'","'+ty+'")', 400);
}
function run_show(fc,ty)
{
  // proceed only if the xmlHttp object isn't busy
  if (xmlHttp.readyState == 4 || xmlHttp.readyState == 0)
  {
	//alert(fc+' '+ty);
// execute the quickstart.php page from the server
	xmlHttp.open("GET", "/index/show/xml.php?func="+fc+"&type="+ty, true);  
    // define the method to handle server responses
	xmlHttp.onreadystatechange = handleServerResponse;
    // make the server request
    xmlHttp.send(null);
  }
  else {
    // if the connection is busy, try again after one second  
	//alert('process('+func+','+type+')');
	try {
		if(aa) clearTimeout(aa);
	} catch (e) {}
	aa = setTimeout('run_show("'+fc+'","'+ty+'")', 200);
  }
}

// executed automatically when a message is received from the server
function handleServerResponse() 
{
  // move forward only if the transaction has completed
  if (xmlHttp.readyState == 4) 
  {
    // status of 200 indicates the transaction completed successfully
    if (xmlHttp.status == 200) 
    {
      // extract the XML retrieved from the server
      xmlResponse = xmlHttp.responseXML;
      // obtain the document element (the root element) of the XML structure
      xmlRoot = xmlResponse.documentElement;
      // get the text message, which is in the first child of
      // the the document element
	  id = xmlRoot.getElementsByTagName("id");
	  title = xmlRoot.getElementsByTagName("title");
	  nm = xmlRoot.getElementsByTagName("name");
	  mid = xmlRoot.getElementsByTagName("mid");
	  aid = xmlRoot.getElementsByTagName("aid");
	  photo = xmlRoot.getElementsByTagName("photo");
	  fid = xmlRoot.getElementsByTagName("fid");
	  order = xmlRoot.getElementsByTagName("order");

	  ty = xmlRoot.getElementsByTagName("ty");
	  fc = xmlRoot.getElementsByTagName("fc");
	  type = ty.item(0).firstChild.data;
 	  func = fc.item(0).firstChild.data;

	  var show_div = document.getElementById("show_pic");
	  var txt = "";
	  for (var i=0; i<id.length; i++) { 
	  
	  	txt += '<div class="content">';
		txt += '<div class="pic">';
		txt += '  <table height="100%" width="100%">';
		txt += '     <tr><td align="center">';
		
	if (func=='file') {
		txt += '<a href="#" onClick=win_fixopen("/file/File_preview.php?aid='+aid.item(i).firstChild.data+'&file_id='+id.item(i).firstChild.data+'&action=preview&file_dirid='+fid.item(i).firstChild.data+'","normal") >';
	} else if (func=='album') {
		txt += '<a href="/album/'+mid.item(i).firstChild.data+'?album_id='+id.item(i).firstChild.data+'&album_name='+escape(title.item(i).firstChild.data)+'&album_order='+order.item(i).firstChild.data+'" >';
	} else if (func=='poll') {
		txt += '<a href="/'+func+'/'+aid.item(i).firstChild.data+'?p_id='+id.item(i).firstChild.data+'" >';
	} else {
		txt += '<a href="/'+func+'/'+aid.item(i).firstChild.data+'?wid='+id.item(i).firstChild.data+'" >';
	}
	
		txt += '       <img src="'+photo.item(i).firstChild.data+'" class="pic2" title="'+title.item(i).firstChild.data+'"></a>';
		txt += '     </td></tr>';
		txt += '  </table>';
		txt += '</div> <!--end of pic-->';
		txt += '<div class="describe">'+nm.item(i).firstChild.data+'</div>';
		txt += '</div> <!--end of content-->';
	  }
	  txt += '<div class="more"><a href="/index/'+func+'">More..</a></div>'
	  show_div.innerHTML = txt;
	  //overFuncTab(ty.item(0).firstChild.data);
	document.getElementById("new").style.background='url(/images/index/tab.jpg)';
	document.getElementById("hot").style.background='url(/images/index/tab.jpg)';
	document.getElementById("commend").style.background='url(/images/index/tab.jpg)';
	document.getElementById(type).style.background='url(/images/index/tab_over.jpg)';  


	document.getElementById("weblog").src='/images/index/func_weblog.jpg';
	document.getElementById("album").src='/images/index/func_album.jpg';
	document.getElementById("podcast").src='/images/index/func_podcast.jpg';
	document.getElementById("file").src='/images/index/func_file.jpg';
	document.getElementById("poll").src='/images/index/func_poll.jpg';
	document.getElementById("club").src='/images/index/func_club.jpg';
	document.getElementById(func).src='/images/index/func_'+fc.item(0).firstChild.data+'_over.jpg';
	
	document.getElementById("global_fc").value = func;
	document.getElementById("global_ty").value = type;

		//document.getElementById("show_type03").style.background='url(images/index/tab_over.jpg)';		
    } 
    // a HTTP status different than 200 signals an error
    else 
    {
      alert("There was a problem accessing the server: " + xmlHttp.statusText);
	  //alert('_su');
    }
  }
}
