// Validate string
function isValid(string, ereg) {
    if (string.search(ereg) != -1)
        return true;
    else
        return false;
}
// ##############################################
// ########## DemoClass form validate script ###
// ##############################################
// lt version
function validate_democlass()
{
	var errstr = "";
	
	if (document.fdemoclass.vardas_pavarde.value=='')
		errstr += 'Vardas ir pavardė yra privalomi.\n';
	if (document.fdemoclass.email.value=='')
	{
		errstr += 'El. paštas yra privalomas.\n';
	}
	else
	{
		if (!isValid(document.fdemoclass.email.value, /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/))
		{
			errstr += 'Neteisingai nurodytas el. paštas.\n';
		}
	}
	if (document.fdemoclass.tel.value!='')
	{
		if (!isValid(document.fdemoclass.tel.value, /^([\+\s\d]+)$/))
		{
			errstr += 'Neteisingai nurodytas telefono numeris.\n';
		}
	}
	if (document.fdemoclass.amzius.value=='')
	{
		errstr += 'Amžius yra privalomas.\n';
	}
	else
	{
		if (!isValid(document.fdemoclass.amzius.value, /^([0-9]{2})$/))
		{
			errstr += 'Neteisingai nurodytas amžius (ne mažiau 2 skaitmenų).\n';
		}
	}
	if (document.fdemoclass.security_code.value=='')
	{
		errstr += 'Slaptas kodas yra privalomas.\n';
	}
	
	if (errstr!="")
	{
		alert (errstr);
		return false;
	}
	else
	{
		pop=window.open('','democlass','width=400,height=130;');pop.focus();
		return true;
	}
}

// en version
function validate_democlass_en()
{
	var errstr = "";
	
	if (document.fdemoclass.vardas_pavarde.value=='')
		errstr += 'Name and surname are mandatory fields.\n';
	if (document.fdemoclass.email.value=='')
	{
		errstr += 'E-mail address is mandatory field.\n';
	}
	else
	{
		if (!isValid(document.fdemoclass.email.value, /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/))
		{
			errstr += 'Incorrect e-mail address.\n';
		}
	}
	if (document.fdemoclass.tel.value!='')
	{
		if (!isValid(document.fdemoclass.tel.value, /^([\+\s\d]+)$/))
		{
			errstr += 'Incorrect phone number (no non-digic characters are allowed).\n';
		}
	}
	if (document.fdemoclass.amzius.value=='')
	{
		errstr += 'Age is mandatory field.\n';
	}
	else
	{
		if (!isValid(document.fdemoclass.amzius.value, /^([0-9]{2})$/))
		{
			errstr += 'Incorrect age (at least 2 digits).\n';
		}
	}
	if (document.fdemoclass.security_code.value=='')
	{
		errstr += 'Secret code is mandatory field.\n';
	}
	
	if (errstr!="")
	{
		alert (errstr);
		return false;
	}
	else
	{
		pop=window.open('','democlass','width=400,height=130;');pop.focus();
		return true;
	}
}

// ##############################################
// ########## OrderNews validate email script ###
// ##############################################
// lt version
function validate_newsemail()
{
	var errstr = "";
	/*
	if (document.f.newsemail.value=="Tavo el. paštas   ")
	{
		errstr += 'Prašome įrašyti savo el. pašto adresą.\n';
	}
	*/
	if (!isValid(document.f.newsemail.value, /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/))
	{
		errstr += 'Neteisingai nurodytas el. paštas.\n';
	}
	if (document.f.security_code2.value=='')
	{
		errstr += 'Slaptas kodas yra privalomas.\n';
	}
	
	if (errstr!="")
	{
		alert (errstr);
		return false;
	}
	else
	{
		pop=window.open('','onews','width=400,height=130;');pop.focus();
		return true;
	}
}
// en version
function validate_newsemail_en()
{
	var errstr = "";
	if (!isValid(document.f.newsemail.value, /^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/))
	{
		errstr += 'Incorrect email address.\n';
	}
	if (document.f.security_code2.value=='')
	{
		errstr += 'Secret code is mandatory field.\n';
	}
	if (errstr!="")
	{
		alert (errstr);
		return false;
	}
	else
	{
		pop=window.open('','onews','width=400,height=130;');pop.focus();
		return true;
	}
}

