$(document).ready(function(){
    $("#Nic").blur(function(event){
	checkForValidNic();
    });
    $("#gallery > img").click(function(event) {
	selectAvatar();
    });
    $("#AvatarFile").uploadify({
                'uploader'       : '/images/uploadify.swf',
                'script'         : '/jq/regform/uploadavatar/',
                'cancelImg'      : '/images/cancel.png',
		'scriptData'     : { 'PHPSESSID' : session_id },
                'folder'         : '/images',
                'auto'           : true,
                'multi'          : true,
                'width'          : '159',
                'height'         : '23',
                'buttonImg'      : '/images/uploadify.gif',
		'onComplete'	 : UploadComplite
    });

    $("#checkbox").click(function () {
    	    $("#submit").slideToggle("fast");
    });

});

function checkForValidNic() {
    $.get("/jq/regform/?check=nic",
	    { 'nic': $('#Nic').val()},
    	    function(data, status){
		if(data == 'ok') {
		    $("#nic_info").html('&nbsp;<font color=darkgreen>свободен</font>');
		    document.getElementById('Nic').style.backgroundColor="#fff";
		} else if (data == 'busy') {
		    $("#nic_info").html('&nbsp;<font color=red>занят</font>');
		    document.getElementById('Nic').style.backgroundColor="#ffe5e5";
		} else if (data == 'skip') {
		    $("#nic_info").html('&nbsp;');
		} else {
		    $("#nic_info").html('&nbsp;<font color=red>недопустимый</font>');
		    document.getElementById('Nic').style.backgroundColor="#ffe5e5";
		}
	    },
	    "text"
	);
}

function selectAvatar(e) {
    $("#userAvatar").attr("src", '/images/avatars/'+$("#gallery :radio[name=avatar]").filter(":checked").val());
}

function makeEdit() {
    $("#goBack").attr("value", 'yes');
    $("#regForm").submit();
}

function passMatch() {
	var m = document.getElementById('mainpwd');
	var n = document.getElementById('repwd');
	if (m.value != n.value) { 
		n.style.backgroundColor="#ffe5e5"; 
	} else { 
		n.style.backgroundColor="#fff"; 
	}
}


