/*
function setCookie (name,value) {
  document.cookie = name + "=" + escape (value.toUpperCase()) ;
}
//mike
*/

// set color to 0 (like in about any other place it's used)
var color=0;

function encodeURL(str)
{
    if (window.encodeURIComponent)
    {
        return encodeURIComponent(str);
    }
    else
    {    
        var resultStr="";
        var i;
        var codePointSave;
        var surrogate=false;
        var vals = new Array(0,0,0,0);
        var asciiUnEnc="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_.!~*'()";

        for (i=0; i < str.length; i++)
        {
            var codePoint=str.charCodeAt(i);
            var nVals=0;

            if (surrogate && codePoint >= 0xDC00 && codePoint <= 0xDFFF)
            {
                vals[0]=((((codePointSave & 0x03C0) >> 6) + 1) >> 2) | 0xF0;
                vals[1]=(((((codePointSave & 0x03C0) >> 6) + 1) & 0x03) << 4) || ((codePointSave & 0x003C) >> 2) | 0x80;
                vals[2]=((codePointSave & 0x0003) << 4) || ((codePoint & 0x03C0) >> 6) || 0x80;
                vals[3]=(codePoint & 0x003F) | 0x80;
                nVals=4;
                surrogate=false;
            } else if (codePoint >= 0xD800 && codePoint <= 0xDBFF)
            {
                surrogate=true;
                codePointSave=codePoint;
                continue;
            } else
            {
                surrogate=false;
                if (codePoint > 0x07FF)
                {
                    vals[0]=((codePoint & 0xF000) >> 12) | 0xE0;
                    vals[1]=(codePoint & 0xFC0) >> 6 | 0x80;
                    vals[2]=(codePoint & 0x3F) | 0x80;
                    nVals=3;
                } else if (codePoint > 0x007F)
                {
                    vals[0]=((codePoint & 0x7C0) >> 6) | 0xC0;
                    vals[1]=(codePoint & 0x3F) | 0x80;
                    nVals=2;
                } else if (asciiUnEnc.indexOf(str.charAt(i)) < 0)
                {
                    vals[0]=codePoint;
                    nVals=1;
                }
            }

            if (nVals > 0)
            {
                var j;
                for (j=0; j < nVals; j++)
                {
                    var hexStr = vals[j].toString(16).toUpperCase();
                    if (hexStr.length == 1)
                    {
                        hexStr="0" + hexStr;
                    }
                    resultStr+="%" + hexStr;
                 }
             } else
             {
                resultStr += str.charAt(i);
             }
         }
         return resultStr;
    }
}


function popup(url, title, subtitle, name, width, height) 
{ 
 //url = url.replace(/&/g, "%26"); 
 url = url.replace(/ /g, "%20"); 
 title = title.replace(/ /g, "%20");
 subtitle = subtitle.replace(/ /g, "%20"); 
// w = open("http://test1.ra.adc.cgey.fr/pls/portal30/volt_api.volt_util.p_popup_window?p_url=" + url + "&p_title=" + title + "&p_subtitle=" + subtitle + "&p_popup_name=" + name + "&p_width=" + width + "&p_height=" + height + "&p_print=YES&p_save=YES", name, "scrollbars=yes,resizable=yes,width=" + width + ",height=" + height); 
w = open("popup.php?url="+url + "&p_title=" + title + "&p_subtitle=" + subtitle + "&p_popup_name=" + name + "&p_width=" + width + "&p_height=" + height + "&p_print=YES&p_save=YES", name, "scrollbars=yes,resizable=yes,width=" + width + ",height=" + height); 
	w.focus();
	}
 

function putkeyword(x) {
	var i=x.selectedIndex;
	x=x.options[i].value;
	document.search.keywords.value = x;	
}

function bd(bdvalue) {
	if ((bdvalue!='')&&(bdvalue!=' ')) {
		var text = "";
		text=text+'<tr><td class="vltListProductBreak" colspan="11">';
        text=text+'<img src="v_images/spacer.gif" width="5" height="1" alt="" border="0">'
		text=text+bdvalue;
		text=text+'</td></tr>';
		table=table+text;
	}
}

