function toggleProGroup(group) {
  var thebox = window.document.getElementById(group+'_box');
  if (thebox.className == 'proboxopen') {
    //It's open so let's close it up
    thebox.className = 'probox';
    window.document.getElementById(group+'_content').style.display = 'none';
    window.document.getElementById(group+'_arrow').className = 'proarrowright';
  } else {
    thebox.className = 'proboxopen';
    window.document.getElementById(group+'_content').style.display = 'block';
    window.document.getElementById(group+'_arrow').className = 'proarrowdown';
  }
}

function toggleProMedia(group, type) {
  window.document.getElementById(group+'_audio').style.display = 'none';
  window.document.getElementById(group+'_video').style.display = 'none';
//  window.document.getElementById(group+'_text').style.display = 'none';
  window.document.getElementById(group+'_'+type).style.display = 'block';
  window.document.getElementById(group+'_tab_audio').className = 'protab';
  window.document.getElementById(group+'_tab_video').className = 'protab';
//  window.document.getElementById(group+'_tab_text').className = 'protab';
  window.document.getElementById(group+'_tab_'+type).className = 'protabselected';
}

function togglePubGroup(group) {
  var thebox = window.document.getElementById(group+'_box');
  if (thebox.className == 'pubboxopen') {
    //It's open so let's close it up
    thebox.className = 'pubbox';
    window.document.getElementById(group+'_content').style.display = 'none';
    window.document.getElementById(group+'_arrow').className = 'pubarrowright';
  } else {
    thebox.className = 'pubboxopen';
    window.document.getElementById(group+'_content').style.display = 'block';
    window.document.getElementById(group+'_arrow').className = 'pubarrowdown';
  }
}

function togglePubMedia(group, type) {
  window.document.getElementById(group+'_audio').style.display = 'none';
  window.document.getElementById(group+'_video').style.display = 'none';
//  window.document.getElementById(group+'_text').style.display = 'none';
  window.document.getElementById(group+'_'+type).style.display = 'block';
  window.document.getElementById(group+'_tab_audio').className = 'pubtab';
  window.document.getElementById(group+'_tab_video').className = 'pubtab';
//  window.document.getElementById(group+'_tab_text').className = 'pubtab';
  window.document.getElementById(group+'_tab_'+type).className = 'pubtabselected';
}


function doProSearch(keywords) {
    //Clear the search results
    var buffer = "<table align=\"center\" class=\"content\">";
    buffer += "<tr><td colspan=\"2\"></td></tr>";
    buffer += "</table>";
    window.document.getElementById("prosearch_audio").innerHTML = buffer;
    window.document.getElementById("prosearch_video").innerHTML = buffer;
    
    //Make sure the box is expanded
    var thebox = window.document.getElementById('prosearch_box');
    if (thebox.className == 'probox') {
      toggleGroup('prosearch');
    }
    loadProXMLDoc('doSearch.php?keywords='+keywords+'&scope=Professional');
}

var proreq;
function loadProXMLDoc(url) {
	proreq = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			proreq = new XMLHttpRequest();
        } catch(e) {
			proreq = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	proreq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		proreq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		proreq = false;
        	}
		}
    }
	if(proreq) {
		proreq.onreadystatechange = processProReqChange;
		proreq.open("GET", url, true);
		proreq.send("");
	}
}

function processProReqChange() {
    // only if proreq shows "loaded"
    if (proreq.readyState == 4) {
        // only if "OK"
        if (proreq.status == 200) {
          populateProSearchResults();
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                proreq.statusText);
        }
    }
}

function populateProSearchResults() {
    var audio = proreq.responseXML.getElementsByTagName("audio")[0];
    var items = audio.getElementsByTagName('item');
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    var buffer = "<table align=\"center\" class=\"content\">";
    buffer += "<tr><td colspan=\"2\"></td></tr>";
    for (var i = 0; i < items.length; i++) {
      buffer += "<tr><td><p class=\"title\">";
      buffer += items[i].getAttribute('title');
      buffer += "</p><p class=\"play\"><a href=\"#\" class=\"play\" onclick=\"playMedia('"+items[i].getAttribute('path')+"');return false;\">Play Audio</a> | <a href=\""+items[i].getAttribute('downloadPath')+"\" class=\"play\">Download</a></p></td>";
      buffer += "<td><A HREF=\"#\" onclick=\"playMedia('"+items[i].getAttribute('path')+"');return false;\"><img src=\"images/pro_content/icon_audio.gif\" border=\"0\"></A></td></tr>";
    }
    buffer += "</table>";
    window.document.getElementById("prosearch_audio").innerHTML = buffer;

    //Now do video
    var video = proreq.responseXML.getElementsByTagName("video")[0];
    items = video.getElementsByTagName('item');
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    var buffer = "<table align=\"center\" class=\"content\">";
    buffer += "<tr><td colspan=\"2\"></td></tr>";
    for (var i = 0; i < items.length; i++) {
      buffer += "<tr><td><p class=\"title\">";
      buffer += items[i].getAttribute('title');
      buffer += "</p><p class=\"play\"><a href=\"#\" class=\"play\" onclick=\"playMedia('"+items[i].getAttribute('path')+"', '"+items[i].getAttribute('id')+"');return false;\">Play Video</a> | <a href=\""+items[i].getAttribute('downloadPath')+"\" class=\"play\">Download</a></p></td>";
      buffer += "<td><A HREF=\"#\" onclick=\"playMedia('"+items[i].getAttribute('path')+"', '"+items[i].getAttribute('id')+"');return false;\"><img src=\"images/pro_content/icon_video.gif\" border=\"0\"></A></td></tr>";
    }
    buffer += "</table>";
    window.document.getElementById("prosearch_video").innerHTML = buffer;
    
}

