$("#root").ready(function() {

	$(".submitButton").click(function() {
		$("#config-form").submit();
	});

	$(".submitButtonGI").click(function() {
		$("#gi-config-form").submit();
	});

	$(".gameMenu").change(function() {
		$("#config-form").submit();
	});

	$(".testConnectionButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "VERSION"
    },
    function(data, status){
        alert(data);
    });

 		//alert("Running connection test.  This action will take some time.  Please be patient.");
	});
	
	$(".readButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "READSETTINGS"
    },
    function(data, status){
        var start;
        var end;
        var tempstring;
        var element;
		var element_slider;
        
  if(gametype == "GI")
  {
	  for(i=1; i<=6; i++)
	  {
	  	start = data.indexOf("S" + i + "ACTIVE=");
	    if(start >= 0)
	    {
	      tempstring = data.substr(start+9);
	      end = tempstring.indexOf("\n");
	      if(end == 1)
	      {
	        element = document.getElementById("activity-check" + i);
	        if(parseInt(tempstring.substr(0,end)) == 1)
	        {
	        	element.checked = true;
	        }
	        else
	        {
	        	element.checked = false;
	        }
	        data = data.substring(0, start)+data.substring(start+9+end+1);
	      }
	    }
	  }

	  var inputmenu = $("#menu-input1");
		for(i=1; i<=6; i++)
	  {
	  	start = data.indexOf("S" + i + "INPUT=");
	    if(start >= 0)
	    {
	      tempstring = data.substr(start+8);
	      end = tempstring.indexOf("\n");
	      if(end == 1)
	      {
	        inputmenu = $("#menu-input" + i);
					inputmenu.prop("selectedIndex",parseInt(tempstring.substr(0,end))-1);
	        data = data.substring(0, start)+data.substring(start+8+end+1);
	      }
	    }
	  }

  for(i=1; i<=6; i++)
  {
  	for(j=1; j<=8; j++)
  	{
  		start = data.indexOf("S" + i + "NORMB" + j + "=");
      if(start >= 0)
      {
        tempstring = data.substr(start+9);
        end = tempstring.indexOf("\n");
        if((end >= 1) && (end <= 3))
        {
          element_slider = document.getElementById("s"+i+"-b"+j);
          if(element_slider != null)
          {
          	element_slider.value = parseInt(tempstring.substr(0,end));
                data = data.substring(0, start)+data.substring(start+9+end+1);
          }
        }
      }
    }
  }

  for(i=1; i<=6; i++)
  {
  	for(j=1; j<=8; j++)
  	{
  		start = data.indexOf("S" + i + "ACTVB" + j + "=");
      if(start >= 0)
      {
        tempstring = data.substr(start+9);
        end = tempstring.indexOf("\n");
        if((end >= 1) && (end <= 3))
        {
          element_slider = document.getElementById("s"+i+"a-b"+j);
          if(element_slider != null)
          {
          	element_slider.value = parseInt(tempstring.substr(0,end));
                data = data.substring(0, start)+data.substring(start+9+end+1);
          }
        }
      }
    }
  }

  		start = data.indexOf("DELAY=");
      if(start >= 0)
      {
        tempstring = data.substr(start+6);
        comma = tempstring.indexOf(",");
        end = tempstring.indexOf("\n");
        if((comma >= 1) && (comma <= 2) && (end >= 3) && (end <= 5))
        {
          element_slider = document.getElementById("fade-delay-min");
          if(element_slider != null)
          {
          	element_slider.value = parseInt(tempstring.substr(0,comma));
          }
          element_slider = document.getElementById("fade-delay-max");
          if(element_slider != null)
          {
          	element_slider.value = parseInt(tempstring.substr(comma+1,end));
          }
          data = data.substring(0, start)+data.substring(start+6+end+1);
        }
      }

  		start = data.indexOf("ACTDUR=");
      if(start >= 0)
      {
        tempstring = data.substr(start+7);
        end = tempstring.indexOf("\n");
        if((end >= 1) && (end <= 3))
        {
          element_slider = document.getElementById("activity-duration");
          if(element_slider != null)
          {
          	element_slider.value = parseInt(tempstring.substr(0,end));
          }
          data = data.substring(0, start)+data.substring(start+7+end+1);
        }
      }

  		start = data.indexOf("50HZ=");
      if(start >= 0)
      {
        tempstring = data.substr(start+5);
        end = tempstring.indexOf("\n");
        if(end == 1)
        {
	        element = document.getElementById("50hz-check");
	        if(parseInt(tempstring.substr(0,end)) == 1)
	        {
	        	element.checked = true;
	        }
	        else
	        {
	        	element.checked = false;
	        }
          data = data.substring(0, start)+data.substring(start+5+end+1);
        }
      }

  }
  else
  {
	  for(i=1; i<=8; i++)
	  {
	  	start = data.indexOf("P" + i + "NAME=");
	    if(start >= 0)
	    {
	      tempstring = data.substr(start+7);
	      end = tempstring.indexOf("\n");
	      if((end >= 0) && (end <= 8))
	      {
	        element = document.getElementById("txt-profile" + i + "-name");
	        element.value = tempstring.substr(0,end);
	        data = data.substring(0, start)+data.substring(start+7+end+1);
	      }
	    }
	  }
	}

  for(i=1; i<=8; i++)
  {
  	for(j=1; j<=8; j++)
  	{
  		start = data.indexOf("P" + i + "B" + j + "=");
      if(start >= 0)
      {
        tempstring = data.substr(start+5);
        end = tempstring.indexOf("\n");
        if((end >= 1) && (end <= 3))
        {
          element_slider = document.getElementById("p"+i+"-b"+j);
          //element = document.getElementById("p" + i + "-b" + j);
          //element.value = tempstring.substr(0,end-1);
          if(element_slider != null)
          {
          	element_slider.value = parseInt(tempstring.substr(0,end));
                data = data.substring(0, start)+data.substring(start+5+end+1);
          }
        }
      }
    }
  }

  for(i=1; i<=8; i++)
  {
  	start = data.indexOf("P" + i + "DELAY=");
    if(start >= 0)
    {
      tempstring = data.substr(start+8);
      end = tempstring.indexOf("\n");
      if(end == 1)
      {
        element_slider = document.getElementById("p"+i+"-delay");
        if(element_slider != null)
        {
        	element_slider.value = parseInt(tempstring.substr(0,end));
                data = data.substring(0, start)+data.substring(start+8+end+1);
        }
      }
    }
  }

	var lampmenu = $("#menu-lamp01");
        for(i=1;i<=88;i++)
	{
          start = data.indexOf("L" + ("0" + i).slice(-2) + "P=");
    if(start >= 0)
    {
      tempstring = data.substr(start+5);
      end = tempstring.indexOf("\n");
      if(end == 1)
      {
				lampmenu = $("#menu-lamp"+("0" + i).slice(-2));
				//if(lampmenu != null)
				//{
					lampmenu.prop("selectedIndex",parseInt(tempstring.substr(0,end))-1);
                data = data.substring(0, start)+data.substring(start+5+end+1);
				//}
      }
    }
	}
        if(data) alert(data);
        $('#busyDialog').dialog('close');
      if(gametype == "GI")
      {
      	$("#gi-config-form").submit();
      }
      else
      {
      	$("#config-form").submit();
      }  
    });

 		//alert("Reading settings.  This action will take some time.  Please be patient.");
		$.mobile.changePage('#busyDialog',{transition:'slide', role:'dialog', dialogClass: 'no-close'});
	});
	
	$(".exportButton").click(function() {
		$.post("export.cgi",
    {
    },
    function(data, status){
        alert(data);
    });
	});
	
	$(".importButton").click(function() {
		$.post("import.cgi",
    {
    },
    function(data, status){
        alert(data);
    });
	});
	
	$(".sendButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;
		var profilename = [];
		var profilebright1 = [];
		var profilebright2 = [];
		var profilebright3 = [];
		var profilebright4 = [];
		var profilebright5 = [];
		var profilebright6 = [];
		var profilebright7 = [];
		var profilebright8 = [];
		var profiledelay = [];
		var lampprofile = [];
		
		for(var p=1; p<=8; p++) {
			profilename[p] = document.getElementById("txt-profile"+p+"-name").value;
			for(var b=1; b<=8; b++) {
				if(p==1) profilebright1[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==2) profilebright2[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==3) profilebright3[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==4) profilebright4[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==5) profilebright5[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==6) profilebright6[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==7) profilebright7[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
				if(p==8) profilebright8[b] = parseInt(document.getElementById("p"+p+"-b"+b).value);
			}
			profiledelay[p] = parseInt(document.getElementById("p"+p+"-delay").value);
		}
		
		var lampmenu = $("#menu-lamp01");
		for(var i=1; i<=88; i++) {
			lampmenu = $("#menu-lamp"+("0" + i).slice(-2));
			lampprofile[i] = lampmenu.prop("selectedIndex") + 1;
			if((lampprofile[i] < 1) || (lampprofile[i] > 8)) {
				lampprofile[i] = 0;
			}
		}

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "SENDSETTINGS",
        profilename1: profilename[1],
        profilename2: profilename[2],
        profilename3: profilename[3],
        profilename4: profilename[4],
        profilename5: profilename[5],
        profilename6: profilename[6],
        profilename7: profilename[7],
        profilename8: profilename[8],
        profilebright11: profilebright1[1],
        profilebright12: profilebright1[2],
        profilebright13: profilebright1[3],
        profilebright14: profilebright1[4],
        profilebright15: profilebright1[5],
        profilebright16: profilebright1[6],
        profilebright17: profilebright1[7],
        profilebright18: profilebright1[8],
        profilebright21: profilebright2[1],
        profilebright22: profilebright2[2],
        profilebright23: profilebright2[3],
        profilebright24: profilebright2[4],
        profilebright25: profilebright2[5],
        profilebright26: profilebright2[6],
        profilebright27: profilebright2[7],
        profilebright28: profilebright2[8],
        profilebright31: profilebright3[1],
        profilebright32: profilebright3[2],
        profilebright33: profilebright3[3],
        profilebright34: profilebright3[4],
        profilebright35: profilebright3[5],
        profilebright36: profilebright3[6],
        profilebright37: profilebright3[7],
        profilebright38: profilebright3[8],
        profilebright41: profilebright4[1],
        profilebright42: profilebright4[2],
        profilebright43: profilebright4[3],
        profilebright44: profilebright4[4],
        profilebright45: profilebright4[5],
        profilebright46: profilebright4[6],
        profilebright47: profilebright4[7],
        profilebright48: profilebright4[8],
        profilebright51: profilebright5[1],
        profilebright52: profilebright5[2],
        profilebright53: profilebright5[3],
        profilebright54: profilebright5[4],
        profilebright55: profilebright5[5],
        profilebright56: profilebright5[6],
        profilebright57: profilebright5[7],
        profilebright58: profilebright5[8],
        profilebright61: profilebright6[1],
        profilebright62: profilebright6[2],
        profilebright63: profilebright6[3],
        profilebright64: profilebright6[4],
        profilebright65: profilebright6[5],
        profilebright66: profilebright6[6],
        profilebright67: profilebright6[7],
        profilebright68: profilebright6[8],
        profilebright71: profilebright7[1],
        profilebright72: profilebright7[2],
        profilebright73: profilebright7[3],
        profilebright74: profilebright7[4],
        profilebright75: profilebright7[5],
        profilebright76: profilebright7[6],
        profilebright77: profilebright7[7],
        profilebright78: profilebright7[8],
        profilebright81: profilebright8[1],
        profilebright82: profilebright8[2],
        profilebright83: profilebright8[3],
        profilebright84: profilebright8[4],
        profilebright85: profilebright8[5],
        profilebright86: profilebright8[6],
        profilebright87: profilebright8[7],
        profilebright88: profilebright8[8],
        profiledelay1: profiledelay[1],
        profiledelay2: profiledelay[2],
        profiledelay3: profiledelay[3],
        profiledelay4: profiledelay[4],
        profiledelay5: profiledelay[5],
        profiledelay6: profiledelay[6],
        profiledelay7: profiledelay[7],
        profiledelay8: profiledelay[8],
        lampprofile01: lampprofile[1],
        lampprofile02: lampprofile[2],
        lampprofile03: lampprofile[3],
        lampprofile04: lampprofile[4],
        lampprofile05: lampprofile[5],
        lampprofile06: lampprofile[6],
        lampprofile07: lampprofile[7],
        lampprofile08: lampprofile[8],
        lampprofile09: lampprofile[9],
        lampprofile10: lampprofile[10],
        lampprofile11: lampprofile[11],
        lampprofile12: lampprofile[12],
        lampprofile13: lampprofile[13],
        lampprofile14: lampprofile[14],
        lampprofile15: lampprofile[15],
        lampprofile16: lampprofile[16],
        lampprofile17: lampprofile[17],
        lampprofile18: lampprofile[18],
        lampprofile19: lampprofile[19],
        lampprofile20: lampprofile[20],
        lampprofile21: lampprofile[21],
        lampprofile22: lampprofile[22],
        lampprofile23: lampprofile[23],
        lampprofile24: lampprofile[24],
        lampprofile25: lampprofile[25],
        lampprofile26: lampprofile[26],
        lampprofile27: lampprofile[27],
        lampprofile28: lampprofile[28],
        lampprofile29: lampprofile[29],
        lampprofile30: lampprofile[30],
        lampprofile31: lampprofile[31],
        lampprofile32: lampprofile[32],
        lampprofile33: lampprofile[33],
        lampprofile34: lampprofile[34],
        lampprofile35: lampprofile[35],
        lampprofile36: lampprofile[36],
        lampprofile37: lampprofile[37],
        lampprofile38: lampprofile[38],
        lampprofile39: lampprofile[39],
        lampprofile40: lampprofile[40],
        lampprofile41: lampprofile[41],
        lampprofile42: lampprofile[42],
        lampprofile43: lampprofile[43],
        lampprofile44: lampprofile[44],
        lampprofile45: lampprofile[45],
        lampprofile46: lampprofile[46],
        lampprofile47: lampprofile[47],
        lampprofile48: lampprofile[48],
        lampprofile49: lampprofile[49],
        lampprofile50: lampprofile[50],
        lampprofile51: lampprofile[51],
        lampprofile52: lampprofile[52],
        lampprofile53: lampprofile[53],
        lampprofile54: lampprofile[54],
        lampprofile55: lampprofile[55],
        lampprofile56: lampprofile[56],
        lampprofile57: lampprofile[57],
        lampprofile58: lampprofile[58],
        lampprofile59: lampprofile[59],
        lampprofile60: lampprofile[60],
        lampprofile61: lampprofile[61],
        lampprofile62: lampprofile[62],
        lampprofile63: lampprofile[63],
        lampprofile64: lampprofile[64],
        lampprofile65: lampprofile[65],
        lampprofile66: lampprofile[66],
        lampprofile67: lampprofile[67],
        lampprofile68: lampprofile[68],
        lampprofile69: lampprofile[69],
        lampprofile70: lampprofile[70],
        lampprofile71: lampprofile[71],
        lampprofile72: lampprofile[72],
        lampprofile73: lampprofile[73],
        lampprofile74: lampprofile[74],
        lampprofile75: lampprofile[75],
        lampprofile76: lampprofile[76],
        lampprofile77: lampprofile[77],
        lampprofile78: lampprofile[78],
        lampprofile79: lampprofile[79],
        lampprofile80: lampprofile[80],
        lampprofile81: lampprofile[81],
        lampprofile82: lampprofile[82],
        lampprofile83: lampprofile[83],
        lampprofile84: lampprofile[84],
        lampprofile85: lampprofile[85],
        lampprofile86: lampprofile[86],
        lampprofile87: lampprofile[87],
        lampprofile88: lampprofile[88]
    },
    function(data, status){
        $('#busyDialog').dialog('close');
        if(length(data) > 0) alert(data);
    });

 		//alert("Sending settings.  This action will take about 15 seconds.  Please be patient.");
		$.mobile.changePage('#busyDialog',{transition:'slide', role:'dialog'});
	});
	
	$(".sendButtonGI").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;
		element = document.getElementById("fade-delay-min");
    var fadedelaymin = element.value;
		element = document.getElementById("fade-delay-max");
    var fadedelaymax = element.value;
		element = document.getElementById("activity-duration");
    var activityduration = element.value;
		element = document.getElementById("50hz-check");
    var fiftyhz = 0;
    if(element.checked == true) fiftyhz = 1;
    var stringinput = [];
    var stringactivity = [];
		var stringbright1 = [];
		var stringbright2 = [];
		var stringbright3 = [];
		var stringbright4 = [];
		var stringbright5 = [];
		var stringbright6 = [];
		var stringbrightactive1 = [];
		var stringbrightactive2 = [];
		var stringbrightactive3 = [];
		var stringbrightactive4 = [];
		var stringbrightactive5 = [];
		var stringbrightactive6 = [];
		
	  var inputmenu = $("#menu-input1");
		for(var s=1; s<=6; s++) {
			inputmenu = $("#menu-input" + s);
			stringinput[s] = inputmenu.prop("selectedIndex") + 1;
			element = document.getElementById("activity-check"+s);
			stringactivity[s] = 0;
    	if(element.checked == true) stringactivity[s] = 1;
			for(var b=1; b<=8; b++) {
				if(s==1) stringbright1[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==2) stringbright2[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==3) stringbright3[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==4) stringbright4[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==5) stringbright5[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==6) stringbright6[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==7) stringbright7[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==8) stringbright8[b] = parseInt(document.getElementById("s"+s+"-b"+b).value);
				if(s==1) stringbrightactive1[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==2) stringbrightactive2[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==3) stringbrightactive3[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==4) stringbrightactive4[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==5) stringbrightactive5[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==6) stringbrightactive6[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==7) stringbrightactive7[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
				if(s==8) stringbrightactive8[b] = parseInt(document.getElementById("s"+s+"a-b"+b).value);
			}
		}
		
		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "SENDSETTINGS",
        fadedelaymin: fadedelaymin,
        fadedelaymax: fadedelaymax,
        activityduration: activityduration,
        fiftyhz: fiftyhz,
        stringinput1: stringinput[1],
        stringinput2: stringinput[2],
        stringinput3: stringinput[3],
        stringinput4: stringinput[4],
        stringinput5: stringinput[5],
        stringinput6: stringinput[6],
        stringactivity1: stringactivity[1],
        stringactivity2: stringactivity[2],
        stringactivity3: stringactivity[3],
        stringactivity4: stringactivity[4],
        stringactivity5: stringactivity[5],
        stringactivity6: stringactivity[6],
        stringbright11: stringbright1[1],
        stringbright12: stringbright1[2],
        stringbright13: stringbright1[3],
        stringbright14: stringbright1[4],
        stringbright15: stringbright1[5],
        stringbright16: stringbright1[6],
        stringbright17: stringbright1[7],
        stringbright18: stringbright1[8],
        stringbright21: stringbright2[1],
        stringbright22: stringbright2[2],
        stringbright23: stringbright2[3],
        stringbright24: stringbright2[4],
        stringbright25: stringbright2[5],
        stringbright26: stringbright2[6],
        stringbright27: stringbright2[7],
        stringbright28: stringbright2[8],
        stringbright31: stringbright3[1],
        stringbright32: stringbright3[2],
        stringbright33: stringbright3[3],
        stringbright34: stringbright3[4],
        stringbright35: stringbright3[5],
        stringbright36: stringbright3[6],
        stringbright37: stringbright3[7],
        stringbright38: stringbright3[8],
        stringbright41: stringbright4[1],
        stringbright42: stringbright4[2],
        stringbright43: stringbright4[3],
        stringbright44: stringbright4[4],
        stringbright45: stringbright4[5],
        stringbright46: stringbright4[6],
        stringbright47: stringbright4[7],
        stringbright48: stringbright4[8],
        stringbright51: stringbright5[1],
        stringbright52: stringbright5[2],
        stringbright53: stringbright5[3],
        stringbright54: stringbright5[4],
        stringbright55: stringbright5[5],
        stringbright56: stringbright5[6],
        stringbright57: stringbright5[7],
        stringbright58: stringbright5[8],
        stringbright61: stringbright6[1],
        stringbright62: stringbright6[2],
        stringbright63: stringbright6[3],
        stringbright64: stringbright6[4],
        stringbright65: stringbright6[5],
        stringbright66: stringbright6[6],
        stringbright67: stringbright6[7],
        stringbright68: stringbright6[8],
        stringbrightactive11: stringbrightactive1[1],
        stringbrightactive12: stringbrightactive1[2],
        stringbrightactive13: stringbrightactive1[3],
        stringbrightactive14: stringbrightactive1[4],
        stringbrightactive15: stringbrightactive1[5],
        stringbrightactive16: stringbrightactive1[6],
        stringbrightactive17: stringbrightactive1[7],
        stringbrightactive18: stringbrightactive1[8],
        stringbrightactive21: stringbrightactive2[1],
        stringbrightactive22: stringbrightactive2[2],
        stringbrightactive23: stringbrightactive2[3],
        stringbrightactive24: stringbrightactive2[4],
        stringbrightactive25: stringbrightactive2[5],
        stringbrightactive26: stringbrightactive2[6],
        stringbrightactive27: stringbrightactive2[7],
        stringbrightactive28: stringbrightactive2[8],
        stringbrightactive31: stringbrightactive3[1],
        stringbrightactive32: stringbrightactive3[2],
        stringbrightactive33: stringbrightactive3[3],
        stringbrightactive34: stringbrightactive3[4],
        stringbrightactive35: stringbrightactive3[5],
        stringbrightactive36: stringbrightactive3[6],
        stringbrightactive37: stringbrightactive3[7],
        stringbrightactive38: stringbrightactive3[8],
        stringbrightactive41: stringbrightactive4[1],
        stringbrightactive42: stringbrightactive4[2],
        stringbrightactive43: stringbrightactive4[3],
        stringbrightactive44: stringbrightactive4[4],
        stringbrightactive45: stringbrightactive4[5],
        stringbrightactive46: stringbrightactive4[6],
        stringbrightactive47: stringbrightactive4[7],
        stringbrightactive48: stringbrightactive4[8],
        stringbrightactive51: stringbrightactive5[1],
        stringbrightactive52: stringbrightactive5[2],
        stringbrightactive53: stringbrightactive5[3],
        stringbrightactive54: stringbrightactive5[4],
        stringbrightactive55: stringbrightactive5[5],
        stringbrightactive56: stringbrightactive5[6],
        stringbrightactive57: stringbrightactive5[7],
        stringbrightactive58: stringbrightactive5[8],
        stringbrightactive61: stringbrightactive6[1],
        stringbrightactive62: stringbrightactive6[2],
        stringbrightactive63: stringbrightactive6[3],
        stringbrightactive64: stringbrightactive6[4],
        stringbrightactive65: stringbrightactive6[5],
        stringbrightactive66: stringbrightactive6[6],
        stringbrightactive67: stringbrightactive6[7],
        stringbrightactive68: stringbrightactive6[8]
    },
    function(data, status){
        $('#busyDialog').dialog('close');
        if(length(data) > 0) alert(data);
    });

 		//alert("Sending settings.  This action will take about 15 seconds.  Please be patient.");
		$.mobile.changePage('#busyDialog',{transition:'slide', role:'dialog'});
	});
	
	$(".saveButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "SAVESETTINGS"
    },
    function(data, status){
        //alert(data);
    });

 		//alert("Saving settings.  This action will take some time.  Please be patient.");
	});
	
	$(".manualTestButton").click(function() {
		$.post("manual.cgi",
    {
    },
    function(data, status){
        alert(data);
    });
	});
	
	$(".passthroughButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "PASSTHROUGH"
    },
    function(data, status){
        //alert(data);
    });

 		//alert("Setting Passthrough operation.");
	});
	
	$(".normalOCDButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "NORMALOCD"
    },
    function(data, status){
        //alert(data);
    });

 		//alert("Setting Normal OCD operation.");
	});
	
	$(".checkButton").click(function() {
		var element = document.getElementById("txt-port");
		var portvar = element.value;
		element = document.getElementById("txt-gametype");
		var gametype = element.value;

		$.post("ocd.cgi",
    {
        gametype: gametype,
        port1: portvar,
        action: "CHECK"
    },
    function(data, status){
        if(data) alert(data);
        $('#busyDialog').dialog('close');
    });

		$.mobile.changePage('#busyDialog',{transition:'slide', role:'dialog', dialogClass: 'no-close'});
	});
	
});
