// CONTACT INFORMATION UTILS
//
// Change the state menu with the states for that country

function country_dd_change_onload(country_dom_id, state_dom_id, default_state, lang) {
	this.onload = function() { 
		country_dd_change(document.getElementById(country_dom_id), state_dom_id, default_state, lang);
	}
}

function country_dd_change(country_dom, state_dom_id, default_state, lang) {
	var value 		= getSelectedOptionValue(country_dom);
	var state_dom	= document.getElementById(state_dom_id);
	
	if (!value.match(/^[a-zA-Z]{2}$/)) {
		state_dom.innerHTML = '';
		state_dom.disabled  = true;
	} else {
		state_dom.innerHTML = '<option value="" selected="selected">Please Wait, Loading...</option>';
		state_dom.disabled  = true;
		var aj				= new AjaxConnection;
		aj.processer		= function(root_node, ajx) {
			state_dom.innerHTML = '';
			xmlToDom(state_dom, root_node);
			state_dom.disabled=false;
			if (default_state != null) {
				for (key in state_dom.options) {
					if (state_dom.options[key] && state_dom.options[key].value == default_state) {
						state_dom.options[key].selected = true;
					}
				}
			}			
		}
	    aj.base_tag 		= 'DomainAdmin';
    	aj.Connect('/states/'+escape(value.toLowerCase()) + '.xml?lang='+escape(lang));       		
	}
}

function orgType(element, company) {
	var sel = getSelectedOptionValue(element);
	
	var c 	= document.getElementById(company);
	
	if (sel == 'IND' && c) {
		c.disabled = true;
		c.style.background = '#eee';
	} else if (sel == 'ORG' && c) {
		c.disabled = false;
		c.style.background = '';
	}

}

function contactBaseTypeChange(element) {
	
	var value = element.value;
	
	if (value == 'registrant' && !element.checked) {
		value = 'custom';
	} else if (value == 'custom' && !element.checked) {
		value = 'registrant';
	}
	
	disableAll(element.form, value == 'registrant' ? true : false, ['type', 'submit']);
	
	var cc = document.getElementById('contact-content');
	
	if (cc) {
		cc.className = cc.className.replace(/grayed/,'') + (value=='registrant' ? ' grayed' : ''); 
	}
	
}

