<cfif mode eq "start">

	<cfif session.UserID NEQ 0>
		
		Welcome to the Yelp For Exes App!<br><br>
	
		Check us out, finish your profile, then get started adding exes and inviting people!<br><br>
	
	<cfelse>
	
		Welcome to the Yelp For Exes App!<br><br>
	
		Please register for an account!<br>
		
	</cfif>
	
<cfelseif mode eq "login">

	<cfparam name="form.username" default="">
	<cfparam name="form.password" default="">

	<cfquery name="check_user" datasource="yelpforexes">
		ID AS UserID
           WHERE    EmailAddress = '#form.username#'
						AND
					Password = '#hash(form.password)#'
						AND
					IsEmailVerified = 1
						AND
					UserIsMobileVerified = 1
	</cfquery>

    <cfif check_user.recordcount EQ 1>
    	
		<!--- Update the session variables and request variables --->
		<cflock timeout="15" throwontimeout="Yes" type="EXCLUSIVE" scope="SESSION">
    	    <cfset session.UserID = #check_user.UserID#>
			<!--- Re-duplicate them  --->
			<cfset request.UserID = Duplicate(session.UserID)>
		</cflock>
		
		<cflocation url="#request.cgipath#">
		
	<cfelse>
	
		No user found!<br><br>

		Please login.<br>
		
	</cfif>
	
<cfelseif mode eq "whatisthis">

	<h3>What is this?! Great Question!!</h3></br>

	Yelp For Exes (YFE) is a fun little app where users can input relationships with all sorts of people in your past.</br></br>

	After you add a relationship then rate them like a restaurant! Invite your friends or family to verify your story, invite the Ex so they can tell their side!</br></br>

	And you can even add your current relationships, they don't necessarily have to be an Ex. Register now and come join the conversations!!</br></br>

