/*
function Get_object_absolute_postion( obj_html_tag )
function MenuBarOnMouseOver( str_popupmenu )
function Hide_popupmenu( str_popupmenu )
function Visible_iframe( str_iframe_id, str_style_visibility )
function Combos_visibility( b_visible )
function Display_MDI_page( str_title, str_url, n_width, n_height )
function window_resize_MDI()
function Hide_MDI_frame()
function Fade_MDI_shadow( n_fade_to )
function Set_object_opacity( obj_object, n_opacity )
function Check_text( obj_input, n_min_length, str_error_message, b_ignore, b_display_alert )
function AddToFavorite( str_url, str_description )
function Move_frame_to_center( str_frame_id )
*/

function Get_object_absolute_postion( obj_html_tag )
{
	var obj_parent = obj_html_tag.offsetParent;
	var n_loop = 0;
	var n_offSet_left = obj_html_tag.offsetLeft;
	var n_offSet_top = obj_html_tag.offsetTop;

	while(obj_parent.tagName != "BODY" && n_loop < 100)
	{
		n_offSet_left += obj_parent.offsetLeft;
		n_offSet_top += obj_parent.offsetTop;
		obj_parent = obj_parent.offsetParent;
		n_loop++;
	}
	n_offSet_left += obj_parent.offsetLeft;
	n_offSet_top += obj_parent.offsetTop;
	return(n_offSet_left + ";" + n_offSet_top);
}

function MenuBarOnMouseOver( str_popupmenu )
{
	var obj_popupmenu = document.getElementById(str_popupmenu);
	var obj_href = obj_popupmenu.parentNode.getElementsByTagName("A")[0];
	var str_coords = new String(Get_object_absolute_postion(obj_href));
	var str_list_item = new Array();

	Combos_visibility(false);
	
	str_list_item = str_coords.split(";");
	obj_popupmenu.style.left = (eval(str_list_item[0]) + 3) + "px";
	obj_popupmenu.style.top = (eval(str_list_item[1]) + obj_href.clientHeight) + "px";
	document.getElementById(str_popupmenu).style.display = "block";
	document.getElementById(str_popupmenu).style.zIndex = 999;
	
}

function Hide_popupmenu( str_popupmenu )
{
	document.getElementById(str_popupmenu).style.display = "none";
	Combos_visibility(true);
}

function Visible_iframe( str_iframe_id, str_style_visibility )
{
	if(document.getElementById(str_iframe_id))
	{
		document.getElementById(str_iframe_id).style.visibility = str_style_visibility;
	}
	if(top.PostingViewer)
	{
		if(top.PostingViewer.document.getElementById(str_iframe_id))
		{
			top.PostingViewer.document.getElementById(str_iframe_id).style.visibility = str_style_visibility;
		}
	}
}

function Combos_visibility( b_visible )
{
	var obj_selects = document.getElementsByTagName("SELECT");
	var i;
	var obj_IMG;
	var obj_frame_container;
	var obj_select;
	
  	if(window.navigator.appName == "Microsoft Internet Explorer")
	{
		if(window.navigator.appVersion.search("6.0") > 0)
		{
			for(i=0; i<obj_selects.length;i++)
			{
				obj_frame_container = obj_selects[i].parentNode;
				if(b_visible)
				{
					if(document.getElementById("virtual_select_" + i))
					{
						obj_frame_container.removeChild(document.getElementById("virtual_select_" + i));
					}
				}
				else
				{
					try
					{
						obj_IMG = document.createElement("img");
						obj_IMG.className = "C_VIRTUAL_SELECT";
						obj_IMG.id = "virtual_select_" + i;
						obj_IMG.style.width = (obj_selects[i].clientWidth - 38) + "px";
						obj_IMG.style.height = "0px"; //(obj_selects[i].clientHeight - 2) + "px";
						obj_IMG.src = "about:blank";
						obj_frame_container.insertBefore(obj_IMG, obj_selects[i]);
					}
					catch(err) {}
				}
				obj_selects[i].style.display = b_visible ? "" : "none";
			}
		}
	}
}