/* This is workaround for a attribute "target" which is not supported by STRICT */
function externalLinks()
{
 if (!document.getElementsByTagName) return;
 var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") &&
		anchor.getAttribute("rel") == "external")
		anchor.target = "_blank";
	}
}
//window.onload = externalLinks;

/* Random image with JavaScript and CSS */
//if (document.getElementById) { window.onload = externalLinks };
function swap()
{
	var numimages=3;
	rndimg = new Array("/i/random/headertop01.jpg", "/i/random/headertop02.jpg", "/i/random/headertop03.jpg"); 
	x=(Math.floor(Math.random()*numimages));
	randomimage=(rndimg[x]);
	document.getElementById("headertop").style.backgroundImage = "url("+ randomimage +")"; 
}

/* Tooltip (ALT) */
/*
originally written by paul sowden <paul@idontsmoke.co.uk> | http://idontsmoke.co.uk
modified and localized by alexander shurkayev <alshur@narod.ru> | http://htmlcoder.visions.ru
*/

window.onerror = null;
var tooltip_attr_name = "tooltip";
var tooltip_blank_text = "[Atsidarys naujame lange] / [Will open in a new window]";
var tooltip_newline_entity = "  "; 
var tooltip_max_width = "400"

/*
window.onload = function(e){
	if (document.createElement) tooltip.d();
}
*/

