/*
  (c) 2008-2014 Samnan ur Rehman
 @web        http://mywebsql.net
 @license    http://mywebsql.net/license
*/
$.mywebsql={popup:!1,dialogs:[]};var main_layout,data_layout,currentTreeItem=null,clipboard_helper=null,historyCurItem=null;
$(document).ready(function(){if($.browser.msie&&7>=$.browser.version)return $("select").hide(),$("#screen-wait").find("div:first").remove(),$("#screen-wait").find("div.compat-notice").show(),!0;$("body").bind("contextmenu",function(a){a=a.originalTarget||a.target;return"textarea"==a.type||"text"==a.type?!0:!1});$("ul#main-menu li ul li:has(ul)").find("a:first").append(" &raquo; ");$("ul#main-menu").find("a").click(function(a){a.stopPropagation();$(this).blur()});$("ul#main-menu li").click(function(){eval($(this).find("a").attr("href"))});
$("#toolbarHolder").mouseover(function(){_contextMenu&&_contextMenu.hide()});$(".ui-layout-data-center").tabs();$(".ui-layout-data-south").tabs({select:function(a,b){setTimeout(focusEditor,200)}});main_layout_props={spacing_open:3,spacing_closed:6,east__minSize:200,west__minSize:150,west__size:.2*$("body").innerWidth(),north__minSize:76,north__resizable:!1,north__closable:!0,north__spacing_open:0,north__spacing_closed:6,north__onopen:function(){main_layout.allowOverflow("north")},south__resizable:!1,
south__closable:!0,south__spacing_open:0,south__spacing_closed:0,center__onresize:function(){data_layout.resizeAll();layoutState.save("main_layout")},enableCursorHotkey:!1};main_layout=$("body").layout($.extend(main_layout_props,layoutState.load("main_layout")));data_layout_props={spacing_open:3,spacing_closed:6,resizerClass:"ui-data-resizer",togglerClass:"ui-data-toggler",center__paneSelector:".ui-layout-data-center",south__paneSelector:".ui-layout-data-south",center__resizable:!0,south__resizable:!0,
south__closable:!0,south__minSize:66,south__size:160,center__onresize:function(){layoutState.save("data_layout")},enableCursorHotkey:!1,onresizeall_end:function(){var a=$(".ui-layout-data-center").tabs("option","selected");0==a?resizeTableHeader("data"):2==a&&resizeTableHeader("info")}};data_layout=$("div.ui-layout-center").layout($.extend(data_layout_props,layoutState.load("data_layout")));main_layout.close("south");main_layout.allowOverflow("north");$(".ui-layout-data-center").tabs("select",2);
$("#tablelist").treeview();contextHandler();$(".ui-layout-resizer").bind("selectstart",function(){return!1});$("#nav_query").button({text:!0,icons:{primary:"ui-icon-play"}}).click(function(){queryGo(0)});$("#nav_queryall").button({text:!0,icons:{primary:"ui-icon-seek-end"}}).click(function(){queryGo(1)});$("#nav_delete").button({text:!0,icons:{primary:"ui-icon-close"}}).click(function(){queryDelete()});$("#nav_update").button({text:!0,icons:{primary:"ui-icon-disk"}}).click(function(){querySave()});
$("#nav_gensql").button({text:!0,icons:{primary:"ui-icon-script"}}).click(function(){queryGenerate()});$("#nav_addrec").button({text:!0,icons:{primary:"ui-icon-plusthick"}}).click(function(){queryAddRecord()});$("#nav_copyrec").button({text:!0,icons:{primary:"ui-icon-copy"}}).click(function(){queryCopyRecord()});$("#nav_refresh").button({text:!0,icons:{}}).click(function(){queryRefresh()});$("#sp-results-maximize").button({text:!1,icons:{primary:"ui-icon-newwin"}}).click(function(){resultsPaneToggle()});
initClipboard();$(window).unload(function(){layoutState.save("data_layout");layoutState.save("main_layout")});taskbar.init();$("#object-filter-text").quickText().bind("keyup",function(){var a=$("#tablelist").hasClass("dblist")?"span.odb a":"span.file a";$("#object_list").setObjectFilter($(this).val(),a,"ul")});$("#screen-wait").remove();$("#wrkfrm").attr("src","index.php?q=wrkfrm&type=info");loadUserPreferences();showNavBtns("query","queryall")});
function contextHandler(){0==arguments.length&&($("ul#main-menu .option").not("."+DB_DRIVER).remove(),$("#object-context-menus .option").not("."+DB_DRIVER).remove(),$(".ui-layout-north").contextMenu("#panel-header"),$("#object_list").contextMenu("#panel-menu-objects"),$("#sql-editor-pane").contextMenu("#panel-menu-editor"),$("#sql-history").contextMenu("#history-menu"));$("#tablelist .odb").contextMenu("#db-menu");$("#tablelist .otable").contextMenu("#table-menu");$("#tablelist .oview").contextMenu("#view-menu");
$("#tablelist .oproc").contextMenu("#proc-menu");$("#tablelist .ofunc").contextMenu("#func-menu");$("#tablelist .otrig").contextMenu("#trig-menu");$("#tablelist .oevt").contextMenu("#evt-menu");$("#tablelist .schmf").contextMenu("#schm-menu");$("#tablelist span").filter(".tablef,.viewf,.procf,.funcf,.trigf,.evtf").contextMenu("#object-menu")}
function initClipboard(){$("#sql-history tr").live("hover",function(){historyCurItem=$(this)});ZeroClipboard.setMoviePath("js/jquery.clipboard.swf");clipboard_helper=new ZeroClipboard.Client;$("#history-menu li.clipboard").mouseover(function(){single=$(this).hasClass("single");clipboard_helper.setText(getHistoryText(single));clipboard_helper.div?(clipboard_helper.receiveEvent("mouseout",null),clipboard_helper.reposition(this)):(clipboard_helper.glue(this),$(clipboard_helper.div).click(function(){clipboard_helper.hide()}));
clipboard_helper.receiveEvent("mouseover",null)})}function showNavBtns(){bn="addrec copyrec query queryall delete update gensql".split(" ");for(i=0;i<bn.length;i++)$("#nav_"+bn[i]).css("display","none");for(i=0;i<arguments.length;i++)$("#nav_"+arguments[i]).css("display","block")}function showNavBtn(){for(i=0;i<arguments.length;i++)$("#nav_"+arguments[i]).css("display","block")}function hideNavBtn(a){for(i=0;i<arguments.length;i++)$("#nav_"+arguments[i]).css("display","none")}
function switchEditor(a){$(".ui-layout-data-south").tabs("select",a)}function editorTextSize(a){if(ts=parseFloat($(currentEditor().editor.container).css("font-size")))0<a&&100>=ts?ts+=a:0>a&&11<=ts&&(ts+=a),$(currentEditor().editor.container).css("font-size",ts+"px")}function editorClear(){$(currentEditor().editor.container).html("")}
function currentEditor(){n=$(".ui-layout-data-south").tabs("option","selected");obj=commandEditor;switch(n){case 1:obj=commandEditor2;break;case 2:obj=commandEditor3}return obj}function focusEditor(){ed=currentEditor();ed.focus()}function getDataMenu(a,b,c){target=$(c.originalTarget||c.target);return target.hasClass("tch")?!1:target.is("th")?$("#data-menu-th").clone():target.is("td")?$("#data-menu-td").clone():!1}
function objListHandler(a,b){tree=$(a).find("#objlist").html();""!=tree?($("#object_list").html(tree),$("#tablelist").treeview(),contextHandler(!1),$("#object-filter-text").val("")):jAlert(__("An error occured while refreshing the object list."));for(i=0;i<b.length;i++)$("#"+b[i]+" span:first").trigger("click");setPageStatus(!1)}
function resultsPaneToggle(){var a=$("#sp-results-maximize");1==a.data("max")?(main_layout.open("north"),data_layout.open("south"),main_layout.open("west"),a.removeData("max")):(a.data("max",1),main_layout.close("north"),data_layout.close("south"),main_layout.close("west"))}
function uiCreateDialog(a){if(-1!=$.inArray(a,$.mywebsql.dialogs))return!0;"dbcreate"==a&&$("#dialog-dbcreate").dialog({autoOpen:!1,width:320,height:160,modal:!0,buttons:[{text:__("Cancel"),click:function(){$(this).dialog("close")}},{text:__("Create Database"),click:function(){dbCreate(1)}}]});$.mywebsql.dialogs.push(a);return!0}
function initEditor(a){var b=commandEditor,c="sql_commandEditor";switch(a){case 1:b=commandEditor2;c="sql_commandEditor2";break;case 2:b=commandEditor3,c="sql_commandEditor3"}(a=$.cookies.get(c))&&b.setCode(a)}$.fn.setObjectFilter=function(a,b,c){if(""==a)return $(b,this).parentsUntil(c).removeClass("ui-helper-hidden"),this;string=a.toUpperCase();$(b,this).each(function(){$(this).text().toUpperCase().match(string)?$(this).parentsUntil(c).removeClass("ui-helper-hidden"):$(this).parentsUntil(c).addClass("ui-helper-hidden")})};
$.fn.quickText=function(){return this.each(function(a){input=$(this);""==input.val()&&(input.addClass("blur"),input.val(input.attr("data-placeholder")));input.focus(function(){$.trim($(this).val())===$(this).attr("data-placeholder")&&$(this).val("").removeClass("blur")}).blur(function(){""===$.trim($(this).val())&&$(this).addClass("blur").val($(this).attr("data-placeholder"))});return $(this)})};
