/*	keep for code coloring
	<script>
*/
function RedirectToURL(strURL){
	self.location = strURL; 
}

function TargettedSubmit(objForm, objHiddenVarTargetURL, strUrl){
	objHiddenVarTargetURL.value = strUrl;
	objForm.submit();
}

function ValidateAndRedirectToURL(strValidationMessage, strURL){
	if (confirm(strValidationMessage)) {
		RedirectToURL(strURL);
	}
}

function GoBack(intHowFar){
	if (!intHowFar) {
		intHowFar = -1;
	}
	if (intHowFar > 0) {
		intHowFar = -1 * intHowFar
	}
	self.history.go(intHowFar); 
}

function GoForward(intHowFar){
	if (!intHowFar) {
		intHowFar = 1;
	}
	self.history.go(intHowFar); 
}

function CloseCurrentWindow(){
	self.close();
}

function SubmitFormAndCloseCurrentWindow(objForm) {
	objForm.submit();
	CloseCurrentWindow();
}

function CloseCurentWindowAndRefreshParent(strSelectListText, strOriginalParms) {
	if (!self.opener.closed){
		if (strOriginalParms){
			self.opener.location.href = self.opener.location.pathname + strOriginalParms + "&Parm1=" + strSelectListText + '&Time=' + escape(new Date());	
		}
		else{
			self.opener.location.href = self.opener.location.pathname + '?Time=' + escape(new Date()) + "&Parm1=" + strSelectListText;
		}
	}
	CloseCurrentWindow();
}

function refreshParentWindow() {
	if (self.opener) {
		if (!self.opener.closed) {
			var strHREF    = new String(self.opener.location.href);
			var strNewHREF = self.opener.location.href;
				
			if ( strHREF.indexOf("?") > -1 ) {
				strNewHREF += "&";
			}
			else {
				strNewHREF += "?";
			}
			self.opener.location.href = strNewHREF + 'Time=' + escape(new Date());
		}
	}
}

function addQueryStringParam(strQS, strParamName, strParamValue, blnEncodeValue) {
	var strQueryString = new String(strQS);

	if (blnEncodeValue == null) {
		blnEncodeValue = false;
	}
	
	if (strQueryString.indexOf("?") == -1) {
		strQueryString += "?";
	}
	else {
		strQueryString += "&";
	}
	
	strQueryString += strParamName + "=";
	if (blnEncodeValue) {
		strParamValue = escape(strParamValue);
	}
	strQueryString += strParamValue;
	
	return strQueryString;
}

//do not use this function. Use setQueryStringParamV2
function setQueryStringParam(strQS, strParamName, strParamValue, blnEncodeValue) {
	strQS = deleteQueryStringParam(strQS, strParamName);
	strQS = addQueryStringParam(strQS, strParamName, strParamValue, blnEncodeValue);
	return strQS;
}

function setQueryStringParamV2(strQS, strParamName, strParamValue, blnEncodeValue) {
    strQS = deleteQueryStringParamV2(strQS, strParamName);
    strQS = addQueryStringParam(strQS, strParamName, strParamValue, blnEncodeValue);
    return strQS;
}


//do not use this function. Use deleteQueryStringParamV2
function deleteQueryStringParam(strQS, strParamName) {
	var strQueryString = new String(strQS);
	var intParamStart  = 0;
	var intParamEnd    = 0;
	
	//is this parameter in query string?
	if (strQueryString.indexOf(strParamName + "=") > -1) {
		//make sure this is the right parameter, it should be preceded with & or ?
		intParamStart = strQueryString.indexOf("?" + strParamName + "=");
		if (intParamStart == -1) {
			intParamStart = strQueryString.indexOf("&" + strParamName + "=");
		}
		if (intParamStart > -1) {
			//the end of paramname=paramvalue group
			//either followed by & or end of query string
			intParamEnd = strQueryString.indexOf("&",intParamStart + 1);
			
			strQueryString = strQueryString.substring(0,intParamStart);
			if (intParamEnd > -1) {
				strQueryString += strQueryString.substring(intParamEnd);
			}
			
		}
	}
	return strQueryString;
}

function deleteQueryStringParamV2(strQS, strParamName) {

    var strQueryString = new String(strQS);
    var intParamStart = 0;
    var intParamEnd = 0;

    //is this parameter in query string?
    if (strQueryString.indexOf(strParamName + "=") > -1) {

        strQueryString = strQueryString.replace("?", "&");

        //make sure this is the right parameter, it should be preceded with & or ?
        intParamStart = strQueryString.indexOf("&" + strParamName + "=");

        if (intParamStart > -1) {
            //the end of paramname=paramvalue group
            //either followed by & or end of query string
            intParamEnd = strQueryString.indexOf("&", intParamStart + 1);

            strTmpString = strQueryString.substring(intParamStart, intParamEnd);
            if (intParamEnd > -1) {
                var re = new RegExp(strTmpString, "gim");
                strQueryString = strQueryString.replace(re, "");
            }
            else {
                strQueryString = strTmpString;
            }

            if (strQueryString.indexOf("?") == -1)
                strQueryString = strQueryString.replace("&", "?");

        }
    }
    return strQueryString;
}


function setRefresh(strQS) {
	return setQueryStringParamV2(strQS, "Time", new Date(), true);
}


function RedirectParent(strURL){
    var strOriginal = ""
    if (!self.opener.closed){
        if( strURL != "" ){
            self.opener.location = setQueryStringParam(strURL, "Time", new Date(), true);
        } else {
            self.opener.location = setQueryStringParam( self.opener.location.pathname, "Time", new Date(), true);
        }
    }
}

function CloseCurentWindowAndRedirectFromParent(strURL) {
    RedirectParent(strURL);
	CloseCurrentWindow();
}

function FocusParent(){
    if( !self.opener.closed ){
        self.opener.focus();
    }
}

function closeCurrentWindowAndFocusParent(){
    FocusParent();
    CloseCurrentWindow();       
}

/*********************************************************************
'***    Program: PopupWindow( strURL, strWindow, nWidth, nHeight )
'***    Type: Function
'***
'***    Function: Pops up a new window with displaying the URL passed
'***
'***    Parameters: 
			url - url to use for popup
			width  - window width (optional) default = 40% of document client width
			height - window height (optional) default = 60% of document client height
			windowName - name of window to use (optional) default="new"

'***
'***
'***    Returns: window object representing the newly opened window
'***    Remarks: none
'***
'***    Created by: dimab
'***    Changed by: dimab
'***    Last change: 12/14/08
'*********************************************************************/
function PopupWindow( url, width, height, windowName ) {
	var SE_SUPPORTS_POPUPS = true;
	var Popup = null;
	
   //Default Page
	if (windowName == null)
		windowName = "New";

	//Default Width
	if (width == null)
		width =  screen.availWidth * 0.4;

	//Default Height
	if (height == null)
		height = screen.availHeight * 0.6;


	if (SE_SUPPORTS_POPUPS == (true || null || "")){
	 	Popup = window.open( url, windowName,"toolbar=yes,location=no,directories=yes,status=yes,scrollbars=yes,resizable=yes,width="+width.toString()+",height="+height.toString()+ ",menubar=yes");
	 	Popup.focus();
	}
	else {
	     window.location.href = url;
	}
}


