/**
 * JJBW WhereWeAre Item object
 *
 * @changes 2008-09-15 / mb / created
 *
 * @copyright Copyright © 2005-2008 / CHILIBYTES Böhm & Welte GbR / www.chilibytes.com
 * @author mb
 * @version 1.0.0
 *
 * @package de.jj_bw
 * @subpackage www
 *
 */

/**
 * Namespaces
 */
if ( !window.de ) window.de = {};
if ( !de.jj_bw ) de.jj_bw = {};
if ( !de.jj_bw.www ) de.jj_bw.www = {};

var CB_ObjectContainer = com.chilibytes.ccl.cms.CB_ObjectContainer;

/**
 * Constructor
 *
 * @access public
 */
de.jj_bw.www.JJBW_WSWItem = function( itemID, name, itemContainer, itemTemplate ) {
    // Constructor
    this.constructor = de.jj_bw.www.JJBW_WSWItem;
    // Class variables
    this.fItemID = itemID;
    this.fName = name;
    this.fItemTemplate = itemTemplate;
    this.fItemContainer = itemContainer;
    this.fAddressContainer = new CB_ObjectContainer();
}

/**
 * Property to GET the news id
 *
 * @access public
 */
de.jj_bw.www.JJBW_WSWItem.prototype.IDGet = function() {
	return this.fItemID;
}

/**
 * Property to GET the name
 *
 * @access public
 */
de.jj_bw.www.JJBW_WSWItem.prototype.NameGet = function() {
	return this.fName;
}

/**
 * Property to SET the name
 *
 * @access public
 */
de.jj_bw.www.JJBW_WSWItem.prototype.NameSet = function( value ) {
	this.fName = value;
}

/**
 * Add a new address to container
 *
 * @access public
 */
de.jj_bw.www.JJBW_WSWItem.prototype.AddressAdd = function( addressObj ) {
	this.fAddressContainer.Add( addressObj );
}

/**
 * Copy data to bind object
 */
de.jj_bw.www.JJBW_WSWItem.prototype.Show = function() {
	if ( this.fAddressContainer.HasChildren() ) {
		while( this.fItemContainer.firstChild ) {
			this.fItemContainer.removeChild( this.fItemContainer.firstChild );
		}
		this.fAddressContainer.Rewind();
		// Select first address
		var officeObj = this.fAddressContainer.Next();
		var officeHTMLObj = null;
		var idPrefix = this.fItemTemplate.id;
		do {
			officeHTMLObj = this.fItemTemplate.cloneNode( true );
			officeHTMLObj.id = idPrefix + "-" + this.fAddressContainer.ObjectIndexGet( officeObj );
			for ( var i = 0; i < officeHTMLObj.childNodes.length; i++ ) {
				if ( officeHTMLObj.childNodes[i].nodeType == 1 ) {
					var objTextNode = null;
					var remChild = true;
					switch( officeHTMLObj.childNodes[i].id ) {
						case idPrefix + "-name":
							if ( officeObj.NameGet() ) objTextNode = document.createTextNode( officeObj.NameGet() );
							break;
						case idPrefix + "-name2":
							if ( officeObj.Name2Get() ) objTextNode = document.createTextNode( officeObj.Name2Get() );
							break;
						case idPrefix + "-street":
							if ( officeObj.StreetGet() ) objTextNode = document.createTextNode( officeObj.StreetGet() );
							break;
						case idPrefix + "-zip":
							if ( officeObj.ZipGet() ) objTextNode = document.createTextNode( officeObj.ZipGet() );
							break;
						case idPrefix + "-city":
							if ( officeObj.CityGet() ) objTextNode = document.createTextNode( officeObj.CityGet() );
							break;
						case idPrefix + "-telephone":
							if ( officeObj.TelephoneGet() ) objTextNode = document.createTextNode( "Tel.: " + officeObj.TelephoneGet() );
							break;
						case idPrefix + "-fax":
							if ( officeObj.FaxGet() ) objTextNode = document.createTextNode( "Fax: " + officeObj.FaxGet() );
							break;
						case idPrefix + "-email":
							if ( officeObj.EmailGet() ) {
								objTextNode = document.createElement( "a" );
								objTextNode.href = "mailto:" + officeObj.EmailGet();
								objTextNode.alt = officeObj.EmailGet();
								objTextNode.target = "_blank";
								objTextNode.appendChild( document.createTextNode( officeObj.EmailGet() ) );
							}
							break;
						default:
							objTextNode = null;
							remChild = false;
							break;
					}
					if ( objTextNode ) {
						officeHTMLObj.childNodes[i].appendChild( objTextNode );
					}
					else if ( remChild ) {
						officeHTMLObj.removeChild( officeHTMLObj.childNodes[i+1] );
						officeHTMLObj.removeChild( officeHTMLObj.childNodes[i] );
					}
				}
			}
			this.fItemContainer.appendChild( officeHTMLObj );
			// Select next address
			officeObj = this.fAddressContainer.Next();
		}
		while( officeObj )
	}
}
