
function write_swf (mov, size, other)
{
	document.write ('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" ' + size + ' ' + other + '>');
	document.write ('<param name="movie" value="' + mov + '" />');
	document.write ('<param name="quality" value="high" />');
	document.write ('<embed src="' + mov + '" quality="high" bgcolor="#ffffff" ' + size + ' name="animation" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write ('</object>');
}

function openurl(u)
{
	document.location = u;
}

function previewurl(u)
{
	u = u.replace(/%%\$KEYWORD%%/, 'test');
	u = u.replace(/\{keyword.*\}/i, 'test');

	if (u.substr(0, 7) != 'http://' && u.substr(0, 8) != 'https://')
		u = 'http://' + u;

	if ( u != 'http://' && u != 'https://')
		window.open(u, '_blank', 'top=50,left=50,width=800,height=600,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes');
	else
		alert ('Please enter a valid URL.');
}

function showPopupDetails(u)
{
	window.open(u, 'contentTips', 'top=20,left=20,width=1050,height=750,menubar=yes,location=yes,resizable=yes,scrollbars=yes,status=yes');
}

function popupUpload(url)
{
	window.open(url, 'popupUpload', 'top=50,left=50,width=545,height=175,menubar=no,location=no,resizable=no,scrollbars=no,status=no');
}

function set_grid_color(row, color)
{
	row.setAttribute('bgcolor', color, 0);
}

function set_grid_color_over(row)
{
	row.setAttribute('bgcolor', '#ffedd3', 0);
}

function set_grid_color_out(row)
{
	row.setAttribute('bgcolor', '#FFFFFF', 0);
}

function set_menu_color(this_td, color)
{
		this_td.setAttribute('bgcolor', color, 0);
}

function change_date_range(dr_name, view)
{
	if (view == 'daily') {
		document.getElementById(dr_name + '_1').disabled = 0;
		document.getElementById(dr_name + '_3').disabled = 0;
		document.getElementById(dr_name + '_4').disabled = 0;
		document.getElementById(dr_name + '_5').disabled = 0;
		document.getElementById(dr_name + '_0').onchange = null;
		document.getElementById(dr_name + '_1').onchange = null;
		document.getElementById(dr_name + '_2').onchange = null;
	} else if (view == 'monthly') {
		document.getElementById(dr_name + '_1').disabled = 1;
		document.getElementById(dr_name + '_3').disabled = 0;
		document.getElementById(dr_name + '_4').disabled = 1;
		document.getElementById(dr_name + '_5').disabled = 0;
		document.getElementById(dr_name + '_0').onchange = null;
		document.getElementById(dr_name + '_1').onchange = null;
		document.getElementById(dr_name + '_2').onchange = null;
	} else if (view == 'hourly') {
		document.getElementById(dr_name + '_1').disabled = 0;
		document.getElementById(dr_name + '_3').disabled = 1;
		document.getElementById(dr_name + '_4').disabled = 1;
		document.getElementById(dr_name + '_5').disabled = 1;
		sync_date(dr_name, 0, 3);
		sync_date(dr_name, 1, 4);
		sync_date(dr_name, 2, 5);
		document.getElementById(dr_name + '_0').onchange = function () {
			sync_date(dr_name, 0, 3);
		}
		document.getElementById(dr_name + '_1').onchange = function () {
			sync_date(dr_name, 1, 4);
		}
		document.getElementById(dr_name + '_2').onchange = function () {
			sync_date(dr_name, 2, 5);
		}
	}
}

function sync_date(dr_name, f1, f2)
{
	document.getElementById(dr_name + '_' + f2).selectedIndex = document.getElementById(dr_name + '_' + f1).selectedIndex;
}

function uradiTab (input,len, e)
{
	var isNN = (navigator.appName.indexOf("Netscape") != -1);
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter  = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];

	if (input.value.length >= len && !containsElement(filter,keyCode)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele)
	{
		var found = false, index = 0;
		while(!found && index < arr.length)
			if(arr[index] == ele) found = true;
			else index++;
		return found;
	}

	function getIndex(input)
	{
		var index = -1, i = 1, found = false;
		while (i < input.form.length && index == -1)
			if (input.form[i] == input)
				index = i;
			else i++;
				return index;
	}

	return true;
}

