// JavaScript Document

/*
	* function chkUserNameExists
	* This function is ran after all default form validations pass
	* By default the form will not submit, if this Ajax Call returns false
	* then it submits the form for you, if not the username exists error displays
	*/
	function chkUserNameExists(cnt,mID){
		// Webservice URL
		var url='/includes/cfc/ajax.cfc?wsdl';
		// Parameters
		var pars='method=checkUserName&userName=' + $F('cstUsername') + '&memberID=' + mID;
	
		// only run if username value is passed
		if ($F('cstUsername') != ''){
			// New Ajax Request
			new Ajax.Request(url,{
				// changed method to post due to IE7 cache bug
				method: 'post',
				parameters:pars,
				onSuccess: function (transport){
					var retVal=transport.responseText.stripTags().strip();
					// start return
					if (retVal == 0){
						if (cnt){
							document.PlaceOrder.submit();
						}
					}else{
							// Name already exists call alert function
							$('cstUsername').className='inputWithError';
							$('errorUserName').show();
							if (cnt){
								alert('The username '+ $F('cstUsername') +' is already in use, please enter another username');
							}
					}
					// end return
				},
				onFailure: function (transport){
					//consoleDump('error occured' + transport);
				}
			});
		}
	}
	
	/*
	* function chkEmailExists
	* This function is ran after all default form validations pass
	* By default the form will not submit, if this Ajax Call returns false
	* then it submits the form for you, if not the email exists error displays
	*/
	function chkEmailExists(cnt,mID){
		// Webservice URL
		// Webservice URL
		var url='/includes/cfc/ajax.cfc?wsdl';
		// Parameters
		var pars='method=checkEmail&email=' + $F('cstEmail') + '&memberID=' + mID;
		// only run if username value is passed
		if ($F('cstEmail') != ''){
			// New Ajax Request
			new Ajax.Request(url,{
				// changed method to post due to IE7 cache bug
				method: 'post',
				parameters:pars,
				onSuccess: function (transport){
					var retVal=transport.responseText.stripTags().strip();
					// start return
					if (retVal == 0){
						if (cnt){
							// Continue to username check
							chkUserNameExists(cnt,mID);						
						}
					}else{
							// Name already exists call alert function
							$('cstEmail').className='inputWithError';
							$('errorEmail').show();
							if (cnt){
								alert('The e-mail address '+ $F('cstEmail') +' is already in use, please enter another e-mail');
							}
					}
					// end return
				},
				onFailure: function (transport){
					//consoleDump('error occured' + transport);
				}
			});
		}
	}
