﻿function openwindow(imageName,imageWidth,imageHeight) { 
  if (imageHeight > screen.height) {
    windowWidth=parseInt(imageWidth)+20; // vert. scroll bar size
	scrBar=",scrollbars=1";
  } else {
	windowWidth=imageWidth;
	scrBar="";
  }
  newWindow =window.open("","newWindow","width="+windowWidth+",height="+imageHeight+",left=20,top=20"+scrBar);

  newWindow.document.open();
  
  newWindow.document.write('<html><title>'+imageName+'</title><meta http-equiv="imagetoolbar" content="no" /><body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" onBlur="self.close();" oncontextmenu="return false;" galleryimg="no" oncopy="return false;" ondragstart="return false;" onmousedown="return false;" onmouseup="return false;" onmousemove="return false;" onmouseout="return false;" onmouseover="return false;" onkeydown="return false;"  onkeyup="return false;" onkeypress="return false;" onselectstart="return false;" onclick="return false;" ondblclick="return false;" >'); 
  newWindow.document.write('<img src='+imageName+' width='+imageWidth+' height='+imageHeight+' title='+imageName+'>');
   
  newWindow.document.write('</body></html>');
  newWindow.document.close();
  newWindow.focus();
} 

//-----------------------------
//-----------------------------

function ismaxlength(obj) {
  if (obj.getAttribute) {
   slength=obj.getAttribute("maxlength");
   mlength=parseInt(slength);
   if (obj.value.length > mlength) {
     alert( "A szöveg "+ slength +" karakter lehet csak!" );	   
	 obj.value=obj.value.substring(0,mlength);
   }	  
  }	
}

function btnAnim(sId, sPict) {
  sImg = new Image();
  sImg.src = sPict;		
  document.getElementById(sId).src=sImg.src;
}

function changeCat(sU1,sCat,sU2){	
  window.location=sU1+sCat+sU2;	
}


// trim
String.prototype.trim = function() {
  a = this.replace(/^\s+/, '');
  return a.replace(/\s+$/, '');
};

//-----------------------------

function addSelectedToList( frmName, srcListName, tgtListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var tgtList = eval( 'form.' + tgtListName );

	var srcLen = srcList.length;
	var tgtLen = tgtList.length;
	var tgt = "x";

	//build array of target items
	for (var i=tgtLen-1; i > -1; i--) {
		tgt += "," + tgtList.options[i].value + ","
	}

	//Pull selected resources and add them to list
	//for (var i=srcLen-1; i > -1; i--) {
	for (var i=0; i < srcLen; i++) {
		if (srcList.options[i].selected && tgt.indexOf( "," + srcList.options[i].value + "," ) == -1) {
			opt = new Option( srcList.options[i].text, srcList.options[i].value );
			tgtList.options[tgtList.length] = opt;
		}
	}
}

function delSelectedFromList( frmName, srcListName ) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );

	var srcLen = srcList.length;

	for (var i=srcLen-1; i > -1; i--) {
		if (srcList.options[i].selected) {
			srcList.options[i] = null;
		}
	}
}

function moveInList( frmName, srcListName, index, to) {
	var form = eval( 'document.' + frmName );
	var srcList = eval( 'form.' + srcListName );
	var total = srcList.options.length-1;

	if (index == -1) {
		return false;
	}
	if (to == +1 && index == total) {
		return false;
	}
	if (to == -1 && index == 0) {
		return false;
	}

	var items = new Array;
	var values = new Array;

	for (i=total; i >= 0; i--) {
		items[i] = srcList.options[i].text;
		values[i] = srcList.options[i].value;
	}
	for (i = total; i >= 0; i--) {
		if (index == i) {
			srcList.options[i + to] = new Option(items[i],values[i], 0, 1);
			srcList.options[i] = new Option(items[i+to], values[i+to]);
			i--;
		} else {
			srcList.options[i] = new Option(items[i], values[i]);
	   }
	}
	srcList.focus();
}

//-----------------------------
function checkNum(x)  {
   var s_len=x.value.length ;
   var s_charcode = 0;
   for (var s_i=0;s_i<s_len;s_i++)     {
      s_charcode = x.value.charCodeAt(s_i);
      if(!((s_charcode>=48 && s_charcode<=57)))  {
         x.value='';
         x.focus();
         return false;
      }
  }
  return true;
}
//-----------------------------
var dtCh= "/";
var minYear=0;
var maxYear=2100;

function isInteger(s){	
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function isDecimal(s){	
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
		if (c!="," && c!="-") {
          if (((c < "0") || (c > "9"))) return false;
		}
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	// ev 4 jegyre egeszit
    var pos1=dtStr.indexOf(".")
    if ((pos1 != -1) && (pos1 < 4)) {
	    for (var x=1; x<parseInt(pos1,10); x++) {
          dtStr = "0" + dtStr
		}
    }
    dtStr=dtStr.substr(5,2)+'/'+dtStr.substr(8,2)+'/'+dtStr.substr(0,4)	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("Érvénytelen dátum formátum (mm/dd/yyyy kell)");
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Érvénytelen dátum: hónap");
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Érvénytelen dátum: nap");
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Érvénytelen dátum: év ("+minYear+" - "+maxYear+")");
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Érvénytelen dátum");
		return false;
	}
return true;
}

