// JavaScript Document
function starSelect(starID,optionalStarParam) {
                if (optionalStarParam === undefined){
                        optionalStarParam = 0;
                }

optionalStar = optionalStarParam;
  myStarID = starID;
  ID = document.getElementById(starID).innerHTML;
  document.getElementById('rating').value = ID;


  myStar = document.getElementById('rating').value;

  videoForm(optionalStar);
  //alert("star rating ="+myStar+"and mpid="+mpid);
}

function escapeQuote2(text){
   var result = text.replace("'","\\'");
   return result;
}

function videoForm(optionalStar){

MyJSONObject = '{                                                                                               '+
                   ' "claz":                  "'+jQuery("#ratevideo input[name=claz]").val()+'",                  '+
                   ' "rating":                "'+jQuery("#ratevideo input[name=rating]").val()+'",                '+
                   ' "defaultVideoPhotoUrl":  "'+jQuery("#ratevideo input[name=defaultVideoPhotoUrl]").val()+'",  '+
                   ' "defaultVideoUrl":       "'+jQuery("#ratevideo input[name=defaultVideoUrl]").val()+'",       '+
                   ' "season":                "'+jQuery("#ratevideo input[name=season]").val()+'",                '+
                   ' "episode_number":        "'+jQuery("#ratevideo input[name=episode_number]").val()+'",        '+
                   ' "showTitle":             "'+escapeQuote2(jQuery("#ratevideo input[name=showTitle]").val())+'",             '+
                   ' "videoTitle":            "'+escapeQuote2(jQuery("#ratevideo input[name=videoTitle]").val())+'",            '+
                   ' "videoId":               "'+jQuery("#ratevideo input[name=videoId]").val()+'",               '+
                   ' "showId":                "'+jQuery("#ratevideo input[name=showId]").val()+'"                 '+
                   '}                                                                                             ';
                if (optionalStar == 1){
                        alert(MyJSONObject);
                }

  selectTest=eval("("+MyJSONObject+")");
 jQuery.post("/community/starRating.html", selectTest, function(data){
                finalStarJob(data);},"json");
}

function finalStarJob(data){
  myTest = data.message;
  divId = "rateThis";
  if (myTest == "Please Login first!"){
    var thisURL = window.location.toString();
    var newPage = thisURL.replace( "?", "," );
    myArray = newPage.split(',');
    var finalPage = myArray[0];
    document.getElementById(divId).innerHTML = '<a href="/community/login/loginform.html?desturl='+finalPage+'">Please Login</a>';
  }
  else if (myTest=="Success"){
      document.getElementById('starRating').className = "rating "+myStarID;
  }
}
