var nLuxaIndex = 1; // Start Globals ==================
var strLuxaJSString = "";

var bRequireFirstContactFlds = false;
var bRequireSecondContactFlds = false;
var bRequireComments = false;
var bRequireLuxaFlexFlds = false;
var bRequireBrochureFld = false;
var bQuoteRequired = false;

var nCommentsSelectedCount = 0;
var nCommonPrmptsSelectedCount = 0;
var nFirstFldsSelectedCount = 0;
var nSecondFldsSelectedCount = 0;
var nQuotecount = 0;


var brochureError = false;
var quoteError = false;
var sampleError = false;
var addressError = false;
var boxError = false;
// End Globals ===================

/* ----------------------------------------------------
Start Contact Us
---------------------------------------------------- */
/* Handle clicks on the contact us form */
function toggle(obj) {
    var oForm = document.forms[0];
    if (obj != null) var dsp = obj.style.display; obj.style.display = (dsp == 'none') ? 'block' : 'none';
    //updateRequiredFields(obj.id.replace("div_", "cb_"));

    /* label is bold only when checked */
    var o2 = document.getElementById(obj.id.replace("div_", "cb_"));
    var o3 = document.getElementById(obj.id.replace("div_", "lbl_"));

    if (o2 != null && o3 != null) {
        o3.style.fontWeight = o2.checked ? "bold" : "normal";
    }

    var obj2 = document.getElementById("cb_smpl_contactfrm");
    var obj3 = document.getElementById("cb_quot_contactfrm");
    var obj4 = document.getElementById("cb_appt_contactfrm");
    var obj5 = document.getElementById("cb_otherquot_contactfrm");
    var obj6 = document.getElementById("cb_luxaquot_contactfrm");

    if (o2.id == "cb_brch_contactfrm") {

        var btn_cb_brch_contactfrm_elm1 = oForm.elements["cb_brch_requestcorp"];
        var btn_cb_brch_contactfrm_elm2 = oForm.elements["cb_brch_requestdealer"];
        if (o2.checked == false) {


            if (btn_cb_brch_contactfrm_elm1) {
                for (var j = 0; j < btn_cb_brch_contactfrm_elm1.length; j++) {
                    btn_cb_brch_contactfrm_elm1[j].checked = false;
                }

            }

            if (btn_cb_brch_contactfrm_elm2) {

                for (var j = 0; j < btn_cb_brch_contactfrm_elm2.length; j++) {
                    btn_cb_brch_contactfrm_elm2[j].checked = false;
                }

            }
        }


    }

    // Check address field
    var stype0 = "off"

    if (obj2.checked == true || obj5.checked == true) {

        stype0 = "on";
    }

    updateRequiredFiled(stype0, "l_comments")

    // Check address field
    var stype = "off";

    if (obj2.checked == true) {

        stype = "on";
    }
    updateaddressRequiredFiled(stype);

    // Check contact by field

    var stype1 = "off";

    if (obj3.checked == true || obj4.checked == true) {

        stype1 = "on";

    }

    updateRequiredFiled(stype1, "l_contactby")

    //check quote fields

    if (obj3.checked == false) {
        var obj1_a = document.getElementById("div_luxaquot_contactfrm");
        var obj2_a = document.getElementById("div_otherquot_contactfrm");

        obj5.checked = false;
        obj6.checked = false;
        swicthdisplay(obj1_a, 0);
        swicthdisplay(obj2_a, 0);

        clearAllLuxaFlexFlds();

    }

    if (obj6.checked == false) {
        clearAllLuxaFlexFlds();

    }



}

/* Adds another set of Luxaflex product charateristics. There can by n-many. */
function addluxaflexprod(obj) {

    indexLuxaflexQuoteJSString();

    var obj = document.getElementById('div_luxaquote_container');
    nLuxaIndex++;

    obj.innerHTML += strLuxaJSString;

}

