/*

arvio.asp			ShowHide()
haku_tiedot.asp		ShowHide(), SetCookie()
haku_tulos.asp		OpenWindow(), SetCookie()
index.asp			OpenWindow()
laite.asp			OpenWindow()
lista_tiedot.asp	OpenWindow()
muokkaa_tiedot.asp	OpenWindow()
myyjat.asp			ShowHide(), SetCookie(), GetCookie(), OpenWindow()

*/

if((navigator.appName == "Microsoft Internet Explorer") && (navigator.userAgent.indexOf("Opera") == -1)) {
	var DisplayTable = 'block';
	var DisplayTableRow = 'block';
} else {
	var DisplayTable = 'table';
	var DisplayTableRow = 'table-row';
}

function DeleteCookie(Name) {
	document.cookie = Name + "="; //;expires=Sat, 01-Jan-2000 00:00:00 GMT";
}

function GetCookie(Name) {
	var Cookie = unescape(document.cookie);
	var i = Cookie.indexOf(Name + "=");
	if(i != -1) {
		var j = Cookie.indexOf(";", i);
		if(j == -1)
			return(Cookie.substr(i + Name.length + 1));
		else
			return(Cookie.substring(i + Name.length + 1, j));
	} else {
		return("");
	}
}

function SetCookie(Name, Value) {
	var Expires = new Date();
	
	Expires.setFullYear(Expires.getFullYear() + 1);	

	document.cookie = Name + "=" + escape(Value)
		+ "; expires=" + Expires.toGMTString();
}

function OpenWindow(Url, Name, Width, Height, Scrollbars) {
	var Wnd = window.open(Url, Name,
			  "width=" + Width + ",height=" + Height + ","
			+ "left=" + (screen.availWidth - Width) / 2 + ",top=" + (screen.availHeight - Height) / 2 + ","
			+ "scrollbars=" + Scrollbars + ",location=0,status=0,menubar=0,resizable=0");
	Wnd.parent = window;
	return(false);
}

function ShowHide(Name, ElementType, OnValue, OffValue) {

	var Button = document.getElementById(Name + "_select");
	var Target = document.getElementById(Name);

	if(Target.style.display == 'none') {
		SetCookie(Name, "1");
		Target.style.display = ElementType;
		Button.innerHTML = OffValue + Button.innerHTML.substr(OnValue.length);
	} else {
		SetCookie(Name, "0");
		Target.style.display = 'none';
		Button.innerHTML = OnValue + Button.innerHTML.substr(OffValue.length);
	}
}

function ShowLength(Name) {
	document.getElementById(Name + '_length').innerHTML = document.getElementById(Name).value.length;
}

