/* javascript function for generating username-password for diffrent mail servers for invite friends*/
function generate_email_block(email_type, ctr, callfrom){
  var mail_suffix = "";

  if (email_type == 'orkut') {
    mail_suffix = email_type;
    login_title = "Email Id :";
  } else {
    mail_suffix = "@"+email_type+".com";
    login_title = "User Name :";
  }
  email_txt = email_type;
  if(ctr){
    if(ctr.checked == true) {
      $('#div_default').hide();
      $('#main_email_block').show();
      $('#password_msg').show();
      $('#submit_btn').show();
      var obj = document.createElement('DIV');
      obj.setAttribute("id","div_"+email_txt);
      $(obj).css('margin', '0');
      $(obj).css('padding', '0');
      var block_style = "";

      if(email_cnt%2 == 1){
        block_style = "style='background:none;'";
      }
//        class="show_error"
      var html = "<span class='pinkbg' "+block_style+"><label><tt class='element_shift'>"+login_title+"</tt><dfn><input type='text'  name='username_"+email_txt+"' id='username_"+email_txt+"' />"+mail_suffix+"</dfn><dfn id = 'err_"+email_txt+"' style = 'display:none' >invalid email address or password</dfn></label><cite style='float:right; backgr ound:pink; text-align:right; width:215px'><tt style='position:relative; right:-10px; text-align:right;'>Password :</tt><dfn><input type='password' name= 'psw_"+email_txt+"' id= 'psw_"+email_txt+"' /></dfn></cite></span>";

      obj.innerHTML = html;
      document.getElementById('email_block').appendChild(obj);
      email_cnt++;
    } else if(ctr.checked == false) {
      document.getElementById('email_block').removeChild(document.getElementById('div_'+email_txt));
      email_cnt--;
      if(email_cnt%2 == 1){
        block_style = "style='border-top:none;background:none;'";
      } else {
        block_style = "style='border-top:none;'";
      }
      if(email_cnt ==0 ){
       if(callfrom == 'invite_friend'){
        //document.getElementById('div_default').style.display = "block";
       }
       document.getElementById('main_email_block').style.display = 'none';
       document.getElementById('password_msg').style.display = 'none';
       document.getElementById('submit_btn').style.display = 'none';
      }
    }
  }
  else {
    email_cnt=0;
    block_style ="";
    //document.getElementById('div_default').style.back
    if(callfrom == 'invite_friend'){
      //document.getElementById('div_default').style.display = "block";
    }
    document.getElementById('main_email_block').style.display = 'none';
    document.getElementById('password_msg').style.display = 'none';
    document.getElementById('submit_btn').style.display = 'none';
  }
  if(email_cnt){
    var i = 0;
    $('.new_bg').each(function() {
       if(i%2 == 0 && i >0){
        $(this).css('background', 'none');
        $(this).css('border-top', 'none');
      } else {
      $(this).css('background', '#EDF7F9');
      }
      i++;
    });
  }
}
function show_people_bubble (object, uid, key, call_from){
  if(call_from == "find_friends"){
    curr_key = key;
  }

  $('#invite_bubble_text').html("");
  var x = findPosX(object) + 0;
  var y = findPosY(object) + 0;
  $('#invite_bubble_body').css('display', 'block');
  $('#invite_people_iframe').css('display', 'block');
  var obj2 = $('#invite_bubble_text');
  $.get(
     base_url + "/ajax/show_invite_bubble.php?type=show_bubble&uid="+uid+"&call_from="+call_from+"&pos="+key,
     {
     },
     function(htmlData) {
        $('#invite_bubble_text').html(htmlData);
     }
   );
  $('#invite_bubble_body').css('left',x-20 +'px');
  $('#invite_bubble_body').css('top', y+20 +'px');
  $('#invite_people_iframe').css('left',x-12 +'px');
  $('#invite_people_iframe').css('top', y+20 +'px');

}
function hide_people_bubble(){
 $('#invite_bubble_text').html("");
 $('#invite_bubble_body').css("display","none");
 $('#invite_people_iframe').css("display","none");
}
function user_not_show(id, uid, call_from){
  var user_list = new Array ;
  var i = 0;
  $('[@id^="pymk_user_list_"]').each(function() {
     user_list[i] = $(this).attr('value');
     i++;
  });
  if(i == 1) {
  $('[@id^="recom_div"]').each(function() {
     $(this).css("display","none");

  });
  $('[@id^="show_pymk"]').each(function() {
     $(this).css("display","inline");
     $('#show_pymk_mail_id_img').attr('src', skin_url+'/images/down-arrow.gif');
     $('#show_pymk_inst_id_img').attr('src', skin_url+'/images/down-arrow.gif');
  });
  }

  $.get(
     base_url + "/ajax/show_invite_bubble.php?type=not_show&uid="+uid+"&pos="+id+ "&call_from="+call_from+"&pymk_user_list="+user_list,
     {
     },
     function(htmlData) {
        if(htmlData == "&nbsp;"){
          $('#individual_'+id).html(htmlData);
          j = 0;
          $('[@id^="individual_"]').each(function() {
            if($(this).attr('innerHTML') == "&nbsp;"){
              $(this).css('border','0 none;');
              $(this).css('display','none');
            } else {
            j++;
            }
          });
          if(j == 1){
            $('[@id^="individual_"]').each(function() {
              $(this).css('border','0 none;');
            });
          }
        } else {
        $('#individual_'+id).html(htmlData);
        }
     }
   );
}
function submit_invite(obj,uid,key,call_from,show_recommend){

//    var x = findPosX(document.getElementById('invite_bubble_body'));
//    var y = findPosY(document.getElementById('invite_bubble_body'));
//
//    $('#invite_bubble_img').css('left',x+130 +'px');
//    $('#invite_bubble_img').css('top', y+55 +'px');
//    $('#invite_bubble_img').css('display','block');
   $('#invite_bubble_text').html("<div class='top'><p class='add_as_friend'><big>Add as friend</big><small></small></p></div><div class='middle' style='float:center'><div class='celb_parent' style='padding:20px 0 0  120px;' ><img  src='"+base_url+"/images/ajax-loader.gif'/></div></div><div class='bottom'></div>");

   var params = {};
    for (var i=0; i < obj.elements.length; i++ ) {
    params[ obj.elements[i].name ] = obj.elements[i].value;
    }
   user_list = new Array;
   if(call_from == 'find_friends' || call_from == 'classmate_search'){
    var j = 0;
    $('[@id^="pymk_user_list_"]').each(function() {
      user_list[j] = $(this).attr('value');
      j++;
    });
   }
    if(j == 1) {
    $('[@id^="recom_div"]').each(function() {
      $(this).css("display","none");

    });
    $('[@id^="show_pymk"]').each(function() {
      $(this).css("display","inline");
      $('#show_pymk_mail_id_img').attr('src', skin_url+'/images/down-arrow.gif');
      $('#show_pymk_inst_id_img').attr('src', skin_url+'/images/down-arrow.gif');
    });
    }
    var url ;
    if(call_from == 'find_friends' || call_from == 'classmate_search'){
     url = base_url + "/ajax/show_invite_bubble.php?type=add_friend&call_from="+call_from+"&pos="+key+"&pymk_user_list="+user_list;
     }
     else {
     url = base_url + "/ajax/show_invite_bubble.php?type=add_friend&call_from="+call_from+"&pos="+key;
    }
   $.post(
    url,
     params,
     function(htmlData) {

//         $('#invite_bubble_img').css('display','none');
        if(htmlData == ''){
         $('#invite_bubble_text').html("<div class='top'><p class='add_as_friend'><big>Add as friend</big><small><img src='"+base_url+"/images/cross_cut.gif' alt='' onclick='hide_people_bubble()' /></small></p></div><div class='middle'><div class='celb_parent' ><p style='text-align:center;;padding-top:25px;'>Sorry, your invite could not be sent.</p><p style='text-align:center;padding-top:5px;'>&nbsp;</p></div></div><div class='bottom'></div>");
         //$('#individual_'+key).html(htmlData);
        } else {
        var recommend_link = "";
        if(show_recommend){
          recommend_link = "<a href='javascript:void(0);' onclick='hide_people_bubble();show_recommend_friend(this,\""+uid+"\");'>Recommend Friend</a>";
        }
        //Not showing recommend link for leadindia
        $('#invite_bubble_text').html("<div class='top'><p class='add_as_friend'><big>Add as friend</big><small><img src='"+base_url+"/images/cross_cut.gif' alt='' onclick='hide_people_bubble()' /></small></p></div><div class='middle'><div class='celb_parent' ><p style='text-align:center;padding-top:25px;'>Your invite has been sent successfully.</p></div></div><div class='bottom'></div>");
//         $('#invite_bubble_text').html("<div class='top'><p class='add_as_friend'><big>Add as friend</big><small><img src='"+base_url+"/images/cross_cut.gif' alt='' onclick='hide_people_bubble()' /></small></p></div><div class='middle'><div class='celb_parent' ><p style='text-align:center;padding-top:25px;'>Your invite has been sent successfully.</p><p style='text-align:center;padding-top:5px;'>"+recommend_link+"</p></div></div><div class='bottom'></div>");

         $('#individual_'+key).html(htmlData);
         $('#add_friend_link'+uid).html("Request Sent");
        }
        j = 0;
        $('[@id^="individual_"]').each(function() {
          if($(this).attr('innerHTML') == "&nbsp;"){
            $(this).css('display','none');
          } else {
          j++;
          }
        });
        if(j == 1){
          $('[@id^="individual_"]').each(function() {
            $(this).css('border','0 none;');
          });
        }
     }
   );
}
function block_user_name( frm ) {
  if( frm.searchfor_user.checked == false && frm.searchfor_comm.checked != false) {
    document.getElementById('user_name_text').style.display = 'none';
  } else if( frm.searchfor_comm.checked == false || frm.searchfor_user.checked == true) {
    document.getElementById('user_name_text').style.display = 'block';
  }
}
function swap_classmate_tab(mode) {
 document.search_classmate.mode.value = mode;
 document.search_classmate.submit();
}
function show_mutual_popup(object, uid){
  x = findPosX(object);
  y = findPosY(object);
  document.getElementById('common_friend_body').style.display = 'block';
  var obj2 = document.getElementById('common_friend_text');
  $.get(
     base_url + "/ajax/show_common_friend.php?uid="+uid+"&type=common",
     {
     },
     function(htmlData) {
        $('#common_friend_text').html(htmlData);
     }
   );
//   document.getElementById('common_friend_body').style.left = x +'px';
//   document.getElementById('common_friend_body').style.top = y +'px';
    document.getElementById('common_friend_body').style.left = 200+scrollX()+'px';
    document.getElementById('common_friend_body').style.top = 70+scrollY()+'px';
    document.getElementById('common_friend_iframe').style.display = 'block';
     document.getElementById('common_friend_iframe').style.left = 380+scrollX()+'px';
     document.getElementById('common_friend_iframe').style.top = 210+scrollY()+'px';
}
function show_recommend_friend(object,uid){
  x = findPosX(object);
  y = findPosY(object);
  document.getElementById('common_friend_body').style.display = 'block';
  var obj2 = document.getElementById('common_friend_text');
  $.get(
     base_url + "/ajax/show_common_friend.php?uid="+uid+"&type=recommend",
     {
     },
     function(htmlData) {
        $('#common_friend_text').html(htmlData);
     }
   );
//   document.getElementById('common_friend_body').style.left = x +'px';
//   document.getElementById('common_friend_body').style.top = y +'px';
     document.getElementById('common_friend_body').style.left = 250+scrollX()+'px';
     document.getElementById('common_friend_body').style.top = 50+scrollY()+'px';
     document.getElementById('common_friend_iframe').style.display = 'block';
     document.getElementById('common_friend_iframe').style.left = 270+scrollX()+'px';
     document.getElementById('common_friend_iframe').style.top = 54+scrollY()+'px';

}
function hide_common_friend_pop_up(){
 $('#common_friend_text').html("");
 document.getElementById('common_friend_body').style.display = 'none';
 document.getElementById('common_friend_iframe').style.display = 'none';

}
function sorting_friend(find_friend) {
  $('a[@id^="user_name_link_"]').each(function() {
    var user_name = $(this).html();
    var split_data = $(this).attr('id').split('_');
    id = split_data[3];
      if ( user_name.toLowerCase().indexOf(find_friend.toLowerCase()) == 0 ) {
      $('#recommend_user_'+id).css('display', 'block');
      }
      else {
      $('#recommend_user_'+id).css('display', 'none');
      }
  })
}
function show_selected_friend(obj,relation,show) {
 if(obj!=''){
    var obj_parent = $(obj).parent().parent().parent().parent();
    $('[@id^="tab_"]').attr('class', 'green_tab');
    $('#'+$(obj_parent).attr('id')).attr('class', 'selected_tab');
  }
  var cnt,selected_cnt=0;
  for(var i=0;i<relation;i++) {
  cnt = i;
   document.getElementById('show_tab').value = show;
  if(show=='ALL') {
   document.getElementById('recommend_user_' + cnt).style.display='block';
  } else if(show == 'SELECTED') {
      if(document.getElementById('rec_user_'+cnt).checked == true) {
      document.getElementById('recommend_user_'+cnt).style.display = 'block';
      } else {
      document.getElementById('recommend_user_'+cnt).style.display = 'none';
  }
  }
  if(document.getElementById('rec_user_'+cnt).checked == true) {
   selected_cnt++;
  }
 }
 if(1) {
 document.getElementById('selected_num').innerHTML = "("+selected_cnt+")";
 }

}
function submit_recommendation(obj){
  var params = {};
  var check_boxes = Array();
  j = 0;
  flag = 0;
  for (var i=0; i < obj.elements.length; i++ ) {
    if ( obj.elements[i].type == 'checkbox' && obj.elements[i].checked ) {
      flag = 1;
      check_boxes[j] = obj.elements[i].value;
      j++;
    }else {
    params[ obj.elements[i].name ] = obj.elements[i].value;
    }
  }
  if(flag == 0){
    document.getElementById('error_div').style.display = "block";
    return false;
  }
  else {
   document.getElementById('error_div').style.display = "none";
  }
  params['check'] = toJSON(check_boxes);
  $.post(
     base_url + "/ajax/show_invite_bubble.php?type=add_recommendation",
     params,
     function(htmlData) {
        $('#common_friend_text').html("");
        document.getElementById('common_friend_iframe').style.display = 'none';
        $('#individual_'+curr_key).html(htmlData);
     }
   );
}
function scrollX() {
  return window.pageXOffset ? window.pageXOffset : document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft;
}
function scrollY() {
  return window.pageYOffset ? window.pageYOffset : document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop;
}

