<!--#include virtual="/includes/topofpage.asp"-->
<%
' Destination Parent Creation

Page = "30"

Dim Conn
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open Application("conn_string")

Dim Edit
If LCase(Request("Edit")) = "true" Then Edit = True

If Edit=True And Request("Dest_ID") = "" Then 
	SQL = "Get_Destination @Dest_ID='" & Session("Admin_Dest_ID") & "'"
	Set RSDest = Conn.Execute(SQL)

	If Not RSDest.EOF Then
		Dest_ID = RSDest("Dest_ID")
		Name = RSDest("Name")
		Dest_Type_ID = RSDest("Dest_Type_ID")
		Latitude = RSDest("Latitude")
		Longitude = RSDest("Longitude")
		Radius = RSDest("Radius")
		Featured = RSDest("Featured")
		Status = RSDest("Status")
	End If

Else
	Dest_ID = Request("Dest_ID")
	Name = Request("Name")
	Dest_Type_ID = Request("Dest_Type_ID")
	Latitude = Request("Latitude")
	Longitude = Request("Longitude")
	Radius = Request("Radius")
	Featured = Request("Featured")
	Status = Request("Status")
End If


If (UCase(Request.ServerVariables("REQUEST_METHOD")) = "POST" And Request.Form("page") = Page And (Request("cont") = "1" Or Request("cont") = "2")) Then

	'@Dest_ID int = Null,
	'@Dest_Name varchar(150),
	'@Dest_Type_ID int,
	'@Latitude real,
	'@Longitude real,
	'@Radius float,
	'@Target bit,
	'@Featured bit,
	'@Status tinyint
	'= Replace(Request(""), "'", "''")
	
	Dest_ID = Replace(Request("Dest_ID"), "'", "''")
	Name = Replace(Request("Name"), "'", "''")
	Dest_Type_ID = Replace(Request("Dest_Type_ID"), "'", "''")
	Latitude = Replace(Request("Latitude"), "'", "''")
	Longitude = Replace(Request("Longitude"), "'", "''")
	Radius = Replace(Request("Radius"), "'", "''")
	Featured = Replace(Request("Featured"), "'", "''")
	Status = Replace(Request("Status"), "'", "''")
	
	If LCase(Trim(Featured)) = "1" Then 
		Featured="1" 
	Else 
		Featured="0" 
	End If
	
	If LCase(Trim(Status)) = "1" Then 
		Status="1" 
	Else 
		Status="0" 
	End If

	SQL = "Update_Destination "
	If Not Trim(Dest_ID) = "" Then SQL = SQL & " @Dest_ID = '" & Dest_ID & "',"
	SQL = SQL & " @Target = '1', @Status='" & Status & "', @Name = '" & Name & "', @Dest_Type_ID = '" & Dest_Type_ID & "', "
	SQL = SQL & " @Latitude = '" & Latitude & "', @Longitude = '" & Longitude & "', @Radius = '" & Radius & "', @Featured=" & Featured & ","
	SQL = SQL & " @Realm_ID = '" & Session("Admin_Realm") & "'"
	
	Response.Write(SQL)

	If Trim(Name) = "" Then 
		Response.Write ("Please select a name for your destination.<br>")
		Response.Write ("<a href='javascript:history.back()'>Click here to Return</a><br>")
		Response.End
	Else
		Set Dest = Conn.Execute(SQL)
		Session("Admin_Dest_ID") = Dest("Dest_ID")
		Response.Redirect ("destination-mapping.asp")
	End If

Else

	Dim State, Country

	If Trim(Request("State")) <> "" Then
		State = Request("State")
	Else
		State = "FL"
	End If

	If Trim(Request("Country")) <> "" Then
		Country = Request("Country")
	Else
		Country="US"
	End If

	City = Request("City")

	If Request("cont") = "3" Then
		If Trim(Request("City")) <> "" And Trim(Request("State")) <> ""  And Trim(Request("Country")) <> "" Then
			Dim LatLon
			Set LatLon = Conn.Execute("getlatlon_ppl @State='" & State & "', @City='" & City & "'")

			If LatLon.EOF Then
				Set RSCity = Conn.Execute("Get_Combo_City @Country_Abbr = '" & Country & "', @State_Abbr = '" & State & "', @Child_City = '" & City & "', @Realm_ID='" & Session("Admin_Realm") & "'")
				If Not RSCity.EOF Then
					City = RSCity("Parent_City")
					Set LatLon = Conn.Execute("getlatlon_ppl @State='" & State & "', @City='" & City & "'")
				End If
			End If
			
			If Not LatLon.EOF Then
				Latitude = LatLon("Lat")
				Longitude = LatLon("Lon")
			End If
		End If
	End If

