var Controller = {
	storedDetail : '',

	toggle : function(id,target,iTarget){
		//if(this.storedDetail && this.storedDetail != id) document.getElementById(this.storedDetail).style.display = 'none';
		this.storedDetail = id;
		var style = document.getElementById(target+id).style;
		if(style.display == 'none'){
		 style.display = 'block';
		 document.images[iTarget+id].src = "images/min.gif";
		}else{ 
		 style.display = 'none';
		 document.images[iTarget+id].src = "images/plus.gif";
		}
		return false;
	}	
};

var headerController = {
	storedDetail : '',

	toggle : function(target){
		//if(this.storedDetail && this.storedDetail != id) document.getElementById(this.storedDetail).style.display = 'none';
		this.storedDetail = target;
		var style = document.getElementById(target).style;		
		if(style.display == 'none'){
		 style.display = 'block';
		 document.images['mainIcon'].src = "images/mainClose.gif";
		}else{ 
		 style.display = 'none';
		 document.images['mainIcon'].src = "images/mainOpen.gif";
		}
		return false;
	}	
};

function expandAll(i,target,iTarget) {
		for (loop=1; loop<=i; loop++)
		{
			document.getElementById(target+loop).style.display = 'block';
			document.images[iTarget+loop].src = "images/min.gif";
		}			
}

function closeAll(i,target,iTarget) {		
		for (loop=1; loop<=i; loop++)
		{	
			document.getElementById(target+loop).style.display = 'none';
			document.images[iTarget+loop].src = "images/plus.gif";	
		}		
}


// UNTUK BUAT EXPAND ALL dan CLOSE ALL, perlu cari tau cara baca ID element yang depannya detail_*
// Lalu tutup semua atau buka semua Element yang ID-nya detail_* tersebut.
function expandAll_shout(i) {
		for (loop=1; loop<=i; loop++)
		{
			document.getElementById("shout_"+loop).style.display = 'block';
			document.images["iShout_"+loop].src = "images/min.gif";
		}			
}

function closeAll_shout(i) {		
		for (loop=1; loop<=i; loop++)
		{	
			document.getElementById("shout_"+loop).style.display = 'none';
			document.images["iShout_"+loop].src = "images/plus.gif";	
		}		
}




function RequestInfo(id) {
 
  // Build the URL to connect to
  var url = "detail_respon.php?pcID=" + escape(id);  
  // Open a connection to the server
  xmlHttp.open("GET", url, true);

  // Setup a function for the server to run when it's done
  // xmlHttp.onreadystatechange = ResponComment;
  xmlHttp.onreadystatechange = function () {
									  alert("Respon ");	  
								  if (xmlHttp.readyState == 4) {
								  	// baca data respon dari server
									var response = xmlHttp.responseText;	
									document.getElementById("divinfo").innerHTML = response;								
								  }
								}

  // Send the request
  xmlHttp.send(null);
}

function experimentalDetail(id) {
//  document.images[iTarget+loop].src = "images/min.gif";
//  document.getElementById("divExperimental").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>"
  // Build the URL to connect to
  xmlEXP = create_request();
  var url = "experimentalDetail.php?pcID=" + escape(id);

  //create_request();
  // Open a connection to the server    
  xmlEXP.open("GET", url, true);


  // Setup a function for the server to run when it's done
  // xmlShout.onreadystatechange = ResponComment;
  xmlEXP.onreadystatechange = function () {															  
				document.getElementById("divExperimental").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>";								
								  if (xmlEXP.readyState == 4) {
								  	// baca data respon dari server
									var response = xmlEXP.responseText;	
									document.getElementById("divExperimental").innerHTML = response;								
								  }
								}

  // Send the request
  xmlEXP.send(null);

}

function create_request(){		
	var objXML = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try {
	  objXML = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
	  try {
		objXML = new ActiveXObject("Microsoft.XMLHTTP");
	  } catch (e2) {
		objXML = false;
	  }
	}
	@end @*/
	
	if (!objXML && typeof XMLHttpRequest != 'undefined') {
	  objXML = new XMLHttpRequest();
	}
	if (!objXML){
	  alert("Error initializing XMLHttpRequest!");
	}else{
	//alert("XMLHttpRequest sukses dibuat!");
	//RequestInfo(1);
	}
	return objXML;
}

function RequestShout() {
	
  // Build the URL to connect to
  xmlShout = create_request();
  var url = "http://www.ruangkecil.or.id/core/plugin/shoutbox/core-view-shoutbox2.php";
  //create_request();
  // Open a connection to the server      
  xmlShout.open("GET", url, true);

  // Setup a function for the server to run when it's done
  // xmlShout.onreadystatechange = ResponComment;	
  document.getElementById("divshout").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>";								  
  xmlShout.onreadystatechange = function () {															  
  document.getElementById("divshout").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>";								
								  if (xmlShout.readyState == 4) {  
								  	// baca data respon dari server
									var response = xmlShout.responseText;	
									document.getElementById("divshout").innerHTML = response;								
								  }
								}

  // Send the request
  xmlShout.send(null);
}

