﻿var isGoogleSearch = true;
var searchFunc = null;
function checkSearch(e, buttonToClick, textBox) {
    if (isGoogleSearch) 
    {    
        if ($('#' + textBox).val() != '') 
        {
            if (e.keyCode == 13 || e.type == "click") 
            {
                window.location = 'http://www.igluski.com/404search.aspx?searchquery=' + _utf8_encode($('#' + textBox).val());
                return false;
            }
            else 
            {
                return true;
            }
        }
        return true;
    }    
    return false;
}

function redirectSearch(textBox) {
    if (isGoogleSearch) 
    {        
        window.location = 'http://www.igluski.com/404search.aspx?searchquery=' + _utf8_encode($('#' + textBox).val());
        return false;
    }    
    return false
}

//method for UTF-8 encoding
function _utf8_encode(string) {
    string = string.replace(/\r\n/g, "\n");
    var utftext = "";

    for (var n = 0; n < string.length; n++) {

        var c = string.charCodeAt(n);

        if (c < 128) {
            utftext += String.fromCharCode(c);
        }
        else if ((c > 127) && (c < 2048)) {
            utftext += String.fromCharCode((c >> 6) | 192);
            utftext += String.fromCharCode((c & 63) | 128);
        }
        else {
            utftext += String.fromCharCode((c >> 12) | 224);
            utftext += String.fromCharCode(((c >> 6) & 63) | 128);
            utftext += String.fromCharCode((c & 63) | 128);
        }

    }

    return utftext;
}

function searchPostBackSuppressGoogle(e, buttonToClick, func) {
    if (e.keyCode == 13) {
        isGoogleSearch = false;
        searchFunc = func;
        searchFunc();
        return false;
    }
}