function cent(amount) {
// returns the amount in the .99 format
    amount = (Math.round(amount*1000))/1000;
    return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}

// empty column for design reasons
var tdempty = '<td WIDTH="1"></TD>';

var tdpv = '<td class="pv">';
var tdpv20 = '<td class="pv" width=20>';
var tdpvref = '<td class="pvref">';
var tdpvf = '<td class="pvf">';
var tdpvp = '<td class="pvp">';
var tdpvl = '<td class="pvl">';
var tdpvlnowrap = '<td class="pvl" nowrap>';
var ftd = '</td>';
var tr = '<tr>';
var tr1 = '<tr class="catRow1">';
var tr2 = '<tr class="catRow2">';
var ftr = '</tr>';
var b = '&nbsp;';


function displayPrice(prix, devise, stdu, conversion_rate)
{
	if ( (prix * 0 == 0) && ( prix != '') )
	{
		if (prix != 0.001)
		{
			if (conversion_rate > 0)
			{
				prix = cent(prix*conversion_rate)+b+devise;
				prix = prix+b;
			} else
			{
				prix = cent(prix)+b+devise;			
			}
			
			if ((stdu!='')&&(stdu!='1')&&(stdu!='0'))
			{
				prix = prix+" "+stdu;
			}
		} else
		{
			prix = nlmessages["VLT_BS_ON_REQUEST"];
		}	
	} else
	{
		prix ='';
	}
		
	return(prix);
}

function wp(ref, ean_ref, second_ref, product,prix,devise,stdu,item,section,link,newok,sellingunit,bdvalue,catalogType, conversion_rate)
{
    if ( bdvalue != currentBreakDown )
    {
        bd(bdvalue);
        currentBreakDown = bdvalue;
    }    
    table = table + wpl(ref,ean_ref, second_ref, product, prix, devise, stdu, item, section, link, newok, sellingunit, catalogType, conversion_rate);
}

