﻿/// <summary>
///     Product:        Enewspaper
///     Classname:    	Common script
///     Version:        02.02 |	12 February, 2009 - 10 March, 2009
///     Programmer:     Soren [sunrise.freedom@gamil.com]
///     Purpose: 
///         The class common java script programming tasks.
/// 
///     Copyright 2009 by Digital Secure Co. All Rights Reserved. 
/// </summary>
/// <remark>
///     For Implement NewsCut mechanism do these task :
///
///     In Page.xslt put this line at Generating Image Map block.
///     <!-- .....hold news image [news cut] per news ID - only the text news has news cut !............... -->
///     NewsCutItems.put('<xsl:value-of select ="nws_Id"/>', '<xsl:value-of select ="NewsPhoto/prp_ImageURL"/>');
///
///     In Common.js put this lint at showContentForArea(divId) function
///      // hold current active news id.
///     SetCurrentNewsID(divId);
///
/// </remark>
/// <IsMultiEdition>True</IsMultiEdition>
/// <classVersion>005</classVersion>

//var NewsCutItems = new Hashtable();
var CurrentNewsID = '0';

// hold the Web Service Utility URL
var NewsUtilityWebServiceURL = '';
var RatingEventGrabberURL = '';

/// Hold current NewsId.
function SetCurrentNewsID(newsID, WebPath) {
    
    CurrentNewsID = newsID;
    ShowRatingPanel();
    var commentIfram = document.getElementById("script-console");
   
    if ((commentIfram != '') || (commentIfram != null))
        commentIfram.src = WebPath + 'Comments/index.aspx?NewsID=' + CurrentNewsID;
}


// Submit the search
// the type should be "LastNewspaper" OR "CurrentNewspaper";
function SubmitQuickSearch()
{
      var txt = document.getElementById("txtSearch").value
      
      if(txt.length < 3)
      {
        alert('برای انجام عمل جستجو باید یک کلمه با حداقل 3 حرف در مکان مورد نظر وارد کنید');  
        return;
      }
      else
      {
          //document.getElementById("limitation").value = type.toString();

          // Get Newspaper Number From Parent HTML Page
          document.getElementById("newspaperNumber").value = document.getElementById("nsn_Number").getAttribute("value");
          
          document.searchForm.submit();
      }
  }
  // init web news web service utility
  function initRatingService(ratingEventGrabberURL, newsUtilityWebServiceURL) {
      RatingEventGrabberURL = ratingEventGrabberURL;
      NewsUtilityWebServiceURL = newsUtilityWebServiceURL;
  }
  
  // first call a web service to obtain current news reating average.
  // show the 5 star rating panel for current news with specific news reating averag.
  function ShowRatingPanel() {
      // clean the Rating div...
      document.getElementById('RatingHolder').innerHTML = '';

      jQuery.ajax({
          type: "POST",
          url: NewsUtilityWebServiceURL + "/GetNewsRateAverage",
          //        url: "http://dsserver/AsrErtebat/ServiceCenter/NewsUtility.asmx/GetNewsRateAverage",
          data: '{nws_Id : "' + CurrentNewsID + '"}',
          //        data: '{}',
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(data) {
              var currentNewsRateAverage = data.d;
              //alert(currentNewsRateAverage);
              jQuery('#RatingHolder').rater(RatingEventGrabberURL, { style: 'basic', curvalue: currentNewsRateAverage });
          }
         , error: function(xmlHttpRequest, status, err) {
             // Debug Only
             //            alert('Sorry! Error happens.' + err);
             // when an error occur - init with 0 strar High Light..
             jQuery('#RatingHolder').rater(RatingEventGrabberURL, { style: 'basic', curvalue: 0 });
             //alert('failed');
         }
      });

  }

  
    
