<?php
include("includes/site_info.php");
include('session_handler.inc');

$WUserID = $_SESSION['Sess_UserId'];
$WUsername = $_SESSION['Sess_UserName'];

//print_r($_POST);
$return=false;
$mainCat = $_REQUEST["mainCat"];
$optionFor = $_REQUEST["optionFor"];
$userid = $_REQUEST['userid'];
if((empty($mainCat) || empty($optionFor)) && !empty($userid)){ $return=true; }

$member_query=mysql_query("SELECT adv_countryid FROM adverts LEFT JOIN members ON (adv_userid=mem_userid) WHERE adv_userid = '$WUserID' AND adv_approved='1'") or die(mysql_error());
$sql_array = mysql_fetch_object($member_query);
?>
<script type="text/javascript">
	
jQuery(document).ready(function($){
$("#mainCat").change(function()
{
var id=$(this).val();
var dataString = 'catID='+ id;

$("#msg_content_error").fadeOut('slow');
$('#msg_content_error').html('');

$("#radioFor").html('<img src="images/loader1.gif" border="0" align="absmiddle">');

$.getJSON('postAction.php?Mode=getForOnly', { catID: id }, function(html) {
	if (html.status=="1") {
		$("#radioFor").html(html.radioFor);
	} else {
		$("#radioFor").html(html.error);
	}
});

});

    $("#addPost1").bind('submit', function() {
	 
	 	$('#msg_content_error').html('');
		
 	if ($("#mainCat").val() == 0) {
	 
		$("#msg_content_error").fadeIn('slow');
	 	$('#msg_content_error').append('Ops! Please select Category!<br>');
      return false;

    }

	if ($("input[name='optionFor']:checked").length == 0) {
	 
		$("#msg_content_error").fadeIn('slow');
	 	$('#msg_content_error').append('Ops! Please choose Option for Category!<br>');
      return false;

    }

	var str = $(this).serialize();
	var that = this;

/*   		$.ajax({
   		type: "POST",
   		url: "postPop2.php",
   		data: str,
   		success: function(result){

		$('#sub_content').append(result);
		}

 });
*/	
	 $('#msg_content_error').hide();
$.facebox({ajax:'<?=$CONST_LINK_ROOT?>/postPop2.php?'+str}, 'Create&nbsp;Post', 'newPost2');
return false;

    });
	 
});

</script>

<table width="400" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td valign="top"><?php if($return==true) {?>
			<div id="msg_content_error" >
				<?php if(empty($mainCat)) echo "Ops! Please select Category!<br>"; if(empty($optionFor)) echo "Ops! Please choose Option for Category!<br>";?>
			</div>
			<?php } else ?>
			<div id="msg_content_error" style="display:none;" ></div>
			<div id="sub_content">
				<form id="addPost1" name="addPost1" method="post" style="padding:0; margin:0; border:0;">
					<input name="userid" type="hidden" value="<?=$WUserID?>" />
					<table width="100%" border="0" cellspacing="0" cellpadding="10">
						<tr>
							<td><div id="markPost">
									<p>
										<label for="mainCat" class="label">Category: </label>
										<select name="mainCat" id="mainCat" class="selectLarge required" rel="Category">
											<?php
										$sql=mysql_query("select catID, catName from market_category order by catID asc");
										while($row=mysql_fetch_array($sql))
										{
											$id=$row['catID'];
											$data=$row['catName'];
											echo '<option value="'.$id.'">'.$data.'</option>';
										} ?>
										</select>
									</p>
									<p>
										<label class="label">&nbsp;</label>
									<div class="left h100"> <span id="radioFor">
										<?php
										$sql=mysql_query("select forID, forName from market_category_for where catID=1 order by forID asc");
										while($row=mysql_fetch_array($sql))
										{
											$id=$row['forID'];
											$data=$row['forName'];
											echo '<label><input type="radio" name="optionFor" id="optionFor" value="'.$id.'" class="radio required" />'.$data.'</label><br/>';
										} ?>
										</span> </div>
									</p>
								</div></td>
						</tr>
						<tr>
							<td align="center" class="left solid_line"><input name="cancel" type="button" class="button" id="cancel" value="Cancel" onclick="javascript: parent.jQuery.facebox.close();"/>
								<input name="reset" type="reset" class="button" id="reset" value="Reset" />
								<input name="save" type="submit" class="submit" id="save" value="Next"/></td>
						</tr>
					</table>
				</form>
			</div></td>
	</tr>
</table>
