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: action
/*--------------------------------------------*/
function ajax_action_for_post( objectform, action, pro_id, div_refresh, div_clear )
{
	//----------------------------------
	// INIT
	//----------------------------------
	if( ! document.forms[objectform] )
	{
		return false;
	}
	var url    = 'index.php?act=shopxmlout&do='+action+'&pid='+pro_id;
	var fields = build_postarray(objectform);
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'shopxmlout';
	fields['pid']      = pro_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 ) )
				{
					document.getElementById( div_refresh ).innerHTML = html;
					if ( div_clear )
					{
						document.getElementById( div_clear ).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_action_for_process( objectform, action, submitform )
{
	//----------------------------------
	// INIT
	//----------------------------------
	if( ! document.forms[objectform] )
	{
		return false;
	}
	var url    = 'index.php?act=shopxmlout&do='+action;
	var fields = build_postarray(objectform);
	//----------------------------------
	// Populate fields
	//----------------------------------
	fields['md5check'] = sdk_md5_check;
	fields['act']      = 'shopxmlout';
	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] == 'processing')
			{
				if( document.forms[submitform] )
				{
					document.forms[submitform].email.value = document.forms[objectform].pi_email.value;
					document.forms[submitform].first_name.value = document.forms[objectform].pi_firstname.value;
					document.forms[submitform].last_name.value = document.forms[objectform].pi_lastname.value;
					document.forms[submitform].tel.value = document.forms[objectform].pi_phone.value;
					document.forms[submitform].address1.value = document.forms[objectform].ba_address.value;
					document.forms[submitform].zip.value = document.forms[objectform].ba_postalcode.value;
					document.forms[submitform].invoice.value = result_html[1];
					document.getElementById( 'paymentform' ).innerHTML = process_gateway;
					document.getElementById( 'submit_div' ).style.visibility = 'visible';
					document.forms[submitform].submit();
				}
				//document.getElementById( 'ajax-post-msg' ).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;
}