// this file is used to reduce size of html on page

// functions used ViewJob page Start
function showAllJobsForCompanyProfileID(companyProfileId, blnCurrentWindow) {
	companyProfileId = parseInt(companyProfileId);
	if(isNaN(companyProfileId) || companyProfileId <= 0)
	    return false;
	if(blnCurrentWindow == null)
	    blnCurrentWindow = false;
	
	var url = "/JobSeekerX/SearchJobs.asp?Jobs_CompanyProfileID=" + companyProfileId;
	
	var strUpperCaseURL = new String(window.location).toUpperCase();   // Current url	
	if (strUpperCaseURL.indexOf("VIEWJOBRSS.ASP") != -1) {
		blnCurrentWindow = true;
	}
	if (strUpperCaseURL.indexOf("VIEWCOMPANYPROFILE.ASP") != -1) {
	    blnCurrentWindow = true;
	}
	
    if (top.opener == null || blnCurrentWindow){
	    // use current window
	    window.location = url;
    }
    else{
	    // use parent
	    url = "http://" + top.opener.location.hostname + url;
	    top.opener.location = url;
	    top.opener.focus();
    }
}

function addJobToInboxForUserId(userId,jobId) {
    if(userId == null || Trim(userId) == "" || jobId == null || Trim(jobId) == "")
        return false;
    
    if (isUserLoggedIn()) {		
	    // user is logged in
	    PopupViewWindow('/JobSeeker/AddJobToInbox.asp?UserID=' + userId + '&JobID=' + jobId, 'AddToInboxWindow', 490, 510);
    }
    else {
	    // user is not logged in
	    PopupViewWindow('/FormsLogin.asp?/JobSeeker/AddJobToInbox.asp?UserID=' + userId + '&JobID=' + jobId + '&i=0', 'AddToInboxWindow', 530, 260);
    }
}

function sendJobToFriend(eJobId) {
    if(eJobId == null || Trim(eJobId) == "")
        return false;
    PopupViewWindow('/JobSeekerX/SendJobForm.asp?JobID=' + eJobId, 'SendJobWindow', 530, 420 );
}

function applyToNonRedirectJob(jobId) {
    if(jobId == null || Trim(jobId) == "")
        return false;
    
    PopupViewWindow('/JobSeekerX/ApplyToJobSwitchForm.asp?JobID=' + jobId, 'applytojobwindow', 530, 640);
    CloseCurrentWindow();
}
// functions used ViewJob page End

// functions used SearchJobs page Start
function AddSelectedJobsToInbox(userId){
	if(userId == null || Trim(userId) == ""){ // to avoid this alert - use PROXY_JOB_SEEKER
        alert("Please specify inbox owner");
        return false;
    }
    var strJobIDs = getSelectedJobIDs();
    if(strJobIDs == ""){
        alert("Please select at least one job.");
        return false;
    }
    
    var numWidth = (!isUserLoggedIn()) ? 530 : 330;
    var numHeight = (!isUserLoggedIn()) ? 260 : 150;
    
	var url = "/JobSeekerX/AddJobToInboxRedirect.asp?" + "UserID=" + userId + "&" + strJobIDs;
	
	PopupViewWindow(url, "AddToInboxWindow", numWidth, numHeight);
}

function getSelectedJobIDs() {
    var strResult = "";
    var j = 0;
    var objCheckBoxArray = document.getElementsByTagName('input');
    for (var i = 0; i < objCheckBoxArray.length; i++) {
        if (objCheckBoxArray[i].type == "checkbox" && objCheckBoxArray[i].name.substr(0, 5) == "JobID") {
            if (objCheckBoxArray[i].checked) {
                j++;
                strResult += (j == 1 ? "JobID=" : "&JobID=") + objCheckBoxArray[i].value;
            }
        }
    }
    return strResult;
}

function AddJobToInbox(jobId,userId){
    if(Trim(jobId) == "" || jobId == null || userId == null || Trim(userId) == ""){
        return false;
    }
    
    var numWidth = (!isUserLoggedIn()) ? 530 : 330;
    var numHeight = (!isUserLoggedIn()) ? 260 : 150;
    
    PopupViewWindow("/JobSeekerX/AddJobToInboxRedirect.asp?UserID=" + userId + "&JobID=" + jobId, "AddToInboxWindow", numWidth, numHeight);
}
// functions used SearchJobs page End


// functions used on SearchJobsFormMainShort page
function setDefaultFieldValue(fieldId, defaultValue) {
    var Field = document.getElementById(fieldId);
    
    if(Field == null)
        return false;
    
    if(Trim(defaultValue) == ""){
        Field.value = "";
        return true;
    }
    
    Field.style.color = "#969595";
    Field.value = defaultValue;
    
    Field.onclick = function() { if (Field.value == defaultValue) { Field.value = ''; Field.style.color = "#000"; } };
    Field.onblur = function() { if (Field.value == '') { Field.value = defaultValue; Field.style.color = "#969595"; } };
    
    return true;
}

function resetDefaultFieldValue(fieldId, defaultValue) {
    var Field = document.getElementById(fieldId);
    
    if(Field == null)
        return false;
    
    if(Trim(defaultValue) == ""){
        Field.value = "";
        return true;
    }
    
    if(Field.value == defaultValue)
        Field.value = "";
    
    Field.onclick = function() {};
    Field.onblur = function() {};
    
    Field.style.color = "#000";
}

function submitToChangeJobSearchProfile() {
    
	with (document.QuickSearchFormWithProfile){
	    if (JobSearchProfileName.value == ''){
		    alert('Please enter a Saved Search Name.');
		    JobSearchProfileName.focus();
		    return false;
	    }
	}
	
	document.QuickSearchFormWithProfile.action = "/JobSeeker/ChangeJobSearchProfile.asp";
	document.QuickSearchFormWithProfile.submit();
}
// functions used on SearchJobsFormMainShort page End