tooltip = {

t: document.createElement("DIV"),
c: null,
g: false,

m: function(e){
if (tooltip.g){
oCanvas = document.getElementsByTagName(
(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
)[0];
x = window.event ? event.clientX + oCanvas.scrollLeft : e.pageX;
y = window.event ? event.clientY + oCanvas.scrollTop : e.pageY;
tooltip.a(x, y);
}
},

d: function(){
tooltip.t.setAttribute("id", "tooltip");
//tooltip.t.style.filter = "alpha(opacity=85)"; // buggy in ie5.0

document.body.appendChild(tooltip.t);
a = document.all ? document.all : document.getElementsByTagName("*");
aLength = a.length;
for (var i = 0; i < aLength; i++){
tooltip_title = a[i].getAttribute("title");
tooltip_alt = a[i].getAttribute("alt");
tooltip_blank = a[i].getAttribute("target") && a[i].getAttribute("target") == "_blank" && tooltip_blank_text;
if (tooltip_title || tooltip_blank){
a[i].setAttribute(tooltip_attr_name, tooltip_blank ? (tooltip_title ? tooltip_title + " " + tooltip_blank_text : tooltip_blank_text) : tooltip_title);
if (a[i].getAttribute(tooltip_attr_name)){
a[i].removeAttribute("title");
if (tooltip_alt && a[i].complete) a[i].removeAttribute("alt");
tooltip.l(a[i], "mouseover", tooltip.s);
tooltip.l(a[i], "mouseout", tooltip.h);
}
}else if (tooltip_alt && a[i].complete){
a[i].setAttribute(tooltip_attr_name, tooltip_alt);
if (a[i].getAttribute(tooltip_attr_name)){
a[i].removeAttribute("alt");
tooltip.l(a[i], "mouseover", tooltip.s);
tooltip.l(a[i], "mouseout", tooltip.h);
}
}
if (!a[i].getAttribute(tooltip_attr_name) && tooltip_blank){
//
}
}
document.onmousemove = tooltip.m;
window.onscroll = tooltip.h;
},

s: function(e){
d = window.event ? window.event.srcElement : e.currentTarget;
if (!d.getAttribute(tooltip_attr_name)) return;
if (tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
tooltip.t.appendChild(document.createTextNode(d.getAttribute(tooltip_attr_name)));

   r = d.getAttribute(tooltip_attr_name);
   re = /  /ig;
   tooltip.t.innerHTML = r.replace(re, "<br />");

tooltip.c = setTimeout("tooltip.t.style.visibility = 'visible';", 1);
tooltip.g = true;

},

h: function(e){
tooltip.t.style.visibility = "hidden";
if (!tooltip_newline_entity && tooltip.t.firstChild) tooltip.t.removeChild(tooltip.t.firstChild);
clearTimeout(tooltip.c);
tooltip.g = false;
tooltip.a(-99, -99);
},

l: function(o, e, a){
if (o.addEventListener) o.addEventListener(e, a, false); // was true--Opera7b workaround!
else if (o.attachEvent) o.attachEvent("on" + e, a);
else return null;
},

a: function(x, y){
oCanvas = document.getElementsByTagName(
(document.compatMode && document.compatMode == "CSS1Compat") ? "HTML" : "BODY"
)[0];

w_width = window.innerWidth ? window.innerWidth + window.pageXOffset : oCanvas.clientWidth + oCanvas.scrollLeft;
w_height = window.innerHeight ? window.innerHeight + window.pageYOffset : oCanvas.clientHeight + oCanvas.scrollTop;

tooltip.t.style.width = "auto";

t_width = window.event ? tooltip.t.clientWidth : tooltip.t.offsetWidth;
t_height = window.event ? tooltip.t.clientHeight : tooltip.t.offsetHeight;

if (t_width > tooltip_max_width){
tooltip.t.style.width = tooltip_max_width + "px";
t_width = window.event ? tooltip.t.clientWidth : tooltip.t.offsetWidth;
}

t_extra_width = 7; // CSS padding + borderWidth;
t_extra_height = 5; // CSS padding + borderWidth;

tooltip.t.style.left = x + 8 + "px";
tooltip.t.style.top = y + 8 + "px";

while (x + t_width + t_extra_width > w_width){
--x;
tooltip.t.style.left = x + "px";
t_width = window.event ? tooltip.t.clientWidth : tooltip.t.offsetWidth;
}

while (y + t_height + t_extra_height > w_height){
--y;
tooltip.t.style.top = y + "px";
t_height = window.event ? tooltip.t.clientHeight : tooltip.t.offsetHeight;
}
}
}

//***********************************************
// Open image in new window (resizeable)
//***********************************************
function image_popup(url){
	if(typeof(url)!="object") {
		window._w = window.open("","","width=30,height=30,scrollbars=no,resizable=yes");
		window._w.document.open();
		window._w.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1257"><title>Ulf Evenas Aikido Centras</title></head><body topmargin="0" rightmargin="0" bottommargin="0" leftmargin="0" marginheight="0" marginwidth="0" bgcolor="#ffffff" text="#000000"><table border="0" cellpadding="0" cellspacing="0" background="" align="center"><tr><td><a href="#" onclick="self.close(); return false;"><img src="'+url+'" border="0" alt="Uždaryti langą? / Close window?" onLoad="opener.image_popup(this);" /></a></td></tr></table></body></html>');
		window._w.document.close();
	}
	else {
		if (document.layers)
			window._w.resizeTo(url.width,url.height);		
		else
			window._w.resizeTo(url.width+10,url.height+30);
	}
}


// ##############################################
// ########## PopUp Window script ##########
// ##############################################

function popper(thisUrl,thisWindow,thisWidth,thisHeight,thisTop,thisLeft)
{
	optionString = ('width=' + thisWidth + ',height=' + thisHeight + ',top=' + thisTop + ',left=' + thisLeft + ',statusbar=no,menubar=no,resizable=no,scrollbars=no');
	mainWin = window.open(thisUrl,thisWindow,optionString);
}

//***********************************************
// Open image in new window (resizeable)
//***********************************************
function imagePopup(url)
{
	if(typeof(url)!="object")
	{
		window._w = window.open("","","width=30,height=30,scrollbars=no,resizable=yes");
		window._w.document.open();
		window._w.document.write('<html><head><meta http-equiv="Content-Type" content="text/html; charset=windows-1257"><title>Ulf Evenas Aikido Center</title></head><body topmargin="0" marginheight="0" leftmargin="0" marginwidth="0" rightmargin="0" bottommargin="0" bgcolor="#FFFFFF" text="#000000"><table border="0" cellpadding="0" cellspacing="0" background="" align="center"><tr><td><a href="#" onclick="self.close(); return false;"><img src="'+url+'" border="0" alt="Uždaryti langą? / Close window?" onLoad="opener.imagePopup(this);"></a></td></tr></table></body></html>');
		window._w.document.close();
	}
	else
	{
		if (document.layers)
			window._w.resizeTo(url.width,url.height);		
		else
			window._w.resizeTo(url.width+10,url.height+30);
	}
}


window.onload=function(e){
   //swap(); // Rotates #headertop background image
   externalLinks(); // instead of 'target="_blank"'
	/*window.onload = function(e) {*/
	//if (document.createElement) tooltip.d(); // ALT and TITLE onmouseover
	/*}*/
}

function formShowHideRadio(id)
{
	//alert (id);
	if (id == "5_a")
	{
		
		document.getElementById('foodid').style.display = "block";
	}
	else
	{
		document.getElementById('foodid').style.display = "none";
	}
}