
function showlinkcursor()
{
	 document.body.style.cursor = "pointer";
}

function shownormalcursor()
{
	 document.body.style.cursor = "auto";
}

function showshoppingcart()
{
    showwnd('sc_js_wnd');
}

function checkout()
{
    location.href = "http://www.trinergi.se/WebShop/Checkout.asp";
}

function togglelang()
{
    location.href = "http://www.trinergi.se/WebShop/ToggleLang.asp?location=" + location.href;
}

function createhelpwnd()
{
    var code = '';
    code += 'Här är det hjälptext!';
    return code;
}

function currencychanged()
{
    var newcurrency = document.getElementById('CurrencyCodeList').value;
    var oldloc = location.href;
    location.href = 'http://www.trinergi.se/WebShop/ChangeCurrency.asp?CUR=' + newcurrency + '&redir_addr=' + oldloc;
}

function login()
{
    location.href = 'http://www.trinergi.se/WebShop/UserAccount.asp?return_page=UserAccount.asp';
}

var string_itemname = '';
var string_qt_in_cart = '';
var string_price_per_item = '';
var string_sum_for_each_row = '';
var string_item = '';
var string_price_per_item_short = '';
var string_sum = '';
var string_click_here_to_go_to_product = '';
var string_change_qt_statustext = '';
var string_costs = '';
var string_currency_code = '';
var string_per_short = '';
var string_total = '';
var string_total_sum = '';
var string_excl_vat_and_freight = '';
var string_quantity = '';
function createshoppingcart(helptitle, showonbuytext, tostorebuttontext, tostorestatustext, itemname, qt_in_cart,
    price_per_item, sum_for_each_row, item, price_per_item_short, sum, click_here_to_go_to_product,
    change_qt_statustext, costs, currency_code, per_short, total, total_sum, excl_vat_and_freight,
    currency_code_list, loginbuttontext, logintatustext, quantity)
{
    string_itemname = itemname;
    string_qt_in_cart = qt_in_cart;
    string_price_per_item = price_per_item;
    string_sum_for_each_row = sum_for_each_row;
    string_item = item;
    string_price_per_item_short = price_per_item_short;
    string_sum = sum;
    string_click_here_to_go_to_product = click_here_to_go_to_product;
    string_change_qt_statustext = change_qt_statustext;
    string_costs = costs;
    string_currency_code = currency_code;
    string_per_short = per_short;
    string_total = total;
    string_total_sum = total_sum;
    string_excl_vat_and_freight = excl_vat_and_freight;
    string_quantity = quantity;
    
    var code = '';
    var scwindow = createwnd('hlpwnd', createhelpwnd(), '#7777FF', '#FFFFFF', '#AAAAAA', helptitle, 400, 200, 150, 150);
    document.getElementById('hlpcontainer').innerHTML = scwindow;

    
    // The list of items...
    code += '<div name="sc_content_list" id="sc_content_list" style="vertical-align: top;'
    code += ' top: 0px;"></div><br>';
    
    // The final row of stuff...
    code += '<div name="hlplnk" id="hlplnk" style="float: left; display: inline; text-align: left;">';
    code += '&nbsp;&nbsp;<a href="#"; onclick="javascript: showwnd(\'hlpwnd\'); return false;">' + helptitle + '</a>';
    
    var showeachtime = readCookie('ShowCartOnBuy');
    if(showeachtime == "")
        showeachtime = "on";
    code += '<br><br>&nbsp;&nbsp;<input type="checkbox" ';
    if(showeachtime == "on") 
    {
        code +=' CHECKED';
    }
    code += ' onchange="javascript: ontoggleshowonbuy(); return true;" style="width: 16px" ';
    code += 'name="ShowOnBuyCheckbox" id="ShowOnBuyCheckbox">' + showonbuytext + '<br>';
    
    // Create currency code list...
    code += '<br><br><select name="CurrencyCodeList" id="CurrencyCodeList"';
    code += ' style="width: 60px; height: 20px; font-size: 12px" ';
    code += ' onchange="javascript: currencychanged(); return true;">';
    var curr_code_arr = currency_code_list.split(";");
    for(var i = 0; i < curr_code_arr.length; i++)
    {
        var this_cur_code = curr_code_arr[i];
        code += '<option name="CCList' + this_cur_code + '" id="CCList' + this_cur_code + '"';
        code += ' value="' + this_cur_code + '"';
        if( this_cur_code == currency_code )
            code += " SELECTED";
        code += '>' + this_cur_code + '</option>';
    } 
    code += '</select>';
    
            
    code += '</div>';
    
    
    code += '<div style="float: right; display: inline;">';
    
    code += '<input type="button" value="' + loginbuttontext + '" class="button"'
    code += ' onmouseover="javascript: setstatus('
    code += "'sc_js_wnd'";
    code += ",'" + logintatustext + "'";
    code += '); return true;" ';
    code += ' onmouseout="javascript: setstatus('
    code += "'sc_js_wnd'";
    code += ",''";
    code += '); return true;" ';
    code += ' onclick="javascript: login(); return true;"'
    code += '>';
    
    code += '<input type="button" value="' + tostorebuttontext + '" class="button"'
    code += ' onmouseover="javascript: setstatus('
    code += "'sc_js_wnd'";
    code += ",'" + tostorestatustext + "'";
    code += '); return true;" ';
    code += ' onmouseout="javascript: setstatus('
    code += "'sc_js_wnd'";
    code += ",''";
    code += '); return true;" ';
    code += ' onclick="javascript: checkout(); return true;"'
    code += '>';
    
    code += '</div>';
    
    // Create feedback frame...
    code += '<div style="height: 0px; width: 0px; visibility: hidden;">';
    code += '<iframe ';
    code += 'style="visibility: hidden; height: 0px; width: 0px; margin-bottom: 0px; margin-top: 0px;"';
    code += 'name="sc_comframe" id="sc_comframe"></iframe>';
    // Create feedback form...
    code += '<div id="sc_form_div" name="sc_form_div" '
    code += 'style="visibility: hidden; height: 0px; width: 0px; margin-bottom: 0px; margin-top: 0px;"'
    code += '>';
    code += '<form d="sc_form" name="sc_form" method="POST" action="/WebShop/CartUpdate.asp" '
    code += ' style="margin-bottom: 0px; margin-top: 0px;"';
    code += ' target="sc_comframe">';
    
    code += '<input type="hidden" name="sc_form_act" id="sc_form_act" value="none">';
    code += '<input type="hidden" name="sc_form_item_id" id="sc_form_item_id" value="none">';
    code += '<input type="hidden" name="sc_form_new_val" id="sc_form_new_val" value="none">';
    code += '<input type="hidden" name="sc_form_special_val" id="sc_form_special_val" value="">';
    
    code += '</form>';
    code += '</div>';
    code += '</div>';
    
    return code;
}

