<script type="text/javascript">

$(document).ready(function(){

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

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

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

function validate_page(){

	var slug_filter = /^[a-z0-9-]+$/ ;
		
	if($("#page_title").val()==''){
		$("#msg_page_title").html('Please enter pages title');
		$("#page_title").addClass('jquery_err');
		$("#page_title").focus();
		return false;
	}else{
		$("#msg_page_title").html('');
		$("#page_title").removeClass('jquery_err');
	}
	
	if($("#page_slug").val()==''){
		$("#msg_page_slug").html('Please enter page slug');
		$("#page_slug").addClass('jquery_err');
		$("#page_slug").focus();
		return false;
	} else if($("#page_slug").val()!='' && !slug_filter.test($("#page_slug").val())){
		$("#msg_page_slug").html('Please enter valid slug. Space are not allowed');
		$("#page_slug").addClass('jquery_err');
		$("#page_slug").focus();
		return false;
	}else{
		$("#msg_page_slug").html('');
		$("#page_slug").removeClass('jquery_err');
	}
	
	
	document.pageFrm.submit();
}

</script>

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

			<h1>Pages &raquo; Add Page</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="addpage.php" method="post" id="pageFrm" name="pageFrm" enctype="multipart/form-data" >

				<?php if(isset($_REQUEST['page_id']) && $_REQUEST['page_id']!=''){ ?>
					<input type="hidden" id="page_id" name="page_id" value="<?php echo $pagesDetail->page_id ?>" >
				<?php } ?>
				
				<!-- Login -->
				<fieldset>
					<legend>Page Details</legend>
					<p class="nomt">
						<label for="inp-01" class="req">Title :</label><br />
						<input type="text" size="50" name="page_title" id="page_title" value="<?php echo $pagesDetail->page_title; ?>" class="input-text-02" /><br/>
						<span class="smaller low message" id="msg_page_title">&nbsp;</span>
					</p>
						<p class="nomt">
      <label for="inp-01" class="req">Parent Page :</label>
      <br />
      <select name="page_parent" id="page_parent" class="input-text-02">
        <option value="0">Select parent page</option>
        <?php 
						if(count($parentDetails) > 0)
						{
							foreach ($parentDetails as $parent){
						
						?>
        <option value="<?php echo $parent->page_id; ?>" <?php if ($pagesDetail->page_parent == $parent->page_id) {echo 'selected="selected"';}?> ><?php echo $parent->page_title; ?></option>
        <?php }
						}
						?>
      </select>
      <span class="smaller low message" id="msg_page_title">&nbsp;</span> </p>
					<?php if(!in_array(trim($pagesDetail->page_slug),$noneEditPage)){ ?>
					
					<p class="nomt">
						<label for="inp-01" class="req">Slug :</label><br />
						<input type="text" size="50" name="page_slug" id="page_slug" value="<?php echo $pagesDetail->page_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_page_slug">&nbsp;</span>
					</p>
                    

					
					
					<?php }else{ ?>
						<input type="hidden" id="page_slug" name="page_slug"  value="<?php echo $pagesDetail->page_slug ?>" />
						
					<?php } ?>
                    <p class="nomt">
						<label for="inp-01" class="req">Short Description :</label><br />
						<textarea name="page_short_desc" id="page_short_desc"  cols="48" ><?php echo $pagesDetail->page_short_desc; ?></textarea><br/>
						<script type="text/javascript"> CKEDITOR.replace( 'page_short_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_page_desc">&nbsp;</span>
					</p>
                    <p class="nomt">
						<label for="inp-01" class="req">Description :</label><br />
						<textarea name="page_desc" id="page_desc"  cols="48" ><?php echo $pagesDetail->page_desc; ?></textarea><br/>
						<script type="text/javascript"> CKEDITOR.replace( 'page_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_page_desc">&nbsp;</span>
					</p>
                    <p class="nomt">
      <label for="inp-01" class="req">Page Banner Image :</label>
      <br />
      <input type="file" size="50"  name="page_banner" id="page_banner" class="input-text-02"   />
      <?php if($pagesDetail->page_banner!='' && file_exists(DIR_UPLOAD_BANNER.$pagesDetail->page_banner)) {?>
      <img src="<?php echo DIR_UPLOAD_BANNER_SHOW.$pagesDetail->page_banner ?>" height="110" width="90"  />
      <input type="hidden" id="uploaded_file" name="uploaded_file" value="<?php echo $pagesDetail->page_banner;  ?>" />
      <?php } ?>
      <br/>
      <span class="smaller low message" id="msg_gallery_banner">&nbsp;</span> </p>
      
					<p class="nomt">
                      <label for="inp-01" class="req">Display On Home Page:</label>
                      <br />
                          <select id="on_home" name="on_home" class="input-text-02">
                            <option value="1" selected="selected">Active</option>
                            <option value="0" <?php if ($pagesDetail->on_home == 0) {echo 'selected="selected"';}?>>Inactive</option>
                          </select>
                      <br/>
                    </p>
					
                   <p class="nomt">
  <label for="inp-01" class="req">Display On Header Menu:</label>
  <br />
  <select id="on_header" name="on_header" class="input-text-02">
    <option value="1" selected="selected">Active</option>
    <option value="0" <?php if ($pagesDetail->on_header == 0) {echo 'selected="selected"';}?>>Inactive</option>
  </select>
  <br/>
</p>
                    <p class="nomt">
                      <label for="inp-01" class="req">Display On Footer Menu:</label>
                      <br />
                      <select id="on_footer" name="on_footer" class="input-text-02">
                        <option value="1" selected="selected">Active</option>
                        <option value="0" <?php if ($pagesDetail->on_footer == 0) {echo 'selected="selected"';}?>>Inactive</option>
                      </select>
                      <br/>
                    </p>
					<p class="nomt">
						<label for="inp-01" class="req">Meta Title :</label><br />
						<textarea name="page_meta_title" id="page_meta_title"  cols="58" rows="5"><?php echo $pagesDetail->page_meta_title; ?></textarea><br/>
					</p>
					
					<p class="nomt">
						<label for="inp-01" class="req">Meta Keywords :</label><br />
						<textarea name="page_meta_keywords" id="page_meta_keywords"  cols="58" rows="5"><?php echo $pagesDetail->page_meta_keywords; ?></textarea><br/>
					</p>
					
					<p class="nomt">
						<label for="inp-01" class="req">Meta Description :</label><br />
						<textarea name="page_meta_desc" id="page_meta_desc"  cols="58" rows="5"><?php echo $pagesDetail->page_meta_desc; ?></textarea><br/>
					</p>
					
					
					<p class="nomb">
						<label for="inp-03" class="req">Status :</label><br />
						<select id="page_status" name="page_status" class="input-text-02">
							<option value="0" <?php echo ($pagesDetail->page_status==0) ? "selected='selected'" : "" ?>>Inactive</option>
							<option value="1" <?php echo (!isset($pagesDetail->page_status) || $pagesDetail->page_status==1) ? "selected='selected'" : "" ?>>Active</option>
						</select><br/>
						<span class="smaller low message" id="msg_page_status">&nbsp;</span>
					</p>

				</fieldset>
				
				<?php if(isset($pagesDetail->page_id) && $pagesDetail->page_id!=''){ ?>
					<p><input type="button" value="Edit page" id="submitPage" name="submitPage" class="input-submit" onclick="return validate_page();" /></p>
				<?php }else{ ?>
					<p><input type="button" value="Add page" id="submitPage" name="submitPage" class="input-submit" onclick="return validate_page();" /></p>
				<?php } ?> <input type="button" value="Cancel" id="cancel" name="cancel" class="input-submit" onclick="javascript:window.location='pagelist.php'" />
				<input type="hidden" name="page_banner" id="page_banner" value="" />
				<input type="hidden" id="hiddenSubmit" name="hiddenSubmit" value="submit" />
				
			</form>

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