// menu www.kpc.lt
var last='';
var path= "http://tau.linkarta.lt/EasyKPC/";
var ua = navigator.userAgent;
if (ua.indexOf("MSIE") >= 0) {
	browser = "ie";
} else {
	browser = "ns";
}
if (browser == "ns" && document.getElementById) {
	browser = "ns6";
}

function showdiv(){
	var css = GetElement("choose").style;
	if (css.display == 'none' ) {
		css.display = 'block';
	} else {
		css.display = 'none';
	}
	var img = GetElement("show");
	if (img.src == path + 'images/simbolis_show.gif') {
		img.src = path + 'images/simbolis_top.gif';
	} else {
		img.src = path+ 'images/simbolis_show.gif';
	}
}
function newWind(url){
	window.open(url,"","width=572,height=500, scrollbars=1, status=1");
	return false;
}

function showM(elem)
{
	
	colbg="col"+elem;
//	hideM(last);
	switch(browser) {
		case "ie": 
			if (document.all[elem]){	
				document.all[elem].style.visibility = "visible";
			}
			break;
		case "ns":  
			if (document.layers[elem]){
				document.layers[elem].visibility = "show";
			}
			break;
		case "ns6": 
			if (document.getElementById(elem)){
				document.getElementById(elem).style.visibility = "visible";
			}
			break;
	}
	last=elem;
}

function hideM(last)
{
	switch(browser) {
		case "ie":
			if (document.all[last]){ 
				document.all[last].style.visibility = "hidden";
				}
				
			break;
		case "ns": 
			if (document.layers[last]){
				document.layers[last].visibility = "hide";
				}
			break;
		case "ns6": 
			if (document.getElementById(last)){
				document.getElementById(last).style.visibility = "hidden";
			}
			break;
	}
}


// ==============================================================================

function GetElement(id){
	var el;
	switch(browser) {
		case "ie":
			el = document.all[id];
			break;
		case "ns": 
			el = document.layers[id];
			break;
		case "ns6": 
			el = document.getElementById(id);
			break;
	}
	return el;
}

var currentSecondLevel;
var currentItem;
var mouseover = false;

function SetMouseOver(){
	mouseover = true;
}

function SetMouseOut(){
	mouseover = false;
	HideCurrentSecondMenu();
}

function ShowSecondMenu(item, itemId){
	var secondLevel = GetElement('m' + itemId);
	HideCurrentSecondMenu();
	if(secondLevel){
		document.onmousedown = HideCurrentSecondMenu;
		document.onmousewheel = HideCurrentSecondMenu;
		document.onkeydown = HideCurrentSecondMenu;
		secondLevel.onmouseover = SetMouseOver;
		secondLevel.onmouseleave = SetMouseOut;
		secondLevel.style.display = "block";
//secondLevel.style.border="2px solid red";
//return;

		item.firstChild.prevColor = item.firstChild.style.color;
		item.firstChild.style.color = "#0068ED";
		secondLevel.style.display = "block";
		secondLevel.style.position = "absolute";
		if(!secondLevel.startPos){
			secondLevel.startTop = secondLevel.offsetTop;
			secondLevel.startPos = secondLevel.offsetLeft;
			secondLevel.startWidth = secondLevel.offsetWidth;
//			secondLevel.startWidth = 160;
		}
		secondLevel.style.top = secondLevel.startTop - item.offsetHeight + 0;
//		secondLevel.style.left = secondLevel.startPos + secondLevel.startWidth;
		secondLevel.style.width = secondLevel.startWidth + "px";
		var leftSide = document.body.offsetWidth/2 - 369;
		if (leftSide < 0){
			leftSide = 0;
		}
		secondLevel.style.left = (leftSide + 181) + "px";


//		secondLevel.style.width = "160px";
	}
	currentSecondLevel = secondLevel;
	currentItem = item;
}

function HideSecondMenu(item, itemId){
return;
}

function HideCurrentSecondMenu(){
	if(currentSecondLevel && !mouseover) {
		currentItem.firstChild.style.color = currentItem.firstChild.prevColor;
		currentSecondLevel.style.display = "none";
		currentSecondLevel.style.position = "static";
		mouseover = false;
	}
}

/*
	EasyForm[28389][TypeLabel] == 28301, 28302			->  Aktyvuoti EasyForm[28389][SideLength]
	EasyForm[28389][TypeLabel] == 28303					->  Aktyvuoti EasyForm[28389][Width], EasyForm[28389][Length]

	EasyForm[28389][ContinuitySupply] == 28355, 28356	->	Aktyvuoti EasyForm[28389][SupplyPlaceTown]

+ scroll
*/
function TypeChanged(el){
	var sideLengthEl	= el.form["EasyForm[28389][SideLength]"];
	var widthEl			= el.form["EasyForm[28389][Width]"];
	var lengthEl		= el.form["EasyForm[28389][Length]"];

	// activate / disable side length dropbox
	var slActive = (el.value == 28301) || (el.value == 28302);
	sideLengthEl.disabled = !slActive;

	// activate / disable width and length dropbox
	var mActive = (el.value == 28303);
	widthEl.disabled	= !mActive;
	lengthEl.disabled	= !mActive;

}

function DeliveryChanged(el){
	var townEl	= el.form["EasyForm[28389][SupplyPlaceTown]"];

	// activate / disable town dropbox
	var tActive = (el.value == 28355) || (el.value == 28356);
	townEl.style.backgroundColor = tActive ? "" : "silver";
	townEl.disabled = !tActive;
}

function StartQueryForm(){
	var form = document.forms["Form_28389"];
	if(form){
		TypeChanged(form["EasyForm[28389][TypeLabel]"]);
		DeliveryChanged(form["EasyForm[28389][ContinuitySupply]"][0]);
	}
}

function SetActivity(objEl, name) {
	document.getElementsByName("EasyForm[28384][" + name + "]")[0].disabled = !objEl.checked;
}
