var box;
window.addEvent('domready', function(){

	/* Initiating the checklist functions */
	if($chk($('SUPPORTFORM'))){
	
		$('CHECK_01').addEvent('click',function(e){
			toggleChecks(this,$('CHECK_02'));
			toggleChecks(this,$('CHECK_03'));
		});
	
	}
	

	/* Setting up the submitbutton event */
	if($chk($('SUPPORTFORM'))){
		$('btn_submit').addEvent('click',function(e){
			e.stop();
			$('SUPPORTFORM').submit();
		});
	}

	/* Making the whole index-element clickable */
	if($chk($('index'))){
		$('index').addEvent('click',function(e){
			e.stop();
			document.location.href = this.getFirst().get('href');
		});
	}

	/* generic code to open all links with rel=_blank in new window, to pass validation in xhtml strict. */
	$$('a').each(function(link,i){
		if(link.get('rel')=='_blank') link.setProperty('target','_blank');
	});	
	/* end link code */

	/* Standard function to give mCCWrapper the remaining window height if avoidElements is defined */
	//	autosize_mCCWrapper();

	if($chk($('link_video'))){
		var averlay = new overlay();
	    box = new multiBox('mb',{ 
	        overlay: averlay,
	        movieWidth: 816,
	        movieHeight: 520
	    });		
	}
	
	if($chk($('administrasjonsveiledningC'))){
		var flashvars = {}
		flashvars.file = 'http://timeflex.no/new/_video/administrasjonsveiledning.f4v';
		flashvars.width = 800;
		flashvars.height = 500;
		var params = {}
		params.wmode = "opaque";
		params.enableFullscreen = true ;

		swfobject.embedSWF('http://timeflex.no/new/_swf/AIVideoPlayer.swf', 'administrasjonsveiledning', 800, 500, '9.0.0', '/swf/expressInstall.swf', flashvars, params);

	}

	if($chk($('brukerveiledningC'))){
		var flashvars = {}
		flashvars.file = 'http://timeflex.no/new/_video/brukerveiledning.f4v';
		flashvars.width = 800;
		flashvars.height = 500;
		var params = {}
		params.wmode = "opaque";
		params.enableFullscreen = true ;

		swfobject.embedSWF('http://timeflex.no/new/_swf/AIVideoPlayer.swf', 'brukerveiledning', 800, 500, '9.0.0', '/swf/expressInstall.swf', flashvars, params);

	}
	
	if($chk($('installasjonC'))){
		var flashvars = {}
		flashvars.file = 'http://timeflex.no/new/_video/installasjon.f4v';
		flashvars.width = 800;
		flashvars.height = 500;
		var params = {}
		params.wmode = "opaque";
		params.enableFullscreen = true ;

		swfobject.embedSWF('http://timeflex.no/new/_swf/AIVideoPlayer.swf', 'installasjon', 800, 500, '9.0.0', '/swf/expressInstall.swf', flashvars, params);

	}
});

window.addEvent('resize', function(){
	
	/* Standard function to give mCCWrapper the remaining window height if avoidElements is defined */
	//	autosize_mCCWrapper();
	
});


function toggleChecks(parent,el){
	chk = parent.get('checked');
	tmp = (chk?'':'disabled');
	el.set('disabled',tmp);
}

function formhandler(form){
	form.addEvent('submit', function(e){
		e.stop();
		
		form.set('send', {
			onComplete : function(response){
				var result = JSON.decode(response);
				var msg = "";
				
				for(var i in result){
					msg = msg + '\r\n' + result[i];
				}
				
				alert(msg);
			}
		});
		
		form.send();
	});
}
