<html><head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>jQuery Mobile: Theme Download</title>
	<link rel="stylesheet" href="resourcen/jquery.mobile.icons.min.css" />
	<link rel="stylesheet" href="resourcen/jquery.mobile.structure-1.4.5.min.css" />
	<script src="resourcen/jquery-1.11.1.min.js"></script>
	<script src="resourcen/jquery.mobile-1.4.5.min.js"></script>
	<script src="resourcen/tame.js"></script>
	<script>
	
		//Webservice definition for all examplesz
		var Plc, debug,
			g_b_block_update_event;
		
		// Austausch Variablen:
		var 	g_b_Licht_Wohnzimmer, 
				g_b_Licht_Esszimmer,
				g_b_Licht_Kueche,
				g_b_Licht_Gast,
				g_b_Licht_Flur;
				
		g_b_Licht_Wohnzimmer = false;
		
		// Debugmodus auf TRUE / FALSE setzen
		debug = true;
		
		function startClient(handles) {
			Plc =  TAME.WebServiceClient.createClient({
				serviceUrl: '/tcadswebservice/tcadswebservice.dll',
				//configFileUrl: 'http://192.168.1.2/tamex/resources/demo2.tpy',  //Path to the TPY file
				amsNetId: '5.37.200.188.1.1',
				amsPort: '801',       //default
				//useHandles: handles,    //use handles
				alignment: '4',       //2 default, set it to "4" if you have TC2 and an ARM based PLC device (i.e. CX90xx), to 8 with TC3
				language: 'ge',       //default, set it to "en" for english names of days and months
				onReady: pollCycl    //this function is defined in each example
				
				//$("#Licht_WZ").val("on").flipswitch( "refresh" ) ;
			});
		
		}
		
	window.onload = startClient;
		
	pollCycl = function(){
	
	
		Plc.readBool({
		name:	".o_b_012",
		jvar:	"g_b_Licht_Wohnzimmer"
		});
		Plc.readBool({
		name:	".o_b_030",
		jvar:	"g_b_Licht_Flur"
		});
		Plc.readBool({
		name:	".o_b_027",
		jvar:	"g_b_Licht_Gast"
		});
		Plc.readBool({
		name:	".o_b_014",
		jvar:	"g_b_Licht_Kueche"
		});
		Plc.readBool({
		name:	".o_b_011",
		jvar:	"g_b_Licht_Esszimmer"
		});
		console.log(g_b_Licht_Flur);
		
		// Update der Events blockieren:
		g_b_block_update_event = true;
		
		// **********************************************
		//			Checkboxes aktualisieren 
		// **********************************************
		//$( "#Licht_WZ").prop('checked', g_b_Licht_Wohnzimmer);
		
		var lichtstatus = $("#Licht_WZ");
		lichtstatus.prop("checked", g_b_Licht_Wohnzimmer);
		lichtstatus.flipswitch( "refresh" );
		
		lichtstatus  = $("#Licht_FL");
		lichtstatus.prop("checked", g_b_Licht_Flur);
		lichtstatus.flipswitch( "refresh" );
		
		lichtstatus  = $("#Licht_GA");
		lichtstatus.prop("checked", g_b_Licht_Gast);
		lichtstatus.flipswitch( "refresh" );
		
		lichtstatus  = $("#Licht_KU");
		lichtstatus.prop("checked", g_b_Licht_Kueche);
		lichtstatus.flipswitch( "refresh" );
		
		lichtstatus  = $("#Licht_EZ");
		lichtstatus.prop("checked", g_b_Licht_Esszimmer);
		lichtstatus.flipswitch( "refresh" );
		
		// Update der Events wieder zulassen:
		g_b_block_update_event = false;
		
		//Call the function again
		window.setTimeout('pollCycl()', 100); //Timeout 100 ms
	
	};
		
	$( document ).on( 'change', '#Licht_WZ', function( e ) {
		//alert(debug);
		if(!g_b_block_update_event) {
			Plc.writeBool({
				name: ".vp_b_Anf_Licht_Wohnzimmer",
				val: true,
				ocd: 200,
				oc: function() {
				Plc.writeBool({name: ".vp_b_Anf_Licht_Wohnzimmer", val: false});
					}
			});
		};
		
	});  
	$( document ).on( 'change', '#Licht_EZ', function( e ) {
		//alert(debug);
		if(!g_b_block_update_event) {
			Plc.writeBool({
				name: ".vp_b_Anf_Licht_Esszimmer",
				val: true,
				ocd: 200,
				oc: function() {
				Plc.writeBool({name: ".vp_b_Anf_Licht_Esszimmer", val: false});
					}
			});
		};
		
	});  
	
	$( document ).on( 'change', '#Licht_FL', function( e ) {
		//alert(debug);
		if(!g_b_block_update_event) {
			Plc.writeBool({
				name: ".vp_b_Anf_Licht_Flur_EG",
				val: true,
				ocd: 200,
				oc: function() {
				Plc.writeBool({name: ".vp_b_Anf_Licht_Flur_EG", val: false});
					}
			});
		};
		
	});  
	
	$( document ).on( 'change', '#Licht_KU', function( e ) {
		//alert(debug);
		if(!g_b_block_update_event) {
			Plc.writeBool({
				name: ".vp_b_Anf_Licht_Kueche",
				val: true,
				ocd: 200,
				oc: function() {
				Plc.writeBool({name: ".vp_b_Anf_Licht_Kueche", val: false});
					}
			});
		};
		
	});  
	
	$( document ).on( 'change', '#Licht_GA', function( e ) {
		//alert(debug);
		if(!g_b_block_update_event) {
			Plc.writeBool({
				name: ".vp_b_Anf_Licht_Gast",
				val: true,
				ocd: 200,
				oc: function() {
				Plc.writeBool({name: ".vp_b_Anf_Licht_Gast", val: false});
					}
			});
		};
		
	});  
		
	</script>