function swicthdisplay(obj, t) {

    if (obj != null) {
        obj.style.display = (t == 1) ? 'block' : 'none';
    }

    /* label is bold only when checked */
    var o2 = document.getElementById(obj.id.replace("div_", "cb_"));
    var o3 = document.getElementById(obj.id.replace("div_", "lbl_"));

    if (o2 != null && o3 != null) {
        o3.style.fontWeight = o2.checked ? "bold" : "normal";
    }
}

function updateaddressRequiredFiled(type) {

    var oForm = document.forms[0];

    for (var i = 1; i < 7; i++) {
        var objAddress = oForm.elements["_addresslabel" + i];

        if (objAddress) {
            if (objAddress.value == "Yes") {

                var objAddressLable = document.getElementById("l_addresslabel" + i);

                if (type == "on") {
                    objAddressLable.innerHTML = "*";
                } else {
                    objAddressLable.innerHTML = "";
                }
            }
        }
    }

}

function updateRequiredFiled(type, f) {

    var objLable = document.getElementById(f);

    if (type == "on") {
        objLable.innerHTML = "*";
    } else {
        objLable.innerHTML = "";
    }

}

function updatecontactbyfieldRequiredFiled(obj) {

    var type = obj.options[obj.selectedIndex].value;

    var objEmailLable = document.getElementById("l_email");
    var objPhoneLable = document.getElementById("l_phone");

    if (type == "email") {
        objPhoneLable.innerHTML = "";
        objEmailLable.innerHTML = "*";
    } else if (type == "phone") {

        objEmailLable.innerHTML = "";
        objPhoneLable.innerHTML = "*";
    } else {
        objEmailLable.innerHTML = "";
        objPhoneLable.innerHTML = "";
    }

}

function clearAllLuxaFlexFlds() {

    var oForm = document.forms[0];
    for (var nDx = 0; nDx < nLuxaIndex; nDx++) {

        var obj, nIter; arrObj = new Array(
			eval("oForm.sel_luxa_product_" + nDx),
			eval("oForm.sel_luxa_rooms_" + nDx),
			eval("oForm.txt_luxa_dim_width_" + nDx),
			eval("oForm.txt_luxa_dim_height_" + nDx),
			eval("oForm.txt_luxa_dim_quantity_" + nDx)
		);
        for (nIter in arrObj) {
            if (arrObj[nIter]) {
                obj = arrObj[nIter];
                if (obj.tagName.toLowerCase() == "input" && obj.type.toLowerCase() == "text") {
                    obj.value = "";
                } else if (obj.tagName.toLowerCase() == "select") {
                    obj.selectedIndex = 0;
                    obj.selected = false;
                }
            }
        }
        var obj = document.getElementById('div_luxaquote_container');
        if (obj) {
            nLuxaIndex = 0;
            indexLuxaflexQuoteJSString();
            nLuxaIndex++;
            obj.innerHTML = strLuxaJSString;
        }
    }
}

function areAnyBrochuresSelected() {

    var bRet = false;
    var obj = document.forms[0].cb_brch_request1;
    for (nDx = 1; obj != null; nDx++) {

        if (obj.checked == true) { bRet = true; break; }
        obj = eval("document.forms[0].cb_brch_request" + nDx);

    }
    return bRet;

}
function areAllLuxaFlexFldsSet() {

    var nDx;
    var bRet = false;
    var objProd = document.forms[0].sel_luxa_product_0;
    var objRoom = document.forms[0].sel_luxa_rooms_0;
    var objWidth = document.forms[0].txt_luxa_dim_width_0;
    var objHeight = document.forms[0].txt_luxa_dim_height_0;
    var objQuant = document.forms[0].txt_luxa_dim_quantity_0;

    for (nDx = 1; objProd != null; nDx++) {

        if (
                objProd.selectedIndex != 0 &&
                objRoom.selectedIndex != 0 &&
                Trim(objWidth.value) != "" &&
                Trim(objHeight.value) != "" &&
                Trim(objQuant.value) != ""
            ) { bRet = true; } else { bRet = false; break; }

        objProd = eval("document.forms[0].sel_luxa_product_" + nDx);
        objRoom = eval("document.forms[0].sel_luxa_rooms_" + nDx);
        objWidth = eval("document.forms[0].txt_luxa_dim_width_" + nDx);
        objHeight = eval("document.forms[0].txt_luxa_dim_height_" + nDx);
        objQuant = eval("document.forms[0].txt_luxa_dim_quantity_" + nDx);

    }
    return bRet;

}

