﻿
//================================================================
//== Capture mouse X Y position
//================================================================
// Global variables
var xMousePos = 0; // Horizontal position of the mouse on the screen
var yMousePos = 0; // Vertical position of the mouse on the screen
var xMousePosMax = 0; // Width of the page (inner)
var yMousePosMax = 0; // Height of the page (inner)

function WindowInner(strXY)
{
    if (document.layers) 
    {
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    } 
    else if (document.all) 
    {
        xMousePosMax = document.body.clientWidth+document.body.scrollLeft;
        yMousePosMax = document.body.clientHeight+document.body.scrollTop;
    } 
    else if (document.getElementById) 
    {
        xMousePosMax = window.innerWidth+window.pageXOffset;
        yMousePosMax = window.innerHeight+window.pageYOffset;
    }
    switch(strXY)
    {
        case "X":
            return xMousePosMax;
            break;
        case "Y":
            return yMousePosMax;
            break;
    }
}
//================================================================
function captureMousePosition(e) 
{
    if (document.readyState == "complete")
    {
        if (document.layers) 
        {
            xMousePos = e.pageX + 25;
            yMousePos = e.pageY - 25;
        } 
        else if (document.all) 
        {
            xMousePos = window.event.x + document.body.scrollLeft + 25;
            yMousePos = window.event.y + document.body.scrollTop - 25;
        } 
        else if (document.getElementById) 
        {
            xMousePos = e.pageX + 25;
            yMousePos = e.pageY - 25;
        }
	    document.umouse.x.value = xMousePos;
  	    document.umouse.y.value = yMousePos;
  	}
}
//================================================================
function CaptureMouseXY() // fired with page onload 
{ 
    if (document.readyState == "complete")
    {
	    if (document.getElementById) 
	    {
	        document.onmousemove = captureMousePosition;
	    } 
	    else if (document.all) 
	    {
	        document.onmousemove = captureMousePosition;
	    } 
	    else if (document.layers) 
	    {
	        document.captureEvents(Event.MOUSEMOVE);
	        document.onmousemove = captureMousePosition;
	    }
	}
}

/*========================================================\
|   RecurseOffset
|   returns all possible levels of offsetParent.offsetXXX
`========================================================*/
function RecurseOffset(obj,type)
{
    var ParentObj;
    var CurrentLeft = obj.offsetLeft;
    var CurrentTop = obj.offsetTop;
    var CurrentObj = obj;
    for(x=0;x<99;x++)
    {
        if (CurrentObj.offsetParent)
        {
            ParentObj = CurrentObj.offsetParent;
            CurrentLeft += ParentObj.offsetLeft;
            CurrentTop += ParentObj.offsetTop;
            CurrentObj = ParentObj;
        }
        else
        {
            break;
        }
    }
    switch (type)
    {
        case "Left": return CurrentLeft; break;
        case "Top": return CurrentTop; break;
    }
    return CurrentLeft; // default
}



/*========================================================\
|   SaveSearch
`========================================================*/
function SaveUserSearch(theForm)
{
    var ssimg = document.getElementById("ssimg");
    var ifr = document.getElementById("componenttarget");
    
    if (theForm == undefined || ssimg.src == savesearch_hot.src) // close saved search
    {
        ifr.style.left = "1px";
        ifr.style.top = "1px";
        ifr.style.width = "1px";
        ifr.style.height = "1px";
        ifr.style.visibility = "hidden";
        ssimg.src = savesearch_norm.src;
    }
    else // open saved search
    {
//        if (trim(theForm.keywords.value).length < 3)
//        {
//			if (theForm.name == "searchbasic")
//			{
//				window.alert("Please provide a search term of at least 3 characters");
//				return;
//			}
//        }
            ifr.style.width = "400px";
            ifr.style.height = "320px";
        
        var ssimgLeft = RecurseOffset(ssimg,"Left");
        var ssimgTop = RecurseOffset(ssimg,"Top");
        
            ssimg.src = savesearch_hot.src;
            
            theForm.action = "../Searches/SaveSearch.aspx";
            theForm.target = "componenttarget";
//            if (theForm.name == "searchadvanced")
//            {
//                SC.transposeSelected(); // uses the MultiSelectNoControlButton Class to define selected elements
//            }
            theForm.submit();
            
            theForm.action = "../Jobs/SearchResults.aspx"; // reset
            theForm.target = "_top"; // reset
            
            ifr.style.left = ((ssimgLeft + ssimg.offsetWidth) - ifr.offsetWidth) + "px";
            ifr.style.top = (ssimgTop + ssimg.offsetHeight) + "px";
            ifr.style.visibility = "visible";
            
    }

    
}