/*****************************************************
	job seeker navigation routines.
	purpose: simplify navigation, isolate logic, shorten html
*****************************************************/
function viewJob( id, acct, keywords ) {
	var KeywordPart = "";
	if (keywords != null)
		KeywordPart = "&keywords=" + escape(keywords);
		
	document.location.href="/JobSeekerx/ViewJob.asp?cjid=" + id + "&accountno=" + acct + KeywordPart ;
}
/* same as add to inbox */
function saveJob( id ) {
	document.location.href="/JobSeeker/AddJobToInbox.asp?jobid=" + id;
}
function sendJob( id ) {
	document.location.href="/JobSeekerx/SendJobForm.asp?jobid=" + id;
}

function applyToJob( id ) {
	document.location.href="/JobSeekerX/ApplyToJobSwitchForm.asp?jobid=" + id;
}
function applyToRedirectJob(jobId){
    var strUrl = "/JobSeekerX/ApplyToJobRedirect.asp?JobID=" + jobId;
    window.open(strUrl);
    
    return false;
}
function viewProfile( id ) {
	document.location.href="/JobSeekerx/ViewCompanyProfile.asp?CompanyProfileID=" + id;
}

function formatLocation(locations, city, state, country) {
	if (locations == 0) {
		document.write("-anywhere-");
	} else if (locations > 1) {
		document.write("-multiple-");
	} else {
		document.write(formatLocationPart(city) + formatLocationPart(state) + country);
	}
}
function formatLocationPart( part, separator ) {
	var re = /\s*-\s*/g; // string with just dash is also empty!

	if (separator == null)
		separator = "-";
	if (part == null || part == "" ||part.replace(re, "") == "")
		return "";
	return part + separator;
}

/*********************************************************************
'***    Function: formatTitle
'***
'***    Parameters: 
        value, text to format
        length - size to conform text 
'***
'***    Returns: void
'***    Remarks: - reformats text to specified length
'***
'***    Created by: niloa
'***    Changed by: 
'***    Last change: 04/01/2009
'*********************************************************************/
function formatTitle(value, length) {
    value = String((value == null) ? "" : value);

    //if no length not specified, print entire length
    if (length == null)
        length = value.length;
    
    //if size is > than val.length, resize text
    if ((length != null) && (value.length > length))
        value = value.slice(0, length) + "...";

    document.write(value);
}
/*********************************************************************
'***    Function: formatPhoneNumber
'***
'***    Parameters: 
'***        strValue - phone number string to format
'***                
'***    Returns: string
'***    Remarks: 
'***        1. replaces non phone number values with ""
'***        2. considers phone number extensions
'***        3. returns a formatted phone number
'***
'***    Created by: internet source
'***    Changed by: niloa
'***    Last change: 04/08/2010
'*********************************************************************/
function formatPhoneNumber(strValue) {
    var phone = new String(Trim(strValue))
    if (phone.length == 0)
        return "";

    //replace noise chars
    phone = phone.replace(/[^0-9xX]/g, "");

    //use one simple char as extension marker
    phone = phone.replace(/[xX]/g, "x");

    var ext = "";

    //get the position of where extension starts
    var ixExt = phone.indexOf("x");
    if (ixExt != -1) {
        ext = " " + phone.substr(ixExt);
        phone = phone.substr(0, ixExt);
    }

    //get total characters in phone numbers
    var intNumbersLength = phone.length;

    //return extension only if no numbers
    if (intNumbersLength == 0)
        return ext;

    switch (intNumbersLength) {
        case 10:
            strValue = phone.replace(/(\d{3})(\d{3})(\d{4})/g, "($1) $2-$3");
            strValue += ext;
            break;
        case 11:
            if (phone.substr(0, 1) == "1") {
                strValue = phone.substr(1);
                strValue = strValue.replace(/(\d{3})(\d{3})(\d{4})/g, "($1) $2-$3");
                strValue += ext;
            }
            break;
        default:
            strValue = ""; //phone;
            break;
    }

    return strValue;
}

// scrolls to top of page where contentContainer tag exists
function toTop() {
	var content = document.getElementById( "contentContainer" );
	if (content != null)
		content.scrollIntoView();
}

// scrolls to the specified id without causing page to scroll out of view
function scrollTo( id, alignToTop ) {
	if (alignToTop == null)
		alignToTop = false;
		
	var elem = document.getElementById( id );
	if (elem != null)
		elem.scrollIntoView(alignToTop);
}


/*********************************************************************
***	Function: configures back button on pages of type Article
***	
***	Parameters: none
***	
***
***	Remarks: none
***
***	Created by: dimab
***	Modified by: sergeyh
***	Last modified: 06/23/2011
***
*********************************************************************/
function configureBackButton(buttonId, buttonBackValue, fnBack){
	if (buttonId == null)
		buttonId = "Back";
	
    buttonBackValue = (buttonBackValue == "" || buttonBackValue == null) ? "Back" : buttonBackValue;
	var btn = document.getElementById(buttonId);
	if (btn != null) {
		if (history.length > getHistoryObjectArrayBase()) {
		    btn.value = buttonBackValue;
		    if (typeof (fnBack) != "function")
		        fnBack = function() { history.back(); };
		    btn.onclick = fnBack;
		}
		else {
			btn.value = "Close";
			btn.onclick = function() {window.close();}
		}
	}
}

/*********************************************************************
***	Function: needs to configure back button
***    returns 0/1 - for different browsers history starts from 0 or 1
***	
***	Parameters: none
***	
***
***	Remarks: 
***
***	Created by: sergeyh
***	Modified by: sergeyh
***	Last modified: 04/16/2009
***
*********************************************************************/
function getHistoryObjectArrayBase () {
    var strUserAgent = DetectUserAgent(); // getting string value of UserAgent
    var strGeckoBasedUA = "chrome firefox safari"; // Gecko based browsers
    intHistoryStart = 0; // other browsers starts history from 0
    
    isGecko = (strGeckoBasedUA.indexOf(strUserAgent) != -1);
    
    if ( isGecko ) {
        intHistoryStart = 1;
    }
    
    return intHistoryStart;
}

