﻿//ArticleGrid
function AG(){}

AG.Cp= function(index, total, uid){
    document.getElementById('hidIndex' + uid).value = index;
    document.getElementById('SF').style.visibility = 'visible';
    document.getElementById('SF').style.display = 'block';
    AG.ChangePager(index, total, uid);
}
              
AG.ChangePager= function(index, total, uid){
    for(var i = 1; i <= total; i++){
     var p = Utilities.getElementById('page' + uid + '_' + i);
        if(i == index){
            p.style.color = "#ffffff";            
        }
        else{
            p.style.color = "#000000";
        }
    }
}
        
       
AG.Gpc = function(title, intro, views, goodVotes, badVotes, reliability, priority, content, comments, hasText, hasImage, hasVideo, hasAudio, image, headings, cluster,sourcename) {

    $(document).ready(function() {
        
        Utilities.getElementById("apTitle").innerHTML = title;
        Utilities.getElementById("apIntro").innerHTML = intro;
        Utilities.getElementById("apViews").innerHTML = views;
        Utilities.getElementById("apComments").innerHTML = comments;
        Utilities.getElementById("apGenre").innerHTML = content;
        Utilities.getElementById("apRating+").innerHTML = goodVotes;  
        Utilities.getElementById("apRating-").innerHTML = badVotes;
        Utilities.getElementById("apReliability").src = '../../images/articleGrid/reability/' + reliability + '.gif';   
        Utilities.getElementById("apPriority").src = '../../images/articleGrid/priority/' + priority + '.gif';      
        Utilities.getElementById("apCategories").innerHTML = headings;  
        Utilities.getElementById("apClustered").innerHTML = cluster;   
        Utilities.getElementById("apSourceName").innerHTML = sourcename;
       
        if(hasText==1){
           Utilities.getElementById("apImgT").style.visibility = "visible";   
        }
        else{
           Utilities.getElementById("apImgT").style.visibility = "hidden";   
        }
        
        if(hasImage==1){
           Utilities.getElementById("apImgI").style.visibility = "visible";   
        }
        else{
           Utilities.getElementById("apImgI").style.visibility = "hidden";   
        }
        
        if(hasVideo==1){
           Utilities.getElementById("apImgV").style.visibility = "visible";   
        }
        else{
           Utilities.getElementById("apImgV").style.visibility = "hidden";   
        }
        
        if(hasAudio==1){
           Utilities.getElementById("apImgA").style.visibility = "visible";   
        }
        else{
           Utilities.getElementById("apImgA").style.visibility = "hidden";     
        }
        
        if(image==''){
          Utilities.getElementById("apImg").style.width = "0px";           
          Utilities.getElementById("apImg").style.visibility = "hidden";                     
        }
        else{
          Utilities.getElementById("apImg").style.visibility = "visible";
          Utilities.getElementById("apImg").src = image;          
            //Check image height and width if it exceeds normal heaight and width then fix the height and width - NirmalaKannan
            var img = new Image();
            img.src=image;
            var width = img.width;
            var height = img.height;  
            if (width > 210 || height > 130 )
            {
                Utilities.getElementById("apImg").style.width = "210px";
                Utilities.getElementById("apImg").style.height = "130px";
            }
            else
            {
                Utilities.getElementById("apImg").style.width = width + "px";
                Utilities.getElementById("apImg").style.height = height + "px";
            }
          Utilities.getElementById("apContentInner").style.height = "200px";
        }
        if(headings=='') {
          Utilities.getElementById("apCDiv").style.visibility = "hidden";   
        }
        else {
          Utilities.getElementById("apCDiv").style.visibility = "visible";
        }
     });
}

function browserDetect4OrangeArticle()
{
this.getById = document.getElementById?true:false;
this.layers = document.layers?true:false;
this.ns4 = ((this.layers) && (!this.getById));
this.ns6 = ((navigator.userAgent.indexOf('Netscape6') != -1) && (this.getById));
this.moz = ((navigator.appName.indexOf('Netscape') != -1) && (this.getById) && (!this.ns6));
this.ie  = ((!this.layers) && (this.getById) && (!(this.ns6 || this.moz)));
this.opera = window.opera?true:false;
}
var popupTimer; 
AG.ShowPopup4OrangeArticle = function(gridRowId,gridRowHeight) {
    if(gridRowHeight != null) {
        var functionCall = "AG.ShowPopupDelay4OrangeArticle('"  + gridRowId + "','" + gridRowHeight + "')";
    }
    else {
        var functionCall = "AG.ShowPopupDelay4OrangeArticle('"  + gridRowId + "')";
    }
   popupTimer = setTimeout(functionCall,500); 
}
 
