// functions for vocabulary trainer


// functions to learn
//
function showCard(id) {
 var delay = 120;
 switch (id) {
    case -3: $('question').hide();$('questionLeft').hide();$('answerRight').hide();$('cardArea').className='bg_card_3';setTimeout("showCard(-2)",delay);break;
    case -2: $('cardArea').className='bg_card_2';setTimeout("showCard(-1)",delay);break;
    case -1: $('cardArea').className='bg_card_1';setTimeout("showCard(0)",delay);break;
    case 0: $('cardArea').className='bg_card';setTimeout("showCard(1)",delay);break;
    case 1: $('question').hide();$('questionLeft').hide();$('answerRight').hide();$('cardArea').className='bg_card_1';setTimeout("showCard(2)",delay);break;
    case 2: $('cardArea').className='bg_card_2';setTimeout("showCard(3)",delay);break;
    case 3: $('cardArea').className='bg_card_3';setTimeout("showCard(4)",delay);break;
    case 4: $('question').show();$('questionLeft').hide();$('answerRight').hide();$('cardArea').className='bg_card_quest';break;
    case 5: $('question').hide();$('questionLeft').show();$('answerRight').show();$('cardArea').className='bg_card_answ';break;
    case 7: $('question').hide();$('questionLeft').hide();$('answerRight').hide();$('cardArea').className='bg_card_7';setTimeout("showCard(8)",delay);break;
    case 8: $('cardArea').className='bg_card_8';setTimeout("showCard(9)",delay);break;
    case 9: $('cardArea').className='bg_card_9';setTimeout("showCard(1)",delay);break;
 }
}

function vocabLearnFlip() {
 oldQuest = $('question').innerHTML;
 oldQuestLeft = $('questionLeft').innerHTML;
 oldAnswerRigt = $('answerRight').innerHTML;
 $('question').innerHTML = '';
 $('questionLeft').innerHTML = '';
 $('answerRight').innerHTML = '';
 new Ajax.Request(ajaxUrl, {
  method: 'post',
  parameters: {
   flip: 1,
   round: 1,
   card: cardId,
   yn: 0
  }
 });
 state=0;
 showCard(7);
 $('vocabControl1').hide();
 $('vocabControl2').show();
 pageTracker._trackPageview("/" +gSiteLang+ "/actions/vocab/flipcards" +T);
}

function vocabLearnCorrect() {
// ajax to save answer and get next vocab
if (state == 1) {
 countL[cardStatus + 1]++;
 countL[cardStatus]--;
 countLearned++;
 $('countLev' + (cardStatus + 1)).innerHTML = countL[cardStatus + 1];
 $('countLev' + (cardStatus)).innerHTML = countL[cardStatus];
 statusVal = Math.round(25*(countL[2]+countL[3]*2+countL[4]*3+countL[5]*4)/(countL[1]+countL[2]+countL[3]+countL[4]+countL[5]));
 $('roundCount').innerHTML = countLearned+"/"+countVoc;
// $('roundStatus').innerHTML = Math.round(100*countLearned/countVoc)+"%";
// $('overallStatus').innerHTML = statusVal+"%";
 $('vocabCounter').innerHTML--;

 oldQuest = $('question').innerHTML;
 oldQuestLeft = $('questionLeft').innerHTML;
 oldAnswerRigt = $('answerRight').innerHTML;
 $('question').innerHTML = '';
 $('questionLeft').innerHTML = '';
 $('answerRight').innerHTML = '';
 new Ajax.Request(ajaxUrl, {
  method: 'post',
  parameters: {
   round: 1,
   card: cardId,
   yn: 1
  },
  onSuccess: function(transport){
   state = 0;
  },
  onFailure: function(transport){
   //stop new card process
   state = 0;
  }
 });
 showCard(7);
 $('vocabControl1').hide();
 $('vocabControl2').show();
 pageTracker._trackPageview("/" +gSiteLang+ "/actions/vocab/nextcard" +T);
}
}

