function dirListStatus(status) { 
	
	Effect.toggle('dirlisting', 'blind', { duration: 0.4 });
	
	if (status == 0) {
		var newStatus = 1;
		var newStatusTxt = 'Näytä kansiot';
	} else {
		var newStatus = 0;
		var newStatusTxt = 'Piilota kansiot';
	}
	
	$('dirListToggle').innerHTML = '<a href="javascript:void(0)" onclick="javascript:dirListStatus(\''+newStatus+'\')">'+newStatusTxt+'</a>';
		
	var options = {
                method : 'post',
				parameters : 'dirListStatus='+status
	};
		
	new Ajax.Request('/ajax/dirlist/', options);
}

function loader (elID) {
	$(elID).innerHTML = '<img src="/img/loader.gif" width="128" height="15" alt="Ladataan..." />';
}

function updateUserTags (user_id, pageNo) {
	var options = {
        method : 'get',
		parameters : 'user_id='+user_id+'&pageNo='+pageNo,
		onLoading: function (t) {
			loader('userTags');
		},
		onSuccess: function(t) {
			$('userTags').innerHTML = t.responseText;
		}
	};
		
	new Ajax.Request('/ajax/usertags/', options);
}

function checkField (fieldID, errorID, value) {
	if (value == '') {
		var color = '#ff0000';
		var status = 'Täytä kenttä'
	} else {
		var color = '#28913d';
		var status = 'OK';
	}
	
	$(fieldID).style.border = "1px solid "+color;
	$(errorID).style.color = color;
	$(errorID).innerHTML = status+' ';
}

function validateEmail(email) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if(reg.test(email) == false) {
		var color = '#ff0000';
		var status = 'Tarkista sähköpostiosoite'
	} else {
		var color = '#28913d';
		var status = 'OK';
	}
	$('email').style.border = "1px solid "+color;
	$('status-email').style.color = color;
	$('status-email').innerHTML = status+' ';   
}

function testPasswordMatch (passwd1, passwd2) {
	if (passwd2 != '') {
		if (passwd2 != passwd1) {
			var color = '#ff0000';
			var status = 'Salasanat eivät täsmää'
		} else {
			var color = '#28913d';
			var status = 'OK';
		}
	} else {
		var color = '#ff0000';
		var status = 'Täytä salasana'
	}
	$('password2').style.border = "1px solid "+color;
	$('status-passwd2').style.color = color;
	$('status-passwd2').innerHTML = status+' ';
}

function checkUser(nick) {
	var options = {
        method : 'get',
		parameters : 'nick='+nick,
		
		onSuccess: function(t) {
			if (nick.length > 1) {
				if (t.responseText == 1) {
					var color = '#ff0000';
					var status = 'Tunnus on varattu toiselle käyttäjälle';
				} else if (t.responseText == 2) {
					var color = '#ff0000';
					var status = 'Tunnus ei kelpaa';
				} else {
					var color = '#28913d';
					var status = 'OK';				
				}
			} else {
				var color = '#ff0000';
				var status = 'Anna tunnus';
			}

			$('nick').style.border = "1px solid "+color;
			$('exist-user').style.color = color;
			$('exist-user').innerHTML = status+' ';
		}
	};
		
	new Ajax.Request('/ajax/checkuser/', options);
}

function selectModels(make) {

	var options = {
        method : 'get',
		parameters : 'make='+make,
			
		onSuccess: function(t) {
			document.getElementById('models').innerHTML = t.responseText;
		}
	};

	new Ajax.Request('/ajax/cameraselect/', options);
}

function testPassword(passwd) {

	var intScore = 0;
	var statusText = "";
	
	if (passwd.length<=6) {
		intScore = (intScore+3)
	} else if (passwd.length>6 && passwd.length<=8) {
		intScore = (intScore+6)
	} else if (passwd.length>8 && passwd.length<=10) {
		intScore = (intScore+15)
	} else if (passwd.length>10) {
		intScore = (intScore+20)
	}

	if (passwd.match(/[a-z]/)) {
		intScore = (intScore+1)
	}
		
	if (passwd.match(/[A-Z]/)) {
		intScore = (intScore+5)
	}
		
	if (passwd.match(/\d+/)) {
		intScore = (intScore+5)
	}
		
	if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) {
		intScore = (intScore+5)
	}
		
	if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) {
		intScore = (intScore+5)
	}

	if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) {
		intScore = (intScore+5)
	}

	if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) {
		intScore = (intScore+2)
	}

	if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)){
		intScore = (intScore+2)
	}
	
	if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) {
		intScore = (intScore+2)
	}
	
	if(intScore <= 10) {
		strVerdict = "hyvin heikko"
		var color = '#ff0000';
	} else if (intScore > 10 && intScore <= 20) {
		strVerdict = "heikko"
		var color = '#ff0000';
	} else if (intScore > 20 && intScore < 30) {
		strVerdict = "hyvä"
		var color = '#28913d';
	} else {
		strVerdict = "erinomainen"
		var color = '#28913d';
	}
	
	$('password').style.border = "1px solid "+color;
	$('status-passwd1').style.color = color;
	$('status-passwd1').innerHTML = "Salasana on vahvuudeltaan "+strVerdict;
}
