﻿

function identifyCurrPagePromo() 
{
    var tdCurr
 
    if (window.location.pathname.toLowerCase().indexOf('default.aspx') > -1 || window.location.pathname == '/')
        tdCurr = document.getElementById('tdMenuHome')
    else if (window.location.pathname.toLowerCase().indexOf('techstuff.aspx') > -1)
        tdCurr = document.getElementById('tdMenuTechStuff')
    else if (window.location.pathname.toLowerCase().indexOf('buy.aspx') > -1 )
        tdCurr = document.getElementById('tdMenuBuy')
    else if (window.location.pathname.toLowerCase().indexOf('contact.aspx') > -1)
        tdCurr = document.getElementById('tdMenuContact')
    else
        return


    tdCurr.style.background = 'url(Images/btnMenu_c.jpg) no-repeat'
}

function identifyCurrPage() 
{
    var oElem
    var arrElemChildLinks

    if (window.location.pathname.toLowerCase().indexOf('clientschedule.aspx') > -1)
        oElem = document.getElementById('aClientSchedule')
    else if (window.location.pathname.toLowerCase().indexOf('schedule.aspx') > -1)
        oElem = document.getElementById('aSchedule')
    else if (window.location.search.toLowerCase().indexOf('availability') > -1)
        oElem = document.getElementById('aAvailable')
    else if (window.location.search.toLowerCase().indexOf('working') > -1)
        oElem = document.getElementById('aWorking')
    else if (window.location.pathname.toLowerCase().indexOf('textview.aspx') > -1)
        oElem = document.getElementById('aTextView')
    else if (window.location.pathname.toLowerCase().indexOf('fewclickscheduling.aspx') > -1)
        oElem = document.getElementById('aFewClick')
    else if (window.location.pathname.toLowerCase().indexOf('tasks.aspx') > -1)
        oElem = document.getElementById('aTasks')
    else if (window.location.pathname.toLowerCase().indexOf('manageleave.aspx') > -1)
        oElem = document.getElementById('aManageLeave')
    else if (window.location.pathname.toLowerCase().indexOf('clients.aspx') > -1)
        oElem = document.getElementById('aClients')
    else if (window.location.pathname.toLowerCase().indexOf('reports.aspx') > -1)
        oElem = document.getElementById('aReports')
    else if (window.location.pathname.toLowerCase().indexOf('payroll.aspx') > -1)
        oElem = document.getElementById('aPayroll')
    else if (window.location.pathname.toLowerCase().indexOf('settings.aspx') > -1)
        oElem = document.getElementById('aSettings')
    else if (window.location.pathname.toLowerCase().indexOf('licenses.aspx') > -1)
        oElem = document.getElementById('aLicenses')
    else if (window.location.pathname.toLowerCase().indexOf('login.aspx') > -1)
        oElem = document.getElementById('spnLogin')
    else if (window.location.pathname.toLowerCase().indexOf('faq.aspx') > -1)
        oElem = document.getElementById('aFAQ')
    else
        return

    if (oElem) {
        arrElemChildLinks = oElem.getElementsByTagName('A')

        if (arrElemChildLinks.length > 0)
            arrElemChildLinks[0].style.color = '#0073E6'
        else
            oElem.style.color = '#0073E6'
    }
        
    
}

function btnMenu_onmouseover()
{
    var arrChildLinks

    if (!((this.id == 'aClientSchedule' && window.location.pathname.toLowerCase().indexOf('clientschedule.aspx') > -1)
        || (this.id == 'aSchedule' && window.location.pathname.toLowerCase().indexOf('schedule.aspx') > -1)
        || (this.id == 'aAvailable' && window.location.search.toLowerCase().indexOf('availability') > -1)
        || (this.id == 'aWorking' && window.location.search.toLowerCase().indexOf('working') > -1)
        || (this.id == 'aTextView' && window.location.pathname.toLowerCase().indexOf('textview.aspx') > -1)
        || (this.id == 'aFewClick' && window.location.pathname.toLowerCase().indexOf('fewclickscheduling.aspx') > -1)
        || (this.id == 'aTasks' && window.location.pathname.toLowerCase().indexOf('tasks.aspx') > -1)
        || (this.id == 'aManageLeave' && window.location.pathname.toLowerCase().indexOf('manageleave.aspx') > -1)
        || (this.id == 'aClients' && window.location.pathname.toLowerCase().indexOf('clients.aspx') > -1)
        || (this.id == 'aReports' && window.location.pathname.toLowerCase().indexOf('reports.aspx') > -1)
        || (this.id == 'aPayroll' && window.location.pathname.toLowerCase().indexOf('payroll.aspx') > -1)
        || (this.id == 'aSettings' && window.location.pathname.toLowerCase().indexOf('settings.aspx') > -1)
        || (this.id == 'aLicenses' && window.location.pathname.toLowerCase().indexOf('licenses.aspx') > -1)
        || (this.id == 'spnLogin' && window.location.pathname.toLowerCase().indexOf('login.aspx') > -1)
        || (this.id == 'aFAQ' && window.location.pathname.toLowerCase().indexOf('faq.aspx') > -1)))
    {
        arrChildLinks = this.getElementsByTagName('A')
        
        if (arrChildLinks.length > 0)
            arrChildLinks[0].style.color = '#0073E6'
        else
            this.style.color = '#0073E6'
    }
}

