var xmlHttp
var mainUrl="modules/news/news.response.php"

var default_bg = "#469103";
var default_color = "#DEE3BF";
var active_bg = "#DEE3BF";
var active_color = "#469103";

function setActiveMenu(active){
         for(i=1;i<4;i++){
            if(i==active){
               document.getElementById("op"+i).style.background=active_bg
               document.getElementById("op"+i).style.color=active_color
            }else{
               document.getElementById("op"+i).style.background=default_bg
               document.getElementById("op"+i).style.color=default_color

            }
         }


}
function viewComment(nid){
         xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        	{
        	alert ("Browser tidak support HTTP Request")
        	}
        var url=mainUrl
        url=url+"?action=viewComment&nid="+nid
        url=url+"&sid="+Math.random()
        xmlHttp.onreadystatechange=function(){
                                    		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                                            	document.getElementById("operationResponse").innerHTML=xmlHttp.responseText
                                             setActiveMenu(2)
                                            	}
                                             /* if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading"){
                                            	document.getElementById("operationResponse").innerHTML="<img src=\"images/indicator.gif\">Tunggu beberapa saat . . ."
                                            	} */
                                             }
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
}
function viewOtherNews(nid,catid){
        xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        	{
        	alert ("Browser tidak support HTTP Request")
        	}
        var url=mainUrl
        url=url+"?action=viewOtherNews&nid="+nid+"&catid="+catid
        url=url+"&sid="+Math.random()
        xmlHttp.onreadystatechange=function(){
                                    		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                                            	document.getElementById("operationResponse").innerHTML=xmlHttp.responseText
                                             setActiveMenu(1)
                                            	}
                                             /* if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading"){
                                            	document.getElementById("operationResponse").innerHTML="<img src=\"images/indicator.gif\">Tunggu beberapa saat . . ."
                                            	} */
                                             }
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
}
function sendCommentForm(nid){
         xmlHttp=GetXmlHttpObject()
        if (xmlHttp==null)
        	{
        	alert ("Browser tidak support HTTP Request")
        	}
        var url=mainUrl
        url=url+"?action=sendCommentForm&nid="+nid
        url=url+"&sid="+Math.random()
        xmlHttp.onreadystatechange=function(){
                                    		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                                            	document.getElementById("operationResponse").innerHTML=xmlHttp.responseText
                                             setActiveMenu(3)
                                            	}
                                             /* if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading"){
                                            	document.getElementById("operationResponse").innerHTML="<img src=\"images/indicator.gif\">Tunggu beberapa saat . . ."
                                            	} */
                                             }
        xmlHttp.open("GET",url,true)
        xmlHttp.send(null)
}

function sendComment(nid){
          //alert(nid)
          var error=0;
          var x=document.getElementById("postComment");
          var queryString="nid="+nid+"&";
          for (var i=0;i<x.length;i++){
            if (i > 0) {
  			queryString += "&";
  		}
            if(x.elements[i].value==""){
              error=1;
              alert("Silahkan lengkapi semua isian form dulu !")
              break
            }else{
              queryString += x.elements[i].id+"="+escape(x.elements[i].value);
            }
          }
        if(error!=1){
          //alert(queryString)
          xmlHttp=GetXmlHttpObject()
          if (xmlHttp==null)
          	{
          	alert ("Browser tidak support HTTP Request")
          	}
          var url=mainUrl
          url=url+"?action=sendComment"
          url=url+"&sid="+Math.random()
          xmlHttp.onreadystatechange=function(){
                                      		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                                                 document.getElementById("operationResponse").innerHTML=xmlHttp.responseText

                                            	}
                                                  /* if (xmlHttp.readyState==1 || xmlHttp.readyState=="loading"){
                                              	document.getElementById("msg").innerHTML="<img src=\"images/indicator.gif\">Tunggu beberapa saat . . ."
                                              	} */
                                               }
          xmlHttp.open("POST",url,true)
          xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; Charset=UTF-8');
          xmlHttp.setRequestHeader("Content-length", queryString.length);
          xmlHttp.setRequestHeader("Connection", "close");
          xmlHttp.send(queryString);
        }
  }

/*##################################################################################################################################
  #################    REQUEST     #####################################################################################################
  ##################################################################################################################################*/

  function GetXmlHttpObject()
  {
  var xmlHttp=null;
  try
  	{
  	// ngecek buat browser firefox, opera 8.0+, safari
  	xmlHttp=new XMLHttpRequest();
  	}
  	catch (e)
  		{
  		// browser Internet Explorer
  		try
  			{
  			// IE 6.0+
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  			}
  			catch (e)
  				{
  				// IE 5.0
  				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  				}
  		}			
  return xmlHttp;
  }
  function changeBg(idx){
         for(i=1;i<4;i++){
            if(i==idx){
               document.getElementById("op"+i).style.background="#FFFDED"
               document.getElementById("op"+i).style.color="#BE0002" 
            }else{
               document.getElementById("op"+i).style.background="#BE0002"
               document.getElementById("op"+i).style.color="#FFFDED"
            }
         }
}
function changeBgDefault(idx){
         for(i=1;i<4;i++){
            if(i==idx){
               document.getElementById("op"+i).style.background="#BE0002"
               document.getElementById("op"+i).style.color="#FFFDED"
            }else{
               document.getElementById("op"+i).style.background="#FFFDED"
               document.getElementById("op"+i).style.color="#BE0002"

            }
         }
}