function updateCommonContactPrmpts(bSelected) {
    nCommonPrmptsSelectedCount += bSelected ? 1 : -1;
    if (bSelected && nCommonPrmptsSelectedCount > 0) { setCommonContactPrmpts(true); }
    if (bSelected == false && nCommonPrmptsSelectedCount == 0) { setCommonContactPrmpts(false); }
}
function updateFirstContactFlds(bSelected) {
    updateCommonContactPrmpts(bSelected);
    nFirstFldsSelectedCount += bSelected ? 1 : -1;
    if (bSelected && nFirstFldsSelectedCount > 0) { bRequireFirstContactFlds = true; setFirstContactPrmpts(true); }
    if (bSelected == false && nFirstFldsSelectedCount == 0) { bRequireFirstContactFlds = false; setFirstContactPrmpts(false); }
}
function updateSecondContactFlds(bSelected) {
    updateCommonContactPrmpts(bSelected);
    nSecondFldsSelectedCount += bSelected ? 1 : -1;
    if (bSelected && nSecondFldsSelectedCount > 0) { bRequireSecondContactFlds = true; setSecondContactPrmpts(true); }
    if (bSelected == false && nSecondFldsSelectedCount == 0) { bRequireSecondContactFlds = false; setSecondContactPrmpts(false); }
}

function setCommonContactPrmpts(bReq) {
    var arrPrmpts = new Array(
            "prmpt_contactinfo_firstname",
            "prmpt_contactinfo_lastname"
        );
    var nPrmpt;
    for (nPrmpt in arrPrmpts) { setPrmpt(arrPrmpts[nPrmpt], bReq); }

}
function setFirstContactPrmpts(bReq) {
    var arrPrmpts = new Array;
    //         = new Array (
    //            "prmpt_contactinfo_address1",
    //            "prmpt_contactinfo_city",
    //            "prmpt_contactinfo_postalcode"
    //        );
    initFirstContatctPrmpts(arrPrmpts);
    var nPrmpt;
    for (nPrmpt in arrPrmpts) { setPrmpt(arrPrmpts[nPrmpt], bReq); }

}
function setSecondContactPrmpts(bReq) {
    var strPrmpt = "prmpt_contactinfo_contactby";
    setPrmpt(strPrmpt, bReq);
    if (bReq == false) {
        var strInput = strPrmpt.substring(strPrmpt.indexOf("_") + 1).substring(strPrmpt.substring(strPrmpt.indexOf("_") + 1).indexOf("_") + 1);
        var oInput = document.getElementById(strInput);
        if (oInput) { oInput.selectedIndex = 0; trackContactByChange(oInput); }
    }

}
function setPrmpt(strPrmpt, bReq) {
    var obj = document.getElementById(strPrmpt);
    if (obj) {
        if (bReq) {
            if (obj.innerHTML.substring(obj.innerHTML.length - 1) != "*") obj.innerHTML += "*";
        } else {
            if (obj.innerHTML.substring(obj.innerHTML.length - 1) == "*")
                obj.innerHTML = obj.innerHTML.substring(0, obj.innerHTML.length - 1);
        }
    }

    var strInput = strPrmpt.substring(strPrmpt.indexOf("_") + 1).substring(strPrmpt.substring(strPrmpt.indexOf("_") + 1).indexOf("_") + 1);
    var oInput = eval("document.forms[0]." + strInput);
    if (oInput && strInput == "contactby") {
        if (bReq) {
            oInput.disabled = false;
        } else {
            oInput.disabled = true;
            switch (oInput.type) {
                case "text": oInput.value = ""; break;
                case "select": oInput.selectedIndex = 0; oInput.selected = false; break;
            }
        }
    }


}
function isSel(strPrmpt) {
    var nRet = false; obj = document.getElementById(strPrmpt);
    if (obj) {
        nRet = (obj.innerHTML.substring(obj.innerHTML.length - 1) == "*")
    }

}
function initFirstContatctPrmpts(arrPrmpts) {
    var ob;
    for (var nDx = 1; nDx <= 6; nDx++) {
        ob = eval("document.forms[0].prompt" + nDx + "required");
        if (ob.value == "Yes")
            arrPrmpts[arrPrmpts.length] = "prmpt_prompt" + nDx;
    }
}
function contains(arrPrmpts, sPrmpt) {
    var bRet = false;
    for (var nDx in arrPrmpts) {
        if (arrPrmpts[nDx] == sPrmpt) { bRet = true; break; }
    }
    return bRet;
}

