/*
=================== CODE MINIMISE =========================

(C) MeloNet Internet Consultancy, 2006-09
http://www.melonet.co.uk
This notice may not be removed from the source code.

=================== CODE MINIMISE =========================
*/
function _Find(id){return document.getElementById(id);}
function _Value(id){if(document.getElementById(id)!=null){return document.getElementById(id).value;}else{return GetRadio(id);}}
function _Int(id){return parseInt(document.getElementById(id).value);}
function _Double(id){return parseFloat(document.getElementById(id).value);}
function _Style(id){return document.getElementById(id).style;}
function _Hide(id){document.getElementById(id).style.display = 'none';}
function _Show(id){document.getElementById(id).style.display = 'block';}

function _Switch(id){if(_Find(id)!=null && _Style(id).display=='none'){_Show(id);}else{_Hide(id);}}

function _SwitchTblRow(id){if(_Find(id)!=null && _Style(id).display=='none'){_ShowTblRow(id);}else{_HideTblRow(id);}}
function _ShowTblRow(id){document.getElementById(id).style.display = '';}
function _HideTblRow(id){document.getElementById(id).style.display = 'none';}



function _SwitchClass(id){if(_Find(id)!=null && _Find(id).className=='cbx-unselected'){_Find(id).className='cbx-selected';}else{_Find(id).className='cbx-unselected';}}


function ping(){ ajax_callback_return_js("handlers/ajax.ping.php","");}
setTimeout("ping();",30000);

function _Goto(url){top.location = _GuRl(url);}
function _Loc(url){document.location = _GuRl(url);}

function _GuRl(url)
{
	if(url.substr(0,7)=="http://") return url;
	
	var b = document.getElementsByTagName('base');
	if (b && b[0] && b[0].href)
	{
		if (b[0].href.substr(b[0].href.length-1) == '/' && url.charAt(0) == '/')
		{
			url = url.substr(1);
		}
	   	url = b[0].href + url;
 	}
 	return url;
}


function _HMS(sec){var h = Math.floor(sec/3600);var m = Math.floor((sec-(h*3600))/60);var s = Math.floor(10*(sec-(m*60)-(h*3600)))/10;if(h>0){return h+"h:"+_NN(m)+"m:"+_NN(s)+"s";}else if(m>0){return m+"m:"+_NN(s)+"s";}else{return s+"s";}}

function _NN(i) { if(i<10) {return "0"+i;}else {return i;}}


function GetRadio(id){
    for (var i=0; i < document.getElementsByName(id).length; i++){
       if (document.getElementsByName(id)[i].checked){
	    	return document.getElementsByName(id)[i].value;
       }
    }
}


function addEvent(elt, eventType, handler, captureMode)
{
	if(document.addEventListener){
		elt.addEventListener(eventType,handler,captureMode)
	}
	else{
		elt.attachEvent('on'+eventType,handler);
	}
}

function windowSize()
{
  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
    //Non-IE
    myWidth = window.innerWidth;
    myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
    //IE 6+ in 'standards compliant mode'
    myWidth = document.documentElement.clientWidth;
    myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
    //IE 4 compatible
    myWidth = document.body.clientWidth;
    myHeight = document.body.clientHeight;
  }
  return { 'x' : myWidth, 'y' : myHeight };
}


/*
=================== DROPDOWN =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== DROPDOWN =========================
*/



/* DropDown Globals */
var g_menu_timer = 0;		/* The timer ID */
var g_current = "";			/* The ID of the currently selected item*/
var g_dropdown = false;		/* Is there a dropdown currently visible */
var g_oldtextcolor = "";	/* If its hover text then this is the previous colour */


function _MenuShow(id,newim,drop) 
{
	//alert(id+" "+g_current+" "+drop);
	if( id!=g_current )
	{
		if(g_current!="")
		{
			clearMyTimer();
			_MenuHide();
		}

		if(drop==1)
		{
			var d = _Style(id);
			d.display = 'block';
			g_dropdown=true;
		}
		g_current = id;

		
		var link = _Find(g_current+'head');
		if(link)
		{
			//g_oldtextcolor=link.style.color;
			//link.style.color="D3A91F";
			link.className='dropmenuheader open';
		}

	}
	else
	{
		clearMyTimer();
	}
}


