﻿/// <summary>
///     Product:        Enewspaper
///     Classname:    	Ajax Proxy
///     Version:        02.02 |	01 September, 2008 - 06 January, 2009
///     Programmer:     Soren [sunrise.freedom@gamil.com]
///     Purpose: 
///         The class call a service (here simple .Net web form) to get an address 
///             of archive page( if exist !! ).
/// 
///     Copyright 2009 by Digital Secure Co. All Rights Reserved. 
/// </summary>
/// <IsMultiEdition>True</IsMultiEdition>
/// <classVersion>002</classVersion>
///<EditingHistory>
///    Name:       Soren
///    Date:       14 May, 2009
///    Reason of change :
///        - change 'ajaxFunction()' to get URL parameter from caller code.
///         in order to understand where we are in code [page, newspaper, root,...]    
///</EditingHistory>
//function $(elementID)
//{
//    return document.getElementById(elementID);
//}


function ajaxFunction(URL)
{
var xmlHttp;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    try
      {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    catch (e)
      {
      alert("Your browser does not support AJAX!");
      return false;
      }
    }
  }
  
  xmlHttp.onreadystatechange=function()
    {
    if(xmlHttp.readyState==4)
      {
      var result = xmlHttp.responseText;
          if(result == 'exception' || result == '')
          {
            alert('مشکل غیر منتظره. لطفاً با مدیر سیستم تماس حاصل نمائید');
          }
          if(result == 'notfound' )
          {
            alert('برای این روز ، روزنامه ای در بایگانی یافت نشد. لطفاً با مدیر سیستم تماس حاصل نمائید');
          }
          else
          {
            document.location.href = result;
          }
      }
    }
  
      var year = document.getElementById('ddlYear').options[document.getElementById('ddlYear').selectedIndex].value;
      var month = document.getElementById('ddlMonth').options[document.getElementById('ddlMonth').selectedIndex].value;
      var newspaperNumber = document.getElementById('ddlNewspaperNumber').options[document.getElementById('ddlNewspaperNumber').selectedIndex].value;
      //var day = $('ddlDay').options[$('ddlDay').selectedIndex].value;

      if (year == '' || month == '' || newspaperNumber=='')
      {
            alert('لطفاً تاریخ را به صورت دقیق وارد نمائید')
      }
      else
      {    
          // archive service url - now it works in first page !          
         //var URL = "../../../../../../../ServiceCenter/GetArchive/GetArchiveURL.aspx";
          URL += "?Year=";   
          URL += year;
          URL += "&Month=";
          URL += month;
          URL += "&NewspaperNumber=";
          URL += newspaperNumber;
//          URL += "&Day=";   
//          URL += day;
              
          xmlHttp.open("GET",URL,true);
          xmlHttp.send(null);
      }
  }