/* ----------------------------------------------------
End Contact Us
Start Utils
---------------------------------------------------- */

//function OpenPhotoGallery(type,vanity,domain) {
function OpenPhotoGallery(domain) {

    //	var gc = oForm.gc.value;
    //	var gl = oForm.gl.value;
    var act = document.getElementById("act").value;

    var photogallerydomain = "http://" + domain;

    var url = photogallerydomain + "/" + "au" + "/" + "en" + "/";
    //	var url = "http://" + domain + "/";

    /*	if (vanity != "" && vanity != null) {
    url += vanity + "/" + "filter.cn?crt=paneltype=photogalleryimage";
		
    if (type != "" && type != null) {
    url += "%26type=" + type + "%26generic1=0"		
    }
		
    } else {	
	
    url += "sb.cn?crt=generic3=1";
    }	*/
    url += "sb.cn?crt=generic3=1%26generic4=c";
    //	url += "%26generic4=c";

    var h;

    if (screen.height < 900) {

        h = (eval(screen.height) - 40);

    } else {
        h = 880;
    }
    PopupWindow(url, "yes", "600", h, "PhotoGallery");
}

function popupw(vanity, extra, type) {


    var url;

    url = vanity;

    if (extra != "") {
        url += "?crt=" + replaceSubstring(extra, "&", "%26");
    }

    if (type && type == 'p') {

        PopupWindow(url, 'yes', '600', '600')
    } else {

        PopupWindow(url, "yes", "600", "600", "");
    }
}

function goInternal(vanity, pagetype, extra) {
    var sLink = "";

    var gc = document.getElementById("gc").value;
    var gl = document.getElementById("gl").value;
    var act = document.getElementById("act").value;
    var sitekey = document.getElementById("sitekey").value;

    if (pagetype == "p") {

        var extra = "";

        var pageid = document.getElementById("pk").value;

        var extra = "";

        for (var i = 1; i < 15; i++) {

            if (document.getElementById("g" + i).value != "") {
                if (extra != "") {
                    extra += "%26";
                }
                extra += "generic" + i + "=" + document.getElementById("g" + i).value;
            }
        }

    }

    sLink = "/" + gc + "/" + gl + "/" + vanity + "/";

    if (act == "SITEBUILDER") {
        sLink += "sb.cn"
    } else {
        sLink += "preview.cn"
    }

    if (extra) {

        sLink += "?crt=" + extra;
    }

    if (pagetype == "p")
        PopupWindow(sLink, 'yes', '760', '600');
    else
        self.location.href = sLink;

}


/* ----------------------------------------------------
End Utils
Start Popups
---------------------------------------------------- */
function OpenDirections(act, sitekey, pagekey, gc, gl, extra) {
    var url;

    if (act == "SITEBUILDER") {
        url = "/" + gc + "/" + gl + "/sb.cn?crt=";
    } else {
        url = "/admin/channelnet.aspx?cn=SiteBuilderadmin&act=PreviewPage&crt=sitekey=" + sitekey + "%26";
    }

    url += "pagekey=" + pagekey;

    if (extra != "") {
        url += "%26" + extra;
    }

    PopupWindow(url, "yes", "660", "640", "Directions");

}


