function clickclear(thisfield, defaulttext)
{
	if (thisfield.value == defaulttext)
	{
		thisfield.value = "";
	}
}

function clickrecall(thisfield, defaulttext) {
	if (thisfield.value == '')
	{
		thisfield.value = defaulttext;
	}
}

function display_date(today)
{
    var monthName = new Array();
    monthName[0]  = "Jan";
    monthName[1]  = "Feb";
    monthName[2]  = "Mar";
    monthName[3]  = "Apr";
    monthName[4]  = "May";
    monthName[5]  = "Jun";
    monthName[6]  = "Jul";
    monthName[7]  = "Aug";
    monthName[8]  = "Sep";
    monthName[9]  = "Oct";
    monthName[10] = "Nov";
    monthName[11] = "Dec";

    var dayNum = today.getDate();
    var year   = today.getYear();
    
    if (year > 2000) year -= 2000;

    if (year > 100) year -= 100;
    if (year < 10) year = "0" + year;

    // Display date.
    //
    return dayNum + "" + monthName[today.getMonth()] + year;

}

// tools for AJAX
function print_update(obj,expireTime , domain)
{
	if (expireTime >0)
	{
		var myDate = new Date( expireTime *1000);
		obj.innerHTML ="<a href=\"javascript:;\" onmouseover=\"menuLayers.show('cellmenu', event, '"+domain+"')\" onmouseout=\"menuLayers.hide()\">Taken ["+display_date(myDate)+"]</a>";
		obj.className="registereddomain";
	}
	else if (expireTime ==-1)  // available
	{
		obj.className="availabledomain";
		obj.innerHTML ="<a href='submit.php?domain="+domain+"&action=add' target=_blank onmouseover=\"menuLayers.show('cellavailmenu', event, '"+domain+"')\" onmouseout=\"menuLayers.hide()\">Available</a>";
	}
	else if (expireTime ==-9) // refused
	{
		obj.innerHTML ="Refused";
	}
	else  // registered but don't know expiry date
	{

		obj.innerHTML ="<a href=\"javascript:;\" onmouseover=\"menuLayers.show('cellmenu', event, '"+domain+"')\" onmouseout=\"menuLayers.hide()\">Taken</a>";
		obj.className="registereddomain";
	}

}

var xmlhttp = new Array();
var pos=0;


function update_cell(y, domain)
{
	var i=pos;

	var pt=document.getElementById('pt').value;
	obj = document.getElementById(y+"-"+domain);

		if( !window.XMLHttpRequest ) XMLHttpRequest = function(){
	        try{ return new ActiveXObject("MSXML3.XMLHTTP") }catch(e){}
	        try{ return new ActiveXObject("MSXML2.XMLHTTP.3.0") }catch(e){}
	        try{ return new ActiveXObject("Msxml2.XMLHTTP") }catch(e){}
	        try{ return new ActiveXObject("Microsoft.XMLHTTP") }catch(e){}
	        throw new Error("Could not find an XMLHttpRequest alternative.")
	};

	xmlhttp[i] =new XMLHttpRequest();
	xmlhttp[i].open("GET", "cell.php?domain="+domain+"&pt="+pt);
	xmlhttp[i].onreadystatechange = function()
	{

		obj = document.getElementById(y+"-"+domain);
		if (xmlhttp[i].readyState == 4 && xmlhttp[i].status == 200)
		{
			print_update(obj, xmlhttp[i].responseText, domain);
		}
		else if (xmlhttp[i].readyState == 1)
		{
			obj.innerHTML = "Checking ..";
		}
		else if (xmlhttp[i].readyState == 2)
		{
			obj.innerHTML = "Checking (state2)";
		}
		else if (xmlhttp[i].readyState == 3)
		{
			obj.innerHTML = "Checking (state3)";
		}
		else if (xmlhttp[i].readyState == 4)
		{
			obj.innerHTML = "Checking (" + xmlhttp[i].status  + ")";
		}
		else
		{
			obj.innerHTML = "err="+xmlhttp[i].readyState;
		}
	}
	xmlhttp[i].send(null);
	pos++;
}


function go(value) {
	//var obj = document.getElementById("celldomain");
	//var obj=document.getElementById('visitsite').innerHTML;
	var domain=document.celldomain.domain.value;
//	var pos=domain.indexof(".");
//	if (pos==-1)
//		pos=strlen(domain);
//	var d=substr(domain, 0, pos);
	var d=domain.replace(/\..*$/, "");
//	alert("d is "+d);
	//var domain=document.getElementById('celldomain').innerHTML;

	//alert("goto "+value+ " -> "+obj.innerHTML);

	switch(value)
	{
		case 'visit':
			var url="http://www."+ domain;
			//alert("site:"+url);
			document.location=url;
			break;
		case 'whois':
			url="http://domaintools.com/whois.php?domain="+domain;
			//alert("whois:"+url);
			document.location=url;
			break;
		case 'backorder':
			url="http://www.domaintools.com/backorder.php?domain="+domain;
			//alert("whois:"+url);
			document.location=url;
			break;
		case 'buy':
			url="submit.php?domain="+domain+"&action=add";
			//alert("whois:"+url);
			break;
		case 'addfavourite':
			url="submit.php?domain="+domain+"&action=favouriteonly";
			//alert("whois:"+url);
			document.location=url;
			break;
		case 'typo':
			url="domain-name-typos.php?domain="+d;
			document.location=url;
			break;
		case 'mangle':
			url="domain-name-mangle.php?domain="+d;
			document.location=url;
			break;
		case 'business':
			url="business-domain-names.php?domain="+d;
			document.location=url;
			break;
		case 'premium':
			url="premium-domain-names.php?domain="+d;
			document.location=url;
			break;
		case 'cool':
			url="cool-domain-names.php?domain="+d;
			document.location=url;
			break;
		default:
			alert("no option selected :"+value);
	}
}

function setmenu(value)
{
	document.celldomain.domain.value=value;

	document.getElementById('visitsite').innerHTML ="<a href=\"http://www."+value+"\" target=_blank>Visit www."+value+"</a>";
	document.getElementById('whois').innerHTML="<a href=\"http://whois.domaintools.com/"+value+"\" target=_blank>Whois "+value+"</a>";

	document.getElementById('buy').innerHTML="<a href=\"http://www.domainnamesoup.com/submit.php?domain="+value+"&action=buy\" target=_blank>Buy "+value+" from domainnamesoup</a>";
	document.getElementById('buygodaddy').innerHTML="<a href=\"http://www.domainnamesoup.com/submit.php?domain="+value+"&action=add\" target=_blank>Buy "+value+" from recommended reseller</a>";
	document.getElementById('addfavourite').innerHTML="<a href=\"http://www.domainnamesoup.com/submit.php?domain="+value+"&action=favouriteonly\" target=_blank>Add to favourites</a>";

}


function bookmarksite(title,url)
{
	if (window.sidebar) // firefox
		window.sidebar.addPanel(title, url, "");
	else if(window.opera && window.print)
	{ // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	}
	else if(document.all)// ie
		window.external.AddFavorite(url, title);
}
