﻿function SetSearch(haFind, ddlStyleClientID, ddlRoomTypeClientID, ddlProductTypeClientID, tbProductCodeClientID) {
    var href = "/product-search.aspx";
    var ddlStyle, ddlRoomType, ddlProductType, tbProductCode;
    ddlStyle = document.getElementById(ddlStyleClientID);
    ddlRoomType = document.getElementById(ddlRoomTypeClientID);
    ddlProductType = document.getElementById(ddlProductTypeClientID);
    var productCode = "";
    if (tbProductCodeClientID != null) {
        tbProductCode = document.getElementById(tbProductCodeClientID);
        if (tbProductCode != null) {
            if (tbProductCode.value != "Product code") {
                productCode = tbProductCode.value;
            }
        }
    }
    if (productCode != "") {
        href += "?pcd=" + productCode;
    }
    else{
        href += "?stid=" + GetDropDownListSelectedValue(ddlStyle);
        href += "&rtid=" + GetDropDownListSelectedValue(ddlRoomType);
        href += "&ptid=" + GetDropDownListSelectedValue(ddlProductType);
    }
        
    haFind.setAttribute("href", href);
}

function GetRefinedSearchUrl(ddlStyleClientID, ddlRoomTypeClientID, ddlProductTypeClientID, ddlProductTypeSubTypeClientID) {
    var href = "/product-search.aspx";
    var ddlStyle, ddlRoomType, ddlProductType, ddlProductTypeSubType;
    ddlStyle = document.getElementById(ddlStyleClientID);
    ddlRoomType = document.getElementById(ddlRoomTypeClientID);
    ddlProductType = document.getElementById(ddlProductTypeClientID);
    if (ddlProductTypeSubTypeClientID != null) {
        ddlProductTypeSubType = document.getElementById(ddlProductTypeSubTypeClientID);
    }

    href += "?stid=" + GetDropDownListSelectedValue(ddlStyle);
    href += "&rtid=" + GetDropDownListSelectedValue(ddlRoomType);
    href += "&ptid=" + GetDropDownListSelectedValue(ddlProductType);
    if (ddlProductTypeSubTypeClientID != null) {
        href += "&ptstid=" + GetDropDownListSelectedValue(ddlProductTypeSubType);
    }

    return href;
}

function GetArticleRefinedSearchUrl(cboTypeClientID) {
    var href = "";
    var cboType = document.getElementById(cboTypeClientID);
    href = GetDropDownListSelectedValue(cboType);
    return href;
}

function GetProductCodeUrl(productCode) {
    var href = "/product-search.aspx";
    href += "?pcd=" + productCode;

    return href;
}

function SetShowroomSearch(haFind, tbShowroomSearchClientID) {
    var href = "/find-a-showroom.aspx";
    var tbShowroomSearch;
    tbShowroomSearch = document.getElementById(tbShowroomSearchClientID);
    
    href += "?pc=" + tbShowroomSearch.value;
    
    haFind.setAttribute("href", href);
}

function SetShowroomSearch2(haFind, tbShowroomSearchClientID, cbIdealListStockistsClientID) {
    var href = "/find-a-showroom.aspx";
    var tbShowroomSearch, cbIdealListStockists;
    tbShowroomSearch = document.getElementById(tbShowroomSearchClientID);
    cbIdealListStockists = document.getElementById(cbIdealListStockistsClientID);

    href += "?pc=" + tbShowroomSearch.value;
    href += "&ils=" + cbIdealListStockists.checked;

    haFind.setAttribute("href", href);
}

function SetPostcodeSearchText(haFind, tbShowroomSearchClientID) {
    var href = haFind.getAttribute("href");
    var tbShowroomSearchClientID;
    var tbShowroomSearch = document.getElementById(tbShowroomSearchClientID);

    href += "&pcst=" + tbShowroomSearch.value;

    haFind.setAttribute("href", href);
}

function GetDropDownListSelectedValue(ddl) {
    var selectedValue = "";
    for(var i = 0; i < ddl.options.length; i++){
        if(ddl.options[i].selected == true){
            if(ddl.options[i].value != "-1" && ddl.options[i].value != "0"){
                selectedValue = ddl.options[i].value;
                break;
            }
        }        
    }
    return selectedValue;
}

function ShowGlossaryTermToolTip(span) {

}

function SelectAllInputText(input) {
    input.focus();
    input.select();
}

function ClearInputText(input) {
    input.value = "";
}

function ClearDefaultInputText(input, defaultValue) {
    if (input.value == defaultValue) {
        input.value = "";
    }
}

function addOnloadEvent(fnc) {
    if (typeof window.addEventListener != "undefined")
        window.addEventListener("load", fnc, false);
    else if (typeof window.attachEvent != "undefined") {
        window.attachEvent("onload", fnc);
    }
    else {
        if (window.onload != null) {
            var oldOnload = window.onload;
            window.onload = function(e) {
                oldOnload(e);
                window[fnc]();
            };
        }
        else
            window.onload = fnc;
    }
}

function CheckIncompleteDetails() {
    // defined on the page: tbFirstNameControlClientID, tbSurnameControlClientID, tbMainContactNumberControlClientID, FirstNameDefaultValue, SurnameDefaultValue, MainContactNumberDefaultValue
    var tbFirstNameControl = document.getElementById(tbFirstNameControlClientID);
    var tbSurnameControl = document.getElementById(tbSurnameControlClientID);
    var tbMainContactNumberControl = document.getElementById(tbMainContactNumberControlClientID);

//    alert(tbFirstNameControl.value == FirstNameDefaultValue);
//    alert(tbSurnameControl.value == SurnameDefaultValue);
//    alert(tbMainContactNumberControl.value == MainContactNumberDefaultValue);

    if (tbFirstNameControl.value == FirstNameDefaultValue || tbFirstNameControl.value == '' || tbSurnameControl.value == SurnameDefaultValue || tbSurnameControl.value == '' || tbMainContactNumberControl.value == MainContactNumberDefaultValue || tbMainContactNumberControl.value == '') {
        alert("If you'd like to use the call-back feature\nplease login or enter your name and\nnumber in the form on the right.");
        return false;
    }
    else {
        return true;
    }
    

    
}