findAddress=function()
{	
	if(document.getElementById("houseno").value == "") {
		alert("You must enter your house name/number!");
		document.getElementById("houseno").focus();
		document.getElementById("spinner1").style.display="none";
		return false;
	} else if(document.getElementById("findPostcode").value == "") {
		alert("You must enter your postcode!");
		document.getElementById("findPostcode").focus();
		document.getElementById("spinner1").style.display="none";
		return false;
	} else {
	    showLoadingProcess('spinner1');
	
		var url="mms/mms_ajax_functions.php";
		var params="action=find_address&postcode=" + document.getElementById("findPostcode").value;
		var opt={asynchronous:false,method:"post",parameters:params,
		onSuccess:function(request)
		{
			var address=eval("(" + request.responseText + ")");
			document.getElementById("address1").value=document.getElementById("houseno").value + " " + address['address1'];
			document.getElementById("address2").value=address['address2'];
			document.getElementById("address3").value=address['address3'];
			document.getElementById("address4").value=address['address4'];
			document.getElementById("address5").value=address['address5'];
			document.getElementById("postCode").value=address['postcode'];
				
		}}
		new Ajax.Request(url,opt);
		
		document.getElementById("spinner1").style.display="none";
	}
}

padMembershipNo=function(membership_no)
{
	var padding="";
		
	if(membership_no.length<8)
	{
		for(var i=0; i<(8-membership_no.length); i++)
		{
			padding+="0";
		}
	}
	return padding + membership_no;
}

addEmailAddress=function()
{
	addItem("emailAddressItemsDiv", new Item(new Array("", "")), true);
}
	
addPhoneNumber=function()
{
	addItem("phoneNumberItemsDiv", new Item(new Array("", "")), true);
}

showLoadingProcess=function(id)
{	
	document.getElementById(id).innerHTML="<img src='/images/spinner.gif' style='width:22px; height:22px; vertical-align:middle;'>";
	document.getElementById(id).style.display="";
}

addSection=function(attach_level, attach_code, target, alt) {
    var description = document.getElementById("section_description_" + attach_level + alt + "_" + attach_code).value;
    var type = document.getElementById("section_type_" + attach_level + alt + "_" + attach_code).value;
	
	if(description=="") {
		alert("You must enter a name for this section!");
	} else if(type=="") {
		alert("You must select a section type for this section!");
	} else {
        var url="mms/mms_ajax_functions.php";
		var params="action=add_section&attach_level=" + attach_level + "&attach_code=" + attach_code + "&description=" + description + "&type=" + type;
		var opt={asynchronous:false,method:"post",parameters:params,
		onSuccess:function(request) {
			parent.addSectionLocal(attach_code, target + alt, request.responseText);
		}}
		new Ajax.Request(url,opt);
	}
}

showAddSection = function(type, code, alt) {
    if(document.getElementById('add_section' + type + alt).innerHTML == "") {
        var url="mms/mms_ajax_functions.php";
    	var params="action=add_section_form&type=" + type + "&code=" + code + "&alt=" + alt;
    	var opt={asynchronous:false,method:"post",parameters:params,
    	onSuccess:function(request) {
    		document.getElementById('add_section' + type + alt).innerHTML = request.responseText;
    		document.getElementById('add_section' + type + alt).style.display = "";
    		document.getElementById('section_description_' + type.charAt(0) + alt + "_" + code).focus();
    		
    		if(eval(document.getElementById('add_section' + type + ((alt == '1') ? "" : "1")))) {
                document.getElementById('add_section' + type + ((alt == '1') ? "" : "1")).style.display = "";
            }
    	}}
    	new Ajax.Request(url,opt);
    } else {
        document.getElementById('add_section' + type + alt).innerHTML = "";
    }
}
