var global_time = Array(0,0,0,0,0,0);

function shadeMain()
{
	wh = document.documentElement.clientHeight;
        rwh = window.innerHeight;
	cwh = document.body.clientHeight;

	h = wh>rwh ? (wh>cwh ? wh : cwh) : (rwh>cwh ? rwh : cwh);

	ovl = document.getElementById("overlay");
	ovl.style.height = h+"px";
	ovl.style.display = "block";
}

function unshadeMain()
{
	document.getElementById("overlay").style.display = "none";
	return true;
}

function showMessage(div)
{
	msg = document.getElementById(div);
	msg.style.width = "300px";
	msg.style.left = (document.body.clientWidth/2 - 150)+"px";
//	msg.style.top = truebody().scrollTop + 200 + "px";
	msg.style.display = "block";
}

function hideMessage(div)
{
	document.getElementById(div).style.display = "none";
}

function showImage(id,w,h)
{
	shadeMain();

	msg = document.getElementById("image_cont_"+id);
	msg.style.width = (w+24)+"px";
	height = h+24+15;
	msg.style.left = Math.round((document.body.clientWidth-(w+24))/2)+"px";
//	msg.style.top = truebody().scrollTop + Math.round((document.documentElement.clientHeight-height)/2) + "px";
	msg.style.display = "block";
}

function hideImage(id)
{
	msg = document.getElementById("image_cont_"+id);
	msg.style.display = "none";

	unshadeMain();
}


function showError(div,message)
{
	contentdiv = document.getElementById(div);

	contentdiv.innerHTML = message;
	contentdiv.style.display = "block";

	self.scrollTo(0,0);
}

function hideError(div)
{
	document.getElementById(div).style.display = "none";
}

function captcha_reload()
{
	img = document.getElementById("captcha_code");
	img.src = "/image_code.gif/"+Math.random();
	

	return false;
}

function truebody()
{
	return ((document.compatMode == "BackCompat") || (document.compatMode == null)) ? document.body : document.documentElement;
}

function showHint(hintname,e)
{
	x = e.x ? e.x : e.pageX;
	y = e.y ? truebody().scrollTop + e.y : e.pageY;
	width = document.body.clientWidth;

	hintobj = document.getElementById(hintname);

	hintobj.style.display = "block";
	hintobj.style.top = (y-30)+"px";
	hintobj.style.right = (width-x-10)+"px";
}

function hideHint(hintname)
{
	document.getElementById(hintname).style.display = "none";
}

function newWindow(url,w,h)
{
	var w = window.open(url,"gp_win","toolbar=no,location=no,status=no,scrollbars=no,width="+w+",height="+h);
}

function goURL(url)
{
	top.location.href = url;
}

function switchFilter(filter)
{
	f = document.getElementById(filter);

	f.style.display = (f.style.display == "block") ? "none" : "block";
}

function global_timer()
{
	global_time[5]++;

	if (global_time[5] == 60)
	{
		global_time[5] = 0; global_time[4]++;
	}

	if (global_time[4] == 60)
	{
		global_time[4] = 0; global_time[3]++;
	}

	if (global_time[3] == 24)
	{
		global_time[3] = 0; global_time[2]++;
	}

	if (global_time[2] == 31)
	{
		global_time[2] = 0; global_time[1]++;
	}

	if (global_time[1] == 12)
	{
		global_time[1] = 0; global_time[0]++;
	}

	for (i=1;i<6;i++)
		document.getElementById("global_timer_"+i).innerHTML = global_time[i];
}

function global_timer_init(year,month,day,hour,mins,sec)
{
	global_time[0] = year;
	global_time[1] = month;
	global_time[2] = day;
	global_time[3] = hour;
	global_time[4] = mins;
	global_time[5] = sec;

	if (global_timer_interval !== undefined)
		clearInterval(global_timer_interval);

	global_timer_interval = self.setInterval("global_timer()",1000);
}

function rand(n)
{
	return Math.floor(Math.random()*(n+1));
}

function settimeActive(pform,num)
{
	pform.rtype.disabled = (num>1);
	pform.month1.disabled = (num != 2);
	pform.month2.disabled = (num != 2);
	pform.day1.disabled = (num != 2);
	pform.day2.disabled = (num != 2);
	pform.year1.disabled = (num != 2);
	pform.year2.disabled = (num != 2);
	pform.lastdays.disabled = (num != 3);
}

function inputReset(el,str)
{
	if (!el.value.length)
		el.value = str;
}

function inputClean(el,str)
{
	if (el.value == str)
		el.value = "";
}

function switchFilter(img)
{
	document.getElementById("filter_body").style.display = (document.getElementById("filter_body").style.display == "none") ? "block" : "none";
	document.getElementById("filter_switch").innerHTML = (document.getElementById("filter_body").style.display == "none") ? "ON" : "OFF";
}

function enableSubmit(txt_id,s_id)
{
	txt = document.getElementById(txt_id);
	sbtn = document.getElementById(s_id);

	sbtn.disabled = !txt.value.length;
}

function showSocial(div_id)
{
	shadeMain();
	msg = document.getElementById(div_id);

	msg.style.width = "600px";
	msg.style.left = (document.body.clientWidth/2 - 300)+"px";
//	msg.style.top = truebody().scrollTop + 200 + "px";
	msg.style.display = "block";
}

function hideSocial(div_id)
{
	document.getElementById(div_id).style.display = "none";
	unshadeMain();
}

function showDiv(div_id)
{
	document.getElementById(div_id).style.display = "block";
}

function hideDiv(div_id)
{
	document.getElementById(div_id).style.display = "none";
}

function switchDiv(div_id)
{
	document.getElementById(div_id).style.display = document.getElementById(div_id).style.display == "block" ? "none" : "block";
}

function cswitchHint(show)
{
	hint = document.getElementById("counter_hint");
	hint.style.visibility = show ? "visible" : "hidden";
}

function imgSwitch(img,file)
{
	img.src="/i/"+file;

	return true;
}