function action_on_community(group_id, user_action) {
  $.get(
    base_url + "/ajax/action_on_community.php",
    {
      'gid':group_id,
      'action':user_action
    },
    function(htmlData) {
      $('#group_user_status_'+group_id).html(htmlData);
    }
  );
}

function celeb_profile(current_val) { 
  document.getElementById('about_me').style.display = "none"; 
  document.getElementById('about_me1').className = "";
  document.getElementById('education').style.display = "none"; 
  document.getElementById('education1').className = "";
  document.getElementById('profession').style.display = "none"; 
  document.getElementById('profession1').className = "";
  document.getElementById('track_record').style.display = "none"; 
  document.getElementById('track_record1').className = "";
  
  document.getElementById(current_val).style.display = "block"; 
  document.getElementById(current_val+'1').className = "active_a";
}

function sort_candidate(curr_field, val) {
  if (curr_field == 'city') {
    var field1 = 'party';
    var field2 = 'consituency';
  } else if (curr_field == 'consituency') {
    var field1 = 'city';
    var field2 = 'party';
    
    var party_val = document.getElementById('party_box').options[document.getElementById('party_box').selectedIndex].value;
  } else if (curr_field == 'party') {   
    var field1 = 'city';
    var field2 = 'consituency';
    
    var city_val = document.getElementById('city_box').options[document.getElementById('city_box').selectedIndex].value;
                     
    var consituency_val = document.getElementById('consituency_box').options[document.getElementById('consituency_box').selectedIndex].value;
  } 
  
  var params = {};
  params['current_field'] = curr_field;
  params['value'] = val;
  params['consituency_val'] = consituency_val;
  params['city_val'] = city_val;
  params['party_val'] = party_val;
  $.post(
    base_url + "/ajax/sort_candidate.php",
    params,
    function(htmlData) { 
      if (htmlData) { 
        var html = htmlData.split('~~');
        var html1 = html[0]; 
        var html2 = html[1];  
        var html3 = html[2]; 
      }                    
      if (html1) {
        $('#'+field1).html(html1);
      }
      if (html2) {
        $('#'+field2).html(html2);
      }
      if (html3) {
        $('#sorted_candidate').html(html3);        
      }
    }
  );
}
function select_candidates(consituency) {
  var params = {};
  params['consituency'] = consituency;
  $.post(
    base_url + "/ajax/select_candidate.php",
    params,
    function(htmlData) {
      if (htmlData) {
        $('#user_consituency_candidate').html(htmlData);
      }
    }
  );
}