function vocabLearnWrong() {
if (state == 1) {
// if (cardRC == 2) { // card==RC ==> this is the third try
  countLearned++;
  countL[1]++;
  countL[cardStatus]--;
  $('countLev1').innerHTML = countL[1];
  $('countLev' + (cardStatus)).innerHTML = countL[cardStatus];
                statusVal = Math.round(25*(countL[2]+countL[3]*2+countL[4]*3+countL[5]*4)/(countL[1]+countL[2]+countL[3]+countL[4]+countL[5]));
  $('roundCount').innerHTML = countLearned+"/"+countVoc;
//  $('roundStatus').innerHTML = Math.round(100*countLearned/countVoc)+"%";
//  $('overallStatus').innerHTML = statusVal+"%";
  $('vocabCounter').innerHTML--;
// }
 oldQuest=$('question').innerHTML;oldQuestLeft=$('questionLeft').innerHTML;oldAnswerRigt=$('answerRight').innerHTML;
 $('question').innerHTML='';$('questionLeft').innerHTML='';$('answerRight').innerHTML='';
 new Ajax.Request(ajaxUrl, {
  method: 'post', parameters: { round:1,card:cardId,yn:0 },
  onSuccess: function(transport){
   state = 0;
  },
  onFailure: function(transport) {
   //stop new card process
   state = 0;
  }
 });
 // ajax to save answer and get next vocab
 showCard(-3);
 $('vocabControl1').hide();
 $('vocabControl2').show();
 $('vocabControl3').hide();
 pageTracker._trackPageview("/" +gSiteLang+ "/actions/vocab/nextcard" +T);
}
}

function vocabLearnPrev() {
if (state == 0 && oldQuest!='') {
 // show last vocabulary
 showCard(5);
 state = -1;
 newQuest = $('question').innerHTML;
 newQuestLeft = $('questionLeft').innerHTML;
 newAnswerRigt = $('answerRight').innerHTML;
 $('question').innerHTML = oldQuest;
 $('questionLeft').innerHTML = oldQuestLeft;
 $('answerRight').innerHTML = oldAnswerRigt;
 $('vocabControl1').hide();
 $('vocabControl2').hide();
 $('vocabControl3').show();
 pageTracker._trackPageview("/" +gSiteLang+ "/actions/vocab/prevcard" +T);
}
}

function vocabLearnShow() {
if (state == 0) {
 // show answer
 showCard(5);
 state = 1;
 $('vocabControl1').show();
 $('vocabControl2').hide();
 $('vocabControl3').hide();
        $('controlPrevCard').show();
 pageTracker._trackPageview("/" +gSiteLang+ "/actions/vocab/showcard" +T);
}
if (state == -1) {
 // show new card
        state=0;
 showCard(4);
 $('question').innerHTML = newQuest;
 $('questionLeft').innerHTML = newQuestLeft;
 $('answerRight').innerHTML = newAnswerRigt;
 $('vocabControl1').hide();
 $('vocabControl2').show();
 $('vocabControl3').hide();
 $('controlPrevCard').show();
 pageTracker._trackPageview("/" +gSiteLang+ "/actions/vocab/showcard");
}
}

function vocabKey(e) {
 var keynum;
 var keychar;
 var numcheck;
 var bArrow=false;
 if(window.event) // IE
 {
  keynum = e.keyCode;
 }
 else if(e.which) // Netscape/Firefox/Opera
 {
  keynum = e.which;
 }
 switch (keynum) {
  case 38: // up - correct answer
   vocabLearnCorrect();
   bArrow=true;
   break;
  case 40: // down - incorrect answer
   vocabLearnWrong();
   bArrow=true;
   break;
  case 37: // left - back
   vocabLearnPrev();
   bArrow=true;
   break;
  case 39: // right - show answer
   vocabLearnShow();
   bArrow=true;
  break;
 } // end of switch
 if (bArrow) {
        if (e.preventDefault) {
                e.preventDefault();
        }
        else {
                return false;
        }
 }
}

