// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function addFormEvent(func) {
  if (!document.getElementById | !document.getElementsByTagName) return
	var oldonload=window.onload
	if (typeof window.onload != 'function') { window.onload=func }
	else {
		window.onload=function() { oldonload(); func() }
	}
}

function attachBorderAndSelect(){
  var obj0 = document.getElementsByTagName('input')
  for (var i = 0; i < obj0.length; i++) {	
    if (obj0[i].className.indexOf('txt-field') != -1){
		obj0[i].onfocus= function() {
					  this.style.background="#f4f5da"; 
					  if (this.value==this.defaultValue) {
	  					  this.value = '';
						  }
					}
		obj0[i].onblur = function() {
					  this.style.background="#ffffff"
					  if (this.value=="") {this.value=this.defaultValue}
					  this.value=this.value
					}
		}
  }
}

function textCounter(field,cntfield,maxlimit) {
	if (field.value.length > maxlimit) // if too long...trim it!
	field.value = field.value.substring(0, maxlimit);
	// otherwise, update 'characters left' counter
	else
	document.getElementById(cntfield).innerHTML = maxlimit - field.value.length;
}

addFormEvent(attachBorderAndSelect)

function openWindow( pageToLoad, winName, width, height, center, x, y) {		 
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
	}
	args = "width=" + width + "," 
	+ "height=" + height + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=1,"
	+ "scrollbars=1,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "screenx=" + x + ","  //NN Only
	+ "screeny=" + y + ","  //NN Only
	+ "left=0" + xposition + ","     //IE Only
	+ "top=0" + yposition;           //IE Only
	window.open( pageToLoad,winName,args );
}

//called by the NavigateUrl property of the hlBack on Entry.aspx
function backFromEntry(){
		if(history.length > 1){
			history.back()
		}
		else{
			window.location = "Default.aspx"
		}
}