window.onload = initPage;

function initPage()
{
	__dnn_Page_OnLoad();
	wsOnLoad();
	//onLoadPrint();
}

function wsGetParameter(name)
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp(regexS);
  var results = regex.exec(window.location.href);
  if(results == null)
	return '';
  else
	return results[1];
}


function wsOnLoad() {
	var ar_name = wsGetParameter('ar');
	if (ar_name != '')
	{
		var x=document.getElementsByName(ar_name);
		if (x != null && x.length != 0)
		{
			var obj = x[0];
			var offsetTop = obj.offsetTop;
			if (obj.offsetParent) {
				while (obj = obj.offsetParent)
					offsetTop += obj.offsetTop;
			}
			
			window.scrollTo(0, offsetTop);
		}
	}
}


/*
function xPageY(e)
{
  var y = 0;
  while (e) {
    if (xDef(e.offsetTop)) y += e.offsetTop;
    //e = xDef(e.offsetParent) ? e.offsetParent : null;
	return y;
  }
  return y;
}
function xDef()
{
  for(var i=0; i<arguments.length; ++i){if(typeof(arguments[i])=='undefined') return false;}
  return true;
}

function onLoadPrint(){
	var a = new String(window.location.search);	
	if (a.length > 6) {
		a = a.substring(a.length - 6, a.length);
		if (a == '&prt=1') {
			var PAGE_LENGTH = 725;
			var currentTop = 0;
			var arrayOfElements = document.getElementsByTagName("TR");
			for (var i = 0; i < arrayOfElements.length; i++){
				if (xPageY(arrayOfElements[i]) - currentTop > PAGE_LENGTH){
					arrayOfElements[i - 1].style.pageBreakBefore = "always";
					currentTop = xPageY(arrayOfElements[i - 1]);
					PAGE_LENGTH = 650;
				}
			}
		} else if (a == '&prt=2') {
			var pgCnt, pgHeight, collp;
			pgCnt = 1;
			collp = document.getElementsByTagName("TR");			
			pgHeight = 600;
			if (collp[0] != null)
				for (var i = 0;i < collp.length;i++) {
					var tr = collp[i];
					if (tr.offsetHeight < pgHeight)
						if ( (tr.offsetTop / (pgCnt * pgHeight)) > 1) {
							tr.style.pageBreakBefore = "always";							
							pgCnt++;pgHeight = 700;}}}
		}
	}
}
*/