/*********************************************************************
***	Function: detects User Agent Name (needs to configure some scripts)
***
***	
***	Parameters: none
***	
***
***	Remarks: 
***
***	Created by: sergeyh
***	Modified by: sergeyh
***	Last modified: 04/16/2009
***
*********************************************************************/
function DetectUserAgent() {
    var strUserAgent = navigator.userAgent.toLowerCase();

    if (strUserAgent.indexOf("msie") >= 0) return "explorer";
    if (strUserAgent.indexOf("opera") >= 0) return "opera";
    if (strUserAgent.indexOf("firefox") >= 0) return "firefox";
    if (strUserAgent.indexOf("safari") >= 0) return "safari";
    if (strUserAgent.indexOf("chrome") >= 0) return "chrome";
    if (strUserAgent.indexOf("konqueror") >= 0) return "konqueror";

    return "somethingElse";
}

/*********************************************************************
***	Job Search agent navigation functions
***
***	Created by: dimab
***	Modified by: dimab
***	Last modified: 2/1/2009
***
*********************************************************************/
function deleteJobAgent( id ) {
	// use dhtml dialog component
	pageDialog.message = 'Are you sure you want to delete this job search agent?';
	pageDialog.title   = "Confirm delete operation";
	pageDialog.onOk = function () {document.location.href = "/JobSeeker/ChangeJobSearchProfile.asp?agent=Full&actn=DELETE&UserAgentID=" + id};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}
// works with both expired and non expired agents
function extendJobAgentExpiration( id, isExpired ) {
	var message = 'Are you sure you want to deactivate this job search agent?';
	var title = 'Confirm deactivate operation';
	if (isExpired) {
		message = 'Are you sure you want to extend expiration date and activate this job search agent?';
		title   = 'Confirm extend operation';
	}

	// use dhtml dialog component
	pageDialog.message = message;
	pageDialog.title   = title;
	pageDialog.onOk = function () {document.location.href = "/JobSeeker/ExtendAgentExpirationDate.asp?UserAgentID=" + id;};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}

function editJobAgent( id ) {
	document.location.href = "/JobSeekerX/SearchJobsForm.asp?agent=Full&UserAgentID=" + id + "&actn=change";
}
function showJobAgentHistory( id ) {
	document.location.href = "/JobSeeker/ViewUserAgentRuns.asp?UserAgentID=" + id;
}

function deleteCoverLetter( id ) {
	// use dhtml dialog component
	pageDialog.message = 'Are you sure you want to delete this cover letter?';
	pageDialog.title   = "Confirm delete operation";
	pageDialog.onOk = function () {document.location.href = "/JobSeeker/ChangeCoverLetter.asp?CoverLetterID=" + id + "&actn=delete"};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}

function viewCoverLetter(id) {
    var url = "/JobSeeker/ViewCoverLetter.asp?CoverLetterID=" + id;
    if (isEmployerSection())//if it's an employer?
        url = "/Employer/ViewCoverLetter.asp?CoverLetterID=" + encodeURIComponent(id);
    
    document.location.href = url;
}

function editCoverLetter( id ) {
	document.location.href="/JobSeeker/ChangeCoverLetterForm.asp?CoverLetterID=" + id + "&actn=change";
}

function copyCoverLetter( id ) {
	document.location.href="/JobSeeker/ChangeCoverLetterForm.asp?BaseCoverLetterID=" + id + "&actn=create";
}

function deleteResume( id ) {
	// use dhtml dialog component
	pageDialog.message = 'Are you sure you want to delete this resume?';
	pageDialog.title   = "Confirm delete operation";
	pageDialog.onOk = function () {document.location.href = "/JobSeeker/ChangeResume.asp?ResumeID=" + id + "&actn=delete"};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}

function refreshResume( id ) {
	document.location.href="/JobSeeker/RefreshResume.asp?ResumeID=" + id ;
}

// shows view resume page for JobSeeker using reusme id (encrypted)
function viewResume( encryptedId ) {
	if (isEmployerSection())
		document.location.href="/Employer/ViewResume.asp?ResumeID=" + encodeURIComponent(encryptedId);
	else
		document.location.href="/JobSeeker/ViewResume.asp?ResumeID=" + encodeURIComponent(encryptedId);
}

function viewResumeNoEncode(encryptedId) {
    document.location.href = "/JobSeeker/ViewResume.asp?ResumeID=" + encryptedId;
}
function viewResumeById(resumeId, userId) {
    var queryString = "?CRID=" + resumeId + "&userID=" + userId;
    if (isEmployerSection())
		document.location.href = "/Employer/ViewResume.asp" + queryString;
    else 
		document.location.href = "/JobSeeker/ViewResume.asp" + queryString;
}
// shows resume by job application
function viewJobApplication(encryptedId) {
    var url = "";
    if (isEmployerSection())
        url = "/Employer/ViewResume.asp?JobApplicationID=" + encodeURIComponent(encryptedId);
    else
        url = "/JobSeeker/ViewResume.asp?JobApplicationID=" + encodeURIComponent(encryptedId);
	
	document.location.href = url;
}

function forwardResume( id ) {
	document.location.href="/JobSeeker/ForwardResumeForm.asp?ResumeID=" + id;
}

function setResumeAsDefault( id ) {
	document.location.href="/JobSeeker/SetResumeAsDefault.asp?ResumeID=" + id;
}
function showResumeHistory( id ) {
	document.location.href="/JobSeeker/ViewResumeStatistics.asp?ItemID=" + id ;
}

function jobApplicationsForResume( id ) {
    var url = "";
    if( isEmployerSection() )
        url = "/Employer/ViewJobApplicationsForResume.asp?ResumeID=" + id ;
    else
        url = "/JobSeeker/ViewJobApplicationsForResume.asp?ResumeID=" + id ;
	document.location.href = url;
}
function jobApplicationsForJob(id) {
    var url = "";
    if( isEmployerSection() )
        url = "/Employer/ViewJobApplicationsForJob.asp?JobID=" + id;
    else
        url = "/JobSeeker/ViewJobApplicationsForJob.asp?JobID=" + id;
    
	document.location.href = url;
}

function jobApplications() {
	document.location.href="/JobSeeker/ViewJobApplications.asp";
}
/*edit resume with optional presentation type parameter*/
function changeResume(id, type) {
    var strPage = "";

    type = parseInt(type);
    switch (type) {
        case 1:
            strPage = "ChangeResumeShortForm.asp";
            break;
        case 2:
            strPage = "ChangeResumeForm.asp";
            break;
        case 3:
            strPage = "ChangeResumeUploadedForm.asp";
            break;
        default:
            strPage = "ChangeResumeFormAny.asp";
            break;
    }
    //redirect to change resume page
    document.location.href = "/JobSeeker/" + strPage + "?ResumeID=" + id;
} 

function whoViewedMyResume( id ) {
	self.location.href="/JobSeeker/ViewCompaniesWhoViewedResume.asp?ResumeID=" + id ;;
}
function showResumeOptions( id ){
	self.location.href="/JobSeeker/ViewResumeOptions.asp?ResumeID=" + id ;;
}

