/* INGATLANMARKT ADMIN SCRIPTS */

/* LOCAL UTILS */
var debug = true;
var log = function(ent){ if(debug == true) { console.log(ent); } };

function empty(){};

window.addEvent('domready', function(){
	//FORMCHECK
	forms = $$('form');
	for(var i = 0; i < forms.length; i++){ var idSS = forms[i].id; new FormCheck(idSS); }
	
	var myTips = new Tips('.mootip');
	
	$('menu-lemezek').addEvents({
		mouseenter: function(){
			if(subD==false){
				this.setStyle('color', '#fff');
				var parent = this.getParent();
				parent.setStyle('background' , 'transparent url(images/lemezek-open-bg.jpg) no-repeat left top');
				var pos = this.getPosition();
				var sub = new Element('div' , {
					id : 'lemezek-sub',
					style : 'top:'+(pos.y+23)+'px;left:'+(pos.x-23)+'px;',
					html : '<a href="ujdonsagok">Új albumok</a><a href="lista">ABC Lista</a>'
				});
				sub.inject(document.body);
				$('lemezek-sub').addEvent('mouseleave',function(){
					var parent = $('menu-lemezek').getParent();
					parent.setStyle('background' , 'transparent');
					$('menu-lemezek').setStyle('color','#444');
					$('lemezek-sub').destroy();
					subD = false;
				});
				subD = true;
			}
		}
	});
	$$('a.menuLink').addEvents({
		mouseenter: function(){
			this.parentNode.setStyle('background' , 'transparent');
			$('menu-lemezek').setStyle('color','#444');
			try{
				$('lemezek-sub').destroy();
				subD = false;
			}catch(z){};
		}
	});
});

//FANCY TABLES
var fancy = {
	init : function() {
		try{
			var tables = $$('table.fancy');
			for(var i=0; i<tables.length; i++) {
				var rows = tables[i].getElements('tr');
				for(var r=0; r<rows.length; r++) {
					if(r==0){
						var ths = rows[r].getElements('th');
						ths[ths.length-1].className = "last";
					}
					if(r != 0) {
						if( r%2 == 0 ) {
							rows[r].className = rows[r].className + " even";
						} else { 
							rows[r].className = rows[r].className + " odd";
						}
					}
				}
			}
		}catch(z){};
	}
};
window.addEvent('domready',fancy.init);
window.addEvent('domready',function(){
	try{
		$('regPass2').addEvents({
			blur : function(){
				if($('regPass1').value != this.value){$('passCheck').innerHTML = "<span class='red'>A két jelszó nem egyezik!<\/span>";}
				if($('regPass1').value == this.value){$('passCheck').innerHTML = "<span class='black'>A két jelszó egyezik.<\/span>";}
			}
		});
		
		$('regPass1').addEvents({
			keyup : function(){
				var passwd = this.value;
				var intScore   = 0
				var strVerdict = "gyenge"
				var strLog     = ""
				
				if (passwd.length<5)                         // length 4 or less
				{
					intScore = (intScore+3)
				}
				else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
				{
					intScore = (intScore+6)
				}
				else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
				{
					intScore = (intScore+12)
				}
				else if (passwd.length>15)                    // length 16 or more
				{
					intScore = (intScore+18)
				}
				
				
				if (passwd.match(/[a-z]/))                              // [verified] at least one lower case letter
				{
					intScore = (intScore+1)
				}
				
				if (passwd.match(/[A-Z]/))                              // [verified] at least one upper case letter
				{
					intScore = (intScore+5)
				}
				
				if (passwd.match(/\d+/))                                 // [verified] at least one number
				{
					intScore = (intScore+5)
				}
				
				if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
				{
					intScore = (intScore+5)
				}
				
				
				if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
				{
					intScore = (intScore+5)
				}
				
				if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
				{
					intScore = (intScore+5)
				}
			
				
				if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
				{
					intScore = (intScore+2)
				}
	
				if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
				{
					intScore = (intScore+2)
				}
		 
				if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
				{
					intScore = (intScore+2)
				}
			
			
				if(intScore < 16)
				{strVerdict = "<span class='grey'>Nagyon gyenge<\/span>"}
				else if (intScore > 16 && intScore < 24){strVerdict = "<span class='black'>Gyenge<\/span>"}
				else if (intScore > 24 && intScore < 32){strVerdict = "<span class='blue'>Közepes<\/span>"}
				else if (intScore > 32 && intScore < 36){strVerdict = "<span class='red'>Erős<\/span>"}
				else{strVerdict = "<span class='green'>Nagyon erős"}
				
				$('passStr').innerHTML = strVerdict;
	
			}
		});
		
	}catch(z){};
});

function semmi(){};

/* LOGIN */

