﻿// JScript File

function forgotPass()
{
  var e = document.getElementById('loginname');
  if(null != e) {
    strEmail = e.value;
    atpos = strEmail.indexOf("@");
    dotpos = strEmail.lastIndexOf(".");

    if(atpos == -1 || dotpos == -1 || dotpos < atpos || (dotpos - atpos) < 3 || atpos < 2 || dotpos > (strEmail.length - 3) || strEmail ==  ""){
      alert("Please enter a valid email address in the box above.");
      usernamecontrol.focus();
      usernamecontrol.select();
    } else {
      window.location="/page/forgotpass?e=" + strEmail
    }
  }
}

function getElement(id) {
  var d = null
	if(document.all) {
		d = document.all[id]
	} else {
		d = document.getElementById(id)
	}

  if(null == d) {
    var x = document.getElementsByName(id)
    d = (x.length > 0) ? x[0] : null;
  }
  return d
}

function ratingStars(val)
{
  val = val / 2;  // ##TODO## halves ? did these disappear with the conversion from the original keyPlay site ?
  var e = document.getElementsByName('rating_star');
  for(var i = 0; i < e.length; i++) {
    if(e[i].id <= val) {
      e[i].src = '/img/Stars/Star_Blue_On_' + (i+1) + '.gif';
    } else {
      e[i].src = '/img/Stars/Star_Blue_Off_' + (i+1) + '.gif';
    }
  }

  e = getElement('search_rating');
  if(null != e) {
    e.value = val;
  }
}

function difficultyStars(val)
{
  var e = document.getElementsByName('difficulty_star');
  for(var i = 0; i < e.length; i++) {
    if(e[i].id <= val) {
      e[i].src = '/img/Stars/Star_Blue_On_' + i + '.gif';
    } else {
      e[i].src = '/img/Stars/Star_Blue_Off_' + i + '.gif';
    }
  }

  e = getElement('search_difficulty');
  if(null != e) {
    e.value = val;
  }
}

function ratingStars2(val)
{
  var e = document.getElementsByName('rating_star');
  for(var i = 0; i < e.length; i++) {
    if(e[i].id <= val) {
      e[i].src = '/img/Stars/Star_Gray_On_' + (i+1) + '.gif';
    } else {
      e[i].src = '/img/Stars/Star_Gray_Off_' + (i+1) + '.gif';
    }
  }

  var e = document.getElementsByName('review_rating');
  for(var i = 0; i < e.length; i++) {
    if(e[i].id <= val) {
      e[i].src = '/img/Stars/Star_Gray_On_' + (i+1) + '.gif';
    } else {
      e[i].src = '/img/Stars/Star_Gray_Off_' + (i+1) + '.gif';
    }
  }

  e = getElement('hdnRating');
  if(null != e) {
    e.value = val;
  }
}

function difficultyStars2(val)
{
  var e = document.getElementsByName('difficulty_star');
  for(var i = 0; i < e.length; i++) {
    if(e[i].id <= val) {
      e[i].src = '/img/Stars/Star_Gray_On_' + i + '.gif';
    } else {
      e[i].src = '/img/Stars/Star_Gray_Off_' + i + '.gif';
    }
  }

  var e = document.getElementsByName('review_diff');
  for(var i = 0; i < e.length; i++) {
    if(e[i].id <= val) {
      e[i].src = '/img/Stars/Star_Gray_On_' + i + '.gif';
    } else {
      e[i].src = '/img/Stars/Star_Gray_Off_' + i + '.gif';
    }
  }

  e = getElement('hdnDifficulty');
  if(null != e) {
    e.value = val;
  }
}

/*  --- from previous version ---
function loginerr()
{
  alert("Please enter a valid email address and password.");
}

function starslide(div_id, input_id, total)
{
	var strIT = "";
	var intValue = Math.max(0, Math.min(5, total));

	for(x = 1; x <= 5; x+=1) {
		if(x < intValue){
			strIT += "<img src='\./images/SiteImages\\GoldStar.jpg'>";
		}else if(x == intValue){
			strIT += "<img src='\./images/SiteImages\\GoldStar.jpg'>";
		}else{
			strIT += "<img src='\./images/SiteImages\\DarkStar.jpg'>";
		}
	}
	document.all(input_id).value = intValue;
	document.all(div_id).innerHTML = strIT;
}

function starslide2(div_id, input_id, total)
{
	var strIT = "";
	var intValue = Math.max(0, Math.min(5, total));

	for(x = 1; x <= 5; x+=1) {
		if(x < intValue){
			strIT += "<img src='\./images/SiteImages\\GoldStar2.jpg'>";
		}else if(x == intValue){
			strIT += "<img src='\./images/SiteImages\\GoldStar2.jpg'>";
		}else{
			strIT += "<img src='\./images/SiteImages\\GrayStar.jpg'>";
		}
	}
	document.all(input_id).value = intValue;
	document.all(div_id).innerHTML = strIT;
}
*/