function RequestQuick() {

  //create_request();		
  xmlQuick = create_request();
  var url = "http://www.ruangkecil.or.id/core/plugin/core-view-quick.php";
  //create_request();
  // Open a connection to the server    
  xmlQuick.open("GET", url, true);

  // Setup a function for the server to run when it's done
  // xmlHttp.onreadystatechange = ResponComment;
  document.getElementById("divquick").innerHTML ="<div align='center'><img src='images/loaddata.gif' /></div>";
  xmlQuick.onreadystatechange = function () {	  							  
  document.getElementById("divquick").innerHTML ="<div align='center'><img src='images/loaddata.gif' /></div>";
								  if (xmlQuick.readyState == 4) {
								  // baca data respon dari server
								    var response = xmlQuick.responseText;										
									document.getElementById("divquick").innerHTML = response;								
								  }

								}

  // Send the request
  xmlQuick.send(null);
}

function CloseComment(pcINFOID) {
	document.getElementById("comment_"+ pcINFOID).innerHTML = "";	
}

function RequestComment(pcINFOID) {
	
  // Build the URL to connect to
  xmlComment = create_request();
  var url = "core-comment.php?pcINFOID=" + escape(pcINFOID);

  //create_request();
  // Open a connection to the server    
  xmlComment.open("GET", url, true);


  // Setup a function for the server to run when it's done
  // xmlShout.onreadystatechange = ResponComment;
  xmlComment.onreadystatechange = function () {															  
		    document.getElementById("comment_" + pcINFOID).innerHTML = "<div align='center'><img src='images/loaddata.gif' /></div>";								
 								  //document.images["iComment_" + pcINFOID].src = "images/plus.gif";								  
								  if (xmlComment.readyState == 4) {
								  	// baca data respon dari server
									var response = xmlComment.responseText;	
									document.getElementById("comment_"+ pcINFOID).innerHTML = response;
								  }
								}

  // Send the request
  xmlComment.send(null);
}

function RequestInfoToWindow(pcINFOID) {
	
  // Build the URL to connect to
  xmlComment = create_request();
  var url = "core-comment.php?pcINFOID=" + escape(pcINFOID);

  //create_request();
  // Open a connection to the server    
  xmlComment.open("GET", url, true);


  // Setup a function for the server to run when it's done
  // xmlShout.onreadystatechange = ResponComment;
  CloseComment(pcINFOID);  

  YAHOO.coreWindow.panel.show();						
  xmlComment.onreadystatechange = function () {															  
		    //document.getElementById("comment_" + pcINFOID).innerHTML = "<div align='center'><img src='images/loaddata.gif' /></div>";								
 								  //document.images["iComment_" + pcINFOID].src = "images/plus.gif";								  
		    document.getElementById("content-window").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>";
								  if (xmlComment.readyState == 4) {
								  	// baca data respon dari server
									var response = xmlComment.responseText;										
									document.getElementById("content-window").innerHTML =response;								
								  }
								}

  // Send the request
  xmlComment.send(null);
}

function addCommentWindow(pcINFOID) {
	
  // Build the URL to connect to
  xmlComment = create_request();
  var url = "core-add-comment.php?pcINFOID=" + escape(pcINFOID);

  //create_request();
  // Open a connection to the server    
  xmlComment.open("GET", url, true);


  // Setup a function for the server to run when it's done
  // xmlShout.onreadystatechange = ResponComment;
  //CloseComment(pcINFOID);  

  YAHOO.coreWindow.panel.show();						
  xmlComment.onreadystatechange = function () {															  
		    //document.getElementById("comment_" + pcINFOID).innerHTML = "<div align='center'><img src='images/loaddata.gif' /></div>";								
 								  //document.images["iComment_" + pcINFOID].src = "images/plus.gif";								  
		    document.getElementById("content-window").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>";
								  if (xmlComment.readyState == 4) {
								  	// baca data respon dari server
									var response = xmlComment.responseText;										
									document.getElementById("content-window").innerHTML =response;								
								  }
								}

  // Send the request
  xmlComment.send(null);
}

function addShoutBox() {
	
  // Build the URL to connect to
  xmlShoutbox = create_request();
  var url = "../../plugin/shoutbox/core-add-shoutbox.php";

  //create_request();
  // Open a connection to the server    
  xmlShoutbox.open("GET", url, true);
  YAHOO.coreWindow.panel.show();						
  document.getElementById("title-window").innerHTML = "Add Shoutbox";
  xmlShoutbox.onreadystatechange = function () {								  
			    document.getElementById("content-window").innerHTML="<div align='center'><img src='images/loaddata.gif' /></div>";
								  if (xmlShoutbox.readyState == 4) {
								  	// baca data respon dari server
									var response = xmlShoutbox.responseText;										
									document.getElementById("content-window").innerHTML =response;								
								  }
								}

  // Send the request
  xmlShoutbox.send(null);
}

var xmlHttp = false;

