
// Hide the div's with the class 'javascript_hide', used for buttons when javascript is enabled and the functions can use ajax.
function hide_javascript_divs()
{
	var div_elements = document.getElementsByTagName('div');

	for (i=0; i<div_elements.length; i++)
	{
		if (div_elements[i].className == 'javascript_hide')
		{
			div_elements[i].style.display = "none";
		}
	}
}


function hide_javascript_trs()
{
	var div_elements = document.getElementsByTagName('tr');

	for (i=0; i<div_elements.length; i++)
	{
		if (div_elements[i].className == 'javascript_hide')
		{
			div_elements[i].style.display = "none";
		}
	}
}

init_functions[init_functions.length] = "hide_javascript_divs();";
init_functions[init_functions.length] = "hide_javascript_trs();";

function open_window(url,name,rw,rh)
{

	if ( screen.width ) {
		xMax = screen.width;
		yMax = screen.height;
	} else {
		if (document.layers) {
			xMax = window.outerWidth; yMax = window.outerHeight;
		} else {
			xMax = 640; yMax=480;
		}
	}

	rw+=40;
	rh+=60;

	xMax-=20;
	yMax-=120;

	w=(rw<xMax)?rw:xMax;
	h=(rh<yMax)?rh:yMax;

	xOffset = (xMax - w)/2;
	yOffset = (yMax - h)/2;

	features='width='+w+
			',height='+h+
			',screenX='+xOffset+
			',screenY='+yOffset+
			',left='+xOffset+
			',top='+yOffset+
			',directories=no'+
			',location=no'+
			',menubar=yes'+
			',scrollbars=yes'+
			',status=no'+
			',toolbar=no'+
			',resizable=yes'+
			',alwaysRaised=yes';

	myWind=window.open(url,name,features);
}

function open_window_inside(url, name, inside)
{

	if( navigator.appName == "Netscape" )
	{
		// Mozilla/Firefox
		x = window.screenX;
		y = window.screenY;
		window_width = window.innerWidth;
		window_height = window.innerHeight;
	}
	else
	{

		if( navigator.appName == "Microsoft Internet Explorer")
		{
			// IE
			x = window.screenLeft;
			y = window.screenTop;
			window_width = document.body.clientWidth;
			window_height = document.body.clientHeight;
		}
		else
		{
			x = 0;
			y = 0;
			window_width = document.body.clientWidth;
			window_height = 600;
		}
	}

	offsetX = x + inside;
	offsetY = y + inside;

	width = window_width -  ( 2 * inside );
	height = window_height -  ( 2 * inside );

	features='width='+width+
			',height='+height+
			',screenX='+offsetX+
			',screenY='+offsetY+
			',left='+offsetX+
			',top='+offsetY+
			',directories=yes'+
			',location=yes'+
			',menubar=yes'+
			',scrollbars=yes'+
			',status=yes'+
			',toolbar=yes'+
			',resizable=yes'+
			',alwaysRaised=yes';

//	alert(features)

	myWind=window.open(url,name,features);
}


/**
 * Restricts a form field with an id of field_id to be maxChars in length
 *
 * It should be called onkeyup and onchange from the form field declaration.
 *
 * If the form element with id of charsleft_text_id exists, a count of how many
 * characters can still be entered will be automatically updated with that number
 *
 * @param field_id			-- the id of the form field to limit the max characters on
 * @param charsleft_text_id	-- the id of the html element of where to display the number of characters remaining
 * @param maxChars			-- the maximum allowed characters
 */
function checkMaxChars(field_id, charsleft_text_id, maxChars)
{
	var formField = document.getElementById(field_id);

	if( charsleft_text_id.length > 0 )
	{
		var charsLeftField = document.getElementById(charsleft_text_id);
	}

	if( formField.value.length > maxChars )
	{
		formField.value = formField.value.substring(0,maxChars);

		if (charsLeftField != undefined)
		{
			charsLeftField.innerHTML = '0';
		}
	}
	else
	{
		charsLeftField.innerHTML = (maxChars - formField.value.length);
	}
} 


