// JavaScript Document
//start of functions used in user_rightmenu.asp menu and body onload
//to dynamically load content into existing page and resize page elements

var minPageHeight = 0; //used to define

function pagesize(intPx) {
	//if browser height is greater than intPx, adjust intPx to browser height
	minPageHeight = intPx; //add global minimum page height for the this page
	var brHeight = parseInt(browserHeight());
	if (brHeight > intPx) {intPx = brHeight;}
	//adjusts page size and related elements
	document.getElementById('maincolumn').style.height = intPx +'px';//set page height
	if (document.getElementById('t_middleright_vertical_line')) {
		document.getElementById('t_middleright_vertical_line').style.height = (intPx - 34) +'px';//set height of middle right vertical line
	}
	if (document.getElementById('footermenu')) {
		document.getElementById('footermenu').style.top = (intPx - 29) +'px';//set height footer menu
	}
	if (document.getElementById('right_properties_menu')) {
		document.getElementById('right_properties_menu').style.height = (intPx - 354) +'px';  //extend block to near bottom of page
	}
	if (document.getElementById('rightwing')) {
		document.getElementById('rightwing').style.height = intPx +'px';//set height of left wing
	}
	if (document.getElementById('leftwing')) {
		document.getElementById('leftwing').style.height = intPx +'px';//set height of left wing
	}
}
function select_menu_element(elmntType,selElmnt,classPrefix) {
//selects specified right menu element by changing it's class to rightmenu_selected
//deselects any other right menu element by changing it's class back to rightmenu
	for (i=0;i<document.getElementsByTagName(elmntType).length; i++) {
		if (document.getElementsByTagName(elmntType).item(i).className == classPrefix + "_selected"){
			document.getElementsByTagName(elmntType).item(i).className = classPrefix;
		}
	}	
	if (selElmnt!='') {
	document.getElementById(selElmnt).className = classPrefix + "_selected";}
}
//end of functions to load ajax pages into loadajax div of main page

//start of function to switch visibility of investments.asp elements depending on whether or not
//user has invoked 'properties' submenu
function specialPropertyPageElmnts(toggle) {
	if (toggle=='yes') {
		//hide lower right property menu and move right vertical brown line up the page
		document.getElementById('right_properties_menu').style.visibility='hidden';
		document.getElementById('t_properties').style.visibility='hidden';
		document.getElementById('t_properties_reunion').style.visibility='hidden';		
		document.getElementById('t_middleright_vertical_line').style.height='240px';
		//display lower top property menu
		document.getElementById('properties_menu_leftblock').style.visibility='visible';
		document.getElementById('properties_menu_legend').style.visibility='visible';
		document.getElementById('properties_menu_rightblock').style.visibility='visible';
		document.getElementById('top_properties_menu').style.visibility='visible';		
	}
	else if (toggle=='no') {
		//display lower right property menu
		document.getElementById('right_properties_menu').style.visibility='visible';
		document.getElementById('t_properties').style.visibility='visible';
		document.getElementById('t_properties_reunion').style.visibility='visible';	
		//hide lower top property menu
		document.getElementById('properties_menu_leftblock').style.visibility='hidden';
		document.getElementById('properties_menu_legend').style.visibility='hidden';
		document.getElementById('properties_menu_rightblock').style.visibility='hidden';
		document.getElementById('top_properties_menu').style.visibility='hidden';		
	}
}



