﻿function setupBackground()
{
    var bodyElem = document.getElementById('body');
    if ( bodyElem )
    {
        intBodyWidth=document.body.clientWidth;
        intOffsetLeft = ((intBodyWidth - 990) / 2) - 181;
        bodyElem.style.background = "transparent url('http://www.dag.net.nz/images/pretty-smile.jpg') scroll " + intOffsetLeft + "px 185px no-repeat";
    }
}


function highlight(id)
{
    var docElem = document.getElementById(id)
    if ( docElem )
    {
        docElem.style.backgroundColor='#FFF';
        docElem.style.textDecoration='none';
        docElem.style.cursor='pointer';
    }
}

function removeHighlight(id)
{
    var docElem = document.getElementById(id)
    if ( docElem )
    {
        docElem.style.backgroundColor='#EEE';
        docElem.style.textDecoration='none';
        docElem.style.cursor='auto';
    }
}

function redirect(pageLoc)
{
    var myUri = window.top.location.href;
    var lastSlash = myUri.lastIndexOf('/') + 1;
    var rootDirectory = myUri.slice( 0, lastSlash );
    window.top.location.href = rootDirectory + pageLoc;
}

function mobileRedirect()
{
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
        xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    
    xmlhttp.onreadystatechange=function()
    {
        if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
            var response = xmlhttp.responseXML.documentElement.firstChild.nodeValue;
            
            if(response.length > 1  )
            { 
                if( response.length < 21 )
                {
                    redirect( response );
                }
                else  
                {
                    // debug
                    // document.write( xmlhttp.responseText );
                }
            }    
        }
    }

    xmlhttp.open("POST","Service.asmx/Mobile?");
    xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    xmlhttp.send(   "ipAddress=" + document.getElementById("ipAddress").value +
                    "&width=" + screen.width + 
                    "&height=" + screen.height 
                    //+ document.getElementById("otherVariables").value
                    
                );
    
}

function MM_preloadImages() 
{ //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
 var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
 if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{ //v4.01
 var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
 d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
 if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
 for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
 if(!x && d.getElementById) x=d.getElementById(n); return x;
} 

function MM_swapImgRestore() 
{ //v3.0
 var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() 
{ //v3.0
 var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
 if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

/*  TODO
onLoad="MM_preloadImages(
'images/template/navbar_jan/training-options-over.gif',
'images/template/navbar_jan/courses-over.gif',
'images/template/navbar_jan/calendar-over.gif',
'images/template/navbar_jan/quote-over.gif',
'images/template/navbar_jan/s-home-over.gif',
'images/template/navbar_jan/s-story-over.gif',
'images/template/navbar_jan/s-faq-over.gif',
'images/template/navbar_jan/s-contact-us-over.gif',
'images/page_general/why2_over.jpg',
'images/page_general/why3_over.jpg',
'images/page_general/why5-over.jpg',
'images/page_general/personalised-pdf-over.jpg')">
*/

function bookmarksite(title,url)
{
    if (window.sidebar) // firefox
     window.sidebar.addPanel(title, url, "");
    else if(window.opera && window.print){ // opera
     var elem = document.createElement('a');
     elem.setAttribute('href',url);
     elem.setAttribute('title',title);
     elem.setAttribute('rel','sidebar');
     elem.click();
    }
    else if(document.all)// ie
     window.external.AddFavorite(url, title);
}

var divArray = new Array();

divArray.push('Portfolio');    
divArray.push('budget.co.nz');
divArray.push('roc');
divArray.push('iView');
divArray.push('cv');
divArray.push('xs');
divArray.push('imsz');

function full(url, name)
{ 
    popup(url, name, screen.width-8, screen.height-26);
}

function popup(url, name, w, h)
{
    var x = (screen.width - w - 8)/2; 
    var y = (screen.height - h - 26)/2; 
    window.open(url,name,'scrollbars=no,resizable=yes,width=' + w + ',height=' + h + ',left=' + x + ',top=' + y + ',screenX=' + x + ',screenY=' + y);
}

function hideAll()
{
    for( i = 0; i < divArray.length; i++ )
    {
        objDiv = document.getElementById( divArray[i] );
        if(objDiv)
        {
            objDiv.style.display = 'none';
            objDiv.style.visibility = 'hidden';
        }
    }
}

function parseQuerystring()
{
    var queryString = location.search.substring(1, location.search.length);
    if(queryString.length != 0 && queryString.indexOf('#') == -1)
    {
        queryString = queryString.replace(/%20/g, ' ');
        var qsArray = queryString.split('=');
        
        if(qsArray[1] == 'Technical Highlights')
        {
            showDiv('Technical Highlights');
                objDiv = document.getElementById('imgBelowMenu');
                if(objDiv)
                {
                    objDiv.style.display = 'block';
                    objDiv.style.visibility = 'visible';
                }
        }
        else
        {
            for( i = 0; i < divArray.length; i++ )
            {
                if(qsArray[1] == divArray[i])
                {
                    showDiv(divArray[i]);
                    return;
                }
            }
        }
    }
}


function goProducts(id)
{
    location.href = '/Portfolio/?r=' + id;
}


function showDiv(id)
{
    
    hideAll();
    hideSubmenus();
    
    objDiv = document.getElementById(id);
    if(objDiv)
    {
        objDiv.style.display = 'block';
        objDiv.style.visibility = 'visible';
    }

}

function showHighlights()
{
    location.search = '?r=Technical Highlights';
    location.hash = '';
}


function showBrochures()
{
    location.search = '?r=Brochures';
    location.hash = '';
}

function showSubmenu(intChild)
{
    objDiv = document.getElementById('submenu' + intChild);
    var intBodyWidth = 0;
    intBodyWidth=document.body.clientWidth;
    intOffsetLeft = (intBodyWidth - 924) / 2;
    if(intOffsetLeft < 0){ intOffsetLeft = 0 }
    
    if(objDiv)
    {
        objDiv.style.display = 'block';
        objDiv.style.visibility = 'visible';
        
        var string = intOffsetLeft + 458;
        objDiv.style.left = string.toString() + 'px';
    }
}

function hideSubmenus()
{
    for( i = 1; i <= 1; i++ )
    {
        objDiv = document.getElementById('submenu' + i.toString() );
        if(objDiv)
        {
            objDiv.style.display = 'none';
            objDiv.style.visibility = 'hidden';
        }
    }

}