function GetDirections(pagekey) {
    var oFormS = document.forms.startlocation;
    var oFormCN = document.forms.channelnet;
    var crt = "pagekey=" + pagekey;
    crt += "&generic1=" + oFormS.generic1.value;

    if (oFormS.postcode.value == "" && oFormS.street.value == "" && oFormS.city.value == "") {
        alert(GLANG_95192);
        return false;
    }

    if (oFormS.postcode.value != "") {
        crt += "&generic4=" + oFormS.postcode.value;
    }
    else {
        if (oFormS.street.value != "" && oFormS.city.value != "") {
            crt += "&generic2=" + oFormS.street.value;
            crt += "&generic3=" + oFormS.city.value;
        }
        else {
            alert(GLANG_95193);
            return false;
        }
    }

    oFormCN.crt.value = crt;
    oFormCN.submit();
}

function GetDirections(act, sitekey, pagekey, gc, gl, extra) {
    var oFormS = document.forms.startlocation;
    var oFormCN = document.forms.channelnet;
    var crt = "pagekey=" + pagekey;
    crt += "%26generic1=" + oFormS.generic1.value;

    if (oFormS.postcode.value == "" && oFormS.street.value == "" && oFormS.city.value == "") {
        alert(GLANG_95192);
        return false;
    }

    if (oFormS.postcode.value != "") {
        crt += "%26generic4=" + oFormS.postcode.value;
    }
    else {
        if (oFormS.street.value != "" && oFormS.city.value != "") {
            crt += "%26generic2=" + oFormS.street.value;
            crt += "%26generic3=" + oFormS.city.value;
        }
        else {
            alert(GLANG_95193);
            return false;
        }
    }

    if (act == "SITEBUILDER") {
        url = "/" + gc + "/" + gl + "/sb.cn?crt=";
    } else {
        url = "/admin/channelnet.aspx?cn=SiteBuilderadmin&act=PreviewPage&crt=sitekey=" + sitekey + "%26";
    }

    url += "%26" + crt;

    PopupWindow(url, "yes", "660", "640", "Directions");

}

/* ----------------------------------------------------
End  Popups
---------------------------------------------------- */

function checkAddress(oForm) {
    addressError = false;
    if (Trim(oForm.elements["firstname"].value) == "") {
        alert(GLANG_95198 + oForm.elements["firstnamelabel"].value + ".");
        addressError = true;
        return false;
    } else if (Trim(oForm.elements["lastname"].value) == "") {
        alert(GLANG_95198 + oForm.elements["lastnamelabel"].value + ".");
        addressError = true;
        return false;
    } else {
        if (document.getElementById("cb_brch_contactfrm").checked == true || document.getElementById("cb_smpl_contactfrm").checked == true) {
            for (i = 1; i <= 6; i++) {
                if (oForm.elements["addresslabel" + i]) {
                    if (oForm.elements["_addresslabel" + i].value == 'Yes') {
                        if (oForm.elements["addresslabel" + i].value.length == 0) {
                            alert(GLANG_95198 + oForm.elements["_vaddresslabel" + i].value + ".");
                            addressError = true;
                            return false;
                        }
                    }
                }
            }
        }

        if (document.getElementById("cb_quot_contactfrm").checked == true || document.getElementById("cb_appt_contactfrm").checked == true) {
            if (Trim(oForm.elements["contactby"].value) == "") {
                alert(GLANG_95198 + oForm.elements["contactbylabel"].value + ".");
                addressError = true;
                return false;
            } else if (oForm.elements["contactby"].value == "phone") {
                if (oForm.elements["phone"].value.length == 0) {
                    alert(GLANG_95198 + oForm.elements["phonelabel"].value + ".");
                    addressError = true;
                    return false;
                }
            } else if (oForm.elements["contactby"].value == "email") {
                if (oForm.elements["email"].value.length == 0) {
                    alert(GLANG_95198 + oForm.elements["emaillabel"].value + ".");
                    addressError = true;
                    return false;
                }
            }
        }
    }

}