function addtocartspecial(productid, special)
{
    document.getElementById('sc_form_act').value = "ADD";
    document.getElementById('sc_form_new_val').value = productid;
    document.getElementById('sc_form_special_val').value = special;
    
    document.sc_form.submit();
    
    var showeachtime = readCookie('ShowCartOnBuy');
    if(showeachtime == "")
        showeachtime = "on";
    var isVisible = document.getElementById('sc_js_wnd').visibility == 'visible';
    if(showeachtime == "on" && !isVisible)
        showshoppingcart();
    
}

function addtocartnownd(productid)
{
    document.getElementById('sc_form_act').value = "ADD";
    document.getElementById('sc_form_new_val').value = productid;
    document.getElementById('sc_form_special_val').value = "";
    document.getElementById('sc_form_prop_option_id').value = "none"
    document.sc_form.submit();
}

function addtocartnowndwithprop(productid, propertyoptionid)
{
    document.getElementById('sc_form_act').value = "ADD";
    document.getElementById('sc_form_new_val').value = productid;
    document.getElementById('sc_form_prop_option_id').value = propertyoptionid;
    document.getElementById('sc_form_special_val').value = "";
    
    document.sc_form.submit();
}


function addtocart(productid)
{
    document.getElementById('sc_form_act').value = "ADD";
    document.getElementById('sc_form_new_val').value = productid;
    document.getElementById('sc_form_special_val').value = "";
    
    document.sc_form.submit();
    
    var showeachtime = readCookie('ShowCartOnBuy');
    if(showeachtime == "")
        showeachtime = "on";
    var isVisible = document.getElementById('sc_js_wnd').visibility == 'visible';
    if(showeachtime == "on" && !isVisible)
        showshoppingcart();
    
}

