/** Usage: tab control and ajax request on anchor element:
 *   onclick="setSubnav('g');return pageRequest(this.href,'nav3');"
 *  Usage: mouseovers on anchor element:
 *   onmouseover="msOn(this)" onmouseout="msOff(this)" id="nav5_btn"
 *  NOTE: For equistone, i've commented out the AJAX component of
 * pageRequest(). Instead, we are simply making synchronus requests.

var nav1_on = new Image(); nav1_on.src = "assets/1_services_on.gif";
var nav1_off = new Image(); nav1_off.src = "assets/1_services_off.gif";
var nav2_on = new Image(); nav2_on.src = "assets/2_property_on.gif";
var nav2_off = new Image(); nav2_off.src = "assets/2_property_off.gif";
var nav3_on = new Image(); nav3_on.src = "assets/3_realestate_on.gif";
var nav3_off = new Image(); nav3_off.src = "assets/3_realestate_off.gif";
var nav4_on = new Image(); nav4_on.src = "assets/4_casestudies_on.gif";
var nav4_off = new Image(); nav4_off.src = "assets/4_casestudies_off.gif";
var nav5_on = new Image(); nav5_on.src = "assets/5_about_on.gif";
var nav5_off = new Image(); nav5_off.src = "assets/5_about_off.gif";
var nav6_on = new Image(); nav6_on.src = "assets/6_dashboard_on.gif";
var nav6_off = new Image(); nav6_off.src = "assets/6_dashboard_off.gif";
var nav7_on = new Image(); nav7_on.src = "assets/login_on.gif";
var nav7_off = new Image(); nav7_off.src = "assets/login.gif";
var nav8_on = new Image(); nav8_on.src = "assets/contact_us_on.gif";
var nav8_off = new Image(); nav8_off.src = "assets/contact_us.gif";
var nav9_on = new Image(); nav9_on.src = "assets/logout_on.gif";
var nav9_off = new Image(); nav9_off.src = "assets/logout.gif";

var snv1_on = new Image(); snv1_on.src = "assets/1_sidenav_tenant_rep_onroll.gif";
var snv1_off = new Image(); snv1_off.src = "assets/1_sidenav_tenant_rep_off.gif";
var snv2_on = new Image(); snv2_on.src = "assets/2_sidenav_proj_lease_onroll.gif";
var snv2_off = new Image(); snv2_off.src = "assets/2_sidenav_proj_lease_off.gif";
var snv3_on = new Image(); snv3_on.src = "assets/3_sidenav_invest_sales_onroll.gif";
var snv3_off = new Image(); snv3_off.src = "assets/3_sidenav_invest_sales_off.gif";
var snv4_on = new Image(); snv4_on.src = "assets/4_sidenav_dev_service_onroll.gif";
var snv4_off = new Image(); snv4_off.src = "assets/4_sidenav_dev_service_off.gif";

var hnv1_on = new Image(); hnv1_on.src = "assets/1_homeservices_onroll.jpg";
var hnv1_off = new Image(); hnv1_off.src = "assets/1_homeservices_off.jpg";
var hnv2_on = new Image(); hnv2_on.src = "assets/2_homeproperty_onroll.jpg";
var hnv2_off = new Image(); hnv2_off.src = "assets/2_homeproperty_off.jpg";
var hnv3_on = new Image(); hnv3_on.src = "assets/3_homerealestate_onroll.jpg";
var hnv3_off = new Image(); hnv3_off.src = "assets/3_homerealestate_off.jpg";
var hnv4_on = new Image(); hnv4_on.src = "assets/4_homecasestudies_onroll.jpg";
var hnv4_off = new Image(); hnv4_off.src = "assets/4_homecasestudies_off.jpg";
var hnv5_on = new Image(); hnv5_on.src = "assets/5_homeabout_onroll.jpg";
var hnv5_off = new Image(); hnv5_off.src = "assets/5_homeabout_off.jpg";
var hnv6_on = new Image(); hnv6_on.src = "assets/6_homedashboard_onroll.jpg";
var hnv6_off = new Image(); hnv6_off.src = "assets/6_homedashboard_off.jpg";
var hnv7_on = new Image(); hnv7_on.src = "assets/home_login_onroll.jpg";
var hnv7_off = new Image(); hnv7_off.src = "assets/home_login_off.jpg";
var hnv8_on = new Image(); hnv8_on.src = "assets/home_contactus_onroll.jpg";
var hnv8_off = new Image(); hnv8_off.src = "assets/home_contactus_off.jpg";

var tim1_on = new Image(); tim1_on.src = "assets/timeline_phase1_on.gif";
var tim1_off = new Image(); tim1_off.src = "assets/timeline_phase1_off.gif";
var tim2_on = new Image(); tim2_on.src = "assets/timeline_phase2_on.gif";
var tim2_off = new Image(); tim2_off.src = "assets/timeline_phase2_off.gif";
var tim3_on = new Image(); tim3_on.src = "assets/timeline_phase3_on.gif";
var tim3_off = new Image(); tim3_off.src = "assets/timeline_phase3_off.gif";
 */

