/**
 * onLoad listeners
 */
window.onloadListeners=new Array();

/**
 * Add onLoad listener
 */
window.addOnLoadListener = function (listener, params) {
	window.onloadListeners[window.onloadListeners.length] = listener;
}

/**
 * Call onLoad functions
 */
window.onload=function(){
	for(var i=0; i<window.onloadListeners.length; i++)
	{
		func = window.onloadListeners[i];
		
		if (typeof func == "function") {
			func.call();
		}
	}
}

function open_popup(pURL,name,w,h,scrollbars,resizable)
{
	if (resizable==null) resizable=1;
	if (scrollbars==null) scrollbars=1;
	var top  = ((screen.availHeight-h)/2);
	var left = ((screen.availWidth-w)/2);
	var nyit = window.open(pURL,name,'toolbar=0,location=0,directories=0,status=0,\
		menubar=0,scrollbars='+scrollbars+',resizable='+resizable+',width='+w+',height='+h+',top='+top+',left='+left);
	nyit.focus();
	return nyit;
}

function addquotes(str)
{
	var re = /(['"])/g;
	return str.replace(re,function ($0, $1) {
	switch($1)
	{
		case '"':
		return "&quot;";
		case '&':
		return "&amp;";
		default:
		return $1;
	}});
}

function pop_kep(kep,label,w,h)
{
	var ablak=open_popup('about:blank','nagykep',w,h,0,0);
	var d=ablak.document;
	var title=(label.length>0) ? label+' - ' : '';
	d.write('<html><head><title>',addquotes(title),
		'</title></head><body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">',
		'<a name="nagykep" href="#" onclick="self.close();" onblur="self.close()">',
		'<img border="0" alt="',addquotes(label),'" src="',addquotes(kep),'" width="',w,'" height="',h,'"></a></body></html>');
	d.anchors[0].focus();

}

function pop_inner(inner,label,w,h)
{
	var ablak=open_popup('about:blank','inner_popup',w,h,1,0);
	var d=ablak.document;
	var title=(label.length>0) ? label+' - ' : '';
	d.write('<html><head><title>',title,
		'</title>\n',
		'<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">\n',
		'<link rel=stylesheet type="text/css" href="/client.css">\n</head>\n',
		'<body marginheight="0" marginwidth="0" leftmargin="0" topmargin="0">\n',
		inner,
		'\n</body>\n</html>\n');
	d.close();
}


function add_to_basket (id) {
	form1 = document.forms['pr'];
	form2 = document.forms['products'];
	form1.elements["doc_id"].value = id;
	form1.elements["piece"].value = form2.elements['pr_'+id].value;
	if (form2.elements['pr_'+id].value>=0)
	{
		form1.submit();
	}
	
}


//<input type="hidden" name="doc_id" value="">
//<input type="hidden" name="piece" value="">

function setPage(form, page) {
	form = document.forms[form];
	element = form.elements["page"];
	element.value = page;
	form.elements["t_number"].value =document.forms['tnumber'].elements["t_number"].value;
	form.submit();
}

/* küldéshez */
function showSend() {
	document.getElementById('email').style.display="block";
	document.sendform.cimzett_email.focus();
}

function hideSend() {
	document.getElementById('email').style.display="none";
}
function checkemail(str)
{
	var filter=/^.+@.+\..{2,3}$/
	return (filter.test(str))
}
function checkSendFields(th) {
		var err=0;
		if(!checkemail(th.cimzett_email.value) ) {
			err=1;
		}
		if(!checkemail(th.felado_email.value)) {
			err=1;
		}
		if(err) {
			alert("A címzett és a feladó email címének megadása kötelező");
			return false;
		}
			return true;		
	}

function checkSendFieldsEn(th) {
		var err=0;
		if(!checkemail(th.cimzett_email.value) ) {
			err=1;
		}
		if(!checkemail(th.felado_email.value)) {
			err=1;
		}
		if(err) {
			alert("Missing email adresses!");
			return false;
		}
			return true;		
	}

function setCookie(c_name, value, expiredays, path) {
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);

	var cookieStr = c_name+"="+escape(value)+((expiredays==null) ? "" : ";expires="+exdate.toGMTString());

	if (typeof(path) == 'string') {
		cookieStr += '; path=' + path;
	}
	document.cookie = cookieStr;
}

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));
    	}
  	} else {
  		return "";
  	}
}

function open_close_div(objName, lang) {
	obj = document.getElementById(objName);
	bObj = document.getElementById("b_" + objName);

	if (typeof(obj) != 'object' || typeof(bObj) != 'object' || typeof(lang) != 'string') {
		alert("ERROR");
		return;
	}

	if (obj.style.visibility == "hidden") {
		obj.style.visibility = "visible";
		obj.style.overflow = "visible";
		obj.style.height="100%";
		bObj.innerHTML = '<img src="/images/'+lang+'/tovabbi_informaciok2.gif" width="157" height="12" border="0" alt="" vspace="3" hspace="4" />';
		setCookie('custom_info', 1, 1);
		window.location.href = "#tovabbi";
	} else {
		obj.style.visibility = "hidden";
		obj.style.overflow = "hidden";
		obj.style.height = "1px";
		bObj.innerHTML='<img src="/images/'+lang+'/tovabbi_informaciok.gif" width="157" height="12" border="0" alt="" vspace="3" hspace="4" />';
		setCookie('custom_info');
		window.location.href="#top";
	}
}

