function rate(star){
	document.getElementById("rating").value = "no";
	for(var i=1;i<=star;i++){
		document.getElementById("star" + i).className = "on";	
		document.getElementById("rating_text").innerHTML = "Betyg: " + i;			
	}
}

function unrate(){
	if(document.getElementById("rating").value == "no"){
		for(var i=1;i<=5;i++){
			document.getElementById("star" + i).className = "off";	
			document.getElementById("rating_text").innerHTML = "";						
		}
	}
}

function rateIt(star){
	document.getElementById("rating").value = star;
}

function show_rating(rating){
	var string = "";
	for(var i=1;i<=rating;i++){
		string = string + "<a class='on'></a>";
				
	}
	return string;
}

function removeValue(actual, base){
  if( actual.value == base ) {
    actual.value = '';
  } else if( actual.value == '' ) {
    actual.value = base;
  }
}

function removeClass(actual){
  if( actual.className == "red" ) {
    actual.className = '';
  }
}


function checkValue(actual, base){
  if( actual.value == '' ) {
    actual.value = base;
  }
}

function valid_commentform(){
	var text = "";
	var valid = 4;
 	if( /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(document.getElementById('email').value) ){
		valid=valid-1;
	 } else {
		var class_email = document.getElementById('email').className = "red";
		text = "Fyll i de röda fälten korrekt. ";
	 }
	
	if(document.getElementById('author').value == '' || document.getElementById('author').value == 'Vad heter du?') {
		document.getElementById('author').className = "red";
		
    } else {
		valid=valid-1;
	}
	
	if(document.getElementById('comment').value == '') {
		document.getElementById('comment').className = "red";
		text = "Fyll i de röda fälten korrekt. ";
    } else {
		valid=valid-1;
	}
	
	 if(document.getElementById('rating').value == 'no') {
		text = text + "Du måste också sätta ett betyg.";
    } else {
		valid=valid-1;
	}
	
	if(valid>0) {
		document.getElementById('valid_text').innerHTML = text;
		return false;
	} else {
		return true;
	}	
}

