﻿// JScript File

//Global variables
var timeID;
var refreshRate = 10000; // two seconds
var rnd = Math.random();
var mTimer;
var uarray=new Array();
var arruser=new Array();
var XmlHttp;
var Operations;
var yuks;
var isNav = false;
var isIE  = false;
if (navigator.appName == "Netscape") {
    isNav = true;
}
else {
    isIE = true;
}


function test()
{
//alert("pp");
}

//Creating and setting the instance of appropriate XMLHTTP Request object to a ?XmlHttp? variable  
//Creating and setting the instance of appropriate XMLHTTP Request object to a ?XmlHttp? variable  
function CreateXmlHttp()
{
	//Creating object of XMLHTTP in IE
	try
	{
		XmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			XmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
		} 
		catch(oc)
		{
			XmlHttp = null;
		}
	}
	
	//Creating object of XMLHTTP in Mozilla and Safari 
	if(!XmlHttp && typeof XMLHttpRequest != "undefined") 
	{
		XmlHttp = new XMLHttpRequest();
	}
}
var Operation;
function RateArticle(artId, rating)
{

    var ServerPageName = "AjexPage.aspx";
  Operation="ArtcleRating";
 
    var dt = new Date();
	var requestUrl = ServerPageName + "?op=ArtcleRating&ArtId="+artId+"&rating="+rating+"&tm="+dt.getTime();
	CreateXmlHttp();
	
	// If browser supports XMLHTTPRequest object
	if(XmlHttp)
	{
		//Setting the event handler for the response
		XmlHttp.onreadystatechange = HandleResponse;
		
		//Initializes the request object with GET (METHOD of posting), 
		//Request URL and sets the request as asynchronous.
		XmlHttp.open("GET", requestUrl,  true);
		           
		//Sends the request to server
		XmlHttp.send(null);		
	}
}

/////////////////////////////////////////////////////////
//Called when response comes back from server
function HandleResponse()
{

	// To make sure receiving response data from server is completed
	if(XmlHttp.readyState == 4)
	{
		// To make sure valid response is received from the server, 200 means response received is OK
		
		if(XmlHttp.status == 200)
		{		
	        //alert(XmlHttp.responseXML.documentElement);
			//var ReturnValue="False"
		
	
			SetResponseWithPage(XmlHttp.responseXML.documentElement);
			
		}
		else
		{
		//location.replace("ActivatDistrict.aspx");
			alert("There was a problem retrieving data from the server." );
			//location.replace("About_MP_view.aspx");
		}
	}
}

function SetResponseWithPage(Result)
{
     if(Operation=="ArtcleRating")
    {
        var ResultValue1 = Result.getElementsByTagName('ResultValue1');
        var str= GetInnerText(ResultValue1[0]);

        if(str=="1")
        {
            var ResultValue2 = Result.getElementsByTagName('ResultValue2');
            var strRate= GetInnerText(ResultValue2[0]);
           // document.getElementById("ctl00_ContentPlaceHolder1_lbl_Rating").innerHTML=strRate;
           //alert(strRate);
         
           document.getElementById("ctl00_ContentPlaceHolder1_lbl_Rating").innerHTML="";
         
                           var h = 0;
                        // document.getElementById("ctl00_ContentPlaceHolder1_lbl_Rating").innerHTML="<b>Rating :</b>";
                         var str='<table><tr><td><b>Rating :</b><t/td>';
                           for(h= 0; h < strRate; h++)
                           {
                              // document.getElementById("ctl00_ContentPlaceHolder1_lbl_Rating").innerHTML+= "<img src='images/star_on.gif' />";
                              str +="<td><img src='images/star_on.gif' /> </td>";
                           }
                           var l=0;
                           for(l = 0; l < 5 - h; l++)
                           {
                            
                               //document.getElementById("ctl00_ContentPlaceHolder1_lbl_Rating").innerHTML+= "<img src='images/star_off.gif' />";
                                str +="<td><img src='images/star_off.gif' /> </td>";
                           }
                           str +="</tr></table>";
                           document.getElementById("ctl00_ContentPlaceHolder1_lbl_Rating").innerHTML=str;
        }
        else
        {
         document.getElementById("ctl00_ContentPlaceHolder1_dvError").innerHTML ="<li>"+ str ;
        }     
      
    }
}
///////////////////////////////////////////////////////////////////////////////////////////////

//Returns the node text value 
function GetInnerText (node)
{
	 return (node.textContent || node.innerText || node.text) ;
}


