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

Dim Page
Page="DestGeo"
Cont = Request("Cont")

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

	If Request("Admin_Dest_ID") <> "" Then
		Session("Admin_Dest_ID") = Request("Admin_Dest_ID")
	End If
	
	If Session("Admin_Dest_ID") = "" Then
		Session("Admin_Dest_ID") = "0"
	End If
	
	Dest_ID = Session("Admin_Dest_ID")

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

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

	SQL = "Delete_Dest_Geography @Dest_ID = '" & Dest_ID & "', @Realm_ID ='" & Session("Admin_Realm") & "'"
	Conn.Execute(SQL)
	
	For each item in Request.Form("City")

		tmpArr = Split(item, "|")
		tCountry = tmpArr(0)
		tState = tmpArr(1)
		tCity = tmpArr(2)

		SQL = "Add_Dest_Geography @Dest_ID= '" & Dest_ID & "', @Realm_ID= '" & Session("Admin_Realm") & "', @City= '" & tCity & "', @State= '" & tState & "', @Country = '" & tCountry & "'"
		Conn.Execute(SQL)
		Got_it = 1
	Next

	For each item in Request.Form("County")
		tmpArr = Split(item, "|")
		tCountry = tmpArr(0)
		tState = tmpArr(1)
		tCounty = tmpArr(2)

		SQL = "Add_Dest_Geography @Dest_ID= '" & Dest_ID & "', @Realm_ID= '" & Session("Admin_Realm") & "', @County= '" & tCounty & "', @State= '" & tState & "', @Country = '" & tCountry & "'"
		Conn.Execute(SQL)
		Got_it = 1
	Next

	If Not Got_it = 1 Then
		For each item in Request.Form("State")
			tmpArr = Split(item, "|")
			tCountry = tmpArr(0)
			tState = tmpArr(1)

			SQL = "Add_Dest_Geography @Dest_ID= '" & Dest_ID & "', @Realm_ID= '" & Session("Admin_Realm") & "', @State= '" & tState & "', @Country = '" & tCountry & "'"
			Conn.Execute(SQL)
			Got_it = 2
		Next

		If Not Got_it = 2 Then
			For each item in Request.Form("Country")
				SQL = "Add_Dest_Geography @Dest_ID= '" & Dest_ID & "', @Realm_ID= '" & Session("Admin_Realm") & "', @Country = '" & item & "'"
				Conn.Execute(SQL)
			Next 
		End If
	End If

	If Request.Form("cont") = "1" Then Response.Redirect (Session("default_page"))
	
	Response.Redirect ("destination-content.asp")	

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

	If Edit = True Then
	End If

End If

		Dim RSCounties
		Dim RSCities

		Dim RSState
		Dim RSCountry
	
		SQL = "Get_Dest_Geography @Dest_ID='" & Dest_ID & "', @Realm_ID='" & Session("Admin_Realm") & "', @Return='" & 0 & "', @No_ID='1'"
		Set RS = Server.CreateObject("ADODB.RecordSet")
		'Response.Write SQL
		Set RS = Conn.Execute(SQL)
		If Not RS.EOF Then
			Arr = RS.GetRows()
			Cols = Ubound(Arr,1) ' Getting total number of Cols in Array (-1)  Array starts at xx(0,0,...)
			Rows = Ubound(Arr,2) ' Getting total number of Rows in Array (-1)  Array starts at xx(0,0,...)
			ReDim sEdit(Rows)
			For i = 0 to Rows 
				rEdit = ""
				For j = 0 to Cols 
					rEdit = rEdit & Trim(Arr(j,i))  & "|"
					'Response.Write rEdit & "<br>"
				Next
				'Response.Write Mid(rEdit, 1, len(rEdit) -1) & ""
				sEdit(i) = Mid(rEdit, 1, len(rEdit) -1) & ""
				
			Next 
			Cont = "4"
			If Not Request("subd") = "1" Then Subd = "1"			
		End If
	
	'Conn.Execute("Select Distinct Country From Destination_Geography Where Dest_ID='" & Dest_ID & "' And Realm_ID='" & Session("Admin_Realm") & "'")

	Set sCountry = Request("Country") 
	Set sState = Request("State")
	Set sCity = Request("City")
	Set sCounty = Request("County")

