//This can prolly be factored out to use a simple url / div replacement ajax call,
//requires httpcall.js
Search = {};
Search.elm = "Search.searchElement";

Search.submitForm = function(id) {
     HttpCall.replaceElement(document.getElementById(id),Search.elm);
}

Search.request = function(url) {
    HttpCall.replaceElement(url,Search.elm);      
}

Search.previous = function() {
	Search.request('search.previous.action');
}

Search.next = function() {
	Search.request('search.next.action');
}

Search.jump = function(page) {
	Search.request('search.page.action?pageNumber=' + page);
}

Search.showSearch = function(e) {
    showBlock('searchPopup');
    if (!e) var e = window.event;
    e.cancelBubble = true;
    if (e.stopPropagation) e.stopPropagation();
}

var storeJob = function(id) {
    document.getElementById('successRedirectLogin').value = 'rw.user.addjob.action?article.rootArticleId='+id;
    document.getElementById('article.rootArticleId').value = id;
    document.getElementById('storeJobForm').submit();
};

var setSearchPref = function(jobsPerPage) {
    if (jobsPerPage) document.getElementById('prefResultsPerPage').value = jobsPerPage;
    document.getElementById('prefForm').submit();
};

var emailFriend = function(url) {
    document.getElementById('emailFriendForm').action = url;
    document.getElementById('emailFriendForm').submit();
};

var getEmailAFriendErrorRedirect = 'include/sendtoafriend.jsp';
var getEmailAFriendSuccessRedirect = 'include/sendtoafriend.jsp';
var getEmailAFriendId = null;
var getEmailAFriendType = null;

var emailAFriendComplete = function() {
    if (HttpCall.http.responseText.indexOf('Email sent',0) > -1) {
        document.getElementById('sendtofriend-'+getEmailAFriendId).innerHTML = '';
    } else {
        document.getElementById('sendtofriend-'+getEmailAFriendId).innerHTML = HttpCall.http.responseText;
        document.getElementById('email.form').onsubmit = emailAFriendSubmit;
    }
}

var emailAFriendSubmit = function() {
    Validate.alertImmeadiatly = true;
    if (Validate.validateForm(document.getElementById('email.form'))) {
        HttpCall.call(document.getElementById('email.form'),emailAFriendComplete);
    }
    return false;
}

var getEmailAFriendFormComplete = function() {
    document.getElementById('sendtofriendloader-'+getEmailAFriendId).style.display = 'none';
    document.getElementById('sendtofriend-'+getEmailAFriendId).innerHTML = HttpCall.http.responseText;
    document.getElementById('emailfriend-success').value = getEmailAFriendSuccessRedirect;
    document.getElementById('emailfriend-error').value = getEmailAFriendErrorRedirect;
    document.getElementById('emailfriend-id').value = getEmailAFriendId;
    document.getElementById('emailfriend-type').value = getEmailAFriendType;
    document.getElementById('sendtoafriendArea').style.display = 'block';
    document.getElementById('email.form').onsubmit = emailAFriendSubmit;
}

var getEmailAFriendForm = function(id, type) {
    document.getElementById('sendtofriendloader-'+id).style.display = 'block';
    if (document.getElementById('sendtoafriendArea')) document.getElementById('sendtoafriendArea').parentNode.removeChild(document.getElementById('sendtoafriendArea'));
    getEmailAFriendId = id;
    getEmailAFriendType = type;
    HttpCall.call('include/sendtoafriend.jsp',getEmailAFriendFormComplete);
}