var currPage = "";
var prevPage = "";

var msgBubbleTextArray = new Array();
	msgBubbleTextArray[0] = "<div>Strategic Planning</div><br /><p>All of our assignments begin with an understanding of the needs of the client. EQUISTONE PARTNERS evaluates the current leasehold, potential acquisition or company owned asset or portfolio. Our professionals assist clients in selecting and interviewing architects, general contractors, real estate attorneys and developers. Project scope is specifically defined in this step to ensure a seamless process.</p>"; 
	msgBubbleTextArray[1] = "<div>Facilities Summary</div><br /><p>The financial and qualitative criteria are evaluated by EQUISTONE PARTNERS. Adjacencies for various departments are established and a space program is developed. In the event of a development, our professionals are available to work with the team to design the overall project and layout of the proposed structure on the site.</p>";
	msgBubbleTextArray[2] = "<div>Market Overview</div><br /><p>A comprehensive list of available alternatives is compiled that meet the financial and qualitative criteria for the new facility or acquisition.</p>";
	msgBubbleTextArray[3] = "<div>Market Tour</div><br /><p>Equistone professionals conduct a qualified market tour of the buildings that meet the client's criteria.</p>";
	msgBubbleTextArray[4] = "<div>Alternatives Evaluation</div><br /><p>Preparation of financial analysis and qualitative matrices of the alternatives.</p>";
	msgBubbleTextArray[5] = "<div>Short List Re-Tour</div><br /><p>Re-visit of the opportunities that meet the client's criteria.</p>";
	msgBubbleTextArray[6] = "<div>Solicitation of Proposals</div><br /><p>EQUISTONE PARTNERS prepares Request for Proposals, Letters of Intent, and Purchase and Sale Agreement documentation to negotiate with the finalist(s).</p>";
	msgBubbleTextArray[7] = "<div>Proposal Negotiations</div><br /><p>EQUISTONE PARTNERS represents the client's interests through the negotiations.</p>";
	msgBubbleTextArray[8] = "<div>Letter of Intent</div><br /><p>Our team structures acceptable business terms used to draft a lease. In the event of an acquisition, the Letter of Intent is used as the framework for drafting the purchase agreement for review and approval by the client.</p>";
	msgBubbleTextArray[9] = "<div>Facilities Evaluation</div><br /><p>From the date the short list is identified, Equistone professionals gather critical data about the facility.</p>";
	msgBubbleTextArray[10] = "<div>Executed Letter of Intent</div><br /><p>Business terms are agreed upon and memorialized in a non-binding Letter of Intent.</p>";
	msgBubbleTextArray[11] = "<div>Space Planning/Evaluation</div><br /><p>EQUISTONE PARTNERS works with the architectural firm and client to identify design for the new premises.</p>";
	msgBubbleTextArray[12] = "<div>Lease/Purchase Negotiations</div><br /><p>EQUISTONE PARTNERS works with the appointed real estate attorney to assist in the negotiation of the Purchase & Sale Agreement (in the event of a purchase) and/or lease document (for lease facility).</p>";
	msgBubbleTextArray[13] = "<div>Lease/Purchase Contract</div><br /><p>The lease or purchase contract is signed.</p>";
	msgBubbleTextArray[14] = "<div>Prepare Construction Drawings</div><br /><p>EQUISTONE PARTNERS works with the appointed contractor and project manager to develop, design and prepare construction drawings for site improvements.</p>";
	msgBubbleTextArray[15] = "<div>Permit</div><br /><p>The construction permit timeframe varies from city to city. A general benchmark is 4 weeks after submittal of approved construction drawings. EQUISTONE PARTNERS monitors the process and ensures the information is presented to the city in a timely manner.</p>";
	msgBubbleTextArray[16] = "<div>Negotiate Construction Contract</div><br /><p>EQUISTONE PARTNERS aids in evaluating the contract. In the event of a tenant build scenario, purchase of a new facility or landlord build scenario, our team remains involved and available as a resource in the process to ensure budgetary guidelines are met.</p>";
	msgBubbleTextArray[17] = "<div>Construction/Move Coordination</div><br /><p>Depending upon the scope of work, construction projects can vary widely. In an existing building, cold or warm shell, a typical Tenant Improvement construction project spans 3-4 months from the date the city approves the plans. This timeframe can be compressed to 1-2 months for projects of limited scope.</p>";
	msgBubbleTextArray[18] = "<div>FF&amp;E</div><br /><p>EQUISTONE PARTNERS professionals work with the move coordination firm to assure this critical step is carried out to completion.</p>";
	msgBubbleTextArray[19] = "<div>Server Move/Beta Test</div><br /><p>EQUISTONE PARTNERS works closely with the move coordination firm to assure the client is up and running at their new location.</p>";
	msgBubbleTextArray[20] = "<div>Move In/Punch List</div><br /><p>All of the hard work and dedication to move in is completed by the team. The project is a success.</p>";

