$(document).ready(function(){
	$("a[rel^='prettyPhoto']").prettyPhoto({
		animationSpeed: 'fast',
		showTitle: false,
		allowresize: false
	});
	
	$(".prod_qty").keypress(function (e)
	{
		if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57))
		{
			return false;
		}
	});
	
	$("#search_btn").click(function(){
		
		prodName = '';
		prodCode = '';
		
		if ( $("#prod_name").val() != "" && $("#prod_name").val() != "Product name..." )
		{
			
			prodName = "&pname=" + $("#prod_name").val();
			
		}
		
		if ( $("#prod_code").val() != "" && $("#prod_code").val() != "Product code..." )
		{
			
			prodCode = "&pcode=" + $("#prod_code").val();
			
		}
		
		window.location.href = '?mod=shop&search=init' + prodName + prodCode;
	});
	
	$("#sort").change(function(){
		if ($("#sort").val())
		{
		
			window.location.href = '?mod=shop&cat=' + $(this).attr("name") + '&order=' + $("#sort").val();
			
		}
	});
	
});

function adImage($type)
{
	
	$(".loader").css("display", "block");
	
	var imagesAds = "1.jpg|2.jpg|3.jpg";
	
	var imageCurrent = $("#top").css("background-image");
	imageCurrent = imageCurrent.replace(")", "").split("topimg/");
	imageCurrent = imageCurrent[1];
	imageCurrent = imageCurrent.replace('"', "");
	
	imagesAds = imagesAds.split("|");
	
	for (i=0; i<=imagesAds.length-1; i++)
	{

		if ( imagesAds[i] ==  imageCurrent)
		{
			
			if ( $type == "next" )
			{
				
				setImage = imagesAds[i+1];
				
			}
			else
			{
			
				setImage = imagesAds[i-1];	
				
			}
			
			if ( setImage == undefined && $type == "next" )
			{
			
				setImage = imagesAds[0];
				
			}
			else if ( setImage == undefined && $type == "prev" )
			{
				
				setImage = imagesAds[imagesAds.length-1];
				
			}
		
		}
		
		
	}
	
	$(".loader").css("display", "block");
    var img = new Image();
    $(img).load(function () {
		$("#top").css("background-image", "url('images/topimg/"+ setImage +"')").fadeIn();
		$(".loader").css("display", "none");
    }).attr('src', 'images/topimg/'+ setImage);
	
}

function sendForm(id)
{

	if ( document.getElementById("name").value.length < 2 )
	{

	    alert("Error: All fields required!");
	    return false;

	}

	if ( document.getElementById("email").value.length < 8 )
	{

	    alert("Error: Invalid E-mail address!");
	    return false;

	}

	if ( document.getElementById("text").value.length < 10 )
	{

	    alert("Error: Message too short!");
	    return false;

	}

	input = document.createElement("input");
	input.type = "hidden";
	input.value = id;
	input.name = "message_send";
	document.getElementById(id).appendChild(input);

	document.getElementById(id).submit();

}

function basket_send()
{

	if ( document.getElementById("order_name").value.length < 5 )
	{
		
	    alert("Invalid Name!");
	    return false;
		
	}
	
	if ( document.getElementById("order_adress").value.length < 9 )
	{
		
	    alert("Address required!");
	    return false;
		
	}
	
	if ( document.getElementById("order_email").value.length < 8 )
	{
		
	    alert("Invalid E-mail address!");
	    return false;
		
	}
	
	if ( document.getElementById("order_phone").value.length < 7 )
	{
		
	    alert("Invalid Phone number!");
	    return false;
		
	}

	document.getElementById("basketsend").submit();
	
}