
//Loads the state orgs page from the drop down list.
function getStateOrg(id){
  if (id != 0){
    document.location.href = "/organizations/" + id + "/content_areas";
  }
}
//functions to work with the ajax requests for the rate and align site page
function getContentAreas(id){
  $('content-area-list').innerHTML = "";
  $('subject-list').innerHTML = "";
  $('standard-list').innerHTML = "";
  if (id != 0){
    new Ajax.Updater('content-area-list', "/get_content_areas_list/" + id , { method:'get' });
  }
}

function getApprovedSubjects(id){
  $('subject-list').innerHTML = "";
  $('standard-list').innerHTML = "";
  if (id != 0){
    new Ajax.Updater('subject-list', "/get_approved_subjects_list/" + id , { method:'get' });
  } 
}

function getStandardsCheckList(id){
  $('standard-list').innerHTML = "";
  if (id != 0){
    new Ajax.Updater('standard-list', "/get_standards_check_list/" + id , { method:'get' });
  }
}
var standardID = 0;
function checkStandard(){
  if (standardID != 0 || $("standard_id") != null || $('is_news_article').checked){
    document.new_web_site.submit();
  } else {
    $("align-to-standard").className = "dont-forget";
    $("dont-forget-message").style.display = "";
  }
}
function setStandardID(id){
  standardID = id;
}

function refreshPage(){
  document.location.reload(true);
}

function toggleStandardsControls() {
	var isNewsArticle = $('is_news_article').checked;
	$('start').disabled = isNewsArticle;
  	$('content-area').disabled = isNewsArticle;
  	$('subject').disabled = isNewsArticle;
  	$('standard-list').style.display = isNewsArticle == true ? 'none' : '';
}





//Function for handling swapping images when rating sites
var currentRating = 0;
var timeOutId = 0;
var ratingLabels = [];
ratingLabels.push("&nbsp;"); // 0 is a space to allow for no rating without page elements shifting.
ratingLabels.push("I don't like it. It doesn't cover the standard at all.");
ratingLabels.push("I don't like it.");
ratingLabels.push("It's OK.");
ratingLabels.push("I like it. Seems to cover the standard.");
ratingLabels.push("I love it. Covers the standard very well.");


// Highlight each item that is lower or equal to the rating
function rate(rating){
	// Make sure the clear function is not called if we are still over one of the items.
	clearTimeout(timeOutId)
	$R(1, 5).each(function(n) {
		$("rate_" + n).src = getImageForRating(n, rating);
	});
	var label = $("rating-label")
	label.update(ratingLabels[rating]);
}

// Set a timeout to call the real fucntion to clear the items
// Allows mouse to go over a different item without clearing the others.
function clearRate(){
	timeOutId = setTimeout('clearRateReally()', 100);
}
//Does the real work of clearing the items.
function clearRateReally(){
	$R(1,5).each(function(n){
		$("rate_" + n).src = getImageForRating(n, currentRating);
	});
	var label = $("rating-label")
	label.update(ratingLabels[currentRating]);
}

function setRating(rating){
	currentRating = rating;
	$("rating_rating").value = currentRating;
}

//Determine the correct image string.
function getImageForRating(n, rating){
	var image = '';
	if(n <= rating){
		image = "/images/apple_1.png";
	} else {
		image = "/images/apple_2.png";
	}
	return image;
}
