//-->
/* ***********************************************************************
	UebiMiau is a GPL'ed software developed by 
	
	 - Aldoir Ventura - aldoir@users.sourceforge.net
	 - http://uebimiau.sourceforge.net
	
	Fell free to contact, send donations or anything to me :-)
	São Paulo - Brasil
	
	**********************************************
	Version 3.2.0 Upgrades and templates developed by
	 
	 - Todd Henderson - Lead Developer
	 - http://tdah.us
	 - Email: todd@tdah.us
	 
	 - Dave Rodgers - Project Consultant
	 - http://www.manvel.net 
	 - Email: Davenmanvel@inbox.com
	
	Feel free to contact us, send donations or anything to me as well...
	
	Special thanks to the developers at telaen.org, codeworxtech.com, tinymce.moxiecode.com
	without help this project wouldn't be possible 

	**********************************************
	- File:			install.js
	- Developer: 	Todd Henderson/ Mods by Laurent (AdNovea)
	- Date:			November 4, 2008
	- version:		(3.2.0) 1.0
	- Description:  Javascript functions for installation program
	JS/PHP array management is Laurent's idea and coding

************************************************************************ */

	var nb_item_profile = 6;		// Number of entries in a profile

// Tabs switching
	function SwitchSetupTab(tab) {
		// hide all
		document.getElementById('main').className='tab_hidden';
		document.getElementById('pop').className='tab_hidden';
		
		document.getElementById('smtp').className='tab_hidden';
		document.getElementById('defaults').className='tab_hidden';
		document.getElementById('security').className='tab_hidden';
		
		document.getElementById('tab_main').className='tab_info_hidden';
		document.getElementById('tab_pop').className='tab_info_hidden';
	
		document.getElementById('tab_smtp').className='tab_info_hidden';
		document.getElementById('tab_defaults').className='tab_info_hidden';
		document.getElementById('tab_security').className='tab_info_hidden';
		
		// show needed
		document.getElementById('tab_'+tab).className='tab_info_visible';
		document.getElementById(tab).className='tab_visible';
	}
	

// Serialize as string the javascript array
	function joinArray(tmp_array) {
		var content = "";
		for (var i=0; i < tmp_array.length; i++) {
			content += tmp_array[i].join(",") + ",";
		}
		if (i > 0 ) content = content.substr(0, content.length - 1);
		return content;
	}
		
// UnSerialize as javascript array the string
	function splitArray(content) {
		var tmp_array = new Array();
		var tmp = content.split(",");
		for (var i=0; i < tmp.length/nb_item_profile; i++) {
			tmp_array[i] = new  Array();
			for (var j=0; j < nb_item_profile; j++) tmp_array[i][j] = tmp[j+i*nb_item_profile]
		}
		joinArray(tmp_array);
		return tmp_array;
	}

// Check if user name and password have been set for an Admin account
// IMPORTANT: in IE named elements create automatically JS variables SO use a different ID otherwise it's already used !
	function sendData(js_msg) {
		if (!js_reinstall) {
			if (  	(document.getElementById('xusername').value == "") ||
					(document.getElementById('xpassword').value == "") ||
					(document.getElementById('xpassword').value != document.getElementById('xconfirm').value)
			) { 
				alert(js_msg);
				return;
			}
		}
		document.getElementById('cmail_servers').value = joinArray(tmp_servers);
		document.form1.submit()
	}

// Add/Remove and modify on POP servers
	function changeServers(id) {
		document.getElementById('ctmp_domain').value = tmp_servers[id][1];
		document.getElementById('ctmp_server').value = tmp_servers[id][2];
		document.getElementById('ctmp_type').value = tmp_servers[id][3];
		document.getElementById('ctmp_protocol').value = tmp_servers[id][4];
		document.getElementById('ctmp_port').value = tmp_servers[id][5];
		document.getElementById('select_server').value = id;
	}
	
	function setDefault() {
		document.getElementById('ctmp_domain').value = "domain.com";
		document.getElementById('ctmp_server').value = "localhost"; 
		document.getElementById('ctmp_type').value = "%user%@%domain%";
		document.getElementById('ctmp_protocol').value = "pop3";
		document.getElementById('ctmp_port').value = "110";
	}
	
	function addServer() {
		id = tmp_servers.length;
		tmp_servers[id] = new Array();
		for (var j=0; j < nb_item_profile; j++) tmp_servers[id][j] = "";
		listServers();
		changeServers(id);
	}
	
	function removeServer(id, js_msg) {
		if ( id == null || id == "") return;
		if (!confirm (js_msg)) return;
		var tmpArray = new Array();
		for (var i=0; i < tmp_servers.length; i++) {
			if (i != id) tmpArray[tmpArray.length] = tmp_servers[i];
		}
//		tmp_servers = new Array();
		tmp_servers = tmpArray;
		listServers();
		if (tmp_servers.length > 0) changeServers(0);
		else clearServers();
	}
	

	function addOption(selectbox,text,value ) {
		var optElt = document.createElement("option");
		optElt.text = text;
		optElt.value = value;
		selectbox.options.add(optElt);
	}

	function listServers() {
		for (var i=document.getElementById('select_server').options.length-1; i>=0; i--) {
			document.getElementById('select_server').remove(i);
		}
		for (var i=0; i < tmp_servers.length; i++) {
			addOption(document.getElementById('select_server'),i+1,i);
		}
		document.getElementById('select_server').selectedIndex = 0;
		if (tmp_servers.length < 1) {
			document.getElementById('bt_remove').style.display = 'none';
			document.getElementById('bt_update').style.display = 'none';
			document.getElementById('bt_default').style.display = 'none';
			document.getElementById('ctmp_domain').style.display = 'none';
			document.getElementById('ctmp_server').style.display = 'none';
			document.getElementById('ctmp_type').style.display = 'none';
			document.getElementById('ctmp_protocol').style.display = 'none';
			document.getElementById('ctmp_port').style.display = 'none';
		} else {
			document.getElementById('bt_remove').style.display = 'inline';
			document.getElementById('bt_update').style.display = 'inline';
			document.getElementById('bt_default').style.display = 'inline';
			document.getElementById('ctmp_domain').style.display = 'inline';
			document.getElementById('ctmp_server').style.display = 'inline';
			document.getElementById('ctmp_type').style.display = 'inline';
			document.getElementById('ctmp_protocol').style.display = 'inline';
			document.getElementById('ctmp_port').style.display = 'inline';
		}
		return tmp_servers.length;
	}
	
	function clearServers() {
		document.getElementById('ctmp_domain').value = "";
		document.getElementById('ctmp_server').value = "";
		document.getElementById('ctmp_type').value = "";
		document.getElementById('ctmp_protocol').value = "";
		document.getElementById('ctmp_port').value = "";
	}

	function updateServers(id, js_msg) {
		if ( id == null || id == "") return;
		tmp_servers[id][0] = document.getElementById('ctmp_domain').value;
		tmp_servers[id][1] = document.getElementById('ctmp_domain').value;
		tmp_servers[id][2] = document.getElementById('ctmp_server').value;
		tmp_servers[id][3] = document.getElementById('ctmp_type').value;
		tmp_servers[id][4] = document.getElementById('ctmp_protocol').value;
		tmp_servers[id][5] = document.getElementById('ctmp_port').value;
		alert(js_msg);
	}

	
<!--





