// JavaScript Document by George Hedfors

function buyOne(prodID) {
	// Get parent
	mypara = document.getElementById("content")

	// Create form
	myform = document.createElement("form")
	myform.action = document.location
	myform.method = "POST"

	// Create input parameters: product_id, Qty and ADD_TO_CART
	id = document.createElement("input")
	id.type = "hidden"
	id.name = "ID"
	id.value = prodID

	qty = document.createElement("input")
	qty.type = "hidden"
	qty.name = "Qty"
	qty.value = "1"

	addtocart = document.createElement("input")
	addtocart.type = "hidden"
	addtocart.name = "ADD_TO_CART"
	addtocart.value = "Lägg i vagnen"

	// Append parameters to form
	myform.appendChild(addtocart)
	myform.appendChild(id)
	myform.appendChild(qty)

	// Append form to parent
	mypara.appendChild(myform)

	// Submit form
	myform.submit()
}

function hideElement(name) {
	myElement = document.getElementById(name)
	myElement.style.display = "none"
}

function supportPanel() {
	document.getElementById("productMenu").style.backgroundColor = "#FFF"
	document.getElementById("productMenu").style.paddingBottom = "7px"

	myEl = document.getElementById("productMenu")
	myEl.innerHTML = "<h3>Support</h3>"
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="kundtjanst.html">Garantier från tillverkaren och Servicepartner</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="support_info.html">Död-Pixel-Garanti för platta skärmar</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="support_info.html">Felsökning</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="support_info.html">Klockan i XP slutar synka</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="http://www.pyrotech.se/TeamViewerQS.exe">TeamView Supportverktyg</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p><a href="http://support.f-secure.se/swe/home/ols.shtml"><img src="/INC/images/fsecure-scan.png"></a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p><a href="http://www.pandasecurity.com/homeusers/solutions/activescan/"><img src="/INC/images/panda-scan.png"></a></p>'
}

function kopinfoPanel() {
	document.getElementById("productMenu").style.backgroundColor = "#FFF"
	document.getElementById("productMenu").style.paddingBottom = "7px"

	myEl = document.getElementById("productMenu")
	myEl.innerHTML = "<h3>Köpinfo</h3>"
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><b>Företag:</b></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text">Mot faktura<br>Mot postförskott<br>Hyra & leasing<br>tex. via WASA kredit<br>Kontant i butiken</p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><b>Privatpersoner:</b></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text">Kontant i butiken<br>Mot postförskott<br>Avbetalning <i>Resurs Finans</i></p>'
	myEl.innerHTML = myEl.innerHTML + '<p><a href="http://www.resurs.se"><img src="/INC/images/resursbank.png"></a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p><a href="http://www.wasakredit.se "><img src="/INC/images/wasakredit.png"></a></p>'
}

function servicePanel() {
	document.getElementById("productMenu").style.backgroundColor = "#FFF"
	document.getElementById("productMenu").style.paddingBottom = "7px"

	myEl = document.getElementById("productMenu")
	myEl.innerHTML = "<h3>Tjänster</h3>"
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Felsökning</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Installation</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Lödning / rengöring</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Montering</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Ominstallation</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Datorräddning</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Virusräddning</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Konsultation</a></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><a href="/services-details.html#1">Uppgradering</a></p>'
}

function kontaktPanel() {
	document.getElementById("productMenu").style.backgroundColor = "#FFF"
	document.getElementById("productMenu").style.paddingBottom = "7px"

	myEl = document.getElementById("productMenu")
	myEl.innerHTML = "<h3>Kontakt</h3>"
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><b>Pyrotech</b></p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text"><b>Stila Data Design AB</b><br>Jägerhorns Väg 1<br>141 75 Huddinge<br>Tel. 08-741 35 90</p>'
	myEl.innerHTML = myEl.innerHTML + '<p id="text">Org.nr 556754-6899</p>'
}

function myEmail(dst) {
	document.write("<a href=\"mailto:")
	document.write(dst)
	document.write("@")
	document.write("pyrotech")
	document.write(".")
	document.write("se")
	document.write("\">")
	document.write(dst)
	document.write("@")
	document.write("pyrotech")
	document.write(".")
	document.write("se")
	document.write("</a>")
}

