	// Get URL Variables
	var urlVars = mcf.getUrlVars();
	
	
	
	/*
		Override the default behavior of alert() to use YUI panel instead
	*/
	AlertDialog = new YAHOO.widget.SimpleDialog("dlg1", {
		effect: {effect:YAHOO.widget.ContainerEffect.FADE,duration:0.15},
		fixedcenter: true,
		modal: true,
		visible: false,
		close: true,
		constraintoviewport: true,
		buttons: [{text:"Ok", handler: function(){this.hide();}, isDefault:true }],
		draggable: false,
		effect: [{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.3}]
	});
	
	AlertDialog.setHeader("Alert");
	AlertDialog.render(document.body);
	
	window.alert = function(text) {
		AlertDialog.cfg.setProperty("text", text);
		AlertDialog.show();
	};
	
	
	
	/*
		This object holds the additional dialog info
	*/
	var addlDialog = function() {
		
		// This method is called when the user clicks continue
		var addlContinue = function() {
			
			// If we entered additional information, then use it and close the dialog
			var email	= document.getElementById("addlEmail").value;
			var name	= document.getElementById("addlName").value;
			var phone	= document.getElementById("addlPhone").value;
			
			if(email != "" && name != "" && phone != "") {
				
				document.getElementById("f-88").value = email;
				document.getElementById("f-89").value = name;
				document.getElementById("f-90").value = phone;
				
				dialog1.hide();
				return;
			}
			
			// If not then just make an ajax call to check information
			this.submit();
		};
		
		// This method is called when the ajax call returned a response
		var addlHandleSuccess = function(o) {
			
			try {
				var response = YAHOO.lang.JSON.parse(o.responseText);
			}
			catch(e) {
				alert("Error decoding server response: '" + e + "'.");
			}
			
			if(response.status == "PASS") {
				document.getElementById("f-27").value = response.rid;
				document.getElementById("f-91").value = response.rid;
				document.getElementById("f-446").value = response.rid;
				dialog1.hide();
			}
			else if(response.status == "ADDLINFO") {
				toggleHide(true, false);
			}
			else if(response.status == "MESSAGE") {
				alert(response.message);
			}
		};
		
		// This method is called when the ajax call did not complete properly
		var addlHandleFailure = function(o) {
			alert("Error connecting to server: '" + o.status + "'.");
		};
		
		
		
		/*
			Load up the dialog
		*/
		var dialog1 = new YAHOO.widget.Dialog("dialog1", {
			width: "350px",
			effect:{effect:YAHOO.widget.ContainerEffect.FADE,duration:0.2},
			fixedcenter: true,
			modal: true,
			visible: true,
			hideaftersubmit: false,
			draggable: false,
			constraintoviewport: true,
			close: false,
			buttons: [
				{text:"Continue", handler: addlContinue, isDefault:true}
			]
		});
		
		dialog1.callback = {
			success: addlHandleSuccess,
			failure: addlHandleFailure
		};
		
		dialog1.setHeader("Sales Team Member Info");
		dialog1.setBody('\
			<form id="addlInfo" method="POST" action="?rid=' + urlVars['rid'] + '">\
				<label for="addlEmail">Email:</label><span class="req">*</span><br>\
				<input type="text" name="addlEmail" id="addlEmail" class="double"><br><span style="font-size:8pt;">Email is a required field</span><br>\
				<div id="addlMore">\
					<label for="addlName">Name:</label><br>\
					<input type="text" name="addlName" id="addlName" class="double"><br><br>\
					<label for="addlPhone">Phone:</label><br>\
					<input type="text" name="addlPhone" id="addlPhone" class="double"><br><br>\
					<input type="hidden" name="doAjax" value="2"><br>\
					<div style="color: red;">Your email address was not found in our system, please enter the additional information above to continue.</div>\
				</div>\
			</form>\
		');
		dialog1.setFooter("Footer");
		dialog1.render();

		
		
		/*
			Toggle show / hiding of additional elements for input
		*/
		var toggleHide = function(sh, initLoad) {
			
			// Set some vars
			var opacity, duration;
			sh			== true ? opacity = 100 : opacity = 0;
			initLoad	== true ? duration = 0.01 : duration = 1.5;
			
			var anim = new YAHOO.util.Anim("addlMore", {
				opacity: {to: opacity}
			}, duration);
			
			anim.animate();
		};
		
		// Hide additional fields on load
		toggleHide(false, true);
	};
	
	// Request additional information, if we pass in the second method
	if(urlVars['method'] == 2 || urlVars['method'] == 4) {
		addlDialog();
	}
	
	
	
	/*
		Gets form data
	*/
	var getData = function() {
		
		var i, j, data = "", fields = YAHOO.util.Dom.getElementsByClassName("inpt");
		for(i = 0; i < fields.length; i++) {
			
			switch(fields[i].tagName) {
				
				case "INPUT":
				
					switch(fields[i].type) {
						case "radio":
							if(fields[i].checked) {
								data += encodeURIComponent(fields[i].name) + "=" + encodeURIComponent(fields[i].value) + "&";
							}
						break;
						
						case "checkbox":
							if(fields[i].checked) {
								data += encodeURIComponent(fields[i].name) + "=" + encodeURIComponent(fields[i].value) + "&";
							}
						break;
						
						case "text":
							data += encodeURIComponent(fields[i].name) + "=" + encodeURIComponent(fields[i].value) + "&";
						break;
						
						case "hidden":
							data += encodeURIComponent(fields[i].name) + "=" + encodeURIComponent(fields[i].value) + "&";
						break;
					}
					
				break;
				
				case "SELECT":
					data += encodeURIComponent(fields[i].name) + "=" + encodeURIComponent(fields[i].options[fields[i].selectedIndex].value) + "&";
				break;
			}
		}
		
		
		// Remove last & symbol and return response
		data = data.slice(0, -1);
		return data;
	};
	
	
	
	/*
		Handle AJAX form submission
	*/
	var submitForm = function() {
		var z_sh = "";
		if('ce' in urlVars){
			z_sh = "&ce="+urlVars['ce'];
		}
		// AJAX call for deletion
		YAHOO.util.Connect.asyncRequest("POST", "?type=" + urlVars['type'] + "&rid=" + urlVars['rid'] + "&refer=" + urlVars['refer']+z_sh, {
			
			success: function(o) {
				
				try {
					var results = YAHOO.lang.JSON.parse(o.responseText);
				}
				catch(e) {
					alert("Error parsing response");
				}
				
				
				if(results.status == "PASS") {
					btnContinue.set("disabled", true);
					document.location.href = "formConfirmation.php";
				}
				else if(results.status == "ERROR") {
					alert(results.message);
				}
				else {
					alert("Server Error");
				}
			},
			
			failure: function(o) {
				alert("Error connecting to server");
			},
			
			customevents: {
				onStart: function(o) {
					YAHOO.util.Dom.get("loading").style.visibility = "visible";
				},
				onComplete: function(o) {
					YAHOO.util.Dom.get("loading").style.visibility = "hidden";
				}
			}
		}, "doAjax=1&" + getData());
	};
	
	
	
	/*
		Button configuration
	*/
	var btnContinue = new YAHOO.widget.Button({
		id:			"continue-contain",
		label:		"Submit",
		type:		"submit",
		container:	"continue"
	});
	
	btnContinue.addListener("click", submitForm);
