// JavaScript Document




// Sets the section height 
function getSectionHeight(id, sections_total) {
	
		var total_sections_height = sections_total; // total height of other sections
		
		var windowHeight=0;
		if ( typeof( window.innerHeight )=='number' ) {
			windowHeight=window.innerHeight;
			//windowHeight=window.document.body.offsetHeight;
		}
		else {
			if ( document.documentElement && document.documentElement.clientHeight ) {
				windowHeight=document.documentElement.clientHeight;
			}
			else {
				if ( document.body&&document.body.clientHeight ) {
					windowHeight=document.body.clientHeight;
				}
			}
		}

	var section_height = windowHeight - total_sections_height;  

	document.getElementById(id).style.height = section_height + "px";

	}




//------------------------------------ Displays a real time clock ----------------------------------------//

function Display_Time(currentlang){
//alert(currentlang);
		var currenttime = new Date();
		var hours = currenttime.getHours();
		var minutes = currenttime.getMinutes();
		var seconds = currenttime.getSeconds();
		var timesuffix = "AM";
		
		if ( currentlang == "en" ){
			  
					if (hours > 11){
						timesuffix = "PM";
						hours = hours - 12;
					}
					
					if (hours == 0){
						hours = 12;
					}
		}
		else {
			
			 var timesuffix = ""; // fr
			
		}
		
		if (minutes < 10){
			minutes = "0" + minutes;
		}
		
		if (seconds < 10){
			seconds = "0" + seconds;
		}

		var clocklocation = document.getElementById("clock");
		clocklocation.innerHTML = hours + ":" + minutes + ":" + seconds + " " + timesuffix;

		setTimeout("Display_Time('"+currentlang+"')", 1000);
	
}



//--------------------------------- Set Menu Width -----------------------------------//

function Set_Menu_Width() {
	var menu_width = 0;	
	if ( document.getElementById("menu") ) {
		if ( document.getElementById("navmenu") ) {
  	var menu = document.getElementById("menu");
  	var menu_ul = document.getElementById("navmenu"); 
			//alert(menu_ul.offsetWidth);
	  //menu.style.width = String(parseInt(menu_ul.offsetWidth + 34) )+ "px";
		 if ( parseInt(menu_ul.offsetWidth + 4) <= 738 ) {
			 menu.style.width = '738px';
			} else {
				menu.style.width = String(parseInt(menu_ul.offsetWidth + 4) )+ "px";
			}
		}
	}
}


// ------------------------------  Menu Functions ------------------------------------//

function hover_onmouseover( obj, background_img, current_browser ) {
  
		if ( current_browser == "Explorer" ) {
   obj.className += " iehover";			
		}
		obj.style.background = "url(" + background_img + ")";

}

function hover_onmouseout( obj, background_img, current_browser ) {
 
	if ( current_browser == "Explorer" ) {
	 obj.className = obj.className.replace(new RegExp(" iehover\\b"), "");
	}
	obj.style.background = "url(" + background_img + ")";

}


// -------------- Shows the clicked row of a list. Example : news list ---------------//

function List_Show_Hide( list_name, total_rows, current_id ) {

 var list_row;
	var i;
	
	for ( i = 1; i <= total_rows; i++ ) {		

		list_row = document.getElementById( list_name + "_" + i );

  if ( i == current_id ) {
		 list_row.style.display='';
		} else { 
		 list_row.style.display='none';
		}
	}

}


function Check_Newsletter_Email() {
	email = document.forms['frm_newsletter_signup'].newsletter_email;
	
	if ( isEmail( email.value ) ) {
		return true;
	} else {
		alert(Get_Txt("MSG_INVALID_EMAIL"));
		email.value ='';
		email.focus();
		return false;
	}
	
	
}



//  check email format
//  str : string (email) to check 
function isEmail( str ) 
{
// are regular expressions supported?
	var supported = 0;
	
	if ( window.RegExp ) 
	{
		var tempStr = "a";
		var tempReg = new RegExp( tempStr );
		if ( tempReg.test( tempStr ) ) 
		{
			supported = 1;
		}
	}
	
	if ( !supported ) 
	{
		return ( str.indexOf(".") > 2 ) && ( str.indexOf("@") > 0 );
	}
	
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,10}|[0-9]{1,3})(\\]?)$");
	
	return ( !r1.test(str) && r2.test(str) );
}