function num2money(n_value) {
	
	if (isNaN(Number(n_value)))
		return 'ERROR';
	
	var b_negative = Boolean(n_value < 0);
	n_value = Math.abs(n_value);
	
	var s_result = String(Math.round(n_value*1e2)%1e2 + '00').substring(0,2);
	
	var b_first = true;
	var s_subresult;

	while (n_value > 1) {
		s_subresult = (n_value >= 1e3 ? '00' : '') + Math.floor(n_value%1e3);
		s_result = s_subresult.slice(-3) + (b_first ? ',' : ' ') + s_result;
		b_first = false;
		n_value = n_value/1e3;
	}

	if (b_first)
		s_result = '0,' + s_result;
	return b_negative
	
	? '($' + s_result + ')'
	: s_result + " kr";
}

function buyConfig() {
	var parent = document.getElementById("content")
	var shop = document.createElement("form")
	
	shop.action = "/cart.html"
	shop.method = "post"

	addtocart = document.createElement("input")
	addtocart.type = "hidden"
	addtocart.name = "ADD_TO_CART"
	addtocart.value = "Lägg i vagnen"

	var pkta = document.createElement("input")
	pkta.type = "hidden"
	pkta.name = "ID"
	pkta.value = document.configomatic.datorpaket.value
	var pktb = document.createElement("input")
	pktb.type = "hidden"
	pktb.name = "Qty"
	pktb.value = "1"

	var a0a = document.createElement("input")
	a0a.type = "hidden"
	a0a.name = "ID"
	a0a.value = document.configomatic.a0.value
	var a0b = document.createElement("input")
	a0b.type = "hidden"
	a0b.name = "Qty"
	a0b.value = "1"

	var a1a = document.createElement("input")
	a1a.type = "hidden"
	a1a.name = "ID"
	a1a.value = document.configomatic.a1.value
	var a1b = document.createElement("input")
	a1b.type = "hidden"
	a1b.name = "Qty"
	a1b.value = "1"
	
	var a2a = document.createElement("input")
	a2a.type = "hidden"
	a2a.name = "ID"
	a2a.value = document.configomatic.a2.value
	var a2b = document.createElement("input")
	a2b.type = "hidden"
	a2b.name = "Qty"
	a2b.value = "1"

	var a3a = document.createElement("input")
	a3a.type = "hidden"
	a3a.name = "ID"
	a3a.value = document.configomatic.a3.value
	var a3b = document.createElement("input")
	a3b.type = "hidden"
	a3b.name = "Qty"
	a3b.value = "1"
	
	var a4a = document.createElement("input")
	a4a.type = "hidden"
	a4a.name = "ID"
	a4a.value = document.configomatic.a4.value
	var a4b = document.createElement("input")
	a4b.type = "hidden"
	a4b.name = "Qty"
	a4b.value = "1"
	
	var a5a = document.createElement("input")
	a5a.type = "hidden"
	a5a.name = "ID"
	a5a.value = document.configomatic.a5.value
	var a5b = document.createElement("input")
	a5b.type = "hidden"
	a5b.name = "Qty"
	a5b.value = document.configomatic.a5n.value
	
	var a6a = document.createElement("input")
	a6a.type = "hidden"
	a6a.name = "ID"
	a6a.value = document.configomatic.a6.value
	var a6b = document.createElement("input")
	a6b.type = "hidden"
	a6b.name = "Qty"
	a6b.value = document.configomatic.a6n.value
	
	var a7a = document.createElement("input")
	a7a.type = "hidden"
	a7a.name = "ID"
	a7a.value = document.configomatic.a7.value
	var a7b = document.createElement("input")
	a7b.type = "hidden"
	a7b.name = "Qty"
	a7b.value = document.configomatic.a7n.value

	var a8a = document.createElement("input")
	a8a.type = "hidden"
	a8a.name = "ID"
	a8a.value = document.configomatic.a8.value
	var a8b = document.createElement("input")
	a8b.type = "hidden"
	a8b.name = "Qty"
	a8b.value = "1"
	
	var a9a = document.createElement("input")
	a9a.type = "hidden"
	a9a.name = "ID"
	a9a.value = document.configomatic.a9.value
	var a9b = document.createElement("input")
	a9b.type = "hidden"
	a9b.name = "Qty"
	a9b.value = "1"
	
	var aaa = document.createElement("input")
	aaa.type = "hidden"
	aaa.name = "ID"
	aaa.value = document.configomatic.aa.value
	var aab = document.createElement("input")
	aab.type = "hidden"
	aab.name = "Qty"
	aab.value = "1"
	
	var aba = document.createElement("input")
	aba.type = "hidden"
	aba.name = "ID"
	aba.value = document.configomatic.ab.value
	var abb = document.createElement("input")
	abb.type = "hidden"
	abb.name = "Qty"
	abb.value = "1"
	
	var aca = document.createElement("input")
	aca.type = "hidden"
	aca.name = "ID"
	aca.value = document.configomatic.ac.value
	var acb = document.createElement("input")
	acb.type = "hidden"
	acb.name = "Qty"
	acb.value = "1"
	
	var ada = document.createElement("input")
	ada.type = "hidden"
	ada.name = "ID"
	ada.value = document.configomatic.ad.value
	var adb = document.createElement("input")
	adb.type = "hidden"
	adb.name = "Qty"
	adb.value = "1"
	
	var aea = document.createElement("input")
	aea.type = "hidden"
	aea.name = "ID"
	aea.value = document.configomatic.ae.value
	var aeb = document.createElement("input")
	aeb.type = "hidden"
	aeb.name = "Qty"
	aeb.value = "1"
	
	var afa = document.createElement("input")
	afa.type = "hidden"
	afa.name = "ID"
	afa.value = document.configomatic.af.value
	var afb = document.createElement("input")
	afb.type = "hidden"
	afb.name = "Qty"
	afb.value = "1"
	
	var b0a = document.createElement("input")
	b0a.type = "hidden"
	b0a.name = "ID"
	b0a.value = document.configomatic.b0.value
	var b0b = document.createElement("input")
	b0b.type = "hidden"
	b0b.name = "Qty"
	b0b.value = "1"
	
	var b1a = document.createElement("input")
	b1a.type = "hidden"
	b1a.name = "ID"
	b1a.value = document.configomatic.b1.value
	var b1b = document.createElement("input")
	b1b.type = "hidden"
	b1b.name = "Qty"
	b1b.value = "1"
	
	var b2a = document.createElement("input")
	b2a.type = "hidden"
	b2a.name = "ID"
	b2a.value = document.configomatic.b2.value
	var b2b = document.createElement("input")
	b2b.type = "hidden"
	b2b.name = "Qty"
	b2b.value = "1"
	
	var b3a = document.createElement("input")
	b3a.type = "hidden"
	b3a.name = "ID"
	b3a.value = document.configomatic.b3.value
	var b3b = document.createElement("input")
	b3b.type = "hidden"
	b3b.name = "Qty"
	b3b.value = "1"
	
	var b4a = document.createElement("input")
	b4a.type = "hidden"
	b4a.name = "ID"
	b4a.value = document.configomatic.b4.value
	var b4b = document.createElement("input")
	b4b.type = "hidden"
	b4b.name = "Qty"
	b4b.value = "1"

	var b5a = document.createElement("input")
	b5a.type = "hidden"
	b5a.name = "ID"
	b5a.value = "457440"
	var b5b = document.createElement("input")
	b5b.type = "hidden"
	b5b.name = "Qty"
	b5b.value = "1"

	shop.appendChild(addtocart)
	shop.appendChild(pkta)
	shop.appendChild(pktb)
	shop.appendChild(a0a)
	shop.appendChild(a0b)
	shop.appendChild(a1a)
	shop.appendChild(a1b)
	shop.appendChild(a2a)
	shop.appendChild(a2b)
	shop.appendChild(a3a)
	shop.appendChild(a3b)
	shop.appendChild(a4a)
	shop.appendChild(a4b)
	shop.appendChild(a5a)
	shop.appendChild(a5b)
	shop.appendChild(a6a)
	shop.appendChild(a6b)
	shop.appendChild(a7a)
	shop.appendChild(a7b)
	shop.appendChild(a8a)
	shop.appendChild(a8b)
	shop.appendChild(a9a)
	shop.appendChild(a9b)
	shop.appendChild(aaa)
	shop.appendChild(aab)
	shop.appendChild(aba)
	shop.appendChild(abb)
	shop.appendChild(aca)
	shop.appendChild(acb)
	shop.appendChild(ada)
	shop.appendChild(adb)
	shop.appendChild(aea)
	shop.appendChild(aeb)
	shop.appendChild(afa)
	shop.appendChild(afb)
	shop.appendChild(b0a)
	shop.appendChild(b0b)
	shop.appendChild(b1a)
	shop.appendChild(b1b)
	shop.appendChild(b2a)
	shop.appendChild(b2b)
	shop.appendChild(b3a)
	shop.appendChild(b3b)
	shop.appendChild(b4a)
	shop.appendChild(b4b)
	shop.appendChild(b5a)
	shop.appendChild(b5b)
	
	parent.appendChild(shop)
	
	shop.submit()
}

