﻿var m_icom_uid = 0;
var m_isEvent = false;

String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}

function fireDefaultButton(event, target) {
    if (event.keyCode == 13) {
        $('#' + target).trigger('click');
        event = jQuery.event.fix(window.event || event);
        event.stopPropagation();
    }
    return true;

}

function deleteCookie() {
    $.post('/show/online/login/RemoveCookie', {}, OnDeleteCookieCompleted);

}
function OnDeleteCookieCompleted(response, status) {
    $('#hfBro_uid').val(response);
    $('#hfIsBro_uid').val("false");

    $('#lblWelcome').hide();
    $('#imgAddRemove').attr('src', 'img_minus.gif');
    $('#spnAddRemove').html('Remove');
    $('#spnShowBriefcase').hide();

    //This exists on the default search page
    $('#LoginPanel').show();
    $('#pnlCreateBriefcase').show();

    window.location = '/show/online/';
}

////

function hideLoginRegister() {
    $('#LoginPanel').dialog('close');
}
function validateEmail(oBrfEmail) {
    var sValue = oBrfEmail.value;
    var obj;
    obj = $('#lblBrfEmailError');
    obj.html('')
    var i = sValue.indexOf('.');
    if (i < 0) {
        obj.html('<br /> invalid email');
    }
    i = sValue.indexOf('@');
    if (i < 0) {
        obj.html('<br /> invalid email');
    }
}
function checkValidBrfCase() {
    var lbl = $('#lblBrfError');
    var obj;
    obj = $('#txtbrfUsername');
    if (obj.val().trim() == 'username:') {
        lbl.html('please fill in required fields');
        return false;
    }
    obj = $('#txtbrfPassword1');
    if (obj.val().trim() == 'password:' || obj.val().trim() == '') {
        lbl.html('please fill in required fields');
        return false;
    }
    obj = $('#txtbrfEmail');
    if (obj.val().trim() == 'email:') {
        lbl.html('please fill in required fields');
        return false;
    }
    if (lbl.html().trim() != '')
    { return false; }
    lbl = $('#lblBrfEmailError');
    if (lbl.html().trim() != '')
    { return false; }
    return true;
}
function createNewBriefcase() {
    createBriefcase($('#hfBro_uid').val(), $('#txtbrfUsername').val(), $('#txtbrfPassword1').val(), $('#txtbrfCompany').val(), $('#txtbrfEmail').val(), $('#txtbrfName').val());
}

function createBriefcase(bro_uid, username, password, company, email, name) {
    $('#pnlUpdatingBriefcase').show();
    $('#pnlCreateBriefcase').hide();

    $.post('/show/online/login/createBriefcasae', { bro_uid: bro_uid, username: username, password: password, company: company, email: email, name: name }, OnCreateBriefcaseCompleted);

}
function OnCreateBriefcaseCompleted(response, status) {
    var arValues = response.split('|');
    $('#spnFirstLastName').html(arValues[1]);
    $('#hfBro_uid').val(arValues[0]);
    $('#hfIsBro_uid').val(true);
    $('#lblWelcome').show();
    $('#spnAddRemove').hide();
    $('#pnlMenu').fadeIn('slow');
    //alert(response);
    $('#pnlUpdatingBriefcase').hide();
    //Now hide the add/remove button on the default page
    $('#divAddRemove').hide();
    //Show the briefcase
    $('#spnShowBriefcase').show();
    $('#txtUsername').val('username:');
    $('#txtPassword1').val('').hide();
    $('#txtPassword').val('password:').show();

    //alert('created case');
    if (typeof (addToBriefCase) != 'undefined') {
        //alert('adding to case');
        $('#LoginPanel').dialog('close');
        addToBriefCase(m_icom_uid, m_isEvent)
    }

}



