var movie_group_on_page = false;
var what_movie_on_page = 0;

var bg_color = "DDDDDD";
var border_color = "BBBBBB";
var bg_1_color = "D1D1D1";
var bg_2_color = "EEEEEE";
var title_color = "6666FF";
var sub_title_color = "6666FF";
var text_color = "000000";

function f_image_changer(what_image, image_id){
	document.getElementById(image_id).src = page_location + "php_scripts/img.php?what_img=" + what_image;
}

function f_span_switch(image_id, what_image_up, what_image_down, what_spawn, switch_state){
	if(window[switch_state]){
		document.getElementById(image_id).src = page_location + "php_scripts/img.php?what_img=" + what_image_up;
		document.getElementById(what_spawn).style.display = 'none';
	}else{
		document.getElementById(image_id).src = page_location + "php_scripts/img.php?what_img=" + what_image_down;
		document.getElementById(what_spawn).style.display = 'block';
	}
	window[switch_state] = !window[switch_state];
}

function f_span_switch_close(image_id, what_image_up, what_spawn, switch_state){
	document.getElementById(image_id).src = page_location + "php_scripts/img.php?what_img=" + what_image_up;
	document.getElementById(what_spawn).style.display = 'none';
	window[switch_state] = false;
}

function f_form_submit(form_id){
	document.getElementById(form_id).submit();
}

function f_change_bg_color(what_color, what_id){
	document.getElementById(what_id).style.backgroundColor = what_color;
}

function f_link_function(where_to){
	document.location = where_to;
}

function f_convert_to_html_safe(what_text){
	what_text = what_text.replace(/&/g, '&amp;');
	what_text = what_text.replace(/÷/g, '&divide;');
	what_text = what_text.replace(/×/g, '&times;');
	what_text = what_text.replace(/®/g, '&reg;');
	what_text = what_text.replace(/©/g, '&copy;');
	what_text = what_text.replace(/§/g, '&sect;');
	what_text = what_text.replace(/€/g, '&euro;');
	what_text = what_text.replace(/¥/g, '&yen;');
	what_text = what_text.replace(/£/g, '&pound;');
	what_text = what_text.replace(/¢/g, '&cent;');
	what_text = what_text.replace(/'/g, '&apos;');
	what_text = what_text.replace(/"/g, '&quot;');
	what_text = what_text.replace(/>/g, '&gt;');
	what_text = what_text.replace(/</g, '&lt;');
	what_text = what_text.replace(/\r\n/g, '<br />');
	what_text = what_text.replace(/\r/g, '<br />');
	what_text = what_text.replace(/\n/g, '<br />');
	return what_text;
}

function f_convert_text(what_text){
	what_text = f_convert_to_html_safe(what_text);
	
	var text_parts_array = what_text.split('&lt;a href=&quot;');
	what_text = text_parts_array[0];
	var counter = 1;
	while(counter < text_parts_array.length){
		var pattern = /javascript:/i ;
		if(pattern.test(text_parts_array[counter])){
			what_text += '&lt;a href=&quot;' + text_parts_array[counter];
		}else{
			var temp_text_part = '';
			var text_segment = text_parts_array[counter].split('&quot;&gt;', 2);
			if(text_segment.length > 1){
				temp_text_part = '<a href="' + text_segment[0] + '">';
				text_segment[1] = text_parts_array[counter].slice(text_segment[0].length + 10);
				var text_segment_2 = text_segment[1].split('&lt;/a&gt;', 2);
				if(text_segment_2.length > 1){
					text_segment_2[1] = text_parts_array[counter].slice(text_segment[0].length + text_segment_2[0].length + 20);
					what_text += temp_text_part + text_segment_2[0] + '</a>' + text_segment_2[1];
				}else{
					what_text += '&lt;a href=&quot;' + text_parts_array[counter];
				}
			}else{
				what_text += '&lt;a href=&quot;' + text_parts_array[counter];
			}
		}
		counter++;
	}
	
	what_text = what_text.replace(/\r\n/g, '<br />');
	what_text = what_text.replace(/\r/g, '<br />');
	what_text = what_text.replace(/\n/g, '<br />');
	
	return what_text;
}

function f_check_password_1(password){
	var error = "";
	var pattern = /[^A-Za-z0-9!@#$%&'*+/=?^_`{|}~-]/;
	if(pattern.test(password)){
		error += "Your password may only contain letters, numbers and the folowing characters !@#$%&'*+/=?^_`{|}~-.";
	}
	if(password.length < 8){
		if(error != ""){
			error += " \n";
		}
		error += "Your password needs to be at least 8 characters long.";
	}else if(password.length > 80){
		if(error != ""){
			error += " \n";
		}
		error += "Your password may not contain more than 80 characters.";
	}
	
	return error;
}

function f_check_password_for_weakness(password){
	var error = "";
	pattern = /[A-Z]/;
	var pattern_2 = /[a-z]/;
	var pattern_3 = /[0-9]/;
	var pattern_4 = /[!@#$%&'*+/=?^_`{|}~-]/;
		
	if(!pattern.test(password) || !pattern_2.test(password) || !pattern_3.test(password) || !pattern_4.test(password)){
		error = "This is a relatively weak password, a strong password contains one or more characters from the folowing four groups: \n\nABCDEFGHIJKLMNOPQRSTUVWXYZ \nabcdefghijklmnopqrstuvw \n01223456789 \n!@#$%&\'*+/=?^_`{|}~-";
	}
	return error;
}


function f_compare_passwords(password_1, password_2){
	var error = "";
	if(password_1 != password_2){
		error = "The Confirm password field does not equal the password field.";
	}
	return error;
}

function f_display_switch(edit_it, switch_what){
	if(edit_it){
		document.getElementById('show_'+switch_what).style.display = 'none';
		document.getElementById('edit_'+switch_what).style.display = 'block';
	}else{
		document.getElementById('show_'+switch_what).style.display = 'block';
		document.getElementById('edit_'+switch_what).style.display = 'none';
	}
}