function Display_MDI_page( str_title, str_url, n_width, n_height )
{
	Visible_iframe("DirectLinkViewer", "hidden");

	window.onresize = window_resize_MDI;
	document.documentElement.style.overflow = "hidden";
	document.body.style.marginRight = "21px";
	document.getElementById("frame_mdi").style.width = n_width + "px";
	document.getElementById("frame_mdi").style.height = n_height + "px";
	document.getElementById("frame_mdi_title").innerHTML = str_title;
	document.getElementById("frame_mdi_iframe").style.width = (n_width - 6) + "px";
	document.getElementById("frame_mdi_iframe").style.height = (n_height - 33) + "px";
	document.getElementById("frame_mdi_shadow").style.display = "block";
	document.getElementById("frame_mdi").style.display = "block";
	if(str_url != "")
	{
		document.getElementById("frame_mdi_iframe").src = str_url;
	}
	window_resize_MDI();
	Fade_MDI_shadow(50);
}
function window_resize_MDI()
{
	var frame_shadow = document.getElementById("frame_mdi_shadow");
	var frame_mdi = document.getElementById("frame_mdi");
	var n_scrollLeft = window.pageXOffset || document.body.scrollLeft || document.documentElement.scrollLeft;
	var n_scrollTop = window.pageYOffset || document.body.scrollTop || document.documentElement.scrollTop;

	frame_shadow.style.width = (document.documentElement.clientWidth + 50) + "px";
	frame_shadow.style.height = (document.documentElement.clientHeight + 500) + "px";
	frame_mdi.style.left = (n_scrollLeft + ((document.documentElement.clientWidth - frame_mdi.clientWidth) / 2)) + "px";
	frame_mdi.style.top = (n_scrollTop + ((document.documentElement.clientHeight - frame_mdi.clientHeight) / 2)) + "px";
}
function Hide_MDI_frame()
{
	document.getElementById("frame_mdi").style.display = "none";
	//document.getElementById("frame_mdi_iframe").src = "about:blank";
	document.getElementById("frame_mdi_iframe").contentWindow.document.body.innerHTML = "<HTML><BODY BGCOLOR=RED x=#000000></BODY></HTML>";
	Fade_MDI_shadow(0);
	Visible_iframe("DirectLinkViewer", "");
}
var m_n_MDI_shadow_opacity = 0;
function Fade_MDI_shadow( n_fade_to )
{
	if(m_n_MDI_shadow_opacity < n_fade_to)
	{
		m_n_MDI_shadow_opacity+=4;
	}
	else if(m_n_MDI_shadow_opacity > n_fade_to)
	{
		m_n_MDI_shadow_opacity-=4;
	}
	
	Set_object_opacity(document.getElementById("frame_mdi_shadow"), m_n_MDI_shadow_opacity);
	if(m_n_MDI_shadow_opacity == 0)
	{
		document.getElementById("frame_mdi_shadow").style.display = "none";
		document.documentElement.style.overflow = "";
		document.body.style.marginRight = "";
	}
	if(Math.abs(m_n_MDI_shadow_opacity - n_fade_to) < 4)
	{
		Set_object_opacity(document.getElementById("frame_mdi_shadow"), n_fade_to);
	}
	else
	{
		setTimeout("Fade_MDI_shadow(" + n_fade_to + ");", 10);
	}
}

function Set_object_opacity( obj_object, n_opacity )
{
    if(navigator.appName.indexOf("Netscape") != -1 && parseInt(navigator.appVersion) >=5)
	{
		obj_object.style.MozOpacity = n_opacity / 100;
		obj_object.style.KhtmlOpacity = n_opacity / 100;
	}
	else if(navigator.appName == "Microsoft Internet Explorer")
	{
		obj_object.filters.alpha.opacity = n_opacity;
	}
	else
	{
		try
		{
			obj_object.style.Opacity = n_opacity / 100;
			obj_object.style.opacity = n_opacity / 100;
		}
		catch(err) {}
	}
}

function IsEmail( str_email )
{
	var obj_RegExp = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/;
	return(obj_RegExp.exec(str_email) != null)
}

function Check_text( obj_input, n_min_length, str_error_message, b_ignore, b_display_alert )
{
	var b_result = true;
	if(!b_ignore)
	{
		b_result = (obj_input.value.length >= n_min_length);
		if(!b_result)
		{
			if(b_display_alert)
			{
				alert(str_error_message);
				obj_input.focus();
			}
		}
	}
	return(b_result);
}