/*========================================================\
|   Cache images for "Save Job" icon for fastest loading
`========================================================*/

    var jobremove = new Image();
        jobremove.src = "../images/jobdelete.png";
    var jobsave = new Image();
        jobsave.src = "../images/jobsave.png";
    var jobremovedetail = new Image();
        jobremovedetail.src = "../images/jobdeletedetail.png";
    var jobsavedetail = new Image();
        jobsavedetail.src = "../images/jobsavedetail.png";
        
var arrSearchImg = new Array("searchhelp",
                            "searchjobs",
                            "savesearch",
                            "browsereset",
                            "browseadd",
                            "browseremove",
                            "savesearchclose",
                            "applied_note",
                            "applied_note_update");
                            
var arrStates = new Array("norm","over");
    
    for (x=0;x<arrSearchImg.length;x++)
    {
        for (y=0;y<arrStates.length;y++)
        {
            eval(arrSearchImg[x] + "_" + arrStates[y] + " = new Image();");
            eval(arrSearchImg[x] + "_" + arrStates[y] + ".src = '../images/search/" + arrSearchImg[x] + "_" + arrStates[y] + ".png';");
        }
    }
    var savesearch_hot = new Image();
        savesearch_hot.src = "../images/search/savesearch_hot.png";
    var applied_note_hot = new Image();
        applied_note_hot.src = "../images/search/applied_note_hot.png";
        
        
/*========================================================\
|   SavedRemoved
|   requires [String] jobid, [String] type
|   flashes the little baloon "saved" or "Removed"
`========================================================*/

var SavedRemovedTimer = window.setTimeout("void(null)",1); // create initial timer

function SavedRemoved(jobid,sor)
{
    var icon = document.getElementById("jobicon" + jobid);
    var baloon = document.getElementById(sor);
    
        window.clearTimeout(SavedRemovedTimer);
        
        //var OffLeft = icon.offsetLeft + icon.offsetParent.offsetLeft + icon.offsetParent.offsetParent.offsetLeft;
        //var OffTop = icon.offsetTop + icon.offsetParent.offsetTop + icon.offsetParent.offsetParent.offsetTop;
        
        var OffLeft = RecurseOffset(icon,"Left");
        var OffTop = RecurseOffset(icon,"Top");
        
        baloon.style.left = OffLeft + icon.offsetWidth + "px";
        baloon.style.top = OffTop - icon.offsetHeight + "px";
        baloon.style.visibility = "visible";
        
        SavedRemovedTimer = window.setTimeout("SavedRemovedOut()",1500);
}

function SavedRemovedOut()
{
    var saved = document.getElementById("saved");
        saved.style.visibility = "hidden";
        saved.style.left = "1px";
        saved.style.top = "1px";
    var removed = document.getElementById("removed");
        removed.style.visibility = "hidden";
        removed.style.left = "1px";
        removed.style.top = "1px";
}

/*========================================================\
|   SaveJob
|   requires [String] jobid
|   saves job if user is logged in
`========================================================*/
function SaveJob(jobid)
{
    if (UserCookieID==null) // defined in top.aspx
    {
        window.alert("Please register to save jobs.");
        return;
    }
    else
    {
        //ROut();
        //ROInfo('Saved', 'R', 70, '#246802');
        
        var ico = document.getElementById("jobicon" + jobid);
            
        //var tt = window.setTimeout("ROut()",1000);
        

                ico.src = jobremove.src;
                SavedRemoved(jobid,"saved");

            //=============== reset event listeners
            ico.onclick = function()
            {
                RemoveJob(jobid);
            }
            ico.onmouseover = function()
            {
                //ROInfo('Remove Saved Job', 'R', 70, '#000000');
            }
        document.getElementById("savejobtarget").src = "../Components/SaveJob.aspx?JobID=" + jobid + "&Action=Save";
        
    }
}


