// !!!!!!! RATING PROCESS

function fxRate(vkey,rate,idToHide,idToShow,vid) {
  //alert(idToHide + " " + idToShow);
//  ajax("ajax/rate_listing_ajax.php?vid="+vid+"&rate="+rate+"&func=process_data",return_data);
  ajax("ajax/rate_listing_ajax.php?id_listing_info="+id_listing+"&rate="+rate+"&func=process_data",return_data);
  //cp.call('ajax/rate_listing_ajax.php','process_data',return_data,rate,vid);
  //hideMe(idToHide);
  //showMe(idToShow);

  //  document.getElementById(idToShow).style.display="";
  //  alert('test');
  //document.getElementById(idToHide).style.display="none";

  //  setTimeout('afterFiveSeconds()',5000)
}


function return_data(restul) {

            

			
  // Collect the number of BLUE star
  var cnt=restul.trate;
  //alert(cnt);
  // document.getElementById('idViewVoteResult').style.display="none";
  //hideMe('idViewVoteResult');
  if(cnt!='exist')
  {
    // # Show the vote
    // var x=document.getElementById('idVoteView').rows[0].cells;
    //      x[1].innerHTML=restul.tvote;

    if(cnt>5)
    {
      cnt=5;
    }
    else if (cnt<0)
    {
      cnt=0;
    }

    str="";
    for (i=0;i<cnt;i++ )
    {
      str=str+'<img src="'+imgurl+'/general/bighouse_1.gif" class="lgRateHouse">';
    }

    for (j=cnt;j<5;j++ )
    {
      str=str+'<img src="'+imgurl+'/general/bighouse_0.gif" class="lgRateHouse">';
    }
//    alert(str);
    document.getElementById('ratingDiv').innerHTML=str;
    document.getElementById('divVoteResult').innerHTML = '<span class="bolder">Average: '+cnt+'</span><br/>('+restul.tvote+' votes)';
    document.getElementById("ratingMessage").innerHTML = "Thanks for rating!";
  }
  else
  {
    var x=document.getElementById('voteProcessthank').innerHTML="<FONT COLOR=#FF0000 >You already vote this video</FONT>";
  }

  return false;
}
// RATING PROCESS END
function afterFiveSeconds() {
  //  alert(document.getElementById('divVoteResult').innerHTML);
  document.getElementById('divVoteResult').style.display="";
  //  document.getElementById('idVoteView').style.display="";
  document.getElementById('idViewVoteResult').style.display="";
}



// !!!!!!! My voting process

function fxVote(voteId)
{
  voteAnswer=document.getElementById('opAns').value;

  if(voteAnswer=='')
  {
    alert('Select any one');
  }
  else
  {
    cp.call(baseurl+'/ajax/rate_listing_ajax.php','process_Vote',return_vote_result,voteId,voteAnswer);
  }
}
function return_vote_result(result)
{
  var xx=result.getElementsByTagName('result').item(0).firstChild.data;
  if (xx=='1'){
    count=result.getElementsByTagName('count').item(0).firstChild.data;

    for (var  ii=0; ii<count  ; ii++ ){

      var vv='A1'+ii;
      var pp='P1'+ii;

      vv=result.getElementsByTagName(vv).item(0).firstChild.data;
      pp=result.getElementsByTagName(pp).item(0).firstChild.data;

      // # Generate Voring table
      var tt=document.getElementById('tblVoteResult').insertRow(0);
      var y=tt.insertCell(0);
      var z=tt.insertCell(1);
      y.innerHTML=vv;
      z.innerHTML=pp +'%';

      if(vv==""){
        break;
      }
    }

    insertInToTable('tblPResult', 0,0,'Vote result');
    // # Hide the previous tale
    hideMe('divviewvresult');
    hideMe('tblVote');

  }
  else if(xx>1)
  {

    insertInToTable('tblPResult', 0,0,'<font color=#FF0000><B>Sorry you already voted..</B></FONT>');
    viewVote(xx);
    // # Hide the previous table
    //showMe('divviewvresult');
    hideMe('tblVote');
  }
}


// END

// VIEW VOTE
function viewVote(pollId)
{
  cp.call(baseurl+'/ajax/rate_listing_ajax.php','view_vote',return_view_vote,pollId);
}
function return_view_vote(result){
  var xx;
  if (1){
    count=result.getElementsByTagName('count').item(0).firstChild.data;
    for (var  ii=0; ii<count  ; ii++ ){

      var vv='A1'+ii;
      var pp='P1'+ii;

      vv=result.getElementsByTagName(vv).item(0).firstChild.data;
      pp=result.getElementsByTagName(pp).item(0).firstChild.data;

      // # Generate Voring table
      var tt=document.getElementById('tblViewVoteResult').insertRow(0);
      var y=tt.insertCell(0);
      var z=tt.insertCell(1);
      y.innerHTML=vv;
      z.innerHTML=pp +'%';

      if(vv==""){
        break;
      }
    }
    insertInToTable('tblViewVote', 0,0,'Current vote status');
  }

}



// !!!!!!!! SEND COMMENT PROCESS

function fxSendComments(idToHide,commentId,uid,vid){
  comment_value=document.getElementById(commentId).value;
  if(comment_value==''){
    alert(' Comment box is empty !!');
  }
  else{
    hideMe(idToHide);
    alert('wqeqweqweqw test !!!');
    cp.call(baseurl+'/ajax/rate_listing_ajax.php','process_comments',return_comment_response,comment_value,uid,vid);
  }

}

function return_comment_response(restul){

  if(restul.getElementsByTagName('a').item(0).firstChild.data==0){
    showMe('divComResult2');
  }
  else{
    showMe('divComResult1');
  }
}
// END


function pollAnsBox(myID)
{
  Me=document.getElementById(myID);
  if(Me.value==""){
    Me.style.background="#3366FF";

  }
  else{

    Me.style.background="#FFFFFF";
    xy=Me.value;
    for (i=0;i<Me.value;i++ ){
      var x=document.getElementById('tblViweAnsBox').insertRow(0);
      var y=x.insertCell(0);
      var z=x.insertCell(1);
      y.innerHTML='Answer ' + (xy-i);
      z.innerHTML='<INPUT TYPE=text SIZE=40 NAME=voteAnsBox'+i+' ID=voteAnsBox'+i+' onBlur=txtBoxValidation(voteAnsBox'+i+', #EAEAEA,#FF0033) >';
    }
  }
}

// ## Delete row of a Tabile
function delteRow(){
  var x=document.getElementById('tblViweAnsBox').rows.length-1;

  for (var i=x;i>=0;i--){
    document.getElementById('tblViweAnsBox').deleteRow(i);
  }
}


function fxvalidation(){
  var flag=true;
  var x=document.getElementById('tblViweAnsBox').rows.length-1;

  // ## Question text
  flag=txtBoxValidation('txtQtn','#EAEAEA','#FF0033');

  // ## Questin qty
  flag=txtBoxValidation('txtPollAnsQty','#EAEAEA','#FF0033');


  for ( i=x; i>=0; i-- )
  {
    targetID='voteAnsBox'+i;
    if (document.getElementById(targetID).value==""){
      txtBoxValidation(targetID,'#EAEAEA','#FF0033');
      flag=false;
      break;
    }


  }

  return flag;
}


function fxShowAccInfo(a,b){
  showMe(a);
  hideMe(b);
}


function pollAnsBox($num){
  alert($num);
}