function more_images_display(max_images)
{
	more_images = more_images + 1;
	if( more_images < max_images )
	{
		max_images = more_images;
	}

	for( i=0; i<max_images; i++ )
	{
		var tr_display = document.getElementById('title_' + i);
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('file_' + i);
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('hr_' + i);
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}
	}
}


function child_details_display(max_child, MAX_NUM_CHILD)
{
	// Hides all first
	for( i=1; i<=MAX_NUM_CHILD; i++ )
	{

		// The HR
		child = document.getElementById('child_' + i + '_hr');
		child.className = 'javascript_hide';
		child.style.display = 'none';

		// The name
		child = document.getElementById('child_' + i + '_name');
		child.className = 'javascript_hide';
		child.style.display = 'none';

		// The File
		child = document.getElementById('child_' + i + '_age');
		child.className = 'javascript_hide';
		child.style.display = 'none';

	}

	for( i=1; i<=max_child; i++ )
	{
		var tr_display = document.getElementById('child_' + i + '_hr');
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('child_' + i + '_name');
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}

		var tr_display = document.getElementById('child_' + i + '_age');
		if( tr_display.className == 'javascript_hide' )
		{
			tr_display.style.display = "";
		}
	}
}

function rating_checkboxs(field, allow_unchecking)
{
	var f = field.form;

	// Only allow turning off of fields if another is selected OR you allow the checked one to be unchecked.
	if( field.checked == true || allow_unchecking == false )
	{
		for( var num=0; num<f.elements[field.name].length; num++ )
		{
			if( f.elements[field.name][num].value == field.value)
			{
				f.elements[field.name][num].checked = true;
			}

			else
			{
				f.elements[field.name][num].checked = false;
			}
		}
	}
}



//
// AJAX to delete watchlist items
//
var watchlist_ajax = create_XMLHttpRequest();

function watchlist_delete(watchlist_delete_url, watchlist_item)
{
	// Url must have content.
	if( watchlist_delete_url.length > 0 )
	{
		//alert( watchlist_ajax.readyState );
		if( watchlist_ajax.readyState == 4 || watchlist_ajax.readyState == 0 )
		{
			// Send data to Delete the watchlist item
			watchlist_ajax.open("GET", watchlist_delete_url, true);
			watchlist_ajax.onreadystatechange = function() { watchlist_remove_item(watchlist_item); };
			watchlist_ajax.send(null);
		}
	}
}

function watchlist_remove_item( watchlist_item )
{
	if( watchlist_ajax.readyState == 4 )
	{
		// Response code was 200, OK!
		if( watchlist_ajax.status == 200 )
		{
			// Delete the three rows of a watchlist item
			for( row=1; row<=3; row++)
			{
				row_id = watchlist_item + "_" + row;

				var watchlist_row = document.getElementById( row_id );

				// The starting colour of the background (row_even colour)
				watchlist_row.currentRGB = [248, 248, 248];

				// Fade Row Background
				doFadeMem(watchlist_row, watchlist_row.currentRGB, [255, 255, 255], 20, 3, 1.3 );

				// Fade the Text between the Links in the second cell of the first row
				if( row == 1 )
				{
					doFadeMem(watchlist_row.childNodes[1], [0, 0, 0], [255, 255, 255], 20, 3, 1.3 );
				}

				if( row == 2 )
				{
					// Fade the Text in the second cell of the second row
					doFadeMem(watchlist_row.childNodes[1], [0, 0, 0], [255, 255, 255], 20, 3, 1.3 );
				}

				// Check if the row has more than 1 cell
				if( watchlist_row.childNodes.length > 1 )
				{
					// Get an array of the links in second td cell
					var watchlist_links = watchlist_row.childNodes[1].getElementsByTagName("a");

					// Fade the link
					for( i=0; i<watchlist_links.length; i++ )
					{
						watchlist_links[i].currentRGB = [0, 0, 0];
						doFadeMem(watchlist_links[i], watchlist_links[i].currentRGB, [255,255,255], 20, 3, 1.3 );
					}
				}
			}
		}
	}
}

