var IsIE = (/msie/).test( navigator.userAgent.toLowerCase() ) ;
if(!IsIE){
	IsGecko = true;
}

function mainNavOver(self){
	self.className = 'mainnva4hover';
}

function mainNavOut(self){
	self.className = 'mainnva4';
}



/* Get Exact Scroll Size */
function getScrollTop(){
	var sT = 0;
	
	sT = document.body.scrollTop; 
	if(!IsIE && !sT){
		sT = document.documentElement.scrollTop;
	}
	
	return sT;
}

function getScrollLeft(){
	var sL = 0;

	sL = document.body.scrollLeft;
	if(!IsIE && !sL){
		sL = document.documentElement.scrollLeft;
	}
	
	return sL;
}

/*
Mouses Actions
*/
function getMouseX(e){
	
	var tempX = 0;
	if (IsIE) {
		if(event){
			tempX = event.clientX + getScrollLeft();
		}
	}else{
		tempX = e.pageX;
	}
	
	if (tempX < 0){ tempX = 0; }
	
	return tempX;
}

function getMouseY(e){
	var tempY = 0;

	if (IsIE) {
		
		if(event){
			tempY = event.clientY + getScrollTop();
		}
	} else {
		tempY = e.pageY;
    }  
	if (tempY < 0){ tempY = 0; }
	
	return tempY;
}

/*
Get Div Position
*/
function getAreaLeft(o){
	var l=o.offsetLeft;      
    while(o=o.offsetParent){    
      l+=o.offsetLeft;     
    }
	return l;
}
function getAreaTop(o){
	var t=o.offsetTop;      
    while(o=o.offsetParent){    
      t+=o.offsetTop;     
    }
	return t;
}

/*
x: mouse X
y: mouse Y
l: left of the area
t: top of the area
r: right of the area
b: bottom of the area
*/
function isInArea(x, y, l, t, r, b){
	isIn = false;

	if(x >= l && x <= r){
		if(y >= t && y <= b){
			isIn = true;
		}
	}
	return isIn;
}

var i = 0;

function browserMouseMoving(e){
	var x = getMouseX(e);
	var y = getMouseY(e);
	
	the_mainnav1=(document.all)?document.all('mainnav1'):document.getElementById('mainnav1');
	the_maincat2=(document.all)?document.all('maincat2'):document.getElementById('maincat2');

	isIn1 = false;
	if(the_mainnav1 && the_maincat2){
		mX1 = getAreaLeft(the_mainnav1);
		mY1 = getAreaTop(the_mainnav1);

		mX2 = getAreaLeft(the_maincat2) + the_maincat2.offsetWidth;
		mY2 = getAreaTop(the_maincat2) + the_maincat2.offsetHeight;

		isIn1 = isInArea(x, y, mX1, mY1, mX2, mY2);
	}
	
	the_catNav=(document.all)?document.all('catNav'):document.getElementById('catNav');

	isIn2 = false;
	//if(catNav){
	if(the_catNav){
		mX1 = getAreaLeft(the_catNav);
		mY1 = getAreaTop(the_catNav);
		mX2 = mX1 + the_catNav.offsetWidth;
		mY2 = mY1 + the_catNav.offsetHeight;
		isIn2 = isInArea(x, y, mX1, mY1, mX2, mY2);
	}

	if(!isIn1 && !isIn2){
		the_catNavStyle = (document.all)?document.all('catNav').style:document.getElementById('catNav').style;
		the_catNav2Style = (document.all)?document.all('catNav2').style:document.getElementById('catNav2').style;
		the_searchbarStyle = (document.all)?document.all('searchbar').style:document.getElementById('searchbar').style;
		
		the_searchbar2Style = (document.all)?document.all('searchbar2').style:document.getElementById('searchbar2').style;

		the_catNavStyle.display = 'none';
		the_catNav2Style.display = 'none';
		the_searchbarStyle.display = '';
		the_searchbar2Style.display = '';

		if (!IsIE) {
			document.removeEventListener("mousemove", browserMouseMoving, false);
		}else{
			document.detachEvent('onmousemove', browserMouseMoving);
		}
	}
}


function mainCatOver(){
	the_catNavStyle = (document.all)?document.all('catNav').style:document.getElementById('catNav').style;
	the_catNav2Style = (document.all)?document.all('catNav2').style:document.getElementById('catNav2').style;

	the_searchbarStyle = (document.all)?document.all('searchbar').style:document.getElementById('searchbar').style;
	the_searchbar2Style = (document.all)?document.all('searchbar2').style:document.getElementById('searchbar2').style;

	the_catNavStyle.display = '';
	the_catNav2Style.display = '';
	the_searchbarStyle.display = 'none';
	the_searchbar2Style.display = 'none';

	if (!IsIE) {
		document.addEventListener("mousemove", browserMouseMoving, false);
	}else{
		document.attachEvent('onmousemove', browserMouseMoving);
	}
}


function htmlspecialchars_decode_x (string, quote_style) {
    // *     example 1: htmlspecialchars_decode("<p>this -&gt; &quot;</p>", 'ENT_NOQUOTES');
    // *     returns 1: '<p>this -> &quot;</p>'
    // *     example 2: htmlspecialchars_decode("&amp;quot;");
    // *     returns 2: '&quot;'

    var optTemp = 0, i = 0, noquotes= false;
    if (typeof quote_style === 'undefined') {
        quote_style = 2;
    }
    string = string.toString().replace(/&lt;/g, '<').replace(/&gt;/g, '>');
    var OPTS = {
        'ENT_NOQUOTES': 0,
        'ENT_HTML_QUOTE_SINGLE' : 1,
        'ENT_HTML_QUOTE_DOUBLE' : 2,
        'ENT_COMPAT': 2,
        'ENT_QUOTES': 3,
        'ENT_IGNORE' : 4
    };
    if (quote_style === 0) {
        noquotes = true;
    }
    if (typeof quote_style !== 'number') { // Allow for a single string or an array of string flags
        quote_style = [].concat(quote_style);
        for (i=0; i < quote_style.length; i++) {
            // Resolve string input to bitwise e.g. 'PATHINFO_EXTENSION' becomes 4
            if (OPTS[quote_style[i]] === 0) {
                noquotes = true;
            }
            else if (OPTS[quote_style[i]]) {
                optTemp = optTemp | OPTS[quote_style[i]];
            }
        }
        quote_style = optTemp;
    }
    if (quote_style & OPTS.ENT_HTML_QUOTE_SINGLE) {
        string = string.replace(/&#0*39;/g, "'"); // PHP doesn't currently escape if more than one 0, but it should
        // string = string.replace(/&apos;|&#x0*27;/g, "'"); // This would also be useful here, but not a part of PHP
    }
    if (!noquotes) {
        string = string.replace(/&quot;/g, '"');
    }
    // Put this in last place to avoid escape being double-decoded
    string = string.replace(/&amp;/g, '&');
    return string;
}