// JavaScript Document
function selectFavorite(fav,elementNumber) {

  ID = fav;
  elemNo = elementNumber;
  if (ID == 'show'){
    MyJSONObject = '{                                                                                      '+
                   ' "claz":                "'+jQuery("#show"+elemNo+" input[name=claz]").val()+'",                  '+
                   ' "defaultShowPhotoUrl": "'+jQuery("#show"+elemNo+" input[name=defaultShowPhotoUrl]").val()+'",   '+
                   ' "defaultShowPageUrl":  "'+jQuery("#show"+elemNo+" input[name=defaultShowPageUrl]").val()+'",    '+
                   ' "title":               "'+jQuery("#show"+elemNo+" input[name=title]").val()+'",                 '+
                   ' "showId":              "'+jQuery("#show"+elemNo+" input[name=showId]").val()+'"                 '+
                   '}                                                                                      ';
  }
  else if (ID == 'video'){
    MyJSONObject = '{                                                                                         '+
                   ' "claz":                  "'+jQuery("#video"+elemNo+" input[name=claz]").val()+'",                  '+
                   ' "defaultVideoPhotoUrl":  "'+jQuery("#video"+elemNo+" input[name=defaultVideoPhotoUrl]").val()+'",  '+
                   ' "defaultVideoUrl":       "'+jQuery("#video"+elemNo+" input[name=defaultVideoUrl]").val()+'",       '+
                   ' "season":                "'+jQuery("#video"+elemNo+" input[name=season]").val()+'",                '+
                   ' "episode_number":        "'+jQuery("#video"+elemNo+" input[name=episode_number]").val()+'",        '+
                   ' "showTitle":             "'+jQuery("#video"+elemNo+" input[name=showTitle]").val()+'",             '+
                   ' "videoTitle":            "'+jQuery("#video"+elemNo+" input[name=videoTitle]").val()+'",            '+
                   ' "videoId":               "'+jQuery("#video"+elemNo+" input[name=videoId]").val()+'",               '+
                   ' "showId":                "'+jQuery("#video"+elemNo+" input[name=showId]").val()+'"                 '+
                   '}                                                                                         ';
  }
  else if (ID == 'actor'){
      actorTitle = jQuery('#actor'+elemNo+' input[name=title]').val();
            
      MyJSONObject = '{                                                                                       '+
                   ' "claz":                "'+jQuery("#actor"+elemNo+" input[name=claz]").val()+'",                    '+
                   ' "defaultBioPhotoUrl":  "'+jQuery("#actor"+elemNo+" input[name=defaultBioPhotoUrl]").val()+'",      '+
                   ' "defaultBioUrl":       "'+jQuery("#actor"+elemNo+" input[name=defaultBioUrl]").val()+'",           '+
                   ' "title":               "'+actorTitle+'",                                                           '+
                   ' "showTitle":           "'+jQuery("#actor"+elemNo+" input[name=showTitle]").val()+'",               '+
                   ' "showId":              "'+jQuery("#actor"+elemNo+" input[name=showId]").val()+'"                   '+
                   '}                                                                                                   ';
                   
  }
  else if (ID == 'character'){
      charTitle = jQuery('#character'+elemNo+' input[name=title]').val();
      
      MyJSONObject = '{                                                                                       '+
                   ' "claz":                "'+jQuery("#character"+elemNo+" input[name=claz]").val()+'",                    '+
                   ' "defaultBioPhotoUrl":  "'+jQuery("#character"+elemNo+" input[name=defaultBioPhotoUrl]").val()+'",      '+
                   ' "defaultBioUrl":       "'+jQuery("#character"+elemNo+" input[name=defaultBioUrl]").val()+'",           '+
                   ' "title":               "'+charTitle+'",                                                                    '+
                   ' "showTitle":           "'+jQuery("#character"+elemNo+" input[name=showTitle]").val()+'",               '+
                   ' "showId":              "'+jQuery("#character"+elemNo+" input[name=showId]").val()+'"                   '+
                   '}                                                                                         ';
  }
  submitFavorite(MyJSONObject);
}

function submitFavorite(json){
  data = eval("("+json+")");
  jQuery.post("/community/addFavorites.html", data, function(data){
  finalJob(data);},"json");
}

function finalJob(data){
  myTest = data.message;
  divId = ID+'Fav'+elemNo;
  if (myTest == "Please Login first!"){
    var thisURL = window.location.toString();
    document.getElementById(divId).innerHTML = '<a href="/community/login/loginform.html?desturl='+thisURL+'">Please Login</a>';
  }
  else if (myTest=="Success"){
    document.getElementById(divId).innerHTML = 'Favorite Added';
  }
}