/* Profile.js - used by profile layout */

/* Prototype window used to update course info */

var win;

// Prototype window used for choose icon
function launchCourseUpdate() {
	
	win = new Window(Application.getNewId(), 
						{className: "dialog", 
						width:640, 
						height:500, 
						zIndex:100, 
						resizable: false, 
						title: "Update Course Info", 
						showEffect:Element.show, 
						hideEffect: Element.hide,
						draggable:true, 
						wiredDrag: false})

	win.setContent('updateCourseInfo', false, false) 
	win.setStatusBar("We appreciate your feedback!");
	win.showCenter();
}

var Alerter = { 
  closeFinderWindow: function(){ 
     win.destroy();
  } 
}

/* Contract and expand User profile header */

function toggleUserProfile(){
  if ($('userProfile').style.display == 'none' ) {
	Element.hide('expandLink');
	new Effect.BlindDown('userProfile', {duration:0.5});
	Element.show('collapseLink');
	setTimeout('activateSliders()',1000);
	
  } else {
	Element.hide('collapseLink');
	new Effect.BlindUp('userProfile', {duration:0.5});
	Element.show('expandLink');
  }
}

/* Contract and expand Course profile header */

function toggleCourseProfile(div_id){
  if ($(div_id).style.display == 'none' ) {
	Element.show(div_id);
	/* new Effect.BlindDown(div_id, {duration:0.5}); */
	
  } else {
	new Effect.BlindUp(div_id, {duration:0.5});
  }
}

function activateSliders(){
	
	var slider1 = new Control.Slider('profileHandle1','profileTrack1',{
	disabled:true,
	sliderValue:[parseInt($('game_strength_rating_1').value)/20]});

	var slider2 = new Control.Slider('profileHandle2','profileTrack2',{
	disabled:true,
	sliderValue:[parseInt($('game_strength_rating_2').value)/20]});

	var slider3 = new Control.Slider('profileHandle3','profileTrack3',{
	disabled:true,
	sliderValue:[parseInt($('game_strength_rating_3').value)/20]});
	
	var slider4 = new Control.Slider('profileHandle4','profileTrack4',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_4').value)/20]});

	var slider5 = new Control.Slider('profileHandle5','profileTrack5',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_5').value)/20]});

	var slider6 = new Control.Slider('profileHandle6','profileTrack6',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_6').value)/20]});
	
	var slider7 = new Control.Slider('profileHandle7','profileTrack7',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_7').value)/20]});

	var slider8 = new Control.Slider('profileHandle8','profileTrack8',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_8').value)/20]});

	var slider9 = new Control.Slider('profileHandle9','profileTrack9',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_9').value)/20]});

	var slider10 = new Control.Slider('profileHandle10','profileTrack10',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_10').value)/20]});

	var slider11 = new Control.Slider('profileHandle11','profileTrack11',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_11').value)/20]});

	var slider12 = new Control.Slider('profileHandle12','profileTrack12',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_12').value)/20]});

	var slider13 = new Control.Slider('profileHandle13','profileTrack13',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_13').value)/20]});

	var slider14 = new Control.Slider('profileHandle14','profileTrack14',{
	  disabled:true,
	  sliderValue:[parseInt($('game_strength_rating_14').value)/20]});
}

/* Used for photo carousel */

function buttonStateHandler(button, enabled) {
 if (button == "prev-arrow") 
   $('prev-arrow').src = enabled ? "/images/profile/profile_photo_prevON.gif" : "/images/profile/profile_photo_prevOFF.gif"
 else 
   $('next-arrow').src = enabled ? "/images/profile/profile_photo_nextON.gif" : "/images/profile/profile_photo_nextOFF.gif"
}

function animHandler(carouselID, status, direction) {
  var region = $(carouselID).down(".carousel-clip-region")
  if (status == "before") {
    Effect.Fade(region, {to: 0.3, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
  if (status == "after") {
    Effect.Fade(region, {to: 1, queue: { position:'end', scope: "carousel" }, duration: 0.2})
  }
}

/* Used on Write Review */

function calc(form) {
	var num = 0;
	var den = 0;
	for (i=0;i<form.elements.length;i++){
		if (form.elements[i].type == 'radio' && form.elements[i].checked){
			num = parseFloat(num) + parseFloat(form.elements[i].value);
			den = parseFloat(den) + 1
		}
	}
	form.overall.value= Math.round(num/den*100)/100
}

function route(action,form) {form.userPath.value = action ;form.submit() }

/* Used on messaging tab */

function removeElement(divNum) {
  	var d = document.getElementById('recipient-list');
  	var olddiv = document.getElementById(divNum);
  	d.removeChild(olddiv);
}

function checkRecipients() {
	var d = document.getElementById('recipient-list');	
	var children = d.childNodes;
	var counter = 0;
	for (var i = 0; i < children.length; i++) {
		if (children[i].tagName == "DIV"){
			counter = counter + 1;
		}
    };
	
	if (counter > 10 ){
		return false;
	} else {
		return true;
	}
}