$(document).ready(function()
{
	$('.confirm').live('click',function()
	{
		var ans = confirm($('.confirmtext',this).text());
		if(ans) window.location.href=this.href;
		return false;
	});
	$('[id^=s_]').live('click',function()
	{
		var id  = $(this).attr('id').split('_')[1];
		$(this).toggleClass('sel');
		$('.e_'+id).toggleClass('hide');
		return false;
	});
	if($('.naverror').text()) 
	{
		$('.naverror').slideDown();
		setTimeout(function(){$('.naverror').fadeOut('slow');},5000);
	}
	$('.nextsetup').live('click',function()
	{
		id = $(this).parents('ul:first').find('.rolecont').not('.hide').first().attr('id').split('_');
		setupid = id[0];
		groupid = parseInt(id[2]);
		nextsetups = $('[id^='+setupid+'_group_'+(groupid+1)+'_]')
		if(nextsetups.size()>0)
		{
			$(this).parents('ul:first').find('.rolecont.toggleroles').addClass('hide');
			nextsetups.removeClass('hide');
		}
	});
	$('.prevsetup').live('click',function()
	{
		id = $(this).parents('ul:first').find('.rolecont').not('.hide').first().attr('id').split('_');
		setupid = id[0];
		groupid = parseInt(id[2]);
		nextsetups = $('[id^='+setupid+'_group_'+(groupid-1)+'_]')
		if(nextsetups.size()>0)
		{
			$(this).parents('ul:first').find('.rolecont.toggleroles').addClass('hide');
			nextsetups.removeClass('hide');
		}
	});
});
/*==========================  Onload ==========================*/

function poptog(name)
{
  $('#pop,#pop_').toggleClass('hide');
  $('#pop_').children('*').each(function(){$(this).hide()});
  $(name).show();
}

function pophtml(o)
{
  $('#pop_warn_text').html(o);
  poptog('#pop_warn');
}

function errordisplay(cont,msg)
{
	$(cont).clearQueue().html(msg).slideDown().queue(function(){
		$(this).delay(2500).fadeOut();
		$(this).dequeue();
	});
}

/*==========================  Pagination ==========================*/

function loadpage(cont,url,pagenum,param,callback)
{
  if(!$(cont).size()) return;
  var data = $.extend({page:pagenum},param);
  $(cont).load(root+url,data,function()
  {
    $(cont+' [id^=val_]').each(function()
    {
      var parse=$(this).attr('id').split('_');	  
      $(this).click(function()
      {
        loadpage(cont,url,parse[1],param,callback);
        return false;
      });
    });
    if(callback) callback();
  });
}
/*==========================  Tools ==========================*/
function limittext(field, num)
{
    if (field.value.length > num)
    {
    	field.value = field.value.substring(0, num);
    }
}
function nocopy(cont)
{
	rfalse = function(){return false;};
	$(cont).mousedown(rfalse).select(rfalse).removeClass(cont);
}
function br2nl(str)
{
	return str.replace("<br/>","\n");
}

function disablectrl(e)
{
	var forbiddenKeys = ['a', 'n', 'c', 'x', 'v', 'j','z'];
	var key;
	var isCtrl;
	
	if(window.event)
	{
        key = window.event.keyCode;     //IE
        isCtrl = (window.event.ctrlKey)? true:false;
	}
	else
	{
        key = e.which;     //firefox
        isCtrl = (e.ctrlKey)?true:false;
	}
	
	if(isCtrl)
	{
        for(i=0; i<forbiddenKeys.length; i++)
        {
            if(forbiddenKeys[i].toLowerCase() == String.fromCharCode(key).toLowerCase())
            {

                return false;
            }
        }
	}
	return true;
}
/*==========================  Ajax ==========================*/

function redirect(o)
{
  if(o.redirect) location.reload(true);
}