function showMsgBubble(linkID,color){
	var bgCol;
	var elm = $(linkID);
	var arr = new Array();
	arr = Position.page(elm);
	arrOffset = Position.realOffset(elm);
	
	if (color != null){
		switch(color){
			case 1:
				bgCol = "#C5D5E2";
				break;
			case 2:
				bgCol = "#85A0B5";
				break;
			case 3:
				bgCol = "#597489";
				break;
			default:
				bgCol = "#C5D5E2";
		}
		
		var editableBGCollection = $$('#messageBubble #MsgBubbleRow1 .center',
					 '#messageBubble #MsgBubbleRow2 .center',
					 '#messageBubble #MsgBubbleRow3 .center');
		
		for (var bgLoop = 0; bgLoop < editableBGCollection.length; bgLoop++){
			editableBGCollection[bgLoop].style.backgroundColor=bgCol;
		}
	}else{
		//alert("no color but it's ok!");
	}
	
	var msgIndex = parseInt(linkID.substring(4)) - 1;
	var txt = null;
	txt = msgBubbleTextArray[msgIndex];
	
	$('messageBubbleContent').innerHTML=txt;
	$('messageBubble').style.visibility="visible";
	$('messageBubble').style.top=arr[1] + arrOffset[1] + -90 + "px";
	$('messageBubble').style.left=arr[0] + arrOffset[0] + 265 + "px";
	return false;
}

function hideMsgBubble(){	
	$('messageBubble').style.visibility="hidden";
	$('messageBubble').style.top= "-1000px";
	$('messageBubble').style.left= "-1000px";
	return false;
}

function msOn(img){
	img.src = eval(img.id.substring(0,4) + "_on.src");
}

function msOff(img){
	if (img.id.substring(0,4) != currPage)
		img.src = eval(img.id.substring(0,4) + "_off.src");
}

function imgRoll(img, path) { img.src = path; }

//fix prototype.js implementation - may need the latest version
var newShow = { show : function(element) { $(element).style.display = "block"; return element; } }
Element.addMethods(newShow);

