﻿
 function pageLoad() {
      var manager=Sys.WebForms.PageRequestManager.getInstance();
      manager.add_beginRequest(OnBeginRequest);
      manager.add_endRequest(OnEndRequest);
      }
    function OnBeginRequest(sender,args){
       
       var postbackElementid = args.get_postBackElement().id.toLowerCase();
       if(postbackElementid) {
        if (postbackElementid == 'butsearchjob'){
         //$get("butsearchjob").disabled = true; 
        $get('PanelResultJobs').style.display = "none";
           $get('UpdateProgressJobs').style.display = "block";
        }
        else if  (postbackElementid.indexOf('story') != -1) {
        $get('ProgressBar').style.display = "none";
            
        }
        else{
           setTimeout("showProgress()",300);
         $get('ProgressBar').style.display = "none";
     }
     }
       
    }
    function showProgress(){
        // get the bounds of both the
            // gridview and the progress div
            var Img = $get('PnlEditorial');
            var ProgressBar = $get('ProgressBar');
            var ImgBounds = Sys.UI.DomElement.getBounds(Img);
            var ProgressBarBounds = Sys.UI.DomElement.getBounds(ProgressBar);
            
            //  center of gridview
            var x = 283;
                    //+ Math.round(ImgBounds.width / 2)
                    //- Math.round(ProgressBarBounds.width / 2);
            var y = 120;
                    //+Math.round(ImgBounds.height / 2)
                    //- Math.round(ProgressBarBounds.height / 2);        
    

        $get('ProgressBar').style.display = "block";
            //    set the progress element to this position
            Sys.UI.DomElement.setLocation(ProgressBar, x, y);
       //$get('TextBanner').style.display = "none";

    }
    
    function OnEndRequest(sender,args){
        //$get('UpdateProgress1').style.display = "none";
            //$get('TextBanner').style.display = "block";
        $get('ProgressBar').style.display = "none";
         //$get('PanelResultJobs').style.display = "block";
           //$get('UpdateProgressJobs').style.display = "none";
                 //$get('butsearchjob').disabled = false;
               $get('st1').className='';
               $get('st2').className='';
               $get('st3').className='';
               $get('st4').className='';
               //alert(sender._postBackSettings.sourceElement.id);
               var postbackElementid = sender._postBackSettings.sourceElement.id.toLowerCase();
                if(postbackElementid) {
        if (postbackElementid.indexOf('story') != -1){
             $get('st' + postbackElementid.substr(postbackElementid.length - 1)).className='active'; 
             
 
}
else {$get('st' + $get('LastActiveTab').value).className='active'}
}
    }    


 function loadRecentJobs(sender,e){
 
 //alert('ok');
//alert(sender.get_activeTab().get_headerText());
//var tab=$get(sender.get_activeTab().get_id());
    // Clear the results page element
    var tab=$get('TabContainer1_ctl02');
    tab.innerHTML = "";
    tab.style.height="350px";
    showProgressLatestJobs();
}
 function showProgressLatestJobs(){
        // get the bounds of both the
            // gridview and the progress div
            var Img = $get('TabContainer1_ctl02');
            var ProgressBar = $get('ProgressBarLatestJobs');
            ProgressBar.style.display = "block";
            var ImgBounds = Sys.UI.DomElement.getBounds(Img);
            var ProgressBarBounds = Sys.UI.DomElement.getBounds(ProgressBar);
            
            //  center of tabs
            var x = ImgBounds.x + Math.round(ImgBounds.width / 2)
                    - Math.round(ProgressBarBounds.width / 2);
            var y = ImgBounds.y + Math.round(ImgBounds.height / 2)
                    - Math.round(ProgressBarBounds.height / 2);        
    //alert(x);
    //alert(y);

            //    set the progress element to this position
            Sys.UI.DomElement.setLocation(ProgressBar, 200, y-50);
       //$get('TextBanner').style.display = "none";
    setTimeout("showLatestJobs()",800);

    }
function showLatestJobs(){
    
//alert(tab.innerHTML);
//alert(sender.get_activeTab());
//__doPostBack('TabContainer1', tab);
// Instantiate the WebRequest object.
    var wRequest =  new Sys.Net.WebRequest();
    
    // Set the request Url.  
    wRequest.set_url('Default.aspx?lj=1');  
    
    // Set the request verb.
    wRequest.set_httpVerb("GET");
          
    // Set user's context
    wRequest.set_userContext("user's context");
    
            
    // Set the web request completed event handler,
    // for processing return data.
    wRequest.add_completed(OnWebRequestCompleted);
       
      
    
    // Execute the request.
    wRequest.invoke();  
}

function OnWebRequestCompleted(executor, eventArgs) 
{
    if(executor.get_responseAvailable()) 
    {
        
        
        //displayElement.innerHTML = "";
        // Clear the previous results. 

   var tab=$get('TabContainer1_ctl02');
   tab.innerHTML=executor.get_responseData();
  // alert(tab.innerHTML);
     //alert(executor.get_responseData());
     $get('ProgressBarLatestJobs').style.display = "none";
    }
    else
    {
        if (executor.get_timedOut())
            alert("Timed Out");
        else
            if (executor.get_aborted())
                alert("Aborted");
    }
}


