var isMinNS4 = 1; //(navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 4) ? 1 : 0;
var isMinNS5 = 1; //(navigator.appName.indexOf("Netscape") >= 0 && parseFloat(navigator.appVersion) >= 5) ? 1 : 0;
var isMinIE4 = 1; //(document.all) ? 1 : 0;
var isMinIE5 = 1; //(isMinIE4 && navigator.appVersion.indexOf("5.") >= 0) ? 1 : 0;


// Top Main menu creation function
function createMenu(menulinks,menuitems,style1,style2,enabledm) {
	var stringId = "";
        if ((isMinIE4) || (isMinNS5)) {
		var menu = "<table cellpadding=0 cellspacing=0 border=0 height=20><tr>";
		for (counter in menulinks) {
		        if (enabledm == true) 
				{ stringId = "";
					if (dm_enable[counter] == true) stringId = "id=menulink"+counter;
					menu += "<td class='"+style1+"' id=tdMenuBarItemM"+counter+" nowrap>&nbsp;<a class="+style2+" href='../.."+menulinks[counter]+"' target=_top "+stringId+">"+menuitems[counter]+"</a>&nbsp;</td>"
			} else { menu += "<td class='"+style1+"' nowrap>&nbsp;<a class='"+style2+"' href='../.."+menulinks[counter]+"' target=_top>"+menuitems[counter]+"</a>&nbsp;</td>" }
		}
		menu += "</tr></table>";
	} 
//	print_string(menu);
	return menu;
}

function print_string(menu1) {
	var menu2 = "";
	for ( var i=0; i <= menu1.length ; i++ )
	{
		if (menu1.substring (i, i+1) == "<") 
			menu2 += "&lt;";
		else  menu2 += menu1.substring (i,i+1);
	}
	menu2 += "<br><br><br><br>";
	document.write (menu2);
}


menulinks = new Array ("/index.php","/products/index.php","/downloads/index.php","/buynow/index.php","/support/index.php","/aboutus/index.php");
menuitems = new Array ("Home","Products","Download","Order","Support","Ablazesoft company");
dm_enable = new Array (false,true,true,false,false,false);

var menuheader = createMenu(menulinks,menuitems,"clsTopMenuNorm","clsMenuTopLink",true); 

var flag = 1; //isMinIE4;
var eOpenMenu = null;
var timerId = 0;
var eSrcOpen = null;

//if ( flag ) {
	document.onmouseover = mouseover;
	document.onmouseout = mouseout;
	document.onclick = onclick;
//}

function OpenMenu(eSrc,eMenu)
{
var eSrcCoordinate = eSrc;
var x = 0;
var y = 0;
while (eSrcCoordinate)
	{
//	document.forms[0].test.value += " Node="+eSrcCoordinate.nodeName+" ID="+eSrcCoordinate.id+" x="+eSrcCoordinate.offsetLeft+" y="+eSrcCoordinate.offsetTop+"\n"
	x += eSrcCoordinate.offsetLeft;
	y += eSrcCoordinate.offsetTop;
	eSrcCoordinate = eSrcCoordinate.offsetParent
	}
	if (navigator.userAgent.indexOf("Mac") != -1 && typeof document.body.leftMargin != "undefined")
	{
		x += document.body.leftMargin;
		y += document.body.topMargin;
	}
//	document.forms[0].test.value += " leftMargin="+document.body.leftMargin+" topMargin="+document.body.topMargin+"\n"+"Total x="+x+" y="+y+"\n";
	eMenu.style.top = y +22+ "px";
	eMenu.style.left = x + "px";
	eMenu.style.visibility = "visible";
	eOpenMenu = eMenu;
	eSrcOpen = eSrc;
	eSrcOpen.className = "clsTopMenuOver";
	
}

var IdBackup;
var MenuSrc;
MenuSrc = null;

function CloseMenu(eMenu)
{
	MenuSrc = null;
	eMenu.style.visibility = "hidden";
	eOpenMenu = null;
	eSrcOpen.style.color = "";
	eSrcOpen.className = "clsTopMenuNorm";
	MenuSrc = document.getElementById(IdBackup);
	//window.alert(IdBackup);
	MenuSrc.style.color = "ffffFF";
	MenuSrc = null;
	}

var classNameBackup;

