var ver = navigator.appVersion;

if (ver.indexOf("MSIE") != -1){
    var DisplayMode = "block";
}else{
    var DisplayMode = "table-row";
}

function resetdata(){

         document.getElementById("step1").style.display = "block";
         document.getElementById("content1").style.display = "block";
         document.getElementById("expandimg1").src =  "http://www.camelbackinn.com/images/collapse.gif";

         document.getElementById("step2_CORP").style.display = "none";
         document.getElementById("nights_row_CORP").style.display = "none";
         document.getElementById("rooms_row_CORP").style.display = "none";
         document.getElementById("step2_EVNT").style.display = "none";
         document.getElementById("rooms_row_EVNT").style.display = "none";
         document.getElementById("step2_GENL").style.display = "none";
         document.getElementById("step3").style.display = "none";

}

function checkdata(dosubmit){

        var theForm = document.rfpform;
        var emailValue = theForm.Email.value;
        var eventType = (theForm.EventType[0].checked) ? theForm.EventType[0].value : theForm.EventType[1].value;

        if(document.getElementById("EventName_"+eventType).value.length<1){
          alert("Please enter a name for your event.");
          document.getElementById("EventName_"+eventType).focus();
        }
        else if(document.getElementById("Requirements_"+eventType).selectedIndex == 0){
          alert("Please select your space & room requirements.");
          document.getElementById("Requirements_"+eventType).focus();
        }
        else if(document.getElementById("Attendees_"+eventType).selectedIndex == 0){
          alert("Please select the number guests/attendees.");
          document.getElementById("Attendees_"+eventType).focus();
        }
        else if(document.getElementById("ArriveDate_"+eventType).value.length<1){
          alert("Please enter your arrival date.");
          document.getElementById("ArriveDate_"+eventType).focus();
        }
        else if(document.getElementById("DepartDate_"+eventType).value.length<1){
          alert("Please enter your departure date.");
          document.getElementById("DepartDate_"+eventType).focus();
        }
        else if(eventType == "CORP" && document.getElementById("KnowNights_"+eventType+"1").checked && document.getElementById("Nights_"+eventType).selectedIndex == 0){
                alert("Please enter your estimated number of nights.");
                document.getElementById("Nights_"+eventType).focus();
        }
        else if(document.getElementById("KnowRooms_"+eventType+"1").checked && document.getElementById("Rooms_"+eventType).selectedIndex == 0){
                alert("Please enter your estimated number of Rooms.");
                document.getElementById("Rooms_"+eventType).focus();
        }
        else if(dosubmit == true) {
                if(eventType == "CORP" && theForm.Organization.value.length<1){
                        alert("Please enter your company/organization.");
                        theForm.Organization.focus();
                }
                else if(theForm.FirstName.value.length<1){
                        alert("Please enter your first name.");
                        theForm.FirstName.focus();
                }
                 else if(theForm.LastName.value.length<1){
                        alert("Please enter your last name.");
                        theForm.LastName.focus();
                }
                 else if((emailValue.indexOf( '@' ) <= 0 ) || (emailValue.indexOf('.',emailValue.indexOf('@')) <= 0 ))
                {
                        alert("Please enter a valid e-mail address.");
                        theForm.Email.focus();
                }
                 else if(theForm.AreaCode.value.length<1){
                        alert("Please enter your area code.");
                        theForm.AreaCode.focus();
                }
                 else if(theForm.Telephone1.value.length<1){
                        alert("Please enter your phone number.");
                        theForm.Telephone1.focus();
                }
                else if(theForm.Telephone2.value.length<1){
                        alert("Please enter your phone number.");
                        theForm.Telephone2.focus();
                }
                 else if(theForm.City.value.length<1){
                        alert("Please enter your city.");
                        theForm.City.focus();
                }
                 else if(theForm.Country.options[theForm.Country.selectedIndex].text == "United States of America" && theForm.State.selectedIndex == 0){
                        alert("Please select your state.");
                        theForm.State.focus();
                }
                 else if(theForm.PreferContact[2].checked && theForm.Address1.value.length<1){
                        alert("Please enter your address.");
                        theForm.Address1.focus();
                }
                 else if(theForm.PreferContact[2].checked && theForm.Zip.value.length<1){
                        alert("Please enter your zip code.");
                        theForm.Zip.focus();
                }
                else {
                        theForm.submit();
                }
        }
        else {
                showStep3();
        }
}