function resetSavedJobs(increment)
{
    var SavedJobs = GetCookieKeyValue(UserCookieName,"JSJobIds");
    var SavedJobsCount = 0;
    if (SavedJobs.indexOf(",") > -1)
    {
        var tempArray = SavedJobs.split(",");
            SavedJobsCount = tempArray.length;
    }
    else
    {
        if (SavedJobs.length > 0)
        {
            SavedJobsCount = 1;
        }
    }
    
    SavedJobsCount = SavedJobsCount + increment;
    
    if (SavedJobsCount < 0)
    {
        SavedJobsCount = 0;
    }

   switch(SavedJobsCount)
   {
        case 0: 
            var message1 = "You have no saved jobs"; 
            //var message2 = "No saved jobs";
            break;
        case 1: 
            var message1 = "You have <A HREF='../Jobs/Saved.aspx'>1 saved job</A>"; 
            //var message2 = "<A HREF='../Jobs/Saved.aspx'>1 saved job</A>"; 
            break;
        default: 
            var message1 = "You have <A HREF='../Jobs/Saved.aspx'>" + SavedJobsCount + " saved jobs</A>"; 
            //var message2 = "<A HREF='../Jobs/Saved.aspx'>" + SavedJobsCount + " saved jobs</A>"; 
            break;
   }
   
    document.getElementById("SJ").innerHTML = message1;
    //document.getElementById("SJ2").innerHTML = message2;

    
}

/*========================================================\
|   RemoveJob
|   requires [String] jobid, [String] rowtype
|   removes saved job if user is logged in
`========================================================*/
function RemoveJob(jobid)
{
    if (UserCookieID==null) // defined in top.aspx
    {
        window.alert("Please register to save jobs.");
        return;
    }
    else
    {
        //ROut();
        //ROInfo('Removed', 'R', 80, '#961702');
        //var tt = window.setTimeout("ROut()",1000);
        
        var ico = document.getElementById("jobicon" + jobid);
            
                SavedRemoved(jobid,"removed");
                ico.src = jobsave.src;

            //reset event listeners
            ico.onclick = function()
            {
                SaveJob(jobid);
            }

        document.getElementById("savejobtarget").src = "../Components/SaveJob.aspx?JobID=" + jobid + "&Action=Remove";
        resetSavedJobs(-1);
    }
}
/*========================================================\
|   ResetJob
|   called when the user has reached the maximum number 
|   of saved jobs. Job was never saved, so icon is reset.
`========================================================*/
function ResetJob(jobid)
{
    ROut();
    var ico = document.getElementById("jobicon" + jobid);
        ico.src = jobsave.src;
        //reset event listeners
        ico.onclick = function()
        {
            SaveJob(jobid);
        }
        ico.onmouseover = function()
        {
            void(null);
        }
        resetSavedJobs(-1);
}
/*========================================================\
|   mySubnavTimer = creates mySubnavTimer as a timer object
`========================================================*/
var mySubnavTimer = setTimeout("void(null)",1);


/*========================================================\
|   ct
|   requires [Integer] len
|   returns nav to default status after len milliseconds
`========================================================*/
function ct(len) {
    clearTimeout(mySubnavTimer);
    if (len>0) {
        mySubnavTimer = setTimeout("SubNavDefault()",len);
     }
}


/*========================================================\
|   ANYRollover
|   requires [String] anyID, [String] anyIMG
|   swaps an image using getElementById
`========================================================*/
function ANYRollover(anyID, anyIMG) {
    document.getElementById(anyID).src = anyIMG;
}
/*========================================================\
|   PNGRollover
|   requires [String] pngID, [String] pngIMG
|   swaps a pngID using getElementById and CSS
|   works only in IE : .NET decides when to use it
|   using browser detection
`========================================================*/
function PNGRollover(pngID, pngIMG) {
    document.getElementById(pngID).style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=" + pngIMG + ", sizingMethod=scale)";
}

/*========================================================\
|   help
|   requires [String] type, [String] headline, [String] anchor
|   pops open help window, sets headline on page,
|   {optional} scrolls page to anchor
`========================================================*/
function help(type,headline,anchor)
{
    var myWindow = window.open("../Help/default.aspx?type=" + type + "&headline=" + escape(headline) + "&anchor=" +  anchor,"myWindow","left=50,top=50,scrollbars=no,width=500,height=350");
}

/*========================================================\
|   ChangeFormElement
|   requires [Form Object] formEle, [String] value
|   sets form element to value
`========================================================*/
function ChangeFormElement(formEle,value)
{
    formEle.value = value;
}

