public static void main(String[] args) throws IOException {
		boolean enableInput;
		
		while(true) {
			System.out.println("Want to (1) Enable or (2) Disable input permission?");
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String line = br.readLine();
			
			try {
				int choice = Integer.parseInt(line);
				
				if(choice == 1) {
					enableInput = true;
					break;
				}
				else if(choice == 2) {
					enableInput = false;
					break;
				}
			}
			catch (NumberFormatException e) {
				System.err.println("Illegal choice; please input 1 or 2");
			}
		}
		
        WebDriver driver = Utils.createFireFoxDriver();
		
		Utils.openTvdb(driver, null);
		
        driver.findElement(By.partialLinkText("v   z")).click();
        driver.findElement(By.partialLinkText("դb@")).click();
        
        String mainWin = driver.getWindowHandle();
        String newWin = null;
        
        for(String hWnd : driver.getWindowHandles()) {
        	if(!hWnd.equals(mainWin)) {
        		newWin = hWnd;
        		break;
        	}
        }
        
        driver.switchTo().window(newWin);
        
        // Start to change the permission.
        // Note that every time the button is clicked, the form is submitted, and thus the WebElement instances become invalid.
        // We have to remember some id's and names in order to traverse all controls.
        
        List<WebElement> ܧs = driver.findElements(By.cssSelector("input[type='submit'][value='ܧ']"));
        List<String> buttonIds = new ArrayList<String>();
        List<String> chkboxNames = new ArrayList<String>();
        
        // First, remember the button ID's
        for(WebElement button: ܧs) {
        	buttonIds.add(button.getAttribute("id"));
        }
        
        // Next, remember the names of the input-permission checkboxes
        List<WebElement> chkboxes = driver.findElements(By.cssSelector("input[type='checkbox']"));
        for(WebElement chkbox: chkboxes) {
        	if(chkbox.getAttribute("name").matches("input_yn.*")) {
        		chkboxNames.add(chkbox.getAttribute("name"));
        	}
        }
        
        // Finally, click the buttons
        for(String buttonId: buttonIds) {
    		WebElement chkbox = driver.findElement(By.name("input_yn_"+buttonId));
    		if(chkbox.isSelected() != enableInput) {
    			chkbox.click();
    		}
        	
        	// Do click the button. Simply clicking the button doesn't work except for IE, so we have to work it around. 
        	((JavascriptExecutor)driver).executeScript("document.getElementsByName('cid')[0].value = '"+buttonId+"';");
        	driver.findElement(By.id(buttonId)).click();
        }
        
        ((JavascriptExecutor)driver).executeScript("alert('Done!')");
	}