<script type="text/javascript">

$(document).ready(function(){

	$("#package_slug").blur(function (){

			var slug_filter = /^[a-z0-9-]+$/ ;
		
			if($("#package_slug").val()==''){
				$("#msg_package_slug").html('Please enter package Slug');
				$("#package_slug").addClass('jquery_err');
				$("#package_slug").focus();
				return false;
			}else if($("#package_slug").val()!='' && !slug_filter.test($("#package_slug").val())){
				$("#msg_package_slug").html('Please enter valid slug. Space are not allowed');
				$("#package_slug").addClass('jquery_err');
				$("#package_slug").focus();
				return false;
			}else{
				$("#msg_package_slug").html('');
				$("#package_slug").removeClass('jquery_err');
		}

	$("#loading_slug").show();
	
	var slug = $("#package_slug").val();
	
	$.ajax({
		  url: "slugexist.php",
		  data: 'slug='+slug+'&type=packages&id=<?php echo (isset($_REQUEST['package_id']) && $_REQUEST['package_id']!='')  ? $_REQUEST['package_id'] : 0 ?>',
		  method: 'POST',
		  success: function(msg){
				$("#loading_slug").hide();
		  		if(msg!=''){
					$("#package_slug").addClass('jquery_err');
					$("#submit").attr("disabled","disabled");
					$("#msg_package_slug").html(msg);
		  		}else{
					$("#package_slug").removeClass('jquery_err');
					$("#msg_package_slug").html('');
					$("#submit").attr("disabled","");
		  		}
		  	}
		});
		
	});
	
});

function validate_package(){

	var slug_filter = /^[a-z0-9-]+$/ ;
		
	if($("#package_title").val()==''){
		$("#msg_package_title").html('Please enter packages title');
		$("#package_title").addClass('jquery_err');
		$("#package_title").focus();
		return false;
	}else{
		$("#msg_package_title").html('');
		$("#package_title").removeClass('jquery_err');
	}
	
	if($("#package_slug").val()==''){
		$("#msg_package_slug").html('Please enter package slug');
		$("#package_slug").addClass('jquery_err');
		$("#package_slug").focus();
		return false;
	} else if($("#package_slug").val()!='' && !slug_filter.test($("#package_slug").val())){
		$("#msg_package_slug").html('Please enter valid slug. Space are not allowed');
		$("#package_slug").addClass('jquery_err');
		$("#package_slug").focus();
		return false;
	}else{
		$("#msg_package_slug").html('');
		$("#package_slug").removeClass('jquery_err');
	}
	
	
	document.packageFrm.submit();
}

</script>