//end of function to switch visibility of investments.asp elements depending on whether or not
//user has invoked 'properties' submenu
function loadPropertyPage(Page,Direction){
	if (Page=='Direct') {
		if (Direction == 'next') {LoadPropertyFirstLastItem('Land','start'); }
		else if (Direction == 'previous') {LoadPropertyFirstLastItem('Real','end'); }
		}
	else if (Page=='Land') {
		if (Direction == 'next') {LoadPropertyFirstLastItem('Operating','start'); }
		else if (Direction == 'previous') {LoadPropertyFirstLastItem('Direct','end'); }
		}
	else if (Page=='Operating') {
		if (Direction == 'next') {LoadPropertyFirstLastItem('Real','start'); }
		else if (Direction == 'previous') {LoadPropertyFirstLastItem('Land','end'); }
		}
	else if (Page=='Real') {
		if (Direction == 'next') {LoadPropertyFirstLastItem('Direct','start'); }
		else if (Direction == 'previous') {LoadPropertyFirstLastItem('Operating','end'); }
		}	
}
function nextSlide(arrType) {
	imgCount = parseInt(imgCount) + 1;
	if (imgCount==eval('arrImg'+arrType + '.length')) {
		imgCount = 0;}
	loadPropertiesImg(imgCount,arrType);	
}

function previousSlide(arrType) {
	imgCount = parseInt(imgCount) - 1;
	if (imgCount < 0) {
		imgCount = eval('arrImg'+arrType + '.length') -1;}
	loadPropertiesImg(imgCount,arrType);	
}

function nextAffSlide(arrType) {
	imgCount = parseInt(imgCount) + 1;
	if (imgCount==eval('arrImg'+arrType + '.length')) {
		imgCount=0;}//loop back to 0
	loadAffiliatesImg(imgCount,arrType);	
}
function previousAffSlide(arrType) {
	imgCount = parseInt(imgCount) - 1;
	if (imgCount < 0) {
		imgCount=eval('arrImg'+arrType + '.length') - 1;}//loop back to end of array
	loadAffiliatesImg(imgCount,arrType);	
}

function loadPropertiesImg(iCount,arrType) {
		imgCount = iCount;
		var imgFrame = document.getElementById('properties_slideshow_img');
		imgFrame.innerHTML  = '<img src="' + eval('arrImg' + arrType + '[' + imgCount + ']') + '" width="361" height="370" />';
		var imgTitle = document.getElementById('properties_slideshow_title');
		imgTitle.innerHTML = eval('arrTitle' + arrType + '[' + imgCount + ']'); 
		var imgDesc = document.getElementById('properties_slideshow_description');
		imgDesc.innerHTML = eval('arrDesc' + arrType + '[' + imgCount + ']'); 
		select_menu_element("p",'properties_slideshow_menu' + imgCount,'properties_slideshow_menu');
}
function loadAffiliatesImg(iCount,arrType) {
		imgCount = iCount;
		var imgFrame = document.getElementById('properties_slideshow_img');
		imgFrame.innerHTML  = '<img src="' + eval('arrImg' + arrType + '[' + imgCount + ']') + '" width="260" height="230" />';
		var imgDesc = document.getElementById('properties_slideshow_description');
		imgDesc.innerHTML = eval('arrDesc' + arrType + '[' + imgCount + ']'); 
}
function resetCounter() {
	imgCount=0;
}

function LoadPropertyFirstLastItem(strCategory,strStartorEnd) {
	arrType = strCategory; //reset public variable
	str = '<h2>'  //start building left hand slide menu and select top menu item
	if (arrType=='Direct') {str+= 'VIEW DIRECT OWNED ASSETS<h2>';select_menu_element('div','top_properties_menu1','top_properties_menu');}
	else if (arrType=='Land') {str+= 'VIEW PROJECT DEVELOPMENT<h2>';select_menu_element('div','top_properties_menu2','top_properties_menu');}
	else if (arrType=='Operating') {str+= 'VIEW OPERATING COMPANIES<br />& JOINT DEVELOPMENT<h2>';select_menu_element('div','top_properties_menu3','top_properties_menu');}
	else if (arrType=='Real') {str+= 'VIEW REAL ESTATE FINANCIAL<br />ACTIVITIES<h2>';select_menu_element('div','top_properties_menu4','top_properties_menu');}
	for (var i = 0;i < eval('arrLink' + arrType +'.length');i++) {
		str+= '<p class="properties_slideshow_menu" id="properties_slideshow_menu' + i +'">';
		str+= '<a href="javascript:loadPropertiesImg(' + i +',\'' + arrType + '\');">';
		str+= eval('arrLink' + arrType + '[' + i + ']') + '</a></p>';
	}
	if (document.getElementById("properties_slideshow_menu"))   {
		document.getElementById("properties_slideshow_menu").innerHTML = str;}	//build	left hand slide menu
	if (strStartorEnd =='start') {
		imgCount = 0; } //reset public variable to first slide in category
	else if (strStartorEnd =='end') {
		imgCount = eval('arrLink' + arrType +'.length') -1;} //reset public variable to last slide in category		
	loadPropertiesImg(imgCount,arrType); //load first or last slide	
}

