/* Generic function for all ajax controls */

function launch_embed_config(account_id){
  if(screen){
    leftPos=screen.width-1000;
    leftPos=(leftPos/2)-5
    topPos=screen.height-600;
    topPos=(topPos/2)-30
  }
	url = 'http://embed.clickstreamtv.net/embed/config/' + account_id + '/';
  mcc_tutorial_video_win = window.open(url, "cst_embed_config_win", "width=1000,height=600,left="+leftPos+",top="+topPos);
}

function launch_tutorial_video(cst_file_id, is_sugarplum){
  if(screen){
    leftPos=screen.width-610;
    leftPos=(leftPos/2)-5
    topPos=screen.height-485;
    topPos=(topPos/2)-30
  }
	url = "http://cst.clickstreamtv.net/mcc/support/videos.php?v=" + cst_file_id + "&sp=" + is_sugarplum;
  mcc_tutorial_video_win = window.open(url, "cst_sp_player_win", "width=610,height=485,left="+leftPos+",top="+topPos);
}

function launch_sp_player(config, accountID, playlistID){
  //alert('Please design your player first.\r\n[No config file for this configID: ' + config + ' ]');
  if(screen){
    leftPos=screen.width-980;
    leftPos=(leftPos/2)-5
    topPos=screen.height-640
    topPos=(topPos/2)-30
  }
	url = "http://sugarplum.clickstreamtv.net/cst-entry.php?c=" + config + "&a=" + accountID;
	if(playlistID>0){
		url += "&p=" + playlistID;
		//alert(url);
	}
  cst_sp_player_win = window.open(url, "cst_sp_player_win", "width=980,height=640,left="+leftPos+",top="+topPos);
}

function loadAjaxControl(controlName, method, vars, divToUpdate){
  if(controlName){
    xmlHttp = GetXmlHttpObject();
    if(xmlHttp == null){
      alert("Browser does not support HTTP Request");
      return;
    }
    var url = "/mcc/ajax_controls/" + controlName + ".php";
    if(!method){
      method = "get";
    }
    if(method=="get"){
      url += "?" + vars + "&r=" + Math.random();
    }
    xmlHttp.onreadystatechange = function(){
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
        if(document.getElementById(divToUpdate)){
          document.getElementById(divToUpdate).innerHTML = xmlHttp.responseText;
        }
      }
    }
    xmlHttp.open(method,url,true);
    xmlHttp.send(null);
  }
}
 
function updateLiveEventStatus(liveEventID,status){
  url = "/mcc/scripts/process.html?cmd=57&liveEventID=" + liveEventID + "&status=" + status;
  xmlHttp = GetXmlHttpObject();
  if(xmlHttp == null){
    alert("Browser does not support HTTP Request");
    return;
  }
  xmlHttp.onreadystatechange = function(){
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
      if(xmlHttp.responseText=="1"){
        alert("Live Event Status Updated");
      }
      else{
        alert("Error setting live event status!");
      }
    }
  }
  xmlHttp.open('get',url,true);
  xmlHttp.send(null);
}