function checkBoxes(oForm) {
    /*boxError = false;
    if (document.getElementById("cb_brch_contactfrm").checked == false && document.getElementById("cb_smpl_contactfrm").checked == false && document.getElementById("cb_quot_contactfrm").checked == false && document.getElementById("cb_appt_contactfrm").checked == false) {
    boxError = true;
    alert(GLANG_95199 + "\n'" + oForm.elements["requestbrochurelabel"].value + "'\n'" + oForm.elements["samplelabel"].value + "'\n'" + oForm.elements["quotelabel"].value + "'\n'" + oForm.elements["aptlabel"].value + "'");
    return false;
    }
    */
}

function checkBrochure(oForm) {
    brochureError = false;
    var thecheckbox = document.getElementById("cb_brch_contactfrm");
    if (thecheckbox.checked == true) {
        var brochureschecked = false;
        var brochures_corp = oForm.elements["cb_brch_requestcorp"];
        if (brochures_corp) {
            for (var j = 0; j < brochures_corp.length; j++) {
                if (brochures_corp[j].checked) {
                    brochureschecked = true;
                    break;
                }
            }
        }
        var brochures_dealer = oForm.elements["cb_brch_requestdealer"];
        if (brochures_dealer) {
            for (var j = 0; j < brochures_dealer.length; j++) {
                if (brochures_dealer[j].checked) {
                    brochureschecked = true;
                    break;
                }
            }
        }
        if (brochureschecked == false) {
            brochureError = true;
            alert(GLANG_95202);
            return false;
        }
    }

}

function checkSample(oForm) {
    sampleError = false;
    var thecheckbox = document.getElementById("cb_smpl_contactfrm");
    if (thecheckbox.checked == true) {
        if (checkComments(oForm) == false) {
            sampleError = true;
            alert(GLANG_95200);
            return false;
        }
    }
}

function checkQuote(oForm) {
    quoteError = false;
    var thecheckbox = document.getElementById("cb_quot_contactfrm");
    if (thecheckbox.checked == true) {
        var luxproduct = document.getElementById("cb_luxaquot_contactfrm");
        var otherproduct = document.getElementById("cb_otherquot_contactfrm");
        if (luxproduct.checked == false && otherproduct.checked == false) {
            quoteError = true;
            alert(GLANG_95199 + "\n'" + oForm.elements["luxaflexquotelabel"].value + "'\n'" + oForm.elements["otherquotelabel"].value + "'");
            return false;
        } else {

            if (luxproduct.checked == true) {
                for (i = 0; i < nLuxaIndex; i++) {
                    if (oForm.elements["sel_luxa_product_" + (nLuxaIndex - 1)].value == 0 || oForm.elements["sel_luxa_rooms_" + (nLuxaIndex - 1)].value == 0 || oForm.elements["txt_luxa_dim_width_" + (nLuxaIndex - 1)].value.length == 0 || oForm.elements["txt_luxa_dim_height_" + (nLuxaIndex - 1)].value.length == 0 || oForm.elements["txt_luxa_dim_quantity_" + (nLuxaIndex - 1)].value.length == 0) {
                        quoteError = true;
                        alert(GLANG_95201);
                        return false;
                        break;
                    }
                }
            }
            if (otherproduct.checked == true) {
                if (checkComments(oForm) == false) {
                    quoteError = true;
                    alert(GLANG_95200);
                    return false;
                }
            }
        }

    }
}


function checkComments(oForm) {
    if (Trim(oForm.elements["comments"].value) != "") {
        return true;
    } else {
        return false;
    }
}

function isCorpEmail(oForm) {
    var brochures_corp = oForm.elements["cb_brch_requestcorp"];
    if (brochures_corp) {
        for (var j = 0; j < brochures_corp.length; j++) {
            if (brochures_corp[j].checked) {
                return true;
            }
        }
    }
    return false;
}

