<?php

	include "library.php";

	$cxn = start_code();

	$cxn_common = db_common_login();



	page_header( "Search Profiles", $cxn, $cxn_common );


//	if (val( $_GET, 'country' ) != "")
//		$curr_country = rawurldecode( val( $_GET, 'country' ) );
//	else
//		$curr_country = "";

    if (! low_res_screen())
        echo "<br><br><br>";
    else
        echo "<br>";
        
	$site_num_active_members = get_site_num_active_members( $cxn );

	$site_num_active_countries = get_site_num_active_countries( $cxn );


	$cities = build_dropdown_list( "city", $cxn_common );

	$countries = build_dropdown_list( "country", $cxn_common );

	$regions = build_dropdown_list( "region", $cxn_common );
	

	$_SESSION['search_attempt'] = "1";


		// NOTE: use different field names to the profile edit screen otherwise going to edit profile will bring values into the search screen
		
	$min_age = val( $_SESSION, "smin_age" );
	$max_age = val( $_SESSION, "smax_age" );
	$city = val( $_SESSION, "scity" );
	$state = val( $_SESSION, "sstate" );
	$country = val( $_SESSION, "scountry" );
	$region = val( $_SESSION, "sregion" );	
	$search_for_word = val( $_SESSION, "ssearch_for_word" );
	$compatability = val( $_SESSION, "scompatability" );
	$logged_on = val( $_SESSION, "slogged_on" );
    $sex_and_seeking = val( $_SESSION, "ssex_and_seeking" );
    $tick_if_gay = val( $_SESSION, "stick_if_gay" );

	echo "<form name='form' action='".url_encode( "search_init.php" )."' method='POST'><table width='100%'>\n";

	
	if (! low_res_screen())
		echo "<tr><td width='18%'></td><td width='37%'></td><td width='25%'></td><td width='7%'></td><td width='10%'></td><td width='5%'></td></tr>";
	else
		echo "<tr><td width='30%'></td><td width='35%'></td><td width='30%'></td><td width='5%'></td></tr>";
		

	$options = "<option></option><option>Men</option>";
	$options .= "<option>Women</option>";	
	$options .= "<option>Either</option>";	

	echo "<tr>".form_dropdowny( "Search for", "sex_and_seeking", $options, $sex_and_seeking );


	if (! low_res_screen())
	{
		echo "<td rowspan='11' valign='middle' align='left'>";

//		show_image( select_website_image2( $cxn, $cxn_common ), 180 );
				
		echo "</td><td>";
		
		echo "<td rowspan='30' valign='top' align='center'>";

//		show_ads_medium_skyscraper();
		
		echo "</td><td width='5%'>&nbsp;</td></tr>";
	}
	else
	{
//		echo "<td rowspan='9' align='center'>";
//
//		show_image( select_website_image2( $cxn ), 120 );
//		
//		echo "</td></tr>";
	}
		

//	form_checkbox( "Select gay members", "tick_if_gay", $tick_if_gay );
	    
	form_text( "Minimum Age", "min_age", "3", $min_age );
	form_text( "Maximum Age", "max_age", "3", $max_age );


	if (low_res_screen())
	{
//		echo "</table><table>";
	}
	

//	if (! low_res_screen())
//    	form_dropdown( "City", "city", $cities, $city );	
	
//	if (! low_res_screen())
//    	form_dropdown( "Country", "country", $countries, $country );

//	form_dropdown( "Region", "region", $regions, $region );	

//	form_text( "Search for Word", "search_for_word", "22", $search_for_word );

	if ($compatability == "on")
		$checked = "checked";
	else
	    $checked = "";


// include the line below to activate compatability searches

//	echo "<tr><td><span class='fprompt'>Order by highest compatability matches</span></td><td><input type='checkbox' name='compatability' ".$checked."> ".watermark( "Must be a member to search by compatability" )."</td></tr>";


	if (! low_res_screen())
	        echo "<tr><td>&nbsp;</td></tr>";


	form_hidden( "screen_width" );
	form_hidden( "screen_height" );
	form_hidden( "has_javascript" );
	form_hidden( "came_from_search", "yes" );


	if (! low_res_screen())
	{
		echo "<tr><td width=18%></td><td>".black( "Leave fields blank if they are not important to your search criteria" )."</td><td></td><td></td><td></td></tr>";		
	}	
	else
	{
//		echo "<tr><td>&nbsp;</td></tr>";
	    
//		if ($city != "")
//		{
//			$pos = strpos( $cities, "<option>".$city."</option>" );
//
//			if ($pos !== false)
//			{
//				$pos = $pos + 8;
//				$cities = substr( $cities, 0, $pos - 1 )." selected".substr( $cities, $pos - 1, strlen( $cities ) - $pos + 1 );
//			}
//		}
//
//		echo "<tr><td colspan='2'><span class='fprompt'>City</span></td></tr>";
//		echo "<tr><td colspan='2'><select name='city' class='finput'>".$cities."</select></td></tr>";				

		echo "<tr><td>&nbsp;</td></tr>";

	    
		if ($country != "")
		{
			$pos = strpos( $countries, "<option>".$country."</option>" );

			if ($pos !== false)
			{
				$pos = $pos + 8;
				$countries = substr( $countries, 0, $pos - 1 )." selected".substr( $countries, $pos - 1, strlen( $countries ) - $pos + 1 );
			}
		}


		echo "<tr><td colspan='2'><span class='fprompt'>Country</span></td></tr>";
		echo "<tr><td colspan='2'><select name='country' class='finput'>".$countries."</select></td></tr>";				
		
		echo "<tr><td>&nbsp;</td></tr>";
		
		echo "<tr><td colspan='2'>".black( "Leave fields blank if they are not important to your search criteria" )."</td><td></td></tr>";		
		echo "<tr><td>&nbsp;</td></tr>";
	}


	if (! low_res_screen())
		echo "<tr><td></td><td width=30%><br>";
	else
	    echo "<tr><td colspan='2' align='center'>";			
		
	show_green_button_submit( "Search", 90 );
	
	echo "</td></tr>";

    echo "<tr><td></td><td></td><td></td><td></td><td></td><td></td></tr>";
    
	if (! low_res_screen())
	{
        echo "<tr><td>&nbsp;</td></tr>";
        echo "<tr><td>&nbsp;</td></tr>";    
        echo "<tr><td>&nbsp;</td></tr>";
        echo "<tr><td>&nbsp;</td></tr>";
        echo "<tr><td>&nbsp;</td></tr>";

        echo "<tr><td></td><td colspan='2'>";

//        if (val( $_SESSION, "id" ) == "")
    		show_ads( $cxn );		

//    	else
///    		show_double_ads( $cxn );
		
        echo "</td></tr>";
	}

    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";
    echo "<tr><td>&nbsp;</td></tr>";

	echo "</table></form>";


		/* don't delete these of there won't be space for the ads */

	echo "<br>";
	echo "<br>";
		


// don't show ads on the mobile search screen that are completely off the bottom of the screen and would lower the average click-through rate
//	if (low_res_screen())
//		show_ads_large_square();
//	else
//		show_double_ads( $cxn );

?>