function get_cartframe_field(fname)
{
    return document.getElementById('sc_comframe').contentWindow.document.getElementById(fname).value;
}

function getshoppingcartitems()
{
    document.getElementById('sc_form_act').value = "GET";
    document.sc_form.submit();
}

function IsNumeric(sText)
{
    var ValidChars = "0123456789.";
    var IsNumber=true;
    var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++) 
    { 
        Char = sText.charAt(i); 
        if (ValidChars.indexOf(Char) == -1) 
        {
            IsNumber = false;
        }
    }
    return IsNumber;
}
   
var prev_field_val = 0;

function numberfieldgotfocus(field_id)
{
    prev_field_val = document.getElementById(field_id).value;
}


function numberfieldlostfocus(field_id, product_id)
{
    var val = document.getElementById(field_id).value;
    if(IsNumeric(val))
    {
        document.getElementById('sc_form_act').value = "UPDATENUMBER";
        
        document.getElementById('sc_form_item_id').value = product_id;
        document.getElementById('sc_form_new_val').value = val;
    
        document.sc_form.submit();
    }
    else
    {
        document.getElementById(field_id).value = prev_field_val;
    }   
}

function vlinkclicked(vlink, wndtitle)
{
    var rlink = 'http://www.trinergi.se/' + vlink;
    location.href = rlink;    
}

function ontoggleshowonbuy()
{
    var val = document.getElementById('ShowOnBuyCheckbox').checked;
    if(val)
        createCookie('ShowCartOnBuy', 'on');
    else
        createCookie('ShowCartOnBuy', 'off');
}