function editSearchProfile( id ) {
	document.location.href="/JobSeekerX/SearchJobsForm.asp?ProfileID=" + id + "&actn=change";
}
function deleteSearchProfile( id ) {
	// use dhtml dialog component
	pageDialog.message = 'Are you sure you want to delete this search profile?';
	pageDialog.title   = "Confirm delete operation";
	pageDialog.onOk = function () {document.location.href = "/JobSeeker/ChangeJobSearchProfile.asp?ProfileID=" + id + "&actn=delete"};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}

function editInboxItem(id) {
    //this is supported only in IE (fails for: Chrome, Fx, and Opera)
    //self.navigate("ChangeInboxItemForm.asp?ItemID=" + id + "&actn=change");
    if (isEmployerSection()) {
        document.location.href = "/Employer/ChangeInboxItemForm.asp?InboxItemID=" + id + "&actn=change";
    }
    else {
        document.location.href = "/JobSeeker/ChangeInboxItemForm.asp?ItemID=" + id + "&actn=change";
    }
}
function executeSearchProfile( id ) {
	document.location.href="/JobSeekerX/SearchJobs.asp?ProfileID=" + id;
}

function createSearchAgent(id, name) {
    name = (name == null) ? "" : name;
	document.location.href="/JobSeekerX/SearchJobsForm.asp?agent=Full&ProfileID=" + id + "&actn=create&JobSearchProfileName=" + name;
}

// assumes encrypted id
function viewJobById(id, iiid) {
    var url = "";
    if (isEmployerSection()) {
        url = "/Employer/ViewJob.asp?JobID=" + encodeURIComponent(id);
    }
    else {
        var strInboxItemPart = (iiid == null ? "" : "&iiid=" + iiid);
        url = "/JobSeekerX/ViewJob.asp?JobID=" + encodeURIComponent(id) + strInboxItemPart;
    }	
	document.location.href = url;
}
function viewJobNoEncode(jobId) {
    var url = "/JobSeekerX/ViewJob.asp?JobID=" + jobId;
    document.location.href = url;
}


/**********************************************************************
***	save job to inbox from view job page(force user to login first)
***
***	Created by: niloa
***	Modified by: 
***	Last modified: 08/10/2009
*** deleted by : rburdan
*********************************************************************/
/*
function saveViewJobRedirect(jobid, blnLogIn) {
    if (typeof (blnLogIn) != "boolean")
        blnLogIn = false;

    if (blnLogIn)
        saveJob("");
    else
        document.location.href = "/JobSeeker/AddJobToInbox.asp?jobid=" + jobid;
}
*/

/*
***	Inbox navigation functions
***
***	Created by: dimab
***	Modified by: rburdan
***	Last modified: 03/06/2009
***
*********************************************************************/
function deleteInboxItem( id ) {
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this item from in-box?';
    pageDialog.title   = "Confirm delete operation";
    if (isEmployerSection())
		pageDialog.onOk = function () {document.location.href = "/Employer/ChangeInboxItem.asp?actn=DELETE&InboxItemID=" + id};
	else
		pageDialog.onOk = function () {document.location.href = "/JobSeeker/ChangeInboxItem.asp?actn=DELETE&ItemID=" + id};
    pageDialog.onCancel = function () {/* do noting*/};
    pageDialog.modal = true;
    pageDialog.show();
}


/*********************************************************************
'***    Function: highlightResItemRow
'***
'***    Parameters: elId - source element id
'***
'***    Returns: void
'***    Remarks: 
        - gets element table row
        - this function assumes that there's a three parent hierarchy
            (e.g. element resides in a p, td, and tr html parent tag)
        - highlights element table row based on id            
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/15/2009
'*********************************************************************/
function highlightResItemRow(elId) {

    var objEl = document.getElementById(elId);

    if (objEl != null) {

        //pattern for rows of table with jobSeekerTable class
        var patternExpr = "table.jobSeekerTable tr";
        unhighlightTableRows(patternExpr);

        //table row element is sitting in
        var elRow = objEl.parentNode.parentNode.parentNode;

        //highlight elemennts row
        toggleHighlightRow(elRow, true);
    }
}

/*********************************************************************
'***    Function: toggleHighlightRow(row, blnHighlight)
'***
'***    Parameters: 
        row, current row to highlight
        blnHighlight - true - highlight row, false - reset
'***
'***    Returns: void
'***    Remarks: 
        - toggle highlight/unhiglight table row
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/15/2009
'*********************************************************************/
function toggleHighlightRow(row, blnHighlight) {
    if (typeof (blnHighlight) != 'boolean')
        blnHighlight = false;

    // find all rows in table
    if (row != null) {
        // add/remove class "highlight" when mouse enters/leaves
        if (blnHighlight)
            row.className = 'highlight';
        else
            row.className = '';
    }
}

/*********************************************************************
'***    Function: unhighlightTableRows
'***
'***    Parameters: patternExpr - xpath expression
        Example:
        1) all table cells: "table td"
        2) all table rows:  "table tr"
        3) all table rows that have the following css class:
            "table.jsSeekerTable tr"
'***
'***    Returns: void
'***    Remarks: 
    - unhighlight all table rows based on expression
    - default expression un-highlights all table rows
    - uses function defined in prototype.js
'***
'***    Created by: niloa
'***    Changed by: niloa
'***    Last change: 03/15/2009
'*********************************************************************/
function unhighlightTableRows(patternExpr) {
    if ((patternExpr == null) || (patternExpr == ""))
        patternExpr = 'table tr';

    //returns an array that match pattern expression
    var row = null, rows = null;
    try {
        rows = jQuery(patternExpr);
    }
    catch (ex) {
        rows = $$(patternExpr);
    }
    for (rowIndex = 0; rowIndex < rows.length; rowIndex++) {
        row = rows[rowIndex];
        toggleHighlightRow(row, false);
    }
}

/*********************************************************************
'***    Function: formatCompanyString
'***
'***    Parameters: 
        value, text to format
        length - size to conform text 
'***
'***    Returns: void
'***    Remarks: -  
'***
'***    Created by:  rburdan
'***    Changed by: 
'***    Last change: 06/10/09
'*********************************************************************/
function formatCompanyString(value, length) {
    value = String((value == null) ? "" : value);
    var strResult = new String("");
    var strShortNameValue =  new String(value);
    
    strShortNameValue = HTMLDecode(strShortNameValue);

    //if no length not specified, print entire length
    if (length == null)
        length = value.length;
    
    //if size is > than val.length, resize text
    if ((length != null) && (value.length > length))
        strShortNameValue = strShortNameValue.slice(0, length) + "...";
  
    var CleanValue = HTMLDecode(value);  
      
    var URLEncodedCleanValue = URLEncode(CleanValue);

    strResult = '<a href="/JobSeekerx/SearchJobs.asp?cnme=' + URLEncodedCleanValue + '"> ' + strShortNameValue + '</a>';

    document.write(strResult);
}


