var last='';
var path= "http://tau.linkarta.lt/EasyKPC/";
var ua = navigator.userAgent;
if (ua.indexOf("MSIE") >= 0) {
	browser = "ie";
} else {
	browser = "ns";
}
if (document.getElementById) {
	browser = "dom";
}

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 "dom": 
			if (document.getElementById(elem)){
				document.getElementById(elem).style.visibility = "visible";
			}
			break;
	}
	last=elem;
	if (currentSecondLevel) {
		currentSecondLevel.style.display = "none";
	}
}

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 "dom": 
			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 "dom": 
			el = document.getElementById(id);
			break;
	}
	return el;
}

var currentSecondLevel;
var currentItem;
var mouseover = false;
var closeSecond = false;

function SetMouseOver(){
//	mouseover = true;
	closeSecond = false;
}

function SetMouseOut(){
	mouseover = false;
	closeSecond = true;
	HideCurrentSecondMenu();
}

function ShowSecondMenu(item, itemId){
	var secondLevel = GetElement('m' + itemId);
	HideCurrentSecondMenu();
	if(secondLevel){
		currentSecondLevel = secondLevel;
		currentItem = item;
		document.onclick = HideCurrentSecondMenu;
		document.onmousewheel = HideCurrentSecondMenu;
		document.onkeydown = HideCurrentSecondMenu;
		secondLevel.onmouseover = SetMouseOver;
		secondLevel.onmouseleave = SetMouseOut;
		closeSecond = false;

		item.firstChild.prevColor = item.firstChild.style.color;
		item.firstChild.style.color = "black";
		secondLevel.style.display = "block";
		secondLevel.style.position = "absolute";
		if(!secondLevel.startPos){
			secondLevel.startTop = secondLevel.offsetTop;
			secondLevel.startPos = secondLevel.offsetLeft;
			secondLevel.startWidth = secondLevel.offsetWidth;
		}
		secondLevel.style.top = secondLevel.startTop - item.offsetHeight + 0;
//		secondLevel.style.left = secondLevel.startPos + secondLevel.startWidth;
		secondLevel.style.width = secondLevel.startWidth + "px";
		var objContainer = document.body.firstChild;
		while(
			objContainer 
			&& (!("TABLE"==objContainer.tagName || "DIV"==objContainer.tagName)
			|| "EasyAdminBar"==objContainer.id)
		) {
			objContainer = objContainer.nextSibling;
		}
		intContainerWidth = parseInt(objContainer.width || objContainer.style.width || objContainer.offsetWidth);
		var leftSide = parseInt(document.body.clientWidth/2 - intContainerWidth/2);
		if (leftSide < 0){
			leftSide = 0;
		}
		objParent = secondLevel.parentNode || secondLevel.parentElement;
		while(objParent && objParent.tagName!="TABLE") {
			objParent = objParent.parentNode || objParent.parentElement;
		}
		secondLevel.style.left = (leftSide + objParent.offsetWidth) + "px";
	}
}

function HideSecondMenu(itm, itmId){
	if (itmId) {
		var lvl = GetElement('m' + itmId);
		if(lvl){
			closeSecond = true;
			window.setTimeout("HideSMenu("+ itmId + ");", 200);
			//lvl.style.display = "none";
		}
	}
	return;
}

function HideSMenu(iId) {
	if (iId != null && closeSecond) {
		var obj = GetElement('m' + iId);
		if(obj){
			obj.style.display = "none";
		}
	}
}

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;
}