function btnMenu_onmouseout()
{
    var arrChildLinks

    if (!((this.id == 'aClientSchedule' && window.location.pathname.toLowerCase().indexOf('clientschedule.aspx') > -1)
        || (this.id == 'aSchedule' && window.location.pathname.toLowerCase().indexOf('schedule.aspx') > -1)
        || (this.id == 'aAvailable' && window.location.search.toLowerCase().indexOf('availability') > -1)
        || (this.id == 'aWorking' && window.location.search.toLowerCase().indexOf('working') > -1)
        || (this.id == 'aTextView' && window.location.pathname.toLowerCase().indexOf('textview.aspx') > -1)
        || (this.id == 'aFewClick' && window.location.pathname.toLowerCase().indexOf('fewclickscheduling.aspx') > -1)
        || (this.id == 'aTasks' && window.location.pathname.toLowerCase().indexOf('tasks.aspx') > -1)
        || (this.id == 'aManageLeave' && window.location.pathname.toLowerCase().indexOf('manageleave.aspx') > -1)
        || (this.id == 'aClients' && window.location.pathname.toLowerCase().indexOf('clients.aspx') > -1)
        || (this.id == 'aReports' && window.location.pathname.toLowerCase().indexOf('reports.aspx') > -1)
        || (this.id == 'aPayroll' && window.location.pathname.toLowerCase().indexOf('payroll.aspx') > -1)
        || (this.id == 'aSettings' && window.location.pathname.toLowerCase().indexOf('settings.aspx') > -1)
        || (this.id == 'aLicenses' && window.location.pathname.toLowerCase().indexOf('licenses.aspx') > -1)
        || (this.id == 'spnLogin' && window.location.pathname.toLowerCase().indexOf('login.aspx') > -1)
        || (this.id == 'aFAQ' && window.location.pathname.toLowerCase().indexOf('faq.aspx') > -1)))
    {
        
        arrChildLinks = this.getElementsByTagName('A')
        if (arrChildLinks.length > 0)
            arrChildLinks[0].style.color = '#000000'
        else
            this.style.color = '#000000'
    }
}

function btnMenuPromo_onmouseover() 
{

    if (!((this.id == 'tdMenuHome' && (window.location.pathname.toLowerCase().indexOf('default.aspx') > -1 || window.location.pathname == '/'))
        || (this.id == 'tdMenuTechStuff' && window.location.pathname.toLowerCase().indexOf('techstuff.aspx') > -1)
        || (this.id == 'tdMenuBuy' && window.location.pathname.toLowerCase().indexOf('buy.aspx') > -1)
        || (this.id == 'tdMenuContact' && window.location.pathname.toLowerCase().indexOf('contact.aspx') > -1))) 
    {
        this.style.background = 'url(Images/btnMenu_b.jpg) no-repeat'
    }
   
}

function btnMenuPromo_onmouseout() 
{
    if (!((this.id == 'tdMenuHome' && (window.location.pathname.toLowerCase().indexOf('default.aspx') > -1 || window.location.pathname == '/'))
        || (this.id == 'tdMenuTechStuff' && window.location.pathname.toLowerCase().indexOf('techstuff.aspx') > -1)
        || (this.id == 'tdMenuBuy' && window.location.pathname.toLowerCase().indexOf('buy.aspx') > -1)
        || (this.id == 'tdMenuContact' && window.location.pathname.toLowerCase().indexOf('contact.aspx') > -1))) 
    {
        this.style.background = 'url(Images/btnMenu_a.jpg) no-repeat'
    } 
    
}

function writeEmail(strPart) {

    switch (strPart) {
        case 'con':
            document.write('<a href="mailto:')
            writeEmail('con2')
            break
        case 'con2':
            document.write('con')
            writeEmail('con3')
            break
        case 'con3':
            document.write('tact')
            writeEmail('con4')
            break
        case 'con4':
            document.write('@on-sch')
            writeEmail('con5')
            break
        case 'con5':
            document.write('edule.org')
            writeEmail('con6')
            break
        case 'con6':
            document.write('">con')
            writeEmail('con7')
            break
        case 'con7':
            document.write('tact')
            writeEmail('con8')
            break
        case 'con8':
            document.write('@on-sch')
            writeEmail('con9')
            break
        case 'con9':
            document.write('edule.org</a>')
            break
    }
}

