var searchBoxEmpty = 1;
var defaultSearchBoxText = 'Type to search';

$(function () {
	$("input.searchBoxTop").focus(function() {
		var windowWidth = $(window).width();

		if (windowWidth > 1100) windowWidth = 1100;
		if (windowWidth > 1000) {
		    var searchBoxWidth = 360 - (1150 - windowWidth);
		    $(this).width(searchBoxWidth + 'px');
		}
		if (searchBoxEmpty || $(this).val() == defaultSearchBoxText) {
			$(this).val('');
			$(this).css('color', '#000000');
		}
	});

	$("input.searchBoxTop").blur(function() {
		if ($(this).val() == '') {
			$(this).val(defaultSearchBoxText);
			searchBoxEmpty = 1;
			$(this).css('color', '#999999');
			$(this).width('194px');
		} else {
			searchBoxEmpty = 0;
		}
	});
});


$(document).ready(function(){
	$("input.searchBoxTop").val(defaultSearchBoxText);
	
});

    function showChatCountryUnlogged(countryName) {
	$('#login-panel-outer').hide();
	$('#chatlocation').show();

	if (countryCode != '--')
	    $('#chatcountry').val(countryName);
    }


    function startChatSession() {
        var countryname = $('#chatcountry').val();
        var statename = $('#chatstate').val();
        if (countryname == null) return;

        $.ajax({
            type: 'GET',
            url: '/ws/client.asmx/GetCustomerRegion?CountryName=' + countryname + '&StateName=' + statename,
            dataType: 'xml',
            success: function(xml) {
                if (xml != null) {

                var data = $(xml).find('string').text();
                    
                    if (data == "") return;
                    
                    var parts = data.split(',');
                    if (parts.length == 2) {
                        var siteId = parts[0];
                        var queueId = parts[1];

                        var e = window.open('/SightMaxAgentInterface/PreChatSurvey.aspx?accountID=1&siteID=' + siteId + '&queueID=' + queueId + '&skipSurvey=no&autoSubmit=true',
		                    'chatWindow',
		                    'width=380,height=516,resizable=0,scrollbars=no,menubar=no,status=no');
                    }
                }
            }
        });
    }


    function stopEvent(e) {
        if (e.stopPropagation) e.stopPropagation();
        else e.cancelBubble = true;

        if (e.preventDefault) e.preventDefault();
        else e.returnValue = false;
    }

