/**
	This script was created by Lasse R. Brock
	 
	The purpose is to provide generic javascript functions that can be used over and over 
	 
	The Ajax Queue System Example:
	 
	[Here we build the request]
		var function_to_call_before_sending = loading();
		var function_to_call_on_return = handleGetMap();
		ajaxQueueCancelThese('map_data'); (Only used if nessesary to cancel other requests of the same tag in the queue)
		ajaxQueueAdd('GET', url, 'map_data', function_to_call_before_sending, function_to_call_on_return, null);
	[Here we recieve the request data]
	****** Notice the use of receiveReq_ajax_queue ******
	function handleGetMap() 
	{	
		var data = receiveReq_ajax_queue.responseText;
	}
**/

/** 
	Required JS:
	php.js is required
**/

window.onload = joinFunctions(window.onload, function(){if(typeof is_numeric != 'function')
{
	alert("Husk at include php.js");
}})

/** Can be used when you want to use window.onload from several different files **/
/** What it does is to continually increase the amount of information stored in window.onload, and when we're done loading, execute it **/
/** Example: window.onload = joinFunctions(window.onload, myNewFunction ); **/
function joinFunctions(function1, function2) 
{
    return function() {
        if (function1)
            function1();
        if (function2)
            function2();
    }
}

/** Detecting browser **/
if(navigator.userAgent.indexOf('Trident') != -1 || navigator.userAgent.indexOf('MSIE') != -1){var browser = "ie";}
else{var browser = "not ie";}
/** And browser version **/
if(navigator.appVersion.indexOf('MSIE 8.0') != -1){var browser_version = 8;}
else if(navigator.appVersion.indexOf('MSIE 7.0') != -1){var browser_version = 7;}
else if(navigator.appVersion.indexOf('MSIE 6.0') != -1){var browser_version = 6;}
else{var browser_version = 'not ie';}

var overlay_zindex_counter = 900000;
var active_overlay_ids_array = new Array();
var receiveReq_ajax_queue = getXmlHttpRequestObject();
var ajax_queue_array = new Array();
var ajax_queue_timer = "";
var ajax_queue_current_tag = undefined;
var ajax_queue_request_validity = true;

function ajaxQueue()
{	
	if(ajax_queue_array.length > 0)
	{	
		/** We run the next element from the queue **/	
		if (receiveReq_ajax_queue.readyState == 4 || receiveReq_ajax_queue.readyState == 0)
		{		
			/** Running and removing the next element **/
			var ajax_data = ajax_queue_array.shift();
						
			/** Executing the functions **/
			ajax_data[3]();
			receiveReq_ajax_queue.open(ajax_data[0], ajax_data[1], true);
			/** Setting the onreadystate function **/
			receiveReq_ajax_queue.onreadystatechange = function(){ajaxQueueObjectReturn(ajax_data[4])};
			/** If we're dealing with a post we need to set the headers **/
			if(ajax_data[0].toLowerCase() == 'post')
			{
				receiveReq_ajax_queue.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
				receiveReq_ajax_queue.setRequestHeader("Content-length", ajax_data[5].length);
				receiveReq_ajax_queue.setRequestHeader("Connection", "close");
			}
			/** Submitting the request **/
			receiveReq_ajax_queue.send(ajax_data[5]);
			/** Setting the current tag so that we may invalidate it later if we need to **/
			ajax_queue_current_tag = ajax_data[2];
		}
	}
		
	if(ajax_queue_array.length > 0)
	{
		/** If there's data in the queue we call this function again in 0.5 second **/
		clearTimeout(ajax_queue_timer);
		ajax_queue_timer = setTimeout("ajaxQueue();", 500);
	}
}

function ajaxQueueAdd(method, url, tag, function_to_call_before_sending, function_to_call_on_return, send_body)
{
	if(method != undefined)
	{		
		if(send_body == undefined)
		{
			send_body = null;
		}
		/** Adding the object to the queue **/
		ajax_queue_array.push(new Array(method, url, tag, function_to_call_before_sending, function_to_call_on_return, send_body));
	}
	
	ajaxQueue();
}

var ajax_queue_request_data = "";
var ajax_queue_request_obj = null;