function wpl(ref, ean_ref, second_ref, product, prix, devise, stdu, item, section, link, newok, sellingunit, catalogType, conversion_rate)
{
    var altRowColor = 1;
    ref=ref;    
	var text = "";
	var s;
	var t = "";
	prix = displayPrice(prix, devise, stdu, conversion_rate);

	if ((newok == 'Y'))
	{
	    t = '<img border="0" ALT="" src="v_images/new_'+languageCode+'.gif"/>';
	}
	
	// to be added later.. alternating row colors
	if (altRowColor == 1)
	{
    	text=text+tr1;
    } else
    {
    	text=text+tr2;
    }
    
    // new layout requires one empty column
    // will be added for old layout for compatibility too
	//text=text+tdempty;

	if (TableCol["new_prd"])
	{
		text=text+tdpv20+t+ftd;
	}
	
	if (TableCol["related_product_id"])
	{
		text=text+tdpv+ref+ftd;
	}
	if (TableCol["second_ref"])
	{
		text=text+tdpv+second_ref+ftd;
	}
	
	if (TableCol["ean_ref"])
	{
		text=text+tdpv+ean_ref+ftd;
	}

	if (TableCol["commercial_description"])
	{
        if ((typeof(pid) == "undefined") || (pid == "voltimum"))
        {
	    	text=text+tdpv+product+'&nbsp;&nbsp;'+t+ftd;
	    } else
	    {
            if ((link.indexOf('P')>=0) && (TableCol["linksP"]))
            {
                text=text+tdpvl;        
                s='<img alt="'+nlmessages["VLT_BS_DATASHEET_IN_HEADER"]+'" border="0" src="layout/' + pid + '/images/bluearrow.gif"/>';
                s='<a href="catalogue.jsp?mode=details&product_id='+encodeURL(ref)+'&family_id='+section+'&catalogType='+catalogType+'&brand='+brand+'&universe='+current_universe_id+'">'+s+"&nbsp;"+product+'</a>'+t;

                if (TableTease["datasheet"] != "nope")
                {
                    s = '<img border="0" src="layout/' + pid + '/images/bluearrow.gif"/>';
                    s = '<a href="javascript:void();" onClick="' + TableTease["datasheet"] + '">' + s + "&nbsp;" + product + '</a>';
                }
        
                text=text+s;
                text=text+ftd;
            } else
            {
                if (TableCol["linksP"])
                {
                    text=text+tdpvl;
                    text = text+b;
                    text=text+ftd;
                };
            }
	    }
	}
	
    if (TableCol["price"])
    {
        if (TableTease["price"]!='nope')
        {
            if ((typeof(pid) == "undefined") || (pid == "voltimum"))
            {
                s='<img border="0" src="v_images/graphics/arrow2'+color+'.gif"/>';
            } else
            {
                s='<img border="0" src="layout/' + pid + '/images/bluearrow.gif"/>';
            }
    
            prix='<a href="javascript:void();" onClick="'+TableTease["price"]+'">'+s+'</a>';
        }
        text=text+tdpv+prix+ftd;
    }
	
    if ((typeof(pid) == "undefined") || (pid == "voltimum"))
    {
        // old layout: basket here.. relauch: end of table
        // output prices
        if ( (prix != '') )
        {
            if (TableCol["selling_unit"])
            {
                if ((typeof(pid) == "undefined") || (pid == "voltimum"))
                {
                    text=text+'<td class="pv" align="left" width="150">'+'<input size="3" class="pvf" type="text" value="0" name="qty['+ref+']">';
                    text=text+' '+sellingunit;
                    text=text+ftd;
                } else
                {
                    // for new layout use this:
                    text=text+'<td class="pv" align="left" width="120">';
                    text=text+'<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD class="pv">';
                    text=text+'<input size="3" class="pvf" type="text" value="0" name="qty['+ref+']" style="width:24px;">';
                    text=text+'&nbsp;'+sellingunit;
                    text=text+'</TD><TD ALIGN=RIGHT WIDTH=26>';
                    text=text+'<INPUT src="layout/' + pid + '/images/cartbutton.gif" type="image" border="0">';
                    text=text+'</TD></TR></TABLE>';
                    text=text+ftd;
                }
            }
        } else
        {
            if (TableCol["selling_unit"])
            {
                text=text+tdpv+b+ftd;
            }
        }
    }
    
	if ((link.indexOf('S')>=0) && (TableCol["linksS"]))
	{
		text=text+tdpvl;

        if ((typeof(pid) == "undefined") || (pid == "voltimum"))
        {
            s='<img border="0" src="v_images/graphics/arrow2'+color+'.gif" alt="'+nlmessages["VLT_BS_SHORT_TEXT_IN_HEADER"]+'"/>';
        } else
        {
            s='<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="'+nlmessages["VLT_BS_SHORTTEXT_VIEW"]+'"/>&nbsp;'+nlmessages["VLT_BS_SHORTTEXT_VIEW"];
        }

		var popup='';
		popup="javascript:win=window.open('popup.php?url=getshort.jsp%3Fproduct_id%3D"+ref+"%26brand%3D"+brand+"&type=bs_all&subtitle=&title=','Voltimum','menubar=no,location=no,scrollbar=yes,resizable=yes,width=400,height=400');win.focus;";
		s='<a href="javascript:void();" onClick="'+popup+'">'+s+'</a>';
		text=text+s;
		text=text+ftd;
    } else
    {
		if (TableCol["linksS"])
		{
			text=text+tdpvl;
			text = text+b;
			text=text+ftd;
	    };
    }

	if ( (typeof(pid) == "undefined") || (pid == "voltimum") )
    {
        if ((link.indexOf('P') >=0 ) && (TableCol["linksP"]))
        {
            text=text+tdpvl;        
    
            if ((typeof(pid) == "undefined") || (pid == "voltimum"))
            {
                s='<img border="0" src="v_images/graphics/arrow2'+color+'.gif" alt="'+nlmessages["VLT_BS_DATASHEET_IN_HEADER"]+'"/>';
            } else
            {
                s='<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="'+nlmessages["VLT_BS_DATASHEET_IN_HEADER"]+'"/>&nbsp;'+nlmessages["VLT_BS_DATASHEET_VIEW"];
            }
            s='<a href="catalogue.jsp?catalogType='+catalogType+'&mode=details&brand='+brand+'&product_id='+encodeURL(ref)+'&family_id='+encodeURL(section)+'&universe='+current_universe_id+'">'+s+'</a>';
            if (TableTease["datasheet"]!="nope")
            {
                if ((typeof(pid) == "undefined") || (pid == "voltimum"))
                {
                    s = '<img border="0" src="v_images/graphics/arrow2'+color+'.gif">';
                } else 
                {
                    s = '<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="">';
                }
                s = '<a href="javascript:void();" onClick="'+TableTease["datasheet"]+'">'+s+'</a>';
            }
    
            text=text+s;
            text=text+ftd;
        } else
        {
            if (TableCol["linksP"])
            {
                text=text+tdpvl;
                text = text+b;
                text=text+ftd;
            };
        }
    }

    // show document links
	if ((link.indexOf('O') >= 0) && (TableCol["linksO"]))
	{
		text=text+tdpvlnowrap;
		
        if ((typeof(pid) == "undefined") || (pid == "voltimum"))
        {
            s='<img border="0" src="v_images/graphics/arrow2'+color+'.gif" alt="'+nlmessages["VLT_BS_OPTIONS_IN_HEADER"]+'"/>';
        } else
        {
            s='<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="'+nlmessages["VLT_BS_OPTIONS_IN_HEADER"]+'"/>&nbsp;'+nlmessages["VLT_BS_OPTIONS_VIEW"];
        }
        s = '<a href="catalogue.jsp?mode=getassoc&product_id=' + encodeURL(ref) + '&brand=' + brand + '&catalogType=' + catalogType + '&universe=' + current_universe_id + '">' + s + '</a>';
		
		if (TableTease["options"] != "nope")
		{
            if ((typeof(pid) == "undefined") || (pid == "voltimum"))
            {
                s='<img border="0" src="v_images/graphics/arrow2'+color+'.gif" alt="">';
            } else
            {
                s='<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="">&nbsp;'+nlmessages["VLT_BS_OPTIONS_VIEW"];
            }

            s='<a href="javascript:void();" onClick="'+TableTease["options"]+'">'+s+'</a>';
        }
        text=text+s;
		text=text+ftd;

	} else
	{
		if (TableCol["linksO"])
		{
			text=text+tdpvl;
			text = text+b;
			text=text+ftd;
		};
	}

	if ((link.indexOf('A')>=0) && (TableCol["linksA"]))
	{
    	text=text+tdpvlnowrap;

        if ((typeof(pid) == "undefined") || (pid == "voltimum"))
        {
            s = '&nbsp;<img border="0" src="v_images/graphics/arrow2'+color+'.gif" alt="'+nlmessages["VLT_BS_DOCS_IN_HEADER"]+'"/>';
        } else
        {
            s = '<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="'+nlmessages["VLT_BS_DOCS_IN_HEADER"]+'"/>&nbsp;'+nlmessages["VLT_BS_DOCS_VIEW"];
        }

		var popup='';
		popup = "javascript:win=window.open('popup.php?url=getattach.jsp%3FcatalogType%3D" + catalogType + "%26product_id%3D" + (ref.replace("+","%252B")).replace(" ","+") + "%26brand%3D" + brand + "&type=bs_all&subtitle=&title=','Voltimum','menubar=no,location=no,scrollbar=yes,resizable=yes,width=600,height=600');win.focus;";

		if (TableTease["documentation"]!="nope")
		{
            if ((typeof(pid) == "undefined") || (pid == "voltimum"))
            {
                s='<img border="0" src="v_images/graphics/arrow2'+color+'.gif"/>';
            } else
            {
                s='&nbsp;<img border="0" src="layout/' + pid + '/images/bluearrow.gif" alt="">&nbsp;'+nlmessages["VLT_BS_DOCS_VIEW"];
            }

            s='<a href="javascript:void();" onClick="'+TableTease["documentation"]+'">'+s+'</a>';
        }
		s = '<a href="javascript:void();" onClick="'+popup+'">'+s+'</a>';
		text = text + s;
		text = text + ftd;
	} else
	{
		if (TableCol["linksA"])
		{
			text=text+tdpvl;
			text = text+b;
			text=text+ftd;
		};
	}

    if ( ! ((typeof(pid) == "undefined") || (pid == "voltimum")) )
    {
        // relaunch only..
        // output prices
        if ( (prix != '') )
        {
            if (TableCol["selling_unit"])
            {
                // for new layout use this:
                /*
                text=text+'<td class="pv" align="left" width="120" nowrap>'+'<input size="3" class="pvf" type="text" value="0" name="qty['+ref+']" style="width:24px;">';
                text=text+'&nbsp;'+sellingunit+"&nbsp;";
                text=text+'<INPUT src="layout/' + pid + '/images/cartbutton.gif" type="image" border="0">';
                text=text+ftd;                    
                */
                text=text+'<td class="pv" align="left" width="120">';
                text=text+'<TABLE WIDTH="100%" CELLSPACING=0 CELLPADDING=0 BORDER=0><TR><TD class="pv" nowrap>';
                text=text+'<input size="3" class="pvf" type="text" value="0" name="qty['+ref+']" style="width:24px;">';
                text=text+'&nbsp;'+sellingunit;
                text=text+'</TD><TD ALIGN=RIGHT WIDTH=26>';
                text=text+'<INPUT src="layout/' + pid + '/images/cartbutton.gif" type="image" border="0">';
                text=text+'</TD></TR></TABLE>';
                text=text+ftd;
            }
        } else
        {
            if (TableCol["selling_unit"])
            {
                text=text+tdpv+b+ftd;
            }
        }
    }        


	text=text+ftr;
	position = position + 1;

	return(text);
}


