var xmlHttp

function changeContent(url)
{
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

xmlHttp.onreadystatechange=stateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} 

function stateChanged() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		alert(xmlHttp.responseText);
	}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
  {
  // Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
  }
catch (e)
  {
  // Internet Explorer
  try
    {
    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
  catch (e)
    {
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
return xmlHttp;
}

function con(td,currentclass){
  if(document.getElementById||(document.all && !(document.getElementById))){
     td.className = currentclass;
  }
}

function cout(td,currentclass){
   if(document.getElementById||(document.all && !(document.getElementById))){
       td.className = currentclass;
   }
}

function postrolldown(selectCounter){
	if (selectCounter != 0 ){
		document.rolldown.shopselect.value="shops"+selectCounter;
	}
	
	document.rolldown.submit();
}

function submitProductSearch(type){
	switch(type){
		case 1: 
			   if(document.productsearch.product.value==""){
				   alert('Nincs kereső feltétel megadva!');
			   }else{
			   		document.productsearch.action="kereses.php?type=2";
					document.productsearch.searchModifier.value=type;
					document.productsearch.submit();
			   }
			   break;
		case 2:if(document.productsearch.shopsSearch.value == 0){
				   alert('Nincs kereső feltétel megadva!');
			   }else{
			   		document.productsearch.action="kereses.php?type=3";
					document.productsearch.searchModifier.value=type;
					document.productsearch.submit();
			   }
		       break;
	}
}


function submitSubscribe(){
	
	var str = document.subscribe.mail.value;
	document.subscribe.mail.value = "";
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	
	if (str == ""){
		alert("Nincs megadva e-mail cím!");
	}else{
		if (filter.test(str)){
		changeContent("subscribe.php?email="+str);
		}else{
			alert("Nem megfelelő e-mail cím formátum!");
		}
	}
}


//fix png images in IE 6
function alphaFixIE() {
	var s, i, j;
	
	// IMG
	var els = document.getElementsByTagName("IMG");
	for (i=0; i<els.length; i++) {
		s = els[i].src;
		if (s.toLowerCase().indexOf(".png") != -1) {
			els[i].src = "style/images/blank.gif";
			els[i].style.filter += "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + s + "', sizingMethod=image);";
		}
	}
	
	// CSS: background
	for (i=0; i<document.styleSheets.length; i++) {
		var pos = document.styleSheets[i].href.lastIndexOf("/");
		var cssDir = (pos != -1) ? document.styleSheets[i].href.substring(0, pos + 1) : "";
		for (j=0; j<document.styleSheets[i].rules.length; j++) {
			var style = document.styleSheets[i].rules[j].style;
			if (style.backgroundImage.toLowerCase().indexOf(".png") != -1) {
				var filename = style.backgroundImage.substring(4, style.backgroundImage.length - 1);
				if (filename.indexOf("http://") != 0 && filename.indexOf("/") != 0)
					filename = cssDir + filename;
				style.backgroundImage = "none";
				style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + filename + "', sizingMethod='crop');";
			}
		}
	}
}

if (navigator.userAgent.indexOf("MSIE") != -1 && navigator.userAgent.indexOf("Windows") != -1)
	window.attachEvent("onload", alphaFixIE);


function forumlogin(){
	if (document.forum.username.value == "" || document.forum.pass.value == ""){
		alert('Hiányzó belépési adatok!');
	}else{
		document.forum.action = "forum.php?login=1";
		document.forum.submit();
	}
}


function accmodify(){
		
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;//e-mail pattern
		
		if (document.forum.accpass.value != ""){//change password
			if(document.forum.accpass.value != document.forum.accpass2.value){
				alert("A jelszó és az ellenőrző nem azonos!");
			}else{
				if (filter.test(document.forum.accmail.value)){
					document.forum.action="forum.php?account=modify";
					document.forum.submit();
				}else{
					alert("Hibás e-mal cím formátum!");
				}
			}
			
		}else{//change only e-mail address
			if (filter.test(document.forum.accmail.value)){
				document.forum.action="forum.php?account=modify";
				document.forum.submit();
			}else{
				alert("Hibás e-mal cím formátum!");
			}
		}
	}


function postmessage(others){
	if(tinyMCE.get('content').getContent()==""){
		alert('Üres hozzászólást nem lehet elküldeni!');
	}else{
		document.forum.action="forum.php?submit=1"+others;
		document.forum.submit();
	}
}

function postperpage(topic,perpage,order){
	document.forum.action = "forum.php?topic="+topic+"&perpage="+perpage+"&order="+order;
	document.forum.submit();
}

function postorder(topic,perpage,order){
	document.forum.action = "forum.php?topic="+topic+"&perpage="+perpage+"&order="+order;
	document.forum.submit();
}
