

function trimObjValue(id, removeDollarSign)
{
    var obj = document.getElementById(id);
    if (obj.value != null && obj.value.length > 0)
    {
        if (removeDollarSign == null || removeDollarSign != false)
        {
            obj.value = trimString(obj.value).replace(/\$/g,"");
        }
    }
}
function isObjValueNullOrEmpty(id)
{
    var obj = document.getElementById(id);
    if (obj.value == null || obj.value.length < 1)
    {
        return true;
    }       
    return false;
}
function requireObjValue(labelId, objId, labelQualifier, removeDollarSign)
{
    var q = labelQualifier == null ? "" : labelQualifier;
    document.getElementById(labelId).className = "label" + q;
    document.getElementById(labelId).title = "";
    trimObjValue(objId, removeDollarSign);
    if (isObjValueNullOrEmpty(objId))
    {
        document.getElementById(labelId).className = "label" + q  + "Error";
        document.getElementById(labelId).title = "This field is required.";
        return false;
    }
    return true;
}
function isObjValueEmail(labelId, objId, labelQualifier)
{
    var q = labelQualifier == null ? "" : labelQualifier;
    document.getElementById(labelId).className = "label" + q;
    document.getElementById(labelId).title = "";
    trimObjValue(objId);
    if ( !isObjValueNullOrEmpty(objId) && !isEmail( document.getElementById(objId).value) )
    {
        document.getElementById(labelId).className = "label" + q  + "Error";
        document.getElementById(labelId).title = "Please enter a valid email address.";
        return false;
    }
    return true;
}
function requireObjListValue(labelId, objName, labelQualifier, mustContain)
{
    var q = labelQualifier == null ? "" : labelQualifier;
    document.getElementById(labelId).className = "label" + q;
    document.getElementById(labelId).title = "";

    var objList = document.getElementsByName(objName);
    var v = 0;
    var values = new Array();
    for (i = 0; i < objList.length; i++)
    {
        if (objList[i].checked)
        {
            values[v] = objList[i].value;
            v++;
        }
    }
    
    var invalid = values.length < 1;
    if (!invalid && mustContain != null)
    {
        invalid = true;
        for (i = 0; i < values.length; i++)
        {
            if (values[i] == mustContain)
            {
                invalid = false;
                break;
            }
        }    
    }    

    if (invalid)
    {
        document.getElementById(labelId).className = "label" + q  + "Error";
        document.getElementById(labelId).title = "This field is required.";
    }
    return values;
}


var mouseX;
var mouseY;

function getMousePos(e) 
{
    if (document.all) 
    {
        mouseX = event.clientX;
        mouseY = event.clientY + document.documentElement.scrollTop;
    }
    else
    {
        mouseX = e.pageX;
        mouseY = e.pageY;
    }
} 

function doMouseCapture()
{
    if (window.captureEvents) 
    {
        window.captureEvents(Event.MOUSEMOVE);
        window.onmousemove = getMousePos;
    }
    else
    {
        document.onmousemove = getMousePos;
    }
}

function playWebcast(frameId, playerLocation, hiddenItemId, hiddenImgId, itemId, imgId, shareLinkId)
{
    var thisItem = document.getElementById(itemId);
    var thisImg = document.getElementById(imgId);
    
    var hiddenItem = document.getElementById(hiddenItemId);
    var hiddenImg  = document.getElementById(hiddenImgId);
    
    var frame = document.getElementById(frameId);
    frame.src = playerLocation + '?frameId=' + frameId + '&startCover=0&id=' + thisItem.attributes['webcastId'].value;
    document.getElementById(shareLinkId).href = thisItem.attributes['shareLink'].value;
    
    var temp = thisItem.attributes['webcastId'].value;
    thisItem.attributes['webcastId'].value = hiddenItem.attributes['webcastId'].value;
    hiddenItem.attributes['webcastId'].value = temp; 
    
    temp = thisImg.src; 
    thisImg.src = hiddenImg.src; 
    hiddenImg.src = temp; 
    
    temp = thisItem.attributes['title'].value; 
    thisItem.attributes['title'].value = hiddenItem.attributes['title'].value; 
    hiddenItem.attributes['title'].value = temp;  
    
    temp = thisItem.attributes['shareLink'].value; 
    thisItem.attributes['shareLink'].value = hiddenItem.attributes['shareLink'].value; 
    hiddenItem.attributes['shareLink'].value = temp;  
}