function validateUsername() {
    if ($('#txtbrfUsername').val().trim() != 'username:') {
        $('#btnCreateBrfCase').attr('disabled', 'disabled');
        $.post('/show/online/login/validateUsername', { username: $('#txtbrfUsername').val().trim() }, OnValidateUsernameCompleted);
        //$.ajax({ url: '/login/validateUsername', type: 'POST', data: { username: 'josh' }, success: OnValidateUsernameCompleted, error: FailValidateUsername });
    }
}
function OnValidateUsernameCompleted(response, status) {
    if (response == "valid") {
        $('#btnCreateBrfCase').attr('disabled', '');
        $('#lblBrfError').html('');
    } else {
        $('#lblBrfError').html('<br />This username is already in use');
    }
}

function validateLogin() {
    //alert('validateLogin ' + $('#txtUsername').val().trim());
    if ($('#txtUsername').val().trim() != 'username:') {
        $('#pnlUpdatingBriefcase').show();
        $('#pnlCreateBriefcase').hide();
        //$('#pnlUpdatingBriefcase').show();                
        //$('#btnCreateBrfCase').attr('disabled', 'disabled');
        $.post('/show/online/login/CheckPassword', { username: $('#txtUsername').val().trim(), password: $('#txtPassword1').val().trim(), com_uid: 0, isEvent: false }, OnValidateLoginCompleted);
        //$.ajax({ url: '/login/validateUsername', type: 'POST', data: { username: 'josh' }, success: OnValidateUsernameCompleted, error: FailValidateUsername });
    }
}
function OnValidateLoginCompleted(response, status) {
    if (response == "0") {
        //bad credentials
        $('#lblLoginError').html('<br />Username or Password not found');
        $('#pnlUpdatingBriefcase').hide();
        $('#pnlCreateBriefcase').show()

    } else {
        //Logged in let's do some work
        var arValues = response.split('|');
        $('#spnFirstLastName').html(arValues[1]);
        $('#hfBro_uid').val(arValues[0]);
        $('#hfIsBro_uid').val(true);
        $('#lblWelcome').show();
        $('#spnAddRemove').hide();
        $('#pnlMenu').fadeIn('slow');
        //alert(response);
        $('#pnlUpdatingBriefcase').hide();
        //Now hide the add/remove button on the default page
        $('#divAddRemove').hide();
        //Show the briefcase
        $('#spnShowBriefcase').show();
        $('#txtUsername').val('username:');
        $('#txtPassword1').val('').hide();
        $('#txtPassword').val('password:').show();
    }
}


function showForgot() {

    $('#pnlForgot').dialog('open');
}

function hideForgot() {
    $('#pnlForgot').dialog('close');
}

function sendForgotEmail() {
    $.post('/show/online/login/sendReminderEmail', { email: $('#txtForgotEmail').val().trim() }, OnForgotCompleted);
}

function OnForgotCompleted(response, status) {
    var lbl = $('#lblForgot');
    if (response == '0') {
        lbl.html('<br />Unable to find email address.').css('color', 'red');

    } else {
        lbl.html('an email has been sent with your username and password.');
    }
}

function briefcaseLogin() {
    if (m_icom_uid != 0) {
        //alert(m_icom_uid);
    }
    //alert('briefcaselogin');
    $('#pnlUpdatingBriefcase').show();
    $('#pnlLoginRegister').hide();
    $.ajax({
        url: '/show/online/login/CheckPassword',
        type: 'POST', data:
        { username: $('#txtUsername').val().trim(),
            password: $('#txtPassword1').val().trim(),
            com_uid: m_icom_uid,
            isEvent: false
        },
        success: OnBriefcaseLoginComplete,
        error: OnBriefcaseLoginFail
    });



}

