// Validate the entry address
function removeDefaultValue(formobject,defaultvalue)
{
	var formvalue = formobject.value;
	if (formvalue == defaultvalue) formobject.value = '';
	
	return true;
}

	
// Validate the entry address
function validateAddress(zip,city,alertmsg)
{
	if (zip.length < 2 && city.length < 3 ) 
	{
		alert(alertmsg);
		if (document.getElementById("alertmsg"))
		{
			document.getElementById("alertmsg").innerHTML = alertmsg;
			document.getElementById("alertmsg").style.display = "block";
		}
		return false;
	}
	return true;
}

// variables that require to become filled in "onLoad" event
// var lastWidth;
// var lastHeight;
// var map24ReloadURL;
function getDocumentWidth()
{
	try {
		if( window.innerWidth && typeof( window.innerWidth ) == 'number' ) 
		{	//Non-IE
		return window.innerWidth;
		} else if (document.innerWidth && typeof (document.innerWidth) == 'number')
		{
			return document.innerWidth;
		} else if( document.documentElement &&
  			 ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{//IE 6+ in 'standards compliant mode'
			return document.documentElement.clientWidth;
			} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
			{//IE 4 compatible		
		if (typeof(document.body.clientWidth) == 'undefined')
				return document.body.offsetWidth;
			else
				return document.body.clientWidth;
		}
	} catch (e)
	{
		//alert (e.message);
		donothing();
	}		
}

function getDocumentHeight()
{
	try {
		if( window.innerHeight && typeof( window.innerHeight ) == 'number' ) 
		{	//Non-IE
		return window.innerHeight;
		} else if (document.innerHeight && typeof (document.innerHeight) == 'number')
		{
			return document.innerHeight;
		} else if( document.documentElement &&
  			 ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) 
		{//IE 6+ in \'standards compliant mode\'
			return document.documentElement.clientHeight;
		} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) 
		{//IE 4 compatible
            if (typeof(document.body.clientHeight) == 'undefined')
				return document.body.offsetHeight;
            else
				return document.body.clientHeight;
		}
	} catch (e)
	{
		//alert (e.message);
		donothing();
	}		
}

function resizePage()
{
	var currentdate = new Date();
	var urlArguments = 	"&windowWidth="+getDocumentWidth()+
						"&windowHeight="+getDocumentHeight()+
						"&resized=1&t="+currentdate.getTime();
	// if the page is resizeable and the width of the document is not correct, then reload 
	// the page to be able to resize the applet
	try {
		eval("parent."+map24TargetURL+".location.href = '"+map24ReloadURL + urlArguments+"';");
	} catch (e)
	{
		try {
			eval(map24TargetURL+".location.href = '"+map24ReloadURL + urlArguments+"';");
		} catch (e) 
		{
			//alert (e.message);
			donothing();
		}	
	}	
}

// function do nothing!
function donothing()
{
}

// check for page resize
function checkPageForResize(_parent)
{
        //alert(getDocumentWidth()+"+"+lastWidth+"+"+lastHeight+"+"+getDocumentHeight());
    if (typeof(_parent) == "undefined") _parent = 0;
	if (typeof(lastWidth) == "undefined") lastWidth = 0;
	if (typeof(lastHeight) == "undefined") lastHeight = 0;
	
	var currentWidth = getDocumentWidth();
	var currentHeight = getDocumentHeight();
	
	var tolerance = 30;
	var minLastWidth = parseInt(lastWidth) - parseInt(tolerance);
	var maxLastWidth = parseInt(lastWidth) + parseInt(tolerance);
	var minLastHeight = parseInt(lastHeight) - parseInt(tolerance);
	var maxLastHeight = parseInt(lastHeight) + parseInt(tolerance);
	
	try {
		parent._init = 0;
    	parent.lastWidth = currentWidth;
    	parent.lastHeight = currentHeight;
	} catch (e)
	{
		_init = 0;
		lastWidth = currentWidth;
		lastHeight = currentHeight;
	}
	
	if ( (currentWidth < minLastWidth || 
		  currentWidth > maxLastWidth) || 
		 (currentHeight < minLastHeight || 
		  currentHeight > maxLastHeight) )
  	{
  		resizePage();
	} 
}