function LinkSectionBrowserHover(thisDiv, mouseOver)
{
    var divs = thisDiv.getElementsByTagName('div');
    var title = divs[0];
    var img = divs[1].getElementsByTagName('img')[0];
    var imgSrc = img.src;
    var split = imgSrc.split('/');
    var path = '';
    for (i = 0; i < (split.length - 1); i++) 
    {
        path += split[i];
        path += '/';
    }
    var filename = split[(split.length - 1)];
    if (mouseOver) 
    {
        title.className = 'LinkSectionBrowserTitle_hvr';
        if ((filename == 'expand.gif')) 
        {
            img.src = path + 'expand_hvr.gif';
        }
        else 
        {
            img.src = path + 'collapse_hvr.gif';
        }
    }
    else 
    {
        title.className = 'LinkSectionBrowserTitle';
        if ((filename == 'expand_hvr.gif')) 
        {
            img.src = path + 'expand.gif';
        }
        else 
        {
            img.src = path + 'collapse.gif';
        }
    }
}
function GetLinkSectionBrowserContents(container)
{
    var divs = container.getElementsByTagName('div');
    var LinkSectionBrowserContents = new Array();
    for (i = 0; i < divs.length; i++)
    {
        if (divs[i].className == 'LinkSectionBrowserContent')
        {
            LinkSectionBrowserContents[LinkSectionBrowserContents.length] = divs[i];
        }
    }  
    return LinkSectionBrowserContents;
}
function GetLinkSectionBrowserImages(container)
{
    var images = container.getElementsByTagName('img');
    var LinkSectionBrowserImages = new Array();
    for (i = 0; i < images.length; i++)
    {
        if (images[i].attributes["lsb"] != null)
        {
            LinkSectionBrowserImages[LinkSectionBrowserImages.length] = images[i];
        }
    }    
    return LinkSectionBrowserImages;
}
function LinkSectionBrowserClick(divContainerId, index) 
{
    var container = document.getElementById(divContainerId);
    var LinkSectionBrowserContents = GetLinkSectionBrowserContents(container);
    var LinkSectionBrowserImages = GetLinkSectionBrowserImages(container);

    var img = LinkSectionBrowserImages[index];
    var imgSrc = img.src;
    var split = imgSrc.split('/');
    var path = '';
    for (i = 0; i < (split.length - 1); i++) 
    {
        path += split[i];
        path += '/';
    }
    
    var filename = split[(split.length - 1)];
    var content = LinkSectionBrowserContents[index];
    
    if (content.style.display == 'none') 
    {
        img.src = path + 'collapse_hvr.gif';
        content.style.display = 'block';
    }
    else 
    {
        img.src = path + 'expand_hvr.gif';
        content.style.display = 'none';
    }
}
function LinkSectionBrowserCollapseAll(divContainerId, thisIdx) 
{
    var container = document.getElementById(divContainerId);
    var LinkSectionBrowserContents = GetLinkSectionBrowserContents(container);
    var LinkSectionBrowserImages = GetLinkSectionBrowserImages(container); 
    
    for (index = 0; index < LinkSectionBrowserContents.length; index++) 
    {
        if (index == thisIdx) 
        {
            continue;
        }
        var content = LinkSectionBrowserContents[index];
        content.style.display = 'none';
        var img = LinkSectionBrowserImages[index];
        var imgSrc = img.src;
        var split = imgSrc.split('/');
        var path = '';
        for (i = 0; i < (split.length - 1); i++) 
        {
            path += split[i];
            path += '/';
        }
        var filename = split[(split.length - 1)];
        img.src = path + 'expand.gif';
    }
}


