/* Replaces variables enlcosed by { and } 
 * with the respective values of the properties of object o
 */
String.prototype.supplant = function (o) {
	return this.replace(/{([^{}]*)}/g,
		function (s, m) {
			var r = o[m];
			return (typeof r === 'string') ? r : '';
		}
	);
}

// Namespace for the downloads list
download_list = function () {
	// Releases arrays
	var kits = [{"distro_id":"11","title":"AXIGEN Mail Server 7.5.0 for Windows","distro_name":"Windows","distro_desc":"For Microsoft Windows Server 2003\/2008","icon":"win32.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"Axigen-7.5.0.msi","filesize":"113450","download_time":"30","seolink":"axigen-mail-server-750-for-windows","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"50","title":"AXIGEN Mail Server 7.5.0 for Windows x64","distro_name":"Windows x64","distro_desc":"For Microsoft Windows Server 2008","icon":"win64.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"Axigen_x64-7.5.0.msi","filesize":"116014","download_time":"30","seolink":"axigen-mail-server-750-for-windows-x64","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"1","title":"AXIGEN Mail Server 7.5.0 for RPM based distros","distro_name":"RPM based distros","distro_desc":"For RedHat Enterprise Linux 4 and 5, SUSE Linux Enterprise 10 and 11, CentOS 4 and 5, Fedora 12 and 13, OpenSUSE 11.2 and 11.3","icon":"rpm.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.rpm.run","filesize":"109926","download_time":"29","seolink":"axigen-mail-server-750-for-rpm-based-distros","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"56","title":"AXIGEN Mail Server 7.5.0 for RPM based distros x64","distro_name":"RPM based distros x64","distro_desc":"For RedHat Enterprise Linux 5, SUSE Linux Enterprise 11, CentOS 5","icon":"rpm64.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.x86_64.rpm.run","filesize":"111373","download_time":"29","seolink":"axigen-mail-server-750-for-rpm-based-distros-x64","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"5","title":"AXIGEN Mail Server 7.5.0 for Ubuntu","distro_name":"Ubuntu","distro_desc":"For Ubuntu Server 8.04 LTS and 10.04 LTS","icon":"ubuntu.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.deb.run","filesize":"109713","download_time":"29","seolink":"axigen-mail-server-750-for-ubuntu","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"4","title":"AXIGEN Mail Server 7.5.0 for Debian","distro_name":"Debian","distro_desc":"For Debian 5.0","icon":"deb.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.deb.run","filesize":"109713","download_time":"29","seolink":"axigen-mail-server-750-for-debian","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"15","title":"AXIGEN Mail Server 7.5.0 for Mandriva Linux","distro_name":"Mandriva Linux","distro_desc":"For Mandriva Enterprise Server 5","icon":"mdk.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.rpm.run","filesize":"109926","download_time":"29","seolink":"axigen-mail-server-750-for-mandriva-linux","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"53","title":"AXIGEN Mail Server 7.5.0 for FreeBSD 8.x","distro_name":"FreeBSD 8.x","distro_desc":"","icon":"freebsd-5.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.freebsd8.run","filesize":"24658","download_time":"6","seolink":"axigen-mail-server-750-for-freebsd-8x","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"47","title":"AXIGEN Mail Server 7.5.0 for FreeBSD 7.x","distro_name":"FreeBSD 7.x","distro_desc":"","icon":"freebsd-3.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.freebsd7.run","filesize":"25225","download_time":"7","seolink":"axigen-mail-server-750-for-freebsd-7x","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"13","title":"AXIGEN Mail Server 7.5.0 for Solaris 10 x86","distro_name":"Solaris 10 x86","distro_desc":"","icon":"solaris.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.i386.solaris.run","filesize":"35862","download_time":"9","seolink":"axigen-mail-server-750-for-solaris-10-x86","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"18","title":"AXIGEN Mail Server 7.5.0 for Solaris 10 SPARC","distro_name":"Solaris 10 SPARC","distro_desc":"","icon":"solaris.gif","product_id":"1","product_name":"AXIGEN Mail Server","description":"","type":"1","filename":"axigen-7.5.0.sparc.solaris.run","filesize":"45537","download_time":"12","seolink":"axigen-mail-server-750-for-solaris-10-sparc","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"}];
	var additionals = {"4":[{"distro_id":"11","title":"AXIGEN Outlook Connector 7.5.0 for Windows","distro_name":"Windows","distro_desc":"For Windows XP Professional x86 SP3,  Windows Vista Business SP2 and Windows 7 with Outlook 2007\/SP2 and 2010","icon":"win32.gif","product_id":"4","product_name":"AXIGEN Outlook Connector","description":"Implements most Exchange-like features, including server-side Search Folders which enables users to easily locate messages based on various filters.","type":"2","filename":"Axiolk-7.5.0.msi","filesize":"12236","download_time":"3","seolink":"axigen-outlook-connector-750-for-windows","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"}],"7":[{"distro_id":"11","title":"Axigen OpenLDAP Schema 7.5.0","distro_name":"Windows","distro_desc":"For OpenLDAP 2.4.x","icon":"win32.gif","product_id":"7","product_name":"Axigen OpenLDAP Schema","description":"","type":"2","filename":"axigen-openldap-schema-7.5.0.tgz","filesize":"5","download_time":"0","seolink":"axigen-openldap-schema-750","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"}],"6":[{"distro_id":"11","title":"Axigen Active Directory Extension 7.5.0 for Windows","distro_name":"Windows","distro_desc":"For Windows 2003 SP2, Windows 2008 SP2","icon":"win32.gif","product_id":"6","product_name":"Axigen Active Directory Extension","description":"","type":"2","filename":"AxiAdExt32-7.5.0.msi","filesize":"4280","download_time":"1","seolink":"axigen-active-directory-extension-750-for-windows","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"},{"distro_id":"50","title":"Axigen Active Directory Extension 7.5.0 for Windows x64","distro_name":"Windows x64","distro_desc":"For Windows 2003 SP2, Windows 2008 SP2, Windows 2008 R2","icon":"win64.gif","product_id":"6","product_name":"Axigen Active Directory Extension","description":"","type":"2","filename":"AxiAdExt64-7.5.0.msi","filesize":"5164","download_time":"1","seolink":"axigen-active-directory-extension-750-for-windows-x64","release_type_id":"1","release_type_name":"Commercial","version":"7.5.0"}]};
	var parallels = [{"distro_id":"1","title":"Virtuozzo EZ Template 1.0 - Axigen for CentOS 5","distro_name":"RPM based distros","distro_desc":"For RedHat Enterprise Linux 4 and RHEL5, SUSE Linux Enterprise 10 and SLES11, CentOS 4.x and 5.x, Fedora 11 and 12, OpenSUSE 11.0, 11.1 and 11.2","icon":"rpm.gif","product_id":"5","product_name":"Virtuozzo EZ Template","description":"","type":"1","filename":"axigen-centos-5-x86-ez-1.0-1.noarch.rpm","filesize":"3","download_time":"0","seolink":"virtuozzo-ez-template-10---axigen-for-centos-5","release_type_id":"1","release_type_name":"Commercial","version":"1.0"},{"distro_id":"2","title":"Virtuozzo EZ Template 1.0 - Axigen for Red Hat Enterprise Linux AS 4","distro_name":"RPM based distros with gcc4","distro_desc":"For Fedora Core 4, 5 and 6, Mandriva Linux 2006.0 and 2007.0, SUSE Linux 10.x","icon":"rpm.gif","product_id":"5","product_name":"Virtuozzo EZ Template","description":"","type":"1","filename":"axigen-redhat-as4-x86-ez-1.0-1.noarch.rpm","filesize":"3","download_time":"0","seolink":"virtuozzo-ez-template-10---axigen-for-red-hat-enterprise-linux-as-4","release_type_id":"1","release_type_name":"Commercial","version":"1.0"}];
	var proddesc = {"4":{"product_name":"AXIGEN Outlook Connector","description":"Implements most Exchange-like features, including server-side Search Folders which enables users to easily locate messages based on various filters."},"7":{"product_name":"Axigen OpenLDAP Schema","description":""},"6":{"product_name":"Axigen Active Directory Extension","description":""}};
	
	// HTML templates for the table
	var top_start = '<div style="width:98%">';
	var border = '<div class="downloadsTableBottomBorder"></div>';
	var top_end = '</div>';
	var h2 = '<h2 class="subSectionTitle noBottomMargin">{title1} <span>{title2}</span></h2>';
	var table_start = '<table border="0" cellspacing="0" cellpadding="0" class="downloadsTable" width="100%">';
	var table_header = '	\
		<tr>	\
			<th align="left"><div>{header}</div></th>	\
			<th width="126px" align="center"><div>Size</div></th>	\
			<th width="98px" align="center" class="noRightBorder"><div>Type</div></th>	\
		</tr>';
	var table_end = '</table>';
	var table_colspan = '<tr><td colspan="3" class="noRightBorder">{text}</td></tr>';
	var table_row = '	\
		<tr>	\
			<td>	\
				<a href="http://www.axigen.com/mail-server/download-{seolink}.html"	title="{distro_desc}">{title}</a>	\
				<p>{distro_desc}</p>	\
			</td>	\
			<td align="center">	\
				{filesize} KB	\
				<p class="alignCenter">{download_time} min /0.5Mbps</p>	\
			</td>	\
			<td align="center" class="noRightBorder">	\
				<a href="http://www.axigen.com/mail-server/download-{seolink}.html" title="{distro_desc}">	\
					<img src="http://www.axigen.com/img/icons/distro/{icon}" alt="{distro_desc}" />	\
				</a>	\
			</td>	\
		</tr>';
	var table_space = '<div>&nbsp;</div>';
	var available_addons_row = '	\
		<tr>	\
		<th align="left"><div>Add-on Name</div></th>	\
		<th width="98px" class="noRightBorder"><div>Vendor</div></th>	\
		</tr>	\
		<tr>	\
			<td>	\
				<a href="http://www.avg.com/download-7?prd=trimsw" title="AVG Email Server Edition 8.5 for Linux" target="_blank">AVG Email Server Edition 8.5 for Linux	\
					<img href="http://www.axigen.com/img/general/external-link.gif" alt="External Link" style="margin: 0pt 2px;">	\
				</a>	\
				<p>AVG AntiVirus and AntiSpam</p>	\
			</td>	\
			<td align="center">	\
				<a href="http://www.avg.com/download-7?prd=trimsw" title="AVG Email Server Edition 8.5 for Linux" targe="_blank">	\
					<img src="http://www.axigen.com/img/icons/avg32.gif" alt="AVG Email Server 8.5 for Linux" title="More info about AVG Email Server Edition 8.5 for Linux" />	\
				</a>	\
			</td>	\
		</tr>';				
	var virtual_appliance_row = '	\
		<tr>	\
			<td>	\
				<a href="http://download.axigen.com/AXIGEN-Virtual-Appliance-1.0.zip" title="AXIGEN Virtual Appliance 1.0">AXIGEN Virtual Appliance 1.0</a>	\
			</td>	\
			<td align="center">	\
				649318 KB	\
				<p class="alignCenter">169min /0.5Mbps</p>	\
			</td>	\
			<td align="center" class="noRightBorder">	\
				<a href="http://download.axigen.com/AXIGEN-Virtual-Appliance-1.0.zip" title="AXIGEN Virtual Appliance 1.0">	\
					<img src="http://www.axigen.com/img/icons/distro/vmware-player.gif" alt="AXIGEN Virtual Appliance 1.0" />	\
				</a>	\
			</td>	\
		</tr>';
	var virtual_appliance_img = '	\
		<a href="http://www.vmware.com/products/player/" target="_blank" rel="nofollow"	title="Try now on VMware Player">	\
			<img src="http://www.axigen.com/img/vmware-try-it-now.png" alt="Try now on VMware Player" style="float:left;" />	\
		</a>	\
		<a href="http://www.vmware.com/appliances/directory/1342" target="_blank" title="More info about AXIGEN Virtual Appliance 1.0">	\
			<img src="http://www.axigen.com/img/general/buttons/more-info.png" alt="More info about AXIGEN Virtual Appliance 1.0" style="float:right;" />	\
		</a>';
	var partner_text = AXIGEN_PWK.dw_list_partner_text || '	\
		<div id="partner_text">	\
			<h3>Beta Products</h3>	\
			<p class="subSectionDescription">	\
				All AXIGEN products are available for the public first in Beta release, then as	\
				commercial releases. When entering the Beta program, products are thoroughly 	\
				tested inside our company, on different working scenarios by running regression 	\
				tests, speed tests, benchmarking, etc. We place products in Beta programs in order	\
				to verify special working environments and most of all, in order to collect suggestions	\
				from you, so please feel free to send us your opinions and	\
				<a href="http://www.axigen.com/about-us/feedback-form/" title="Feedback">feedback</a>. See our	\
				<a href="http://www.axigen.com/beta-testing/" title="Beta Testing Page">Beta testing page</a> for more details.	\
				<br />	\
				<em><strong>Note</strong>: In order to avoid potential functionality problems, we recommend you not to install beta products into production environment.</em>	\
			</p>	\
			<div class="verticalDottedLine">&nbsp;</div>	\
			<h3>Documentation</h3>	\
			<p class="subSectionDescription">	\
				For specific documentation and manuals on your version of AXIGEN Mail Server	\
				(AXIGEN User Manual, Quick Install and Config Guide, Server Side Scripting Language and more),	\
				check out the Documentation page by \
				<a href="http://www.axigen.com/mail-server/documentation.php" title="AXIGEN Mail Server Documentation Page">clicking here</a>.	\
			</p>	\
			<div class="verticalDottedLine">&nbsp;</div>	\
			<h3>Automation Tools</h3>	\
			<p class="subSectionDescription">	\
			Our support team has generated a number of Python scripts for use with AXIGEN Command Line Interface (CLI), which are meant to automate a number of tasks you may come across.	\
			<a href="http://www.axigen.com/mail-server/scripts.php" title="Automation Scripts">Click here</a> for more details	\
			</p>	\
		</div>';
			
	var html = [];
	
	function add_html(s) { html[html.length] = s; }
	
	return {
		generate_document: function () {
			add_html(top_start);
			
			// Product Kits
			add_html(h2.supplant({title1: 'Product', title2: 'Kits'}));
			add_html(table_start);
			add_html(table_header.supplant({header: 'Package Name'}));
			var kit_version = 0, i;
			for (i = 0; i < kits.length; i++) {
				if (kit_version === kits[i].version || kit_version === 0) {
					kit_version = kits[i].version;
					add_html(table_row.supplant(kits[i]));
				}
			}
			add_html(table_end + border + table_space);
			
			// Available Addons
			add_html(h2.supplant({title1: 'Available', title2: 'Addons'}));
			add_html(table_start);
			add_html(available_addons_row);
			add_html(table_end + border + table_space);
			
			// Outlook Connector
			add_html(h2.supplant({title1: 'Outlook', title2: 'Connector'}));
			add_html(table_start);
			i = 0;
			for (i in additionals) {
				if (additionals.hasOwnProperty(i)) {
					add_html(table_header.supplant({header: proddesc[i].product_name}));
					if (proddesc[i].description)
						add_html(table_colspan.supplant({text: proddesc[i].description}));
					
					var additional_version = 0, j, add = additionals[i];
					for (j = 0; j < add.length; j++) {
						if (additional_version === add[j].version || additional_version === 0) {
							additional_version = add[j].version;
							
							// Fix for Outlook Connector - display only win32 icon
							if (proddesc[i].description === 'AXIGEN Outlook Connector')
								add[j].icon = 'win32.gif';
							
							add_html(table_row.supplant(add[j]));
						}
					}
				}
			}
			if (i === 0) {
				// No additional modules for download
				add_html(table_colspan.supplant({text: "No additional modules available for download at this time"}));
			}
			add_html(table_end + border + table_space);
			
			// Parallels (+Virtual Appliance)
			add_html(h2.supplant({title1: 'Virtualization',title2: ''}));
			add_html(table_start);
			add_html(table_header.supplant({header: 'Package Name'}));
			for (i = 0; i < parallels.length; i++) {
				add_html(table_row.supplant(parallels[i]));
			}
			add_html(virtual_appliance_row);
			add_html(table_colspan.supplant({text: virtual_appliance_img}))
			add_html(table_end + border + table_space);

			add_html(partner_text + table_space);
			
			// Previous Versions Product Kits
			add_html(h2.supplant({title1: 'Previous Versions Product', title2: 'Kits'}));
			add_html(table_start);
			add_html(table_header.supplant({header: 'Package Name'}));
			for (i = 0; i < kits.length; i++) {
				if (kits[i].version !== kit_version) {
					add_html(table_row.supplant(kits[i]));
				}
			}
			add_html(table_end + border + table_space);

			// Previous Versions Additional Modules
			add_html(h2.supplant({title1: 'Previous Versions Additional', title2: 'Modules'}));
			add_html(table_start);
			i = 0;
			for (i in additionals) {
				if (additionals.hasOwnProperty(i)) {
					add_html(table_header.supplant({header: proddesc[i].product_name}));
					if (proddesc[i].description)
						add_html(table_colspan.supplant({text: proddesc[i].description}));
					
					var add = additionals[i];
					for (j = 0; j < add.length; j++) {
						if (add[j].version !== additional_version) {
							add_html(table_row.supplant(add[j]));
						}
					}
				}
			}
			if (i === 0) {
				// No additional modules for download
				add_html(table_colspan.supplant({text: "No additional modules available for download at this time"}));
			}
			add_html(table_end + border + table_space);
			
			add_html(top_end);
			// Write HTML
			document.write(html.join(''));
		}
	};
}();

// Generate HTML Table with downloads list
download_list.generate_document();
