var errCenterTo="idCenterPartContainer";

function GetRadioButtonValue(formElement){
	myOption = -1;
	for (i=formElement.length-1; i > -1; i--) {
		if (formElement[i].checked) {
			myOption = i; i = -1;
		}
	}
	if (myOption == -1) return false;
	return formElement[myOption].value;
}

function closeErrorBox(){
	win.style.visibility='hidden';
	EnableAllFormElements();
	objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'none';
	ErrMsg=[];
	if(ItemToFocus != "")	$(ItemToFocus).focus();
}

function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

function showErrorBox(errTitle){
	var msgT='<p class="errTitle">'+errTitle+'</p>';
	objOverlay = document.getElementById('overlay');
	objOverlay.style.display = 'block';
	objOverlay.style.zIndex = '90';
	objOverlay.style.width = '100%';
	objOverlay.style.height = '100%';
	var arrayPageSize = getPageSize();
 	objOverlay.style.height = (arrayPageSize[1] + 'px');
	 	
	var msg = msgT+'<p class="errList">';
	for (var i = 0; i < ErrMsg.length; i++) {
		msg += '<p class="errList">'+ErrMsg[i]+'</p>';
	}
	$("errorBoxButton").onclick = function() { closeErrorBox(); }
	$("errorBoxContent").innerHTML = msg;
	$("errorBoxContentHGB").style.height = ($('errorBoxContentContainer').offsetHeight - 11 - 9) + "px";
	win=$('errorBox');

	var gl=$(errCenterTo);
	var d=($(errCenterTo).scrollWidth-win.scrollWidth)/2+10;
	var coors = findPos(gl);
	win.style.top = coors[1] + 50 + 'px';
	win.style.left = coors[0]+ d + 'px';

	DisableAllFormElements();
	win.style.visibility='visible';
	win.style.zIndex=91;
	win.style.display='block';
}

function DisableAllFormElements(){
	for(var iForm=0;iForm<document.forms.length;iForm++) {
		for (var i=0; i < document.forms[iForm].elements.length; i++){
			element=document.forms[iForm].elements[i];
			element.disabled = "disabled";
		}
	}
}

function EnableAllFormElements(){
	for(var iForm=0;iForm<document.forms.length;iForm++) {
		for (var i=0; i < document.forms[iForm].elements.length; i++){
			element=document.forms[iForm].elements[i];
			element.disabled = false;
		}
	}
}

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;
}