function wpf(fName, sectionID, links)
{
	var text = "";
    if ((typeof(pid) == "undefined") || (pid == "voltimum"))
    {
	    var s = "<A HREF='" + store + uri  + "&mode=$$$" + "&family_id=" + sectionID + "&brand=" + brand + "'><img alt='???' border='0' src='v_images/graphics/arrow2"+color+".gif'></a>";
    } else
    {
	    var s = '<A HREF="' + store + uri  + '&mode=$$$' + '&family_id=' + sectionID + '&brand=' + brand + '"><img alt="???" border="0" src="layout/' + pid + '/images/bluearrow.gif">&nbsp;' + nlmessages["VLT_BS_DATASHEET_VIEW"] + '</A>';
    }
    
	text = text + tr + "<td class='vltHeightSeparator' colspan='2'>" + ftd + ftr;
	text = text + tr + tdpv + fName + ftd;
	text = text + tdpvl;

	if (links.indexOf('L') >= 0)
	{
		text = text + s.replace('???',nlmessages["VLT_BS_LIST_IN_HEADER"]).replace('$$$','prodlist');
	} else
	{
		text = text + "&nbsp;";
	}
	
	text = text + ftd;
	text = text + tdpvl;
	
	if (links.indexOf('M') >= 0)
	{
		text = text + s.replace('???',nlmessages["VLT_BS_DISCOVERY_IN_HEADER"]).replace('$$$','details');
	} else
	{
		text = text + "&nbsp;";
	}
	
	text = text + ftd;
	text = text + tdpvl;
	
	if (links.indexOf('A') >= 0)
	{
		text = text + s.replace('???',nlmessages["VLT_BS_ASSISTANT_IN_HEADER"]).replace('$$$','assistant');
	} else
	{
		text = text + "&nbsp;";
	}
	
	text = text + ftd;
	text = text + ftr;
	position = position + 1;
	return(text);
}

function wwp()
{
	document.write(table);
}

function MM_preloadImages()
{ //v3.0
    var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

