/* 
Script made by Martial Boissonneault © 2001-2006 http://getElementById.com
This script may be used and changed freely as long as this msg is intact
Visit http://getElementById.com/ for more free scripts and tutorials.
*/

var ie5 = (document.getElementById && document.all);
var ns6 = (document.getElementById && !document.all);

function setXML(rq){
	var menuTab = rq.responseXML.getElementsByTagName('menu');
	for (var i=0;i<menuTab.length;i++){
		var p = document.createElement('p');
		var span = document.createElement('span');
		if(menuTab[i].getAttribute('url') != null){
			var b = document.createElement('b');
		    span.appendChild(b);
		    var txt = menuTab[i].getAttribute('text');
			span.appendChild(document.createTextNode(txt));
			var url = menuTab[i].getAttribute('url');
			p.onclick = new Function("setCookie('mn'," + i + "); document.location.href = '" + url + "';");
			if (i == 0) {
			    //ie5 ? p.setAttribute("className", "menuOut") : p.setAttribute("class", "menuOut");
			    p.setAttribute("class", "menuOut");
			    p.onmouseover = new Function("changeClass('menu" + i + "','menuOver1');");
			    p.onmouseout = new Function("changeClass('menu" + i + "','menuOut');");
			} else if (i == 1) {
			    //ie5 ? p.setAttribute("className", "menuOut") : p.setAttribute("class", "menuOut");
			    p.setAttribute("class", "menuOut");
			    p.onmouseover = new Function("changeClass('menu" + i + "','menuOver2');");
			    p.onmouseout = new Function("changeClass('menu" + i + "','menuOut');");
            } else {
			    //ie5 ? p.setAttribute("className", "menuOut") : p.setAttribute("class", "menuOut");
			    p.setAttribute("class", "menuOut");
			    p.onmouseover = new Function("changeClass('menu" + i + "','menuOver');");
			    p.onmouseout = new Function("changeClass('menu" + i + "','menuOut');");
			}
			
		}else{
		    var b = document.createElement('b');
		    var img = document.createElement('img');
		    img.src = 'images/plus.gif';
		    b.appendChild(img);
		    span.appendChild(b);
			var txt = menuTab[i].getAttribute('text');
			span.appendChild(document.createTextNode(txt));
			p.onclick = new Function("checkSign(document.getElementById('menu" + i + "')); switchMenu('sub" + i + "');");
			if (i == 0) {
			    //ie5 ? p.setAttribute("className", "menuOutPlus") : p.setAttribute("class", "menuOutPlus");
			    p.setAttribute("class", "menuOutPlus");
			    p.onmouseover = new Function("changeClass('menu" + i + "','menuOverPlus1');");
			    p.onmouseout = new Function("changeClass('menu" + i + "','menuOutPlus');");

			} else if (i == 1) {
			    //ie5 ? p.setAttribute("className", "menuOutPlus") : p.setAttribute("class", "menuOutPlus");
			    p.setAttribute("class", "menuOutPlus");
			    p.onmouseover = new Function("changeClass('menu" + i + "','menuOverPlus2');");
			    p.onmouseout = new Function("changeClass('menu" + i + "','menuOutPlus');");
			} else {
			    //ie5 ? p.setAttribute("className", "menuOutPlus") : p.setAttribute("class", "menuOutPlus");
			    p.setAttribute("class", "menuOutPlus");
			    p.onmouseover = new Function("changeClass('menu" + i + "','menuOverPlus');");
			    p.onmouseout = new Function("changeClass('menu" + i + "','menuOutPlus');");
			}
			
		   
		}
		if(ie5){p.style.cssText= 'width: 100%;';}
		p.setAttribute("id", "menu" + i);
		p.appendChild(span);
		document.getElementById('SwitchMenu').appendChild(p);
		var d = document.createElement('div');
		d.setAttribute("id", "sub" + i);
		//ie5?d.setAttribute("className", "submenu"):d.setAttribute("class", "submenu");
		d.setAttribute("class", "submenu");
		if (getCookie('mn')!= ""){
			if (i == getCookie('mn')){
				d.style.cssText = 'display:block;';
				var img = p.getElementsByTagName("img")[0];
				if(typeof(img)!="undefined"){
				    img.src = "images/minus.gif";
				}
			}else{
				d.style.cssText = 'display:none;';
			}
		}else{
			d.style.cssText = 'display:none;';
		}
		var subMenuTab = menuTab[i].getElementsByTagName('submenu');
		if(subMenuTab.length>0){
		    document.getElementById('SwitchMenu').appendChild(d);
		}
		for (var j=0;j<subMenuTab.length;j++){
			var a = document.createElement('a');
			var subUrl = subMenuTab[j].getAttribute('url');
            a.style.cursor = "pointer";
			a.onclick = new Function("setCookie('mn',"+i+");" + "document.location.href = '" + subUrl + "';");
			var txt = subMenuTab[j].getAttribute('text');
			var spn = document.createElement('span');
			spn.appendChild(document.createTextNode(txt));
			a.appendChild(spn);
			d.appendChild(a);
			var b = document.createElement('br');
			d.appendChild(b);
		}
	}  
}

