


$(document).ready(function () {

    //The following marks specific feilds as required depending on the 
    //selection from a dropdown on how one would like to be contacted.
    //There are four options (phone: business or home or mobile; and
    //email, all of which set the pertinent field as required (with a
    //red asterisk. The last option 'mail' makes the address 1, city,
    //zipcode and country fields 'required.' NOTE: the State/Region
    //is always marked as required and is not affected by any of 
    //the selections in this dropdown.

    var contactPref = $('#RequestConsultation1_MyPanel').find('#RequestConsultation1_new_contactpreference-Picklist');
    contactPref.live('change', function () {
        //get non-verbose pointer to the ID of the selected option
        var contactPrefValue = $('#RequestConsultation1_new_contactpreference-Picklist option:selected').val();
        //reset everything just in case not the first
        //time making a selection
        resetAll();
        //if option 3 (mail) hasn't been selected, clear mail fields
        //and set selected field as 'required' 
        if (contactPrefValue != '3') {
            mailIsReq(false); makeInputReq(contactPrefValue);
        } else { mailIsReq(true); }
    });

    function resetAll() {
        //removes the red asterisk, the 'required' class and the 'Required' label added after a submit action.
        var businessPhone = $('#RequestConsultation1_telephone1-String'); businessPhone.prev().html('Business Phone:'); businessPhone.next().html(''); addReqClass(businessPhone, false); //business phone
        var email = $('#RequestConsultation1_emailaddress1-String'); email.prev().html('E-mail:'); email.next().html(''); addReqClass(email, false); //email
        var mobilePhone = $('#RequestConsultation1_mobilephone-String'); mobilePhone.prev().html('Mobile Phone:'); mobilePhone.next().html(''); addReqClass(mobilePhone, false); //mobile phone
        var homePhone = $('#RequestConsultation1_telephone2-String'); homePhone.prev().html('Home Phone:'); homePhone.next().html(''); addReqClass(homePhone, false); //home phone
    }
    function makeInputReq(selectedValue) {
        //based on the selected option, load a less verbose pointer
        //with the ID of the input to be made a 'required' field
        switch (selectedValue) {
            case '1': txtBoxId = $('#RequestConsultation1_telephone1-String'); break; //business phone
            case '2': txtBoxId = $('#RequestConsultation1_emailaddress1-String'); break; //email
            //This option sets multiple fields as required and so 
            //must be handled with a different set of functions 
            case '3': mailIsReq(true); break; //mail - just in case
            case '4': txtBoxId = $('#RequestConsultation1_mobilephone-String'); break; //mobile phone
            case '5': txtBoxId = $('#RequestConsultation1_telephone2-String'); break; //home phone
        }
        //if 'mail' isn't selected set the field as 'required'
        if (selectedValue != '3') setAsteriskEtc(txtBoxId);
    }
    function setAsteriskEtc(txtBoxId) {
        //add the required class        
        addReqClass(txtBoxId, true);
        //get the text from the label before the input
        var temp = txtBoxId.prev().html();
        //add red asterisk to indicate required field
        addReqIndicator(txtBoxId, temp, true);
    }
    function addReqClass(id, yesno) {
        //if 'true' add the 'required' class [else] remove the 'required' class
        if (yesno) { id.addClass('required'); } else { id.removeClass('required'); }
    }
    function addReqIndicator(txtBoxId, labelText, yesno) {
        //if 'true' add red asterisk to indicate required field
        //[else] just add the text to the label
        if (yesno) {
            txtBoxId.prev().html('<i style="color:red">* </i>' + labelText);
        } else { txtBoxId.prev().html(labelText); }
    }
    function mailIsReq(yesno) {
        //get less verbose pointers to the id's of the inputs
        var address = $('#RequestConsultation1_address1_line1-String');
        var city = $('#RequestConsultation1_address1_city-String');
        var zipcode = $('#RequestConsultation1_address1_postalcode-String');
        var country = $('#RequestConsultation1_address1_country-String');
        if (yesno) {//true
            //add red asterisk to indicate a required field
            addReqIndicator(address, address.prev().html(), yesno);
            addReqIndicator(city, city.prev().html(), yesno);
            addReqIndicator(zipcode, zipcode.prev().html(), yesno);
            addReqIndicator(country, country.prev().html(), yesno);
        } else {//flase
            //remove red asterisk indicator by re-writing the original label
            //remove 'Required' label after the input.
            addReqIndicator(address, 'Street 1:', yesno); address.next().html('');
            addReqIndicator(city, 'City:', yesno); city.next().html('');
            addReqIndicator(zipcode, 'ZIP/Postal Code:', yesno); zipcode.next().html('');
            addReqIndicator(country, 'Country/Region:', yesno); country.next().html('');
        }
        //add class required to all
        addReqClass(address, yesno);
        addReqClass(city, yesno);
        addReqClass(zipcode, yesno);
        addReqClass(country, yesno);
    }
    //end ***  

    var pathname = window.location.pathname;
    pathname = pathname.toLowerCase();

    $("#requestSubmit").live("click", function () {

        var validated = "true";
        var xmldoc = "<xml>";

        setCookie("formCookie", "true", 365);
        //alert("requestsubmit");

        $('#RequestConsultation1_MyPanel').children(':first-child').children().each(function (index, eleDom) {

            var html = $(eleDom).children(':nth-child(1)');
            var input = $(html).next();
            //var input = $(eleDom).children(':nth-child(1)');
            var name = $(input).attr('name');
            var myclass = $(input).attr('class');
            var type = name.substring(name.indexOf('-') + 1, name.length);
            var crminputname = name.substring(name.indexOf('$new') + 1, name.indexOf('-'));

            var value = $(input).val();

            if (myclass == 'required') {
                //validate required field
                switch (type) {
                    case 'Picklist':
                        //make sure valid is not empty
                        if (value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                        }
                        else {
                            $(input).next().html("");
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        break;
                    case 'String':
                        //make sure valid is not empty
                        if (value == null || value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                        }
                        else {
                            $(input).next().html("");
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        break;
                    case 'Memo':
                        //make sure valid is not empty
                        if (value == null || value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        else {
                            $(input).next().html("");
                        }
                        break;
                    default:
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                }
            }
            else {
                //validate field
                switch (type) {
                    case 'String':
                        //add to xml
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                    case 'Memo':
                        //add to xml
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                    default:
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                }
            }
        });

        xmldoc += "</xml>";
        //alert(xmldoc);

        if (validated == "true") {
            $('#requestSubmit').after("<img src='/DesktopModules/ProCureMedia/loading.gif'/><span>Submitting form...Please Wait</span>");
            $.post("CrmInsertHttpHandler.axd", { xml: xmldoc }, function (data) {

                $("#popupUniversal-content").fadeOut();
                //$('#requestSubmit').next().remove();
                //$('#requestSubmit').next().remove();
                $('#GoogleConf').attr('src', '/RequestAConsultationConf.html');

                if (pathname.indexOf("oklahomacity") != -1) {
                    $("#popupUniversal-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>ProCure Proton Therapy Center in Oklahoma City Thanks You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for requesting a consultation. The intake nurse from ProCure Proton Therapy Center will be in touch with you soon to followup and process the information necessary for your case to be evaluated by the Physician Review Board. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }
                else if (pathname.indexOf("illinois") != -1) {
                    $("#popupUniversal-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>CDH Proton Center, A ProCure Center Thanks You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for requesting a consultation. The intake nurse from ProCure Proton Therapy Center will be in touch with you soon to followup and process the information necessary for your case to be evaluated by the Physician Review Board. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }
                else if (pathname.indexOf("newjersey") != -1) {
                    $("#popupUniversal-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>ProCure Proton Therapy Center in Somerset, New Jersey/Metro New York Thanks You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>We have received your email request and will be in touch with your shortly. Thank you for your interest in this powerful treatment for cancer. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }
                else {
                    $("#popupUniversal-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>Thank You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for requesting a consultation. The intake nurse from ProCure Proton Therapy Center will be in touch with you soon to followup and process the information necessary for your case to be evaluated by the Physician Review Board. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }



                $("#popupUniversal-content").next().fadeIn();
            });





        }
        else {
            //Scroll to top!
            $(this).parent().scrollTop(0);
            var count = $(this).parent().children(':first-child').children().length;
            if (count < 3) {
                $(this).parent().children(":first-child").append("<br /><span style='font-weight:bold;color:#FF0000;'>Please fill in all required fields</span>");
            }
        }


    });


    $("#patientSubmit").live("click", function () {

        var validated = "true";
        var xmldoc = "<xml>";

        setCookie("formCookie", "true", 365);
        //alert("patientsubmit");

        $('#ReferPatient1_MyPanel').children(':first-child').children().each(function (index, eleDom) {

            var html = $(eleDom).children(':nth-child(1)');
            var input = $(html).next();
            var name = $(input).attr('name');
            var myclass = $(input).attr('class');
            var type = name.substring(name.indexOf('-') + 1, name.length);
            var crminputname = name.substring(name.indexOf('$new') + 1, name.indexOf('-'));

            var value = $(input).val();

            if (myclass == 'required') {
                //validate required field
                switch (type) {
                    case 'Picklist':
                        //make sure valid is not empty
                        if (value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                        }
                        else {
                            $(input).next().html("");
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        break;
                    case 'String':
                        //make sure valid is not empty
                        if (value == null || value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                        }
                        else {
                            $(input).next().html("");
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        break;
                    case 'Memo':
                        //make sure valid is not empty
                        if (value == null || value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        else {
                            $(input).next().html("");
                        }
                        break;
                    default:
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                }
            }
            else {
                //validate field
                switch (type) {
                    case 'String':
                        //add to xml
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                    case 'Memo':
                        //add to xml
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                    default:
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                }
            }
        });

        xmldoc += "</xml>";
        //alert(xmldoc);

        if (validated == "true") {
            $('#patientSubmit').after("<img src='/DesktopModules/ProCureMedia/loading.gif'/><span>Submitting form...Please Wait</span>");
            $.post("CrmInsertHttpHandler.axd", { xml: xmldoc }, function (data) {

                $("#popupPatient-content").fadeOut();

                $('#GoogleConf').attr('src', '/ReferAPatientConf.html');

                if (pathname.indexOf("oklahomacity") != -1) {
                    $("#popupPatient-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>ProCure Proton Therapy Center in Oklahoma City Thanks You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for requesting a consultation. The intake nurse from ProCure Proton Therapy Center will be in touch with you soon to followup and process the information necessary for your case to be evaluated by the Physician Review Board. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }
                else if (pathname.indexOf("illinois") != -1) {
                    $("#popupPatient-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>CDH Proton Center, A ProCure Center Thanks You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for requesting a consultation. The intake nurse from ProCure Proton Therapy Center will be in touch with you soon to followup and process the information necessary for your case to be evaluated by the Physician Review Board. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }
                else {
                    $("#popupPatient-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>Thank You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for requesting a consultation. The intake nurse from ProCure Proton Therapy Center will be in touch with you soon to followup and process the information necessary for your case to be evaluated by the Physician Review Board. For our address and other contact information, <a href=\"/ContactUs.aspx\">click here.</a></p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/Oklahoma.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }



                $("#popupPatient-content").next().fadeIn();
            });





        }
        else {
            //Scroll to top!
            $(this).parent().scrollTop(0);
            var count = $(this).parent().children(':first-child').children().length;
            if (count < 3) {
                $(this).parent().children(":first-child").append("<br /><span style='font-weight:bold;color:#FF0000;'>Please fill in all required fields</span>");
            }
        }


    });

    $("#contactusSubmit").live("click", function () {


        var inquiryType = $("#ContactUs1_new_inquirytype-Picklist").val();


        var validated = "true";
        var xmldoc = "<xml>";

        setCookie("formCookie", "true", 365);
        //alert("contactussubmit");

        $('#ContactUs1_MyPanel').children(':first-child').children().each(function (index, eleDom) {

            var html = $(eleDom).children(':nth-child(1)');
            var input = $(html).next();
            var name = $(input).attr('name');
            var myclass = $(input).attr('class');
            var type = name.substring(name.indexOf('-') + 1, name.length);
            var crminputname = name.substring(name.indexOf('$new') + 1, name.indexOf('-'));

            var value = $(input).val();

            if (myclass == 'required') {
                //validate required field
                switch (type) {
                    case 'Picklist':
                        //make sure valid is not empty
                        if (value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                        }
                        else {
                            $(input).next().html("");
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        break;
                    case 'String':
                        //make sure valid is not empty
                        if (value == null || value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                        }
                        else {
                            $(input).next().html("");
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        break;
                    case 'Memo':
                        //make sure valid is not empty
                        if (value == null || value == "") {
                            $(input).next().html("Required");
                            validated = "false";
                            xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        }
                        else {
                            //test
                            //test
                            //test
                            $(input).next().html("");
                        }
                        break;
                    default:
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                }
            }
            else {
                //validate field
                switch (type) {
                    case 'String':
                        //add to xml
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                    case 'Memo':
                        //add to xml
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                    default:
                        xmldoc += "<" + name + ">" + value + "</" + name + ">";
                        break;
                }
            }
        });

        xmldoc += "</xml>";
        //alert(xmldoc);

        if (validated == "true") {

            $('#contactusSubmit').after('<img src="/DesktopModules/ProCureMedia/loading.gif"/><span>Submitting form...Please Wait</span>');
            $.post("CrmInsertHttpHandler.axd", { xml: xmldoc }, function (data) {
                $("#popupContact-content").fadeOut();
                $('#GoogleConf').attr('src', '/ContactUsConf.html');



                if (inquiryType == "6") {
                    //dev
                    $("#popupContact-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>Thank You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you for your interest in bringing proton therapy to your community. A ProCure representative will be in touch with you soon to follow up on your inquiry.</p><p>In the meantime, please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProtonTherapy/QuestionsAboutProtonTherapy.aspx\">Frequently Asked Questions About Proton Therapy</a></li><li><a href=\"/ForMedicalProfessionals.aspx\">Information for Medical Professionals</a></li><li><a href=\"/OurLocations/OklahomaCity.aspx\">ProCure Proton Therapy Center, Oklahoma</a></li><li><a href=\"/OurLocations/Illinois.aspx\">CDH Proton Center, A ProCure Center, in suburban Chicago</a></li><li><a href=\"/OurLocations/NewJersey.aspx\">ProCure Proton Therapy Center, New Jersey</a></li><li><a href=\"/OurLocations/Washington.aspx\">ProCure Proton Therapy Center, Washington</a></li><li><a href=\"/OurLocations/Florida.aspx\">ProCure Proton Therapy Center, Florida</a></li><li><a href=\"/OurLocations/Michigan.aspx\">ProCure Proton Therapy Center, Michigan</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                } else {
                    //corp
                    $("#popupContact-content").after("<div id=\"main-body-copy\" class=\"thankyou\" style=\"display:none; border-left:0px; min-height:0px;\" class=\"media-page\"><h1>Thank You</h1><div class=\"content-block-wrapper\" style=\"border-bottom: 1px solid #cccccc; margin-bottom:20px;\"><p>Thank you, your request has been successfully submitted. You will be contacted shortly from our representatives.</p><p>In the meantime, to learn more about ProCure's innovative development process please explore our site for additional information:</p><br /><ul id=\"bulleted-links-left\" style=\"width:auto;\"><li><a href=\"/ProCureDevelopment.aspx\">Information about ProCure Development</a></li><li><a href=\"/ProCureDevelopment/WorkingwithProCure.aspx\">Working with ProCure</a></li><li><a href=\"/ProCureDevelopment/DevelopingCenters.aspx\">Developing Centers</a></li></ul></div><div class=\"content-block-wrapper last-content-block\"></div></div>");
                }






                $("#popupContact-content").next().fadeIn();
            });

        }
        else {
            //Scroll to top!
            $(this).parent().scrollTop(0);
            var count = $(this).parent().children(':first-child').children().length;
            if (count < 3) {
                $(this).parent().children(":first-child").append("<br /><span style='font-weight:bold;color:#FF0000;'>Please fill in all required fields</span>");
            }
        }

    });

});

	

    function MySubmit()
    {
        alert($(this).html());
        /*
        
        if (Page_ClientValidate(""))
        {

            alert("make call to httphandler()");
            
            //var $inputs = $('#form1 :input');

            var formxml = "<xml>";
            var values = {};
            $.each($('#form1').serializeArray(), function(i, field) {
                values[field.name] = field.value;
                formxml += "<" + field.name + ">" + field.value + "</" + field.name + ">";
            });
            
            formxml += "</xml>";
            
            $.ajax({
                url: "CrmInsertHttpHandler.axd",
                data: {
                    xml: formxml
                },
                success: function(data, textStatus, XMLHttpRequest)
                {
                    $('#RequestConsultation1_MyPanel').html("success");
                }
            });
            
            
            
        } */
    }
    

    
    
    function ValidateCrmDecimal(source, args)
    {	
	    var re = new RegExp("[0-9]+(\.[0-9][0-9]?)?");
    	
	    args.IsValid = (window.event.srcElement.value.match(re));
    }
    
    function ValidateCrmDateTime(source, args)
    {	
	    var re = new RegExp("((^(10|12|0?[13578])([/])(3[01]|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(11|0?[469])([/])(30|[12][0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(2[0-8]|1[0-9]|0?[1-9])([/])((1[8-9]\d{2})|([2-9]\d{3}))$)|(^(0?2)([/])(29)([/])([2468][048]00)$)|(^(0?2)([/])(29)([/])([3579][26]00)$)|(^(0?2)([/])(29)([/])([1][89][0][48])$)|(^(0?2)([/])(29)([/])([2-9][0-9][0][48])$)|(^(0?2)([/])(29)([/])([1][89][2468][048])$)|(^(0?2)([/])(29)([/])([2-9][0-9][2468][048])$)|(^(0?2)([/])(29)([/])([1][89][13579][26])$)|(^(0?2)([/])(29)([/])([2-9][0-9][13579][26])$))");
    	
	    args.IsValid = (window.event.srcElement.value.match(re));
    }
    
    
    function ValidateCrmMoney(source, args)
    {	
	    var re = new RegExp("^[-]?[0-9]\d{0,11}(\.\d{1,2})?%?$");
    	
	    args.IsValid = (window.event.srcElement.value.match(re));
    }
    
    function ValidateCrmNumber(source, args)
    {	
	    var re = new RegExp("^[-]?[0-9]\d{0,11}?%?$");
    	
	    args.IsValid = (window.event.srcElement.value.match(re));
    }
    
    
function json2xml(o, tab) {
  var toXml = function(v, name, ind) {
    var xml = "";
    if (typeof(v) == "object") {
      var hasChild = false;
      for (var m in v) {
        if (m.charAt(0) == "@") {
          xml += " " + m.substr(1) + "=\"" + v[m].toString() + "\"";          
        } else {
          hasChild = true;
        }
      }
      if (hasChild) {
        for (var m in v) {
          if (m=="name") {
            xml += "<" + v[m] + ">" + v['value'] + "";
          }
        }
      }
    }
    return xml;
  }, xml="";
  for (var m in o) {
    xml += toXml(o[m], m, "");
  }

  return xml;

}    