function show_details(url)
{
	window.open(url, 'details', 'top=200,left=400,width=270,height=350,scrollbars=1,resizable=1');
}

function showAd(exampleLink, adDiv)
{
	if (self.innerWidth) {
		adScrollTop = self.pageYOffset;
		adScrollLeft = self.pageXOffset;
		adWinWidth = Math.min(self.innerWidth, document.documentElement.clientWidth);
		adWinHeight = Math.min(self.innerHeight, document.documentElement.clientHeight);
	} else if (document.documentElement && document.documentElement.clientWidth) {
		adScrollTop = document.documentElement.scrollTop;
		adScrollLeft = document.documentElement.scrollLeft;
		adWinWidth = document.documentElement.clientWidth;
		adWinHeight = document.documentElement.clientHeight;
	} else if (document.body) {
		adScrollTop = document.body.scrollTop;
		adScrollLeft = document.body.scrollLeft;
		adWinWidth = document.body.clientWidth;
		adWinHeight = document.body.clientHeight;
	}
	// Very old browsers.
	else return;

	adLeft = absoluteLeft(exampleLink);
	adMargin = (adWinWidth + adScrollLeft) - (adLeft + adDiv.offsetWidth);

	if (adMargin < 10)
		adLeft += adMargin;

	adTop = absoluteTop(exampleLink) - (adDiv.offsetHeight);
	if (adTop < adScrollTop + 5)
		adTop = absoluteTop(exampleLink) + exampleLink.offsetHeight + 15;

	adDiv.style.left = (adLeft > 0 ? adLeft : 0) +"px";
	adDiv.style.top = (adTop > 0 ? adTop : 0) +"px";

	adDiv.style.visibility = 'visible';

	try {
		var fla = (isIE) ? $('RLflash') : document['RLflash'];
		fla.pauseResume(1);
	} catch (e) {}

	window.clearTimeout(timeoutID);
	timeoutID = null;
}

function absoluteTop (element)
{
	var top = 0;
	while (element) {
		top += element.offsetTop;
		element = element.offsetParent
	}
	return top;
}

function absoluteLeft (element)
{
	var left = 0;
	while (element) {
		left += element.offsetLeft;
		element = element.offsetParent
	}
	return left;
}

var isIE = navigator.appName.indexOf("Microsoft") != -1;

function hideAd ()
{
	try {
		var fla = (isIE) ? $('RLflash') : document['RLflash'];
		fla.pauseResume(0);
	} catch (e) {}
	$('previewDiv').style.visibility = 'hidden';
}

function addSlashes(str)
{
	return (str + '').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}

function urlEncode(str)
{
	return escape(str).replace(/\+/g,'%2B').replace(/%20/g, '+').replace(/\*/g, '%2A').replace(/\//g, '%2F').replace(/@/g, '%40');
}

function getElementPosition(element)
{
	var result = new Object();

	result.x      = 0;
	result.y      = 0;
	result.width  = 0;
	result.height = 0;

	if (element.offsetParent) {
		result.x = element.offsetLeft;
		result.y = element.offsetTop;

		var parent = element.offsetParent;

		while (parent) {
			result.x += parent.offsetLeft;
			result.y += parent.offsetTop;

			var parentTagName = parent.tagName.toLowerCase();

			if ((parentTagName != "table") &&
				 (parentTagName != "body") &&
				 (parentTagName != "html") &&
				 (parentTagName != "div") &&
				 parent.clientTop &&
				 parent.clientLeft) {

				result.x += parent.clientLeft;
				result.y += parent.clientTop;
			}

			parent = parent.offsetParent;
		}
	}
	else if (element.left && element.top) {
		result.x = element.left;
		result.y = element.top;
	}
	else {
		if (element.x)
			result.x = element.x;

		if (element.y)
			result.y = element.y;
	}

	if (element.offsetWidth && element.offsetHeight) {
		result.width  = element.offsetWidth;
		result.height = element.offsetHeight;
	}
	else if (element.style && element.style.pixelWidth && element.style.pixelHeight) {
		result.width  = element.style.pixelWidth;
		result.height = element.style.pixelHeight;
	}

	return result;
}
