/* AAC Secção de Rugby site
   PHP & MYSQL & JS 
   Autor: Leonel Marça (leonelpalla@gmail.com)
   Site: www.leonelpalla.com
*/

function getBrowserSize()	{
	var bodyWidth = document.documentElement.clientWidth;
	var bodyHeight = document.documentElement.clientHeight;
	var bodyWidth, bodyHeight; 

	if (self.innerHeight){ // all except Explorer 
	   bodyWidth = self.innerWidth; 
	   bodyHeight = self.innerHeight; 
	}  else if (document.documentElement && document.documentElement.clientHeight) {
	   // Explorer 6 Strict Mode 		 
	   bodyWidth = document.documentElement.clientWidth; 
	   bodyHeight = document.documentElement.clientHeight; 
	} else if (document.body) {// other Explorers 		 
	   bodyWidth = document.body.clientWidth; 
	   bodyHeight = document.body.clientHeight; 
	} 
	return [bodyWidth,bodyHeight];
}

function setMaxSize(width, height, max_width, max_height, img) {
	var x_ratio = max_width / width;
	var y_ratio = max_height / height;
	
	if(!((width <= max_width) && (height <= max_height)) ){
		if ((x_ratio * height) < max_height){
			var tn_height = Math.ceil(x_ratio * height);
			var tn_width = Math.ceil((width * tn_height) / height);
		}else{
			var tn_width = Math.ceil(y_ratio * width);
			var tn_height = Math.ceil((height * tn_width) / width);
		}
		img.width = tn_width;
		img.height = tn_height;
	} else {
		img.width = width;
		img.height = height;
	}
}	

function setSize() {
	setMaxSize(this.width, this.height, 360, 500, this.imagem);
}

function setSizeRight() {
	var img = document.getElementsByName("userImg");
	
	for (var i=0;i<img.length;i++) {
		if((img[i].width && img[i].width > 360) || (img[i].height && img[i].height > 500)) {
			var newImage = new Image();
			newImage.onload = setSize;
			newImage.imagem = img[i];
			newImage.src = img[i].src;
		}
	}
}

function setSizeBanner() {
	setMaxSize(this.width, this.height, 100, 650, document.getElementById("bannerImage"));
}

function setBanner() {
	var newImage = new Image();
	newImage.onload = setSizeBanner;
	newImage.src = document.getElementById("bannerImage");
}


function setSidebarHeight(timeout) {
	var sidebar2 = document.getElementById("sidebar2");
	var sidebar3 = document.getElementById("sidebar4");
	var sidebar4 = document.getElementById("sidebar4_layout7");

	var bodyHeight = document.getElementById("container").offsetHeight - 3;
			
	if(bodyHeight > 736) {
		if(sidebar2 && sidebar2.offsetHeight != bodyHeight)
			sidebar2.style.height = bodyHeight + 'px';
		if(sidebar3 && sidebar3.offsetHeight != bodyHeight)
			sidebar3.style.height = bodyHeight + 'px';
		if(sidebar4 && sidebar4.offsetHeight != bodyHeight)
			sidebar4.style.height = bodyHeight + 'px';
	} 
	if(timeout)
		setTimeout("setSidebarHeight();",timeout);
}

function isIE6() {
	var browser=navigator.appName;
	var details=navigator.userAgent;

	if (browser.substring(0,4) == "Micr")  {
		var a=details.indexOf("MSIE") +5; 
		var b=a+3;
		
		return (details.substring(a,b) < 7.0);
	}
	
	return false;
}
