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 addColliToBasket(item_id,id)
{
        newURL = '/?id='+id+'&action=addKolliToBasket&itemId='+item_id;
	window.location=newURL;
}
/*
function addToBasket(itemId,item_number,id,item_note,warning,item_amount,item_price)
{
    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;
}
*/
function addToBasket(itemId,item_number,id,item_note,warning,item_amount,item_price)
{
    // opdateret 11-11-2011, mmn: item_note, item_amount og item_price

    if (warning != undefined)
        alert(warning);

    if (item_note != undefined)
        newURL = '/?id='+id+'&action=addToBasket&itemId='+itemId+'&itemNumber='+item_number+"&item_note="+item_note;
    else
        newURL = '/?id='+id+'&action=addToBasket&itemId='+itemId+'&itemNumber='+item_number;

    if (document.getElementById('variant_id') != null) {
        if(document.getElementById('variant_id').value != "0")
        {
            val = document.getElementById('variant_id').value;
            newURL = newURL+'&variantId='+val;
        }
        else
        {
            alert('Vælg venligst en variant.');
            return false;
        }
    }

    // Tilføjer kommentar til item_note i `webshop_basket_items`
    if (document.getElementById('product_comment_'+itemId) != null) {
        if(document.getElementById('product_comment_'+itemId).value != "")
        {
            val = document.getElementById('product_comment_'+itemId).value;

            newURL = newURL+'&item_note='+val;
        }
    }

    if(item_amount >= 1)
    {
        newURL = newURL+'&item_amount='+item_amount;
    }

    if(item_price != undefined)
    {
        newURL = newURL+'&item_price='+item_price;
    }

    window.location.href=newURL;
    return;
}

function changeColorSize(item_id,item_number,id,type)
{
	newURL = '/?id='+id+'&recordid='+item_id;

	if(type == 'size')
	{
		if(document.getElementById('size_'+item_number))
		{
			itemSize = document.getElementById('size_'+item_number).options[document.getElementById('size_'+item_number).selectedIndex].value;
				newURL = newURL+'&itemSize='+itemSize;
		}
	
		if(document.getElementById('color_'+item_number))
		{
			itemColor = document.getElementById('color_'+item_number).options[document.getElementById('color_'+item_number).selectedIndex].value;
				newURL = newURL+'&itemColor='+itemColor;
		}
	}
	else
	{
		if(document.getElementById('color_'+item_number))
		{
			itemColor = document.getElementById('color_'+item_number).options[document.getElementById('color_'+item_number).selectedIndex].value;
				newURL = newURL+'&itemColor='+itemColor;
		}
		
		if(document.getElementById('size_'+item_number))
		{
			itemSize = document.getElementById('size_'+item_number).options[document.getElementById('size_'+item_number).selectedIndex].value;
				newURL = newURL+'&itemSize='+itemSize;
		}
	}
	
	window.location=newURL;
}


// var fields = new Array('name','familyName','address','zipcode','city','phone','mobile')
// <SPAN id="msgname">*</SPAN>
function oldsubmitForm(fields)
{
	var x
	var doSubmit = true
	var focusField
	
	if(document.getElementById) {
		ref = document.getElementById('customer_lastname');
	}
	if(ref) {
		alert('findes')
	}
	else
		alert('findes ikke');

	for(x in fields)
	{
		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)
	{
		alert('submit');
		// document.form.submit();
	}else{
	
		alert('Udfyld venligst alle felter med *');
		window.scrollTo(0, 0);
		
		function focusL()
		{
                	document.getElementById(focusField).focus();
		}
		window.onReadyState=focusL();
	}
}

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(){
	$(function() {
		$('input.product_comment').inputlimiter({
		limit: 12,
		remText: '',
		remFullText: '',
		limitText: ''});
	});
});
