/*Documentation located in navigation.js.doc in Dev Team Sharepoint */
function bodyOnLoad() {}

function openMenu(menuID,linkObj){		
	if(um.ready){
		var coords = {'x' : um.getRealPosition(linkObj,'x'), 'y' : um.getRealPosition(linkObj,'y')};
		coords.y += (linkObj.offsetHeight + 0);
		coords.x += 1;
		um.activateMenu(menuID, coords.x + 'px', coords.y + 'px');
	}
} 

function closeMenu(menuID){
	if(um.ready) {
		um.deactivateMenu(menuID);
	}
}

function loadXMLDoc(method, url, params){
	var xmlhttp=null
	// code for Mozilla, etc.
	if (window.XMLHttpRequest) {
	  xmlhttp=new XMLHttpRequest()
  	}
	// code for IE
	else if (window.ActiveXObject) {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}
	if (xmlhttp!=null) {
	  xmlhttp.open(method,url,true)
	  xmlhttp.send(params)
    } else {
      //nothing?
    }
}

function saveDownload(obj, security, key, type) { 	
 	loadXMLDoc("POST","/mt/secureDownload/saveDownload.jsp", "f="+obj.href+"&k="+key+"&c="+type+"&s="+security);
} 

function observeKeyTopic(obj, url) {
	loadXMLDoc("GET", "/mt/homepage/keyTopics.jsp", "u="+url);
}
	
function Is() {     
    var agent = navigator.userAgent.toLowerCase();  
    
    this.major = parseInt(navigator.appVersion);  
    this.minor = parseFloat(navigator.appVersion);  
    
    this.ns = ((agent.indexOf('mozilla')!=-1) && (agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1) );  
    this.ns2 = (this.ns && (this.major == 2)); 
    this.ns3 = (this.ns && (this.major == 3));  
    this.ns4b = (this.ns && (this.minor < 4.04));  
    this.ns4 = (this.ns && (this.major >= 4)); 
    this.ns6 = (this.ns && (this.major >= 6)); 
    this.ie = (agent.indexOf('msie') != -1);  
    this.ie3 = (this.ie && (this.major == 2));  
    this.ie4 = (this.ie && (this.major >= 4));  
    this.op3 = (agent.indexOf('opera') != -1); 
    this.ver5m=(this.major >= 5); 
}
var is = new Is();

// document.URL.split will enable the capture of either http or https prefixes. 
// split_url[0] will equal either http or https.
var split_url = document.URL.split(':');
// document domain can get the domain for the server dynamically. EG. localhost or mt.com
var baseUrl = split_url[0] + '://' + document.domain;
var ie4 = false; if(document.all) { ie4 = true; }
var openImg = baseUrl + '/images_nav/open.gif';
var closeImg = baseUrl + '/images_nav/close.gif'; 

function getMBObject(id) {/* if (ie4) { return document.all[id]; } else { */ return document.getElementById(id); /*}*/}

function toggle(link, divId, state) {   
    var obj1 = getMBObject(divId + "_open");
    var obj2 = getMBObject(divId + "_close");
    var d = getMBObject(divId);
    if (obj1 != null) {
        if (obj1.style.display=='') { 
            obj1.style.display='none';
            obj2.style.display='';
            d.style.display = 'block'; 
        } 
        else { 
            if (state != 'open') {
                obj1.style.display='';
                obj2.style.display='none';
                d.style.display = 'none'; 
            }
        } 
    }
}

function simpleToggle(element) {
	var id = getMBObject(element);
	if(id != null) {
		if(id.style.display=='none'){
			id.style.display='';
		} else {
			id.style.display='none';
		}
	}
}

function getObject(id) { if (ie4) { return document.all[id]; } else { return document.getElementById(id); }}

function browserCheck() {   
    if (!document.getElementById) {
        window.location = "/upgrade.html";
        //alert("This browser is not compliant with the W3C Document Object Model standard!\nAs a result, these pages may not display properly.\nTo ensure the best browsing experience, please upgrade your browser.");
    }
}

function popup(url, height, width){
  window.open(url, "", "height=" + height + ",width=" + width + ",scrollbars=yes,menubar=no,resizable=yes,titlebar=no,status=no,toolbar=no,menubar=no,location=no");
}

function submitCountrySelectForm(pDropDown, pDefaultValue, pFormObj, pText){
    var bProceed=0;    
    if (pFormObj.cartLength.value > 0) {
        if (confirm(pText)) {
            bProceed=0;
        } else {
            bProceed=1;
        }
    }
    if (bProceed==0 && pDropDown.options[pDropDown.selectedIndex].value != ""
                    && pDropDown.options[pDropDown.selectedIndex].value != pDefaultValue) {
                pFormObj.submit();
    }
}