function ajaxQueueObjectReturn(function_to_call)
{
	if (receiveReq_ajax_queue.readyState == 4) 
	{		
		ajax_queue_current_tag = undefined;
		if(ajax_queue_request_validity)
		{
			ajax_queue_request_data = receiveReq_ajax_queue.responseText;
			ajax_queue_request_obj = receiveReq_ajax_queue;
			if(typeof function_to_call == 'function')
			{
				function_to_call();
			}
		}
		else
		{
			ajax_queue_request_validity = true;
		}
	}
}

function ajaxQueueCancelThese(tag)
{	
	for(x in ajax_queue_array)
	{
		if(ajax_queue_array[x][2] == tag)
		{			
			ajax_queue_array.splice(x,1);
		}
	}
	
	if(ajax_queue_current_tag == tag)
	{
		ajax_queue_request_validity = false;
		ajax_queue_current_tag = undefined;
	}	
}

function ajaxRequest(method, url, function_to_call_on_return, send_body)
{
	if(method != undefined)
	{		
		if(send_body == undefined)
		{
			send_body = null;
		}
		
		/** Creating a new object **/
		var ajax_request_object = getXmlHttpRequestObject();
		
		ajax_request_object.open(method, url, true);
		/** Setting the onreadystate function **/
		ajax_request_object.onreadystatechange = function(){ajaxRequestObjectReturn(ajax_request_object, function_to_call_on_return)};
		/** If we're dealing with a post we need to set the headers **/
		if(method.toLowerCase() == 'post')
		{
			ajax_request_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			ajax_request_object.setRequestHeader("Content-length", send_body.length);
			ajax_request_object.setRequestHeader("Connection", "close");
		}
		/** Submitting the request **/
		ajax_request_object.send(send_body);
	}
}

var ajax_request_data = "";
var ajax_request_obj = null;
function ajaxRequestObjectReturn(request_object, function_to_call)
{
	if (request_object.readyState == 4) 
	{		
		ajax_request_data = request_object.responseText;
		ajax_request_obj = request_object;
		if(typeof function_to_call == 'function')
		{
			function_to_call();
		}
		/** Destroying the object **/
		request_object = null;
	}
}

function createVeil(final_fade, do_fade, color, function_to_execute_when_done, pause_between_fade_incrementions)
{
	setDocumentHeightAndWidth();
	var body_dom = document.getElementsByTagName('body')[0];

	/** We create the protective layer that will make sure that the user cannot click on anything except our overlay **/
	var protective_div = document.createElement('div');
	protective_div.id = 'protective_div';				
	
	/** Styling the protective div **/
	protective_div.style.position = "absolute";
	if(browser != "ie")
	{
		protective_div.style.position = "fixed";
	}
	
	protective_div.style.top 	= "0px";
	protective_div.style.left 	= "0px";
	protective_div.style.width 	= document_total_width+"px";
	protective_div.style.height = document_total_height+"px";
	
	if(color == undefined)
	{
		color = "#000000";
	}
	protective_div.style.backgroundColor = color;
	protective_div.style.zIndex = overlay_zindex_counter;
	protective_div.style.opacity = 0;
	protective_div.style.display = 'inline';
	
	/** Appending it to the body **/
	body_dom.appendChild(protective_div);
	
	/** Updating the zindex counter **/
	overlay_zindex_counter++;
	
	if(browser_version == 6)
	{
		hideSelects();
	}
	
	if(final_fade != undefined)
	{
		if(do_fade != undefined && do_fade)
		{
			fadeElement(protective_div, 0, final_fade, 'in', function_to_execute_when_done, pause_between_fade_incrementions);
		}
		else
		{
			if(browser == 'ie')
			{
				protective_div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity='+final_fade+')';	
				protective_div.style.filter = 'alpha(opacity='+final_fade+');';
			}
			else
			{
				protective_div.style.opacity = final_fade/100;
			}
			
			if(typeof function_to_execute_when_done == 'function')
			{
				function_to_execute_when_done();
			}
		}
	}
	else
	{
		if(browser == 'ie')
		{
			protective_div.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity=50)';	
			protective_div.style.filter = 'alpha(opacity=50);';
		}
		else
		{
			protective_div.style.opacity = 0.5;
		}
		
		if(typeof function_to_execute_when_done == 'function')
		{
			function_to_execute_when_done();
		}		
	}
	
	if(browser == 'ie')
	{
		protective_div.onmousewheel = joinFunctions(protective_div.onmousewheel, function(){handleVeilScroll();});
		window.onresize 			= joinFunctions(window.onresize, function(){handleVeilScroll();});
	}		
}

