function doShow(form) {
    form.style.display = "block";
}

//=====================================Menu Function=============================================
var menuTime;   // Timer identifier used to hide submenus
var hideSub = null;    // Menu item, for which submenu should be hidden
var closetype; //If 'all' then all menus must be closed. Else only 1 menu will be closed

//This function add some test data to title (convenient for testing)
function addTitle(text)
{
 	if (document.title.length > 55) {
 		document.title = '';
 	}                                	
	document.title += ' ' + text + ' ';
	
}


/* check if obj is menu item or its contents (oblect if true, null if false) */
function isMenuItem(obj) {
    while (obj && (obj != document) && (obj.tagName.toLowerCase() != "ul")) {
        if (obj.tagName.toLowerCase() == "li") return obj;
        obj = (obj.parentElement) ? obj.parentElement : obj.parentNode;
    }
    return false;
}

/* handling multiple styles applied to an element */
function addStyle(obj, class_name) {
    var cn = obj.className;
    var re = new RegExp("(^| )" + class_name + "($| )");
    var re1 = new RegExp("(^| )"  + "*cust" + class_name + "($| )");
    var re2 = new RegExp("cust");
    if (cn.search(re) != -1) return false;
    if (cn.search(re1) != -1) return false;
    if ((cn.search(re2) != -1) && ((class_name == "sub") || (class_name == "sub over"))) {
		cn = cn.replace(re2, "cust" + class_name);
	} else {
	    if (cn != "" && cn.charAt(cn.length - 1) != " ") cn += " ";
	    cn += class_name;
	}
    obj.className = cn;
}
function removeStyle(obj, class_name) {

    if (!obj) return;
    var re = new RegExp(" " + class_name + " ");
    var re1 = new RegExp("(^" + class_name + " )|( " + class_name + "$)|(^"
                           + class_name + "$)");
    var re2 = new RegExp("cust" + class_name + "($| )");
    if ( closetype == 'all' )
    {
	    while (obj && (obj != document) && (obj.className != "menu") && (obj.className != "menu1")) {
        	if (obj.tagName.toLowerCase() == "li")
		{
		    var cn = obj.className;
		    cn = cn.replace(re, " ");
		    cn = cn.replace(re1, "");
		    cn = cn.replace(re2, "cust");
		    obj.className = cn;
		}

	        obj = (obj.parentElement) ? obj.parentElement : obj.parentNode;
	    }
	hideSub = null;
    }
    else
    {
	    var cn = obj.className;
	    cn = cn.replace(re, " ");
	    cn = cn.replace(re1, "");
	    cn = cn.replace(re2, "cust");
	    obj.className = cn;
    }
}

function parentUL(obj) {
	parentul = ((obj.parentElement) ? obj.parentElement : obj.parentNode);
	return parentul;
}

function parentLI(obj) {
	parentul = ((obj.parentElement) ? obj.parentElement : obj.parentNode);
	if ((parentul.className == "menu") || (parentul.className == "menu1")) return null;
	parentli = ((parentul.parentElement) ? parentul.parentElement : parentul.parentNode);
	return parentli;
}

function doubleParentUL(obj) {
	parentul = ((obj.parentElement) ? obj.parentElement : obj.parentNode);
	if ((parentul.className == "menu") || (parentul.className == "menu1")) return null;
	doubleparentul = ((parentul.parentElement) ? parentul.parentElement.parentElement : parentul.parentNode.parentNode);
	return doubleparentul;
}



function handleMouseOver(e) {
    var el = (e) ? e.target : event.srcElement;
    var menuitem = isMenuItem(el);
    if (menuitem) {
	var vParentUL = null;
	var vParentLI = null;
	var vDoubleParentUL = null;
	var vHideParentUL = null;
	var vHideParentLI = null;
	var vHideDoubleParentUL = null;

	vParentUL = parentUL(menuitem);
	vParentLI = parentLI(menuitem);
	vDoubleParentUL = doubleParentUL(menuitem);
	if (hideSub != null)
	{
		vHideParentUL = parentUL(hideSub);
		vHideParentLI = parentLI(hideSub);
		vHideDoubleParentUL = doubleParentUL(hideSub);
	}

	if (menuitem == hideSub)
	{
		clearTimeout(menuTime);
		addStyle(menuitem, "over");
		hideSub = menuitem;
	}
	else if (hideSub == null)
	{
		addStyle(menuitem, "sub over");
	}

	else if (vParentUL == vHideParentUL)
	{
		clearTimeout(menuTime);
		closetype = 'current';
		removeStyle(hideSub, "sub");
		addStyle(menuitem, "sub over");
		hideSub = menuitem;
	}
	else if ((vParentLI != null) && (vParentLI == hideSub))
	{
		clearTimeout(menuTime);
		addStyle(menuitem, "sub over");
		hideSub = menuitem;
	}
	else if ((vHideParentLI != null) && (vHideParentLI == menuitem))
	{
		clearTimeout(menuTime);
		closetype = 'current';
		removeStyle(hideSub, "sub");
		addStyle(menuitem, "over");
		hideSub = menuitem;
	}
	else if ((vHideDoubleParentUL != null) && (vHideDoubleParentUL == vParentUL))
	{
		clearTimeout(menuTime);
		closetype = 'current';
		removeStyle(hideSub, "sub");
		removeStyle(vHideParentLI, "sub");
		addStyle(menuitem, "sub over");
		hideSub = menuitem;
	}
	else
	{
		clearTimeout(menuTime);
		closetype = 'all';
		removeStyle(hideSub, "sub");
	}	


    }
}

