function myChartLogin() { 

    var loginForm;
    if (loginForm = document.getElementById("loginForm")) {

        for(i=0; i<loginForm.elements.length; i++) 
        {
            var e = loginForm.elements[i];
            if (e.name.indexOf("Ektron") != -1) 
                e.parentNode.removeChild(e);		
        }

        loginForm.jsenabled.value = "1";
        var sID, sPassword;
        sID = loginForm.Login.value;
        sPassword = loginForm.Password.value;
        if ((sID == "") && (sPassword == "")) {
            alert("Please enter a User ID and a Password.");
            loginForm.Login.focus();
            return false
        } else {
            if (sID == "") {
                alert("Please enter a User ID.");
                loginForm.Login.focus();
                return false
            } else {
                if (sPassword == "") {
                    alert("Please enter a Password.");
                    loginForm.Password.focus();
                    return false
                } 
            } 
        } 
    } return true
} 

function checkKeycode(e) {
   var keycode;
   if (window.event) // IE                    
        keycode = e.keyCode;
   else if (e.which) // Netscape/Firefox/Opera
        keycode = e.which;

   if (keycode==13) { 
        CallSearch();
        return false;
   }
   else
        return true;
}

function remove_s_hint(targetInput) {

    if (targetInput.value == "") {
        targetInput.value = "Enter Keyword(s)...";
    }
    else if (targetInput.value=="Enter Keyword(s)...")
        targetInput.value="";
}


function CallSearch()
{

   var objsearchText = document.getElementById('txtSearchText');
   var searchText;
   if ((objsearchText!=null))
   {
       searchText = objsearchText.value;
       searchText = searchText.replace(/>/gi, " >");
       searchText = searchText.replace(/</gi, "< ");
       objsearchText.value = searchText;
   }

   //This cookie is used for the backbutton to work in search on postback
   //This cookie must be cleared to prevent old search results from displayed

   document.cookie='postbackcookie=';
   var this_url = "/search.aspx?searchtext=" + searchText.replace('alert','').replace('confirm','');
   document.location.href = this_url;

   //Load the page with the websearch server control in the bottom frame using Javascript
   //Set websearch properties using querystring parameters
   //Properties set here- search text,Orderby, FolderId, and SearchFor
   //SearchFor can be a value from all/html/documents/images/multimedia/discussionForum
   //Orderby can be one of these - editor,id,rank,title,datecreated,datemodified
   //OrderDirection can be ascending or descending
}

// Changes links to point to staging site while on staging server. 
// CMS should be doing this automatically but its not always doing it. 
// For example menu items that are also folders or menu items that are using absolute paths.
// This also changes all the link to point to development while on development server
// This should not effect production at all.
function fixlinks() {
    var hostname = ""

    if (document.location.hostname.substr(0,4) == 'dev.')
    {	
	    for (var i = 0; i < document.links.length; i++) {
		    hostname = document.links[i].hostname;

		    if (hostname == 'www.hawaiipacifichealth.org' ||
		        hostname == 'www.kapiolani.org' ||
		        hostname == 'www.palimomi.org' ||
		        hostname == 'www.straubhealth.org' ||
		        hostname == 'www.wilcoxhealth.org' ||
		        hostname == 'www.kapiolaniwoman.org')
		    {
			    document.links[i].href = document.links[i].href.replace("www.", "dev.");
			    document.links[i].href = document.links[i].href.replace("https:", "http:");
		    }

		    if (hostname == 'stage.hawaiipacifichealth.org' ||
		        hostname == 'stage.kapiolani.org' ||
		        hostname == 'stage.palimomi.org' ||
		        hostname == 'stage.straubhealth.org' ||
		        hostname == 'stage.wilcoxhealth.org' ||
		        hostname == 'stage.kapiolaniwoman.org')
		    {
			    document.links[i].href = document.links[i].href.replace("stage.", "dev.");
			    document.links[i].href = document.links[i].href.replace("https:", "http:");
		    }
		    
		    if (hostname.substr(0,4) == 'dev.')
			    document.links[i].href = document.links[i].href.replace("https:", "http:");
	    }
    }

    if (document.location.hostname.substr(0,6) == 'stage.')
    {
	    for (var i = 0; i < document.links.length; i++) {
		    hostname = document.links[i].hostname;

		    if (hostname == 'www.hawaiipacifichealth.org' ||
		        hostname == 'www.kapiolani.org' ||
		        hostname == 'www.palimomi.org' ||
		        hostname == 'www.straubhealth.org' ||
		        hostname == 'www.wilcoxhealth.org' ||
		        hostname == 'www.kapiolaniwoman.org')
		    {
			    document.links[i].href = document.links[i].href.replace("www.", "stage.");
			    document.links[i].href = document.links[i].href.replace("https:", "http:");
		    }
		    
		    if (hostname.substr(0,6) == 'stage.')
			    document.links[i].href = document.links[i].href.replace("https:", "http:");
	    }
    }
}