<!-- Content (Right Column) -->
		<div id="content" class="box">

			<h1>Packages &raquo; Add Package</h1>

			<?php if(isset($successMsg) && $successMsg!=''){ ?>
				<p class="msg done"><?php echo $successMsg; ?></p>
			<?php } ?>
			
			<?php if(isset($failedMsg) && $failedMsg!=''){ ?>
				<p class="msg error"><?php echo $failedMsg; ?></p>
			<?php } ?>

			<form action="addpackage.php" method="post" id="packageFrm" name="packageFrm" enctype="multipart/form-data" >

				<?php if(isset($_REQUEST['package_id']) && $_REQUEST['package_id']!=''){ ?>
					<input type="hidden" id="package_id" name="package_id" value="<?php echo $packagesDetail->package_id ?>" >
				<?php } ?>
				
				<!-- Login -->
				<fieldset>
					<legend>package Details</legend>
					<p class="nomt">
						<label for="inp-01" class="req">Title :</label><br />
						<input type="text" size="50" name="package_title" id="package_title" value="<?php echo $packagesDetail->package_title; ?>" class="input-text-02" /><br/>
						<span class="smaller low message" id="msg_package_title">&nbsp;</span>
					</p>

					
					<p class="nomt">
						<label for="inp-01" class="req">Slug :</label><br />
						<input type="text" size="50" name="package_slug" id="package_slug" value="<?php echo $packagesDetail->package_slug; ?>" class="input-text-02"  /><span id="loading_slug" class="aloader" style="display:none"><img src="images/ajaxLoader.gif"></span><br/>
						<span class="smaller low message" id="msg_package_slug">&nbsp;</span>
					</p>
                    
                    <p class="nomt">
						<label for="inp-01" class="req">Short Description :</label><br />
						<textarea name="package_short_desc" id="package_short_desc"  cols="48" ><?php echo $packagesDetail->package_short_desc; ?></textarea><br/>
						
						  
						<span class="smaller low message" id="msg_package_desc">&nbsp;</span>
					</p>

					<p class="nomt">
						<label for="inp-01" class="req">Description :</label><br />
						<textarea name="package_desc" id="package_desc"  cols="48" ><?php echo $packagesDetail->package_desc; ?></textarea><br/>
						<script type="text/javascript"> CKEDITOR.replace( 'package_desc',
						 {
							filebrowserBrowseUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/ckfinder.html',
							filebrowserUploadUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/userfiles',
							filebrowserImageBrowseUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/ckfinder.html?Type=Images',
							filebrowserFlashBrowseUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/ckfinder.html?Type=Flash',
							filebrowserUploadUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Files',
							filebrowserImageUploadUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Images',
							filebrowserFlashUploadUrl : '<?php echo SITE_URL.'libs';?>'+'/ckfinder/core/connector/php/connector.php?command=QuickUpload&type=Flash'
							}
						  ); </script>
						  
						<span class="smaller low message" id="msg_package_desc">&nbsp;</span>
					</p>
                    
					<p class="nomt">
      <label for="inp-01" class="req">Package Image :</label>
      <br />
      <input type="file" name="package_image" id="package_image" class="input-text-02"   />
      <?php if($packagesDetail->package_image!='' && file_exists(DIR_UPLOAD_BANNER.$packagesDetail->package_image)) {?>
      <img src="<?php echo SITE_URL; ?>libs/timthumb.php?src=<?php echo DIR_UPLOAD_BANNER_SHOW.$packagesDetail->package_image ?>&w=250&zc=0&q=90"/>
      <input type="hidden" id="uploaded_file" name="uploaded_file" value="<?php echo $packagesDetail->package_image;  ?>" />
      <?php } ?>
      <br/>
      <span class="smaller low message" id="msg_gallery_banner">&nbsp;</span> </p>
					<p class="nomt">
						<label for="inp-01" class="req">Meta Title :</label><br />
						<textarea name="package_meta_title" id="package_meta_title"  cols="58" rows="5"><?php echo $packagesDetail->package_meta_title; ?></textarea><br/>
					</p>
					
					<p class="nomt">
						<label for="inp-01" class="req">Meta Keywords :</label><br />
						<textarea name="package_meta_keywords" id="package_meta_keywords"  cols="58" rows="5"><?php echo $packagesDetail->package_meta_keywords; ?></textarea><br/>
					</p>
					
					<p class="nomt">
						<label for="inp-01" class="req">Meta Description :</label><br />
						<textarea name="package_meta_desc" id="package_meta_desc"  cols="58" rows="5"><?php echo $packagesDetail->package_meta_desc; ?></textarea><br/>
					</p>
					
					
					<p class="nomb">
						<label for="inp-03" class="req">Status :</label><br />
						<select id="package_status" name="package_status" class="input-text-02">
							<option value="0" <?php echo ($packagesDetail->package_status==0) ? "selected='selected'" : "" ?>>Inactive</option>
							<option value="1" <?php echo (!isset($packagesDetail->package_status) || $packagesDetail->package_status==1) ? "selected='selected'" : "" ?>>Active</option>
						</select><br/>
						<span class="smaller low message" id="msg_package_status">&nbsp;</span>
					</p>

				</fieldset>
				
				<?php if(isset($packagesDetail->package_id) && $packagesDetail->package_id!=''){ ?>
					<p><input type="button" value="Edit package" id="submitpackage" name="submitpackage" class="input-submit" onclick="return validate_package();" /></p>
				<?php }else{ ?>
					<p><input type="button" value="Add package" id="submitpackage" name="submitpackage" class="input-submit" onclick="return validate_package();" /></p>
				<?php } ?> <input type="button" value="Cancel" id="cancel" name="cancel" class="input-submit" onclick="javascript:window.location='packagelist.php'" />
				<input type="hidden" name="package_image" id="package_image" value="" />
				<input type="hidden" id="hiddenSubmit" name="hiddenSubmit" value="submit" />
				
			</form>

		</div> <!-- /content -->
