﻿/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//
// WORK
//
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

var LastSelection_Work = false;
var objWwdTitles = { 'WWD_AppDevelopment':'Application Development',
                     'WWD_WebDevelopment':'Web Development',
                     'WWD_StaffAug':'Staff Augmentation',
                     'WWD_SoftMaint':'Software Maintenance',
                     'WWD_ITServices':'IT Services',
                     'WWD_DataStorage':'Data Storage' };

var RefreshingWorkDescriptionTimeout;

function LoadWhatWeDo(refTagId,reset)
{    
    // every time navigation changes, this object is set to 'none' due to
    // ie css layering behavior
    docObj('wwd_descriptions').style.display = 'block';
    
    var parentId = refTagId;
    var targetId = parentId.replace('_Link','');
    var targetObj = docObj(targetId);
    
    clearTimeout(RefreshingWorkDescriptionTimeout);
    
    // whenever we would navigate from another section to the work section, the nature of the css
    // involved with the WWD divs is that it would layer on top of the footer as it was rising.  This
    // didn't look right so I'm basically forcing all of them to 0 opacity, then callin' this function again.
    if (reset)
    {
        for (var obj in objWwdTitles)
            forceOpacity(0, obj);
            
        RefreshingWorkDescriptionTimeout = setTimeout('LoadWhatWeDo("'+refTagId+'",false)',200);
        return;
    }
    
    if (LastSelection_Work)
    {
        var lastObj = docObj(LastSelection_Work);
        lastObj.style.zIndex = 1;
        docObj(LastSelection_Work+'_Link').className = 'link_deselected';
    }
    docObj(parentId).className = 'link_selected';
 
    docObj('wwd_ElementHead').innerHTML = objWwdTitles[targetId];
    
    if (lastObj)
        targetObj.style.height = lastObj.offsetHeight+'px';
    
    forceOpacity(0, targetId);
    
    targetObj.style.zIndex = 2;
    doOpacity(targetId, 0, 100, 250, 'block');
    
    LastSelection_Work = targetId;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//
// CAREER
//
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

function SetJobListDiv(active)
{
    var obj = docObj('jobListingDrop'); 
    if (active)
    {
        var refObj = docObj('job_title');
        var refPos = findPos(refObj);
        
        obj.style.top  = (14+refPos.top)+'px';
        obj.style.left = refPos.left+'px';
        
        obj.className = 'jobListDropDivShow';
    }
    else
        obj.className='jobListDropDivHide';       
}

function CreateListItems()
{        
    var jobs = new JobList();
    for (var i = 0; i < OmniJobsForDDL.jobs.length; i++)
    {
        var _job = null;
        _job = new jobDefinition(OmniJobsForDDL.jobs[i].id,OmniJobsForDDL.jobs[i].title,'');
        if(_job != null)
            jobs.AddJob(_job);
    }
    
    var elementDDL = docObj('jobListingDrop');
    for(var i = 0; i < jobs.count(); i++)
    {            
        var job = jobs.GetJobAtIndex(i);
        listItem = job.GetListItemDDL();
        elementDDL.appendChild(listItem);
    }        
    jobs = null;
}

function JobList()
{
    this.jobArray = new Array();
    this.count = function() {return this.jobArray.length;}
    
    this.AddJob = function (job)
    {            
        this.jobArray.push(job);
    }
    
    this.GetJobAtIndex = function (jIndex)
    {
        return this.jobArray[jIndex];
    }
}

function jobDefinition(jobId,jobName,jobSampleText)
{
    this.id = jobId;
    this.name = jobName;
    this.sampleText = jobSampleText;
    
    //Create clickable lightbox link    
    this.GetListItemLinks = function()
    {        
        var listItem = document.createElement("div");
        listItem.id = 'div_' + this.name + '_' + this.id;
        //listItem.value = jobId;
        var AnchorLink = document.createElement("A");
        AnchorLink.href='#';
        AnchorLink.onclick = function(){JobDescriptionDisplay(jobId);return false;};            
        AnchorLink.appendChild(document.createTextNode(this.name));
        listItem.appendChild(AnchorLink);
        listItem.appendChild(document.createElement("BR"));
        return listItem;
    }
    
    //Create custom DDL List Item       
    this.GetListItemDDL = function()
    {
        var listItem = document.createElement("div");
        listItem.id = 'li_' + this.name + '_' + this.id;
        listItem.appendChild(document.createTextNode(this.name));
        listItem.className = 'jobListItemOff';

        //Add select events                         
        listItem.onmouseover = function(){ this.className = 'jobListItemOn'; };
        listItem.onmouseout  = function(){ this.className = 'jobListItemOff'; };
        listItem.onclick     = function(){ selectThisJobForApp(jobId); SetJobListDiv(false); }
        return listItem;
    }
}

function selectThisJobForApp(id)
{
    docObj('job_title_id').value = id;
    for (var i = 0; i < OmniJobsForDDL.jobs.length; i++)
    {
        if (OmniJobsForDDL.jobs[i].id == id)
        {
            docObj('job_title').value = OmniJobsForDDL.jobs[i].title;
            break;
        }    
    }
}

// Application Form
var ApplicantInformation;
var WaitingForResume = false;

var jobFrameName = 'hiddenJobFrame';
var jobFrameResumeInput = 'resumeFile';
var jobResumeTextInput = 'job_resume';
var jobPostReturnDiv = 'result';    
var jobPostCurrentAction = '';
var jobResumeFilename = '';
var jobPostTimeCheck = 100;
var jobPostTimeCount = 0;
var jobPostTimeMaxCount = 50;  

function valAppForm()
{    
    var returnType = true;
    var formId = 'career';
    var arFlds = [['job_title','job',true],['job_name','name',true],['job_phone','phone',true],
                  ['job_email','email',true],['job_resume','resume',false]];

    resetFldFocus(arFlds[0][0]);
    
    for (var i = 0; i < arFlds.length; i++)
    {
        if (! valFields(arFlds[i]))
            returnType = false;
    }
    
    if (!returnType)
        var nothing;
    else
    {
        AppInformation = 
                    { "job" : { "id" : docObj('job_title_id').value, "title" : docObj('job_title').value },
                      "name" : docObj('job_name').value,
                      "phone" : docObj('job_phone').value,
                      "email" : docObj('job_email').value,
                      "comments" : docObj('job_message').value,
                      "resume" : "" };

        arFlds[arFlds.length] = ['job_message'];
        arFlds[arFlds.length] = ['jobSubmit'];
        arFlds[arFlds.length] = ['jobReset'];   

        initFormProcessingAnimation(formId);
        
    var AjaxParams  = "InjectionFree=true&AjaxAction=Save_Application&ID="+AppInformation.job.id;
        AjaxParams += "&Name="+AppInformation.name+"&Phone="+AppInformation.phone+"&Email="+AppInformation.email;
	    AjaxParams += "&Message="+AppInformation.comments+"&Resume=";
	    
        FormObjAjax.CurrentForm      = formId;
        FormObjAjax.FieldCollection  = arFlds;
        FormObjAjax.AjaxParams       = AjaxParams;
        FormObjAjax.ObjectCollection = AppInformation;
        
        if (docObj('job_resume').value.length > 8)
        {
            setTimeout("changeStatusMsg('Uploading Resume...','career');",350);
            
            var injectionFree = docObj(jobFrameName).contentWindow.document.createElement('input');
                injectionFree.name = 'InJectionFree'; injectionFree.id = 'InJectionFree';                
            docObj(jobFrameName).contentWindow.document.forms[0].appendChild(injectionFree);
            
            docObj(jobFrameName).contentWindow.document.forms[0].submit();            
        }
        else
            FormObjAjax.Timer.Load = setTimeout('doHttpFormPost();',1000);
    }
}

function resumeUploadComplete(json)
{
    var AppResume = json;
    
    if (AppResume.success)
    {
        AppInformation.resume = AppResume.fileName;        
        FormObjAjax.AjaxParams += AppResume.fileName;
        FormObjAjax.Timer.Load = setTimeout('doHttpFormPost();',500);
    }
    else
    {
        throwFormSubmitError(2);
        return false;
    }
}

//Simulates file input type. Copies selected file to form input
function jobShowResumeName()
{        
    try
    {
        var frameObj = docObj(jobFrameName);            
        if (frameObj)
        {            
            var inputObj = frameObj.contentWindow.document.getElementById(jobFrameResumeInput);
            if (inputObj)
            {    
                var textObj = docObj(jobResumeTextInput)
                if (textObj && textObj.value != inputObj.value)
                    textObj.value = inputObj.value;
            }
            else
                return;
        }
        else
            return;
    }
    catch(exp)
    {
        //frame unavailable         
        if(docObj(jobResumeTextInput) != null)
            docObj(jobResumeTextInput).value = '';
    }
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//
// CONTACT
//
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

function valContactForm()
{
    var returnType = true;
    var formId = 'contact';
    var arFlds = [['contact_name','name',true],['contact_phone','phone',true],['contact_email','email',true],
                  ['contact_subject','',false],['contact_comments','',true]];

    resetFldFocus(arFlds[0][0]);

    for (var i = 0; i < arFlds.length; i++)
    {
        if (! valFields(arFlds[i]))
            returnType = false;
    }
    
    if (!returnType)
        var nothing;
    else
    {       
        ContactInformation = 
                    { "name" : docObj('contact_name').value,
                      "phone" : docObj('contact_phone').value,
                      "email" : docObj('contact_email').value,
                      "subject"  : docObj('contact_subject').value, 
                      "comments" : docObj('contact_comments').value };

        arFlds[arFlds.length] = ['contactSubmitButton'];
        arFlds[arFlds.length] = ['contactReset'];

    var AjaxParams  = "InjectionFree=true&AjaxAction=Save_Comment&Name="+ContactInformation.name;
        AjaxParams += "&Subject="+ContactInformation.subject+"&Phone="+ContactInformation.phone;
	    AjaxParams += "&Email="+ContactInformation.email+"&Comment="+ContactInformation.comments
	    
        initFormProcessingAnimation(formId);
        setTimeout("changeStatusMsg('Sending Contact Information...','contact');",350);
        
        FormObjAjax.CurrentForm      = formId;
        FormObjAjax.FieldCollection  = arFlds;
        FormObjAjax.AjaxParams       = AjaxParams;
        FormObjAjax.ObjectCollection = ContactInformation;
        FormObjAjax.Timer.Load = setTimeout('doHttpFormPost();',1000);        
    }
}

function showGMapLocation()
{
    loadOmniBox(docObj('divGMap'),355,500);
    docObj('ifrmGMap').src = 'map.aspx';
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//
// HOME
//
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

function FeedBackOver(img,fb_display)
{
    var obj = docObj('img_feedback_thumb');
        
    if(fb_display)
    {
        var absPos = findPos(img);
        obj.className = 'feedback_thumb_show';
        obj.style.top = absPos.top;
        obj.style.left = (absPos.left-obj.width-3)+'px';
    }
    else
        obj.className = 'feedback_thumb_hide';
}

function RssOver(SourceImg,doDisplay)
{
    if(doDisplay)
        SourceImg.src = 'images/feedicon_clr.gif';
    else
        SourceImg.src = 'images/feedicon.gif';
}

function GotoWWD(_wwd_id)
{    
    //Show Work Tab
    OmniCordion.display(3);

    //Display WWD Link
    count = 0;
    for (var o in objWwdTitles)
    {
        count++;
        if (count == _wwd_id)
        {
            forceOpacity(0,o);
            setTimeout("LoadWhatWeDo('"+o+"_Link',true);",40);
            break;
        }
    }
    return false;
}

// global feedback object
var FeedbackObj = { LastFeedbackId:0, FeedbackImgTag:'' };

function getNextFeedbackItem()
{
    var AjaxParams = 'InjectionFree=true&AjaxAction=LoadFeedback&Id='+FeedbackObj.LastFeedbackId;       
    doHttpGet(AjaxParams);
}
function writeNewFeedback(Feedback)
{
    docObj('spnFeedbackQuote').innerHTML = '"' + txt2Html(Feedback.quote) + '"';
    docObj('lnkFeedbackTitle').innerHTML = Feedback.name;
    docObj('spnFeedbackBiz').innerHTML = txt2Html(Feedback.business);

    FeedbackObj.LastFeedbackId = Feedback.id;
    FeedbackObj.FeedbackImgTag = Feedback.imageTag;
    
    docObj('lnkFeedbackTitle').href = 'images/feedback/'+FeedbackObj.FeedbackImgTag+'_b.jpg';
    docObj('lnkFeedbackThumbIcon').href = 'images/feedback/'+FeedbackObj.FeedbackImgTag+'_b.jpg';
    
    docObj('img_feedback_thumb').src = 'images/feedback/'+FeedbackObj.FeedbackImgTag+'.jpg';

    var arImgList = '';
    for (var i = 0; i < Feedback.ImageTags.length; i++)
    {
        arImgList += '<a href="images/feedback/'+Feedback.ImageTags[i]+'_b.jpg" rel="lytebox[feedback]" />';
    }
    
    docObj('spnFeedbackImgCollection').innerHTML = arImgList;
}

/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//
// HELP DESK
//
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////

function hideHelpDeskMask(obj)
{
    if (obj.id == 'Code')
    {
        docObj('divHelpDeskMask').innerHTML = '&nbsp;';
        docObj('divHelpDeskMask').style.width = '1px';        
    }
    else
    {
        obj.innerHTML = '&nbsp;';
        obj.style.width = '1px';
     
        if (obj.parentNode.childNodes[0])
            obj.parentNode.childNodes[0].focus();
        else
            obj.parentNode.childNodes[1].focus();
    }
}

function doHelpDeskSubmit()
{
    var form = document.forms[0];
    var ViewStateFld = docObj('__VIEWSTATE');
    
    form.method = 'post';
    form.action = 'https://secure.logmeinrescue.com/Customer/Code.aspx';
    form.target = '_HelpDesk';

    // We have to do this because you can't post a viewstate to
    // another .NET site.
    ViewStateFld.parentNode.removeChild(ViewStateFld);
    
    form.submit();
}

/////////////////////////////////////////////////////////////
// HTTP
// The Main Http Method to handle form submissions.
// This function is used by contact, career, and the blog.
//
/////////////////////////////////////////////////////////////

function doHttpFormPost()
{
	if (! FormObjAjax.IsActive)
	{       
	    try
	    {
		    FormObjAjax.SetActive(true);
		    FormObjAjax.StartClocking(FormObjAjax.CurrentForm);
            
		    httpFormPost.open('POST', FormObjAjax.BasePath + '/controls/ajaxLib.aspx', true);
		    httpFormPost.onreadystatechange = function() {

			    if (httpFormPost.readyState == 4)
			    {
			        if (httpResponseIsValid(httpFormPost))
                    {
                        var _json = httpFormPost.responseText.replace(/\\\"/g,'"');
                        var ResultObj = eval('(' + _json + ')');

                        if (ResultObj.success == 'true')
                            throwFormSubmitSuccess(FormObjAjax.ObjectCollection);
                        else
                            throwFormSubmitError(0);
			        }
			        else
			            throwFormSubmitError(0);
			    }
			        
		    };
		    httpFormPost.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		    httpFormPost.send(FormObjAjax.AjaxParams);

	    }
	    catch (e)
	    {
		    throwFormSubmitError(0);
	    }
    }
}

function doHttpGet(AjaxParams)
{
	if (! GetObjAjax.IsActive)
	{       
	    try
	    {
		    GetObjAjax.SetActive(true);

		    httpGet.open('GET', GetObjAjax.BasePath + '/controls/ajaxLib.aspx?'+AjaxParams, true);
		    httpGet.onreadystatechange = function() {

			    if (httpResponseIsValid(httpGet))
			    {
                    try
                    {
                        var _json = httpGet.responseText.replace(/\\\"/g,'"');
                        var ResultObj = eval('(' + _json + ')');

                        if (ResultObj.success == 'true')
                        {
			                if (ResultObj.Feedback)
			                {			            
			                    GetObjAjax.Timer.ReLoad(setTimeout('getNextFeedbackItem();',15000));
			                    writeNewFeedback(ResultObj.Feedback);
			                }
			                else
			                {
			                    //left this open for other possible uses
			                }
			            }
			            GetObjAjax.SetActive(false);
			        }
			        catch (e)
			        {
			            GetObjAjax.Timer.ReLoad(setTimeout('getNextFeedbackItem();',10000));
			        }
			    }
			    else
			    {
			        GetObjAjax.Timer.ReLoad(setTimeout('getNextFeedbackItem();',350));
			    }
			        
		    };
		    httpGet.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		    httpGet.send(null);
	    }
	    catch (e)
	    {
		    // exit without a fuss
	    }
    }
}