function updateCaptcha()
{
	document.getElementById("i_usr_f_captcha").src = document.getElementById("i_usr_f_captcha").src + '?regenerate';
}

function showInstructions()
{
	var descExt = Ext.get('usr_f_dsc_captcha');
	var btnDom = Ext.query('a.btn-info')[0];

	if (descExt.hasClass('x-hidden'))
	{
		descExt.alignTo(btnDom, 'l-r', [22, 0]);
		descExt.removeClass('x-hidden');
	}
	else
	{
		descExt.addClass('x-hidden');
	}

}

function usernameTip()
{	
	var name = 'usr_f_username';

	Ext.onReady(function(){
		window.usernameTipObj = new Ext.ValidateTip({
			target: name,
			title: 'Username Validation',
			mouseOffset: [-50, 0],
			autoLoad: {url: getBaseUrl('appRootUrl') + 'signup/register/username/', params: {html: '', value: Ext.getDom(name).value}, callback: Ext.emptyFn, nocache: true},
			firstLoad: true,
			width: 250,
			autoHeight: true,
			minHeight: 100
		});
	});

	Ext.getDom(name).highlightError = function() {
			Ext.get(this).parent('dd').addClass('err');
			window.usernameTipObj.errorHtml = arguments[0];
			window.usernameTipObj.fireEvent('beforeshow');
	};
	Ext.getDom(name).hideError = function() {
		Ext.get(this).parent('dd').removeClass('err');
		window.usernameTipObj.errorHtml = '';
		window.usernameTipObj.fireEvent('beforeshow');
	};
}

function validatePass(defaultMsg, f, name, skipFocus, val, msgTpl)
{
	if (Ext.getDom(name).value != Ext.getDom('usr_f_password').value)
	{
		ShowAlert(Lang['password_not_match'], f, name, skipFocus);
		return false;
	}

	return true;
}

function validateEmail(defaultMsg, f, name, skipFocus, val, msgTpl)
{
	Ext.Ajax.request({url: getBaseUrl('appRootUrl') + '?IT:usr_checker', params:{email:true,value:val},success:function(r){
			r = Ext.decode(r.responseText);
			if (!r.valid)
			return ShowAlert(r.msg, f, name, skipFocus);
		}
	});
	return true;
}

function validateUserEmail(defaultMsg, f, name, skipFocus, val, msgTpl)
{
	Ext.Ajax.request({url: getBaseUrl('appRootUrl') + '?IT:usr_checker', params:{email:true,value:val},success:function(r){
			r = Ext.decode(r.responseText);
			if (!r.valid)
			return ShowAlert(r.msg, f, name, skipFocus);
		}
	});
	return true;
}


function validateCountry(defaultMsg, f, name, skipFocus, val, msgTpl)
{
	switch(Ext.get('usr_f_state_is_combo').dom.value)
	{
		case 'combo':
			if (!Ext.get('usr_f_state_combo').dom.value)
			{
				return ShowAlert(defaultMsg, f, 'usr_f_state_combo', skipFocus);
				return false;
			}
			return true;

		break;
		case 'text':
			if (!Ext.get('usr_f_state').dom.value)
			{
				return ShowAlert(defaultMsg, f, name, skipFocus);
				return false;
			}
			return true;
	}
	return true;
}
function workState(text)
{
if ('United States' == text)
		{
			Ext.get('usr_f_state_is_combo').dom.value = 'combo';
			showElement(Ext.get('usr_f_state_combo_container'));

			Ext.get('usr_f_state_container').addClass('x-hidden');
		}
		else
		{
			if(!Ext.get('usr_f_state_combo_container').hasClass('x-hidden'))
			{
				Ext.get('usr_f_state_is_combo').dom.value = 'text';
				Ext.get('usr_f_state_combo_container').addClass('x-hidden');
				showElement(Ext.get('usr_f_state_container'));
				//Ext.get('usr_f_state_container').removeClass('x-hidden');
				Ext.getDom('usr_f_state').value='';
			}
		}
}
function onPageInit()
{
	Ext.Options.comboEmptyStrings =  [
		{name:'usr_f_country',string:'Please select your country'},
		{name:'usr_f_state_combo',string:'Please select your state'}
	];
	convertedInputs = convertForm('signup');
	Ext.get('usr_f_state_is_combo').dom.value = 'text';
	convertedInputs['usr_f_country'].on('select',function(combo,record,index){
		workState(record.data.text);
	});
	workState(Ext.get('usr_f_country').dom.ext.lastSelectionText);
	convertedInputs['usr_f_country'].emptyText = "Please select your country";
	convertedInputs['usr_f_state_combo'].emptyText = "Please select your State";
	
	if(Ext.isIE)
	{		
		Ext.get(Ext.query(".x-form-text.x-form-field.combo")).setStyle("width", "187px");	
	} 
}
