// if (top.location != self.location) top.location=self.location; 

function SetCookie(cookieName,cookieValue,nDays) {
    var today = new Date();
    var expire = new Date();
    if (nDays==null || nDays==0) nDays=1;
    expire.setTime(today.getTime() + 60*60*1000*24*nDays);
    document.cookie = cookieName+"="+escape(cookieValue) + ";expires="+expire.toGMTString();
}

function tellAfriend()
{      
var strTitle = document.title

var safeTitle = strTitle.replace(/&/gi, "and")
var safeTitle = safeTitle.replace(/<br>/gi, " ")

  if (document.title.length == 0)
  	var strBody = "The page is regarding wenxuecity.com, and is located here: "+window.location;
  else
  	var strBody = "The page is regarding '"+safeTitle+"', and is located here: "+window.location;
  
  var strSubject = "I thought this page from wenxuecity.com might interest you...";
  window.location = "mailto:?subject="+strSubject+"&body="+strBody;
}

var VP_smallStar = "images/star-full.gif";
var VP_smallStarHalf = "images/star-half.gif";
var VP_smallStarEmpty = "images/stars-off.gif";
var VP_largeStarOn = "images/stars-on.gif";
var VP_largeStarOff = "images/stars-off.gif";

var MSG_RATING_POOR = '我鼓<strong>1</strong>掌';
var MSG_RATING_BELOW_AVERAGE = '我鼓<strong>2</strong>掌';
var MSG_RATING_AVERAGE = '我鼓<strong>3</strong>掌';
var MSG_RATING_ABOVE_AVERAGE = '我鼓<strong>4</strong>掌';
var MSG_RATING_EXCELLENT = '我鼓<strong>5</strong>掌!';

var MSG_ANNOTATION_SAVING = '感谢您的支持...';

var rated = false;
var newRating = -1;

function getEle(eleName) {
 if(document.getElementById && document.getElementById(eleName)) {
    return document.getElementById(eleName);
  }
  else if (document.all && document.all(eleName)) {
    return document.all(eleName);
  }
  else if (document.layers && document.layers[eleName]) {
    return document.layers[eleName];
  } else {
    return false;
  }
}

function setStars(url, val, location) {
  getEle("rating_info_" + location).style.display = "inline";
  if (location == 'top') {
    // need to conceal community rating
    // getEle('communityRating').style.display = "none";
	  getEle('rating_' + location).style.display = "none";
  }
  getEle("rating_info_" + location).innerHTML = MSG_ANNOTATION_SAVING;
  rated = true; 
  submitRating(url, val, location);
 }

function overStars(rating, location, realRating, cell) {
  rated = false;
  cell.style.cursor='pointer';
  getEle("rating_info_" + location).style.display = "inline";
  if (location == 'top') {
    // need to conceal community rating
    getEle('communityRating').style.display = "none";
  }

  getEle('1_' + location).src = VP_largeStarOff;
  getEle('2_' + location).src = VP_largeStarOff;
  getEle('3_' + location).src = VP_largeStarOff;
  getEle('4_' + location).src = VP_largeStarOff;
  getEle('5_' + location).src = VP_largeStarOff;

  if (rating >= 1) {
    getEle('1_' + location).src = VP_largeStarOn;
    getEle('rating_info_' + location).innerHTML = MSG_RATING_POOR;
  }
  if (rating >= 2) {
    getEle('2_' + location).src = VP_largeStarOn;
    getEle('rating_info_' + location).innerHTML = MSG_RATING_BELOW_AVERAGE;
  }
  if (rating >= 3) {
    getEle('3_' + location).src = VP_largeStarOn;
    getEle('rating_info_' + location).innerHTML = MSG_RATING_AVERAGE;
  }
  if (rating >= 4) {
    getEle('4_' + location).src = VP_largeStarOn;
    getEle('rating_info_' + location).innerHTML = MSG_RATING_ABOVE_AVERAGE;
  }
  if (rating >= 5) {
    getEle('5_' + location).src = VP_largeStarOn;
    getEle('rating_info_' + location).innerHTML = MSG_RATING_EXCELLENT;
  }
}

function outStars(rating, location, realRating, cell) {
  cell.style.cursor='default';
  if (!rated) {
    getEle('communityRating').style.display = "inline";
    if (newRating == -1) {
      setStarsToValueInLocation(realRating, location);
    } else {
      setStarsToValueInLocation(newRating, location);
    }
  } else {
    getEle('1_' + location).src = VP_largeStarOff;
    getEle('2_' + location).src = VP_largeStarOff;
    getEle('3_' + location).src = VP_largeStarOff;
    getEle('4_' + location).src = VP_largeStarOff;
    getEle('5_' + location).src = VP_largeStarOff;
  }
}

function submitRating(url, rating, location) {
  window.open(url + '&rate=' + rating,'_blank','width=300,height=100,scrollbars=0,status=0,resizable=0,directories=0,toolbar=0');
}

function setStarsToValueInLocation(rating, location) {
    getEle('rating_info_'+ location).innerHTML = '';
    getEle('rating_info_' + location).style.display = "none";
    getEle('1_' + location).src = VP_largeStarOff;
    getEle('2_' + location).src = VP_largeStarOff;
    getEle('3_' + location).src = VP_largeStarOff;
    getEle('4_' + location).src = VP_largeStarOff;
    getEle('5_' + location).src = VP_largeStarOff;

    if (rating >= 1) {
      getEle('1_' + location).src = VP_largeStarOn;
    }
    if (rating >= 2) {
      getEle('2_' + location).src = VP_largeStarOn;
    }
    if (rating >= 3) {
      getEle('3_' + location).src = VP_largeStarOn;
    }
    if (rating >= 4) {
      getEle('4_' + location).src = VP_largeStarOn;
    }
    if (rating >= 5) {
      getEle('5_' + location).src = VP_largeStarOn;
    }
}