﻿
var strIntroTypeDivID

function identifyCurrPagePromo() 
{
    var tdCurr

if (window.location.pathname.toLowerCase().indexOf('default.aspx') > -1 || window.location.pathname == '/' || window.location.pathname == '/OnSchedule/') {
        tdCurr = document.getElementById('tdMenuHome')
        document.getElementById('divIntroStandard').style.display = "none"
        document.getElementById('divIntroClientVisit').style.display = "none"
        document.getElementById('divIntroHomeCare').style.display = "none"
    }
    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'

    setUpQueryStringStore()
    if(arrQueryString['filter'] == 'standard')
        document.getElementById("btnFilterStandard").style.borderColor = '#999999'
    else if(arrQueryString['filter'] == 'clientvisit')
        document.getElementById("btnFilterClientVisit").style.borderColor = '#999999'
    else if (arrQueryString['filter'] == 'homecare')
        document.getElementById("btnFilterHomeCare").style.borderColor = '#999999'
}

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 btnWindow_onmouseover() 
{
    this.style.borderColor = '#999999'
}

function btnWindow_onmouseout() 
{

    this.style.borderColor = '#FFFFFF'
}

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('+44 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')
            break;
        case 'phone':
            document.write('+44 115 ')
            writePhone('phone2')
            break;
        case 'phone2':
            document.write('714')
            writePhone('phone3')
            break;
        case 'phone3':
            document.write(' code')
            writePhone('phone4')
            break;
        case 'phone4':
            document.write('<br />or ')
            writePhone('phone5')
            break;
        case 'phone5':
            document.write('+44 ')
            writePhone('phone6')
            break;
        case 'phone6':
            document.write('115 ')
            writePhone('phone7')
            break;
        case 'phone7':
            document.write('714 ')
            writePhone('phone8')
            break;
        case 'phone8':
            document.write('2633')
            break;
        case 'USA':
            document.write('+1 718 ')
            writePhone('USA2')
            break;
        case 'USA2':
            document.write('530')
            writePhone('USA3')
            break;
        case 'USA3':
            document.write(' 0321')
            break;
            
    }
}

function btn_OnMouseOver() {
    
    if (this.src != null)
        this.src = this.src.replace('.gif', '_MouseOver.gif').replace('.jpg', '_MouseOver.jpg')
    else if (strIntroTypeDivID != this.getAttribute('relatedelem'))
        this.style.background = this.style.background.replace('.gif', '_MouseOver.gif').replace('.jpg', '_MouseOver.jpg')

}

function btn_OnMouseOut() {

    

    if (this.src != null)
        this.src = this.src.replace('_MouseOver.gif', '.gif').replace('_MouseOver.jpg', '.jpg')
    else if (strIntroTypeDivID != this.getAttribute('relatedelem'))
        this.style.background = this.style.background.replace('_MouseOver.gif', '.gif').replace('_MouseOver.jpg', '.jpg')
  
    
}

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'] + "&clientvisit=" + arrQueryString['clientvisit'];
}

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, strNextClip) 
{
    var imgVideoClose
    var divVideo
    var divVideoContainer
    var arrDivsInDoc
    var divSeparator
    
    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

    divSeparator = document.createElement('div')

    imgVideoClose = document.body.appendChild(imgVideoClose)

    divVideoContainer.appendChild(imgVideoClose)
    divVideoContainer.appendChild(divSeparator)
    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>Download then install by double clicking on the downloaded file. Once installed, try refreshing the page. We have found that usually you have to restart your computer after installation.</div>"
                + "<br /><br /><br />"
            + "</div>"
        + "</strong>"

    QuickTimeReplace.replace('divVideo', 'Videos/' + strVideoName, 'Video', nWidth, nHeight, strPreferedFileExtension, 6, null, strNextClip)

    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.getElementById('divVideo').innerHTML = ''
    document.body.removeChild(document.getElementById('divVideoContainer'));
}

function imageInsert(strImageName) 
{
    var imgVideoClose
    var divImage
    var divImageContainer
    var imgSeparator

    fade('divWholeContainer', 100, 0, 500)

    imgImage = new Image()
    imgImage.src = 'Images/' + strImageName

    divImageContainer = document.createElement('divImageContainer')
    divImageContainer.setAttribute('id', 'divImageContainer')
    divImageContainer.style.border = '4px solid #AAAAAA'
    divImageContainer.style.marginLeft = '-400px'
    

    imgImageClose = new Image()
    imgImageClose.src = 'Images/Cross.gif'
    imgImageClose.onclick = imageRemove

    divSeparator = document.createElement('div')

    imgImageClose = document.body.appendChild(imgImageClose)

    divImageContainer.appendChild(imgImageClose)
    divImageContainer.appendChild(divSeparator)
    divImageContainer.appendChild(imgImage)
    document.body.appendChild(divImageContainer)

    arrDivsInDoc = document.getElementsByTagName('div')

    for (var i = 0; i < arrDivsInDoc.length; i++) {
        if (arrDivsInDoc[i].className == 'windowButton')
            arrDivsInDoc[i].style.display = 'none'
    }

}

function imageRemove() 
{
    fade('divWholeContainer', 0, 100, 500)
    window.setTimeout("var arrDivsInDoc = document.getElementsByTagName('div'); for (var i = 0; i < arrDivsInDoc.length; i++) if (arrDivsInDoc[i].className == 'windowButton') arrDivsInDoc[i].style.display = 'block';", 1000)
    document.body.removeChild(document.getElementById('divImageContainer'));

}



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
}

function switchToIntroType() {
    var arrButtons;
    strIntroTypeDivID = this.getAttribute('relatedelem')

    arrButtons = document.getElementById('tblSchedulingTypes').getElementsByTagName('th')
    for (var n = 0; n < arrButtons.length; n++) {

        if (arrButtons[n].getAttribute('relatedelem') != strIntroTypeDivID)
            arrButtons[n].style.background = arrButtons[n].style.background.replace('_MouseOver.gif', '.gif').replace('_MouseOver.jpg', '.jpg')
     
        
    }

    document.getElementById('divIntroGeneral').style.display = "none"
    document.getElementById('divIntroStandard').style.display = "none"
    document.getElementById('divIntroHomeCare').style.display = "none"
    document.getElementById('divIntroClientVisit').style.display = "none"
    
    fade(strIntroTypeDivID, 0, 100, 2000)

    window.setTimeout('document.getElementById(strIntroTypeDivID).style.display = "block";',0)
}