function doFadeMem(elem, startRGB, endRGB, steps, intervals, powr)
{
	//Fader with Memory by www.hesido.com
	if (elem.fadeMemInt)
	{
		window.clearInterval(elem.fadeMemInt);
	}

	var actStep = 0;

	elem.fadeMemInt = window.setInterval(
		function() {
			elem.currentRGB = [
				easeInOut(startRGB[0], endRGB[0], steps, actStep, powr),
				easeInOut(startRGB[1], endRGB[1], steps, actStep, powr),
				easeInOut(startRGB[2], endRGB[2], steps, actStep, powr)
				];
			if( elem.tagName == "TR" )
			{
				elem.style.backgroundColor = "rgb(" + elem.currentRGB[0] + "," + elem.currentRGB[1] + "," + elem.currentRGB[2] + ")";
			}
			else
			{
				elem.style.color = "rgb(" + elem.currentRGB[0] + "," + elem.currentRGB[1] + "," + elem.currentRGB[2] + ")";
			}
			actStep++;
			if (actStep > steps)
			{
				window.clearInterval(elem.fadeMemInt);

				elem.style.display = 'none';
			}
		}
		, intervals)
}

function easeInOut( minValue, maxValue, totalSteps, actualStep, powr )
{
	//Generic Animation Step Value Generator By www.hesido.com
	var delta = maxValue - minValue;
	var stepp = minValue + (Math.pow( ((1 / totalSteps) * actualStep), powr) * delta);
	return Math.ceil(stepp)
}

function crossfade( fromElement, toElement, step, delay )
{
	var value = 0;
	if( arguments[5] != undefined )
	{
		value = arguments[5];
	}

	fromElement.style.opacity = ((100 - value) / 100);
	fromElement.style.filter = 'alpha(opacity=' + (100 - value) + ')';

	toElement.style.opacity = (value / 100);
	toElement.style.filter = 'alpha(opacity=' + value + ')';

	var callback = null;
	if( arguments[4] != undefined && arguments[4] != null )
	{
		callback = arguments[4];
	}

	if( value < 100 )
	{
		window.setTimeout(function() {crossfade(fromElement, toElement, step, delay, callback, value + step);}, delay);
	}
	else
	{
		toElement.style.filter = 'none';
		if( callback != null )
		{
			callback();
		}
	}
}

// http://textsnippets.com/posts/show/686
function getElementsByClassName(oElm, strTagName, strClassName)
{
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++)
	{
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className))
		{
			arrReturnElements.push(oElement);
		}
	}

	return (arrReturnElements)
}

function IsNumeric(sText)
{
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
	{
		Char = sText.charAt(i);
		if( ValidChars.indexOf(Char) == -1 )
		{
			IsNumber = false;
		}
	}

	return IsNumber;
}

function isEmail(str)
{
	 var filter=/^.+@.+\..{2,3}$/

	 if (filter.test(str))
	 {
	 	 return 'TRUE';
	 }
	 else
	 {
	    return 'FALSE';
	}
}

function select_all_checkbox(e, items_name)
{
	// get the list of checkbox note: the name must be the same
	var list = getElementsByClass(items_name)
	for (i = 0; i < list.length; i++)
	{
		var relTarg = e.target || e.srcElement;
		if( relTarg.checked )
		{
			list[i].checked = true ;
		}
		else
		{
			list[i].checked = false ;
		}
	}
}

function get_viewport_height()
{
	if( window.innerHeight != window.undefined )
	{
		return window.innerHeight;
	}
	else if( document.compatMode == 'CSS1Compat' )
	{
		return document.documentElement.clientHeight;
	}
	else if( document.body )
	{
		return document.body.clientHeight;
	}

	return window.undefined;
}

function get_viewport_width()
{
	if( window.innerWidth != window.undefined )
	{
		return window.innerWidth;
	}
	else if( document.compatMode == 'CSS1Compat' )
	{
		return document.documentElement.clientWidth;
	}
	else if (document.body)
	{
		return document.body.clientWidth;
	}

	return window.undefined;
}