// businessMap24 Easy Control Object
function bmeCtrl()
{
	// Map24 Control Object
	var m24Ctrl 	= "NULL";
	var width 	= 2526;
	var centerWidth = 300;
	var locMarker   = 20944;
	var sLocMarker  = 20943;
	var dLocMarker  = 20945;	
	
	var zoom  = new Array('IN','OUT');
	var navigation  = new Array('BACK','FORWARD','HOME');
	
	this.bmeCtrl 	= _bmeCtrl;
	this.setControl	= _setControl;
	
	this.move					= _move;
	this.zoom					= _zoom;
	this.centerTo 				= _centerTo;
	this.addCenterTo			= _moveCenterTo;
	this.showRouteDestination	= _showRouteDestination;
	this.showRouteSegment		= _showRouteSegment;
	this.appendLink				= _appendLink;
	this.addArgument			= _addArgument;
	this.switchMetricDisplayer	= _switchMetricDisplayer;
	
	// Constructor for bmeCtrl
	function _bmeCtrl(map24Control)
	{
		if (!map24Control) return false;
		this.m24Ctrl = map24Control;
		
		return;
	}
	
	// Constructor for bmeCtrl
	function _setControl(map24Control)
	{
		if (!map24Control) return false;
		this.m24Ctrl = map24Control;
		
		return;
	}

	// Add argument
	function _addArgument(name,value)
	{
		this.m24Ctrl.addArgument(name,value);		
		return;
	}
	
	// Constructor for bmeCtrl
	function _appendLink(URL)
	{
		this.m24Ctrl.appendLink(URL);		
		return;
	}
	
	// Move to direction
	function _move(direction)
	{
		if (this.m24Ctrl == "NULL") return;
		this.m24Ctrl.move(navigation[direction]);
		this.m24Ctrl.commit();
	}
	
	// Zoom type
	function _zoom(type)
	{
		if (this.m24Ctrl == "NULL") return;
		this.m24Ctrl.zoom(zoom[type]);
		this.m24Ctrl.commit();
	}
	
	// Move Locations
	function _centerTo(locid,x,y,desc,logo)
	{
		if (this.m24Ctrl == "NULL") return;
		
		//this.m24Ctrl.addLocation(locid,x,y,desc,logo,locMarker);
		//this.m24Ctrl.groupAddObject("contents",locid);
		//this.m24Ctrl.show("contents");
		//this.m24Ctrl.centerAbove(locid,width);
		
		this.m24Ctrl.moveTo(x,y,centerWidth);
		this.m24Ctrl.commit();
		loadScreen(1);		
		
		return;
	}
		// Move Locations
	function _moveCenterTo(locid,x,y,desc,logo)
	{
		if (this.m24Ctrl == "NULL") return;
		
		this.m24Ctrl.addLocation(locid,x,y,desc,logo,locMarker);
		this.m24Ctrl.groupAddObject("contents",locid);
		this.m24Ctrl.show("contents");
		this.m24Ctrl.centerAbove(locid,width);
		this.m24Ctrl.commit();
		loadScreen(1);		
		
		return;
	}
	
	// Set Destination Flag
	function _showRouteDestination(locid,x,y,desc,symbol)
	{
		if (this.m24Ctrl == "NULL") return;
		
		this.m24Ctrl.addLocation(locid,x,y,desc,null,symbol);
		this.m24Ctrl.groupAddObject("contents",locid);
		this.m24Ctrl.show("contents");
		this.m24Ctrl.centerAbove(locid,width);
		
		//this.m24Ctrl.show(locid);
		//this.m24Ctrl.centerAbove(locid,this.width);
		this.m24Ctrl.commit();
		loadScreen(1);		
		
		return;
	}

	// Set Section / Segment
	function _showRouteSegment(loc1,x1,y1,desc1,sym1,loc2,x2,y2,desc2,sym2)
	{
		if (this.m24Ctrl == "NULL") return;
		var group = loc1+"|"+loc2;

		this.m24Ctrl.addLocation(loc1,x1,y1,desc1,null,sLocMarker);
		this.m24Ctrl.addLocation(loc2,x2,y2,desc2,null,dLocMarker);

		this.m24Ctrl.groupAddObject("contents",group);
		this.m24Ctrl.show("contents");
		this.m24Ctrl.centerAbove(group,0,98);
		this.m24Ctrl.commit();
		loadScreen(1);		

		return;
	}
	
	// Wrapper Command to switch the metric display
	// Applet:
	// &cmd0=SHOWCOMPONENT&component0=MRC&key0:0=METRIC_DISPLAY&value0:0=false
	// execute("MOV", "&nav?=NORTH");
	// MGI:
	// &prop:distanceunit=english (Miles)
	// &prop:distanceunit=metric  (Metric)	
	function _switchMetricDisplayer(maptype,metric)
	{
		if (this.m24Ctrl == "NULL") return;
		switch (maptype)
		{
			case "JAVA": 
				if (metric == "N")
					this.m24Ctrl.execute("SHOWCOMPONENT","&component?=MRC&key?:0=METRIC_DISPLAY&value?:0=false");
				else
					this.m24Ctrl.execute("SHOWCOMPONENT","&component?=MRC&key?:0=METRIC_DISPLAY&value?:0=true");
					
				this.m24Ctrl.commit();
			break;
			default: 
				if (metric == "N")
					this.m24Ctrl.addArgument("prop:distanceunit","english");
				else
					this.m24Ctrl.addArgument("prop:distanceunit","metric");
			break;
		}
	}
}	


