function showSubMenu(submenuID) {
	hideAll();
	document.getElementById(submenuID).style.visibility = "visible";
	document.getElementById(submenuID).style.display = "block";
}

function hideAll() {
	var sel = document.getElementById('prodcategory').getElementsByTagName('div');
	for (var i=0; i<sel.length; i++) { sel[i].style.display = 'none'; }
}

function checkAmount(AmountNeeded,AmountMinimal) {
	if(AmountNeeded.value % AmountMinimal != 0)
	{	
		alert("Hibás mennyiséget adott meg! A megrendelt mennyiségnek a minimális rendelési mennyiségnek ("+AmountMinimal+"), vagy annak többszörösének kell lennie.");
		AmountNeeded.value = 0;
		return false;
	} else {
		return false;
	}
}

function showCompany($Value) {
	if($Value == 0) {
		document.getElementById('companydata').style.visibility = 'hidden';
		document.getElementById('companydata').style.display = 'none';
	} else {
		document.getElementById('companydata').style.visibility = 'visible';
		document.getElementById('companydata').style.display = 'block';
	}
}

function showBilling($Checked) {
	if($Checked) {
		document.getElementById('billingdata').style.visibility = 'hidden';
		document.getElementById('billingdata').style.display = 'none';
	} else {
		document.getElementById('billingdata').style.visibility = 'visible';
		document.getElementById('billingdata').style.display = 'block';
	}
}

function showShopRegistration($Checked) {
	if(!$Checked) {
		document.getElementById('shopregistration').style.visibility = 'hidden';
		document.getElementById('shopregistration').style.display = 'none';
	} else {
		document.getElementById('shopregistration').style.visibility = 'visible';
		document.getElementById('shopregistration').style.display = 'block';
	}
}

function ajax_do (url) {
	// Does URL begin with http?
	if (url.substring(0, 4) != 'http') {
					url = base_url + url;
	}

	// Create new JS element
	var jsel = document.createElement('SCRIPT');
	jsel.type = 'text/javascript';
	jsel.src = url;

	// Append JS element (therefore executing the 'AJAX' call)
	document.body.appendChild (jsel);
}

function testPassword(Element,Weak,Medium,Good,Default)
{
		var intScore   = 0;
		var strVerdict = "";
		var ecolor = "";
		
		var passwd = Element.value;
		
		if (passwd.length>=5)                         // length 4 or less
		{			
			if (passwd.length>4 && passwd.length<8) intScore = (intScore+6)
			else if (passwd.length>7 && passwd.length<16) intScore = (intScore+12)
					 else if (passwd.length>15) intScore = (intScore+18)

			if (passwd.match(/[a-z]/)) intScore = (intScore+1)
			if (passwd.match(/[A-Z]/)) intScore = (intScore+5)
			if (passwd.match(/\d+/)) intScore = (intScore+5)
			if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) intScore = (intScore+5)
			if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) intScore = (intScore+5)
			if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) intScore = (intScore+5)
			if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) intScore = (intScore+2)
			if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) intScore = (intScore+2)
			if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) intScore = (intScore+2)
		
			if(intScore < 16)
			{
				ecolor = "#ffc1c1";
				color = "#f00";
				strVerdict = Weak
			}
			else if (intScore > 15 && intScore < 25)
			{
				ecolor = "#ffe5ae";				
				color = "#ff7e00";				
				strVerdict = Medium
			}
			else if (intScore > 24 && intScore < 35)
			{
				ecolor = "#ffe5ae";				
				color = "#ff7e00";				
				strVerdict = Medium
			}
			else if (intScore > 34 && intScore < 45)
			{
				ecolor = "#c2ffc1";				
				color = "#00953c";				
				strVerdict = Good
			}
			else
			{
				ecolor = "#c2ffc1";				
				color = "#00953c";				
				strVerdict = Good
			}
	}
	else
	{
		color = "#000";				
		strVerdict = Default;
	}
	Element.style.backgroundImage = 'none';
	Element.style.backgroundColor = ecolor;
	document.getElementById('pwVerdict').innerHTML = '<span style="color:' + color + '">' + strVerdict + '</span>';
}

function verifyPasswords()
{
	var pone = document.getElementById('passwordone');
	var ptwo = document.getElementById('passwordtwo');

	document.getElementById('pwIconOne').style.visibility = 'hidden';
	document.getElementById('pwIconTwo').style.visibility = 'hidden';
	document.getElementById('pwVerdict').style.visibility = 'visible';
	
	if(pone.value != '' && ptwo.value != '')
	{
		if(pone.value == ptwo.value)
		{
			document.getElementById('pwIconOne').style.visibility = 'visible';
			document.getElementById('pwIconTwo').style.visibility = 'visible';
			document.getElementById('pwVerdict').style.visibility = 'hidden';
		}
	}
}

function loadCatalogue(CatalogueCode)
{
		document.getElementById('CatalogueViewer').innerHTML = '<object style="width:780px;height:653px" >'
		+ '<param name="movie" value="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf?mode=embed&amp;layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Fdark%2Flayout.xml&amp;showFlipBtn=true&amp;' + CatalogueCode + '" />'
		+ '<param name="allowfullscreen" value="true"/>'
		+ '<param name="menu" value="false"/>'
		+ '<embed src="http://static.issuu.com/webembed/viewers/style1/v1/IssuuViewer.swf" type="application/x-shockwave-flash" allowfullscreen="true" menu="false" style="width:780px;height:653px" flashvars="mode=embed&amp;layout=http%3A%2F%2Fskin.issuu.com%2Fv%2Fdark%2Flayout.xml&amp;showFlipBtn=true&amp;' + CatalogueCode + '" />'
		+ '</object>';
}