/*
var mousePosition = {'x':0, 'y':0};

function getMousePosition(e) {
	var posx = 0;
	var posy = 0;

	if(!e) var e = window.event;

	if (e) {
		if (e.pageX || e.pageY) {
			posx = e.pageX;
			posy = e.pageY;
		} else if (e.clientX || e.clientY) 	{
			posx = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
			posy = e.clientY + document.body.scrollTop + document.documentElement.scrollTop;
		}
		mousePosition.x = posx;
		mousePosition.y = posy;
	}
}

document.onmousemove = getMousePosition;
*/

function showInventoryInfo(objName) {
	var iObj = document.getElementById(objName);
	
	if (iObj) {
		iObj.style.display = 'inline';
		/*
		iObj.style.top = mousePosition.y + 12;
		iObj.style.left = mousePosition.x + 12;
		*/
	}
}

function hideInventoryInfo(objName) {
	var iObj = document.getElementById(objName);

	if (iObj) {
		iObj.style.display = 'none';
	}
}

function setSubtitle(obj, title, subtitle, link) {
	if (obj && title) {
		if (subtitle) {
			obj.innerHTML = title+'<br /><span class="subTitle">'+subtitle+'</span>';
			/*
			obj.style.paddingTop = '4px';
			obj.style.paddingBottom = '4px';
			*/
		} else {
			obj.innerHTML = title;
			/*
			obj.style.paddingTop = '12px';
			obj.style.paddingBottom = '10px';
			*/
		}

	}
}
function menuOver(current,lang) {
	
	var temp = current.src.split('.');
	var imageUrl = temp[temp.length-2].split('/');
	var newUrl = imageUrl[imageUrl.length-1];
	var newSrc = '/images/fl'+lang+newUrl+'_over.png';
	current.src = newSrc;
}
function menuOut(current,lang) {
	
	var temp = current.src.split('.');
	var imageUrl = temp[temp.length-2].split('/');
	var newUrl = imageUrl[imageUrl.length-1].split('_')[0];
	var newSrc = '/images/fl'+lang+newUrl+'.png';
	current.src = newSrc;
}

function setSideImagePosition() {
	if (typeof($) == 'function') {
		var infoObj = $('b_tovabbi_informaciok');
		var imgContainerObj = $('docImageContainer');

		if (infoObj && imgContainerObj) {
			var infoPos = infoObj.positionedOffset();
			var imgPos = imgContainerObj.positionedOffset();
			var imgDim = imgContainerObj.getDimensions();

			if (infoPos.top > imgPos.top + imgDim.height) {
				imgContainerObj.setStyle({
					height: (infoPos.top - imgPos.top)+'px'
					});
			}
		}
	}
}

addOnLoadListener(setSideImagePosition);

function replaceCustomFonts() {
	if (typeof($) == 'function' && typeof(Cufon) == 'function') {
		var objs = null;
		/*
		objs = $$('.cufonDevinne');

		if (objs) {
			Cufon.replace(objs, {fontFamily: 'DeVinne Txt BT'});
			objs = null;
		}
		*/
		objs = $$('.cufonAvenirMedium');
		
		if (objs) {
			Cufon.replace(objs, {fontFamily: 'Avenir LT Pro'});
			objs = null;
		}
	
		objs = $$('.cufonAvenirHeavy');
		
		if (objs) {
			Cufon.replace(objs, {fontFamily: 'Avenir LT Pro 55 Roman'});
			objs = null;
		}

		objs = $$('.cufonAvenirNextMedium');

		if (objs) {
			Cufon.replace(objs, {fontFamily: 'AvenirNext LT Pro Medium'});
			objs = null;
		}
		
		objs = $$('.cufonITCModernLight');

		if (objs) {
			Cufon.replace(objs, {fontFamily: 'ITC Modern TwoSxtn Hun', fontWeight: 300});
			objs = null;
		}
		
		objs = $$('.cufonITCModernMedium');

		if (objs) {
			Cufon.replace(objs, {fontFamily: 'ITC Modern TwoSxtn Hun', fontWeight: 500});
			objs = null;
		}

		Cufon.now();
	}
}

addOnLoadListener(replaceCustomFonts);

function navigateParent(url) {
	var win = (window.opener) ? window.opener : (window.parent) ? window.parent : window;
	
	if (win && url) {
		win.location.replace(url);
        win.focus();
	}
}

function popupSubMing(url) {
    var params = '';

    params  = 'width='+screen.width;
    params += ', height='+screen.height;
    params += ', top=0, left=0'
    params += ', fullscreen=yes';

    window.open(url,'mywindow',params);
}