function addEmailContentVideo(contentID,fileID){
  xmlHttp_addEmailContentVideo=GetXmlHttpObject()
  if(xmlHttp_addEmailContentVideo==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/scripts/process.html?cmd=40&contentID="+contentID+"&fileID="+fileID+"&r="+Math.random();
  xmlHttp_addEmailContentVideo.onreadystatechange=addEmailContentVideo2
  xmlHttp_addEmailContentVideo.open("GET",url,true)
  xmlHttp_addEmailContentVideo.send(null)
}

function addEmailContentVideo2(){
  if (xmlHttp_addEmailContentVideo.readyState==4 || xmlHttp_addEmailContentVideo.readyState=="complete"){
    //document.myForm.recipientCount.value=xmlHttp_checkEmailRecipients.responseText;
    if(xmlHttp_addEmailContentVideo.responseText==1){
      // refresh
      reloadEmailVideoContentList();
    }
  }
}

function addEmailContentPdf(contentID,fileID){
  xmlHttp_addEmailContentPdf=GetXmlHttpObject()
  if(xmlHttp_addEmailContentPdf==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/scripts/process.html?cmd=42&contentID="+contentID+"&fileID="+fileID+"&r="+Math.random();
  xmlHttp_addEmailContentPdf.onreadystatechange=addEmailContentPdf2
  xmlHttp_addEmailContentPdf.open("GET",url,true)
  xmlHttp_addEmailContentPdf.send(null)
}

function addEmailContentPdf2(){
  if (xmlHttp_addEmailContentPdf.readyState==4 || xmlHttp_addEmailContentPdf.readyState=="complete"){
    //document.myForm.recipientCount.value=xmlHttp_checkEmailRecipients.responseText;
    if(xmlHttp_addEmailContentPdf.responseText==1){
      // refresh
      reloadEmailPdfContentList();
    }
  }
}

function addUserAccount(userID,accountID,mccGroupID){
  if((!userID)||(!accountID)||(!mccGroupID)){
    return false
  }
  xmlHttp3=GetXmlHttpObject()
  if(xmlHttp3==null){
    alert ("Browser does not support HTTP Request")
    return false
  }
  var url="/mcc/ajax_controls/display_user_accounts_dropdown_add.php?mccGroupID="+mccGroupID+"&userID="+userID+"&cmd=1&accountID="+accountID
  xmlHttp3.onreadystatechange=addUserAccount2
  xmlHttp3.open("GET",url,true)
  xmlHttp3.send(null)
  // update ajax controls
}

function addUserAccount2(){
  if (xmlHttp3.readyState==4 || xmlHttp3.readyState=="complete"){
    document.getElementById("divAddAccount").innerHTML=xmlHttp3.responseText;
    xmlHttp4=GetXmlHttpObject()
    if(xmlHttp4==null){
      alert ("Browser does not support HTTP Request")
      return
    }
    var url="/mcc/ajax_controls/display_user_groups.php?mccGroupID="+global_mccGroupID+"&userID="+global_userID
    xmlHttp4.onreadystatechange=addUserAccount3
    xmlHttp4.open("GET",url,true)
    xmlHttp4.send(null)
  }
}

function addUserAccount3(){
  if (xmlHttp4.readyState==4 || xmlHttp4.readyState=="complete"){
    document.getElementById("divCurrentAccess").innerHTML=xmlHttp4.responseText;
  }
}

function analyzeFile(file,accountID){
  url = "http://media.d1tv.net/mcc/scripts/start_analyze_file.html?accountID="+accountID+"&file="+file;
  if(screen){
    leftPos=screen.width-400;
    leftPos=(leftPos/2)-5;
    topPos=screen.height-300;
    topPos=(topPos/2)-30;
  }
  mccAnalyzeUploadWin=window.open(url, "mccAnalyzeUploadWin", "width=400,height=300,left="+leftPos+",top="+topPos);
}

function bandwidthToggleHistory(type){
  switch(type){
    case "m":
      document.getElementById('divDays').style.display='none';
      document.getElementById('divWeeks').style.display='none';
      document.getElementById('divMonths').style.display='block';
      document.getElementById('divLinkDays').innerHTML = "<a href=\"#\" onClick=\"bandwidthToggleHistory('d');return false;\" class='copy'>5 Days</a>";
      document.getElementById('divLinkWeeks').innerHTML = "<a href=\"#\" onClick=\"bandwidthToggleHistory('w');return false;\" class='copy'>5 Weeks</a>";
      document.getElementById('divLinkMonths').innerHTML = "5 Months";
      break;
    case "w":
      document.getElementById('divDays').style.display='none';
      document.getElementById('divMonths').style.display='none';
      document.getElementById('divWeeks').style.display='block';
      document.getElementById('divLinkDays').innerHTML = "<a href=\"#\" onClick=\"bandwidthToggleHistory('d');return false;\" class='copy'>5 Days</a>";
      document.getElementById('divLinkMonths').innerHTML = "<a href=\"#\" onClick=\"bandwidthToggleHistory('m');return false;\" class='copy'>5 Months</a>";
      document.getElementById('divLinkWeeks').innerHTML = "5 Weeks";
      break;
    case "d":
      document.getElementById('divMonths').style.display='none';
      document.getElementById('divWeeks').style.display='none';
      document.getElementById('divDays').style.display='block';
      document.getElementById('divLinkMonths').innerHTML = "<a href=\"#\" onClick=\"bandwidthToggleHistory('m');return false;\" class='copy'>5 Months</a>";
      document.getElementById('divLinkWeeks').innerHTML = "<a href=\"#\" onClick=\"bandwidthToggleHistory('w');return false;\" class='copy'>5 Weeks</a>";
      document.getElementById('divLinkDays').innerHTML = "5 Days";
      break;
  }
}

function changePerPage(sel,cur,url){
  if(sel!=cur){
    str = "limit=" + cur
    newStr = "limit=" + sel
    url = url.replace(str,newStr)
    window.location = url
  }
}

function changeMenu(div,expand){
	if((div)&&(expand)){
		if(document.getElementById(div)){
			theCell = document.getElementById(div).style;
			if(theCell.display=="none"){
				theCell.display="block";
				if(document[expand]){
					document[expand].src="../images/collapse.gif";
				}
			}
			else{
				theCell.display="none";
				if(document[expand]){
					document[expand].src="../images/expand.gif";
				}
			}
		}
	}
}

function checkEmailRecipients(jobID){
  // Verifies number of recipients before pressing 'submit' and scheduling email job //
  xmlHttp_checkEmailRecipients=GetXmlHttpObject()
  if(xmlHttp_checkEmailRecipients==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/get_email_recipient_count.php?jobID="+jobID+"&r="+Math.random();
  xmlHttp_checkEmailRecipients.onreadystatechange=checkEmailRecipients2
  xmlHttp_checkEmailRecipients.open("GET",url,true)
  xmlHttp_checkEmailRecipients.send(null)
}

function checkEmailRecipients2(){
  if (xmlHttp_checkEmailRecipients.readyState==4 || xmlHttp_checkEmailRecipients.readyState=="complete"){
    document.myForm.recipientCount.value=xmlHttp_checkEmailRecipients.responseText;
  }
}

function checkForm(vars){
  form = document.myForm;
  arrVars = vars.split(",");
  for(x=0;x<arrVars.length;x++){
    myVar = arrVars[x];
    if(!form[myVar].value){
      alert("Please complete the field");
      form.myVar.focus();
    }
    else{
      alert(form[myVar].value);
    }
  }
  //return false;
}

function confirmDelete(what,url){
  var agree=confirm("Are you sure you wish to delete this "+what+"?\r\nThis action cannot be undone!");
  if(agree){
    window.location=url;
  }
}

function confirmContactsDelete(what,url){
    var delete_contacts = myform.delete_groups_contacts.checked;
	  var agree = null;
	  if(delete_contacts ){
		  agree = confirm("You have chosen to delete this group and all associated contacts.\r\nThis action cannot be undone!");
		  if(agree){
			  url += '&deleteContacts=true';
			  confirmDelete(what,url);
		  }
	  }
	  else{
		  confirmDelete(what,url);
	  }
} 

function selectAll(obj){
	if(obj.innerHTML == 'Select All'){
		obj.innerHTML = 'Deselect All';
		with(document.entries) {
			for(var i = 0; i < entry.length; i++){
				entry[i].checked = 'checked';
			}
		}
		if(document.entries.entry.value){
			document.entries.entry.checked = 'checked';
		}
	}
	else{
		obj.innerHTML = 'Select All';
		with(document.entries) {
			for(var i = 0; i < entry.length; i++){
				entry[i].checked = '';
			}
		}
		if(document.entries.entry.value){
			document.entries.entry.checked = '';
		}
	}
	return false;
}

function confirmSelectedDelete(cmd){
	var contact_list = "";
	with(document.entries) {
		for(var i = 0; i < entry.length; i++){
			if(entry[i].checked) {
				contact_list += entry[i].value + "|";
			}
		}
	}
	if(contact_list == "") {
		if(document.entries.entry.value && document.entries.entry.checked){
			if(confirm('You have chosen to delete the selected entry.\r\nThis action cannot be undone!')){
				window.location = '/mcc/scripts/process.html?cmd='+cmd+'&data='+document.entries.entry.value;				
			}
			return false;
		}
		else{
			alert("No entries selected for deletion.");
			return false;
		}
	}
	if(confirm('You have chosen to delete the selected entries.\r\nThis action cannot be undone!')){
		window.location = '/mcc/scripts/process.html?cmd='+cmd+'&data='+contact_list;
	}
	return false;
} 

function deleteEmailContentVideo(contentID,offset){
  xmlHttp_deleteEmailContentVideo=GetXmlHttpObject()
  if(xmlHttp_deleteEmailContentVideo==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/scripts/process.html?cmd=39&contentID="+contentID+"&offset="+offset+"&r="+Math.random();
  xmlHttp_deleteEmailContentVideo.onreadystatechange=deleteEmailContentVideo2
  xmlHttp_deleteEmailContentVideo.open("GET",url,true)
  xmlHttp_deleteEmailContentVideo.send(null)
}

function deleteEmailContentVideo2(){
  if (xmlHttp_deleteEmailContentVideo.readyState==4 || xmlHttp_deleteEmailContentVideo.readyState=="complete"){
    if(xmlHttp_deleteEmailContentVideo.responseText==1){
      // refresh
      reloadEmailVideoContentList();
    }
  }
}

function deleteEmailContentPdf(contentID,offset){
  xmlHttp_deleteEmailContentPdf=GetXmlHttpObject()
  if(xmlHttp_deleteEmailContentPdf==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/scripts/process.html?cmd=39&contentID="+contentID+"&offset="+offset+"&r="+Math.random();
  xmlHttp_deleteEmailContentPdf.onreadystatechange=deleteEmailContentPdf2
  xmlHttp_deleteEmailContentPdf.open("GET",url,true)
  xmlHttp_deleteEmailContentPdf.send(null)
}

function deleteEmailContentPdf2(){
  if (xmlHttp_deleteEmailContentPdf.readyState==4 || xmlHttp_deleteEmailContentPdf.readyState=="complete"){
    if(xmlHttp_deleteEmailContentPdf.responseText==1){
      // refresh
      reloadEmailPdfContentList();
    }
  }
}

function deleteEmailPdf(pdfID){
  if(confirm("Do you really want to delete this PDF? This action cannot be undone!")){
    xmlHttp_deleteEmailPdf=GetXmlHttpObject()
    if(xmlHttp_deleteEmailPdf==null){
      alert ("Browser does not support HTTP Request")
      return
    }
    var url="/mcc/scripts/process.html?cmd=43&pdfID="+pdfID+"&r="+Math.random();
    xmlHttp_deleteEmailPdf.onreadystatechange=deleteEmailPdf2
    xmlHttp_deleteEmailPdf.open("GET",url,true)
    xmlHttp_deleteEmailPdf.send(null)
  }
}

function deleteEmailPdf2(){
  if(xmlHttp_deleteEmailPdf.readyState==4||xmlHttp_deleteEmailPdf.readyState=="complete"){
    if(xmlHttp_deleteEmailPdf.responseText==1){
      // refresh
      reloadEmailPdfContentOnly();
    }
  }
}

function doLinkForm(){
  result = "";
  // myForm = document.myForm;
  playlist = document.myForm.playlist.value;
  file = document.myForm.file.value;
  backgroundURL = document.myForm.url.value;
  account = document.myForm.account.value;
	var config_key = document.myForm.sp_design_config.value;
  var emailAddress = "";
  ref = "";
  if(document.myForm.linkType[1].checked){
    var type = "url";
  }
  else{
    var type = "js";
  }
  
  //if(myForm.linkType[1].checked){
  //  result = "http://media.d1tv.net/gateway/link/launch.html?account="+account+"&playlist="+playlist+"&clip="+clip+"&backgroundURL="+backgroundURL;
  //}
  //else{
  //  result = "<script type=\"text/javascript\" language=\"javascript\" src=\"http://media.d1tv.net/gateway/link/d1_mpi_link.js?account="+account+"&playlist="+playlist+"&clip="+clip+"&backgroundURL="+backgroundURL+"\"></script>";
  //  result2 = "<script type=\"text/javascript\" language=\"javascript\">";
  //  result3 = "launchPlayer('"+playlist+"','"+clip+"','"+emailAddress+"','"+ref+"');"
  //  result4 = "</script>";
  //  result = result + "\r\n" + result2 + "\r\n" + result3 + "\r\n" + result4;
  //}
  //myForm.result.value=result;
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/generate_link.php?type="+type+"&c="+config_key+"&account="+account+"&playlist="+playlist+"&file="+file+"&backgroundURL="+backgroundURL+"&r="+Math.random();
  xmlHttp.onreadystatechange=doLinkForm2
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
  return false;
}

function doLinkForm2(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    document.getElementById("divLinkResults").innerHTML=xmlHttp.responseText;
  }
}

function dumpPlainTextEmail(){
  document.getElementById("divDumpPlainTextProgressImageOff").style.visibility='hidden';
  document.getElementById("divDumpPlainTextProgressImageOn").style.visibility='visible';
  xmlHttp12=GetXmlHttpObject()
  if(xmlHttp12==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/email_strip_html.php"
  xmlHttp12.onreadystatechange=dumpPlainTextEmail2
  xmlHttp12.open("POST",url,true)
  xmlHttp12.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
  code = document.myForm.wysiwyg.value
  code = code.replace(/&/g,"*am*")
  code = code.replace(/=/g,"*eq*")
  xmlHttp12.send('code='+code)
  alert(code)
  return false;
}

function dumpPlainTextEmail2(){
  if (xmlHttp12.readyState==4 || xmlHttp12.readyState=="complete"){
    document.myForm.plainText.value=xmlHttp12.responseText;
    document.getElementById("divDumpPlainTextProgressImageOn").style.visibility='hidden';
    document.getElementById("divDumpPlainTextProgressImageOff").style.visibility='visible';
  }
}

function generateRandomPassword(){
  xmlHttp8=GetXmlHttpObject()
  if(xmlHttp8==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  document.getElementById("divProgressImage").style.visibility='visible';
  var url="/mcc/ajax_controls/generate_password.php"
  xmlHttp8.onreadystatechange=generateRandomPassword2
  xmlHttp8.open("GET",url,true)
  xmlHttp8.send(null)
  return false;
}

function generateRandomPassword2(){
  if (xmlHttp8.readyState==4 || xmlHttp8.readyState=="complete"){
    document.myForm.password.value=xmlHttp8.responseText;
    document.getElementById("divProgressImage").style.visibility='hidden';
  }
}

function GetXmlHttpObject(handler){ 
  var objXMLHttp=null
  if (window.XMLHttpRequest){
    objXMLHttp=new XMLHttpRequest()
  }
  else if (window.ActiveXObject){
    objXMLHttp=new ActiveXObject("Microsoft.XMLHTTP")
  }
  return objXMLHttp
}

function loadAccountSummary(){
  xmlHttp_accountSummary=GetXmlHttpObject()
  if(xmlHttp_accountSummary==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/account_summary.php"
  xmlHttp_accountSummary.onreadystatechange=loadAccountSummary2
  xmlHttp_accountSummary.open("GET",url,true)
  xmlHttp_accountSummary.send(null)
  return false;
}

function loadAccountSummary2(){
  if (xmlHttp_accountSummary.readyState==4 || xmlHttp_accountSummary.readyState=="complete"){
    document.getElementById('divAccountSummary').innerHTML=xmlHttp_accountSummary.responseText;
  }
}

function loadContactsDropDown(addContactsSelectName){
  xmlHttp_contactsDropDown=GetXmlHttpObject()
  if(xmlHttp_contactsDropDown==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/send_email_contacts_dropdown.php?addContactsSelectName="+addContactsSelectName+"&r="+Math.random();
  xmlHttp_contactsDropDown.onreadystatechange=loadContactsDropdown2
  xmlHttp_contactsDropDown.open("GET",url,true)
  xmlHttp_contactsDropDown.send(null)
  return false;
}

function loadContactsDropdown2(){
  if (xmlHttp_contactsDropDown.readyState==4 || xmlHttp_contactsDropDown.readyState=="complete"){
    document.getElementById('divContactsDropDown').innerHTML=xmlHttp_contactsDropDown.responseText;
  }
}

function loadContactsInGroup(groupID){
  xmlHttp_contactsInGroup=GetXmlHttpObject()
  if(xmlHttp_contactsInGroup==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/group_contacts_in_group.php?groupID="+groupID+"&r="+Math.random();
  xmlHttp_contactsInGroup.onreadystatechange=loadContactsInGroup2
  xmlHttp_contactsInGroup.open("GET",url,true)
  xmlHttp_contactsInGroup.send(null)
  return false;
}

function loadContactsInGroup2(){
  if (xmlHttp_contactsInGroup.readyState==4 || xmlHttp_contactsInGroup.readyState=="complete"){
    document.getElementById('divContactsInGroup').innerHTML=xmlHttp_contactsInGroup.responseText;
  }
}

function loadContactsNotInGroup(groupID){
  xmlHttp_contactsNotInGroup=GetXmlHttpObject()
  if(xmlHttp_contactsNotInGroup==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/group_contacts_not_in_group.php?groupID="+groupID+"&r="+Math.random();
  xmlHttp_contactsNotInGroup.onreadystatechange=loadContactsNotInGroup2
  xmlHttp_contactsNotInGroup.open("GET",url,true)
  xmlHttp_contactsNotInGroup.send(null)
  return false;
}

function loadContactsNotInGroup2(){
  if (xmlHttp_contactsNotInGroup.readyState==4 || xmlHttp_contactsNotInGroup.readyState=="complete"){
    document.getElementById('divContactsNotInGroup').innerHTML=xmlHttp_contactsNotInGroup.responseText;
  }
}

function loadEmailPdfContent(contentID){
  xmlHttp_emailPdfContent=GetXmlHttpObject()
  if(xmlHttp_emailPdfContent==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/email/ajax/pdf_content.php?contentID="+contentID+"&r="+Math.random();
  xmlHttp_emailPdfContent.onreadystatechange=loadEmailPdfContent2
  xmlHttp_emailPdfContent.open("GET",url,true)
  xmlHttp_emailPdfContent.send(null)
  return false;
}

function loadEmailPdfContent2(){
  if (xmlHttp_emailPdfContent.readyState==4 || xmlHttp_emailPdfContent.readyState=="complete"){
    document.getElementById('divPdfContent').innerHTML=xmlHttp_emailPdfContent.responseText;
  }
}

function loadEmailPdfContentList(contentID){
  xmlHttp_emailPdfContentList=GetXmlHttpObject()
  if(xmlHttp_emailPdfContentList==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/email/ajax/pdf_content_list.php?contentID="+contentID+"&r="+Math.random();
  xmlHttp_emailPdfContentList.onreadystatechange=loadEmailPdfContentList2
  xmlHttp_emailPdfContentList.open("GET",url,true)
  xmlHttp_emailPdfContentList.send(null)
  return false;
}

function loadEmailPdfContentList2(){
  if (xmlHttp_emailPdfContentList.readyState==4 || xmlHttp_emailPdfContentList.readyState=="complete"){
    document.getElementById('divPdfContentList').innerHTML=xmlHttp_emailPdfContentList.responseText;
  }
}

function loadEmailVideoContentPlaylist(contentID,playlist){
  xmlHttp_loadEmailVideoContentPlaylist=GetXmlHttpObject()
  if(xmlHttp_loadEmailVideoContentPlaylist==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/scripts/process.html?cmd=41&contentID="+contentID+"&playlist="+playlist+"&r="+Math.random();
  xmlHttp_loadEmailVideoContentPlaylist.onreadystatechange=loadEmailVideoContentPlaylist2
  xmlHttp_loadEmailVideoContentPlaylist.open("GET",url,true)
  xmlHttp_loadEmailVideoContentPlaylist.send(null)
  return false;
}

function loadEmailVideoContentPlaylist2(){
  if (xmlHttp_loadEmailVideoContentPlaylist.readyState==4 || xmlHttp_loadEmailVideoContentPlaylist.readyState=="complete"){
    if(xmlHttp_loadEmailVideoContentPlaylist.responseText==1){
      reloadEmailVideoContent();
    }
  }
}

function loadEmailVideoContent(contentID,campaignID){
  xmlHttp_emailVideoContent=GetXmlHttpObject()
  if(xmlHttp_emailVideoContent==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/email/ajax/video_content.php?contentID="+contentID+"&campaignID="+campaignID+"&r="+Math.random();
  xmlHttp_emailVideoContent.onreadystatechange=loadEmailVideoContent2
  xmlHttp_emailVideoContent.open("GET",url,true)
  xmlHttp_emailVideoContent.send(null)
  return false;
}

function loadEmailVideoContent2(){
  if (xmlHttp_emailVideoContent.readyState==4 || xmlHttp_emailVideoContent.readyState=="complete"){
    document.getElementById('divVideoContent').innerHTML=xmlHttp_emailVideoContent.responseText;
  }
}

function loadEmailVideoContentList(contentID){
  xmlHttp_emailVideoContentList=GetXmlHttpObject()
  if(xmlHttp_emailVideoContentList==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/email/ajax/video_content_list.php?contentID="+contentID+"&r="+Math.random();
  xmlHttp_emailVideoContentList.onreadystatechange=loadEmailVideoContentList2
  xmlHttp_emailVideoContentList.open("GET",url,true)
  xmlHttp_emailVideoContentList.send(null)
  return false;
}

function loadEmailVideoContentList2(){
  if (xmlHttp_emailVideoContentList.readyState==4 || xmlHttp_emailVideoContentList.readyState=="complete"){
    document.getElementById('divVideoContentList').innerHTML=xmlHttp_emailVideoContentList.responseText;
  }
}

function loadGroupMembers(groupID){
  xmlHttp_groupMembers=GetXmlHttpObject()
  if(xmlHttp_groupMembers==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/group_list_members.php?groupID="+groupID+"&r="+Math.random();
  xmlHttp_groupMembers.onreadystatechange=loadGroupMembers2
  xmlHttp_groupMembers.open("GET",url,true)
  xmlHttp_groupMembers.send(null)
  return false;
}

function loadGroupMembers2(){
  if (xmlHttp_groupMembers.readyState==4 || xmlHttp_groupMembers.readyState=="complete"){
    document.getElementById('divGroupMembers').innerHTML=xmlHttp_groupMembers.responseText;
  }
}

function loadGroupsDropDown(addGroupSelectName){
  xmlHttp_groupsDropDown=GetXmlHttpObject()
  if(xmlHttp_groupsDropDown==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/send_email_groups_dropdown.php?addGroupSelectName="+addGroupSelectName+"&r="+Math.random();
  xmlHttp_groupsDropDown.onreadystatechange=loadGroupsDropdown2
  xmlHttp_groupsDropDown.open("GET",url,true)
  xmlHttp_groupsDropDown.send(null)
  return false;
}

function loadGroupsDropdown2(){
  if (xmlHttp_groupsDropDown.readyState==4 || xmlHttp_groupsDropDown.readyState=="complete"){
    document.getElementById('divGroupsDropDown').innerHTML=xmlHttp_groupsDropDown.responseText;
  }
}

function loadOeTask(task,id){
  switch(task){
     case "iphone":
      url = "/mcc/ajax_controls/oe_task_custom.php?out=iphone&id=" + id + "&d=" + Date()
      break; 
    case "cst":
      url = "/mcc/ajax_controls/oe_task_cst.php?id=" + id + "&d=" + Date()
      break;
    case "youtube":
      url = "/mcc/ajax_controls/oe_task_youtube.php?id=" + id + "&d=" + Date()
      break;
    case "ipod":
      url = "/mcc/ajax_controls/oe_task_custom.php?out=ipod&id=" + id + "&d=" + Date()
      break;
    case "winmedia":
      url = "/mcc/ajax_controls/oe_task_custom.php?out=winmedia&id=" + id + "&d=" + Date()
      break;
    case "psp":
      url = "/mcc/ajax_controls/oe_task_custom.php?out=psp&id=" + id + "&d=" + Date()
      break;
    default:
      //url = "/mcc/ajax_controls/oe_task_cst.php?id=" + id + "&d=" + Date()
      //break;
  }
  // load it
  if(url){
    document.getElementById("divOeTask").innerHTML=""
    xmlHttp16=GetXmlHttpObject()
    if(xmlHttp16==null){
      alert ("Browser does not support HTTP Request")
      return
    }
    xmlHttp16.onreadystatechange=loadOeTask2
    xmlHttp16.open("GET",url,true)
    xmlHttp16.send(null)
  }
}

function loadOeTask2(){
  if (xmlHttp16.readyState==4 || xmlHttp16.readyState=="complete"){
    document.getElementById("divOeTask").innerHTML=xmlHttp16.responseText;
  }
}

function oe_loadThumbnailSelection(uploadID){
  if(uploadID){
    document.getElementById("divThumbnailSelection").style.display='block'
    xmlHttp18=GetXmlHttpObject()
    if(xmlHttp18==null){
      alert ("Browser does not support HTTP Request")
      return
    }
    var url="/mcc/ajax_controls/oe_thumbnail_selection.php?uploadID=" + uploadID
    xmlHttp18.onreadystatechange=oe_loadThumbnailSelection2
    xmlHttp18.open("GET",url,true)
    xmlHttp18.send(null)
  }
}

function oe_loadThumbnailSelection2(){
  if (xmlHttp18.readyState==4 || xmlHttp18.readyState=="complete"){
    document.getElementById("divThumbnailSelection").innerHTML=xmlHttp18.responseText
  }
}

function oe_updateThumbnailSelection(id,numCells){
  for(x=1;x<=numCells;x++){
    clear="thumbCell_"+x
    if(x%2==0){
      // even
      bgc = "#f5f9fd"
    }
    else{
      bgc = "#ffffff"
    }
    border = "3px solid " + bgc;
    document.getElementById(clear).style.backgroundColor=bgc
    document.getElementById(clear).style.border=border
  }
  border = "3px solid #336699"
  //ocument.getElementById(id).style.backgroundColor="#ffffc0"
  document.getElementById(id).style.border=border
  document.myForm.selectedThumbnailID.value=id
}

function remUserAccount(userID,accountID,mccGroupID){
  if((!userID)||(!accountID)||(!mccGroupID)){
    return false
  }
  xmlHttp5=GetXmlHttpObject()
  if(xmlHttp5==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/display_user_accounts_dropdown_rem.php?mccGroupID="+mccGroupID+"&userID="+userID+"&cmd=1&accountID="+accountID
  xmlHttp5.onreadystatechange=remUserAccount2
  xmlHttp5.open("GET",url,true)
  xmlHttp5.send(null)
  // update ajax controls
}

function remUserAccount2(){
  if (xmlHttp5.readyState==4 || xmlHttp5.readyState=="complete"){
    document.getElementById("divRemAccount").innerHTML=xmlHttp5.responseText;
    xmlHttp6=GetXmlHttpObject()
    if(xmlHttp6==null){
      alert ("Browser does not support HTTP Request")
      return
    }
    var url="/mcc/ajax_controls/display_user_groups.php?mccGroupID="+global_mccGroupID+"&userID="+global_userID
    xmlHttp6.onreadystatechange=remUserAccount3
    xmlHttp6.open("GET",url,true)
    xmlHttp6.send(null)
  }
}

function remUserAccount3(){
  if (xmlHttp6.readyState==4 || xmlHttp6.readyState=="complete"){
    document.getElementById("divCurrentAccess").innerHTML=xmlHttp6.responseText;
  }
}

function setColumn(type,column){
  form = document.myForm
  myVar = "var_" + type
  form[myVar].value = column
}

function stateChanged(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    document.getElementById("divEmailClips").innerHTML=xmlHttp.responseText;
  }
}

function submitEmailClipsForm(){
  if(!isPdfUpload){
    document.myForm.cmd.value = 44;
  }
  else{
    if(!document.myForm.name.value){
      alert("You must assign your PDF a NAME before uploading");
      document.myForm.name.focus();
      return false;
    }
    document.getElementById('divPdfUploadForm').style.visibility='hidden';
    document.getElementById('divPdfUploadStatus').style.visibility='visible';
    document.myForm.target = "iframeProcessForm";
    document.myForm.cmd.value = 38;
  }
  return true;
}

function submitSpreadsheetForm(){
  document.getElementById('divUpdate').innerHTML = "Processing...";
}

function switchAccount(accountID){
  if(accountID!=0){
    url = "../auth/switch_account.html?accountID="+accountID;
    window.location = url;
  }
}

function switchCategory(id,categories){
  // hide all text boxes
  for (var c=0;c<categories.length;c++){
    cat = "divCat_"+categories[c];
    document.getElementById(cat).style.visibility='hidden';
  }
  cat = "divCat_"+id;
  document.getElementById(cat).style.visibility='visible';
  currentCat = id;
}

function switchSourceAccount(accountID){
  if(!accountID){
    return false
  }
  document.getElementById("divAccountFiles").innerHTML = "<center><img src=../images/progress.gif> <span class=copy></center>"
  xmlHttp9=GetXmlHttpObject()
  if(xmlHttp9==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/update_import_file.php?accountID="+accountID
  xmlHttp9.onreadystatechange=switchSourceAccount2
  xmlHttp9.open("GET",url,true)
  xmlHttp9.send(null)
}

function switchSourceAccount2(){
  if (xmlHttp9.readyState==4 || xmlHttp9.readyState=="complete"){
    document.getElementById("divAccountFiles").innerHTML=xmlHttp9.responseText;
  }
}

function toggleDivs(divs,div){
  divs = divs.split('|');
  for(x=0;x<divs.length;x++){
    myDiv = divs[x];
    myDiv2 = "divNav_"+myDiv;
    //alert(myDiv);
    document.getElementById(myDiv2).style.backgroundColor = '#e0ebf6';
    document.getElementById(myDiv2).className = "tableHeader";
    myDiv3 = "divContent_"+myDiv;
    document.getElementById(myDiv3).style.display='none';
  }
  myDiv = "divNav_"+div;
  document.getElementById(myDiv).style.backgroundColor = '#336699';
  document.getElementById(myDiv).className = "tableHeaderW";
  myDiv = "divContent_"+div;
  document.getElementById(myDiv).style.display='block';
}

function toggleEmailTemplate(templateID,templates){
  var arrTemplates = templates.split(",")
  for(i=0;i<arrTemplates.length;i++) {
    id = arrTemplates[i];
    var img = "imgCheckbox_"+id
    document.images[img].src='../images/check_off.gif';
  }
  var img = "imgCheckbox_"+templateID
  document.images[img].src='../images/check_on.gif';
  document.myForm.templateID.value=templateID
}

function toggleEmailVideo(clipID){
  var inArray = js_in_array(clipID, arrFiles);
  if(!inArray){
    // not included, add it!
    arrFiles.push(clipID);
    // update image
    var img = "imgCheckbox_"+clipID;
    document.images[img].src='../images/check_on.gif';
  }
  else{
    arrTempFiles = new Array();
    for(i=0;i<arrFiles.length;i++) {
      id = arrFiles[i];
      if(id!=clipID){
        arrTempFiles.push(id);
      }
    }
    arrFiles = arrTempFiles;
    var img = "imgCheckbox_"+clipID;
    document.images[img].src='../images/check_off.gif';
  }
}

function toggleImportSourceFile(fileID,files){
  var arrFiles = files.split(",")
  for(i=0;i<arrFiles.length;i++) {
    id = arrFiles[i];
    var img = "imgCheckbox_"+id
    document.images[img].src='../images/check_off.gif';
  }
  var img = "imgCheckbox_"+fileID
  document.images[img].src='../images/check_on.gif';
  document.myForm.importFileID.value=fileID
}

function toggleLinkVideo(clip,files){
  var arrFiles = files.split(",")
  for(i=0;i<arrFiles.length;i++) {
    name = arrFiles[i];
    var img = "imgCheckbox_"+name
    document.images[img].src='../images/check_off.gif';
  }
  var img = "imgCheckbox_"+clip
  document.images[img].src='../images/check_on.gif';
  document.myForm.file.value=clip
}

function toggleSendEmailDate(state){
  if(state){
    document.getElementById("divSendEmailDate").style.display='block';
  }
  else{
    document.getElementById("divSendEmailDate").style.display='none';
  }
}

function updateClipsView(playlist,accountID,clips){
  if(playlist==0){
    return false
  }
  document.getElementById("divClipsView").innerHTML = "<center><img src=../images/progress.gif> <span class=copy></center>"
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/manage_clips_view.php?accountID="+accountID+"&playlist="+playlist+"&clips="+clips
  xmlHttp.onreadystatechange=updateClipsView2
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateClipsView2(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    document.getElementById("divClipsView").innerHTML=xmlHttp.responseText;
  }
}

function updateClipsView3(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    d = document.getElementById("iframeEmailRecipients");
    //alert(d);
    //alert(d.contentWindow);
    //    alert(d.contentWindow.document);
    d.contentWindow.document.getElementById("divEmailRecipients").innerHTML=xmlHttp.responseText;
  }
}

function updateEmailCampaignStats(){
  xmlHttp14=GetXmlHttpObject()
  if(xmlHttp14==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/email_campaign_stats.php?" + Math.random();
  xmlHttp14.onreadystatechange=updateEmailCampaignStats2
  xmlHttp14.open("GET",url,true)
  xmlHttp14.send(null)
}

function updateEmailCampaignStats2(){
  if (xmlHttp14.readyState==4 || xmlHttp14.readyState=="complete"){
    document.getElementById("divEmailCampaignStats").innerHTML=xmlHttp14.responseText;
  }
}

function updateEmailClips(playlist,accountID,clips){
  arrFiles = null;
  arrFiles = new Array();
  // refill with orig
  for(x=0;x<arrFilesOrig.length;x++){
    arrFiles.push(arrFilesOrig[x]);
  }
  if(playlist==0){
    return false
  }
  document.getElementById("divEmailClips").innerHTML = "<center><img src=../images/progress.gif> <span class=copy></center>"
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return false
  }
  var url="/mcc/ajax_controls/email_update_clips.php?accountID="+accountID+"&playlist="+playlist+"&clips="+clips
  xmlHttp.onreadystatechange=updateClipsView2
  xmlHttp.onreadystatechange=stateChanged
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateEmailPdfs(accountID){
  document.getElementById("divEmailPdfs").innerHTML = "<center><img src=../images/progress.gif> <span class=copy></center>"
  xmlHttp_emailPdfs=GetXmlHttpObject()
  if(xmlHttp_emailPdfs==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/email_update_pdfs.php?accountID="+accountID
  xmlHttp_emailPdfs.onreadystatechange=updateEmailPdfs2
  xmlHttp_emailPdfs.open("GET",url,true)
  xmlHttp_emailPdfs.send(null)
}

function updateEmailPdfs2(){
  if (xmlHttp_emailPdfs.readyState==4 || xmlHttp_emailPdfs.readyState=="complete"){
    document.getElementById("divEmailPdfs").innerHTML=xmlHttp_emailPdfs.responseText;
  }
}

function updateEmailRecipients(emailJobID,contactType,id,state){
  if(emailJobID==0){
    return false
  }
  d = document.getElementById("iframeEmailRecipients");
  d.contentWindow.document.getElementById("divEmailRecipients").innerHTML="<center><img src=../images/progress.gif> <span class=copy>Working... Please wait...</center>"
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/email_update_recipients.php?emailJobID="+emailJobID+"&state="+state+"&contactType="+contactType+"&id="+id
  xmlHttp.onreadystatechange=updateClipsView3
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateFiles(showHiddenFiles){
	var show_hidden;
	try { show_hidden = ($('show_hidden_files').checked)?1:0; } catch (e) {  show_hidden = 0; }
	
  	xmlHttp10=GetXmlHttpObject()
  	if(xmlHttp10==null){
   	 	alert ("Browser does not support HTTP Request")
   		return
  	}
  	var url="/mcc/ajax_controls/list_files.php?showHiddenFiles=" + show_hidden + "&r=" + Math.random();
  	xmlHttp10.onreadystatechange=updateFiles2
  	xmlHttp10.open("GET",url,true)
  	xmlHttp10.send(null)	
  //document.getElementById("divFiles").innerHTML = "<center><img src=../images/progress.gif> <span class=copy></center>"
}

function updateFiles2(){
  if (xmlHttp10.readyState==4 || xmlHttp10.readyState=="complete"){
    document.getElementById("divFiles").innerHTML=xmlHttp10.responseText;
  }
}

function updateLiveEvents(){
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/list_files.php?isLiveEvents=1&r=" + Math.random();
  xmlHttp.onreadystatechange = function() {
    if((xmlHttp.readyState == 4) || (xmlHttp.readyState=="complete")) {
      document.getElementById("divLiveEvents").innerHTML=xmlHttp.responseText;
    }
  }
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateEmailRecipientsManual(emailJobID,mccGroupID,accountID){
  var fname = document.myForm.manual_fname.value
  var lname = document.myForm.manual_lname.value
  var email = document.myForm.manual_email.value
  if(document.myForm.btnAddToContacts.checked){
    addToContacts = 1
  }
  else{
    addToContacts = 0
  }
  if(emailJobID==0){
    return false
  }
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/email_update_recipients.php?emailJobID="+emailJobID+"&state=1&contactType=3&fname="+fname+"&lname="+lname+"&email="+email+"&addToContacts="+addToContacts+"&mccGroupID="+mccGroupID+"&accountID="+accountID
  xmlHttp.onreadystatechange=updateClipsView3
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateOnlineEncodingFiles(sortBy,dir){
  xmlHttp15=GetXmlHttpObject()
  if(xmlHttp15==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/online_encoding_files_table.php?r=" + Math.random() + "&sort=" + sortBy + "&dir=" + dir;
  xmlHttp15.onreadystatechange=updateOnlineEncodingFiles2
  xmlHttp15.open("GET",url,true)
  xmlHttp15.send(null)
}

function updateOnlineEncodingFiles2(){
  if (xmlHttp15.readyState==4 || xmlHttp15.readyState=="complete"){
    document.getElementById("divOnlineEncodingFiles").innerHTML=xmlHttp15.responseText;
  }
}

function updateOnlineEncodingJobs(limit){
  xmlHttp17=GetXmlHttpObject()
  if(xmlHttp17==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  if(limit){
    var url="/mcc/ajax_controls/online_encoding_jobs.php?recent=1&" + Math.random();
  }
  else{
    var url="/mcc/ajax_controls/online_encoding_jobs.php?" + Math.random();
  }
  xmlHttp17.onreadystatechange=updateOnlineEncodingJobs2
  xmlHttp17.open("GET",url,true)
  xmlHttp17.send(null)
}

function updateOnlineEncodingJobs2(){
  if (xmlHttp17.readyState==4 || xmlHttp17.readyState=="complete"){
    document.getElementById("divOnlineEncodingJobs").innerHTML=xmlHttp17.responseText;
  }
}

function updateSelectAddGroupMember(contactID){
  if(contactID!=0){
    document.getElementById("divAddButton").style.visibility='visible';
  }
  else{
    document.getElementById("divAddButton").style.visibility='hidden';
  }
}

function updateSelectRemGroupMember(contactID){
  if(contactID!=0){
    document.getElementById("divRemButton").style.visibility='visible';
  }
  else{
    document.getElementById("divRemButton").style.visibility='hidden';
  }
}

function updateSpreadsheetUploadStatus(batchID){
  xmlHttp_spreadsheetUploadStatus=GetXmlHttpObject()
  if(xmlHttp_spreadsheetUploadStatus==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/email/ajax/get_contact_upload_batch_status.php?batchID="+batchID+"&d=" + Math.random();
  xmlHttp_spreadsheetUploadStatus.onreadystatechange=updateSpreadsheetUploadStatus2
  xmlHttp_spreadsheetUploadStatus.open("GET",url,true)
  xmlHttp_spreadsheetUploadStatus.send(null)
}

function updateSpreadsheetUploadStatus2(){
  if (xmlHttp_spreadsheetUploadStatus.readyState==4 || xmlHttp_spreadsheetUploadStatus.readyState=="complete"){
    arrStatus = xmlHttp_spreadsheetUploadStatus.responseText.split("|");
    if(arrStatus[0]==100){
      innerHTML = "<table cellspacing=0 cellpading=0 border=0><tr><td style='padding-right:5px;'><img src='../images/icons/32/check.png' /></td><td><strong>Spreadsheet import successful. "+arrStatus[1]+" new contacts added.</strong></td></tr></table>";
    }
    else if(arrStatus[0]==0){
      innerHTML = "<table cellspacing=0 cellpading=0 border=0><tr><td style='padding-right:5px;'><img src='../images/icons/32/wait.png' /></td><td><strong>Preparing spreadsheet for processing... Please wait...</strong></td></tr></table>";
    }
    else{
      innerHTML = "<table cellspacing=0 cellpading=0 border=0><tr><td style='padding-right:5px;'><img src='../images/icons/32/wait.png' /></td><td>Processing spreadsheet... <strong>" + arrStatus[0] + "% complete...</strong> Please wait...</td></tr></table>";
    }
    document.getElementById('divUpdate').innerHTML = innerHTML;
  }
}

function updateLinkFilesView(playlist,accountID){
  if(!playlist){
    return false
  }
  document.myForm.file.value = ""
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/link_update_files.php?playlist="+playlist+"&accountID="+accountID
  xmlHttp.onreadystatechange=updateLinkFilesView2
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateLinkFilesView2(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    document.getElementById("divPlaylistFiles").innerHTML=xmlHttp.responseText;
  }
}

function updateUploads(){
  xmlHttp11=GetXmlHttpObject()
  if(xmlHttp11==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/list_uploads.php?" + Math.random();
  xmlHttp11.onreadystatechange=updateUploads2
  xmlHttp11.open("GET",url,true)
  xmlHttp11.send(null)
}

function updateUploads2(){
  if (xmlHttp11.readyState==4 || xmlHttp11.readyState=="complete"){
    document.getElementById("divUploads").innerHTML=xmlHttp11.responseText;
  }
}

function updateUserGroups(mccGroupID,userID){
  if((!mccGroupID)||(!userID)){
    return false
  }
  xmlHttp=GetXmlHttpObject()
  if(xmlHttp==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/display_user_groups.php?mccGroupID="+mccGroupID+"&userID="+userID
  xmlHttp.onreadystatechange=updateUserGroups2
  xmlHttp.open("GET",url,true)
  xmlHttp.send(null)
}

function updateUserGroups2(){
  if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete"){
    document.getElementById("divCurrentAccess").innerHTML=xmlHttp.responseText;
  }
}

function updateUserGroupsAdd(mccGroupID,userID){
  if((!mccGroupID)||(!userID)){
    return false
  }
  xmlHttp2=GetXmlHttpObject()
  if(xmlHttp2==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/display_user_accounts_dropdown_add.php?mccGroupID="+mccGroupID+"&userID="+userID
  xmlHttp2.onreadystatechange=updateUserGroupsAdd2
  xmlHttp2.open("GET",url,true)
  xmlHttp2.send(null)
}

function updateUserGroupsAdd2(){
  if (xmlHttp2.readyState==4 || xmlHttp2.readyState=="complete"){
    document.getElementById("divAddAccount").innerHTML=xmlHttp2.responseText;
  }
}

function updateUserGroupsRem(mccGroupID,userID){
  if((!mccGroupID)||(!userID)){
    return false
  }
  xmlHttp7=GetXmlHttpObject()
  if(xmlHttp7==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/display_user_accounts_dropdown_rem.php?mccGroupID="+mccGroupID+"&userID="+userID
  xmlHttp7.onreadystatechange=updateUserGroupsRem2
  xmlHttp7.open("GET",url,true)
  xmlHttp7.send(null)
}

function updateUserGroupsRem2(){
  if (xmlHttp7.readyState==4 || xmlHttp7.readyState=="complete"){
    document.getElementById("divRemAccount").innerHTML=xmlHttp7.responseText;
  }
}

function validateEmail(email){
  xmlHttp13=GetXmlHttpObject()
  if(xmlHttp13==null){
    alert ("Browser does not support HTTP Request")
    return
  }
  var url="/mcc/ajax_controls/validate_email.php?email="+email
  xmlHttp13.onreadystatechange=validateEmail2
  xmlHttp13.open("GET",url,true)
  xmlHttp13.send(null)
}

function validateEmail2(){
  if (xmlHttp13.readyState==4 || xmlHttp13.readyState=="complete"){
    document.getElementById("divEmailValidation").innerHTML=xmlHttp13.responseText;
  }
}

// playlists - files moving in and out

function moveIn(){
  available=document.myForm.available;
  cat = "included_"+currentCat;
  included=document.myForm[cat];
  numIncluded = included.options.length;
  index=available.options.selectedIndex;
  if(index>=0){
    text = available.options[index].text;
    value = available.options[index].value;
    var newOption = new Option(text, value);
    included.options[numIncluded] = newOption;
    available.options[index] = null;
  }
  else{
    alert("Please make a selection from the AVAILABLE column first");
  }
  if(!index){
    available.options.selectedIndex=0;
  }
  else{
    available.options.selectedIndex=index-1;
  }
  included.options.selectedIndex=numIncluded;
}

function moveOut(){
  available=document.myForm.available;
  cat = "included_"+currentCat;
  included=document.myForm[cat];
  numAvailable = available.options.length;
  index=included.options.selectedIndex;
  if(index>=0){
    text = included.options[index].text;
    value = included.options[index].value;
    var newOption = new Option(text, value);
    available.options[numAvailable] = newOption;
    included.options[index] = null;
  }
  else{
    alert("Please make a selection from the INCLUDED column first");
  }
  if(!index){
    included.options.selectedIndex=0;
  }
  else{
    included.options.selectedIndex=index-1;
  }
  available.options.selectedIndex=numAvailable;
 }
  
function moveUp(){
  cat = "included_"+currentCat;
  included=document.myForm[cat];
  index = included.options.selectedIndex;
  if ( index >= 0 ) {
    if ( index != 0 ) {
      oldindex = index;   // bottom
      newindex = index-1; // top
      topString = included.options[newindex].text;
      botString = included.options[oldindex].text;
      included.options[newindex].text = botString;
      included.options[oldindex].text = topString;
      topValue = included.options[newindex].value;
      botValue = included.options[oldindex].value;
      included.options[newindex].value = botValue;
      included.options[oldindex].value = topValue;
      included.options.selectedIndex=newindex;
    }
    else {
      alert("This item is already at the top");
    }
  }
  else {
    alert("Please select an item before you perform this operation");
  }
}

function moveDown(){
  cat = "included_"+currentCat;
  included=document.myForm[cat];
  index = included.options.selectedIndex;
  if ( index >= 0 ) {
    numItems = included.options.length-1;
    if ( index != numItems ) {
      oldItem = index;   // top
      newItem = index+1; // bottom
      topString = included.options[newItem].text;
      botString = included.options[oldItem].text;
      included.options[newItem].text = botString;
      included.options[oldItem].text = topString;
      topValue = included.options[newItem].value;
      botValue = included.options[oldItem].value;
      included.options[newItem].value = botValue;
      included.options[oldItem].value = topValue;
      included.options.selectedIndex=newItem;
    }
    else {
      alert("This item is already at the bottom");
    }
  }
  else {
    alert("Please select an item before you perform this operation");
  }
}

function makePlaylist(arrCategories){
  stringIncluded = "";
  if(arrCategories.length){
    for (var c=0;c<arrCategories.length;c++){
      cat = "included_"+arrCategories[c];
      included=document.myForm[cat];
      numItems = included.options.length;
      if(numItems){
        for(x=0;x<numItems;x++){
          stringIncluded = stringIncluded+arrCategories[c]+"/"+included.options[x].value+",";
        }
      }
    }
  }
  else{
    cat = "included_"
    included=document.myForm[cat];
    numItems = included.options.length;
    if(numItems){
      for(x=0;x<numItems;x++){
        stringIncluded = stringIncluded+"/"+included.options[x].value+",";
      }
    }
  }
  document.myForm.fileList.value=stringIncluded;
}

function js_in_array(the_needle, the_haystack){
  var the_hay = the_haystack.toString();
  if(the_hay == ''){
    return false;
  }
  var the_pattern = new RegExp(the_needle, 'g');
  var matched = the_pattern.test(the_haystack);
  return matched;
}

