function validateEmail(elementValue){
   var emailPattern = /^((\w+\+*\-*)+\.?)+@((\w+\+*\-*)+\.?)*[\w-]+\.[a-z]{2,6}$/i;
   return emailPattern.test(elementValue);
 }

/*function validateEmailInput(inp) {
	if(!validateEmail(inp.value)) {	
		//inp.focus();
		//inp.select();
		alert("Adjon meg egy érvényes email-címet!");
		//return false;
	}
 }*/
  
function printPage(page) {
	url = "print.php?page=" + page;
	window.open(url);	
}  
  
function showSendForm() {
	$("msg").update("&nbsp;");
	$("msg").style.color = "red";
	div = $("sendFormDiv");
	if (window.innerHeight) {
		div.style.left = (window.innerWidth-350)/2+"px";
		$("overlay").style.height = window.innerHeight + "px";
	} else {
		div.style.left = (document.body.clientWidth-350)/2+"px";
		$("overlay").style.height = document.body.clientHeight + "px";
	}
	$("overlay").show();
	$("sendFormDiv").show();
	window.scrollTo(0,0);
	document.body.style.overflow = "hidden";
}
 
function hideSendForm() {
	$("sendFormDiv").hide();
	$("overlay").hide();
	document.body.style.overflow = "auto";
}
function sendArticle() {
	form = $('sendForm');
	
	if (!$F($('sendToName'))) {
		$("msg").update("Adja meg a címzett nevét!");
		$("sendToName").activate();
		return;
	}
	emailto = ($F($('sendTo')));
	if (!validateEmail(emailto)) {
		$("msg").update("Adjon meg egy érvényes email-címet!");
		$("sendTo").activate();
		return;
	}
	if (!$F($('sendFromName'))) {
		$("msg").update("Adja meg a feladó nevét!");
		$("sendFromName").activate();
		return;
	}
	emailfrom = ($F($('sendFrom')));
	if (!validateEmail(emailfrom)) {
		$("msg").update("Adjon meg egy érvényes email-címet!");
		$("sendFrom").activate();
		return;
	}
	
	$('msg').update("Email küldése folyamatban <img src='images/loading.gif'>");
	new Ajax.Request("ajax/sendpage.php", {
		method: "post",
		parameters: form.serialize(true),
		onSuccess: function(transport) {
			r = transport.responseXML;
			//window.e = r	
			if (r.getElementsByTagName("error").length>0) {
				$("msg").update(r.getElementsByTagName("msg")[0].firstChild.nodeValue);
			} else {
				$("msg").style.color = "#336600";
				$("msg").update("Az email elküldése sikerült!");
				setTimeout("hideSendForm()", 2000);
			}
		}
	});	
 }
 
function regForm(page, value) {
 
	new Ajax.Request("ajax/reg_form.php", {
		method: "post",
		encoding: "iso-8859-2",
		parameters: {
			formPage: page,
			formValue: value
		}
	});	
}

function defineToggle(el) {
	el = $(el);
	divs = el.getElementsByTagName("div");
	
	for (i=0; i<divs.length; i++) {
		if(divs[i].hasClassName("toggleDiv")) {
			d = divs[i];
			cnt = d.childElements().last();
			id = cnt.identify();
			cnt.hide();
			d.firstDescendant().onclick = function() {this.nextSiblings()[0].toggle();
			}
		}
	}
}

function refreshImg(id) {
	$(id).src = "modules/captcha.php?rnd=" + (Math.random()*100);
}

function startDiab() {
	var javawsInstalled = 0;  
	/*var javaws142Installed=0;
	var javaws150Installed=0;
	var javaws160Installed = 0;
	isIE = "false"; */
	if (navigator.mimeTypes && navigator.mimeTypes.length) { 
	   x = navigator.mimeTypes['application/x-java-jnlp-file']; 
	   if (navigator.mimeTypes['application/x-java-jnlp-file'] != null ||
                 navigator.mimeTypes['application/x-java-vm'] != null) { 
		  javawsInstalled = 1; 
		  /*javaws142Installed=1;
		  javaws150Installed=1;
		  javaws160Installed = 1; */
	  } 
	} 
	else { 
	   //isIE = "true"; 
	   try { 
            var jws = new ActiveXObject('JavaWebStart.isInstalled'); 
            javawsInstalled = 1; 
        } 
        catch (e) { 
            javawsInstalled = 0; 
        } 
	} 
	if (javawsInstalled || (navigator.userAgent.indexOf("Gecko") !=-1)) {
		//document.write("<a href=http://all.dnsalias.com/DIAB/diaball.jnlp>Belépés a DIABALL rendszerbe!</a>");
		//window.location.href = "http://all.dnsalias.com/DIAB/diaball.jnlp";
		//window.open("http://192.168.1.2/DIAB/diaball.jnlp");
		window.open("http://all.dnsalias.com/DIAB/diaball.jnlp");
		//window.location.href = "http://192.168.1.2/DIAB/diaball.jnlp";
	} else {
		window.open("http://java.sun.com/PluginBrowserCheck?pass=http://all.dnsalias.com/DIAB/JRE_Install.html&fail=http://java.sun.com/javase/downloads/ea.jsp");
		//document.write("Kattintson ");
		//document.write("<a href=http://java.sun.com/PluginBrowserCheck?pass=http://all.dnsalias.com/DIAB/JRE_Install.html&fail=http://java.sun.com/javase/downloads/ea.jsp>IDE</a> ");
		//document.write("letölteni és installálni a DIABALL futtató környezetet.(JRE 6.x, JNLP)");
	}
}

function setCookie(c_name, value, expiredays) {
	exdate = new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
}

function getCookie(c_name) {
	if (document.cookie.length>0) {
		c_start=document.cookie.indexOf(c_name + "=");
		if (c_start!=-1) {
			c_start=c_start + c_name.length+1;
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) {
				c_end=document.cookie.length; 
			}
			return unescape(document.cookie.substring(c_start,c_end));
		}
	}
	return "";
}
