
var ajaxConn = new XHConn()
function getLangto() {
	if (document.getElementById("lang_from")) {
		var lang_from
		var lang_from = document.getElementById("lang_from").value
		ajaxConn.connect("/custom/ajax_get_langto.asp", "GET", "f="+lang_from, setLangto)
	}
}

function setLangto(XML) {
	var sb = document.getElementById("lang_to")
	var result = unescape(XML.responseText)
	var arr = result.split(";")

	while (sb.hasChildNodes()) sb.removeChild(sb.firstChild)
	addOption(phrase1, -1)
	for (var i=0; i < arr.length-1; ++i) {
		arr_part = arr[i].split("@")
		addOption(arr_part[1], arr_part[0])
	}

	document.getElementById("info_step2").setAttribute("className", "active")
	document.getElementById("info_step2").setAttribute("class", "active")
}
function getProducts() {
	if (document.getElementById("lang_from")) {
		var lang_from = document.getElementById("lang_from").value
		var lang_to = document.getElementById("lang_to").value
		if (lang_to != "-1") ajaxConn.connect("/custom/ajax_get_products.asp", "GET", "f="+lang_from+"&t="+lang_to, setProducts)
	}
}
function setProducts_old(XML) {
	var result = unescape(XML.responseText)
	var root = document.getElementById("results_placeholder")

	root.innerHTML = ''

	var tbo = document.createElement('tbody')
	var row, cell
	var arr = result.split(";")
	var tab = document.createElement('table')
	tab.className = "product_table"

	addRow('',tablehead1, tablehead2,'','head',tbo)

	for (var i = 0; i < arr.length-1; i++) {
		arr_part = arr[i].split("@")

		addBox(arr_part[0], arr_part[1], arr_part[2], arr_part[3], "", tbo)
	}
	tab.appendChild(tbo)
	root.appendChild(tab)

	document.getElementById("info_step3").setAttribute("className", "active")
	document.getElementById("info_step3").setAttribute("class", "active")
}


function setProducts(XML) {
	var result = unescape(XML.responseText)
	var root = document.getElementById("results_placeholder")

	root.innerHTML = ''

	var box
	var arr = result.split(";")

	for (var i = 0; i < arr.length-1; i++) {
		arr_part = arr[i].split("@")

		addBox(arr_part[0], arr_part[1], arr_part[2], arr_part[3], root)
	}

	clearbox = document.createElement('div')
	clearbox.style.clear = 'both'
	root.appendChild(clearbox)

	document.getElementById("info_step3").setAttribute("className", "active")
	document.getElementById("info_step3").setAttribute("class", "active")
}
function addBox(idno, artno, name, simg, tbo) {
	box = document.createElement('div')
	box.className = 'product_box'

	link = document.createElement('a')
	link.setAttribute('href', '/shop/'+idno+'---')
	link.appendChild(document.createTextNode(name))
	p = document.createElement('h2')
	p.appendChild(link)
	box.appendChild(p)

	p2 = document.createElement('p')
	image = document.createElement('img')
	image.setAttribute('src', '/rwdx/image_cache/shop.'+simg)

	link2 = document.createElement('a')
	link2.setAttribute('href', '/shop/'+idno+'---')

	link2.appendChild(image)
	p2.appendChild(link2)
	box.appendChild(p2)

/*
	link.appendChild(image)
	cell.appendChild(link)
*/
	tbo.appendChild(box)
}
function addRow(idno, artno, name, simg, clname, tbo) {
	row = document.createElement('tr')
	row.className = clname
	cell = document.createElement('td')

	if (idno != '') {
//		cell.appendChild(document.createTextNode(name))
//		row.appendChild(cell)
		
		cell = document.createElement('td')
		link = document.createElement('a')
		link.setAttribute('href', '/shop/'+idno+'---')
		link.appendChild(document.createTextNode(name))
		cell.appendChild(link)
		row.appendChild(cell)

		cell = document.createElement('td')
		link = document.createElement('a')
		link.setAttribute('href', '/shop/'+idno+'---')

		image = document.createElement('img')
		image.setAttribute('src', '/rwdx/image_cache/shop.'+simg)

		link.appendChild(image)

		cell.appendChild(link)

	} else {
		cell.appendChild(document.createTextNode(artno))
		row.appendChild(cell)

		cell = document.createElement('td')
		cell.appendChild(document.createTextNode(name))
//		cell.appendChild(cell)
	}
	row.appendChild(cell)
	tbo.appendChild(row)
}
function addOption(text, value) {
    var opt = document.createElement("option");
	// Add an Option object to Drop Down/List Box
	document.getElementById("lang_to").options.add(opt)
	opt.text = text
	opt.value = value
}

document.onload = getLangto()


