<!-- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />-->
<?php require '../public/system/headers/headers.php';?>
<?php echo $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/seotoaster.css'); ?>
<?php echo $this->headLink()->appendStylesheet($this->websiteUrl . 'system/js/thickbox/thickbox.css'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/jquery/jquery.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/thickbox/thickbox.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl .'system/js/page/page.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.queue.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/fileprogress.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/handlers.js'); ?>
<?php echo $this->headScript(); ?>
<script type="text/javascript">
	function replaceAll(txt, replace, with_this) {
		return txt.replace(new RegExp(replace, 'g'),with_this);
	}
    $(document).ready(function(){

		var str = $('#pageurl').val();
		var url = replaceAll(str, "'", "");
		$('#pageurl').val(url);


		$('#pageurl').keyup(function(){
			var str = $('#pageurl').val();
			var url = replaceAll(str, "'", "");
			$('#pageurl').val(url);
		});


		var str  = ($('#pageh1').val()+'').toLowerCase();
		$('#h1image').val(str);
		$('#pageh1').keyup(function()
        {
			var str  = ($('#pageh1').val()+'').toLowerCase();
			$('#h1image').val(str);
        });


        initObjectSWFUpload('<?php echo $this->websiteUrl?>','pageuploadpic');
		function hideBlock()
		{
			$('#lbl-is-category').hide();
			$('#pageiscategory').hide();
			$('#or-span').hide();
			$('#pageselectcategory').hide();
		}
		function showBlock()
		{
			$('#lbl-is-category').show();
			$('#pageiscategory').show();
			$('#or-span').show();
			$('#pageselectcategory').show();
		}
        var websiteUrl = $('#website_url').val();
		var mainMenuRad = $('#selectmenu-1');
		var statMenuRad = $('#selectmenu-2');
		var noMenuRad = $('#selectmenu-0');

		var initChecked = $('#pageiscategory').attr('checked');
		if(initChecked) {
			$('#pageselectcategory').hide();
            $('#or-span').hide();
		}

		var initSelected = $('#pageselectcategory option:selected').val();
		if(initSelected != -1) {
		}

		var initStaticMenu = $('#selectmenu-2').attr('checked');
		if(initStaticMenu) {
			hideBlock();
		}

        var initNoMenu = $('#selectmenu-0').attr('checked');
		if(initNoMenu) {
			hideBlock();
		}

		/*click on no menu*/
        $('#selectmenu-0').click(function(){hideBlock()});

        /*click on main menu*/
		$('#selectmenu-1').click(function(){showBlock()});

        /*click on static menu*/
        $('#selectmenu-2').click(function(){hideBlock()});

		$('#pageiscategory').click(function(){
            var isCat = true;
            $('#pageselectcategory').toggle();
            var checked = $(this).attr('checked');
            var selectedOption = $('#pageselectcategory option:selected').val();
            if(!checked && selectedOption == -1) {
                isCat = false;
            }
            if(isCat) {
				$('#or-span').toggle();
            }
            else {
                mainMenuRad.attr('checked', 'checked');
                statMenuRad.show();
                noMenuRad.show();

                $('#or-span').show();
                $('#lbl-staticmenu').show();
                $('#lbl-nomenu').show();
            }
        });

        $('#pageselectcategory').change(function(){
            var isCat = true;
            var selectedOption = $('#pageselectcategory option:selected').val();
            if(selectedOption == -1) {
                isCat = false;
            }
            if(!isCat) {
                mainMenuRad.attr('checked', 'checked');
                mainMenuRad.show();
				statMenuRad.show();
				noMenuRad.show();

                $('#or-span').show();
                $('#lbl-mainmenu').show();
                $('#lbl-staticmenu').show();
				$('#lbl-nomenu').show();
            }
        })

        /*$('#successPage').animate({opacity: 0}, 2000, function(){
            $('#successPage').hide();
            top.tb_remove();
            top.location.href=websiteUrl+proccessUrl($('#pageurl').val().toLowerCase());
        });*/


		$("#page-exists").fadeOut(24000, function () {
            $(this).hide();
		});

		$("#page-exists").click(function(){
			$("#page-exists").hide();
		});

        /*$("#page-exists").show();
        $("#page-exists").click(function(){
            hidePageMessages();
        });*/

        $("#category-exists").show();
        $("#category-exists").click(function(){
            hidePageMessages();
        });

        $("#has-pages").show();
        $("#has-pages").click(function(){
            hidePageMessages();
        });

		$("#url-exists").show();
        $("#url-exists").click(function(){
            hidePageMessages();
        });

        /*
        $('#pageExists').animate({opacity: 0}, 6000,  function(){$('#pageExists').hide()});
        $('#categoryExists').animate({opacity: 0}, 6000,  function(){$('#categoryExists').hide()});
        $('#hasPages').animate({opacity: 0}, 6000,  function(){$('#hasPages').hide()});
        $('#errorPage').animate({opacity: 0}, 8000,  function(){$('#errorPage').hide()});		
		 */
    });
	function initObjectSWFUpload(urlWebsite, buttonId)
	{
		var swfu;
		var settings = {
			flash_url : ""+urlWebsite+"system/js/swfupload/swfupload.swf",
			upload_url: ""+urlWebsite+"sys/backend_swfuploader/uploadpage/",

			file_size_limit : "3 MB",
			file_types : "*.gif;*.png;*.jpg",
			file_types_description : "Web Image Files",
			file_upload_limit : 10,
			file_queue_limit : 0,

			custom_settings : {
				progressTarget : "UploadProgress",
				cancelButtonId : "btnCancel"
			},
			debug: false,

			// Button settings
			button_placeholder_id: buttonId,
			button_image_url: ""+urlWebsite+"system/js/swfupload/bg-select-image.png",
			button_width: "163",
            button_height: "37",
			button_cursor: SWFUpload.CURSOR.HAND,
            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			// The event handler functions are defined in handlers.js
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete	// Queue plugin event
		};
		swfu = new SWFUpload(settings);
	}
	function uploadSuccess(file, serverData, responseReceived)
	{
		var fileName = serverData;
		if(fileName.length < 15 && fileName!='')
		{
			var str = '<img width="100" height="100" alt = "'+fileName+'" src="<?php echo $this->websiteUrl?>tmp/'+fileName+'"/>';//uploaded files
			document.getElementById('pageupdateimage').style.backgroundColor = '#FFFFFF';
			document.getElementById('image_name').value = fileName;
			document.getElementById('pageupdateimage').innerHTML = str;
            document.getElementById('image_path').value = 'tmp/'+fileName;
		}
	}
