	/**
	 * 
	 * Javascript functions for all the website.
	 * 
	 * @name module_movies
	 * @author Vincent Cantin Bellemare
	 * @since 2006-07-06
	 * @version 2.1.1
	 * @package reptileframework
	 * 
	 * 
	 */

	global_eval_action = ""

	function $$(name)
	{
		return(document.getElementsByName(name));
	}
	
	
	function $(elementId)
	{
		return(document.getElementById(elementId));
	}
	
	function remove_element(element)
	{
		parent_element = element.parentNode;
		parent_element.removeChild(element)
	}
	
	function remove_values_input(theElement)
	{
		theElement = theElement.cloneNode(true)
		rand = Math.random(0,3000);
		elements_inputs = theElement.getElementsByTagName('input');
		elements_inputs[0].value = ''
		elements_inputs[0].name = elements_inputs[0].name + rand 
		elements_inputs[0].id = elements_inputs[0].name + rand 
		elements_inputs[1].value = ''
		elements_inputs[1].name = elements_inputs[1].name + rand
		elements_inputs[1].id = elements_inputs[1].name + rand
		return theElement		
	}
	
	

	var counter = 0;
	function add_element(containerId,elementToAddId)
	{
		counter++;
		var newFields = document.getElementById(elementToAddId).cloneNode(true);
		newFields.id = '';
		newFields.style.display = 'block';
		var newField = newFields.childNodes;
		for (var i=0;i<newField.length;i++) {
			var theName = newField[i].name
			if (theName)
				newField[i].name = theName + counter;
		}
		var insertHere = document.getElementById(containerId);
		insertHere.parentNode.insertBefore(newFields,insertHere);
	}
	
	
	function _confirm(confirm_text, eval_action)
	{
		global_eval_action = eval_action
		$('confirmAdded').style.top = posTop() + ((pageHeight() - 165) / 2) + "px";
		$('confirmAddedText').innerHTML = confirm_text;
		onOffDiv('confirmAdded'); // show the confirmation

	}
		
	function show_email_form()
	{
		$('emailAdded').style.display='block';	
		$('emailAdded').style.visibilty='visible';	
	}
	
	
	function event_confirm(is_eval)
	{		
		if(is_eval)
		{
			eval(global_eval_action)
		}
		
		$('confirmAdded').style.display = 'none';
		$('confirmAdded').style.visibilty= 'hidden';
	}
	
	
	function display_fck()
	{
		_alert('test');	
	}
	
	

	function display_div(theDiv)
	{
		$(theDiv).style.display = 'block';
		$(theDiv).style.visibility = 'visible';
	}


	function hide_div(theDiv)
	{
		$(theDiv).style.display = 'none';
		$(theDiv).style.visibility = 'hidden';
	}


	function URLEncode(plaintext)
	{
		// The Javascript escape and unescape functions do not correspond
		// with what browsers actually do...
		var SAFECHARS = "0123456789" +					// Numeric
						"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
						"abcdefghijklmnopqrstuvwxyz" +
						"-_.!~*'()";					// RFC2396 Mark characters
		var HEX = "0123456789ABCDEF";
		var swapCodes   = new Array(8211, 8212, 8216, 8217, 8220, 8221, 8226, 8230);
		var swapStrings = new Array("-", "-", "'",  "'",  '"',  '"',  "*",  "...");
	
	   for(charId = 0; charId < swapCodes.length; charId++)
	   {
	      plaintext = plaintext.replace(eval("/" + String.fromCharCode(swapCodes[charId]) + "/g"), swapStrings[charId]);
	   }
		
		var encoded = "";
		for (var i = 0; i < plaintext.length; i++ ) 
		{
			var ch = plaintext.charAt(i);
			if (ch == " ") 
			{
				encoded += "+";				// x-www-urlencoded, rather than %20
			} 
			else if (SAFECHARS.indexOf(ch) != -1) 
			{
				encoded += ch;
			} 
			else 
			{
				var charCode = ch.charCodeAt(0);
				if (charCode > 255) 
				{
					_alert( "le caractère "+ ch + " génère un problème d'encodage. L'espace sera ainsi remplacé.", 0);
					encoded += "+";
				} 
				else 
				{
					encoded += "%";
					encoded += HEX.charAt((charCode >> 4) & 0xF);
					encoded += HEX.charAt(charCode & 0xF);
				}
			}
		} // for
	
		return encoded;
		
	};
	
	function URLDecode( )
	{
	   // Replace + with ' '
	   // Replace %xx with equivalent character
	   // Put [ERROR] in output if %xx is invalid.
	   var HEXCHARS = "0123456789ABCDEFabcdef"; 
	   var encoded = document.URLForm.F2.value;
	   var plaintext = "";
	   var i = 0;
	   while (i < encoded.length) {
		   var ch = encoded.charAt(i);
		   if (ch == "+") {
			   plaintext += " ";
			   i++;
		   } else if (ch == "%") {
				if (i < (encoded.length-2) 
						&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
						&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
					plaintext += unescape( encoded.substr(i,3) );
					i += 3;
				} else {
					alert( 'Bad escape combination near ...' + encoded.substr(i) );
					plaintext += "%[ERROR]";
					i++;
				}
			} else {
			   plaintext += ch;
			   i++;
			}
		} // while
	   document.URLForm.F1.value = plaintext;
	   return false;
	};


	function is_phones(phone1,phone2)
	{
		if(is_phone(phone1))
		{
			return true;	
		}
		
		if(is_phone(phone2))
		{
			return true;	
		}
		
		return false;
		
	}
	
	
	
	function is_credit_card(creditCard)
	{
		
		if(creditCard > 1000000000000000 && creditCard < 10000000000000000)
			return true;
		else
			return false;
			
		
	}
	
	
	function send_email()
	{

		var fv = new Form_validator($('email_automatic'));		
		fv.addElement('email_name','is_empty($(\'email_automatic\').name.value)','','*');
		fv.addElement('last_name','is_empty($(\'email_automatic\').email.value)','','*');

		if(fv.validate())
		{
			var req = new AJAX.Request('common.html',
				{
					method: 'GET',
					parameters: ['action=send_email', 'email=' + $('email_automatic').email.value ,  'name=' + $('email_automatic').name.value , 'description=' + $('email_automatic').description.value  ],
					onComplete : function(e) {ajax_eval(e.responseText)} 
				}			
			);
		}		
	}
	
	function _send_email(email_sended_text)
	{
		onOffDiv('emailAdded')
		_alert(email_sended_text)	
	}
	
	
	function _active(id, dateFormat)
	{
		theElement = "mod_timestamp_" + id
		
		if($(theElement))
		{
			$(theElement).innerHTML = dateFormat
		}
		else
		{
			trace('It misses ' + theElement)	
		}
		
	}
	
	function _alert(msg, timout)
	{
		$('popupAdded').style.top = posTop() + ((pageHeight() - 165) / 2) + "px";
		$('popupAddedText').innerHTML = msg
		onOffDiv('popupAdded'); // show the confirmation
		
		if(timout > 0)
		{
			window.setTimeout("hideDiv('popupAdded');", timout); // hide the confirmation in 3 seconds
		}
	}
	
	
	function preview_image(pix, width)
	{
		$('popupPreview').style.top = posTop() + ((pageHeight() - 165) / 2) + "px";
		$('popupPreviewPix').innerHTML = '<img width="'+ width +'" src="' + pix + '"/>';
		onOffDiv('popupPreview'); // show the confirmation
		light('popupPreview',true);
	}
	
	function preview_files(theFile)
	{
		window.open("pop_file0698.html?no_char_cut=1&amp;src="+theFile+"","win","width=800px,height=600px")
	}
	
	function ajax_eval(e)
	{
		eval(e);
	}
	
	function is_int(theInt)
	{
		if(isNaN(theInt))
		{
			return false;			
		}

		if(theInt > 0)
		{
			return true;
		}
	
		return false;
	}
	
	
	function is_postal_code(postal_code)
	{
		postal_code = postal_code.toUpperCase()
		var reg = /^([A-Z]){1}([0-9]){1}([A-Z]){1}([\.\ \-]){0,1}([0-9]){1}([A-Z]){1}([0-9]){1}$/;
		return reg.test(postal_code);	
		
	}
	
	
	function is_length(theValue, theNumber)
	{
		if(theValue.length > theNumber)
		{
			return true;			
		}

		return false;
	
	}
	
	function is_expiration(expiration)
	{
			expirationArray = Array
			expirationArray = expiration.split('default.asp');
		
			if(expirationArray.length != 2)
			{
				return false;	
			}

			/*
			The year is harcoded because we can't be shure to get the good year by javascript
			*/
			return (expirationArray[0] > 0 && expirationArray[0] < 13 &&  expirationArray[1] >= 07 && expirationArray[1] < 99  );	
	
	}
	
	
	function is_phone(phone)
	{
			if(phone.length<3)
			{
				return false;				 
			}

			 if(phone.match(/[\<\>\,\;\:\\\"\[\]]/) || phone.match(/[a-zA-Z]/))
			 {
				return false;				 
			 }
			 
			return true;			
	}
	
	function is_empty(theField)
	{
			if(theField.length > 0)
			{
				return true;				 
			}		
			
			return false;
	}
	
	function is_priceFormat(price){
		var reg = /^\d+[.]{1}\d{2}$/;
		return reg.test(price);
	}
	
	function is_timeFormat(time){
		var reg = /^(\d{1}|\d{2})[:]{1}\d{2}$/;
		return reg.test(time);
	}
	

	function is_dateFormat(time){
		var reg = /^\d{4}[-]{1}\d{2}[-]{1}\d{2}$/;
		return reg.test(time);
	}

	
	function is_float(theFloat){
		var reg = /^\d*[\,|\.]{0,1}\d{0,2}$/;
		return reg.test(time);

	}
	
	function is_email (strng) 
	{
		if (strng == "") 
		{
			return false;
		}
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
		if (reg.test(strng) == false)
		{
			return false;
		}
		else
		{
			return true;
		}
	}


	function is_year(theYear)
	{
		if(theYear > 1968 && theYear < 2500 )
		{
			return true
		}
		
		return false;
		
	}

	
	function is_positive_int(theNumber)
	{
		if(theNumber > 0 )
		{
			return true;
		}
		
		return false;
		
	}

	
	function required(theField)
	{
		return is_empty(theField);		
	}


	function generateValidator(string_validators , field , form  )
	{
		var function_generated = '';
		
		array_string_validators = string_validators.split(',')

		for( i in array_string_validators)
		{
			function_generated += array_string_validators[i] + '($("' + form + '").' + field + '.value ) '  
		}
		
		return function_generated;		
	}


	function style_div(theId, attribute)
	{
		$(theId).style.display = attribute;	
	}
	



	function trace(logprint)
	{
		if( window.console ) 
		{
			window.console.log( logprint ) ;
		}
	}


	function showDiv(divId)
	{
		var div = document.getElementById(divId);
		if (typeof div.style != "undefined")
		{
			div.style.visibility = "visible";
			div.style.display = "block";
		}
	}
	
	
	
	function hideDiv(divId)
	{
		var div = document.getElementById(divId);
		if (typeof div.style != "undefined")
		{
			div.style.visibility = "hidden";
			div.style.display = "none";	
		}
	}

	
	function is_explorer()
	{
		return (typeof document.body.style.maxHeight != "undefined") ? 0 : 1 ;	
	}



	function _displayNoneTimer(divToHide)
	{
		$(divToHide).style.display = 'none';
	}
	
	
	function displayNoneTimer(divToHide, timer)
	{
		if( $(divToHide) )
		{	
			RRRtimer = window.setTimeout("_displayNoneTimer('"+ divToHide +"')",timer);
		}
		else
		{
			trace('Errreur de id sur : ' + divToHide );	
		}
	}
	
	
	
	function onOffDiv(theDiv)
	{
		displayDiv = $(theDiv).style.display;
		if(displayDiv == 'none')
		{
			$(theDiv).style.display = 'block';
			$(theDiv).style.visibility = 'visible';
			light(theDiv,true)
		}
		else
		{
			$(theDiv).style.display = 'none';
			$(theDiv).style.visibility = 'hidden';
		}		
	}

	function Display_Div(theDiv)
	{
		displayDiv = $(theDiv).style.display;
		if(displayDiv == 'none')
		{
			$(theDiv).style.display = 'block';
		}
		else
		{
			$(theDiv).style.display = 'none';
		}
	}

	
	function priceFomat(num) 
	{
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		{
			num = "0";		
		}
	
		sign = (num == (num = Math.abs(num)));
		num = Math.floor(num*100+0.50000000001);
		cents = num%100;
		num = Math.floor(num/100).toString();
	
		if(cents<10)
		{
			cents = "0" + cents;			
		}

		for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
		{
			num = num.substring(0,num.length-(4*i+3))+','+
			num.substring(num.length-(4*i+3));		
		}

		return (((sign)?'':'-') + '' + num + '.' + cents + ' $');
	}
	
	function is_price(num) 
	{
		num = num.toString().replace(/\$|\,/g,'');
		if(isNaN(num))
		{
			return false;	
		}
		return true;
	}
	
	
	function img_order( id , newSrc)
	{
		theId = 'img_order_' + id
		if(theImage = document.getElementById(theId))
		{
				theImage.src = 'images/' + newSrc;
		}
	
	}
	
	function _replace_field(theField,theValue)
	{
		$(theField).value = theValue
	}
	
	function get_elements(element)
	{
		str = '';
		for( i in element)
		{
			str += element[i]
		}
		alert(str);
	}
	
	function update_field(lang,file,field,theInput, validator, page_site, query)
	{
		current_iframe ='wysiwyg' + theInput.id;
		
		if( $(current_iframe) )
		{
			theFrame = $(current_iframe);
			
			if(theFrame.contentDocument.body.innerHTML)
			{
				theInput.value = theFrame.contentDocument.body.innerHTML
			}
		
		}

		if(required(validator))
		{
			eval('if(' + validator + '(theInput.value) ) {field_validated = true;} else {field_validated = false;}')
		}
		else
		{
			field_validated = true;	
		}
		
		if(field_validated == false)
		{
			_alert('Format non valide',3000);	
			
			var req = new AJAX.Request('dictionary340d.html?action=replace_field',
				{
					method: 'POST',
					parameters: [ 'lang=' + lang, 'page_site=' + page_site , 'file=' + file, 'field=' + field , 'value=' + URLEncode(theInput.value), 'query=' + query ],
					onComplete : function(e) {ajax_eval(e.responseText)}
				}
			);	
		}
		else
		{
			var req = new AJAX.Request('dictionarycefb.html?action=update_field',
				{
					method: 'POST',
					parameters: [ 'page_site=' + page_site ,'lang=' + lang, 'file=' + file, 'field=' + field , 'value=' + URLEncode(theInput.value), 'query=' + query ],
					onComplete : function(e) {ajax_eval(e.responseText)}
				}
			);	
		}
	}
	
	function set_cookie (name, value) 
	{
		var argv = set_cookie.arguments;
		var argc = set_cookie.arguments.length;
		var expires=(argc > 2) ? argv[2] : null;
		var path=(argc > 3) ? argv[3] : null;
		var domain=(argc > 4) ? argv[4] : null;
		var secure=(argc > 5) ? argv[5] : false;
		document.cookie=name+"="+escape(value)+
			((expires==null) ? "" : ("; expires="+expires.toGMTString()))+
			((path==null) ? "" : ("; path="+path))+
			((domain==null) ? "" : ("; domain="+domain))+
			((secure==true) ? "; secure" : "");
	}
	
	function getCookieVal(offset) 
	{
		var endstr=document.cookie.indexOf (";", offset);
		if (endstr==-1)
				endstr=document.cookie.length;
		return unescape(document.cookie.substring(offset, endstr));
	}

	function cookie(name) 
	{
		var arg=name+"=";
		var alen=arg.length;
		var clen=document.cookie.length;
		var i=0;
		while (i<clen) 
		{
			var j=i+alen;
			if (document.cookie.substring(i, j)==arg)
			{		
				return getCookieVal (j);
			}
			
			i=document.cookie.indexOf(" ",i)+1;
			
			if (i==0) 
			{
				break;
			}
		}
		return null;
	}	
	
	/* Transparency */
	function light_up()
	{	
		if(!document.getElementById(obj_id))
		{
			return false;
		}
		
		if ( navigator.appName.indexOf("Netscape")!=-1 && parseInt(navigator.appVersion)>=5)
		{  
			document.getElementById(obj_id).style.MozOpacity=opacity/100
		}
		else if (navigator.appName.indexOf("Microsoft")!= -1 && parseInt(navigator.appVersion)>=4)
		{ 
			if(document.getElementById(obj_id).filters.alpha)
			{
				document.getElementById(obj_id).filters.alpha.opacity=opacity
			}
		}
	
	}

	
	
	function light_up_time()
	{		
			if(up_transition == true)
			{
				opacity += 7;
			}
			else
			{
				opacity -= 7;
			}
	
			light_up( opacity )
			max_timout ++;

			if(max_timout < 150)
			{
				setTimeout("light_up_time()",10);		
			}		
	
	}

	/* Global variables for the timer */
	opacity = 0;
	obj_id = '';
	max_timout = 0
	up_transition = true;

	function light(element_id,up)
	{
		obj_id = element_id
		up_transition = up
		
		if(up == true)
		{
			opacity = 0;
		}
		else
		{
			opacity = 100;	
		}
		
		max_timout = 0;		
		light_up_time(element_id,up);

	}
	
	
	
	function browser_status(status_text)
	{
		if(detect_explorer())
		{
			window.status = status_text
		}
		
	}
	
	function url_encode_elements_form(the_form)
	{
		inputs = the_form.getElementsByTagName('input')
		selects = the_form.getElementsByTagName('select')
		var elements_id = ''
		
		for(i in inputs)
		{
			if(inputs[i].id)
			{
				elements_id	+= ',' + inputs[i].id 
			}				
		}
		
		for(i in selects)
		{
			if(selects[i].id)
			{
				elements_id	+= ',' + selects[i].id 
			}				
		}
		
		return url_encode_elements(elements_id.substr(1))
	}
	
	function url_encode_elements(string_elements, is_separator)
	{	
		array_elements = string_elements.split(',');
	
		var url_encode = ''
	
		for(i in array_elements)
		{
			if(is_separator == true)
			{
				separator = (i==0) ? '?' : '&amp;';
			}
			else
			{
				separator = ',';	
			}

			current_element = array_elements[i];
			current_value = '';
			
			if($(current_element))
			{			
				if($(current_element).innerHTML)
				{
					current_value = escape($(current_element).innerHTML)
				}
							
				if($(current_element).value )
				{
					current_value = $(current_element).value
				}
			
				if($(current_element).type == "radio")
				{
					if($(current_element).checked)
					{
						current_value = '1'
					}
					else
					{
						current_value = '0'
					}
					
				}
				
				if($(current_element).type == "checkbox")
				{
					if ($(current_element).checked)
					{
						current_value = $(current_element).value;
					}
					else
					{
						continue;
					}
				}
			}
			else
			{
				eval('if(' + current_element + ') { current_value = ' + current_element + '.toString();} else {v="";}  ')
			}			
			
			var reg=new RegExp("(,)", "g");
			current_value = current_value.replace(reg,"~");
			var reg=new RegExp("(=)", "g");
			current_value = current_value.replace(reg,"°");
			current_url = separator + encode64(current_element + '=' + current_value); 
			url_encode += current_url;	
		}

		if(!is_separator)
		{
			return url_encode = 'values=' + escape(url_encode.substr(1))
		}

		return escape(url_encode)
	}
	
	function api_is_readable(readable,field_id)
	{
		var req = new AJAX.Request('common.html',
				{
					method: 'GET',
					parameters: 
					[
						'action=is_readable', 
						'readable=' + escape(readable), 
						'field_id=' + field_id
					],
					onComplete : function(e) {ajax_eval(e.responseText)}
				}
			);	
	}

	function append_help(element, msg)
	{
		if(!typeof(element) == 'object')
		{
			trace('Not an element');
			return false;
		}
	
		span = document.createElement('span');
		span.style.fontSize = '9px'
		span.setAttribute('onclick','display_inversed()');
		inserted_image = document.createElement('img');
		inserted_image.src = 'images/s_really.html';
		inserted_image.style.cursor = 'pointer';
		inserted_image.setAttribute('onmousemove','showToolTip(event,\''+ msg + '\');return false');
		inserted_image.setAttribute('onmouseout','hideToolTip()');
		span.appendChild(inserted_image);
		element.parentNode.insertBefore(span,element.nextSibling)
	}
	
	function showToolTip(e,text)
	{
		if(document.all)e = event;
		
		var obj = document.getElementById('bubble_tooltip');
		var obj2 = document.getElementById('bubble_tooltip_content');
		obj2.innerHTML = text;
		obj.style.display = 'block';
		var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
		if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
		var leftPos = e.clientX - 100;
		if(leftPos<0)leftPos = 0;
		obj.style.left = leftPos + 'px';
		obj.style.top = e.clientY - obj.offsetHeight -1 + st + 'px';
	}	

	function hideToolTip()
	{
		document.getElementById('bubble_tooltip').style.display = 'none';
	}
	
	function change_dict_fields(fieldsData)
	{
		parent.document.getElementById("dic_fields").innerHTML = decode64(fieldsData);
	}
	
	function alert64(text)
	{
		alert(decode64(text));
	}
	