function updatePrice(type) {
	document.getElementById("configPrice 1").innerHTML = num2money(price[document.configomatic.a0.value])
	document.getElementById("configPrice 2").innerHTML = num2money(price[document.configomatic.a1.value])
	document.getElementById("configPrice 3").innerHTML = num2money(price[document.configomatic.a2.value])
	document.getElementById("configPrice 4").innerHTML = num2money(price[document.configomatic.a3.value])
	document.getElementById("configPrice 5").innerHTML = num2money(price[document.configomatic.a4.value])
	document.getElementById("configPrice 6").innerHTML = num2money(price[document.configomatic.a5.value] * Number(document.configomatic.a5n.value))
	document.getElementById("configPrice 7").innerHTML = num2money(price[document.configomatic.a6.value] * Number(document.configomatic.a6n.value))
	document.getElementById("configPrice 8").innerHTML = num2money(price[document.configomatic.a7.value] * Number(document.configomatic.a7n.value))
	document.getElementById("configPrice 9").innerHTML = num2money(price[document.configomatic.a8.value])
	document.getElementById("configPrice 10").innerHTML = num2money(price[document.configomatic.a9.value])
	document.getElementById("configPrice 11").innerHTML = num2money(price[document.configomatic.aa.value])
	document.getElementById("configPrice 12").innerHTML = num2money(price[document.configomatic.ab.value])
	document.getElementById("configPrice 13").innerHTML = num2money(price[document.configomatic.ac.value])
	document.getElementById("configPrice 14").innerHTML = num2money(price[document.configomatic.ad.value])
	document.getElementById("configPrice 15").innerHTML = num2money(price[document.configomatic.ae.value])
	document.getElementById("configPrice 16").innerHTML = num2money(price[document.configomatic.af.value])
	document.getElementById("configPrice 17").innerHTML = num2money(price[document.configomatic.b0.value])
	document.getElementById("configPrice 18").innerHTML = num2money(price[document.configomatic.b1.value])
	document.getElementById("configPrice 19").innerHTML = num2money(price[document.configomatic.b2.value])
	document.getElementById("configPrice 20").innerHTML = num2money(price[document.configomatic.b3.value])
	document.getElementById("configPrice 21").innerHTML = num2money(price[document.configomatic.b4.value])
	
	var total = price[document.configomatic.a0.value] +
	            price[document.configomatic.a1.value] +
	            price[document.configomatic.a2.value] +
	            price[document.configomatic.a3.value] +
	            price[document.configomatic.a4.value] +
	            (price[document.configomatic.a5.value] * Number(document.configomatic.a5n.value)) +
	            (price[document.configomatic.a6.value] * Number(document.configomatic.a6n.value)) +
	            (price[document.configomatic.a7.value] * Number(document.configomatic.a7n.value)) +
	            price[document.configomatic.a8.value] +
	            price[document.configomatic.a9.value] +
	            price[document.configomatic.aa.value] +
	            price[document.configomatic.ab.value] +
	            price[document.configomatic.ac.value] +
	            price[document.configomatic.ad.value] +
	            price[document.configomatic.ae.value] +
	            price[document.configomatic.af.value] +
	            price[document.configomatic.b0.value] +
	            price[document.configomatic.b1.value] +
	            price[document.configomatic.b2.value] +
	            price[document.configomatic.b3.value] +
	            price[document.configomatic.b4.value] + 875
	
	document.getElementById("configTotal").innerHTML = num2money(total)
}
