String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ''); };

var reloadnum = function(){
  $('checknum').src = '/checknum.php?num='+Math.ceil(100000*Math.random());
} 

var openSlideShow = function(tourl){
    var xsize = 1000;
    var ysize = 800; 
     popupwin(tourl,xsize,ysize);


}

var currentImage = 0;
var totalImages = 2;
var viewSize = 1;
var offSet = 420;

var ready = 1;
function moveToPrevious() {
	if((currentImage > 0) && (ready == 1)) {
		ready = 0;
  		new Effect.Move('photoinside', { 
			x: offSet, 
			y: 0, 
			transition: Effect.Transitions.sinoidal, afterFinish: function() {
			ready = 1;
			}
		});
		currentImage--;
	}
}

function moveToNext() {
	if((currentImage < totalImages-viewSize) && (ready == 1)) {
		ready = 0;
		new Effect.Move('photoinside', { 
			x: -offSet, 
			y: 0, 
			transition: Effect.Transitions.sinoidal, afterFinish: function() {
			ready = 1;
			}
		});		
		currentImage++;	
	}
}

function moveToFirst() {
	if(ready == 1) {
		ready = 0;
		new Effect.Move('photoinside', { 
			x: offSet*currentImage, 
			y: 0, 
			transition: Effect.Transitions.sinoidal, afterFinish: function() {
			ready = 1;
			}
		});		
		currentImage = 0;	
	}
}     

function moveTo(pos) {
	if(ready == 1) {
		ready = 0;
		new Effect.Move('photoinside', { 
			x: offSet*(currentImage-pos), 
			y: 0, 
			transition: Effect.Transitions.sinoidal, afterFinish: function() {
			ready = 1;
			}
		});		
		currentImage = pos;	
	}
}      

function popupwin(tourl,xsize,ysize){

		if ((typeof popup=='undefined') || popup.closed){
		    popup=window.open(tourl, 'popup', "toolbar=no,location=no,resizable=no,status=no,scrollbars=yes,menubar=no,width=" + xsize + ",height=" + ysize + ",left=" + ((screen.width/2)- xsize/2) + ",top=" + ((screen.height/2)- ysize/2));
		} else {
    		if (popup.outerWidth) {
    		    popup.outerWidth = xsize;
    		    popup.outerHeight = ysize;
    	  } else if (popup.resizeTo) {
    		    popup.resizeTo(xsize,ysize);
    	  }
    		popup.location.href=tourl;
    		popup.focus();
		}
    return false;
}
function setdefault(id){
      if ($(id)){
      	if(($F(id) == '') || ($F(id) == $(id).getAttribute('title')) ) { $(id).value = $(id).getAttribute('title');}
        $(id).onclick = function(){ if ($F(this)==this.getAttribute('title')){ Field.clear(this); } }
        $(id).onblur = function(){
          var val = $F(this);
          if (val.trim()==''){ this.value=this.getAttribute('title'); }
        }                    
      }
}

Event.observe(window,'load',function(){
setdefault('searchfield');
setdefault('username');
    if($('commentform')) {
	   	$('submit').onclick = function() {
		    var commenttext=''+$('comment2').value;
		    commenttext = commenttext.trim();
		    commenttext = commenttext.replace(/(\.|-|\?| )*/ig,'');
			   if (commenttext.length) {
			      $('submit').value = 'Hozzászólás küldése....';			      
			     $('submit').disabled=true;
           var myAjax = new Ajax.Updater( 'comment', $('commentform').action, { method: 'post', parameters: Form.serialize('commentform'), onComplete: function() {  
                $('submit').value = 'Elküld';
                $('submit').disabled=false;
            } });
           Field.clear('comment2'); 
           $('msg').innerHTML = '';
			   } else {
            $('msg').innerHTML = 'Hiányzó hozzászólás!';
            Element.show('msg');
         }
			 return false;
		  }
	 }
},false);	 