// JavaScript Document

// IMAGE SWAP AND PRELOADING

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_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_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];}
}

//DROP-DOWN MENU

var menuHome=new Array()
menuHome[0]="<a href=\"about.aspx\">About NCM</a>";
menuHome[1]="<a href=\"ncmCoreValues.aspx\">NCM Core Values</a>";
menuHome[2]="<a href=\"ncmServices.aspx\">NCM Services</a>";
menuHome[3]="<a href=\"personnel.aspx\" style=\"border-bottom:5px solid #6d4f06;\">Our Team</a>";

//Contents for menu 1
var menu20Groups=new Array()
menu20Groups[0]="<a href=\"TwentyGroupApplication.aspx\">Twenty Group Application</a>";
menu20Groups[1]="<a href=\"industry.aspx\">NCM Industry Selection</a>";
menu20Groups[2] = "<a href=\"FAQ.aspx\" style=\"border-bottom:5px solid #6d4f06;\">FAQ</a>";

var menuInformation = new Array()
menuInformation[0] = "<a href=\"Benchmark.aspx\">Benchmark Products</a>";
menuInformation[1] = "<a href=\"BestPractices.aspx\">Best Practices</a>";


//Contents for menu 2
var menuTraining=new Array()
menuTraining[0]="<a href=\"ncminstitute_list.aspx\">NCM Institute</a>";
//menuTraining[1]="<a href=\"manufacturer_sponsored.aspx\">Manufacturer Sponsored</a>";
menuTraining[1]="<a href=\"BuyHerePayHere.aspx\" style=\"border-bottom:5px solid #6d4f06;\">Buy Here, Pay Here</a>";

//Contents for menu 3
var menuConsulting=new Array()
menuConsulting[0]="<a href=\"InDealership.aspx\">In Dealership Solutions</a>";
menuConsulting[1]="<a href=\"MergerAcquisition.aspx\" style=\"border-bottom:5px solid #6d4f06;\">Mergers &amp; Acquisitions</a>";

var menuwidth='400px' //default menu width
var menubgcolor='#6d4f06' //menu bgcolor
var disappeardelay=250 //menu disappear speed onMouseout (in miliseconds)
var hidemenu_onclick="yes" //hide menu when user clicks within menu?

/////No further editting needed

var ie4=document.all
var ns6=document.getElementById&&!document.all

if (ie4||ns6)
document.write('<div id="dropmenudiv" style="visibility:hidden;width:'+menuwidth+';background-color:'+menubgcolor+'" onMouseover="clearhidemenu()" onMouseout="dynamichide(event)"></div>')

function getposOffset(what, offsettype){
var totaloffset=(offsettype=="left")? what.offsetLeft : what.offsetTop;
var parentEl=what.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}


function showhide(obj, e, visible, hidden, menuwidth){
if (ie4||ns6)
dropmenuobj.style.left=dropmenuobj.style.top="-500px"
if (menuwidth!=""){
dropmenuobj.widthobj=dropmenuobj.style
dropmenuobj.widthobj.width=menuwidth
}
if (e.type=="click" && obj.visibility==hidden || e.type=="mouseover")
obj.visibility=visible
else if (e.type=="click")
obj.visibility=hidden
}