function SendContactUsFormGallery(dealertype) {
    var oForm = document.forms[0];

    var emailusemail = "";

    var oSubject1 = oForm.elements["subject"];

    var siteKey = oForm.elements["sitekey"];

    var ofName = oForm.elements["firstname"];
    var olName = oForm.elements["lastname"];
    var oPhone = oForm.elements["phone"];
    var oEmail = oForm.elements["email"];
    var oMessage = oForm.elements["comments"];

    var oAddress1 = oForm.elements["addresslabel1"];
    var oAddress2 = oForm.elements["addresslabel2"];
    var oAddress3 = oForm.elements["addresslabel3"];
    var oAddress4 = oForm.elements["addresslabel4"];
    var oAddress5 = oForm.elements["addresslabel5"];
    var oAddress6 = oForm.elements["addresslabel6"];
    var oAddressLabel1 = oForm.elements["_vaddresslabel1"];
    var oAddressLabel2 = oForm.elements["_vaddresslabel2"];
    var oAddressLabel3 = oForm.elements["_vaddresslabel3"];
    var oAddressLabel4 = oForm.elements["_vaddresslabel4"];
    var oAddressLabel5 = oForm.elements["_vaddresslabel5"];
    var oAddressLabel6 = oForm.elements["_vaddresslabel6"];

    var omessinfolabel = oForm.elements["messinfolabel"];
    var ocusinfolabel = oForm.elements["cusinfolabel"];
    var oemaillabel = oForm.elements["emaillabel"];
    var obrlabel = oForm.elements["requestbrochure_label"];
    var oconlabel = oForm.elements["conlabel"];
    var ofnamelabel = oForm.elements["firstnamelabel"];
    var olnamelabel = oForm.elements["lastnamelabel"];

    var dealerEmail = oForm.dealeremail.value;

    var fFormType = '3';
    var fStoreType = '1';
    var fRecMark = document.getElementById("nomaterials").checked;
    var sRecMark = "0";
    if (fRecMark == true) {
        sRecMark = "1";
    }
    var bErrors = false;
    var strErrors = "";

    if (ofName.value == '') {
        strErrors += "First Name is required.\n";
        bErrors = true;
    }
    if (olName.value == '') {
        strErrors += "Surname is required.\n";
        bErrors = true;
    }
    if (oAddress4.value == '') {
        strErrors += "Postcode is required.\n";
        bErrors = true;
    }

    if (oPhone.value == '' && oEmail.value == '') {
        strErrors += "Phone or Email are required.\n";
        bErrors = true;
    }

    if (bErrors == true) {
        alert(strErrors);
        return false;
    } else {
        var strParams = "?crt=";
        strParams += "FormType=" + fFormType;
        //strParams += "%26StoreType=" + fStoreType;
        strParams += "%26DealerType=" + dealertype;
        strParams += "%26Email=" + oEmail.value;
        strParams += "%26FirstName=" + ofName.value;
        strParams += "%26LastName=" + olName.value;
        if (oAddress1.value != '') {
            strParams += "%26Address=" + oAddress1.value;
        }
        if (oAddress2.value != '') {
            strParams += "%26Suburb=" + oAddress2.value;
        }
        if (oAddress3.value != '') {
            strParams += "%26State=" + oAddress3.value;
        }
        strParams += "%26PostCode=" + oAddress4.value;
        strParams += "%26Country=AU";
        if (oPhone.value != '' && oPhone.value != 'phone number') {
            strParams += "%26Phone=" + oPhone.value;
        }
        strParams += "%26Comments=" + document.getElementById("comments").value;
        if (document.getElementById("howdidyouhear").value != 'how did you hear about us?') {
            strParams += "%26AboutUs=" + document.getElementById("howdidyouhear").value;
        }
        strParams += "%26RecMark=" + sRecMark;
        if (document.getElementById("cb_smpl_contactfrm").checked == true) {
            strParams += "%26ReqSamp=1";
        }
        if (document.getElementById("cb_quot_contactfrm").checked == true) {
            strParams += "%26ReqQuote=1";
        }
        if (document.getElementById("cb_appt_contactfrm").checked == true) {
            strParams += "%26Appt=1";
        }

        if (oEmail.value != '') {
            strParams += "%26contactby=email";
        }
        else {
            strParams += "%26contactby=phone";
        }


        strParams += "%26pc=" + oAddress4.value;
        strParams += "%26NotificationEmail=" + dealerEmail;
        var sLink = "addlead.cn" + strParams;
        //alert(sLink);
        location.assign(sLink);
    }
}

