var mystored_selection = '';
var post_cache    = new Array();
var ajax_loaded   = 1;
var ignore_cache  = new Array();
function build_postarray(postform){
	var pa=new Array();
	var fv=new Array();
	var f;
	var obj_form=document.getElementById(postform);
	for(var i=0;i<obj_form.length;i++){
		f=obj_form.elements[i];
		if (f.type=='checkbox') {
			if (f.checked) {
				if (pa[f.name]) pa[f.name] += f.value+'|';
				else pa[f.name] = f.value+'|';
			}
		}
		else{ pa[f.name]=f.value; }
	}
	return pa;
}
/*--------------------------------------------*/
// Ajax: location show
/*--------------------------------------------*/
function ajax_location_show( country_id, location_id, event )
{
	//----------------------------------
	// Cancel bubble (Prevent IE scroll...)
	//----------------------------------
	global_cancel_bubble( event, true );
	var post_main_obj = document.getElementById('div_location');
	var post_box_top  = _get_obj_toppos( post_main_obj );
	//----------------------------------
	// INIT
	//----------------------------------
	var url = 'index.php?act=xmlout&do=location-show&cid='+country_id+'&lid='+location_id;
	if ( ! country_id || country_id == '' )
	{
		//
		return false;
	}
	//----------------------------------
	// Attempt to close open menus
	//----------------------------------
	try
	{
		menu_action_close();
	}
	catch(e)
	{
		//alert( e );
	}
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading();
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		if ( html == 'nopermission' )
		{
			alert( js_error_no_permission );
		}
		else if ( html != 'error' )
		{
			if ( post_box_top )
			{
				scroll( 0, post_box_top - 30 );
			}
			document.getElementById('div_location').innerHTML = html;
		}
		else {
			document.getElementById('div_location').innerHTML = 'ERROR';
		}
		
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	xmlobj.process( url );
	return false;
}
/*--------------------------------------------*/
// Ajax: Save for post
/*--------------------------------------------*/
function ajax_save_for_post( objectform, action, user_id )
{
	//----------------------------------
	// INIT
	//----------------------------------
	if(!document.forms[objectform])
	{
		return false;
	}
	var url    = 'index.php?act=havenxmlout&do='+action+'&uid='+user_id;
	var fields = build_postarray(objectform);
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'havenxmlout';
	fields['do']       = action;
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading();
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		if ( html != 'error' )
		{
			scroll( 0, 0 );
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
		else
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) );
	return false;
}
/*--------------------------------------------*/
// Ajax: action
/*--------------------------------------------*/
function ajax_action_for_post( action, user_id, user_name, div_action, div_refresh )
{
	//----------------------------------
	// INIT
	//----------------------------------
	var url    = 'index.php?act=havenxmlout&do='+action+'&uid='+user_id+'&uname='+user_name;
	var fields = new Array();
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'havenxmlout';
	fields['uid']      = user_id;
	fields['uname']    = user_name;
	fields['do']       = action;
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading();
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		if ( html != 'error' )
		{
			scroll( 0, 0 );
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
			if (div_refresh && div_action) ajax_refresh_div(div_action, div_refresh, html);
		}
		else
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) );
	return false;
}
/*--------------------------------------------*/
// Ajax: action
/*--------------------------------------------*/
function ajax_post_action( objectform, action, user_id, div_refresh )
{
	//----------------------------------
	// INIT
	//----------------------------------
	var url    = 'index.php?act=havenxmlout&do='+action+'&uid='+user_id;
	var fields = build_postarray(objectform);
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'havenxmlout';
	fields['uid']      = user_id;
	fields['do']       = action;
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading();
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		if ( html != 'error' )
		{
			var result_html = html.split("|");
			if ( result_html[0] != 'error')
			{
				if ( (div_refresh) && document.getElementById( div_refresh ) )
				{
					scroll( 0, 0 );
					document.getElementById( div_refresh ).innerHTML = html;
				}
				document.getElementById( 'ajax-post-msg' ).innerHTML = '';
			}
			else
			{
				document.getElementById( 'ajax-post-msg' ).innerHTML = result_html[1];
			}
		}
		else
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) );
	return false;
}
/*--------------------------------------------*/
// Ajax: action
/*--------------------------------------------*/
function ajax_my_action( action, user_id, user_name, div_refresh, ajax_msg )
{
	//----------------------------------
	// INIT
	//----------------------------------
	var url    = 'index.php?act=havenxmlout&do='+action+'&uid='+user_id+'&uname='+user_name;
	var fields = new Array();
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'havenxmlout';
	fields['uid']      = user_id;
	fields['uname']    = user_name;
	fields['do']       = action;
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading(ajax_msg);
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		if ( html != 'error' )
		{
			var result_html = html.split("|");
			if ( result_html[0] != 'error')
			{
				if ( (div_refresh) && document.getElementById( div_refresh ) )
				{
					document.getElementById( div_refresh ).innerHTML = html;
				}
			}
			else
			{
				document.getElementById( 'ajax-post-msg' ).innerHTML = result_html[1];
			}
		}
		else
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) );
	return false;
}
/*--------------------------------------------*/
// Ajax: user bookmark list 
/*--------------------------------------------*/
function ajax_refresh_div(div_action, div_refresh, result)
{
	//----------------------------------
	// INIT
	//----------------------------------
	var url    = 'index.php?act=havenxmlout&do='+div_action;
	var fields = new Array();
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['act']      = 'havenxmlout';
	fields['do']       = div_action;
	fields['result']   = result;
	fields['st']       = document.getElementById( 'st' ).value;
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading();
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		scroll( 0, 0 );
		if ( html != 'error' )
		{
			document.getElementById( div_refresh ).innerHTML = html;
		}
		else
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = document.getElementById( 'ajax-post-msg' ).innerHTML + html;
		}
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) );
	return false;
}

/*--------------------------------------------*/
// Ajax: update newsletters
/*--------------------------------------------*/
function ajax_update_newsletters( user_id )
{
	//----------------------------------
	// INIT
	//----------------------------------
	var url    = 'index.php?act=xmlout&do=update-newsletters&uid='+user_id;
	var fields = build_postarray('newsletter_form');
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'xmlout';
	fields['do']       = 'update-newsletters';
	fields['uid']      = user_id;
	/*--------------------------------------------*/
	// Main function to do on request
	// Must be defined first!!
	/*--------------------------------------------*/
	do_request_function = function()
	{
		//----------------------------------
		// Ignore unless we're ready to go
		//----------------------------------
		if ( ! xmlobj.readystate_ready_and_ok() )
		{
			xmlobj.show_loading();
			return;
		}
		xmlobj.hide_loading();
		//----------------------------------
		// INIT
		//----------------------------------
		var html = xmlobj.xmlhandler.responseText;
		scroll( 0, 0 );
		if ( html != 'error' )
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
		else
		{
			document.getElementById( 'ajax-post-msg' ).innerHTML = html;
		}
	}
	//----------------------------------
	// LOAD XML
	//----------------------------------
	xmlobj = new ajax_request();
	xmlobj.onreadystatechange( do_request_function );
	var xmlreturn = xmlobj.process( url, 'POST', xmlobj.format_for_post(fields) );
	return false;
}
function disable_check(postform){
	var f;
	var obj_form=document.getElementById(postform);
	for(var i=0;i<obj_form.length;i++){
		f=obj_form.elements[i];
		if (f.type=='checkbox') {
			if (f.checked) {
				f.disabled = true;
				f.checked = false;
				f.style.backgroundColor="#F01928";
			}
		}
	}
	return true;
}
