function onOver(name,new_img) 
{
	filename = document.images[name].src;
	document.images[name].src = "/media/1/" + new_img;
}
		
function onOut(name,new_img) 
{
	filename = document.images[name].src;
	document.images[name].src = "/media/1/" + new_img;
}
function Over(hover_color)
{
	lmnt = window.event.srcElement;
	if (lmnt.tagName.toUpperCase() == 'TABLE')
	return;
	while (lmnt.tagName.toUpperCase() !='TD') 
	lmnt = lmnt.parentElement;
	lmnt.style.background = hover_color;
}

function Out(color)
{
	lmnt = window.event.srcElement;
	if (lmnt.tagName.toUpperCase() == 'TABLE')
	return;
	while (lmnt.tagName.toUpperCase() !='TD') 
	lmnt = lmnt.parentElement;
	lmnt.style.background =color;
}
//function addToBasket(item,id)
//{
//	newURL = '/?id='+id+'&action=addToBasket&itemNumber='+item;

//	if(document.getElementById(item))
//	{
//		itemSize = document.getElementById(item).options[document.getElementById(item).selectedIndex].text;
//		newURL = newURL+'&itemSize='+itemSize;
//	}
	
//	if(document.getElementById('color'+item))
//	{
//		itemColor = document.getElementById('color'+item).options[document.getElementById('color'+item).selectedIndex].text;
//		newURL = newURL+'&itemColor='+itemColor;
//	}
	
//	window.location=newURL;
//}

function addToBasket(itemId,item_number,id,item_note,stock_alert)
{
    newURL = '/?id='+id+'&action=addToBasket&itemId='+itemId+'&itemNumber='+item_number+(item_note != undefined ? "&item_note="+item_note : "");
    if (typeof stock_alert == "string") {
        alert(stock_alert);
    }
    if (document.getElementById('variant_id') != null) {
        if(document.getElementById('variant_id').value != "0")
        {
            //itemSize = document.getElementById('variant_id').options[document.getElementById('variant_id').selectedIndex].text;
            val = document.getElementById('variant_id').value;
            newURL = newURL+'&variantId='+val;
            window.location.href=newURL;
            return;
        }
        alert('V�lg venligst en variant.');
        return false;
    }
    window.location.href=newURL;
}

// var fields = new Array('name','familyName','address','zipcode','city','phone','mobile')
// <SPAN id="msgname">*</SPAN>
function submitForm(fields)
{
	var x
	var doSubmit = true
	var focusField

	for(x in fields)
	{
		if(document.getElementById) {
			ref = document.getElementById(fields[x])
		}
		if(ref){
			if(window.document.getElementById(fields[x]).value == "")
			{
				if(doSubmit == true)
				{
					focusField = fields[x];
				}
				
				doSubmit = false
				window.document.getElementById('msg'+fields[x]).style.color = "#FF0000";
			}else{
				window.document.getElementById('msg'+fields[x]).style.color = "#000000";
			}
		}
	}
	
	if(doSubmit)
	{
		document.form.submit();
	}else{
	
		alert('Udfyld venligst alle felter med *');
		window.scrollTo(0, 0);
		
		function focusL()
		{
                	document.getElementById(focusField).focus();
		}
		window.onReadyState=focusL();
	}
}
$(document).ready(function() {
        
        $(".product-item").mouseover(function (e) {
            $(this).find("span.product-item-variants").css('display', 'block');
            $(this).find("span.product-item-variants").css('opacity', 0.7);
        });

        $(".product-item").mouseout(function (e) {
            $(this).find("span.product-item-variants").css('display', 'none');
        });


        $("#adrtest").click(function() {
            
            payment_all_completed = true;

            $(".payment_address").each(function(i) {

                if($(this).val() != '' && payment_all_completed)
                {
                    payment_all_completed = true;
                    $(this).css('background-color', '#FFFFFF');
                }
                else
                {
                    payment_all_completed = false;
                    $(this).css('background-color', 'red');
                }
            });
            
            shipping_all_empty = true;
            shipping_all_completed = true;
            var mark_error=new Array();

            $(".shipping_address").each(function(i) {

                if($(this).val() != '' && shipping_all_empty)
                    shipping_all_empty = false;
                
                if($(this).val() != '' && shipping_all_completed)
                    shipping_all_completed = true;
                else
                {
                    shipping_all_completed = false;
                    mark_error[i]=$(this).attr('id');
                }
            });

            // alert(mark_error);
            
                $.each(mark_error, function(key, value) { 
                    $("#"+value).css('background-color', 'red');
                        // alert(key + ': ' + value); 
                });
            
            if((shipping_all_empty || shipping_all_completed) && payment_all_completed)
                alert('ok');
            else
            {
                alert('Udfyld venligst alle felter med rød.');
            }


        });
    
	// Jquery Validate
	$("form[name='form']").validate({
		rules: {
			customer_email: {
				required: true,
				email: true
			},
			customer_condition: "required",
			customer_name: "required",
			customer_address: "required",
			customer_zip: "required",
			customer_city: "required",
			customer_phone: "required"
		},
		messages: {
			customer_email: "<br/>Indtast en gyldig e-mail-adresse",
			customer_condition: "Accepter venligst handelsbetingelserne",
			customer_name: "Påkrævet",
			customer_name: "Påkrævet",
			customer_address: "Påkrævet",
			customer_zip: "Påkrævet",
			customer_city: "Påkrævet",
			customer_phone: "Påkrævet"
		}
	});
	
$(".shipping_address").blur(function(){
	$(".shipping_address").each(function() {
		if( $(this).val().length === 0 ) {
			if($(this).hasClass("required")) { // if no input but have required class
				
			}
			else { // if blank but has required class then remove it
				
			}
		}
		else { // if one has input then add required to all
			$(".shipping_address").not($(this)).addClass("required");
		}

		if($(".shipping_address[value!='']").length === 0 ){
			
				$(this).removeClass("required");
	
		} 
	});		
});


$("form[name='form']").submit(function(){

	if($(".shipping_address[value!='']").length === 0 ){
		$(".shipping_address").each(function() {
			$(this).removeClass("required");
		});	
	} 
	
});	


	
});
