	/**
	 * 
	 * Javascript for tracking HTML eventse.
	 * 
	 * @name module_movies
	 * @author Chrsitian
	 * @since 2006-07-06
	 * @version 1.0.0
	 * @package reptileframework
	 * 
	 * 
	 */


	function $$(name)
	{
		return(document.getElementsByName(name));
	}
	
	
	function $(elementId)
	{
		return(document.getElementById(elementId));
	}
	
	function el_show(elementId)
	{
		var element = $(elementId);
		
		if (typeof(element.style) != "undefined")
		{
			element.style.display = "block";
			element.style.visibility = "visible";
		}
	}
	
	function el_hide(elementId)
	{
		var element = $(elementId);
		
		if (typeof(element.style) != "undefined")
		{
			element.style.display = "none";
			element.style.visibility = "hidden";
		}
	}
	
	function el_update(elementId, text)
	{
		var element = $(elementId);
		
		if (typeof(element.innerHTML) != "undefined")
		{
			element.innerHTML = text;
		}
	}
	
	function el_new_id(elementId, elementNewId)
	{
		var element = $(elementId);
		
		if (typeof(element.id) != "undefined")
		{
			element.id = elementNewId;
		}
	}
	
	function img_src(image, newsrc)
	{
		var img = document[image];
		
		if (typeof(img.src) != "undefined")
		{
			img.src = newsrc;
		}
	}
	
	function pop_window(mypage, myname, w, h, props) {
	
		var winl = (screen.width - w) / 2;
		var wint = (screen.height - h) / 2;
		winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+','+props
		win = window.open(mypage, myname, winprops)
		
		if (parseInt(navigator.appVersion) >= 4) { 
			win.window.focus(); 
		}
		
		return(win);
		
	}
	
	function do_check_uncheck(field, value)
	{
		if (value == true)
		{
			check_all(field);
		}
		else
		{
			uncheck_all(field);
		}
	}
	
	function check_all(field)
	{
		if (typeof(field.length) == 'undefined')
		{
			field.checked = true;
		}
		else
		{
			for(i = 0; i < field.length; i++)
			{
				field[i].checked = true;
			}
		}
	}
	
	function uncheck_all(field)
	{
		if (typeof(field.length) == 'undefined')
		{
			field.checked = false;
		}
		else
		{
			for(i = 0; i < field.length; i++)
			{
				field[i].checked = false;
			}
		}
	}
	
	function empty_select(field)
	{
		var length = field.length;
		
		for (i = 0; i < length; i++)
		{
			field.options[0] = null;
		}
	}
	
	function add_option(field, text, value, selected)
	{
		if (selected)
		{
			field.options.add(new Option(text, value, true, true));
		}
		else
		{
			field.options.add(new Option(text, value));
		}
	}
	
	function radio_hook(field, eventfunction)
	{
		for(i = 0; i < field.length; i++)
		{
			field[i].onclick = eventfunction;
		}
	}
	
	function radio_value(field)
	{
		for(i = 0; i < field.length; i++)
		{
			if (field[i].checked)
			{
				return(field[i].value);
			}
		}
		
		return('');
	}
	
	function switchlang()
	{
		var currentpage = document.location.href;
	//	currentpage = currentpage.toLowerCase();
		var position = currentpage.indexOf('lang=');
		
		if (position == -1)
		{
			if (currentpage.indexOf('?') != -1)
			{
				document.location = currentpage + '&lang=en';
			}
			else
			{
				document.location = currentpage + '?lang=en';
			}
		}
		else
		{
			var lang = currentpage.substr(position + 5, 2);	
			var newlocation = currentpage.substr(0, position + 5);
			
			if (lang == 'fr')
			{
				newlocation += 'en' + currentpage.substr(position + 7);
			}
			else
			{
				newlocation += 'fr' + currentpage.substr(position + 7);
			}
			
			document.location = newlocation;
		}
		
	}
	
	function validate_captcha(hash, value)
	{
		makePostRequest('captcha.php',  'hash=' + escape(hash) + '&value=' + escape(value), 'validate_captcha_handler');
	}
	
	function validate_captcha_handler()
	{
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				var response = http_request.responseXML.documentElement;
				var valid = response.getElementsByTagName('valid')[0].firstChild.data;
				
				if (Number(valid) == 1)
				{
					// captcha is valid
					captcha_validator(true);
				}
				else
				{
					// captcha is invalid
					captcha_validator(false);
				}
			}
		}
	}
	
	function generate_captcha()
	{
		makePostRequest('captcha.php?action=generate',  '', 'generate_captcha_handler');
	}
	
	function generate_captcha_handler()
	{
		if (http_request.readyState == 4)
		{
			if (http_request.status == 200)
			{
				var response = http_request.responseXML.documentElement;
				var newhash = response.getElementsByTagName('hash')[0].firstChild.data;
				
				captcha_reload(newhash);
			}
		}
	}
	
	function clearDefault(el) {
	  if (el.defaultValue==el.value) el.value = ""
	}