function countryChangeValidate(pDropDown, pDefaultValue, pFormObj, pText, pTextSub, pTextBoth){
    var bProceed=0;
    var hasCartItems = pFormObj.cartLength.value > 0;
    var hasSubs = pFormObj.hasSubscriptions != null && pFormObj.hasSubscriptions.value > 0;
    var msg = pText;        
    if (hasCartItems && hasSubs) {        
        msg = pTextBoth;    
    } else if (!hasCartItems && hasSubs) {        
        msg = pTextSub;
    } else if (hasCartItems && !hasSubs) {        
        msg = pText;
    }    
    if (hasCartItems || hasSubs) {
        if (! confirm(msg)) {
            //Change back to default
            var tmpOptionValue = "";
            for (i = pDropDown.length - 1; i >= 0; i--) {
                tmpOptionValue = pDropDown[i].value;
                if ( pDefaultValue.indexOf(tmpOptionValue) > -1 && tmpOptionValue != '' ) {
                    pDropDown[i].selected = true;
                }
            }
            return false;
        }
    }    
}

// Email validator expression from
// http://www.breakingpar.com/bkp/home.nsf/Doc!OpenNavigator&U=87256B280015193F87256C40004CC8C6
function isEmailFieldInvalid(pTextObj) {
    var emailAddress = pTextObj.value;
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
    return !re.test(emailAddress);
}

function setChecked(bChecked,pChkID) {
  var formObj = document.profile_update;
  if (formObj != null) {
    var iElementLen = formObj.elements.length;
    var iLoop = 0;
    for( iLoop=0 ; iLoop < iElementLen; iLoop++) {
        if (formObj.elements[iLoop].id == pChkID) {         
            formObj.elements[iLoop].checked = bChecked;
        }
    }
  }
}

function checkChildren(bChecked,pParentID) {
    var formObj = document.profile_update;    
    if (formObj != null) {
        var iCheckboxLen = formObj.elements.length;
        var iLoop = 0;
        var iParentLen = pParentID.length;
        var sElementID = "";
        for( iLoop=0 ; iLoop < iCheckboxLen; iLoop++) {
            sElementID = formObj.elements[iLoop].id;
            if (sElementID.length > iParentLen) {
                if (sElementID.substring(0, iParentLen) == pParentID) {                 
                    if (! formObj.elements[iLoop].disabled ) {
                        formObj.elements[iLoop].checked = bChecked;
                    }
                }
            }
        }
    }
}

function checkTree(pCheckBox, checkParent) {
    if (window.navigator.appName=="Microsoft Internet Explorer" && parseInt(window.navigator.appVersion) >= 4 ){
        var sCurrentID = pCheckBox.id;
        var sSplit = "/"
        var iLastSplit = 0;
        var sParent = "";
        var sCurrentNode = pCheckBox.id;        
        if (pCheckBox.checked == true) {
            if (checkParent != false) {             
                iLastSplit = sCurrentNode.lastIndexOf(sSplit);
                while (iLastSplit > 0) {
                    sParent = sCurrentNode.substring(0,iLastSplit);
                    setChecked(true, sParent);
                    sCurrentNode = sParent;
                    iLastSplit = sCurrentNode.lastIndexOf(sSplit);
                }   
            }       
            checkChildren(true, sCurrentID + sSplit);
        } else {    
            if (checkParent == false) {         
                //need to uncheck the parent                
                iLastSplit = sCurrentNode.lastIndexOf(sSplit);
                while (iLastSplit > 0) {
                    sParent = sCurrentNode.substring(0,iLastSplit);
                    setChecked(false, sParent);
                    sCurrentNode = sParent;
                    iLastSplit = sCurrentNode.lastIndexOf(sSplit);
                }                
            }
            checkChildren(false, sCurrentID + sSplit);
        }
    }
}

function checkRadioTree(pRadioButton) {
    var formObj = document.profile_update;
    if (formObj != null) {
        var iRadioFormLen = formObj.elements.length;    
        var sRadioID = pRadioButton.id;
        var sRadioName = pRadioButton.name;
        sRadioName = sRadioName.substring(0,sRadioName.length -1);    
        var iLoop = 0;
        var sSplit = "/";
        var sElementID = "";    
        var iRadioIDLen = sRadioID.length;
        var iLastSplit = sRadioID.lastIndexOf(sSplit);
        var sParent = sRadioID.substring(0,iLastSplit);    
        //Loop through each Radio Button.
        for( iLoop=0 ; iLoop < iRadioFormLen; iLoop++) {
            sElementID = formObj.elements[iLoop].id;
            sElementName = formObj.elements[iLoop].name;
            sElementName = sElementName.substring(0,sElementName.length-1);    
            //Make sure same Radio Button Array
            if (sRadioName == sElementName) {
                //  1)Check to make sure that only children of mine are checked.
                if (sElementID.length > iRadioIDLen) {
                    //  If Path is longer, then if the Path does not start with the Current Name, then uncheck it.
                    if (sElementID.substring(0, iRadioIDLen) != sRadioID) {
                        formObj.elements[iLoop].checked = false;
                    }
                } else {
                    //Else if the Path is not longer, then definetly uncheck it.
                    formObj.elements[iLoop].checked = false;
                }    
                if (sElementID == sParent) {
                    //  2)Check if my Parent is checked, if not, then check it.
                    formObj.elements[iLoop].checked = true;
                }
            }
        }
        //Just incase it set the Current Button Off line, make sure it is checked
        pRadioButton.checked = true;
    }
}