function trim(s) {
    var m = s.match(/^\s*(\S+(\s+\S+)*)\s*$/);
    return (m == null) ? "" : m[1];
}

function replaceString(sVal, sFind, sRepl) {
  for (var i=0; i<sVal.length; i++) {
    if (sVal.substring(i,i+sFind.length) == sFind) {
      sVal = sVal.substring(0,i)+sRepl+sVal.substring(i+sFind.length,sVal.length);
      i += sRepl.length - sFind.length;
    }
  }
  return sVal;
}

function rgb2hex(str) {
   if (str.indexOf('rgb') != 0) return str;
   str = str.replace(/rgb\(|\)/g, "").split(",");
   str[0] = parseInt(str[0], 10).toString(16).toLowerCase();
   str[1] = parseInt(str[1], 10).toString(16).toLowerCase();
   str[2] = parseInt(str[2], 10).toString(16).toLowerCase();
   str[0] = (str[0].length == 1) ? '0' + str[0] : str[0];
   str[1] = (str[1].length == 1) ? '0' + str[1] : str[1];
   str[2] = (str[2].length == 1) ? '0' + str[2] : str[2];
   return ('#' + str.join(""));
}

function fixCalendarSearchDate(elem, minYear, maxYear, useMonthStart)
{
    var v = trim(elem.value);

    // split the 
    var temp = new Array();
    temp = v.split('/');
    
    // if the data entered was a year, formatted as "yyyy", then 
    if (temp.length == 2)
    {
        var v1 = trim(temp[0]);
        var v2 = trim(temp[1]);
        if (parseInt(v1) == v1 && parseInt(v2) == v2 
            && v1 >= 1 && v1 <= 12
            && v2 >= minYear && v2 <= maxYear)
        {
            var dt = new Date();
            dt.setFullYear(v2);
            dt.setMonth(v1);
            dt.setDate(1);
            
            if (!useMonthStart)
            {
                dt.setDate(dt.getDate() - 1);
            }
            
            elem.value = (v1 + '/' + dt.getDate() + '/' + v2); 
        }
    }

    // if the data entered was a year, formatted as "yyyy", then 
    if (parseInt(v) == v && v >= minYear && v <= maxYear)
    {
        elem.value = ((useMonthStart) ? '1/1/' : '12/31/') + v; 
    }
}

var currTimeline = "";

function timeLineSwap(elm){
	var stripId = elm.id.substring(3,4);
	var elementToShow = "phase" + stripId + "_timelineOn"; 
	var elementToHide = "phase" + stripId + "_timelineOff";
	
	if ($(elementToShow) != null){	
		$(elementToShow).style.display="block";
		new Effect.Opacity(elementToShow,{duration:0.5, from:0.1, to:0.99999});
	 	new Effect.Opacity(elementToHide,{duration:0.5, from:0.9, to:0.1});
		currTimeline = stripId;
	}
	//setHighlightForTableRows(stripId);
}

function resetTimeline(elm){
	var stripId = elm.id.substring(3,4);
	var elementToShow = "phase" + stripId + "_timelineOff";
	var elementToHide = "phase" + stripId + "_timelineOn";
	if ($(elementToShow) != null){
		new Effect.Opacity(elementToShow,{duration:0.5, from:0.1, to:0.99999});
		new Effect.Opacity(elementToHide,{duration:0.5, from:0.99999, to:0.1});
	}
}

function timeLineSwap2(elm){
	var stripId = elm.id.substring(3,4);
	var elementToShow = "phase" + stripId + "_timelineOn"; 
	var elementToHide = "phase" + stripId + "_timelineOff";
	
	if ($(elementToShow) != null){	
		$(elementToShow).show();
		$(elementToHide).hide();
		currTimeline = stripId;
	}
	clearHighlightForTableRows();
	setHighlightForTableRows(stripId);
}

function resetTimeline2(elm){
	var stripId = elm.id.substring(3,4);
	var elementToShow = "phase" + stripId + "_timelineOff";
	var elementToHide = "phase" + stripId + "_timelineOn";
	clearHighlightForTableRows();
	if ($(elementToShow) != null){
		$(elementToShow).show();
		$(elementToHide).hide();
	}
}

