﻿
// ####################################
// ########## School Object ##########
// ####################################

function School()
{  
    this.VEShapeLayer = _schoolLayer; // VEShapeLayer
    this.VEShape = null;
    this.SchoolId = null;
	this.InstitutionType = null;
    this.DistrictName = null;
    this.SchoolType = null;
    this.CountyName = null;
    this.Latitude = null;
    this.Longitude = null;
    this.SchoolName = null;
    this.Address = null;
    this.City = null;
    this.State = null;
    this.PostalCode = null;
    this.Phone = null;
    this.EducationalClimate = null;
    this.AdvancedPlacement = null;
    this.BeforeAndAfterSchoolPrograms = null;
    this.BlueRibbonSchool = null;
    this.CoalitionOfEssentialSchools = null;
    this.CharterSchool = null;
    this.GiftedAndTalented = null;
    this.MagnetSchool = null;
    this.GradeSpan = null;
    this.StudentCount = null;
}

School.prototype.Populate = function(schoolItems) {

    if ((schoolItems === undefined) || (schoolItems === null)) { return; }
    if ((schoolItems.id === undefined) && (schoolItems.id === null)) { return; }


    this.SchoolId = schoolItems.id;
    this.InstitutionType = schoolItems.institutionType;
    this.DistrictName = schoolItems.schoolDistrictName;
    this.SchoolType = schoolItems.institutionType;
    this.CountyName = schoolItems.county;
    this.Latitude = schoolItems.latitude;
    this.Longitude = schoolItems.longitude;
    this.SchoolName = schoolItems.schoolName;
    this.Address = schoolItems.addressLine1;
    this.City = schoolItems.city;
    this.State = schoolItems.state;
    this.PostalCode = schoolItems.zip5;
    this.StudentCount = schoolItems.enrollmentCnt;
    this.Phone = schoolItems.phone;
    this.GradeSpan = schoolItems.lowestGrade + '-' + schoolItems.highestGrade;

    // HJ does not provide the following items
    //this.EducationalClimate = null;
    //this.AdvancedPlacement = null;
    //this.BeforeAndAfterSchoolPrograms = null;
    //this.CoalitionOfEssentialSchools = null;
    //this.GiftedAndTalented = null;
}

School.prototype.DisplayShapeArray = function(array) 
{   
    this.VEShapeLayer.AddShape(array);
}

School.prototype.GetShape = function() {
    var descrip = '';

    this.VEShape = new VEShape(VEShapeType.Pushpin, new VELatLong(this.Latitude, this.Longitude));
    this.VEShape.SetTitle(this.SchoolName);
    
    if( (this.Address !== null) && (this.City !== null) && (this.State !== null) && (this.PostalCode !== null) ) {
        descrip += this.Address + "<br />" + this.City + ", " + this.State + " " + this.PostalCode + "<br />";
    }
    descrip += '<a href="javascript:popUpCenteredWindow(\'SchoolDetail.aspx?SchoolID=' + this.SchoolId + '\');">Click to view Details..</a><br /><br /><ul>';

    if (this.SchoolType != null) {
        descrip += (this.SchoolType != 'Unknown') ? "<li>" + this.SchoolType : "";
    }

    if (this.GradeSpan !== null) {
        descrip += "<li>Grades " + this.GradeSpan;
    }

    if (this.StudentCount !== null) {
        descrip += '<li>' + this.StudentCount + ' students';
    }

    if (this.AdvancedPlacement !== null) {
        descrip += (this.AdvancedPlacement != 'False') ? "<li>Advanced Placement" : "";
    }

    if (this.BeforeAndAfterSchoolPrograms !== null) {
        descrip += (this.BeforeAndAfterSchoolPrograms != 'False') ? "<li>After School Programs" : "";
    }

    if (this.BlueRibbonSchool !== null) {
        descrip += (this.BlueRibbonSchool != 'False') ? "<li>Blue Ribbon School" : "";
    }

    if (this.CharterSchool !== null) {
        descrip += (this.CharterSchool != 'False') ? "<li>Charter School" : "";
    }

    if (this.GiftedAndTalented !== null) {
        descrip += (this.GiftedAndTalented != 'False') ? "<li>Gifted and Talented" : "";
    }

    if (this.MagnetSchool !== null) {
        descrip += (this.MagnetSchool != 'False') ? "<li>Magnet School" : "";
    }

    descrip += '</ul><div style="font-size:.7em;position:absolute;bottom:3px;right:3px"><br />information provided by home junction.</span>';

    this.VEShape.SetDescription(descrip);
    this.VEShape.SetCustomIcon("../App_Themes/Default/Images/Map/icon_school.gif");
    return this.VEShape;

}

School.prototype.GetGridRowData = function(n)
{
    var addr = this.Address+'<br />'+this.City+',&nbsp;'+this.State+'&nbsp;'+this.PostalCode;
    var row = "<div><span style=\"font-size:.75em;color:#646464;\"><a style=\"color:#3f4065\" href=\"javascript:popUpCenteredWindow(\'SchoolDetail.aspx?SchoolID="+this.SchoolId+"\');\">"+this.SchoolName+"</a></span></div>"
            + "<div><span style=\"font-size:.75em;color:#a4a4a4;\">"+addr+"</span></div><br />";
	return row;
}

School.prototype.DisplayGridArray = function(array)
{
    document.getElementById('divSchoolResults').innerHTML = array.join('');
}
