function add_minimize_event()
{
    // RadDock does not come with events for maximize or minimize at
    var objectList = getElementsByClass('RadDockableObjectCommandButton');
    for (var i = 0; i < objectList.length; i++)
    {
        var object = objectList[i];
        object.firstChild.onclick = SaveStateDelay;
        
    }
}

function SaveStateDelay()
{
    setTimeout('SaveState()', 100);
}


function SaveState()  
{  
    try
    {
        var objectList = getElementsByClass('RadDockableObjectFixed');
        var i ;
        var left_list = '';
        var right_list = '';
        var object_title = '';
        var object_open
        for (i = 0; i < objectList.length; i++)
	    {
	        var object = objectList[i];
	        // note that the object is nested deep
	        // this is the new parent zone, the old parent zone is appened to the object name
	        var parent_zone =  object.parentNode.parentNode.parentNode.parentNode.id
            
            var old_parent_zone = '';
            if( object.id.indexOf('docking_zone_left') != -1 )
            {
                old_parent_zone = 'docking_zone_left'
            }
            if( object.id.indexOf('docking_zone_right') != -1 )
            {
                old_parent_zone = 'docking_zone_right'
            }
            if( object.id.indexOf('docking_zone_center') != -1 )
            {
                old_parent_zone = 'docking_zone_center'
            }
            
            // 18 is the char length of docking_zone_left_
            object_title = object.id.slice(old_parent_zone.length + 1);
            id_string = old_parent_zone + '_' + object_title + '_Collapse';

            if(document.getElementById(id_string).style.display == 'none')
            {
                object_open = false;
            }
            else
            {
                object_open = true;
            }
    	    
	        if( parent_zone == 'docking_zone_left') 
	        {
	            if( left_list.length == 0)
	            {
	                left_list = object_title + '=' + object_open;
	            }
	            else
	            {
	                left_list = left_list + '&' + object_title + '=' + object_open;
	            }
	        }
    	  
	        if( parent_zone == 'docking_zone_right') 
	        {
	            if( right_list.length == 0)
	            {
	                right_list = object_title + '=' + object_open;
	            }
	            else
	            {
	                right_list = right_list + '&' + object_title + '=' + object_open;
	            }
	        }
	    }
        createCookie('MyWestnetZoneLeft',left_list,365)
        createCookie('MyWestnetZoneRight',right_list,365)
    }
    catch(error)
    {
        // if they are moving the object it will error, once they place it down it will save again
    }
}  



function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';

	var els = node.getElementsByTagName(tag);

	var elsLen = els.length;

	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");

    var j = 0;
	for (i = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}

	return classElements;
}

/**
 * Activating the search box's
 *
 * $ms_slider is a global variable holding all the sliding objects and properties.
 *
 * @param string $section
 */
function ms_activate( $section )
{
	try
	{
		// $ms_slider is a global variable holding all the sliding objects and properties.

		// Fetch the current height, 0 height = closed.
		var $height = parseInt($ms_slider[$section].divObj.style.height);

		// Slide it.
		$ms_slider[$section].slideit();

		// Change the image once it has opened/closed.
		setTimeout('ms_icon_change("' + $section + '")', $ms_slider['animatetime'] + 20);

		// Close the other search box's if this one is to be opened.
		if( $height == 0 )
		{
			//ms_deactivate_others($section);
			setTimeout('ms_deactivate_others("' + $section + '")', $ms_slider['animatetime'] + 20);
		}

	}
	catch( $e )
	{
		//alert($e);
	}
}


/**
 * Closes all the multi search box's, bar the one passed in.
 *
 * $ms_slider is a global variable holding all the sliding objects and properties.
 *
 * @param string $section
 */
function ms_deactivate_others( $section )
{
	for( var $key in $ms_slider )
	{
		if( $key != 'animatetime' && $key != $section )
		{
			$ms_slider[$key].slideup();

			// Change the image.
		    setTimeout('ms_icon_change("' + $key + '")', $ms_slider['animatetime'] + 20);
		}
	}
}


/**
 * Changes the up/down grey arrow on the multi search box's.
 *
 * $ms_slider is a global variable holding all the sliding objects and properties.
 *
 * @param string $section
 */