/*========================================================\
|   CaptureEnterKey
|   captures the user hitting the enter key, submits 
|   appropriate form by checking what form exists in page
`========================================================*/
function CaptureEnterKey() 
{
    if (document.layers)
    {
        document.captureEvents(Event.KEYDOWN);
    }
    document.onkeydown = function (evt) 
    { 
        var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
        if (keyCode == 13)
        {
            if (document.searchadvanced) { Search(document.searchadvanced); }
            if (document.searchbasic) { Search(document.searchbasic); }
            if (document.Login) { Login(); }
        }
    }
}



/*========================================================\
|   SwitchResultDetail
|   requires [Form Object] theForm, [String] resultDetail
|   sets value, submits form
`========================================================*/
function SwitchResultDetail(theForm,resultDetail)
{
    if (theForm.name == "searchbrowse")
    {
        theForm.categories.value = MSBrowse.returnTargetKeys();
     }

    if (theForm.action.value == "")
    {
        theForm.action = "../Jobs/SearchResults.aspx";
        theForm.target = "_top";
	}

        theForm.resultdetail.value = resultDetail;
        theForm.submit();
}

/*========================================================\
|   parseUserQuery
|   requires [String] theQuery
|   returns theQuery parsed using rules
`========================================================*/
function parseUserQuery(theQuery)
{
    theQuery = trim(theQuery);
    var OKRegEx = /[0-9a-z"]/i;
    var rightmostCharacter = theQuery.substr((theQuery.length-1),1);
    var leftmostCharacter = theQuery.substr(0,1);
    while (!OKRegEx.test(rightmostCharacter) && theQuery.length > 3)
    {
        theQuery = theQuery.substr(0,(theQuery.length-1));
        rightmostCharacter = theQuery.substr((theQuery.length-1),1);
    }
    while (!OKRegEx.test(leftmostCharacter) && theQuery.length > 3)
    {
        theQuery = theQuery.substr(1,theQuery.length);
        leftmostCharacter = theQuery.substr(0,1);
    }
    return theQuery;
}

/*========================================================\
|   Search
|   requires [Form Object] theForm
|   validates theForm, submits - used for both forms
`========================================================*/
function SearchBrowse()
{
    var selectedcats = MSBrowse.returnTargetKeys();
    if (selectedcats.length < 1)
    {
        window.alert("Please select at least one category to browse");
        return;
    }
    else
    {
        document.searchbrowse.jobids.value = "";
        document.searchbrowse.categories.value = MSBrowse.returnTargetKeys();
        document.searchbrowse.page.value = "1";
        document.searchbrowse.submit();
    }
}

/*========================================================\
|   Search
|   requires [Form Object] theForm
|   validates theForm, submits - used for both 
|   advanced and basic search
`========================================================*/
function Search(theForm)
{
    var keywords = theForm.keywords;
    var jobids = theForm.jobids;
    var page = theForm.page;
    var radius = theForm.radius;
    var zip = theForm.zip;
    var cityid = theForm.cityid;
    //----------------------------
        jobids.value = "";
        page.value = "";
        keywords.value = trim(keywords.value);
        zip.value = trim(zip.value);

	    keywords.value = parseUserQuery(keywords.value);

		zip.value = trim(zip.value.replace(/^'/,'').replace(/'$/,'').replace(/^"/,'').replace(/"$/,''));
	    
		if (zip.value.length > 0)
		{
			if (zip.value.match(RegExZip))
			{
				cityid.value = zip.value.substring(0,5); 
				// only allow 5 digit zip in search
			}
			if (!isNaN(zip.value.replace(/\-/g,'')) && !( zip.value.length == 5 || zip.value.length == 10) )
			{
				window.alert("Please check the zip code provided");
				return;
			}
		}
		if (zip.value.length == 0)
		{
			radius.selectedIndex = 0;
			cityid.value = "";
		}
    
    //if (theForm.name == "searchbasic")
		//{
			if ( (keywords.value.length < 3) && (zip.value.length < 1) && (theForm.categories.selectedIndex < 1) )
			{
			window.alert("Please provide a keyword, category or city to search.");
			return;
        	}
    //}


//    if (theForm.name == "searchadvanced")
//    {
//        //SC.transposeSelected(); 
//        // uses the MultiSelectNoControlButton Class to define selected elements
//    
//		if ((keywords.value.length < 3) && (theForm.categories.value.length < 1) && (zip.value.length  < 1))
//		{
//			window.alert("Please provide a keyword, category or city to search.");
//			return;
//		}
//	}

    theForm.action = "../Jobs/SearchResults.aspx";
    //theForm.target = "_top";
    
    theForm.submit();
}

/*========================================================\
|   EmptyCityId
|   remove value from cityid
`========================================================*/
function CSSelectCity(cityname, cityid)
{
    if (document.searchadvanced) { theForm = document.searchadvanced; }
    if (document.searchbasic) { theForm = document.searchbasic; }
    if (document.searchhidden) { theForm = document.searchhidden; }
    theForm.zip.value = cityname;
    theForm.cityid.value = cityid;
    Search(theForm);
}


function EmptyCityId(theForm)
{
    theForm.cityid.value = "";
}


/*========================================================\
|   goPage
|   requires [Integer] thePage
|   used in paging through search results, goes to the 
|   page by submitting form
`========================================================*/
function goPage(thePage)
{
    var theForm;
    if (document.searchadvanced) 
    { 
        theForm = document.searchadvanced; 
        //SC.transposeSelected(); // uses the MultiSelectNoControlButton Class to define selected elements
    }
    if (document.searchnational) 
    { 
        theForm = document.searchnational;
        theForm.startpage.value = thePage; 
    }

    if (document.searchbasic) { theForm = document.searchbasic; }
    if (document.searchhidden) { theForm = document.searchhidden; }
    if (document.searchbrowse) { theForm = document.searchbrowse; }
    
        theForm.page.value = thePage;
        
    if (document.searchhidden) 
    {
        theForm.submit(); // no validation or changes needed for hidden form option
    }
    else if (document.searchbrowse) 
    {
        theForm.categories.value = MSBrowse.returnTargetKeys();
        theForm.submit(); 
    }
    else
    {
        theForm.action = "../Jobs/SearchResults.aspx";
        //theForm.target = "_top";
        theForm.submit();
    }
}
/*========================================================\
|   goSearch
|   requires [Integer] SearchId
|   uses form in bottom.aspx to run search based on 
|   saved searchID alone
`========================================================*/
function goSearch(SearchId)
{
    if (SearchId==0)
    {
        window.location.href="../Searches/Saved.aspx";
    }
    else
    {
        document.gosearch.searchid.value=SearchId;
        document.gosearch.submit();
    }
}
    
/*========================================================\
|   PerPage
|   requires [Form Select Object] SelectObj
|   alters number of jobs per page allowed
`========================================================*/
function PerPage(SelectObj)
{
    if (SelectObj.selectedIndex > 0)
    {
        var theForm;
        if (document.searchadvanced) { theForm = document.searchadvanced; }
        if (document.searchbasic) { theForm = document.searchbasic; }
        if (document.searchhidden) { theForm = document.searchhidden; }
        if (document.searchbrowse) { theForm = document.searchbrowse; }
        
            theForm.perpage.value = SelectObj.options[SelectObj.options.selectedIndex].value;
            theForm.page.value = "1";
            //alert(theForm.perpage.value);
            
        if (document.searchhidden) // no form validation needed on the hidden form option
        {
            theForm.submit();
        }
        else if (document.searchbrowse) 
        {
            theForm.categories.value = MSBrowse.returnTargetKeys();
            theForm.submit();
            //SearchBrowse(theForm);
        }
        else
        {
		theForm.submit();
            //Search(theForm);
        }
    }
}

/*========================================================\
|   SwapSearch
|   requires [form object] theForm [String] type
|   changes form type
`========================================================*/
function SwapSearch(theForm,type)
{
    ChangeFormElement(theForm.searchtype,type);
    theForm.action = "../Jobs/SearchResults.aspx";
    if (type == "browse")
    {
        theForm.jobids.value = "";
        theForm.keywords.value = "";
        
    }
    //theForm.target = "_top";
    if (theForm.name == "searchadvanced")
    {
        //SC.transposeSelected(); // uses the MultiSelectNoControlButton Class to define selected categories
    }
    else if (theForm.name == "searchbrowse")
    {
         theForm.categories.value = MSBrowse.returnTargetKeys(); // uses the MultiSelect Class to define selected categories
    }
    theForm.jobids.value = "";
    theForm.submit();
    return;
}


/*========================================================\
|   SearchBasicReset
|   resets basic form
`========================================================*/
function SearchBasicReset()
{
    var theForm     = document.searchbasic;
    var keywords    = theForm.keywords;
   // var andor       = theForm.andor;
    var categories  = theForm.categories;
    var zip         = theForm.zip;
    var radius      = theForm.radius;
    var x;
    //-----------------------------------------
    keywords.value = "";
    //andor[0].checked = true;
    categories.options.selectedIndex = 0;
    zip.value = "";
    radius.options.selectedIndex = 0;
    theForm.action = "../Jobs/SearchResults.aspx";
    //theForm.target = "_top";
}

/*========================================================\
|   SearchAdvancedReset
|   resets advanced form
`========================================================*/
function SearchAdvancedReset()
{
    var theForm     = document.searchadvanced;
    var keywords    = theForm.keywords;
    var andor       = theForm.andor;
    var categories  = theForm.categories;
    var zip         = theForm.zip;
    var radius      = theForm.radius;
    var perpage     = theForm.perpage;
    var sortby      = theForm.sortby;
    var jobfrom     = theForm.jobfrom;
    var timespan    = theForm.timespan;
    
    var x;
    //-----------------------------------------
    keywords.value = "";
    andor[0].checked = true;
    //SC.doResetNoPrompt(); // MultiSelectNoControlButton instance
    zip.value = "";
    radius.options.selectedIndex = 0;
    //perpage.options.selectedIndex = 0;
    sortby[0].checked = true;
    jobfrom[0].checked = true;
    timespan.options.selectedIndex = 0;
    theForm.action = "../Jobs/SearchResults.aspx";
    //theForm.target = "_top";
}

/*========================================================\
|   JobDetail
|   if externallink == "true" then link goes to External.aspx.
|   External.aspx = logging and reporting, etc
`========================================================*/
function JobDetail(theForm,jobdetailid,jobdetailindex,jobdetailtype)
{
    theForm.jobdetailid.value = jobdetailid;
    theForm.jobdetailindex.value = jobdetailindex;
    theForm.jobdetailtype.value = jobdetailtype;
    
    if (theForm.name == "searchadvanced")
    {
        //SC.transposeSelected(); // uses the MultiSelectNoControlButton Class to define selected elements
    }
    else if(theForm.name == "searchbrowse")
    {
        theForm.categories.value = MSBrowse.returnTargetKeys();
    }
    else
    { // do whatever
      }
    
    
    if (jobdetailtype == "external")
    {
        theForm.action = "../Jobs/External.aspx";
        theForm.target = "_new";
        theForm.submit();
        theForm.target = "_top"; //----- reset
    }
    else if (jobdetailtype == "apply")
    {
        if (UserCookieID==null) // defined in top.aspx
        {
		window.location = "../registration/default.aspx";
            //window.alert("Please register to apply for jobs.");
            return;
        }
        var CurrentlyApplying = GetCookieKeyValue(UserCookieName,"CurrentlyApplying");
        if (trim(CurrentlyApplying).indexOf("|") > -1)
        {
            window.alert("Please complete or cancel your current application \nbefore applying to another job.");
            return;
        }
     
        theForm.action = "../Jobs/SearchResults.aspx";
        //theForm.target = "_top";
        
        var ApplyForm = document.applydetail;
        
        ApplyForm.jobids.value = theForm.jobids.value;
        ApplyForm.categories.value = theForm.categories.value;
        ApplyForm.keywords.value = theForm.keywords.value;
        ApplyForm.cityid.value = theForm.cityid.value;
        //ApplyForm.sortby.value = theForm.sortby.value;
        ApplyForm.andor.value = theForm.andor.value;
        //ApplyForm.timespan.value = theForm.timespan.value;
        //ApplyForm.positiontype.value = theForm.positiontype.value;
        ApplyForm.returnto.value = theForm.returnto.value;
        ApplyForm.perpage.value = theForm.perpage.value;
        ApplyForm.page.value = theForm.page.value;
        
        ApplyForm.action = "../Jobs/Apply.aspx";
        ApplyForm.target = "_top";
        ApplyForm.submit();
        
    }
    else
    {
        theForm.action = "../Jobs/Detail.aspx";
        theForm.target = "_top";
        theForm.submit();
    }
    
    
    
}
/*========================================================\
|   GoJobByIndex : 
|   index : position of Job in JobIds Array
`========================================================*/
function GoJobByIndex(theForm,index)
{
    var arrJobIds = theForm.jobids.value.split(",");
        if (theForm.name == "searchadvanced")
        {
            //SC.transposeSelected(); // uses the MultiSelectNoControlButton Class to define selected elements
        }
        JobDetail(theForm,trim(arrJobIds[index]),index);
        
}
/*========================================================\
|   BackToSearchResults : requires {Form Object] theForm
|   Returns to search results from detail page
`========================================================*/
function BackToSearchResults(theForm)
{
        
    if (theForm.name == "searchadvanced")
    {
        //SC.transposeSelected(); 
        // uses the MultiSelectNoControlButton Class to define selected elements
    }
    if (theForm.name == "applydetail")
    {
        theForm.searchtype.value = theForm.returnto.value;
    }
    
    theForm.action = "../Jobs/SearchResults.aspx";
    //theForm.page.value = "1";
    //theForm.target = "_top";
    theForm.submit();

}
/*========================================================\
|   styleDiv
`========================================================*/
function styleDiv(DivID, DivStyleType, DivStyle)
{
    eval("document.getElementById('" + DivID + "').style." + DivStyleType + " = '" + DivStyle + "';");
}

/*========================================================\
|   COOKIES
`========================================================*/
function createCookie(name,value,days)
{
	if (days != undefined)
	{
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else 
	{
	    var expires = "";
	}
	document.cookie = name + "=" + value + expires + "; path=/";
}

function readCookie(name)
{
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++)
	{
		var c = ca[i];
		while (c.charAt(0)==' ') 
		{
		    c = c.substring(1,c.length);
		}
		if (c.indexOf(nameEQ) == 0) 
		{
		    return c.substring(nameEQ.length,c.length);
		}
	}
	return "";
}

function eraseCookie(name)
{
	createCookie(name,"",-1);
}


function GetCookieKeyValue(CookieName,Key)
{
    // UserCookieName defined in top.aspx
    
    var UserCookie = readCookie(CookieName);
    var elements = UserCookie.split("&");
    var x = 0;
    for (x=0;x<elements.length;x++)
    {
        var templine = elements[x].split("=");
        if (trim(templine[0]).toLowerCase() == trim(Key).toLowerCase())
        {
            return trim(templine[1]);
        }
    }
    return "";
}

function CancelApplyPersist()
{
    // UserCookieName defined in top.aspx
    
    var UserCookie = readCookie(UserCookieName);
    var elements = UserCookie.split("&");
    var x = 0;
    var newcookie = new Array();
    var theForm;
    if (document.searchadvanced) { theForm = document.searchadvanced; }
    if (document.searchbasic) { theForm = document.searchbasic; }
    if (document.searchhidden) { theForm = document.searchhidden; }
    
    for (x=0;x<elements.length;x++)
    {
        var templine = elements[x].split("=");
        if (trim(templine[0]).toLowerCase() == "currentlyapplying")
        {
            newcookie.push(templine[0] + "=");
        }
        else
        {
            newcookie.push(templine[0] + "=" + templine[1]);
        }
    }
    createCookie(UserCookieName,newcookie.join("&"));
    var thispage = trim(window.location.href).toLowerCase();
    
    if (thispage.indexOf("/jobs/searchresults.aspx") > -1)
    {
        theForm.submit();
    }
    else if (thispage.indexOf("/jobs/detail.aspx") > -1)
    {
        GoJobByIndex(theForm,parseInt(theForm.jobdetailindex.value,10));
    }
    else if (thispage.indexOf("/jobs/apply.aspx") > -1)
    {
        window.location.href = "../Home/";
    }
    else
    {
        window.location.href = window.location.href;
    }
    
}

/*========================================================\
|   Component Window
`========================================================*/

function ComponentWindow()
{
    this.CachedClass = "";
    this.HighClass = "";
    this.Target = document.getElementById("componenttarget");
    this.AlignObj = null;
    
    /*========================================================\
    |   Open Window, align to target
    `========================================================*/
    ComponentWindow.prototype.openComponent = function(Url,Width,Height,AlignObjID,Align,AlignObjClass)
    {
        with (this)
        {
            if (AlignObj!=null)
            {
                closeComponent();
            }
            AlignObj = document.getElementById(AlignObjID);
            CachedClass = AlignObj.className;
            AlignObj.className = AlignObjClass;
            
            Target.src = Url;
            Target.style.width = Width + "px";
            Target.style.height = Height + "px";
            
            switch (Align)
            {
                case "LL": // left, lower
                    Target.style.left = RecurseOffset(AlignObj,"Left") + "px";
                    Target.style.top = (RecurseOffset(AlignObj,"Top") + AlignObj.offsetHeight) + "px";
                    break;
                case "CL": // center, lower
                    Target.style.left = (RecurseOffset(AlignObj,"Left") + parseInt(AlignObj.offsetWidth / 2,10)) - parseInt(Target.offsetWidth / 2,10) + "px";
                    Target.style.top = (RecurseOffset(AlignObj,"Top") + AlignObj.offsetHeight) + "px";
                    break;
                case "RL": // right, lower
                    Target.style.left = ((RecurseOffset(AlignObj,"Left") + AlignObj.offsetWidth) - Target.offsetWidth) + "px";
                    Target.style.top = (RecurseOffset(AlignObj,"Top") + AlignObj.offsetHeight) + "px";
                    break;
            }
            
            this.Target.style.visibility = "visible";
        }
        
    }
    
    /*========================================================\
    |   Close Window, reset
    `========================================================*/
    ComponentWindow.prototype.closeComponent = function()
    {
        with (this)
        {
            AlignObj.className = this.CachedClass.replace("Over","Norm");
            Target.src = "../Components/Default.aspx";
            Target.style.width = "1px";
            Target.style.height = "1px";
            Target.style.left = "1px";
            Target.style.top = "1px";
            Target.style.visibility = 'hidden';
        }
    }

    /*========================================================\
    |   Resize height
    `========================================================*/
    ComponentWindow.prototype.resizeHeight = function(newheight)
    {
        with (this)
        {
            Target.style.height = newheight + "px";
        }
    }
    
    /*========================================================\
    |   Resize width
    `========================================================*/
    ComponentWindow.prototype.resizeWidth = function(newwidth)
    {
        with (this)
        {
            Target.style.width = newwidth + "px";
        }
    }
}


/*
----------------------------------
---------- Calculator ------------
----------------------------------
*/
function calculator(formEle,OnCloseEvent) {
		
		//AllSelectsVisibility('hidden');
	var myUrl = '../components/calculator.aspx?formEle=' + formEle + '&OnCloseEvent=' + escape(OnCloseEvent);
	
	var IFrm = document.getElementById('componenttarget');
		IFrm.style.visibility = 'visible';
		IFrm.style.width = "1px";
		IFrm.style.height = "1px";
		IFrm.style.left = document.umouse.x.value + "px";
		IFrm.style.top = document.umouse.y.value + "px";
		IFrm.src = myUrl;
}

function closecalculator() {
        var IFrm = document.getElementById('componenttarget');
	        IFrm.style.visibility = 'hidden';
		    IFrm.style.left = "1px";
		    IFrm.style.top = "1px";
}



function CleanWordHTML( html, bIgnoreFont, bRemoveStyles, bRemoveMargins, bRemovePadding )
{
	html = html.replace(/<o:p>\s*<\/o:p>/g, "") ;
	html = html.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
	
	// Remove mso-xxx styles.
	html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;

	// Remove margin styles.
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;
	html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;
	html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;
	html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;
	html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
	html = html.replace( /\s*tab-stops:[^"]*/gi, "" ) ;

	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;
    
    if ( bRemovePadding )
	{
        html = html.replace( /<(\w[^>]*) style="padding([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
    }
    
    if ( bRemoveMargins )
	{
        html = html.replace( /<(\w[^>]*) style="margin([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
    }
    
	// Remove FONT face attributes.
	if ( bIgnoreFont )
	{
		html = html.replace( /\s*face="[^"]*"/gi, "" ) ;
		html = html.replace( /\s*face=[^ >]*/gi, "" ) ;
		html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
	}
	
	// Remove styles.
	if ( bRemoveStyles )
	{
		html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;
    }
    
	// Remove empty styles.
	html = html.replace( /\s*style="\s*"/gi, '' ) ;
	html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
	html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
	
	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;
	html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;

	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
	
	// Remove Tags with XML namespace declarations: <o:p><\/o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
	
	html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
	html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
	html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
	html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
	html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
	html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;
	html = html.replace( /<\/H\d>/gi, '<\/font><\/b><\/div>' ) ;
	html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

	// Remove empty tags (three times, just to be sure).
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;

	// Transform <P> to <DIV>
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;	// Different because of a IE 5.0 error
	html = html.replace( re, "<div$2<\/div>" ) ;

	return html ;
}

