

django.jQuery(document).ready(function() {
		//alert('Init OK');

		//django.jQuery('#id_password').attr('type', 'password');		
		//django.jQuery('#id_password').remove();
		//django.jQuery('#id_password').removeAttr('type')
		//django.jQuery('#id_password').clone();
		
});

function getRandomNum() {
        
    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000    
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127        
    rndNum = (rndNum % 94) + 33;
            
    return rndNum;
}

function checkPunc(num) {
    
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }    
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    
    return false;
}

function GeneratePassword() {
    
    if (parseInt(navigator.appVersion) <= 3) { 
        alert("Sorry this only works in 4.0 browsers"); 
        return true; 
    }
    
    var length=10;
    var sPassword = "";
    
    var noPunction = true;
    
    for (i=0; i < length; i++) {
    
        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        
        sPassword = sPassword + String.fromCharCode(numI);
    }

    document.forms.myuser_form.password.value = sPassword;
    document.forms.myuser_form.password2.value = sPassword;
    django.jQuery('p.help').html('<a onclick="GeneratePassword();" href="#">Сгенерить пароль автоматически.</a> Пароль: ' + sPassword);
    
    return true;
}
