/************************************************************************************************************
Ajax dynamic list
Copyright (C) September 2005  DTHMLGoodies.com, Alf Magne Kalleland

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

Dhtmlgoodies.com., hereby disclaims all copyright interest in this script
written by Alf Magne Kalleland.

Alf Magne Kalleland, 2006
Owner of DHTMLgoodies.com
	
************************************************************************************************************/	
var module_name;
function showbubble(e,msg,yes_url,no_url,x_coord,y_coord){//alert(msg);alert(yes_url);alert(no_url);return  
  if(document.all)e = event;
  var my_text = ''+msg+' <div  style=margin:auto;padding:0;width:auto;text-align:center;><input type = button value=Yes onclick ="window.location =\''+yes_url+'\'">   <input type = button value=No onclick = \'hideToolTip();\'> </div></div></div>';

  var obj = document.getElementById('bubble_tooltip');
  var obj2 = document.getElementById('bubble_tooltip_content');
  obj2.innerHTML = my_text;
  obj.style.display = 'block';
  var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
  if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
  var leftPos = e.clientX - 100 - x_coord;
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  obj.style.top = e.clientY - obj.offsetHeight -1 + st + y_coord +'px';
//   var hide_bubble = "document.getElementById('bubble_tooltip').style.display='none';";
//   clear_bubble_hide = window.setTimeout(hide_bubble,3000);
     
}	

function showmoduleclosebubble(e, msg, yes_url, no_url){
  module_name=yes_url;
  if(document.all)e = event; 
  var my_text ='Do you want to remove '+msg+' <div  style=margin:auto;padding:0;width:auto;text-align:center;><input type = button value=Yes onclick =\'delete_from_user_page_yes();\'>   <input type = button value=No onclick = \'hideToolTip();\'> </div></div></div>';
  var obj = document.getElementById('bubble_tooltip');
  var obj2 = document.getElementById('bubble_tooltip_content');
  obj2.innerHTML = my_text;
  obj.style.display = 'block';
  var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
  if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st +=2;
  if(navigator.userAgent.toLowerCase().indexOf('chrome')>=0)st -=10;
  var leftPos = e.clientX - 170;
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  obj.style.top = e.clientY - obj.offsetHeight - 2 + st + 'px';
  //var hide_bubble = "    document.getElementById('bubble_tooltip').style.display='none';";
//   clear_bubble_hide = window.setTimeout(hide_bubble,3000);
}

var module_name;
function deletecheckmessage(e, field, item, form_name, x_coord, y_coord){ 
  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;
      }
    }
  } 
  str=item;
  if(field=='delete') {
    if(chk_cnt) {
      if (chk_cnt > 1) {
        str = str + 's';
      }
      if(document.all)e = event;
      var my_text ='Are you sure you want to delete the selected '+str+'? <div  style=margin:auto;padding:0;width:auto;text-align:center;><input type = button value=Yes onclick ="submitform(\''+form_name+'\');">   <input type = button value=No onclick = \'hideToolTip();\'> </div></div></div>';
          
//       var my_text = '<div><b>Are you sure you want to delete the selected '+str+' ? </b> <div style="margin:0;float:left;padding:0;width:200px;text-align:center;"> <div  style="margin:auto;padding:0;width:auto;text-align:center;"><input type = "button" value="Yes" onclick ="submitform(\''+form_name+'\');">   <input type = "button" value="No" onclick = \'hideToolTip();\'> </div></div></div>';
      var obj = document.getElementById('bubble_tooltip');
      var obj2 = document.getElementById('bubble_tooltip_content');
      obj2.innerHTML = my_text;
      obj.style.display = 'block';
      var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
      if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
      var leftPos = e.clientX - 100 - x_coord;
      if(leftPos<0)leftPos = 0;
      obj.style.left = leftPos + 'px';
      obj.style.top = e.clientY - obj.offsetHeight -1 + y_coord + st +'px';
    } 
  }
}

function hideToolTip() {
  document.getElementById('bubble_tooltip').style.display = 'none';
}

function hideToolTip_help() {
  document.getElementById('bubble_tooltip_help').style.display = 'none';
  prev_id_or_url = '';
  document.getElementById('bubble_tooltip_content_help').innerHTML = '';
}

function submitform(form_name) {
  document.forms[form_name].submit();
}


function delete_from_user_page_yes() { 
  $('#' + module_name).hide('slow',serialize);
  try {
    $('#chk_'+module_name).removeAttr("checked");
  } catch (e) {
  }
  hideToolTip(); 
}


function showcategorydesc(e, msg, no_of_user, img_path, x_coord, y_coord){//alert(msg);alert(yes_url);alert(no_url);return  
    if(document.all)e = event;
  var my_text = '<img src = "'+img_path+'" alt = "" /> '+msg+'( '+no_of_user+' Games )';

  var obj = document.getElementById('bubble_tooltip');
  var obj2 = document.getElementById('bubble_tooltip_content');
  document.getElementById('bottomrightarrow').style.display="none";
  document.getElementById('bottomleftarrow').style.display="block";
  obj2.innerHTML = my_text;
  obj.style.display = 'block';
  var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
  if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
  var leftPos = e.clientX - 100 - x_coord;
  if(leftPos<0)leftPos = 0;
  obj.style.left = leftPos + 'px';
  obj.style.top = e.clientY - obj.offsetHeight -12 + st + y_coord +'px';
//   var hide_bubble = "document.getElementById('bubble_tooltip').style.display='none';";
//   clear_bubble_hide = window.setTimeout(hide_bubble,3000);
     
}

var prev_id_or_url = '';
function helpbubble(e, inline, id_or_url, id, arrow_possition) {
  if ( prev_id_or_url == id_or_url ) {
    return ;
  }
  alert(id_or_url);
  prev_id_or_url = id_or_url;
  var my_text = '';
  var obj = document.getElementById('bubble_tooltip_help');
  var obj2 = document.getElementById('bubble_tooltip_content_help');
  var module_obj = document.getElementById(id);
  if(document.all)e = event;
  if ( inline ) {
    my_text = $('#'+id_or_url).html();
  } else {
    $.get(
      id_or_url,
      {
        'random': (new Date().getTime())
      },
      function(data) {
        my_text = data;
        obj2.innerHTML = my_text;
      }
    );
  }
  obj2.innerHTML = my_text;
  
  var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
  if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st +=20;
  if(navigator.userAgent.toLowerCase().indexOf('chrome')>=0)st -=20;
  
  var leftPos = e.clientX;
  if ( leftPos < 0 ) {
    leftPos = 0;
  }
  if ( arrow_possition == 'left' ) {
    obj.style.display = 'none';
    obj.style.left = leftPos + 'px';
    obj.style.top = e.clientY - obj.offsetHeight - 30 + st + 'px';
    $('#bottomrightarrow_help').css('display', 'none');
    $('#topleftarrow_help').css('display', 'block');
  } else {
    obj.style.left =  e.clientX - 170 + 'px';
    obj.style.top = e.clientY - obj.offsetHeight - 210 + st + 'px';
//     if(!(st)) {
//      obj.style.top = e.clientY - obj.offsetHeight - 175 + st + 'px';
//     } else {
//     obj.style.top = e.clientY - obj.offsetHeight - 190 + st + 'px';
//     }
  }
obj.style.display = 'block';  
  $('#close_link_help').css('display', 'block');
}