On Error Resume Next
%>

	<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="subd" value="<%=Subd%>">
<input type="hidden" name="Dest_ID" value="<%=Dest_ID%>">
  <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 Geography 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"><%=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 valign="top" class="manage-menu-bold"><br>Countries to Include:</td>
      <td><select name="Country" id="Country" size="4" MULTIPLE>
<%
   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") & """"
       For i = 0 to UBound(sEdit)
			tEdit = sEdit(i)
			tmpArr = Split(tEdit, "|")
			tCity = tmpArr(0)
			tState = tmpArr(1)
			tCounty = tmpArr(2)
			tCountry = tmpArr(3)
			If RSCountry("Country_Abbr") = tCountry Then Response.Write " selected"
	   Next
	   For each tCountry in sCountry
			If RSCountry("Country_Abbr") = tCountry Then Response.Write " selected"
	   Next
       Response.Write ">" & RSCountry("Country_Name") & "</option>" & Chr(13)
       RSCountry.MoveNext
    Loop
   End If 
%>        
		</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><a onClick="return Country_onchange();">Select States</a></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
<% If Cont = "5" Or Cont = "4" Or Cont = "3" Then %>
    <tr> 
      <td class="manage-menu-bold">State(s) to Include:</td>
      <td><select name="State" id="State" MULTIPLE SIZE="5">
<%
	For each Country in sCountry
			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=""" & Country & "|" & RSState("State_Abbr") & """"
			    For i = 0 to UBound(sEdit) 
					tEdit = sEdit(i)
					tmpArr = Split(tEdit, "|")
					tCity = tmpArr(0)
					tState = tmpArr(1)
					tCounty = tmpArr(2)
					tCountry = tmpArr(3)
					If RSState("State_Abbr") = tState And Country = tCountry Then Response.Write " selected"
				Next
				For each tState in sState
					tmpArr = Split(tState, "|")
					tCountry = tmpArr(0)
					tState = tmpArr(1)
					If RSState("State_Abbr") = tState And Country = tCountry Then Response.Write " selected"
				Next
			    Response.Write ">" & Country & ": " & RSState("State_Name") & "</option>" & Chr(13)
			    RSState.MoveNext
			 Loop
			End If 
	Next
%>        
		</select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><a onClick="return State_onchange();">Select Cities &amp; Counties</a></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
<% If Cont = "3" Or Cont = "4" Then %>
    <tr> 
      <td class="manage-menu-bold">Cities to Include:</td>
      <td><select name="City" id="City" MULTIPLE SIZE="7">
<%
		For each State in sState
			tmpArr = Split(State, "|")
			Country = tmpArr(0)
			State = tmpArr(1)
			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=""" & Country & "|" & State & "|" & Trim(RSCities("City")) & """"
				    For i = 0 to UBound(sEdit) 
						tEdit = sEdit(i)
						tmpArr = Split(tEdit, "|")
						tCity = tmpArr(0)
						tState = tmpArr(1)
						tCounty = tmpArr(2)
						tCountry = tmpArr(3)
						If Trim(RSCities("City")) = tCity And State = tState And Country = tCountry Then Response.Write " selected"
					Next
				For each tCity in sCity
					tmpArr = Split(tCity, "|")
					tCountry = tmpArr(0)
					tState = tmpArr(1)
					tCity = tmpArr(2)
					If Trim(RSCities("City")) = tCity And State = tState And Country = tCountry Then Response.Write " selected"					
				Next

				    Response.Write ">" & Country & ": " & State & ": " & RSCities("City") & "</option>" & Chr(13)
				    RSCities.MoveNext
				 Loop
				End If       
		Next
%>        
      </select></td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td><a onClick="return City_onchange();">Update Counties</a></td>
      <td>&nbsp;</td>
    </tr>
<% End If %>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
<% If Cont = "4" Then %>
    <tr> 
      <td class="manage-menu-bold">Counties to Include:</td>
      <td><select name="County" id="County" MULTIPLE SIZE="7">
<%
		For each State in sState
			tmpArr = Split(State, "|")
			Country = tmpArr(0)
			State = tmpArr(1)
			
				Set RSCounties = Conn.Execute("Get_Counties @State_Abbr='" & State & "', @Country_Abbr = '" & Country & "'")
				If Not RSCounties.EOF Then
					Do Until RSCounties.EOF
				    Response.Write "<option value=""" & Country & "|" & State & "|" & Trim(RSCounties("County")) & """"
				    For i = 0 to UBound(sEdit) 
						tEdit = sEdit(i)
						tmpArr = Split(tEdit, "|")
						tCity = tmpArr(0)
						tState = tmpArr(1)
						tCounty = tmpArr(2)
						tCountry = tmpArr(3)
						If Trim(RSCounties("County")) = tCounty And State = tState And Country = tCountry Then Response.Write " selected"
					Next

					For each tCounty in sCounty
						tmpArr = Split(tCounty, "|")
						tCountry = tmpArr(0)
						tState = tmpArr(1)
						tCounty = tmpArr(2)
						If Trim(RSCounties("County")) = tCounty And State = tState And Country = tCountry Then Response.Write " selected"
					Next

				    Response.Write ">" & Country & ": " & State & ": " & RSCounties("County") & "</option>" & Chr(13)
				    RSCounties.MoveNext
				 Loop
				End If       
		Next

%>        
      </select></td>
      <td>&nbsp;</td>
    </tr>
<% ElseIf Cont = "3" Then %>
    <tr> 
      <td class="manage-menu-bold">Counties to Include:</td>
      <td><select name="County" id="County" MULTIPLE SIZE="7">
<%
			For each City in sCity
						tmpArr = Split(City, "|")
						Country = tmpArr(0)
						State = tmpArr(1)
						City = tmpArr(2)
				Set RSCounties = Conn.Execute("Get_Counties @City = '" & City & "', @State_Abbr='" & State & "', @Country_Abbr = '" & Country & "'")
				If Not RSCounties.EOF Then
					Do Until RSCounties.EOF
				    Response.Write "<option value=""" & Country & "|" & State & "|" & Trim(RSCounties("County")) & """"
				    For i = 0 to UBound(sEdit) 
						tEdit = sEdit(i)
						tmpArr = Split(tEdit, "|")
						tCity = tmpArr(0)
						tState = tmpArr(1)
						tCounty = tmpArr(2)
						tCountry = tmpArr(3)
						If Trim(RSCounties("County")) = tCounty And State = tState And Country = tCountry Then Response.Write " selected"
					Next
					For each tCounty in sCounty
						tmpArr = Split(tCounty, "|")
						tCountry = tmpArr(0)
						tState = tmpArr(1)
						tCounty = tmpArr(2)
						If Trim(RSCounties("County")) = tCounty And State = tState And Country = tCountry Then Response.Write " selected"
					Next
				    Response.Write ">" & Country & ": " & State & ": " & RSCounties("County") & "</option>" & Chr(13)
				    RSCounties.MoveNext
				 Loop
				End If       
			Next
%>        
      </select></td>
      <td>&nbsp;</td>
    </tr>
<% End If %>
<% End If %>
    <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>
<% If subd = "1" Or subd = "2" Then %>
<script language="javascript">
<% If Not Request("subd") = "2" Then %>
 form1.subd.value='2';
<% end if %>
State_onchange();
</script>
<% End If %>
</body>
</html>
