<cfcomponent displayname="Locations Functions" hint="I Return Locations Information" output="false">

   <cffunction name="init" displayname="Initialize Component" access="public" returntype="Locations" hint="I initialize and return the Locations object.">
		<cfreturn this>
	</cffunction>
    
   	<cffunction name="get_locations"  returntype="any" access="public" output="false" >
	    <cfargument name="Loc_ID" required="no" hint="Loc_ID" default="0">
	    <cfargument name="Agy_ID" required="no" hint="Agy_ID" default ="0">
		  <cfquery name = "get_loc" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_lookup#.lu_locations
				 WHERE Loc_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Loc_ID#">
				 <cfif arguments.Agy_ID neq 0>
				    AND Agy_ID = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Agy_ID#"> 
				 </cfif>
		  </cfquery>
		 <cfreturn  get_loc>
	</cffunction>

    <cffunction name="check_loc_email" access="remote"  httpmethod="GET" returnformat="plain" >
	    <cfargument name="email" required="yes" hint="email">
	    <cfargument name="phone" required="yes" hint="Phonenumber">
        <cfargument name="loc_id" required="no" hint="loc_id" default="0">

		  <cfquery name = "get_email" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_lookup#.lu_locations
				 WHERE Agy_Mailing =  <cfqueryparam VALUE="#arguments.email#"  cfsqltype="cf_sql_varchar">
				 AND Loc_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Loc_ID#">
		  </cfquery>
		  <cfquery name = "get_phone" datasource="#Application.DataSrc#">
				SELECT * FROM #Request.prefix_db_lookup#.lu_locations 
				WHERE Agy_Phone = <cfqueryparam VALUE="#arguments.phone#"  cfsqltype="cf_sql_varchar">
				AND Loc_ID != <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.Loc_ID#">
		  </cfquery>
		  <cfif get_email.recordcount gt 0>
			 <cfreturn 'email'>
		  <cfelseif get_phone.recordcount gt 0>
			 <cfreturn 'phone'>
		  <cfelse>
		     <cfreturn 'Success'>
		 </cfif>
	</cffunction>

            
</cfcomponent>