function iecompattest(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function clearbrowseredge(obj, whichedge){
var edgeoffset=0
if (whichedge=="rightedge"){
var windowedge=ie4 && !window.opera? iecompattest().scrollLeft+iecompattest().clientWidth-15 : window.pageXOffset+window.innerWidth-15
dropmenuobj.contentmeasure=dropmenuobj.offsetWidth
if (windowedge-dropmenuobj.x < dropmenuobj.contentmeasure)
edgeoffset=dropmenuobj.contentmeasure-obj.offsetWidth
}
else{
var topedge=ie4 && !window.opera? iecompattest().scrollTop : window.pageYOffset
var windowedge=ie4 && !window.opera? iecompattest().scrollTop+iecompattest().clientHeight-15 : window.pageYOffset+window.innerHeight-18
dropmenuobj.contentmeasure=dropmenuobj.offsetHeight
if (windowedge-dropmenuobj.y < dropmenuobj.contentmeasure){ //move up?
edgeoffset=dropmenuobj.contentmeasure+obj.offsetHeight
if ((dropmenuobj.y-topedge)<dropmenuobj.contentmeasure) //up no good either?
edgeoffset=dropmenuobj.y+obj.offsetHeight-topedge
}
}
return edgeoffset
}

function populatemenu(what){
if (ie4||ns6)
dropmenuobj.innerHTML=what.join("")
}


function dropdownmenu(obj, e, menucontents, menuwidth) {

    if (window.event) event.cancelBubble=true
    else if (e.stopPropagation) e.stopPropagation()
    clearhidemenu()
    dropmenuobj=document.getElementById? document.getElementById("dropmenudiv") : dropmenudiv
    populatemenu(menucontents)

    if (ie4 || ns6)
    {
        showhide(dropmenuobj.style, e, "visible", "hidden", menuwidth)
        dropmenuobj.x=getposOffset(obj, "left")
        dropmenuobj.y=getposOffset(obj, "top")
        dropmenuobj.style.left=dropmenuobj.x-clearbrowseredge(obj, "rightedge")+"px"
        dropmenuobj.style.top=dropmenuobj.y-clearbrowseredge(obj, "bottomedge")+obj.offsetHeight+"px"
    }

    return clickreturnvalue()

}

function clickreturnvalue(){
if (ie4||ns6) return false
else return true
}

function contains_ns6(a, b) {
while (b.parentNode)
if ((b = b.parentNode) == a)
return true;
return false;
}

function dynamichide(e){
if (ie4&&!dropmenuobj.contains(e.toElement))
delayhidemenu()
else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
delayhidemenu()
}

function hidemenu(e){
if (typeof dropmenuobj!="undefined"){
if (ie4||ns6)
dropmenuobj.style.visibility="hidden"
}
}

function delayhidemenu(){
if (ie4||ns6)
delayhide=setTimeout("hidemenu()",disappeardelay)
}

function clearhidemenu(){
if (typeof delayhide!="undefined")
clearTimeout(delayhide)
}

if (hidemenu_onclick=="yes")
    document.onclick = hidemenu

//// FOR EMAIL NEWSLETTER SIGNUP
var TOP_OFFSET = 40;
var TEXTBOX_TEXT = 'Enter e-mail address';

function HideDiv(obj, atObj) {
    var obj = $get(obj);
    var atObj = $get(atObj);
    obj.style.display = 'none';
    if (atObj.value == '') {
        atObj.value = TEXTBOX_TEXT;
    }

}

function getOffsetTop(obj) {
    xPos = obj.offsetTop;
    tempEl = obj.offsetParent;

    while (tempEl != null) {
        xPos += tempEl.offsetTop;
        tempEl = tempEl.offsetParent;
    }

    return xPos;
}

function getOffsetLeft(obj) {
    xPos = obj.offsetLeft;
    tempEl = obj.offsetParent;

    while (tempEl != null) {
        xPos += tempEl.offsetLeft;
        tempEl = tempEl.offsetParent;
    }

    return xPos;
}

function ShowDiv(element, atElement) {
    var obj = $get(element);
    var atObj = $get(atElement);

    obj.style.top = getOffsetTop(atObj) - TOP_OFFSET + 'px';
    obj.style.left = getOffsetLeft(atObj) + 'px';
    obj.style.display = 'inline';

    atObj.value = '';

}

function TextRotator(TextDivId, BannerDivId) {
    //SETUP DOM OBJECTS
    var bannerDivObj = $get(BannerDivId);
    var textDivObj = $get(TextDivId);

    this.BANNER_ROTATION_TIME = 8000;
    this.NCM_LOGO_TOP_OFFSET = 75;
    this.NCM_LOGO_LEFT_OFFSET = 230;
    
    this.CurrentBannerIndex = 0;
    this.BannerTexts = GetBannerTexts();
   
    this.RotateBanner = function() {
        if (this.CurrentBannerIndex == this.BannerTexts.length) this.CurrentBannerIndex = 0;

        textDivObj.innerHTML = this.BannerTexts[this.CurrentBannerIndex];
        this.CurrentBannerIndex++;
        return false;
    }

    this.SetBannerLocation = function() {

        var textLocationTop = getOffsetTop(bannerDivObj) + this.NCM_LOGO_TOP_OFFSET;
        var textLocationLeft = getOffsetLeft(bannerDivObj) + this.NCM_LOGO_LEFT_OFFSET; //Offset Left By X Pixels To Clear NCM Logo
        textDivObj.style.top = textLocationTop + 'px';
        textDivObj.style.left = textLocationLeft + 'px';
    }

    this.SetBannerLocation();
    textDivObj.style.display = 'inline';
    textDivObj.innerHTML = this.BannerTexts[0];
    this.CurrentBannerIndex++;
}



function GetBannerTexts() {
    var BannerTexts = new Array();
    BannerTexts[0] = '<a href=\"ncminstitute_list.aspx\">NCM Institute Classes</a><br />Used Vehicle Management I & II';
    BannerTexts[1] = '<a href=\"ncminstitute_list.aspx\">NCM Institute Classes</a><br />General Management I & II';
    BannerTexts[2] = '<a href=\"ncminstitute_list.aspx\">NCM Institute Classes</a><br />Sales Management I & II';
    BannerTexts[3] = '<a href=\"ncminstitute_list.aspx\">NCM Institute Classes</a><br />Service Management I & II';
    BannerTexts[4] = '<a href=\"ncminstitute_list.aspx\">NCM Institute Classes</a><br />Financial Management I & II';
    BannerTexts[5] = '<a href=\"ncminstitute_list.aspx\">NCM Institute Classes</a><br />eCommerce Management I & II';
    return BannerTexts;
}

function DoGoogleSearch() {
        var searchUrl = 'http://www.ncm20.com/searchResults.aspx?' +
            'cx=004196642300316781615:ni9s767ga8w&cof=FORID%3A11&ie=UTF-8&q=' +
            document.getElementById('googleSearch').value + '&sa=Search';
    document.location.href = searchUrl;
}


function SubmitOnEnter(myfield, e)  
{  
    var keycode;  
    if (window.event)  
        keycode = window.event.keyCode;  
    else if (e)  
        keycode = e.which;  
    else  
        return true;  
    if (keycode == 13)  
    {
        DoGoogleSearch();
        return false;  
    }  
    else  
        return true;  
}

var tooltip = function() {
    var id = 'tt';
    var top = 3;
    var left = 3;
    var maxw = 300;
    var speed = 10;
    var timer = 20;
    var endalpha = 95;
    var alpha = 0;
    var tt, t, c, b, h;
    var ie = document.all ? true : false;
    return {
        show: function(v, w) {
            if (tt == null) {
                tt = document.createElement('div');
                tt.setAttribute('id', id);
                t = document.createElement('div');
                t.setAttribute('id', id + 'top');
                c = document.createElement('div');
                c.setAttribute('id', id + 'cont');
                b = document.createElement('div');
                b.setAttribute('id', id + 'bot');
                tt.appendChild(t);
                tt.appendChild(c);
                tt.appendChild(b);
                document.body.appendChild(tt);
                tt.style.opacity = 0;
                tt.style.filter = 'alpha(opacity=0)';
                document.onmousemove = this.pos;
            }
            tt.style.display = 'block';
            c.innerHTML = v;
            tt.style.width = w ? w + 'px' : 'auto';
            if (!w && ie) {
                t.style.display = 'none';
                b.style.display = 'none';
                tt.style.width = tt.offsetWidth;
                t.style.display = 'block';
                b.style.display = 'block';
            }
            if (tt.offsetWidth > maxw) { tt.style.width = maxw + 'px' }
            h = parseInt(tt.offsetHeight) + top;
            clearInterval(tt.timer);
            tt.timer = setInterval(function() { tooltip.fade(1) }, timer);
        },
        pos: function(e) {
            var u = ie ? event.clientY + document.documentElement.scrollTop : e.pageY;
            var l = ie ? event.clientX + document.documentElement.scrollLeft : e.pageX;
            tt.style.top = (u - h) + 'px';
            tt.style.left = (l + left) + 'px';
        },
        fade: function(d) {
            var a = alpha;
            if ((a != endalpha && d == 1) || (a != 0 && d == -1)) {
                var i = speed;
                if (endalpha - a < speed && d == 1) {
                    i = endalpha - a;
                } else if (alpha < speed && d == -1) {
                    i = a;
                }
                alpha = a + (i * d);
                tt.style.opacity = alpha * .01;
                tt.style.filter = 'alpha(opacity=' + alpha + ')';
            } else {
                clearInterval(tt.timer);
                if (d == -1) { tt.style.display = 'none' }
            }
        },
        hide: function() {
            clearInterval(tt.timer);
            tt.timer = setInterval(function() { tooltip.fade(-1) }, timer);
        }
    };
} ();