function AddToFavorite( str_url, str_description )
{
	var b_result = true;
	try
	{
		if(window.sidebar)
		{
			// Mozilla Firefox Bookmark	
			window.sidebar.addPanel(str_description, str_url,"");
		}
		else if(window.external)
		{
			// IE Favorite
			window.external.AddFavorite(str_url, str_description);
		}
	}
	catch(err)
	{
		b_result = false;
	}
	if(!b_result)
	{
		alert("Can't add to favorites");
	}
}

function Date_OnBlur( obj_input )
{
	var str_date = new String(Trim(obj_input.value));
	var str_list_item = new Array();
	                
	if(str_date != "")
	{
		str_date = RemoveDoubleSpace(str_date);
		str_date = Replace(str_date, ".", "/");
		str_date = Replace(str_date, "-", "/");
		str_date = Replace(str_date, " ", "/");
 		str_list_item = str_date.split("/");
		if(str_list_item.length == 3)
		{
			if(Val(str_list_item[0]) == 0) { str_list_item[0] = "1"; }
			if(Val(str_list_item[0]) < 10) { str_list_item[0] = "0" + Val(str_list_item[0]); }
			if(Val(str_list_item[1]) < 10) { str_list_item[1] = "0" + Val(str_list_item[1]); }
			if(Val(str_list_item[2]) < 50)
			{
				str_list_item[2] = 2000 + Val(str_list_item[2]);
			}
			else if( Val(str_list_item[2]) < 100 )
			{
				str_list_item[2] = 1900 + Val(str_list_item[2]);
			}
			obj_input.value = str_list_item.join("/");
		}
	}
}

function Replace( str_expression, str_find, str_replace )
{
	var str_result = new String(str_expression);

	if(str_find.substr(0, 1) != "-")
	{
		return(eval("str_result.replace(/[" + str_find + "]/g, '" + str_replace + "');"));
	}
	else
	{
		return(eval("str_result.replace(/" + str_find + "/g, '" + str_replace + "');"));
	}
}

function Val( str_expression )
{
	var n_result = 0;
	var str_string = new String();
	
	try
	{
		if(str_expression != "")
		{
			str_string = "" + str_expression;
			str_string = Replace(str_string, "'", "");
			while(str_string.substr(0, 2) == "00" || (str_string.substr(0, 1) == "0" && str_string.length > 1))
			{
				str_string = str_string.substring(1);
			}
			
			if( str_string.indexOf(".") >= 0 )
			{
				n_result = eval(str_string + "0");
			}
			else
			{
				n_result = eval(str_string + ".0");
			}
		}
	}
	catch(err)
	{
		n_result = 0;
	}
	
	return(n_result);
}

function Trim( str_expression )
{
	str_expression = str_expression.replace(/^\s+/g, "");
	return(str_expression.replace(/\s+$/g, ""));
}

function RemoveDoubleSpace( str_expression )
{
	var str_result = new String(str_expression);
    str_result = str_result.replace(/[\s]{2,}/g," "); // Enlève les espaces doubles, triples, etc.
    //str_result = str_result.replace(/^[\s]/, ""); // Enlève les espaces au début
    //str_result = str_result.replace(/[\s]$/,""); // Enlève les espaces à la fin
    return(str_result);
}

function Set_object_class( obj_element, str_new_class )
{
	if(obj_element.className != str_new_class)
	{
		obj_element.className = str_new_class;
	}
}

function Move_frame_to_center( str_frame_id )
{
	var obj_frame = document.getElementById(str_frame_id);
	
	if(obj_frame.offsetWidth > 0)
	{
		obj_frame.style.position = "absolute";
		obj_frame.style.left = Math.round(((document.documentElement.clientWidth - obj_frame.offsetWidth) / 2)) + "px";
		obj_frame.style.top = Math.round((((document.documentElement.clientHeight / 2) - obj_frame.offsetHeight) / 2)) + "px";
	}
	else
	{
		setTimeout("Move_frame_to_center('" + str_frame_id + "');", 1000);
	}
}