function setHighlightForTableRows(tableSection){
	var arr = "";
	clearHighlightForTableRows();
	switch(tableSection){
		case "1":
			arr = $$('tr.highlight1_off');
			for (var i = 0; i < arr.length;i++){
				arr[i].toggleClassName('highlight1_on');
			}
			break;
		case "2":
			arr = $$('tr.highlight2_off');
			for (var i = 0; i < arr.length;i++){
				arr[i].toggleClassName('highlight2_on');
			}
			break;
		case "3":
			arr = $$('tr.highlight3_off');
			for (var i = 0; i < arr.length;i++){
				arr[i].toggleClassName('highlight3_on');
			}
			break;
		default:
	}
	
}

function clearHighlightForTableRows(){
	
	var h1_arr = $$('tr.highlight1_on');
	for (var i = 0; i < h1_arr.length;i++){
		h1_arr[i].className='highlight1_off';
	}
	
	var h2_arr = $$('tr.highlight2_on');
	for (var i = 0; i < h2_arr.length;i++){
		h2_arr[i].className='highlight2_off';
	}

	var h3_arr = $$('tr.highlight3_on');
	for (var i = 0; i < h3_arr.length;i++){
		h3_arr[i].className='highlight3_off';
	}
	
}

function pageRequest(url,page){//i.e. page = nav1
	prevPage = currPage;
	currPage = page;
	
	/*
	var myAjax = new Ajax.Request(
	url,
	{
		method: 'get',
		onComplete: fadeInContent
	});
	*/
	
	var _currNav = $(currPage + "_btn");
	var _prevNav = $(prevPage + "_btn");

	msOn(_currNav);
	msOff(_prevNav);
	
	return true;
}

function loginPanelAppear(){	
	isLoginPanelOpen = true;
	var elm = "";
	var bodyWidth = "";
	 
	if (document.body && document.body.clientWidth){
		bodyWidth = document.body.clientWidth;
		bodyHeight = document.body.clientHeight;
	}else if(window && window.innerWidth){
		bodyWidth = window.innerWidth;
		bodyHeight = window.innerHeight;
	}else if(document.documentElement && document.documentElement.clientWidth){
		bodyWidth = document.documentElement.clientWidth;
		bodyHeight = document.documentElement.clientHeight;
	}

	if ($('mainContainer')){
		elm = $('mainContainer');
	}else if ($('timeLineContainer')){
		elm = $('timeLineContainer');
	}else if ($('homeContainer')){
		elm = $('homeContainer');
	}
	
	var dimensions = Element.getDimensions(elm);
	var width = dimensions.width;
	var height = dimensions.height;
	var footerHeight = $('footer') ? Element.getHeight('footer'): "";
	
	var offsetValues = Position.cumulativeOffset(elm);
	var left = offsetValues[0];
	var top = offsetValues[1];
	
	$('disableLayer').style.width=bodyWidth + "px";
	$('disableLayer').style.height=bodyHeight + "px";
	$('disableLayer').style.left="0px";
	$('disableLayer').style.top="0px";
	$('loginPopUp').style.left=width/2 - 170 + "px";
	$('loginPopUp').style.top=top + 200 + "px";
	
	var isIE = navigator.appName.indexOf("Microsoft") != -1;
	
	if (isIE){
		var x = navigator.userAgent.indexOf('MSIE');
		var v = navigator.userAgent.charAt(x + 5);
		
		//var i = navigator.appVersion.indexOf('MSIE');
		//if (i != -1) var v = parseInt(navigator.appVersion.substring(i));
		
		if (v < 7) var dd = $('searchDropDown').hide();
	}
	
	Effect.Appear('disableLayer', { duration: 2.0, from: 0.0, to: 0.7 });
	var showLoginPane = setTimeout( showLogin, 2000 );
	return false;
}

function loginPanelClear(){
	history.go(-1);
	return false;
}