function handleVeilScroll()
{
	var veil = getElement("protective_div");
	if(veil)
	{
		setDocumentHeightAndWidth();
		veil.style.width 	= document_total_width+"px";
		veil.style.height 	= document_total_height+"px";		
	}
}

function createOverlay(data, position, top, left, id, create_this_overlay_at_this_element, dragable, dragable_element_in_data)
{
	if(top == undefined)
	{
		top = 'center';
	}
	else if(top != 'center')
	{
		top = parseInt(top);
	}
	
	if(left == undefined)
	{
		left = 'center';
	}
	else if(left != 'center')
	{
		left = parseInt(left);
	}
	
	if(position == undefined)
	{
		position = "fixed";
	}

	var body_dom = document.getElementsByTagName('body')[0];
	
	/** Creating an overlay **/		
	var overlay_div = document.createElement('div');

	if(id == undefined)
	{
		id = 'overlay_div_'+overlay_zindex_counter;
	}
	
	/** Setting the id of the overlay **/
	overlay_div.id = id;
	
	/** Addding this overlay's id to the array of active overlays **/
	active_overlay_ids_array.push(id);
	
	/** A few styles **/
	overlay_div.style.position = 'absolute'; // IE doesn't understand fixed so it's always absolute
	if(browser != 'ie')
	{		
		overlay_div.style.position = position;
	}

	overlay_div.style.zIndex = overlay_zindex_counter;
	overlay_zindex_counter++;
	
	/** Inserting the data **/
	if(data != undefined)
	{
		overlay_div.innerHTML = data;	
	}	
	
	/** Now we append this overlay to the body **/
	body_dom.appendChild(overlay_div);
	
	if(dragable != undefined && dragable)
	{
		/** This overlay should be dragable **/
		if(dragable_element_in_data != undefined)
		{
			dragable_element_in_data 				= getElement(dragable_element_in_data);
			dragable_element_in_data.onmousedown	= function(event){startDragging(event, id);};
			dragable_element_in_data.onmouseup		= function(){cancelDragging();};			
		}
		else
		{
			overlay_div.onmousedown	= function(event){startDragging(event, this);};
			overlay_div.onmouseup	= function(){cancelDragging();};
		}
	}
	
	/** Positioning the overlay **/
	if(create_this_overlay_at_this_element != undefined && getElement(create_this_overlay_at_this_element))
	{		
		var obj_positions 		= getPositionOfObject(create_this_overlay_at_this_element).split(";");		
		overlay_div.style.left 	= (obj_positions[0]*1+left)+"px";
		overlay_div.style.top 	= (obj_positions[1]*1+top)+"px";
	}
	else
	{
		if(top == "center")
		{
			centerObject("top", id);
		}
		else
		{
			overlay_div.style.top = top+"px";	
		}
		
		if(left == "center")
		{
			centerObject("left", id);
		}
		else
		{
			overlay_div.style.left = left+"px";
		}
	}
	
	if(position == "fixed" && browser == 'ie')
	{
		window.onscroll = joinFunctions(window.onscroll, function(){ieFixed(id, top, left)});
		window.onresize = joinFunctions(window.onresize, function(){ieFixed(id, top, left)});
	}
}

function ieFixed(obj, top, left)
{
	var obj = getElement(obj);
	
	if(obj)
	{
		/** Updating window dimensions **/
		updateWindowDimensions();	
		
		if(top == undefined || top == "center")
		{
			centerObject("top", obj);
		}
		else
		{
			obj.style.top = (window_scroll_y+top)+"px";
		}
		
		if(left == undefined || left == "center")
		{
			centerObject("left", obj);
		}
		else
		{
			obj.style.left = (window_scroll_x+left)+"px";
		}
	}
}

