/*
* This function is called after the completion of the ajax validation request.
* It looks through the JSON data. And displays the errors if it needs or if there
* are no errors, it evaluates the code in yzValidator_eval_onsuccess hidden tag.
*/
function yzCSV_JSONUpdater(request, hidden_id)
{
	var json = eval(request.responseText);

	var numElementsInResponse = json.length;
	var elementId;
	var elementText;

	var formId = $("#"+hidden_id).attr('name');

	//Looks for the form error <div> by its class name
	var formErrorDivs = $('.form_error');
	var numFormErrorDivs = formErrorDivs.length;
	//Loops through all of the form error div's to
	//delete any error messages from previous errors

	$('#'+formId+' > .input_error').removeClass('input_error');

	for(var i = 0; i < numFormErrorDivs; i++)
	{
		$("#"+formErrorDivs.get(i).id).html('');
		var str = 'error_for_';

		var inputId = formErrorDivs.get(i).id.substring(str.length);
		$("#"+inputId).removeClass('input_error');

	}
	//Evaluate the code in yzValidator_eval_onsuccess tag if there are no errors
	if(numElementsInResponse > 0){

		$("#"+formId).attr('done', false);
		//If there are errors, loop through the JSON data and
		//update each form_error div with its corresponding message
		for (var i = 0; i < numElementsInResponse; i++)
		{

			elementId=json[i][0];
			elementText=json[i][1];

			var str = 'error_for_';

			var inputId = elementId.substring(str.length);

			if (inputId == 'is_agree') {

                $('#is_agree_error').css('padding', '6px');
                $('#is_agree_error').css('border', 'solid 2px red');
                $('#is_agree_error').attr('error', 'true');
                $('#is_agree_error').show();
                $("#"+elementId).show();

			} else {

    			$("#"+inputId).addClass('input_error');

    			var inputOffsets = $("#"+inputId).offset();

    			try{
    				var topPos = inputOffsets.top;
    				var leftPos = inputOffsets.left + $("#"+inputId).width() + 5;

    				if ($("#"+elementId)) {
    					$("#"+elementId).css("top", topPos);
    					$("#"+elementId).css("left", leftPos);

    					$("#"+elementId).html(elementText);
    					$("#"+elementId).show();
    				}
    			}catch(e){}
			}

			if (numElementsInResponse > 0) {
			}
		}

	} else{
		eval($("#"+hidden_id).val());
		$("#"+formId).attr('done', true);
	}
}