<cfelseif mode eq "register">

	<cfparam name="register_form_submitted" default="0">
	<cfparam name="messages" default="">
	
	<cfif register_form_submitted EQ 0>
		
		<cfparam name="values.Password" default="">
	    <cfparam name="values.Password_verify" default="">
	    <cfparam name="values.EmailAddress" default="">
	    <cfparam name="values.EmailAddress_verify" default="">
	    <cfparam name="values.UserMobileNumber" default="">
	    <cfparam name="values.UserMobileNumber_verify" default="">
	    
	<cfelseif register_form_submitted EQ 1>
	
		<cfparam name="form.Password" default="">
		<cfparam name="form.Password_verify" default="">
		<cfparam name="form.EmailAddress" default="">
		<cfparam name="form.EmailAddress_verify" default="">
		<cfparam name="form.UserMobileNumber" default="">
		<cfparam name="form.UserMobileNumber_verify" default="">
	
		<cfset values.Password = trim(form.Password)>
		<cfset values.Password_verify = trim(form.Password_verify)>
		<cfset values.EmailAddress = trim(form.EmailAddress)>
		<cfset values.EmailAddress_verify = trim(form.EmailAddress_verify)>
		<cfset values.UserMobileNumber = trim(form.UserMobileNumber)>
		<cfset values.UserMobileNumber_verify = trim(form.UserMobileNumber_verify)>
		
	<cfelse>
		
		Problem!<cfabort>
	
	</cfif>
	
	<cfif register_form_submitted EQ 1>
		
		<cfif REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", values.EmailAddress) EQ 0>
			<cfset messages = listappend(messages, "invalid email address entered")>
		<cfelseif values.EmailAddress NEQ values.EmailAddress>
			<cfset messages = listappend(messages, "email address values do not match")>
		<cfelse>
			<CFQUERY name="check_dupe_email" datasource="#application.datasource#">
				SELECT		ID
				FROM		Users
				WHERE		EmailAddress='#values.EmailAddress#'
	                            AND 
	                        IsEmailVerified = 1
	                            AND 
	                        UserIsMobileVerified = 1
			</CFQUERY>
			<cfif check_dupe_email.recordcount GT 0>
				<cfset messages = listappend(messages, "that email address already has a Yelp For Exes account")>
			</cfif>
		</cfif>
	
		<cfmodule credential = "#values.UserMobileNumber#" template = "modules/parse_phnum.cfm">
	
		<cfset values.UserMobileNumber = parsed_phnum>
	
		<cfmodule credential = "#values.UserMobileNumber_verify#" template = "modules/parse_phnum.cfm">
	
		<cfset values.UserMobileNumber_verify = parsed_phnum>
		
		<!--- <cfdump var=#values#> --->
	
		<cfif len(values.UserMobileNumber_verify) NEQ 10>
		    <cfset messages = listappend(messages, "Mobile number must be a 10-digit number")>
		<cfelseif values.UserMobileNumber_verify NEQ values.UserMobileNumber>
	    	<cfset messages = listappend(messages, "Values for contact number do not match")>
			<cfset values.UserMobileNumber = "">
			<cfset values.UserMobileNumber_verify = "">
		<cfelse>
			<CFQUERY name="check_dupe_ContactNumber" datasource="#application.datasource#">
				SELECT		ID
				FROM		Users
				WHERE		UserMobileNumber='#values.UserMobileNumber#'
								AND 
							IsEmailVerified = 1
								AND 
							UserIsMobileVerified = 1
			</CFQUERY>
	
			<cfif check_dupe_ContactNumber.recordcount NEQ 0>
				<cfset messages = listappend(messages, "that mobile number already has a Yelp For Exes account")>
			</cfif>
		</cfif>
		
		<cfif values.Password EQ "">
			<cfset messages = listappend(messages, "password is required")>
		<cfelseif values.Password NEQ values.Password_verify>
			<cfset messages = listappend(messages, "password values do not match")>
			<cfset values.Password = "">
			<cfset values.Password_verify = "">
		</cfif>
	
	</cfif>
	
	<cfif register_form_submitted EQ 0 OR messages GT "">
	
	    <br><h2>Register for Yelp For Exes:</h2>
			
		<cfif messages GT "">
		
			<CFLOOP INDEX="ListElement" LIST=#messages#> 
			<CFOUTPUT><div align="center"><font color="FF0000"><h2>#ListElement#</h2></font></div></CFOUTPUT>
			</CFLOOP><br><br>
			
			</cfif>
		
		<cfoutput>
		
		<div align="center">
		
		<form action="#request.cgiPath#" method="post" name="register" id="register">
		
			<table border="0" cellspacing="2" cellpadding="2">
				<tr>
					<td colspan="2" align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm"> = required<br></td>
				</tr>
				<tr>
					<td align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm">Email:</td>
					<td><input type="text" name="EmailAddress" id="EmailAddress" size="25" maxlength="100" tabindex="1" value=#values.EmailAddress#></td>
				</tr>
				<tr>
					<td align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm">Email verify:</td>
					<td><input type="text" name="EmailAddress_verify" id="EmailAddress_verify" size="25" maxlength="100" tabindex="2" value=#values.EmailAddress_verify#></td>
				</tr>            
				<tr>
					<td align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm">Mobile number:</td>
					<td><input type="text" name="UserMobileNumber" id="UserMobileNumber" size="25" maxlength="100" tabindex="3" value=#values.UserMobileNumber#></td>
				</tr>            
				<tr>
					<td align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm">Mobile verify:</td>
					<td><input type="text" name="UserMobileNumber_verify" id="UserMobileNumber_verify" size="25" maxlength="100" tabindex="4" value=#values.UserMobileNumber_verify#></td>
				</tr>
				<tr>
					<td align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm">Password:</td>
					<td><input type="password" name="Password" id="Password" size="12" maxlength="30" tabindex="5" value=#values.Password#></td>
				</tr>
				<tr>
					<td align="right"><cfinclude template="#application.wwwrootprefix#includes/required_indicator.cfm">Password verify:</td>
					<td><input type="password" name="Password_verify" id="Password_verify" size="12" maxlength="30" tabindex="6" value=#values.Password_verify#></td>
				</tr>
				<tr>
					<td>&nbsp;</td>
					<td><input type="submit" tabindex="10" value="register" tabindex="7"></td>
				</tr>
			</table>
			
			<input type="hidden" name="register_form_submitted" value="1">
			<input type="hidden" name="mode" value="register">
		
		</form>
		
		</div>
							
		</cfoutput>
		
	<cfelseif register_form_submitted EQ 1>
	
		<cfset UUID_to_insert = CreateUUID()>
	
		<cfset customer_OPT_confirm = round(rand()*899996+100000)>
	
		<cfmodule ContactNumber = "#values.UserMobileNumber#" template = "#application.wwwrootprefix#modules/send_reg_text.cfm">
	
		<!--- <cfset isMessageSent = application.twilioObj.sendSMS(recipientNumber=#values.UserMobileNumber#, messageBody = "Yelp For Exes OTP code is #customer_OPT_confirm#, please input it into your registration page, or tap here: https://payfr.it/confirm_mobile.cfm")> --->
	
		<cfquery name="insert_account" datasource="#application.datasource#">
		    INSERT INTO		Users
							(
							 EmailAddress,
							 Password,
	                         UserProfileImage,
	                         UserMobileNumber,
	                         IsActive,
	                         UserIsMobileVerified,
	                         UserDeviceToken,
	                         UserPlatform,
	                         AddedOn,
	                         UUID,
							 MobileVerifyCode
							)
			VALUES
							(
							 '#values.EmailAddress#',
							 '#hash(values.Password)#',
	                         '',
	                         '#values.UserMobileNumber#',
	                          0,
	                          0,
	                          '',
	                         'web signup register.cfm',
	                          #createODBCDateTime(now())#,
	                         '#UUID_to_insert#',
							 '#customer_OPT_confirm#'
							 )
		</cfquery>
			
	    <cfset link_to_build = "https://"&cgi.server_name&application.wwwrootprefix&"confirm_email.cfm?UUID="&UUID_to_insert>
			
		<cfmail to="admin@payfrit.com, #values.EmailAddress#"
	        from="admin@payfrit.com"
	        subject="Activate your Yelp For Exes account"
	        type="HTML"><cfoutput>
			Thank you for registering for Yelp For Exes!<br>Click this link to confirm your email:<br><br>
			<a href="#link_to_build#">click here to confirm</a><br><br>
			if that doesn't work you can try to copy and paste this link into your browser:<br><br>
			#link_to_build#<br><br>
			if that doesn't work then <a href="admin@yelpforexes.com">email</a> us and we will figure out how to fix it.<br><br>
			regards,<br>
			<br>
			Yelp For Exes<br></cfoutput>
		</cfmail>
		
		<cfmail to="admin@payfrit.com, payfrit@gmail.com"
	        from="admin@payfrit.com"
	        subject="new registration on Yelp For Exes"
	        type="HTML"><cfoutput>
			Email address = #values.EmailAddress#<br>
			Mobile number = #values.UserMobileNumber#<br>
			</cfoutput>
		</cfmail>
					
		<br>
	
		<cfoutput>now let's validate your mobile number!<br><br>

		<cfmodule variable_value = "#values.UserMobileNumber#" template = "#application.wwwrootprefix#modules/format_phnum.cfm">
	
		we just sent a six digit code to #formatted_phnum#<br><br>please input that code here:<br><br>
	
		<script language="JavaScript">
			function submitformconfirmmobile()
			{
			document.myformconfirmmobile.submit();
			}
		</script>
		
		<form action="#request.cgiPath#" method="post" name="myformconfirmmobile" id="myformconfirmmobile" style="display:inline;">
		
			<input type="text" size="5" maxlength="6" name="OTP">&nbsp;<a href="javascript: submitformconfirmmobile()">confirm mobile</a>
			
			<input type="hidden" name="UUID" value="#UUID_to_insert#">
			<input type="hidden" name="mode" value="confirm">
		
		</form><br><br>
		
		in addition we sent you an email with a link to click on to confirm your email, after you submit your six digit code above<br><br>thanks!<br></cfoutput>
	
	</cfif>

<cfelseif mode eq "rate_an_ex">

	<cfif request.UserID GT 0>

		<cfparam name="form.FirstName" default="">
		<cfparam name="form.LastName" default="">
		<cfparam name="form.EmailAddress" default="">
		<cfparam name="form.UserMobileNumber" default="">
	
		The first step is to find out if your Ex already has an account here<br><br>
		
		Please enter their name and at least one contact method:<br><br>
		
		<cfoutput>
		
		<script language="JavaScript">
			function submitformsearch()
			{
			document.myformsearch.submit();
			}
		</script>
		
		<form action="#request.cgiPath#" method="post" name="myformsearch" id="myformsearch" style="display:inline;">
		
			<TABLE border="0">
				<TR> 
					<TD>
						First Name:
					</TD>
					<TD> 
						<INPUT name="FirstName" value="#form.FirstName#" size="12" maxlength="50">
					</TD>
				</TR>
				<TR> 
					<TD>
						Last Name:
					</TD>
					<TD> 
						<INPUT name="LastName" value="#form.LastName#" size="25" maxlength="50">
					</TD>
				</TR>
				<TR> 
					<TD>
						Email address:
					</TD>
					<TD>
						<INPUT name="EmailAddress" value="#form.EmailAddress#" size="25" maxlength="100">
					</TD>
				</TR>
				<TR> 
					<TD>
						Mobile Number:
					</TD>
					<TD>
						<INPUT name="UserMobileNumber" value="#form.UserMobileNumber#" size="12" maxlength="15">
					</TD>
				</TR>
			</TABLE><br><br>
		
			<a href="javascript:submitformsearch()">- - - ></a>
		
			<input type="hidden" name="mode" value="rate_an_ex_search">
			
			</form></cfoutput><br><br>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "rate_an_ex_search">

	<cfif request.UserID GT 0>

		<CFQUERY name="check_dupe_user" datasource="#application.datasource#">
			SELECT		ID
			FROM		Users
			WHERE		EmailAddress='#form.EmailAddress#'
							AND
						UserMobileNumber='#form.UserMobileNumber#'
	                           AND 
	                       IsEmailVerified = 1
	                           AND 
	                       UserIsMobileVerified = 1
		</CFQUERY>
		
		<cfif check_dupe_user.recordcount EQ 1>
		
			User found! Is this the person?<br>
			
		<cfelse>
		
			No current YFE user found, are you sure this info is correct?<br><br>
			<cfoutput><table>
				<tr>
					<td>First Name:</td>
					<td>#form.FirstName#</td>
				</tr>
				<tr>
					<td>Last Name:</td>
					<td>#form.LastName#</td>
				</tr>
				<tr>
					<td>Email Addr:</td>
					<td>#form.EmailAddress#</td>
				</tr>
				<tr>
					<td>Number:</td>
					<td>#form.UserMobileNumber#</td>
				</tr>
			</table></cfoutput><br><br>
	
			<script language="JavaScript">
				function submitformyescorrect()
				{
				document.myformyescorrect.submit();
				}
			</script>
			
			<cfoutput><form action="#request.cgiPath#" method="post" name="myformyescorrect" id="myformyescorrect" style="display:inline;">
			
				<a href="javascript:submitformyescorrect()">YES it's correct</a>
				
				<input type="hidden" name="mode" value="rate_an_ex_add_basics">
				<input type="hidden" name="FirstName" value="#form.FirstName#">			
				<input type="hidden" name="LastName" value="#form.LastName#">
				<input type="hidden" name="EmailAddress" value="#form.EmailAddress#">			
				<input type="hidden" name="UserMobileNumber" value="#form.UserMobileNumber#">
			
			</form><br><br>
			
			<script language="JavaScript">
				function submitformtryagain()
				{
				document.myformtryagain.submit();
				}
			</script>
			
			<form action="#request.cgiPath#" method="post" name="myformtryagain" id="myformtryagain" style="display:inline;">
			
				<a href="javascript:submitformtryagain()">NO try again</a>
							
				<input type="hidden" name="mode" value="rate_an_ex">
				<input type="hidden" name="FirstName" value="#form.FirstName#">			
				<input type="hidden" name="LastName" value="#form.LastName#">
				<input type="hidden" name="EmailAddress" value="#form.EmailAddress#">			
				<input type="hidden" name="UserMobileNumber" value="#form.UserMobileNumber#">
			
			</form></cfoutput><br><br>
			
		</cfif>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "rate_an_ex_add_basics">

	<cfif request.UserID GT 0>

		<cfparam name = form.LastInsertedUserID default=0>
	
		<cfif prevmode neq "rate_an_ex_confirm_basic_details">
		
			<cfset UUID_to_insert = CreateUUID()>
			
			<cfquery name="insert_account" datasource="#application.datasource#">
			    INSERT INTO		Users
								(
								 FirstName,
			                     LastName,
			                     EmailAddress,
			                     UserMobileNumber,
			                     UserPlatform,
			                     AddedOn,
			                     UUID
								)
				VALUES
								(
								 '#form.FirstName#',
		                         '#form.LastName#',
		                         '#form.EmailAddress#',
		                         '#form.UserMobileNumber#',
		                         'relationship submitted online',
		                          #createODBCDateTime(now())#,
		                         '#UUID_to_insert#'
								 )
			</cfquery>
			
			<cfquery name="get_last_inserted" datasource="#application.datasource#">
				SELECT UserID as LastInsertedUserID FROM `Users` order by UserID desc limit 1;
			</cfquery>
		
		<cfelse>
		
			<cfquery name="get_name" datasource="#application.datasource#">
				SELECT	FirstName, LastName
				FROM	Users
				WHERE	ID = #form.LastInsertedUserID#
			</cfquery>
			
			<cfset form.FirstName = #get_name.FirstName#>
			<cfset form.LastName = #get_name.LastName#>
			<cfset get_last_inserted.LastInsertedUserID = #form.LastInsertedUserID#>
		</cfif>
		
		<cfparam name="form.RelationshipTitle" default="">
		<cfparam name="form.RelationshipStartDate" default="">
		<cfparam name="form.RelationshipEndDate" default="">
		<cfparam name="form.RelationshipTypeID" default="0">
		<cfparam name="form.RelationshipDescription" default="">
		<cfparam name="form.RelationshipQuickRating" default="0">
	
		You are rating: <cfoutput>#form.FirstName# #form.LastName#</cfoutput><br><br>
	
		The next step is to provide some basic details about the relationship you are rating:<br><br>
		
		<script language="JavaScript">
			function submitformsearch()
			{
			document.myformsearch.submit();
			}
		</script>
		
		<cfoutput><form action="#request.cgiPath#" method="post" name="myformsearch" id="myformsearch" style="display:inline;">
		
			<TABLE border="0">
				<TR> 
					<TD>
						Title your rating:
					</TD>
					<TD> 
						<INPUT name="RelationshipTitle" value="#form.RelationshipTitle#" size="25" maxlength="100">
					</TD>
				</TR>			
				<script>
				$( function() {
				  $( "##datepicker" ).datepicker({ changeMonth: true, changeYear: true });
				} );
				</script>
				<TR> 
					<TD>
						Start Date:
					</TD>
					<TD>
						<input type="text" name="RelationshipStartDate" id="datepicker" value="#form.RelationshipStartDate#">
					</TD>
				</TR>		
				<script>
				$( function() {
				  $( "##datepicker1" ).datepicker({ changeMonth: true, changeYear: true });
				} );
				</script>
				<TR> 
					<TD>
						End Date:
					</TD>
					<TD>
						<input type="text" name="RelationshipEndDate" id="datepicker1" value="#form.RelationshipEndDate#">
					</TD>
				</TR>
				<TR> 
					<TD>
						Relationship Type:
					</TD>
					<CFQUERY name="get_relationship_types" datasource="#application.datasource#">
						SELECT      RelationshipTypeID, RelationshipTypeName
						FROM        tt_RelationshipTypes
						ORDER BY	RelationshipTypeSortOrder
					</CFQUERY>
					<TD>
						<select name="RelationshipTypeID">
							<option value="0">Please Select</option>
							<cfoutput query=#get_relationship_types#>
		  						<option value="#get_relationship_types.RelationshipTypeID#"<cfif form.RelationshipTypeID EQ get_relationship_types.RelationshipTypeID> Selected</cfif>>#RelationshipTypeName#</option>
							</cfoutput>
						</select>
					</TD>
				</TR>
				<TR> 
					<TD>
						Description:
					</TD>
					<TD>
						<TEXTAREA name="RelationshipDescription" value="#form.RelationshipDescription#" rows="4" cols="30" maxlength="100"><cfoutput>#form.RelationshipDescription#</cfoutput></textarea>
					</TD>
				</TR>			
				  <script>
				  $( function() {
				    $( "##slider" ).slider();
				  } );
				  </script>
				<TR> 
					<TD>
						Quick Rating: <span id="RelationshipQuickRating"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						 <br><input type="range" min="1" max="10" value="5" class="slider" id="myRange"name="RelationshipQuickRating">
						</div>
						<script>
							var slider = document.getElementById("myRange");
							var output = document.getElementById("RelationshipQuickRating");
							output.innerHTML = slider.value;
							
							slider.oninput = function() {
							  output.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
			</TABLE><br><br>
		
			<a href="javascript:submitformsearch()">- - - ></a>
		
			<input type="hidden" name="LastInsertedUserID" value="#get_last_inserted.LastInsertedUserID#">
			<input type="hidden" name="mode" value="rate_an_ex_confirm_basic_details">
			
		</form></cfoutput><br><br>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>
		
<cfelseif mode eq "rate_an_ex_confirm_basic_details">

	<cfif request.UserID GT 0>

		You are about to create this rating, does everything look correct?<br><br>
	
		<cfoutput>Title=#form.RelationshipTitle#<br>
		StartDate=#form.RelationshipStartDate#<br>
		EndDate=#form.RelationshipEndDate#<br>
		TypeID=#form.RelationshipTypeID#<br>
		Description=#form.RelationshipDescription#<br>
		QuickRating=#form.RelationshipQuickRating#<br><br></cfoutput>
	
		<script language="JavaScript">
			function submitformyescorrect()
			{
			document.myformyescorrect.submit();
			}
		</script>
		
		<cfoutput><form action="#request.cgiPath#" method="post" name="myformyescorrect" id="myformyescorrect" style="display:inline;">
		
			<a href="javascript:submitformyescorrect()">YES it's correct</a>
			
			<input type="hidden" name="mode" value="rate_an_ex_add_details">
			<input type="hidden" name="prev_mode" value="rate_an_ex_confirm_basic_details">
			<input type="hidden" name="RelationshipTitle" value="#form.RelationshipTitle#">
			<input type="hidden" name="RelationshipStartDate" value="#form.RelationshipStartDate#">
			<input type="hidden" name="RelationshipEndDate" value="#form.RelationshipEndDate#">
			<input type="hidden" name="RelationshipTypeID" value="#form.RelationshipTypeID#">
			<input type="hidden" name="RelationshipDescription" value="#form.RelationshipDescription#">
			<input type="hidden" name="RelationshipQuickRating" value="#form.RelationshipQuickRating#">
			<input type="hidden" name="LastInsertedUserID" value="#form.LastInsertedUserID#">
		
		</form><br><br>
		
		<script language="JavaScript">
			function submitformtryagain()
			{
			document.myformtryagain.submit();
			}
		</script>
		
		<form action="#request.cgiPath#" method="post" name="myformtryagain" id="myformtryagain" style="display:inline;">
		
			<a href="javascript:submitformtryagain()">NO try again</a>
						
			<input type="hidden" name="mode" value="rate_an_ex_add_basics">
			<input type="hidden" name="prev_mode" value="rate_an_ex_confirm_basic_details">
			<input type="hidden" name="RelationshipTitle" value="#form.RelationshipTitle#">
			<input type="hidden" name="RelationshipStartDate" value="#form.RelationshipStartDate#">
			<input type="hidden" name="RelationshipEndDate" value="#form.RelationshipEndDate#">
			<input type="hidden" name="RelationshipTypeID" value="#form.RelationshipTypeID#">
			<input type="hidden" name="RelationshipDescription" value="#form.RelationshipDescription#">
			<input type="hidden" name="RelationshipQuickRating" value="#form.RelationshipQuickRating#">
			<input type="hidden" name="LastInsertedUserID" value="#form.LastInsertedUserID#">
		
		</form></cfoutput>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "rate_an_ex_add_details">

	<cfif request.UserID GT 0>

		<cfquery name="insert_relationship" datasource="#application.datasource#">
		    INSERT INTO		Relationships
							(
							 RelationshipAddedByUserID,
							 RelationshipSubjectUserID,
							 RelationshipTitle,
		                     RelationshipStartDate,
		                     RelationshipEndDate,
		                     RelationshipTypeID,
		                     RelationshipDescription,
		                     RelationshipQuickRating,
		                     RelationshipAddedOn
							)
			VALUES
							(
							  #request.UserID#,
							  #form.LastInsertedUserID#,
							 '#form.RelationshipTitle#',
	                          #createODBCDate(form.RelationshipStartDate)#,
	                          #createODBCDate(form.RelationshipEndDate)#,
	                          #form.RelationshipTypeID#,
	                         '#form.RelationshipDescription#',
	                         '#form.RelationshipQuickRating#',
	                          #createODBCDateTime(now())#
							 )
		</cfquery>
			
		<cfquery name="get_last_inserted" datasource="#application.datasource#">
			SELECT RelationshipID as LastInsertedRelationshipID FROM `Relationships` order by RelationshipID desc limit 1;
		</cfquery>
		
		Basic details added, now here's some additional optional details, if you'd like to give us more info!<br><br>
		
			<script language="JavaScript">
			function submitformsearch()
			{
			document.myformsearch.submit();
			}
		</script>
		
		<cfoutput><form action="#request.cgiPath#" method="post" name="myformsearch" id="myformsearch" style="display:inline;">
		
			<TABLE border="0">
				<CFQUERY name="get_States" datasource="#application.datasource#">
					SELECT      tt_StateID, Name
					FROM        tt_States
					WHERE		tt_StateCountryID = 1 <!--- only USA --->
					ORDER BY	tt_StateSortOrder
				</CFQUERY>
				<TR> 
					<TD>
						City & State:
					</TD>
					<TD><input type="text" name="RelationshipCity" size="25" maxlength="100">
						<select name="RelationshipStateID">
							<option value="0">Please Select</option>
							<cfoutput query=#get_States#>
		  						<option value="#tt_StateID#">#Name#</option>
							</cfoutput>
						</select>
					</TD>
				</TR>
				</TR>
				<TR> 
					<TD>
						Honesty Rating: <span id="RelationshipHonesty"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange1" name="RelationshipHonesty">
						</div>
						<script>
							var slider1 = document.getElementById("myRange1");
							var output1 = document.getElementById("RelationshipHonesty");
							output1.innerHTML = slider1.value;
							
							slider1.oninput = function() {
							  output1.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Loyalty Rating: <span id="RelationshipLoyalty"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange2" name="RelationshipLoyalty">
						</div>
						<script>
							var slider2 = document.getElementById("myRange2");
							var output2 = document.getElementById("RelationshipLoyalty");
							output2.innerHTML = slider2.value;
							
							slider2.oninput = function() {
							  output2.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Frugality Rating:<br>(1=cheap, 10=$$$) <span id="RelationshipFrugality"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange3" name="RelationshipFrugality">
						</div>
						<script>
							var slider3 = document.getElementById("myRange3");
							var output3 = document.getElementById("RelationshipFrugality");
							output3.innerHTML = slider3.value;
							
							slider3.oninput = function() {
							  output3.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Responsibility Rating: <span id="RelationshipResponsibility"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange4" name="RelationshipResponsibility">
						</div>
						<script>
							var slider4 = document.getElementById("myRange4");
							var output4 = document.getElementById("RelationshipResponsibility");
							output4.innerHTML = slider4.value;
							
							slider4.oninput = function() {
							  output4.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Funniness Rating: <span id="RelationshipFunny"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange5" name="RelationshipFunny">
						</div>
						<script>
							var slider5 = document.getElementById("myRange5");
							var output5 = document.getElementById("RelationshipFunny");
							output5.innerHTML = slider5.value;
							
							slider5.oninput = function() {
							  output5.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Outdoor Rating: <span id="RelationshipOutdoor"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange6" name="RelationshipOutdoor">
						</div>
						<script>
							var slider6 = document.getElementById("myRange6");
							var output6 = document.getElementById("RelationshipOutdoor");
							output6.innerHTML = slider6.value;
							
							slider6.oninput = function() {
							  output6.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Geek Rating: <span id="RelationshipGeek"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange7" name="RelationshipGeek">
						</div>
						<script>
							var slider7 = document.getElementById("myRange7");
							var output7 = document.getElementById("RelationshipGeek");
							output7.innerHTML = slider7.value;
							
							slider7.oninput = function() {
							  output7.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Sex Rating: <span id="RelationshipSex"></span>
					</TD>
					<TD>
						<div class="slidecontainer">
						  <input type="range" min="1" max="10" value="5" class="slider" id="myRange8" name="RelationshipSex">
						</div>
						<script>
							var slider8 = document.getElementById("myRange8");
							var output8 = document.getElementById("RelationshipSex");
							output8.innerHTML = slider8.value;
							
							slider8.oninput = function() {
							  output8.innerHTML = this.value;
							}
						</script>
					</TD>
				</TR>
				<TR> 
					<TD>
						Best thing about it:
					</TD>
					<TD><input type="text" name="RelationshipBestThing" size="25" maxlength="1000">
					</TD>
				</TR>
				</TR>
				<TR> 
					<TD>
						Worst thing about it:
					</TD>
					<TD><input type="text" name="RelationshipWorstThing" size="25" maxlength="1000">
					</TD>
				</TR>
				</TR>
				<TR> 
					<TD>
						Who would be perfect for this person:
					</TD>
					<TD><input type="text" name="RelationshipWhoWouldEnjoy" size="25" maxlength="500">
					</TD>
				</TR>
				</TR>
				<TR> 
					<TD>
						Who should stay away:
					</TD>
					<TD><input type="text" name="RelationshipWhoShouldStayAway" size="25" maxlength="500">
					</TD>
				</TR>
				</TR>
				</TABLE><br><br>
		
			<a href="javascript:submitformsearch()">- - - ></a>
		
			<input type="hidden" name="LastInsertedUserID" value="#form.LastInsertedUserID#">
			<input type="hidden" name="LastInsertedRelationshipID" value="#get_last_inserted.LastInsertedRelationshipID#">
			<input type="hidden" name="mode" value="rate_an_ex_save_extra">
			
		</form></cfoutput><br><br>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>
	
<cfelseif mode eq "rate_an_ex_save_extra">

	<cfif request.UserID GT 0>
	
		<cfquery name="update_relationship" datasource="#application.datasource#">
		    UPDATE		Relationships
			SET			RelationshipCity = '#form.RelationshipCity#',
						RelationshipStateID = '#form.RelationshipStateID#',
						RelationshipHonesty = '#form.RelationshipHonesty#',
						RelationshipLoyalty = '#form.RelationshipLoyalty#',
						RelationshipFrugality = '#form.RelationshipFrugality#',
						RelationshipResponsibility = '#form.RelationshipResponsibility#',
						RelationshipFunny = '#form.RelationshipFunny#',
						RelationshipOutdoor = '#form.RelationshipOutdoor#',
						RelationshipGeek = '#form.RelationshipGeek#',
						RelationshipSex = '#form.RelationshipSex#',
						RelationshipBestThing = '#form.RelationshipBestThing#',
						RelationshipWorstThing = '#form.RelationshipWorstThing#',
						RelationshipWhoWouldEnjoy = '#form.RelationshipWhoWouldEnjoy#',
						RelationshipWhoShouldStayAway = '#form.RelationshipWhoShouldStayAway#'
			WHERE
						relationshipID = '#form.LastInsertedRelationshipID#'
		</cfquery>
		
		<cfoutput><form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
			<input type="hidden" name="mode" value="rate_an_ex_upload_media">
			<input type="hidden" name="chip" value="#form.LastInsertedRelationshipID#">
		</form>
		</cfoutput>
	
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>
		
	<cfelse>
		
		Please login!<br>
		
	</cfif>
	
<cfelseif mode eq "rate_an_ex_upload_media">

	<cfif request.UserID GT 0>
	
		Upload media to accompany your rating!<br><br>
		
		<cfparam name="image_form_submitted" default="0">
		
		<cfif image_form_submitted EQ 0>
	
			<cfoutput>
				<form method="post" action="#request.cgiPath#" enctype="multipart/form-data" style="display:inline;">
					<input type="file" name="file_sent" id="file_sent" size="100" accept="image/jpeg">
					<input type="hidden" name="image_form_submitted" value="1">
					<input type="hidden" name="chip" value="#form.chip#">
					<input type="hidden" name="mode" value="rate_an_ex_upload_media">
					<input type="submit" value="Upload >>>">
				</form>
			</cfoutput>
			
		<cfelse>
	
			<cfset messages="">
			
			<cfif file_sent neq "">
			
				<cffile action="UPLOAD" filefield="file_sent" destination="#application.uploads_dir#" nameconflict="MAKEUNIQUE" mode="755">
					
				<cfif LCase(cffile.ClientFileExt) NEQ "jpg" AND LCase(cffile.ClientFileExt) NEQ "gif" AND LCase(cffile.ClientFileExt) NEQ "png">
					<cfset messages="Only image files are accepted (jpg, gif, png)">
					<cffile action="DELETE" file="#application.uploads_dir##cffile.ClientFile#">
				<cfelse>
					<cfset image_randomizer = round(rand()*899996+100000)>
					<cfset this_file_name = "rel_"&chip&"_"&image_randomizer&"."&#cffile.ClientFileExt#>
					<cfset built_storage_subdirs = "/">
					<!--- <cfif DirectoryExists(#application.uploads_dir#&#built_storage_subdirs#) EQ "No">
					
						<cfdirectory action="CREATE" directory="#application.uploads_dir##built_storage_subdirs#" mode="755">
						<cfdirectory action="CREATE" directory="#application.uploads_dir##built_storage_subdirs#thumbs/" mode="755">
					
					</cfif> --->
					
					<cffile action="RENAME" source="#application.uploads_dir#\#cffile.ClientFile#" destination="#application.uploads_dir##built_storage_subdirs##this_file_name#" mode="755">
					<cfimage source="#application.uploads_dir##built_storage_subdirs##this_file_name#" action="info" structName="image_info">
					<cfif image_info.height GT image_info.width and image_info.height GT 1280>
						
						<cfset this_file_name_tmp = "tmp_"&request.userid&"_"&chip&"_"&image_randomizer&"."&#cffile.ClientFileExt#>
						<cfimage action="resize" source="#application.uploads_dir##built_storage_subdirs##this_file_name#" height="1280" destination="#application.uploads_dir##built_storage_subdirs##this_file_name_tmp#">
						<cffile action="RENAME" source="#application.uploads_dir##built_storage_subdirs##this_file_name_tmp#" destination="#application.uploads_dir##built_storage_subdirs##this_file_name#" mode="755">
					
					</cfif>
					<cfif image_info.width GT image_info.height and image_info.width GT 1280>
						
						<cfset this_file_name_tmp = "tmp_"&request.userid&"_"&chip&"_"&image_randomizer&"."&#cffile.ClientFileExt#>
						<cfimage action="resize" source="#application.uploads_dir##built_storage_subdirs##this_file_name#" width="1280" destination="#application.uploads_dir##built_storage_subdirs##this_file_name_tmp#">
						<cffile action="RENAME" source="#application.uploads_dir##built_storage_subdirs##this_file_name_tmp#" destination="#application.uploads_dir##built_storage_subdirs##this_file_name#" mode="755">
					
					</cfif>
					<cffile action="COPY" source="#application.uploads_dir##built_storage_subdirs##this_file_name#" destination="#application.uploads_dir##built_storage_subdirs#thumbs/#this_file_name#" mode="755">
					<cfimage action="resize" source="#application.uploads_dir##built_storage_subdirs#thumbs/#this_file_name#" width="125" destination="#application.uploads_dir##built_storage_subdirs#thumbs/#this_file_name#.#cffile.ClientFileExt#">
					<cffile action="RENAME" source="#application.uploads_dir##built_storage_subdirs#thumbs/#this_file_name#.#cffile.ClientFileExt#" destination="#application.uploads_dir##built_storage_subdirs#thumbs/#this_file_name#" mode="755">
					<!--- <cffile action="DELETE" file="#application.wwwrootprefix#uploads/#request.userid#/thumbs/#this_file_name#"> --->
					
					<cfquery name="add_image" datasource="#application.datasource#">
						INSERT INTO		lt_Relationships_UploadedImages
										(
										 lt_Relationships_UploadedImages_RelationshipID,
										 lt_Relationships_UploadedImages_ImageName,
										 lt_Relationships_UploadedImages_AddedOn
										)
						VALUES			(
										 #form.chip#,
										'#this_file_name#',
										 #createODBCDateTime(now())#
										)
					</cfquery>
					
				</cfif>
				
			<cfelse>
			
				<cfset messages="You did not select a file to upload">
			
			</cfif>
			
			<cfif messages EQ "">
			
				<cfoutput>	
					<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
						<input type="hidden" name="mode" value="rate_an_ex_edit">
						<input type="hidden" name="chip" value="#form.chip#">
					</form>
				</cfoutput>
				
				<script type="text/JavaScript" language="JavaScript">  
					document.go_page.submit();  
				</script>
				
			<cfelse>
			
				Your upload attempt has been rejected for the following reason(s):<br><br>
				
				<cfoutput><font color="FF0000">#messages#</font></cfoutput><br><br>
				
				<script language="JavaScript" type="text/javascript">
				function submitform1()
				{
				document.myform1.submit();
				}
				</script>
				
				<cfoutput>
					<form action="#request.cgiPath#" method="post" name="myform1" id="myform1" style="display:inline;">
						<a href="javascript: submitform1()">Return to editing</a>
								<input type="hidden" name="mode" value="rate_an_ex_edit">
								<input type="hidden" name="chip" value="#form.chip#">
					</form>
				</cfoutput><br>
			
			</cfif>
			
		</cfif>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "rate_an_ex_edit">

	<cfif request.userid neq 0>
	
		<cfparam name="form.rel_update_form_submitted" default="0">
	
		<cfif form.rel_update_form_submitted EQ 1>
		
			<cfquery name="update_relationship" datasource="#application.datasource#">
			    UPDATE		Relationships
				SET			RelationshipTitle = '#form.RelationshipTitle#',
		                    RelationshipStartDate = #CreateODBCDate(form.RelationshipStartDate)#,
		                    RelationshipEndDate = #CreateODBCDate(form.RelationshipEndDate)#,
		                    RelationshipTypeID = '#form.RelationshipTypeID#',
		                    RelationshipDescription = '#form.RelationshipDescription#',
		                    RelationshipQuickRating = '#form.RelationshipQuickRating#',
							RelationshipCity = '#form.RelationshipCity#',
							RelationshipStateID = '#form.RelationshipStateID#',
							RelationshipHonesty = '#form.RelationshipHonesty#',
							RelationshipLoyalty = '#form.RelationshipLoyalty#',
							RelationshipFrugality = '#form.RelationshipFrugality#',
							RelationshipResponsibility = '#form.RelationshipResponsibility#',
							RelationshipFunny = '#form.RelationshipFunny#',
							RelationshipOutdoor = '#form.RelationshipOutdoor#',
							RelationshipGeek = '#form.RelationshipGeek#',
							RelationshipSex = '#form.RelationshipSex#',
							RelationshipBestThing = '#form.RelationshipBestThing#',
							RelationshipWorstThing = '#form.RelationshipWorstThing#',
							RelationshipWhoWouldEnjoy = '#form.RelationshipWhoWouldEnjoy#',
							RelationshipWhoShouldStayAway = '#form.RelationshipWhoShouldStayAway#'
				WHERE
							relationshipID = '#form.chip#'
			</cfquery>
			
			Relationship updated!<br>
	
		<cfelse>

			<CFQUERY name="values" datasource="#application.datasource#">
				SELECT		U.FirstName, U.LastName, R.*
				FROM		Relationships R, Users U
				WHERE		R.RelationshipID = #form.chip#
								AND
							U.ID = R.RelationshipSubjectUserID
			</cfquery>
			
			<script language="JavaScript">
				function submitformrel_update()
				{
				document.myformrel_update.submit();
				}
			</script>
			
			<cfoutput><form action="#request.cgiPath#" method="post" name="myformrel_update" id="myformrel_update" style="display:inline;">
			
				<TABLE border="0">
					<TR> 
						<TD>
							Title your rating:
						</TD>
						<TD> 
							<INPUT name="RelationshipTitle" value="#values.RelationshipTitle#" size="25" maxlength="100">
						</TD>
					</TR>			
					<script>
					$( function() {
					  $( "##datepicker" ).datepicker({ changeMonth: true, changeYear: true });
					} );
					</script>
					<TR> 
						<TD>
							Start Date:
						</TD>
						<TD>
							<input type="text" name="RelationshipStartDate" id="datepicker" value="#dateformat(values.RelationshipStartDate, "Mmm d, yyyy")#">
						</TD>
					</TR>		
					<script>
					$( function() {
					  $( "##datepicker1" ).datepicker({ changeMonth: true, changeYear: true });
					} );
					</script>
					<TR> 
						<TD>
							End Date:
						</TD>
						<TD>
							<input type="text" name="RelationshipEndDate" id="datepicker1" value="#dateformat(values.RelationshipEndDate, "Mmm d, yyyy")#">
						</TD>
					</TR>
					<TR> 
						<TD>
							Relationship Type:
						</TD>
						<CFQUERY name="get_relationship_types" datasource="#application.datasource#">
							SELECT      RelationshipTypeID, RelationshipTypeName
							FROM        tt_RelationshipTypes
							ORDER BY	RelationshipTypeSortOrder
						</CFQUERY>
						<TD>
							<select name="RelationshipTypeID">
								<option value="0">Please Select</option>
								<cfoutput query=#get_relationship_types#>
			  						<option value="#get_relationship_types.RelationshipTypeID#"<cfif values.RelationshipTypeID EQ get_relationship_types.RelationshipTypeID> Selected</cfif>>#RelationshipTypeName#</option>
								</cfoutput>
							</select>
						</TD>
					</TR>
					<TR> 
						<TD>
							Description:
						</TD>
						<TD>
							<TEXTAREA name="RelationshipDescription" value="#values.RelationshipDescription#" rows="4" cols="30" maxlength="100"><cfoutput>#values.RelationshipDescription#</cfoutput></textarea>
						</TD>
					</TR>			
					  <script>
					  $( function() {
					    $( "##slider" ).slider();
					  } );
					  </script>
					<TR> 
						<TD>
							Quick Rating: <span id="RelationshipQuickRating"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							 <br><input type="range" min="1" max="10" value="#values.RelationshipQuickRating#" class="slider" id="myRange"name="RelationshipQuickRating">
							</div>
							<script>
								var slider = document.getElementById("myRange");
								var output = document.getElementById("RelationshipQuickRating");
								output.innerHTML = slider.value;
								
								slider.oninput = function() {
								  output.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<CFQUERY name="get_States" datasource="#application.datasource#">
						SELECT      tt_StateID, Name
						FROM        tt_States
						WHERE		tt_StateCountryID = 1 <!--- only USA --->
						ORDER BY	tt_StateSortOrder
					</CFQUERY>
					<TR> 
						<TD>
							City & State:
						</TD>
						<TD><input type="text" name="RelationshipCity" value="#values.RelationshipCity#" size="25" maxlength="100">
							<select name="RelationshipStateID">
								<option value="0">Please Select</option>
								<cfoutput query=#get_States#>
			  						<option value="#tt_StateID#">#Name#</option>
								</cfoutput>
							</select>
						</TD>
					</TR>
					</TR>
					<TR> 
						<TD>
							Honesty Rating: <span id="RelationshipHonesty"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipHonesty#" class="slider" id="myRange1" name="RelationshipHonesty">
							</div>
							<script>
								var slider1 = document.getElementById("myRange1");
								var output1 = document.getElementById("RelationshipHonesty");
								output1.innerHTML = slider1.value;
								
								slider1.oninput = function() {
								  output1.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Loyalty Rating: <span id="RelationshipLoyalty"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipLoyalty#" class="slider" id="myRange2" name="RelationshipLoyalty">
							</div>
							<script>
								var slider2 = document.getElementById("myRange2");
								var output2 = document.getElementById("RelationshipLoyalty");
								output2.innerHTML = slider2.value;
								
								slider2.oninput = function() {
								  output2.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Frugality Rating: <span id="RelationshipFrugality"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipFrugality#" class="slider" id="myRange3" name="RelationshipFrugality">
							</div>
							<script>
								var slider3 = document.getElementById("myRange3");
								var output3 = document.getElementById("RelationshipFrugality");
								output3.innerHTML = slider3.value;
								
								slider3.oninput = function() {
								  output3.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Responsibility Rating: <span id="RelationshipResponsibility"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipResponsibility#" class="slider" id="myRange4" name="RelationshipResponsibility">
							</div>
							<script>
								var slider4 = document.getElementById("myRange4");
								var output4 = document.getElementById("RelationshipResponsibility");
								output4.innerHTML = slider4.value;
								
								slider4.oninput = function() {
								  output4.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Funniness Rating: <span id="RelationshipFunny"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipFunny#" class="slider" id="myRange5" name="RelationshipFunny">
							</div>
							<script>
								var slider5 = document.getElementById("myRange5");
								var output5 = document.getElementById("RelationshipFunny");
								output5.innerHTML = slider5.value;
								
								slider5.oninput = function() {
								  output5.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Outdoor Rating: <span id="RelationshipOutdoor"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipOutdoor#" class="slider" id="myRange6" name="RelationshipOutdoor">
							</div>
							<script>
								var slider6 = document.getElementById("myRange6");
								var output6 = document.getElementById("RelationshipOutdoor");
								output6.innerHTML = slider6.value;
								
								slider6.oninput = function() {
								  output6.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Geek Rating: <span id="RelationshipGeek"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipGeek#" class="slider" id="myRange7" name="RelationshipGeek">
							</div>
							<script>
								var slider7 = document.getElementById("myRange7");
								var output7 = document.getElementById("RelationshipGeek");
								output7.innerHTML = slider7.value;
								
								slider7.oninput = function() {
								  output7.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Sex Rating: <span id="RelationshipSex"></span>
						</TD>
						<TD>
							<div class="slidecontainer">
							  <input type="range" min="1" max="10" value="#values.RelationshipSex#" class="slider" id="myRange8" name="RelationshipSex">
							</div>
							<script>
								var slider8 = document.getElementById("myRange8");
								var output8 = document.getElementById("RelationshipSex");
								output8.innerHTML = slider8.value;
								
								slider8.oninput = function() {
								  output8.innerHTML = this.value;
								}
							</script>
						</TD>
					</TR>
					<TR> 
						<TD>
							Best thing about it:
						</TD>
						<TD><input type="text" name="RelationshipBestThing" value="#values.RelationshipBestThing#" size="25" maxlength="1000">
						</TD>
					</TR>
					</TR>
					<TR> 
						<TD>
							Worst thing about it:
						</TD>
						<TD><input type="text" name="RelationshipWorstThing" value="#values.RelationshipWorstThing#" size="25" maxlength="1000">
						</TD>
					</TR>
					</TR>
					<TR> 
						<TD>
							Who would be perfect for this person:
						</TD>
						<TD><input type="text" name="RelationshipWhoWouldEnjoy" value="#values.RelationshipWhoWouldEnjoy#" size="25" maxlength="500">
						</TD>
					</TR>
					</TR>
					<TR> 
						<TD>
							Who should stay away:
						</TD>
						<TD><input type="text" name="RelationshipWhoShouldStayAway" value="#values.RelationshipWhoShouldStayAway#" size="25" maxlength="500">
						</TD>
					</TR>
					</TR>
					</TABLE><br><br>
			
				<a href="javascript:submitformrel_update()">Update - - - ></a>
			
				<input type="hidden" name="chip" value="#form.chip#">
				<input type="hidden" name="rel_update_form_submitted" value="1">
				<input type="hidden" name="mode" value="rate_an_ex_edit">
				
			</form></cfoutput><br><br>
			
			<cfquery name="get_images" datasource="#application.datasource#">
				SELECT		lt_Relationships_UploadedImages_ImageName, lt_Relationships_UploadedImages_ID
				FROM		lt_Relationships_UploadedImages
				WHERE		lt_Relationships_UploadedImages_RelationshipID = #form.chip#
								AND
							lt_Relationships_UploadedImages_ImageIsActive=1
			</cfquery>
			
			<cfif get_images.recordcount gt 0>
			
				<cfoutput query="get_images">
					<img src="#application.httpsprefix#uploads/thumbs/#get_images.lt_Relationships_UploadedImages_ImageName#" border="0" alt=""><br>
					<script language="JavaScript">
						function submitformdelete#lt_Relationships_UploadedImages_ID#()
						{
						document.myformdelete#lt_Relationships_UploadedImages_ID#.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformdelete#lt_Relationships_UploadedImages_ID#" id="myformdelete#lt_Relationships_UploadedImages_ID#" style="display:inline;">
						
						<a href="javascript: submitformdelete#lt_Relationships_UploadedImages_ID#()">Delete image & thumbnail</a>
						
						<input type="hidden" name="mode" value="rel_del_image">
						<input type="hidden" name="chip" value="#get_images.lt_Relationships_UploadedImages_ID#">
					
					</form>
					<br><br>
				</cfoutput>
			
			<cfelse>
			
				No images for this relationship!<br><br>
			
			</cfif>
				
			<script language="JavaScript">
				function submitformupload()
				{
				document.myformupload.submit();
				}
			</script>
			
			<cfoutput><form action="#request.cgiPath#" method="post" name="myformupload" id="myformupload" style="display:inline;">
				
				<a href="javascript: submitformupload()">Upload an image!!</a><br><br>
				
				<input type="hidden" name="mode" value="rate_an_ex_upload_media">
				<input type="hidden" name="chip" value="#form.chip#">
			
			</form></cfoutput>
			
		</cfif>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>
	
<cfelseif mode eq "rel_del_image">

	<cfif request.userid NEQ 0>

		<cfquery name="del_image" datasource="#application.datasource#">
			UPDATE		lt_Relationships_UploadedImages
			SET			lt_Relationships_UploadedImages_ImageIsActive=0
			WHERE		lt_Relationships_UploadedImages_ID  = #form.chip#
		</cfquery>
				
		<cfquery name="get_rel_id" datasource="#application.datasource#">
			SELECT		lt_Relationships_UploadedImages_RelationshipID
			FROM		lt_Relationships_UploadedImages
			WHERE		lt_Relationships_UploadedImages_ID  = #form.chip#
		</cfquery>
				
		<cfoutput>	
			<form action="#request.cgiPath#" method="post" name="go_page" id="go_page">
				<input type="hidden" name="mode" value="rate_an_ex_edit">
				<input type="hidden" name="chip" value="#get_rel_id.lt_Relationships_UploadedImages_RelationshipID#">
			</form>
		</cfoutput>
		
		<script type="text/JavaScript" language="JavaScript">  
			document.go_page.submit();  
		</script>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "invite_friends">

	<cfif request.userid gt 0>

		<cfparam name="register_form_submitted" default="0">
		<cfparam name="messages" default="">
		
		<cfif register_form_submitted EQ 0>
			
			<cfloop index="looper" from="1" to="5" step="1">
				<cfoutput><cfparam name="values.UserInfo#looper#" default=""></cfoutput>
		    </cfloop>
		    
		<cfelseif register_form_submitted EQ 1>
			
			<cfloop index="looper" from="1" to="5" step="1">
				<cfoutput><cfparam name="form.UserInfo#looper#" default="">
				<cfset built_variable="values.UserInfo"&#looper#>
				<cfset #built_variable# = trim(#built_variable#)></cfoutput>
		    </cfloop>
			
		<cfelse>
			
			Problem!<cfabort>
		
		</cfif>
		
		<cfif register_form_submitted EQ 1>
			
			<cfloop index="looper" from="1" to="5" step="1"><cfoutput>
			
				<cfset builtmessagebody="Your friend "&check_user.FirstName&" wanted to tell you about Yelp For Exes! https://yelpforexes.com Check out the Exes they rated, and add some ratings of your own!!">
				
				<cfset messages="">
			
				<cfset built_variable="form.UserInfo"&#looper#>
			
				<cfmodule credential = "#evaluate(built_variable)#" template = "modules/parse_phnum.cfm">
				
				<!--- len(trim(parsed_phnum)) = <cfoutput>#len(trim(parsed_phnum))# (#trim(parsed_phnum)#)</cfoutput> --->
				
				<cfif len(parsed_phnum) lt 10 OR len(parsed_phnum) gt 11>
				
					<cfif REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", evaluate(built_variable)) EQ 0>
						<!--- number <cfoutput>#looper# </cfoutput> is invalid data (#parsed_phnum#)<br> --->
					<cfelse>
						<cfset email_to_invite = evaluate(built_variable)>
						<!--- #looper# is an email address  ---><cfoutput>sent email to #evaluate(built_variable)#</cfoutput><br>
						<cfmail to="#email_to_invite#"
				        from="admin@payfrit.com"
				        subject="Your friend wanted to tell you about Yelp For Exes!"
				        type="HTML"><cfoutput>
						#builtmessagebody#</cfoutput>
					</cfmail>
					</cfif>
					
				<cfelse>
				
					<!--- #looper# is a phone number  --->sent text to <cfoutput>#parsed_phnum#</cfoutput><br>
					<cfset isMessageSent = application.twilioObj.sendSMS(recipientNumber=#parsed_phnum#, messageBody = #builtmessagebody#)>
				
				</cfif>
				
			</cfoutput></cfloop>
			
			<br>Thanks for sharing Yelp For Exes!<br><br>
			
			Here is the message we sent:<br><br>
			
			<cfoutput>#builtmessagebody#</cfoutput>
		
		</cfif>
		
		<cfif register_form_submitted EQ 0>
		
		    <h3>Input the mobile number or email address of a person to share with:</h3>
				
			<cfoutput>
			
				<form action="#request.cgiPath#" method="post" name="register" id="register">
				
					<table border="0" cellspacing="2" cellpadding="2">
						<cfloop index="looper" from="1" to="5" step="1">
							<tr>
								<td align="right">Mobile/Email:</td>
								<cfset built_variable="values.UserInfo"&#looper#>
								<td><input type="text" name="UserInfo#looper#" id="UserInfo#looper#" size="25" maxlength="100" value="#evaluate(built_variable)#" tabindex="#looper#"></td>
							</tr>
						</cfloop>
						<tr>
							<td>&nbsp;</td>
							<td><input type="submit" tabindex="10" value="Invite" tabindex="#looper+1#"></td>
						</tr>
					</table>
					
					<input type="hidden" name="register_form_submitted" value="1">
					<input type="hidden" name="mode" value="invite_friends">
				
				</form>
								
			</cfoutput>
			
		</cfif>
			
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "rating_detail">

	<CFQUERY name="values" datasource="#application.datasource#">
		SELECT		U.FirstName, U.LastName, R.*
		FROM		Relationships R, Users U
		WHERE		R.RelationshipID = #form.chip#
						AND
					U.ID = R.RelationshipSubjectUserID
	</cfquery>
	
	<CFQUERY name="check_for_images" datasource="#application.datasource#">
		SELECT		I.lt_Relationships_UploadedImages_ImageName 
		FROM		lt_Relationships_UploadedImages I
		WHERE		I.lt_Relationships_UploadedImages_ImageIsActive = 1
						AND
					I.lt_Relationships_UploadedImages_RelationshipID = #form.chip#
		ORDER BY	I.lt_Relationships_UploadedImages_AddedOn
	</cfquery>		
	
	<script language="JavaScript">
		function submitformrel_update()
		{
		document.myformrel_update.submit();
		}
	</script>
	
	<cfoutput>
	
		<h2>#values.RelationshipTitle#</h2>
	
		<TABLE border="0">
			<TR> 
				<TD>
					Date:
				</TD>
				<TD>
					#dateformat(values.RelationshipStartDate, "Mmm d, yyyy")# - #dateformat(values.RelationshipEndDate, "Mmm d, yyyy")#
				</TD>
			</TR>
			<TR> 
				<TD>
					Relationship Type:
				</TD>
				<CFQUERY name="get_relationship_types" datasource="#application.datasource#">
					SELECT      RelationshipTypeName
					FROM        tt_RelationshipTypes
					WHERE		RelationshipTypeID = #values.RelationshipTypeID#
				</CFQUERY>
				<TD>
					#get_relationship_types.RelationshipTypeName#
				</TD>
			</TR>
			<TR> 
				<TD>
					Description:
				</TD>
				<TD>
					#values.RelationshipDescription#
				</TD>
			</TR>
			<TR> 
				<TD>
					Quick Rating:
				</TD>
				<TD>
					#values.RelationshipQuickRating#
				</TD>
			</TR>
			<CFQUERY name="get_State" datasource="#application.datasource#">
				SELECT      Name
				FROM        tt_States
				WHERE		ID = #values.RelationshipStateID#
			</CFQUERY>
			<TR> 
				<TD>
					City & State:
				</TD>
				<TD>#values.RelationshipCity#, #get_State.Name#
				</TD>
			</TR>
			</TR>
			<TR> 
				<TD>
					Honesty Rating:
				</TD>
				<TD>
					<cfif values.RelationshipHonesty LT 4><font color="Red"><cfelseif values.RelationshipHonesty lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipHonesty#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Loyalty Rating:
				</TD>
				<TD>
					<cfif values.RelationshipLoyalty LT 4><font color="Red"><cfelseif values.RelationshipLoyalty lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipLoyalty#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Frugality Rating:<br>
					(1 = cheap 10=$$$)
				</TD>
				<TD>
					<cfif values.RelationshipFrugality LT 4><font color="Red"><cfelseif values.RelationshipFrugality lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipFrugality#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Responsibility Rating:
				</TD>
				<TD>
					<cfif values.RelationshipResponsibility LT 4><font color="Red"><cfelseif values.RelationshipResponsibility lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipResponsibility#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Funniness Rating:
				</TD>
				<TD>
					<cfif values.RelationshipFunny LT 4><font color="Red"><cfelseif values.RelationshipFunny lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipFunny#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Outdoor Rating:
				</TD>
				<TD>
					<cfif values.RelationshipOutdoor LT 4><font color="Red"><cfelseif values.RelationshipOutdoor lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipOutdoor#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Geek Rating:
				</TD>
				<TD>
					<cfif values.RelationshipGeek LT 4><font color="Red"><cfelseif values.RelationshipGeek lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipGeek#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Sex Rating:
				</TD>
				<TD>
					<cfif values.RelationshipSex LT 4><font color="Red"><cfelseif values.RelationshipSex lt 8><font color="CEEC00"><cfelse><font color="Green"></cfif><h2>#values.RelationshipSex#</h2></font>
				</TD>
			</TR>
			<TR> 
				<TD>
					Best thing about it:
				</TD>
				<TD>#values.RelationshipBestThing#
				</TD>
			</TR>
			</TR>
			<TR> 
				<TD>
					Worst thing about it:
				</TD>
				<TD>#values.RelationshipWorstThing#
				</TD>
			</TR>
			</TR>
			<TR> 
				<TD>
					Would be perfect for:
				</TD>
				<TD>#values.RelationshipWhoWouldEnjoy#
				</TD>
			</TR>
			</TR>
			<TR> 
				<TD>
					Who should stay away:
				</TD>
				<TD>#values.RelationshipWhoShouldStayAway#
				</TD>
			</TR>
			</TR>
		</TABLE>

		Images:</br></br>
		
		<cfif check_for_images.recordcount GT 0>
			<cfloop query="check_for_images">
				<a href="#application.httpsprefix#uploads/#check_for_images.lt_Relationships_UploadedImages_ImageName#" target="_blank"><img src="#application.httpsprefix#uploads/thumbs/#check_for_images.lt_Relationships_UploadedImages_ImageName#" border="0" alt=""></a></br></br>
			</cfloop>
		</cfif>
		
	</cfoutput>
	
	<cfelseif mode eq "view_exes">

	<cfif request.UserID GT 0>
		
		<CFQUERY name="get_relationships" datasource="#application.datasource#">
			SELECT		U.ID, U.FirstName, U.LastName, R.RelationshipStartDate, R.RelationshipEndDate, R.RelationshipID, R.RelationshipTitle, R.RelationshipDescription
			FROM		Relationships R, Users U
			WHERE		U.ID = R.RelationshipAddedByUserID
			ORDER BY	R.RelationshipAddedOn
		</cfquery>
		
		<h3>Relationships with at least one image:</h3>
		
			<cfoutput query="get_relationships">
				
				<CFQUERY name="check_for_images" datasource="#application.datasource#">
					SELECT		lt_Relationships_UploadedImages_ImageName
					FROM		lt_Relationships_UploadedImages
					WHERE		lt_Relationships_UploadedImages_RelationshipID = #get_relationships.RelationshipID#
									AND
								lt_Relationships_UploadedImages_ImageIsActive = 1
					LIMIT 		1
				</cfquery>
			
				<cfif check_for_images.recordcount EQ 1>
				
					<table width="400" border="1" cellspacing="2" cellpadding="2">
						<tr>
							<td rowspan="2" width="125">
							
								<script language="JavaScript">
									function submitformdetail#get_relationships.RelationshipID#()
									{
									document.myformdetail#get_relationships.RelationshipID#.submit();
									}
								</script>
								
								<form action="#request.cgiPath#" method="post" name="myformdetail#get_relationships.RelationshipID#" id="myformdetail#get_relationships.RelationshipID#" style="display:inline;">
									
									<a href="javascript: submitformdetail#get_relationships.RelationshipID#()"><img src="#application.httpsprefix#uploads/thumbs/#check_for_images.lt_Relationships_UploadedImages_ImageName#" border="0" alt=""></a>
										
									<input type="hidden" name="chip" value="#get_relationships.RelationshipID#">
									<input type="hidden" name="mode" value="rating_detail">
								
								</form>
								
							</td>
							<td valign="top" align="center"><cfif len(RelationshipTitle) GT 25>#left(RelationshipTitle,20)#...<cfelse>#RelationshipTitle#</cfif></td>
							<td align="center">#dateformat(RelationshipStartDate, "Mmm D, yyyy")#<br>to<br>#dateformat(RelationshipEndDate, "Mmm D, yyyy")#</td>
						</tr>
						<tr>
							<td colspan="2"><cfif len(RelationshipDescription) GT 100>#left(RelationshipDescription,100)#...<cfelse>#RelationshipDescription#</cfif></td>
						</tr>
					</table>

				</cfif>
			
				<br>
		
			</cfoutput>
		
		<h3>All relationships:</h3>
		
		<CFQUERY name="get_relationships_all" datasource="#application.datasource#">
			SELECT		U.ID, U.FirstName, U.LastName, R.RelationshipStartDate, R.RelationshipEndDate, R.RelationshipID, R.RelationshipTitle, R.RelationshipDescription
			FROM		Relationships R, Users U
			WHERE		U.ID = R.RelationshipAddedByUserID
			ORDER BY	R.RelationshipAddedOn
		</cfquery>
		
		<cfoutput query="get_relationships_all">
				
			<CFQUERY name="check_for_images_all" datasource="#application.datasource#">
				SELECT		lt_Relationships_UploadedImages_ImageName
				FROM		lt_Relationships_UploadedImages
				WHERE		lt_Relationships_UploadedImages_RelationshipID = #get_relationships.RelationshipID#
								AND
							lt_Relationships_UploadedImages_ImageIsActive = 1
				LIMIT 		1
			</cfquery>
		
			<table width="400" border="1" cellspacing="2" cellpadding="2">
				<tr>
					<td rowspan="2" width="125">
					
						<script language="JavaScript">
							function submitformdetail1#get_relationships_all.RelationshipID#()
							{
							document.myformdetail1#get_relationships_all.RelationshipID#.submit();
							}
						</script>
						
						<form action="#request.cgiPath#" method="post" name="myformdetail1#get_relationships_all.RelationshipID#" id="myformdetail1#get_relationships_all.RelationshipID#" style="display:inline;">
							
							<a href="javascript: submitformdetail1#get_relationships_all.RelationshipID#()"><cfif check_for_images_all.recordcount EQ 1><img src="#application.httpsprefix#uploads/thumbs/#check_for_images_all.lt_Relationships_UploadedImages_ImageName#" border="0" alt=""><cfelse>click</cfif></a>
															
							<input type="hidden" name="chip" value="#get_relationships_all.RelationshipID#">
							<input type="hidden" name="mode" value="rating_detail">
						
						</form>
						
					</td>
					<td valign="top" align="center"><cfif len(RelationshipTitle) GT 25>#left(RelationshipTitle,20)#...<cfelse>#RelationshipTitle#</cfif></td>
					<td align="center">#dateformat(RelationshipStartDate, "Mmm D, yyyy")#<br>to<br>#dateformat(RelationshipEndDate, "Mmm D, yyyy")#</td>
				</tr>
				<tr>
					<td colspan="2"><cfif len(RelationshipDescription) GT 100>#left(RelationshipDescription,100)#...<cfelse>#RelationshipDescription#</cfif></td>
				</tr>
			</table>

		
			<br>
		
		</cfoutput>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>
	
<cfelseif mode eq "account">

	<cfif request.UserID GT 0>

		<cfparam name="submitted" default="0">
		<cfparam name="messages" default="">
	
		<cfif submitted EQ 0>
	
			<CFQUERY name="values" datasource="#application.datasource#">
				SELECT      *
				FROM        Users
				WHERE		ID = #request.UserID#
			</CFQUERY>
		    
		<cfelseif submitted EQ 1>
			
		    <cfset values.FirstName = form.FirstName>
		    <cfset values.LastName = form.LastName>
		    <cfset values.UserAddress1 = form.UserAddress1>
		    <cfset values.UserAddress2 = form.UserAddress2>
		    <cfset values.UserCity = form.UserCity>
		    <cfset values.UserStateID = form.UserStateID>
		    <cfset values.UserZIPCode = form.UserZIPCode>
		    
		<cfelse>
			
			Problem!<cfabort>
		
		</cfif>
		
		<cfif submitted EQ 1>
		
		 	<cfif trim(values.FirstName) EQ "">
				<cfset messages = listappend(messages, "First Name is required")>
				<cfset submitted = 0>
			</cfif>
		
		 	<cfif trim(values.LastName) EQ "">
				<cfset messages = listappend(messages, "Last Name is required")>
				<cfset submitted = 0>
			</cfif>
		
		 	<cfif Len(trim(values.UserAddress1)) LT 2>
				<cfset messages = listappend(messages, "Address is required")>
				<cfset submitted = 0>
			</cfif>
		
		 	<cfif Len(trim(values.UserCity)) LT 2>
				<cfset messages = listappend(messages, "City is required")>
				<cfset submitted = 0>
			</cfif>
		
		 	<cfif UserStateID EQ 0>
				<cfset messages = listappend(messages, "Please select your state")>
				<cfset submitted = 0>
			</cfif>
		
		</cfif>
		
		<cfif messages gt 0>
		
			<CFLOOP INDEX="ListElement" LIST=#messages#> 
			<CFOUTPUT><div align="center"><font color="FF0000"><strong>#ListElement#</strong></font></div></CFOUTPUT>
			</CFLOOP><br><br>
			
		</cfif>
		
		<cfif submitted EQ 0>
			
				Edit account<br><br>
				
				<cfoutput><form action="#request.cgiPath#" method="post"></cfoutput>
				
				<TABLE border="0">
					<TR> 
						<TD>
							First Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="FirstName" value="#values.FirstName#" size="15" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Last Name:
						</TD>
						<TD> 
							<cfoutput><INPUT name="LastName" value="#values.LastName#" size="25" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Address Line 1:
						</TD>
						<TD>
							<cfoutput><INPUT name="UserAddress1" value="#values.UserAddress1#" size="30" maxlength="100"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							Address Line 2 (or unit, apt, etc.):
						</TD>
						<TD>
							<cfoutput><INPUT name="UserAddress2" value="#values.UserAddress2#" size="30" maxlength="100"></cfoutput>
						</TD>
					</TR>
					<TR> 
						<TD>
							City:
						</TD>
						<TD> 
							<cfoutput><INPUT name="UserCity" value="#values.UserCity#" size="25" maxlength="50"></cfoutput>
						</TD>
					</TR>
					<CFQUERY name="get_States" datasource="#application.datasource#">
						SELECT      tt_StateID, Name
						FROM        tt_States
						WHERE		tt_StateCountryID = 1 <!--- only USA --->
						ORDER BY	tt_StateSortOrder
					</CFQUERY>
					<TR> 
						<TD>
							Select State:
						</TD>
						<TD>
							<select name="UserStateID">
								<option value="0">Please Select</option>
								<cfoutput query=#get_States#>
			  						<option value="#tt_StateID#" <cfif #values.UserStateID# EQ #get_States.tt_StateID#>Selected</cfif>>#Name#</option>
								</cfoutput>
							</select>
						</TD>
					</TR>
					<TR> 
						<TD>
							ZIP Code:
						</TD>
						<TD> 
							<cfoutput><INPUT name="UserZIPCode" value="#values.UserZIPCode#" size="6"></cfoutput>
						</TD>
					</TR>
			    </TABLE>
				
				<input type="hidden" name="submitted" value="1">
				<input type="hidden" name="mode" value="account">
				
				<input TYPE="SUBMIT" Value="Update Info"  name=SUBMIT>
					
			</form>
		
		<cfelse>
			
			<CFQUERY name="update_user" datasource="#application.datasource#">
				UPDATE	Users
				SET		FirstName =  '#values.FirstName#',
						LastName =  '#values.LastName#',
						UserAddress1 =  '#values.UserAddress1#',
						UserAddress2 =  '#values.UserAddress2#',
						UserCity =  '#values.UserCity#',
						UserStateID =  '#values.UserStateID#',
						UserZIPCode =  '#values.UserZIPCode#'
				WHERE	UserID = #request.UserID#
			</CFQUERY>
		
			User info updated!<br><br>
		
		</cfif>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>
	
<cfelseif mode eq "my_exes">

	<cfif request.UserID GT 0>

		<CFQUERY name="get_relationships" datasource="#application.datasource#">
			SELECT		U.FirstName, U.LastName, R.RelationshipStartDate, R.RelationshipEndDate, R.RelationshipID
			FROM		Relationships R, Users U
			WHERE		R.RelationshipAddedByUserID = #request.UserID#
							AND
						U.ID = R.RelationshipSubjectUserID
		</cfquery>
		
		<table>
			<tr>
				<td>Name</td>
				<td>From</td>
				<td>To</td>
			</tr>
		<cfoutput query="get_relationships">
			<tr>
				<td>
					<script language="JavaScript">
						function submitformeditrel#get_relationships.RelationshipID#()
						{
						document.myformeditrel#get_relationships.RelationshipID#.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformeditrel#get_relationships.RelationshipID#" id="myformeditrel#get_relationships.RelationshipID#" style="display:inline;">
						
						<a href="javascript: submitformeditrel#get_relationships.RelationshipID#()">#LastName#, #FirstName#</a>
						
						<input type="hidden" name="mode" value="rate_an_ex_edit">
						<input type="hidden" name="chip" value="#get_relationships.RelationshipID#">
					
					</form>
				</td>
				<td>#dateformat(RelationshipStartDate, "m/yy")#</td>
				<td>#dateformat(RelationshipEndDate, "m/yy")#</td>
				<td>					
					<script language="JavaScript">
						function submitformaddpic#get_relationships.RelationshipID#()
						{
						document.myformaddpic#get_relationships.RelationshipID#.submit();
						}
					</script>
					
					<form action="#request.cgiPath#" method="post" name="myformaddpic#get_relationships.RelationshipID#" id="myformaddpic#get_relationships.RelationshipID#" style="display:inline;">
						
						<a href="javascript: submitformaddpic#get_relationships.RelationshipID#()">Add pic</a>
						
						<input type="hidden" name="mode" value="rate_an_ex_upload_media">
						<input type="hidden" name="chip" value="#get_relationships.RelationshipID#">
					
					</form>
				</td>
			</tr>
		</cfoutput>
		</table>
	
	<cfelse>
		
		Please login!<br>
		
	</cfif>

<cfelseif mode eq "logout">

	<cfset request.UserID = 0>
	<cfset session.UserID = 0>
	
	<cflocation url="index.cfm" addtoken="No">
	
<cfelseif mode eq "forgot">

    <script language="JavaScript">
        function submitformforgot1()
        {
        document.myformforgot1.submit();
        }
    </script>
    
    <cfoutput><form action="#request.cgiPath#" method="post" name="myformforgot1" id="myformforgot1" style="display:inline;">

        Please input either your email address or cell phone:<br><br>
        
        <input type="text" name="credential" size="15">
    
        <a href="javascript: submitformforgot1()">Submit</a>
        
        <input type="hidden" name="mode" value="forgot1">
    
    </form></cfoutput><br>

<cfelseif mode eq "forgot1">

    <cfoutput><cfmodule credential = "#form.credential#" template = "modules/parse_phnum.cfm"></cfoutput>

    <cfif REFindNocase("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.(([a-z]{2,3})|(aero|coop|info|museum|name))$", form.credential) EQ 0 AND len(parsed_phnum) neq 10>
		<cfset messages = listappend(messages, "invalid info entered - please input only an email address or mobile nuber.")>
	</cfif>

    <cfquery name="Get_user" datasource="#application.datasource#">
        SELECT	    EmailAddress, UserMobileNumber, UUID
        FROM	    Users
        WHERE       (EmailAddress = '#form.credential#'
                        OR 
                    UserMobileNumber =  '#parsed_phnum#')
                        AND 
                    IsEmailVerified = 1
                        AND 
                    UserIsMobileVerified = 1
                    
    </cfquery>

    <cfif get_user.recordcount EQ 1>

        <cfset link_to_build = "https://"&cgi.server_name&application.wwwrootprefix&"reset.cfm?UUID="&Get_user.UUID>

        <cfset isMessageSent = application.twilioObj.sendSMS(recipientNumber=#Get_user.UserMobileNumber#, messageBody = "Password change requested for Yelp For Exes, please visit #link_to_build#")>

        <cfmail to="admin@payfrit.com, #get_user.EmailAddress#"
        from="admin@payfrit.com"
        subject="change your Yelp For Exes password"
        type="HTML"><cfoutput>
		someone requested a password change for your Yelp For Exes account. Click here:<br><br>
        #link_to_build#<br>
        <br>
        if you didn't request this action, please either ignore it or <a href='admin@yelpforexes.com'>email</a> us and we will figure out what happened.<br><br>
        regards,<br>
        <br>
        Yelp For Exes<br></cfoutput></cfmail>

        If there is registered Yelp For Exes account with that information, you will receive information on how to reset your password.

    <cfelse>
        User not found!<br><br>
    </cfif>

<cfelseif mode eq "forgot3">

    <cfif form.new_password eq form.new_password_confirm>

        <cfquery name="update_password" datasource="#application.datasource#">
           UPDATE	    Users
           SET          Password = '#hash(new_password)#'
           WHERE        UUID = '#form.UUID#'
                            AND 
                        IsEmailVerified = 1
                            AND 
                        UserIsMobileVerified = 1
        </cfquery>

        Password updated!<br><br>

    <cfelse>

       <script language="JavaScript">
            function submitformforgot1()
            {
            document.myformforgot1.submit();
            }
        </script>
    
      <cfoutput><form action="#request.cgiPath#" method="post" name="myformforgot1" id="myformforgot1" style="display:inline;">

            Values did not match, please try again!<br><br>
            
            Please input your new password:<br><br>
            
            <input type="text" name="new_password" size="15"><br><br>
        
            Please type it again:<br><br>
            
            <input type="text" name="new_password_confirm" size="15"><br><br>
        
            <a href="javascript: submitformforgot1()">Submit</a>
            
            <input type="hidden" name="mode" value="forgot3">
            <input type="hidden" name="UUID" value="#form.UUID#">
        
        </form></cfoutput><br>

    </cfif>

<cfelseif mode EQ "confirm">

	<cfquery name="check_valid" datasource="#application.datasource#">
	    SELECT	    ID, IsEmailVerified, EmailAddress, MobileVerifyCode
	    FROM	    Users
	    WHERE       UUID = '#form.UUID#'
	                    AND 
	                MobileVerifyCode = '#form.OTP#'
	                    AND 
	                UserIsMobileVerified = 0
	                    AND 
	                IsEmailVerified = 0
	</cfquery>
	
	<cfif check_valid.recordcount EQ 1>
	
	    <cfquery name="confirm_mobile" datasource="#application.datasource#">
	        UPDATE	    Users
	        SET         UserIsMobileVerified = 1
	        WHERE       UserID = #check_valid.UserID#
	    </cfquery>
	
	    OTP verified, please check your email <cfoutput>#check_valid.EmailAddress#</cfoutput><br><br>
	
	    There's a link there for you to click, then you can login to Yelp For Exes!<BR>
	
	<cfelse>    
	
	    <cfquery name="check_valid_with_email_confirmed" datasource="#application.datasource#">
	        SELECT	    ID, IsEmailVerified, EmailAddress
	        FROM	    Users
	        WHERE       UUID = '#form.UUID#'
	                        AND 
	                     MobileVerifyCode = '#form.OTP#'
	                        AND 
	                    UserIsMobileVerified = 0
	                        AND 
	                    IsEmailVerified = 1
	    </cfquery>
	
	    <cfif check_valid_with_email_confirmed.recordcount eq 1>
	
	        <cfquery name="confirm_mobile" datasource="#application.datasource#">
	            UPDATE	    Users
	            SET         UserIsMobileVerified = 1
	            WHERE       UserID = #check_valid_with_email_confirmed.UserID#
	        </cfquery>
	
	        <!--- might as well log them in since they confirmed successfully, probably a bad idea but not worried about it for now --->
	        
	        <!--- Update the session variables and request variables --->
	        <cflock timeout="60" throwontimeout="Yes" type="EXCLUSIVE" scope="SESSION">
	            <cfset session.UserID = #check_valid_with_email_confirmed.UserID#>
	            <!--- Re-duplicate them  --->
	            <cfset request.UserID = Duplicate(session.UserID)>
	        </cflock>
	                            
			<cfmail to="admin@payfrit.com, #get_user.EmailAddress#"
		        from="admin@payfrit.com"
		        subject="Login to Yelp For Exes!"
		        type="HTML"><cfoutput>
			You're now fully verified and ready to use Yelp For Exes!<br><br>
			
			it's time to go <a href="index.cfm">rate an ex!</a></cfoutput></cfmail>
	
	        <cflocation url="index.cfm?userstatus=new">
	
	    <cfelse>
	
	        <cfquery name="check_valid" datasource="#application.datasource#">
	            SELECT	    ID, IsEmailVerified
	            FROM	    Users
	            WHERE       UUID = '#form.UUID#'
	                            AND 
	                        UserIsMobileVerified = 0
	        </cfquery>
	    
	    </cfif>
	    
	</cfif>

</cfif>
