﻿/* The following js files were combined into this script file:
search_results.js
savedsearches.js
reorder.js
TreeViewHack.js
OneUpText.js
oneup_behavior.js
oneup.js
MultiBox.js
message.js
MediaButton.js
managesearches.js
keyword.js
iframe_set.js
fixtures.js
exchangeUtils.js
*/

var lmt = null;

function BreadCrumbkwdsearch(keyword, sequence, displayname) {
    var l = 'Portal.aspx?_st=k&_k=' + keyword + '&_chk=on&bd=true&sequence=' + sequence + '&displayname=' + displayname;
    document.location = l;
    return (false);
}

function searchOnEnter(evt) {
    resetTimer();
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3)
        return (KeywordSearch());
    else
        return (true);
}

function PageNumOnEnter(ctrl, evt, num_pages) {
    if (isNaN(ctrl.value)) {
        return false;
    }
    if (ctrl.value < 1 || ctrl.value > num_pages) {
        return false;
    }

    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
    if (charCode == 13 || charCode == 3) {
        return (true);
    }
    else
        return (false);
}

var ls = null;
var lsi = null;
function shwPg(pt, mt) {
    var CURRENT_SEARCH = 6;
    lmt = (mt.length > 0 ? mt : lmt);
    search((ls == null) ? '' : lsi, (ls == null) ? CURRENT_SEARCH : ls, pt, lmt);
}
function similar(id) {
    var SIMILAR_SEARCH = 5;
    var mt = 'Text';
    var pt = 'First';

    ls = SIMILAR_SEARCH;
    lsi = id;
    search(id, SIMILAR_SEARCH, pt, mt);
}

function search(item, st, pt, mt) {
    resetTimer();
    el = document.getElementById('_' + mt);

    if (el == null)
        return;

    try {
        AjaxUtil.Search(item, st, pt, mt, getStart(mt), getEnd(mt), ajax_cb, el);
        var ani = document.getElementById('_ani' + mt);
        if (ani != null)
            ani.style.display = 'block';
    }

    catch (e) { return (false); }

}
function ajax_cb(response) {
    if (response.value == null)
        return;

    response.context.innerHTML = response.value;
    try {
        AP.ToolTip_OnLoad(null, response.context);

        switch (response.context.id) {
            case '_Text':
                viewState();
                attachBehavior();
                break;
            case '_Graphic':
                FixGraphics();
                break;
            case '_Photo':
                FixPhotos();
                break;
        }

        resetTimer();
    }
    catch (e) { }
}

function getStart(mt) {
    var s = document.getElementById('_start' + mt);
    if (s != null) {
        if (s.value.length == 0)
            return 0;
        else
            return (s.value);
    }
}

function getEnd(mt) {
    var s = document.getElementById('_end' + mt);
    if (s != null) {
        if (s.value.length == 0)
            return 0;
        else
            return (s.value);
    }
}
function reload() {
    document.location = document.location;
    return (false);
}

var timeoutID = -1;  // default
var newlimit = null;

function autoRefresh() {
    try {
        if ((!document.images) || typeof (parselimit) == "undefined" || parselimit == null)
            return;
    }
    catch (e) { return; }

    if (newlimit == 1) {
        reload();
        newlimit = parselimit;
    }

    if (newlimit == null)
        newlimit = parselimit;

    if (timeoutID != -1)
        clearTimeout(timeoutID);

    newlimit -= 1;
    timeoutID = setTimeout("autoRefresh()", 1000);
}

function doOnLoad() {
    autoRefresh();
}

function resetTimer() {
    try {
        if (typeof (parselimit) != "undefined" && parselimit != null) {
            newlimit = parselimit;
        }
    }
    catch (e) { return; }

}

function SetFullEAPSearch(content) {
    var url = "AdvancedSearch.aspx?origin=" + content;
    var chkPressReleases = document.getElementById("_prl");
    if (chkPressReleases.checked) {

        url = url + "&_prl=2";
    }
    var chkMyLocalCompany = document.getElementById("_pmlc");
    if (chkMyLocalCompany.checked) {

        url = url + "&_pmlc=2";
    }
    var chkPhotoArchive = document.getElementById("_ppa");
    if (chkPhotoArchive.checked) {

        url = url + "&_ppa=2";
    }
    document.location = url;
}

