//------------------------------------------------------------------------------
// init functions
//------------------------------------------------------------------------------

function smInitPage()
{
	if (document.links)
	  for (a=0; a<document.links.length; a++)
		{
		  href = document.links[a].href;
		  if (href.substr(href.length-1,1)!='#')
			document.links[a].onclick = function()
			{
  		  hf = smGetObject('hiddenform');
			  qa = this.name.split(":");
				for (n in qa)
				{
				  qb = qa[n].split("_");
			    t = document.createElement('input');
					t.setAttribute('type','hidden');
					t.setAttribute('name',qb[0]);
					t.setAttribute('value',qb[1]);
					hf.appendChild(t);
				} 
			  hf.action = this.href;
				hf.submit();
				return false;
			}
		}

}

//------------------------------------------------------------------------------
// common functions
//------------------------------------------------------------------------------

function smGetObject(id) {
  if (document.getElementById) t = document.getElementById(id)
  if (document.all)            t = document.all[id]
  return t;
}

function smFindPos(id)
{
	var left = 0;
	var top = 0;
	object = smGetObject(id);
	if (object.offsetParent)
	{
		do
		{
			left += object.offsetLeft;
			top += object.offsetTop;
		} while (object = object.offsetParent);
	}
	return {left:left,top:top};
}

function smGetSize(id)
{
	var width = 0;
	var height = 0;
	object = smGetObject(id);
  width = object.offsetWidth;
  height = object.offsetHeight;
	return {width:width,height:height};
}

function smGetWindowSize()
{
	var width = 0;
	var height = 0;
	if (window.innerWidth || window.innerHeight)
	{
    width = window.innerWidth;
  	height = window.innerHeight;
	}
	else
	{
    width = document.body.offsetWidth;
  	height = document.body.offsetHeight;
	}
	return {width:width,height:height};
}

function smGetMouse(e)
{
  var evt = e || window.event;
  x = parseInt(evt.clientX);
  y = parseInt(evt.clientY);
	return {x:x,y:y}
}

function smTrim(str, chars) {
    return smLTrim(smRTrim(str, chars), chars);
}

function smLTrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function smRTrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function smWriteEmail(s1,s2,s3)
{
  document.write('<a href="mai'+'lto:'+s1+'@'+s2+'.'+s3+'">'+s1+'@'+s2+'.'+s3+'</a>')
}

function smCheckEmail(emil) {
 obj = smGetObject(emil);
 if (obj.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)) 
  return true;
 else {
  alert("Az e-mail cím megadása kötelező!");
  return false;
 }
}



function smCheckPass(passwd1,passwd2) {
 obj1 = smGetObject(passwd1);
 obj2 = smGetObject(passwd2);
 if (obj1.value!=obj2.value) {
  alert("A beírt két jelszó nem egyezik!");
  return false;
 }
 else
  return true;
}


function smSetHomepage(page)
{
  if (document.all)
	{
    document.body.style.behavior = 'url(#default#homepage)'
    document.body.setHomePage('http://' + page)
    return false
  }
  else alert('Ez a funkció csak Internet Explorer böngészővel működik!')
}

function smObjEventAdd(object,event,fn)
{
	if (object.addEventListener)
		object.addEventListener(event,fn,false);
	else if (object.attachEvent)
		object.attachEvent('on'+event,fn);
}

function smObjEventRemove(object,event,fn)
{
	if (object.removeEventListener)
		object.removeEventListener(event,fn,false);
	else if (object.detachEvent)
		object.detachEvent('on'+event,fn);
}

//------------------------------------------------------------------------------

function smOpenVideo(file,x,y)
{
  if( document.all )
  {
    VidWin = window.open('', 'VidWin', 'width='+x+',height='+y+',toolbar=no,scrollbars=no,menubar=no');
 		VidWin.document.write('<html>\n<body style="margin: 0px;">\n');
 		VidWin.document.write('<object type="application/x-mplayer2" width="'+x+'" height="'+y+'">\n<param name="src" value="/video/'+file+'"></param>\n</object>\n');
 	}
 	else
	{
 	  VidWin = window.open('', 'VidWin', 'width='+x+',height='+y+',toolbar=no,scrollbars=no,menubar=no');
 		VidWin.document.write('<html>\n<body style="margin: 0px;">\n');
 		VidWin.document.write('<object type="video/avi" data="/video/'+file+'" width="'+x+'" height="'+y+'">\n<param name="controller" value="true"></param>\n</object>\n');
	}
  VidWin.document.write('</body>\n</html>\n');
}