var basic_popup_ajax = create_XMLHttpRequest();
function basic_popup_send(type, id)
{
	process_loading('Please wait while we process your request..');
	if( basic_popup_ajax.readyState == 4 || basic_popup_ajax.readyState == 0 )
	{
		var title = document.getElementById('email_title').value;
		var body = FCKeditorAPI.__Instances['email_body'];
		body = body.GetHTML();

		param = 'title=' + escape(title) + '&body=' +  escape(body);

		basic_popup_ajax.open('POST', '/ajax/basic_popup/' + type + '/' + id, true);
		basic_popup_ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		basic_popup_ajax.setRequestHeader("Content-length", param.length);
		basic_popup_ajax.setRequestHeader("Connection", "close");
		basic_popup_ajax.onreadystatechange = basic_popup_send_complete;
		basic_popup_ajax.send(param);
	}
}

function basic_popup_send_complete(type)
{
	if (basic_popup_ajax.readyState == 4)
	{
		// Response code was 200, OK!
		if( basic_popup_ajax.status == 200 )
		{
			complete_process_loading();
			// Get XML data
	 		var xmldoc = basic_popup_ajax.responseXML;
 			var success = xml_get_field(xmldoc, "success");
			var reached_friend_request_limit = xml_get_field(xmldoc, "reached_friend_request_limit");
			var friend_request_made = xml_get_field(xmldoc, "friend_request_made");
			
			// The name is valid
	 		if( success.toUpperCase() == "TRUE" )
	 		{
		 		if ( reached_friend_request_limit == "TRUE" )
		 		{
		 			alert('You have already sent your max amount of friend requests for today');
		 		}
		 		else
		 		{
		 			if ( friend_request_made == "TRUE" )
		 			{
		 				parent.document.getElementById('friend_request').innerHTML = 'Friend requested';
		 				parent.document.getElementById('friend_request').style.color = '#A0A0A0';
		 			}
		 		 	popup_mail_close();
	 		 	}
			}
			else
			{
				var body = document.getElementsByTagName('body');
				for (i=0;i<body.length;i++)
				{
					body[i].innerHTML= '<center><h2>There was an error please try again later<h2><center>';
				}

				setTimeout("popup_mail_close()",2000);
			}
	   	}
	}
}

/*
 * type
 * id
 * get_arguments (optional), a hash of get arguments to be added to the source of the iframe
 * title (optional), defaults to 'powered by parents'
 * height (optional), defaults to 380
 * scrolling (optional), defaults to no
 */