function doPubSearch(keywords) {
    //Clear the search results
    var buffer = "<table align=\"center\" class=\"content\">";
    buffer += "<tr><td colspan=\"2\"></td></tr>";
    buffer += "</table>";
    window.document.getElementById("pubsearch_audio").innerHTML = buffer;
    window.document.getElementById("pubsearch_video").innerHTML = buffer;
    
    //Make sure the box is expanded
    var thebox = window.document.getElementById('pubsearch_box');
    if (thebox.className == 'pubbox') {
      toggleGroup('pubsearch');
    }
    loadPubXMLDoc('doSearch.php?keywords='+keywords+'&scope=Public');
}

var pubreq;
function loadPubXMLDoc(url) {
	pubreq = false;
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			pubreq = new XMLHttpRequest();
        } catch(e) {
			pubreq = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	pubreq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		pubreq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		pubreq = false;
        	}
		}
    }
	if(pubreq) {
		pubreq.onreadystatechange = processPubReqChange;
		pubreq.open("GET", url, true);
		pubreq.send("");
	}
}

function processPubReqChange() {
    // only if pubreq shows "loaded"
    if (pubreq.readyState == 4) {
        // only if "OK"
        if (pubreq.status == 200) {
          populatePubSearchResults();
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                pubreq.statusText);
        }
    }
}

function populatePubSearchResults() {
    var audio = pubreq.responseXML.getElementsByTagName("audio")[0];
    var items = audio.getElementsByTagName('item');
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    var buffer = "<table align=\"center\" class=\"content\">";
    buffer += "<tr><td colspan=\"2\"></td></tr>";
    for (var i = 0; i < items.length; i++) {
      buffer += "<tr><td><p class=\"title\">";
      buffer += items[i].getAttribute('title');
      buffer += "</p><p class=\"play\"><a href=\"#\" class=\"play\" onclick=\"playMedia('"+items[i].getAttribute('path')+"');return false;\">Play Audio</a> | <a href=\""+items[i].getAttribute('downloadPath')+"\" class=\"play\">Download</a></p></td>";
      buffer += "<td><A HREF=\"#\" onclick=\"playMedia('"+items[i].getAttribute('path')+"');return false;\"><img src=\"images/public_content/icon_audio.gif\" border=\"0\"></A></td></tr>";
    }
    buffer += "</table>";
    window.document.getElementById("pubsearch_audio").innerHTML = buffer;

    //Now do video
    var video = pubreq.responseXML.getElementsByTagName("video")[0];
    items = video.getElementsByTagName('item');
    // loop through <item> elements, and add each nested
    // <title> element to Topics select element
    var buffer = "<table align=\"center\" class=\"content\">";
    buffer += "<tr><td colspan=\"2\"></td></tr>";
    for (var i = 0; i < items.length; i++) {
      buffer += "<tr><td><p class=\"title\">";
      buffer += items[i].getAttribute('title');
      buffer += "</p><p class=\"play\"><a href=\"#\" class=\"play\" onclick=\"playMedia('"+items[i].getAttribute('path')+"', '"+items[i].getAttribute('id')+"');return false;\">Play Video</a> | <a href=\""+items[i].getAttribute('downloadPath')+"\" class=\"play\">Download</a></p></td>";
      buffer += "<td><A HREF=\"#\" onclick=\"playMedia('"+items[i].getAttribute('path')+"', '"+items[i].getAttribute('id')+"');return false;\"><img src=\"images/public_content/icon_video.gif\" border=\"0\"></A></td></tr>";
    }
    buffer += "</table>";
    window.document.getElementById("pubsearch_video").innerHTML = buffer;
    
}

var playreq;
function playAudio(record_id, track) {
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			playreq = new XMLHttpRequest();
        } catch(e) {
			playreq = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	playreq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		playreq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		playreq = false;
        	}
		}
    }
	if(playreq) {
		playreq.open("GET", "recordPlay.php?record_id="+record_id, true);
		playreq.send("");
	}
  flashProxy.call('js_wimpy_gotoTrack', track);
}

  function playMedia(media, record_id) {
    // branch for native XMLHttpRequest object
    if(window.XMLHttpRequest) {
    	try {
			playreq = new XMLHttpRequest();
        } catch(e) {
			playreq = false;
        }
    // branch for IE/Windows ActiveX version
    } else if(window.ActiveXObject) {
       	try {
        	playreq = new ActiveXObject("Msxml2.XMLHTTP");
      	} catch(e) {
        	try {
          		playreq = new ActiveXObject("Microsoft.XMLHTTP");
        	} catch(e) {
          		playreq = false;
         	}
	     	}
    }
  	if(playreq) {
  		playreq.open("GET", "recordPlay.php?record_id="+record_id, true);
  		playreq.send("");
  	}


    document.getElementById('player').innerHTML="<OBJECT id='cvmdplayer' width='292' height='284'"
      	+ " CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'"
      	+ " type='application/x-oleobject'>"
      	+ " <PARAM NAME='URL' VALUE='"+media+"'>"
      	+ " <PARAM NAME='SendPlayStateChangeEvents' VALUE='True'>"
      	+ " <PARAM NAME='AutoStart' VALUE='True'>"
      	+ " <PARAM name='uiMode' value='full'>"
      	+ " <PARAM name='PlayCount' value='1'>"
        + " <EMBED type='application/x-mplayer2'"
        + " SRC='"+media+"'"
        + " pluginspage = 'http://www.microsoft.com/Windows/MediaPlayer/'"
        + " name='cvmdplayer'"
        + " id='cvmdplayer'"
        + " uiMode='full'"
        + " playCount='1'"
        + " width='292'"
        + " height='284'"
        + " AutoStart='true'>"
        + " </EMBED>"
        + " </OBJECT>";
  }