// ------------------------- Opens a new window ----------------------------- //

function Open_Window( url, win_name, features ) {
  my_win = window.open( url, win_name, features);
		my_win.focus();
}



// Retrieves the text specified by the id from the aLang array
// textid : id of the text
function Get_Txt( textid )
{
	
	var string = "";
	if ( TXT[textid] == null )
	{
		string = textid;
	} 
	else{
		string = TXT[textid];
	}			
	
	return string;
}



//************************************************************************************************//
//************************************** MEMBERSHIP FORM *****************************************//
//************************************************************************************************//

// --------------------- copy member address info -------------------------- //

function Copy_Member_Address( form_name, prefix ) {

		// fields to copy
		var fields = Array( 'address', 'city', 'postal_code', 'country', 'province_state' );
		
		if ( document.forms[form_name].elements[prefix+'_same_as_company'].checked ){
				for ( i=0; i<fields.length; i++ ){
				  document.forms[form_name].elements[prefix+'_'+fields[i]].value = document.forms[form_name].elements[fields[i]].value;
				}
		} else {
				for ( i=0; i<fields.length; i++ ){
						if ( fields[i] == "country" ){
							 document.forms[form_name].elements[prefix+'_'+fields[i]].value = "canada";
						} else {
				    document.forms[form_name].elements[prefix+'_'+fields[i]].value = "";
						}
				}
	 }
		
}

// --------------------------- validate form ------------------------------- //

