﻿var application = {
    apply: function() {
        var html = [];
        html[html.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td class="edit-title" width="100%">START a PENCIL Partnership</td>';
        html[html.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        html[html.length] = '     </tr>';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td colspan="2">';
        html[html.length] = '             <table cellspacing="0" cellpadding="5" border="0" width="100%">';
        html[html.length] = '                 <tr>';
        html[html.length] = '                   <td><input type="radio" id="radBP" name="register" checked /></td>';
        html[html.length] = '                   <td>Business Partner Application</td>';
        html[html.length] = '                   </tr>';
        html[html.length] = '                   <tr>';
        html[html.length] = '                   <td><input type="radio" id="radSP" name="register" /></td>'
        html[html.length] = '                   <td>School Application</td>';
        html[html.length] = '                 </tr>';
        html[html.length] = '             </table>';
        html[html.length] = '         </td>';
        html[html.length] = '     </tr>';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td colspan="2" class="edit-title" align="right"><input type="button" value="Continue" onclick="application.register();" />&nbsp;<input type="button" value="Cancel" onclick="shadow.hide()" /></td>';
        html[html.length] = '     </tr>';
        html[html.length] = '</table>';
        var application = document.getElementById('selectApplication');
        if (application) {
            application.innerHTML = html.join('');
            shadow.show(application, false);
        }
    },

    register: function() {
        var radBP = document.getElementById('radBP') && document.getElementById('radBP').checked;
        if (radBP) {
            document.location = "bpregister.htm";
        }
        else {
            document.location = "spregister.htm";
        }
    },

    applyForLocation: function() {
        var html = [];
        html[html.length] = '<table cellspacing="0" cellpadding="5" border="0" width="100%">';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td class="edit-title" width="100%">START a PENCIL Partnership</td>';
        html[html.length] = '         <td class="edit-title" align="right"><input type="button" value=" x " onclick="shadow.hide()" /></td>';
        html[html.length] = '     </tr>';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td colspan="2">';
        html[html.length] = '             <table cellspacing="0" cellpadding="5" border="0" width="100%">';
        html[html.length] = '                 <tr><td colspan="2"><table><tr>';
        html[html.length] = '                 <td>Location: ';
        html[html.length] = '                 </td>';
        html[html.length] = '                 <td><select id = "ddLocation" style="width:100px;"><option value="0">-Select-</option><option value="1" name="New York">New York</option><option value="2" name="Rochester">Rochester</option><option value="3" name="Baltimore">Baltimore</option></select><div id="validLocation" style="display:none" class="Validation-control"></div>';
        html[html.length] = '                 </td></tr></table></td>';
        html[html.length] = '                 </tr>';



        html[html.length] = '                 <tr>';
        html[html.length] = '                   <td><input type="radio" id="radBP" name="register"/></td>';
        html[html.length] = '                   <td>Business Partner Application</td>';
        html[html.length] = '                   </tr>';
        html[html.length] = '                   <tr>';
        html[html.length] = '                   <td><input type="radio" id="radSP" name="register" /></td>'
        html[html.length] = '                   <td>School Application<div id="validAppType" style="display:none" class="Validation-control"></td>';
        html[html.length] = '                 </tr>';
        html[html.length] = '             </table>';
        html[html.length] = '         </td>';
        html[html.length] = '     </tr>';
        html[html.length] = '     <tr>';
        html[html.length] = '         <td colspan="2" class="edit-title" align="right"><input type="button" value="Continue" onclick="application.registerForLocation();" />&nbsp;<input type="button" value="Cancel" onclick="shadow.hide()" /></td>';
        html[html.length] = '     </tr>';
        html[html.length] = '</table>';
        var application = document.getElementById('selectApplication');
        if (application) {
            application.innerHTML = html.join('');
            shadow.show(application, false);
        }
    },


    registerForLocation: function() {

        var returnValue = true;
        var focusControl = null;

        var locationId = document.getElementById('ddLocation').value;
        var appType = document.getElementById("radBP").checked || document.getElementById("radSP").checked;


        if (locationId == "" || locationId == 0) {
            //alert("Please enter number of years!");
            document.getElementById("validLocation").innerHTML = "Please select location.";
            document.getElementById("validLocation").style.display = "block";
            focusControl = document.getElementById("ddLocation");
            returnValue = false;
        }
        else {
            document.getElementById("validLocation").style.display = "none";

        }

        if (!appType) {
            document.getElementById("validAppType").innerHTML = "Please select application type.";
            document.getElementById("validAppType").style.display = "block";
            focusControl = document.getElementById("radBP");
            returnValue = false;
        }
        else {
            document.getElementById("validAppType").style.display = "none";

        }

        if (!returnValue) {
            focusControl.focus();
            return false;
        }


        var radBP = document.getElementById('radBP') && document.getElementById('radBP').checked;

        var ddLocation = document.getElementById('ddLocation');
        var homesite
        if(ddLocation.value==2)
        {
            homesite="www.rcsdk12.org";
        }
        else if(ddLocation.value==3)
        {
            homesite="www.bvumaryland.org";
        } 
        if (radBP) {
            document.location = "bpregister.htm?locationId=" + ddLocation.value + "&locationName=" + ddLocation.options[ddLocation.selectedIndex].text + "&homesite="+ homesite +"&affiliatelogo=" + ddLocation.options[ddLocation.selectedIndex].text + ".JPG";
        }
        else {
            document.location = "spregister.htm?locationId=" + ddLocation.value + "&locationName=" + ddLocation.options[ddLocation.selectedIndex].text + "&homesite="+ homesite +"&affiliatelogo=" + ddLocation.options[ddLocation.selectedIndex].text + ".JPG"; ;
        }
    },

    showLoginPage: function() {
        document.location = "spregister.htm?locationId=" + ddLocation.value + "&locationName=" + ddLocation.options[ddLocation.selectedIndex].text + "&homesite=www.google.com&affiliatelogo=" + ddLocation.options[ddLocation.selectedIndex].text + ".JPG"; ;
    }
}