function makeOneOfficeDetailDiv(full)
{		
	// The div that contains the details
	var div = document.createElement('div');

	// Company name
	if(defined(full.n))
	{
		var h1 = document.createElement('h1');
		h1.appendChild(document.createTextNode(full.n));
		div.appendChild(h1);
	}
	if(defined(full.n2))
	{
		var h1 = document.createElement('h3');
		h1.appendChild(document.createTextNode(full.n2));
		div.appendChild(h1);
	}
	if(defined(full.n3))
	{
		var h1 = document.createElement('h3');
		h1.appendChild(document.createTextNode(full.n3));
		div.appendChild(h1);
	}
	// Office Type
	if(defined(full.o))
	{
		var p = document.createElement('div');
		p.appendChild(document.createTextNode(full.o));
		setClass(p,'officetype');
		div.appendChild(p);
	}
	div .appendChild(document.createElement('hr'));
	// Adding the services
		var ser = document.createElement('div');
		setClass(ser,'businessfunctions');

		var p = document.createElement('p');
		p.appendChild(document.createTextNode('Services: '));

		if(defined(full.s))
		{
			var b = document.createElement('b');
			b.appendChild(document.createTextNode(" "+returnVars(full.s)));
			p.appendChild(b);
			if(returnVars(full.s)!="")
			{
				ser.appendChild(p);
				div.appendChild(ser);
				div.appendChild(document.createElement('hr'));
			}
		}
		var x=0;
		// Adding the business functions
		var fun = document.createElement('div');
		setClass(fun,'officefunctions');

		var p = document.createElement('p');
		p.appendChild(document.createTextNode('Business Functions:'));
		var b = document.createElement('b');
		b.appendChild(document.createTextNode(" "+returnVars(full.f)));
		p.appendChild(b);
		if(returnVars(full.f)!="")
		{
			fun.appendChild(p);
			div.appendChild(fun);
			div .appendChild(document.createElement('hr'));
		}

	var addressinfo = document.createElement('div');
	setClass(addressinfo,'addressinfo');
	///////////////////////////////////////////////////////////////////////
	if(defined(full.postal))
	{
		// create div for address information etc.


		// Postal address
		var info = document.createElement('div');
		addressinfo.appendChild(info);
		setClass(info,'info');

		var h3 = document.createElement('em');
		h3.appendChild(document.createTextNode('› Postal Address'));
		info.appendChild(h3);

 
		var t = "";
		if(defined(full.n))
			t+= '<b>'+ full.n + '</b>';
		if(defined(full.n2))
			t+= '<br/><b>'+ full.n2 + '</b>';
		if(defined(full.n3))
			t+= '<br/><b>'+ full.n3 + '</b>';

		if(defined(full.postal.a))
		{
			t+='<br/>'+full.postal.a;
		}

		if(defined(full.postal.z))
			if(t!="")
			{
				t+='<br/>'+full.postal.z;
			}


		if(defined(full.postal.c))
		{
			// Only add a linebreak if zip is NOT defined
			if (!defined(full.postal.z && t!=""))
				t+='<br/>';
			
			t+=" " + full.postal.c;
			
		}
		if(defined(full.postal.s) && full.postal.s!="")
		{
			t+='<br/>'+full.postal.s;
		}
		if(defined(full.cn))
		{
			if(t!="")
			{
				t+='<br/>'+full.cn;
				
			}	
		}
		if(t!="")
		{
			var p = document.createElement('p');
			p.innerHTML=t;
			info.appendChild(p);
		}
		div.appendChild(addressinfo);
	}
	
///////////////////////////////////////////////////////////////////////
	// Here visitor address starts
	if(defined(full.visitor))
	{
		// Visitor address
		var info = document.createElement('div');
		addressinfo.appendChild(info);
		setClass(info,'info');


		var h3 = document.createElement('em');
		h3.appendChild(document.createTextNode('› Visiting Address'));
		info.appendChild(h3);

		var t = "";
		if(defined(full.n))
			t = '<b>'+ full.n + '</b>';
		if(defined(full.n2))
			t+= '<br/><b>'+ full.n2 + '</b>';
		if(defined(full.n3))
			t+= '<br/><b>'+ full.n3 + '</b>';
			

		if(defined(full.visitor.a))
			if(t!="")
				t+='<br/>'+full.visitor.a;

		if(defined(full.visitor.z))
			if(t!="")
				t+='<br/>'+full.visitor.z;

		if(defined(full.visitor.c))
		{
			// Only add a linebreak if zip is NOT defined
			if (!defined(full.visitor.z && t!=""))
				t+='<br/>';
			
			t+=" " + full.visitor.c;
		}
		
		if(defined(full.visitor.s) && full.visitor.s!="")
		{
			t+='<br/>'+full.visitor.s;
		}
		
		if(defined(full.cn))
		{
			if(t!="")
				t+='<br/>'+full.cn;

		}


		if(t!="")
		{
			var p = document.createElement('p');
			p.innerHTML=t;
			info.appendChild(p);
		}
		div.appendChild(addressinfo);


	}

	if(defined(full.contact))
	{
		// NEW contact info begins
		// Contact info
		var info = document.createElement('div');
		addressinfo.appendChild(info);
		setClass(info,'info');
	
		
		var h3 = document.createElement('em');
		h3.appendChild(document.createTextNode('› Contact info'));
		info.appendChild(h3);
	
		var contacts = full.contact;
	
		// There are 0,1 or 2 fields in contacts {1: 
		var num_contacttypes  = 0
		for (var key in contacts)
		{
			num_contacttypes++;
			if(num_contacttypes==2)
			{
				// Insert a blanc line in the output
				var span = document.createElement('span');
				span.appendChild(document.createElement('br'));
				var p = document.createElement('p');
				p.appendChild(span);
				info.appendChild(p);
			}
			var contacttypes = contacts[key]
			for (var key2 in contacttypes)
			{
				var name = key2;
				var value= contacttypes[key2]
							
				var span = contactinformation(name,value); 			
				var p = document.createElement('p');
				p.appendChild(span);
				info.appendChild(p);
			}
		}
	}

	if(	defined(full.note))
	{

		// Office note
		var info = document.createElement('div');
		addressinfo.appendChild(info);
		setClass(info,'info');


		var h3 = document.createElement('em');
		h3.appendChild(document.createTextNode('› Office Note'));
		info.appendChild(h3);

		var h5 = document.createElement('p');
		h5.innerHTML=full.note;
		info.appendChild(h5);

		div.appendChild(addressinfo);
	}
	///////////////////////////////////////////////////////////////////////
//	div .appendChild(document.createElement('hr'));

	// create div for additional contact info etc.
	var contactinfo = document.createElement('div');
	setClass(contactinfo,'contactinfo');

	if(defined(full.s))
	{
		var services = full.s;
		for (var key in services)
		{
			var info = document.createElement('div');
			setClass(info,'info');
	
			var h3 = document.createElement('h4');
			var b = document.createElement('b');
			h3.appendChild(b);
			b.appendChild(document.createTextNode("› "+key));
			var added=false
			var addedp=false
			var service = services[key];
			var span = document.createElement('span');
			for (var subkey in service)
			{
				if(!added)
				{
					added=true;
					info.appendChild(h3);
				}
				if(addedp)
				{
					span.appendChild(document.createElement('br'));
				}
				addedp=true;
	
				var span = contactinformation(subkey,service[subkey]);
				var p = document.createElement('p');
				p.appendChild(span);
				info.appendChild(p);
			}
			if(addedp)
				contactinfo.appendChild(info);	// Only add it to the dom if it contains info.	
				
		}
	}
	// Here, the business functions must be added	
	if(defined(full.f))
	{
		var businesses = full.f;
		for (var key in businesses)
		{
			var info = document.createElement('div');
			setClass(info,'info');
	
			var h3 = document.createElement('h4');
			var b = document.createElement('b');
			h3.appendChild(b);
			b.appendChild(document.createTextNode("› "+key));
			var added=false
			var addedp=false
			var business = businesses[key];
			var span = document.createElement('span');
			for (var subkey in business)
			{
				if(!added)
				{
					added=true;
					info.appendChild(h3);
				}
				if(addedp)
				{
					span.appendChild(document.createElement('br'));
				}
				addedp=true;
				if(subkey == "Email" || subkey == "E-mail")
				{
					var a = document.createElement('a');
					a.href="mailto:"+business[subkey];
					a.innerHTML=business[subkey];
					span.appendChild(document.createTextNode(subkey+" : "));
					span.appendChild(a);
				}
				else
				{
					span.appendChild(document.createTextNode(subkey+" : "+business[subkey]));
				}
				var p = document.createElement('p');
				p.appendChild(span);
				info.appendChild(p);
			}
			if(addedp)
				contactinfo.appendChild(info);	// Only add it to the dom if it contains info.	
		}
	}
	div.appendChild(contactinfo);
	return div;
}

