function getCode(sitename, siteid, siteurl)
{
	//var sitename = prompt("Please enter the URL to your site where you want this tracker to be installed?",'http://');
	if(sitename.replace('http://','')!='')
	{
		var hDiv = $('hiddenBuffer').cloneNode(true);
	
		var Buffer = hDiv.value;
		hDiv.value = Buffer.replace('#SITENAME#',escape('http://'+sitename.replace('http://','')));
		
		var trafficCode = "<script language='javascript' src='"+siteurl+"/traffic.php?site_id="+siteid+"'></script>\n\r";
		
		hDiv.value = trafficCode+hDiv.value;
		
		var pDiv = document.createElement('div');
		pDiv.style.fontWeight = 'bold';
		pDiv.style.fontSize = '11px';
		
/*		var input = document.createElement('input');
		input.type = 'text';
		input.value = trafficCode;
		input.className = 'roTxt';
		input.style.width = '85%';
		
		input.onclick = function()
		{
			this.select();
		}
*/	
		
		
		var closeBtn = getCloseBtn();
		
		pDiv.appendChild(closeBtn);
		pDiv.appendChild(getBR());
/*		pDiv.appendChild(document.createTextNode('Traffic Code:'));
		pDiv.appendChild(getBR());
		pDiv.appendChild(input);
		pDiv.appendChild(getBR());*/
		hDiv.style.position = 'relative';
		hDiv.style.visibility = 'visible';
		pDiv.appendChild(document.createTextNode('Crawler Code:'));
		pDiv.appendChild(getBR());
		pDiv.appendChild(hDiv);
		
		pDiv.className = 'popup';		
		var _to = document.body.scrollTop || document.documentElement.scrollTop;
		pDiv.style.top = (_to +100)+'px';
		pDiv.style.left = (screen.width/2 - 320)+'px';
		
		document.body.appendChild(pDiv);		
		
		hDiv.select();
		hDiv.onclick = function()
		{
			this.select();
		}
	}else
	{
		alert("Please enter a valid URL");
	}
}

function getBR()
{
	var br = document.createElement('br');
	br.style.fontSize = '1px';
	br.style.clear = 'both';
	
	return br;
}

function getCloseBtn()
{
	var a = document.createElement('a');
	
	a.href = 'javascript://';
	a.onclick = function()
	{
		this.parentNode.style.visibility = 'hidden';
		
		//$('hiddenBuffer').style.position = 'absolute';
		//$('hiddenBuffer').style.visibility = 'hidden';
		
		//document.body.appendChild($('hiddenBuffer'));
	
		document.body.removeChild(this.parentNode);
		
	}
	a.innerHTML = 'x';
	a.className = 'closeBtn';
	
	return a;
}

window.onload = function()
{
	if($('filterUrl'))
	{
		getAllData();
		var opt = $('filterUrl');
		
		var optind = 0;
		for(i in gAry)
			opt.add(new Option(gAry[i],gAry[i]),(window.ActiveXObject?optind++:null));
	}
}

function getAllData()
{
	var tbl = $('dataGrid');
	gAry = [];
	
	for(t=0;t<tbl.rows.length;t++)
	{
		var val = tbl.rows[t].cells[1].innerHTML.toLowerCase().replace(/<a[^>]*>/g,'').replace('</a>','');
		if(!inArray(gAry, val))
			gAry.push(val);
	}
}

function inArray(ary, val)
{
	for(i in ary)
	{
		if(ary[i]==val)
		{
			return true;
		}
	}
	return false;
}

function filterTable()
{
	var tbl = $('dataGrid');
	var fUrl = $('filterUrl');
	
	var curUrlIdx = fUrl.options.selectedIndex;
	
	for(i=0; i<tbl.rows.length; i++)
	{
		if(fUrl.options[curUrlIdx].value != 'all')
		{
			if(tbl.rows[i].cells[1].innerHTML.search(fUrl.options[curUrlIdx].value)<0)
				tbl.rows[i].style.display='none';
			else
				tbl.rows[i].style.display='';
		}else
		{
			tbl.rows[i].style.display='';
		}
	}
}


function onConfig(frm)
{
	if(frm.tblName.value.replace(/http\:\/\/[a-z0-9_\-\.]+/ig,'')!='')
	{
		alert('Invalid Site URL!');
		return false;
	}else
	{
		var c1 = confirm('You are about to add url "'+frm.tblName.value+'"! Is this correct?');
		if(c1)
		return true;
		else
		return false;
	}
}

function $(id)
{
	return document.getElementById(id);
}

window.onload = function()
{
	var del = document.getElementsByTagName('a');
	
	for(i=0; i<del.length; i++)
	{
		if(del[i].innerHTML=='Delete')
		{
			var tUrl = del[i].href;
			del[i].href = '#';
			del[i].onclick = function()
			{
				var c1 = confirm("Are you sure to DELETE this URL? This action cannot be restored!");
				if(c1)
				{
					if(confirm("You are about to DELETE this URL from being tracked and remove its current details completely from database! Click OK to continue."))
					{
						window.location.href = tUrl;
					}
				}
			}
		}
	}
}

function mopyHeader(obj)
{
	var hd = obj.firstChild.tHead;
	hd.style.position = 'relative';
	hd.style.top = obj.scrollTop+'px';
	document.title = obj.scrollTop+'px';
}
