/***************************************************
hidden div 'DivItem_Menu' required

m_id - button id (numeric)
pr_id - product id (numeric)
pr_url - product url (string)
pr_info - product info (boolean 0/1)
pr_trial - product trial (boolean 0/1)
pr_pricing - pricing information (boolean 0/1)
pr_req - system requirements (boolean 0/1)
pr_dlink - download link (boolean 0/1)
pr_blink - buy link (boolean 0/1)
aph_id - ad product history id (numeric)
****************************************************/

//if (document.images) {
	button_on =new Image();  button_on.src ="/images/prodmenu_iconh.gif"; 
	button_off=new Image();  button_off.src="/images/prodmenu_icon.gif"; 
	
	prodmenu_icon_info = new Image();  prodmenu_icon_info.src = "/images/prodmenu_info.gif";
	prodmenu_icon_price = new Image();  prodmenu_icon_price.src = "/images/prodmenu_price.gif";
	prodmenu_icon_down = new Image();  prodmenu_icon_down.src = "/images/prodmenu_down.gif";
	prodmenu_icon_cart = new Image();  prodmenu_icon_cart.src = "/images/prodmenu_cart.gif";
	prodmenu_bg_image = new Image();  prodmenu_bg_image.src = "/images/prodmenu_bg.gif";
//}

var active_m_id;