function select_constituency_pdf(curr_field, val) {
  if (curr_field == 'city') {
    var field1 = 'constituency_pdf';
  } else if (curr_field == 'constituency') {
    var field1 = 'city_pdf';
    var city_val = document.getElementById('cityBoxPdf').options[document.getElementById('cityBoxPdf').selectedIndex].value;
  }
  var params = {};
  params['current_field'] = curr_field;
  params['value'] = val;
  params['city_val'] = city_val;
  $.post(
    base_url + "/ajax/select_constituency_pdf.php",
    params,
    function(htmlData) {
      if (htmlData) { 
        var html = htmlData.split('~~');
        var html1 = html[0]; 
        var html2 = html[1]; 
      }                    
      if (html1) {
        $('#'+field1).html(html1);
      }
      if (html2) {
        $('#pdf_data').html(html2);
      }
    }
  );
}

function pdf_pagination(limit, curr_field, val, page) {
  if (curr_field == 'city') {
    var field1 = 'constituency_pdf';
  } else if (curr_field == 'consituency') {
    var field1 = 'city_pdf';
  }
  var params = {};
  params['current_field'] = curr_field;
  params['value'] = val; 
  params['limit'] = limit; 
  params['page'] = page; 
  $.post(
    base_url + "/ajax/select_constituency_pdf.php",
    params,
    function(htmlData) {
      if (htmlData) { 
        var html = htmlData.split('~~');
        var html1 = html[0]; 
        var html2 = html[1]; 
      }                    
      if (html1) {
        $('#'+field1).html(html1);
      }
      if (html2) {
        $('#pdf_data').html(html2);
      }
    }     
  );  
}

function open_pdf(file_name) {
  window.open(base_url+"/files/"+file_name, '_blank');
}
