var chatapp;
var timer_clock;

function Over(obj){obj.style.backgroundColor="d5e65b";}
function Out(obj){obj.style.backgroundColor="";}
function overMenu(obj, num){obj.src='images/button_'+num+'_over.jpg';}
function outMenu(obj, num){obj.src='images/button_'+num+'.jpg';}
function $(id){return document.all ? document.all[id] : document.getElementById ? document.getElementById(id) : null;}

function Clock(){
	if(times){
		times[2]=times[2];
		times[1]=times[1];
		times[0]=times[0];
		
		times[2]++;
		if (times[2]>=60){
			times[2]=0;
			times[1]++;
			if(times[1]>=60){
				times[1]=0;
				times[0]++;
				if(times[0]>=24){
					times[0]=0;
				}
			}
		}
		tmp_times = times;
		for (i=0;i<tmp_times.length;i++){
			tmp_times[i] = tmp_times[i].toString();
			if (tmp_times[i].length==1){
				tmp_times[i] = "0"+tmp_times[i];
			}
		}
		document.getElementById('times').innerHTML=""+tmp_times[0]+":"+tmp_times[1]+":"+tmp_times[2]+"";
		timer_clock = setTimeout("Clock()", 1000);
	}
}

function playSound(srcs){
	srcs='http://www.horse-nation.nl/sounds/'+srcs;	
	document.getElementById("sound").innerHTML += '<EMBED id="shooter" SRC="'+srcs+'" HIDDEN="true" loop="false"  AUTOSTART="true" />'; 
}

function GetMoney(num)
{
	num = Math.floor(Math.floor(num*100+0.50000000001)/100).toString();
	for (var i=0;i<Math.floor((num.length-(1+i))/3);i++)
	{
		num=num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
	}
	return num;
}

function GetChatApp()
{
	if (!chatapp)
	{
		chatapp=window.open("pages/chatbox.php", "ChatBox", "toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=450");
	}
	else
	{
		window.chatapp.focus();	
	}
}

function Resize(max_length){
	for(i=14;i<document.images.length;i++){
		if(document.images[i].src.match("horse-nation.nl") != 'horse-nation.nl'){
			if(parseInt(document.images[i].width) > max_length){		
				widths = ResizeImage(new Array(document.images[i].width,document.images[i].height), max_length);	
				document.images[i].width = widths[0];
				document.images[i].height = widths[1];
			}
		}
	}
}

function ResizeImage(widths, max_length){
	if (widths[0]<widths[1]){
	    iiihh=1;
	    pc_sz1=widths[1];
	    pc_sz2=widths[0]; 
	}
	else{
	    iiihh=0;
	    pc_sz1=widths[0];
	    pc_sz2=widths[1]; 
	}
	if (pc_sz1>max_length){
	    pc_sz_tmp=Math.round(max_length/(pc_sz1/100));
	    widths[0]=Math.round((pc_sz1/100)*pc_sz_tmp);
	    widths[1]=Math.round((pc_sz2/100)*pc_sz_tmp);
	}
	else{
	    widths[0]=pc_sz1;
	    widths[1]=pc_sz2;
	}
	size= new Array(0,0);
	if (iiihh==1){
	    size[0]=widths[1];
	    size[1]=widths[0];
	}
	else{
	    size[0]=widths[0];
	    size[1]=widths[1];
	}	
	return size;
}