function centerObject(type, obj)
{	
	var obj = getElement(obj);
	
	/** Updating window dimensions **/
	updateWindowDimensions();
			
	/** Getting objects dimensions **/
	var width = obj.offsetWidth;
	var height = obj.offsetHeight;		
		
	if(type != undefined && type == "top")
	{		
		obj.style.top 	= (window_scroll_y)+(window_height/2)-(height/2)+"px";
	}
	else if(type != undefined && type == "left")
	{
		obj.style.left 	= (window_scroll_x)+(window_width/2)-(width/2)+"px";
	}
	else
	{
		obj.style.top 	= (window_scroll_y)+(window_height/2)-(height/2)+"px";
		obj.style.left 	= (window_scroll_x)+(window_width/2)-(width/2)+"px";			
	}
	
	if(parseInt(obj.style.top) < 0)
	{
		obj.style.top = '0px';
	}
	if(parseInt(obj.style.left) < 0)
	{
		obj.style.left = '0px';
	}
}

function closeOverlay(id_to_close)
{
	if(id_to_close != undefined)
	{
		if(getElement(id_to_close))
		{
			removeElementFromDom(id_to_close);
			active_overlay_ids_array = unset(active_overlay_ids_array, id_to_close);
		}
	}
	else
	{
		/** We close all overlays **/
		for(x in active_overlay_ids_array)
		{
			removeElementFromDom(active_overlay_ids_array[x]);
		}
		active_overlay_ids_array = new Array();
	}
}

function closeVeil(fadeout, pause_between_fade_incrementions)
{
	var protective_div = getElement('protective_div');
	if(protective_div)
	{
		if(browser == 'ie')
		{
			/** Stopping the onscroll function **/
			protective_div.onmousewheel = '';			
		}
		
		if(fadeout != undefined && fadeout)
		{		
			var current_fade = 0;
			
			if(browser == 'ie')
			{
				current_fade = protective_div.filters[0].opacity;
			}
			else
			{
				current_fade = protective_div.style.opacity*100;
			}
			
			fadeElement(protective_div, current_fade, 0, 'out', function(){ removeElementFromDom("protective_div"); }, pause_between_fade_incrementions);
		}
		else
		{		
			removeElementFromDom("protective_div");
		}		
	}

	if(browser_version == 6)
	{
		showSelects();
	}
}

function fadeElement(obj, current_fade, final_fade, direction, function_to_execute_when_done, pause_between_fade_incrementions)
{	
	obj = getElement(obj);
	if(direction == undefined)
	{
		direction = 'in';
	}
	
	if(pause_between_fade_incrementions == undefined)
	{
		pause_between_fade_incrementions = 25;
	}
	
	/** Setting the fade to current_fade **/
	obj.style.zoom = 1;
	if(browser == "ie")
	{
		obj.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(Opacity='+current_fade+')';	
		obj.style.filter = 'alpha(opacity='+current_fade+');';
	}
	else
	{
		obj.style.opacity = current_fade/100;
	    obj.style.MozOpacity = current_fade/100;
	    obj.style.KhtmlOpacity = current_fade/100;		
	}
	
	if(direction == 'in')
	{
		/** Increasing the current_fade by 10% **/
		current_fade += 10;
		
		if(current_fade <= final_fade)
		{
			/** We have some more fading to do **/
			setTimeout(function(){fadeElement(obj, current_fade, final_fade, direction, function_to_execute_when_done, pause_between_fade_incrementions)}, pause_between_fade_incrementions);
		}
		else if(typeof function_to_execute_when_done == 'function')
		{
			function_to_execute_when_done();
		}
	}
	else
	{
		/** Decreasing the current_fade by 10% **/
		current_fade -= 10;
		
		if(current_fade >= final_fade)
		{
			/** We have some more fading to do **/
			setTimeout(function(){fadeElement(obj, current_fade, final_fade, direction, function_to_execute_when_done, pause_between_fade_incrementions)}, pause_between_fade_incrementions);
		}
		else if(typeof function_to_execute_when_done == 'function')
		{
			function_to_execute_when_done();
		}
	}
}

function hideSelects()
{
	var select_objects = document.getElementsByTagName("select");	
	for(var i=0;i<select_objects.length;i++)
	{
		select_objects[i].style.display = 'none';
	}
}

function showSelects()
{
	var select_objects = document.getElementsByTagName("select");	
	for(var i=0;i<select_objects.length;i++)
	{
		select_objects[i].style.display = 'inline';
	}
}