</script>
<?php if(isset($this->redirect) && $this->redirect!="") { ?>
<script type="text/javascript">
	var tmpredirect = '<?php echo $this->redirect;?>';
	parent.tb_remove();
	top.location = tmpredirect;
</script>
<?php  } ?>

<?php /*if(isset($this->successEdit) && $this->successEdit==true){  ?>
<div id="successPage" ><strong>Page was edited.</strong></div>
<?php }*/ ?>

<div id="seotoaster" class="page" style="overflow-x:hidden;overflow-y:auto;">
	<!-- Start Errors -->
	<?php if($this->pageExists==true) {  ?>
	<div id="page-exists" class="errors" style="background-color:green;top:12%;"><strong>For your information, a page with a similar navigation label already exists.<br/> This can be confusing to your website visitors.<br/> Please think twice about this.</strong></div>
<?php } ?>


<?php if($this->urlExists || $this->categoryExists || $this->hasPages || $this->errorElements ) { ?>

	<div id="page-errors" class="errors"  style="display:block;cursor:pointer;" onclick="hidePageMessages();">
		<ul>
	<?php /*if($this->pageExists){ ?>
        <li id="page-exists" style="display:none;"><strong>Page with such navigation name already exists.</strong></li>
        <?php } */?>

	<?php if($this->categoryExists==true) {  ?>
			<li id="category-exists" style="display:none;"><strong>Category with such navigation name already exists.</strong></li>
	<?php } ?>

	<?php if(isset($this->hasPages)) {  ?>
			<li id="has-pages" style="display:none;"><strong>This Category has pages.</strong></li>
	<?php } ?>

	<?php if(isset($this->urlExists)) {  ?>
			<li id="url-exists" style="display:none;"><strong>Page with such a URL already exists.</strong></li>
	<?php } ?>

	<?php if(isset($this->errorElements)) {
					echo $this->errorElements;
				} ?>
		</ul>
	</div>

<?php }?>
    <div id="pageuploadpic"></div>
	<div id="template-list-div" style="overflow:none;height:588px;widht:500px;display:none;"></div>
	<div id="fa-list-div" style="display:none;"></div>
    <div id="admineditwhat" style="top: -2px;">Edit page</div>
    <div class="close_window" onclick="parent.tb_remove();"></div>
    <p id="show-template-list-link-container" ><a id="show-template-list-link" title="Click here to change template" href="javascript:void(0);"></a></p>
    <p id="show-fa-list-link-container"><a id="show-fa-list-link"onclick="showFaLink();" title="Click here to select featured areas" href="#"><?php echo $this->faLinkMessage;?></a></p>

	<!--
		<span style="position: absolute; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255); left: 467px; top: 81px;" id="lbl-mainmenu">Main menu</span>
		<span style="position: absolute; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255); top: 81px; left: 571px;" id="lbl-staticmenu">Static menu</span>
		<span style="position: absolute; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255); left: 683px; top: 81px;" id="lbl-nomenu">No menu</span>
		<span style="position: absolute; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255); left: 467px; top: 116px;" id="lbl-is-category">This is a category</span>
		<span style="position: absolute; font-size: 13px; font-weight: bold; color: rgb(255, 255, 255); left: 655px; top: 116px;" id="or-span"> OR</span>
	-->
    <span style="position: absolute; font-size: 13px; font-weight: bold; color: #fff; left: 501px; top: 81px;" id="lbl-mainmenu">{%Main menu%}</span>
    <span style="position: absolute; font-size: 13px; font-weight: bold; color: #fff; top: 81px; left: 612px;" id="lbl-staticmenu">{%Static menu%}</span>
    <span style="position: absolute; font-size: 13px; font-weight: bold; color: #fff; left: 724px; top: 81px;" id="lbl-nomenu">{%No menu%}</span>
    <span style="position: absolute; font-size: 13px; font-weight: bold; color: #fff; left: 484px; top: 116px;" id="lbl-is-category">{%This is a new category%}</span>
    <span style="position: absolute; font-size: 13px; font-weight: bold; color: #fff; left: 690px; top: 116px;" id="or-span"> {%OR%}</span>
	<span style="position: absolute; font-size: 13px; font-weight: bold; color: #fff; left: 525px; top: 116px; font-size: 20px; display: none;" id="notav"> {%Not available for this page%}</span>
