text: /* Mu Young
  	Boss Balrog
  */
  
  
  var status = -1;
  var balrogMode; // false = easy, true = hard
  
  function action(mode, type, selection) {
      switch (status) {
  	case -1:
  	    status = 0;
  	    switch (cm.getChannelNumber()) {
  		case 5:
  		    balrogMode = true;
  		    cm.sendNext("The channel you are currently staying is available for #bNormal Balrog Expedition Squad#k. If you wish to join a different mode, please select the correct channel. \n\r #b#i3994116# Ch.5 / Level 50 and above / 6 ~ 15 users \n#b#i3994115# The rest of the channel  / Level 50 ~ Level 70 / 3 ~ 6 users.");
  		    break;
  		default:
  		    balrogMode = false;
  		    cm.sendNext("The channel you are currently staying is available for #bEasy Balrog Expedition Squad#k. If you wish to join a different mode, please select the correct channel. \n\r #b#i3994116# Ch.5 / Level 50 and above / 6 ~ 15 users \n#b#i3994115# The rest of the channel  / Level 50 ~ Level 70 / 3 ~ 6 users.");
  		    break;
  	    }
  	    break;
  	case 0:
  	    var em = cm.getEventManager(balrogMode ? "BossBalrog_NORMAL" : "BossBalrog_EASY");
  
  	    if (em == null) {
  		cm.sendOk("The event isn't started, please contact a GM.");
  		cm.safeDispose();
  		return;
  	    }
  
  	    if (cm.getParty() != null) {
  	var prop = em.getProperty("state");
  	    var marr = cm.getQuestRecord(balrogMode ? 160106 : 160105);
  	    var data = marr.getCustomData();
  	    if (data == null) {
  		marr.setCustomData("0");
  	        data = "0";
  	    }
  	    var time = parseInt(data);
  	if (prop == null || prop.equals("0")) {
  		var squadAvailability = cm.getSquadAvailability("BossBalrog");
  		if (squadAvailability == -1) {
  		    status = 1;
  	    if (time + (6 * 3600000) >= cm.getCurrentTime() && !cm.getPlayer().isGM()) {
  		cm.sendOk("You have already went to Balrog in the past 6 hours.Time left: " + cm.getReadableMillis(cm.getCurrentTime(), time + (6 * 3600000)));
  		cm.dispose();
  		return;
  	    }
  		    cm.sendYesNo("Would you like to become the leader of the Balrog Expedition Squad?");
  
  		} else if (squadAvailability == 1) {
  	    if (time + (6 * 3600000) >= cm.getCurrentTime() && !cm.getPlayer().isGM()) {
  		cm.sendOk("You have already went to Balrog in the past 6 hours.Time left: " + cm.getReadableMillis(cm.getCurrentTime(), time + (6 * 3600000)));
  		cm.dispose();
  		return;
  	    }
  		    // -1 = Cancelled, 0 = not, 1 = true
  		    var type = cm.isSquadLeader("BossBalrog");
  		    if (type == -1) {
  			cm.sendOk("The squad has ended, please re-register.");
  			cm.safeDispose();
  		    } else if (type == 0) {
  			var memberType = cm.isSquadMember("BossBalrog");
  			if (memberType == 2) {
  			    cm.sendOk("You been banned from the squad.");
  			    cm.safeDispose();
  			} else if (memberType == 1) {
  			    status = 5;
  			    cm.sendSimple("What do you want to do? \r\n#b#L0#Check out members#l \r\n#b#L1#Join the squad#l \r\n#b#L2#Withdraw from squad#l");
  			} else if (memberType == -1) {
  			    cm.sendOk("The squad has ended, please re-register.");
  			    cm.safeDispose();
  			} else {
  			    status = 5;
  			    cm.sendSimple("What do you want to do? \r\n#b#L0#Check out members#l \r\n#b#L1#Join the squad#l \r\n#b#L2#Withdraw from squad#l");
  			}
  		    } else { // Is leader
  			status = 10;
  			cm.sendSimple("What do you want to do? \r\n#b#L0#Check out members#l \r\n#b#L1#Remove member#l \r\n#b#L2#Edit restricted list#l \r\n#r#L3#Enter map#l");
  		    // TODO viewing!
  		    }
  	    } else {
  			var eim = cm.getDisconnected(balrogMode ? "BossBalrog_NORMAL" : "BossBalrog_EASY");
  			if (eim == null) {
  				var squd = cm.getSquad("BossBalrog");
  				if (squd != null) {
  	    if (time + (6 * 3600000) >= cm.getCurrentTime() && !cm.getPlayer().isGM()) {
  		cm.sendOk("You have already went to Balrog in the past 6 hours. Time left: " + cm.getReadableMillis(cm.getCurrentTime(), time + (6 * 3600000)));
  		cm.dispose();
  		return;
  	    }
  					cm.sendYesNo("The squad's battle against the boss has already begun.\r\n" + squd.getNextPlayer());
  					status = 3;
  				} else {
  					cm.sendOk("The squad's battle against the boss has already begun.");
  					cm.safeDispose();
  				}
  			} else {
  				cm.sendYesNo("Ah, you have returned. Would you like to join your squad in the fight again?");
  				status = 2;
  			}
  	    }
  	} else {
  			var eim = cm.getDisconnected(balrogMode ? "BossBalrog_NORMAL" : "BossBalrog_EASY");
  			if (eim == null) {
  				var squd = cm.getSquad("BossBalrog");
  				if (squd != null) {
  	    if (time + (6 * 3600000) >= cm.getCurrentTime() && !cm.getPlayer().isGM()) {
  		cm.sendOk("You have already went to Balrog in the past 6 hours. Time left: " + cm.getReadableMillis(cm.getCurrentTime(), time + (6 * 3600000)));
  		cm.dispose();
  		return;
  	    }
  					cm.sendYesNo("The squad's battle against the boss has already begun.\r\n" + squd.getNextPlayer());
  					status = 3;
  				} else {
  					cm.sendOk("The squad's battle against the boss has already begun.");
  					cm.safeDispose();
  				}
  			} else {
  				cm.sendYesNo("Ah, you have returned. Would you like to join your squad in the fight again?");
  				status = 2;
  			}
  	}
  	    } else {
  		cm.sendPrev("You need a party.");
  		cm.safeDispose();
  	    }
  	    break;
  	case 1:
  	    if (mode == 1) {
  		if (!balrogMode) { // Easy Mode
  		    var lvl = cm.getPlayerStat("LVL");
  		    if (lvl >= 50 && lvl <= 70) {
  			if (cm.registerSquad("BossBalrog", 5, " has been named the Leader of the squad. If you would you like to join please register for the Expedition Squad within the time period.")) {
  				cm.sendOk("You have been named the Leader of the Squad. For the next 5 minutes, you can add the members of the Expedition Squad.");
  			} else {
  				cm.sendOk("Error, try again.");
  			}
  		    } else {
  			cm.sendNext("A member of the party is not within the range of Levels 50 and 70. Please set up your party so that everyone fits the level limit.");
  		    }
  		} else { // Normal Mode
  			if (cm.registerSquad("BossBalrog", 5, " has been named the Leader of the squad. If you would you like to join please register for the Expedition Squad within the time period.")) {
  				cm.sendOk("You have been named the Leader of the Squad. For the next 5 minutes, you can add the members of the Expedition Squad.");
  			} else {
  				cm.sendOk("Error, try again.");
  			}
  		}
  	    } else {
  		cm.sendOk("Talk to me if you want to become the leader of the Expedition squad.")
  	    }
  	    cm.safeDispose();
  	    break;
  	case 2:
  		if (!cm.reAdd(balrogMode ? "BossBalrog_NORMAL" : "BossBalrog_EASY", "BossBalrog")) {
  			cm.sendOk("Error... please try again.");
  		}
  		cm.safeDispose();
  		break;
  	case 3:
  		if (mode == 1) {
  			var squd = cm.getSquad("BossBalrog");
  			if (squd != null && !squd.getAllNextPlayer().contains(cm.getPlayer().getName())) {
  				squd.setNextPlayer(cm.getPlayer().getName());
  				cm.sendOk("You have reserved the spot.");
  			}
  		}
  		cm.dispose();
  		break;
  	case 5:
  	    if (selection == 0) {
  		if (!cm.getSquadList("BossBalrog", 0)) {
  		    cm.sendOk("Due to an unknown error, the request for squad has been denied.");
  		    cm.safeDispose();
  		} else {
  		    cm.dispose();
  		}
  	    } else if (selection == 1) { // join
  		var ba = cm.addMember("BossBalrog", true);
  		if (ba == 2) {
  		    cm.sendOk("The squad is currently full, please try again later.");
  		    cm.safeDispose();
  		} else if (ba == 1) {
  		    cm.sendOk("You have joined the squad successfully");
  		    cm.safeDispose();
  		} else {
  		    cm.sendOk("You are already part of the squad.");
  		    cm.safeDispose();
  		}
  	    } else {// withdraw
  		var baa = cm.addMember("BossBalrog", false);
  		if (baa == 1) {
  		    cm.sendOk("You have withdrawed from the squad successfully");
  		    cm.safeDispose();
  		} else {
  		    cm.sendOk("You are not part of the squad.");
  		    cm.safeDispose();
  		}
  	    }
  	    break;
  	case 10:
  	    if (selection == 0) {
  		if (!cm.getSquadList("BossBalrog", 0)) {
  		    cm.sendOk("Due to an unknown error, the request for squad has been denied.");
  		}
  		cm.safeDispose();
  	    } else if (selection == 1) {
  		status = 11;
  		if (!cm.getSquadList("BossBalrog", 1)) {
  		    cm.sendOk("Due to an unknown error, the request for squad has been denied.");
  		}
  		cm.safeDispose();
  	    } else if (selection == 2) {
  		status = 12;
  		if (!cm.getSquadList("BossBalrog", 2)) {
  		    cm.sendOk("Due to an unknown error, the request for squad has been denied.");
  		}
  		cm.safeDispose();
  	    } else if (selection == 3) { // get insode
  		if (cm.getSquad("BossBalrog") != null) {
  		    var dd = cm.getEventManager(balrogMode ? "BossBalrog_NORMAL" : "BossBalrog_EASY");
  		    dd.startInstance(cm.getSquad("BossBalrog"), cm.getMap(), balrogMode ? 160106 : 160105);
  		    cm.dispose();
  		} else {
  		    cm.sendOk("Due to an unknown error, the request for squad has been denied.");
  		    cm.safeDispose();
  		}
  	    }
  	    break;
  	case 11:
  	    cm.banMember("BossBalrog", selection);
  	    cm.dispose();
  	    break;
  	case 12:
  	    if (selection != -1) {
  		cm.acceptMember("BossBalrog", selection);
  	    }
  	    cm.dispose();
  	    break;
      }
  }