var http_request = false;

function ajaxSwitchMenu(url){
	http_request = false;
	if (window.XMLHttpRequest){ 
		http_request = new XMLHttpRequest();
		if (http_request.overrideMimeType){
			http_request.overrideMimeType('text/xml');
		}
	}else if(window.ActiveXObject){ 
		try{
			http_request = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
    			http_request = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(e){}
		}
	}
	if (!http_request) {
		alert('Cannot create an XMLHTTP instance');
		return false;
	}
	http_request.onreadystatechange = displayXML;
	http_request.open('GET', url, true);
	http_request.send(null);
}

function displayXML(){
	if (http_request.readyState != 4) {
		//document.getElementById("SwitchMenu").innerHTML = "<div><img src='images/loading.gif' alt='loading' /></div>";
	}else{ 
		if (http_request.status == 200) {
			setTimeout('document.getElementById(\'SwitchMenu\').innerHTML = ""', 1000);
			setTimeout('setXML(http_request)', 1000);
		}else{
			alert('There was a problem with the request.');
		}
	} 
} 

function getURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	if(strHref.indexOf("?")>-1){
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for (var i=0;i<aQueryString.length;i++){
			if (aQueryString[i].indexOf(strParamName + "=")>-1){
				var aParam = aQueryString[i].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
} 

function switchMenu(obj){
	if(document.getElementById){
	var el = document.getElementById(obj);
	var ar = document.getElementById("SwitchMenu").getElementsByTagName("DIV");
		if(el.style.display == "none"){
			for (var i=0; i<ar.length; i++){
				ar[i].style.display = "none";
			}
			el.style.display = "block";
//			$(document.body).click(function () {
//			    $("#div").attr(obj).slideDown('slow');
//            });
			
		}else{
			el.style.display = "none";
		}
	}
}

function changeClass(menu, newClass) { 
	 if (document.getElementById) { 
	 	document.getElementById(menu).className = newClass;
	 } 
} 

function checkSign(obj){
    var img = obj.getElementsByTagName("img")[0];
    var ar = document.getElementById("SwitchMenu").getElementsByTagName("p");
    if(img.src.indexOf("plus.gif")>-1){
        for (var i=0; i<ar.length; i++){
            var img1=ar[i].getElementsByTagName("img")[0];
            if(typeof(img1)!="undefined"){
                img1.src = "images/plus.gif";
            }
        }
        img.src = "images/minus.gif";
    }else{
        img.src = "images/plus.gif";
    }
}

function getCookie(Name){ 
    var re=new RegExp(Name+"=[^;]+", "i") //construct RE to search for target name/value pair
	if (document.cookie.match(re)) //if cookie found
        return document.cookie.match(re)[0].split("=")[1] //return its value
return null
}

function setCookie(name, value)
{
    document.cookie = name + "=" + value + "; path=/"
   // del_cookie('globalfromprice_sortby');
   // del_cookie('globaltoprice_sortby');
}
function del_cookie(name) {
    document.cookie = name + '=; path=/; expires=Thu, 01-Jan-70 00:00:01 GMT;';
} 