// this file is used to reduce size of html on page

// place for this fn empty id at the page 'BackStageJsLoginPage' with value
function SmartPopupViewWindow(strURL, strWindow, nWidth, nHeight, strToolbar, strStatus, strLocation, strDirectories, strMenubar){
	var blnUserLoggedIn = isUserLoggedIn();
	
	var numWidthDefault = (!blnUserLoggedIn) ? 530 : 400;
    var numHeightDefault = (!blnUserLoggedIn) ? 260 : 150;
	nWidth = (nWidth == null || nWidth == "") ? numWidthDefault : nWidth;
	nHeight = (nHeight == null || nHeight == "") ? numHeightDefault : nHeight;
	
	if (blnUserLoggedIn) {
		return PopupViewWindow(strURL, strWindow, nWidth, nHeight, strToolbar, strStatus, strLocation, strDirectories, strMenubar);
	}
	else {
		// redirect
		var jsLoginPage = document.getElementById("BackStageJsLoginPage").innerHTML;
		return RedirectToURL(jsLoginPage + "?se_redirect=http://casting.backstage.com" + strURL + "&s=1");
	}
}
/*********************************************************************
'***    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;
}

function unselectListBoxItems(listId){
	var objList = document.getElementById(listId);
	if(objList == null)
	    return;
	for (var i=0; i < objList.length; i++) {
		// this item needs to unselect
		objList.options[i].selected = false;
	}
	return;
}


// ********************* functions used on 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 casting notice.");
        return false;
    }
	
	SmartPopupViewWindow("/JobSeekerX/AddJobToInboxRedirect.asp?UserID=" + userId + "&" + strJobIDs, "AddToInboxWindow");
}

/* 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;
}

function AddJobToInbox(jobId,userId){
    if(userId == null || Trim(userId) == ""){ // to avoid this alert - use PROXY_JOB_SEEKER
        alert("Please specify inbox owner");
        return false;
    }
    if(Trim(jobId) == "" || jobId == null){
        return false;
    }
    
    SmartPopupViewWindow("/JobSeekerX/AddJobToInboxRedirect.asp?UserID=" + userId + "&JobID=" + jobId, "AddToInboxWindow");
}

function ViewJobWithKeywords(encryptedID, keywords, keywordType){
	if(keywords.indexOf("'") >= 0)
		keywords = keywords.replace(/'/g, "");
    
    var link = "/JobSeeker/ViewJob.asp?JobID=" + encodeURIComponent(encryptedID); //URLEncode(encryptedID);
	if(keywordType != 3 && keywords != ""){
		link += "&Keywords=" + escape(keywords);
	}
	
	SmartPopupViewWindow(link, 'ViewJob', 740, 670);
}

// ********************* functions used on SearchJobs page End


// ********************* functions used on SearchJobsFormMainShort, SearchJobsFormAdvanced and SearchJobsFormMain pages
function submitToChangeJobSearchProfile(formId) {
    if(document.getElementById("JobSearchProfileName").value == ''){
        alert('Please enter a Saved Search Name.');
        JobSearchProfileName.focus();
        return;
    }
	var srchForm = document.getElementById(formId);
	if(srchForm == null) return;
	srchForm.action = "/JobSeeker/ChangeJobSearchProfile.asp";
	srchForm.submit();
}
// ********************* functions used on SearchJobsFormMainShort, SearchJobsFormAdvanced and SearchJobsFormMain pages End


// ********************* functions used on SearchJobsForm page
function setCheckboxCustomLocation(){
    var checkBox = document.getElementById("customLocations");
    if(checkBox != null)
        checkBox.checked = true;
}
function unselectCustomLocations(blnChecked){
    if(blnChecked){
        unselectListBoxItems("st"); // USA states
        unselectListBoxItems("prvn"); // Canada provinces
        unselectListBoxItems("cn"); // countries
    }
}
function setCountryValue(currentListBox, countryListBoxId, value){
    countryList = document.getElementById(countryListBoxId);
    if(countryList == null || currentListBox == null)
        return;
    if(getSelectedItemCount(currentListBox) > 0)
        selectListItem(countryList, value);
    else
        unSelectListItem(countryList, value);
}
// ********************* functions used on SearchJobsForm End

