var Mindshark={plugin:{},poll_ajax:null,poll_session_id:"0_0",tab_selected:null,ajax:function(url,options){options=$.extend({data:{},async:true,type:"post",success:null,failure:null},options||{});return $.ajax({url:url,type:options.type,contentType:"application/json",data:$.toJSON(options.data),dataType:"json",success:function(data){if(data.status!=true){if(data.message!=undefined)Mindshark.alert(data.message);if(options.failure)options.failure(data);return}if(data.message!=undefined)if(typeof data.callback== "object"&&data.callback.parent)Mindshark.gritter(data.message,true);else Mindshark.gritter(data.message);if(options.success)options.success(data)},error:function(){if(options.failure)options.failure()}})},ajax_load:function(elm,url,callback){elm.load(url,{},callback)},redirect:function(url){window.location=url},alert:function(message,callback){var buttons={};buttons[_("Ok")]=function(){$(this).dialog("close");if(callback!=undefined)callback.call(this)};$("#dialog_confirm").html(message).dialog("option", "title",_("Error")).dialog("option","buttons",buttons).dialog("open");$("button:first",$("#dialog_confirm").parents("div.ui-dialog:first")).focus()},gritter:function(text,child){if(child)parent.$.gritter.add({title:"empty",text:text,class_name:"gritter-no-title",sticky:false,time:4500});else $.gritter.add({title:"empty",text:text,class_name:"gritter-no-title",sticky:false,time:4500})},confirm:function(message,confirm_callback,cancel_callback){var buttons={};buttons[_("No")]=function(){$(this).dialog("close"); if(cancel_callback)cancel_callback.call()};buttons[_("Yes")]=function(){$(this).dialog("close");if(confirm_callback)confirm_callback.call()};$("#dialog_confirm").html(message).dialog("option","title",_("Confirm")).dialog("option","buttons",buttons).dialog("open");$("button:first",$("#dialog_confirm").parents("div.ui-dialog:first")).focus()},dialog_open:function(url){$("#dialog iframe").attr("src","/modal"+url);$("#dialog").dialog("option","title","");$("#dialog").dialog("open");$("#dialog").data("opened_by", this)},dialog_close:function(reload,redirect){$("#dialog").dialog("close");if(reload)if(redirect!=undefined)window.location=redirect;else window.location=window.location},dialog_settings:function(settings){for(var i in settings)$("#dialog").dialog("option",i,settings[i]);$("#dialog").dialog("option","position",["center","middle"])},strip_prefix:function(name,prefix){if(prefix!=null&&name.substring(0,prefix.length)==prefix)name=name.substring(prefix.length);return name},window_toggle_info:function(state){if(state)$("#projectInfoContent").slideDown("fast"); else $("#projectInfoContent").slideUp("fast")},window_toggle_employees:function(state){if(state){$("#employeesList").show();$("#employeeViewIcon").css("backgroundColor","#d7dce2");$("#empSearchInput").focus()}else{$("#employeesList").hide();$("#employeeViewIcon").css("backgroundColor","#2b3036")}},menu_toggle:function(state){if(state){$(this).next().slideDown("slow");$("img.image_hover",this).attr("src","/images/layout/menuLeftUpHover.png")}else{$(this).next().slideUp("slow");$("img.image_hover", this).attr("src","/images/layout/menuLeftDownHover.png")}},autocomplete:function(id,url,param){param=$.extend({selectFirst:true,dataType:"json",parse:function(data){return $.map(data.result,function(row){return{data:row,value:row.id,result:row.name}})},formatItem:function(item){return item.name}},param||{});return $(id).autocomplete(url,param)},poll:function(session_id){Mindshark.poll_ajax=$.post("/poll/"+session_id+"/",{at:location.href},function(data){Mindshark.poll_session_id=data.session_id;for(var i= 0;i=0;i--,step++){if(step==3&&num[0][i]!="-"){new_value=i18n.number_format[0]+ new_value;step=0}new_value=num[0][i]+new_value}if(num.length>1&&decimals){num[1]=num[1].substring(0,decimals);for(var length=num[1].length;length>0;length--)if(num[1][length]!="0")break;if(length)new_value+=i18n.number_format[1]+num[1].substring(0,length)}return new_value},parse_number:function(value,def){if(value==null)return 0;value=value.toString();value=value.replace(i18n.number_format[0],"");value=value.replace(i18n.number_format[1],".");value=parseFloat(value);return!isNaN(value)?value:def=== undefined?0:def},rgb2hex:function(rgb){rgb=rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);function hex(x){hexDigits=new Array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f");return isNaN(x)?"00":hexDigits[(x-x%16)/16]+hexDigits[x%16]}return hex(rgb[1])+hex(rgb[2])+hex(rgb[3])},bind_events:function(){var id=this.id.substring(0,this.id.indexOf("_"));var rel=$(this).attr("rel").split(",");if(rel==undefined||rel[0]==undefined||rel[1]==undefined)return false;var data=new Object;var container= $("#"+rel[0]+"_"+id);$("input",container).each(function(){var name=Mindshark.strip_prefix(this.id,id+"_");if(this.type=="checkbox")data[name]=$(this).is(":checked");else data[name]=$(this).val()});$("select,textarea",container).each(function(){name=Mindshark.strip_prefix(this.id,id+"_");data[name]=$(this).val()});$.ajax({type:"POST",url:"/ajax/dashboard/ajax/?widget_id="+id+"&method="+rel[1],dataType:"json",data:$.toJSON(data),success:function(data){for(i in data){var elm=$("#"+id+"_"+i);elm.html(data[i])}}}); return true},wizard:{open:function(){var wizard=$("
").hide().appendTo($("body"));wizard.load("/empty/base/wizard/?open=yes",function(){wizard.fadeIn("fast")})}},strip_slashes:function(str){return str.replace(/\\'/g,"'").replace(/\\"/g,'"').replace(/\\\\/g,"\\")},change:{_state:{},_message:_("You have made changes to the current page, are you sure you want to continue without saving?"),set:function(elm){var dad=$(elm).parents("form:first");var id=$(elm).attr("id");var selector;dad=dad.length? $(dad).attr("id"):"general";if(id==undefined||!id.length){id=$(elm).attr("name");selector='[name="'+id+'"]'}else selector="#"+id;if(typeof Mindshark.change._state[dad]=="undefined")Mindshark.change._state[dad]={};Mindshark.change._state[dad][id]=selector},clear:function(dad){if(dad==undefined){Mindshark.change._state={};$(".change_highlight").removeClass("change_highlight");return}if(typeof dad!="array"&&typeof dad!="object")dad=[dad];for(var i in dad){if(typeof Mindshark.change._state[dad[i]]=="undefined")continue; $(".change_highlight",$("#"+dad[i])).removeClass("change_highlight");delete Mindshark.change._state[dad[i]]}},message:function(msg){Mindshark.change._message=msg},setup:function(){$(window).bind("beforeunload",function(){change=false;for(var dad in Mindshark.change._state){var form=$("#"+dad);for(var id in Mindshark.change._state[dad]){change=true;$(Mindshark.change._state[dad][id],form).addClass("change_highlight")}}if(change)return Mindshark.change._message});$("input.change, select.change, textarea.change").live("change", function(){Mindshark.change.set(this)})},changed:function(dad){var form,change=false;if(dad==undefined){for(var dad in Mindshark.change._state){form=$("#"+dad);for(var id in Mindshark.change._state[dad]){change=true;$(Mindshark.change._state[dad][id],form).addClass("change_highlight")}}return change}if(typeof dad!="array"&&typeof dad!="object")dad=[dad];for(var i in dad){if(typeof Mindshark.change._state[dad[i]]=="undefined")continue;form=$("#"+dad[i]);for(var id in Mindshark.change._state[dad[i]]){change= true;$(Mindshark.change._state[dad[i]][id],form).addClass("change_highlight")}}return change}},overlay:function(options){options=$.extend({width:$(options.container).outerWidth(),height:$(options.container).outerHeight()},options||{});var overlay=$('
').width(options.width).height(options.height).appendTo($("body")).position({my:"center center",at:"center center",of:options.container});$("img",overlay).position({my:"center center",at:"center center", of:overlay});overlay.animate({opacity:0.8},500);overlay.remove=function(){$(this).animate({opacity:0},300,function(){$(this).remove()})};return overlay},tooltip:function(parent){$.J.tooltip(parent)},parseUri:function(str){var o=parseUri.options,m=o.parser[o.strictMode?"strict":"loose"].exec(str),uri={},i=14;while(i--)uri[o.key[i]]=m[i]||"";uri[o.q.name]={};uri[o.key[12]].replace(o.q.parser,function($0,$1,$2){if($1)if($1.substring($1.length-2)=="[]"){if(uri[o.q.name][$1]===undefined)uri[o.q.name][$1]= [];uri[o.q.name][$1].push($2)}else uri[o.q.name][$1]=$2});return uri},createUri:function(uri){var str="";if(uri.protocol)str+=uri.protocol+"://";if(uri.host)str+=uri.host;if(uri.path)str+=uri.path;if(uri.queryKey){str+="?";for(var i in uri.queryKey)if(typeof uri.queryKey[i]=="object")for(var m in uri.queryKey[i])str+=i+"="+uri.queryKey[i][m]+"&";else str+=i+"="+uri.queryKey[i]+"&"}return str},load_js:function(url){var found=false;$("head > script").each(function(){if($(this).attr("src")==url){found= true;return false}});if(!found){var head=document.getElementsByTagName("head")[0]||document.documentElement;var script=document.createElement("script");script.src=url;head.insertBefore(script,head.firstChild)}},load_css:function(url,options){var found=false;$("head > link").each(function(){if($(this).attr("href")==url){found=true;return false}});if(!found)if(options){var link_string='").appendTo($("head"))})}else $('').appendTo($("head"))},inline_open:function(url,container,overlay_elm){if(container.attr("rel")==url)return;var overlay;if(overlay_elm)overlay=Mindshark.overlay({container:overlay_elm});var show=function(){container.attr("rel",url).hide().load("/inline"+url,function(){container.slideDown();if(overlay)overlay.remove()})};if(container.is(":visible"))container.slideUp(show); else show()},inline_close:function(container){$.J.inline.close(container)}};$(function(){$.J.tooltip()});function _(str){return str}function str_repeat(i,m){for(var o=[];m>0;o[--m]=i);return o.join("")} function sprintf(){var i=0,a,f=arguments[i++],o=[],m,p,c,x,s="";while(f){if(m=/^[^\x25]+/.exec(f))o.push(m[0]);else if(m=/^\x25{2}/.exec(f))o.push("%");else if(m=/^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)){if((a=arguments[m[1]||i++])==null||a==undefined)throw"Too few arguments.";if(/[^s]/.test(m[7])&&typeof a!="number")throw"Expecting number but found "+typeof a;switch(m[7]){case "b":a=a.toString(2);break;case "c":a=String.fromCharCode(a);break;case "d":a=parseInt(a); break;case "e":a=m[6]?a.toExponential(m[6]):a.toExponential();break;case "f":a=m[6]?parseFloat(a).toFixed(m[6]):parseFloat(a);break;case "o":a=a.toString(8);break;case "s":a=(a=String(a))&&m[6]?a.substring(0,m[6]):a;break;case "u":a=Math.abs(a);break;case "x":a=a.toString(16);break;case "X":a=a.toString(16).toUpperCase();break}a=/[def]/.test(m[7])&&m[2]&&a>=0?"+"+a:a;c=m[3]?m[3]=="0"?"0":m[3].charAt(1):" ";x=m[5]-String(a).length-s.length;p=m[5]?str_repeat(c,x):"";o.push(s+(m[4]?a+p:p+a))}else throw"Huh ?!"; f=f.substring(m[0].length)}return o.join("")}var parseUri={options:{strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}}};