﻿
var oDocs = new Array();
var oLADocs = new Array(); 
var oLADocsArticles = new Array();

function Docs(id, displayno, docno, title, date,la,latitle,dt,dttitle,ds,dstitle) {
    this.ID = id;
    this.DisplayNo = displayno;
    this.DocumentNo = docno;
    this.Title = title;
    this.DocumentDate = date;
    this.LawsArea = la;
    this.LawsAreaTitle = latitle;
    this.DocumentSectionType = ds;
    this.DocumentSectionTypeTitle = dstitle;
    this.DocumentType = dt;
    this.DocumentTypeTitle = dttitle;
}

              

$(document).ready(function(){

    $('#listticker').innerfade({
		animationtype: 'slide',
		speed: 90,
		timeout: 3000,
		type:'sequence',
		containerheight: '100px',
		controlBox: 'show',
		ControlBoxPath:'Admin/L4IFiles/Images'
	});
	
	$('#hdrimg').cycle({ 
        fx:    'fade', 
        speed:  2500 
     });
 
	$('#rdLastDay').live("click",(function(){getLatestUpdate(1);}));
	$('#rdLastWeek').live("click",(function(){getLatestUpdate(7);}));
	$('#rdLastTwoWeek').live("click",(function(){getLatestUpdate(15);}));
	
	getLatestUpdate(15);
	
	
});

function getLatestUpdate(days){
       var daysPara = 'days=' + days;
       $.ajax({
          type: "POST",
          dataType: "json",
          url:"./GetQueryData.aspx",
          data: daysPara,
          error: function(XMLHttpRequest, textStatus, errorThrown){
              alert(textStatus);
          },
          success:updateNews 
       });
}



