function refreshImage( imgVerification, txtValidate, txtValidateOK )
{
	txtValidate.value = "";
	imgVerification.src = "/phpincludes/siteinc/captcha/verificationimage.php?rand=" + Math.random();
	
	txtValidateOK.value = "0";
	
	setCmdSubmitDisabled();
	
	txtValidate.focus();
}

function makeUpperCase( textfield )
{
	textfield.value = textfield.value.toUpperCase();
}

function setCountryFlag( abbrev )
{
	$("#countryflag").css("display", "");
	
	$("#country").css("background-color", "#FFFFFF");
	
	if( abbrev == "" )
	{
		$("#countryflag").attr("src", "");
	}
	else
	{
		$("#countryflag").attr("src", "/sources/img/custom/flags/" + abbrev + ".png");
	}
}

function checkInput( element, lang )
{
	// taconite code
    $.taconiteAjax({
        url: "/phpincludes/ajax/webresume/checkInput.php",
        type: "POST",
        data: "element=" + encodeURIComponent(element.id) + "&value=" + encodeURIComponent(element.value) + "&lang=" + encodeURIComponent(lang)
    });
}

function checkAllInputOK()
{
	var isOK = true;
	
	for( i = 0; i < document.frm.elements.length; i++ )
	{
		if( stristr(document.frm.elements[i].id, "inputok") != false )
		{
			if( document.frm.elements[i].value == "0" )
			{
				isOK = false;
				break;
			}
		}
	}
	
	// Check the manditory checkboxes
	if( isOK ) // If the textfields are OK...
	{
		isOK = checkCheckboxEduLevelOK();
	}
	if( isOK )	// If the textfields are OK AND the previous checkboxes are OK ...
	{
		isOK = checkCheckboxEduBackgroundOK();
	}
	
	return isOK;
}

function setCmdSubmitDisabled()
{
	if( checkAllInputOK() )
	{
		$("#divrequiredmessage").css( "display", "none" );
		// $("#cmdSubmit").attr("disabled", false);
	}
	else
	{
		$("#divrequiredmessage").css( "display", "" );
		// $("#cmdSubmit").attr( "disabled", true );
	}
}

function changeInputBGcolor( element, e )
{
    $("#inputok" + element.id).attr("value", "1");
	element.style.backgroundColor = "#FFFFFF";
    $("#trerror" + element.id).css("display", "none");
}

function checkEnterPressed( element, lang, e )
{
	if( e == 13 ) // Enter pressed?
	{
		checkInput( element, lang );
		
		return false;
	}
	else
	{
		return true;
	}
}

function checkVerificationCode( element, lang, e )
{
	if( element.value.length == 5 )
	{
		checkInput( element, lang );
	}
	
	if( e == 13 ) // Enter pressed?
	{
		return false;
	}
	else
	{
		return true;
	}
}

function saving()
{
	$("#cmdSubmit").attr("disabled", true);
	$("#spanSaveLoading").css("visibility", "visible");

    sleep( 1500 );

    var isOK = true;

	for( i = 0; i < document.frm.elements.length; i++ )
	{
		if( stristr(document.frm.elements[i].id, "inputok") != false )
		{
			if( document.frm.elements[i].value == "0" )
			{
				isOK = false;
                idke = document.frm.elements[i].id.replace("inputok", "")
                $("#" + idke).css("background-color", "#FF9999");
                $.scrollTo( "#" + idke, 1000, {onAfter: function() {$("#" + idke).focus();}} );
				break;
			}
		}
	}

    // Check the manditory checkboxes
	if( isOK ) // If the textfields are OK...
	{
		isOK = checkCheckboxEduLevelOK();

        if( !isOK )
        {
            $.scrollTo( "#h3EduLevel", 1000 );
        }
        else
        {

            isOK = checkCheckboxEduBackgroundOK();

            if( !isOK )
            {
                $.scrollTo( "#h3EduBackground", 1000 );
            }
        }
	}


	if( isOK )
    {
        $("#frm").submit();
    }
    else
    {
        $("#cmdSubmit").attr("disabled", false);
        $("#spanSaveLoading").css("visibility", "hidden");
    }
}

function startup()
{
	setCountryFlag( $("#country").attr("value") );
	
	if( $("#isSubmitted").attr("value") == "1" )
	{
		// Loop through all elements (and check the input text's)
		for( i = 0; i < document.frm.elements.length; i++ )
		{
			if( stristr(document.frm.elements[i].id, "inputok") != false )
			{
				document.frm.elements[i].value = "1";
			}
		}
	}
}

