﻿
var strIntroTypeDivID
var arrUserComments = new Array()

                                

function changeUserComment(nNext) {

    fade('divUserComments', 0, 100, 1000);
   
    document.getElementById('divUserComments').innerHTML = arrUserComments[nNext % arrUserComments.length]

    nNext++
    
    window.setTimeout("changeUserComment(" + nNext + ")", 5000);
    
}

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 = '#FF0000'
}

function btnWindow_onmouseout() 
{

    this.style.borderColor = 'grey'
}

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'] + "&clientplacevisit=" + arrQueryString['clientplacevisit'];
}

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 popupShow(strASPControlID) {
    var arrDivs = document.getElementsByTagName("DIV");

    for (var n = 0; n < arrDivs.length - 1; n++) {
        if (arrDivs[n].id.indexOf(strASPControlID) > -1) {
            arrDivs[n].style.visibility = 'visible'
            break;
        }
    }
   
}

function popupHide(strASPControlID) {
    var arrDivs = document.getElementsByTagName("DIV");

    for (var n = 0; n < arrDivs.length - 1; n++) {
        if (arrDivs[n].id.indexOf(strASPControlID) > -1) {
            arrDivs[n].style.visibility = 'hidden'
            break;
        }
    }
}

function popupPostion(strASPControlID, nWidth, nHeight, bTopLeft) 
{
    var arrDivs = document.getElementsByTagName("DIV");
    
    for (var n = 0; n < arrDivs.length - 1; n++)
    {
        if (arrDivs[n].id.indexOf(strASPControlID) > -1)
        {
            arrDivs[n].style.width = nWidth + 'px'
            arrDivs[n].style.height =  nHeight + 'px'

            if (bTopLeft)
            {
                arrDivs[n].style.top = '0px'
                arrDivs[n].style.left = '0px'
                arrDivs[n].style.margin = '0px'
            }
            else
            {
                arrDivs[n].style.marginLeft = '-' + (nWidth / 2) + 'px'
                arrDivs[n].style.marginTop = '-' + (nHeight / 2) + 'px'
            }
            arrDivs[n].style.border = '4px solid #AAAAAA'

            try 
            {
           
                new ActiveXObject("Microsoft.XMLHTTP")
                if (BrowserDetect.version < 7) 
                {
                    if (bTopRight) {
                        arrDivs[n].style.top = '0px'
                        arrDivs[n].style.marginTop = '200px'
                    }
                    arrDivs[n].style.position = 'absolute'
                }
            }
            catch (err) 
            {

            }
            break;
        }
    }
}

function videoInsert(strVideoName, nWidth, nHeight, strPreferedFileExtension, nPluginVersion, strNextClip) 
{
    var imgVideoClose
    var divVideo
    var divVideoContainer
    var arrDivsInDoc
    var divSeparator

    fade('divWholeContainer', 100, 0, 2000)
    
    
    divVideo = document.createElement('divVideo')
    divVideo.setAttribute('id', 'divVideo')
    
    divVideoContainer = document.createElement('divVideoContainer')
    divVideoContainer.setAttribute('id', 'divVideoContainer')
    divVideoContainer.style.marginLeft = '-' + nWidth / 2 + 'px'
    divVideoContainer.style.marginTop = '-' + (nHeight + 45) / 2 + 'px'
    divVideoContainer.style.border = '4px solid #AAAAAA'
    
    // save flash variables for use in another function
    divVideo.strVideoName = strVideoName
    divVideo.strPreferedFileExtension = strPreferedFileExtension
    divVideo.nPluginVersion = nPluginVersion
    divVideo.strNextClip = strNextClip
    divVideo.nWidth = nWidth
    divVideo.nHeight = nHeight + 16

    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)

    grow('divVideoContainer', 200, 200, nWidth, nHeight + 45,3000);

    window.setTimeout('videoInsertSub()', 3000);

    
    arrDivsInDoc = document.getElementsByTagName('div')
    
    for (var i = 0; i < arrDivsInDoc.length; i++) 
    {
        if(arrDivsInDoc[i].className == 'videoIconContainer')
            arrDivsInDoc[i].style.visible = 'false'
    }
}