function mouseover(evt)
{

  evt = (evt) ? evt : (window.event) ? window.event : "";
  if (evt)
  {
	var eSrc = (evt.target) ? evt.target : evt.srcElement;
	
	classNameBackup = "clsTopMenuNorm";
	
	if (eSrc.className == "clsDMLink") //if mouseover src obj is link in dm we go to level up -> <td>
		eSrc = eSrc.parentNode;
	
	if (eSrc.className != "clsDMnormal" && eSrc.className != "dmTitles") // If not dmTitle and not dmnormal
	{
		if (eSrc.className == "clsMenuTopLink") 
		{
			if (eSrc.id != "") 
			{
				eSrc.style.color = "ffffff"; 
				IdBackup = eSrc.id;
			}
			eSrc = eSrc.parentNode;
		 }
		if (eSrc.className == "clsTopMenuNorm")
		{
			var eMenu = document.getElementById(eSrc.id.replace("tdMenuBarItem", "divMenu"));//we get right drop menu object by changing id name
			if (eOpenMenu && eOpenMenu != eMenu) //if we call new drop menu we need to close already opened drop menu 
				CloseMenu(eOpenMenu); 
			
			if (eMenu)
				timerId = window.setTimeout('OpenMenu(' + eSrc.id + ',' + eMenu.id + ')', 100);//drop menu open delay
   		    else eSrc.className = "clsTopMenuOver";
        }
		else if (eOpenMenu)
			     if (!f_parent(eSrc))
					   CloseMenu(eOpenMenu); 
	 }
	 else if (eSrc.className == "clsDMnormal")
			     eSrc.className = "clsDMover"
	return true;
  }
}


function f_parent(Obj1) //Function check does src obj contains in main menu
{
var result = new Boolean;
result = false;
	while ((Obj1.parentNode.nodeName != "HTML") && (Obj1.nodeName != "HTML"))
	{
		if (Obj1.id == "divMenuBar")
		{
			result = true;
			break;
		}
	Obj1 = Obj1.parentNode;
	}
return result;
}

function mouseout(evt)
{

	window.clearTimeout(timerId);
	timerId = 0;
	evt = (evt) ? evt : (window.event) ? window.event : "";
	if (evt)
	{
	
	var eSrc = (evt.target) ? evt.target : evt.srcElement;

	if (eOpenMenu) { 
		if (eSrcOpen) { eSrcOpen.style.color = "#FFFFFF";} 
		if (eSrc.className == "clsDMLink") 
			eSrc = eSrc.parentNode;
		if (eSrc.className == "clsDMover")	
			eSrc.className = "clsDMnormal"
	  }
	else { 
			eSrc.style.color = ""
			if (eSrc.className == "clsMenuTopLink")
				eSrc = eSrc.parentNode;
			if (eSrc.className == "clsTopMenuOver") {
				eSrc.className = classNameBackup;
		}
	}
	}
}	

function onclick(evt)
{
var link = "";
evt = (evt) ? evt : (window.event) ? window.event : "";
if (evt)
	{
	var eSrc = (evt.target) ? evt.target : evt.srcElement;
	if ((eSrc.className == "clsDMover") || (eSrc.className == "clsTopMenuOver")) 
		{ 
		i=0;
		while (eSrc.childNodes[i])
			{
			if (eSrc.childNodes[i].nodeName == "A")
				{
				link = eSrc.childNodes[i].href;
				location.href = link; 
				}
			i++;
			}
		}
	}
}

function BuildDropMenu(menuitems,menulinks) {
	var menu = "<table width=100% cellpadding=1 cellspacing=0 class=clsMainMenu><tr><td width=100% align=center><table width=98% cellpadding=0 cellspacing=0>";
	var menu1 = "";
	for (counter in menuitems) {
		menu += "<tr><td height=20 class='";
		if (menulinks[counter] == "") { menu += "dmTitles'><b>"+menuitems[counter]+"</b><br>" }
		else { menu += "clsDMnormal'><a class='clsDMLink' href='../.."+menulinks[counter]+"'>"+menuitems[counter]+"</a><br>" }
		menu += "</td></tr>";
	}
	menu += "</table></tr></td></table>";
//print_string(menu);
	return menu;
}

DropMenus = new Array();

menuitems = Array("Private InfoKeeper","Private InfoKeeper Light", "Product update", "Localization", "Screen Shots", "F.A.Q.", "Awards");
menulinks = Array("/products/apik.php","/products/apikl.php", "/products/upd.php", "/localization/index.php", "/ss/index.php", "/faq/index.php", "/awards/index.php");
DropMenus[1] = BuildDropMenu(menuitems,menulinks);

menuitems = Array("Our products","Mozilla FireFox plugin");
menulinks = Array("/downloads/index.php","/products/ff_setup.php");
DropMenus[2] = BuildDropMenu(menuitems,menulinks);

function drawmenus()
{
	var str = '';
	var str1 ='';

	if ( flag )	{	

		str += '<div id="divMenuM1" class="clsDMenu" style="width:165;position:absolute;z-index:2;left:0px; visibility:hidden;">';
		str += DropMenus[1];
		str += '</div>';


		str += '<div id="divMenuM2" class="clsDMenu" style="width: 165px; position: absolute; z-index: 2; left: 250px; visibility: hidden">';
		str += DropMenus[2];
		str += '</div>';

		document.write(str);
//		print_string(str)		
	}
}

var timerID = 0;


function Validate(form)
{
	var msg = "You need enter both Your name and Your email values ...";
	var name = document.forms[0].realname.value;
	var email = document.forms[0].email.value;

	
	// check for any space characters that may be input
  	
  	if (name == "" || name == null || email == "" || email == null)
  	{
  		alert (msg);
  		return false;
  	}
}
function link_menu (path) {  location.href = path;}


