var folio_image_up = false;
var in_more_view = false;

function changeFolioImage(img)
{
	$('image').src = img;
	return false;
}
function initFolioView()
{
	
	Event.observe(window.document, 'mousemove', function(event) {
	
		if (Position.within($('product-img-box'), event.pageX, event.pageY) && !in_more_view)
		{
			in_more_view = true;
			new Effect.Move('more-views', {
				x: 0, y: -55, mode: 'absolute',
				transition: Effect.Transitions.sinoidal,
				duration:0.3
			});		
		} else
		{
			if (!Position.within($('product-img-box'), event.pageX, event.pageY) && in_more_view)
			{
			in_more_view = false;
			new Effect.Move('more-views', {
				  x: 0, y: 0, mode: 'absolute',
				  transition: Effect.Transitions.sinoidal,
				  duration:0.3
				});
			}
		}

	});

	
	
	
	
}


Validation.add('domain-taken', 'This domain name has been taken!', function(value ,el) {
	return input_domain_taken !== true; 
});

Validation.add('validate-domain', 'Please enter a valid domain name. For example example.com or newdomain.org', function (v) {
    return Validation.get('IsEmpty').test(v) || /^([a-z0-9-_]+\.)+[a-z]{2,3}$/i.test(v)
});

var input_correct_domain = false;
var test = false;
var request_url = "http://www.bustaname.com:9091/?word=domain_search&search_type=4&taken=1&tlds=com%2Cnet%2Corg%2Cinfo%2Cbiz&position=start&length=15&page=1";

var ajax_reqesting = false;
var ajax_request = false;

function JSONscriptRequest(fullUrl) {
    this.fullUrl = fullUrl; 
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    this.headLoc = document.getElementsByTagName("head").item(0);
    this.scriptId = 'JscriptId' + JSONscriptRequest.scriptCounter++;
}

JSONscriptRequest.scriptCounter = 1;

JSONscriptRequest.prototype.buildScriptTag = function () {

    this.scriptObj = document.createElement("script");
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("charset", "utf-8");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}

JSONscriptRequest.prototype.removeScriptTag = function () {
    this.headLoc.removeChild(this.scriptObj);  
}


JSONscriptRequest.prototype.addScriptTag = function () {
    this.headLoc.appendChild(this.scriptObj);
}


var bObj = false;
var domain_text_el = false;
var just_pick = false;
function initDomainSuggestor(el_id)
{
	domain_text_el = el_id;
	$(el_id).addClassName('validate-domainname');
	$(el_id).addClassName('validate-domain');
	
	$(el_id).observe('keyup',function(){
		if (this.value != '')
		{
			bObj = new JSONscriptRequest(request_url.replace('domain_search',this.value)); 
			bObj.buildScriptTag(); 
			bObj.addScriptTag();
		}
	});
	$(el_id).observe('blur',function(){
		if (!just_pick)
		{
			$('wmResults').fade();
		}
		just_pick = true;
	});
	
}

function selectDomain(domain)
{
	$(domain_text_el).value = domain;
	$('wmResults').fade();
	just_pick = true;
	return false;
}



var WordMaker = {results:function(data){
	
	var html_rows = '';
	
	if (data.data.length > 0)
	{
	data.data.each(function(row){
		domain_name = row.url.replace('<u>','').replace('</u>','');
		html_rows += '<tr class="row"><td class="madeWord">'+row.url+'</td>';
		
		if (row.com)
		{
			html_rows += '<td class="wmResult wmAvailable wmResColAvailable" onclick="return selectDomain(\''+domain_name+'.com\');">com</td>';
		} else
		{
			html_rows += '<td class="wmResult wmResCol">com</td>';
		}
		
		if (row.net)
		{
			html_rows += '<td class="wmResult wmAvailable wmResColAvailable" onclick="return selectDomain(\''+domain_name+'.net\');" >net</td>';
		}else
		{
			html_rows += '<td class="wmResult wmResCol">net</td>';			
		}
		
		if (row.org)
		{
			html_rows += '<td class="wmResult wmAvailable wmResColAvailable" onclick="return selectDomain(\''+domain_name+'.org\');">org</td>';	
		}
		else
		{
			html_rows += '<td class="wmResult wmResCol">org</td>';			
		}
		
		if (row.info)
		{
			html_rows += '<td class="wmResult wmAvailable wmResColAvailable" onclick="return selectDomain(\''+domain_name+'.info\');">info</td>';	
		}
		else
		{
			html_rows += '<td class="wmResult wmResCol">info</td>';			
		}
		
		if (row.biz)
		{
			html_rows += '<td class="wmResult wmAvailable wmResColAvailable" onclick="return selectDomain(\''+domain_name+'.biz\');">biz</td></tr>';	
		}
		else
		{
			html_rows += '<td class="wmResult wmResCol">biz</td>';
		}
				
	});
	
	$$('#wmResults table').first().innerHTML = html_rows;
	
	$('wmResults').show();
	
	}
	
	
	bObj.removeScriptTag(); 
}};


function personalWebsiteHideAll()
{
	$$('.options_10').each(function(el){
		el.hide();		
	});
	
	$$('.options_9').each(function(el){
		el.hide();		
	});
	
	$$('.options_8').each(function(el){
		el.hide();		
	});

}

function personalWebsiteInit()
{

	$('wmResults').hide();
	
	personalWebsiteHideAll();
	initDomainSuggestor('options_10_text');
	$('select_11').observe('change',function(e){
		
		personalWebsiteHideAll();

		if (this.value == 18)
		{
			$$('.options_9').each(function(el){
				el.show();		
			});
			
			
		}
		
		if (this.value == 19)
		{
			$$('.options_10').each(function(el){
				el.show();		
			});
			
			$$('.options_8').each(function(el){
				el.show();		
			});
			
			
		}
		
	});

}