function clearMyTimer()
{
	if(g_menu_timer!=0)
	{
		clearTimeout(g_menu_timer);
		g_menu_timer=0;
	}
}


function shide()
{
	if(g_menu_timer==0)
	{
		if(g_current!="")
		{
			g_menu_timer=setTimeout( '_MenuHide()', 600 );
		}
	}
}


function _MenuHide()
{
	clearMyTimer();
	
	if(g_current!="")
	{
		if(g_dropdown)
		{
			var d = _Style(g_current);
			d.display="none";
			g_dropdown=false;
		}

		var link = _Find(g_current+"head");
		if(link)
		{
			//link.style.color=g_oldtextcolor;
			link.className='dropmenuheader';
		}

		g_current = "";
	}
}




/*
=================== CONTEXTMENU =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== CONTEXTMENU =========================
*/

var _CM = {

    // private attributes
    _menus : new Array,
    _attachedElement : null,
    _menuElement : null,
    _preventDefault : true,
    _preventForms : true,
    _menuWidth : 0,
    _clickId : "",
    _original_bordercolor : new Array,
    _original_color : new Array,
    _original_class : new Array,

	//
    // public method. Sets up whole context menu stuff..
    //
	setup : function (conf) 
	{

        if ( document.all && document.getElementById && !window.opera ) 
		{
            _CM.IE = true;
        }

        if ( !document.all && document.getElementById && !window.opera ) 
		{
            _CM.FF = true;
        }

        if ( document.all && document.getElementById && window.opera ) 
		{
            _CM.OP = true;
        }

        if ( _CM.IE || _CM.FF ) 
		{
			//document.addEventListener('contextmenu',_CM._show,false);			
            document.oncontextmenu = _CM._show;
            document.onclick = _CM._hide;
            //document.addEventListener('click',_CM._hide,false);

            if (conf && typeof(conf.preventDefault) != "undefined") {
                _CM._preventDefault = conf.preventDefault;
            }

            if (conf && typeof(conf.preventForms) != "undefined") {
                _CM._preventForms = conf.preventForms;
            }

        }

    },


    // public method. Attaches context menus to specific class names
    attach : function (classNames, menuId,width)
	{

		_CM._menuWidth = width;

        if (typeof(classNames) == "string") 
		{
            _CM._menus[classNames] = menuId;
        }

        if (typeof(classNames) == "object") 
		{
            for (x = 0; x < classNames.length; x++) 
			{
                _CM._menus[classNames[x]] = menuId;
            }
        }

    },


    // private method. Get which context menu to show
    _getMenuElementId : function (e) 
	{



        if (_CM.IE) 
		{
            _CM._attachedElement = event.srcElement;
            //_CM._clickId = event.srcElement['id'];

        } 
		else 
		{
            _CM._attachedElement = e.target;
            //_CM._clickId = e.target['id'];
        }


        while(_CM._attachedElement != null) 
		{
            var className = _CM._attachedElement.className;

            _CM._clickId = _CM._attachedElement['id'];

            if (typeof(className) != "undefined") 
			{
                className = className.replace(/^\s+/g, "").replace(/\s+$/g, "")
                var classArray = className.split(/[ ]+/g);

                for (i = 0; i < classArray.length; i++) 
				{
                    if (_CM._menus[classArray[i]]) 
					{
                        return _CM._menus[classArray[i]];
                    }
                }
            }

            if (_CM.IE) 
			{
                _CM._attachedElement = _CM._attachedElement.parentElement;
            } 
			else 
			{
                _CM._attachedElement = _CM._attachedElement.parentNode;
            }
        }

        return null;

    },


    // private method. Shows context menu
    _getReturnValue : function (e) 
	{

        var returnValue = true;
        var evt = _CM.IE ? window.event : e;

        if (evt.button != 1) 
		{
            if (evt.target) 
			{
                var el = evt.target;
            } 
			else if (evt.srcElement) 
			{
                var el = evt.srcElement;
            }

            var tname = el.tagName.toLowerCase();

            if ((tname == "input" || tname == "textarea")) 
			{
                if (!_CM._preventForms) 
				{
                    returnValue = true;
                } 
				else 
				{
                    returnValue = false;
                }
            } 
			else 
			{
                if (!_CM._preventDefault) 
				{
                    returnValue = true;
                } 
				else 
				{
                    returnValue = false;
                }
            }
        }

        return returnValue;

    },


	//
	// Stops context menu crossing edge of page
	//
	_checkWidth : function (position) 
	{
		if(window && window.clientWidth)
		{
			w = ""+window.clientWidth;
		}
		else if (document.documentElement)
	    {
	    	w = ""+document.documentElement.clientWidth;
	    }
	    else if (document.body)
	    {
	        w = ""+document.body.clientWidth;
	    }
	    
	    //
	    // strip 'px'
	    //
	    width = w.replace("px","");
	    end = (position.x+_CM._menuWidth+4);
	      
	    if( end > width ) 
		{
		 	position.x = position.x-_CM._menuWidth+4 ;
		}
	
	    return position;
     },


    _highlight : function () 
	{

            if( _CM._clickId )
            {
	            temp = _Find(_CM._clickId);
	
				_CM._original_class[0] = temp.className;
	
	            temp.className += 'hover';
	
				tr = temp.firstChild;
				cnt = 1;
				while(tr)
				{
				
					if ( tr['style'] != undefined )
					{
						_CM._original_class[cnt] = tr.className;
						
						if(tr.className!="")
						{
							tr.className += 'highlight';
						}
					}
					tr = tr.nextSibling;
					cnt++;
				}
            }
    },

    _unhighlight : function () 
	{

            if( _CM._clickId )
            {
	            temp = _Find(_CM._clickId);
				temp.className = _CM._original_class[0];
	
	            tr = temp.firstChild;
				cnt = 1;
				while(tr)
				{
	
					if ( tr['style'] != undefined )
					{
					   tr.className = _CM._original_class[cnt];
					}
				   	tr = tr.nextSibling;
					cnt++;
	   			}
            }
    },


	//
    // private method. Shows context menu
    //
    _show : function (e) 
	{

        _CM._hide();
        var menuElementId = _CM._getMenuElementId(e);

        if (menuElementId && _CM._clickId) 
		{
			
            var position = _CM._getMousePosition(e);

            position = _CM._checkWidth(position);

            _CM._menuElement = _Find(menuElementId);
            _CM._highlight();
            _CM._menuElement.style.left = position.x + 'px';
            _CM._menuElement.style.top = position.y + 'px';
            _CM._menuElement.style.display = 'block';
            return false;
        }

        return _CM._getReturnValue(e);

    },


	//
    // private method. Hides context menu
    //
    _hide : function () 
	{

		_CM._unhighlight();

        if (_CM._menuElement) 
		{
            _CM._menuElement.style.display = 'none';
        }

    },

	//
    // private method. Returns mouse position
    //
    _getMousePosition : function (e) 
	{   e = e || window.event;
	    var cursor = {x:0, y:0};
	    if (e.pageX || e.pageY) 
		{
	        mX = e.pageX;
	        mY = e.pageY;
	    }
	    else 
		{
	        var de = document.documentElement;
	        var b = document.body;
	        mX = e.clientX +(de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
	        mY = e.clientY +(de.scrollTop || b.scrollTop) - (de.clientTop || 0);
	    }
	
	    return { 'x' : mX, 'y' : mY };
    }

}
_CM.setup({'preventDefault':true, 'preventForms':false});

/*
=================== BUTTONS =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== BUTTONS =========================
*/

function btnEnabled(name)
{
	_Find(name).className = "Button enabled";	
}

function btnDisabled(name)
{
	
	_Find(name).className = "Button disabled";
}



/*
=================== CONTROLGROUPS =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== CONTROLGROUPS =========================
*/

function groupRepShow(sMenu,groupName,total,inc)
{
	selectMenu = _Find(sMenu);
	tot = parseInt(selectMenu.value)+inc;
	for(i=1;i<=tot;i++){_Show(groupName+i);}
	j=1+tot;
	for(i=j;i<=total;i++){_Hide(groupName+i);}
}

/*
=================== CONFIRM =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== CONFIRM =========================
*/

function confirm_op($page,$type)
{
	if(confirm("Are you sure you wish to "+$type+"?")){_Loc($page);}
}

function confirm_link($type)
{
	if(confirm("Are you sure you wish to "+$type+"?")){return true;}
	return false;
}

/*
=================== AJAX =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== AJAX =========================
*/
var req = create_http_request();
function ajax_callback(target,xml)
{
    try
    {     
        req.open("POST", target,true);
        req.send(xml);
    }catch(e){return;}
}
function create_http_request()
{
    try
    {
        if (window.XMLHttpRequest){return new XMLHttpRequest();}
        else if (window.ActiveXObject){return new ActiveXObject("Microsoft.XMLHTTP");}
    }catch(e){return;}
}

function ajax_callback_return_js(target,xml)
{
    try
    {     
        req.open("POST", target,true);
        req.onreadystatechange = callbackFunction;
        req.send(xml);
    }catch(e){return;}
}
function callbackFunction()
{
  if (req.readyState != 4) return;
  eval(req.responseText);
}

/*
=================== AD CLICK =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== AD CLICK =========================
*/

function ajax_ad_click(type,url){ajax_callback("handlers/ajax.adclick.php",type+","+url);}


/*
=================== SIDE PANEL =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== SIDE PANEL =========================
*/

function switchpanel(name)
{
	var panel=_Find(name);
	var inner=_Find(name+"inner");

	if(panel.style.width=="1px"){panel.style.width="136px";inner.style.width="136px";type="show";}
	else{panel.style.width="1px";inner.style.width="1px";type="hide";}

	var hlinker=_Find(name+"_"+type);hlinker.style.display="none";

	if(type=="hide"){var linker=_Find(name+"_show");linker.style.display="block";}
	else{var linker=_Find(name+"_hide");linker.style.display="block";}
}


/*
=================== HIERACHICAL GRID =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== HIERACHICAL GRID =========================
*/
function sSubGrid(name)
{
	for(i=1;i<100;i++)
	{
		if(_Find(name+i)!=null)
		{
			if(_Style(name+i).display=='none'){_Style(name+i).display='table-row';}
			else{_Hide(name+i);}
		}else return;
	}
}

/*
=================== QUICK LOAD FORMS =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== QUICK LOAD FORMS =========================
*/
function createForm(url,title)
{
	//alert('1');
	scroll(0);
	
	var container = document.createElement('div');
   	container.setAttribute('id', 'qlaunch');

	var win = document.createElement('div');
	
	var header = document.createElement('div');

	//alert('4');
	header.setAttribute('id', 'qheader');
	header.innerHTML = "<img src='ims/icons/16x16_cross.png' onclick='closeForm();' /><span>"+title+"</span>";
   	
   	var iframe = document.createElement('iframe');
   	iframe.setAttribute('id', 'qiframe');
   	iframe.src = url;
   	iframe.frameBorder = 0;

	//alert('6');
   	
   	win.appendChild(header);
   	win.appendChild(iframe);
   	//win.className = "popupWindow";
	var mask = document.createElement('div');
	mask.setAttribute('id', 'qblur');
	alpha = 7;
	mask.style.opacity = alpha/10;
	mask.style.filter = 'alpha(opacity=' + alpha*10 + ')';
	mask.style.display = 'block'; 
	
	//alert('8');	
	   	
	container.appendChild(win);
   	document.body.appendChild(container);
   	document.body.appendChild(mask);
   	//alert(document.documentElement.style.overflow);
   	//document.body.style.overflow = "hidden";
   	document.documentElement.style.overflow = "hidden";
   	
	//alert('10');   	
}

function closeForm()
{
	obj = document.getElementById("qlaunch");
  	document.body.removeChild(obj);
  	obj = document.getElementById("qblur");
  	document.body.removeChild(obj);
    //alert(document.documentElement.style.overflow);
    //document.body.style.overflow = "auto";
	//document.body.style.overflow = "";
	document.documentElement.style.overflow = "auto";
	scroll(2);
}

function scroll(i)
{
      if ( document.documentElement && document.documentElement.scrollTop )
      {
            document.documentElement.scrollTop = i;
      }
      else if ( document.body )
      {
            document.body.scrollTop = i;
      }
}


/*
=================== COUNTDOWN =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== COUNTDOWN =========================
*/


var currentRace = new Number(0);
var clockcntr = new Number(0);
var races_ls = new Array();
var races_dt = new Array();


function tickClock()
{
	var dt = races_dt[currentRace];
	
	if(dt!=null)
	{
		var now = new Date();
		var diff = (dt.getTime()-now.getTime())/1000;
	
		var weeks = Math.floor(  diff/(60*60*24*7)  );
		var week_s = weeks*60*60*24*7;
		_Find("vweek").innerHTML = _NN(weeks);
	
		var days = Math.floor(  (diff-week_s)/(60*60*24)  );
		var day_s = days*60*60*24;
		_Find("vday").innerHTML = _NN(days);
	
		var hours = Math.floor(  (diff-week_s-day_s)/(60*60)  );
		var hour_s = hours*60*60;
		_Find("vhour").innerHTML = _NN(hours);
	
		var mins = Math.floor(  (diff-week_s-day_s-hour_s)/(60)  );
		var min_s = mins*60;
		_Find("vmin").innerHTML = _NN(mins);
	
		var secs = Math.floor(  (diff-week_s-day_s-hour_s-min_s)  );
		var sec_s = secs;
		_Find("vsec").innerHTML = _NN(secs);
	
		var ms = Math.floor((diff-week_s-day_s-hour_s-min_s-sec_s)*1000);
	
	
		clockcntr++;
		if(clockcntr>25)
		{
			clockcntr = 0;	
			nextClock();
		}
		setTimeout("tickClock();",ms);
	}
	else setTimeout("tickClock();",600);
}

var letter = 0;
function writeClockTitle()
{
	var title = races_ls[currentRace];
	
	if(title!=null)
	{
		_Find("vtitle").innerHTML += title.charAt(letter);
		letter++;
		if(letter<title.length)
		{
			setTimeout("writeClockTitle();",70);	
		}
	}
	else setTimeout("writeClockTitle();",600);
}

function nextClock()
{
	currentRace++;
	if(currentRace>=races_ls.length) currentRace = 0;	
	
	_Find("vweek").innerHTML = "00";
	_Find("vday").innerHTML = "00";
	_Find("vhour").innerHTML = "00";
	_Find("vmin").innerHTML = "00";
	_Find("vsec").innerHTML = "00";
	_Find("vtitle").innerHTML = "&nbsp;";
	letter = 0;
	writeClockTitle();
}

/*
=================== STAR =========================

(C) MeloNet Internet Consultancy, 2006-09

=================== STAR =========================
*/

function starReg(id)
{
    val = _Find(id).value;
    
    s="l";
    for(i=5;i<=50;i+=5)
    {
        if(i==5) j = "05";
        else j = i;
        
        if((i/10)<=val) _Find('star'+j+id).className = s+'star_sel';
        else _Find('star'+j+id).className = s+'star';
        
        if(s=="l") s="r";
        else s="l";
    }
}

function starShow(id,val)
{
    val=val/10;
    s="l";
    for(i=5;i<=50;i+=5)
    {
        if(i==5) j = "05";
        else j = i;
        
        if((i/10)<=val) _Find('star'+j+id).className = s+'star_sel';
        else _Find('star'+j+id).className = s+'star';
        
        if(s=="l") s="r";
        else s="l";
    }
    
}

function starClick(id,val)
{
    val=val/10;
    s="l";
    for(i=5;i<=50;i+=5)
    {
        if(i==5) j = "05";
        else j = i;
        
        if((i/10)<=val) _Find('star'+j+id).className = s+'star_sel';
        else _Find('star'+j+id).className = s+'star';
        
        _Find('star'+j+id).onmouseover = function (){};
        _Find('star'+j+id).onmouseout = function (){};
        _Find('star'+j+id).onclick = function (){};
        
        if(s=="l") s="r";
        else s="l";
    }
    
    _Find(id).value = val;
    _Find(id).onchange();
}