function OnBriefcaseLoginComplete(response, status) {
    //split the response
    var arValues = response.split('|');
    //alert(response);
    $('#hfBro_uid').val(arValues[0]);
    $('#hfIsBro_uid').val('true');
    $('#spnFirstLastName').html(arValues[1]);
    $('#lblWelcome').show();
    //make view briefcase show up
    $('#spnShowBriefcase').show();
    //Close our login panel
    $('#LoginPanel').dialog('close');

    //
    $('#txtUsername').val('username:');
    $('#txtPassword').val('password:');

    //Create briefcase info 
    var img;
    var sPrefix;
    var sSuffix;
    var sVal;
    if (m_icom_uid != 0) {
        $('#Img_' + m_icom_uid).attr("src", '/images/showonline/img_Briefcase_Sm.gif');
        $('#A_' + m_icom_uid).attr("href", 'javascript:checkLogin(' + $('#hfBro_uid').val() + ', false);').attr("title", "View Briefcase");
        m_icom_uid = 0;
    }
    for (i = 2; i < arValues.length; i++) {
        sPrefix = arValues[i].substring(0, 1);
        sSuffix = arValues[i].substring(1, arValues[i].length);
        $('#Img_' + sSuffix).attr("src", '/images/showonline/img_Briefcase_Sm.gif');
        $('#A_' + sSuffix).attr("href", 'javascript:checkLogin(' + $('#hfBro_uid').val() + ', false);').attr("title", "View Briefcase");


    }

    if (typeof (DetailBriefcaseSuccess) != 'undefined') {
        //alert('Checking Detailed');
        DetailBriefcaseSuccess(response, status);
    }

    if (typeof (gotoBriefcase) != 'undefined') {
        if (gotoBriefcase == true) {
            window.location = '/show/online/briefcase/?bro_uid=' + $('#hfBro_uid').val();
        }
    }
}
function OnBriefcaseLoginFail(Response, status) {
    //alert("error logging in " + Response.responseText);
}


$.extend({ URLEncode: function(c) {
    var o = ''; var x = 0; c = c.toString(); var r = /(^[a-zA-Z0-9_.]*)/;
    while (x < c.length) {
        var m = r.exec(c.substr(x));
        if (m != null && m.length > 1 && m[1] != '') {
            o += m[1]; x += m[1].length;
        } else {
            if (c[x] == ' ') o += '+'; else {
                var d = c.charCodeAt(x); var h = d.toString(16);
                o += '%' + (h.length < 2 ? '0' : '') + h.toUpperCase();
            } x++;
        } 
    } return o;
},
    URLDecode: function(s) {
        var o = s; var binVal, t; var r = /(%[^%]{2})/;
        while ((m = r.exec(o)) != null && m.length > 1 && m[1] != '') {
            b = parseInt(m[1].substr(1), 16);
            t = String.fromCharCode(b); o = o.replace(m[1], t);
        } return o;
    }
});

//////////////////
/////New Stuff
//////
function selKeyword(ControlName) {
    $('#' + ControlName).select();
    //alert('hi');
}
function checkSearchTerm() {

    var ddl = $('#selSearchType');
    var oControl;
    var iscontinue = true;
    switch (ddl.val()) {

        case 'Keyword':
            oControl = $('#txtKeyword');
            if (oControl.val().trim().length <= 2) {
                alert('You must enter at least 3 characters to search');
                iscontinue = false;
            }
            break;
        case 'Company':
            oControl = $('#txtCompany');
            if (oControl.val().trim().length <= 2) {
                alert('You must enter at least 3 characters to search');
                iscontinue = false;
            }
            break;
        case 'Show Category':
            oControl = $('#selCategories');
            break;
        case 'Product/Index':
            oControl = $('#txtProducts');
            break;
        case 'Brands/Licenses':
            oControl = $('#txtKeyword');
            break;
        case 'Events, Displays & Seminars':
            oControl = $('#txtKeyword');
            break;
        case 'Country':
            oControl = $('#selCountry');
            break;
        case 'US State':
            oControl = $('#selStates');
            break;
        case 'New + Returning Exhibitors':
            oControl = $('#txtKeyword');
            break;
		case 'New Product Showcase':
            oControl = $('#txtKeyword1');
            break;
        default:
            break;
    }
    if (iscontinue == true) {
        $('#SearchValue').val(oControl.val());
        document.body.className = (document.body.className == 'wait') ? '' : 'wait';
        document.documentElement.style.cursor = 'wait';
        window.location = $('#theForm').attr('action') + '?selSearchType=' + $.URLEncode($('#selSearchType').val()) + '&SearchValue=' + $('#SearchValue').val();
        //$('#theForm').attr('action', $('#theForm').attr('action') + '?selSearchType=' + $('#selSearchType').val() + '&SearchValue=' + $('#SearchValue').val()).submit(); 
    }

    return iscontinue;
}