function removeElementFromDom(id_or_dom_element)
{
	id_or_dom_element = getElement(id_or_dom_element);
	
	if(id_or_dom_element != undefined)
	{
		id_or_dom_element.parentNode.removeChild(id_or_dom_element);
	}
}

function remObj(id_or_dom_element)
{
	removeElementFromDom(id_or_dom_element);
}

function getElement(id_or_dom_element)
{
	if(typeof(id_or_dom_element) != 'object')
	{
		id_or_dom_element = document.getElementById(id_or_dom_element);
	}
	
	if(typeof(id_or_dom_element) != 'object')
	{
		return false;
	}
	else
	{
		return id_or_dom_element;	
	}
}

var window_height = 0;
var window_width = 0;
var window_scroll_y = 0;
var window_scroll_x = 0;
function updateWindowDimensions()
{	
	if(browser == "ie")
	{
		/** Scroll Y **/
		if(document.documentElement && document.documentElement.scrollTop != 0)
		{
			window_scroll_y = document.documentElement.scrollTop;
		}
		else
		{
			window_scroll_y = document.body.scrollTop;
		}
		
		/** Scroll X **/
		if(document.documentElement && document.documentElement.scrollLeft != 0)
		{
			window_scroll_x = document.documentElement.scrollLeft;
		}
		else
		{
			window_scroll_x = document.body.scrollLeft;
		}
		
		/** Height **/
		if(document.documentElement && document.documentElement.clientHeight != 0)
		{
			window_height = document.documentElement.clientHeight;
		}
		else
		{
			window_height = document.body.clientHeight;
		}

		/** Width **/
		if(document.documentElement && document.documentElement.clientWidth != 0)
		{
			window_width = document.documentElement.clientWidth;
		}
		else
		{
			window_width = document.body.clientWidth;
		}	
	}
	else
	{
		window_scroll_y = window.pageYOffset;
		window_scroll_x = window.pageXOffset;
		window_width 	= window.innerWidth;
		window_height 	= window.innerHeight;		
	}
}

var document_total_height = "";
var document_total_width = "";

function setDocumentHeightAndWidth()
{
	var body = document.body, html = document.documentElement;
	
	document_total_height = Math.max( body.scrollHeight, body.offsetHeight,  html.clientHeight, html.scrollHeight, html.offsetHeight );
	document_total_width = Math.max( body.scrollWidth, body.offsetWidth,  html.clientWidth, html.scrollWidth, html.offsetWidth );
		
	if(browser == "ie" && browser_version < 8)
	{
		document_total_height = (Math.max( body.scrollHeight, body.offsetHeight,  html.clientHeight, html.scrollHeight, html.offsetHeight )-5);
		document_total_width = (Math.max( body.scrollWidth, body.offsetWidth,  html.clientWidth, html.scrollWidth, html.offsetWidth )-21);		
	}
}

var current_popup = "";
/** Keep in mind that ie doesn't accept spaces and - in winName **/
function popupWindow(theURL, winName, width, height) 
{	
	if(winName == undefined)
	{
		winName = "popup";
	}
	if(width == undefined)
	{
		width = 200;
	}
	if(height == undefined)
	{
		height = 200;
	}
		
	var features = "width="+width+", height="+height;
	/** We make sure that the popup opens in the middle of the users screen **/
	updateWindowDimensions();
	var top = (window_height/2)-(height/2);
	var left = (window_width/2)-(width/2);	
	features += ", top="+top+", left="+left;
	
	current_popup = window.open(theURL, winName, features);	
	if(current_popup == null)
	{
		/** Popup was catched by a popup blocker **/
		alert("Popup caught by popup blocker");
	}
	else
	{
		if(typeof popupSpecificFunction == 'function')
		{
			window.onfocus = popupSpecificFunction;
		}
		current_popup.focus();				
	}	
}

/** Switches the display of the two provided objects, if the 3rd parameter is sent that object is given focus in the end **/
function sdoto(obj_to_show, obj_to_hide, focus_this_object)
{
	switchDisplayOfTheseObjects(obj_to_show, obj_to_hide, focus_this_object);
}

