function getshopcontent()
{
    var fullcontent = window.name;
    var shopcard = getshopcard();

    if (fullcontent.indexOf(shopcard) != -1)
    {
         var begin = fullcontent.indexOf(shopcard) + shopcard.length;
         var end = fullcontent.lastIndexOf(shopcard);
         var shopcontent = fullcontent.substring(begin, end);
    }
    else
    {
        shopcontent = "";
    }
    return shopcontent;
}

function getsearchcontent()
{
    var fullcontent = window.name;
    var searchcard = getsearchcard();

    if (fullcontent.indexOf(searchcard) != -1)
    {
         var begin = fullcontent.indexOf(searchcard);
         var end = fullcontent.lastIndexOf(searchcard) + searchcard.length;
         var searchcontent = fullcontent.substring(begin, end);
    }
    else
    {
        searchcontent = "";
    }
    return searchcontent;
}


function getshopcard()
{
    return "shopcard";
}

function getsearchcard()
{
    return "searchcard";
}

function setshopcontent(arti, number)
{
    var shopcard = getshopcard();
    var searchcontent = getsearchcontent();
    var shopcontent = getshopcontent();
    var shopsplit = shopcontent.split("_");

    if (shopcontent == "")
    {
        shopcontent = searchcontent + shopcard + getWert(number) + "_" + getName(arti) + shopcard;
    }
    else
    {
        shopcontent = "";
        for (i=0;i<shopsplit.length;i++)
        {
            if (shopsplit[i+1] == getName(arti))
            {
                shopsplit[i] = getWert(number);
            }
            if (shopcontent == "")
            {
                shopcontent = shopsplit[i] + "_" + shopsplit[i+1];
            }
            else
            {
                shopcontent = shopcontent + "_" + shopsplit[i] + "_" + shopsplit[i+1];
            }
            ++i;
        }
        if (shopcontent.indexOf(getName(arti)) == -1)
        {
            shopcontent = shopcontent + "_" + getWert(number) + "_" + getName(arti);
        }
        shopcontent = searchcontent + shopcard + shopcontent + shopcard;
    }
    self.name = shopcontent;
    location.reload();
}

function getWert(sObj)
{
    return sObj.value;
}

function getName(sObj)
{
    if (sObj.name.indexOf("KOMP_ID") != -1)
    {
        return sObj.value;
    }
    return sObj.name;
}

function printshopcontent(language)
{
  var fehler = "";
  var artikel = "";
  var bezeichnung = "";
  var anzahl = "";
  var aendern = "";
  var loeschen = "";
  
  
  switch(language) {
 	case "d":
		fehler = "Ihr&nbsp;Warenkorb&nbsp;ist&nbsp;leer.";
		artikel = "Art Nr.";
		bezeichnung = "Bezeichnung";
		anzahl = "Anzahl";
		aendern = "Ändern";
		loeschen = "Löschen";
 		break;
 	case "e":
		fehler = "There&nbsp;are&nbsp;no&nbsp;items&nbsp;in&nbsp;your&nbsp;shopping&nbsp;basket.";
		artikel = "Part No.";
		bezeichnung = "description";
		anzahl = "quantity";
		aendern = "change";
		loeschen = "delete";
 		break;
 	case "s":
		fehler = "Su&nbsp;carro&nbsp;esta&nbsp;vacio.";
		artikel = "referencia";
		bezeichnung = "decriptión";
		anzahl = "cantidad";
		aendern = "cambiar";
		loeschen = "cancelar";
 		break;
  }
  
    
    var shopcontent = getshopcontent();
    if (shopcontent == "")
    {
        document.write("<tr>");
        document.write("<td colspan='2'><img src='nav_pics/spacer.gif' width='10' height='5' border='0'><b>"+fehler+"</b></td>");
        document.write("<td colspan='1' width='100%'><img src='nav_pics/spacer.gif' width='1' height='1' border='0'></td>");
        document.write("</tr>");
    }
    else
    {
        var shopsplit = shopcontent.split("_");
        document.write("<tr>");
        document.write("<td class='Sub' valign=top align=left nowrap width='60'><img src='nav_pics/spacer.gif' width='10' height='1' border='0'>"+artikel+"</td>");
        document.write("<td class='Sub' valign=top align=left nowrap>"+bezeichnung+"</td>");
        document.write("<td class='Sub' valign=top align=left nowrap width='60'>"+anzahl+"</td>");
        document.write("<td class='Sub' valign=top style='text-align:center;' nowrap width='60'>"+aendern+"</td>");
        document.write("<td class='Sub' valign=top style='text-align:center;' nowrap width='60'>"+loeschen+"</td>");
        document.write("</tr>");

        for (i=0;i<shopsplit.length;i++)
        {
            for (j=0;j<arti_id.length;j++)
            {
                if (shopsplit[i+1].toLowerCase() == arti_id[j].toLowerCase())
                {
                    document.write("<tr>");
                    document.write("<td bgcolor='#f0f0f0'><img src='nav_pics/spacer.gif' width='10' height='1' border='0'>" + shopsplit[i+1] + "</td>");
                    document.write("<td bgcolor='#f0f0f0'>" + arti_bezeichnung[j] + "</td>");
                    document.write("<td bgcolor='#f0f0f0'><input type='Text' name='" + shopsplit[i+1] + "' size='3' value='" + shopsplit[i] +"'></td>");
                    document.write("<td bgcolor='#f0f0f0' style='text-align:center;'><a href='#' onClick='setshopcontent(document.formular." + shopsplit[i+1] +", document.formular." + shopsplit[i+1] +");'><img src='shop_pics/change_h.gif' width='15' height='15' border='0'></a></td>");
                    document.write("<td bgcolor='#f0f0f0' style='text-align:center;'><a href='#' onClick='delshopcontent(document.formular." + shopsplit[i+1] +", document.formular." + shopsplit[i+1] +");'><img src='shop_pics/delete_h.gif' width='20' height='15' border='0'></a></td>");
                    document.write("</tr>");
                }
            }
            ++i;
        }
    }
}

function delshopcontent(arti, number)
{
    var shopcontent = getshopcontent();
    var searchcontent = getsearchcontent();
    var shopcard = getshopcard();
    var shopsplit = shopcontent.split("_");
    var part = "";
    for (i=0;i<shopsplit.length;i++)
    {
        if (shopsplit[i+1] != getName(arti))
        {
            if (part == "")
            {
                part = shopsplit[i] + "_" + shopsplit[i+1];
            }
            else
            {
                part = part + "_" + shopsplit[i] + "_" + shopsplit[i+1];
            }
        }
        ++i;
    }
    if (part == "")
    {
        self.name = searchcontent;
    }
    else
    {
        self.name = searchcontent + shopcard + part + shopcard;
    }
    location.reload();
}

function formcontent()
{
    var shopcontent = getshopcontent();
    if (shopcontent != "")
    {
        var shopsplit = shopcontent.split("_");
        var body = "";
        var j = 1;
        for (i=0;i<shopsplit.length;i++)
        {
            body = "\tArticleNumber: " + shopsplit[i+1] + "\tQuantity: " + shopsplit[i];
            ++i;
            document.write("<input type='hidden' name='Order"+ j +"' value='"+ body +"'>");
            j++;
        }
    }
}
