function ManipulateStyleClass(action, obj, class1, class2) {
/*
	action - defines the action you want the function to perform.
	obj - the object in question.
	class1 - the name of the first class
	class2 - the name of the second class
	
	Possible actions are:
	
	swap
		replaces class c1 with class c2 in object o.
	add
		adds class c1 to the object o.
	remove
		removes class c1 from the object o.
	check
		test if class c1 is already applied to object o and returns true or false. 
*/

	switch (action){
		case 'swap':
			obj.className=!ManipulateStyleClass('check',obj,class1)?obj.className.replace(class2,class1):obj.className.replace(class1,class2);
			break;
		case 'add':
			if(!ManipulateStyleClass('check',obj,class1)){obj.className+=obj.className?' '+class1:class1;}
			break;
		case 'remove':
			var rep=obj.className.match(' '+class1)?' '+class1:class1;
			obj.className=obj.className.replace(rep,'');
			break;
		case 'check':
			return new RegExp('\\b'+class1+'\\b').test(obj.className)
			break;
	}
}


function getElementsByStyleClass(className) {
/* --- find all elements with a given style class name */
	var all = document.all ? document.all :
		document.getElementsByTagName('*');
	var elements = new Array();
	for (var e = 0; e < all.length; e++)
		if (all[e].className == className)
			elements[elements.length] = all[e];
	return elements;
}


function AddEvent(object, evt, func, capture) {
/**
*   Add an event listener to an object
*   @param      object
*   @param      evt         event
*   @param      func        function
*   @param      capture
*   @return     boolean
*/

	if(typeof func != 'function') {
        return false;
    }
    if(object.addEventListener) {
        object.addEventListener(evt, func, capture);
        return true;
    } else if(object.attachEvent) {
        object.attachEvent('on' + evt, func);
        return true;
    }
    return false;
}

function RemoveEvent(object, evt, func, capture) {
/**
*   Removes an event listener
*   @param      object
*   @param      evt         event
*   @param      func        function
*   @param      capture
*   @return     boolean
*/
    if(typeof func != 'function') {
        return false;
    }
    if(object.removeEventListener) {
        object.removeEventListener(evt, func, capture);
        return true;
    } else if(object.detachEvent) {
        object.detachEvent('on' + evt, func);
        return true;
    }
    return false;
}


/**
*   Gets an event with all needed properties
*   @param      e           event
*   @return     event object
*/
function GetEvent(e)
{
    if(!e)
    {
        e               = window.event;
    }
 
    if(e.layerX)
    {
        e.offsetX       = e.layerX;
        e.offsetY       = e.layerY;
    }
 
    if(e.type == 'mouseover' && !e.relatedTarget)
    {
        e.relatedTarget     = e.fromElement;
    }
    else if(e.type == 'mouseout' && !e.relatedTarget)
    {
        e.relatedTarget     = e.toElement;
    }
 
    e.src               = e.srcElement || e.target;
    e.key               = e.keyCode || e.charCode;
 
    return e;
}




// not yet in use... (from buy.com headerscript.js
function getProductData(sku,grpID,insert,count) { // 204737126,'mpHomeBox',3,60
// www.buy.com/retail/product_ajax_postFile.asp?sku=204737126&grpID=mpHomeBox&itemID=3&count=60

	if(prodZoomCookie == "1") {
		hideProductDataDiv('',grpID,count);
		if(document.getElementById('pdHover_'+grpID+'_'+insert).value == sku && document.getElementById('pdInsert_'+grpID+'_'+insert).innerHTML.length > 0){
			document.getElementById('pdInsert_'+grpID+'_'+insert).style.visibility = "visible";
		}else{
			document.getElementById('pdHover_'+grpID+'_'+insert).value = sku;
			var url = '/retail/product_ajax_postFile.asp?sku='+sku+'&grpID='+grpID+'&itemID='+insert+'&count='+count
	
			if(window.XMLHttpRequest) {
				try {
					req = new XMLHttpRequest();
				} catch(e) {
					req = false;
				}
				// branch for IE/Windows ActiveX version
			} else if(window.ActiveXObject) {
				try {
					req = new ActiveXObject("Msxml2.XMLHTTP");
				} catch(e) {
					try {
						req = new ActiveXObject("Microsoft.XMLHTTP");
					} catch(e) {
						req = false;
					}
				}
			}
	
			if(req) {
				//req.onreadystatechange = processRequest;
				req.onreadystatechange = function() {
					if (req.readyState == 4) {
						if (req.status == 200) {
							document.getElementById('pdInsert_'+grpID+'_'+insert).style.visibility = "visible";
							document.getElementById('pdInsert_'+grpID+'_'+insert).innerHTML = req.responseText;
							//setGrouperPlayerStyle('pdInsert_'+grpID+'_'+insert);
						} else {
						}
					}
				};
				req.open("GET", url, true);
				req.send(null);
			}
		}
	}
}


