function ReStyleRows(parentTable, ignoreSubheadItems)
{
 var alternativeStyle = false;
 var listItemCount = 0;
 var SubHead1;
 for ( var x = 1 ; x < parentTable.childNodes.length; x +=1 )
 {
 //there are 3 types of rows: list item rows, line rows, and save rows (uplevel only).
 //List item and save rows need to be restyled, but the save row should be the same color as its list item row.
 //Line rows do not need to be styled.
 row = parentTable.childNodes[x];
 if(row.listEntry == "true"){
 listItemCount++;
 alternativeStyle = !alternativeStyle;
 }
 if(row.className.search(/listrow/i) != -1){
 if ( alternativeStyle )
 {
 row.className = "altListRow";
 }
 else
 {
 row.className = "listRow";
 }
 }
 }
 if(!ignoreSubheadItems){
 SubHead1 = document.getElementById("subheaditem1")
 if ( listItemCount >= c_maxListItems )
 {
 SubHead1.oldHtml = SubHead1.innerHTML;
 SubHead1.innerHTML = SubHead1.innerText;
 SubHead1.className = "disabledModHead";
 }
 else
 {
 if ( SubHead1.oldHtml )
 {
 SubHead1.innerHTML = SubHead1.oldHtml;
 SubHead1.className = "";
 SubHead1.oldHtml = "";
 }
 }
 }
}
function DeleteList(cnsId, listName, listHeader, action)
{
 var DialogHeight = 195;
 var dataArray = new SimpleDialogData(listName, null, null, null, c_confirmationList, c_yesBtn, c_noBtn);
 returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=" + action, dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if ( returnValObj != null && returnValObj.Action != null && returnValObj.Action == "OK")
 {
 GrayTopMenu();
 // delete from the server
 _sd_Post(GetActionUrl( listHeader ), "itemid=" + cnsId + "&FormMethod=post&MethodType=" + action);
 }
}
// used for myspace page to remove list item rows
function DeleteRow(cnsId, listHeader, confirmation)
{
 var row;
 var rowClass;
 var dataArray;
 var returnValObj;
 var DialogHeight = 195;
 var reStyle = false;
 var parentTable;
 var textCell;
 if ( confirmation == 'null' || confirmation == null )
 {
 confirmation = c_confirmation;
 }
 parentTable = document.getElementById(cnsId).parentElement;
 if ( parentTable.childNodes[2].className.search(/altListRow/) != -1)
 {
 reStyle = true;
 }
 for ( var x = 0 ; x < parentTable.childNodes.length; x ++ )
 {
 row = document.getElementById(cnsId).parentElement.childNodes[x];
 if ( row.id == cnsId )
 {
 textCell = row.firstChild;
 if((textCell.children[0] == null) ||
 ((textCell.children[0].children[0] != null) && (textCell.children[0].children[0].tagName == "IMG"))){
 textCell = row.cells[1];
 }
 dataArray = new SimpleDialogData(textCell.innerText, null, null, null, confirmation, c_yesBtn, c_noBtn);
 returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=deletelist", dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if(returnValObj != null && returnValObj.Action != null && returnValObj.Action == "OK")
 {
 // delete from the server
 _sd_Post(GetActionUrl( listHeader ), "itemid=" + cnsId + "&MethodType=delete&FormMethod=post");
 // if successful
 if ( document.getElementById(cnsId).parentElement.childNodes.length == 4 )
 {
 document.getElementById(document.getElementById(listHeader).nolist).style.display = "block";
 document.getElementById(listHeader).style.display = "none";
 }
 //remove row
 parentTable.removeChild( row );
 do{
 //remove rows until a row containing a cell with class of line is found.
 row = parentTable.childNodes[x];
 rowClass = row.childNodes[0].className;
 parentTable.removeChild( row )
 }while((rowClass.search(/line/i) == -1) && (parentTable.childNodes.length > x));
 }
 break;
 }
 }
 if ( reStyle ) //re-style the whole list
 {
 ReStyleRows( parentTable );
 }
}
// use for myspace lists to display confirmation dialog and do the deletes
function Action(actionType, actionDescription, nameArray, valueArray, limitsArray, actionUrl, command)
{
 var DialogHeight;
 var dataArray;
 if ( actionUrl == null )
 actionUrl = location.href;
 if(("EditListItem" == actionType) || ("CreateListItem" == actionType))
 DialogHeight = 320;
 else if ((actionType == "renamelist") || (actionType == "addmusiclist"))
 DialogHeight = 200;
 else if ( actionType == "CreateBookItem" )
 DialogHeight = 345;
 else if ( actionType == "addlist" )
 DialogHeight = 220;
 else
 DialogHeight = 185
 if(window.showModalDialog)
 {
 dataArray = new ComplexDialogData(nameArray, valueArray, actionDescription, null, null, limitsArray);
 var returnValObj = window.showModalDialog("SimpleDialog.aspx?actionType=" + actionType, dataArray, "dialogWidth=450px;dialogHeight=" + DialogHeight + "px;status=no;help=no;center=yes;unadorned=yes;scroll=no");
 if(null != returnValObj)
 {
 if(returnValObj.Action == "OK")
 {
 var returnVal = _sd_Post(actionUrl, null);
 if ( returnVal == null || returnVal.indexOf("http") != 0 )
 {
 location.reload();
 }
 }
 else if(returnValObj.Action == "NameValueReturn")
 {
 var FormParams = "MethodType=" + command + "&FormMethod=post&";
 for ( var x = 0 ; x < returnValObj.ReturnValues.length ; x++ )
 {
 if ( x != 0 ) FormParams += "&";
 FormParams += "value" + (x+1) + "=" + SimpleEncode( returnValObj.ReturnValues[x] );
 }
 // if the return is a url that redirect there / else reload the current page
 var string = _sd_Post(actionUrl, FormParams);
 if ( string == null || strText.toLowerCase().indexOf("http") != 0 )
 {
 location.reload();
 }
 }
 }
 }
}
// use for myspace lists to display confirmation dialog and do the deletes
function SimpleEncode(rawString)
{
 rawString = rawString.replace(/%/g, "%25");
 rawString = rawString.replace(/&/g, "%26");
 rawString = rawString.replace(/\+/g, "%2b");
 return rawString;
}
function UnGrayTable(mainTable, rowException)
{
 var currentRow;
 var table;
 UnGrayTopMenu();
 if ( mainTable.nodeName != "TABLE" )
 {
 table = document.getElementById( mainTable );
 }
 else
 {
 table = mainTable;
 }
 if ( table != null )
 {
 for ( var y = 0; y < table.children[0].children.length ; y ++ )
 {
 currentRow = table.children[0].children[y];
 if ( currentRow.id != rowException ) // enable the unused rows
 {
 for ( var x = 0 ; x < currentRow.children.length ; x ++ )
 {
 if ( currentRow.children[x].celltype == 'edit')
 {
 var oldLink = currentRow.children[x].oldlink;
 currentRow.children[x].innerHTML = "";
 currentRow.children[x].appendChild(oldLink);
 currentRow.children[x].oldlink = null;
 }
 else if ( currentRow.children[x].celltype == 'delete' )
 {
 currentRow.children[x].innerHTML = currentRow.children[x].children[0].oldvalue;
 }
 }
 }
 }
 }
}
function UnGrayTopMenu()
{
 //re-enable the menus
 var menu = document.getElementById("subNavHeader");
 if ( menu )
 {
 menu.innerHTML = menu.oldvalue;
 menu.className = menu.className.replace("disabledModHead", "");
 }
}
function GrayTopMenu()
{
 // disable the top menus if they exist
 var menu = document.getElementById("subNavHeader");
 if ( menu )
 {
 menu.oldvalue = menu.innerHTML;
 menu.className = menu.className + " disabledModHead";
 menu.innerHTML = menu.innerText;
 }
}
function GrayTable(table, rowException)
{
 var addButton;
 var currentRow;
 if ( table.nodeName != "TABLE" )
 {
 table = document.getElementById( table );
 }
 GrayTopMenu();
 if ( table != null )
 {
 for ( var x = 0; x < table.children[0].children.length ; x ++ )
 {
 currentRow = table.children[0].children[x];
 if ( currentRow.id != rowException ) // gray out the unused rows
 {
 for ( var y = 0 ; y < currentRow.children.length ; y ++ )
 {
 if ( currentRow.children[y].celltype == 'edit' )
 {
 //save the children of the element so they can be put back later.
 //Must save in dhtml object form (rather than html) because of attached events.
 var oldLink = null;
 for(var i = 0; i < currentRow.children[y].children.length; i++){
 if(currentRow.children[y].children[i].tagName == "A"){
 oldLink = currentRow.children[y].children[i];
 break;
 }
 }
 if(oldLink){
 currentRow.children[y].oldlink = oldLink;
 }else{
 //not an expected case.
 currentRow.children[y].oldlink = currentRow.children[y].children[i].children[0];
 }
 //replace the old image with the newly created disabled link image.
 addButton = document.createElement("img");
 addButton.setAttribute('src', 'images/editicon_disabled.gif');
 currentRow.children[y].replaceChild(addButton, oldLink);
 }
 else if ( currentRow.children[y].celltype == 'delete' )
 {
 addButton = document.createElement("img");
 addButton.setAttribute('src', 'images/clearicon_disabled.gif');
 addButton.setAttribute('oldvalue', currentRow.children[y].innerHTML);
 currentRow.children[y].innerHTML = '';
 currentRow.children[y].appendChild( addButton );
 }
 }
 }
 }
 }
}
var delayRequiredFields;
var delayRequiredFieldValues;
function EditRow(listHeader, row)
{
 var fieldValue;
 var escapedValue;
 var inputBox;
 var addButton;
 var currentRow;
 var imageIcon;
 var headerItem;
 var required;
 var requiredField;
 var requiredFieldValue;
 //index of interesting elements (not a text node)
 var itemIndex = 0;
 // gray out all the rows not being edited
 GrayTable(document.getElementById(row).parentElement.parentElement, row);
 delayRequiredFields = new Array();
 delayRequiredFieldValues = new Array();
 for ( var y = 0; y < document.getElementById(row).parentElement.children.length ; y ++ )
 {
 currentRow = document.getElementById(row).parentElement.children[y];
 if ( currentRow.id == row ) // modify the editing row
 {
 for ( var x = 0; x < currentRow.children.length ; x++ )
 {
 if ( currentRow.children[x].celltype == 'text' ||
 currentRow.children[x].celltype == 'link' )
 {
 fieldValue = currentRow.children[x].children[0].innerText;
 required = (currentRow.children[x].children[0].required == "true");
 inputBox = document.createElement('input');
 inputBox.style.width = gblListColumnSizes[itemIndex];
 inputBox.className = 'editBox editTableWidth';
 inputBox.setAttribute('type', 'text');
 inputBox.maxLength = currentRow.children[x].maxLength;
 inputBox.setAttribute('oldvalue', currentRow.children[x].innerHTML);
 currentRow.children[x].innerText = '';
 currentRow.children[x].appendChild( inputBox );
 if ( required )
 {
 escapedValue = fieldValue.replace(/\\/g, "\\\\");
 escapedValue = escapedValue.replace(/\'/g, "\\\'");
 escapedValue = escapedValue.replace(/\"/g, "\\\"");
 currentRow.children[x].children[0].onpropertychange = Function("ValidateTextboxAdd(this, 'editRow');");
 delayRequiredFields.push( currentRow.children[x].children[0] );
 delayRequiredFieldValues.push( escapedValue ); //gets put inside a javascript string
 }
 else
 {
 currentRow.children[x].children[0].value = fieldValue;
 }
 itemIndex++;
 }
 else if ( currentRow.children[x].celltype == 'edit' ) // edits change to add
 {
 addButton = document.createElement("<input id='editRow' type='button'>");
 addButton.onclick = Function("SubmitRow('" + listHeader + "', '" + row + "');");
 addButton.setAttribute('oldvalue', currentRow.children[x].innerHTML);
 addButton.setAttribute('value', c_lists_save_button);
 addButton.style.width = "87px";
 //remove "listCell" class which adds padding
 currentRow.children[x].className = "";
 currentRow.children[x].innerHTML = '';
 currentRow.children[x].appendChild( addButton );
 itemIndex++;
 }
 else if ( currentRow.children[x].celltype == 'delete' ) // deletes change to cancel
 {
 addButton = document.createElement("<input type='button'>");
 addButton.onclick = Function("CancelRow('" + row + "');");
 addButton.setAttribute('oldvalue', currentRow.children[x].innerHTML);
 addButton.setAttribute('value', c_lists_cancel_button);
 addButton.style.width = "87px";
 //remove "listCell" class which adds padding
 currentRow.children[x].className = "";
 currentRow.children[x].innerHTML = '';
 currentRow.children[x].appendChild( addButton );
 itemIndex++;
 }
 }
 }
 }
 for ( var x = 0; x < delayRequiredFields.length; x++ )
 {
 setTimeout("eval(delayRequiredFields[" + x + "]).value = \"" + delayRequiredFieldValues[x] + "\"", 50);
 }
}
function CancelRow(row)
{
 var fieldValue;
 var inputBox;
 var addButton;
 var oldLink;
 UnGrayTable(document.getElementById(row).parentElement.parentElement, row);
 for ( var y = 0; y < document.getElementById(row).parentElement.children.length ; y ++ )
 {
 currentRow = document.getElementById(row).parentElement.children[y];
 if ( currentRow.id == row ) // enable the unused rows
 {
 for ( var x = 0; x < currentRow.children.length ; x++ )
 {
 if ( currentRow.children[x].celltype == 'text' ||
 currentRow.children[x].celltype == 'edit' ||
 currentRow.children[x].celltype == 'link' ||
 currentRow.children[x].celltype == 'delete' )
 {
 currentRow.children[x].innerHTML = currentRow.children[x].children[0].oldvalue;
 }
 }
 }
 }
}
function SubmitRow(listHeader, row)
{
 var values = '';
 var success = true;
 var message;
 var link;
 var cell;
 var dom;
 var domRow;
 var img;
 var div;
 var returnString;
 var tableRow = document.getElementById(row);
 var submitUrl;
 var itemIndex = 0;
 submitUrl = GetActionUrl( listHeader );
 for ( var x = 0; x < tableRow.children.length ; x++ )
 {
 if ( tableRow.children[x].celltype == 'text' ||
 tableRow.children[x].celltype == 'link' )
 {
 if ( values != '' ) values += "&";
 values += "value" + (x+1) + "=" + SimpleEncode( tableRow.children[x].children[0].value );
 }
 }
 if ( success == true )
 {
 values += "&itemid=" + tableRow.id + "&MethodType=update&FormMethod=post";
 returnString = _sd_Post(submitUrl, values);
 try {dom = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) {dom = null;};
 if ( dom != null )
 {
 dom.async = false;
 dom.loadXML( returnString );
 if ( dom.selectNodes("xml/row/column").length == 0 )
 {
 success = false;
 location.href = c_errorUrl;
 }
 }
 else
 {
 location.href = c_errorUrl;
 }
 }
 // success - write the values with dhtml
 if ( success == true )
 {
 itemIndex = 0;
 for ( var x = 0; x < tableRow.children.length ; x++ )
 {
 cell = tableRow.children[x];
 if ( dom.selectNodes("xml/row/column") != null && dom.selectNodes("xml/row/column").length != 0 && dom.selectNodes("xml/row/column")[x].getAttribute("name") != null )
 {
 domRow = dom.selectNodes("xml/row/column")[x];
 switch ( domRow.getAttribute("type") )
 {
 case "link":
 link = document.createElement("A");
 link.setAttribute("href", domRow.getAttribute("url"));
 link.setAttribute("target", "_blank");
 link.className = "listcellText";
 if(domRow.getAttribute("name").length > 0){
 link.style.width = gblListColumnSizes[itemIndex];
 }else{
 link.style.width = "0px";
 }
 link.appendChild( document.createTextNode( domRow.getAttribute("name") ) );
 if ( domRow.getAttribute("required") != null )
 {
 link.setAttribute('required', 'true');
 }
 cell.innerHTML = '';
 cell.appendChild( link );
 itemIndex++;
 break;
 case "text":
 div = document.createElement("div");
 div.appendChild( document.createTextNode( domRow.getAttribute("name") ) );
 div.className = "listcellText";
 div.style.width = gblListColumnSizes[itemIndex];
 if ( domRow.getAttribute("required") != null )
 {
 div.setAttribute('required', 'true');
 }
 cell.innerHTML = '';
 cell.appendChild( div );
 itemIndex++;
 break;
 }
 }
 else
 {
 if ( cell.celltype == 'text' )
 {
 div = document.createElement("div");
 div.innerText = cell.children[0].value;
 div.className = "listcellText";
 div.style.width = gblListColumnSizes[itemIndex];
 cell.innerHTML = '';
 cell.appendChild( div );
 itemIndex++;
 }
 else if ( cell.celltype == 'link' )
 {
 link = document.createElement("A");
 link.className = "listcellText";
 link.setAttribute("href", cell.children[0].value);
 if(cell.children[0].value.length > 0){
 link.style.width = gblListColumnSizes[itemIndex];
 }else{
 link.style.width = "0px";
 }
 link.appendChild( document.createTextNode( cell.children[0].value ) );
 cell.innerHTML = '';
 cell.appendChild( link );
 itemIndex++;
 }
 else
 {
 cell.innerHTML = cell.children[0].oldvalue;
 }
 }
 }
 UnGrayTable(tableRow.parentElement.parentElement, row);
 }
 else
 {
 location.href = c_errorUrl;
 }
}
function showHideElement(element, focusElement)
{
 if ( document.getElementById( element) != null )
 {
 if ( document.getElementById( element ).style.display == 'none' )
 {
 document.getElementById( element ).style.display = 'block';
 }
 else
 {
 document.getElementById( element ).style.display = 'none';
 }
 }
 if (document.getElementById( focusElement ) != null )
 {
 document.getElementById( focusElement ).focus();
 }
}
function CreateRowFromXml(domRow, listHeader)
{
 var row;
 row = document.createElement("TR");
 row.id = domRow.getAttribute("id");
 row.className = "listRow";
 row.listEntry = "true";
 for ( var x = 0 ; x < domRow.selectNodes('column').length ; x++ )
 {
 row.appendChild( CreateCellFromXml(domRow.selectNodes('column')[x], listHeader, gblListColumnSizes[x]) );
 }
 return row;
}
function CreateCellFromXml(domColumn, listHeader, width)
{
 var cell;
 var link;
 var div;
 cell = document.createElement("TD");
 cell.noWrap = 'nowrap'
 cell.className = "listcell";
 cell.setAttribute("maxLength", domColumn.getAttribute("maxlength"));
 switch ( domColumn.getAttribute("type") )
 {
 case "link":
 link = document.createElement("A");
 link.setAttribute("href", domColumn.getAttribute("url"));
 link.setAttribute("target", "_blank");
 link.className = "listcellText";
 if(domColumn.getAttribute("name").length > 0){
 if(width){
 link.style.width = width;
 }
 }else{
 link.style.width = "0px";
 }
 link.appendChild( document.createTextNode( domColumn.getAttribute("name") ) );
 if ( domColumn.getAttribute("required") != null )
 {
 link.setAttribute('required', 'true');
 }
 cell.innerHTML = '';
 cell.celltype = "link";
 cell.appendChild( link );
 break
 case "text":
 div = document.createElement("div");
 div.className = "listcellText";
 if(width){
 div.style.width = width;
 }
 div.appendChild( document.createTextNode( domColumn.getAttribute("name") ) );
 if ( domColumn.getAttribute("required") != null )
 {
 div.setAttribute('required', 'true');
 }
 cell.innerHTML = '';
 cell.appendChild( div );
 cell.celltype = "text";
 break
 case "edit":
 link = document.createElement("A");
 link.setAttribute("href", "javascript:EditRow('" + listHeader + "', '" + domColumn.getAttribute("handle") + "')");
 img = document.createElement("<img src='images/editicon.gif' border='0'>");
 img.setAttribute("alt", domColumn.getAttribute("tooltip"));
 link.appendChild( img );
 cell.innerHTML = '';
 cell.align = 'center';
 cell.className = "";
 cell.appendChild( link );
 cell.celltype = "edit";
 break
 case "delete":
 link = document.createElement("A");
 link.setAttribute("href", "javascript:DeleteRow('" + domColumn.getAttribute("handle") + "', '" + listHeader + "')");
 img = document.createElement("<img src='images/clearicon.gif' border='0'>");
 img.setAttribute("alt", domColumn.getAttribute("tooltip"));
 link.appendChild( img );
 cell.innerHTML = '';
 cell.align = 'center';
 cell.className = "";
 cell.appendChild( link );
 cell.celltype = "delete";
 break
 }
 return cell;
}
function AddListItem(table, maintable)
{
 var parentTable;
 var submitString = '';
 var returnString;
 var success = true;
 var dom;
 var row;
 var rowValue;
 parentTable = document.getElementById( table );
 for ( var x = 0 ; x < parentTable.children[0].children[0].children.length ; x++ )
 {
 cell = parentTable.children[0].children[0].children[x];
 if ( cell.rowType == 'text' )
 {
 if ( submitString != '' ) submitString += "&";
 //children[0]: label
 //children[1]: br
 //children[2]: input element
 rowValue = cell.children[2].value;
 submitString += "value" + (x+1) + "=" + SimpleEncode( rowValue );
 }
 }
 submitString += "&MethodType=add&FormMethod=post";
 // submit the values
 returnString = _sd_Post(GetActionUrl( maintable ), submitString);
 if ( success )
 {
 // add the row to the table
 try {dom = new ActiveXObject("Microsoft.XMLDOM"); } catch (e) {dom = null;}
 if ( dom != null )
 {
 dom.async = false;
 dom.loadXML( returnString );
 if ( dom.selectNodes("xml/row/column").length == 0 )
 {
 success = false;
 location.href = c_errorUrl;
 }
 }
 else
 {
 location.href = c_errorUrl;
 }
 if ( success )
 {
 CancelAdd(table, maintable);
 // hide the norows area and show the main table
 if ( document.getElementById(maintable).children[0].childNodes.length == 2 )
 {
 document.getElementById(document.getElementById(maintable).nolist).style.display = "none";
 document.getElementById(maintable).style.display = "block";
 }
 // add the row to the table
 row = CreateRowFromXml(dom.selectSingleNode("xml/row"), maintable);
 document.getElementById( maintable ).children[0].appendChild( row );
 document.getElementById( maintable ).children[0].appendChild( CreateLineRow( row.children.length ) );
 ReStyleRows( document.getElementById( maintable ).children[0] );
 }
 }
 else
 {
 location.href = c_errorUrl;
 }
}
function CreateLineRow(cols)
{
 var cell;
 var row;
 row = document.createElement("TR");
 cell = document.createElement("TD");
 cell.className = "Line";
 cell.colSpan = cols;
 row.appendChild( cell );
 return row;
}
function CancelAdd(table, maintable)
{
 var parentTable;
 var cell;
 var addArea;
 addArea = document.getElementById('addarea');
 parentTable = document.getElementById( table );
 for ( var x = 0 ; x < parentTable.children[0].children[0].children.length ; x++ )
 {
 cell = parentTable.children[0].children[0].children[x];
 if ( cell.rowType == 'text' )
 {
 cell.children[2].value = '';
 }
 }
 addArea.style.display = 'none';
 UnGrayTable(maintable);
}
var playLists
var selectedPlaylist;
function ExpandMusicRow(rowNumber, style)
{
 var img = document.getElementById("expander" + rowNumber);
 if ( img.expanded == false )
 {
 img.src = "images/expanded.gif"
 img.expanded = true;
 }
 else
 {
 img.src = "images/collapsed.gif"
 img.expanded = false;
 }
 if ( document.getElementById("songRow" + rowNumber) == null )
 {
 // get the items from WMP
 var tbody = document.getElementById("row" + rowNumber).parentElement;
 var playlistCurrent = playLists.item(rowNumber);
 var row;
 var item;
 var cell;
 var table;
 var musicRow;
 var musicCell;
 var tbody;
 var nobr;
 row = document.createElement("tr");
 row.id = "songRow" + rowNumber
 row.className = style;
 cell = document.createElement("<td width='200' nowrap>");
 row.appendChild( cell );
 cell = document.createElement("td") ;
 table = document.createElement("<table border='0' cellpadding='0' cellspacing='0' width='100%' class='fixedTable'>");
 musicTbody = document.createElement("tbody");
 for ( i = 0; i < playlistCurrent.count; i++ )
 {
 musicRow = document.createElement("tr");
 musicCell = document.createElement("<td class='listcell' width='200'>");
 nobr = document.createElement("nobr");
 nobr.appendChild( document.createTextNode( playlistCurrent.item(i).name ) );
 musicCell.appendChild( nobr );
 musicRow.appendChild ( musicCell );
 musicCell = document.createElement("<td class='listcell' width='200'>");
 nobr = document.createElement("nobr");
 nobr.appendChild( document.createTextNode( playlistCurrent.item(i).getItemInfo("Author") ) );
 musicCell.appendChild( nobr );
 musicRow.appendChild ( musicCell );
 musicCell = document.createElement("<td class='listcell'>");
 nobr = document.createElement("nobr");
 nobr.appendChild( document.createTextNode( playlistCurrent.item(i).getItemInfo("WM/AlbumTitle") ) );
 musicCell.appendChild( nobr );
 musicRow.appendChild ( musicCell );
 musicTbody.appendChild( musicRow );
 // if we're not the last row than add a line
 if ( i != (playlistCurrent.count - 1) )
 {
 musicRow = document.createElement("tr");
 musicRow.appendChild( document.createElement("<td colspan=3 class='line'></td>") );
 musicTbody.appendChild( musicRow );
 }
 }
 table.appendChild( musicTbody );
 cell.appendChild( table );
 row.appendChild( cell );
 tbody.insertBefore(row, document.getElementById("row" + rowNumber).nextSibling);
 }
 else // just show hide the songs
 {
 showHideElement( document.getElementById("songRow" + rowNumber).id );
 }
}
function CreatePlayListTable()
{
 var row;
 var cell;
 var item;
 var link;
 var altStyle = false;
 playLists = wmpPlayer.playlistCollection.getAll();
 if ( playLists.count == 0 )
 {
 document.getElementById("NoPlaylists").style.display = 'block';
 }
 else
 {
 for ( i = 0 ; i < playLists.count ; i ++ )
 {
 altStyle = !altStyle;
 row = document.createElement("tr");
 row.id = "row" + i;
 row.name = "row" + i;
 if ( altStyle )
 {
 row.className = "altListRow";
 }
 else
 {
 row.className = "ListRow";
 }
 cell = document.createElement("<td class='padleft'>");
 cell.colSpan = 2;
 link = document.createElement("a");
 link.setAttribute("href", "javascript:ExpandMusicRow(" + i + ", '" + row.className + "')");
 item = document.createElement("<img src='images/collapsed.gif' border='0'>");
 item.id = "expander" + i;
 item.expanded = false;
 link.appendChild( item );
 item = document.createElement("<input type='radio' name='playlist'>");
 item.setAttribute("value", i);
 try
 {
 item.playList = playLists.item(i);
 var table = document.createElement("<table border='0' cellpadding='0' width='100%' class='fixedTable'>");
 var tbody = document.createElement("tbody");
 var elRow = document.createElement("tr");
 var elCell = document.createElement("<td width='30'>");
 elCell.noWrap = 'nowrap';
 elCell.appendChild( link );
 elCell.appendChild( item );
 elRow.appendChild( elCell );
 elCell = document.createElement("<td class='ellipse bold' width='*'>");
 elCell.noWrap = 'nowrap';
 elCell.appendChild( document.createTextNode( playLists.item(i).name ) );
 elRow.appendChild( elCell );
 tbody.appendChild( elRow );
 table.appendChild( tbody );
 cell.appendChild( table );
 }
 catch(e)
 {
 continue;
 }
 row.appendChild ( cell );
 document.getElementById("_ctl2_LinksList").children[0].appendChild( row );
 row = document.createElement("tr");
 row.appendChild( document.createElement("<td type='line' colspan='3' class='Line'></td>") );
 document.getElementById("_ctl2_LinksList").children[0].appendChild( row );
 // select the radio button on the very first album
 if ( i == 0 )
 {
 item.checked = true;
 }
 }
 }
}
function GetWmpAccess()
{
 var showNoAccess = true;
 var majorVersion;
 if ( wmpPlayer.Settings != null )
 {
 majorVersion = wmpPlayer.versionInfo.split(".");
 if ( majorVersion[0].valueOf() >= 9 )
 {
 if ( wmpPlayer.Settings.mediaAccessRights != "read" && wmpPlayer.Settings.mediaAccessRights != "full" )
 {
 wmpPlayer.Settings.requestMediaAccessRights("read");
 }
 if ( wmpPlayer.Settings.mediaAccessRights != "read" && wmpPlayer.Settings.mediaAccessRights != "full" )
 {
 document.location = musicListUrl;
 return;
 }
 showNoAccess = false;
 CreatePlayListTable();
 }
 }
 if ( showNoAccess )
 {
 document.getElementById('importMusic').style.display = 'none';
 document.getElementById('importMusicFailed').style.display = 'block';
 }
}
function ValidateCheckBox(checkbox)
{
 if ( checkbox.checked == true )
 {
 if ( selectedItems >= c_max_items )
 {
 alert( maxItemsText );
 checkbox.checked = false;
 }
 else
 {
 selectedItems++;
 }
 }
 else
 {
 selectedItems --;
 }
}
function RenderSelectedPlaylist(playlist)
{
 var row;
 var cell;
 var tbody;
 var item;
 var table;
 var musicRow;
 var musicCell;
 var nobr;
 selectedPlaylist = playlist;
 tbody = document.getElementById("_ctl2_LinksList_page2").children[0];
 row = document.createElement("tr");
 row.className = "ListRow";
 cell = document.createElement("<td colspan='2'>");
 var elTable = document.createElement("<table border='0' cellpadding='0' width='100%' class='fixedTable'>");
 var elTbody = document.createElement("tbody");
 var elRow = document.createElement("tr");
 var elCell = document.createElement("<td width='30'>");
 elRow.appendChild( elCell );
 elCell = document.createElement("<td class='ellipse bold' width='*'>");
 elCell.noWrap = 'nowrap';
 elCell.appendChild( document.createTextNode( playlist.name ) );
 elRow.appendChild( elCell );
 elTbody.appendChild( elRow );
 elTable.appendChild( elTbody );
 cell.appendChild( elTable );
 row.appendChild( cell );
 tbody.appendChild( row );
 row = document.createElement("tr");
 row.className = "ListRow";
 cell = document.createElement("td");
 cell.width = 180;
 row.appendChild( cell );
 cell = document.createElement("td") ;
 table = document.createElement("<table border='0' cellpadding='0' cellspacing='0' width='100%' class='fixedTable'>");
 musicTbody = document.createElement("tbody");
 for ( var i = 0; i < playlist.count; i++ )
 {
 musicRow = document.createElement("tr");
 musicRow.index = i;
 musicCell = document.createElement("<td class='listcell' width='20'>");
 item = document.createElement("<input type='checkbox'>");
 item.id = "songChk" + i;
 item.onclick = Function("ValidateCheckBox(this);");
 musicCell.appendChild( item );
 musicRow.appendChild( musicCell );
 musicCell = document.createElement("<td class='listcell' width='200'>");
 nobr = document.createElement("nobr");
 nobr.appendChild( document.createTextNode( playlist.item(i).name ) );
 musicCell.appendChild( nobr );
 musicRow.appendChild ( musicCell );
 musicCell = document.createElement("<td class='listcell' width='200'>");
 nobr = document.createElement("nobr");
 nobr.appendChild( document.createTextNode( playlist.item(i).getItemInfo("Author")) );
 musicCell.appendChild( nobr );
 musicRow.appendChild ( musicCell );
 musicCell = document.createElement("<td class='listcell'>");
 nobr = document.createElement("nobr");
 nobr.appendChild( document.createTextNode( playlist.item(i).getItemInfo("WM/AlbumTitle")) );
 musicCell.appendChild( nobr );
 musicRow.appendChild ( musicCell );
 musicTbody.appendChild( musicRow );
 if ( i != (playlist.count - 1 ) )
 {
 musicRow = document.createElement("tr");
 musicRow.appendChild( document.createElement("<td colspan=4 class='line'></td>") );
 musicTbody.appendChild( musicRow );
 }
 }
 table.appendChild( musicTbody );
 cell.appendChild( table );
 row.appendChild( cell );
 tbody.appendChild( row );
 // you can only check a checkbox after it's appended to the main dom
 // circle through all the checkboxes and check the first 100
 for ( var i = 0; i < c_max_items; i++ )
 {
 if ( document.getElementById("songChk" + i) != null )
 {
 document.getElementById("songChk" + i).checked = true;
 selectedItems++;
 }
 else
 {
 break;
 }
 }
}
function SelectPlayList()
{
 var selectedPlayList = null;
 if (playLists.count == 1)
 {
 selectedPlayList = musicForm.playlist.playList;
 }
 else
 {
 for (var i = 0 ; i < playLists.count ; i++ )
 {
 if ( musicForm.playlist[i] != null && musicForm.playlist[i].checked )
 {
 selectedPlayList = musicForm.playlist[i].playList;
 break;
 }
 }
 }
 if ( selectedPlayList == null )
 {
 // no items selected return
 return;
 }
 document.getElementById("_ctl2_LinksList").style.display = 'none';
 document.getElementById("_ctl2_LinksList_page2").style.display = 'block';
 document.getElementById("nextPlaylist").style.display = 'none';
 document.getElementById("copyPlaylist").style.display = 'block';
 document.getElementById("subNavHeader").style.display = 'block';
 document.getElementById("importHelpText").innerHTML = importHelpPage2;
 // if there are more than 100 items change text to select top 100
 if ( selectedPlayList.count > c_max_items )
 {
 document.getElementById("playListSelectAll").innerText = selectTopText;
 }
 RenderSelectedPlaylist( selectedPlayList );
}
function SelectAll()
{
 var count = 0;
 selectedItems = 0;
 for ( var i = 0 ; i < selectedPlaylist.count && i < c_max_items ; i++ )
 {
 if ( document.getElementById("songChk" + i) != null )
 {
 document.getElementById("songChk" + i).checked = true;
 selectedItems ++;
 }
 }
}
function ClearAll()
{
 for ( var i = 0 ; i < selectedPlaylist.count ; i++ )
 {
 if ( document.getElementById("songChk" + i) != null )
 {
 document.getElementById("songChk" + i).checked = false;
 }
 }
 selectedItems = 0;
}
function CopyPlaylist()
{
 var count = 0;
 var songString;
 var postString = "MethodType=import&FormMethod=post&playlist=";
 var song;
 var returnString;
 var songname;
 var album;
 var artist;
 var title;
 title = selectedPlaylist.name;
 if ( title.length > c_title_max_length )
 {
 title = title.substring(0, c_title_max_length - 1);
 }
 postString += title;
 for ( var i = 0 ; i < selectedPlaylist.count && count < c_max_items ; i++ )
 {
 if ( document.getElementById("songChk" + i) != null )
 {
 if ( document.getElementById("songChk" + i).checked == true )
 {
 song = selectedPlaylist.item(i);
 // add the song to the big list
 songname = song.getItemInfo("Title");
 album = song.getItemInfo("WM/AlbumTitle");
 artist = song.getItemInfo("Author");
 if ( songname.length > c_song_max_length )
 {
 songname = songname.substring(0, c_song_max_length - 1);
 }
 if ( album.length > c_album_max_length )
 {
 album = album.substring(0, c_album_max_length - 1);
 }
 if ( artist.length > c_artist_max_length )
 {
 artist = artist.substring(0, c_artist_max_length - 1);
 }
 postString += "&title" + count + "=" + SimpleEncode( songname ) + "&author" + count + "=" + SimpleEncode( artist ) + "&album" + count + "=" + SimpleEncode( album ) + "&wmid" + count + "=" + SimpleEncode(song.getItemInfo("WM/WMContentID"));
 count++;
 }
 }
 }
 // post the songs to the server
 _sd_Post(postUrl, postString);
}
// downlevel methods
function SubmitAddItem()
{
 var form = document.getElementById('downleveladdform');
 form.MethodType.value = "showadd";
 form.submit();
}
function SubmitCancelItem()
{
 var form = document.getElementById('downleveladdform');
 form.MethodType.value = "hideadd";
 document.downleveladdform.submit();
}
function SaveSubmit()
{
 if (! VerifyDownLevelValues() ) return;
 var form = document.getElementById('downleveladdform');
 form.MethodType.value = "add";
 form.FormMethod.value = "downlevelpost";
 form.submit();
}
function VerifyDownLevelValues()
{
 var maxLength;
 // verify the first value is present
 if ( document.getElementById('value1').value.length == 0 )
 {
 alert( c_lists_missingtextdown );
 return false;
 }
 // check if the strings are too long
 for ( var x = 1 ; x < 10 ; x++ )
 {
 if ( document.getElementById('maxlength' + x) == null )
 break;
 maxLength = document.getElementById('maxlength' + x).value.valueOf();
 if ( document.getElementById('value' + x).value.length > maxLength )
 {
 alert( c_lists_toolongdown );
 return false;
 }
 }
 return true;
}
// the downlevel list
function SubmitUpdate(url, handle)
{
 if (! VerifyDownLevelValues() ) return;
 var form = document.getElementById(url);
 form.MethodType.value = "update";
 form.FormMethod.value = "downlevelpost";
 form.itemid.value = handle;
 form.submit();
}
function SubmitListDelete(url, handle)
{
 var formObject = document.getElementById(url);
 if ( window.confirm(c_confirmation) )
 {
 formObject.MethodType.value = "deletelist";
 formObject.FormMethod.value = "downlevelpost";
 formObject.itemid.value = handle;
 formObject.submit();
 }
}
function SubmitDelete(url, handle, type)
{
 var formObject = document.getElementById(url);
 if ( window.confirm(c_confirmation) )
 {
 formObject.MethodType.value = "delete";
 formObject.FormMethod.value = "downlevelpost";
 formObject.itemid.value = handle;
 formObject.itemtype.value = type;
 formObject.submit();
 }
}
function SubmitEdit(url, handle)
{
 var formObject = document.getElementById(url);
 formObject.MethodType.value = "edit";
 formObject.itemid.value = handle;
 formObject.submit();
}
function ValidateTextboxAdd(box, button)
{
 var buttonCtrl = document.getElementById( button );
 if ( buttonCtrl != null )
 {
 if (box.value == "")
 {
 buttonCtrl.disabled = true;
 }
 else
 {
 buttonCtrl.disabled = false;
 }
 }
}
function SubmitCancelRename(url)
{
 document.location.href = url;
}
function SubmitRename(formName, maxlength)
{
 if ( formName.value1.value.length == 0 || formName.value1.value.length > maxlength )
 {
 alert( c_lists_stringerror );
 return false;
 }
 else
 {
 return true;
 }
}