function checkSearchTerm1() {

    var ddl = $('#selSearchType1');
    var oControl;
    var iscontinue = true;
    switch (ddl.val()) {

        case 'Keyword':
            oControl = $('#txtKeyword1');
            if (oControl.val().trim().length <= 2) {
                alert('You must enter at least 3 characters to search');
                iscontinue = false;
            }
            break;
        case 'Company':
            oControl = $('#txtCompany1');
            if (oControl.val().trim().length <= 2) {
                alert('You must enter at least 3 characters to search');
                iscontinue = false;
            }
            break;
        case 'Show Category':
            oControl = $('#selCategories1');
            break;
        case 'Product/Index':
            oControl = $('#txtProducts1');
            break;
        case 'Brands/Licenses':
            oControl = $('#txtKeyword1');
            break;
        case 'Events, Displays & Seminars':
            oControl = $('#txtKeyword1');
            break;
        case 'Country':
            oControl = $('#selCountry1');
            break;
        case 'US State':
            oControl = $('#selStates1');
            break;
        case 'New + Returning Exhibitors':
            oControl = $('#txtKeyword1');
            break;
		case 'New Product Showcase':
            oControl = $('#txtKeyword1');
            break;			
        default:
            break;
    }
    if (iscontinue == true) {
        $('#SearchValue1').val(oControl.val());
        document.body.className = (document.body.className == 'wait') ? '' : 'wait';
        document.documentElement.style.cursor = 'wait';
        window.location = $('#theForm1').attr('action') + '?selSearchType=' + $.URLEncode($('#selSearchType1').val()) + '&SearchValue=' + $('#SearchValue1').val();
        //$('#theForm').attr('action', $('#theForm').attr('action') + '?selSearchType=' + $('#selSearchType').val() + '&SearchValue=' + $('#SearchValue').val()).submit(); 
    }

    return iscontinue;
}




function showSearch() {
    $('#imgClose').attr('src', '/images/showOnline/img_X.gif');
    //$('#pnlMenu').toggle('fast');
    $('#pnlSearch').show('slide', { direction: 'up' }, 500, toggleComplete);
}
function toggleComplete() {
    $('#pnlNewSearch').fadeOut('fast');
}
function hideSearch() {
    $('#pnlSearch').hide('slide', { direction: 'up' }, 500);
    $('#pnlMenu').fadeIn('fast');
    $('#pnlNewSearch').fadeIn('fast');
    return false;
}


function showHide(oControl) {
    if (oControl != null) {
        $('.searches').not(oControl).hide();
        $(oControl).show();
    } else {
        $('.searches').hide();
    }
}

function checkLogin() {
    //alert($('#hfIsBro_uid').val());        
    if ($('#hfIsBro_uid').val().toLowerCase() == 'true') {
        window.location = '/show/online/briefcase/?bro_uid=' + $('#hfBro_uid').val();
    }
    else {
        alert('not a valid briefcase');
    }

}