function browserHeight() {
	var h = 0;

	//IE
	if(!window.innerWidth)
	{
		//strict mode
		if(!(document.documentElement.clientWidth == 0))
		{
			h = document.documentElement.clientHeight;
		}
		//quirks mode
		else
		{
			h = document.body.clientHeight;
		}
	}
	//w3c
	else
	{
		h = window.innerHeight;
	}
	return h;	
}

function resizePageToWindow() {
	//if window size is greater than page size on browser resize, adjust page size to stretch to window size
	//determine page size
	var BrowserHeight = parseInt(browserHeight());
	if (BrowserHeight > minPageHeight) {pagesize(minPageHeight);}
}

function standardAjaxPage(page,pageheight,selMenuElmnt,MenuClass) {
	 dojo.xhrGet( { 
        url: page, 
        handleAs: "text",

        timeout: 5000, // Time in milliseconds

        // The LOAD function will be called on a successful response.
        load: function(response, ioArgs) { 
          dojo.byId("loadajax").innerHTML = response; //load div with ajax include
		 pagesize(pageheight); //resize page
		 select_menu_element("div",selMenuElmnt,MenuClass); //select menu element		  
          return response;
		 },

        // The ERROR function will be called in an error case.
        error: function(response, ioArgs) { 
          console.error("HTTP status code: ", ioArgs.xhr.status); 
          return response; // ?
          }
        });
}

function InvestmentsAjaxPage(page,pageheight,selMenuElmnt,MenuClass) {
	 dojo.xhrGet( { 
        url: page, 
        handleAs: "text",

        timeout: 5000, // Time in milliseconds

        // The LOAD function will be called on a successful response.
        load: function(response, ioArgs) { 
         dojo.byId("loadajax").innerHTML = response; //load div with ajax include
		 pagesize(pageheight); //resize page
 		 specialPropertyPageElmnts('no'); 
		 select_menu_element("div",selMenuElmnt,MenuClass); //select menu element		  
          return response;
		 },

        // The ERROR function will be called in an error case.
        error: function(response, ioArgs) { 
          console.error("HTTP status code: ", ioArgs.xhr.status); 
          return response; // ?
          }
        });
}

function InvestmentsSlideShowAjaxPage(page,pageheight,selMenuElmnt,MenuClass,propCat) {
	 dojo.xhrGet( { 
        url: page, 
        handleAs: "text",

        timeout: 5000, // Time in milliseconds

        // The LOAD function will be called on a successful response.
        load: function(response, ioArgs) { 
         dojo.byId("loadajax").innerHTML = response; //load div with ajax include
		 pagesize(pageheight); //resize page
 		 specialPropertyPageElmnts('yes'); 
		 select_menu_element("div",selMenuElmnt,MenuClass); //select menu element		  
		 LoadPropertyFirstLastItem(propCat,'start'); //load category of properties into slide show	
         return response;
		 },

        // The ERROR function will be called in an error case.
        error: function(response, ioArgs) { 
          console.error("HTTP status code: ", ioArgs.xhr.status); 
          return response; // ?
          }
        });
}