function fShowSubMenu(m_id, pr_id, pr_url, pr_info, pr_trial, pr_pricing, pr_req, pr_dlink, pr_blink, aph_id){
		var div_obj = document.getElementById('DivItem_Menu');
		//if (div_obj.style.visibility=='visible') div_obj.style.visibility='hidden';
				
		if (m_id == active_m_id) {
			fHideSubMenus();
		} else {
		
			fHideSubMenus();
			var div_width=160;
			//var div_height=46;
			
			//var div_left=document.getElementById('button_'+m_id).offsetLeft;
			var div_left=findPosX(document.getElementById('button_'+m_id));
			
			div_obj.style.left=div_left+"px"; 
			
			//var div_top=document.getElementById('button_'+m_id).offsetTop+document.getElementById('button_'+m_id).height;
			//var div_top=findPosY(document.getElementById('button_'+m_id))+document.getElementById('button_'+m_id).height;
			
			//div_obj.style.top=div_top+"px";
			
			var div_text="<div class='prodmenu_shad'>";
						
			if (navigator.appName =="Microsoft Internet Explorer" && navigator.userAgent.indexOf("Opera") < 0) div_text = div_text+"<iframe name=iframM2 frameborder=0 src=about:blank style=position:absolute;width:160px;height:133px;overflow-x:hidden;overflow-y:hidden;z-index:-1; scrolling=No></iframe>";
			
			div_text = div_text+"<table class='prodmenu' width='"+div_width+"' border='0' cellspacing='0' cellpadding='0' onMouseover=\"clearhidemenu()\" onMouseout=\"dynamichide(event)\">";
						
			if (pr_info==1){
				div_text = div_text+"<tr id='tr_1' class='prodmenu_itemtr' onmouseout=\"f_sm_items_Out('1')\" onmouseover=\"f_sm_items_Over('1')\" onclick=\"f_sm_Action1("+pr_id+", '"+aph_id+"','"+pr_url+"')\" height='22'><td>";
				div_text = div_text+"<div id='prodmenu_item'>";
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_info.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Product Information</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			else {
				div_text = div_text+"<tr id='tr_1' height='22'><td>";
				if (pr_info==2) {
					div_text = div_text+"<div class='prodmenu_item_disabled'>";
				} else {
					div_text = div_text+"<div class='prodmenu_item_inactive'>";
				}				
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_info.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Product Information</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";				
			}
			
			/*
			if (pr_trial==1){
				div_text = div_text+"<tr id='tr_2' class='prodmenu_itemtr' onmouseout=\"f_sm_items_Out('2')\" onmouseover=\"f_sm_items_Over('2')\" onclick=\"f_sm_Action2("+pr_id+", "+aph_id+")\" height='22'><td>";
				div_text = div_text+"<div id='prodmenu_item'>";
				div_text = div_text+"<div class='prodmenu_icon'>&nbsp;</div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Trial</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			else{
				div_text = div_text+"<tr id='tr_2' height='22'><td>";
				if (pr_trial==2) {
					div_text = div_text+"<div class='prodmenu_item_disabled'>";
				} else {
					div_text = div_text+"<div class='prodmenu_item_inactive'>";
				}
				div_text = div_text+"<div class='prodmenu_icon'>&nbsp;</div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Trial</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			*/
			
			if (pr_pricing==1){
				div_text = div_text+"<tr id='tr_3' class='prodmenu_itemtr' onmouseout=\"f_sm_items_Out('3')\" onmouseover=\"f_sm_items_Over('3')\" onclick=\"f_sm_Action3("+pr_id+", '"+aph_id+"')\" height='22'><td>";
				div_text = div_text+"<div id='prodmenu_item'>";
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_price.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Pricing information</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			else{
				div_text = div_text+"<tr id='tr_3' height='22'><td>";
				if (pr_pricing==2) {
					div_text = div_text+"<div class='prodmenu_item_disabled'>";
				} else {
					div_text = div_text+"<div class='prodmenu_item_inactive'>";
				}
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_price.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Pricing information</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			
			if (pr_req==1){
				div_text = div_text+"<tr id='tr_4' class='prodmenu_itemtr' onmouseout=\"f_sm_items_Out('4')\" onmouseover=\"f_sm_items_Over('4')\" onclick=\"f_sm_Action4("+pr_id+", '"+aph_id+"')\" height='22'><td>";
				div_text = div_text+"<div id='prodmenu_item'>";
				div_text = div_text+"<div class='prodmenu_icon'>&nbsp;</div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;System requirements</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			else{
				div_text = div_text+"<tr id='tr_4' height='22'><td>";
				if (pr_req==2) {
					div_text = div_text+"<div class='prodmenu_item_disabled'>";
				} else {
					div_text = div_text+"<div class='prodmenu_item_inactive'>";
				}
				div_text = div_text+"<div class='prodmenu_icon'>&nbsp;</div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;System requirements</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}	
				
			div_text = div_text+"<tr><td><div class='prodmenu_sep'></div></td></tr>";
			
			if (pr_dlink==1){
				div_text = div_text+"<tr id='tr_5' class='prodmenu_itemtr' onmouseout=\"f_sm_items_Out('5')\" onmouseover=\"f_sm_items_Over('5')\" onclick=\"f_sm_Action5("+pr_id+", '"+aph_id+"')\" height='22'><td>";
				div_text = div_text+"<div id='prodmenu_item'>";
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_down.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Add to Download Basket</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			else{
				div_text = div_text+"<tr id='tr_5' height='22'><td>";
				if (pr_dlink==2) {
					div_text = div_text+"<div class='prodmenu_item_disabled'>";
				} else {
					div_text = div_text+"<div class='prodmenu_item_inactive'>";
				}
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_down.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Add to Download Basket</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}					
			
			if (pr_blink==1){
				div_text = div_text+"<tr id='tr_6' class='prodmenu_itemtr' onmouseout=\"f_sm_items_Out('6')\" onmouseover=\"f_sm_items_Over('6')\" onclick=\"f_sm_Action6("+pr_id+", '"+aph_id+"')\" height='22'><td>";
				div_text = div_text+"<div id='prodmenu_item'>";
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_cart.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Add to Shopping Cart</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}
			else{
				div_text = div_text+"<tr id='tr_6' height='22'><td>";
				if (pr_blink==2) {
					div_text = div_text+"<div class='prodmenu_item_disabled'>";
				} else {
					div_text = div_text+"<div class='prodmenu_item_inactive'>";
				}
				div_text = div_text+"<div class='prodmenu_icon'><img src='/images/prodmenu_cart.gif' width='12' height='12' border='0'></div>";
				div_text = div_text+"<div class='prodmenu_text'>&nbsp;&nbsp;Add to Shopping Cart</div>";
				div_text = div_text+"</div>";
				div_text = div_text+"</td></tr>";
			}				
			
		
			div_text = div_text+"</table></div>";
			div_obj.innerHTML=div_text;
			
//////////////////////////////////////////////////////////////////			

			var doc_h;
			if (document.body.clientHeight)	doc_h = document.body.clientHeight;
			if (document.body.offsetHeight)	doc_h = document.body.offsetHeight; 
						
			var button_top=findPosY(document.getElementById('button_'+m_id))
			var button_h=document.getElementById('button_'+m_id).height;
			var menu_h=div_obj.offsetHeight;

			/*
			if ((button_top+button_h+menu_h) <= doc_h) {
				var div_top=button_top+button_h;
			} else {
				var div_top=button_top-menu_h+4;
			}
						
			div_obj.style.top=div_top+"px";
			*/
			
			
			var window_h;
			if (self.innerHeight) { window_h = self.innerHeight; }
			else if (document.documentElement.clientHeight) { window_h = document.documentElement.clientHeight; }
			else if (document.body) { window_h = document.body.clientHeight; }

			var scroll_h;
			if (self.pageYOffset) {	scroll_h = self.pageYOffset; }
			else if (document.documentElement.scrollTop) { scroll_h = document.documentElement.scrollTop; }
			else if (document.body) { scroll_h = document.body.scrollTop; }
			
			
			if ((button_top+button_h+menu_h-4) <= (scroll_h+window_h)) {
				var div_top=button_top+button_h;
			} else {
				var div_top=button_top-menu_h+4;
			}
						
			div_obj.style.top=div_top+"px";
			
			
				
			//alert (window_h+' '+scroll_h);
//////////////////////////////////////////////////////////////////			

			
			div_obj.style.visibility='visible';	
			
			
			active_m_id = m_id;
		}
		//event.cancelBubble=true;

}

function f_sm_items_Over(td_id){
	document.getElementById("tr_"+td_id).className='prodmenu_itemtrH';
}

function f_sm_items_Out(td_id){
	document.getElementById("tr_"+td_id).className='prodmenu_itemtr';
}

function f_sm_Action1(pr_id, aph_id, pr_url){
	fHideSubMenus();
	//alert('1. Product Information ('+pr_id+')');
	if (aph_id=='') {
		if (pr_url=='') {
			window.location = "/ProductOverview.aspx?prID="+pr_id;
		} else {
			window.location = "/" + pr_url + "/6_" + pr_id + ".html";
		}
	} else {
		window.location = "/AdClick.aspx?id="+aph_id+"&url=ProductOverview.aspx?prID="+pr_id;
	}
}

function f_sm_Action2(pr_id, aph_id){
	fHideSubMenus();
	alert('2. Trial ('+pr_id+')');
	/*
	if (aph_id=="") {
		window.location = "/ProductDownload.aspx?prID="+pr_id;
	} else {
		window.location = "/AdClick.aspx?id="+aph_id+"&url=ProductDownload.aspx?prID="+pr_id;
	}
	*/	
}

function f_sm_Action3(pr_id, aph_id){
	fHideSubMenus();
	//alert('3. Pricing information ('+pr_id+')');
	if (aph_id=='') {
		window.location = "/ProductPricing.aspx?prID="+pr_id;
	} else {
		window.location = "/AdClick.aspx?id="+aph_id+"&url=ProductPricing.aspx?prID="+pr_id;
	}	
}

function f_sm_Action4(pr_id, aph_id){
	fHideSubMenus();
	//alert('4. System requirements ('+pr_id+')');	
	if (aph_id=='') {
		window.open ("/ProductRequirements.aspx?prID="+pr_id, "Requirements");
	} else {
		window.open ("/AdClick.aspx?id="+aph_id+"&url=ProductRequirements.aspx?prID="+pr_id, "Requirements");
	}
	
}

function f_sm_Action5(pr_id, aph_id){
	fHideSubMenus();
	//alert('5. Add to Download Basket ('+pr_id+')');
	if (aph_id=='') {
		//window.location = "/ProductDownloadAdd.aspx?prID="+pr_id;
		ProductAddToDownloadBasket(pr_id);
	} else {
		window.location = "/AdClick.aspx?id="+aph_id+"&url=ProductDownloadAdd.aspx?prID="+pr_id;
	}	
}

function f_sm_Action6(pr_id, aph_id){
	fHideSubMenus();
	//alert('6. Add to Shopping Cart ('+pr_id+')');
	if (aph_id=='') {
		//window.location = "/ProductBuyAdd.aspx?prID="+pr_id;
		ProductAddToShoppingCart(pr_id);
	} else {
		window.location = "/AdClick.aspx?id="+aph_id+"&url=ProductBuyAdd.aspx?prID="+pr_id;
	}
}

function fHideSubMenus(){
	document.getElementById('DivItem_Menu').style.visibility='hidden';
	if (window.delayhide) clearTimeout(delayhide)
	active_m_id = 0;
}

function findPosX(obj)
{
	var curleft = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj)
{
	var curtop = 0;
	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}

function dynamichide(){
	delayhide=setTimeout("fHideSubMenus()",800)
}

function clearhidemenu(){
	if (window.delayhide) clearTimeout(delayhide)
}

function SubMenuBtOver (m_id) {
	if (m_id == active_m_id) clearhidemenu();
	if (document.images) document.getElementById('button_'+m_id).src=button_on.src;
}

function SubMenuBtOut (m_id) {
	if (m_id == active_m_id) dynamichide();
	if (document.images) document.getElementById('button_'+m_id).src=button_off.src;
}

function ProductAddToDownloadBasket(pr_id) {
    var xmlHttp;
    try {       
        xmlHttp = new XMLHttpRequest();
    }
    catch(e) {        
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e) {
                window.location = "/ProductDownloadAdd.aspx?prID="+pr_id;
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)        {
			document.getElementById("lm_update_progress").style.display = "none";
			var returnvalue = xmlHttp.responseText;
			returnvalue = returnvalue.replace(/^\s+|\s+$/g,"");
			if (returnvalue != "") {
				var dbel = document.getElementById("lm_user_down");
				if (dbel) dbel.innerHTML = returnvalue;
			} else {
				window.location = "/ProductDownloadAdd.aspx?prID="+pr_id;
			}
        }
    }
    xmlHttp.open("GET", "/ProductDownloadAdd.aspx?prID="+pr_id+"&ajax=1", true);
    xmlHttp.send(null);
    document.getElementById("lm_update_progress").style.display = "";
}

function ProductAddToShoppingCart(pr_id) {
    var xmlHttp;
    try {       
        xmlHttp = new XMLHttpRequest();
    }
    catch(e) {        
        try {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(e) {
            try {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e) {
                window.location = "/ProductBuyAdd.aspx?prID="+pr_id;
                return false;
            }
        }
    }
    xmlHttp.onreadystatechange = function() {
        if (xmlHttp.readyState == 4)        {
			document.getElementById("lm_update_progress").style.display = "none";
			var returnvalue = xmlHttp.responseText;
			returnvalue = returnvalue.replace(/^\s+|\s+$/g,"");
			if (returnvalue != "") {
				var dbel = document.getElementById("lm_user_cart");
				if (dbel) dbel.innerHTML = returnvalue;
			} else {
				window.location = "/ProductBuyAdd.aspx?prID="+pr_id;
			}
        }
    }
    xmlHttp.open("GET", "/ProductBuyAdd.aspx?prID="+pr_id+"&ajax=1", true);
    xmlHttp.send(null);
    document.getElementById("lm_update_progress").style.display = "";
}