function basic_popup(type, id)
{
	window.scroll(0,0);
	//document.documentElement.style.overflow = 'hidden';
    var blocking_el = document.createElement('div');
    blocking_el.setAttribute('id', 'mailBlockingElement');
    blocking_el.style.backgroundColor = '#000000';
    blocking_el.style.opacity = 0.50;
    blocking_el.style.filter = 'alpha(opacity=50)';
    blocking_el.style.position = 'absolute';
    blocking_el.style.width = get_viewport_width() + 'px';
    blocking_el.style.height = get_viewport_height() + 'px';
    blocking_el.style.top = '0px';
    blocking_el.style.left = '0px';
    blocking_el.style.zIndex = 2;
    document.body.appendChild(blocking_el);

	var div_el = document.createElement('div');
 	div_el.setAttribute('id', 'drag_mail_div');
	div_el.className = 'window';
	div_el.style.width = '655px';
	div_el.style.zIndex = 3;

	var height = 400;
	if( arguments[4] != undefined )
	{
		height = arguments[4];
	}

	div_el.style.height = height.toString() + 'px';
	div_el.style.position = 'absolute';

	var title_el = document.createElement('div');
 	title_el.setAttribute('id', 'parent_drag_title_mail_div');
 	title_el.className = 'window_title';

 	var extra_title = 'powered by parents';
 	if( arguments[3] != undefined )
 	{
 		extra_title = arguments[3];
 	}
 	title_el.innerHTML = '&nbsp&nbsp;minti - ' + extra_title;

	var close_el = document.createElement('div');
 	close_el.setAttribute('id', 'close_mail_div');
 	close_el.className = 'close_button';
 	close_el.innerHTML = 'X';
 	close_el.onclick = popup_mail_close;

 	var scrolling = 'no';
 	if( arguments[5] != undefined )
 	{
 		scrolling = arguments[5];
 	}

    var iframe_el = document.createElement('iframe');
    iframe_el.setAttribute('id', 'mail_iframe');
    iframe_el.setAttribute('name', 'mail_iframe_name');
    iframe_el.setAttribute('scrolling', scrolling);
    iframe_el.style.width = '100%';
    iframe_el.style.height = (height - 22).toString() + 'px';
    iframe_el.style.border = '0px';
    iframe_el.style.background = 'white';
    iframe_el.style.borderTop = '1px solid black';
    iframe_el.style.styleFloat = 'left';

    div_el.appendChild(title_el);
	div_el.appendChild(close_el);
    div_el.appendChild(iframe_el);
    document.body.appendChild(div_el);

    var iframe_src = '/popup/' + type + '/' + id;
    if( arguments[2] != undefined )
    {
    	iframe_src += '?';
    	for( i in arguments[2] )
    	{
    		iframe_src += '&' + i + '=' + arguments[2][i];
    	}
    }
    iframe_el.src = iframe_src;
}

function login_required(redir)
{
	window.scroll(0,0);
	//document.documentElement.style.overflow = 'hidden';
    var blocking_el = document.createElement('div');
    blocking_el.setAttribute('id', 'mailBlockingElement');
    blocking_el.style.backgroundColor = '#000000';
    blocking_el.style.opacity = 0.50;
    blocking_el.style.filter = 'alpha(opacity=50)';
    blocking_el.style.position = 'absolute';
    blocking_el.style.width = document.body.clientWidth + 'px';
    blocking_el.style.height = document.body.clientHeight + 'px';
    blocking_el.style.top = '0px';
    blocking_el.style.left = '0px';
    blocking_el.style.zIndex = 2;
    document.body.appendChild(blocking_el);

	var div_el = document.createElement('div');
 	div_el.setAttribute('id', 'drag_mail_div');
	div_el.className = 'window';
	div_el.style.position = 'absolute';
	div_el.style.width = '290px';
    div_el.style.height = '375px';
    div_el.style.left = '35%';
    div_el.style.zIndex = 2;

	var title_el = document.createElement('div');
 	title_el.setAttribute('id', 'parent_drag_title_mail_div');
 	title_el.className = 'window_title';
 	title_el.innerHTML = '&nbsp&nbsp;';

	var close_el = document.createElement('div');
 	close_el.setAttribute('id', 'close_mail_div');
 	close_el.className = 'close_button';
 	close_el.innerHTML = 'X';
 	close_el.onclick = popup_mail_close;

    var iframe_el = document.createElement('iframe');
    iframe_el.setAttribute('id', 'mail_iframe');
    iframe_el.setAttribute('name', 'mail_iframe_name');
    iframe_el.setAttribute('scrolling', 'no');
   	iframe_el.src = '/login-required/?redir=' + redir;
    iframe_el.style.width = '290px';
    iframe_el.style.height = '351px';
    iframe_el.style.border = '0px';
    iframe_el.style.background = 'white';
    iframe_el.style.borderTop = '1px solid black';
    iframe_el.style.styleFloat = 'left';

    div_el.appendChild(title_el);
	div_el.appendChild(close_el);
    div_el.appendChild(iframe_el);
    document.body.appendChild(div_el);

    var f = document.getElementById('mail_iframe');
	f.src = f.src;
}