function ms_icon_change( $section)
{
	try
	{
		// Fetch the current height
		var $height = parseInt($ms_slider[$section].divObj.style.height);

		// If the height is 0, then it it is closed.
		var $icon = document.getElementById('ms_icon_' + $section);
		if( $height == 0 )
		{
			$icon.src = 'http://images.mywestnet.com.au/images01/icons/icon_arrow_down-grey.gif';
		}
		else
		{
			$icon.src = 'http://images.mywestnet.com.au/images01/icons/icon_arrow_up-grey.gif';
		}
	}
	catch( $e )
	{
		// alert($e);
	}
}


/**
 * Activates the passed in area.
 *
 * All regions which correspond to the given area name are made visible, rest are hidden.
 *
 */
function ml_activate( $activate_area )
{
	var $areas = new Array('btn_mod_login-homepage', 'btn_mod_login-email', 'btn_mod_login-myaccount', 'btn_mod_login-myfoto');
	try
	{
		if($activate_area == 'btn_mod_login-homepage' || $activate_area == 'btn_mod_login-email')
		{
			$new_class = 'mod_login-tab_selected_top btn_mod_login';
		} else {
			$new_class = 'mod_login-tab_selected_bottom btn_mod_login';
		}
		// Change the style of the tab.
		document.getElementById($activate_area + '_td').className = $new_class;
		document.getElementById($activate_area + '_div1').className = '';
		document.getElementById($activate_area + '_div2').className = '';
		document.getElementById($activate_area + '_image').className = $activate_area + '_on';

		for( var $key in $areas )
		{
			if( $areas[$key] != $activate_area )
			{
				if($areas[$key] == 'btn_mod_login-homepage' || $areas[$key] == 'btn_mod_login-email')
				{
					$new_class = 'mod_login-tab_deselected_top';
				} else {
					$new_class = 'mod_login-tab_deselected_bottom';
				}

				// Change the styles of the area's to be deselected.
				document.getElementById($areas[$key] + '_td').className = $new_class;
				document.getElementById($areas[$key] + '_div1').className = 'btn_mod_login';
				document.getElementById($areas[$key] + '_div2').className = 'btn_mod_login-r';
				document.getElementById($areas[$key] + '_image').className = $areas[$key] + '_off';
			}
		}

		// Display the right content area - 'homepage' area for homepage tab, 'form' area for other three tabs
		if($activate_area == 'btn_mod_login-homepage')
		{
			document.getElementById($activate_area + '_content').style.display = '';
			document.getElementById('btn_mod_login-form_content').style.display = 'none';
		} else {
			document.getElementById('btn_mod_login-form_content').style.display = '';
			document.getElementById('btn_mod_login-homepage_content').style.display = 'none';
		}
	}
	catch( $e )
	{
		//alert($e);
	}
}

function create_XMLHttpRequest()
{
	if (window.XMLHttpRequest)
	{
		return new XMLHttpRequest();
	}
	else if(window.ActiveXObject)
	{
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else
	{
		return false;
		/*
		document.getElementById('p_status').innerHTML =
		'Status: Cound not create XmlHttpRequest Object.' +
		'Consider upgrading your browser.';
		*/
	}
}

function xml_get_field(xmldoc, field_name)
{
   var xml_array = xmldoc.getElementsByTagName(field_name);
	if( xml_array.length > 0 )
	{
		if( xml_array[0].firstChild != null )
		{
			// If the client is using mozilla, we fetch the xml element differently as Mozilla has a bug not allowing more than 4096 chars in each element.
			if( true == isMoz() )
			{
				return xml_array[0].textContent;
			}
			else
			{
				return xml_array[0].firstChild.nodeValue;
			}
		}
		else
		{
			return "";
		}
	}
	else
	{
		return "";
	}
}

function xml_get_attribute(xmldoc, field_name, attribute_name)
{
	var xml_array = xmldoc.getElementsByTagName(field_name);

	if( xml_array.length > 0 )
	{
	
		if( xml_array[0].getAttribute(attribute_name) != null )
		{
		    return xml_array[0].getAttribute(attribute_name);
		}
		else
		{
			return "";
		}
	}
	else
	{
		return "";
	}
}

function isMoz()
{
	// Set the default value to false.
	var moz = false;

	if ( !document.layers )
	{
		// Is the browser Konquerer.
		konq = ( navigator.userAgent.indexOf( 'Konqueror' ) != -1 );

		// Is the browser Safari?
		saf = ( navigator.userAgent.indexOf( 'Safari' ) != -1 );

		// Is the browser Mozilla?
		moz = ( navigator.userAgent.indexOf( 'Gecko' ) != -1 && !saf && !konq);
	}

	return moz;
}