// this file is used to reduce size of html on page

/*********************************************************************
'***    Function:  setDefaultFieldValue - sets to field default alt text which disappears onclick, onblur
'***
'***    Parameters: 
'***		fieldId - id of the field to which needs apply
'***        defaultText - default text which is set when field.value is empty
'***        defaultEmptyText - (if not empty) this text will be set as default (non empty value)
'***        withDefaultClassName - when field is empty text color changes to gray (to be not very attractive) (default class input[type="text"].defaultAltText)
'***        withoutDefaultClassName - when field is not empty changes class back (by default non)
'***
'***	Return: void
'***
'***    Remarks: usually used for input[type='text'].
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 03/08/2010
'*********************************************************************/	
function setDefaultFieldValue(fieldId, defaultText, defaultEmptyText, withDefaultClassName, withoutDefaultClassName) {
    var Field = document.getElementById(fieldId);
    
    if(Field == null)
        return;
    if(Trim(defaultText) == ""){
        Field.value = "";
        return;
    }
    if(defaultEmptyText == null || Trim(defaultEmptyText) == ""){
        defaultEmptyText = defaultText;
    }
    if(withDefaultClassName == "" || withDefaultClassName == null)
        withDefaultClassName = "defaultAltText";
    if(withoutDefaultClassName == null)
        withoutDefaultClassName = "";
    
    if(defaultEmptyText != defaultText)
        withDefaultClassName = withoutDefaultClassName;
    
    Field.className = withDefaultClassName;
    Field.value = defaultEmptyText;
    
    Field.onclick = function() { if (Field.value == defaultText) { Field.value = ''; Field.className = withoutDefaultClassName; } };
    Field.onblur = function() { if (Field.value == '') { Field.value = defaultEmptyText; Field.className = withDefaultClassName; } };
}
/*********************************************************************
'***    Function:  clearDefaultFieldValue - clears default value (and onclick, onblur fns) which were set with setDefaultFieldValue fn
'***
'***    Parameters: 
'***		fieldId - id of the field to which needs apply
'***        defaultText - default text which is set when field.value is empty
'***        withoutDefaultClassName - when field is not empty changes class back (by default non)
'***
'***	Return: void
'***
'***    Remarks: usually used for input[type='text'] and set at the top of validateForm function
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 03/08/2010
'*********************************************************************/	
function clearDefaultFieldValue(fieldId, defaultText, withoutDefaultClassName) {
    var Field = document.getElementById(fieldId);
    
    if(Field == null)
        return;
    if(Trim(defaultText) == ""){
        Field.value = "";
        return;
    }
    if(Field.value == defaultText)
        Field.value = "";
    if(withoutDefaultClassName == null)
        withoutDefaultClassName = "";
    
    Field.onclick = function() {};
    Field.onblur = function() {};
    Field.className = withoutDefaultClassName;
}
/* returns a url delim list of selected job ids */
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;
}

// ********* SearchJobs page scripts
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;
    }
	document.location.href = "/JobSeekerX/AddJobToInboxRedirect.asp?" + "UserID=" + userId + "&" + strJobIDs;
}

// ********* end SearchJobs page scripts

// ********* SearchJobsFormMainShort page scripts
function submitToChangeJobSearchProfile(formId) {
    if (document.getElementById("QuickSearchFormWithProfile").value == ''){
	    alert('Please enter a Saved Search Name.');
	    JobSearchProfileName.focus();
	    return;
    }
	
	objForm = document.getElementById(formId);
	if(objForm == null) return;
	objForm.action = "/JobSeeker/ChangeJobSearchProfile.asp";
	objForm.submit();
}
// ********* end SearchJobsFormMainShort page scripts
