String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}

/* //  Published at: scripts.tropicalpcsolutions.com
var reloaded = false;
var loc=""+document.location;
loc = loc.indexOf("?reloaded=")!=-1?loc.substring(loc.indexOf("?reloaded=")+10,loc.length):"";
loc = loc.indexOf("&")!=-1?loc.substring(0,loc.indexOf("&")):loc;
reloaded = loc!=""?(loc=="true"):reloaded;

function reloadOnceOnly() {
    if (!reloaded) 
        window.location.replace(window.location+"?reloaded=true");
}
reloadOnceOnly(); //You can call this via the body tag if desired*/

if(navigator.userAgent.indexOf("Firefox")!=-1){
	var nn4 = true;
	var nn6 = true;
}
else{
	var nn4 = false;
	var nn6 = true;
}
var ie4 = (document.all && !document.getElementById);
var ie5 = (document.all && document.getElementById);

function loadPage(id,nestref,url,content_frame) {
	if (nn4) {
		var lyr = (nestref)? eval('document.'+nestref+'.document.'+id) : document.layers[id]
		lyr.load(url,lyr.clip.width)
	}
	else 
	if(ie4){
		parent.contentFRM.location = url;
	}
	else 
	if(ie5 || nn6){
		document.getElementById(content_frame).src = url;
	}
	else{
		//alert('not supported: '+url);
	}
}

function showPage(id,content_frame) {
	var loc;
	
	if(window.frames[content_frame].document.getElementById('ForDialog')!=null){	
		if(window.frames[content_frame].document.getElementById('ForDialog').innerHTML.trim()!=""){
			//Display dialog
			jQuery.facebox(window.frames[content_frame].document.getElementById('ForDialog').innerHTML);			
			
			//Set auto close
			if(window.frames[content_frame].document.getElementById('DialogAutoClose')!=null){
				if(window.frames[content_frame].document.getElementById('DialogAutoClose').value!=0){
					//Close after specificed timing
					setTimeout('$.facebox.close()', window.frames[content_frame].document.getElementById('DialogAutoClose').value);
				}
			}
			else{
				//Default to close after 5 secs 
				setTimeout('$.facebox.close()', 5000);
			}
		}
	}
	
	if(window.frames[content_frame].document.getElementById('ForContent')!=null){	
		if(window.frames[content_frame].document.getElementById('ForContent').innerHTML.trim()!=""){
			document.getElementById('TheBody').innerHTML=window.frames[content_frame].document.getElementById('ForContent').innerHTML;
		}
	}
	
	if(window.frames[content_frame].document.getElementById('Refresh')!=null){	
		//Refresh page if required	
		if(window.frames[content_frame].document.getElementById('Refresh').value!=""){	
			if(window.frames[content_frame].document.getElementById('Refresh').value=="_top"){	
				//window.frames[content_frame].location="";
				if(nn4){
					//window.location=window.location;
					window.location.reload(true);					
				}
				else 
				if(ie4 || ie5 || nn6){
					window.location.reload(true);
				}
			}
			else{
				var refresh_target=window.frames[content_frame].document.getElementById('Refresh').value;				
				//alert(refresh_target);
				window.frames[refresh_target].location.reload(true);
				//bind_js();
			}
		}
	}
		
	if(window.frames[content_frame].document.getElementById('Refresh2')!=null){	
		//Refresh page if required
		if(window.frames[content_frame].document.getElementById('Refresh2').value!=""){	
			if(window.frames[content_frame].document.getElementById('Refresh2').value=="_top"){	
				//window.frames[content_frame].location="";
				if(nn4){
					//window.location=window.location;
					window.location.reload(true);
				}
				else 
				if(ie4 || ie5 || nn6){
					window.location.reload(true);
				}
			}
			else{
				var refresh_target=window.frames[content_frame].document.getElementById('Refresh2').value;
				//alert(refresh_target);
				window.frames[refresh_target].location.reload(true);
				//bind_js();
			}
		}	
	}
}

function refreshPageContent(id,content_frame) {	
	if(window.frames[content_frame].document.getElementById('theBody')==null){
		//alert("Error Code: 2" + content_frame);
	}
	if(document.getElementById(id)!=null){
		document.getElementById(id).innerHTML=window.frames[content_frame].document.getElementById('theBody').innerHTML;
		//alert(document.getElementById(id).innerHTML);
		//bind_js();
	}
}

//Resize functions

function getWindowWidth() {
	var windowWidth = 0;
	if (typeof(window.innerWidth) == 'number') {
		windowWidth = window.innerWidth;
	}
	else {
		if (document.documentElement && document.documentElement.clientWidth) {
			windowWidth = document.documentElement.clientWidth;
		}
		else {
			if (document.body && document.body.clientWidth) {
				windowWidth = document.body.clientWidth;
			}
		}
	}
	return windowWidth;
}//getWindowWidth

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}//getWindowHeight

function resizeImg() {
	//Find background images
	var mybg = document.getElementsByName('BGPics');
	
	//Find windows size
	var winW = getWindowWidth();
	var winH = getWindowHeight();
	
	/*var winX = (document.all)?window.screenLeft:window.screenX;
	var winY = (document.all)?window.screenTop:window.screenY;	*/
	
	//Process all backgrounds
	var i=0;
	while(i<mybg.length){
		mybg[i].style.display="none";
		
		//Retireve height of background pictures
		imgW=1422;//mybg[i].width;
		imgH=1422;//mybg[i].height;
		
		//Calcuilate scaling factors
		Wfactor=winW/imgW;
		Hfactor=winH/imgH;

		//Scale the pictures to fill the viewport without affecting aspect ratio
		if(imgW*Hfactor>=winW && imgH*Hfactor>=winH){
			mybg[i].style.height = imgH*Hfactor + "px";
			mybg[i].style.width = imgW*Hfactor + "px";
			
			//mybg[i].style.top = winY + "px";
		}
		else{
			mybg[i].style.height = imgH*Wfactor + "px";
			mybg[i].style.width = imgW*Wfactor + "px";		
			
			//mybg[i].style.top = winY + "px";
		}		
		i++;
	}
}//resizeImg

window.onload = resizeImg;
window.onresize = resizeImg;
