// JavaScript Document

//== get sizes of page to extend left menu ===================================================================================================

function alertSize() {
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  //alert(myHeight);
  document.getElementById("viewingArea").style.height = myHeight-176+'px';
  document.getElementById("leftMenuDiv").style.height = myHeight-167+'px';
}

//== various page measurements ===================================================================================================

function pageWidth() {
	return window.innerWidth != null? window.innerWidth : document.documentElement && document.documentElement.clientWidth ?       document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
} 

function pageHeight() {
	return  window.innerHeight != null? window.innerHeight : document.documentElement && document.documentElement.clientHeight ?  document.documentElement.clientHeight : document.body != null? document.body.clientHeight : null;
}

function posLeft() {
	return typeof window.pageXOffset != 'undefined' ? window.pageXOffset :document.documentElement && document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft ? document.body.scrollLeft : 0;
}

function posTop() {
	return typeof window.pageYOffset != 'undefined' ?  window.pageYOffset : document.documentElement && document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop ? document.body.scrollTop : 0;
} 

function posRight() {
	return posLeft()+pageWidth();} function posBottom() {return posTop()+pageHeight();
}

//== navigation functions ===================================================================================================

function MM_goToURL() { //v3.0
	var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
	for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

//== empty text box on click ===================================================================================================

function emptyTextBox(myElement) {
	if(myElement.value == 'enter your postcode'){
		myElement.value = "";
	}
}

//== place scaled images on pages depending on surrounding div size ===================================================================================================

function placeImage(imageSrc,imageAlt,imgID){
	//get image size
	var newImg = new Image();
	//var newImg= IEWIN? new Image() : document.createElement('img'); 
	newImg.src = imageSrc;
	if (newImg.complete) {
		// for other borwsers
		var imgWidth = newImg.width;
		var imgHeight = newImg.height;
	} else {
		// for IE
		var imgWidth = newImg.width;
		var imgHeight = newImg.height;
	}
	//alert(imgWidth+'x'+imgHeight);
	//get div size
	var divWidth=document.getElementById(imgID).style.width;
	var divHeight=document.getElementById(imgID).style.height;
	divWidth = divWidth.replace('px','');
	divHeight = divHeight.replace('px','');
	//get ratios
	var ratX = (divWidth/imgWidth);
	var ratY = (divHeight/imgHeight);
	//set new sizes
	if(ratX < ratY){
		var newImgWidth = parseInt(imgWidth*ratX);
		var newImgHeight = parseInt(imgHeight*ratX);
	} else {
		var newImgWidth = parseInt(imgWidth*ratY);
		var newImgHeight = parseInt(imgHeight*ratY);
	}
	
	//document.write('<img src="'+imageSrc+'" alt="'+imageAlt+'" title="'+imageAlt+'" width="'+newImgWidth+'" height="'+newImgHeight+'">');
	document.getElementById(imgID).innerHTML = '<img src="'+imageSrc+'" alt="'+imageAlt+'" title="'+imageAlt+'" width="'+newImgWidth+'" height="'+newImgHeight+'">';
}
