/*
 * 
function send()
{document.theform.submit()}
 */

$(document).ready(function(){
	  
	//$("#registerFormNoAccount").validate();
	
	$("#registerFormNoAccount").validate({
		rules: {
			user_password: {
				required: true,
				minlength: 6
			},
			user_password2: {
				equalTo: "#cuser_password"
			},
			user_company: {
				required: function() {
				return $("#cvat:checked").length == 1;
				}
			},
			user_nip:{
				required: function(element) {
				return $("#cvat:checked").length == 1;
				},
				minlength: 10
			}
		}
	});
	
	$("#registerFormFastOrder").validate({
		
		rules:{
			user_company: {
				required: function() {
				return $("#cvat2:checked").length == 1;
				}
			},
			user_nip:{
				required: function(element) {
				return $("#cvat2:checked").length == 1;
				},
				minlength: 10
			}
		}
	});
	
	$("#myAccount").validate({
		
		rules:{
			user_company: {
				required: function() {
				return $("#cvat:checked").length == 1;
				}
			},
			user_nip:{
				required: function(element) {
				return $("#cvat:checked").length == 1;
				},
				minlength: 10
			}
		}
	});
	
	$('#cvat2').click(function(){
		
		var display = $('#vat2').css("display");
		$('#vat2').toggle();
		
	});

	$('#cvat').click(function(){
		
		//var display = $('#vat').css("display");
		$('#vat').toggle();
		
	});

	$('#cpayWay').change(function(){
		
		var value = $('#cpayWay').val();
		//alert (value);
		if(value=='przelew'){
			$('#accountInfo').show();
		}else{
			$('#accountInfo').hide();	
		}
	});
	
	$('.setOrderButton').click(function(){

		var dest = $(this).attr("dest");
		//var noWay = dest.substr(3,1);
		
		//var display = $('#way' + noWay).css("display");
		
		//alert(dest);
		
		$('#way1').hide();
		$('#way2').hide();
		$('#way3').hide();
		
		$('#' + dest).toggle();
		
	});
	

	
	
	$('.changeViewButton').click(function(){
		
		var currentstyle;
		var arr;
		var imgfile;
		var urlstyle; 
		
		currentstyle = $("#changeView").attr("href");
		arr = currentstyle.split("/");
		
		//nazwa pliku
		currentstyle = arr[arr.length-1];
		arr = currentstyle.split(".");
		currentstyle = arr[arr.length-2];
		
		if(currentstyle == 'list'){
			currentstyle = 'mozaic';
		}else{
			currentstyle = 'list';
		}
		
		urlstyle = burl + "style/style.prod." + currentstyle + ".css"
		imgfile = burl + "img_page/changeview." + currentstyle + ".gif";
		
		//$(".changeViewButton").fadeOut("fast");
    	$("#productsMark").fadeOut("fast");
    	
		$(".changeViewButton").css('background-image', 'url(' + imgfile + ')');
    	$("#changeView").attr("href", urlstyle);
    	
		//$(".changeViewButton").fadeIn("fast");
    	$("#productsMark").fadeIn("fast");
    	
    	$('#hidden').load(burl + 'ajax.changeview.php?currentstyle=' + currentstyle);
    	
		return false;
		
	});
	
});




function addInputSubmitEvent(form, input) {
    input.onkeydown = function(e) {
        e = e || window.event;
        if (e.keyCode == 13) {
            form.submit();
            return false;
        }
    };
}

window.onload = function() {
    var forms = document.getElementsByTagName('form');

    for (var i=0;i < forms.length;i++) {
        var inputs = forms[i].getElementsByTagName('input');

        for (var j=0;j < inputs.length;j++)
            addInputSubmitEvent(forms[i], inputs[j]);
    }
};


function toggle(id){
	
	var myDiv=document.getElementById(id);
	
	if(myDiv.style.visibility=='visible'||myDiv.style.visibility==''){
	
		myDiv.style.visibility='hidden';
		myDiv.style.display='none';
		
	}else{
		
		myDiv.style.visibility='visible';
		myDiv.style.display='block';
		
	}
	
}


function toggleAdd(show,hide){

	var divShow = document.getElementById(show);
	var divHide = document.getElementById(hide);
	
	divHide.style.visibility='hidden';
	divHide.style.display='none';
	identity=document.getElementById('li' + hide);
	identity.className='noactive';
	
	divShow.style.visibility='visible';
	divShow.style.display='block';
	identity=document.getElementById('li' + show);
	identity.className='active';
	
}

function closeD(id){
	document.getElementById(id).style.visibility='hidden';
	if(setT){clearTimeout(setT)}
}


function showPic(id){

	var myDiv=document.getElementById('toShowPic');
	
	myDiv.style.visibility='visible';
	myDiv.style.display='block';
	myDiv.style.border='1px solid gray';
	myDiv.style.margin='5px';
	
	document.images["toShowPic"].src = 'http://www.4na4.pl/img_prod/' + id;

	//alert(document.images["toShowPic"].src);
	
}

function hidePic(){

	var myDiv=document.getElementById('toShowPic');
	myDiv.style.visibility='hidden';
	myDiv.style.display='none';
	
}