function popup_full(url) {
  window.open(url, "", "scrollbars=yes,menubar=yes,resizable=yes,titlebar=yes,status=yes,toolbar=yes,menubar=yes,location=yes");
}

function isTxtFieldEmpty(pTextObj) {
    var fieldText = pTextObj.value.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ;
    if (fieldText.length > 0) {
        return false;
    } else {
        return true;
    }
}

function isDropDownEmpty(pDDObj) {
    if (pDDObj.options[pDDObj.selectedIndex].value.length > 0) {
        return false;
    } else {
        return true;
    }
}

function isStringEmpty(pStringObj) {
   var fieldText = pStringObj.replace(/^\s*([\s\S]*\S+)\s*$|^\s*$/,'$1') ; 
   if (fieldText.length > 0) {
       return false;
   } else {
       return true;
   }
}


function limitChars(ta, n){
  return (ta.value.length < n);
}   

function sfMouseover(linkObj) {
    linkObj.style.background='#E2F5D1';
}

function sfMouseout(linkObj) {
    linkObj.style.background='#ffffff';
}

/*http://blog.firetree.net/2005/07/04/javascript-find-position/*/
function findPosX(obj)  {
    var curleft = 0;
    if(obj.offsetParent) {
        while(1) {
          curleft += obj.offsetLeft;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    }
    else if(obj.x) curleft += obj.x;
    return curleft;
  }

function findPosY(obj)  {
    var curtop = 0;
    if(obj.offsetParent)
        while(1)
        {
          curtop += obj.offsetTop;
          if(!obj.offsetParent)
            break;
          obj = obj.offsetParent;
        }
    else if(obj.y)
        curtop += obj.y;
    return curtop;
}
  
/*
 * Function: Script for Learning Browse
 * Author: Oliver Arnoczky
 * Date: 11-24-2004
 * Purpose: Hide or shows the different views on the product family and detail pages
 */
function showView(v) {    
    var a1 = getObject('mainview_link');
    var b1 = getObject('secondview_link');
    var c1 = getObject('thirdview_link');
    var a2 = getObject('mainview');
    var b2 = getObject('secondview');
    var c2 = getObject('thirdview');
    if (v==0) { 
        a1.className = 'tabActive';
        if (b1 != null) b1.className = 'tab';
        if (c1 != null) c1.className='tab';
        a2.style.display='block';
        if (b2 != null) b2.style.display='none';
        if (c2 != null) c2.style.display='none';
    }
    if (v==1) {
        a1.className = 'tab';
        b1.className = 'tabActive';
        if (c1 != null) c1.className='tab';
        a2.style.display='none';
        b2.style.display='block';
        if (c2 != null) c2.style.display='none';
    }
    if (v==2) {        
        a1.className = 'tab';
        if (b1 != null)  b1.className = 'tab';
        c1.className='tabActive';              
        a2.style.display='none';        
        if (b2 != null)  b2.style.display='none';                
        c2.style.display='block';
    }
}

function displayPopUpLayer (reference, elementId, center) {
    var xpos = findPosX(reference);
    var ypos = findPosY(reference);
    var box = document.getElementById(elementId);
    if (box != null) {
        box.style.display='block';
        box.style.position='absolute';
        box.style.top=ypos-20+'px';
        if (center == true) {
        	box.style.left=xpos-(box.offsetWidth/2)+20+'px';
        } else {
        	box.style.left=xpos+20+'px';
        } 
    }
}

// Function : Script to close the pop-up layer
function closeMe (elementId) {
    var box = document.getElementById(elementId);
    if (box != null) {
        box.style.display='none';
    }
}       

function display(elementName, displayType) { //display type is "block" or "inline",  by default "block"
    var element = getObject(elementName);
    if (element != null) {
        if (displayType != null) {
            element.style.display=displayType;
        } else {
            element.style.display='block';
        }
    }
}

function hide (elementName) {
    var element = getObject(elementName);
    if (element != null) {
        element.style.display='none';
    }
}

/* Function to allow the easy change of an elements class */
function changeClassOfId(id, newClass) {
	identity=document.getElementById(id);
	identity.className=newClass;
}

/**
The Ultimate getElementsByClassName
Written by Jonathan Snook, http://www.snook.ca/jonathan
**/
// ---
// Revised version May 11th 2007
function getElementsByClassName(oElm, strTagName, strClassName){	
	var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);	
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/-/g, "\-");	
	var oRegExp = new RegExp("(^|\s)" + strClassName + "(\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}
	return (arrReturnElements)
}

// ---
// Array support for the push method in IE 5
if(typeof Array.prototype.push != "function"){
	Array.prototype.push = ArrayPush;
	function ArrayPush(value){
		this[this.length] = value;
	}
}

function rotateBanners() {
	var elements = getElementsByClassName(document.getElementById("matchingBlockContent"), "div", "rotate-banner");
	var ran_number= Math.floor(Math.random()*elements.length);
	for (i = 0; i < elements.length; i++) {
		if (i == ran_number) {
			elements[i].style.display='block';
		}
	}
}