AG.ShowPopupDelay4OrangeArticle = function(gridRowId,gridRowHeight) {    
    var loc = Sys.UI.DomElement.getLocation($get(gridRowId));
    var popupControl = Utilities.getElementById("ArticlePopup");
    var browser=navigator.appName;
    this.type = new browserDetect4OrangeArticle();
    popupControl.style.left = loc.x + 75 + "px";        
    if (this.type.ie)
    {
        if (gridRowHeight != null)
            popupControl.style.top = loc.y + gridRowHeight + "px";        
       else               
            popupControl.style.top = loc.y + 22 + "px";
    }
    else
    {  
         var hgt = loc.y + document.getElementById(gridRowId).offsetHeight
         hgt = parseInt(hgt);         
         popupControl.style.top = hgt + "px";        
    }       
       
        
       popupControl.style.visibility = "visible";
       popupControl.style.display = "block";    
}       
AG.ShowPopup = function(gridRowId,gridRowHeight) {
    if(gridRowHeight != null) {
        var functionCall = "AG.ShowPopupDelay('"  + gridRowId + "','" + gridRowHeight + "')";
    }
    else {
        var functionCall = "AG.ShowPopupDelay('"  + gridRowId + "')";
    }
   popupTimer = setTimeout(functionCall,350); 
}
 
AG.ShowPopupDelay = function(gridRowId,gridRowHeight) {
    //var gridRowControl = Utilities.getElementById(gridRowId);
    //var loc = Sys.UI.DomElement.getLocation(gridRowControl);
    var loc = Sys.UI.DomElement.getLocation($get(gridRowId));
    var popupControl = Utilities.getElementById("ArticlePopup");
       popupControl.style.left = loc.x + 75 + "px";
       if (gridRowHeight != null)
            popupControl.style.top = loc.y + gridRowHeight + "px";        
       else               
            popupControl.style.top = loc.y + 22 + "px";
        
       popupControl.style.visibility = "visible";
       popupControl.style.display = "block";    
}       
        
AG.HidePopup = function() {  
    clearTimeout(popupTimer);
    if(Utilities.getElementById("ArticlePopup") != undefined) {
    Utilities.getElementById("ArticlePopup").style.visibility = "hidden";
    Utilities.getElementById("ArticlePopup").style.display = "none";
    }
    Utilities.getElementById("apImg").style.visibility = "hidden";
    Utilities.getElementById("apImgT").style.visibility = "hidden";
    Utilities.getElementById("apImgI").style.visibility = "hidden";
    Utilities.getElementById("apImgV").style.visibility = "hidden";
    Utilities.getElementById("apImgA").style.visibility = "hidden";
    Utilities.getElementById("apImgA").style.visibility = "hidden";
    Utilities.getElementById("apCDiv").style.visibility = "hidden";
}
         
AG.ChangeRowStyle = function(row, color,mouseover) {
    //row.style.backgroundColor = color;
    row.style.color = color;
    if(mouseover) {
    row.className = "gridRowHover";
    }
    else {
    row.className = "gridRow";
    }
    
}

AG.ChangeSmartGridRowStyle = function(row, color,mouseover) {
    //row.style.backgroundColor = color;
    row.style.color = color;    
    if(mouseover) {    
    row.className = "smartgridRowHover";
    }
    else {
    row.className = "smartgridRow";
    }
    
}

/* Register script to ajax script manager */
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 



/*ArticleGrid.changeRowStyle = function() {
    var row = arguments[0];
    var color = arguments[1];
    var RowCss = arguments[2];
    var mouseOver = arguments[3];
    
    var cells = row.getElementsByTagName("td");
    var title = cells[3].getElementsByTagName("a").item(0);
      
    row.style.backgroundColor = color;

    if(mouseOver == 1){
        row.className = 'ArticleList_HoverItem'; 
        title.className = 'ArticleList_HoverItem'; 
        cells[0].style.backgroundColor = color;
        cells[cells.length - 1].style.backgroundColor = color; 
    }
    else
    {
        row.className = RowCss; 
        title.className = RowCss; 
        cells[0].style.backgroundColor = '#ffffff';
        cells[cells.length - 1].style.backgroundColor = '#ffffff';
    }
}

ArticleGrid.setRowStyle = function() {
    if (arguments.length < 2) {
        throw "Invalid number of arguments.";
        return;
    }
    
    var cell = arguments[0];
    var cssClass = arguments[1];
    var alternateCssClass = "";
    
    if (arguments.length == 3) alternateCssClass = arguments[2];

    var row = cell.parentNode;
    var cells = row.getElementsByTagName("td");
    
    for (var index = 0; index < cells.length; index++) 
    {        
        if (arguments.length == 3) cells[index].style.backgroundColor = (index % 2) ? alternateCssClass : cssClass;
        else
        cells[index].style.backgroundColor=cssClass
    }
}
*/
/* Register script to ajax script manager */
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded(); 
