function validatePassword(){
	var password = document.getElementById('password');
	var password_length = 5;
	if(password.value.length < password_length) {
		password.style.backgroundColor="#fccae3";
		return false;
	} else {
		password.style.backgroundColor="#ffffff";
		var password = document.getElementById('password');
		var confirm = document.getElementById('confirm_password');
		if(password.value !=  confirm.value) {
			confirm.style.backgroundColor="#fccae3";
			return false;
		} else {
			confirm.style.backgroundColor="#ffffff";
			return true;
		}
	}
}

function checkConfirmPassword() {
	var password = document.getElementById('password');
	var confirm = document.getElementById('confirm_password');
	if(password.value !=  confirm.value) {
		confirm.style.backgroundColor="#fccae3";
		return false;
	} else {
		confirm.style.backgroundColor="#ffffff";
		return true;
	}
}

function checkEmail(){
	email=document.getElementById('email').value;
	if(isEmail(email)) {
		document.getElementById('email').style.backgroundColor="#ffffff";
		return true;
	}else{
		document.getElementById('email').style.backgroundColor="#fccae3";
		return false;
	}
}

function isEmail(v) {
	var reg = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
	return reg.test(v);
}

function checkRegistrationForm(){
	var err_mail=false;
	var err_pass=false;
	var err_confpass=false;
	var err_check_confpass=false;
	var err=false;


	if(checkEmail()){
		err_mail=true;
		document.getElementById('err_fieldmail').style.display="none";
	}else{
		err=true;
		document.getElementById('err_fieldmail').style.display="block";
	}

	if(document.getElementById('password').value==''){
		document.getElementById('err_pass').style.display="block";
		err=true;
	}else{
		document.getElementById('err_pass').style.display="none";
		err_pass=true;
	}

	if(document.getElementById('confirm_password').value==''){
		document.getElementById('err_confirm_pass').style.display="block";
		err=true;
	}else{
		document.getElementById('err_confirm_pass').style.display="none";
		err_confpass=true;
	}

	if(err_pass && err_confpass){
		if(validatePassword()){
			document.getElementById('err_check_confirm_pass').style.display="none";
			err_check_confpass=true;
		}else{
			err=true;
			document.getElementById('err_check_confirm_pass').style.display="block";
		}
	}

	if(!err) {
		document.getElementById('error_registration').style.display="none";
		return true;
	}else{
		document.getElementById('error_registration').style.display="block";
		return false;
	}

}


function addToPlayList(idUser, idSong){
	cnt=parseInt(document.getElementById('cntSongPL').innerHTML);
	new Ajax.Request('/ajax/addToPl.php', 
		{ 
			method: 'post', 
			parameters: 'idSong='+idSong+'&idUser='+idUser, 
			onSuccess: function(transport){
				var response = transport.responseText;
				if(response=="ok"){
					document.getElementById('cntSongPL').innerHTML=cnt+1;
					document.getElementById('LinkPl').innerHTML='убрать из Плейлиста';
					document.getElementById('LinkPl').href='javascript: delFromPlayList('+idUser+', '+idSong+');';
				}
			}
		}
	);
}
function delFromPlayList(idUser, idSong){
	cnt=parseInt(document.getElementById('cntSongPL').innerHTML);
	new Ajax.Request('/ajax/delFromPl.php', 
		{ 
			method: 'post', 
			parameters: 'idSong='+idSong+'&idUser='+idUser, 

			onSuccess: function(transport){
				var response = transport.responseText;
				if(response=="ok"){
					document.getElementById('cntSongPL').innerHTML=cnt-1;
					document.getElementById('LinkPl').innerHTML='добавить в Плейлист';
					document.getElementById('LinkPl').href='javascript: addToPlayList('+idUser+', '+idSong+');';
				}
			}
		}
	);
}

function delSongPL(idSong){
	new Ajax.Updater( 'id_song_pl_'+idSong, '/ajax/deleteFromPl.php?idSong='+idSong);
	document.getElementById('id_song_pl_'+idSong).style.backgroundColor='#fdf1ef';
	document.getElementById('id_song_pl_'+idSong).innerHTML='Песня удалена из плэй листа!';
}

function bookmark(a){
 var url = window.document.location;
 var title = window.document.title;
 var b = getBrowserInfo();
 if (b.type == 'IE' && 7 > b.version && b.version >= 4) window.external.AddFavorite(url,title);
 else if (b.type == 'Opera') {
  a.href = url;
  a.rel = "sidebar";
  a.title = url+','+title;
  return true;
 }
 else if (b.type == "Netscape") window.sidebar.addPanel(title,url,"");
 else alert("Нажмите CTRL-D, чтобы добавить страницу в закладки.");
 return false;
}
function getBrowserInfo() {
 var t,v = undefined;
 if (window.opera) t = 'Opera';
 else if (document.all) {
  t = 'IE';
  var nv = navigator.appVersion;
  var s = nv.indexOf('MSIE')+5;
  v = nv.substring(s,s+1);
 }
 else if (navigator.appName) t = 'Netscape';
 return {type:t,version:v};
}