function videoInsertSub() {
    
    var divVideo = document.getElementById('divVideo');
    VideoReplace.replace('divVideo', 'Videos/' + divVideo.strVideoName, 'Video', divVideo.nWidth, divVideo.nHeight, divVideo.strPreferedFileExtension, divVideo.nPluginVersion, null)
}

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)
    
    divImageContainer = document.createElement('divImageContainer')
    divImageContainer.setAttribute('id', 'divImageContainer')
    divImageContainer.style.border = '4px solid #AAAAAA'
    divImageContainer.style.marginLeft = '-400px'
    
    divImageContainer.strImageName = strImageName
    
    
    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)

    document.body.appendChild(divImageContainer)
    
    grow('divImageContainer',100,100,825,600,3000)

    window.setTimeout('imageInsertSub()', 3100)
    
    arrDivsInDoc = document.getElementsByTagName('div')

    for (var i = 0; i < arrDivsInDoc.length; i++) {
        if (arrDivsInDoc[i].className == 'windowButton')
            arrDivsInDoc[i].style.display = 'none'
    }

}

function imageInsertSub() {
    imgImage = new Image()
    var divImageContainer = document.getElementById('divImageContainer')

    imgImage.src = 'Images/' + divImageContainer.strImageName
    divImageContainer.appendChild(imgImage)

    divImageContainer.style.height = ''
    divImageContainer.style.width = ''
}

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 grow(elemId, nWidthStart, nHeightStart, nWidthEnd, nHeightEnd, nDurationMiliseconds) {
    var nIntervalMiliseconds = Math.round((nDurationMiliseconds * 10) / abs(nWidthStart + nHeightStart - nWidthEnd - nHeightEnd))
    var nCount = 0
    var nWidth
    var nHeight
    var elem = document.getElementById(elemId)

    elem.style.width = nWidthStart + 'px'
    elem.style.height = nHeightStart + 'px'

    if (nWidthStart > nWidthEnd) {
        for (nWidth = nWidthStart; nWidth >= nWidthEnd; nWidth = nWidth - 10) {
            setTimeout("document.getElementById('" + elemId + "').style.width = '" + nWidth + "px'", (nCount * nIntervalMiliseconds))
            nCount++
        }
    }
    else if (nWidthStart < nWidthEnd) {
        for (nWidth = nWidthStart; nWidth <= nWidthEnd; nWidth = nWidth + 10) {
            setTimeout("document.getElementById('" + elemId + "').style.width = '" + nWidth + "px'", (nCount * nIntervalMiliseconds))
            nCount++
            
        }
    }
    
    if (nHeightStart > nHeightEnd) {
        for (nHeight = nHeightStart; nHeight >= nHeightEnd; nHeight = nHeight - 10) {
            setTimeout("document.getElementById('" + elemId + "').style.height = '" + nHeight + "px'", (nCount * nIntervalMiliseconds))
            nCount++
        }
    }
    else if (nHeightStart < nHeightEnd) {
        for (nHeight = nHeightStart; nHeight <= nHeightEnd; nHeight = nHeight + 10) {
        setTimeout("document.getElementById('" + elemId + "').style.height = '" + nHeight + "px'", (nCount * nIntervalMiliseconds))
            nCount++
        }
    }

}

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)
}

function showPopupImg(strFileName, strLabel, nImgWidth, nImgHeight) {
    var divImg
    var img;

    divImg = document.getElementById('divImg')
    if(divImg) {
        divImg.firstChild.src = strFileName
        divImg.firstChild.alt = strLabel + "'s Location"
        $('#divImg').dialog('open')
    }
    else
    {
        divImg = document.createElement('div')
        divImg.id = 'divImg'
        img = document.createElement('img')
        img.src = strFileName
        img.alt = strLabel + "'s Location"
        divImg.appendChild(img)
        document.body.appendChild(divImg)
        $('#divImg').dialog({ title: strLabel + "'s location", disabled: true, width: nImgWidth + 50, height: nImgHeight + 50 });
    }



    

}