//var login = {
//	init : function(){
//		var wSize = window.getSize();
//		var xlogin = new Element('div',{
//			id : 'loginBox',
//			html : '<form method="post" action="'+home+'login" name="lForm" id="lForm">E-mail cím:<br /><input type="text" name="email" class="textfield validate[\'required\'] validate[\'email\']" /><div class="s5"><\/div>Jelszó:<br /><input type="password" name="password" class="textfield validate[\'required\']" /><div class="s5"><\/div><input type="submit" value="Belépés" class="submit" /><input type="button" onclick="login.close();" value="Mégse" class="cancel" />',
//			//style : 'top:'+((wSize.y/2)-100)+'px;left:'+((wSize.x/2)-200)+'px;'
//			style : 'top:100px;left:'+((wSize.x/2)-200)+'px;'
//		});
//		xlogin.setOpacity(0);
//		xlogin.inject(document.body)
//		new FormCheck('lForm');
//		var xx = new Fx.Tween($('loginBox'), {duration:300});
//		xx.start('opacity',0,1);
//	},
//	close : function(){
//		var xx = new Fx.Tween($('loginBox'), {duration:300});
//		xx.start('opacity',1,0).chain(function(){$('loginBox').destroy();});
//	}
//};
var login = {
		init : function(){
		var wSize = window.getSize();
		var xlogin = new Element('div',{
			id : 'loginBox',
			html : '<form method="post" action="'+home+'login" name="lForm" id="lForm">E-mail cím:<br /><input type="text" name="email" id="loginemail" class="textfield validate[\'required\'] validate[\'email\']" /><div class="s5"><\/div>Jelszó:<br /><input type="password" id="loginpass" name="password" class="textfield validate[\'required\']" /><div class="s5"><\/div></form><input type="button" onclick="login.exec();" value="Belépés" class="submit" /><input type="button" onclick="login.close();" value="Mégse" class="cancel" /><a href="jelszo">elfelejtett jelszó</a> | <a href="regisztracio">regisztráció</a>',
			//style : 'top:'+((wSize.y/2)-100)+'px;left:'+((wSize.x/2)-200)+'px;'
			style : 'top:100px;left:'+((wSize.x/2)-200)+'px;'
		});
		xlogin.setOpacity(0);
		xlogin.inject(document.body)
		new FormCheck('lForm');
		var xx = new Fx.Tween($('loginBox'), {duration:300});
		xx.start('opacity',0,1);
	},
	close : function(){
		var xx = new Fx.Tween($('loginBox'), {duration:300});
		xx.start('opacity',1,0).chain(function(){$('loginBox').destroy();});
	},
	exec : function(){
		var email = $('loginemail').value;
		var pass = $('loginpass').value;
		var Ajax = new Request({
			method: 'post', 
			data : {'email' : email , 'pass' : pass},
			url: home+'ajax/login',
			evalScripts : true
		}).send();
	}
};

function delFromBasket(id){
	var Ajax = new Request({
		method: 'post', 
		data : {'id' : id},
		url: home+'ajax/basket/remove',
		evalScripts : true,
		onComplete : function() {
			var fo = new Fx.Tween($('bItem'+id),{duration:300});
			var size = $('bItem'+id).getSize();
			fo.start('opacity' , 1 , 0).chain(function(){
				fo.start('height' , size.y , 0).chain(function(){
					$('bItem'+id).destroy();
					try{
						if($$('div.bsElement').length==0){
							var dd = new Fx.Tween($('basketDIV'), {duration:300});
							dd.start('opacity',1,0).chain(function(){
								$('basketDIV').style.display = "none";
							});
						}
					}catch(z){};
				});
			});
		}
	}).send();
};

function add2basket(id) {
	var Ajax = new Request({
		method: 'post', 
		data : {'id' : id},
		url: home+'ajax/basket/add',
		evalScripts : true,
		update : 'basketList'
	}).send();
};

function setType(c){
	var Ajax = new Request({
		method: 'post', 
		data : {'type' : c},
		url: home+'ajax/settype',
		evalScripts : true
	}).send();
};

/*dfs*/

window.addEvent('domready',function(){
	var fs = $('footer').getSize();
	var fp = $('footer').getPosition();
	new Element('a', {
		html : "<img src='images/dfs.png' alt='' />",
		href : "http://darkfire.hu",
		target : "_blank",
		title : "Honlapkészítés - Webáruház",
		id : "dfsLogo",
		style : "display:block;width:72px;height:27px;position:absolute;z-index:1000;top:"+((fp.y)+25)+"px;left:"+((fs.x)-87)+"px;"
	}).inject(document.body);
	$('dfsLogo').setOpacity(0.5);
	$('dfsLogo').addEvents({
		mouseenter : function(){this.fade(0.5,1);},
		mouseleave : function(){this.fade(1,0.5);}
	});
});
window.addEvent('resize',function(){
	var fs = $('footer').getSize();
	var fp = $('footer').getPosition();
	$('dfsLogo').setStyles({
		'top' : ((fp.y)+25)+"px",
		'left' : ((fs.x)-87)+"px"
	});
});
