$(function(){$.form("page/pages","page/page_categories","page_category_id","page_shared_category_id",[{name:"title",text:"Title"},{name:"sef_title",text:"URL Title"}]);if($.url.param("id")!=undefined){$.getJSON("http://demo.firerift.com/api/page/pages?include=page_category&id="+$.url.param("id"),function(data){var opts={page_category_id:data.items[0].page_category[0].id,order:"position"}
if(data.items[0].user_id!=$.session.user.id){opts.shared="YES";$("#shared").parent().remove();$("#category_id").parent().parent().remove();}
$.breadcrumbs("page/pages","Pages",data.items[0].page_category[0].name,data.items[0].title,opts,$.url.param("id"));});}
$(".form-holder form").css("display","block");var iframe=document.getElementById("iframe");if($.session.user.message_type=="html"){iframe.style.display="none";$("#frm-text").show();$("#msg-opts").hide();$("#msg_type").val($.session.user.message_type);$("#msg-type-update").text($("#msg_type option:selected").text());}
$("#msg_type").change(function(){var val=$(this).val();if(val=="html"){$("#frm-text").val(iframe.contentWindow.document.body.innerHTML);$("#iframe, #msg-opts").hide();$("#frm-text").show();$("#frm-insert-link").unbind().click(function(){$("#dropdown-holder").html($("#add_link_dropdown").html()).show("slide",{direction:'up'},function(){$("#dropdown-holder input[name=name]").focus();$("#dropdown-holder input[name=new_window]").val("NO");});$("#dropdown-holder form").submit(function(){$.addlinks();return false;});return false;});}else{var content=$("#frm-text").val();content=content.replace(/{\{base_url}\}/g,"http://demo.firerift.com/");iframe.contentWindow.document.body.innerHTML=content;$("#frm-text").hide();$("#iframe, #msg-opts").show();$("#frm-insert-link").unbind().click(function(){var mylink=prompt("Enter a URL:","http://");if((mylink!=null)&&(mylink!="")){iframe.contentWindow.document.execCommand("CreateLink",false,mylink);}
return false;});}
$("#msg-type-update").text($(this).children(":selected").text());return false;});$("#msg-opts a.btn-bold").click(function(){iframe.contentWindow.document.execCommand('bold',false,null);return false;});$("#msg-opts a.btn-italic").click(function(){iframe.contentWindow.document.execCommand('italic',false,null);return false;});$("#msg-opts a.btn-underline").click(function(){iframe.contentWindow.document.execCommand('underline',false,null);return false;});$("#msg-opts a.btn-ul").click(function(){iframe.contentWindow.document.execCommand('insertunorderedlist',false,null);return false;});$("#msg_heading").change(function(){var headval=$(this).val();if(headval!="null"&&headval!=""){if(headval=="normal"){iframe.contentWindow.document.execCommand('formatblock',false,"P");}else{iframe.contentWindow.document.execCommand('formatblock',false,headval);}}
$("#msg-heading-update").text($(this).children(":selected").text());return false;});});