function editResumeSearchProfile( id ) {
	document.location.href="/Employer/SearchResumesForm.asp?ProfileID=" + id + "&actn=change";
}

function deleteResumeSearchProfile( id ) {
	// use dhtml dialog component
	pageDialog.message = 'Are you sure you want to delete this search profile?';
	pageDialog.title   = "Confirm delete operation";
	pageDialog.onOk = function () {document.location.href = "/Employer/ChangeResumeSearchProfile.asp?ProfileID=" + id + "&actn=delete"};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}

function executeResumeSearchProfile( id ) {
	document.location.href="/Employer/SearchResumesTable.asp?ProfileID=" + id;
}

function createResumeSearchAgent( id, name ) {
	document.location.href="/Employer/SearchResumesForm.asp?agent=Full&ProfileID=" + id + "&actn=create&ResumeSearchProfileName=" + name;
}

function createResumeSearchAgentV2( id, name ) {
	document.location.href="/Employer/ChangeSearchAgentForm.asp?agent=Full&ProfileID=" + id + "&actn=create&ResumeSearchProfileName=" + name;
}



/*********************************************************************
***	Resume Search agent navigation functions
***
***	Created by: dimab
***	Modified by: dimab
***	Last modified: 2/1/2009
***
*********************************************************************/
function deleteResumeAgent( id ) {
	// use dhtml dialog component
	pageDialog.message = 'Are you sure you want to delete this Resume search agent?';
	pageDialog.title   = "Confirm delete operation";
	pageDialog.onOk = function () {document.location.href = "/Employer/ChangeResumeSearchProfile.asp?agent=Full&actn=DELETE&UserAgentID=" + id};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}
// works with both expired and non expired agents
function extendResumeAgentExpiration( id, isExpired ) {
	var message = 'Are you sure you want to deactivate this Resume search agent?';
	var title = 'Confirm deactivate operation';
	if (isExpired) {
		message = 'Are you sure you want to extend expiration date and activate this Resume search agent?';
		title   = 'Confirm extend operation';
	}

	// use dhtml dialog component
	pageDialog.message = message;
	pageDialog.title   = title;
	pageDialog.onOk = function () {document.location.href = "/Employer/ExtendAgentExpirationDate.asp?UserAgentID=" + id;};
	pageDialog.onCancel = function () {/* do noting*/};
	pageDialog.modal = true;
	pageDialog.show();
}

function editResumeAgent( id ) {
    document.location.href = "/Employer/ChangeSearchAgentForm.asp?agent=Full&UserAgentID=" + id + "&actn=change";
}
function showResumeAgentHistory( id ) {
	document.location.href = "/Employer/ViewUserAgentRuns.asp?UserAgentID=" + id;
}

/*allows to edit any resume, simplay by resume id*/
function editAnyResume(id) {
    document.location.href = "/JobSeeker/ChangeResumeFormAny.asp?ResumeID=" + id + "&actn=change";
}

/*returns view order item link html*/
function getOrderItemViewLinks(itemID, itemName, itemType) {
    var aLink = new String("<a title=\"click to view details\" href=\"#URL#\">#CAPTION#</a>");
    var type = parseInt(itemType);
    var url = new String("");
    var currUrl = new String(document.location.href).toLowerCase();
    var folderName = (currUrl.indexOf("/employer") > -1) ? "/Employer": "/JobSeeker";
    switch (type) {
        case 123: //SE_OBJECT_ORDER_PRODUCT_ITEM
            url = aLink.replace("#URL#", folderName + "X/ViewProduct.asp?ProductID=" + itemID);
            break;
        case 122: //  SE_OBJECT_ORDER_PACKAGE_ITEM
            url = aLink.replace("#URL#", folderName + "X/ViewPackage.asp?PackageID=" + itemID);
            break;
        case 341: // SE_OBJECT_ORDER_PROMOTION_ITEM
            url = aLink.replace("#URL#", folderName + "/ViewPromotion.asp?PromotionID=" + itemID);
            break;
        default:
            url = "";
            //nothing
            break;
    }
    return url.replace("#CAPTION#", itemName);
}

/*view package details*/
function viewPackage(id) {
    var currUrl = new String(document.location.href).toLowerCase();

    //check which site section is viewing
    var folderName = (currUrl.indexOf("/employer") > -1) ? "/Employerx" : "/JobSeekerx";
    var url = folderName + "/ViewPackage.asp?PackageID=" + id;
    
    document.location.href = url;
}

/*********************************************************************
***	Function: determines if current url is employer section
*** Param: 
***	Created by: dimab
***	Modified by: 
***	Last modified: 09/19/2009
***
*********************************************************************/
function isEmployerSection() {
	var thisHref = new String(window.location.href).toLowerCase();
	return (thisHref.indexOf("/employer/") > -1 || thisHref.indexOf("/employerx/") > -1 );

}

/*********************************************************************
***	Function: navigates to change job page
*** Param: 
***	Created by: niloa
***	Modified by: 
***	Last modified: 09/21/2009
***
*********************************************************************/
function changeJob(id) {
    document.location.href = "/Employer/ChangeQuickJobForm.asp?actn=change&JobID=" + id  + "&TargetURL=" + document.URL;
}

function deleteJob(id) {
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this job?';
    pageDialog.title = "Confirm delete operation";
    pageDialog.onOk = function() { document.location.href = "/Employer/ChangeQuickJob.asp?actn=delete&JobID=" + id + "&TargetURL=" + document.URL};
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}

function cloneJob(id) {
    document.location.href = "/Employer/ChangeQuickJobForm.asp?actn=create&JobID=" + id
}

function showJobHistory(id) {
    document.location.href = "/Employer/ViewJobStatistics.asp?ItemID=" + id;
}

/*loads the contact us form for based on section*/
function contactUs() {
    var url = isEmployerSection() ? "/EmployerX/ContactForm.asp" : "/Resources/ContactForm.asp";
    document.location.href = url;
}

// send resume 
function sendResume( encryptedResumeId )  {
    document.location.href = "/Employer/SendResumeForm.asp?enrid=" + encryptedResumeId;
}
		
// add to inbox
function saveResume( Id )  {
    document.location.href = "/Employer/AddResumeToInbox.asp?ResumeID=" + Id;
}
// contact job seeker
function contactJobseeker( encryptedResumeId )  {
    document.location.href = "/Employer/ContactJobSeekerForm.asp?enrid=" + encryptedResumeId;
}