function setupSearch() {
    //alert('hi');
    var ddl = $('#selSearchType');
    var lblTerm = $('#lblSearchTerm');
    var lblTypeHint = $('#lblSearchTypeHint');
    var lblTermHint = $('#lblSearchTermHint');
    var oControl;

    switch (ddl.val()) {
        case 'Keyword':
            lblTerm.html('Keyword');
            lblTypeHint.html('Keyword Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. When searching keywords, entering ""kni"" instead of ""knives"" or ""knife"" will return results for both products. A search for ""knives"" will not include listings for ""knife.""');
            oControl = $('#txtKeyword');
            showHide(oControl);
            break;
        case 'Company':
            lblTerm.html('Company');
            lblTypeHint.html('Company Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. As you begin to type a company name we will make suggestions for items that match your typed selection. You may pick from the suggestions or keep typing.');
            oControl = $('#txtCompany');
            showHide(oControl);
            break;
        case 'Show Category':
            lblTerm.html('Show Category');
            lblTypeHint.html('Show Category Search Hint:');
            lblTermHint.html('Chose a category from the drop down to see results for all companies associated with the chosen category.');
            oControl = $('#selCategories');
            showHide(oControl);
            break;
        case 'Product/Index':
            lblTerm.html('Product/Index');
            lblTypeHint.html('Product/Index Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. As you begin to type a product or index we will make suggestions for items that match your typed selection. You may pick from the suggestions or keep typing.');
            oControl = $('#txtProducts');
            showHide(oControl);
            break;
        case 'Brands/Licenses':
            lblTerm.html('Brands/Licenses');
            lblTypeHint.html('Brands/Licenses Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. When searching brands/licenses, entering ""kni"" instead of ""knives"" or ""knife"" will return more results.');
            oControl = $('#txtKeyword');
            showHide(oControl);
            break;
        case 'Events, Displays & Seminars':
            lblTerm.html('Events, Displays & Seminars');
            lblTypeHint.html('Events, Displays & Seminars Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. By typing in a word like ""green"" you will see results for any event, display or seminar with ""green"" in the title or description.');
            oControl = $('#txtKeyword');
            showHide(oControl);
            break;
        case 'Country':
            lblTerm.html('Country');
            lblTypeHint.html('Country Search Hint:');
            lblTermHint.html('Please chose a country from the drop down to see the related results.');
            oControl = $('#selCountry');
            showHide(oControl);
            break;
        case 'US State':
            lblTerm.html('US State');
            lblTypeHint.html('US State Search Hint:');
            lblTermHint.html('Please chose a state from the drop down to see the related results.');
            oControl = $('#selStates');
            showHide(oControl);
            break;
        case 'New + Returning Exhibitors':
            lblTerm.html('');
            lblTypeHint.html('New + Returning Exhibitors Hint:');
            lblTermHint.html('This search will give you a list of companies that are new to the 2010 Show or companies that have returned after a brief absence.');
            showHide();
            break;
        case 'New Product Showcase':
            lblTerm.html('');
            lblTypeHint.html('New Product Showcasae:');
            lblTermHint.html('This search will give you a list of companies that have products appearing in the new product showcase.');
            showHide();
            break;

        default:
            break;
    }
}




