function setupPage()
{
	// Focus on url input in page rank checker
	if ($('pageRankChecker')) {
		$('url').focus();
	}
	
	// Focus on url input in back link checker
	if ($('backlinkChecker')) {
		$('url').focus();
	}
	
	if ($('submitSite')) {
		$('postData-email').focus();
	}
	
	// Copy page rank tool code
	if ($('pageRankTool')) {
		Event.observe('pageRankToolCode', 'click', copyPageRankTool);
	}
	
	// Login button on submit url page
	if ($('submitPageLoginLink')) {
		Event.observe('submitPageLoginLink', 'click', showHideLoginBox);
	}
	
	// Login container on top right containe
	if ($('loginLink')) {
		Event.observe('loginLink', 'click', showHideLoginBox);
	}
}

function showHideLoginBox(e)
{
	e.stop();
	
	if ($('loginBox').style.display != "block") {
		$('loginBox').style.display = "block";
		$('email').focus();
	} else {
		$('loginBox').style.display = "none";
	}
	if ($('welcomeMessage')) {
		$('welcomeMessage').style.display = "none";
	}
	if ($('loginLink')) {
		$('loginLink').blur();
	}
	if ($('submitPageLoginLink')) {
		$('submitPageLoginLink').blur();
	}
}

function copyPageRankTool()
{
	var textboxName = eval("document." + "pageRankToolForm.pageRankToolCode");
	textboxName.select();
	
	if (document.all && textboxName.createTextRange) {
		textCaption = textboxName.createTextRange()
		
		if (textCaption.execCommand) {
			textCaption.execCommand("Copy");
		} else {
			return;
		}
	}
}

function openComment(id, type)
{
	$(type + 'Link' + id).blur();
	$('reviewContainer' + id).style.display = "none";
	$('writeReviewContainer' + id).style.display = "none";
	$('voteContainer' + id).style.display = "none";
	
	$(type + 'Container' + id).style.display = "block";
	
	return false;
}

function closeComment(id, type)
{
	$(type + 'Container' + id).style.display = "none";
	
	return false;
}

function disableSubmitButton(submitButton)
{
	$(submitButton).innerHTML = '<img src="/images/loader/tiny_spinner.gif" alt="loading..." height="16" width="16" />';
}

function openAllUrls(urls)
{
    var urlsTotal = urls.length;
    var url = '';
    for (var i = 0; i < urlsTotal; i++){
        url = urls[i];
        if(urlsTotal){
            if (url.substr(0,7) != 'http://') {
                url = 'http://' + url;
            }
            window.open(url);
        }
    }
    return false;
}

function inputToArray(field, separator)
{
    var textInput      = (document.getElementById(field).value).split(separator);
    var textInputTotal = textInput.length;
    var textArray      = new Array();

    for (var i = 0; i < textInputTotal; i++){
    	textArray.push(textInput[i]);
    }
    return textArray;
}

Event.observe(window, 'load', setupPage);