﻿// JScript File

function showsegment()
{ //Show and Segment fields
    var pre = "ctl00_CPH_Main_mbrSignup_";
    var segment = document.getElementById(pre + "selSegment");
    var segment_index = segment.selectedIndex;
    var segmentValue = segment.options[segment_index].value;
    
    var lc = document.getElementById("LC");
    var cu = document.getElementById("CU");
    var k12 = document.getElementById("K12");
    var hc = document.getElementById("HC");
    var bi = document.getElementById("BI");
    var cr = document.getElementById("CR");
    var ve = document.getElementById("VE");

    if (segmentValue == ""){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
    if (segmentValue == "K12"){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'block';
        k12.style.visibility = 'visible';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
    if (segmentValue == "LC"){
        lc.style.display = 'block';
        lc.style.visibility = 'visible';
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
    if (segmentValue == "CU"){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';
        cu.style.display = 'block';
        cu.style.visibility = 'visible';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
    if (segmentValue == "HC"){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'block';
        hc.style.visibility = 'visible';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
    if (segmentValue == "BI"){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';       
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'block';
        bi.style.visibility = 'visible';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
    if (segmentValue == "CR"){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'block';
        cr.style.visibility = 'visible';
        ve.style.display = 'none';
        ve.style.visibility = 'hidden';
    }
     if (segmentValue == "VE"){
        lc.style.display = 'none';
        lc.style.visibility = 'hidden';
        cu.style.display = 'none';
        cu.style.visibility = 'hidden';
        k12.style.display = 'none';
        k12.style.visibility = 'hidden';
        hc.style.display = 'none';
        hc.style.visibility = 'hidden';
        bi.style.display = 'none';
        bi.style.visibility = 'hidden';
        cr.style.display = 'none';
        cr.style.visibility = 'hidden';
        ve.style.display = 'block';
        ve.style.visibility = 'visible';
    }  
}

/* Sep 2009   O.N.                                                        */
/* this function is used in the FAFH signup page to toggle a hidden field */
/* takes a dropdownlist ID and an html element IDs and toggles visibility */
/* the dropdownList ID can also be a radio button list or any other       */
/* controlling element to be used to act as a toggle switch.  the first 2 */
/* parameters are required, but the third parameter is optional           */
/* this method was designed to display 2 hiddent td's as part of a tr row */
function showSelfOperated(ddListID, htmlElementID, optionalHtmlElementID)
{
    if (ddListID != null && ddListID != undefined && htmlElementID != null && htmlElementID != undefined)
    {
        var ddList = document.getElementById(ddListID);
        if (ddList != undefined && ddList != null)
        {
            var hiddenTag = document.getElementById(htmlElementID);    
            if (hiddenTag != null && hiddenTag != undefined)
            {
                if (ddList.options[ddList.selectedIndex].value.toUpperCase() == "NO")
                {
                    hiddenTag.style.display = 'block';
                    hiddenTag.style.visibility = 'visible';
                    if (typeof optionalHtmlElementID != "undefined")
                    {
                        var optionalHiddenTag = document.getElementById(optionalHtmlElementID);    
                        optionalHiddenTag.style.display = 'block';
                        optionalHiddenTag.style.visibility = 'visible';
                    }                
                }
                else /* YES */
                {
                    hiddenTag.style.display = 'none';
                    hiddenTag.style.visibility = 'hidden';
                    if (typeof optionalHtmlElementID != "undefined")
                    {
                        var optionalHiddenTag = document.getElementById(optionalHtmlElementID);    
                        optionalHiddenTag.style.display = 'none';
                        optionalHiddenTag.style.visibility = 'hidden';
                    }                
                }
            } 
        }
    }
}

/* Oct 2009   O.N.                                                        */
/* this function is used in the FAFH signup page to toggle a hidden field */
/* it takes the id of the radio button to toggle, and 1 or 2 IDs of div   */
/* tags which should be hidden or displayed                               */
function toggleHiddenDivwithRB(radioButtonID, requiredDivElementID, optionalDivElementID)
{
    var rbOwnershipClassChain = document.getElementById(radioButtonID);    
    var chainBrandName1 = document.getElementById(requiredDivElementID);
    // toggle visibility of div containing textbox
    if (rbOwnershipClassChain.checked && rbOwnershipClassChain.value.indexOf("rbLcChainOwned") >= 0)
    {
        chainBrandName1.style.display = 'block';
        chainBrandName1.style.visibility = 'visible';
        if (typeof optionalDivElementID != "undefined")
        {
            var chainBrandName2 = document.getElementById(optionalDivElementID);
            chainBrandName2.style.display = 'block';
            chainBrandName2.style.visibility = 'visible';
        }
    }
    else
    {
        chainBrandName1.style.display = 'none';
        chainBrandName1.style.visibility = 'hidden';
        if (typeof optionalDivElementID != "undefined")
        {
            var chainBrandName2 = document.getElementById(optionalDivElementID);
            chainBrandName2.style.display = 'none';
            chainBrandName2.style.visibility = 'hidden';
        }
    }
}

function validateform()
{
    //Validate form fields
    //alert('inside validateform');
    var pre = "ctl00_CPH_Main_mbrSignup_";
    var errmsg = "";
    var i;
    var counter = 0;
    var counterSegment = 0;
    var segment = document.getElementById(pre + "selSegment");
    var segment_index = segment.selectedIndex;
    var segmentValue = segment.options[segment_index].value;
    var state = document.getElementById(pre + "selState");
    var state_index = state.selectedIndex;
    
    /* Member Basic Section Validation */
    var arrReqFields = new Array("txtFirst","txtLast","txtTitle","selSegment","txtAddress","txtCity","selState","txtZip","txtPhone","txtFax","txtEmail","txtUsername","txtPassword","txtPassword2");
    //Loop through common fields and validate
    for (i=0; i<arrReqFields.length; i++)
    {
       //Check all required fields
        var rField = pre + arrReqFields[i];
        if (arrReqFields[i] == "selSegment")
        {
            var rValue = document.getElementById(rField).selectedIndex;
            if(rValue == 0)
                rValue = "";
        }
        else if (arrReqFields[i] == "selState")
        {
            var rValue = document.getElementById(rField).selectedIndex;
            if(rValue == 0)
                rValue = "";
        }
        else
        {
            var rValue = document.getElementById(rField).value;
        }

        //Check all required fields
        if (rValue.length == 0)
        {
            //alert('rField = '+rField);
            counter += 1;
        }
       
        //Check Zipcode is 5 digits
        if (arrReqFields[i] == "txtZip")
        {
            //alert("rField - " + rValue.length + "\r\n");
            //check if zip is a number
            if (IsNumeric(rValue) == false || rValue.length != 5)
            {
                errmsg += "The Zip Code field must be 5 numbers \r\n";
                counter += 1;
            }
        }

        //check email is valid format
        if (arrReqFields[i] == "txtEmail")
        {
            if (emailCheck(rValue) == false)
            {
                errmsg += "Email Address is not in valid format \r\n";
                counter += 1;
            }
        }
        
        //Check if passwords match
        if (arrReqFields[i] == "txtPassword")
        {
            var pwd1 = document.getElementById(pre + "txtPassword").value;
            var pwd2 = document.getElementById(pre + "txtPassword2").value;

            if (pwd1 != pwd2)
            {
                errmsg += "Your passwords must match \r\n";
                counter += 1;
            }
        }

	    //Check if username exists
	    //checkUser();

	    //Check if user email exists
	    //checkUserEmail();
    }
    //check How Heard
    var chkDirectMail = document.getElementById(pre + "rdoDirectMail");
    var chkKmail = document.getElementById(pre + "rdoKmail");
    var chkTradeAd = document.getElementById(pre + "rdoTradeAd");
    var chkSalesContact = document.getElementById(pre + "rdoSalesContact");    
    var chkOtherHowHeard = document.getElementById(pre + "rdoOtherHowHeard");
    if (chkDirectMail.checked==false && chkKmail.checked==false && chkTradeAd.checked==false && chkSalesContact.checked==false && chkOtherHowHeard.checked==false)
    {
        counter += 1;
    }
    if (chkOtherHowHeard.checked==true)
    {
        if (document.getElementById(pre + "txtHowHeardOther").value == "")
        {
            counter += 1;
        }
    }
    /* End Member Basic */ 
    
    //Check Business
    if (segmentValue == "BI")
    {
        //alert('inside segment check on BI');
        var arrReqFieldsBI = new Array("ddlDistributorNameBI","ddlDistributorStateBI","txtEstNameBI","txtDistributorCityBI","txtBIBADP","txtBILADP");
        /* if BI self operated drop downlist has a value of no then we have to modify the required array */
        var ddlBISelfOp = document.getElementById(pre + "ddlBISelfOperated");
        if (ddlBISelfOp.options[ddlBISelfOp.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsBI.push("txtBIContractMgmt");
        }
        
        //Loop through BI fields and validate
        for (i=0; i<arrReqFieldsBI.length; i++)
        {
            var rField = pre + arrReqFieldsBI[i];
            //alert('rField = '+rField);
            if (arrReqFieldsBI[i] == "ddlDistributorNameBI")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else if (arrReqFieldsBI[i] == "ddlDistributorStateBI")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else{
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }
        }    
    }

	//College & University
	if (segmentValue == "CU")
	{
	    //alert('inside segment check on CU');
        var arrReqFieldsCU = new Array("txtCuName","txtCuDiningName","txtCUstudentEnrollment","ddlDistributorNameCU","txtDistributorCityCU","ddlDistributorStateCU","txtCUSalesRep");
        var ddlCUSelfOp = document.getElementById(pre + "ddlCUSelfOperated");
        if (ddlCUSelfOp.options[ddlCUSelfOp.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsCU.push("txtCUcmc");
        }

        //Loop through CU fields and validate
        for (i=0; i<arrReqFieldsCU.length; i++)
        {
            var rField = pre + arrReqFieldsCU[i];
            //alert('rField = '+rField);
            if (arrReqFieldsCU[i] == "ddlDistributorNameCU")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else if (arrReqFieldsCU[i] == "ddlDistributorStateCU")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else
            {
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }
        
            //Check Enrollment is a number
            if (arrReqFieldsCU[i] == "txtCUstudentEnrollment")
            {
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    counterSegment += 1;
                    errmsg += "Student Enrollment must be a number \r\n";
                }
            }
        }
        
        // Validate Check Boxes
        var chkCash = document.getElementById(pre + "chkCUopCash");
        var chkDining = document.getElementById(pre + "chkCUopDining");
        var chkCater = document.getElementById(pre + "chkCUopCater");
        
        if (chkCater.checked==false && chkDining.checked==false && chkCash.checked==false)
        {
            counterSegment += 1;
        }
    }

    //Commercial Restaurants
    if (segmentValue == "CR")
    {
        //alert('inside segment check on CR');
        var arrReqFieldsCR = new Array("txtEstNameCR","txtFranchiseNameCR","txtFranchisesOwnedCR","ddlDistributorNameCR","txtDistributorCityCR","ddlDistributorStateCR","txtCRSalesRep");    

        //Loop through CR fields and validate
        for (i=0; i<arrReqFieldsCR.length; i++)
        {
            var rField = pre + arrReqFieldsCR[i];
            //alert('rField = '+rField);
            if (arrReqFieldsCR[i] == "ddlDistributorNameCR")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else if (arrReqFieldsCR[i] == "ddlDistributorStateCR")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else
            {
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }

             //check if Number of Franchises value is a number
            if (arrReqFieldsCR[i] == "txtFranchisesOwnedCR")
            {             
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Franchises Owned must be a number \r\n";
                    counterSegment += 1;
                }
            }
        }
    }
    
	//Healthcare
    if (segmentValue == "HC")
    {
        //alert('inside segment check on HC');
        var arrReqFieldsHC = new Array("txtEstNameHC","txtPrimaryGPO","txtLicensedBedNum","txtEmployeeNum","ddlDistributorNameHC","txtDistributorCityHC","ddlDistributorStateHC");
        var ddlHCSelfOp = document.getElementById(pre + "ddlHCSelfOperated");
        if (ddlHCSelfOp.options[ddlHCSelfOp.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsHC.push("txtContractMgmt");
        }
        // if other radio button is checked, add text box other to array of required fileds
        var rbFTOther = document.getElementById(pre + "rFTOther");
        if (rbFTOther.checked)
        {
            arrReqFieldsHC.push("txtOtherFacilityType");
        }
        
        //loop through hc fields and validate
        for (i=0; i<arrReqFieldsHC.length; i++)
        {
            var rField = pre + arrReqFieldsHC[i];
            //alert('rField = '+rField);
            if (arrReqFieldsHC[i] == "ddlDistributorNameHC")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else if (arrReqFieldsHC[i] == "ddlDistributorStateHC")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else
            {
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }
             //check if value is a number
            if (arrReqFieldsHC[i] == "txtLicensedBedNum")
            {               
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Beds must be a number \r\n";
                    counterSegment += 1;
                }
            }
            if (arrReqFieldsHC[i] == "txtEmployeeNum")
            {               
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Employees must be a number \r\n";
                    counterSegment += 1;
                }
            }
        } 

        // ensure that at least one of the facility type radio buttons are selected
        var rbAcuteCare = document.getElementById(pre + "rAcute");
        var rbOutpatientCare = document.getElementById(pre + "rOutpatient");
        var rbLongTermCare = document.getElementById(pre + "rLongTerm");
        var rbOtherFacilityType = document.getElementById(pre + "rFTOther");
        if (rbAcuteCare.checked == false && rbOutpatientCare.checked == false && rbLongTermCare.checked == false && rbOtherFacilityType.checked == false)
        {                
            counterSegment += 1;
        }
    }
    
	//K12
	 if (segmentValue == "K12")
	 {
        var arrReqFieldsK12 = new Array("txtK12DistrictName","txtK12SchoolName","txtK12NumSchools","txtK12DistrictEnrollment","txtK12BADP","txtK12LADP","txtK12SalesRep","ddlDistributorNameK12","txtDistributorCityK12","ddlDistributorStateK12");
        var ddlK12SelfOp = document.getElementById(pre + "ddlK12SelfOperated");
        if (ddlK12SelfOp.options[ddlK12SelfOp.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsK12.push("txtk12ContractCo");
        }
        var ddlK12CoOpChoice = document.getElementById(pre + "ddlK12CoOp");
        if (ddlK12CoOpChoice.options[ddlK12CoOpChoice.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsK12.push("txtk12CoOp");
        }
        
        //Loop through K12 fields and validate
        for (i=0; i<arrReqFieldsK12.length; i++)
        {
            var rField = pre + arrReqFieldsK12[i];
            //alert('rField = '+rField);
            if (arrReqFieldsK12[i] == "ddlDistributorNameK12")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else if (arrReqFieldsK12[i] == "ddlDistributorStateK12")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else
            {
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }
             //check if value is a number
            if (arrReqFieldsK12[i] == "txtK12NumSchools")
            {               
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "K-12 Number of School must be a number \r\n";
                    counterSegment += 1;
                }
            } 
            if (arrReqFieldsK12[i] == "txtK12DistrictEnrollment")
            {               
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "District Enrollment must be a number \r\n";
                    counterSegment += 1;
                }
            } 
            if (arrReqFieldsK12[i] == "txtK12BADP")
            {               
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "K-12 Breakfast Participation must be a number \r\n";
                    counterSegment += 1;
                }
            }
            if (arrReqFieldsK12[i] == "txtK12LADP")
            {               
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Lunch Participation must be a number \r\n";
                    counterSegment += 1;
                }
            }
        }
    }
	
    //Lodging & Catering
	if (segmentValue == "LC")
	{
        //alert('inside segment check on LC');
        var arrReqFieldsLC = new Array("txtEstNameLC","ddlDistributorNameLC","txtDistributorCityLC","ddlLCdistributorState","txtLCnumRooms");
        var ddlLCChainFran = document.getElementById(pre + "ddlLCChainFranchise");
        if (ddlLCChainFran.options[ddlLCChainFran.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsLC.push("txtLCChainFranchise");
        }
        var ddlLCMgmtGrpChoice = document.getElementById(pre + "ddlLCMgmtGrp");
        if (ddlLCMgmtGrpChoice.options[ddlLCMgmtGrpChoice.selectedIndex].value.toUpperCase() == "NO")
        {
            arrReqFieldsLC.push("txtLCMgmtGrp");
        }
        // display chain brand name textbox
        var rbOwnershipClassInd = document.getElementById(pre + "rbLcIndependent");
        var rbOwnershipClassChain = document.getElementById(pre + "rbLcChainOwned");
        var divChainBrandName = document.getElementById(pre + "divLcBrandName1");
        if (rbOwnershipClassChain.checked == true && divChainBrandName.style.visibility == 'visible')
        {
            arrReqFieldsLC.push("txtLCbrand");
        }
        
        //Loop through LC fields and validate
        for (i=0; i<arrReqFieldsLC.length; i++)
        {
            var rField = pre + arrReqFieldsLC[i];
            //alert('rField = '+rField);
            if (arrReqFieldsLC[i] == "ddlDistributorNameLC")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else if (arrReqFieldsLC[i] == "ddlLCdistributorState")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else
            {
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }
            //check if Number of Rooms value is a number
            if (arrReqFieldsLC[i] == "txtLCnumRooms")
            {
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Rooms must be a number \r\n";
                    counterSegment += 1;
                }                
            }
        }
        // ensure that one of the ownership classification radio buttons have been selected
        if (rbOwnershipClassInd.checked == false && rbOwnershipClassChain.checked == false)
        {
            counterSegment += 1;
        }
                 
        //check Full Service Kitchen
        var rLCkitchenYes = document.getElementById(pre + "rLCkitchenYes");
        var rLCkitchenNo = document.getElementById(pre + "rLCkitchenNo");    
        if (rLCkitchenYes.checked==false && rLCkitchenNo.checked==false)
        {
            counterSegment += 1;
        }
        //check OnSite Catering
        var LCcateringYes = document.getElementById(pre + "LCcateringYes");
        var LCcateringNo = document.getElementById(pre + "LCcateringNo");    
        if (LCcateringYes.checked==false && LCcateringNo.checked==false)
        {
            counterSegment += 1;
        }
    }

    //Vending
    if (segmentValue == "VE")
    {
        //alert('inside segment check on VE');
        var arrReqFieldsVE = new Array("txtEstNameVE","txtVendDistributors","txtVendDistributorsCity","ddlVendDistributorsState","txtVendGlassFronts","txtVendHonorBoxes","txtCounterTops");
        
        //Loop through VE fields and validate
        for (i=0; i<arrReqFieldsVE.length; i++)
        {
            var rField = pre + arrReqFieldsVE[i];
            //alert('rField = '+rField);
            if (arrReqFieldsVE[i] == "ddlVendDistributorsState")
            {
                var rValue = document.getElementById(rField).selectedIndex;
                if(rValue == 0)
                    rValue = "";
            }
            else
            {
                var rValue = document.getElementById(rField).value;
            }
            //alert('rValue = '+rValue);
            //Check all required fields
            if (rValue.length == 0)
            {
                //alert('rField = '+rField);
                counterSegment += 1;
            }
            //check if value is a number
            if (arrReqFieldsVE[i] == "txtVendGlassFronts")
            {
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Glass Fronts must be a number \r\n";
                    counterSegment += 1;
                }                
            }
            if (arrReqFieldsVE[i] == "txtVendHonorBoxes")
            {
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Honor Boxes must be a number \r\n";
                    counterSegment += 1;
                }                
            }
            if (arrReqFieldsVE[i] == "txtCounterTops")
            {
                if (rValue.length != 0 && IsNumeric(rValue) == false)
                {
                    errmsg += "Number of Counter Tops must be a number \r\n";
                    counterSegment += 1;
                }                
            }
        }
    }

    //Convenience & Drug Store
    if (segmentValue == "CDS")
    {
    }
    
    //Military
    if (segmentValue == "MIL")
    {
    }
    
    // check counter
    if (counter > 0)
    {            
        errmsg += "Complete all Contact fields before clicking submit \r\n";
        counter = 0; 
    }
    // check counter
    if (counterSegment > 0)
    {            
        errmsg += "Complete all Segment fields before clicking submit \r\n";   
        counterSegment = 0;  
    }

    if (errmsg != "")
    {
        Modalbox.show('<div align=\'center\' class=\'warning\'><input type=\'button\' value=\'' + errmsg + '\' onclick=\'Modalbox.hide()\' /></div>', {width: 500, title: 'Oops! There were Sign Up Errors'}); 
        return false;
    }
    else
    {
        return true;   
    }
}

var n;
var p;
var p1;
    
function ValidatePhone()
{
    var pre = "ctl00_CPH_Main_mbrSignup_";
    p=p1.value
    if(p.length==3){
	    //d10=p.indexOf('(')
	    pp=p;
	    d4=p.indexOf('(')
	    d5=p.indexOf(')')
	    if(d4==-1){
		    pp="("+pp;
	    }
	    if(d5==-1){
		    pp=pp+")";
	    }
	    //pp="("+pp+")";
	    document.getElementById(pre + "txtPhone").value="";
	    document.getElementById(pre + "txtPhone").value=pp;
    }
    if(p.length>3){
	    d1=p.indexOf('(')
	    d2=p.indexOf(')')
	    if (d2==-1){
		    l30=p.length;
		    p30=p.substring(0,4);
		    //alert(p30);
		    p30=p30+")"
		    p31=p.substring(4,l30);
		    pp=p30+p31;
		    //alert(p31);
		    document.getElementById(pre + "txtPhone").value="";
		    document.getElementById(pre + "txtPhone").value=pp;
	    }
	}
    if(p.length>5){
	    p11=p.substring(d1+1,d2);
	    if(p11.length>3){
	        p12=p11;
	        l12=p12.length;
	        l15=p.length
	        //l12=l12-3
	        p13=p11.substring(0,3);
	        p14=p11.substring(3,l12);
	        p15=p.substring(d2+1,l15);
	        document.getElementById(pre + "txtPhone").value="";
	        pp="("+p13+")"+p14+p15;
	        document.getElementById(pre + "txtPhone").value=pp;
	        //obj1.value="";
	        //obj1.value=pp;
	    }
        l16=p.length;
        p16=p.substring(d2+1,l16);
        l17=p16.length;
        if(l17>3&&p16.indexOf('-')==-1){
	        p17=p.substring(d2+1,d2+4);
	        p18=p.substring(d2+4,l16);
	        p19=p.substring(0,d2+1);
	        //alert(p19);
            pp=p19+p17+"-"+p18;
            document.getElementById(pre + "txtPhone").value="";
            document.getElementById(pre + "txtPhone").value=pp;
            //obj1.value="";
            //obj1.value=pp;
        }
    }
    //}
    setTimeout(ValidatePhone,100)
}

function getIt(m)
{
    n=m.name;
    //p1=document.forms[0].elements[n]
    p1=m
    ValidatePhone()
}


//Fax Format
var nf;
var pf;
var p1f;

function ValidateFax()
{
    var pre = "ctl00_CPH_Main_mbrSignup_";    
    pf=p1f.value
    if(pf.length==3){
	    //d10=p.indexOf('(')
	    pp=pf;
	    d4=pf.indexOf('(')
	    d5=pf.indexOf(')')
	    if(d4==-1){
		    pp="("+pp;
	    }
	    if(d5==-1){
		    pp=pp+")";
	    }
	    //pp="("+pp+")";
	    document.getElementById(pre + "txtFax").value="";
	    document.getElementById(pre + "txtFax").value=pp;
    }
    if(pf.length>3){
	    d1=pf.indexOf('(')
	    d2=pf.indexOf(')')
	    if (d2==-1){
		    l30=pf.length;
		    p30=pf.substring(0,4);
		    //alert(p30);
		    p30=p30+")"
		    p31=pf.substring(4,l30);
		    pp=p30+p31;
		    //alert(p31);
		    document.getElementById(pre + "txtFax").value="";
		    document.getElementById(pre + "txtFax").value=pp;
	    }
	}
    if(pf.length>5){
	    p11=pf.substring(d1+1,d2);
	    if(p11.length>3){
	        p12=p11;
	        l12=p12.length;
	        l15=pf.length
	        //l12=l12-3
	        p13=p11.substring(0,3);
	        p14=p11.substring(3,l12);
	        p15=pf.substring(d2+1,l15);
	        document.getElementById(pre + "txtFax").value="";
	        pp="("+p13+")"+p14+p15;
	        document.getElementById(pre + "txtFax").value=pp;
	        //obj1.value="";
	        //obj1.value=pp;
	    }
        l16=pf.length;
        p16=pf.substring(d2+1,l16);
        l17=p16.length;
        if(l17>3&&p16.indexOf('-')==-1){
	        p17=pf.substring(d2+1,d2+4);
	        p18=pf.substring(d2+4,l16);
	        p19=pf.substring(0,d2+1);
	        //alert(p19);
            pp=p19+p17+"-"+p18;
            document.getElementById(pre + "txtFax").value="";
            document.getElementById(pre + "txtFax").value=pp;
            //obj1.value="";
            //obj1.value=pp;
        }
    }
    //}
    setTimeout(ValidateFax,100)
}
    
function getItFax(m)
{
    nf=m.name;
    //p1=document.forms[0].elements[n]
    p1f=m
    ValidateFax()
}
    
function testphone(obj1)
{
    p=obj1.value
    //alert(p)
    p=p.replace("(","")
    p=p.replace(")","")
    p=p.replace("-","")
    p=p.replace("-","")
    //alert(isNaN(p))
    if (isNaN(p)==true)
    {
        alert("Check phone");
        return false;
    }
}
    
function IsNumeric(strString)
//  check for valid numeric strings	
{
    var strValidChars = "0123456789.-";
    var strChar;
    var blnResult = true;

    if (strString.length == 0) return false;

    //  test strString consists of valid characters listed above
    for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
    return blnResult;
}


//Username Validation

//Check if username exists
function checkUser()
{
    var pre = "ctl00_CPH_Main_mbrSignup_";
	var username = document.getElementById(pre + "txtUsername").value;				
	var url = "checkmember.aspx?username="+username;				
	var http_request = false;
    if (username != "")
    {
	    if (window.XMLHttpRequest) { // Mozilla, Safari,...
			    http_request = new XMLHttpRequest();
			    if (http_request.overrideMimeType) {
					    http_request.overrideMimeType('text/xml');
					    // See note below about this line
			    }
	    } else if (window.ActiveXObject) { // IE
			    try {
					    http_request = new ActiveXObject("Msxml2.XMLHTTP");
			    } catch (e) {
					    try {
							    http_request = new ActiveXObject("Microsoft.XMLHTTP");
					    } catch (e) {}
			    }
	    }

	    if (!http_request) {
			    alert('Giving up :( Cannot create an XMLHTTP instance');
			    return false;
	    }

	    http_request.onreadystatechange = function() { ajaxResponse_checkUser(http_request); };
	    http_request.open('GET', url, true);
	    http_request.send(null);
    }
}
				
function ajaxResponse_checkUser(http_request)
{
	//alert('Ready State: '+http_request.readyState+'\nHTTP Status: '+http_request.status);
	var pre = "ctl00_CPH_Main_mbrSignup_";
	if ((http_request.readyState == 4) && (http_request.status == 200))
	{					
		//document.getElementById('usercheck').innerHTML = http_request.responseText;
		var response = http_request.responseText;
		if (response == "True")
		{
		    alert("That Username is Already taken, Please enter a different username");
		    document.getElementById(pre + "txtUsername").focus();
		    return false;
		}
		else
		{				
		    return true;
		}
	}
}

//Check if email address exists
function checkUserEmail()
{
    var pre = "ctl00_CPH_Main_mbrSignup_";   
	var email = document.getElementById(pre + "txtEmail").value;				
	var url = "checkmemberEmail.aspx?email="+email;				
	var http_request = false;
    if (email != "")
    {
	    if (window.XMLHttpRequest)
	    { // Mozilla, Safari,...
		    http_request = new XMLHttpRequest();
		    if (http_request.overrideMimeType)
		    {
			    http_request.overrideMimeType('text/xml');
			    // See note below about this line
		    }
	    }
	    else if (window.ActiveXObject)
	    { // IE
		    try
		    {
			    http_request = new ActiveXObject("Msxml2.XMLHTTP");
		    }
		    catch (e)
		    {
			    try
			    {
				    http_request = new ActiveXObject("Microsoft.XMLHTTP");
			    }
			    catch (e) {}
		    }
	    }

	    if (!http_request)
	    {
		    alert('Giving up :( Cannot create an XMLHTTP instance');
		    return false;
	    }

	    http_request.onreadystatechange = function() { ajaxResponse_checkUserEmail(http_request); };
	    http_request.open('GET', url, true);
	    http_request.send(null);	
    }	
}
				
function ajaxResponse_checkUserEmail(http_request) 
{
    var pre = "ctl00_CPH_Main_mbrSignup_";
	//alert('Ready State: '+http_request.readyState+'\nHTTP Status: '+http_request.status);
	if ((http_request.readyState == 4) && (http_request.status == 200))
	{					
		//document.getElementById('usercheck').innerHTML = http_request.responseText;
		var response = http_request.responseText;
		if (response == "True")
		{
		    alert("That Email Address is Already taken, Please enter a different Email");
		    document.getElementById(pre + "txtEmail").focus();
		    return false;
		}
		else
		{
		    return true;
		}
	}	
}

// email validation
function emailCheck (emailStr)
{
    /* The following variable tells the rest of the function whether or not
    to verify that the address ends in a two-letter country or well-known
    TLD.  1 means check it, 0 means don't. */
    var checkTLD=1;
    /* The following is the list of known TLDs that an e-mail address must end with. */
    var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum)$/;
    /* The following pattern is used to check if the entered e-mail address
    fits the user@domain format.  It also is used to separate the username
    from the domain. */
    var emailPat=/^(.+)@(.+)$/;
    /* The following string represents the pattern for matching all special
    characters.  We don't want to allow special characters in the address. 
    These characters include ( ) < > @ , ; : \ " . [ ] */
    var specialChars="\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
    /* The following string represents the range of characters allowed in a 
    username or domainname.  It really states which chars aren't allowed.*/
    var validChars="\[^\\s" + specialChars + "\]";
    /* The following pattern applies if the "user" is a quoted string (in
    which case, there are no rules about which characters are allowed
    and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
    is a legal e-mail address. */
    var quotedUser="(\"[^\"]*\")";
    /* The following pattern applies for domains that are IP addresses,
    rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
    e-mail address. NOTE: The square brackets are required. */
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    /* The following string represents an atom (basically a series of non-special characters.) */
    var atom=validChars + '+';
    /* The following string represents one word in the typical username.
    For example, in john.doe@somewhere.com, john and doe are words.
    Basically, a word is either an atom or quoted string. */
    var word="(" + atom + "|" + quotedUser + ")";
    // The following pattern describes the structure of the user
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    /* The following pattern describes the structure of a normal symbolic
    domain, as opposed to ipDomainPat, shown above. */
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    /* Finally, let's start trying to figure out if the supplied address is valid. */
    /* Begin with the coarse pattern to simply break up user@domain into
    different pieces that are easy to analyze. */
    var matchArray=emailStr.toLowerCase().match(emailPat);
    if (matchArray==null)
    {
        /* Too many/few @'s or something; basically, this address doesn't
        even fit the general mould of a valid e-mail address. */
        //alert("Email address seems incorrect (check @ and .'s)");
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];
    // Start by checking that only basic ASCII characters are in the strings (0-127).
    for (i=0; i<user.length; i++)
    {
        if (user.charCodeAt(i)>127)
        {
            //alert("Ths username contains invalid characters.");
            return false;
        }
    }
    for (i=0; i<domain.length; i++)
    {
        if (domain.charCodeAt(i)>127)
        {
        //alert("Ths domain name contains invalid characters.");
        return false;
        }
    }
    // See if "user" is valid 
    if (user.match(userPat)==null)
    {
        // user is not valid
        //alert("The username doesn't seem to be valid.");
        return false;
    }
    /* if the e-mail address is at an IP address (as opposed to a symbolic
    host name) make sure the IP address is valid. */
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null)
    {
        // this is an IP address
        for (var i=1;i<=4;i++)
        {
            if (IPArray[i]>255)
            {
                //alert("Destination IP address is invalid!");
                return false;
            }
       }
    }

    // Domain is symbolic name.  Check if it's valid.
    var atomPat=new RegExp("^" + atom + "$");
    var domArr=domain.split(".");
    var len=domArr.length;
    for (i=0;i<len;i++)
    {
        if (domArr[i].search(atomPat)==-1)
        {
            //alert("The domain name does not seem to be valid.");
            return false;
        }
    }

    /* domain name seems valid, but now make sure that it ends in a
    known top-level domain (like com, edu, gov) or a two-letter word,
    representing country (uk, nl), and that there's a hostname preceding 
    the domain or country. */

    if (checkTLD && domArr[domArr.length-1].length!=2 && 
    domArr[domArr.length-1].search(knownDomsPat)==-1)
    {
        //alert("The address must end in a well-known domain or two letter " + "country.");
        return false;
    }

    // Make sure there's a host name preceding the domain.
    if (len<2)
    {
        //alert("This address is missing a hostname!");
        return false;
    }

    // If we've gotten this far, everything's valid!
    return true;
}

//  End -->
