﻿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>';
        html[html.length] = '             <table>';
        html[html.length] = '                 <tr>';
        html[html.length] = '                   <td>Location:</td>';
        html[html.length] = '                   <td>';

        html[html.length] = '                   <select id="ddLocation">'        
        html[html.length] = '                   <option name="NEW YORK" value="1">NEW YORK</option><option name="ROCHESTER" value="2">ROCHESTER</option><option name="BALTIMORE" value="3">BALTIMORE</option><option name="PHILADELPHIA" value="5">PHILADELPHIA</option>';
        html[html.length] = '                   </select>'     
        //this.jsonservice.loadScript("content_fetchbreads_0001", "services/content.aspx?action=fetchbreads&id=" + this.pageId + "&callback=myContentMgr.setBreads&expires=600");   
        html[html.length] = '                   </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">';
        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;
        var location = document.getElementById('ddLocation').value;
        var locationName = (location==1)?"NEW YORK":(location==2)?"ROCHESTER":"BALTIMORE";
        if (location == 5) {locationName = "PHILADELPHIA"};
        if (radBP) {
            document.location = "bpregister.htm?locationId="+location+"&locationName="+locationName+"&affiliatelogo=" + ddLocation.options[ddLocation.selectedIndex].text + ".JPG";
        }
        else {
            document.location = "spregister.htm?locationId="+location+"&locationName="+locationName+"&affiliatelogo=" + ddLocation.options[ddLocation.selectedIndex].text + ".JPG";
        }
    },

    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>';
        
        html[html.length] = '                 <select id="ddLocation" style="width:100px;">';
        html[html.length] = '                 <option value="0">-Select-</option>';
        html[html.length] = '                 <option value="1" name="New York">New York</option><option value="2" name="Rochester">Rochester</option><option value="3" name="Baltimore">Baltimore</option><option value="5" name="Philadelphia">Philadelphia</option>';
        html[html.length] = '                 </select>';
        
        html[html.length] = '                 <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"; ;
    }
}
