var ajax_urls = new Array();
var ajax_titles = new Array();
var current_theme_path;
var login_click;
var chk_box_counter = 1;
var error_border = '1px solid rgb(220, 3, 3)';
var fix_border = '1px solid #1a84bb';
var error_border_color = 'rgb(220,3,3)';
// Find Position
function findPosX(obj) {
  var curleft = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curleft += obj.offsetLeft;
      obj = obj.offsetParent;
    }
  }
  else if (obj.x)
    curleft += obj.x;
  return curleft;
}
function findPosY(obj) {
  var curtop = 0;
  if (obj.offsetParent) {
    while (obj.offsetParent) {
      curtop += obj.offsetTop
      obj = obj.offsetParent;
    }
  }
  else if (obj.y)
    curtop += obj.y;
  return curtop;
}
function isValidEmail(strEmail) {
  validRegExp = /^[^@]+@[^@]+.[a-z]{2,}$/i;
  if(strEmail.search(validRegExp) == -1) {
    return false;
  }
  return true;
}
function confirm_delete(msg) {
  var msg = msg;
  if (confirm(msg)) {
    return true;
  }
  else {
    return false;
  }
}
function trim(field) {
  value = field;
  while (value.charAt(value.length-1) == " ") {
    value = value.substring(0,value.length-1);
  }
  while(value.substring(0,1) ==" ") {
    value = value.substring(1,value.length);
  }
  return value;
}
// for Confirmation on deleting
function delete_confirmation_msg(msg) {
  return_argument = confirm(msg);
  return return_argument;
}
//UploadedImageModule, ViewAllMediaModule
function image_popup(obj, id,type_spec) {
  obj = obj.firstChild;
  var image_width = obj.width;
  var image_height = obj.height;
  if (type_spec == 'image') {
    var mydiv = document.getElementById('divIdName'+id);
  }else {
    var mydiv = document.getElementById('VideoDiv'+id);
  }
  x = findPosX(obj);
  y = findPosY(obj);
  x += image_width - 10;
  y += image_height - 10;
  mydiv.style.top = y + 'px';
  mydiv.style.left = x + 'px';
  mydiv.style.display = 'block';
}
//UploadedImageModule, ViewAllMediaModule
function image_out(id,type_spec) {
  if (type_spec == 'image') {
    document.getElementById('divIdName'+id).style.display = 'none';
  }else {
    document.getElementById('VideoDiv'+id).style.display = 'none';
  }
}
function checkall_fields(form_name, field, str) { 
var str = (str == null) ? "friend" : str;
count = 0;
count = document.forms[form_name].elements.length;
chk_cnt=0;
var check_flag = false;
for (i=0; i < count; i++) {
  if (document.forms[form_name].elements[i].type=='checkbox') {
    if (document.forms[form_name].elements[i].checked == 1) {
    chk_cnt++;
    check_flag = true;
    }
    if(field=='check') {
    document.forms[form_name].elements[i].checked = 1;
    } else if(field=='uncheck') {
        document.forms[form_name].elements[i].checked = 0;
    }
  }
 }

 if(field=='accept') {
  if(chk_cnt) {
    if (chk_cnt >= 1) {
      document.getElementById('request_friend_action').value = 'accept';
      document.forms[form_name].submit();
    }
  } else { 
      set_error_massage('Please select a friend request to accept');
  }
  
 } else if(field=='decline') {
  if(chk_cnt) {
    if (chk_cnt >= 1) {
      document.getElementById('request_friend_action').value = 'decline';
      document.forms[form_name].submit();
    }
  } else {
      set_error_massage('Please select a friend request to decline');
    }
 }
 if(field=='delete') {
  if(chk_cnt) {
    if (chk_cnt >= 1) {
      document.forms[form_name].submit();
    }
  } else {
    set_error_massage('Please select a option to delete');
  }
 }
 if(field=='report') {
  if(chk_cnt) {
    if (chk_cnt >= 1) {
    document.forms[form_name].action =base_url+'/report_messages.php';
    document.forms[form_name].submit();
    }
  }
 }
}
function redirect(url) {
  if(url) {
    window.location = url;
  }
}
function message_action(message, id) {
  switch (message) {
    case 'delete':
      document.forms['message_form'].form_action.value = 'delete';
      document.getElementById('message_index_id').value = id;
      break;
    case 'reply':
      document.forms['message_form'].mid.value = id;
      document.forms['message_form'].do_action.value = 'reply';
      break;
    case 'forward':
      document.forms['message_form'].mid.value = id;
      document.forms['message_form'].do_action.value = 'forward';
      break;
    case 'edit':
      document.forms['message_form'].mid.value = id;
      document.forms['message_form'].do_action.value = 'edit';
      break;
  }
  document.forms['message_form'].submit();
}
function update_relationship_status(obj,id,counter) {
  url = 'update_relationship.php?uid='+id+'&type='+obj.value;
  url += "&random=" + (new Date().getTime());
  id = 'show_update_result_'+counter;
  document.getElementById(id).innerHTML = '';
  $('#').load(url);
  $('#'+id).fadeIn(500, function(){ document.getElementById(id).innerHTML= __("Relationship updated successfully");
  $('#'+id).fadeOut(7000);
  });
}
function comment_reply_box(id) {
  val = 'reply_box_'+id;
  val1= 'sub_reply_box_'+id;
  reply = 'reply_text_'+id;
  document.getElementById(reply).value='';
  document.getElementById(val).style.display='none';
  if (document.getElementById(val1).style.display=='block') {
    document.getElementById(val1).style.display='none';
  } else {
    document.getElementById(val1).style.display='block';
	document.getElementById(reply).style.width = 250+'px';
    document.getElementById(reply).focus();
  }
}
function cancel_reply_box(id) {
  val = 'reply_box_'+id;
  val1 = 'sub_reply_box_'+id;
  reply = 'reply_text_'+id;
  document.getElementById(reply).value='';
  document.getElementById(val).style.display='none';
  document.getElementById(val1).style.display='none';
}
function submit_reply_box(sender_id, recipient_id, reply_text, id, user_name) {
  var val = 'sub_reply_box_'+id;
  var display_id = 'reply_box_'+id;
  var body = document.getElementById(reply_text).value;
  var ref_url = window.location;
  ref_url = '';
  var url = base_url+'/save_reply_comment.php?sender_id='+sender_id+'&recipient_id='+recipient_id+'&body='+body+'&referrer='+ref_url+'&name='+user_name;
  url += "&random=" + (new Date().getTime());
  document.getElementById(val).style.display='none';
  document.getElementById(display_id).style.display='block';
  $.get(
    url,
    {
    },
    function(data) {
      $('#'+display_id).html(data);
    }
  );
}
function change_search_params(seachval, id) {
 try {
    type = seachval
    val = document.getElementById(id).value ;
    if (val =='') {
      url = 'peoples.php?type='+type;
    } else {
      url = base_url+'/peoples.php?type='+type+'&text_search='+val+'&submit_search=search';
    }
  } catch (e) {  }
  window.location = url;
}
function search_type(form_id,dropdown_id) {
  val = document.getElementById(form_id).value;
  type = document.getElementById(dropdown_id).value ;
  if (val =='') {
    url = 'peoples.php?type='+type;
  } else {
    if(type=='user') {
      url = 'peoples.php?type='+type+'&first_name='+val+'&submit_search=search';
    } else {
      url = 'peoples.php?type='+type+'&'+type+'_search='+val+'&submit_search=search';
    }
  }
  window.location = url;
}
function set_mood (mood_id) {
  url = 'set_mood.php?mood_id='+mood_id;
  url += "&random=" + (new Date().getTime());
  id = 'update_mood';
  $('#'+id).load(url);
}
function show_hide_div(id) {
  if(document.getElementById(id).style.display=='block') {
    document.getElementById(id).style.display='none';
  } else {
    document.getElementById(id).style.display='block';
  }
}
function setHomepage(what, url) {
  if (navigator.appName == 'Microsoft Internet Explorer' && document.getElementById) {
    setHomepageExplorer(what, url);
  } else if (document.layers || document.getElementById) {
    setHomepageNetscape(what, url);
  }
  return false;
}
function setHomepageNetscape(what, url) {
  var warn = 'Due to Netscapes security handling, this page will show you a dialog with a warning.' + 'If you do not wish to grant this site the access to ' + 'your browser settings, you can manually copy ' + 'http://itimes.com and paste it in the location field in ' + 'Edit|Preferences|Navigator.';
  if ( confirm(warn) ) {
    netscape.security.PrivilegeManager.enablePrivilege("UniversalPreferencesWrite");
    navigator.preference('browser.startup.homepage', url);netscape.security.PrivilegeManager.disablePrivilege("UniversalPreferencesWrite");
  }
}
function setHomepageExplorer(what, url) {
  what.style.behavior = 'url(#default#homepage)';
  what.setHomePage(url);
}
function addslashes(str) {
	str=str.replace(/\'/g,'\'');
	str=str.replace(/\"/g,'\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}
function match_height(id1, id2) {
  h1 = document.getElementById(id1).offsetHeight;
  h2 = document.getElementById(id2).offsetHeight;
  if(h1>h2) {
    document.getElementById(id2).style.height = h1-1+'px';
  } else {
    document.getElementById(id1).style.height = h2-1+'px';
  }
}
function serach_side_block_validation(obj, field) {
  if (obj.elements[field].value == 'Type your keyword') {
    alert("Please insert a keyword")
    obj.elements[field].focus();
    return false;
  }
}
function ismaxlength(obj) {
  var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")) : ""
  if ( obj.getAttribute && obj.value.length > mlength ) {
    obj.value=obj.value.substring(0, mlength)
    showToolTip_from(obj.id, "You can write only " + mlength + " characters.",325,6);
     var hide_bubble = "document.getElementById('bubble_body').style.display='none';document.getElementById('bubble_iframe').style.display='none';";
     clear_bubble_hide = window.setTimeout(hide_bubble,3000);
  }
}
var swap_tab_allowed='true';
function swap_tab(obj) {
  if(swap_tab_allowed=='true') {
    $('#bubble_body').css('display', 'none');
    $('#bubble_iframe').css('display', 'none');
    var parent_table = $(obj).parent().parent().parent().parent().parent().parent().parent()
    $('td.selected_tab', parent_table).each(function() {
      $(this).attr('class', 'green_tab');
      $('#'+$(this).attr('id') + '_data').css('display', 'none')
    });
    var selected_obj = $(obj).parent().parent().parent().parent();
    $(selected_obj).attr('class', 'selected_tab');
    $('#'+ $(selected_obj).attr('id') + '_data').css('display', 'block');
  } else {
    var edu_status = check_editprofile();
    if(edu_status) {
      showToolTip_from('save_all', 'Please save the details',110,6);
    }
  }
}
function swap_ajax_call(type, media_id, uid, obj) {
  swap_tab(obj);
  if ( type == 'media' ) {
    $('#tab').val('media');
    $('#pagging_links').show();
    $('#photo_privacy_settings_link').show();
  }
  else {
    $('#pagging_links').hide();
    $('#photo_privacy_settings_link').hide();
  }
  var req_url = '';
  if ( type == 'flickr_photo' ) {
    req_url = base_url+"/ajax/flickr_pics.php";
  }
  else if ( type == 'picasa_photo' ) {
    req_url = base_url+"/ajax/picasa_pics.php";
  }
  else if ( type == 'youtube_video' ) {
    $('#tab').val('youtube');
    req_url = base_url+"/ajax/youtube.php";
  }
  if ( req_url ) {
    $.get(
      req_url,
      {
        'id':media_id,
        'uid':uid,
        'random': (new Date().getTime())
      },
      function(htmlData) {
        $('#'+ type + '_data').html(htmlData);
      }
    );
  }
}
function swap_food(obj) {
  $('[@id^="col_a_"]').css({display:"none"});
  $('#col_a_'+obj.value).css({display:"block"});
  $('[@id^="col_b_"]').css({display:"none"});
  $('#col_b_'+obj.value).css({display:"block"});
}
function show_pics(photo_type, media_id, uid, obj) {
  var obj_parent = $(obj).parent().parent().parent().parent();
  if ( $(obj_parent).attr('class') != 'selected_subtab' ) {
    $('[@id^="photos_arrow_"]').attr('class', 'unselected_subtab');
    $('[@id^="images_"]').hide('slow');
    $('#'+$(obj_parent).attr('id')).attr('class', 'selected_subtab');
    $('#'+photo_type).show('slow');
    $('#pagging_links').hide();
    property = photo_type.split('_')
    var req_url;
    if ( property[1] == 'flickr' ) {
      req_url = "ajax/flickr_pics.php"
    }
    else if ( property[1] == 'picasa' ) {
      req_url = "ajax/picasa_pics.php"
    }
    else if ( property[1] == 'youtube' ) {
      req_url = "ajax/youtube.php"
    }
    else if ( property[1] == 'email' ) {
      req_url = "ajax/zimbra_friends.php"
    }
    if ( req_url ) {
    $.get(
      req_url,
      {
        'id':media_id,
        'uid':uid,
        'random': (new Date().getTime())
      },
      function(htmlData) {
        $("#"+photo_type).html(htmlData);
      });
    }
    else {
      $('#pagging_links').show();
    }
  }
}
//create classified
function display_text_field(obj, id) {
  if ( obj.value == 'Other' ) {
    $('#'+id).css('visibility', 'visible');
    $('#'+id).attr('value', '');
    $('#'+id).attr('disabled', false);
    $('#'+id).focus();
  }
  else {
    $('#'+id).css('visibility', 'hidden');
    $('#'+id).attr('value', '');
    $('#'+id).attr('disabled', true);
  }
}
function show_invite_nonitimesuser(caption, html, height, width, nonmodal, name, email) {
  html_data = '<div class="top"><p class="add_as_friend"><big>&nbsp;</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" style="width:170px;" ><p style="text-align:center;padding:25px 0 0 0;">'+name+' '+__("is not itimes user.")+'</p><p style = "text-align:center;">'+__("Please invite")+' '+name+' '+__("to join itimes.")+'</p><p style="padding:10px 0 0 70px;"><span><i><dfn style="float:left;padding-right:5px;"><u class="green_left"></u><u><input type = "button" tabindex="0" style="font-weight:normal;" id="yes_btn" value='+__("Invite")+' name = "submit" class = "green_center green_padding_left_right" onclick="javascript:invite_nonitimesuser_yes(\''+name+'\', \''+email+'\');" /> </u><u class="green_right"></u></dfn><dfn style="float:left;"><u class="green_left"></u><u ><input type="button" value='+__("Cancel")+' onclick="hide_people_bubble()" class="green_center green_padding_left_right"  tabindex="2" /></u><u class="green_right"></u></dfn></i></span></p></div></div><div class="bottom"></div>'
  $('#invite_bubble_text').html(html_data);
  document.getElementById('invite_bubble_body').style.left = 315+scrollX()+'px';
  document.getElementById('invite_bubble_body').style.top = 150+scrollY()+'px';
  document.getElementById('invite_people_iframe').style.left = 335+scrollX()+'px';
  document.getElementById('invite_people_iframe').style.top = 150+scrollY()+'px';
  document.getElementById('invite_people_iframe').style.display = 'block';
  document.getElementById('invite_bubble_body').style.display = 'block';
}
function invite_nonitimesuser_yes(name, email) {
  var submitForm = document.createElement("FORM");
  document.body.appendChild(submitForm);
  submitForm.method = "POST";
  submitForm.action = "";
  var newElement = document.createElement("input");
  newElement.name = "email_id";
  newElement.type = "hidden";
  newElement.value = email;
  submitForm.appendChild(newElement);
  var newElement = document.createElement("input");
  newElement.name = "invite_from_homepage";
  newElement.type = "hidden";
  newElement.value = "invite";
  submitForm.appendChild(newElement);
  submitForm.submit();
}
function verify_tinymce_maxlength(formObject) {
  tinyMCE.triggerSave();
  elementCount = formObject.elements.length;
  for(i=0; i < elementCount; i++) {
    if(formObject.elements[i].type == 'textarea') {
      if (formObject.elements[i].value.length > 50000) {
        alert("Only 50000 characters allowed here.");
        return false;
      }
    }
  }
  return true;
}
function show_feeds(obj) {
  posts_ul_id = obj.id + '_posts';
  if($('#'+posts_ul_id).is(':hidden')) {
    $('#'+obj.id).attr('src', base_url+"/images/collapse.gif");
  }
  else {
    $('#'+obj.id).attr('src', base_url+"/images/expand.gif");
  }
  $('#'+posts_ul_id).toggle('slow');
}
function delete_content1() {
  if (confirm('Are you sure you want to delete this content ?')) {
    return true;
  }
  else {
    return false;
  }
}
function toggle_album_settings() {
  if ( chk_box_counter ) {
    var obj = document.getElementById('sort_by')
    var x = findPosX(obj) + 'px';
    $('#sort_album').css('left', x);
    chk_box_counter = 0;
  }
  $('#sort_album').toggle();
}
function toggle_users_settings() {
  if ( chk_box_counter ) {
    var obj = document.getElementById('sort_by')
    var x = findPosX(obj) + 'px';
    $('#sort_friend').css('left', x);
    var y = findPosY(obj) + 'px';
    $('#sort_friend').css('top', y);
    chk_box_counter = 0;
  }
  $('#sort_friend').toggle();
}
function toggle_photo_settings() {
  $('#photo_privacy_my').toggle();
}
function view_emails_loading() {
  $.get(
     base_url + "/ajax/get_mails.php",
     {
     },
     function(htmlData) {
        $('#view_emails_loading').html(htmlData);
     }
   );
}
function user_view_emails_loading(img_src) {
  $.get(
     base_url + "/ajax/get_mails.php",
     {
     },
     function(htmlData) {
        $('#view_emails_loading').html('<img src ="'+img_src+'" alt ="" >'+htmlData);
     }
   );
}
function toggle_notification_privacy(id) {
  if ( $('#'+id).is(':hidden') ) {
    $('#'+id+'_img').attr('src', skin_url+'/images/down-arrow-settings.gif');
    $('#'+id+'_href').html(__('Hide'));
  }
  else {
    $('#'+id+'_img').attr('src', skin_url+'/images/right-arrow-notification.gif');
    $('#'+id+'_href').html(__('Edit'));
  }
  $('#'+id).toggle('slow');
}
function pageScroll(id) {
  var obj = document.getElementById(id)
  var posX = findPosX(obj)
  var posY = findPosY(obj)
  window.scroll(posX,posY);
  document.getElementById(id).style.border = "1px solid #072D99";
  var i = 0;
  window.setTimeout("clearborder('"+i+"','"+id+"')", 200)
}
function clearborder(i,id) {
  col = new Array('#072D99','#072D99','#072D99', '#072D99','none')
  if(col[i] == 'none') {
    document.getElementById(id).style.border = "";
  }
  else {
    document.getElementById(id).style.border = "1px solid "+col[i];
    i++;
    window.setTimeout("clearborder('"+i+"','"+id+"')", 200)
  }
}
function show_mutual_friend(id) {
  if(document.getElementById(id).style.display == 'none') {
    document.getElementById(id).style.display = 'block'
  }
  else{
    document.getElementById(id).style.display = 'none'
  }
}
function celeb_interest_add_content(obj, uid) {
  $('#add_content').toggle();
  if ( obj.name == 'cancel' || obj.name == 'add_content_link' ) {
    $('#field_name').attr('value', 'Title');
    $('#field_name').css('color', '#d6d6d6');
    $('#field_value').attr('value', 'Description');
    $('#field_value').css('color', '#d6d6d6');
  }
  else if ( obj.name == 'add_content' ) {
    var params = {};
    params[$('#field_name').attr('value')] = $('#field_value').attr('value');
    $('#celeb_biography_html').html('<div style="float:left; margin:150px 0;"><img src="'+skin_url+'/images/loadingAnimation.gif" width="178px" alt = "loading.." /></div>');
    $.post(
      base_url + "/ajax/save_celeb_interest.php?&random=1&add_content=true&uid="+uid,
      params,
      function(htmlData) {
        $('#celeb_biography_html').html(htmlData);
      }
    );
  }
  else if ( obj.name = 'edit_content' ) {
    var len = obj.elements.length;
    var params = {};
    for ( i=0; i < len; i++ ) {
      if ( obj.elements[i].type == 'submit' || obj.elements[i].type == 'button' ) {
      }
      else if ( obj.elements[i].name.indexOf('field_name_') == 0 ) {
        var field_name = obj.elements[i].value;
      }
      else {
        params[ field_name ] = obj.elements[i].value;
      }
    }
    $.post(
      base_url + "/ajax/save_celeb_interest.php?&random=1&uid="+uid,
      params,
      function(htmlData) {
        $('#celeb_biography_html').html(htmlData);
      }
    );
  }
  return false;
}

function celeb_interest_edit_content(action_name, uid) {
  var url;
  if ( action_name == 'edit' ) {
    url = base_url + "/ajax/get_celeb_interest.php?&random=1";
  }
  else {
    url = base_url + "/ajax/save_celeb_interest.php?&random=1";
  }
  if ( url ) {
   // $('#celeb_interest').html('<div class = "no-comments"><img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." /></div>');
  $('#celeb_biography_html').html('<div style="float:left; text-align:center; margin:150px 0;"><img src="'+skin_url+'/images/loadingAnimation.gif" width="178px" alt = "loading.." /></div>');
    $.get(
      url,
      {
        'uid':uid
      },
      function(htmlData) {
          $('#celeb_biography_html').html(htmlData);
      }
    );
  }
}

function import_addressbook(obj) {
  document.getElementById("get_content").innerHTML = '<div class = "it_fleft" style = "margin-top:10px;width:100%;text-align:center;"><img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." /></div>';
  var params = {};
  for ( i=0; i < obj.elements.length; i++ ) {
    params[ obj.elements[i].name ] = obj.elements[i].value;
  }
  $.post("importer.php?&random=1",params,
        function(htmlData) {
        document.getElementById("get_content").innerHTML = htmlData;
    }
  );
}
function add_more_fields() {
  var obj = document.createElement('DIV');
  var html = '<span class="it_create_label" style = "padding:5px 0 0 0;">Video URL</span><span class="it_create_colon" style = "padding:5px 0 0 0;"> : </span><span class="it_create_input" style = "padding:5px 0 0 0;"><input type="text" name="video_url[]" value= ""  />';
  obj.innerHTML = html;
  document.getElementById('add_more').appendChild(obj);
}
function change_label(val) {
  if(val == 'job'){
    document.getElementById('price_label').innerHTML = 'Compensation'
  }
  else {
    document.getElementById('price_label').innerHTML = 'Price'
  }
}
function view_friends_photos (obj,uid) {
  window.location='album.php?view=friend&uid='+uid;
}
function check_all_friends(ctr) {
  $('input[@id^="user_id_"]').each(function() {
    if(ctr.checked == true){
      $(this).attr('checked',true);
    } else {
      $(this).attr('checked',false);
    }
  });
}
function poll_file_field_show(no) {
  $('#option'+no+'_file').show();
  $('#option'+no+'_button').hide();
}
function toggle_div (id) {
  $('#'+id).toggle();
  if ( $('#'+id).is(':hidden') ) {
    $('#'+id+'_img').attr('src', skin_url+'/images/arrow-up.gif');
  }
  else {
    $('#'+id+'_img').attr('src', skin_url+'/images/arrow-bottom.gif');
  }
  if(id == 'share_div') {
    document.getElementById('share_field').value = 'share';
  }
}
function check_empty(ctr) {
  if(ctr.value == '' || ctr.value =='Type here') {
    set_error_massage("Comment cannot be left blank");
    return false
   }
  else {
    return true;
  }
}
function clear_all(frm){
  var len=frm.length;
  for ( var i=0; i < len; i++ ) {
    if ( frm.elements[i].type=='text' ) {
      frm.elements[i].value = '';
    }
    if ( frm.elements[i].type=='radio' ) {
      frm.elements[i].checked = false;
    }
    if ( frm.elements[i].type=='select-one' ) {
      frm.elements[i].selectedIndex = 0;
    }
  }
}
function validatephone(ctr,add_plus) {
  var maintainplus = '';
 	var numval = document.getElementById(ctr).value;;
  if(add_plus ==true) {
 	  if ( numval.charAt(0)=='+' ){ maintainplus = '+';}
  }
 	curphonevar = numval.replace(/([\\A-Za-z!"£$%^&*+_={}();:'@#~,.¦\/<>?|`¬\]\[]|--)/g,'');
 	document.getElementById(ctr).value = maintainplus + curphonevar;
 	var maintainplus = '';
 	document.getElementById(ctr).focus;
}
function validate_celeb_msg ( obj ) {
  if(obj.elements[0].value == ""){
    alert("Message cannot be left blank");
    return false;
  }
  return true;
}
function get_type(val1, val2){
  if(val2 == "mail") {
    if(val1 == "others"){
      $('#checkmail').css('display', 'none');
      $('#others').css('display', 'block');
    } else {
      $('#others').css('display', 'none');
      $('#checkmail').css('display', 'block');
      document.getElementById("mail_type").innerHTML = val1;
    }
  } else if(val2 == "others") {
    document.getElementById("mailtype").value = val1;
  }
}
function get_type( val ) {
  document.getElementById("mail_type").innerHTML = val;
}
function sorting_octazen_friend(find_friend) {
  $('em[@id^="fren_name_"]').each(function() {
    var user_name = $(this).html();
    var split_data = $(this).attr('id').split('_');
    id = split_data[2];
      if ( user_name.toLowerCase().indexOf(find_friend.toLowerCase()) == 0 ) {
      $('#my_fren_'+id).css('display', 'block');
      }
      else {
      $('#my_fren_'+id).css('display', 'none');
      }
  })
}
function toggle_submission(id) {
  if ( $('#'+id).is(':hidden') ) {
    $('#'+id+'_img').attr('src', skin_url+'/images/down-arrow.gif');
  }
  else {
    $('#'+id+'_img').attr('src', skin_url+'/images/right-arrow.gif');
  }
  $('#'+id).toggle('slow');
}
function showToolTip_from(field_id, text, a, b){
  var field_obj = document.getElementById(field_id);
  var leftPos = findPosX(field_obj) + a;
  var rightPos = findPosY(field_obj) - b;
  var obj = document.getElementById('bubble_body');
  var obj2 = document.getElementById('bubble_text');
  obj2.innerHTML = __(text);
  //obj2.innerHTML = text;
  obj.style.display = 'block';
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  var obj_height = obj.offsetHeight;
  var obj_width = obj.offsetWidth;
  obj.style.top = rightPos + 'px';
  $('#bubble_iframe').css({top:rightPos+'px',left:leftPos+'px',display:'block',height:obj_height+'px', width:obj_width+'px'});
  var hide_bubble = "document.getElementById('bubble_body').style.display='none';document.getElementById('bubble_iframe').style.display='none';";
 // clear_bubble_hide = window.setTimeout(hide_bubble,6000);
}
function showToolTipGreen_from(field_id, text, a, b){
  var field_obj = document.getElementById(field_id);
  var leftPos = findPosX(field_obj) + a;
  var rightPos = findPosY(field_obj) - b;
  var obj = document.getElementById('bubble_body_green');
  var obj2 = document.getElementById('bubble_text_green');
  obj2.innerHTML = __(text);
  obj.style.display = 'block';
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  var obj_height = obj.offsetHeight;
  var obj_width = obj.offsetWidth;
  obj.style.top = rightPos + 'px';
  $('#bubble_iframe').css({top:rightPos+'px',left:leftPos+'px',display:'block',height:obj_height+'px', width:obj_width+'px'});
}
function post_blog_comment(obj) {
  if ( !trim($('#Content').val()) ) {
    return false;
  }
  return true;
}
function hide_div() {
  $('#test').css('display', 'none');
}
function add_friend_from_import(obj) {
  if ( invite_checkall_fields(obj.name) )  {
    var len = obj.elements.length;
    var params = {};
    var k = 0;
    params['user_to_invite'] = new Array;
    for ( i=0; i < len; i++ ) {
      if ( obj.elements[i].type == 'submit' || obj.elements[i].type == 'button' ) {
      }
      else if ( obj.elements[i].type == 'checkbox' && obj.elements[i].checked == true ) {
        if (obj.elements[i].id != 'selall1' && obj.elements[i].id != 'selall2') {
          params['user_to_invite'][k++] = obj.elements[i].value;
        }
      }
      else if(obj.elements[i].type == 'hidden' &&  (obj.elements[i].name == 'call_from'  || obj.elements[i].name == 'action' || obj.elements[i].name == 'result' || obj.elements[i].name == 'page_from')){
       params[obj.elements[i].name ] = obj.elements[i].value;
      }
    }
    params['user_to_invite'] = toJSON(params['user_to_invite']);
    $('#all_ititmes_user').html('<img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." />');
    $.post(
      base_url + "/ajax/add_friend_from_import.php?&random=1",
      params,
      function(htmlData) {
        if(obj.name == 'invitefriend') {
         $('#imported_mail_paranet').html('<b>'+htmlData+'</b>');
        } else {
		$('#headline_msg1').html('');
		$('#all_ititmes_user').html('<b>'+htmlData+'</b>');
		$('#all_ititmes_user').css({'text-align':'center', 'padding':'10px 0px', 'font-size':'16px'});		//align centre bold padding font
        }
      }
    );
  } else {
    return false;
  }
}
function send_invitation(obj, siteid) {
  if ( invite_checkall_fields(obj.name) ) {
    var len = obj.elements.length;
    var params = {};
    params['provider']=obj.provider.value;
    params['personalized_message']=obj.personalized_message.value;
    if ( obj.name != 'multiple_invite' ) {
      params['email_id'] = new Array;
      var k = 0;
    } else {
      params['not_array'] = true;
      if ( !trim(document.multiple_invite.email_id.value) ) {
        alert('Please enter email id');
        return false;
      }
    }
    params['siteid'] = siteid;
    for ( i = 0; i < len; i++ ) {
      if ( obj.elements[i].type == 'checkbox' ) {
        if ( obj.elements[i].checked == true ) {
          params['email_id'][k++] = obj.elements[i].value;
        }
      } else {
        params[ obj.elements[i].name ] = obj.elements[i].value;
      }
    }
    if ( obj.name != 'multiple_invite' ) {
      params['email_id'] = toJSON(params['email_id']);
    }
    $('#imported_mail_paranet').html('<img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." />');
    $.post(
      "ajax/send_invitation.php?&random=1",
      params,
      function(msg) {
		$('#headline_msg2').html('');
		$('#imported_mail_paranet').html('<div id="imported_mail_paranet_inner">'+msg+'</div>');
		$('#imported_mail_paranet_inner').css({'text-align':'center','position':'relative', 'font-weight':'bold', 'float':'left', 'width':'97%','padding':'10px 0px', 'font-size':'16px'});		//align centre bold padding font
      }
    );
  } else {
  	alert('Please select at least one friend');
    return false;
  }
}
function invite_checkall_fields(form_name,send_count,excludeId) {	//send_count - tells the function to return the count of checkboxes and not just T/F
  excludeId= typeof(excludeId) == 'undefined' ? '' : excludeId;		//this is optional - useful for excluding select all checkbox if it is in the form
  count = 0;
  count = document.forms[form_name].elements.length;
  chk_cnt=0;
  for (i=0; i < count; i++) {
    if (document.forms[form_name].elements[i].type=='checkbox') {
      if (document.forms[form_name].elements[i].checked == 1) {
	    if (excludeId=='' || document.forms[form_name].elements[i].id!=excludeId) {
			chk_cnt++;
		}
      }
    }
  }

  send_count= typeof(send_count) == 'undefined' ? false : send_count;
  if(send_count) {
	return chk_cnt;
  }

  if(chk_cnt) {
    return true;
  } else {
   if(form_name == "invitefriend_itimes"){
     //showToolTip_from('invitefriend_itimes_div', 'Please select a contact to invite',95,2);
   	 return false;
   }
   else if(form_name == "invitefriend"){
     //showToolTip_from('invitefriend_div', 'Please select a contact to invite',95,2);
   	 return false;
   }
  }
}
function show_report_bubble (object, uid){
  x = findPosX(object) + 30;
  y = findPosY(object) ;
 document.getElementById('report_bubble_body').style.display = 'block';
  var obj = document.getElementById('report_bubble_body');
  var obj2 = document.getElementById('report_bubble_text');
  obj2.innerHTML ='<form method="POST" name ="report"  action ="'+base_url+'/report.php" onsubmit ="return report_validate( this);"><ul style="float:left;width:150px;"><li style="list-style:none;disply:block;margin:0px;padding:0;" >'+__('I would like to Report abuse:')+'</li><li style="list-style:none" ><input type="radio" name ="type" value="profile"> '+__('Profile details')+'</li><li style="list-style:none;"><input type="radio" name ="type" value="profilephoto">'+__('Profile Picture')+' </li><li style="list-style:none"><input type="hidden" name="parent_id" value="'+uid+'" ></li><li style="list-style:none">&nbsp;</li><li style="list-style:none"><input type="submit" name="report" value="'+__('Report')+'" >&nbsp;<input type="button" name="cancel" value="'+__('Cancel')+'" onclick="hide_report_bubble();" ></li></ul></form>';
  document.getElementById('report_bubble_body').style.left = x +'px';
  document.getElementById('report_bubble_body').style.top = y +'px';
}
function hide_report_bubble(){
document.getElementById('report_bubble_body').style.display = 'none';
}
function toggle_report_div(id){
$('#'+id).toggle();
}
function CheckDate(call_from) {
  var dob_month =Number(document.getElementById('dob_month').value);
  var dob_day =Number(document.getElementById('dob_day').value);
  var dob_year =Number(document.getElementById('dob_year').value);
  var source_date = new Date(dob_year,dob_month,dob_day);
  var myDate=new Date();
  myDate.setFullYear(dob_year, dob_month-1, dob_day);
  var today = new Date();
  today.setFullYear(today.getFullYear() - 18, today.getMonth(), today.getDay());
  var RegExPattern = /^(?=\d)(?:(?:(?:(?:(?:0?[13578]|1[02])(\/|-|\.)31)\1|(?:(?:0?[1,3-9]|1[0-2])(\/|-|\.)(?:29|30)\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})|(?:0?2(\/|-|\.)29\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))|(?:(?:0?[1-9])|(?:1[0-2]))(\/|-|\.)(?:0?[1-9]|1\d|2[0-8])\4(?:(?:1[6-9]|[2-9]\d)?\d{2}))($|\ (?=\d)))?(((0?[1-9]|1[012])(:[0-5]\d){0,2}(\ [AP]M))|([01]\d|2[0-3])(:[0-5]\d){1,2})?$/;
  var dob = dob_month+'/'+dob_day+'/'+dob_year;
  if(dob_month==0) {
    show_bubble_tip('dob_month', 'Please specify month of birth', 85, 6);
    if(call_from == 'registration'){
      $('#dob_month').css('border', error_border);
    }else {
    document.getElementById('dob_month').focus();
    }
    return true;
  } else if(dob_day==0) {
    show_bubble_tip('dob_day', 'Please specify date of birth', 50, 6);
    if(call_from == 'registration'){
      $('#dob_day').css('border', error_border);
    }else {
    document.getElementById('dob_day').focus();
    }
    return true;
  } else if(dob_year==0) {
    show_bubble_tip('dob_year', 'Please specify year of birth', 55, 6);
    if(call_from == 'registration'){
      $('#dob_year').css('border', error_border);
    } else {
      document.getElementById('dob_year').focus();
    }
    return true;
  } else if (!(dob.match(RegExPattern))) {
     if(call_from == 'edit_profile'){
       show_bubble_tip('dob_month', 'Invalid date of birth', 85, 6);
       document.getElementById('dob_month').focus();
     } else {
      show_bubble_tip('dob_year', 'Invalid date of birth', 55, 6);
      $('#dob_month').css('border', error_border);
      $('#dob_day').css('border', error_border);
      $('#dob_year').css('border', error_border);
    }
    return true;
  } else if ($('#site_reg').val() != 'dt') {
    if ( myDate > today ) {
      if(call_from == 'edit_profile'){
        show_bubble_tip('dob_year', 'Minimum age should be 18', 55, 6);
        document.getElementById('dob_year').focus();
      } else {
        show_bubble_tip('dob_year', 'Minimum age for registration is 18', 55, 6);
        $('#dob_month').css('border', error_border);
        $('#dob_day').css('border', error_border);
        $('#dob_year').css('border', error_border);
      }
      return true;
    }
  }
  $('#bubble_body_green').css('display', 'none');
  $('#bubble_body').css('display', 'none');
  $('#bubble_iframe').css('display', 'none');
  if(call_from == 'registration'){
    $('#dob_month').css('border', fix_border);
    $('#dob_day').css('border', fix_border);
    $('#dob_year').css('border', fix_border);
  }
  return false;
}
function show_bubble_tip(field_id, text, a, b) {
  document.getElementById('bubble_body_green').style.display='none';
  document.getElementById('bubble_body').style.display='block';
  showToolTip_from(field_id, text, a, b);
}
function friend_request_action(uid, action_name, form_name) {
  checkall_fields('request_friend_list', 'uncheck');
  document.getElementById('request_friend_'+uid).checked = true;
  if ( action_name == 'accept' ) {
    document.getElementById('request_friend_action').value = 'accept';
    document.forms[form_name].submit();
  } else if ( action_name == 'decline' ) {
    document.getElementById('request_friend_action').value = 'decline';
    document.forms[form_name].submit();
  }
}
function report_validate (obj){
 var radio_checked = false;
   var i=0;
  for ( var i = 0; i < obj.type.length; i++ ) {
    if ( obj.type[i].checked ) {
      radio_checked = true;
    }
  }
  if(radio_checked == true){
    return true;
   } else{
    return false;
  }
}
function delete_conformation(msg, cat_type, id) {
  var msg = msg;
  if (confirm(msg)) {
   window.location = base_url+"/manage_category.php?type="+cat_type+"&a=delete&cat_id="+id;
   return true;
  }
  else {
    return false;
  }
}
function swap_gender_tab(gender) {
  if ( gender == 'male' ) {
    $('#male_span').css('font-weight','bold');
    $('#female_span').css('font-weight','normal');
  } else {
    $('#female_span').css('font-weight','bold');
    $('#male_span').css('font-weight','normal');
  }
  $('#new_male_friend_id').html('<div class="itimes_cool_members"><div style = "width:257px;float:left;padding: 0 0 0 10px;"><img src="'+skin_url+'/images/loadingAnimation.gif" alt = "loading.." /></div></div>');
  $.get(
    base_url+"/ajax/make_new_friend.php",
    {
      'gender': gender,
      'random': (new Date().getTime())
    },
    function(data) {
      $('#new_male_friend_id').html(data);
    }
  );
}
function add_video(cid) {
  $.get(
    base_url+"/ajax/add_to_my_video.php",
    {
      'cid': cid,
      'random': (new Date().getTime())
    },
    function(data) { 
      var msg_data = data.split('--');
      var msg = msg_data[1]; 
      if (msg_data[0] == 'error') {
        set_error_massage(msg);
      } else {
        display_mes_ajax(msg, 'status');
      }
    }
  );
}
function display_div_mes_ajax(msg, message_type, div_id) { 
  var color  = 'green';
  if ( typeof message_type == 'undefined' ) {
   color = 'red';
  }
  if ( message_type == 'status' ) {
    color = 'green';
  }
  if ( message_type == 'error' ) {
    color  = 'red';
  }
  if ( msg ) {
    document.getElementById(div_id).style.color = color;
    document.getElementById(div_id).innerHTML= msg;
  }
}
function display_mes_ajax(msg, message_type) {
  var color;
  color  = 'green';
  if ( typeof message_type == 'undefined' ) {
    color = 'red';
  }
  if ( message_type == 'status' ) {
    color  = 'green';
  }
  if ( message_type == 'error' ) {
    color = 'red';
  }
  if ( msg ) {
    $('#message').css('display', 'block');
    $('#message').html('<span> <table border="0" cellpadding="2" cellspacing="0" align="center" width = "100%" > <tr><td height="24"><div style="margin:0;padding:0;"> <span style="padding:0 4px 0 0;color:'+color+';font-weight:bold;">'+msg+'</span><span><img src="'+base_url+'/images/cross-img-new.gif" alt="" style = "cursor:pointer;" onclick = "$(\'#message\').hide();" /></span></div></td></tr></table></span>');
   // $('#message').html("<span ><table border='0' cellpadding='2' cellspacing='0' align='center'> <tr><td height='24'><div style='margin:0;padding:0;'> <span style='padding:0 4px 0 0;color:"+color+";font-weight:bold;'>"+msg+"</span><span><img src='"+base_url+"/images/cross-img-new.gif' alt='' onclick = 'hide_div();' /></span></div></td></tr></table></span>");
  }
   var id = document.getElementById('message');
   var posX = findPosX(id);
   var posY = findPosY(id);
   window.scroll(posX,posY);
}
function change_cat(category_id){
  if(category_id != 'All'){
    window.location = base_url+'/fan_clubs.php?category_id='+category_id;
  } else {
    window.location = base_url+'/fan_clubs.php';
  }
}
// function change_string_order(sort_by){
//   if(sort_by != ''){
//     window.location = base_url+'/manage_english_string.php?sort_by='+sort_by;
//   } else {
//     window.location = base_url+'/manage_english_string.php';
//   }
// }
// function change_trans_order(sort_by){
//   if(sort_by != ''){
//     window.location = base_url+'/manage_translitration.php?sort_by='+sort_by;
//   } else {
//     window.location = base_url+'/manage_translitration.php';
//   }
// }
/*
//moved to indiatimes.js
function popup_register(block , pop_type,  position, ref_id, return_file, additional_data_json) {
 try{
  var video_div = document.getElementById('video_player_div');
  if (video_div) {
    document.getElementById('video_player_div').style.visibility='hidden';
  }
 if(additional_data_json) {
 	//var additional_data_pass=escape(additional_data_json);
 	var additional_data_pass=additional_data_json;
 }
  var tid = 0;
  get_data ='additional_data='+additional_data_pass+'&pop_type='+pop_type+'&position='+position+'&ref_id='+ref_id+'&return_file=';
  if ( return_file && return_file!='') {
    get_data += return_file;
  } else {
    get_data += escape(document.URL);
  }
  $.ajax({
    type: "GET",
    url: base_url+"/popup_register.php?show="+block,
    data: get_data,
    success: function(data) {
    var r = data.split('@#$~~');
    if (r[0] == 'Already login' ) {
      window.location = r[1];
    } else {
      window.parent.document.getElementById('register_popup_parent').style.display='block';
      window.parent.document.getElementById('register_popup').innerHTML = data;
      mydiv = window.parent.document.getElementById('register_popup_parent');

      if (typeof( window.pageYOffset ) == 'number' ) {
        var s = window.pageYOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        var s = document.body.scrollTop;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        var s = document.documentElement.scrollTop;
      }
      var y =  80 + parseInt(s);
      mydiv.style.top = y + 'px';
    }
  }
  });
  } catch (e){
   alert(e.message);
  }
}
*/



/*
function popup_register(block , pop_type,  position, ref_id, return_file) {
 try{
  var video_div = document.getElementById('video_player_div');
  if (video_div) {
    document.getElementById('video_player_div').style.visibility='hidden';
  }
  var tid = 0;
  get_data ='pop_type='+pop_type+'&position='+position+'&ref_id='+ref_id+'&return_file=';
  if ( return_file ) {
    get_data += escape(return_file);
  } else {
    get_data += escape(document.URL);
  }
  $.ajax({
    type: "GET",
    url: base_url+"/popup_register.php?show="+block,
    data: get_data,
    success: function(data) {
    var r = data.split('@#$~~');
    if (r[0] == 'Already login' ) {
      window.location = r[1];
    } else {
      window.parent.document.getElementById('register_popup_parent').style.display='block';
      window.parent.document.getElementById('register_popup').innerHTML = data;
      mydiv = window.parent.document.getElementById('register_popup_parent');

      if (typeof( window.pageYOffset ) == 'number' ) {
        var s = window.pageYOffset;
      } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        var s = document.body.scrollTop;
      } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        var s = document.documentElement.scrollTop;
      }
      var y =  60 + parseInt(s);
      mydiv.style.top = y + 'px';
    }
  }
  });
  } catch (e){
   alert(e.message);
  }
}
*/
/*
//move to indiatimes.js
function popup_close() {
 if (document.getElementById('bubble_body')){
  document.getElementById('bubble_body').style.display='none';
 }
 if (document.getElementById('bubble_iframe')){
  document.getElementById('bubble_iframe').style.display='none';
 }
 document.getElementById('register_popup_parent').style.display='none';
 document.getElementById('register_popup').innerHTML='';
 var video_div = document.getElementById('video_player_div');
 if (video_div) {
  document.getElementById('video_player_div').style.visibility='visible';
 }
}
*/
function change_popup_block(id) {
  remove_bubble_or_error();
  if ( id == 'signin' ) {
    $('#'+id).css('display', 'block');
    $('#signup').css('display', 'none');
  } else {
    $('#'+id).css('display', 'block');
    $('#signin').css('display', 'none');
  }
}


function page(cur_page, total_page, section){
  var total_page = parseInt(total_page);
  var cur_page = parseInt(cur_page);
  var next_page =cur_page + 1;
  var prev_page = cur_page - 1;
   if(section =='bloggers'){
   $('[@id^="p_"]').each(function(){
     var id = $(this).attr('id');
     $('#'+id).hide();
   });
   $('#p_'+cur_page).show();
 }else{
  $('[@id^="pro_"]').each(function(){
     var id = $(this).attr('id');
     $('#'+id).hide();
$('#'+id).css('visibility', 'hidden');
   });
   $('#pro_'+cur_page).show();
$('#pro_'+cur_page).css('visibility', 'visible');
}
   if(cur_page != 1){
     $('#'+section+'_prev_page_upper').show();
     $('#'+section+'_prev_page_upper').html('<b onclick =page('+prev_page+','+total_page+',"'+section+'")>  Prev </b>');
      $('#'+section+'_prev_page_lower').show();
     $('#'+section+'_prev_page_lower').html('<b onclick =page('+prev_page+','+total_page+',"'+section+'")>  Prev </b>');
  }else{
    $('#'+section+'_prev_page_upper').hide();
     $('#'+section+'_prev_page_lower').hide();
  }
   if( total_page != cur_page){
    $('#'+section+'_next_page_upper').show();
    $('#'+section+'_next_page_upper').html('<b onclick =page('+next_page+','+total_page+',"'+section+'")>   Next &gt;&gt;</b>');
    $('#'+section+'_next_page_lower').show();
    $('#'+section+'_next_page_lower').html('<b onclick =page('+next_page+','+total_page+',"'+section+'")>   Next &gt;&gt;</b>');
   } else {
     $('#'+section+'_next_page_lower').hide();
     $('#'+section+'_next_page_upper').hide();
   }
  if(cur_page <5){
        var start_page = 1;
       }else{
        var  start_page = cur_page - 4;
    }

  if((start_page+4) <  total_page){
        var end_page = start_page+4;
   } else {
        var end_page =  total_page;
   }
  var htmlData = '';
  for ( var i = start_page; i <= end_page; i++ ) {
          if(i == cur_page){
            var cl ='class="selected"';
           } else{
           var cl = '';
          }
  htmlData +='<li  style = "float:left;display:inline;list-style:none;"><b '+cl+' onclick = "page('+i+','+total_page+',\''+section+'\')">'+i+'</b></li>';
  }
   $('#'+section+'_page_listing_upper').html(htmlData);
   $('#'+section+'_page_listing_lower').html(htmlData);
}

function redirect_fanclub( cat_id, query_str ){
  var redirect_url ='';
  if(cat_id !='All'){
  redirect_url = base_url+'/fan_clubs.php?category_id='+cat_id;
  }else{
    redirect_url = base_url+'/fan_clubs.php?category_id=0';
  }
  if(query_str){
  redirect_url +='&for='+query_str;
  }
  redirect_url +='#for';
  window.location = redirect_url;
}

function celeb_show_for(id){
  $('li[@id^="l_"]').each(function(){
     var id = $(this).attr('id');
     $('#'+id).css('fontWeight','normal');
  });
  $('#l_'+id).css('fontWeight','bold');
  if(id !='All'){
    $('ul[@id^="u_"]').each(function(){
      var id = $(this).attr('id');
      $('#'+id).hide();
    });
    $('#u_'+id).show();
  } else {
    $('ul[@id^="u_"]').each(function(){
      var id = $(this).attr('id');
      $('#'+id).show();
    });
  }
}
function __(s, replace_with) {
  var new_s = s.toLowerCase();
  if ( typeof(lang_string) != 'undefined' && lang_string[new_s] ) {
    s = lang_string[new_s];
  }
  if ( typeof(replace_with) != 'undefined' ) {
    var str;
    var replace_with_cnt = replace_with.length;
    if ( replace_with_cnt ) {
      for ( var i = 0; i < replace_with_cnt; i++ ) {
        if ( i == 0 ) {
          str = '%dynamic%';
        } else {
          str = '%dynamic'+i+'%';
        }
        s = s.replace(str, replace_with[i]);
      }
    }
  }
  return s;
}

function disable_settings(obj){
if(obj.checked){
  document.getElementById('public_profile_picture').disabled =false;
  document.getElementById('public_city').disabled =false;
  document.getElementById('public_dob').disabled =false;
  document.getElementById('public_gender').disabled =false;
}else {
 document.getElementById('public_profile_picture').disabled =true;
 document.getElementById('public_city').disabled =true;
 document.getElementById('public_dob').disabled =true;
 document.getElementById('public_gender').disabled =true;
}
}
var unread_popup_time_out;
function show_unread_bubble(bubble_type, cnt){
  var b_width = screen.width;
  var pos_right = "";
  $('#popup_uncheckedt_'+bubble_type).css('display','block');
  $('#popup_uncheckedt_'+bubble_type).css('left',pos_right);
  if ( $('#popup_uncheckedt_'+bubble_type).css('top') == '53px' ) {
  } else {
//      $('#popup_uncheckedt_'+bubble_type).css('top','0px');
  }
  if(parseInt(cnt) == 0 || cnt == ''){
    $('#popup_uncheckedt_'+bubble_type).css('visibility','hidden');
  } else {
  // setTimeout(hide_unread_popup(bubble_type),1500000);
  }
}
function hide_unread_popup(bubble_type){ 
   $('[@id^="popup_unchecked_"]').each(function() {
     // $(this).css('display','none');
  });
  $('#popup_unchecked_'+bubble_type).css('visibility','visible');
  $('#popup_unchecked_'+bubble_type).css('display','none');
}
function header_search(frm) {
  if ( frm.text_search.value == __('Type your keyword') || trim(frm.text_search.value) == '' ) {
  //alert(__("Please enter a keyword"));
  set_error_massage(__("Please enter a keyword"));
  frm.text_search.focus();
  return false;
  } else {
    if(frm.search_type.value == 'community') {
      document.getElementById('dummy_id').name = 'community_search';
      document.getElementById('dummy_id').value = frm.text_search.value;
    } else if(frm.search_type.value == 'user') {
      document.getElementById('dummy_id').name = 'user_search';
      document.getElementById('dummy_id').value = frm.text_search.value;
    } else if(frm.search_type.value == 'blogs') {
      document.getElementById('dummy_id').name = 'blogs_search';
      document.getElementById('dummy_id').value = frm.text_search.value;
    } else if(frm.search_type.value == 'media') {
      document.getElementById('dummy_id').name = 'media_search';
      document.getElementById('dummy_id').value = frm.text_search.value;
    } else if(frm.search_type.value == 'video') {
      document.getElementById('dummy_id').name = 'video_search';
      document.getElementById('dummy_id').value = frm.text_search.value;
    } else if(frm.search_type.value == 'fans_club') {
      document.getElementById('dummy_id').name = 'fans_club_search';
      document.getElementById('dummy_id').value = frm.text_search.value;
    }
  }
}

function add_upload_field() {
  var ni = document.getElementById('mydiv');
  var obj = document.createElement('LI');
  var numi = document.getElementById('theValue');
  var num = (document.getElementById('theValue').value -1)+ 1;
  numi.value =eval(num);
  var inc=eval(num);
    inc = inc + 1;
    inc_field = inc - 1;
  document.getElementById('theValue').value = inc;
  var field="<span><input  class='it_txt' type='file' name='userfile_"+inc_field+"' style = 'height:26px;' /></span>";
  obj.innerHTML = field;
  document.getElementById('mydiv').appendChild(obj);
   var obj_cap = document.createElement('LI');
  var field_cap ="<input class='it_txt' type='text' maxlength='50' name = 'caption["+inc_field+"]' value='Enter title here...'  onfocus=\"if (this.value=='Enter title here...') this.value='';\" onblur=\"if (this.value=='') this.value = 'Enter title here...';\" />";
  obj_cap.innerHTML = field_cap;
 document.getElementById('mydiv').appendChild(obj_cap);
  if ( num == '12' ) {
    document.getElementById('more').innerHTML="";
  }
}
function increase_popcnt() {
  var obj2 = document.getElementById('ipl_text');
  $.get(
     base_url + "/ajax/load_teamIPL.php?type=homepage",
     {
     },
     function(htmlData) {
        $('#ipl_text').html(htmlData);
     }
   );

     document.getElementById('create_topic_ipl').style.display = 'block';
     var st = 0;
     if(screen.width > 1024) {
       if(navigator.appName == 'Microsoft Internet Explorer') {
       st = 20;
       } else {
       st = 150;
       }
     }
     if(navigator.appName == 'Microsoft Internet Explorer') {
       document.getElementById('create_topic_ipl').style.left = 310+st+scrollX()+'px';
       document.getElementById('create_topic_ipl').style.top = 140+scrollY()+'px';
     } else {
     document.getElementById('create_topic_ipl').style.left = 220+st+scrollX()+'px';
     document.getElementById('create_topic_ipl').style.top = 110+scrollY()+'px';
     }
     document.getElementById('ipl_iframe').style.display = 'block';
     if(navigator.appName == 'Microsoft Internet Explorer') {
       document.getElementById('ipl_iframe').style.left = 310+st+scrollX()+'px';
       document.getElementById('ipl_iframe').style.top = 140+scrollY()+'px';
     } else {
     document.getElementById('ipl_iframe').style.left = 220+st+scrollX()+'px';
     document.getElementById('ipl_iframe').style.top = 104+scrollY()+'px';
     }

}
function save_reply_ipl(ans, gid){
  $.get(
     base_url + "/ajax/load_teamIPL.php?type=answer&ans="+ans,
     {
     },
     function(htmlData) {
      if(parseInt(ans) == 1) {
       window.location.href = base_url+'/main_community.php?gid='+gid;
      }
     }
   );
}
function join_contest_community(group_id, user_action, board_mid) {
  $.get(
    base_url + "/ajax/action_on_community.php",
    {
      'gid':group_id,
      'action':user_action
    },
    function(htmlData) {
      $('#post_here_join').attr('href', base_url+"/ajax/load_teamIPL.php?gid="+group_id+"&board_mid="+board_mid+"&type=play&width=700&height=440")
      tb_show(null, base_url+"/ajax/load_teamIPL.php?gid="+group_id+"&board_mid="+board_mid+"&type=play&width=700&height=440",false);
    }
  );
}
function hide_ipl_popup(){
  $('#ipl_text').html("");
  document.getElementById('create_topic_ipl').style.display = 'none';
  document.getElementById('ipl_iframe').style.display = 'none';
}
function logout_call(url){
  //set_status('Offline');
  window.location.href = url;
}
function get_unread_mails(ws) { return false;
  if ( typeof(ws) == 'undefined' ) {
    ws = 0;
  }
  $.get(
    base_url + "/ajax/get_mails.php",
    {
      'top_head': true,
      'ws': ws,
      'random': (new Date().getTime())
    },
    function(response) {
      $('#top_unread_mail_count').html(response);
      $('#popup_uncheckedt_mail').html("<em>"+response+"</em><i></i>");
      show_unread_bubble('mail', response);
    }
  );
}

function pre_login_post(obj,additional_data_json){
  var params = {};var k = 0;
  for ( i=0; i < obj.elements.length; i++ ) {
     params[ obj.elements[i].name ] = obj.elements[i].value;
  }
 try {
    $.post(
     base_url+"/ajax/prelogin_post.php",
     params,
     function(htmlData) {
       if (document.getElementById('create_topic')) {
        var obj = document.getElementById('create_topic');
        obj.style.display = 'none';
        obj.innerHTML = '';
      }
      var data = htmlData.split('-');
      popup_register('signin' , data[1],  data[2], data[3],'',additional_data_json);
     }
     );
     } catch (e){

     }
  return false;
}

function prelogin_popup(block , pop_type,  position, ref_id,additional_data_json){
	var params = {};
   params ['show'] = block;
   params ['type'] = pop_type;
   params ['position'] = position;
   if (pop_type == 1) {
     params ['gid'] = ref_id;
   } else if (pop_type == 2) {
     params ['uid'] = ref_id;
   }
  try {
    $.post(
     base_url+"/ajax/prelogin_post.php",
     params,
     function(htmlData) {
      var data = htmlData.split('-');
      popup_register('signin' , data[1],  data[2], data[3],'',additional_data_json);
     }
     );
     } catch (e){
     }
  return false;
}
/* group.php, create album - get sub category list corresponding to category */
function generate_sub_category_list(category_obj, sub_category_field) {
  var category_id = category_obj.value;
  if ( category_id ) {
    $('#sub_category_drop_down').html('<font color = "red">loading..</font>');
    $.get(
      base_url + "/ajax/generate_sub_category_list.php",
      {
        'category_id' : category_id,
        'sub_category_field' : sub_category_field,
        'random': (new Date().getTime())
      },
      function(response) {
        $('#sub_category_drop_down').html(response);
      }
    );
  } else {
    $('#sub_category_drop_down').html('<select class="category" name = "group_sub_category"><option>Select Category</option></select>');
  }
}

function accept_friend_request_bubble (object, uid){
  x = findPosX(object) + 30;
  y = findPosY(object) ;
  document.getElementById('report_bubble_body').style.display = 'block';
  var obj = document.getElementById('report_bubble_body');
  var obj2 = document.getElementById('report_bubble_text');
  $.get(
     base_url+"/ajax/accept_friend_request.php",
    {
    'uid':uid
    },
    function(data) {
      $('#report_bubble_text').html(data);
    }
  );
  document.getElementById('report_bubble_body').style.left = x +'px';
  document.getElementById('report_bubble_body').style.top = y +'px';
}

//to enable forgot password action from login popup on prelogin pages
function lp_forgot_password_popup() {
  var user_name = $('#lp_forgot_user_name').val();
  if ( !trim(user_name) ) {
    $('#lp_forgot_password_msg').html(__('Email field cannot be left blank. Please enter your email id'));
    $('#lp_forgot_password').css('display', 'none');
    $('#lp_forgot_password_msg').css('display', 'block');
     var set_time = setTimeout("$('#lp_forgot_password').css('display', 'block');$('#lp_forgot_password_msg').css('display', 'none');", 1500);
  } else {
    $.get(
      base_url + '/ajax/forgot_password.php?user_name='+user_name+'&lp=1',
      {
      },
      function(response) {
        var pos = response.indexOf('*#*');
        var content = response.substr(0,pos);
        var success = response.substr(pos+3,1);
        $('#lp_forgot_password_msg').html(content);
        $('#lp_forgot_password').css('display', 'none');
        $('#lp_forgot_password_msg').css('display', 'block');
        if(!parseInt(success)) {
        var set_time = setTimeout("$('#lp_forgot_password').css('display', 'block');$('#lp_forgot_password_msg').css('display', 'none');", 1500);
        }
      }
    );
  }
}
function clear_error_class(id, error_class, normal_class) {
  if ( typeof(error_class) != 'undefined' ) {
    $('#'+id).removeClass(error_class);
  }
  if ( typeof(normal_class) != 'undefined' ) {
    $('#'+id).addClass(normal_class);
  }
}
function check_module_privacy(perm, val){
  if (perm == 1 ) {
    index_val = 1;
  } else if(perm == 9) {
    index_val = 2;
  } else if (perm == 10) {
    index_val = 0;
  } else {
    index_val = 3;
  }  
  if ( val > perm) {
   set_error_massage( 'you cannot select this level of privacy');
   if (document.getElementById('album_privacy')) { 
     document.getElementById('album_privacy').selectedIndex = index_val;
   }
   if (document.getElementById('video_perm')) { 
     document.getElementById('video_perm').selectedIndex = index_val;
   }
   return false;
  } else {
    return true;
  }
}

function check_public_id_availbilty( ){ 
 var val = document.getElementById('public_id').value;
 var url = base_url + "/ajax/check_id_availbilty.php?&random=1";
 if (val == '' || (!alpha_numeric_test(val))) {
   $('#availbilty').css('color', 'red');
   $('#availbilty').html('Please enter valid id');
  return;
 } else if(val.length>30 || val.length<3) {
   $('#availbilty').css('color', 'red');
   $('#availbilty').html('Id can be ranging from 3-30 characters');
   return;
  }
 $.get(
  url,
  {
    'public_id': val
  },
  function(htmlData) {
    if (htmlData =='Available for you') {
      $('#availbilty').css('color', 'green');
    } else {
      $('#availbilty').css('color', 'red');
    }
    $('#availbilty').html(htmlData);
  }
 );
}
function alpha_numeric_test( numaric ){
  var pass = false;
  for(var j=0; j < numaric.length; j++) {
    var alphaa = numaric.charAt(j);
    var hh = alphaa.charCodeAt(0);
    if((hh > 47 && hh < 58) || (hh > 64 && hh < 91) || (hh > 96 && hh < 123)) {
     pass = true;
    } else	{
      pass = false;
    }
  }
 return pass;
}

function numbersonly(e) {
  var unicode = e.charCode? e.charCode : e.keyCode
  if (unicode != 8){  //if the key isn't the backspace key (which we should allow)
    regexp = /w+(-?w+)*/;
    var val = document.getElementById('public_id').value;
    if (!regexp.test(val)) { //if not alphanumeric
      return false //disable key press
    }
 }
}
function onlypageScroll(id) {
  var obj = document.getElementById(id)
  var posX = findPosX(obj)
  var posY = findPosY(obj)
  window.scroll(posX,posY);
}
function toggle_div_with_img (id,imgdwn,imgrt) {
  $('#'+id).toggle();
  if ( $('#'+id).is(':hidden') ) {
    $('#'+id+'_img').attr('src', skin_url+'/images_landing/'+imgrt);
  }
  else {
    $('#'+id+'_img').attr('src', skin_url+'/images_landing/'+imgdwn);
  }
  if(id == 'share_div') {
    document.getElementById('share_field').value = 'share';
  }
}

