# ****************************************************************************
# Surgeweb - Extension customisation Javascript
# ----------------------------------------------------------------------------
# This mechanism is still incomplete and subject to change
#
# ****************************************************************************

# This gets called from main initialisation code to apply our javascript
# "Early" javascrip initialisation
function js_extend_init_early()
{
#	Remove the top border on the footer onthe main page
	if(false){
		util_body_style=enBody3;
		tweaks.cch['plain']++;
	}	
}

#  based interface extension functionality if we are expected to do so
function js_extend_init_late(){

# 	New plain panel up the top left with arbitrary content
	if(false){
		var content='<div title="Example tooltip over panel"> '+
				'My own domain based customisable pane!!! '+
				'with any html eg. <a href="http://netwinsite.com" target="_popup"> links</a>, '+
				'<span style="color:red" title="">text</span>, latest news, system info etc.</div>';
		new_panel_basic(content,'top');
	}


# 	New plain panel at bottom taking content from system / global / domain defs files 
# 	  (just reusing the footer defs variable as an example)
	if (false){
		new_panel_basic('||footer||','bottom');
	}


#	New fancy panel at the bottom with title and body text. Again can have anything in it
	if (false){
		new_panel_fancy('My own panel header', 'Fancy panel body with anything in it','bottom');
	}

#	New fancy panel at the bottom with live maps as an example
	if (||iftrue(example_extension)||true||else||false||endif||){
		var content='<iframe id="a_map" src="http://wikimapia.org/s/#lat=-40.7805414&lon=173.8476563&z=4&l=0&m=a&v=1" width="'+lc_width()+
					'" height="200" frameborder="0" style="background:||lpanel_color||"></iframe>';
		new_panel_fancy('Wikimapia!! <i><a href="http://wikimapia.com" target="_popup">link</a></i>',content,'bottom',true);
	}

#	New fancy panel at the bottom with youtube content as an example
	if (false){
		var content='<object width="'+lc_width()+'" height="200"><param name="movie" value="http://www.youtube.com/v/Pfs4Rd5f_IQ&hl=en&fs=1"></param>'+
					'<param name="allowFullScreen" value="true"></param>'+
					'<embed src="http://www.youtube.com/v/Pfs4Rd5f_IQ&hl=en&fs=1" type="application/x-shockwave-flash" allowfullscreen="true"'+
					' width="'+lc_width()+'" height="200"></embed></object>';
		new_panel_fancy('Youtube!!',content,'bottom',true);
	}


# 	Add a right comlumn too
	if(false){
		right_column=126;
		var x=document.getElementById('right_column');
		class_remove(x,'hidden');
# 		... and maybe change the content to whatever...
#		x.innerHTML='The quick brown fox jumped over the lazy dog';
	}
	
# 	Use alternative application menu and move it to the top of the page
	if(false){
		move_panel_to_top('app_menu')
		alternate_menu();
	}

# 	Change the panelisation style on one particular page "panel"
#	Remove the top border on the footer onthe main page
	if(false){
		panelise_plain(panelise_undo(dge('messages')),enBody3);
		tweaks.cch['plain']++;
	}	

# 	Hook the usercgi dialog function to do some of our own handling instead
	if(false){
		hook_user_cgi_dlg(); 
	}
}

# Store original function and replace with your own one. In this case do your own action if it was the password button
var user_cgi_dlg_orig;
function hook_user_cgi_dlg()
{
	user_cgi_dlg_orig=user_cgi_dlg;
	user_cgi_dlg=function(type){
		if (type=='password'){

#			Customise these to suit your site appropriate
			var url='https://yourserver.com/public/changepass.aspx';
			var dlg_title='Dialog title text';

#			Open as a new popup window
#			open_popup2(url);

#			OR

#			Open as a "dialog" much like the user.cgi functionality (hence no problems with popup bockers)
			x_custom_dlg2(dlg_title,dialog_iframe(url),function(btn){ie_fixfocus();	dlg_reset();}, U, {'tall':true,'width':0.9});
			
			return;
		}
		user_cgi_dlg_orig(type);
 	 }
}


function js_extend_resize(size)
{
  ||iftrue(example_extension)||
	dge('a_map').width=px(size);
  ||endif||
}


# ****************************************************************************
# Additional custom functionality
# ****************************************************************************
var panel_borders= ||if(equal(panel_mode,(none)))||0||endif|| ||if(equal(panel_mode,(plain)))||1||endif||  ||if(equal(panel_mode,(orig)))||2||endif||;
function lc_width(){
#	alert("foo"+(panel_mode=='orig'?2:0));
	return pref.sizer1-||panel_gap||-panel_borders;
}

function alternate_menu(){
	var x=dge('app_menu');
	panelise_undo(x);
	x.className="";
	x.id="xapp_menu";
	x.style.background="none";
	x.style.height="115px";
	x.innerHTML=
			 '<div id="AppMenuPane" class="big">'
			+'  <a id="XMail" class="mbtn" title="Email" href="#" onclick="app_menu(\'mail\')"></a>'
			+'  <a id="XContacts" class="mbtn" title="Address book" onclick="app_menu(\'contacts\')"></a>'
			+'  <a id="XCalendar" class="mbtn" title="Calendar" onclick="app_menu(\'calendar\')"></a>'
			+'  <a id="XPhotos" class="mbtn" title="Your photographs" onclick="app_menu(\'photos\')"></a>'
			+'  <a id="XBlogs" class="mbtn" title="Blogs" onclick="app_menu(\'blogs\')"></a>'
			+'  <a id="XFiles" class="mbtn" title="Your Surgeplus shared files" onclick="app_menu(\'photos\')"></a>'
			+'</div>';
}

function move_panel_to_top(id)
{
	juggle_ui(id,'lpanel_hdr');
}


# ****************************************************************************
# ignore stuff below here... Still testing

#	el=document.getElementById("adv_behaviour")
#	if (el) el.innerHTML="Set from javascript";
#	if (!document.isajax) return;
	
#	oldM=M;	M=myM;	 // Hook the M function
#	juggle_ui("app_menu","lpanel_hdr");
#	var a=new_anchor_before("foobar", "contacts");
#	a.className="left_pane";
#	a.innerHTML='<div style="background:white">my own domain based <br> customisable based pane!!!</div>';
#	panelise_round(a,enBoth);

#function myM(item)
#{
#	alert("my own message submission calling the orig function :-)");
#	oldM(item);
#}
#var oldM;



