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

var default_bg = "#1D4D8D";
var default_color = "#FFFDED";
var active_bg = "#EDF5FF";
var active_color = "#F2BD7D";

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);
        }
  }
  function deleteComment(cid,idx){
          if(confirm('Apakah Anda akan menghapus komentar ini ?')){
            xmlHttp=GetXmlHttpObject()
            if (xmlHttp==null)
            	{
            	alert ("Browser tidak support HTTP Request")
            	}
            var url=mainUrl
            url=url+"?action=deleteComment&cid="+cid
            url=url+"&sid="+Math.random()
            xmlHttp.onreadystatechange=function(){
                                        		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                                                	   if(xmlHttp.responseText=='1'){
                                                        document.getElementById("comment_"+idx).innerHTML='';
                                                     }else{
                                                        alert('Penghapusan Komentar GAGAL !');
                                                     }
                                                	}
                                                 }
            xmlHttp.open("GET",url,true)
            xmlHttp.send(null)
          }
  }
  function FBComments(){
         
         document.getElementById("operationResponse").innerHTML='<fb:comments> </fb:comments>';
         FB.init("29abea6e45c85f394f9ae2bb1f2ca9cd");
         setActiveMenu(4);
         /* xmlHttp=GetXmlHttpObject()

        if (xmlHttp==null)

        	{

        	alert ("Browser tidak support HTTP Request")

        	}

        var url=mainUrl

        url=url+"?action=FBComments"

        url=url+"&sid="+Math.random()

        xmlHttp.onreadystatechange=function(){

                                    		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
                                                setActiveMenu(4)
                                            	document.getElementById("operationResponse").innerHTML=xmlHttp.responseText
                                                FB.init("29abea6e45c85f394f9ae2bb1f2ca9cd");
                                                 
                                            	}

                                             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) */

}
/*##################################################################################################################################
  #################    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"

            }
         }
}