function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

function Mid(str, start, len)
        /***
                IN: str - the string we are LEFTing
                    start - our string's starting position (0 based!!)
                    len - how many characters from start we want to get

                RETVAL: The substring from start to start+len
        ***/
        {
                // Make sure start and len are within proper bounds
                if (start < 0 || len < 0) return "";

                var iEnd, iLen = String(str).length;
                if (start + len > iLen)
                        iEnd = iLen;
                else
                        iEnd = start + len;

                return String(str).substring(start,iEnd);
        }
		
		
function Len(str)
        /***
                IN: str - the string whose length we are interested in

                RETVAL: The number of characters in the string
        ***/
        {  return String(str).length;  }


function LTrim(str)
        /***
                PURPOSE: Remove leading blanks from our string.
                IN: str - the string we want to LTrim

                RETVAL: An LTrimmed string!
        ***/
        {
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(0)) != -1) {
                    // We have a string with leading blank(s)...

                    var j=0, i = s.length;

                    // Iterate from the far left of string until we
                    // don't have any more whitespace...
                    while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                        j++;


                    // Get the substring from the first non-whitespace
                    // character to the end of the string...
                    s = s.substring(j, i);
                }

                return s;
        }
		
		
 function RTrim(str)
        /***
                PURPOSE: Remove trailing blanks from our string.
                IN: str - the string we want to RTrim

                RETVAL: An RTrimmed string!
        ***/
        {
                // We don't want to trip JUST spaces, but also tabs,
                // line feeds, etc.  Add anything else you want to
                // "trim" here in Whitespace
                var whitespace = new String(" \t\n\r");

                var s = new String(str);

                if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
                    // We have a string with trailing blank(s)...

                    var i = s.length - 1;       // Get length of string

                    // Iterate from the far right of string until we
                    // don't have any more whitespace...
                    while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                        i--;


                    // Get the substring from the front of the string to
                    // where the last non-whitespace character is...
                    s = s.substring(0, i+1);
                }

                return s;
        }
		
		
function Trim(str)
        /***
                PURPOSE: Remove trailing and leading blanks from our string.
                IN: str - the string we want to Trim

                RETVAL: A Trimmed string!
        ***/
        {
                return RTrim(LTrim(str));
        }


function InStr(strSearch, charSearchFor)
/*
InStr(strSearch, charSearchFor) : Returns the first location a substring (SearchForStr)
                           was found in the string str.  (If the character is not
                           found, -1 is returned.)
                           
Requires use of:
	Mid function
	Len function
*/
{
	for (i=0; i < Len(strSearch); i++)
	{
	    if (charSearchFor == Mid(strSearch, i, 1))
	    {
			return i;
	    }
	}
	return -1;
}


function get_mouse_y(event_i) {
	if (!event_i) {
		if (window.event) {
			event_i = window.event;
		}
		else {
			return;
		}
	}
	if (event_i.pageY) {
		return event_i.pageY;
	}
	else if (event_i.clientY) {
		return event_i.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}
	else {
		return null;
	}
}

function get_mouse_x(event_i) {
	if (!event_i) {
		if (window.event) {
			event_i = window.event;
		}
		else {
			return;
		}
	}
	if (event_i.pageX) {
		return event_i.pageX;
	}
	else if (event_i.clientX) {
		return event_i.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
	}
	else {
		return null;
	}
}



var Move =	{
/*
	This script is copyright (c) 2006 Elliot Swan under the
	Creative Commons Attribution-ShareAlike 2.5 license:
	http://creativecommons.org/licenses/by-sa/2.5/
	
	More information on this script can be found at:
	http://www.elliotswan.com/2006/04/12/move-and-copy/
*/

	copy	:   function(e, target)	{
	    var eId      = $(e);
	    var copyE    = eId.cloneNode(true);
	    var cLength  = copyE.childNodes.length -1;
	    copyE.id     = e+'-copy';

	    for(var i = 0; cLength >= i;  i++)	{
			if(copyE.childNodes[i].id) {
				var cNode   = copyE.childNodes[i];
				var firstId = cNode.id;
				cNode.id    = firstId+'-copy'; }
			}
			$(target).appendChild(copyE);
	    },
  element:  function(e, target, type)	{
	    var eId =  $(e);
	    if(type == 'move') {
	       $(target).appendChild(eId);
	    } else if(type == 'copy')	{
	       this.copy(e, target);
	    }
    }
}



if (getElementsByStyleClass('catNav_SearchBox')[0]) {
	//--- if search box exists, raise max character length on text field
	getElementsByStyleClass('catNav_SearchBox')[0].maxLength = 100;
}