</head>
<body>
	<div data-role="page" data-theme="a">
		<div data-role="header" data-position="inline">
			<h1>Licht</h1>
		</div>
		<div data-role="content" data-theme="a">
		
		<a data-role="button" data-icon="bars" data-iconpos="left" href="#PopupMenu1_menu" data-rel="popup" data-transition="slidedown" id="PopupMenu1_button">Wohnzimmer</a><div data-role="popup" id="PopupMenu1_menu">
		<ul data-role="listview" data-inset="true" id="PopupMenu1" width="90%">
		<li><a href="./Licht_Erdgeschoss.html"><strong>Licht EG</strong></a></li>
		<li><strong>Licht OG</strong></li>
		</ul>
		</div>
			
			<div class="ui-field-contain">
			<fieldset data-role="controlgroup">
				<label for="Licht_WZ">Wohnzimmer:</label>
				<input type="checkbox" data-role="flipswitch" name="Licht_1" id="Licht_WZ" data-on-text="An" data-off-text="Aus">
				<label for="Licht_EZ">Esszimmer:</label>
				<input type="checkbox" data-role="flipswitch" name="Licht_2" id="Licht_EZ" data-on-text="An" data-off-text="Aus">
				<label for="Licht_KU">Küche:</label>
				<input type="checkbox" data-role="flipswitch" name="Licht_3" id="Licht_KU" data-on-text="An" data-off-text="Aus">
				<label for="Licht_GA">Gast:</label>
				<input type="checkbox" data-role="flipswitch" name="Licht_4" id="Licht_GA" data-on-text="An" data-off-text="Aus">
				<label for="Licht_FL">Flur:</label>
				<input type="checkbox" data-role="flipswitch" name="Licht_5" id="Licht_FL" data-on-text="An" data-off-text="Aus">
			</fieldset>
			</div>
			</div>
	</div>
</body>
</html>