function updateNews(result,stats){
    if(stats !="success"){
        alert("Error while getting the updated !!");
        return; 
    }
    
    oDocs = new Array();
    oLADocs = new Array();
    oLADocsArticles = new Array();
    
    var data = eval(result);
    
    for (var i = 0; i < data.length; i++) {
        var doc = data[i];
        var oDoc = new Docs(doc.ID,
                            doc.DisplayNo,doc.DocumentNo,doc.Title,
                            doc.DocumentDate,doc.LawsArea,doc.LawsAreaTitle,doc.DocumentType,
                            doc.DocumentTypeTitle,doc.DocumentSectionType,doc.DocumentSectionTypeTitle);
        oDocs[oDoc.ID] = oDoc;
        /*Added if Condition for Document Type Article  */
        if(oDoc.DocumentTypeTitle=='Article')
            var doctyp = (typeof(oDoc.DocumentSectionTypeTitle)=="undefined" || oDoc.DocumentSectionTypeTitle == null)?'':oDoc.DocumentSectionTypeTitle;
        else
            var doctyp = (typeof(oDoc.DocumentSectionTypeTitle)=="undefined" || oDoc.DocumentSectionTypeTitle == null)?oDoc.DocumentTypeTitle:oDoc.DocumentSectionTypeTitle;

        doctyp = (oDoc.DisplayNo.indexOf(doctyp)>=0)?'':doctyp + ' - ';
    
        if (typeof (oLADocs[oDoc.LawsArea]) == "undefined" || oLADocs[oDoc.LawsArea] == null) {
        if ( oDoc.DocumentType !=15 )
            oLADocs[oDoc.LawsArea] = '<a onmouseover="showDetails(' + oDoc.ID + ');" href="javascript:openContent(' + oDoc.ID + ',\'same\');">' 
                + doctyp  + oDoc.DisplayNo + '</a>';
        } else if(oDoc.DocumentType !=15 ){
            oLADocs[oDoc.LawsArea] += ' , <a onmouseover="showDetails(' + oDoc.ID + ');"  href="javascript:openContent(' + oDoc.ID + ',\'same\');">' 
                + doctyp + oDoc.DisplayNo + '</a>';
        }
       
         if (typeof (oLADocsArticles[oDoc.LawsArea]) == "undefined" || oLADocsArticles[oDoc.LawsArea] == null) {
          if ( oDoc.DocumentType ==15 )
            oLADocsArticles[oDoc.LawsArea] = '<a onmouseover="showDetailsArticles(' + oDoc.ID + ');" href="javascript:openContent(' + oDoc.ID + ',\'same\');">' 
                + doctyp  + oDoc.DisplayNo + '</a>';
        } 
        else if( oDoc.DocumentType ==15 ) {
             oLADocsArticles[oDoc.LawsArea] +=' , <a onmouseover="showDetailsArticles(' + oDoc.ID + ');" href="javascript:openContent(' + oDoc.ID + ',\'same\');">' 
                + doctyp  + oDoc.DisplayNo + '</a>';
        }
    }
    /*Display Data Fixed the lawsarea if any update needs to update it here */   
    if(typeof(oLADocs[1])!="undefined" && oLADocs[1]  != null) 
        $("#dt").html(oLADocs[1]);
    else
        $("#dt").html("&nbsp;");
        
    if(typeof(oLADocs[2])!="undefined" && oLADocs[2]  != null) 
        $("#st").html(oLADocs[2]);
    else
        $("#st").html("&nbsp;");
        
    if(typeof(oLADocs[4])!="undefined" && oLADocs[4]  != null) 
        $("#cl").html(oLADocs[4]);
    else
        $("#cl").html("&nbsp;");
     
    if(typeof(oLADocs[7])!="undefined" && oLADocs[7]  != null) 
        $("#ex").html(oLADocs[7]);
    else
        $("#ex").html("&nbsp;");
        
    if(typeof(oLADocs[5])!="undefined" && oLADocs[5]  != null) 
        $("#fl").html(oLADocs[5]);
    else
        $("#fl").html("&nbsp;");
        
    if(typeof(oLADocs[8])!="undefined" && oLADocs[8]  != null) 
        $("#ll").html(oLADocs[8]);
    else
        $("#ll").html("&nbsp;");
    if(typeof(oLADocs[10])!="undefined" && oLADocs[10]  != null) 
        $("#pl").html(oLADocs[10]);
    else
        $("#pl").html("&nbsp;");   
    if(typeof(oLADocs[11])!="undefined" && oLADocs[11]  != null) 
        $("#llp").html(oLADocs[11]);
    else
        $("#llp").html("&nbsp;");   
        
    $("#docno").html("&nbsp;");
    $("#doctitle").html("&nbsp;");
    $("#docdate").html("&nbsp;");


 /*Display Data Fixed the Latest Articles if any update needs to update it here */   
    if(typeof(oLADocsArticles[1])!="undefined" && oLADocsArticles[1]  != null) 
        $("#dtarticles").html(oLADocsArticles[1] );
    else
        $("#dtarticles").html("&nbsp;");
       
    if(typeof(oLADocsArticles[2])!="undefined" && oLADocsArticles[2]  != null) 
        $("#starticles").html(oLADocsArticles[2] );
    else
        $("#starticles").html("&nbsp;");
     
    if(typeof(oLADocsArticles[4])!="undefined" && oLADocsArticles[4]  != null) 
        $("#clarticles").html(oLADocsArticles[4] );
    else
        $("#clarticles").html("&nbsp;");
       
    if(typeof(oLADocsArticles[7])!="undefined" && oLADocsArticles[7]  != null) 
   
        $("#exarticles").html(oLADocsArticles[7]);
    else
        $("#exarticles").html("&nbsp;");
    
        
    if(typeof(oLADocsArticles[5])!="undefined" && oLADocsArticles[5]  != null) 
   
            $("#flarticles").html(oLADocsArticles[5]);
        else
            $("#flarticles").html("&nbsp;");
            
    if(typeof(oLADocsArticles[8])!="undefined" && oLADocsArticles[8]  != null) 
        $("#llarticles").html(oLADocsArticles[8]);
    else
        $("#llarticles").html("&nbsp;");
    if(typeof(oLADocsArticles[10])!="undefined" && oLADocsArticles[10]  != null) 
        $("#plarticles").html(oLADocsArticles[10]);
    else
        $("#plarticles").html("&nbsp;"); 
    if(typeof(oLADocsArticles[11])!="undefined" && oLADocsArticles[11]  != null) 
        $("#llparticles").html(oLADocsArticles[11]);
    else
        $("#llparticles").html("&nbsp;");     
        
    $("#Docnoarticles").html("&nbsp;");
    $("#doctitlearticles").html("&nbsp;");
    $("#docdatearticles").html("&nbsp;");
}
function showDetails(id){
    var doc = oDocs[id];
    var doctyp  = (typeof(doc.DocumentSectionTypeTitle)=="undefined" || doc.DocumentSectionTypeTitle == null)?doc.DocumentTypeTitle:doc.DocumentSectionTypeTitle;
    doctyp = (doc.DisplayNo.indexOf(doctyp)>=0)?'': doctyp + ' - ';
    $("#docno").html(doctyp + doc.DisplayNo);
    $("#doctitle").html(doc.Title);
    var dtValue =eval( ' new ' +  doc.DocumentDate.replace('/','').replace('/',''));
    var dtStr = (dtValue.getDate()) + "/" + (dtValue.getMonth()+1)+ "/" + dtValue.getFullYear();
    $("#docdate").html(dtStr);
}
function showDetailsArticles(id){
    var doc = oDocs[id];
    var doctyp  = (typeof(doc.DocumentSectionTypeTitle)=="undefined" || doc.DocumentSectionTypeTitle == null)?doc.DocumentTypeTitle:doc.DocumentSectionTypeTitle;
    doctyp = (doc.DisplayNo.indexOf(doctyp)>=0)?'': doctyp + ' - ';
    $("#Docnoarticles").html(doctyp + doc.DisplayNo);
    $("#doctitlearticles").html(doc.Title);
    var dtValue =eval( ' new ' +  doc.DocumentDate.replace('/','').replace('/',''));
    var dtStr = (dtValue.getDate()) + "/" + (dtValue.getMonth()+1)+ "/" + dtValue.getFullYear();
    $("#docdatearticles").html(dtStr);
}
