var lastMenuId = 0;
var timer;
var mSheets = new Array();
var currZ = 100;
var mReady = false;
var menu_path = new Array();

function setClass(obj, cl){
	if (obj.className!=cl) obj.className = cl;
}

function MenuLink(textVal, linkVal, subVal){
	this.text = textVal;
	this.action = linkVal;
	this.submenu = subVal;
}

function menuHideAll(){
	for (var c in mSheets) mSheets[c].hide();
}

function menuHideTimerSet(){
	timer = window.setTimeout(menuHideAll, 300);
}

function menuHideTimerReset(){
	if (timer) window.clearTimeout(timer);
}

function menuAddLink(textVal, linkVal){
	this.links[this.links.length] = new MenuLink(textVal, linkVal, null);
}

function menuAddSubmenu(textVal, linkVal){
	this.links[this.links.length] = new MenuLink(textVal, linkVal, new MenuSheet(this));
}

function menuShow(leftVal, topVal, obj){
	this.block.style.left = leftVal + "px";
	this.block.style.top = topVal + "px";
	this.block.style.display = "block";
}

function menuHide(){
	this.hideCh();
	this.block.style.display = "none";
}

function menuFlip(leftVal, topVal){
	var disp = this.block.style.display;
	if (disp == "none") this.show(leftVal, topVal);
	else this.hide();
}

function menuHideCh(){
	for (var c in this.links){
		curLink = this.links[c];
		if (curLink.submenu) curLink.submenu.hide();
	}
}

function menuCreate(path){
	//if (!mSheets) return;
	var res = "<div class=\"menu-sh\" onmouseout=\"menuHideTimerSet()\" onmouseover=\"menuHideTimerReset()\"><table cellpadding=\"0\" cellspacing=\"0\" class=\"tab-menu-sh\">";
	var curLink;
	var newPath;
	if (path == null) path = "mSheets[" + this.id + "]";
	for (var c in this.links){
		curLink = this.links[c];
		res += "<tr valign=\"center\"><td class=\"blk-menu-sh";
		if (curLink.submenu) res += " blk-menu-arr";
		res += "\" onmouseover=\"setClass(this, 'blk-menu-sh-act";
		if (curLink.submenu) res += " blk-menu-arr-act";
		res += "'); ";
		res += path + ".hideCh()";
		if (curLink.submenu){
			newPath = path + ".links[" + c + "].submenu";
			res += "; " + newPath + ".show(getLeftPos(this) + this.offsetWidth, getTopPos(this) - 1,this)";
			curLink.submenu.create(newPath);
		}
		res += "\" onmouseout=\"setClass(this, 'blk-menu-sh";
		if (curLink.submenu) res += " blk-menu-arr";
		res += "')\" onclick=\"gotoURL('"+curLink.action+"')\" nowrap=\"nowrap\">" + curLink.text + "</td></tr>";
	}
	res += "</table></div>";
	this.block.innerHTML = res;
}

function MenuSheet(parentObj){
	this.links = new Array();
	this.addLink = menuAddLink;
	this.addSubmenu = menuAddSubmenu;
	this.create = menuCreate;
	this.show = menuShow;
	this.hide = menuHide;
	this.flip = menuFlip;
	this.hideCh = menuHideCh;
	this.id = lastMenuId;
	lastMenuId++;
	this.parent = parentObj; 
	this.block = document.createElement("DIV");
	this.block.className = "blk-menu";
	this.block.style.position = "absolute";
	this.block.style.display = "none";
	this.block.style.zIndex = currZ;
	currZ++;
	this.block.id = "ms" + this.id;
	document.body.appendChild(this.block);
}

function showMenu(objVal, numVal){
	
	if (mReady){
		menuHideAll();
		/*objVal.className = "menu_item_selected";
		
		if ( document.getElementById(obj_left) )
			document.getElementById(obj_left).className='menu_sep_selected';
		
		if ( document.getElementById(obj_right) )
			document.getElementById(obj_right).className='menu_sep_selected';
		*/
		if ( numVal >= 0 && mSheets[numVal] ) {
			mSheets[numVal].show(getLeftPos(objVal), getTopPos(objVal)+32,objVal);
			menuHideTimerReset();
		}
	}
}

function hideMenu(objVal, numVal){
	
	if (mReady){
		menuHideTimerSet();
	}
}
function requestCartclass(prodid,imgid,attri,lang) {

var quantid ='cart_quantity';
var buttonid ='ajaxbutton' + prodid;
var quant = document.getElementById(quantid).value;
var attri = attri;
var lang = lang;
var button = document.getElementById(buttonid).innerHTML;
var cartimgid =imgid;
var cartimgsrc = document.getElementById(cartimgid).src;

cartimgsrc=cartimgsrc.replace('.jpg', "green.jpg");
cartimgsrc=cartimgsrc.replace('greengreen.jpg', "green.jpg");
document.getElementById(cartimgid).src = cartimgsrc;
this.prodid=prodid;
this.quantid = quantid;
this.buttonid = buttonid;
this.quant = quant;
this.button = button;
this.attris = attri;
this.langs = lang;
this.langoption = 'langoption'+this.prodid;
if(document.getElementById(this.langoption))
    {
        var selected_value = document.getElementById(this.langoption).options[document.getElementById(this.langoption).selectedIndex].value;
        this.langs = selected_value;
    }
var url4 ="http://www.pmpathway.com/add_to_cart.php?action=add_ajax&products_id="+ this.prodid + '&cart_quantity=' + this.quant+ '&attribute=' + this.attris+ '&lang=' + this.langs;
http.open("GET", url4 , true);
http.onreadystatechange = handleHttpResponse4;
http.send(null);

	function handleHttpResponse4() {
		if (http.readyState == 4) {
			  if(http.status==200) {
			  	var results=http.responseText;
//			alert("The server replied with: " + button + buttonid);

			  document.getElementById('cart').innerHTML = results;
                        document.getElementById('cart').className="withcartrightbg";
//			  document.getElementById(buttonid).innerHTML = button;
//			  document.getElementById(buttonid).style.display = 'block';
			  }
  			}
		}

}

function requestCart2(prodid,imgid,attri,lang) {
var myPoint = new requestCartclass(prodid,imgid,attri,lang);
}

function getHTTPObject() {
  var xmlhttp;

  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }

}
  return xmlhttp;


}
var http = getHTTPObject();



