﻿// JScript File
    
    var CurrIndex = 0;
    //Sapinder 18-Sep-2007
    var adPositions=new Array();
    adPositions[0]=0;
    var currentIndex;
    var shownNextPositions=0;
    var shownPrevPositions=0;
    
    //A timer will be fired in 4 seconds to call getNextImage()
    var c_interval = 4000;
    var timerID ; //= window.setInterval("getNextImage()", c_interval);
    
    var running = false;
   
        
    function getNextImage()
    {
    //alert(document.getElementById('ctl00_ContentPlaceHolder1_SliderViewerUC1_hdnCurrIndex')+"mani");
        var _index = document.getElementById('SliderViewerUC1_hdnCurrIndex');
     
        var _hdnRequestedFor = document.getElementById('SliderViewerUC1_hdnRequestedFor');
        if (running) 
        {
           //Send the request to server with the current image url as the argument
           //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "NEXT" + "," +  _index.value + "," + "0" + "," + _hdnRequestedFor.value , "");          
           
           //Sapinder 18-Sep-07
           for(var x=0;x<adPositions.length;x++)
           {
                if(adPositions[x]==(parseInt(CurrIndex)+1) && adPositions[x]!=shownNextPositions)
                {
                    currentIndex=(parseInt(CurrIndex)+1)+"#Y";
                    shownNextPositions=adPositions[x];
                    break;
                }
                else
                {
                    currentIndex=(parseInt(CurrIndex)+1)+"#N";
                    if(adPositions.length==1)
                    {
                        shownNextPositions=0;
                    }
                }
           }
           //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "NEXT" + "," +  currentIndex + "," + "0" + "," + _hdnRequestedFor.value , "");          
           CallServer(document.getElementById("SliderViewerUC1_photo").src + "," +  "NEXT" + "," +  currentIndex + "," + "0" + "," + 0 , "");          
        }
    }
              
    function ReceiveServerData(rValue)
    {
        //Receive server's response of a string rValue, which is prepared in the server's function
        //GetCallbackResult()
        var wds = rValue.split("#@#@#");
        CurrIndex=wds[1];
        
        
        //Assign the transition effect
        document.getElementById("SliderViewerUC1_photo").style.filter = wds[2];
        //Preload the image file from server.  When finishing download, imageLoaded function will be called
        //with the img object as the argument                           
        var img  = new Image();
        img.src = wds[0];  
        img.onload = function(){ imageLoaded(this); }
        img.onerror = function(){ imageError(this); }
        img.onabort = function(){ imageError(this); }
        
        var _imgPhoto = document.getElementById("SliderViewerUC1_photo");
        if(_imgPhoto != null)
           _imgPhoto.src = wds[0];
        
        var _divPhoto = document.getElementById("SliderViewerUC1_divPhotoArea");
        var _divAd = document.getElementById("SliderViewerUC1_divAdArea");
        var _divRatingQuad = document.getElementById("RatingProduct");
        var _RHSAdMessage = document.getElementById("SliderViewerUC1_RHSAdMessage");
        var _divTopPhotosCountText = document.getElementById("divTopPhotosCountText");
        var _divBottomPhotosCount = document.getElementById("divBottomPhotosCount");
        
        var _divTopSkipAd = document.getElementById("divTopSkipAd");
        var _divBottomSkipAd = document.getElementById("divBottomSkipAd");
        
        if(wds[14] == "NONE")
        { 
          if(_divPhoto != null)
             _divPhoto.style.display = "block";
          
          if(_divAd != null)
             _divAd.style.display = "none";
             
          if(_divRatingQuad != null)
             _divRatingQuad.style.display = "block";
             
          if(_RHSAdMessage != null)
             _RHSAdMessage.style.display = "none";
             
          if(_divTopPhotosCountText != null)
             _divTopPhotosCountText.style.display = "block";
             
          if(_divBottomPhotosCount != null)
             _divBottomPhotosCount.style.display = "block";
              
          if(_divTopSkipAd != null)
             _divTopSkipAd.style.display = "none";
             
          
          if(_divBottomSkipAd != null)
             _divBottomSkipAd.style.display = "none";
             
          
        }
        else 
        {      
            if(_divAd != null)
            {
               _divAd.style.display = "block";
               _divAd.innerHTML = wds[14];
            }         
         
            if(_divRatingQuad != null)
                _divRatingQuad.style.display = "none";
          
           if(_divPhoto != null)
             _divPhoto.style.display = "none";

           if(_RHSAdMessage != null)
             _RHSAdMessage.style.display = "block";
             
           if(_divTopPhotosCountText != null)
             _divTopPhotosCountText.style.display = "none";
             
           if(_divBottomPhotosCount != null)
             _divBottomPhotosCount.style.display = "none";
             
           if(_divTopSkipAd != null)
             _divTopSkipAd.style.display = "block";
             
          
          if(_divBottomSkipAd != null)
             _divBottomSkipAd.style.display = "block";
        }
        var _hdnRequestedFor = document.getElementById('SliderViewerUC1_hdnRequestedFor');
        if(_hdnRequestedFor != null)
        {
           _hdnRequestedFor.value  = wds[14];
        }
        
        var _hdnfield = document.getElementById('SliderViewerUC1_hdnCurrIndex');
        if(_hdnfield != null)
        {
           _hdnfield.value  = wds[1];
        }           
        
        var _CurrPhotoIndex = document.getElementById('SliderViewerUC1_lblCurrPhotoIndex'); 
        var _topCurrPhotoIndex = document.getElementById('SliderViewerUC1_lblTopCurrPhotoIndex'); 
        if(_CurrPhotoIndex != null)
        {
           _CurrPhotoIndex.innerHTML =  parseInt(wds[1]) + parseInt('1');
        }
        if(_topCurrPhotoIndex != null)
        {
           _topCurrPhotoIndex.innerHTML =  parseInt(wds[1]) + parseInt('1');
        }
       
        // For Title of the Image /Category Description                       
        var _lnkTitleOfTheImage = document.getElementById('SliderViewerUC1_lnkTitleOfTheImage'); 
        if(_lnkTitleOfTheImage != null)
           _lnkTitleOfTheImage.innerHTML = wds[3];
           
        
       
        // Credit Line /Mail Link
        var _lblSsource = document.getElementById('SliderViewerUC1_lblSsource'); 
        if(_lblSsource != null)       
        {
           _lblSsource.innerHTML =  wds[4]
        }  
        
        
        // Location & DateLine of the Photo
        var _lblLocationNDateLine = document.getElementById('SliderViewerUC1_lblLocationNDateLine'); 
        if(_lblLocationNDateLine != null)       
        {
           _lblLocationNDateLine.innerHTML =  wds[5]
        }    
        
        // First Published of the Photo
        var _lblPublishedDate = document.getElementById('SliderViewerUC1_lblPublishedDate'); 
        if(_lblPublishedDate != null)       
        {
           _lblPublishedDate.innerHTML =  wds[6]
        }    
        
        // Last Updated Date of the Photo
        var _lblUpdateDate = document.getElementById('SliderViewerUC1_lblUpdateDate'); 
        if(_lblUpdateDate != null)       
        {
           _lblUpdateDate.innerHTML =  wds[7]
        }    
      
        // Kicker of the Photo
        var _lblKicker = document.getElementById('SliderViewerUC1_lblKicker'); 
        if(_lblKicker != null)       
        {
           _lblKicker.innerHTML =  wds[8]
        }    
        
        // Division for Related Item Control
        var _divAlsoSee = document.getElementById('SliderViewerUC1_divAlsoSee'); 
        if(_divAlsoSee != null)       
        {
           _divAlsoSee.innerHTML =  wds[9]
        }   
        
        // Division for Related Item Control
        var _divHaveYourSay = document.getElementById('SliderViewerUC1_divHaveYouSay'); 
        if(_divHaveYourSay != null)       
        {
           _divHaveYourSay.innerHTML =  wds[10]
        }   
         
        // Division for Action Item Control
        var _divphotoslideroption1 = document.getElementById('SliderViewerUC1_photoslideroption1'); 
        if(_divphotoslideroption1 != null)       
        {
           _divphotoslideroption1.innerHTML =  wds[11]
        }   
        
        // Division for Feedback Bottom Control
        var _divFeedbackBottomlinks = document.getElementById('SliderViewerUC1_divFeedbackBottomlinks'); 
        if(_divFeedbackBottomlinks != null)       
        {
           _divFeedbackBottomlinks.innerHTML = wds[12]
        }   
        
        if(wds[13] != "")
        {
          //show the PollOptiondiv & hide the ProgressBarDiv
          document.getElementById('RatingProduct').style.display = "block";
          document.getElementById('ProgressImageDiv').style.display = "none";
          document.getElementById('Rating_Old').style.display = "none";
          document.getElementById('Rating_New').style.display = "block";
          
          var splitresRating;
          splitresRating = wds[13].split(" ");
  
          //check whether the user has already polled for the given pollid, and show the message
          //that we havn't treated the values provided by him
          if(splitresRating[1] == "1")
          {
             alert("Sorry, You can't rate the same Photo twice");
          }
	      else if(splitresRating[0]=="")
	      {
             alert("Sorry, You can't rate the same Photo twice");
	      }
	      else if(splitresRating[0]!="")
	      {
	         document.getElementById('inputrating').src = "../Images/Site/Rating-0" + splitresRating[0] + ".gif";
	      }
          // calculate the new product rating giving the current rating and raters count.
          var k;
          var j = splitresRating[2];

         var spanCount = document.getElementById('SliderViewerUC1_lblRatersCounting');
         if(spanCount != null)
           spanCount.innerText = "Number of votes cast : " + splitresRating[3];
    
            
          var tmpElemStr;
          for(k = 0; k < splitresRating[2]; k++)
          {
             var s;
             s = k+ 1;
             tmpElemStr = 'rating_rate'+ s;
             var idTEMP = document.getElementById(tmpElemStr);
             if(idTEMP != null)
                idTEMP.src = "../Images/Site/rateimage.gif";
          }
          
          var tmpElementStrP;
          if(splitresRating[2] == "0")
          {
             for(p = 0; p < 5; p++)
             {
                var sp;
                sp = p + 1;
                tmpElementStrP = 'rating_rate'+ sp;
                var idTEMPP = document.getElementById(tmpElementStrP);
                if(idTEMPP != null)
                   idTEMPP.src = "../Images/Site/rateimage1.gif";
             }
          }
         
          tmpElemStr = "";
          var t = "-1";
          for(k = splitresRating[2]; k < 5; k++)
          {             
             if(t == "-1")
             {
                t = s + 1;
             }
             else
             {
                t = t + 1;
             }
             tmpElemStr = 'rating_rate'+ t;
             var iTeElement = document.getElementById(tmpElemStr);
             if( iTeElement != null)
             {    
                iTeElement.src = "../Images/Site/rateimage1.gif";
             }
          }  
       }
       
      
    }
    
    function imageError(img)
    {
        alert('Error Occurs.');
        //If image download errors occur, this function will be called.
        window.setInterval("getNextImage()", c_interval);
    }
    function imageLoaded(img)
    {
        var photo = document.getElementById("SliderViewerUC1_photo");   //Find the image control object
        photo.src = img.src;                            //Assign the image to the image control
        photo.filters[0].apply();                       //Apply the transition effect
        photo.filters[0].play();                        //Play the effect and display the new image
        
        
        //window.setInterval("getNextImage()", c_interval);//Initiate the next request
    }
    
    // slider [Play/Pause] as toggle
    function SliderPause()
    {
       if (running)
        {
          running=false;
          window.clearTimeout(timerID);
          timerID =0;
          document.getElementById('SliderViewerUC1_imgPausePlay').src = "images/play.gif"; 
          document.getElementById('SliderViewerUC1_imgPausePlayBottom').src = "images/play.gif"; 
          
       } 
       else
       {
          running = true;
          window.setInterval("getNextImage()", c_interval);
          document.getElementById('SliderViewerUC1_imgPausePlay').src = "images/pause.gif"; 
          document.getElementById('SliderViewerUC1_imgPausePlayBottom').src = "images/pause.gif"; 
       }
    }
    
    // Move to Previous Image
    function SliderPrevious()
    {
        running = false;
	shownNextPositions=0;
        document.getElementById('SliderViewerUC1_imgPausePlay').src = "images/play.gif"; 
        document.getElementById('SliderViewerUC1_imgPausePlayBottom').src = "images/play.gif"; 
        var _index = document.getElementById('SliderViewerUC1_hdnCurrIndex');
        var _hdnRequestedFor = document.getElementById('SliderViewerUC1_hdnRequestedFor');
        
        //Send the request to server with the current image url as the argument
        //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "PREV" + "," +  _index.value + "," + "0" + "," + _hdnRequestedFor.value, "");
        //Sapinder 18-Sep-07
       for(var x=0;x<adPositions.length;x++)
       {
            if(adPositions[x]==(parseInt(CurrIndex)) && adPositions[x]!=shownPrevPositions)
            {
                currentIndex=(parseInt(CurrIndex)-1) +"#Y";
                shownPrevPositions=adPositions[x];
                break;
            }
            else
            {
                currentIndex=(parseInt(CurrIndex)-1)+"#N";
                if(adPositions.length==1)
                {
                    shownPrevPositions=0;
                }
            }
       }
        //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "PREV" + "," +  currentIndex + "," + "0" + "," + _hdnRequestedFor.value, "");                    
        CallServer(document.getElementById("SliderViewerUC1_photo").src + "," +  "PREV" + "," +  currentIndex + "," + "0" + "," + 0, "");                    
    }
    
    // Move to Next Image
    function SliderNext()
    {
        running = false;
	shownPrevPositions=0;
        document.getElementById('SliderViewerUC1_imgPausePlay').src = "images/play.gif"; 
        document.getElementById('SliderViewerUC1_imgPausePlayBottom').src = "images/play.gif"; 
       var _index = document.getElementById('SliderViewerUC1_hdnCurrIndex');
       var _hdnRequestedFor = document.getElementById('SliderViewerUC1_hdnRequestedFor');
       
       //Send the request to server with the current image url as the argument
       //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "NEXT" + "," +  _index.value + "," + "0" + "," + _hdnRequestedFor.value, "");          
       
       //Sapinder 18-Sep-07
       for(var x=0;x<adPositions.length;x++)
       {
            if(adPositions[x]==(parseInt(CurrIndex)+1) && adPositions[x]!=shownNextPositions)
            {
                currentIndex=(parseInt(CurrIndex)+1)+"#Y";
                shownNextPositions=adPositions[x];
                break;
            }
            else
            {
                currentIndex=(parseInt(CurrIndex)+1)+"#N";
                if(adPositions.length==1)
                {
                    shownNextPositions=0;
                }
            }
       }
       //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "NEXT" + "," +  currentIndex + "," + "0" + "," + _hdnRequestedFor.value, "");          
       CallServer(document.getElementById("SliderViewerUC1_photo").src + "," +  "NEXT" + "," +  currentIndex + "," + "0" + "," + 0, "");          
    }
    
    // Call skip advertise and move to next image
    function SkipAdvertise()
    {
        running = true;
        document.getElementById('SliderViewerUC1_imgPausePlay').src = "images/play.gif"; 
        document.getElementById('SliderViewerUC1_imgPausePlayBottom').src = "images/play.gif"; 
        var _index = document.getElementById('SliderViewerUC1_hdnCurrIndex');
        var _hdnRequestedFor = document.getElementById('SliderViewerUC1_hdnRequestedFor');
     
       // Send the request to server with the current image url as the argument
       //CallServer(document.getElementById("ctl00_ContentPlaceHolder1_SliderViewerUC1_photo").src + "," +  "SKIP" + "," +  _index.value + "," + "0" + "," + _hdnRequestedFor.value, "");          
       CallServer(document.getElementById("SliderViewerUC1_photo").src + "," +  "SKIP" + "," +  _index.value + "," + "0" + "," + 0, "");          
    }
    
   // Method to Set Css class for[OnMouseOver] Tab control
   function AOnMouseOver(id)
   {
       document.getElementById(id).style.cursor = 'pointer';
   }
    
   // Method to Set Css class for[OnMouseOut] Tab control
   function AOnMouseOut(id)
   {
      document.getElementById(id).style.textDecoration = 'none';
   }
   
   
   function CallRateServerNow()
   {
       var res;  
       var radinput1 = 'SliderViewerUC1_radioinput1';
       var radinput2 =  'SliderViewerUC1_radioinput2';
       var radinput3 =  'SliderViewerUC1_radioinput3';
       var radinput4 =  'SliderViewerUC1_radioinput4';
       var radinput5 =  'SliderViewerUC1_radioinput5';
       var _countTempVal = radinput1;
       var _countTempVal2 = radinput2;
       var _countTempVal3 = radinput3;
       var _countTempVal4 = radinput4;
       var _countTempVal5 = radinput5;
          
       var _someVal;
 
          
        if(document.getElementById(_countTempVal).checked == true)
        {
            res = "1";
            document.getElementById(_countTempVal).checked = false;
        }
          
        if(document.getElementById(_countTempVal2).checked == true)
         {
            res = "2";
            document.getElementById(_countTempVal2).checked = false;
         }
        if(document.getElementById(_countTempVal3).checked == true)
         {
            res = "3";
            document.getElementById(_countTempVal3).checked = false;
         }
        if(document.getElementById(_countTempVal4).checked == true)
         {
            res = "4";
            document.getElementById(_countTempVal4).checked = false;
         }
        if(document.getElementById(_countTempVal5).checked == true)
         {
            res = "5";
            document.getElementById(_countTempVal5).checked = false;
         }
       
        //hide the PollOptiondiv
        document.getElementById('RatingProduct').style.display = "none";
          //alert(res);
        //show the ProgressBarDiv
        document.getElementById('ProgressImageDiv').style.display = "block";
        
        running=false;
        window.clearTimeout(timerID);
        timerID =0;
        var PlayPauseId = document.getElementById('SliderViewerUC1_imgPausePlay');
        
        if(PlayPauseId != null)
            PlayPauseId.src = "images/play.gif"; 
        
        var PlayPauseBottomId = document.getElementById('SliderViewerUC1_imgPausePlayBottom');
           
        if(PlayPauseBottomId != null)
            PlayPauseBottomId.src = "images/play.gif"; 
          
        var _index = document.getElementById('SliderViewerUC1_hdnCurrIndex');
        //Send the request to server with Current Rating as the argument
        CallServer(document.getElementById("SliderViewerUC1_photo").src + "," +  "NONE" + "," +  _index.value + "," + res, "");          
   }
   
   function CallSliderInterval(IntervalValue)
   {
     c_interval = IntervalValue;
     window.clearTimeout(timerID);
     timerID = window.setInterval("getNextImage()", c_interval);
     running=true;
     var PauseImgId = document.getElementById('SliderViewerUC1_imgPausePlay');
     
     if(PauseImgId != null)
        PauseImgId.src = "images/pause.gif"; 
     var PauseBottomImgId = document.getElementById('SliderViewerUC1_imgPausePlayBottom');
     
     if(PauseBottomImgId != null)
        PauseBottomImgId.src = "images/pause.gif"; 
   }