// Removed HTML tags from a string and return just the text 
function removeHTMLTags(strInputCode) {
        strInputCode = strInputCode.replace(/&(lt|gt);/g, function(strMatch, p1) {
            return (p1 == "lt") ? "<" : ">";
        });
        var strTagStrippedText = strInputCode.replace(/<\/?[^>]+(>|$)/g, "");
     
    return strTagStrippedText;
}

// Trim the right and left of a string
function trim(stringToTrim) {
   return stringToTrim.replace(/^\s+|\s+$/g, '');
}

// Populates the careers tab with HPH jobs listed on HR Smarts website using an RSS feed.
function initializeJobFeed() {
    var feed = new google.feeds.Feed("https://hawaiipacifichealth.ats.hrsmart.com/cgi-bin/a/alljobs.rss?status=open&featured=1");

    feed.setNumEntries(100);
    
    feed.load(function(result) {
        if (!result.error) {
            var container = document.getElementById("feed");
            var numOfJobs = result.feed.entries.length;
            var currJob = 0;
            var jobFound = false;
            
            

            
            for (var i = 0; i < numOfJobs; i++) {
 
                var pJob = document.getElementById('job' + (currJob + 1));
 
                if (pJob != null) {
                    var entry = result.feed.entries[i];

                    if (entry.title != 'No Jobs') {
                    
                        var jobInfo = '';
                        var jobTitle = entry.title;
                        var jobTitle2 = entry.title;
                        var jobLink = entry.link;
                        var jobFacility = '';
                        var jobDepartment = '';
                        var jobLocation = '';
                        var jobType = '';

                        jobTitleArray = jobTitle.replace(' - ', '$%#').split("$%#");

                        if (jobTitleArray.length == 2)
                            jobTitle = jobTitleArray[1];

                        var description = entry.content;
                        description = description.replace(/<\/td>/g, '$%#</td>');
                        description = removeHTMLTags(description);
                        description = description.replace(/\n/g, '');
                        description = description.replace(/\r/g, '');
                        description = description.replace(/&nbsp;/g, '');

                        job = description.split("$%#");

                        for (n = 0; n < job.length - 1; n++) {
                            jobInfo = trim(job[n]);

                            if (jobInfo == "Division:") {
                                jobFacility = trim(job[n + 1]);
                                n++;
                            }
                            else if (jobInfo == "Department:") {
                                jobDepartment = trim(job[n + 1]);
                                n++;
                            }
                            else if (jobInfo == "Location:") {
                                jobLocation = trim(job[n + 1]);
                                n++;
                            }
                            else if (jobInfo == "Job Type:") {
                                jobType = trim(job[n + 1]);
                                n++;
                            }
                        }

                        if (isFacilityWebSite(jobFacility) == true) {
                            jobFound = true;
                            currJob = currJob + 1;
                            pJob.innerHTML = '<a href="' + jobLink + '"><strong>' + jobTitle + '</strong></a><br />Facility: ' + jobFacility + '<br />Department Name: ' + jobDepartment + '<br />Location: ' + jobLocation + '<br />Job Type: ' + jobType;
                        }
                    }
                }
            }
            if (jobFound == false) {
                 var job1 = document.getElementById('job1');
                 if (job1 != null) {
                    job1.innerHTML = 'No Featured Jobs.';
                 }
                 var job2 = document.getElementById('job2');
                 if (job2 != null) {
                    job2.style.display = 'none';
                 }
                 var job3 = document.getElementById('job3');
                 if (job3 != null) {
                    job3.style.display = 'none';
                 }
                 var job4 = document.getElementById('job4');
                 if (job4 != null) {
                    job4.style.display = 'none';
                 }
            }
        }
    });
}

// check to see if the job's facility matches current website
function isFacilityWebSite(facility) {
    var hostname = location.hostname.split(".")[1].toLowerCase();
    facility = facility.toLowerCase().replace(/\'/g, "");
    
    if (hostname == 'hawaiipacifichealth')
        return true;
        
    if (hostname == 'kapiolani' && facility == 'kapiolani medical center for women and children') {
        return true;
    }
        
    if (hostname == 'kapiolaniwoman' && facility == 'kapiolani medical center for women and children') {
        return true;
    }
        
    if (hostname == 'straubhealth' && facility == 'straub clinic and hospital') {
        return true;
    }
        
    if (hostname == 'palimomi' && facility == 'pali momi medical center') {
        return true;
    }
        
    if (hostname == 'wilcoxhealth' && facility == 'wilcox memorial hospital') {
        return true;
    }
    
    return false;
}
