$(document).ready(function() {

       //$("a[@class=newsDetail1]").bind("click",Services);
	//$("#newsDetail10").bind("click",Services);
	//$("#newsDetail9").bremote("newsHeadLine-",Services);
	//$("#newsindeks1").bremote("newsDetail-",Services);


	$("a.newsDetail1").bremote("newsDetail-",Services);
	$("a.newsindeks1").bremote("newsIndeks-",Services);
	$("#newsDetail8").bremote("newsTodays-",Services);
	

});

function MenuNewsServices() {	
 // getPrtlstd("news","s11","","","","","","","","","");
var url='modules/?id=news&svr=s11';$.getScript(url);return
}


function Services(el) {
/*       if (el == 'undefined') {
            el = $(this).get(0);
            alert(el);
      }
*/
	if (el.clientX) {
            el = $(this).get(0);
           // alert(el);
      }

	var idreg = $(el).attr("idreg");
	var svr = $(el).attr("svr");
	var idNews = $(el).attr("idNews");
	var currentPage = $(el).attr("currentPage");
	var ctgr = $(el).attr("ctgr");
	var key = $(el).attr("key");
	var sdate = $(el).attr("sdate");
	var edate = $(el).attr("edate");
	var jumpPage = $(el).attr("jumpPage");
	var totalPages = $(el).attr("totalPages");
	var idBUMN = $(el).attr("idBUMN");
	var nametitle= $(el).attr("nametitle");
	var input = $(el).siblings("@name=pageNum").val();

    totalPages = totalPages*1;
	
	if(jumpPage == 1)
	{
		var currentPage = input*1;
		
		if(currentPage != 0)
		{
			if (currentPage > totalPages)
				alert(message("halamanTerakhir")+totalPages);
			else
		getPrtlstd(idreg,svr,idNews,idBUMN,currentPage,ctgr,key,sdate,edate,jumpPage,nametitle);
		}
	}
	else
		getPrtlstd(idreg,svr,idNews,idBUMN,currentPage,ctgr,key,sdate,edate,jumpPage,nametitle);

}

function formatTanggal(tinput) //yyyy-mm-dd
{
	namaBulan = new Array("Januari","Pebruari","Maret","April","Mei","Juni","Juli","Agustus","September","Oktober","Nopember","Desember");

	if(tinput != null)
	{
	var xx = tinput;
	
	var tglArr = xx.split("-");
	
	var tgl = tglArr[2];
	var bln = namaBulan[((tglArr[1] * 1)-1)];
	var thn = tglArr[0];
	var dateFormated = tgl+" "+bln+" "+thn;
	}
	return dateFormated;
}

function getPrtlstd(idreg,svr,idNews,idBUMN,currentPage,ctgr,key,sdate,edate,jumpPage,nametitle) {
		var fopts ="";
		var showsfilters="";

		var judul =nametitle; 
		//var judul =getJudul(idreg);

		showsfilters=true; 
		fopts = { id: idreg };			
		  var url  = "modules/";	
		  //var options = {title : judul,url: "modules/",showfilter: showsfilters};
		  var pctgr = function() {

					//$("a[@class=newPage]").bind("click",Services);

					$("a.newsDetail5").bremote("newsDetail-",Services);
					$("a.newsDetail6").bremote("newsDetail-",Services);
					$("a.newsDetail7").bremote("newsDetail-",Services);
					$("a.newPage").bremote("newsPaging-",Services);
					$("a.newsindeks1").bremote("newsIndeks-",Services);
					$("input[@class=searchButton]").bind("click",Services);
					$("#newsDetail9").bremote("newsHeadLine-",Services);


//	$("#newsDetail8").bremote("newsTodays-",Services);

/*
			  $("a[@class=newsDetail5]").bind("click",Services);
			  $("a[@class=newsDetail6]").bind("click",Services);
			  $("a[@class=newsDetail7]").bind("click",Services);
			  $("a[@class=newPage]").bind("click",Services);
			  $("input[@class=searchButton]").bind("click",Services);
*/
		  }
		  
		var idreg = "news";	
		var options = {title : judul,url: url,filterOptions : fopts, id : idreg, postCtgr : pctgr, postKey : pctgr, postPrd : pctgr};
		
		var pars = {id : idreg, idreg :idreg, svr : svr, idNews : idNews, idBUMN : idBUMN, ctgr : ctgr, key : key, sdate : sdate, edate : edate, currentPage: currentPage}; 
	if((svr == "s03") ||(svr == 's04') || (svr == 's100') ||(svr == 's110')||(svr == 's120')||(svr == 's11'))
	{
			
		Container.displayOnView(options,pars,function( ) {

/*
			//$("a[@class=newsDetail1]").bind("click",Services);
			$("a[@class=newsDetail2]").bind("click",Services);
			$("a[@class=newsDetail3]").bind("click",Services);
			$("a[@class=newsDetail4]").bind("click",Services);
			$("#vsPrint1").bind("click",newsPrint);
			$("#vsPrint2").bind("click",newsPrint);
			$("a[@class=newsDetail5]").bind("click",Services);
			$("a[@class=newsDetail6]").bind("click",Services);
			$("a[@class=newsDetail7]").bind("click",Services);
			//$("#newsDetail8").bind("click",Services);
			$("#newsDetail9").bind("click",Services);
			//$("#newsDetail10").bind("click",Services);
			$("a[@class=newPage]").bind("click",Services);
			$("input[@class=searchButton]").bind("click",Services);
*/
//	$("#newsDetail8").bremote("newsTodays-",Services);

				$("#newsDetail9").bremote("newsHeadLine-",Services);
				$("a.newsDetail2").bremote("newsDetail-",Services);
				$("a.newsDetail3").bremote("newsDetail-",Services);
				$("a.newsDetail4").bremote("newsDetail-",Services);
				$("#vsPrint1").bind("click",newsPrint);
				$("#vsPrint2").bind("click",newsPrint);
				$("a.newsDetail5").bremote("newsDetail-",Services);
				$("a.newsDetail6").bremote("newsDetail-",Services);
				$("a.newsDetail7").bremote("newsDetail-",Services);
				$("a.newsDetail9").bremote("newsDetail-",Services);
				$("a.newPage").bremote("newsPaging-",Services);
				$("a.newsindeks1").bremote("newsIndeks-",Services);
				$("input[@class=searchButton]").bind("click",Services);

			$("#formTanggapan3").ajaxForm(ct_options3);
		});
				
	}
	else
	{
		$.get(url,pars, function (data) {
			$("#containerNews").html(data);

/*				//$("a[@class=newsDetail1]").bind("click",Services);
				$("a[@class=newsDetail2]").bind("click",Services);
				$("a[@class=newsDetail3]").bind("click",Services);
				$("a[@class=newsDetail4]").bind("click",Services);
				$("a[@class=newsDetail5]").bind("click",Services);
				$("a[@class=newsDetail6]").bind("click",Services);
				$("a[@class=newsDetail7]").bind("click",Services);
				//$("#newsDetail8").bind("click",Services);
				$("#newsDetail9").bind("click",Services);
				//$("#newsDetail10").bind("click",Services);
				$("a[@class=newPage]").bind("click",Services);
				$("input[@class=searchButton]").bind("click",Services);	
*/

$("a.newsindeks1").bremote("newsIndeks-",Services);
//$("#newsideks1").unbind("click",Services);
$("a[@class=newsDetail2]").bremote("newsDetail-",Services);
$("a[@class=newsDetail3]").bremote("newsDetail-",Services);
$("a[@class=newsDetail4]").bremote("newsDetail-",Services);
$("a[@class=newsDetail5]").bremote("newsDetail-",Services);
$("a[@class=newsDetail6]").bremote("newsDetail-",Services);
$("a[@class=newsDetail7]").bremote("newsDetail-",Services);
//$("a[@class=newsDetail9]").bremote("newsDetail-",Services);
	$("#newsDetail8").bremote("newsTodays-",Services);
	$("#newsDetail9").bremote("newsHeadLine-",Services);
//$("a.newsindeks1").bremote("newsDetail-",Services);
$("a[@class=newPage]").bind("click",Services);
$("input[@class=searchButton]").bind("click",Services);

			
		});
	}
}