End If

	SQL = "Get_Destination @Dest_ID='" & Session("Admin_Dest_ID") & "', @Realm_ID='" & Session("Admin_Realm") & "'"
	Set Dest = Conn.Execute(SQL)

%>
	<html>
<STYLE>
BODY {SCROLLBAR-FACE-COLOR: #5e5ebe; SCROLLBAR-HIGHLIGHT-COLOR: #5e5ebe; SCROLLBAR-SHADOW-COLOR: #5e5ebe; SCROLLBAR-3DLIGHT-COLOR: #5e5ebe; SCROLLBAR-ARROW-COLOR:  #6666CC; SCROLLBAR-TRACK-COLOR: #E3E3E3; SCROLLBAR-DARKSHADOW-COLOR: #666666; }
</STYLE>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function Sub_Form(cont) {
  form1.cont.value=cont
  form1.submit();
}

//-->
</script>
<link rel="stylesheet" href="../Style-sheets/headline.css" type="text/css">
<SCRIPT ID=clientEventHandlersJS LANGUAGE=javascript>
<!--

function Country_onchange()
{
  form1.action = ""
  form1.cont.value='5'
  form1.submit();
}

function State_onchange()
{
  form1.action = ""
  form1.cont.value='4'
  form1.submit();
}

function City_onchange()
{
  form1.action = ""
  form1.cont.value='3'
  form1.submit();
}

function Sub_Form (cont)
{

var errMsg='';

//if (document.form1.City.value=='') {errMsg+='Please Specify a City\n';}
//if (document.form1.State.value=='') {errMsg+='Please Specify a State\n';}
//if (document.form1.Country.value=='') {errMsg+='Please Specify a Country\n';}
//if (document.form1.Package_Name.value=='') {errMsg+='Please Specify a Package Name\n';}
//if (document.form1.Package_Type_ID.value=='') {errMsg+='Please Specify a Package Type\n';}
//if (document.form1.Package_Duration_ID.value=='') {errMsg+='Please Specify a Package Duration\n';}
//if (document.form1.Num_Adults.value=='') {errMsg+='Please Specify a Number of Adults\n';}
//if (document.form1.Num_Children.value=='') {errMsg+='Please Specify a Number of Children\n';}
//if (document.form1.Lodging.value=='' && document.form1.Tickets.value=='' && document.form1.Food_Bev.value=='' && document.form1.Transport.value=='') {errMsg+='Please sekect an item to work with.\n';}

if (errMsg) alert(errMsg);
else {
  form1.action = ""
  form1.cont.value=cont
  form1.submit();
}
}

//-->
</SCRIPT>
</head>

<body bgcolor="#FFFFFF" text="#000000" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" onLoad="MM_preloadImages('images/icon-return-to-main-2.gif','images/icon-submit-changes-2.gif','images/icon-continue-wizard-2.gif')">
<form name="form1" method="post" action="">
<input type="hidden" name="page" value="<%=Page%>">
<input type="hidden" name="cont" value="">
<input type="hidden" name="Dest_ID" value="<%=Dest_ID%>">
<input type="hidden" name="Edit" value="<%=Edit%>">

  <table width="525" border="0" cellspacing="0" cellpadding="2" align="center">
  <tr bgcolor="#FFFFFF"> 
    <td width="467">&nbsp;</td>
    <td align="right" width="58">&nbsp;</td>
  </tr>
  <tr bgcolor="#5e5ebe"> 
      <td width="467" align="center" class="headline-ffffff">Destination Target Management</td>
    <td bgcolor="#5e5ebe" align="right" width="58"><a href="javascript:;" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','images/icon-return-to-main-2.gif',1)" onClick="MM_goToURL('this','default-destinations.asp');return document.MM_returnValue"><img src="images/icon-return-to-main.gif" width="75" height="17" usemap="#returntomain" border="0" name="Image1"></a></td>
  </tr>
  <tr> 
    <td width="467"><%If Not Dest.EOF Then Response.Write(Dest("Name"))%></td>
    <td width="58">&nbsp;</td>
  </tr>
</table>
  <table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr> 
      <td width="217">&nbsp;</td>
      <td width="194">&nbsp;</td>
      <td width="89">&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Destination Name:</td>
      <td><input type="text" name="Name" size="30" value="<%=Name%>"></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Destination Type:</td>
      <td><select name="Dest_Type_ID" id="Dest_Type_ID">
<%
   Dim RSDestT
   Set RSDestT = Conn.Execute("Get_Destination_Types")

   If Not RSDestT.EOF Then
	Do Until RSDestT.EOF
       Response.Write "<option value=""" & RSDestT("Dest_Type_ID") & """"
       If Int(RSDestT("Dest_Type_ID")) = Int(Dest_Type_ID) Then Response.Write (" selected")
       Response.Write ">" & RSDestT("Dest_Type_Name") & "</option>" & Chr(13)
       RSDestT.MoveNext
    Loop
   Else
		Response.Write "<option value="""">No destination types defined</option>"
   End If 
%>        
		</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Center Country:</td>
      <td><select name="Country" onchange="return Country_onchange()" id="Country" Language="JAVASCRIPT">
      <option value="">Select a Country</option>
<%
	Dim RSCountry
	Set RSCountry = Conn.Execute("Select * from Countries Where Not Country_Name Like '%Available%';")

   If Not RSCountry.EOF Then
	Do Until RSCountry.EOF
       Response.Write "<option value=""" & RSCountry("Country_Abbr") & """"
       If RSCountry("Country_Abbr") = Country Then Response.Write " selected"
       Response.Write ">" & RSCountry("Country_Name") & "</option>" & Chr(13)
       RSCountry.MoveNext
    Loop
   End If 
%>        
		</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Center State:</td>
      <td><select name="State" onchange="return State_onchange()" id="State" Language="JAVASCRIPT">
      <option value="">Select a State</option>
<%
	Dim RSState
   Set RSState = Conn.Execute("Select * from States S Inner Join Countries C On S.Country_ID = C.Country_ID Where C.Country_Abbr='" & Country & "';")

   If Not RSState.EOF Then
	Do Until RSState.EOF
       Response.Write "<option value=""" & RSState("State_Abbr") & """"
       If RSState("State_Abbr") = State Then Response.Write " selected"
       Response.Write ">" & RSState("State_Name") & "</option>" & Chr(13)
       RSState.MoveNext
    Loop
   End If 
%>        
		</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Center City:</td>
      <td><select name="City" onchange="return City_onchange()" id="City" Language="JAVASCRIPT">
      <option value="">Select a City</option>
<%
	Dim RSCities
   Set RSCities = Conn.Execute("Get_Cities @State_Abbr='" & State & "', @Country_Abbr = '" & Country & "', @Realm_ID = '%'")

   If Not RSCities.EOF Then
	Do Until RSCities.EOF
       Response.Write "<option value=""" & RSCities("City") & """"
       If RSCities("City") = Request("City") Then Response.Write " selected"
       Response.Write ">" & RSCities("City") & "</option>" & Chr(13)
       RSCities.MoveNext
    Loop
   End If       
%>        
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Center Latitude:</td>
      <td><input type="text" name="Latitude" size="5" value="<%=Latitude%>"></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Center Longitude:</td>
      <td><input type="text" name="Longitude" size="5" value="<%=Longitude%>"></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Radius (in miles):</td>
      <td><input type="text" name="Radius" size="5" value="<%=Radius%>"></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Featured Target:</td>
      <td class="manage-menu"><input type="checkbox" name="Featured" value="1" <% If Trim(Featured) = "1" Or Featured=True Then Response.Write " checked"%>> Yes</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td class="manage-menu-bold">Status:</td>
      <td class="manage-menu"><input type="checkbox" name="Status" value="1" <% If Trim(Status) = "0" Or (Not Trim(Status) = "" And Not Trim(Status) = "1") Then 
      'do nothing
      Else
		Response.Write " checked"
      End If %>> Active</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
<table width="525" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr bgcolor="#5e5ebe"> 
    <td align="right" width="49%" height="18"><a href="javascript:Sub_Form('1');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('submitchanges','','images/icon-submit-changes-2.gif',1)"><img src="images/icon-submit-changes.gif" width="200" height="15" name="submitchanges" border="0"></a></td>
    <td width="51%" height="18"><a href="javascript:Sub_Form('2');" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image2','','images/icon-continue-wizard-2.gif',1)"><img src="images/icon-continue-wizard.gif" width="150" height="15" usemap="#continue" border="0" name="Image2"></a></td>
  </tr>
  <tr> 
    <td width="49%">&nbsp;</td>
    <td width="51%">&nbsp;</td>
  </tr>
</table></form>
</body>
</html>