/*********************************************************************
***	Function: determines if current url is from secure.searchease
*** Param: 
***	Created by: niloa
***	Modified by: 
***	Last modified: 11/09/2009
***
*********************************************************************/
function isSecureClientSite() {
    var thisHref = new String(window.location.href).toLowerCase();
    return (thisHref.indexOf("https://secure.searchease.com") > -1);
}

/*********************************************************************
***	Function: navigates user to incomplete order form
*** Param: orderId - required order id
***	Created by: niloa
***	Modified by: 
***	Last modified: 09/04/2009
***
*********************************************************************/
function changeOrder(orderId) {
    var id = orderId;
    var url = "", pathname = "", httpHost = "";

    //this function is used in a https context
    //therefore, it needs to provide an exit from https
    var loc = document.location;
    
    //if under https protocol
    if ("https:" == loc.protocol.toLowerCase())
    //default protocol to the unsecure (http) version
        httpHost = "http://" + loc.host;

    pathname = isEmployerSection() ? "/Employer" : "/JobSeeker";
    
    //from location object and compose a non-secure url as
    //example: http:// + host + pathname + queryString
    url = httpHost + pathname + "/ViewIncompleteOrder.asp?actn=change&OrderID=" + id;

    window.location.href = url;
}

//view order
function viewOrder(id) {
    var dir = isEmployerSection() ? "/Employer" : "/JobSeeker";
    document.location.href = dir + "/ViewOrder.asp?OrderID=" + id;
}

//delete on hold order
function deleteOrder(id) {
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this order?';
    pageDialog.title = "Confirm delete operation";
    pageDialog.onOk = function() {
        var targetURL = String(document.location.href);
        var dir = (isEmployerSection()) ? "/Employer" : "/JobSeeker";
        var url = dir + "/ChangeOrder.asp?actn=delete&OrderID=" + id;
        //need to specify target url to redirect after deleting an order
        //IE referrer is empty when redirecting from function
        //to fix, set current url as targetURL query string param
        //get param from server side, if value is not empty, redirect to it
        url += "&TargetURL=" + targetURL;
        
        document.location.href = url;
    };
    pageDialog.onCancel = function() { /* do nothing*/ };
    pageDialog.modal = true;
    pageDialog.show();
}
/*view order bad charge attempts*/
function viewOrderChargeAttempts(id) {
    var dir = isEmployerSection() ? "/Employer" : "/JobSeeker";
    document.location.href = dir + "/ViewOrderBadChargeAttempts.asp?OrderID=" + id;
}
//allows user proceed to checkout, non-held orders displays validation message
function placeOrder(id) {
    var dir = isEmployerSection() ? "/Employer" : "/JobSeeker";
    document.location.href = dir + "/PlaceOrderForm.asp?OrderID=" + id;
}
/*redirects to Job Question Answers page*/
function viewJobAnswers(id) {
    document.location.href = "/Employer/ViewJobQuestionAnswers.asp?JobApplicationID=" + id
}

/* Actions for Employer Questions/Answers */
function deleteEmployerQuestion(id) {
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this question?';
    pageDialog.title = "Confirm delete operation";
    pageDialog.onOk = function() { document.location.href = "/Employer/ChangeEmployerQuestion.asp?actn=DELETE&QuestionID=" + id };
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}
function editEmployerQuestion(id) {
    document.location.href = "/Employer/ChangeEmployerQuestionForm.asp?actn=CHANGE&QuestionID=" + id;
}
function deleteSelAnswerItem(id, qId){
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this answer?';
    pageDialog.title = "Confirm delete operation";
    pageDialog.onOk = function() { beginDeleteAnswerItem(id, qId) };
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}
function beginDeleteAnswerItem(answerId, questionId){
    var strUrl = "/Components/ViewEmployerAnswersItems.asp";
    var strQS = "actn=DELETE&AnswerItemID=" + answerId + "&QuestionID=" + questionId;
    
    var options = jQueryGetAjaxOptions("#answHistory", strUrl, strQS);
    jQuery.ajax(options);
}

function editAnswerItemAjax(id){
    var strUrl = "/Components/ChangeEmployerAnswerForm.asp";
    var strQS = "actn=CHANGE&AnswerOptionID=" + id;
    var answerCntId = "answBuilder";
    
    var onSuccess = function(){
        // refresh hints for loaded form
        prepareAllInputsForHints(answerCntId);
    }
    
    var options = jQueryGetAjaxOptions("#" + answerCntId, strUrl, strQS, null, onSuccess);
    jQuery.ajax(options);;
}
function beginGetNewAnswerForm(questionId){
    var strUrl = "/Components/ChangeEmployerAnswerForm.asp";
    var strQS = "actn=CREATE&QuestionID=" + questionId;
    var answerCntId = "answBuilder";
    
    var onSuccess = function(){
        // refresh hints for loaded form
        prepareAllInputsForHints(answerCntId);
    }
    
    var options = jQueryGetAjaxOptions("#" + answerCntId, strUrl, strQS, null, onSuccess);
    jQuery.ajax(options);
}

function loadAnswerItems(questionId){
    var strUrl = "/Components/ViewEmployerAnswersItems.asp";
    var strQS = "QuestionID=" + questionId;
    var answerItemsCntId = "#answHistory";
    
    var options = jQueryGetAjaxOptions(answerItemsCntId, strUrl, strQS);
    jQuery.ajax(options);
}

function submitEmployerAnswerForm(questionId, frmId){
    if(!validateAnswer())
        return false;
    
    if(frmId == null || frmId == "")
        frmId = "FormEmployerAnswer";
    
    var onComplete = function(){
        loadAnswerItems(questionId);
    }
    var onSuccess = function(){
        hideValidationMessage("validationMessageAnswers");
        beginGetNewAnswerForm(questionId);
    }
    
    AjaxFormSubmit(frmId, onComplete, onSuccess);
}



/*Company Profile*/
function viewCompanyProfile( id ) {
    document.location.href="/Employer/ViewCompanyProfile.asp?CompanyProfileID=" + id;
}

function editCompanyProfile( id ) {
    document.location.href="/Employer/ChangeCompanyProfileForm.asp?CompanyProfileID=" + id + "&actn=change";
}

function deleteCompanyProfile( id ) {
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this Company Profile?';
    pageDialog.title   = "Confirm delete operation";
    pageDialog.onOk = function () {document.location.href = "/Employer/ChangeCompanyProfile.asp?CompanyProfileID=" + id + "&actn=delete"};
    pageDialog.onCancel = function () {/* do noting*/};
    pageDialog.modal = true;
    pageDialog.show();
}    
        
function statisticsCompanyProfile( id ){
    document.location.href="/Employer/ViewCompanyProfileStatistics.asp?ItemID=" + id;
}

