var xmlHttp;

function comment_process() {
	if (document.getElementById('IUD')) var IUD=document.getElementById('IUD').value; else var IUD="";
	if (document.getElementById('username')) var username=document.getElementById('username').value; else var username="";
	if (document.getElementById('email')) var email=document.getElementById('email').value; else var email="";
	if (document.getElementById('shortdesc')) var shortdesc=document.getElementById('shortdesc').value; else var shortdesc="";
	function stateChanged_comment_process() {
		if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
			document.getElementById('comment').innerHTML=xmlHttp.responseText;
			run_scripts('comment');
		}
	}
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null) {
		alert("Browser does not support HTTP Request");
		return;
	}
	xmlHttp.onreadystatechange=stateChanged_comment_process;
	xmlHttp.open("POST","modules/i_addcomment.php?IUD="+IUD+"&username="+username+"&email="+email+"&shortdesc="+shortdesc,true);
	xmlHttp.send(null);
}

// global //
function run_scripts(object) {
	var scripttags=document.getElementById(object).getElementsByTagName('script');
	for (var No=0;No<scripttags.length;No++) {
		eval(scripttags[No].innerHTML);
	}
}
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 check_browser() {
	var sAgent=navigator.userAgent.toLowerCase();
	if ((sAgent.indexOf("msie")!=-1 || sAgent.indexOf("firefox")!=-1) && sAgent.indexOf("mac")==-1 && sAgent.indexOf("opera")==-1) return true; else return false;
}
function img_overlay(name,url,y_pos,x_pos) {
	document.getElementById('show_img').innerHTML="";
	//if (document.getElementById('t_name') && ("<b>"+name+"</b>")==document.getElementById('t_name').innerHTML) { showHideDiv('dummy'); return false };
	/*if (document.getElementById('dummy').style.display=="none") */ showHideDiv('dummy');
	if (check_browser()==true) {
		document.getElementById('show_img').style.top=document.documentElement.scrollTop+5+"px";
	} else {
		document.getElementById('show_img').style.top=window.pageYOffset+5+"px";
	}
	document.getElementById('show_img').style.left=(document.body.offsetWidth/2-150)+"px";
	var img_body="<div style=\"background:url('resources/imgs/black_t.png'); padding:5px;\" id=\"m_img\">";
		if (name) img_body+="<div style=\"font-size:14px;color:#ffffff;background:url('images/black_t.png');padding:4px;margin-bottom:5px\" id=\"t_name\" nowrap><b>"+name+"</b></div>";
		img_body+="<div id=\"loading\" style=\"width:300px;height:100px;padding-top:65px;\" align=\"center\"><img src=\"resources/imgs/lightbox-loading.gif\" /></div>"+
		"<img src="+url+" style=\"cursor:pointer;max-width:770px;display:none\" id=\"t_img\" title=\"(az ablak bez&aacute;r&aacute;s&aacute;hoz kattintson a k&eacute;pre!)\" />"+
		"<div style=\"font-size:11px;color:#ffffff;background:url('resources/imgs/black_t.png');padding:4px;margin-top:5px;text-align:right\" nowrap>az ablak bez&aacute;r&aacute;s&aacute;hoz kattintson a k&eacute;pre!</div>"+
		"</div></div>";
	document.getElementById('show_img').innerHTML=img_body;
	document.getElementById('dummy').style.height=document.body.offsetHeight+"px";
	setTimeout('isImageOk()', 150);
}
function isImageOk() {
	if (!document.getElementById('t_img').complete) {
		setTimeout('isImageOk()', 150);
		return false;
	}
	if (typeof document.getElementById('t_img').naturalWidth != "undefined" && document.getElementById('t_img').naturalWidth == 0) {
		setTimeout('isImageOk()', 150);
		return false;
	}
	document.getElementById('loading').style.display="none";
	document.getElementById('t_img').style.display="block";
	var width=document.getElementById('t_img').offsetWidth+20;
	var height=document.getElementById('t_img').offsetHeight+66;
	document.getElementById('show_img').style.left=((document.body.offsetWidth-width)/2)+"px";
	if (check_browser()==true) var sum_height=height+document.documentElement.scrollTop; else var sum_height=height+document.body.scrollTop;
	var client_height=document.body.clientHeight;
	if (sum_height>client_height) {
		var new_pos=document.body.clientHeight-height-60;
		document.getElementById('show_img').style.top=new_pos+"px";
		window.scrollTo(0,new_pos);
	}
}

function showHideDiv(mit) {
	var id=document.getElementById(mit);
	if (id.style.display=="block" || id.style.display=="") {
		id.style.display='none';
	} else {
		id.style.display='block';
	}
}
function showDiv(mit) {
	document.getElementById(mit).style.display='block';
}
function hideDiv(mit) {
	document.getElementById(mit).style.display='none';
}

function countdown() {
	if (document.getElementById('timer').innerHTML>1) {
		document.getElementById('timer').innerHTML-=1;
		setTimeout("countdown()",1000);
	} else {
		clearTimeout("countdown()");
		hideDiv('comment');
	}
}

function preload_images() {
	preload_image_object=new Image();
	image_url=new Array();
	var imgtags=document.getElementsByTagName('img');
	for (var i=0;i<imgtags.length;i++) {
		image_url[i]=imgtags[i].src;
	}
	for (i=0;i<=imgtags.length-1;i++) {
		preload_image_object.src=image_url[i];
	}
}

function open_window(url,width,height) {
	ujkwin=window.open(url,'_blank',"width="+width+",height="+height+",notoolbar,status=0,scrollbars=1");
	var xc=(screen.width-width)/2;
	var yc=(screen.height-height)/2;
	ujkwin.moveTo(xc,yc);
}

function change_img(id) {
	/*if (document.getElementById('img_'+id).src=='resources/imgs/products/'+img1_thumb) {
		alert('a');
		document.getElementById('a_'+id).href='resources/imgs/products/'+img2;
		document.getElementById('img_'+id).src='resources/imgs/products/'+img2_thumb;
	} else {
		document.getElementById('a_'+id).href='resources/imgs/products/'+img1;
		document.getElementById('img_'+id).src='resources/imgs/products/'+img1_thumb;
	}*/
	if (document.getElementById('img2_'+id).style.display=='none') {
		document.getElementById('img1_'+id).style.display='none';
		document.getElementById('img2_'+id).style.display='block';
	} else {
		document.getElementById('img1_'+id).style.display='block';
		document.getElementById('img2_'+id).style.display='none';
	}
	//document.getElementById('img_selector_'+id).style.background='#01b0f0';
}