function printProps(obj, objName) {
  var output = "" ;
  for (var prop in obj) {
    output += objName + "." + prop + " = " + obj[prop] + "\n" ;
  }
  alert( output );
}

function defined(object){
	if(typeof(object)=="undefined")
		return false;
	else
		return true;
}
function setClass(element,clName)
{
	if (navigator.appName=="Microsoft Internet Explorer")
		element.className=clName;
	else
		element.setAttribute("class",clName);
}
function returnVars(obj)
{
	var s="";
	var first = true;
	if(typeof(obj)=="string")
		s = obj;
	else
		for (var key in obj)
		{
			if(first)
			{
				s += key;
				first=false;
			}
			else
				s += ", "+ key;
		}
	return s;
}

function contactinformation(name,value){
	var span = document.createElement('span');
	if(isURL(value))
	{
		var a = document.createElement('a');
		if (value.substr(1,5)!="http:")	// prepend http:// 
			a.href="http://"+value;
		else
			a.href=value;
		
		a.innerHTML=value;
		span.appendChild(document.createTextNode(name+" : "));
		span.appendChild(a);
	}
	else if(isEmail(value))
	{
		var a = document.createElement('a');
		a.href="mailto:"+value;
		a.innerHTML=value;
		span.appendChild(document.createTextNode(name+" : "));
		span.appendChild(a);
	}
	else
		span.appendChild(document.createTextNode(name+" : "+value));

	return span;
}			

// protocal is optional.
function isURL(string){
    if(!string) return false;
    string = string.toLowerCase();
    urlRegExp = /^((((ht|f)tp(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/
    return urlRegExp.test(string);
}

function isEmail(string){
    emailRegExp = /^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.([a-z]){2,4})$/
    return emailRegExp.test(string);
}
