var gl_error_was_focused = false;//if the error was occured atlist once
function init()
{
	document.getElementById('compad_id').focus();
}

/**
function validate_form()
@description validate the change user form and if not valid return an error in the right place
@author Yuval Dayan
@param none
@return true or false
**/	
function validate_form() 
{
	var ret = true;
	var compad_id = document.getElementById('compad_id').value;
	var user_pass = document.getElementById('user_pass').value;
	var word = document.getElementById('word').value;
	gl_error_was_focused = false;
	if (!is_a_compad_id(compad_id)) 
	{
		error_to_html('compad_id_value','compad_id_div','compad_id');
		ret = false;
	}
	else
	{
		clear_err_html('compad_id_div','compad_id');
	}
	
	if(is_a_space(user_pass) || user_pass.length < 6)
	{
		error_to_html('user_pass_value','user_pass_div','user_pass');
		ret = false;
	}
	else
	{
		clear_err_html('user_pass_div','user_pass');
	}
	
	if(is_a_space(word))
	{
		error_to_html('word_value','word_div','word');
		ret = false;
	}
	else
	{
		clear_err_html('word_div','word');
	}
	
	if(ret == true)
	{
		document.getElementById('frm1').submit();
	}
	
	return ret;
}


/**
function clear_err_html(clear_elm)
@description - clear the space where the error should be written
@author Yuval Dayan
@param clear_elm - the element id
@return none
**/
function clear_err_html(clear_elm,input_elm)
{
	document.getElementById(clear_elm).innerHTML = '&nbsp;';
	document.getElementById(input_elm).style.backgroundColor = '';
}

/**
function error_to_html(err,err_elm)
@description - create the error 
@author Yuval Dayan
@param err - the error id,clear_elm - the element id
@return none
**/
function error_to_html(err,err_elm,input_elm)
{
	var str = '';
	
	switch(err)
	{
		case 'compad_id_value':
			str = gl_error_arr["compad_id_invalid"];
			break;
		case 'user_pass_value':
			str = gl_error_arr["password_invalid"];
			break;
		case 'word_value':
			str = gl_error_arr["word_invalid"];
			break;
	}
	
	if(str != '')
	{
		document.getElementById(err_elm).innerHTML = str;
		document.getElementById(input_elm).style.backgroundColor='#FFD95E';
	}
	//check if need to go to the error
	if(!gl_error_was_focused)
	{
		document.getElementById(err_elm+'_fc').focus();
		document.getElementById(input_elm).focus();
		gl_error_was_focused = true;
	}
}

/**
function is_a_space(value)
@description - check if the given value is a space only 
@author Yuval Dayan
@param value - the value to check
@return true or false
**/
function is_a_space(value)
{
	var ret = false;

	value = value.replace(/ /g,'');
	if(value.length == 0)
	{
		ret = true;
	}
	
	return ret;
}
