/******************** common functions ************/

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}



/* back to top */
function backToTop() {
	var index = window.location.href.indexOf('#');
	if (index >= 0) {
		var newurl = (window.location.href.substring(0, index) + '#top');
	} else {
		var newurl = (window.location.href + '#top');
	}

	window.location = newurl;
}

/* go to bottom */
function goToBottom() {
	var index = window.location.href.indexOf('#');
	if (index >= 0) {
		var newurl = (window.location.href.substring(0, index) + '#bottom');
	} else {
		var newurl = (window.location.href + '#bottom');
	}

	window.location = newurl;
}


/* trigger disclaimer text display */
function triggerDisclaimer() {
	var disclaimer = document.getElementById("FooterUC_disclaimerText");
	if (disclaimer != null) {
		if (disclaimer.style.display == 'none') {
			disclaimer.style.display = '';
			createCookie('showDisclaimer','true','1');
		} else {
			disclaimer.style.display = 'none';
			createCookie('showDisclaimer','false','1');
		}
	}
}


/* reload page when select year is changed */
function reloadSelectedYear() {
	var select_box = document.getElementById("select_box")
	if (select_box != null) {
		var selected_value = select_box[select_box.selectedIndex].value
		if (selected_value != "") {
			location.href = location.pathname + '?year=' + selected_value;
		}		
	}
}


/* general reload page from ddl */
function reloadSelectedDDLItem(basePath) {
	if (basePath.indexOf("/") != 0) {
		basePath = "/" + basePath;
	}
	var select_box = document.getElementById("select_box")
	if (select_box != null) {
		var selected_value = select_box[select_box.selectedIndex].value
		if (selected_value != "") {
			location.href = basePath + selected_value + '.aspx';
		}		
	}
}


/* popup window */
function popupWin(url, winName, winSize) {
	var y = (screen.availHeight - 650)/2;
    var x = (screen.availWidth - 550)/2;
    var w = 640;
    var h = 550;
    var para = ',menubar=no,resizable=yes,scrollbars=yes,location=no,status=no,toolbar=no,screenX=0,screenY=50,left=';
    
    // get win size
    if (winSize == 'normal') {
		w = 640;
		h = 550;
    }
    if (winSize == 'full') {
		w = screen.availWidth;
		h = screen.availHeight;
		para = ',menubar=no,resizable=yes,scrollbars=yes,location=no,status=no,toolbar=no,screenX=0,screenY=0,left='
		y=0;
		x=0;
    }
    
	window.open(url, winName, 'height='+h+',width='+w+para+x+',top='+y);
}



/************* cookies related ************/
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/*************************** popup image related **********************/
// Set the horizontal and vertical position for the popup
PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)
defaultWidth  = 500;
defaultHeight = 500;




if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;
}

var optNN='width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY+',scrollbars=';
var optIE='width=150,height=100,left='+PositionX+',top='+PositionY+',scrollbars=';

function popupImg(imageURL,imageTitle, showScrollbars){
        p = screen.height-85;
       	q = screen.width-10;
    if (imageTitle == 'FloorPlan'){PositionX = 0;PositionY = 0;optIE='width='+q +',height='+p+',left='+PositionX+',top='+PositionY+', menubar=no, resizable=yes, toolbar=no, fullscreen=no, status=yes, scrollbars=';}

	if (isNN){imgWin=window.open('about:blank','',optNN+showScrollbars);}
	if (isIE){imgWin=window.open('about:blank','',optIE+showScrollbars);}
	with (imgWin.document){
		writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');
		writeln('<sc'+'ript>');
		writeln('var maxPopupWidth, maxPopupHeight;');
		writeln('maxPopupWidth=710;');
		writeln('maxPopupHeight=510;');

		writeln('var isNN,isIE;');
		writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
		writeln('isNN=(navigator.appName=="Netscape")?1:0;');
		writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
		
		writeln('function reSizeToImage(){');
		if (imageTitle != "FloorPlan"){
		writeln('if (isIE){');
		//writeln('window.resizeTo(100,100);');
		writeln('window.moveTo(0,0);');
		writeln('if ((document.images[0].width > maxPopupWidth) || (document.images[0].height > maxPopupHeight)) {');
		writeln('width=maxPopupWidth;');
		writeln('height=maxPopupHeight;');
		writeln('} else {');
		//writeln('width=100-(document.body.clientWidth-document.images[0].width);');
		//writeln('height=100-(document.body.clientHeight-document.images[0].height);');
		
		writeln('width=document.images[0].width+10;');
		writeln('height=document.images[0].height+30;');
		writeln('}');
		writeln('window.resizeTo(width,height);');
		writeln('}');
		
		

		writeln('if (isNN){');       
		writeln('if ((document.images["img1"].width > maxPopupWidth) || (document.images["img1"].height > maxPopupHeight)) {');
		writeln('window.innerWidth=maxPopupWidth;');
		writeln('window.innerHeight=maxPopupHeight;');
		writeln('} else {');
		writeln('window.innerWidth=document.images["img1"].width;');
		writeln('window.innerHeight=document.images["img1"].height;');
		writeln('}');
		writeln('}');
		}
		writeln('}');
		writeln('function doTitle(){document.title="'+imageTitle+'";}');
		
		
		writeln('</sc'+'ript>');
		
		
		writeln('</head><body id=bodyTag bgcolor=ffffff onload="reSizeToImage();doTitle();self.focus();">');
		writeln('<img name="img1" src='+imageURL+' style="display:block">');
		writeln('</body></html>');
		close();		
	}
}










