﻿/*
Name:			common_functions.js
Author:			Kevin Mauer
Created:		11/22/2006
Description:	Contains common javascript functions used on every page.
*/




function SubmitSearch(keywords) { 
     //var activeForm = document.getElementById('aspnetForm');
     var activeForm = document.forms[0]
     if (typeof activeForm.__ekSearchPost == "object") {
         activeForm.__ekSearchPost.value = "1"
         activeForm.ecmBasicKeywords.value = keywords
         activeForm.action = '/search.aspx';
         activeForm.submit();
         //return false;
     }
 }

function checkEnter(e) {
    var charCode="";
    if (e && e.which) {
        e = e;
        charCode = e.which;
    } else {
        e = event;
        charCode = e.keyCode;
    }
    
    if (charCode == "13") {
        return(true);
    } else {
        return(false);
    }
}

function do_searchPostback2(txtBoxId) {
    var SearchText = document.getElementById(txtBoxId).value;
    var url = "/search.aspx?searchtext=" + urlEncode(SearchText) + "&type=all&sort=rank";
    window.location = url;
}

function do_searchPostbackOnEnter2(txtBoxId,enterDetected) {
    if (enterDetected) {
        var SearchText = document.getElementById(txtBoxId).value;
        var url = "/search.aspx?searchtext=" + urlEncode(SearchText) + "&type=all&sort=rank";
        window.location = url;
        return(false);
    }
}

function do_searchPostback(txtBoxId, searchTypeId, searchSortId) {
    var SearchText = document.getElementById(txtBoxId).value;
    var searchType = document.getElementById(searchTypeId).options[document.getElementById(searchTypeId).selectedIndex].value;
    var searchSort  = "";
    for (i=0; i < 2; i++) {
        if (document.getElementById(searchSortId + "_" + i).checked) {
            searchSort = document.getElementById(searchSortId + "_" + i).value;
        }
    }
    var url = "/search.aspx?searchtext=" + urlEncode(SearchText) + "&type=" + searchType + "&sort=" + searchSort;
    window.location = url;
}

function do_searchPostbackOnEnter(txtBoxId, searchTypeId, searchSortId,enterDetected) {
    if (enterDetected) {
        var SearchText = document.getElementById(txtBoxId).value;
        var searchType = document.getElementById(searchTypeId).options[document.getElementById(searchTypeId).selectedIndex].value;
        var searchSort  = "";
        for (i=0; i < 2; i++) {
            if (document.getElementById(searchSortId + "_" + i).checked) {
                searchSort = document.getElementById(searchSortId + "_" + i).value;
            }
        }
        var url = "/search.aspx?searchtext=" + urlEncode(SearchText) + "&type=" + searchType + "&sort=" + searchSort;
        window.location = url;
        return(false);
    }
}

function do_searchFromLink(SearchText) {
    window.location = "/search.aspx?searchtext=" + urlEncode(SearchText);
}
 
function urlEncode(str) {
    var result = "";
        for (i=0; i < str.length; i++) {
            if (str.charAt(i) == " ") {
                result += "+";
            } else {
                result += str.charAt(i);
            }
        }
        return(escape(result));
    }
    
function urlEncode2(str) {
    var result = "";
        for (i=0; i < str.length; i++) {
            if (str.charAt(i) == " ") {
                result += "%20";
            } else {
                result += str.charAt(i);
            }
        }
        return(escape(result));
    }

function urlDecode(str) {
    var result = str.replace(/\+/g, " ");
    
    /*
    for (i = 0; i < str.length; i++) {
        if (str.charAt(iu) == "+") {
            result += " ";
        } else {
            result += str.charAt(i);
        }
    }
    */
    
    return(unescape(result));
}

function showhide( divId1) {
    var mydiv = document.getElementById( divId1 );
    if ( mydiv.style.display == 'block' ) {
        mydiv.style.display = 'none';
    } else {
        mydiv.style.display = 'block';
    }
}

function showhideExpandCollapse( divId1,aId) {
    var mydiv = document.getElementById( divId1 );
    var myA = document.getElementById( aId );
    if ( mydiv.style.display == 'block' ) {
        mydiv.style.display = 'none';
    } else {
        mydiv.style.display = 'block';
    }

    if (myA.innerHTML =='Expand&nbsp;Profile'){
    myA.innerHTML ='Collapse&nbsp;Profile'
    }
    else{
    myA.innerHTML ='Expand&nbsp;Profile'
    }
}