/*Actions for ViewResponseMessages.asp*/
function deleteResponseMessage(id) {
    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to delete this response message?';
    pageDialog.title = "Confirm delete operation";
    pageDialog.onOk = function() { document.location.href = "/Employer/ChangeResponseMessage.asp?actn=DELETE&ResponseMessageID=" + id };
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}

function editResponseMessage(id) {
    document.location.href = "/Employer/ChangeResponseMessageForm.asp?actn=change&ResponseMessageID=" + id;
}

function saveFormAndViewResume(objFormResume, id){
    var strUrl    = "/JobSeeker/ViewResume.asp?ResumeID=" +  id;
	var TargetURL = document.getElementById("TargetURL");
	
    TargetURL.value = strUrl;
    objFormResume.submit();
}
	    
function revealContacts(ids){
    document.location.href="/Employer/RevealContacts.asp?rid=" + ids;
}

/*********************************************************************
***	Function: opens a form to allow editing employer user
*** Param: id - required user id
***	Created by: niloa
***	Modified by: 
***	Last modified: 03/02/2010
***
*********************************************************************/
function editEmployerUser(id) {
    document.location.href = "/Employer/Manager/ChangeEmployerUserForm.asp?actn=change&UserID=" + id;
}

//deletes(disables in backend) employer user id
function deleteEmployerUser(id) {

    // use dhtml dialog component
    pageDialog.message = 'All records created by user(s) you are deleting will be deleted. Are you sure you want to proceed?';
    pageDialog.title = "Confirm delete operation";
    pageDialog.onOk = function() {
        var url = "/Employer/Manager/BulkChangeUsers.asp?BulkOperationType=DeleteSelected&UID=" + id;
        url += "&TargetURL=ViewUsers.asp";
        document.location.href = url;
    };
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}

/*receives a valid employer user id and logs the user in*/
function loginAsUser(id) {
    //do not use document.location.href, it needs to open a new window
    //do not pass any open attributes, just open a new window with defaults
    var URL = "/Employer/Manager/LoginAsUser.asp?UserID=" + id;
    window.open(URL);
}

//displays employer user available permissions
function viewUserPermissions(id) {
    document.location.href = "/Employer/ViewUserPermissions.asp?UserID=" + id;
}

//displays employer user available permissions
function viewUserPermissionsWithReturn(id) {
    document.location.href = "/Employer/Manager/ViewUserPermissionsWithReturn.asp?UserID=" + id;
}

//displays employer user activity report
function viewUserStatistics(id) {
    var dir = isEmployerSection() ? "/Employer" : "/JobSeeker";
    document.location.href = dir + "/ViewUserStatistics.asp?ItemID=" + id;
}

// displayed on ViewEvent/SearchEvents pages when event attached to company
function viewEventParticipants(eventId){
    document.location.href = "/JobSeekerX/SearchCompanyProfiles.asp?evnt=" + eventId;
}

/*********************************************************************
'***    Function:   using RegExp detects if strText contains incorrect symbols 
'***                (usually tinyMCE produces xml mso-styles which are incorrect when sending resume in email)
'***                to avoid this - ask user to use 'Paste from Word' button
'***
'***    Parameters: 
'***		strText - text which is testing
'***    
'***    Returns: True/False
'***    Remarks: returns true if given text contains MSO specific styles.
'***                To get error text use getMSOValidationMessageForTinyMCE function (ValidationLib.js)
'***
'***    Created by: sergeyh
'***    Changed by: sergeyh
'***    Last change: 06/15/2010
'*********************************************************************/
function TextHasMSOfficeStyles(strText){
    if(Trim(strText) == "" || strText == null)
        return false;
    var re = null;
    
    // 0 - do not validate plain text
    // text that has this class, does not need to be validated
    re = /class=\"MsoPlainText\"/gim;
    if (re.test(strText)) return false;
    // 1
    re = /\[if gte mso(.*?)\](.*?)&lt;xml&gt;(.*?)\[endif\]/gim;
    if (re.test(strText)) return true; // no need to continue
    // 2
    re = /\[if supportFields\](.*?)\[endif\]/gim;
    if (re.test(strText)) return true;
    // 3
    re = /\[if gte vml(.*?)[0-9]\](.*?)\[endif\]/gim;
    if (re.test(strText)) return true;
    // 4
    re = /&lt;\/v:formulas&gt;/gim;
    if (re.test(strText)) return true;
    // 5
    re = /@page\sSection/gim;
    if (re.test(strText)) return true;
    // 6
    re = /mso\-(.+)/gim;
    if (re.test(strText)) return true;
    
    return false; // no MS styles found
}

/*********************************************************************
'***    Function:   using RegExp detects if strText contains unsupported html tags
'***    
'***    Parameters: 
'***		strText - text which is testing
'***    
'***    Returns: True/False
'***    Remarks: returns true if text valid
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 04/02/2010
'*********************************************************************/
function IsHtmlValidForEntry(strText){
    if(Trim(strText) == "" || strText == null)
        return true;
    
    htmlRegExp = new RegExp('&lt;/?(?:!doctype|html|head|title|link|meta|style|script|body)(.*?)/?&gt;', 'gim');
    
    return !htmlRegExp.test(strText);
}

/*********************************************************************
'***    Function:   adds "back to search results" button on ViewJob/ViewResume page
'***    
'***    Parameters: 
'***                strShowOneBtnOnly [string] - allows to show only one button ("top" / "bottom")
'***    
'***    Returns: void
'***    Remarks: none
'***
'***    Created by: sergeyh
'***    Changed by: sergeyh
'***    Last change: 10/30/2010
'*********************************************************************/
function configureBackToSearchResultsBtn(strShowOneBtnOnly){
    var blnShowTopBtn = (strShowOneBtnOnly == "top");
    var blnShowBottomBtn = (strShowOneBtnOnly == "bottom");
    
    // if parameter is not passed - show both buttons
    if(!blnShowTopBtn && !blnShowBottomBtn){
        blnShowTopBtn = true;
        blnShowBottomBtn = true;
    }
    
    // bottom
    if(blnShowBottomBtn){
        var objBackBtn = document.getElementById("BackBottom");
        objBackBtn.className = "";
        objBackBtn.value = "Back to Search Results";
    }
    
    // top
    if(blnShowTopBtn){
        var objContent = document.getElementById("content");
        var strBackBtn = '<input id="BackTop" name="BackTop" type="button" value="Back to Search Results" onclick="self.history.back()"/>';
        objContent.innerHTML = '<fieldset id="ContainerButtonBarTop" class="actionBar">' + strBackBtn + '</fieldset>' + objContent.innerHTML;
    }
}

