function CalcSize(normsrc,largersrc) {
	var frmWidth = getElementWidth('__aspnetForm');
	//alert("form width: " + frmWidth);
	var imgWidth = getElementWidth('imgTopBanner');
	//alert("Topbanner image width: " + imgWidth);			
	var divHMenuWidth = getElementWidth('Horizontalmenu');
	//alert("Horizontalmenu width: " + divHMenuWidth);
	
	//Window size: 1024 - form size: 926 - image size: 916
	//Window size: 1280 - form size: 1162 - image size: 1152
	var normsize = 916;
	var largersize = 1152;
	
	//if ((frmWidth-10) >= largersize) {
	if ((divHMenuWidth+6) >= largersize) {
		if (imgWidth != largersize) {
			var img = getElement('imgTopBanner');
			if (img) img.src = largersrc;
		}				
	}
	else {
		if (imgWidth != normsize) {
			var img = getElement('imgTopBanner');
			if (img) img.src = normsrc;
		}							
	}
}

function CalcMenu() {
	var DEBUG = 0;
	var menu = getElement('Horizontalmenu');
	if (menu) {
		//alert("Menu div found!");
		var menuwidth = getWidth(menu);							
		var litags = menu.getElementsByTagName("li");
		if (litags) {
			var liwsum = 0;
			var awsum = 0;
			var psum = 0;				
			for (i=0; i<litags.length; i++) {
				var li = litags[i];
				if (li) {
					var liwidth = getWidth(li);
					//alert("List element width: " + liwidth);
					liwsum += liwidth;
					
					var a = li.childNodes[0];
					if (a) {
						var p;
						if (a.style.paddingLeft && a.style.paddingLeft != '') {
							p = a.style.paddingLeft;										
						}
						else {
							p = "12px";
						}
						var pos = p.indexOf("px");
						if (pos > -1) {
							p = parseInt(p.substring(0,pos)) * 2;
						}
						else pl = 0;
						//if (DEBUG > 1) alert("p: {0}".format(p));
						var w = a.offsetWidth || 0;	
						psum += p; 
						w = w - p;
						awsum += w;
						//if (w) alert("w: " + w);																
					}
					
				}
			}
			//if (DEBUG) alert("Menu width: {0} - List-sum: {1} - Anchor-sum: {2} - Padding-sum: {3}".format(menuwidth,liwsum,awsum,psum));
			//if (DEBUG > 1) alert("Found {0} list elements".format(litags.length));					
			if (awsum <= (menuwidth-6)) {
				var spaceavail = menuwidth - 6 - awsum;
				var newpadding = parseInt(spaceavail / (litags.length * 2));
				//if (DEBUG) alert("Space available: {0} - New padding size: {1}".format(spaceavail,newpadding));						
				if (newpadding > 12 && (Math.abs(spaceavail-psum) > (litags.length * 2))) {						
					//var newliwidth = Math.floor(liwsum / litags.length);
					//if (DEBUG) alert("New list element width: " + newliwidth);						
					for (i=0; i<litags.length; i++) {
						var li = litags[i];
						//li.style.width = newliwidth + 'px';								
						var a = li.childNodes[0];
						if (a) {
							a.style.paddingLeft = newpadding + 'px';
							a.style.paddingRight = newpadding + 'px';
						}							
					}
				}						
			}
		}
	}
}			


function CalcSize_obsolete(normsrc,largersrc) {
	var frmWidth = getElementWidth('__aspnetForm');		
	var imgWidth = getElementWidth('imgTopBanner');		
	
	//Window size: 1024 - form size: 926 - image size: 916
	//Window size: 1280 - form size: 1162 - image size: 1152
	var normsize = 916;
	var largersize = 1152;
	
	if ((frmWidth-10) >= largersize) {
		if (imgWidth != largersize) {
			var img = getElement('imgTopBanner');
			if (img) img.src = largersrc;
		}				
	}
	else {
		if (imgWidth != normsize) {
			var img = getElement('imgTopBanner');
			alert("img.src: " + img.src);
			if (img) img.src = normsrc;
		}							
	}
}

function ShowSize() {
	var aW = self.screen.availWidth;
	var aH = self.screen.availHeight;
	//alert('aW: ' + aW + ' - aH: ' + aH);
	var WW = getWindowWidth();
	var WH = getWindowHeight();				
	alert('WW: ' + WW + ' - WH: ' + WH);
	var frmWidth = getElementWidth('__aspnetForm');
	alert("form width: " + frmWidth);
	var imgWidth = getElementWidth('imgTopBanner');
	alert("image width: " + imgWidth);
}

function getElementWidth( elementID ) {
	var w = 0;
	var e = getElement(elementID);
	return getWidth(e);
}; //end getElementWith( elementID )

function getWidth( e ) {
	if (e) {
		if (e.innerWidth) {			
			return e.innerWidth;
		}
		if (e.clientWidth) {
			return e.clientWidth;
		}
	}
	return 0;
}; //end getWith( e )

function setWidth( e, width ) {
	if (e) {
		if (e.innerWidth) {			
			e.innerWidth = width;
		}
		if (e.clientWidth) {
			e.clientWidth = width;
		}
	}
}; //end setWith( e )

/**
 * Returns the specified computed style on an object.
 * @param {HTMLObject} obj HTML Object
 * @param {String} styleProp Property name.
 * @return {Mixed} Computed style on object.
 */
function getStyle(obj, styleProp)
{
  if (obj.currentStyle)
    return obj.currentStyle[styleProp];
  else if (window.getComputedStyle)
    return document.defaultView.getComputedStyle(obj,null).getPropertyValue(styleProp);
}

function getElement( nameStr ) {
  if ( document.getElementById ) return document.getElementById( nameStr ); // DOM
  if ( document.all ) return document.all[ nameStr ];  // IE4
  return null;  // sorry, no NS4.
}; //end getElement( string ) -> HTML element


String.prototype.format = function()
{
	var pattern = /\{\d+\}/g;
	var args = arguments;
	return this.replace(pattern, function(capture){ return args[capture.match(/\d+/)]; });
}




// PreloadImages
function PreloadImages() 
{
	var d = document; 
	if (d.images) { 
	if(!d._p) d._p = new Array();
	var i, j=d._p.length, a=PreloadImages.arguments; 
	for (i=0; i<a.length; i++)
		if (a[i].indexOf("#") != 0) {
    		d._p[j] = new Image; 
    		d._p[j++].src = a[i];
		}
	}
}

// Waits ms milliseconds
function wait(ms)
{
	if (ms > 0) setTimeout('wait(0)', ms);
}
