
	function clearResults()
	{
		domains = new Array();
		wordlist = '';
		domGroup = new Array();
		//if (domCheck) domCheck.each(function(dom) {dom=null;} );
		domCheck = new Array();
		domOut = '';
		$(divcontainer).innerHTML = ' Loading... ';
	}
	
	function addDomain(domain)
	{
		domains.push(domain);
	}

	function makeOutput()
	{
		outCnt=0; domOut=''; domGroup=new Array();
		$(divcontainer).innerHTML = '';
		makeGrid();

		domains.each(function(ditem,dindex){
				outCnt++;
				if (domGroup.indexOf(ditem)==-1)
				{
					domGroup.push(ditem);
					if (ditem.search(/\.\.\./)>-1) makeSuggestGrid(ditem);
					else
					{
						makeResultGrid(ditem, 'primary');
						if (outCnt>=200) {outCnt=0; dumpToScr();  }
					}
				}
		}); // end domains
		dumpToScr();
		//updateDom();

		//grab code and place it in bottom of div
		// div name = domain_ext_[primary|secondary|global]
		// url = ax.php?d=domain&t(ype)=[primary|secondary|global]
		//call update new Ajax.update('div','url','loading:{}','loaded:{}');
	}


	function updateDom()
	{
		//transfer doms // make string, //ajax.request(string,type)  //process JSON return (dom{vals},[1,(2,4)5,6]
		domGroupUp = domGroup.slice();
		domGroupList = domGroupUp.join(",");
		domGroup = new Array(); // clear array
		domCheck = new Array();
		dcCnt=0; dcGCnt=0; dcList = new Array(); dcGroup = new Array();
		
		domGroupUp.each(function(dom,domindex)
		{
			if ($(dom+'_p'))
			{
				dcGroup[dcGCnt] = encodeURIComponent(dom); 
				dcGCnt++;
				if (dcGCnt>5)
				{
					dcList[dcCnt] = dcGroup;
					dcGroup = new Array();
					dcGCnt=0;
					dcCnt++;
				}
			}
		});
		if (dcGCnt>0) { dcList[dcCnt] = dcGroup; }
		dcList.each(function(list,lindex)
		{
			listStr = list.join(',');
			new Ajax.Request('./dc.php', { method: 'get',  parameters: 't=p&d='+listStr,  onSuccess: updateDomStatus });
		});
		// ajax : request { domain : type: {P1:P2:S1:S2:G}, domain:{results1|2|4|5|6}, repeat
		//alert(domGroupUp.length);
	}

	function updateDomS(domS)
	{
		$(domS+'_s').innerHTML = ' Loading ... ';
		if (domS != '') new Ajax.Request('./dc.php', { method: 'get',  parameters: 't=s&d='+encodeURIComponent(domS),  onSuccess: updateDomStatus });
	}

	function updateDomStatus(transport)
	{
		//result = P@domain:1,2|domain:1,2
    		if (transport.responseText != '' )
    		{
    			data = transport.responseText.split("@");
    			type = data[0];
    			reslist = data[1].split("|");

    			reslist.each(function(resdata,resindex)
    			{
    				resParts = resdata.split(":");
    				dgitem = resParts[0];
    				
    				if ($(dgitem+'_'+type))
    				{
    					extRes = resParts[1].split(",");
    					if (type=='p') $(dgitem+'_'+type).update(makePrimary(dgitem, extRes));
    					else if (type=='s') $(dgitem+'_'+type).innerHTML = makeSecondary(dgitem, extRes);
    				}
    			});  
    		}
	}
	
	function dumpToScr()
	{
		$(divcontainer).insert(domOut);
		domOut='';
		setTimeout(updateDom, 1000);
	}