﻿function saveForm_crb() {
    return saveForm_crb("");
}
function saveForm_crb(ClientID) {
    var oz = $i(ClientID + "hdnProdId");
    var ozv = null;

    var hdnZip = $(ClientID + "hdnZip");
    var hdnCity = $(ClientID + "hdnCity");
    var hdnState = $(ClientID + "hdnState");
    var hdnAdvctgid = $(ClientID + "hdnAdvctgid");

    if (oz != null && ((ozv = oz.value) != null) && ozv == "Enter Zip")
        oz.value = "";

    var sel = $i(ClientID + "rpb_sel_cat");
    var selv = null;
    if (sel != null) {
        selv = sel[sel.selectedIndex].value;
    }

    //has zip but no category
    if ((ozv != null && ozv != '') && (selv == null || selv == '0')) {
        alert('Please select a category');
        return false;
    }
    var f = $i(ClientID + 'frmSearch');
    if (f != null) {
        if ((ozv != null && ozv != '') || (selv != null && selv != '0')) {
            f.action += "?";

            if (ozv != null && ozv != '') {
                if (/^[0-9]{3,}$/.test(ozv))    //zip code
                {
                    f.action += "zip=" + ozv;
                    hdnZip.value = ozv;
                    hdnCity.removeAttribute("name");
                    hdnState.removeAttribute("name");
                }
                else {
                    hdnZip.removeAttribute("name");
                    var locationInfo = ozv.split(',');
                    if (typeof locationInfo.length != 'undefined') {
                        if (locationInfo.length > 1) {
                            f.action += "city=" + locationInfo[0].replace(/ /g, '_'); +"&state=" + locationInfo[1].replace(' ', '');
                            hdnCity.value = locationInfo[0].replace(/ /g, '_');
                            hdnState.value = locationInfo[1].replace(' ', '');
                        }
                        if (locationInfo.length == 1) {
                            f.action += "city=" + locationInfo[0].replace(/ /g, '_');
                            hdnCity.value = locationInfo[0].replace(/ /g, '_');
                        }
                    }

                }
                if (selv != null && selv != '0') {
                    f.action += "&";
                }
            }
            if (selv != null && selv != '0') {
                f.action += "advctgid=" + selv;
                hdnAdvctgid.value = selv;
            }
        }
        if ($F(ClientID + 'hdnProdId') != '0' && selv != -1)
            f.submit();
        else {
            f.action = '/Services.aspx';
            var txtFakeObj = $(ClientID + 'txt_Fake'), rpbObj = $(ClientID + 'divSelCategory'), txtObj = $(ClientID + 'txt');
            if ($F(ClientID + 'hdnProdId') == '0') {
                txtFakeObj.style.border = 'solid 1px Red';
                txtObj.style.border = 'solid 1px Red';
                $(ClientID + 'divTxtError').style.display = '';
            }
            else {
                txtFakeObj.style.border = '';
                txtObj.style.border = '';
                $(ClientID + 'divTxtError').style.display = 'none';
            }
            if (selv == -1) {
                rpbObj.style.border = 'solid 1px Red';
                $(ClientID + 'divCtgError').style.display = '';
            }
            else {
                rpbObj.style.border = '';
                $(ClientID + 'divCtgError').style.display = 'none';
            }
        }

    }

    return false;

}

function logWithOptions() {
    return logWithOptions("");
}
function logWithOptions(ClientID) {
    if ($F(ClientID + 'rpb_sel_cat') == 0) {
        if ($F(ClientID + 'txt') == '')
            logEvent(5434);
        else
            logEvent(5435);
    }
    else {
        if ($F(ClientID + 'txt') == '')
            logEvent(5436);
        else
            logEvent(5437);
    }
    return true;
}
function submit_search(clientID, hdnprodID, txt, txtError, advctgid, defaultAction , sesseionLocation) {
    var ozv = $F(hdnprodID);
    var f = $i(clientID + '_frmSearch');
    
    var hdnZip = $(clientID + "_hdnZip");
    var hdnCity = $(clientID + "_hdnCity");
    var hdnState = $(clientID + "_hdnState");
    var hdnAdvctgid = $(clientID + "_hdnAdvctgid");
    var hdnSessionLocation = $(clientID + "_hdnSessionLocation");

    if (f != null) {
        if (ozv !== null && ozv != '0') {
            
            //f.action += "?";
            if (/^[0-9]{3,}$/.test(ozv))    //zip code
            {
                //f.action += "zip=" + ozv;
                hdnZip.value = ozv;
                hdnCity.removeAttribute("name");
                hdnState.removeAttribute("name");
            }
            else {
                hdnZip.removeAttribute("name");
                var locationInfo = ozv.split(',');
                if (typeof locationInfo.length != 'undefined') {
                    if (locationInfo.length > 1) {
                        //f.action += "city=" + locationInfo[0] + "&state=" + locationInfo[1].replace(' ', '');
                        hdnCity.value = locationInfo[0].replace(/ /g, '_');
                        hdnState.value = locationInfo[1].replace(' ', '');
                    }
                    if (locationInfo.length == 1) {
                        //f.action += "city=" + locationInfo[0];
                        hdnCity.value = locationInfo[0].replace(/ /g, '_');
                    }
                }
            }
            if ($('rpbCategories') === null) {
                //f.action += "&advctgid=" + advctgid;
                hdnAdvctgid.value = advctgid;
            }
            else {
                //f.action += "&advctgid=" + $F('rpbCategories');
                hdnAdvctgid.value = $F('rpbCategories');
            }
             f.submit();
         }
         else if (sesseionLocation != null && hdnSessionLocation != '0') {
            if (/^[0-9]{3,}$/.test(sesseionLocation))    //zip code
            {
                hdnZip.value = sesseionLocation;
                hdnCity.removeAttribute("name");
                hdnState.removeAttribute("name");
            }
            else {
                hdnZip.removeAttribute("name");
                var locationInfo = sesseionLocation.split(',');
                if (typeof locationInfo.length != 'undefined') {
                    if (locationInfo.length > 1) {
                        //f.action += "city=" + locationInfo[0] + "&state=" + locationInfo[1].replace(' ', '');
                        hdnCity.value = locationInfo[0].replace(/ /g,'_');
                        hdnState.value = locationInfo[1].replace(' ', '');
                    }
                    if (locationInfo.length == 1) {
                        //f.action += "city=" + locationInfo[0];
                        hdnCity.value = locationInfo[0].replace(/ /g, '_');
                    }
                }
            }
            if ($('rpbCategories') === null) {
                //f.action += "&advctgid=" + advctgid;
                hdnAdvctgid.value = advctgid;
            }
            else {
                //f.action += "&advctgid=" + $F('rpbCategories');
                hdnAdvctgid.value = $F('rpbCategories');
            }
            f.submit();
        }
        else {
            f.action = defaultAction;
            var txtObj = $(txt);
            txtObj.style.border = 'solid 1px Red';
            $(txtError).style.display = '';
        }

    }
    return false;
}
function onGuestRepairClick(obj) {
    // check if RTE is empty
    update_rte_2();
    var isOK = ctrl_solution_editor_checkf();
    if ($F("c_solution_window_type") == 0) {
        logEventPtype(1, 5923);
    } else {
        logEvent(5946);
    }
    
    if (isOK == false) {
        return false;
    }

    // not empty
    doModal();
    ShowCenteredAlertDIV1("divAreYouAdvert_" + iCurThdId);
    return false;
}