function writePhone(strPart) {

    switch (strPart) {
        case 'mob':
            document.write('777')
            writePhone('mob2')
            break
        case 'mob2':
            document.write('96')
            writePhone('mob3')
            break
        case 'mob3':
            document.write('41')
            writePhone('mob4')
            break
        case 'mob4':
            document.write('375')
    }
}

function btnTryOut_onmouseover() 
{
    this.style.border = '2px solid #999999'
}

function btnTryOut_onmouseout() 
{
    this.style.border = '2px solid #FFFFFF'
}

function areYouSure(strMsg) 
{
    return confirm('Are you sure you want to ' + strMsg)
}

function colourCombos() 
{

    var arrCombos = document.getElementsByTagName('SELECT')

    for (var nIndex = 0; nIndex < arrCombos.length; nIndex++) 
    {
        if(arrCombos[nIndex].length > 0)
        {
            arrCombos[nIndex].style.backgroundColor = arrCombos[nIndex].options[arrCombos[nIndex].selectedIndex].style.backgroundColor;
            arrCombos[nIndex].style.color = arrCombos[nIndex].options[arrCombos[nIndex].selectedIndex].style.color;
        }
    }

}

function fillDateTimeCurr()
{
    var arrCombos = document.getElementsByTagName('INPUT')
    var dt = new Date();
    var nMins, nHourIndex;
    
    for (var nIndex = 0; nIndex < arrCombos.length; nIndex++) 
    {
        if (arrCombos[nIndex].id.indexOf('dpVisitCancelDate_') > -1
            || arrCombos[nIndex].id.indexOf('dpClientNoteDateTime') > -1
            || arrCombos[nIndex].id.indexOf('dpDocDate') > -1) 
        {
            if (arrCombos[nIndex].value.trim() == '')
            {
                arrCombos[nIndex].value = (dt.getMonth() + 1) + "/" + dt.getDate() + "/" + dt.getFullYear();
            }
        }
    }

    arrCombos = document.getElementsByTagName('SELECT')

    for (var nIndex = 0; nIndex < arrCombos.length; nIndex++) 
    {
        if (arrCombos[nIndex].id.indexOf('cbxVisitCancel') > -1 
            || arrCombos[nIndex].id.indexOf('cbxClientNote') > -1) 
        {
            if (arrCombos[nIndex].value == '') 
            {
                arrCombos[nIndex].selectedIndex = dt.getHours() + 1;
                nHourIndex = nIndex;
                do
                {
                    nIndex++;
                    if (arrCombos[nIndex].id.indexOf('cbxVisitCancel') > -1 || arrCombos[nIndex].id.indexOf('cbxClientNote') > -1) 
                    {
                        nMins = Math.round(dt.getMinutes() / 15) * 15
                        if (nMins == 60) {
                            arrCombos[nIndex].selectedIndex = 1;
                            arrCombos[nHourIndex].selectedIndex++;
                        }
                        else 
                        {
                            arrCombos[nIndex].selectedIndex = (nMins / 15) + 1;
                        }
                    }
                }
                while(arrCombos[nIndex].id.indexOf('cbxVisitCancel') < 0 && arrCombos[nIndex].id.indexOf('cbxClientNote') < 0)
            }
        }
    }
}

function slideFewClickTotals(nDay) 
{
    var divFewClickTotals = document.getElementById('divFewClickTotals')
    var tblShiftsForCurr = document.getElementById('ctl00_Main_tblShifts_' + nDay)
    var tblShiftsForFirst = document.getElementById('ctl00_Main_tblShifts_1')
    
    divFewClickTotals.style.marginTop =  (tblShiftsForCurr.offsetTop - tblShiftsForFirst.offsetTop) + 'px'
}

function addLoadEvent(func) 
{

    var funcOnloadOld = window.onload;
    if (typeof window.onload != 'function') 
    {
        window.onload = func;
    } 
    else 
    {
        window.onload = function() 
        {
            if (funcOnloadOld) 
            {
                funcOnloadOld();
            }
            func();
        }
    }
}


function btnFinaliseSignup_Click() 
{
    setUpQueryStringStore()
    window.location.href = 'buy.aspx?action=finalise&company=' + arrQueryString['company'];
}

var arrQueryString = new Array()

function setUpQueryStringStore() 
{
  var arrNameValueStrings = window.location.search.substring(1).split("&");
  for (var i=0;i<arrNameValueStrings.length;i++) 
  {
    var arrNameValue = arrNameValueStrings[i].split("=");
    arrQueryString[arrNameValue[0]] = arrNameValue[1];
  }
}