function initLearning(c1, c2, c3, c4, c5, cv, cl, url) {
 countL[1] = c1;
 countL[2] = c2;
 countL[3] = c3;
 countL[4] = c4;
 countL[5] = c5;
 countVoc=cv;
 countLearned=cl;
 $('cardArea').className='bg_card_1';
 $('cardArea').className='bg_card_2';
 $('cardArea').className='bg_card_3';
 $('cardArea').className='bg_card_quest';
 $('cardArea').className='bg_card_answ';
 $('cardArea').className='bg_card_7';
 $('cardArea').className='bg_card_8';
 $('cardArea').className='bg_card_9';
 $('cardArea').className='bg_card';
 oldQuest='';oldQuestLeft='';oldAnswerRigt='';
 newQuest='';newQuestLeft='';newAnswerRigt='';
 $('question').innerHTML='';$('questionLeft').innerHTML='';$('answerRight').innerHTML='';
 new Ajax.Request(url, {
  method: 'post', paramenters: { round:1 },
  onSuccess: function(transport){
   state = 0;
  },
  onFailure: function(transport) {
   //stop new card process
   state = 0;
  }
 });
 // ajax to save answer and get next vocab
 showCard(1);
// $('cardArea').show();
}

function vocabResetLessons(inId, v) {
  var ajaxUrl = '/tools/resetVocabLesson.php';
         new Ajax.Request(ajaxUrl, {
  method: 'post',
  parameters: {
   id: inId,
   v: v
  },
  onSuccess: function(transport){
  },
  onFailure: function(transport){
   //stop new card process
  }
 });
}
//
// PM
//
function vocabGetPremiumInfo() {
 var url='/tools/getPremiumInfo.php';
 new Ajax.Updater('placeModal', url, {
  method: 'post',
  evalScripts: true,
  parameters: { partner: 1, pid: 1 },
  onSuccess: function(transport) {
  },
  onFailure: function(transport) {
  }
 });
}

function vocabGetPayment() {
 var url='/tools/getPaymentStep1.php';
 new Ajax.Updater('placeModal', url, {
  method: 'post',
  evalScripts: true,
  parameters: { partner: 1, pid: 1 },
  onSuccess: function(transport) {
  },
  onFailure: function(transport) {
  }
 });
}

function vocabGetPaymentStep2() {
 var url='/tools/getPaymentStep2.php';
 var pidId=0; 
 if ($("mPayPid1").checked) pidId=1;
 else if ($("mPayPid2").checked) pidId=2; 
 else if ($("mPayPid3").checked) pidId=3;
 new Ajax.Updater('placeModal', url, {
  method: 'post',
  evalScripts: true,
  parameters: { partner: 1, pid: pidId },
  onSuccess: function(transport) {
  },
  onFailure: function(transport) {
  }
 });
 return false;
}

function vocabDoPayment(em) {
if ($("regTosCheck").checked) {
 vocabClosePayment();
 $("modalPayIframe").show();
 $("babMBgd").show();
 return true;
} else {
 alert(em);
 return false;
}
}

function vocabClosePayment() {
 if (UserAgent.MSIE)    {
   var  selects = document.getElementsByTagName('select');
   for  (i = 0; i <     selects.length; i++) {
     selects[i].style.visibility        = '';
   }
 }
 if ($('modalPay')!=null) $('modalPay').hide();
 if ($('modalBkgd')!=null) $('modalBkgd').hide();
}

function vocabCancelPremium() {
 if (confirm(mCancel)) {
  var url='/tools/vocabCancelPremium.php';
  new Ajax.Request(url, {
   method: 'post',
   parameters: { partner: 1 },
   onSuccess: function(transport) {
   },
   onFailure: function(transport) {
   }
  });
 }
}
//
// Warning for premium content
//
function vocabMsgPremium(lessonId) {
 vocabGetPremiumInfo();
}

function babVocabSpeak(id, pos)
// load swf-player
{
url="/sounds/speak-vocab.php?id=" +id+ "%26pos=" +pos;
speak_html="<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0' width='10' height='10'><param name='movie' value='" +url+ "'><param name='quality' value='high'><param name='loop' value='false'><param name='bgcolor' value='#000000'><param name='menu' value='false'><embed src='" +url+ "' loop='false' width='1' height='1' quality='high' bgcolor='#00000f' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' menu='false'></embed></object>";
speak_html="<object type='application/x-shockwave-flash' data='/emff.swf' width='1' height='1'><param name='bgcolor' value='#ffffff'><param name='movie' value='/emff.swf'><param name='FlashVars' value='src=" +url+ "&amp;autoload=yes&amp;autostart=yes'></object>";
$('placeModal').show();
$('placeModal').innerHTML = speak_html;
pageTracker._trackPageview(gSiteLang + url);
//speakTracker._trackEvent(lang, id);
}