function showStep2() {
        for (i=0; i < document.rfpform.EventType.length; i++) {
                document.getElementById("step2_"+document.rfpform.EventType[i].value).style.display = (document.rfpform.EventType[i].checked) ? "block" : "none";
                // make sure content is expanded
                if (i <= 1 && document.rfpform.EventType[i].checked) document.getElementById("content2_"+document.rfpform.EventType[i].value).style.display = "block";
        }
        document.getElementById("step3").style.display = "none";
        // close step 1
        toggleSections("1","");
}

function toggleNights(typ) {
        document.getElementById("nights_row_"+typ).style.display =  (document.getElementById("KnowNights_"+typ+"1").checked) ? DisplayMode : "none";
        if (document.getElementById("KnowNights_"+typ+"2").checked) document.getElementById("Nights_"+typ).value = "";
}

function toggleRooms(typ) {
        document.getElementById("rooms_row_"+typ).style.display =  (document.getElementById("KnowRooms_"+typ+"1").checked) ? DisplayMode : "none";
        if (document.getElementById("KnowRooms_"+typ+"2").checked) document.getElementById("Rooms_"+typ).value = "";
}

function showStep3() {
        document.getElementById("step3").style.display = "block";
        // make sure content is expanded
        document.getElementById("content3").style.display = "block";
        document.getElementById("company_row").style.display =  (document.rfpform.EventType[0].checked) ? DisplayMode : "none";
        //collapse other sections
        if (document.getElementById("content1").style.display != "none") toggleSections("1","");
        if (document.getElementById("step2_CORP").style.display != "none" && document.getElementById("content2_CORP").style.display != "none") toggleSections("2","_CORP");
        if (document.getElementById("step2_EVNT").style.display != "none" && document.getElementById("content2_EVNT").style.display != "none") toggleSections("2","_EVNT");
}

function toggleAddress() {
        var theDisplay = (document.rfpform.PreferContact[2].checked) ? DisplayMode : "none";
        document.getElementById("address1_row").style.display = theDisplay;
        document.getElementById("address2_row").style.display = theDisplay;
        document.getElementById("city_row").style.display = theDisplay;
        document.getElementById("zip_row").style.display = theDisplay;
}

function toggleStates() {
        if (document.rfpform.Country.options[document.rfpform.Country.selectedIndex].text == "United States of America") {
                document.getElementById("state_dd_row").style.display = DisplayMode;
                document.getElementById("stateprovince_row").style.display = "none";
        } else {
                document.getElementById("state_dd_row").style.display = "none";
                document.getElementById("stateprovince_row").style.display = DisplayMode;
        }
}

function toggleSections(s,et) {
        var contentDiv = document.getElementById("content"+s+et);
        // don't collapse section 1 if nothing is checked
        if (s == 1 && contentDiv.style.display != "none" && (!document.rfpform.EventType[0].checked && !document.rfpform.EventType[1].checked)) {
        // don't expand section 2 if nothing is checked
        } else if (s > 1 && contentDiv.style.display == "none" && (!document.rfpform.EventType[0].checked && !document.rfpform.EventType[1].checked)) {
        } else {
                document.getElementById("expandimg"+s+et).src = (contentDiv.style.display == "none") ? "http://www.camelbackinn.com/images/collapse.gif" : "http://www.camelbackinn.com/images/expand.gif";
                contentDiv.style.display = (contentDiv.style.display == "none") ? "block" : "none";
        }
}
