// Copyright (C) 2007 Robert W. Clarke Consulting, all rights reserved.
// MapTron Locator 1207 see www.maptron.com for product manual

// Flash embed functions ------------------------------------------------------

function embedMapTron1207(ary_param){	
	if(ary_param['border_width'] > 0){ 
		var div_style =' style="border: '+ary_param['border_width']+'px solid '+ary_param['border_color']+';';
		div_style += 'position:relative; width:'+ary_param['width']+'px; height:'+ary_param['height']+'px; overflow:visible;"';
	} else {
		var div_style ='';
	}
	document.write('<div'+div_style+'>');
	
	var app_full_path = ary_param['app_path'];
	var ary_app_vars = new Array();

	if(hasContent(ary_param['startup_xml'])){ary_app_vars.push("sx="+escape(ary_param['startup_xml']));}
	if(ary_app_vars.length > 0){
		app_full_path += "?"+ary_app_vars.join("&");
	}
	
	document.write('<object id="MT1207" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" ');
	document.write('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" ');
	document.write('width="'+ary_param['width']+'" height="'+ary_param['height']+'" align="MIDDLE">');
	
	document.write('<param name="movie" value="'+app_full_path+'">');
	document.write('<param name=quality value="high">');
	document.write('<param name=BASE value="'+ary_param['base']+'">');
	document.write('<param name="BGCOLOR" value="'+ary_param['bg_color']+'">');
	
	document.write('<embed swliveconnect="true" name="MT1207" src="'+app_full_path+'" bgcolor="'+ary_param['bg_color']+'" quality=high ');
	
	document.write('pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" ');
	document.write('type="application/x-shockwave-flash" width="'+ary_param['width']+'" height="'+ary_param['height']+'" ');
	document.write('align="MIDDLE" base="'+ary_param['base']+'">');
	
	document.write('</embed></object>');
	document.write('</div>');
}

function hasContent(array_piece){
	try{
		if(array_piece == undefined){return false;}
		if(array_piece == "undefined"){return false;}
		if(array_piece == null){return false;}
		if(array_piece == "null"){return false;}
		if(array_piece == "default"){return false;}
		if(array_piece == ""){return false;}
		if(array_piece.length < 1){return false;}
	}catch(err){return false;}
	return true;
}

// System status functions --------------------------------------------------------------------

var MT1207_status = "pending";
function getSystemStatus(){
	if((window.MT1207)||(document.MT1207)){
		sendXML('<getstatus />');
	}
	return MT1207_status;
}

// XML functions ------------------------------------------------------------------------------

function sendXML(xml){
	if(window.MT1207){
		window.document["MT1207"].SetVariable("jxin",xml);
	}
	if(document.MT1207){
		document.MT1207.SetVariable("jxin",xml);
	}
}

// Functions called from MT1207 ---------------------------------------------------------------

function MT1207_handleEmail(email_address){
	// this function handles clicked email links, depends on module prefs
	// alert("Send email to "+email_address)
	location.href = "mailto:" + email_address;
}

function MT1207_handleLinks(link_url,link_target,caller){
	// this function handles clicked url links, depends on module prefs
	var msg = "Configure your links to appear in same window, new window, target frame, ";
	msg += "or call on a JavaScript function.";
	alert("Requested link\n"+link_url+"\n\n"+msg);
}