function setupSearch1() {
    var ddl = $('#selSearchType1');
    var lblTerm = $('#lblSearchTerm1');
    var lblTypeHint = $('#lblSearchTypeHint1');
    var lblTermHint = $('#lblSearchTermHint1');
    var oControl;
    switch (ddl.val()) {
        case 'Keyword':
            lblTerm.html('Keyword');
            lblTypeHint.html('Keyword Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. When searching keywords, entering ""kni"" instead of ""knives"" or ""knife"" will return results for both products. A search for ""knives"" will not include listings for ""knife.""');
            oControl = $('#txtKeyword1');
            showHide1(oControl);
            break;
        case 'Company':
            lblTerm.html('Company');
            lblTypeHint.html('Company Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. As you begin to type a company name we will make suggestions for items that match your typed selection. You may pick from the suggestions or keep typing.');
            oControl = $('#txtCompany1');
            showHide1(oControl);
            break;
        case 'Show Category':
            lblTerm.html('Show Category');
            lblTypeHint.html('Show Category Search Hint:');
            lblTermHint.html('Chose a category from the drop down to see results for all companies associated with the chosen category.');
            oControl = $('#selCategories1');
            showHide1(oControl);
            break;
        case 'Product/Index':
            lblTerm.html('Product/Index');
            lblTypeHint.html('Product/Index Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. As you begin to type a product or index we will make suggestions for items that match your typed selection. You may pick from the suggestions or keep typing.');
            oControl = $('#txtProducts1');
            showHide1(oControl);
            break;
        case 'Brands/Licenses':
            lblTerm.html('Brands/Licenses');
            lblTypeHint.html('Brands/Licenses Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. When searching brands/licenses, entering ""kni"" instead of ""knives"" or ""knife"" will return more results.');
            oControl = $('#txtKeyword1');
            showHide1(oControl);
            break;
        case 'Events, Displays & Seminars':
            lblTerm.html('Events, Displays & Seminars');
            lblTypeHint.html('Events, Displays & Seminars Search Hint:');
            lblTermHint.html('Keep your searches broad for more results. By typing in a word like ""green"" you will see results for any event, display or seminar with ""green"" in the title or description.');
            oControl = $('#txtKeyword1');
            showHide1(oControl);
            break;
        case 'Country':
            lblTerm.html('Country');
            lblTypeHint.html('Country Search Hint:');
            lblTermHint.html('Please chose a country from the drop down to see the related results.');
            oControl = $('#selCountry1');
            showHide1(oControl);
            break;
        case 'US State':
            lblTerm.html('US State');
            lblTypeHint.html('US State Search Hint:');
            lblTermHint.html('Please chose a state from the drop down to see the related results.');
            oControl = $('#selStates1');
            showHide1(oControl);
            break;
        case 'New + Returning Exhibitors':
            lblTerm.html('');
            lblTypeHint.html('New + Returning Exhibitors Hint:');
            lblTermHint.html('This search will give you a list of companies that are new to the 2010 Show or companies that have returned after a brief absence.');
            showHide1();
            break;
        case 'New Product Showcase':
            lblTerm.html('');
            lblTypeHint.html('New Product Showcasae:');
            lblTermHint.html('This search will give you a list of companies that have products appearing in the new product showcase.');
            showHide1();
            break;

        default:
            break;
    }
}

function showHide1(oControl) {
    if (oControl != null) {
        $('.searches1').not(oControl).hide();
        $(oControl).show();
    } else {
        $('.searches1').hide();
    }
}

