window.onload = function() {
  clearDefault();
};

function popUp(URL) {
var xtavolsag =((screen.width)-550);
adatok = "toolbar=0,location=0,statusbar=0,menubar=0,resizable=0,width=540,height=690,left ="+xtavolsag+",top = 0";
newwindow = window.open(URL, 'Galeria2', adatok); 
newwindow.focus();
}

function checkForm()
{
	var cname, cemail, csubject, cmessage, cnumber;
    with(window.document.msgform)
    {
        cname    = sname;
        cemail   = email;
        csubject = subject;
        cmessage = message;
		cnumber = txtNumber;
    }
    
    if(trim(cname.value) == '')
    {
        alert('Add meg a neved!');
        cname.focus();
        return false;
    }
    else if(trim(cemail.value) == '')
    {
        alert('Add meg az email címed!');
        cemail.focus();
        return false;
    }
    else if(!isEmail(trim(cemail.value)))
    {
        alert('A megadott email cím hibás!');
        cemail.focus();
        return false;
    }
    else if(trim(csubject.value) == '')
    {
        alert('Az üzenetnek nincs tárgya!');
        csubject.focus();
        return false;
    }
    else if(trim(cmessage.value) == '')
    {
        alert('Az üzenet mező üres!');
        cmessage.focus();
        return false;
    }
    else if(trim(cnumber.value) == '')
    {
        alert('Add meg az ellenőrző kódot!');
        cnumber.focus();
        return false;
    }
	    else if(trim(cnumber.value) == '')
   {
        alert('Add meg a helyes ellenőrző kódot!');
        cnumber.focus();
        return false;
    }
    else
    {
        cname.value    = trim(cname.value);
        cemail.value   = trim(cemail.value);
        csubject.value = trim(csubject.value);
        cmessage.value = trim(cmessage.value);
        cnumber.value = trim(cnumber.value);
        return true;
    }
}

/*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}

/*
Check if a string is in valid email format. 
Returns true if valid, false otherwise.
*/
function isEmail(str)
{
    var regex = /^[-_.a-z0-9]+@(([-_a-z0-9]+\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i;
    return regex.test(str);
}


function clearDefault(){ 
var dbg='#E4E4E4'; // Background color, Default
var fbg='#FFFFFF'; // Background color, onFocus 
	var tI = document.getElementsByTagName('input'); var tT = document.getElementsByTagName('textarea');
	for (var i = 0; i < tI.length; i++) { 
		if (tI[i] && tI[i].getAttribute('type') != '' && tI[i].getAttribute('type').toLowerCase() == 'text' || tI[i].getAttribute('type').toLowerCase() == 'password') 
		{tI[i].style.backgroundColor = dbg; thisValue = tI[i].getAttribute("title");
			if (thisValue){	tI[i].value = thisValue;} 
			tI[i].onfocus = function(){this.style.backgroundColor = fbg; if (this.value != this.getAttribute("title") && this.value != '') {return;} 
			else {this.value = '';}};
			tI[i].onblur = function(){this.style.backgroundColor = dbg; if (this.value == ''){this.value = this.getAttribute("title");}};}} 
	for (var i = 0; i < tT.length; i++){if (tT[i]){tT[i].style.backgroundColor = dbg; thisValue = tT[i].getAttribute("title");if (thisValue){tT[i].value = thisValue;} 
			tT[i].onfocus = function(){this.style.backgroundColor = fbg; if (this.value != this.getAttribute("title") && this.value != ''){return;}
			else {this.value = '';}};
			tT[i].onblur = function(){this.style.backgroundColor = dbg;if (this.value == ''){this.value =  this.getAttribute("title");}};}} 
}

function JustSoPicWindow(imageName,imageWidth,imageHeight,alt,bgcolor,hugger,hugMargin) {
// by E Michael Brandt of ValleyWebDesigns.com - Please leave these comments intact.
// version 3.0.4  

	if (bgcolor=="") {
		bgcolor="#FFFFFF";
	}
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	if(w<740){
	  var lift=0.90;
	}
	if(w>=740 & w<835){
	  var lift=0.91;
	}
	if(w>=835){
	  var lift=0.93;
	}
	if (imageWidth>w){	
	  byFactor = w / imageWidth;			
	  imageWidth = w;
	  imageHeight = imageHeight * byFactor;
	}
	if (imageHeight>h-adj){
	  byFactor = h / imageHeight;
	  imageWidth = (imageWidth * byFactor);
	  imageHeight = h; 
	}
	   
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;

	if (imageHeight>scrHeight){
  	  imageHeight=imageHeight*lift;
	  imageWidth=imageWidth*lift;
	}

	var posLeft=0;
	var posTop=0;

	if (hugger == "hug image"){
	  if (hugMargin == ""){
	    hugMargin = 0;
	  }
	  var scrHeightTemp = imageHeight - 0 + 2*hugMargin;
	  if (scrHeightTemp < scrHeight) {
		scrHeight = scrHeightTemp;
	  } 
	  var scrWidthTemp = imageWidth - 0 + 2*hugMargin;
	  if (scrWidthTemp < scrWidth) {
		scrWidth = scrWidthTemp;
	  }
	  
	  if (scrHeight<100){scrHeight=100;}
	  if (scrWidth<100){scrWidth=100;}

	  posTop =  ((h-(scrHeight/lift)-adj)/2);
	  posLeft = ((w-(scrWidth)-adj)/2);
 	}

	if (imageHeight > (h*lift)-adj || imageWidth > w-adj){
		imageHeight=imageHeight-adj;
		imageWidth=imageWidth-adj;
	}
	posTop = parseInt(posTop);
	posLeft = parseInt(posLeft);		
	scrWidth = parseInt(scrWidth); 
	scrHeight = parseInt(scrHeight);
	
	var agt=navigator.userAgent.toLowerCase();
	if (agt.indexOf("opera") != -1){
	  var args= new Array();
	  args[0]='parent';
	  args[1]=imageName;
	  var i ; document.MM_returnValue = false;
	  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
	} else {
	newWindow = window.open("vwd_justso.htm","newWindow","width="+scrWidth+",height="+scrHeight+",left="+posLeft+",top="+posTop);
	newWindow.document.open();
	newWindow.document.write('<html><title>'+alt+'</title><body leftmargin="0" topmargin="0" marginheight="0" marginwidth="0" bgcolor='+bgcolor+' onBlur="self.close()" onClick="self.close()">');  
	newWindow.document.write('<table width='+imageWidth+' border="0" cellspacing="0" cellpadding="0" align="center" height='+scrHeight+' ><tr><td>');
	newWindow.document.write('<img src="'+imageName+'" width='+imageWidth+' height='+imageHeight+' alt="Kattints az ablakra a bezáráshoz!" >'); 
	newWindow.document.write('</td></tr></table></body></html>');
	newWindow.document.close();
	newWindow.focus();
	}
}


function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.id; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' mezőbe add meg az email címed.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' számnak kell lennie.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' számnak kell lennie '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' mezőt ki kell töltened.\n'; }
  } if (errors) alert('Hiányosan töltötted ki a nevezési lapot:\n'+errors);
  document.MM_returnValue = (errors == '');
}

