
// Browser detection -- Begin -------------------
var browser = '';

//Detect Opera
if(navigator.userAgent.indexOf("Opera")!=-1){
  var versionindex=navigator.userAgent.indexOf("Opera")+6;
  if (parseInt(navigator.userAgent.charAt(versionindex))>=8)
    browser = 'opera';
}

//Detect Netscape 4.7+
if (navigator.appName=="Netscape"&&parseFloat(navigator.appVersion)>=4.7) {
    browser = 'netscape';
}

//Detect FireFox 1.0+
if(navigator.userAgent.indexOf("Firefox")!=-1){
  var versionindex=navigator.userAgent.indexOf("Firefox")+8;
  if (parseInt(navigator.userAgent.charAt(versionindex))>=1)
    browser = 'firefox';
}

//Detect IE5.5+
version=0
if (navigator.appVersion.indexOf("MSIE")!=-1){
  temp=navigator.appVersion.split("MSIE");
  version=parseFloat(temp[1]);
}
if (version>=5.5) {//NON IE browser will return 0
    browser = 'msie';
}
// Browser detection -- End -------------------





// Save mouse position -- Begin -------------------
var screenX;
var screenY;

function mousecoordIE(){
  screenX = event.clientX;
  screenY = event.clientY;
}

function mousecoordNS(e){
  screenX = e.clientX;
  screenY = e.clientY;
}

if (browser == 'msie') {
  document.onmousemove=mousecoordIE;
}
else {
  document.onmousemove=mousecoordNS;
}
// Save mouse position -- End -------------------




// Show / Hide HTML elements -- Begin -------------------
function show_element_onclick(id) {
  var w = document.getElementById(id);

  var offsetX = 0;
  var offsetY = 0;

  var right = screenX + parseInt(w.style.width.replace(/[px]/g, ""));
  var bottom = screenY + parseInt(w.style.height.replace(/[px]/g, ""));

  if (screen.width < right) {
    offsetX = right - screen.width + 30; // Gördítősáv méretét hozzáadjuk
  }
  if (screen.height < bottom) {
    offsetY = bottom - screen.height + 30; // Gördítősáv méretét hozzáadjuk
  }

  w.style.left = screenX - offsetX + 'px';
  w.style.top = screenY - offsetY + 'px';
  w.style.visibility = 'visible';
}

function show_element(id) {
  var w = document.getElementById(id);
  w.style.visibility = 'visible';
}

function hide_element(id) {
  var w = document.getElementById(id);
  w.style.visibility = 'hidden';
}
// Show / Hide HTML elements -- End -------------------



// Other functions -- Begin ---------------------------




// Csak számokat lehet beírni a mezőbe

// calculate the ASCII code of the given character
function CalcKeyCode(aChar) {
  var character = aChar.substring(0,1);
  var code = aChar.charCodeAt(0);
  return code;
}

function only_number(id) {
  var val;
  val = document.getElementById(id);
  var strPass = val.value;
  var strLength = strPass.length;
  var lchar = val.value.charAt((strLength) - 1);
  var cCode = CalcKeyCode(lchar);

  /* Check if the keyed in character is a number  do you want alphabetic UPPERCASE only ?  or lower case only just check their respective  codes and replace the 48 and 57 */
  if (cCode < 48 || cCode > 57 ) {
    var myNumber = val.value.substring(0, (strLength) - 1);
    val.value = myNumber;
  }
  return false;
}
// Csak számokat lehet beírni a mezőbe


// Számlázási cím adatainak másolása a szállítási címbe
function copy_address(){ 
  document.mainform.us_country2.value = document.mainform.us_country.value;
  document.mainform.us_zipcode2.value = document.mainform.us_zipcode.value;
  document.mainform.us_city2.value = document.mainform.us_city.value;
  document.mainform.us_address2.value = document.mainform.us_address.value;
}

// Forint konvertálva Euróra
function huf_to_eur($huf,$eur) {
	retval = Math.ceil(($huf/$eur)*10)/10;
	return retval;
}

// Nem üres szám
function ismynumeric(adat){ 
  var minta = "0123456789";
  if (adat.length == 0)
    return 0;
  for (var i=0; i<adat.length; i++) 
    if (minta.indexOf(adat.charAt(i)) == -1) 
      return 0; 
  return adat; 
}

// Help ablak megnyitása
function help(id) { 
  var str='help.php?id='+id;
  window.open(str,'help','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=400, height=500, top=0');
} 


// Kép ablak megnyitása
function pic(pic, width, height) { 
  height = height + 33;
  var str='picview.php?pic='+pic;
  var str2='toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+', top=0';
  window.open(str,'pic',str2);
} 


// Popup ablak megnyitása
function popup(url, width, height) { 
  var str2='toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+width+', height='+height+', top=0';
  window.open(url,'pop',str2);
} 


// Linkre ugrik
function jump(mezo){ 
  setTimeout("location.href='"+mezo+"'",50);
} 

function inc(id) {
  var field;
  field = document.getElementById(id);
  if (!ismynumeric(field.value)) {
    field.value = 0;
  }
  field.value++;
}

function dec(id) {
  var field;
  field = document.getElementById(id);
  if (field.value <= 1) {
    field.value = '';
  }
  else {
    field.value--;
  }
}

function addtopack(id, add) {
  var field;
  field = document.getElementById(add);
  if (ismynumeric(field.value)) {
    setTimeout("location.href='pack_items.php?page=CHECK&id="+id+"&add="+add+"&db="+field.value+"'",50);
  }
}

function news_message_submit(logged_user) {
	var retval = false;
	if (logged_user && document.news_message.nm_text.value != '') {
		retval = true;
	}
	return retval;
}


