﻿/*********************************/
/* OnBoard Navigator Scripts     */
/*********************************/
function OnBoardNavigator()
{
    var input = null;
    
    this.Initialize = function(userInput)
    {
        this.input = userInput
    }
    
    this.GetURL = function(type) 
    {
        var url = null;
        if (this.input && this.input != null)
        {
            //url = "http://www.onboardnavigator.com/webcontent/OBWC_Results.aspx?&AID=591-d4bcea6e99ea&SearchType=1&Datatype=";
            url = "http://www.onboardnavigator.com/1.5/webContent/OBWC_Results.aspx?&AID=591-d4bcea6e99ea&SearchType=1&Datatype=";
            url += type;
            if (this.input.city != null)
            {
                url += "&city="+this.input.city;
            }
            
            if (this.input.state != null)
            {
                url += "&state="+this.input.state;
            }
            
            if (this.input.postalCode != null)
            {
                url += "&zip="+this.input.postalCode;
            }
            
            if (this.input.neighborhood != null && this.input.neighborhood != this.input.city)
            {
                url += "&nhood="+this.input.neighborhood;
            }
        }
        return url;   
    } 
    
   
    this.GetCommunityURL = function()
    {
        return this.GetURL(1);
    }
    
    this.GetSchoolURL = function()
    {
        return this.GetURL(2);
    }
    
    this.GetHomeSalesURL = function()
    {
        return this.GetURL(4);
    }
    
    this.GetCommunityComparisonURL = function()
    {
        return this.GetURL(5);
    }
    
    this.OpenURL = function(url, largeWindow)
    {
        var onBoardWindow = null;
        if (!largeWindow)
        {
            onBoardWindow = window.open(url,'BHGOnBoardNavigator','width=640,height=650,scrollbars=yes,toolbar=yes,titlebar=yes,menubar=yes,location=yes,status=yes,resizable=yes,directories=yes'); 
        }
        else
        {
            onBoardWindow = window.open(url,'BHGOnBoardNavigator','width=918,height=650,scrollbars=yes,toolbar=yes,titlebar=yes,menubar=yes,location=yes,status=yes,resizable=yes,directories=yes'); 
        }
        
        if (onBoardWindow != null)
        {
            onBoardWindow.focus();
        }
    }
    
    this.OpenCommunityURL = function()
    {
        var url = this.GetCommunityURL();
        if (url != null)
        {
            this.OpenURL(url, true);
        }
    }
    
    this.OpenSchoolURL = function()
    {
        var url = this.GetSchoolURL();
        if (url != null)
        {
            this.OpenURL(url, true);
        }
    }
    
    this.OpenHomeSalesURL = function()
    {
        var url = this.GetHomeSalesURL();
        if (url != null)
        {
            this.OpenURL(url, true);
        }
    }
    
    this.OpenCommunityComparisonURL = function()
    {
        var url = this.GetCommunityComparisonURL();
        if (url != null)
        {
            this.OpenURL(url, true);
        }
    }
}     

/****************************/
/* Homepage OnBoard Scripts */
/****************************/
var onBoard = null;
var parsedAddress = null;
function switchTabs(page, element)	{ 
    if (element == 'tab-look' && document.getElementById(element).style.display != 'block')
    {
        //coming to look tab from other tab
        document.getElementById('look-tabs-list').style.display = 'none';
        document.getElementById('home-look-instr').style.display = 'block';     
    }
    document.getElementById('tab-look').style.display = 'none';
    document.getElementById('tab-learn').style.display = 'none';
    document.getElementById('tab-live').style.display = 'none';
    document.getElementById(element).style.display = 'block';
}

function onBoardAddressClick()
{
    var input = document.getElementById('tab-look-neighborhood').value;
    if (input != "Enter City & State or ZIP")
    {
        onBoard = new OnBoardNavigator();
        YAHOO.util.Cookie.set("DL", input, { path: "<%=BasePath%>", expires: new Date("January 12, 2025") });
        updateDefaultLocationTextBoxes(input);
        parsedAddress = processAddressInput(input);
        if (parsedAddress.postalCode != null && parsedAddress.state == null)
        {
            PageMethods.GetStateCodeFromZip(parsedAddress.postalCode, zipToStateCallback);   
        }
        else
        {
            initializeOnBoard();
        }
    }
    else
    {
        return false;
    }
}

function initializeOnBoard()
{
    onBoard.Initialize(parsedAddress);
    document.getElementById('home-look-instr').style.display = 'none'; 
    document.getElementById('look-tabs-list').style.display = 'block';
}

function zipToStateCallback(cityState)
{
    if (cityState.State != null && cityState.State != "")
    {
        parsedAddress.state = cityState.State;  
    }
    
    if (parsedAddress.city == null && cityState.City != null && cityState.City != "")
    {
        parsedAddress.city = cityState.City;  
    }    
    initializeOnBoard();
}

function navigateToOnBoard(reportType)
{
    if (onBoard != null)
    {
        var url = null;
        switch (reportType)
        {
            case 1:
                onBoard.OpenHomeSalesURL();
                break;
            case 2:
                onBoard.OpenSchoolURL();
                break;
            case 3:
                onBoard.OpenCommunityURL();
                break;
        }
    }
}

/*************************/
/* Look Section Scripts  */
/*************************/
function toggleDetails(open, close)	{
	if (open == 'valuations-result')	{
		addressDefault = 'Street Address';
		cityDefault = 'Enter City & State or ZIP';
		address = document.getElementById('home-val-address').value;
		city = document.getElementById('home-val-city').value;
		if (address == addressDefault || city == cityDefault)	{
			document.getElementById('val-message').className = 'error';
		}
		else	{
			document.getElementById('valuation-address').innerHTML = address + ' ' + city;
			document.getElementById(open).style.height = document.getElementById(close).offsetHeight;
			document.getElementById(close).style.display = 'none';
			document.getElementById(open).style.display = 'block';
		}
	}
	else if (open == 'valuations-enter-address')	{
		document.getElementById('home-val-address').value = addressDefault;
		document.getElementById('home-val-city').value = cityDefault;
		document.getElementById(close).style.display = 'none';
		document.getElementById(open).style.display = 'block';
		document.getElementById('val-message').className = '';
	}
	else if (open == 'look-search-results')	{
		
		if (document.getElementById('tab-look-neighborhood').value == 'Enter City & State or ZIP')	{
			document.getElementById('look-icon-error').style.display = 'block';
		}
		else	{
			//document.getElementById('look-landing-right').className = 'look-cont cont-right';
    		document.getElementById('look-overlay').style.display = 'none';
			document.getElementById(close).style.display = 'none';
			document.getElementById('look-icon-error').style.display = 'none';
			document.getElementById(open).style.display = 'block';
		}
	}
	else if (open == 'look-search')	{
		//document.getElementById('look-landing-right').className = 'look-cont cont-right ghost';
		document.getElementById('tab-look-neighborhood').value = 'Enter City & State or ZIP';
        document.getElementById('look-overlay').style.display = 'block';
		document.getElementById(close).style.display = 'none';
		document.getElementById(open).style.display = 'block';
	}
	else	{
		document.getElementById(close).style.display = 'none';
		document.getElementById(open).style.display = 'block';
	}
	
}
