<?php
$filename = 'popupList2.js';
$file = fopen($filename, 'w');

$stringWrite = 
				"\t".		'$(function(){'.					"\n" .
				"\t"."\t".		'// don\'t forget this init!'.	"\n" .
				"\t"."\t".		'$.initWindowMsg();'.			"\n" .
				

				"\t"."\t".		'// maximalni pocet odkazu v list2 pro odeslani hodnoty do formulare je:'.	"\n" .
        		"\t"."\t".		'// 		maximalni pocet radku tabulky list2 = 30'.						"\n" .
        		"\t"."\t".		'//		maximalni pocet sloupcu tabulky s odkazy = 4'.						"\n" .
        		"\t"."\t".		'//		celkem = 30 * 4 = 120'.												"\n"."\n"."\n".
				"\t"."\t".		'// upon click of a button, send corresponding text input value to parent window'."\n";
$cell = 0;
for ($column = 0; $column < 4; $column++){
	for ($row = 0; $row < 10; $row++){
		
		$stringWrite .= 
		"\n"."\n".
		"\t".		'$(\'#button'.$column.$index.'\').click(function(){'.				"\n" .
		"\t"."\t".		'value = $(\'#in'.$cell.'\').val();'.					"\n" .
		"\t"."\t".		'$.triggerParentEvent("childMsg'.$column.'", value);'. 	"\n" .
		"\t".		'});';
		$cell++;
	}
}
$stringWrite .= 
		"\n" ."\n" .
		'/*'.																								"\n" .
        "\t".		'// set up the message handlers, listen for events \'parentMsg1\' and \'parentMsg2\''.	"\n" .
        "\t".		'$.windowMsg("parentMsg1", function(message) {'.										"\n" .
        "\t"."\t".		'$(\'#in1\').val(message);'.														"\n" .
        "\t"."\t".		'});'.																				"\n" .
        "\t".		'$.windowMsg("parentMsg2", function(message) {'.										"\n" .
        "\t"."\t".		'$(\'#in2\').val(message);'.														"\n" .
        "\t".		'});'.																					"\n" .
        '*/'.																								"\n" .
		'});';


fwrite($file, $stringWrite);
fclose($file);