jQuery.noConflict();


jQuery(document).ready(function(){


	Dolj_ArtikelInfo();

	if (jQuery("#JL_varum").val() != '')
	{
		Hamta_Artiklar();
	}

	jQuery("#JL_varum").change(function(){
	
		Hamta_Artiklar();
		
	});
	
	jQuery("a[href='/cgi-bin/ibutik/AIR_ibutik.pl?funk=steg_tva&artgrp=108']").each(function(){
		var html = '<br><a href="/cgi-bin/ibutik/AIR_ibutik.pl?funk=justlamps&artgrp=102">';
		html += '<img vspace="0" hspace="0" border="0" align="absmiddle" src="/bilder/ibutik-a/_pil_liten_1.gif">';
		html += 'Projektorlampor';
		html += '</a>';

		jQuery(this).after(html);
	
	})
	
	jQuery(".VarukorgAndra a[href*='/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artnr=L_']").click(function(){
	
		var html = jQuery(this).html();
		html = jQuery.trim(html);
		if ((html.substr(0,5) == "Lampa") || (html.substr(0,7) == "Diamond"))
		{
		
			window.location.href = "/cgi-bin/ibutik/AIR_ibutik.pl?funk=justlamps";
			return false;
		
		}
		
	})
	
	jQuery(".VarukorgAndra a[href*='/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artnr=L_']").click(function(){
	
		var html = jQuery(this).html();
		html = jQuery.trim(html);
		if ((html.substr(0,5) == "Lampa") || (html.substr(0,7) == "Diamond"))
		{
		
			window.location.href = "/cgi-bin/ibutik/AIR_ibutik.pl?funk=justlamps";
			return false;
		
		}
		
	})
	
	jQuery(".Snabbkassa_Varukorg a[href*='/cgi-bin/ibutik/AIR_ibutik.pl?funk=visa_artikel&artnr=L_']").click(function(){
	
		var html = jQuery(this).html();
		html = html.replace("st.","");
		html = jQuery.trim(html);
//		alert(html);
		if ((html.substr(0,5) == "Lampa") || (html.substr(0,7) == "Diamond"))
		{
		
			window.location.href = "/cgi-bin/ibutik/AIR_ibutik.pl?funk=justlamps";
			return false;
		
		}
		
	})
	


})


Hamta_Artiklar = function(){

	Dolj_ArtikelInfo();

	if (jQuery("#JL_varum").val() != '')
	{

		var url = "/cgi-bin/ibutik/API.pl?funk=artiklar_varumarke&retur=xml&Artgrp=124&Varum=" + jQuery("#JL_varum").val();
		jQuery.get(url, function(xml){
			var html = '<option value="">Välj modell</option>';
			jQuery(xml).find("artikel").each(function(){
				
				var a = new Artikel();
				a.Artnr = jQuery("Artnr",this).text();
				a.Beskr = jQuery("Beskr",this).text();
				a.Saldo = jQuery("Saldo",this).text();
				a.Pris = jQuery("Pris",this).text();
				a.Egenskap4_SV = jQuery("Egenskap4_SV",this).text();
				a.Egenskap4_SV = jQuery.trim(a.Egenskap4_SV);
				if (a.Egenskap4_SV == "Lampa")
				{
					a.Egenskap4_SV = "Orginallampa";	
				}
				a.Egenskap5_SV = jQuery("Egenskap5_SV",this).text();
				html = html + '<option value="' + a.Artnr + '">' + a.Egenskap5_SV + ' (' + a.Egenskap4_SV + ')</option>';	
				
				
			});
			jQuery("#JL_Lampor").html(html);
			jQuery("#JL_Lampor").change(function(){
				
					Hamta_ArtikelInfo();
				
			})
		});
	}
	else
	{
		var html = '<option value="">Välj modell</option>';
		jQuery("#JL_Lampor").html(html);
	}
	
}

Hamta_ArtikelInfo = function(){
	Dolj_ArtikelInfo();
	
	if (jQuery("#JL_Lampor").val() != '')
	{
		var url = "/cgi-bin/ibutik/API.pl?funk=artikelinfo&retur=xml&Artnr=" + jQuery("#JL_Lampor").val();
		jQuery.get(url, function(xml){
			var a = new Artikel();
			jQuery(xml).find("artikel").each(function(){
				
				
				a.Artnr = jQuery("Artnr",this).text();
				a.Beskr = jQuery("Beskr",this).text();
				a.Beskr = jQuery.trim(a.Beskr);
				if (a.Beskr.substr(0,5) == "Lampa")
				{
					a.Beskr = "Orginallampa "+a.Beskr.substr(6,(a.Beskr.length -1));
				}
				a.Saldo = jQuery("Saldo",this).text();
				a.Saldo = jQuery("Saldo",this).text();
				a.Egenskap6_SV = jQuery("Egenskap6_SV",this).text();
				a.Egenskap7_SV = jQuery("Egenskap7_SV",this).text();
				a.Pris = jQuery("Pris",this).text();
				
			});
			
			
			if (a.Artnr != '')
			{
				Visa_ArtikelInfo(a);	
			}
			
		});
	}
	else
	{
		Dolj_ArtikelInfo();
	}
}


Visa_ArtikelInfo = function(a)
{

	jQuery("#Artikel").show();
	jQuery("#Artikel_Beskr").show();
	jQuery("#Artikel_Artnr").html("<strong>Artikelnr:</strong> " + a.Artnr);
	jQuery("#Artikel_Beskr").html(a.Beskr);
	var lagerstatus = "Beställningsvara";
	if (a.Saldo > 0)
	{
		lagerstatus = "Leverantörens lager";
	}
	jQuery("#Artikel_Saldo").html("<strong>Lagerstatus:</strong> " + lagerstatus);
	jQuery("#Artikel_Pris").html('<span class="PrisBOLD"><strong>Pris:</strong> ' +a.Pris + '</span>');		
	jQuery("#altnr").val(a.Artnr);
	jQuery("#Artikel_Info").html("<strong>Watt:</strong> " + a.Egenskap6_SV +"<br><strong>Lamptid:</strong> " + a.Egenskap7_SV +"<br>");
}

Dolj_ArtikelInfo = function()
{

	jQuery("#Artikel").hide();
	jQuery("#Artikel_Artnr").html("");
	jQuery("#Artikel_Beskr").hide();
}


Artikel = function()
{

	Artnr	 		= '';
	Beskr 			= '';
	Saldo 			= '';
	Pris 			= '';
	Egenskap4_SV		= '';
	Egenskap5_SV		= '';
	Egenskap6_SV		= '';
	Egenskap7_SV		= '';	
}