function Validate_Membership_Form( form_name ) {

  var bypass = false; // set to true to bypass the check
		
		if ( !bypass ){

				if ( document.forms[form_name].elements['membership_category'] && document.forms[form_name].elements['membership_category'].value == "" ){
						alert( Get_Txt('MSG_CHOOSE_MEMBERSHIP_CATEGORY') );
						document.forms[form_name].elements['membership_category'].focus();
						return false;
				}
				
				// main company coordinates
				if ( document.forms[form_name].elements['company_name'] && document.forms[form_name].elements['company_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_COMPANY_NAME') );
						document.forms[form_name].elements['company_name'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['address'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_ADDRESS') );
						document.forms[form_name].elements['address'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['postal_code'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_POSTAL_CODE') );
						document.forms[form_name].elements['postal_code'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['city'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_CITY') );
						document.forms[form_name].elements['city'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['telephone'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PHONE') );
						document.forms[form_name].elements['telephone'].focus();
						return false;
				}
				if ( !isEmail( document.forms[form_name].elements['email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['email'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['province_state'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PROVINCE') );
						document.forms[form_name].elements['province_state'].focus();
						return false;
				}
				
				// exports percentage
				if ( !Check_Exports_Percentage( form_name ) ){
						alert( Get_Txt('MSG_EXPORTS_PERCENTAGE') );
						document.forms[form_name].elements['exports_us'].focus();
						return false;
				}
		
				// primary contact
				if ( document.forms[form_name].elements['primary_contact_first_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_FIRST_NAME') );
						document.forms[form_name].elements['primary_contact_first_name'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_last_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_LAST_NAME') );
						document.forms[form_name].elements['primary_contact_last_name'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_title'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_TITLE') );
						document.forms[form_name].elements['primary_contact_title'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_address'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_ADDRESS') );
						document.forms[form_name].elements['primary_contact_address'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_postal_code'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_POSTAL_CODE') );
						document.forms[form_name].elements['primary_contact_postal_code'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_city'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_CITY') );
						document.forms[form_name].elements['primary_contact_city'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_telephone'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PHONE') );
						document.forms[form_name].elements['primary_contact_telephone'].focus();
						return false;
				}
				if ( !isEmail( document.forms[form_name].elements['primary_contact_email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['primary_contact_email'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_country'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_COUNTRY') );
						document.forms[form_name].elements['primary_contact_country'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['primary_contact_province_state'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PROVINCE') );
						document.forms[form_name].elements['primary_contact_province_state'].focus();
						return false;
				}


   if ( document.forms[form_name].elements['accounting_first_name'].value != "" ){
				
				if ( !isEmail( document.forms[form_name].elements['accounting_email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['accounting_email'].focus();
						return false;
				}
			
			}

		}
		
		document.forms[form_name].submit();
		
}

// ----------------- check total percentage of exports --------------------- //

function Check_Exports_Percentage( form_name ) {

		var exports = Array( 'exports_us', 'exports_europe', 'exports_asia', 'exports_others' );
		var total;
		total = 0; 
																																																								
		for ( var i=0; i<exports.length;i++ ){
			 var temp_export = exports[i];
				total += parseInt( document.forms[form_name].elements[temp_export].value );
		}

  if ( total != 100 && total != 0 ){
	   return false;
		} else {
				return true;
		}

}




// --------------------------- validate suggestion box form ------------------------------- //

function Validate_Suggestion_Box_Form( form_name ) {

				// main company coordinates
				if ( document.forms[form_name].elements['subject'].value == "" ) {
						alert( Get_Txt('MSG_EMPTY_SUBJECT') );
						document.forms[form_name].elements['subject'].focus();
						return false;
				}
				
				// main company coordinates
				if ( document.forms[form_name].elements['comments'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_COMMENTS') );
						document.forms[form_name].elements['comments'].focus();
						return false;
				}
				
				// main company coordinates
				if ( document.forms[form_name].elements['first_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_FIRST_NAME') );
						document.forms[form_name].elements['first_name'].focus();
						return false;
				}
				
				// main company coordinates
				if ( document.forms[form_name].elements['last_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_LAST_NAME') );
						document.forms[form_name].elements['last_name'].focus();
						return false;
				}
				
				// main company coordinates
				if ( document.forms[form_name].elements['phone'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PHONE') );
						document.forms[form_name].elements['phone'].focus();
						return false;
				}
				
				// main company coordinates
				if ( !isEmail(document.forms[form_name].elements['email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['email'].focus();
						return false;
				} 
				
		document.forms[form_name].submit();
}




// --------------------------- validate form ------------------------------- //

function Validate_Event_Identification( form_name ) {


				// main company coordinates
				if ( document.forms[form_name].elements['company_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_COMPANY_NAME') );
						document.forms[form_name].elements['company_name'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['address'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_ADDRESS') );
						document.forms[form_name].elements['address'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['postal_code'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_POSTAL_CODE') );
						document.forms[form_name].elements['postal_code'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['city'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_CITY') );
						document.forms[form_name].elements['city'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['telephone'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PHONE') );
						document.forms[form_name].elements['telephone'].focus();
						return false;
				}
				if ( !isEmail( document.forms[form_name].elements['email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['email'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['province_state'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PROVINCE') );
						document.forms[form_name].elements['province_state'].focus();
						return false;
				}
				
				if ( document.forms[form_name].elements['billing_first_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_FIRST_NAME') );
						document.forms[form_name].elements['billing_first_name'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['billing_last_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_LAST_NAME') );
						document.forms[form_name].elements['billing_last_name'].focus();
						return false;
				}					
				if ( document.forms[form_name].elements['billing_address'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_ADDRESS') );
						document.forms[form_name].elements['billing_address'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['billing_postal_code'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_POSTAL_CODE') );
						document.forms[form_name].elements['billing_postal_code'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['billing_city'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_CITY') );
						document.forms[form_name].elements['billing_city'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['billing_telephone'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PHONE') );
						document.forms[form_name].elements['billing_telephone'].focus();
						return false;
				}
				if ( !isEmail( document.forms[form_name].elements['billing_email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['billing_email'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['billing_province_state'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PROVINCE') );
						document.forms[form_name].elements['billing_province_state'].focus();
						return false;
				}
       
				document.forms[form_name].submit();
}




function Validate_Event_Member_Identify( form_name ){
	   				
				if ( document.forms[form_name].elements['username'].value == "" ){					
						document.forms[form_name].elements['username'].focus();
						return false;
				}
	
	   
				if ( document.forms[form_name].elements['password'].value == "" ){					
						document.forms[form_name].elements['password'].focus();
						return false;
				}
				
				document.forms[form_name].submit();
}




function Copy_Billing_Address( form_name, prefix ) {

		// fields to copy
		var fields = Array( 'address', 'city', 'postal_code', 'country', 'province_state', 'telephone', 'fax', 'email' );
		
		if ( document.forms[form_name].elements[prefix+'_same_as_company'].checked ){
				for ( i=0; i<fields.length; i++ ){
				  document.forms[form_name].elements[prefix+'_'+fields[i]].value = document.forms[form_name].elements[fields[i]].value;
				}
		} else {
				for ( i=0; i<fields.length; i++ ){
						if ( fields[i] == "country" ){
							 document.forms[form_name].elements[prefix+'_'+fields[i]].value = "canada";
						} else {
				    document.forms[form_name].elements[prefix+'_'+fields[i]].value = "";
						}
				}
	 }
		
}


function Validate_Event_Participants( form_name ) {
	

	if ( document.forms[form_name].elements['participant_0_first_name'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_FIRST_NAME') );
			document.forms[form_name].elements['participant_0_first_name'].focus();
			return false;
	}
	if ( document.forms[form_name].elements['participant_0_last_name'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_LAST_NAME') );
			document.forms[form_name].elements['participant_0_last_name'].focus();
			return false;
	}
	if ( document.forms[form_name].elements['participant_0_title'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_TITLE') );
			document.forms[form_name].elements['participant_0_title'].focus();
			return false;
	}
	if ( document.forms[form_name].elements['participant_0_address'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_ADDRESS') );
			document.forms[form_name].elements['participant_0_address'].focus();
			return false;
	}
	if ( document.forms[form_name].elements['participant_0_city'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_CITY') );
			document.forms[form_name].elements['participant_0_city'].focus();
			return false;
	}
	if ( document.forms[form_name].elements['participant_0_province_state'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_PROVINCE') );
			document.forms[form_name].elements['participant_0_province_state'].focus();
			return false;
	}
	if ( document.forms[form_name].elements['participant_0_postal_code'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_POSTAL_CODE') );
			document.forms[form_name].elements['participant_0_postal_code'].focus();
			return false;
	}
	if ( !isEmail( document.forms[form_name].elements['participant_0_email'].value ) ){
			alert( Get_Txt('MSG_INVALID_EMAIL') );
			document.forms[form_name].elements['participant_0_email'].focus();
			return false;
	}

	if ( document.forms[form_name].elements['participant_0_telephone'].value == "" ){
			alert( Get_Txt('MSG_EMPTY_PHONE') );
			document.forms[form_name].elements['participant_0_telephone'].focus();
			return false;
	}
	
	
	
	for ( var i = 1; i < document.forms[form_name].elements['participants'].value; i++ ) {

   if ( document.forms[form_name].elements['participant_' + i + '_first_name'].value != "" ){
				
				if ( document.forms[form_name].elements['participant_' + i + '_last_name'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_LAST_NAME') );
						document.forms[form_name].elements['participant_' + i + '_last_name'].focus();
						return false;
				}
				
				if ( document.forms[form_name].elements['participant_' + i + '_title'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_TITLE') );
						document.forms[form_name].elements['participant_' + i + '_title'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['participant_' + i + '_address'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_ADDRESS') );
						document.forms[form_name].elements['participant_' + i + '_address'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['participant_' + i + '_city'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_CITY') );
						document.forms[form_name].elements['participant_' + i + '_city'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['participant_' + i + '_province_state'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PROVINCE') );
						document.forms[form_name].elements['participant_' + i + '_province_state'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['participant_' + i + '_postal_code'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_POSTAL_CODE') );
						document.forms[form_name].elements['participant_' + i + '_postal_code'].focus();
						return false;
				}
				if ( !isEmail( document.forms[form_name].elements['participant_' + i + '_email'].value ) ){
						alert( Get_Txt('MSG_INVALID_EMAIL') );
						document.forms[form_name].elements['participant_' + i + '_email'].focus();
						return false;
				}
				if ( document.forms[form_name].elements['participant_' + i + '_telephone'].value == "" ){
						alert( Get_Txt('MSG_EMPTY_PHONE') );
						document.forms[form_name].elements['participant_' + i + '_telephone'].focus();
						return false;
				}

			}
	}	
	
	document.forms[form_name].submit();
}


function Validate_Event_Confirmation( form_name ) {
 /*
	var answer = confirm( Get_Txt("MSG_EVENT_CONFIRMATION") );
 
	if ( answer == null ) {
		return false;
	}
	if ( answer == false ) {
		 return false;
	}*/
	
	document.forms[form_name].submit();
	
}

function Validate_Search_Form( form_name )
{
	if (document.forms[form_name].elements['m'].value != document.forms[form_name].elements['defaulttext'].value
					&& document.forms[form_name].elements['m'].value != '') {
		return true;
	} else {
		return false;
	}
}


function Check_Job_Offer_Form( form_name ){
		
 if( document.forms[form_name].elements['publication_date'].value == "" ){
					alert( Get_Txt( 'MSG_EMPTY_DATE' ) );
					document.forms[form_name].elements['publication_date'].focus();
					return false;
	}
 if( document.forms[form_name].elements['title_fr'].value == "" ){
					alert( Get_Txt( 'MSG_EMPTY_TITLE_FR' ) );
					document.forms[form_name].elements['title_fr'].focus();
					return false;
	}
 if( document.forms[form_name].elements['title_en'].value == "" ){
					alert( Get_Txt( 'MSG_EMPTY_TITLE_EN' ) );
					document.forms[form_name].elements['title_en'].focus();
					return false;
	}

document.forms[form_name].submit();

}


function Display_Sub_Events_Total( default_event_price, nbr_sub_events ){

	var total = 0;
	var counter = 0;
	var display;
	
 for ( var i = 1; i <= nbr_sub_events; i++ ) {

			if ( document.forms[0].elements[ document.forms[0].elements['checkbox_' + i].value ].checked ){
					total += parseFloat( document.forms[0].elements['sub_event_' + i + '_price'].value );
					counter++;
			}

	}
 
	total = total.toFixed(2);
	
	if ( total == 0 ){
			total = default_event_price;
	}

	display = "Total : " + total + "$";
	
 document.getElementById('sub_events_total').innerHTML=display;


}





// CALENDAR 

function Find_Position(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return [curleft,curtop];
}

// Creates a new div as a popup, located next to the object given to this function
function Show_Calendar_Event( object, align, calendar_id ) {
	// Create a new div
	var popup_element = new Element('div');

	var class_str = 'calendar_popup';
	// Identify the new element by the id of the parent object so we can reach it (and hide it) later
	var popup_id = 'popup_' + object.id;
	// The id of the element that contains the text we want to display in this popup
	var source_text_id = 'title_' + object.id;
	
	// Get the position of the parent object
	pos = Find_Position(object);
	
	// Set the correct class and id of the new popup element.  className is for IE, class for the rest
	// The other browsers ignore className, no need to test for browser here
	popup_element.setAttribute('className', class_str);
	popup_element.setAttribute('class', class_str);
	popup_element.setAttribute('id', popup_id);

	// Set the text that we want this popup to display
	popup_element.innerHTML = document.getElementById(source_text_id).innerHTML;
	
	// Insert the new popup as a child of our popup container
	document.getElementById('popup_container_' + calendar_id).appendChild(popup_element);

	alignment = '';
	if ( align == "left" ) {
		// If we're being told to align this to the left, append a negative left margin
		// the width of the element
		alignment = 'margin-left: -' + $(popup_id).offsetWidth + 'px;'
	}
	
	// Set the absolute position of this element to be a little bit below the parent
	var style_str = alignment + 'top: ' + (pos[1] + 20) +  'px; left: ' + pos[0] + 'px;';
	
	if( popup_element.style.setAttribute ) {
		// IE way of setting style
		popup_element.style.setAttribute("cssText", style_str );
	} else {
		// Other browsers way of setting style
		popup_element.setAttribute("style", style_str );
	}
	
}

// Deletes (and thus hides) the popup element associated with the element given as an argument
function Hide_Calendar_Event( object, calendar_id ) {
	var popup_element = document.getElementById( 'popup_' + object.id );
	if (popup_element != null) {
		document.getElementById('popup_container_' + calendar_id).removeChild(popup_element);
	}
}

// Get a new calendar month by way of an ajax request
function Get_Ajax_Calendar( month, year, language, align, calendar_id, guard ) {
		
	var url = 'calendar.php?calendar=' + year + '-' + month + '-01' + '&lang=' + language + '&align=' + align + '&calendar_id=' + calendar_id;
	// See moo.fx documentation for this method
	var ajax = new Ajax(url, {method: 'get', update: calendar_id});
	// Make the request
	ajax.request();

	if ( guard != false){

			// BIGGEST PATCH EVER!!!
			switch ( calendar_id ){
					case 'calendar_1' :
							if ( month == 12 )	{
						   month = 0;
						   year = year + 1;
			    }
							Get_Ajax_Calendar(month + 1, year, language, align, 'calendar_2', false);
					break;
					case 'calendar_2' :
							Get_Ajax_Calendar(month - 1, year, language, align, 'calendar_1', false);
					break;
			}
	
	}
	
}