﻿/// Created By: Gurinder Bagga 04 Aug,2008
/// Project:    NatGeo Junior.
/// ***********Java script file to add functions for javascript to be used
///****** in admin pages.



/// Functions common for all




  function AdminDeleteConfirm()
  {
     var flag=confirm("Do you want to delete this Record?");
     
     return flag;
     
  }


 function showCal(divid)
 {
    var obj=document.getElementById(divid);
    
    obj.style.visibility='visible';
    obj.style.display='inline';
 
 }



///-- End of Functions common for all.

/// Function to show youtube videos....

function ShowVideoYouTube(EmbedObject,EmbedObjectInner,EmbedObjectText)
{
    var obj = document.getElementById(EmbedObject);
    obj.style.display = "block";
    obj.style.backcolor = "#cccccc";
    obj.style.visibility = 'visible';
    var objInner = document.getElementById(EmbedObjectInner);
    var idx = EmbedObjectText.indexOf( "||" );
    while ( idx > -1 )
    {
        EmbedObjectText = EmbedObjectText.replace( "||", "'" ); 
        idx = EmbedObjectText.indexOf( "||" );
    }
    objInner.innerHTML = EmbedObjectText;
}

function Close(Obj,ObjInner)
{
  document.getElementById(Obj).style.visibility='hidden';
  document.getElementById(Obj).style.display='none';
  document.getElementById(ObjInner).innerHTML = "";
}


///-- end of function for youtube videos...
///---Ajax function starts here ----------///


         var xmlhttpObj;
         var callbackText;
         
         function initHttp() 
         {
            if (window.XMLHttpRequest) //for firefox
             {
                return new XMLHttpRequest();
             }
             else if (window.ActiveXObject)//for IE
              {
                try {
                     return
                      new ActiveXObject("Microsoft.XMLHTTP");
                    }catch(e)
                    {
                      return new ActiveXObject("Msxml2.XMLHTTP"); 
                    }
               }
            }
            ///Impmentation of Ajax call to ashx file
            
          function UpdatePublish(id,Sender)
          {
              xmlhttpObj=initHttp();
           
             // alert(Sender.checked);
              if(Sender)
              { if(Sender.checked)
                 {
                xmlhttpObj.open('POST','RequestHandler.ashx?FastFactId='+id+"&Published=true");
                //alert(document.getElementById('lbl'+id).innerHTML);
                document.getElementById('lbl'+id).innerHTML="Published";
                Sender.valueOf="Published";
                }
                else
                {
                 xmlhttpObj.open('POST','RequestHandler.ashx?FastFactId='+id+"&Published=false");
                 document.getElementById('lbl'+id).innerHTML="Unpublished";
                 Sender.valueOf="Unpublished";
                }
                xmlhttpObj.send(null);
                xmlhttpObj.onreadystatechange=function()
                            {
                              //
                              // --checking for ready state
                              //
                              if(xmlhttpObj.readyState==4)
                              {
                                if(xmlhttpObj.status==200)
                                {
                                  //scuccess of ajax call;
                                  callbackText=xmlhttpObj.responseText;
                                  //check for true or false return.
                                  
                                    if(callbackText=="true")
                                    {
                                       //reload the window.
                                      // window.location.reload();
                                    }
                                    else if(callbackText=="false")
                                    {
                                      /// theres an error.
                                      alert("Oops!! There's an error executing your request.");
                                    }
                                  return callbackText;
                                }
                                else
                                {
                                 // alert(xmlhttpObj.status);
                                }
                        }
             
              return callbackText;
             }
               }      
          }
          