/****************************************************************
* Author:	Alistair Lattimore
* Website:	http://www.lattimore.id.au/
* Contact:	http://www.lattimore.id.au/contact/
*			Errors, suggestions or comments
* Date:		30 June 2005
* Version:	1.0
* Purpose:	Emulate the disabled attributte for the <option> 
*			element in Internet Explorer.
* Use:		You are free to use this script in non-commercial
*			applications. You are however required to leave
*			this comment at the top of this file.
*
*			I'd love an email if you find a use for it on your 
*			site, though not required.
****************************************************************/
/****
window.onload = function() {
	if (document.getElementsByTagName) {
		var s = document.getElementsByTagName("select");

		if (s.length > 0) {
			window.select_current = new Array();

			for (var i=0, select; select = s[i]; i++) {
				if ((select.name == 'idPais') || 
					(select.name == 'idPaisOrigen') || 
					(select.name == 'idPaisDestino')) 
				{
					select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
					select.onchange = function(){ restore(this); }
					emulate(select);
				}
			}
		}
	}
}
*/

function disable_options() {
	
	if (document.getElementsByTagName) {
		var s = document.getElementsByTagName("select");

		if (s.length > 0) {
			window.select_current = new Array();

			for (var i=0, select; select = s[i]; i++) {
				if ((select.name == 'idPais') || 
					(select.name == 'idPaisOrigen') || 
					(select.name == 'idPaisDestino') ||
					(select.name == 'idPaisIntermedio') ||					
					(select.name == 'facIdPais') ||
					(select.name == 'usuario.provincia.pais.idPais') ||
					(select.name == 'usuario.facProvincia.pais.idPais'))
				{
					onchangeActual = select.onchange;
					select.onfocus = function(){ window.select_current[this.id] = this.selectedIndex; }
					select.onchange = function(){ if (this.value==1) {onchangeActual();}  restore(this); }
					emulate(select);
				}
			}
		}
	}
}


function restore(e) {
	if (e.options[e.selectedIndex].disabled) {
		e.selectedIndex = window.select_current[e.id];		
	}
	
}

function emulate(e) {
	for (var i=0, option; option = e.options[i]; i++) {
		if (option.value>1) {
			option.style.color = "graytext";
			option.disabled = true;
		}
	}
}