function selectanchor(elmName) {
    if (elmName == 'commnets' || elmName == 'comments') {
        document.getElementById("comments").focus();
    }
}

function goSearch(frm) {
    var pagename = document.getElementById("pagevanity").value;
    var query = "?crt=generic1=" + document.getElementById("searchbox").value;
    var sLink = pagename + query;
    self.location.href = sLink;
}

function PopupWindow1(myLocation) {
    var oWin;

    //window.showModalDialog(myLocation,'','dialogHeight:'+height+'px;dialogWidth:'+width+'px;center:yes;resizeable:yes;help:no;status:no');
    oWin = window.open(myLocation);
    oWin.focus();
}

function switchba(id, t1, t2) {
    var oImage1 = document.getElementById(t1 + "image" + id);
    var oImage2 = document.getElementById(t2 + "image" + id);
    var oTable1 = document.getElementById("tbl_" + t1 + "_" + id);
    var oTable2 = document.getElementById("tbl_" + t2 + "_" + id);

    oImage2.style.display = "none";
    oImage1.style.display = "inline";
    oTable2.style.display = "none";
    oTable1.style.display = "inline";
}

function goDrivingDirections() {
    var strAddress = Trim(document.getElementById("address").value);
    var strSuburb = Trim(document.getElementById("suburb").value);
    var intLocationKey = Trim(document.getElementById("locationkey").value);

    var sLink = "sb.cn?crt="

    if (strAddress != '' && strSuburb != '') {
        sLink += "generic1=address";
        sLink += "%26generic2=" + strAddress;
        sLink += "%26generic3=" + strSuburb;
        sLink += "%26generic9=" + intLocationKey;
    } else {
        alert("An Address and Suburb is required for Driving Directions.");
        return false;
    }

    //alert(sLink);
    location.assign(sLink);
}

function changeLocation(iCurrent, iTotal) {
    var step_navlocation = "";
    var step_navlocationtitle = "";
    for (i = 1; i <= iTotal; i++) {
        step_navlocation = "navlocation_" + i;
        document.getElementById(step_navlocation).style.display = 'none';
        step_navlocationtitle = "navlocationtitle_" + i;
        if (pngAlpha) {
            document.getElementById(step_navlocationtitle).innerHTML = "<img src='/Themes/common/images/blank.gif' border='0' width='7' height='7' style='width: 7px; height: 7px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/Themes/Default/en-us/SiteBuilder/themes/Dealer/images/arrow_category-closed.png, sizingMethod=scale);' />";
        } else {
            document.getElementById(step_navlocationtitle).innerHTML = "<img border='0' src='/Themes/Default/en-us/SiteBuilder/themes/Dealer/images/arrow_category-closed.png' width='7' height='7' />";
        }
    }
    step_navlocation = "navlocation_" + iCurrent;
    document.getElementById(step_navlocation).style.display = 'block';
    step_navlocationtitle = "navlocationtitle_" + iCurrent;
    if (pngAlpha) {
        document.getElementById(step_navlocationtitle).innerHTML = "<img src='/Themes/common/images/blank.gif' border='0' width='7' height='7' style='width: 7px; height: 7px; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=/Themes/Default/en-us/SiteBuilder/themes/Dealer/images/arrow_category-open.png, sizingMethod=scale);' />";
    } else {
        document.getElementById(step_navlocationtitle).innerHTML = "<img border='0' src='/Themes/Default/en-us/SiteBuilder/themes/Dealer/images/arrow_category-open.png' width='7' height='7' />";
    }
}
