var clicking = false;
var show_loading = false;
var page_name = "search";
var merchant_type = 'merchant';
var merchant_array = new Array();
var merchant_count = 0;
var new_merchant_id = 10000;

function get_page(page, search){
	var url = "/create/?p=" + page + "&s=" + search;
		
	makeRequest(url);
}

function add_merchant(merchant_id, name){
	var merchants = document.getElementById('selected_merchants');
	var div = document.createElement('div');
	
	if(merchant_count < 5 && merchant_array[merchant_id] == null){
		div.setAttribute('id','merchant_div_' + merchant_id);
		div.innerHTML = name + '&nbsp;<a href="javascript:remove_merchant(' + merchant_id + ')" class="remove">(remove)</a><br /><input type="text" class="txt-merchant-list" name="merchant_comments[' + merchant_id + ']" value="Optional Comments..." onclick="this.value=\'\'" /> <input type="hidden" name="merchants['+ merchant_id + ']" value="' + merchant_id + '"/><div class="clear"/><br style="line-height:15px;" />';
		merchants.appendChild(div);
		merchant_array[merchant_id] = true;
		merchant_count++;
		if(merchant_count == 5 && document.getElementById('name').value.length > 0){
			document.getElementById("submit").disabled = false;
		}
	}
}

function add_new_merchant(form, submit_name, submit_value){
	var url = "/create";
	form_fields = form_submit(form, submit_name, submit_value);
	show_loading = "1";
	makeRequest(url, form_fields);
	form.action = "javascript:void(0)";
}

function remove_merchant(merchant_id){
	var parent = document.getElementById('selected_merchants');
	
	if(parent != null){
		parent.removeChild(document.getElementById('merchant_div_' + merchant_id));
		merchant_array[merchant_id] = null;
		merchant_count--;
		document.getElementById("submit").disabled = true;
	}
}

function check_list_name(name){
	if(name.value.length > 0 && merchant_count == 5){
		document.getElementById("submit").disabled = false;
	}else{
		document.getElementById("submit").disabled = true;
	}
}
