function onBodyLoad() 
{

}

function NVL(value, defaultValue) 
{
  if (null == defaultValue) defaultValue = false;
  if(typeof(value) == "undefined" || value == null) {
    return defaultValue;
  }
  return value;
}

function showElementById(el_id) 
{
	var el = document.getElementById(el_id);
    if (NVL(el)) el.style.display = 'block';
}

function hideElementById(el_id) 
{
	var el = document.getElementById(el_id);
    if (NVL(el)) el.style.display = 'none';
}

function showWithdraw(record) 
{
	var vis_form ="withdraw_form" + record[record.selectedIndex].value;
	var hide_form = new String;
	for (var i=0; i < record.length; i++) {
		hide_form = "withdraw_form" + record[i].value;
        hideElementById(hide_form);
	}
    showElementById(vis_form);
}

function manageGroup(groupListId) 
{
    if (document.getElementById) {
	var el = document.getElementById (groupListId);
        var groupId = el.options[el.selectedIndex].value;
	window.location = "groups.php#" + groupId;
    }
    return;
}

function setFormAction(action, form) 
{    
    document.forms[form].elements['action'].value=action;
}

function setFormSubAction(action, form) 
{
    document.forms[form].elements['subaction'].value=action;
}

function fiter_redirect(addr, pk) {

    var address = (-1 != addr.indexOf("?")) ? (addr + "&") : (addr + "?");
    address += "pt=" + current_period_type + "&pk=" + pk + "&";
    if (NVL(filter_url_param, false))	
      address += filter_url_param;
    window.location.href = address;
}


function trim(s)
{
  return rtrim(ltrim(s));
}

function ltrim(s)
{
  return s.replace(/^\s+/, ''); 
}

function rtrim(s)
{
  return s.replace(/\s+$/, ''); 
}

function link_channelmodify(channel_id, code_id) {
	var channel = document.getElementById(channel_id);
	var code = document.getElementById(code_id);
	if (NVL(channel) && NVL(code)) {
		var channel_regexp = new RegExp("(.*)\\?channel=([^&]+)&(.*)", "i");	
		var res = channel_regexp.exec(code.value);		
		var channel_encode = escape(trim(channel.value));
		var code_modified = "";
	//
		if (!NVL(res)) {
			if ("" != channel.value) {
				code_modified = (code.value).replace("?", "?channel=" + channel_encode + "&");
				code.value = code_modified;
			}
		} else {
			code_modified = ("" != channel.value) ? (res[1] + "?channel=" + channel_encode +  "&" + res[3]) : (res[1] + "?" + res[3]) ;
			code.value = code_modified;
		}
	//
	}
}

//

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
