﻿/// <reference path="jquery.min-vsdoc.js" />


function SurveyInit() {
    $("[ID$='_txtEnrolledMilitaryStudents']").bind("blur",CalculateMilStudentPercent);
    $("[ID$='_txtEnrolledStudentsTotal']").bind("blur", CalculateMilStudentPercent);

    $(".tipAnchor").hover(
        function() {
            $(this).toggleClass("tipHovering");
        }, function() {
            $(this).toggleClass("tipHovering");
        }
    );

    $(".tipAnchorBig").hover(
        function() {
            $(this).toggleClass("tipHovering");
        }, function() {
            $(this).toggleClass("tipHovering");
        }
    ); 

}

function CalculateMilStudentPercent() {
    var milStudents = $("[ID$='_txtEnrolledMilitaryStudents']").val();
    var totStudents = $("[ID$='_txtEnrolledStudentsTotal']").val();
    var $txtMilPercent = $("[ID$='_txtMilitaryStudentPercent']");
    if (milStudents != null && milStudents != 0 && 
            totStudents != null && totStudents != 0) {
        var pct = parseFloat(milStudents)/parseFloat(totStudents);
        pct = pct * 100;
        $txtMilPercent.val(pct.toFixed(2));
    }
}

function CalculateSchoolDescCount(){
    var $tb = $("[ID$='_txtSchoolDescription']");
    var $lbl = $("[ID$='txtSchoolDescriptionChars']");
    if ($tb.val().length <= 1000) {
        $lbl.html((1000 - $tb.val().length) + " characters left");
    } else {
        $lbl.html("<span style='color: #f00;'>Over 1000 character limit! Text will be lost!</span>");
    }
}

function alertContactRequired() {
    var $contactID = $("[ID$='_hidSelectedContactID']");
    if ($contactID.val() == null || $contactID.val() == '') {
        alert("You must select a contact from the list to continue");
    }
}


function copySchoolAddressInfo() {
    if ($("[ID$='chkCopyAddress']").attr("checked") == true) {
        $("[ID$='txtStreetAddress1']").val($("[ID$='txtSchoolStreetAddress']").val());
        $("[ID$='txtMailStop']").val($("[ID$='txtSchoolMailStop']").val());
        $("[ID$='txtStreetAddress2']").val($("[ID$='txtSchoolStreetAddress2']").val());
        $("[ID$='txtStreetAddress3']").val($("[ID$='txtSchoolStreetAddress3']").val());
        $("[ID$='txtCity']").val($("[ID$='txtSchoolCity']").val());
        $("[ID$='ddlState']").val($("[ID$='ddlSchoolState']").val());
        $("[ID$='txtZip']").val($("[ID$='txtSchoolZip']").val());
    } else {
        $("[ID$='txtStreetAddress1']").val('');
        $("[ID$='txtMailStop']").val('');
        $("[ID$='txtStreetAddress2']").val('');
        $("[ID$='txtStreetAddress3']").val('');
        $("[ID$='txtCity']").val('');
        $("[ID$='ddlState']").val('');
        $("[ID$='txtZip']").val('');
    }
}

function displayCharsLeft(textbox, label) {
    var max = $(textbox).attr('maxlength');
    var val = $(textbox).attr('value');
    var cur = 0;
    var remaining = 0;
    if (val) cur = val.length;
    remaining = max - cur;
    if (remaining < 0) {
        $(label).text("last " + (-remaining).toString() + " characters will be lost");
    } else {
        $(label).text(remaining.toString() + " characters remaining");
    }
}


function copyBillingInfo(opt) {
    if (opt !== true) {
        $("[ID$='txtShipFname']").val('');
        $("[ID$='txtShipLname']").val('');
        $("[ID$='txtShipAddress1']").val('');
        $("[ID$='txtShipAddress2']").val('');
        $("[ID$='txtShipCity']").val('');
        $("[ID$='ddlShipState']").val(0);
        $("[ID$='txtShipZip']").val('');
        $("[ID$='txtShipEmail']").val('');
        $("[ID$='txtShipPhone1']").val('');
        $("[ID$='txtShipPhone2']").val('');
        $("[ID$='txtShipPhone3']").val('');
    } else {
        $("[ID$='txtShipFname']").val($("[ID$='txtBillFname']").val());
        $("[ID$='txtShipLname']").val($("[ID$='txtBillLname']").val());
        $("[ID$='txtShipAddress1']").val($("[ID$='txtBillAddress1']").val());
        $("[ID$='txtShipAddress2']").val($("[ID$='txtBillAddress2']").val());
        $("[ID$='txtShipCity']").val($("[ID$='txtBillCity']").val());
        $("[ID$='ddlShipState']").val($("[ID$='ddlBillState']").val());
        $("[ID$='txtShipZip']").val($("[ID$='txtBillZip']").val());
        $("[ID$='txtShipEmail']").val($("[ID$='txtBillEmail']").val());
        $("[ID$='txtShipPhone1']").val($("[ID$='txtBillPhone1']").val());
        $("[ID$='txtShipPhone2']").val($("[ID$='txtBillPhone2']").val());
        $("[ID$='txtShipPhone3']").val($("[ID$='txtBillPhone3']").val());
    }
}