function checkAction(act) {
    // alert(act);
    ok = 0;
    for (var i = 0; i < document.forms[0].elements.length; i++) {
        e = document.forms[0].elements[i];
        if (e.type == 'checkbox' && e.name.indexOf('cbSelect') != -1 && e.checked) {
            ok = 1;
            break;
        }
    }
    if (!ok) {
        alert("No searches selected!");
        return false;
    }
    if (act == 'delete') {
        if (!confirm("Are you sure you want to delete the selected searches?")) {
            return false;
        }
    }
    return true;
}

function Reorder(ctrl, idx, eSelect, iCurrentField, numSelects) {
    var fldName;
    var fldNo;
    var eForm = eSelect.form;
    var iNewOrder = eSelect.selectedIndex + 1;
    var iPrevOrder;
    var positions = new Array(numSelects);
    var ix;
    for (ix = 0; ix < numSelects; ix++) {
        positions[ix] = 0;
    }
    for (ix = 0; ix < numSelects; ix++) {
        fldno = ix + 1;
        if (fldno > 0 && fldno < 10)
            fldno = "0" + fldno;
        fldName = ctrl + "_ctl" + fldno + "_ddlReorder";
        positions[eSelect.form[fldName].selectedIndex] = 1;
    }
    for (ix = 0; ix < numSelects; ix++) {
        if (positions[ix] == 0) {
            iPrevOrder = ix + 1;
            break;
        }
    }
    if (iNewOrder != iPrevOrder) {
        var iInc = iNewOrder > iPrevOrder ? -1 : 1
        var iMin = Math.min(iNewOrder, iPrevOrder);
        var iMax = Math.max(iNewOrder, iPrevOrder);
        for (var iField = 0; iField < numSelects; iField++) {
            if (iField != iCurrentField) {
                fldNo = iField + 1;
                if (fldNo > 0 && fldNo < 10)
                    fldNo = "0" + fldNo;
                fldName = ctrl + "_ctl" + fldNo + "_ddlReorder";

                if (eSelect.form[fldName].selectedIndex + 1 >= iMin && eSelect.form[fldName].selectedIndex + 1 <= iMax) {
                    eSelect.form[fldName].selectedIndex += iInc;
                }
            }
        }
    }
}

function ReorderDropDowns(ctrl, idx, eSelect, iCurrentField, numSelects) {
    var fldName;
    var fldNo;
    var eForm = eSelect.form;
    var iNewOrder = eSelect.selectedIndex + 1;
    var iPrevOrder;
    var positions = new Array(numSelects);
    var ix;
    for (ix = 0; ix < numSelects; ix++) {
        positions[ix] = 0;
    }
    for (ix = 0; ix < numSelects; ix++) {
        fldno = ix + 2;
        if (fldno > 0 && fldno < 10)
            fldno = "0" + fldno;
        fldName = ctrl + "_ctl" + fldno + "_ddlReorder";
        positions[eSelect.form[fldName].selectedIndex] = 1;

    }
    for (ix = 0; ix < numSelects; ix++) {
        if (positions[ix] == 0) {
            iPrevOrder = ix + 1;
            break;
        }
    }
    if (iNewOrder != iPrevOrder) {
        var iInc = iNewOrder > iPrevOrder ? -1 : 1
        var iMin = Math.min(iNewOrder, iPrevOrder);
        var iMax = Math.max(iNewOrder, iPrevOrder);
        for (var iField = 0; iField < numSelects; iField++) {
            if (iField != iCurrentField) {
                fldNo = iField + 2;
                if (fldNo > 0 && fldNo < 10)
                    fldNo = "0" + fldNo;
                fldName = ctrl + "_ctl" + fldNo + "_ddlReorder";

                if (eSelect.form[fldName].selectedIndex + 1 >= iMin && eSelect.form[fldName].selectedIndex + 1 <= iMax) {
                    eSelect.form[fldName].selectedIndex += iInc;
                }
            }
        }
    }
}

