function doShowHideSecondProfile( sShow, eForm ) {
	if( sShow == 'yes' )
		$( '.form_second_col', eForm ).css( 'display', '' );
	else
		$( '.form_second_col', eForm ).css( 'display', 'none' );
}

function validateJoinForm( eForm ) {
	if( !eForm )
		return false;
	
	hideJoinFormErrors( eForm );
	
	$(eForm).ajaxSubmit(function(sResponce) {
		//alert( sResponce );
		try {
			var aErrors = eval(sResponce);
		} catch(e) {
			return false;
		}
		
		doShowJoinErrors( aErrors, eForm );
	} );
	
	return false;
}

function hideJoinFormErrors( eForm ) {
	$( 'img.form_warn_icon', eForm ).css( 'display', 'none' );
	$( '.input_erroneus', eForm ).removeClass( 'input_erroneus' );
	
	//
	var d = document.getElementById('errDiv');
	d.className = 'errDiv';
	//
}

function doShowJoinErrors( aErrors, eForm ) {
	if( !aErrors || !eForm )
		return false;
	
	var bHaveErrors = false;
	
	for( var iInd = 0; iInd < aErrors.length; iInd ++ ) {
		var aErrorsInd = aErrors[iInd];
		for( var sField in aErrorsInd ) {
			var sError = aErrorsInd[ sField ];
			bHaveErrors = true;
			
			doShowError( eForm, sField, iInd, sError );
		}
	}
	
	//
	if( bHaveErrors )
	{
		var d = document.getElementById('errDiv');
		d.className = 'errDivV';
	}
	//
	
	if( !bHaveErrors )
		eForm.submit();
}

function doShowError( eForm, sField, iInd, sError ) {
	var $Field = $( "[name='" + sField + "']", eForm ); // single (system) field
	
	if( eForm['Password[0]'].value != '' && eForm['Password_confirm[0]'].value != eForm['Password[0]'].value )
	{
		$Field = $( "[name='" + 'Password_confirm' + '[' + iInd + ']' + "']", eForm );
		$Field.addClass( 'input_erroneus' );
	}
	
	if( !$Field.length ) // couple field
	{
		$Field = $( "[name='" + sField + '[' + iInd + ']' + "']", eForm );
		$Field.addClass( 'input_erroneus' );
	}
}