function loadVideo(YouTubeID) {
	document.getElementById('VideoPlayerFrame').src = 'http://www.youtube.com/embed/' + YouTubeID + '?rel=0&amp;hd=1&amp;autoplay=1';
}

function cartSubmit(SubmitMode) {
	if(SubmitMode == 1) {
		document.getElementById('carttarget').value = 'cart';
	} else {
		document.getElementById('carttarget').value = 'request';
	}
	document.addtocartform.submit();
}

function showLogoPanel(ProductID) {
		document.getElementById('addlogo_' + ProductID).style.visibility = 'visible';
		document.getElementById('addlogo_' + ProductID).style.display = 'block';
}

(function($){
/*----------------------------------------------------------------------------------
Class: FloatObject
-------------------------------------------------------------------------------------*/
	function FloatObject(jqObj, params)
	{
		this.jqObj = jqObj;
		
		switch(params.speed)
		{
			case 'fast': this.steps = 5; break;
			case 'normal': this.steps = 10; break;
			case 'slow': this.steps = 20; break;
			default: this.steps = 10;
		};
		
		var offset = this.jqObj.offset();
		
		this.currentX = offset.left;
		this.currentY = offset.top;
		
		
		this.origX = typeof(params.x) == "string" ?  this.currentX : params.x;
		this.origY = typeof(params.y) == "string" ?  this.currentY : params.y;
		//if( params.y) this.origY = params.y;
		
		
		//now we make sure the object is in absolute positions.
		this.jqObj.css({'position':'absolute' , 'top':this.currentY ,'left':this.currentX});
	}
	
	FloatObject.prototype.updateLocation = function()
	{
		this.updatedX = $(window).scrollLeft() + this.origX;
		this.updatedY = $(window).scrollTop()+ this.origY;
		
		this.dx = Math.abs(this.updatedX - this.currentX );
		this.dy = Math.abs(this.updatedY - this.currentY );
		
		return this.dx || this.dy;
	}
	
	FloatObject.prototype.move = function()
	{
		if( this.jqObj.css("position") != "absolute" ) return;
		var cx = 0;
		var cy = 0;
		
		if( this.dx > 0 )
		{			
			if( this.dx < this.steps / 2 )
				cx = (this.dx >= 1) ? 1 : 0;
			else
				cx = Math.round(this.dx/this.steps);
			
			if( this.currentX < this.updatedX )
				this.currentX += cx;
			else
				this.currentX -= cx;
		}
		
		
		if( this.dy > 0 )
		{
			if( this.dy < this.steps / 2 )
				cy = (this.dy >= 1) ? 1 : 0;
			else
				cy = Math.round(this.dy/this.steps);
			
			if( this.currentY < this.updatedY )
				this.currentY += cy;
			else
				this.currentY -= cy;
		}
		
		this.jqObj.css({'left':this.currentX, 'top': this.currentY });			
	}

	
	
/*----------------------------------------------------------------------------------
Object: floatMgr
-------------------------------------------------------------------------------------*/		
	$.floatMgr = {
		
		FOArray: new Array() ,
		
		timer: null ,
		
		initializeFO: function(jqObj,params) 
		{
			var settings =  $.extend({
				x: 0 ,
				y: 0 ,
				speed: 'normal'	},params||{});
			var newFO = new FloatObject(jqObj,settings);
			
			$.floatMgr.FOArray.push(newFO);
			
			if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
			
			//now making sure we are registered to all required window events
			if( !$.floatMgr.registeredEvents ) 
			{
					$(window).bind("resize", $.floatMgr.onChange);
					$(window).bind("scroll", $.floatMgr.onChange);
					$.floatMgr.registeredEvents = true;
			}		
		} , 
		
		adjustFO: function() 
		{
			$.floatMgr.timer = null;
			
			var moveFO = false;
			
			for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
			{
				 FO = $.floatMgr.FOArray[i];
				 if( FO.updateLocation() )  moveFO = true;
			}
			
			if( moveFO )
			{
				for( var i = 0 ; i < $.floatMgr.FOArray.length ; i++ )
				{
					FO = $.floatMgr.FOArray[i];
					FO.move();
				}
				
				if( !$.floatMgr.timer ) $.floatMgr.timer = setTimeout($.floatMgr.adjustFO,50);
			}
		}	,
		
		onChange: function()
		{
			if( !$.floatMgr.timer ) $.floatMgr.adjustFO();
		}
	};
	
/*----------------------------------------------------------------------------------
Function: makeFloat
-------------------------------------------------------------------------------------*/		
	$.fn.makeFloat = function(params) {
		var obj = this.eq(0); //we only operate on the first selected object;
		$.floatMgr.initializeFO(obj,params); 
		if( $.floatMgr.timer == null ) $.floatMgr.adjustFO();
		return obj;
	};
})(jQuery);