function popup_mail_open(reply)
{
	window.scroll(0,0);
	//document.documentElement.style.overflow = 'hidden';
    var blocking_el = document.createElement('div');
    blocking_el.setAttribute('id', 'mailBlockingElement');
    blocking_el.style.backgroundColor = '#000000';
    blocking_el.style.opacity = 0.50;
    blocking_el.style.filter = 'alpha(opacity=50)';
    blocking_el.style.position = 'absolute';
    blocking_el.style.width = document.body.clientWidth + 'px';
    blocking_el.style.height = document.body.clientHeight + 'px';
    blocking_el.style.top = '0px';
    blocking_el.style.left = '0px';
    blocking_el.style.zIndex = 2;
    document.body.appendChild(blocking_el);

	var div_el = document.createElement('div');
 	div_el.setAttribute('id', 'drag_mail_div');
	div_el.className = 'window';
	div_el.style.position = 'absolute';
	div_el.style.zIndex = 3;

	var title_el = document.createElement('div');
 	title_el.setAttribute('id', 'parent_drag_title_mail_div');
 	title_el.className = 'window_title';
 	title_el.innerHTML = '&nbsp&nbsp;minti - powered by parents';

	var close_el = document.createElement('div');
 	close_el.setAttribute('id', 'close_mail_div');
 	close_el.className = 'close_button';
 	close_el.innerHTML = 'X';
 	close_el.onclick = popup_mail_close;

    var iframe_el = document.createElement('iframe');
    iframe_el.setAttribute('id', 'mail_iframe');
    iframe_el.setAttribute('name', 'mail_iframe_name');
    iframe_el.setAttribute('scrolling', 'no');
    if ( reply )
    {
    	iframe_el.src = '/members/anonymous/mail/template/?reply=' + reply;
    }
    else
    {
    	iframe_el.src = '/members/anonymous/mail/template/';
    }
    iframe_el.style.width = '100%';
    iframe_el.style.height = '480px';
    iframe_el.style.border = '0px';
    iframe_el.style.background = 'white';
    iframe_el.style.borderTop = '1px solid black';
    iframe_el.style.styleFloat = 'left';

    div_el.appendChild(title_el);
	div_el.appendChild(close_el);
    div_el.appendChild(iframe_el);
    document.body.appendChild(div_el);

    var f = document.getElementById('mail_iframe');
	f.src = f.src;
}

function popup_mail_close()
{
	var blocking_el = parent.document.getElementById('mailBlockingElement');
	if( blocking_el )
	{
		blocking_el.parentNode.removeChild(blocking_el);
	}

	parent.document.documentElement.style.overflow = 'auto';

	var mail_el = parent.document.getElementById('drag_mail_div');
	if( mail_el )
	{
		mail_el.parentNode.removeChild(mail_el);
	}
}

function optionValueIndexOf(options,value)
{
	for (var i=0;i<options.length;i++)
	{
		if (options[i].value == value)
		{
			return i;
		}
	}
	return -1;
}

function send_message(name, reply)
{
	var recipient_list = document.getElementById('recipient_list')
	if( recipient_list== undefined)
	{
		// The list does not exist so lets insert one
		recipient_list = document.createElement('select');
		recipient_list.style.display = "none";
		recipient_list.setAttribute('id', 'recipient_list');
		document.body.appendChild(recipient_list);
	}

	recipient_list.options[recipient_list.length] = new Option('Name', name);
	popup_mail_open(reply);
}

