
function setCookie (name, value, expires)
{
	expdate = new Date();
	expdate.setTime (expdate.getTime() + (1000 * expires));

    document.cookie = name + "=" + escape (value) + "; expires=" + expdate.toGMTString() +  "; path=/";
}

// setCookie ('kukinev', 'ertek', 60);    // expires in 60 seconds

function asknumber(name, num)
{
	ver4 = (parseInt(navigator.appVersion) > 3)
	ns4 = (ver4 && navigator.appName == "Netscape") ? 1:0
	ie4 = (ver4 && navigator.appName != "Netscape") ? 1:0

	askUrl = '/ask.php' + '?' + 'name=' + no_uc(escape(name)) + '&' + 'num=' + num;

	if(ie4)
		ret = window.showModalDialog(askUrl, "", "dialogWidth: 300px; dialogHeight: 200px; status: no;");
	else
		ret = prompt(name + '\nAdja meg a kért darabszámot!', c);

	return parseInt(ret);
}

function _item(op, pid, partnum, shortname, price, q, w, carr)
{
	c = (op == 'add') ? 1 : q;
	y = asknumber(shortname, c);

	if(y == NaN)
		return;

	x = y * 1;

	if(x != y)
		return;

	y = x;

	if((op == 'add') && (y <= 0))
		return;

	if((op == 'mod') && (y < 0))
		return;

	if(q == y)
		return;

	basketurl = '/kosar_hu.php?pid=' + pid + '&partnum=' + escape(partnum);
	basketurl += '&shortname=' + no_uc(escape(shortname)) + '&price=' + escape(price);
	basketurl += '&q=' + escape(y) + '&w=' + escape(w) + '&carr=' + escape(carr);

	h = document.location;
	s = h.protocol + '//' + h.host + h.port + basketurl;      // h.pathname;

	setCookie ('basketitemop', op, 180);
	window.location = s;
}

function item(op, pid, shortname, price, q)
{
	if((q == NaN) || (q == '') || (q.length == 0) || (q == 0))
		return;

	x = q * 1;

	if(x != q)
		return;

	x = parseInt(q);

	if(x != q)
		return;

	if(q < 0)
		return;

	setCookie('basketitemop', op, 180);

	if(op == 'add')
		askUrl  = 'item.php';
	else
		askUrl  = 'askitem.php';

	askUrl += '?pid=' + pid;
	askUrl += '&shortname=' + no_uc(escape(shortname));
	askUrl += '&price=' + escape(price);
	askUrl += '&q=' + escape(q);

	sw = centerwin(300, 180);
	neo_addwin = window.open(askUrl, "neo_add", sw);
}

function centerwin(intWidth, intHeight)
{
	winL = 100;
	winT = 100;
	winW = 630;
	winH = 460;
	
	if(parseInt(navigator.appVersion) > 3)
	{
		if(navigator.appName == "Netscape")
		{
			winL = window.screenX;
			winT = window.screenY;
			winW = window.outerWidth - 16;
			winH = window.outerHeight - 16;
		}

		if (navigator.appName.indexOf("Microsoft") != -1)
		{
			winL = top.screenLeft;
			winT = top.screenTop - 60;
			winW = top.document.body.offsetWidth - 20;
			winH = top.document.body.offsetHeight - 20;
		}
	}

	wleft = (winW / 2) - (intWidth / 2) + winL;
	wtop = (winH / 2) - (intHeight / 2) + winT;

	strWinProp = " toolbar=no"			//Back, Forward, etc...
	           + ",location=no"			//URL field
	           + ",directories=no"		//"What's New", etc...
	           + ",status=no"			//Status Bar at bottom of window.
	           + ",menubar=no"			//Menubar at top of window.
	           + ",resizable=yes"		//Allow resizing by dragging.
	           + ",scrollbars=no"		//Displays scrollbars is document is larger than window.
	           + ",titlebar=yes"		//Enable/Disable titlebar resize capability.
	           + ",width=" + intWidth	//Standard 640,800/788, 800/788
	           + ",height=" + intHeight	//Standard 480,600/541, 600/566               
	           + ",top=" + wtop			//Offset of windows top edge from screen.
	           + ",left=" + wleft		//Offset of windows left edge from screen.
	           + "";  
	
	return strWinProp;
}


function no_uc(str)
{
	str = str.replace(/%u0151/ig, '%F5');		// ő
	str = str.replace(/%u0150/ig, '%D5');		// Ő
	str = str.replace(/%u0171/ig, '%FB');		// ű
	str = str.replace(/%u0170/ig, '%DB');		// Ű
	
	return str;
}

function brkframe(real_location)
{
	if(top.location)
	{
		if(self != top)
			top.location = self.location;
	}
	else
	{
		if(parent.location)
		{
			if(parent.location != real_location)
				parent.location = real_location;
		}
	}
}

function dologin()
{
	neo_loginwin = window.open("dologin_hu.html","neo_login","width=210,height=200,top=200,left=200,resizable,scrollbars,status='0',toolbar='0',location='0',menubar='0',directories='0'");
}

function sendpw()
{
	neo_pwwin = window.open("sendpw_hu.html","neo_pw","width=270,height=210,top=200,left=200,resizable,scrollbars,status='0',toolbar='0',location='0',menubar='0',directories='0'");
}

function windowopen(theURL)
{
	x = window.open(theURL,"neo_opened","left=50,top=50,width=500,height=500,resizable,scrollbars,status='0',toolbar='0',location='0',menubar='0',directories='0'");
}

function tpopup(theURL, theName)
{
	var wp;
	if(! theURL) theURL = "";
	if(! theName) theName = "neo_opened";
	wp = window.open(theURL, theName, "left=" + (50 + (screen.width - 800) / 4) + ",top=" + (25 + (screen.height - 600) / 4) + ",width=512,height=520,resizable=yes,scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,directories=no");
	wp.focus();
	return wp;
}

function highlight(x)
{
	document.all.item(x).style.background = '#DEE7EF';
}

function normlight(x)
{
	document.all.item(x).style.background = '#ECECEC';
}

function mouseover_init()
{
	if (! document.getElementById)
		return;
	
	var mo_imgSrc = new Array();
	var mo_imgHSrc = new Array();
	
	var mo_imgarr = document.getElementsByTagName('img');
	
	for (var i = 0; i < mo_imgarr.length; i++)
		if (mo_imgarr[i].getAttribute('hsrc'))
		{
			mo_imgSrc[i] = new Image();
			mo_imgSrc[i].src = mo_imgarr[i].getAttribute('src');
			
			mo_imgHSrc[i] = new Image();
			mo_imgHSrc[i].src = mo_imgarr[i].getAttribute('hsrc');
			
			mo_imgarr[i].setAttribute('moid', i);
			
			mo_imgarr[i].onmouseover = function(){ this.src = mo_imgHSrc[this.getAttribute('moid')].src; }

			mo_imgarr[i].onmouseout = function(){ this.src = mo_imgSrc[this.getAttribute('moid')].src; }
		}
}

function links2blank(mydomain)
{
	for(i = 0; i <= (document.links.length - 1); i++)
	{
		if(document.links[i].hostname.indexOf(mydomain) == -1 && document.links[i].href.indexOf("http:") != -1)
			if(document.links[i].target == "")
				document.links[i].target = "_blank"
	}
}

function chkmail(mailaddr)
{
	var e;
	e = mailaddr;
	return (! (e.search("^[a-zA-Z0-9_\\-\\.]+@[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z0-9\\-\\.]+$")));
}