function getQueryVariable(variable) 
{
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0; i < vars.length; i++) 
    {
        var pair = vars[i].split("=");
        if (pair[0] == variable) 
        {
            return pair[1];
        }
    } 
    return null;
}
function setCookie(c_name, value, expiredays)
{
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + expiredays);
    document.cookie = c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires=" + exdate.toGMTString() +";path=/" );
}
function getCookie(c_name)
{
    if (document.cookie.length > 0)
    {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1)
        { 
            c_start = c_start + c_name.length + 1; 
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) c_end = document.cookie.length;
            return unescape(document.cookie.substring(c_start, c_end));
        } 
    }
    return "";
}

function isEmail(src) 
{
    var regex = /^[a-zA-Z0-9._-]+@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;
    return regex.test(src);
}
function trimString(str) 
{
	var	str = str.replace(/^\s\s*/, ''), ws = /\s/, i = str.length; 
	while (ws.test(str.charAt(--i)));
	return str.slice(0, i + 1);
}

function reSortTable(id)
{
    var table = document.getElementById(id);
    var row = table.getElementsByTagName("tr");
    var numCols = 0;
    var list = new Array();
    var i = 0;
    var tr = null;
    var col = null;
    var td = null;
    for (r = 0; r < row.length; r++)
    {
        tr = row[r];
        col = tr.getElementsByTagName("td");  
        if (r == 0)
        {
            numCols = col.length;     
        }
        for (c = 0; c < col.length; c++)
        {
            td = col[c];
            list[i] = td.innerHTML;
            i++;
        }
    }
    i = 0;
    for (c = 0; c < numCols; c++)
    {
        for (r = 0; r < row.length; r++)
        {
            tr = row[r];
            col = tr.getElementsByTagName("td");  
            td = col[c];
            if (td != null)
            {
                td.innerHTML = list[i];
                i++;
            }
        }
    }
}

// page should be specified WITHOUT the relative app root e.g. "Folder1/Folder2/PageName.aspx"
function resolveUrl(page)
{
    var href = location.href;
    var root = "http://www.sonicfoundry.com/";
    if (href.indexOf(root) != 0)
    {
        root = "http://www.sonicfoundry.com/";
    }
    return root + page;
}
function ajax(page, data, tbResponse)
{
    doAsynchPostBack(page, data, tbResponse);
}
function doAsynchPostBack(page, data, tbResponse)
{
    var err;
    var url = resolveUrl(page);
    var req = null;
    if (window.XMLHttpRequest)
    {
        req = new XMLHttpRequest();
    }
    else
    {
        req = new ActiveXObject("MSXML2.XMLHTTP.3.0");
    }
    req.onreadystatechange = function() 
    { 
        if (tbResponse != null)                
        {
            try
            {
                if (req.status && req.status == 200)
                {
                    tbResponse.value = trimString(req.responseText);
                }
                else
                {
                    tbResponse.value = "$ERROR=";
                    try
                    {
                        tbResponse.value += req.status;
                    }
                    catch (err)
                    {
                        tbResponse.value += err;
                    }
                }
            }
            catch (err)
            {
            }
        }       
    }; 
    req.open("POST", url, true);
    req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); 
    if (data == null)
    {
        data = "";
    }
    req.send(data);
}

function findElementByTagAndId(tag, id)
{
    var objs = document.getElementsByTagName("div");
    for (i = 0; i < objs.length; i++)
    {
        if (objs[i].id.indexOf(id) > 0)
        {
            return objs[i];
        }
    }
    return null;
}

function findElementById(parentNode, id)
{
    for (i = 0; i < parentNode.childNodes.length; i++)
    {
        var thisId = parentNode.childNodes[i].id;
        if (thisId != null && thisId.indexOf(id) > 0)
        {
            return parentNode.childNodes[i];
        }
    }   
    return null; 
}