function attach_toggle(element, dropdown_id, show_header)
{
	var dropdown = document.getElementById(dropdown_id);

	if( dropdown.style.display == '' )
	{
		slide_current_wait = -1;
		slide_element = dropdown;
		document.getElementById(dropdown_id + "_arrow").src = "/images/address_book/dropArrowDown.gif";
		slide_up(dropdown_id, show_header);
		slide_current = '';
		slide_with_header = false;
	}
	else
	{
		if( slide_element != null )
		{
			slide_element.style.display = 'none';
			if( slide_header != null )
			{
				slide_header.style.display = 'none';
			}
			document.getElementById(slide_element.id + "_arrow").src = "/images/address_book/dropArrowDown.gif";

		}

		slide_current_wait = slide_max_wait;
		slide_element = dropdown;
		dropdown.style.display = '';
		document.getElementById(dropdown_id + "_arrow").src = "/images/address_book/dropArrowUp.gif";
		dropdown.style.height = '0px';

		if( show_header )
		{
			slide_header = document.getElementById(dropdown_id + '_header');
			slide_header.style.display='';
		}

		//Position the drop down to be in the correct position
		var dropdown_box_pos = findPos(element);
		var new_left = parseInt(dropdown_box_pos[0]) + 2 +'px';
		var new_top = parseInt(dropdown_box_pos[1]) + element.offsetHeight + 'px';

		if( show_header )
		{
			slide_header = document.getElementById(dropdown_id + '_header');
			// align with the header
			var slide_pos = findPos(slide_header);
			new_left = parseInt(slide_pos[0]) + 'px';
			new_top = parseInt(slide_pos[1]) + 'px';
		}
		dropdown.style.left = new_left;
		dropdown.style.top = new_top;


		slide_down()
		setTimeout('slide_down_wait_check("' + dropdown_id + '",'  + show_header + ')', 1000);
	}
}

function slide_down_wait_check(dropdown_id, with_header)
{
	current_dropdown_id = slide_element.id;

	if( current_dropdown_id != dropdown_id	)
	{
		// A different id is selected and we must cancel this thread
		return;
	}
	slide_current_wait--;

	if(slide_current_wait > 0)
	{
		setTimeout('slide_down_wait_check("' + dropdown_id + '",'  + with_header + ')', 1000);
		return;
	}

	slide_current_wait = -1;
	document.getElementById(dropdown_id + "_arrow").src = "/images/address_book/dropArrowDown.gif";
	slide_up(dropdown_id, with_header);
}

function extend_dropdown_time()
{
	slide_current_wait = slide_max_wait;
}

function slide_down()
{
	if( slide_element.offsetHeight < slide_height )
	{
		slide_element.style.height = slide_element.offsetHeight + slide_speed + "px";
		setTimeout('slide_down()', slide_delay);
	}
}

function slide_up(dropdown_id, show_header)
{
	// test to see if the element is already hidden
	if( slide_element )
	{
		if( slide_element.offsetHeight > 0 )
		{
			slide_element.style.height = slide_element.offsetHeight - slide_speed + "px";
			setTimeout('slide_up("' + dropdown_id + '",' + show_header + ')', slide_delay);
		}

		if( slide_element.offsetHeight < slide_speed )
		{
			slide_element.style.display = 'none';
			if( show_header )
			{
				var dropdown_header = document.getElementById(dropdown_id + '_header');
				dropdown_header.style.display='none';
				slide_element = null;
			}
		}
	}
}

function select_all(item)
{
	item.focus();
	item.select();
}

function clearlistbox(lb)
{
  for (var i=lb.options.length-1; i>=0; i--)
  {
    lb.options[i] = null;
  }
  lb.selectedIndex = -1;
}

function dateselect_update( update_field, form_name, optional )
{
	if( update_field == 'month' || update_field == 'year' )
	{
		if( document.getElementById(form_name + '_' + update_field).value == '0' )
		{
			document.getElementById(form_name + '_month').selectedIndex = 0;
			document.getElementById(form_name + '_year').selectedIndex = 0;
			document.getElementById(form_name + '_day').selectedIndex = 0;
		}
		else
		{
			var year_widget = document.getElementById(form_name + '_year');
			var year = parseInt(year_widget.value);
			var month = parseInt(document.getElementById(form_name + '_month').value);

			var day_widget = document.getElementById(form_name + '_day');
			var day = parseInt(day_widget.value);

			day_widget.length = 0;

			var days_in_current_month = (32 - new Date(year, month - 1, 32).getDate());

			var i = 1;

			if( optional )
			{
				day_widget[0] = new Option('--', '0');
				i++;
			}

			for( var i_label = 1; i_label <= days_in_current_month; i_label++ )
			{
				var new_option = new Option(i_label, i_label);

				day_widget[i - 1] = new_option;

				if( i_label == day )
				{
					day_widget.selectedIndex = i - 1;
				}

				i++;
			}
		}
	}
	else if( document.getElementById(form_name + '_day').value == '0' )
	{
		document.getElementById(form_name + '_month').selectedIndex = 0;
		document.getElementById(form_name + '_year').selectedIndex = 0;
	}
}