function switchDisplayOfTheseObjects(obj_to_show, obj_to_hide, focus_this_object)
{
	obj_to_show = getElement(obj_to_show);
	obj_to_hide = getElement(obj_to_hide);
	
	obj_to_show.style.display = 'inline';
	obj_to_hide.style.display = 'none';
	
	if(focus_this_object != undefined)
	{		
		focus_this_object = getElement(focus_this_object);
		focus_this_object.focus();
	}	
}

/** Switches the visibility of the provided object **/
function svote(obj)
{
	switchVisibilityOfThisElement(obj);
}

function switchVisibilityOfThisElement(obj)
{
	obj = getElement(obj);
	if(obj.style.visibility == 'hidden'){obj.style.visibility = 'visible';}	
	else{obj.style.visibility = 'hidden';}	
}

function getXmlHttpRequestObject() 
{
	if (window.XMLHttpRequest) 
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject) 
	{
		return new ActiveXObject('Microsoft.XMLHTTP');
	}
	else 
	{
		alert('Status: Cound not create XmlHttpRequest Object.' + 'Consider upgrading your browser.');
	}
}

function unset(array, item_to_remove)
{
	/** Getting the array position of the element and removing it when found **/
	for(x in array)
	{
		if(array[x] == item_to_remove)
		{
			/** Removing the element from the array **/
			array.splice(x, 1);
			break;
		}
	}
	
	return array;
}

window.onload = joinFunctions(window.onload, keepAlive);

function keepAlive()
{ 	
	if(typeof(keep_alive_url) !== 'undefined' && keep_alive_url != "")
	{
		setTimeout("keepAlive()", 600000);
		ajaxRequest('GET', keep_alive_url);
	}
}

function getPositionOfObject(obj) 
{
	obj = getElement(obj);
	return findPosX(obj)+";"+findPosY(obj);
}

function findPosX(obj) 
{
	var curleft = 0;
	if (obj) 
	{
		if (obj.offsetParent) 
		{
			while (obj.offsetParent) 
			{
				curleft += obj.offsetLeft
				obj = obj.offsetParent;
			}
		}
		else if (obj.x) 
		{
			curleft += obj.x;
		}
	}
	return curleft;
}

function findPosY(obj) 
{
	var curtop = 0;
	if (obj) 
	{
		if (obj.offsetParent) 
		{
			while (obj.offsetParent) 
			{
				curtop += obj.offsetTop
				obj = obj.offsetParent;
			}
		}
		else if (obj.y) 
		{
			curtop += obj.y;
		}
	}
	return curtop;
}

function getSelectValue(select_obj)
{
	var select_obj = getElement(select_obj);
	return select_obj.options[select_obj.selectedIndex].value;
}

function getSelectText(select_obj)
{
	var select_obj = getElement(select_obj);
	return select_obj.options[select_obj.selectedIndex].text;	
}

/** Validation **/
var validation_array = new Array();
function addValidationElement(element_to_validate, type_of_element, alert_on_error, empty_allowed)
{
	if(empty_allowed == undefined)
	{
		empty_allowed = false;
	}
	
	if(alert_on_error == undefined)
	{
		alert_on_error = '';
	}
	
	if(getElement(element_to_validate) && type_of_element != undefined && type_of_element != '')
	{
		validation_array.push(new Array(element_to_validate, type_of_element, alert_on_error, empty_allowed));
	}
}

var validation_error_color = "#D30000";
var validation_ok_color = "";

