
var lstBusinessStates_ClientID = '_ctl0__ctl0_cphContent_cphContentCenter__ctl0_lstCollegeStates';
var lstBusinessSchools_ClientID = '_ctl0__ctl0_cphContent_cphContentCenter__ctl0_lstCollegesConsidering';
var bShowEmptyEntries_BusinessSchool = false;
var bIgnoreViewBusinessProfile = false;

var lstBusinessState;
var lstBusinessSchools;
var spnBusinessSchoolProfile;
var bBusinessSchoolProfile;

function BusinessSchoolGetByState_OnLoad()
{
    lstBusinessState = document.getElementById(lstBusinessStates_ClientID);
    lstBusinessSchools = document.getElementById(lstBusinessSchools_ClientID);
    spnBusinessSchoolProfile = document.getElementById('spnViewProfile');
    bBusinessSchoolProfile = (spnBusinessSchoolProfile != null);
    
    if (lstBusinessState != null)
    {
        lstBusinessState.onchange = function(){lstBusinessStates_Change();};
        if (bBusinessSchoolProfile && !bIgnoreViewBusinessProfile)
        {
            lstBusinessSchools.onchange = function(){showHideViewBusinessSchoolProfileButton(false);};
            spnBusinessSchoolProfile.onclick = function(){openBusinessSchoolProfile();};
        }
    }
    
    showHideViewBusinessSchoolProfileButton(false);
}
function lstBusinessStates_Change()
{
    var iState = parseInt(lstBusinessState.options[lstBusinessState.selectedIndex].value);
    if (iState > 0)
        ResetBusinessSchools_AJAX(iState, false);
    else
        OnSucceeded_BSchoolUpdate(null, null);
        
}

function ResetBusinessSchools_AJAX(iState, bAllBusinessSchools)
{
    Searches.Ajax.Business.GetByState.AJAX_GetBusinessSchools(iState,
                                                              bShowEmptyEntries_BusinessSchool,
                                                              OnSucceeded_BSchoolUpdate,
                                                              OnFailed_BSchoolUpdate);
}
       
function OnSucceeded_BSchoolUpdate(result,
                            eventArgs)
{
    var aBusinessSchools = result;
    var aTemp;
    var oBusinessSchool;
    var i;
    
    var sTemp = '';
    
    //Eliminate Existing BusinessSchool Options
    var oExisting = lstBusinessSchools.options.length;
    for (i = 0; i < oExisting; i++)
    {
        lstBusinessSchools.remove(0);
    }

   //If Array contains BusinessSchools, add them to lstBusinessSchools
   //

    if (aBusinessSchools != null && typeof(aBusinessSchools) == "object")
    {
        for (i = 0; i < aBusinessSchools.length; i++)
        {
            aTemp = aBusinessSchools[i];
            oBusinessSchool = document.createElement("OPTION");
            oBusinessSchool.text = aTemp[0];
            oBusinessSchool.value = aTemp[1];
            
            lstBusinessSchools.options[lstBusinessSchools.options.length] = oBusinessSchool;
        }
        lstBusinessSchools.SelectedIndex = 0;
        lstBusinessSchools.style.display = "";
    }
    
    showHideViewBusinessSchoolProfileButton(true);
}

function OnFailed_BSchoolUpdate(error)
{
    document.getElementById('spnMessage').innerHTML = 'Error';
}

var sBusinessSchoolName = '';
var iBusinessSchoolID = 0;
function showHideViewBusinessSchoolProfileButton(bAutoHide)
{
    if (bBusinessSchoolProfile)
    {
	    if (lstBusinessSchools.selectedIndex > -1)
		    iBusinessSchoolID = parseInt(lstBusinessSchools.options[lstBusinessSchools.selectedIndex].value);
    	
	    if (iBusinessSchoolID <= 0 || bAutoHide)
		    spnBusinessSchoolProfile.style.visibility = "hidden";
	    else
		    spnBusinessSchoolProfile.style.visibility = "visible";
	}
}
	
function openBusinessSchoolProfile()
{
	if (lstBusinessSchools.selectedIndex > -1)
	{
		iBusinessSchoolID = parseInt(lstBusinessSchools.options[lstBusinessSchools.selectedIndex].value);
		if (iBusinessSchoolID > 0)
		{
		    Searches.Ajax.Business.GetByState.AJAX_sBusinessSchoolName(lstBusinessSchools.options[lstBusinessSchools.selectedIndex].text,
		                                                       OnSucceeded_sBusinessSchoolName,
                                                               OnFailed_sBusinessSchoolName);
            window.setTimeout("BusinessSchoolProfilePopup()", 300);
        }
	}
}
function OnSucceeded_sBusinessSchoolName(result, eventArgs){sBusinessSchoolName = result.toLowerCase();}
function OnFailed_sBusinessSchoolName(error){sBusinessSchoolName = '';}
function BusinessSchoolProfilePopup(){window.open('http://controls.collegetoolkit.com/co/controls/business/overview/' + sBusinessSchoolName + '/' + iBusinessSchoolID + '.aspx');}