function checkLogin1() {
    //alert($('#hfIsBro_uid').val());        
    if ($('#hfIsBro_uid1').val().toLowerCase() == 'true') {
        window.location = '/show/online/kioskbriefcase/?bro_uid=' + $('#hfBro_uid1').val();
	}
    else {
        alert('not a valid briefcase');
    }
}
    function briefcaseLogin1() {
        if (m_icom_uid != 0) {
            //alert(m_icom_uid);
        }
        //alert('briefcaselogin');
        $('#pnlUpdatingBriefcase').show();
        $('#pnlLoginRegister').hide();
        $.ajax({
            url: '/show/online/login/CheckPassword',
            type: 'POST', data:
        { username: $('#txtUsername').val().trim(),
            password: $('#txtPassword1').val().trim(),
            com_uid: m_icom_uid,
            isEvent: false
        },
            success: OnBriefcaseLoginComplete1,
            error: OnBriefcaseLoginFail1
        });



    }

    function OnBriefcaseLoginComplete1(response, status) {
        //split the response
        var arValues = response.split('|');
        //alert(response);
        $('#hfBro_uid').val(arValues[0]);
        $('#hfIsBro_uid1').val('true');
		$('#hfBro_uid1').val(arValues[0]);
        $('#hfIsBro_uid').val('true');
        $('#spnFirstLastName').html(arValues[1]);
        $('#lblWelcome').show();
        //make view briefcase show up
        $('#spnShowBriefcase').show();
        //Close our login panel
        $('#LoginPanel').dialog('close');

        //
        $('#txtUsername').val('username:');
        $('#txtPassword').val('password:');
		
		//Show the loggedIn Div
		//Change the loggedIn DIV
        $('#loggedOut').hide();
        $('#loggedIn').show();

        //Create briefcase info 
        var img;
        var sPrefix;
        var sSuffix;
        var sVal;
		$('#deleteCookie').attr('href', 'javascript:deleteCookie1();');
        if (m_icom_uid != 0) {
            $('#Img_' + m_icom_uid).attr("src", '/images/showonline/img_Briefcase_Sm.gif');
            $('#A_' + m_icom_uid).attr("href", 'javascript:checkLogin1(' + $('#hfBro_uid').val() + ', false);').attr("title", "View Briefcase");
            m_icom_uid = 0;
			
        }
        for (i = 2; i < arValues.length; i++) {
            sPrefix = arValues[i].substring(0, 1);
            sSuffix = arValues[i].substring(1, arValues[i].length);
            $('#Img_' + sSuffix).attr("src", '/images/showonline/img_Briefcase_Sm.gif');
            $('#A_' + sSuffix).attr("href", 'javascript:checkLogin1(' + $('#hfBro_uid').val() + ', false);').attr("title", "View Briefcase");


        }

        if (typeof (DetailBriefcaseSuccess) != 'undefined') {
            //alert('Checking Detailed');
            DetailBriefcaseSuccess(response, status);
        }

        if (typeof (gotoBriefcase) != 'undefined') {
            if (gotoBriefcase == true) {
                window.location = '/show/online/kioskbriefcase/?bro_uid=' + $('#hfBro_uid').val();
            }
        }
    }
    function OnBriefcaseLoginFail1(Response, status) {
        //alert("error logging in " + Response.responseText);
    }







function watermarkEnter(obj, svalue) {
    if (obj.value == svalue) {
        obj.value = '';
        obj.style.color = '';
        obj.focus();
    }
}
function watermarkLeave(obj, svalue, sColor) {
    if (obj.value.trim() == '') {
        obj.value = svalue;
        obj.style.color = sColor;
    }
}
function watermarkEnterPassword(obj, spassword1, svalue) {
    if (obj.value == svalue) {
        var opwd = $('#' + spassword1);
        opwd.css('display', '');
        opwd.focus();
        obj.style.display = 'none';
    }
}
function watermarkLeavePassword(obj, spassword, svalue, sColor) {
    if (obj.value.trim() == '') {
        obj.value = '';
        var opwd = $('#' + spassword);
        opwd.css('display', '');
        obj.style.display = 'none';
    }
}