function cartupdateloaded()
{
    if( get_cartframe_field('containsitems') == "YES")
    {
    
        var numberofitems = get_cartframe_field('tot_items');
        
        var code = '<table cellpadding="0" cellspacing="0">';
        code += '<TR>';
            
        code += '<TD';
        
        code += ' onmouseover="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",'" + string_itemname + "'";
        code += '); return true;" ';
        code += ' onmouseout="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",''";
        code += '); return true;" ';
        code += '>';
        
        code += '<b>' + string_item + '</b>';
        code += '</TD>';
        code += '<TD';
        code += ' onmouseover="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",'" + string_qt_in_cart + "'";
        code += '); return true;" ';
        code += ' onmouseout="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",''";
        code += '); return true;" ';
        code += '>';
        code += '<b>' + string_quantity + '</b>';
        code += '</TD>';
        code += '<TD';
        code += ' onmouseover="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",'" + string_price_per_item + "'";
        code += '); return true;" ';
        code += ' onmouseout="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",''";
        code += '); return true;" ';
        code += '>';
        code += '<b>' + string_price_per_item_short + '</b>';
        code += '</TD>';
        code += '<TD';
        code += ' onmouseover="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",'" + string_sum_for_each_row + "'";
        code += '); return true;" ';
        code += ' onmouseout="javascript: setstatus('
        code += "'sc_js_wnd'";
        code += ",''";
        code += '); return true;" ';
        code += '>';
        code += '<b>' + string_sum + '</b>';
        code += '</TD>';
        
        code += '</TR>';
        
        var total = 0;
        for(i = 1; i <= numberofitems; i++)
        {
            var iname = get_cartframe_field('item_name_' + i);
            code += '<TR>';
            var link = get_cartframe_field('item_link_' + i);
            
            code += '<TD onclick="javascript: vlinkclicked(' + "'" + link + "'" + ', ' + "'" + iname + "'" + '); return false;"';
            
            code += ' onmouseover="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",'" + string_click_here_to_go_to_product + "'";
            code += '); return true;" ';
            
            code += ' onmouseout="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",''";
            code += '); return true;" ';
            
            code += '>';
            
            code += iname;
            code += '</TD>';
            
            code += '<TD';
            
            code += ' onmouseover="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",'" + string_change_qt_statustext + "'";
            code += '); return true;" ';
            code += ' onmouseout="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",''";
            code += '); return true;" ';
            code += '>';
            
            code += '<input type="text" name="item_no_' + i + '" id="item_no_' + i + '" ';
            code += ' style="font-size: 11px; height: 15px; padding: 1px; width: 20px;" ';
            code += ' onfocus="javascript: numberfieldgotfocus(' + "'" + 'item_no_' + i + "'" +'); return true;" ';
            code += ' onblur="javascript: numberfieldlostfocus(' + "'" + 'item_no_' + i + "'" +',';
            code += get_cartframe_field('item_prod_id_' + i) + '); return true;" ';
            code += 'value="' + get_cartframe_field('item_no_' + i) + '">';
            code += '</TD>';
            
            code += '<TD';
            code += ' onmouseover="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",'" + iname + " " + string_costs + " " + get_cartframe_field('item_price_' + i) + " ";
            code += string_currency_code + "/" + string_per_short + "'";
            code += '); return true;" ';
            code += ' onmouseout="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",''";
            code += '); return true;" ';
            code += '>';
            
            code += get_cartframe_field('item_price_' + i);
            code += '</TD>';
            
            code += '<TD';
            
            code += ' onmouseover="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",'" + get_cartframe_field('item_no_' + i) + " " + string_per_short + " " + iname;
            code += " " + string_price_per_item_short + " " + get_cartframe_field('item_price_' + i);
            code += " " + string_currency_code + "/" + string_per_short + ", " + string_total + " ";
            code += (get_cartframe_field('item_price_' + i)*get_cartframe_field('item_no_' + i)) +" " + string_currency_code + "'";
            
            total += get_cartframe_field('item_price_' + i)*get_cartframe_field('item_no_' + i);
            
            code += '); return true;" ';
            code += ' onmouseout="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",''";
            code += '); return true;" ';
            code += '>';
            
            code += get_cartframe_field('item_price_' + i)*get_cartframe_field('item_no_' + i);
            code += '</TD>';
            
            code += '</TR>';
        }
        // Empty row
        code += '<TR>';
        code += '<TD style="">&nbsp;</TD>';
        code += '<TD>&nbsp;</TD>';
        code += '<TD>&nbsp;</TD>';
        code += '<TD>&nbsp;</TD>';
        code += '</TR>';
        // Sum row...
        code += '<TR>';
        code += '<TD style="border-top-width: 2px; border-top-color: #000000; border-top-style: solid;"></TD>';
        code += '<TD style="border-top-width: 2px; border-top-color: #000000; border-top-style: solid;"></TD>';
        code += '<TD style="border-top-width: 2px; border-top-color: #000000; border-top-style: solid;"';
            
            code += ' onmouseover="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",'" + string_total_sum + " " + total + " " + string_currency_code + ", " + string_excl_vat_and_freight + ".'";
            code += '); return true;" ';
            code += ' onmouseout="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",''";
            code += '); return true;" ';
            
        code += '><b>Summa</b></TD>';
        code += '<TD style="border-top-width: 2px; border-top-color: #000000; border-top-style: solid;"';
        
             code += ' onmouseover="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",'" + string_total_sum + " " + total + " " + string_currency_code + ", " + string_excl_vat_and_freight + ".'";
            code += '); return true;" ';
            code += ' onmouseout="javascript: setstatus('
            code += "'sc_js_wnd'";
            code += ",''";
            code += '); return true;" ';
            
        code += '><b>' + total + '</b></TD>';
        
        code += '</TR>';
        
        code += '</table>';
               
        document.getElementById('sc_content_list').innerHTML = code;
        
    }
    else
    {
        if( get_cartframe_field('containsitems') == "NO")
        {
            getshoppingcartitems();
        }
    }
}