function Optionlist_Sort(optionlist) 
{
    var lb = optionlist;
    arrTexts = new Array();

    for (i = 0; i < lb.length; i++) 
    {
        arrTexts[i] = lb.options[i].text+':'+lb.options[i].value;
    }
    arrTexts.sort();
    for (i = 0; i < lb.length; i++) 
    {
        el = arrTexts[i].split(':');
        lb.options[i].text = el[0];
        lb.options[i].value = el[1];
    }
}
var playerwin = null;
function popWin(url,WinName, w, h, r, s) 
{
	var widthString  = ",width=" + w;	
	var heightString = ",height=" +h;
	
	//window.newWin.close();
		if (playerwin && !playerwin.closed) 
		{
			playerwin.location = url;
		} 
		else 
		{
			var args = "toolbar=no,location=no,directories=no,status=yes,menubar=no,titlebar=yes, dependent=no," + heightString + widthString;
			args = args + ",resizable=" + r;
			args = args + ",scrollbars=" + s;
			playerwin = window.open("",WinName,args);
			playerwin.moveTo(0, 17);
			playerwin.location = url;
		}
		
	
} 

var autoSuggestSlots = 10;
var autoSuggestIdx = -1;
function autoSuggest(display)
{
    document.getElementById("searchBoxAutoSuggest").className = display ? "autoSuggest" : "hideItem";
    autoSuggestIdx = display ? 0 : -1;
    for (i = 1; i <= autoSuggestSlots; i++)
    {
        document.getElementById("as" + i).className = "";
    }
    if (false)
    {
        try
        {
            document.getElementById("ctl00_menu_divMenu").className = display ? "hideItem" : "menu";
        }
        catch (e) 
        {
        }
    }
}
function asClick(slot)
{
    if (slot.innerHTML.length > 0)
    {
        for (i = 1; i <= autoSuggestSlots; i++)
        {
            document.getElementById("as" + i).className = "";
        }
        slot.className = "selected";
        var q = slot.innerHTML;
        document.getElementById("searchBox").value = q;
        
        document.getElementById("searchBoxEncoded").value = "";
        ajax("WebControls/js/ajax.aspx?call=urlencode", q, document.getElementById("searchBoxEncoded"));
        setTimeout("searchBoxRedirect()", 50);
    }
}
function searchBoxFocus(box)
{
    box.value = "";
    autoSuggest(false);
}
function searchBoxKeyUp(box, event)
{
    // get query
    var q = box.value;
    q = q.replace(/^\s+|\s+$/g, ""); 
    q = q.replace(/\’/g, "'");
    q = q.replace(/\+/g, "");
    q = trimString(q);

    var iKeyCode = event == null ? 13 : event.keyCode;
    if (iKeyCode == 13) 
    {
        // enter key
        if (q.length > 0)
        {
            document.getElementById("searchBoxEncoded").value = "";
            ajax("WebControls/js/ajax.aspx?call=urlencode", q, document.getElementById("searchBoxEncoded"));
            setTimeout("searchBoxRedirect()", 50);
        }
        else
        {
            box.value = "";
            autoSuggest(false);
        }
    }
    else if (iKeyCode == 38 || iKeyCode == 40)
    {
        // navigate suggestions with up & down arrows
        var dir = iKeyCode == 38 ? -1 : 1;
        autoSuggestIdx += dir;
        if (autoSuggestIdx < 1)
        {
            autoSuggestIdx = 1;
        }
        if (autoSuggestIdx > autoSuggestSlots)
        {
            autoSuggestIdx = autoSuggestSlots;
        }
        while (document.getElementById("as" + autoSuggestIdx).innerHTML.length == 0)
        {
            if (--autoSuggestIdx < 1) break;
        }
        for (i = 1; i <= autoSuggestSlots; i++)
        {
            var slot = document.getElementById("as" + i);
            slot.className = "";
            if (i == autoSuggestIdx)
            {
                slot.className = "selected";
                box.value = slot.innerHTML;
            }
        }
    }
    else
    {
        // refresh auto suggest
        if (q.length > 0)
        {
            document.getElementById("searchBoxSuggestions").value = "";
            ajax("WebControls//js/ajax.aspx?call=search-suggest", q, document.getElementById("searchBoxSuggestions"));
            setTimeout("searchBoxSuggestionResponse()", 50);
        }
        else
        {
            autoSuggest(false);
        }        
    }
}
function searchBoxRedirect()
{
    var value = document.getElementById("searchBoxEncoded").value;
    if (value == null || value.length < 1)
    {
        setTimeout("searchBoxRedirect", 50);
        return;
    }
    else
    {
        var value = value.split("’")[0];
        window.location = "/support/WebControls/search.aspx?q=" + value;
    }
}
function searchBoxSuggestionResponse()
{
    var value = document.getElementById("searchBoxSuggestions").value;   
    if (value == null || value.length < 1)
    {
        setTimeout("searchBoxSuggestionResponse", 50);
        return;
    }
    else
    {
        for (i = 1; i <= autoSuggestSlots; i++)
        {
            document.getElementById("as" + i).innerHTML = "";
        }
        var suggestion = value.split("’");       
        var count = 0;
        for (i = 0; i < suggestion.length; i++)
        {
            if (i == autoSuggestSlots)
            {    
                break;
            }
            else
            {
                count++;
                document.getElementById("as" + (i + 1)).innerHTML = suggestion[i];
            }
        }       
        autoSuggest(count > 0);
    }
}