function reportError(request)
	{
		alert('Sorry. There was an error.');
	}

function newsPrint(event)
{
	var idreg = $(this).attr("idreg");
	var svr = $(this).attr("svr");
	var idNews = $(this).attr("idNews");
	var idBUMN = $(this).attr("idBUMN");
	var idLang = $(this).attr("idLang");

	
	var url = 'modules/';
	swin = window.open(url+"?id="+idreg+"&idreg="+idreg+"&svr="+svr+"&idNews="+idNews+"&idBUMN="+idBUMN +"&idLang="+idLang ,'win','scrollbars,width=750,height=600,top=80,left=140,status=yes,toolbar=no,menubar=yes,location=no');

	swin.focus();
}

function convertDate(inputDate)
{
	var datefield = inputDate;
	
	
	var strMonthArray= new Array()
		strMonthArray["Januari"]="Jan";
		strMonthArray["Pebruari"]="Feb";
		strMonthArray["Maret"]="Mar";
		strMonthArray["April"] = "Apr";
		strMonthArray["Mei"] = "May";
		strMonthArray["Juni"] = "Jun";
		strMonthArray["Juli"] = "Jul";
		strMonthArray["Agustus"] = "Aug";
		strMonthArray["September"] = "Sep";
		strMonthArray["Oktober"] = "Oct";
		strMonthArray["Nopember"] = "Nov";
		strMonthArray["Desember"] = "Dec";

	if(datefield != "")
		strDate = datefield;
	else
		strDate = "";

	if(strDate != "")
	{
		strDateArray = strDate.split(" ");
		var strDay = strDateArray[0];
		var strMonth = strDateArray[1];
		var strYear = strDateArray[2];
		
		var strDate1 = strMonthArray[strMonth] + " " + strDay+" " + strYear;
		return strDate1;
		
	}
	else
	{
		var strDate1 = "";
		return strDate1;
	}
}

function doDateCheck(awal,akhir) 
{
	var strDateFrom = convertDate(awal);
	var strDateTo = convertDate(akhir);
	
	
	if (Date.parse(strDateFrom) <= Date.parse(strDateTo)) 
	{
		return true;
	}
	else 
	{
		if (strDateFrom == "" || strDateTo == "") 
			alert("Periode Harus Diisi.");
		else 
			alert("Isi Dengan Periode yang Benar.");
	}

}



/* script untuk comment */
/*======================*/
function panel_respond(){
	document.getElementById('ct-panelRespond').style.display='block';
	document.getElementById('ct-panelRespond2').style.display='none';
}
function panel_respond2(){
	document.getElementById('ct-panelRespond2').style.display='block';
	document.getElementById('ct-panelRespond').style.display='none';
}
function closed(){
	document.getElementById('ct-panelRespond').style.display='none';
	document.getElementById('ct-panelRespond2').style.display='none';
}
/* end script comment */

 