<?php echo $this->pageForm; ?>


	<p id="headertext">{%Page header H1 tag:%}</p>
	<p id="titletext">{%Display in browser title as:%}</p>
	<p id="urltext">{%Page URL in address bar:%}</p>
	<p id="navigationtext">{%Display in navigation as:%}</p>
	<p id="metadesctext">{%Meta description:%}</p>
	<p id="metakeytext">{%Meta keywords:%}</p>
	<p id="teasertext">{%Page Teaser text:%}</p>
	<p id="navigationblocktext">{%NAVIGATION%}</p>
	<p id="settingstext">{%SETTINGS%}</p>
	<p id="imageteasertext">{%IMAGE TEASER FOR THIS PAGE%}</p>
	<p id="currenttemplatetext">{%Current Template:%}</p>
	<p id="pageisfeaturedtext">{%Page is featured:%}</p>
	<p id="pagenotfoundtext">{%Use as 404 page not found:%}</p>
	<p id="noimagetext">{%No image Yet%}</p>


    <!--NECESSARY FOR SWF UPLOAD!!!!!!-->
    <input disabled="disabled" id="btnCancel" value="Cancel All Uploads" onclick="swfu.cancelQueue();" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;" type="button">
	<div id ="swfbackground"></div>
    <div class="fieldset flash" style="display:none;" id="UploadProgress"></div>
    <div class="fieldset flash" style="display:none;" id="divStatus"></div>

    <div  id="pageupdateimage" style="border: 1px solid #fff;">
<?php if($this->pageForm->image_name->getValue()) { ?>
        <img width="100px" height="100px" src="<?php echo $this->websiteUrl?>previews/<?php echo $this->pageForm->image_name->getValue(); ?>"/>
<?php } ?>
    </div>
	<input type="hidden" id="hid-main-wsurl" name="hid-main-wsurl" value="<?php echo $this->websiteUrl; ?>" />
</div>
