﻿function browserWindowSize(){
    var intWidth = 0; 
    var intHeight = 0;
    if( typeof( window.innerWidth ) == 'number' ) 
    {
      intWidth = window.innerWidth;
      intHeight = window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
      intWidth = document.documentElement.clientWidth;
      intHeight = document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
      intWidth = document.body.clientWidth;
      intHeight = document.body.clientHeight;
    }
    document.getElementById("ctl00_hdSW").value = intWidth;
    document.getElementById("ctl00_hdSH").value = intHeight;
    };
  
// Call this function to start synchronization of scrolling in Training Plan Details  
function SyncTP() {
  if(document.getElementById("ctl00_cp1_divTPTableHeadings")== null)
  {
    alert("null");
  }
	addScrollSynchronization(document.getElementById("ctl00_cp1_divTPTableHeadings"),document.getElementById("ctl00_cp1_divTPTableBody"), "horizontal");
	addScrollSynchronization(document.getElementById("ctl00_cp1_divTPRowHeadings"),document.getElementById("ctl00_cp1_divTPTableBody"),  "vertical");
}
    
// This is a function that returns a function that is used
// in the event listener
function getOnScrollFunction(oElement) {
	return function () {
		if (oElement._scrollSyncDirection == "horizontal" || oElement._scrollSyncDirection == "both")
			oElement.scrollLeft = event.srcElement.scrollLeft;
		if (oElement._scrollSyncDirection == "vertical" || oElement._scrollSyncDirection == "both")
			oElement.scrollTop = event.srcElement.scrollTop;
	};

}
// This function adds scroll syncronization for the fromElement to the toElement
// this means that the fromElement will be updated when the toElement is scrolled
function addScrollSynchronization(fromElement, toElement, direction) {
	removeScrollSynchronization(fromElement);
	
	fromElement._syncScroll = getOnScrollFunction(fromElement);
	fromElement._scrollSyncDirection = direction;
	fromElement._syncTo = toElement;
	toElement.attachEvent("onscroll", fromElement._syncScroll);
}

// removes the scroll synchronization for an element
function removeScrollSynchronization(fromElement) {
	if (fromElement._syncTo != null)
		fromElement._syncTo.detachEvent("onscroll", fromElement._syncScroll);

	fromElement._syncTo = null;;
	fromElement._syncScroll = null;
	fromElement._scrollSyncDirection = null;
}