function init() {
    myfunc = TreeView_ProcessNodeData;
    TreeView_ProcessNodeData = ResizeAfterCallback;

    myfunc1 = TreeView_ToggleNode;
    TreeView_ToggleNode = MyToggleNode;

    myfunc2 = TreeView_PopulateNode;
    TreeView_PopulateNode = MyPopulateNode;
    fixAllHtml();
}
function ResizeAfterCallback(context, param) {
    context = fixhtml(context);
    if (myfunc != null)
        myfunc(context, param);
    parent.resizeIframe(window.name);
}
function MyToggleNode(param1, param2, param3, param4, param5) {
    if (param3.alt)
        parent.MediaButton.SetParams("ExpandedTopics=" + param3.alt);
    else {
        var tid = gettid(param5);
        parent.MediaButton.SetParams("ExpandedTopics=" + tid);
        param3.alt = tid;
    }
    if (myfunc1 != null)
        myfunc1(param1, param2, param3, param4, param5);

}
function MyPopulateNode(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11) {
    if (myfunc2 != null)
        myfunc2(param1, param2, param3, param4, param5, param6, param7, param8, param9, param10, param11);
    // a_tag = document.getElementById('ptv_tvTreeViewn0');
    param3.alt = param8;
}
function fixhtml(str) {
    var re = /src=\"\/WebResource.axd/g;
    if (document.location.href.indexOf('eWB') != -1) {
        re = /src=\"\/eWB\/WebResource.axd/g;
        newstr = str.replace(re, " style=\"height:0px\;\" src=\"\/eWB\/WebResource.axd");
    } else {
        newstr = str.replace(re, " style=\"height:0px\;\" src=\"\/WebResource.axd");
    }

    return newstr;
}
function gettid(param) {
    var usePopulateNode = false;
    if (param.innerHTML.indexOf('TreeView_PopulateNode') != -1)
        usePopulateNode = true;
    var tid = ''
    var anchorFields = param.getElementsByTagName("a");
    if (usePopulateNode) {
        for (var aIndex = 0; aIndex < anchorFields.length - 1; aIndex++) {
            for (var aIndex = 0; aIndex < anchorFields.length - 1; aIndex++) {
                var atag = anchorFields[aIndex];
                if (atag) {
                    if (atag.href.indexOf('TreeView_PopulateNode') != -1) {
                        var st = atag.href.indexOf('(');
                        var ed = atag.href.length - 1;
                        var fparams = atag.href.substring(st + 1, ed);
                        var arrfp = fparams.split(',');
                        if (arrfp) {
                            for (var ix = 0; ix < arrfp.length; ix++) {
                                if (arrfp[ix].indexOf('\\') != -1) {
                                    var sts = arrfp[ix].indexOf('\'');
                                    var ste = arrfp[ix].indexOf('\\');
                                    tid = arrfp[ix].substring(sts + 1, ste);
                                    return tid;
                                } else if (arrfp[ix].indexOf('//') != -1) {
                                    var sts = arrfp[ix].indexOf('\'');
                                    var ste = arrfp[ix].indexOf('//');
                                    tid = arrfp[ix].substring(sts + 1, ste);
                                    return tid;
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    var useToggleNode = false;
    if (param.innerHTML.indexOf('TreeView_ToggleNode') != -1)
        useToggleNode = true;
    if (tid == '') {
        for (var aIndex = 0; aIndex < anchorFields.length - 1; aIndex++) {
            for (var aIndex = 0; aIndex < anchorFields.length - 1; aIndex++) {
                var atag = anchorFields[aIndex];
                if (atag) {
                    if (atag.href.indexOf('TreeNodeClick') != -1) {
                        var st = atag.href.indexOf('(');
                        var ed = atag.href.indexOf(')');
                        var tparams = atag.href.substring(st + 1, ed);
                        var tfp = tparams.split(',');
                        if (tfp) {
                            if (useToggleNode)
                                return tfp[1];
                            else
                                return tfp[0];
                        }
                    }
                }
            }
        }
    }
    return '';
}
function th(stid) {
}
function fixAllHtml() {
    var imgFields = document.getElementsByTagName("img");
    for (var iIndex = 0; iIndex < imgFields.length - 1; iIndex++) {
        var iField = imgFields[iIndex];
        if (iField) {
            if (iField.src.indexOf("WebResource.axd") != -1 && iField.alt == '') {
                iField.style.height = "0px";
            }
        }
    }
}
function oneUpText(URL) {
    day = new Date();
    id = day.getTime();
    sURL = URL + "&site=1";
    eval("page" + id + " = window.open(sURL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=945,height=665,left=0,top=0');");
}

//zebra stripe function. the argument should be the parent element
function zebra(elem) {

    if (elem == null) return;
    //get the table
    var table = elem.getElementsByTagName('table')[0];

    //these are the colors we will use
    //if they are supplied as arguments, then use those colors. otherwise, defaults
    var evenColor = arguments[1] ? arguments[1] : "#e0e0e0";
    var oddColor = arguments[2] ? arguments[2] : "#ededed";

    //now get the rows of the table
    if (table) {
        var rows = table.getElementsByTagName('tr');

        //now loop through the rows and apply styles to the td's
        for (var i = 0; i < rows.length; i++) {
            //get the td's in the row
            var td = rows[i].getElementsByTagName('td');
            //now apply the background colors to them
            for (var j = 0; j < td.length; j++) {
                if (i % 2 == 0) {
                    td[j].style.backgroundColor = evenColor;
                } else {
                    td[j].style.backgroundColor = oddColor;
                }
                fontCheck(td[j]);
                //for valid XHTML Strict 1.0, we have to add the td width dynamically,
                //until support for the pseudo-class :first-child is standard
                //so, if we're at the first row and the first td, set the width to 30%
                (j % 2 == 0 && i == 0 && elem.getAttribute('id') == 'summary') ? td[j].style.width = "30%" : null;
            }
        }
    }
}

function fontCheck(what) {
    /* this controls the font-size of the element based on the cookie */
    var userState = new Cookie(document, "userState", 8760);
    userState.load();
    if (userState.font) what.style.fontSize = userState.font + "px";
}

window.onload = function() {
    try { refreshDisplay(); }
    catch (e) { }
    //fontCheck(document.which('left'));
    //fontCheck(document.which('right'));
}

function refreshDisplay() {
    zebra(document.which('summary'));
    fontCheck(document.which('content_group'));

}

function CopyToClip(field) {
    var tempval = document.getElementById(field);
    if (tempval != null) {
        tempval.focus();
        tempval.select();
        therange = tempval.createTextRange();
        therange.execCommand("Copy");
    }
}

function oneUp(URL) {
//debugger
day = new Date();
id = day.getTime();
var h = 665;
var w = 945;
var lp = (screen.width) ? (screen.width-w)/2 : 0;
var tp = (screen.height) ? (screen.height-h)/2 : 0;

window.open(URL,id,'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=' + w + ',height=' +h + ',left=' + lp + ',top=' + tp);
return id;
}


function serializeAllLists(ctrl) {
    document.body.style.cursor = "wait";
    var TopList = document.getElementById(ctrl + "_lstTop");
    var BottomList = document.getElementById(ctrl + "_lstBottom");
    var rListVal = document.getElementById(ctrl + "_BottomListValues");
    var lListVal = document.getElementById(ctrl + "_TopListValues");
    //serializeList(TopList, lListVal);
    serializeList(BottomList, rListVal);
    document.body.style.cursor = "default";
}

function serializeList(listObj, fieldObj) {
    fieldObj.value = "";
    for (var i = 0, l = listObj.options.length; i < l; i++) {
        fieldObj.value += listObj.options[i].value + ":" + listObj.options[i].text + "|";
    }
    //remove last "|"
    fieldObj.value = fieldObj.value.substring(0, fieldObj.value.length - 1);
}
function CheckEmpty(oListBox) {
    if (oListBox.options.length > 0) {
        if (oListBox.options[0].value == "0") {
            oListBox.options[0] = null;
        }
    }
}

function MoveSelected(sSource, sDestination, bSort) {
    var i, j, k;
    oSource = document.getElementById(sSource);
    oDestination = document.getElementById(sDestination);
    var bExists = false;
    //exit if source is empty
    if (oSource.length < 1 || oSource.selectedIndex == -1) {
        alert("Nothing selected");
        return;
    }
    //get total items in source/dest
    i = oSource.length;
    j = oDestination.length;
    //Do not move MSG values
    if (oSource.options[0].value != "0") {
        CheckEmpty(oDestination);
        // move selected source --> dest
        for (k = 0; k < i; k++) {
            if (oSource.options[k].selected) {
                // Check to see if the item is already there.
                if (oDestination.length != 0) {
                    for (z = 0; z != oDestination.length; z++) {
                        if (oDestination.options[z].value == oSource.options[k].value) {
                            bExists = true;
                            //alert( oSource.options[k].text + " already exists in the destination.");
                            oSource.options[k].value = "DEL";
                            break;
                        }
                    }
                }
                if (bExists != true) {
                    oDestination.options[oDestination.length] = new Option(oSource.options[k].text, oSource.options[k].value, false, false)
                    oSource.options[k].value = "DEL";
                }
            }
            bExists = false;
        }
        if (bSort == 'True') {
            SortListBoxItems(oDestination);
        }
        RemoveMovedItems(sSource);
    }
}

function RemoveMovedItems(sSource) {
    oSource = document.getElementById(sSource);
    while (oSource.selectedIndex != -1) {
        y = oSource.length;
        for (x = 0; x < y; x++) {
            if (oSource.options[x].value == "DEL") {
                oSource.options[x] = null;
                y--;
                break;
            }
        }
    }
}

function ListBoxItem(id, text) {
    this.id = id;
    this.text = text;
}

function SortListBoxItems(listObj) {
    aUnsortedListBoxItems = new Array();
    aSortedListBoxItems = new Array();
    for (var i = 0, l = listObj.options.length; i < l; i++) {
        aUnsortedListBoxItems[i] = new ListBoxItem(listObj.options[i].value, listObj.options[i].text);
    }
    aSortedListBoxItems = myObjectBubbleSort(aUnsortedListBoxItems, aUnsortedListBoxItems.length);
    populateListBox(listObj, aSortedListBoxItems);
}

function myObjectBubbleSort(arrayName, length) {
    for (var i = 0; i < (length - 1); i++) {
        for (var j = i + 1; j < length; j++) {
            if (arrayName[j].text < arrayName[i].text) {
                var dummy = arrayName[i];
                arrayName[i] = arrayName[j];
                arrayName[j] = dummy;
            }
        }
    }
    return arrayName;
}

function populateListBox(listObj, arrayName) {
    // Clear listbox
    while (listObj.length > 0) {
        listObj.options[0] = null;
    }
    // Repopulate listbox
    for (var i = 0; i < arrayName.length; i++) {
        listObj.options[listObj.length] = new Option(arrayName[i].text, arrayName[i].id, false, false)
    }
}

function shwmsg(type, msg) {
    var e = document.getElementById(type);
    var m = document.getElementById('p_' + type);
    if (e != null && m != null) {
        m.innerHTML = msg;
        e.style.display = 'block';
    }
}

function shwhd(type) {
    var e = document.getElementById(type);
    var m = document.getElementById('p_' + type);
    if (e != null && m != null) {
        e.style.display = 'none';
    }
}

function __CreateMediaButtonObject(cbRef, clientRefId) {
    this.MediaParams = '';
    this.Id = clientRefId;
    this.Control = document.getElementById(clientRefId);
    this.Left = true;
    this.Right = true;
    this.Font = 11;
    this.LeftMenu = '';
    this.TextRows = 0;
    this.PhotoRows = 0;
    this.GraphicRows = 0;
    this.VideoRows = 0;
    this.InteractiveRows = 0;
    this.AudioRows = 0;

    // bread crumbs
    // params is the html to set
    this.SetBreadCrumbs = function(params) {
        // set the breadcrumbs
        var results_id = document.which('results');
        // alert("results_id="+results_id);
        params = params.replace(/&/, "&amp;");
        results_id.innerHTML = params;
    }

    this.SetSearchCriteria = function(params) {
        var results_id = document.which('results');
        results_id.title = params;
    }

    // media counts
    // e.g. params text=10;photos=5;graphics=15;video=12
    this.SetCounts = function(params) {
        // set button title
        // call SetMediaCounts in leftnav.js
        SetMediaCounts(params);
    }

    //var cbfunc = eval(cbRef);
    this.InitCallback = cbRef;
    this.SetParams = function(params, context) {
        context = context || this.Control;
        this.MediaParams = params;
        this.InitCallback(params, context);
    }
}

function __MediaButtonOnSuccess(response, context) {
    //    if (context)
    //		resizeIframe.defer(context);
}

function __MediaButtonCallbackOnError(error, context) {
    alert(error);
}

function changeAll()
{
	if(document.frmManage.checkall.checked == true)
		selectAll();
	else
		clearAll();
}
function selectAll(name)
{
	for (var i = 0; i < document.frmManage.elements.length; i++)
	{

		if(document.frmManage.elements[i].type == 'checkbox' &&
			(document.frmManage.elements[i].name == name ||
			document.frmManage.elements[i].name == 'checkall'))
		{
	 		document.frmManage.elements[i].checked = true;
	 	}
	 }

}
function clearAll(name)
{
	for (var i = 0; i < document.frmManage.elements.length; i++)
	{

	if(document.frmManage.elements[i].type == 'checkbox' &&
		(document.frmManage.elements[i].name == name ||
		document.frmManage.elements[i].name == 'checkall'))
		{
	 		document.frmManage.elements[i].checked = false;
	 	}
 	}

}
function savechanges(act)
{
	//alert("submit('action') function called.");
	mymessage	= document.getElementById("message");
	var sPath = "";
	//Safari pathing fix
	//if(GetBrowser() == "Safari")
	//{
	//	sPath="user/";
	//}
	if(act == 'delete') 
	{
		ok = 0;
		for (var i = 0; i < document.frmManage.elements.length; i++) 
		{
			e = document.frmManage.elements[i];
			if (e.type == 'checkbox' && e.name == 'selectSearch' && e.checked) 
			{
				ok = 1;
				break;
			}
		}
		if (!ok) 
		{
			alert("No searches selected for deletion!");
			return;
		}
		if (!confirm("Are you sure you want to delete the selected searches?")) 
		{
			return;
		}
		document.frmManage.action=sPath + 'ManageProfiles.aspx?a=del';
	}
	else if(act == 'copy')
	{
		document.frmManage.action=sPath + 'ManageProfiles.aspx?a=copy';
	}
	else if(act == 'savechanges')
	{
		document.frmManage.action=sPath + 'ManageProfiles.aspx?a=sc';
		mymessage.innerHtml ="Changes saved.";
	}
	//alert("document.frmManage.action=" + document.forms['frmManage'].action);
document.forms['frmManage'].submit();
//todo document.frmManage.submit();
}


function moveRow(action) { 
	
	var FOOTER_ROWS = 1;
	//get our table
	var tbl = currRow;
	while (tbl !=null && tbl.tagName != "TABLE")
		tbl = tbl.parentNode;
	
	if (tbl == null)
		return;

	//figure out the current & next rows
	var crPos		= currRow.rowIndex; 
	var childNode	= null;
	var newNode		= null;
	
	if (action == "down")
		{
			nrPos = crPos + 1;
			if (nrPos == tbl.rows.length - FOOTER_ROWS) //if we are @ the last row
				{
					//swap the rows - since we use insertBefore
					nrPos = crPos;
					crPos = 1;
				}
		
			childNode	= tbl.rows[crPos];
			newNode		= tbl.rows[nrPos];
		}
	else
		{
			nrPos = crPos - 1;
			nrPos = (nrPos == 0) ? tbl.rows.length - FOOTER_ROWS : nrPos ; //if we are @ the first row
			
			childNode	= tbl.rows[nrPos];
			newNode		= tbl.rows[crPos];
		}

	newNode.parentNode.insertBefore(newNode,childNode);

	//update the row #s in our hidden field
	//sortOrders: 1456=1,1567=2,7863=3
	var newSortOrders = "";
	for(i=1;i<tbl.rows.length - 2; i++)
	{
		var sid = tbl.rows[i].id.replace("row_","");
		newSortOrders += ((newSortOrders.length > 0 ) ? "," : "") + sid + "=" + i;
	}
		
	var se = document.getElementById("sortOrders");
	if (se != null)
		se.value = newSortOrders;
	
	// movind radio buton UP makes it become deselected
	currRadio.checked = true;
} 

var currRow = null;
var currRadio = null;
function selectRow(row, radio) {
  Element.removeClassName(currRow, "highlighted");
  Element.addClassName(row, "highlighted");
  
  currRow = row;
  currRadio = radio;
  
  Element.hide($('orderTitle'));
  Element.show($('orderButtons'));
}

function __CreateKeywordObject(cbRef, clientRefId) {
    this.KeywordParams = '';
    this.Id = clientRefId;
    this.Control = document.getElementById(clientRefId);

    //var cbfunc = eval(cbRef);
    this.InitCallback = cbRef;
    this.GetSearchString = function(params) {
        this.KeywordParams = params;
        this.InitCallback(params, this.Control);
    }
}

function __KeywordOnSuccess(response, context) {
    alert(response);
}

function __KeywordCallbackOnError(error, context) {
    alert(error);
}

var mediaids = ["textIFrame", "photoIFrame", "graphicsIFrame", "videoIFrame"]
function setIFrameSrc(src) {
    for (i = 0; i < mediaids.length; i++) {
        var cfr = document.getElementById(mediaids[i]);
        var ds = "Text";
        if (mediaids[i] == "textIFrame")
            ds = "Text";
        else if (mediaids[i] == "photoIFrame")
            ds = "Photo";
        else if (mediaids[i] == "graphicsIFrame")
            ds = "Graphic";
        else if (mediaids[i] == "videoIFrame")
            ds = "Video";
        var s = "SearchHandler.aspx?DisplayStyle=" + ds + "&" + src;
        // alert(s);
        cfr.src = s
    }
}

function hideMenu(daLayer, daSymbol) {
    var sym = document.getElementById(daSymbol).src;
    var re_c = /contract/;
    var re_e = /expand/;
    if (re_c.test(sym)) {
        document.getElementById(daLayer).style.display = "none";
        document.getElementById(daSymbol).src = '../images/expand.gif';
        return;
    } else if (re_e.test(sym)) {
        document.getElementById(daLayer).style.display = "block";
        document.getElementById(daSymbol).src = '../images/contract.gif';
        return;
    }
}

function ArrangeMedia(id) {
    var e = document.which(id);
    if (e) {
        var oldstyle = e.style.display;
        if (oldstyle == 'none')
            e.style.display = "block";
        var eli = e.getElementsByTagName('li');
        liHeight(eli);
        e.style.display = oldstyle;
    }
}

function FixVideos() {
    ArrangeMedia('video');
}

function FixPhotos() {
    var photos = document.which('photos');
    if (photos) {
        var oldstyle = photos.style.display;
        if (oldstyle == 'none')
            photos.style.display = "block";

        var photoli = photos.getElementsByTagName('li');
        liHeight(photoli);
        photos.style.display = oldstyle;
    }
}

function FixGraphics() {
    var graphics = document.which('graphic');
    if (graphics) {
        var oldstyle = graphics.style.display;
        if (oldstyle == 'none')
            graphics.style.display = "block";
        graphicsli = graphics.getElementsByTagName('li');
        liHeight(graphicsli);
        graphics.style.display = oldstyle;
    }
}

function liHeight(what) {
    var height = 0;
    for (var i = 0; i < what.length; i++) {
        if (parseInt(what[i].offsetHeight) > height) height = parseInt(what[i].offsetHeight);
    }
    //height += 20;
    for (var i = 0; i < what.length; i++) {
        what[i].style.height = height + "px";
    }
}