function videoInsert(strVideoName, nWidth, nHeight,strPreferedFileExtension) 
{
    var imgVideoClose
    var divVideo
    var divVideoContainer
    var arrDivsInDoc
    
    alert('Some videos take longer than others to load depending their length. You may see a Q symbol for some time before the video plays if you have a slow internet connection (recommeded no less than 2 Mb/s). A second viewing should be much quicker to start. For help call 07779641375 (UK time) or email contact@on-schedule.org.')

    fade('divWholeContainer', 100, 0, 2000)
    
    divVideo = document.createElement('divVideo')
    divVideo.style.width = nWidth
    divVideo.style.height = nHeight + 16
    divVideo.setAttribute('id', 'divVideo')
    
    divVideoContainer = document.createElement('divVideoContainer')
    divVideoContainer.setAttribute('id', 'divVideoContainer')
    divVideoContainer.style.marginLeft = '-' + nWidth / 2 + 'px'
    divVideoContainer.style.marginTop = '-' + (nHeight + 16) / 2 + 'px'
    divVideoContainer.style.border = '4px solid #AAAAAA'

    imgVideoClose = new Image()
    imgVideoClose.src = 'Images/Cross.gif'
    imgVideoClose.onclick = videoRemove

    imgVideoClose = document.body.appendChild(imgVideoClose)

    divVideoContainer.appendChild(imgVideoClose)
    divVideoContainer.appendChild(divVideo)
    
    try 
    {
   
        new ActiveXObject("Microsoft.XMLHTTP")
        if (BrowserDetect.version < 7) 
        {
        
            divVideoContainer.style.top = '0px'
            divVideoContainer.style.marginTop = '25px'
            divVideoContainer.style.position = 'absolute'
        }
    }
    catch (err) 
    {
       
    }

    document.body.appendChild(divVideoContainer)

    document.getElementById('divVideo').innerHTML
        = "<strong>"
            + "<div style='padding:40px'>"
                + "<div class='highlight'>QuickTime Install Required</div>"
                + "<br />"
                + "<div>"
                    + "You need Apple QuickTime player (at least) version 6 to view the help videos."
                    + "<br /><br />"
                    + "<a href='http://www.apple.com/quicktime/download/' target='blank'>Apple QuickTime download page</a>"
                + "</div>"
                + "<br /><br />"
                + "<div>Once installed refresh the page</div>"
                + "<br /><br /><br />"
            + "</div>"
        + "</strong>"
        
    QuickTimeReplace.replace('divVideo', 'Videos/' + strVideoName, 'Video', nWidth, nHeight, strPreferedFileExtension, 6, null)

    arrDivsInDoc = document.getElementsByTagName('div')

    for (var i = 0; i < arrDivsInDoc.length; i++) 
    {
        if(arrDivsInDoc[i].className == 'videoIconContainer')
            arrDivsInDoc[i].style.visible = 'false'
    }

    
        
}

function videoRemove() {

    fade('divWholeContainer', 0, 100, 2000)
    window.setTimeout("var arrDivsInDoc = document.getElementsByTagName('div'); for (var i = 0; i < arrDivsInDoc.length; i++) if (arrDivsInDoc[i].className == 'videoIconContainer') arrDivsInDoc[i].style.visible = 'true';", 1000)
    document.body.removeChild(document.getElementById('divVideoContainer'));
}

function fade(elemId, lngOpacityPercentStart, lngOpacityPercentEnd, lngDurationMiliseconds) 
{
    var lngIntervalMiliseconds = Math.round(lngDurationMiliseconds / abs(lngOpacityPercentStart - lngOpacityPercentEnd))
    var lngCount = 0
    var lngOpacity

    if (lngOpacityPercentStart > lngOpacityPercentEnd) 
    {
        for (lngOpacity = lngOpacityPercentStart; lngOpacity >= lngOpacityPercentEnd; lngOpacity--) 
        {
            setTimeout("opacitySet('" + elemId + "'," + lngOpacity + ")", (lngCount * lngIntervalMiliseconds))
            lngCount++
        }
    }
    else if (lngOpacityPercentStart < lngOpacityPercentEnd) 
    {
        for (lngOpacity = lngOpacityPercentStart; lngOpacity <= lngOpacityPercentEnd; lngOpacity++) 
        {
            setTimeout("opacitySet('" + elemId + "'," + lngOpacity + ")", (lngCount * lngIntervalMiliseconds))
            lngCount++
        }
    }

}

function opacitySet(elemId, lngOpacityPercent) 
{
    var elem = document.getElementById(elemId)
    elem.style.opacity = lngOpacityPercent / 100;
    elem.style.MozOpacity = lngOpacityPercent / 100;
    elem.style.KhtmlOpacity = lngOpacityPercent / 100;
    elem.style.filter = 'alpha(opacity=' + lngOpacityPercent + ')';
}

function abs(Number) {
    if (Number < 0)
        return Number * -1
    else
        return Number
}