function doValidation()
{
	var validation_passed = true;

	/** We run through the array, setting all fields to the validation_ok_color **/
	for(x in validation_array)
	{
		if(getElement(validation_array[x][0]))
		{
			var element_to_validate = getElement(validation_array[x][0]);
			var type_of_element = validation_array[x][1];
			
			element_to_validate.style.borderStyle = "";
			element_to_validate.style.borderColor = validation_ok_color;		
		}
	}	
		
	/** Now for the actual validation **/
	for(x in validation_array)
	{
		/** Setting up variables **/
		var element_to_validate = getElement(validation_array[x][0]);
		var type_of_element = validation_array[x][1];
		var alert_on_error = validation_array[x][2];
		var empty_allowed = validation_array[x][3];
		
		if(type_of_element == 'email')
		{						
			var email_validation_string = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/
			
			/** Checks if the element was allowed to be empty **/
			if(empty_allowed && element_to_validate.value == '')
			{
				
			}
			/** Checks if the content is an email **/
			else if(element_to_validate.value.search(email_validation_string) == -1)
			{
				validation_passed = false;
			}
			
		}
		else if(type_of_element == 'text')
		{			
			/** Checks if the element was allowed to be empty **/
			if(empty_allowed && element_to_validate.value == '')
			{
				
			}
			/** Checks if there's content set **/
			else if(element_to_validate.value == "")
			{
				validation_passed = false;
			}			
		}
		else if(type_of_element == 'numeric')
		{
			/** Checks if the element was allowed to be empty **/
			if(empty_allowed && element_to_validate.value == '')
			{
				
			}
			/** Checks if the content is_numeric **/
			else if(!is_numeric(element_to_validate.value))
			{
				validation_passed = false;
			}						
		}
		
		/** Validation failed, we color the field alert the error and stop **/
		if(!validation_passed)
		{
			if(element_to_validate != undefined)
			{
				element_to_validate.focus();
				element_to_validate.style.borderStyle = "solid";
				element_to_validate.style.borderColor = validation_error_color;
			}
						
			if(alert_on_error != '')
			{
				alert(alert_on_error);	
			}			
			break;
		}
	}
	
	return validation_passed;
}

function createSubmitButton(id, value)
{
	var container = getElement(id);
	container.innerHTML = '<input type="submit" value="'+value+'">';
}

function fadeInFadeOutAndRemove(data, time_to_display, fade_in_time, fade_out_time, position, top, left, function_to_run_when_done)
{
	if(time_to_display == undefined)
	{
		time_to_display = 2000;
	}
	if(fade_in_time == undefined)
	{
		fade_in_time = 75;
	}
	if(fade_out_time == undefined)
	{
		fade_out_time = 75;
	}
	
	if(position == undefined)
	{
		position = 'fixed';
	}
	
	createOverlay(data, position, top, left);
	fadeElement("overlay_div", 0, 100, "in", function(){setTimeout(function(){fadeElement("overlay_div", 100, 0, "out", function(){remObj("overlay_div"); if(function_to_run_when_done != undefined){function_to_run_when_done();}}, fade_out_time);}, time_to_display);}, fade_in_time);	
}

var preloaded_images_array = new Array();
function preloadThisImage(complete_image_path)
{
	var array_length = preloaded_images_array.length;
	preloaded_images_array[array_length] = new Image();
	preloaded_images_array[array_length].src = complete_image_path;
}

var mouseX = "";
var mouseY = "";
function setMouseXY(e) 
{
  if (browser == "ie") { // grab the x-y pos.s if browser is IE
    mouseX = event.clientX + document.body.scrollLeft;
    mouseY = event.clientY + document.body.scrollTop;
  } else {  // grab the x-y pos.s if browser is NS
    mouseX = e.pageX;
    mouseY = e.pageY;
  }  
  // catch possible negative values in NS4
  if (mouseX < 0){mouseX = 0;}
  if (mouseY < 0){mouseY = 0;}
}


var dragged_obj;
var capturedMouseX;
var capturedMouseY;
var objectCapturedX;
var objectCapturedY;

function startDragging(e, obj)
{
	dragged_obj = getElement(obj);
    
	/** If this object isn't the top object, we make it the top object **/
	if((dragged_obj.style.zIndex*1+1) < overlay_zindex_counter)
	{
		dragged_obj.style.zIndex = overlay_zindex_counter;
		overlay_zindex_counter++;
	}
    setMouseXY(e);
    capturedMouseX = mouseX;
    capturedMouseY = mouseY;
    
    objectCapturedX = parseInt(dragged_obj.style.left+0);
    objectCapturedY = parseInt(dragged_obj.style.top+0);
    
    document.onmousemove = dragObject;
    return false;
}

function cancelDragging()
{
	document.onmousemove = '';
}

function dragObject(e)
{
	setMouseXY(e);
	
    dragged_obj.style.left 	= objectCapturedX + mouseX - capturedMouseX;
    dragged_obj.style.top 	= objectCapturedY + mouseY - capturedMouseY;
    
    return false;
}