﻿// Common javascript for printing
// this function will be called on client side to post back real time on client side

    function setDateTime()
    {
       var node = document.getElementById("form1") ;
       if (node != null)
       {
            var timeNode = document.getElementById("currentTime");
            if (timeNode != null)
            {
                currentDate = new Date();
                timeNode.value = currentDate.getFullYear() + "/" + (currentDate.getMonth() + 1) +"/" + currentDate.getDate()+" " + currentDate.getHours()+":"+currentDate.getMinutes();
            }
       }
    }

    function foward()
    {
        if(window.history.forward(1) != null)
           window.history.forward(1);
    }
    
    function goBack()
    {
        this.history.go(-1); 
    }
    
    function ClosePage(){
    var topLayer= null;
   
   try{
    topLayer=window.top.document.getElementById(window.top._PrintLayer);
   
    }catch(e){}
       if( topLayer!= null){
         topLayer.style.display = 'none';
          self.close();
         }
       else {
         //This closes without warning.
            window.opener=self;window.close();
        }
          
        return false;
    
    }

   function postback()
    {
        this.focus();
        var flag=  "false";
        var node = document.getElementById("PostBackFlag"); 
        if (node != null)
          flag = node.value ;
        if (flag == "true")
        {      
           var node = document.getElementById("form1") ;
           if (node != null)
           {
                node.submit();   // after submit, "flag" value will be modified by server side.
                showLoading();
           }
        }
    }
    function getObject(id)
	{
		return document.getElementById(id);		
	}
	function hideLoading()
	{
		var loadObj=getObject("LoadDiv");
	    hideObject(loadObj);
	}
	function showLoading()
	{
		var loadObj=getObject("LoadDiv");
		showObject(loadObj);
	}
    function showObject(theObj) 
	{		
	  	if(theObj)
	  		theObj.style.visibility = "visible";
	}	
    function hideObject(theObj) 
	{		
	  	if(theObj)
	  		theObj.style.visibility = "hidden";
	}	
	
   function GetJoinData(layerId, rootFeatureId, joinId, originRowId, invisibleJoinId, divId, joinLinkImageId, expandedImageUrl, collapsedImageUrl)
   {
                               
      if(!sessionExpired)
      {
          if(layerId != null && rootFeatureId != null && joinId != null && originRowId != null && divId != null &&  joinLinkImageId != null && expandedImageUrl != null && collapsedImageUrl != null)
          {   
            var divElem = document.getElementById(divId);
              var joinLinkImgElem = document.getElementById(joinLinkImageId);
          
              if(divElem != null && joinLinkImgElem != null)
              {	        
                  try
                  {		                	                
                      var hasChildNodesValue = divElem.getAttribute("hasChildNodes");	                              
                      if(hasChildNodesValue == "false")
                      {	           
                          var infoControlObj = InfoControl;         
                          if(infoControlObj != null)
                          {            
                              var joinHtml = PageMethods.GetJoinInfoHTML(layerId, rootFeatureId, joinId, originRowId, invisibleJoinId);	                    
                              divElem.innerHTML = joinHtml.value;
                              divElem.setAttribute("hasChildNodes", "true");
                             
                            }
                          else
                          {
                            //alert("info control object is null.");
                          }
                      }                           
                      if(divElem.style.visibility == "hidden")
                    {
                        divElem.style.visibility = 'visible';
                        divElem.style.display  = 'block';

                        var imgExpand = new Image();
                        imgExpand.src = expandedImageUrl;
                        joinLinkImgElem.src = imgExpand.src;
                        joinLinkImgElem.title = "Expand";  
                        
                    }
                    else
                    {
                        divElem.style.visibility = 'hidden';
                        divElem.style.display  = 'none';

                        
                        var imgCollapse = new Image();
                        imgCollapse.src = collapsedImageUrl; 

                        joinLinkImgElem.src = imgCollapse.src;
                        joinLinkImgElem.title = "Collapse";                  
                    }                    
                }
                catch(e)
                {   
                    alert(e.value);              
                }
              }                   
          }          
       }
   else
	    {
	        HandleSessionExpired();
	    }
}
