// My AppliedIRC JavaScript
// $Id: my.js 969 2008-10-21 12:16:36Z giggsey $

function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
function refreshlist()
{
    var xhr;
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e)
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2)
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }

    xhr.onreadystatechange  = function()
    {
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200)
                  document.getElementById('dothelist').innerHTML = '<tr><th>Channel</th><th>Logged</th><th>Access Management</th></tr>' + xhr.responseText;
         }
    };

   xhr.open('GET', 'http://my.appliedirc.com/logs/?var=refreshlist',  true);
   xhr.send(null);
   return false;
}
function submitchan(channel,enable)
{
	document.getElementById('ajaxsubmit').innerHTML = 'Submitting Changes...';
	document.getElementById('ajaxsubmit').style.display = 'inline';
	setTimeout("document.getElementById('ajaxsubmit').innerHTML = 'Editing Log Configuration...';",4000);
	setTimeout("document.getElementById('ajaxsubmit').innerHTML = 'Reloading LogServ...';",6000);
    var xhr;
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e)
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2)
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }

    xhr.onreadystatechange  = function()
    {
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200)
                  document.getElementById('ajaxsubmit').innerHTML = xhr.responseText;
            refreshlist();
            setTimeout("document.getElementById('ajaxsubmit').style.display = 'none';",7000);
         }
    };

   xhr.open('GET', 'http://my.appliedirc.com/logs/?var=submitajax&chan=' + channel + '&daction=' + enable, true);
   xhr.send(null);

   return false;
}

function webaccess()
{
	var list = document.getElementById('authmethod');
	switch (list.options[list.selectedIndex].value)
	{
		case 'password':
			document.getElementById('password').style.display = 'inline';
			document.getElementById('usermgmt').style.display = 'none';
			document.getElementById('access').style.display = 'none';
		break;
		case 'users':
			document.getElementById('password').style.display = 'none';
			document.getElementById('usermgmt').style.display = 'inline';
			document.getElementById('access').style.display = 'none';
		break;
		case 'access':
			document.getElementById('password').style.display = 'none';
			document.getElementById('usermgmt').style.display = 'none';
			document.getElementById('access').style.display = 'inline';
		break;
		case 'open':
			document.getElementById('password').style.display = 'none';
			document.getElementById('usermgmt').style.display = 'none';
			document.getElementById('access').style.display = 'none';
		break;

	}
}

function addusername()
{
	var channelname = document.getElementById('channelname').value;
	var username = document.getElementById('addusername').value;

	var xhr;
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e)
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2)
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }

    xhr.onreadystatechange  = function()
    {
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200)

                  document.getElementById('addeduser').innerHTML = "<span style='color: green;'>" + xhr.responseText + '</span>';
         }
    };

   xhr.open('GET', 'http://my.appliedirc.com/webaccess/?var=addusername&chan=' + channelname + '&username=' + username,  true);
   xhr.send(null);
   return false;
}

function access()
{
	var list = document.getElementById('accesstype');
	switch (list.options[list.selectedIndex].value)
	{
		case 'custom':
			document.getElementById('customlevel').style.display = 'inline';
		break;
		default:
			document.getElementById('customlevel').style.display = 'none';
		break;
	}
}

function refreshstats()
{
    var xhr;
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e)
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2)
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }

    xhr.onreadystatechange  = function()
    {
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200)
                  document.getElementById('dothelist').innerHTML = '<tr><th>Channel</th><th>Statistics</th></tr>' + xhr.responseText;
         }
    };

   xhr.open('GET', 'http://my.appliedirc.com/stats/?var=refreshlist',  true);
   xhr.send(null);
   return false;
}
function submitstats(channel,enable)
{
	document.getElementById('ajaxsubmit').innerHTML = 'Submitting Changes...';
	document.getElementById('ajaxsubmit').style.display = 'inline';
	setTimeout("document.getElementById('ajaxsubmit').innerHTML = 'Changing Statistics options on channel';",7000);
    var xhr;
    try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
    catch (e)
    {
        try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
        catch (e2)
        {
          try {  xhr = new XMLHttpRequest();     }
          catch (e3) {  xhr = false;   }
        }
     }

    xhr.onreadystatechange  = function()
    {
         if(xhr.readyState  == 4)
         {
              if(xhr.status  == 200)
                  document.getElementById('ajaxsubmit').innerHTML = xhr.responseText;
            setTimeout("refreshstats();",10000);
            setTimeout("document.getElementById('ajaxsubmit').style.display = 'none';",11000);
         }
    };

   xhr.open('GET', 'http://my.appliedirc.com/stats/?var=submitajax&chan=' + channel + '&daction=' + enable, true);
   xhr.send(null);

   return false;
}