function showAboutInfo(id){
	var tmp = id + "_info";
	$(tmp).className="showInfo";
}
function hideAboutInfo(id){
	var tmp = id + "_info";
	$(tmp).className="hideInfo";
}

function setDivHeight(tmp){
	alert(tmp.style.height);
	return false;	
}

function setOnFocusEvent(elm){
	if (elm != null){
		elm.observe(
			'focus',
			function(){
				elm.value = "";
			}
		);
	}
}

function displayContainer(containerId){
	if ($(containerId) != null){
		$(containerId).style.visibility = "visible";
	}else{
		//alert('could not find container');
	}
}

function setPageHeight(containerId){
	if ($(containerId) != null){
		var mainContainerHeight = $(containerId).getHeight();
		var getULsInSideNav = $$('div#col1_leftnav ul');
		var getULsInCol2Content = $$('#col2_content ul');
		var mainHeight = "";
		var UL_Height = "";

		if (getULsInSideNav != null && getULsInSideNav.length > 0){
			UL_Height = getULsInSideNav[0].getHeight();
		}

		//found ul height for side nav buttons
		if (UL_Height != null){
			var leftColHeight = null;
			
			if ($('col1_leftnav') != null) {
				leftColHeight = $('col1_leftnav').getHeight();
			}
			
			//found leftColumn div height
			if (leftColHeight != null){
		
				// is side nav > mainContainer
				if (mainContainerHeight < leftColHeight){
					mainHeight = UL_Height;
				}
				
				if (leftColHeight < (mainContainerHeight - 100)){
					mainHeight = mainContainerHeight;
				}
				
				//if page content > mainContainer
				if (getULsInCol2Content != null && getULsInCol2Content.length > 0){
					var ContentULHeight = getULsInCol2Content[0].getHeight();
					var col2_height = $('col2_content').getHeight();
					if (mainContainerHeight < ContentULHeight){
						mainHeight = col2_height + 50;
					}
				}
				
				//set element heights
				$(containerId).style.height = mainHeight + 168 + "px";
				$('col1_leftnav').style.height = mainHeight + "px";
				$('col1_leftnav').style.visibility="visible";
			}
		}
		$(containerId).style.visibility="visible";
	}
}

function setHPColumnHeights(){
	var col1_nu = $('ctl00_ctl00_ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolder_ContentPlaceHolder1_WelcomeContentPlaceHolder_FeaturedProperties1_FeaturedItem1_FeaturedPropertyDiv');
	var col2_nu = $('ctl00_ctl00_ctl00_ctl00_MainContentPlaceHolder_MainContentPlaceHolder_ContentPlaceHolder1_WelcomeContentPlaceHolder_FeaturedProperties1_FeaturedItem2_FeaturedPropertyDiv');
	
	if ( col1_nu != null && col2_nu != null){
		var col1_height = col1_nu.getHeight();
		var col2_height = col2_nu.getHeight();
		var nuHeight = "";
		
		var main = $('homeContainer').getHeight();
		var diff = 0;
		
		if (col1_height > col2_height){
			nuHeight = col1_height + "px";
			diff = col1_height - col2_height;
		}else if (col2_height > col1_height){
			nuHeight = col2_height + "px";
			diff = col2_height - col1_height;
		}else{
			//do nothing
		}
		col1_nu.style.height=nuHeight;
		col2_nu.style.height=nuHeight;
		
		$('homeContainer').style.height = main;
	}
}

function init(){
	displayContainer('homeContainer');
	displayContainer('row1_nav');
	setPageHeight('homeContainer');
	setPageHeight('mainContainer');
	setHPColumnHeights();
}

function setCookie(cookieName, cookieValue, nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 3600000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
}

var __date = new Date();
setCookie('timeZoneOffset', __date.getTimezoneOffset(), 1);

// Confirmation popup functions
function confirmCustom(msg) { return confirm(msg); }
function confirmOp(op) { return confirm("You are about to " + op + ".  Do you wish to proceed?"); }
function confirmDelete() { return confirmOp("permanently delete this item"); }

function isIE(){
    return /msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent);
}

window.onload=init;

