/**
 * Lookup (for jQuery)
 *
 * version: 1.0 (4/6/2009)
 * @requires jQuery v1.3 or later
 * @copyright EasyDNS Technologies Inc.
 *
 */

var FLAG_NOT_REGISTERED = false;

function Lookup() {
	this.MY_NAME = 'Lookup';
	this.pending = new Bucket();
	this.item = null;
	this.xmlobj = null;
	this.is_transfer = 'no';
	this.must_exist = 'no';
	this.add = Lookup__add;
	this.start = Lookup__start;
	this.stop = Lookup__stop;
	this.done = Lookup__done;
	this.next = Lookup__next;
	this.process = Lookup__process;
};

function Lookup__add(domain, callback) {
	if(this.pending.locked) {
		return false;
	}

	return this.pending.add(new LookupItem(domain, callback));
};

function Lookup__start() {
	if(this.pending.locked) {
		return false;
	}

	if(this.pending.empty()) {
		return false;
	}

	FLAG_NOT_REGISTERED = false;
	this.pending.locked = true;
	return this.next();
};

function Lookup__stop() {};

function Lookup__done() {
	if(this.pending.locked && this.pending.empty()) {
		this.pending.locked = false;
		return true;
	}

	if(this.pending.locked) {
	return false;
	}
	return true;
};

function Lookup__next() {
	var item = false;
	var obj = null;
	var transfer = 'no';
	var must_exist = 'no';
	try {
	if(!this.pending.locked) {
		return false;
	}

	if(this.pending.empty()) {
		this.pending.locked = false;
		return false;
	}

	this.item = this.pending.next();
	if(this.item == null) {
		this.pending.locked = false;
		return false;
	}

	if(this.is_transfer === true || this.is_transfer == 'yes') {
		transfer = 'yes';
	}

	if(this.must_exist === true || this.must_exist == 'yes') {
		must_exist = 'yes';
	}

	var packet = new AjaxPacket('Whois', new Array('domain', this.item.domain, 'transfer', transfer, 'must_exist', must_exist, 'tld', $('#tld').val()));
	this.xmlobj = AJAX.send(packet, this.item.callback);
	sendInfo('lookup', this.item.domain);
	}
	 catch(e) {
	return false;
	}
};

function Lookup__process(doc) {
	var domain, status, brief;
	try {
		var result = AJAX.handleResponse(doc);
		if(!result) {
		return false;
		}

		domain = AJAX.full;
		status = AJAX.status;
		brief = AJAX.brief;
		if(status == 'OK') {
		}
		 else {
		if(brief == 'NOT REGISTERED') {
		FLAG_NOT_REGISTERED = true;
		}

		}

		this.next();
	} catch(e) {
	return false;
	}
};

function LookupItem(domain, callback) {
	this.domain = domain;
	this.callback = callback;
};