function accept_moolah_tos( callback )
{
	var req = create_XMLHttpRequest();

	var params = '';

	req.open('POST', '/ajax/accept_moolah_tos', true);
	req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
	req.setRequestHeader('Content-length', params.length);
	req.setRequestHeader('Connection', 'close');
	req.onreadystatechange = function() {
		if( req.readyState == 4 && req.status == 200 )
		{
			var error = xml_get_field(req.responseXML, 'error');
			if( error.length > 0 )
			{
				alert(error);
			}
			else
			{
				callback();
			}
		}
	};
	req.send(params);
}

function autoscroll( cls, speed )
{
	var element_list = getElementsByClassName(document, '*', cls);

	for( i = 0; i < element_list.length; i++ )
	{
		var el = element_list[i];

		if( el.offsetHeight > el.parentNode.offsetHeight )
		{
			var top = ((el.style.top ? parseInt(/^-?(\d+)/.exec(el.style.top)[0]) : 1) - speed);

			if( -top > el.offsetHeight )
			{
				el.style.top = '0';
			}
			else
			{
				el.style.top = top + 'px';
			}
		}
	}
}

function FAQexpandall()
{
	document.getElementById('FAQexpand').style.display = 'none';
	document.getElementById('FAQcollapse').style.display = '';
	document.getElementById('FAQexpand_bottom').style.display = 'none';
	document.getElementById('FAQcollapse_bottom').style.display = '';
	var objectList = getElementsByClass('faqexpand');
	for (var i = 0; i < objectList.length; i++)
	{
		var object = objectList[i];
		object.style.display='';
	}
}
function FAQcollapseall()
{
	document.getElementById('FAQexpand').style.display = '';
	document.getElementById('FAQcollapse').style.display = 'none';
	document.getElementById('FAQexpand_bottom').style.display = '';
	document.getElementById('FAQcollapse_bottom').style.display = 'none';
	var objectList = getElementsByClass('faqexpand');
	for (var i = 0; i < objectList.length; i++)
	{
		var object = objectList[i];
		object.style.display='none';
	}
}

function process_loading(loading_title)
{
	window.scroll(0,0);
	//document.documentElement.style.overflow = 'hidden';
    var blocking_el = document.createElement('div');
    blocking_el.setAttribute('id', 'proccessLoadingBlockingElement');
    blocking_el.style.backgroundColor = '#188d31';
    blocking_el.style.opacity = 0.90;
    blocking_el.style.filter = 'alpha(opacity=90)';
    blocking_el.style.position = 'absolute';
    blocking_el.style.width = '30%';
    blocking_el.style.height = '20%';
    blocking_el.style.top = '40%';
    blocking_el.style.left = '33%';
    blocking_el.style.padding = '20px';
    blocking_el.style.zIndex = '10';
    blocking_el.style.border = '1px solid silver';
    blocking_el.style.minWidth = '268px';
    blocking_el.innerHTML = '<span style="position: relative; top: 50%; color: #FFFFFF; font-size: 13px; font-family: Tahoma;"><img src="/images/indicator_black.gif" border="0"> ' + loading_title + '</span>';
    blocking_el.style.zIndex = 2;
    document.body.appendChild(blocking_el);
}

function complete_process_loading()
{
	var blocking_el = document.getElementById('proccessLoadingBlockingElement');
	if( blocking_el )
	{
		blocking_el.parentNode.removeChild(blocking_el);
	}
}


function toggle_newsletter_html_preview()
{
	var el = document.getElementById('newsletter_html_preview');
	if( el.style.display == 'none' )
	{
		el.style.display = '';
	}
	else
	{
		el.style.display = 'none';
	}
		
}