/*********************************************************************
'***    Program: showDocumentWithPreview( intObjId )
'***    Type: Function
'***
'***    Function: changes iframe (quick document preview) source
'***
'***    Parameters: 
'***                intObjId [int]* - id which will be added to all items (makes these objects unique)
'***
'***
'***    Returns: void
'***    Remarks: none
'***
'***    Created by: sergeyh
'***    Changed by: 
'***    Last change: 08/18/2010
'*********************************************************************/
function showDocumentWithPreview(intObjId){
    intObjId = parseInt(intObjId);
    if(intObjId <= 0)
        return;
    var doc = document;
    var objIFrame = doc.getElementById("mediaItem" + intObjId);
    if (objIFrame == null){ // if no iframe found - do nothing
        return;
    }
    var googlePreviewUrl = doc.getElementById("gPreviewUrl" + intObjId).value; // get google preview url
    var lstDocuments = doc.getElementById("selectDocument" + intObjId);
    if (lstDocuments == null)
        return;
    // filename for preview
    var fileName = lstDocuments.options[lstDocuments.options.selectedIndex].value;
    // get full paths to items
    var encViewPath = doc.getElementById("siteUrlWithPathEnc" + intObjId).value;
    var ViewPath = doc.getElementById("siteUrlWithPath" + intObjId).value; // simple files do nto support encoded path
    
    var strPreviewUrl = "";
    var blnGooglePreview = fileName.indexOf("googlePreview,") >= 0; // determine if google mask exist
    
    if(blnGooglePreview){
        // google viewer
        fileName = fileName.replace("googlePreview,",""); // remove google mask from filename
        strPreviewUrl = googlePreviewUrl + encViewPath + fileName + "&embedded=true";
    }
    else{
        // simple viewer
        strPreviewUrl = ViewPath + fileName;
    }
    
    objIFrame.src = strPreviewUrl; // change source in iframe
}

/*********************************************************************
'***    Function: deleteUserAuthProvider( id )
'***
'***    Parameters: id - user auth provider id
'***
'***    Returns: void
'***    Remarks: deletes a user auth provider entry
'***    unlinks Auth Provider from User's Account
'***
'***    Created by: niloa
'***    Changed by: 
'***    Last change: 04/20/2011
'*********************************************************************/
function deleteUserAuthProvider(userAuthProviderId, providerId) {
    var msg = "";

    var onOK_ClickHandler = function() {
        
        var url = "ChangeUserAuthProvider.asp?actn=DELETE&UserAuthProviderID=" + userAuthProviderId;
        document.location.href = url;
        return;
    };

    //componse message to display
    var siteName        = jQuery("#siteName").val();
    var providerName    = jQuery("#prov" + providerId).data("providerName");
    var linkedAccounts  = jQuery("#userAuthProvidersCount").val();
    intProvidersCount   = parseInt(linkedAccounts);
    linkedAccounts      = isNaN(linkedAccounts) ? 0 : linkedAccounts;
    
    msg += 'Unlinking your ' + providerName + ' account from your ' + siteName + ' will not allow you to sign on using that account. ';
    msg += 'However, you will still be able to sign on with ' + siteName + ' login and password';
    msg += (linkedAccounts > 1) ? ' or other linked account(s). ' : '. ';
    msg += 'Are you sure you would like to proceed?';
        
    // use dhtml dialog component
    pageDialog.message = msg;
    pageDialog.title = "Confirm unlink operation";
    pageDialog.onOk = onOK_ClickHandler;
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}

//redirects user to create resume form LinkedIn mem profile
function getResumeFromLinkedInProfile(userId) {
    var id = parseInt(userId);
    if (isNaN(id) || id <= 0)
        return;
    
    //force user to login, to linked in user hasn't already done so
    var url = "/Auth/OAuth/LinkedIn/Login.aspx?actn=CREATE_RESUME&";
    url += "providerId=4&accountType=1&UserID=" + id;
    
    document.location.href = url;
}

function addOccurrenceToCalendar(ocurrenceId){
    window.location.href= "/Resources/DownloadEventOccurrenceAsiCal.asp?EventOccurrenceID=" + ocurrenceId;
}

function viewEventParticipants(id) {
	document.location.href="/JobSeekerX/ViewEventParticipants.asp?EventID=" + id;
}


/* changes result type on SearchJobs[Table] pages based on passed type */
function changeSearchJobsResultType(intType, strQS){
    intType = parseInt(intType);
    var strUrl = "";
    
    switch(intType){
        case 1: //RESULT_DETAILED
            strUrl = "/JobSeekerX/SearchJobs.asp";
    	    break;
        case 2: //RESULT_BRIEF
            strUrl = "/JobSeekerX/SearchJobsTable.asp";
    	    break;
	    case 3: //RESULT_REFINE
	        strUrl = "/JobSeekerX/SearchJobsV2.asp";
	        break;
        case 4: //RESULT_XML
            strUrl = "/JobSeekerX/SearchJobsRSS.asp";
	        break;
        default:
            strUrl = "/JobSeekerX/SearchJobs.asp";
    }
    
    window.location = strUrl + "?" + strQS;
}
function changeSearchSpecialJobsResultType(intType, strQS){
    intType = parseInt(intType);
    var strUrl = "";
    
    switch(intType){
        case 1: //RESULT_DETAILED
            strUrl = "/JobSeekerX/ViewSpecialJobs.asp";
    	    break;
        case 2: //RESULT_BRIEF
            strUrl = "/JobSeekerX/ViewSpecialJobsTable.asp";
    	    break;
        case 4: //RESULT_XML
            strUrl = "/JobSeekerX/SpecialJobsRSS.asp";
	        break;
        default:
            strUrl = "/JobSeekerX/ViewSpecialJobs.asp";
    }
    
    window.location = strUrl + "?" + strQS;
}

function viewProfilesByAccountNo( id ) {
	document.location.href="/JobSeekerx/SearchCompanyProfiles.asp?acc=" + id;
}

function viewJobsByAccountNo( id ) {
	document.location.href="/JobSeekerx/SearchJobs.asp?acc=" + id;
}

function activateJob(id, code, target) {
    var ActionLbl = "";
    var strTargetURL = "";

    if (target == null)
        target = "";

    if (code.toLowerCase() == "activate") {
        ActionLbl = "Activate";
    }
    else if (code.toLowerCase() == "deactivate") {
        ActionLbl = "Deactivate";
    }

    if (target != "")
        strTargetURL = "&TargetURL=" + target;

    // use dhtml dialog component
    pageDialog.message = 'Are you sure you want to ' + ActionLbl + ' this job?';
    pageDialog.title = "Confirm " + ActionLbl + " operation";
    if (code.toLowerCase() == "activate" || code.toLowerCase() == "deactivate")
        pageDialog.onOk = function() { document.location.href = "/Employer/ChangeQuickJob.asp?actn=activate&JobID=" + id + strTargetURL };
    pageDialog.onCancel = function() { /* do noting*/ };
    pageDialog.modal = true;
    pageDialog.show();
}