function validateLogin1() {
    //alert('validateLogin ' + $('#txtUsername').val().trim());
    if ($('#txtUsername1').val().trim() != 'username:') {
        $('#pnlUpdatingBriefcase').show();
        $('#pnlCreateBriefcase').hide();
        //$('#pnlUpdatingBriefcase').show();                
        //$('#btnCreateBrfCase').attr('disabled', 'disabled');
        $.post('http://www.housewares.org/show/online/login/CheckPassword', { username: $('#txtUsername1').val().trim(), password: $('#txtPassword4').val().trim(), com_uid: 0, isEvent: false }, OnValidateLoginCompleted1);
        //$.ajax({ url: '/login/validateUsername', type: 'POST', data: { username: 'josh' }, success: OnValidateUsernameCompleted, error: FailValidateUsername });
    }
}
function OnValidateLoginCompleted1(response, status) {
    //alert(response);
    if (response == "0") {
        //bad credentials
        $('#lblLoginError').html('<br />Username or Password not found');
        $('#pnlUpdatingBriefcase').hide();
        $('#pnlCreateBriefcase').show();
		alert('incorrect username/password combination');
		return;
    } else {
        //Logged in let's do some work
        var arValues = response.split('|');
        $('#spnFirstLastName').html(arValues[1]);
        $('#hfBro_uid').val(arValues[0]);
        $('#hfBro_uid1').val(arValues[0]);
        $('#hfIsBro_uid').val(true);
        $('#hfIsBro_uid1').val(true);
        $('#lblWelcome').show();
        $('#spnAddRemove').hide();
        $('#pnlMenu').fadeIn('slow');
        //alert(response);
        $('#pnlUpdatingBriefcase').hide();
        //Now hide the add/remove button on the default page
        $('#divAddRemove').hide();
        //Show the briefcase
        $('#spnShowBriefcase').show();
        $('#txtUsername').val('username:');
        $('#txtPassword1').val('').hide();
        $('#txtPassword').val('password:').show();

        //Change the loggedIn DIV
        $('#loggedOut').hide();
        $('#loggedIn').show();
		$('#loggedinname').html(arValues[1]);
    }
}


function deleteCookie1() {
    $.post('http://www.housewares.org/show/online/login/RemoveCookie', {}, OnDeleteCookieCompleted1);

}
function OnDeleteCookieCompleted1(response, status) {
    $('#hfBro_uid').val(response);
    $('#hfIsBro_uid').val("false");
    $('#hfBro_uid1').val(response);
    $('#hfIsBro_uid1').val("false");


    $('#lblWelcome').hide();
    $('#imgAddRemove').attr('src', 'img_minus.gif');
    $('#spnAddRemove').html('Remove');
    $('#spnShowBriefcase').hide();

    //This exists on the default search page
    $('#LoginPanel').show();
    $('#pnlCreateBriefcase').show();

    window.location = '/show/online/kiosk/';
}


function createNewBriefcase1() {
    createBriefcase1($('#hfBro_uid1').val(), $('#txtbrfUsername').val(), $('#txtbrfPassword1').val(), $('#txtbrfCompany').val(), $('#txtbrfEmail').val(), $('#txtbrfName').val());
}

function createBriefcase1(bro_uid, username, password, company, email, name) {
    $('#pnlUpdatingBriefcase').show();
    $('#pnlCreateBriefcase').hide();
	//alert(bro_uid);
    $.post('http://www.housewares.org/show/online/login/createBriefcasae', { bro_uid: bro_uid, username: username, password: password, company: company, email: email, name: name }, OnCreateBriefcaseCompleted1);

}
function OnCreateBriefcaseCompleted1(response, status) {
	//alert('hi')
    var arValues = response.split('|');
    $('#spnFirstLastName').html(arValues[1]);
    $('#hfBro_uid').val(arValues[0]);
    $('#hfIsBro_uid').val(true);
	///The New Kiosk Stuff
	$('#hfBro_uid1').val(arValues[0]);
    $('#hfIsBro_uid1').val(true);
	$('#loggedOut').hide();
    $('#loggedIn').show();
	$('#LoginPanel').dialog('close');
	$('#loggedinname').html(arValues[1]);
	////////////
    $('#lblWelcome').show();
    $('#spnAddRemove').hide();
    $('#pnlMenu').fadeIn('slow');
    //alert(response);
    $('#pnlUpdatingBriefcase').hide();
    //Now hide the add/remove button on the default page
    $('#divAddRemove').hide();
    //Show the briefcase
    $('#spnShowBriefcase').show();
    $('#txtUsername').val('username:');
    $('#txtPassword1').val('').hide();
    $('#txtPassword').val('password:').show();

    //alert('created case');
    if (typeof (addToBriefCase) != 'undefined') {
        //alert('adding to case');
        $('#LoginPanel').dialog('close');
        addToBriefCase(m_icom_uid, m_isEvent)
    }

}