function GetElementById (id) { var el = document.getElementById(id); return el;  }  function OptionList_Add (OptionList, OptionText, OptionValue) { OptionList[OptionList.length] = new Option(OptionText, OptionValue); return false;  }  function OptionList_Clear (OptionList) { for (i = OptionList.length - 1; i >= 0; i--) {  OptionList_Delete(OptionList, i);  }  return false;  }  function OptionList_Delete (OptionList, Index) { if (OptionList.length > 0) { OptionList[Index] = null;  }   }  function OptionList_SelectAll (OptionList) { for (i = 0; i < OptionList.length; i++) {  OptionList[i].selected = true;  }  return false;  }  function OptionList_RemoveSelected (OptionList, DelimitTextBox) { for (i = OptionList.length - 1; i >= 0; i--) {  if (OptionList[i].selected) { OptionList_Delete(OptionList, i);  }   }  OptionList_DelimitToTextBox(OptionList, DelimitTextBox); return false;  }  function OptionList_Move (OptionListFrom, OptionListTo, SortOrder, DelimitList, DelimitTextBox) { var selOpts = new Array(); var selCount = 0; for (i = OptionListFrom.length - 1; i >= 0; i--) {  if (OptionListFrom[i].selected) { selOpts[selCount] = new Option(OptionListFrom[i].text, OptionListFrom[i].value); selCount++; OptionList_Delete(OptionListFrom, i);  }   }  for (i = selCount - 1; i >= 0; i--) {  OptionList_Add(OptionListTo, selOpts[i].text, selOpts[i].value);  }  if (SortOrder != null) { selOpts = new Array(); selCount = 0; for (sort = 0; sort < SortOrder.length; sort++) {  for (i = 0; i < OptionListTo.length; i++) {  if (SortOrder[sort] == OptionListTo[i].value) { selOpts[selCount] = new Option(OptionListTo[i].text, OptionListTo[i].value); selCount++; break;  }   }   }  OptionList_Clear(OptionListTo); for (i = 0; i < selOpts.length; i++) {  OptionList_Add(OptionListTo, selOpts[i].text, selOpts[i].value);  }   }  OptionList_DelimitToTextBox(DelimitList, DelimitTextBox);  try { filterContentType(document.getElementById('ddFilterContentType').value); } catch (e) {}  return false;  }  function OptionList_DelimitToTextBox (OptionList, TextBox) { var selValues = ''; for (i = 0; i < OptionList.length; i++) {  selValues += OptionList[i].value; if (i + 1 < OptionList.length) { selValues += ';';  }   }  TextBox.value = selValues  }  function GetDelimitedValues (text, delimiter) { var split = text.split(delimiter); return split;  }  