function handleMouseOut(e) {
    var el = (e) ? e.target : event.srcElement;
    var toel = (e) ? e.relatedTarget : event.toElement;
    var menuitem = isMenuItem(el);
    if (menuitem && (menuitem != isMenuItem(toel))) {
        removeStyle(menuitem, "over");
        hideSub = menuitem;
	closetype = 'all';
        menuTime = setTimeout('removeStyle(hideSub, "sub")', 200);
    }
}

function handleClick(e) {
    var el = (e) ? e.target : event.srcElement;
    var menuitem = isMenuItem(el);
    if (menuitem && el.tagName.toLowerCase() != "a") {
		neededA = menuitem.getElementsByTagName("a");
		if ( neededA.length != 0 ) {
			neededLink = neededA[0].getAttribute('href',2);
			neededLocation = neededA[0].getAttribute('target',2);
			if (neededLocation && neededLocation == "_blank")
			{
				window.open(neededLink,"","");
			} else {
				location.assign(neededLink);
			}
		}
	}
}

function handleLoad() {
   
    
    // This overcomes event-handling bug in menuitems in Mozilla
    if (navigator.appName.indexOf('Netscape') != -1) {
        var re = new RegExp("(^| )menu($| )");
        var re1 = new RegExp("(^| )menu1($| )");
        var menus = document.getElementsByTagName("ul");
        var mozMenuItem;
        
        for (var i = 0; i < menus.length; i++) {
            if ((menus[i].className.search(re) != -1) || (menus[i].className.search(re1) != -1)) {
                var menuItems = document.getElementsByTagName("li");
                for (var k = 0; k < menuItems.length; k++) {
                    mozMenuItem = document.createElement("div");
                    mozMenuItem.className = "moz";
                    menuItems[k].appendChild(mozMenuItem);
                }
            }
        }
    }
    
	//Adding validator to forms
	var forms = document.getElementsByTagName("FORM");
        for (var i = 0; i < forms.length; i++) {
            if (forms[i].className.indexOf("contact") != -1) {
		doShow(forms[i]);
            }
        }

}



function dPopup(url){
    newPopup = window.open(
        url,
        "",
        "height=300, width=400, menubar=no, resizable=yes, " +
        "scrollbars=no, status=no, titlebar=yes, toolbar=no, " +
        "left=" + (screen.availWidth/5*2) + ", " +
        "top=" + (screen.availHeight/5*1)
        );
}

function errorTrap() {
    return true;
}

function loadImage(imgName, imgWidth, imgHeight)
{
	imgWidth += 12;
	imgHeight += 15;
	var myt = "newWin = window.open(\"\", \"\", \"height="+ imgHeight + ", width=" + imgWidth + ",resizable=yes\")";
	eval(myt);
	newWin.document.write("<body style=\"padding: 0px; margin: 0px;\">");
	newWin.document.write("<table>");
	newWin.document.write("<tr>");
	newWin.document.write("<td style=\"background-color: #FFFFFF; padding: 5px;\">");
	newWin.document.write("<img src=\"" + imgName + "\" border=\"0\">");
	newWin.document.write("</td>");
	newWin.document.write("</tr>");
	newWin.document.write("</table>");
	newWin.document.write("</body>");
	newWin.document.close();
}

function loadFlash(swfName, swfWidth, swfHeight)
{
	var myt = "newWin = window.open(\"\", \"\", \"height="+ swfHeight + ", width=" + swfWidth + ",resizable=no\")";
	eval(myt);
	newWin.document.write("<body style=\"padding: 0px; margin: 0px;\">");
	newWin.document.write("<OBJECT classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0\" WIDTH=\"" + swfWidth + "\" HEIGHT=\""+ swfHeight + "\" id=\"animation\">");
	newWin.document.write("<PARAM NAME=\"movie\" VALUE=\"media/" + swfName + "\">");
	newWin.document.write("<PARAM NAME=\"quality\" VALUE=\"high\">");
	newWin.document.write("<PARAM NAME=\"bgcolor\" VALUE=\"#FFFFFF\">");
	newWin.document.write("<EMBED src=\"media/" + swfName + "\" quality=\"high\" bgcolor=\"#FFFFFF\" WIDTH=\"" + swfWidth + "\" HEIGHT=\""+ swfHeight + "\" NAME=\"animation\" ALIGN=\"\" TYPE=\"application/x-shockwave-flash\" PLUGINSPAGE=\"http://www.macromedia.com/go/getflashplayer\">");
	newWin.document.write("</EMBED>");
	newWin.document.write("</OBJECT>");
	newWin.document.write("</body>");
	newWin.document.close();
}



document.onmouseover = handleMouseOver;
document.onmouseout = handleMouseOut;
document.onclick = handleClick;
window.onload = handleLoad;
//window.onerror=errorTrap;
