function submitSearch() {
    var searchTypeField = document.getElementById("searchType");
    var searchTextField = document.getElementById("searchText");
    
    if(searchTypeField != null && searchTextField != null) {
        if(searchTypeField.value == "web") {
        window.location.href = "http://search.yahoo.com/search?fr=yscpb&p=" + searchTextField.value;
        }
        else {
        window.location.href = "/search/?keywords=" + searchTextField.value;
        }
    }
    else {
    if(searchTypeField == null) {
        alert("submitSearch error: searchType field is undefined");
    }
    else {
        alert("submitSearch error: searchTextField field is undefined");
    }
    }
}

// Opens a new browser window and writes HTML to display
function showPopupWithDynamicContent(winName, winWidth, winHeight, pageTitle, pageCss, pageBody) {
            
    // specify window parameters
    win = window.open("", winName, "width=" + winWidth + ", height=" + winHeight + ", status, scrollbars, resizable");

    // wrote content to window
    win.document.write('<html><head><title>' + pageTitle + '</title><link href="' + pageCss + '" rel="Stylesheet"/></head>');  
    win.document.write('<body>' + pageBody + '</body>');
    win.document.write('</body></html>');
    win.document.close();    
    
    // If we are on NetScape, we can bring the window to the front
    if (navigator.appName.substring(0,8) == "Netscape") win.focus();
 }
 
 function openWindow(url, winName, attributes) 
 {
    window.open(url, winName, attributes);
 }

function createCookie(name,value,days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime()+(days*24*60*60*1000));
        var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function eraseCookie(name) {
    createCookie(name,"",-1);
}
/***************************************************************************************************/
// truncate string, pass string and number of characters to be displayed before appending ellipsis;
// intended for simple client side strings (usernames, etc.) does not account for sentences, spaces;
// do not user for server side purposes! use "Create Shortened String" template
// Example: "CheeseHead4Life" becomes "CheeseH..."
function stringTruncate(stringobj,lengthobj)
{
    // string to truncate
    if (!stringobj) return ("");
    var gotstring = stringobj;

    // number of characters to be displayed before appending ellipsis
    var gotlength = lengthobj;

    // default number of characters if none specified
    if (!gotlength)
    {
        gotlength = 10;
    }

    return ((gotlength) < gotstring.length?(gotstring.slice(0,gotlength) + "&hellip;"):gotstring);
} // end of stringTruncate()
/****************************************************************************************************/

function shortenText(text, length)
{
    var ellipsis = '...';

    // if text length does not exceed limit then return text as is 
    if (text.length <= length) return text; 

    // convert text string
    for (var i = length-1; text.charAt(i) != ' '; i--) {
        length--;
    }

    return text.substr(0, length) + ellipsis;
}

function removeBreakes(text)
{
    var br_re = /<\s*br\s*\/?\s*>/ig;
    var result = text.replace(br_re, " ");
    result = trim(result);

    return result;
}

function trim(text) {
    var result = text.replace(/^\s*/, "").replace(/\s*$/, ""); 
    result = result.replace(/\s{2,}/, " ");
     
    return result;
} 
