﻿// ------------------------------------------------------------------------------------------
// Copyright AspDotNetStorefront.com, 1995-2010.  All Rights Reserved.
// http://www.aspdotnetstorefront.com
// For details on this license please visit  the product homepage at the URL above.
// THE ABOVE NOTICE MUST REMAIN INTACT.
// ------------------------------------------------------------------------------------------
function $bindMethod(object, method) {
    return function () {
        return method.apply(object, arguments);
    };
}

function $window_addLoad(handler) {
    if (window.addEventListener) {
        window.addEventListener('load', handler, false);
    }
    else if (document.addEventListener) {
        document.addEventListener('load', handler, false);
    }
    else if (window.attachEvent) {
        window.attachEvent('onload', handler);
    }
    else {
        if (typeof window.onload == 'function') {
            var oldload = window.onload;
            window.onload = function () {
                oldload();
                handler();
            }
        }
        else { window.onload = init; }
    }

}

function $getElement(id, handler) {
    var el = document.getElementById(id);
    return el;
}

var Keys = {
    Enter: 13
}

function $handleSearchEnterKey(id, handler) {
    var el = $getElement(id);
    if (el) {
        var delKeypress = function (e) {

            var keyCode;
            if (e && e.which) {
                keyCode = e.which;
            }
            else if (typeof (event) != 'undefined') {
                keyCode = event.keyCode;
            }

            // we must manually invoke the Page_ClientValidate
            // method here since relying on the normal behavior
            // is not guaranteed to set the appropriate validation flags
            // to stop the postback.
            if (keyCode == Keys.Enter) {
                if (typeof (Page_ClientValidate) != 'undefined') {
                    if (Page_ClientValidate() == false) {
                        return;
                    }
                }

                handler();

                return false;
            }
        }

        el.onkeypress = delKeypress;
    }

}


/** Img rollover function. **/
function rollover(name, source) {
    document.images[name].src = source;
}

/** Preload image function: takes an array of img srouces. **/
function preload(aImgSrc) {
    for (var i = 0; i < aImgSrc.length; i++) {
        var newImg = new Image();
        newImg.src = aImgSrc[i];
        aImgSrc["img_" + i] = newImg;
    }
}


function launchWin(winName, winURL, width, height) {
    var ieIncrement = ((navigator.appName + "").indexOf("Netscape") == -1) ? 15 : 0;
    eval(winName + "=window.open('" + winURL + "','" + winName + "','resizable=yes,scrollbars=yes,width=" + (width + ieIncrement) + ",height=" + (height + ieIncrement) + ",top=5,left=75')");
    eval("window." + winName + ".focus()");
}

function checkKeyword(keyword, defaultText) {
    var minKeywordLength = 0;
    var maxKeywordLength = 0;
    minKeywordLength += 3;
    maxKeywordLength += 30;
    var errMsg = '';
    //alert("minKeywordLength " + minKeywordLength);
    var searchTerms = '';
    searchTerms = keyword.value;
    //alert("searchTerms.length " + searchTerms.length);

    var invalidSearchTermMessage = 'Invalid characters found.'; // probably want to change this message! 
    var invalidChars = /[<>'"%;|^]/; // add all illegal characters here. 
    var matches_array = searchTerms.match(invalidChars);
    if (matches_array != null && matches_array.length > 0) {
        // show the user a dialog if '<' or '>' or '!' are found in the keyword. 
       alert(invalidSearchTermMessage);
        return false;
    }


    var noSearchTerm = 'Please enter a keyword or item number';
    var shortSearchTerm = 'Your keyword or item number must be at least 3 characters long';

    if (searchTerms == defaultText) {
        //alert(noSearchTerm);
        return false;
    }
    if (searchTerms == '') {
        //alert(noSearchTerm);
        return false;
    } else if (searchTerms.length < minKeywordLength) {
        //(shortSearchTerm);
        return false;
    } else {
        return true;
    }
}


//added for cart color/size options
function addOption(selectbox, text, value) {
//    alert(text);
//    if (text.indexOf('select') > 0) {
//        alert('ok');
//        alert(text.indexOf('select'));
//    }
//        else{
//            alert('ok1');
//            alert(text.indexOf('select'));
//        }
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    selectbox.options.add(optn);
    //alert('m');
}


var needValidate = false;

var defaultVal2 = "Type in your question to start chatting with a Spa Consultant now.\n\n";
var defaultVal2Off = "Type in your question to send a message to a Spa Consultant now.\n\n";

function openchatwindow() {
    var res = true;

    var msg = document.getElementById("lp_msgfield");

    if (needValidate) {
        var validateMessage = "Before you start your chat, type in the following fields:\r\n ";

        if (msg.value.length == 0 || msg.value == defaultVal2) {
            validateMessage += "Your Question\r\n";
            res = false;
        }
        if (res == false) {
            alert(validateMessage);
        }

    }

    //var formurl = cbForm.action;
    var formurl = "https://server.iad.liveperson.net/hc/37067960/?site=37067960&SESSIONVAR!source=chatbox&SESSIONVAR!survey_pre-chat_enable=off&file=visitorWantsToChat&cmd=file&imageUrl=http://d24dd7ms791idc.cloudfront.net/images/new/Winter10_KC.jpg/newimages3&SESSIONVAR!message=" + msg.value;
    //    if (formurl.indexOf('?') == -1)
    //        formurl += '?';
    //    var elemCol = cbForm.elements;
    //    for (var ie = 0; ie < elemCol.length; ie++) {
    //        var et = elemCol[ie].type;
    //        if (et == "text" || et == "hidden" || et == "radio" || et == "textarea") {
    //            formurl += elemCol[ie].name + "=" + escape(elemCol[ie].value) + "&";
    //        }
    //    }

    if (res == true)
        window.open(formurl, 'chat37067960', 'width=472,height=320,resizable=yes');
    return false;
}


