﻿var delaytime;

function DisplayResponse(XML)
{  
        var ProductIdList = XML.getElementsByTagName('search');     
        var strTable='';
      
        strTable = strTable + "<table border='0' width='600px' cellspacing='0' cellpadding='0'><tr><td><span class='headline'>Resultat af søgningen</span></td></tr><tr><td colspan='3'>&nbsp;</td></tr></table><div>Din søgning matchede ikke nogen produkter.<br /><br />Forslag:<br /><br /></div><div><a href='Search.aspx' target='_self' style='display: inline-block; color: DarkBlue; height: 14px;'>Anvend alfabetisk emneords-liste.</a><div style='padding-bottom: 10px; padding-top: 30px;'><table border='0' width='500px' cellspacing='0' cellpadding='0'><tr><td><span class='headline'>Mente du...?</span></td></tr></table></div></div>Forslag til søgninger, der ligner det, du søgte på.";
        strTable = strTable +' <table border=0 cellpadding=2 cellspacing=1 class=gvTable >';
         
        if (ProductIdList.length >0 )
        {
            for (var i=0 ; i < ProductIdList.length; i++)
            {
                strTable = strTable + ' <tr>';
                strTable = strTable + ' <td class=gvItem >';
                strTable = strTable + "<a title='" + GetInnerText(ProductIdList[i]) + "' href='products.aspx?searchword=" + GetInnerText(ProductIdList[i]) + "' target='_self' >" + GetInnerText(ProductIdList[i]) + "</a>";
                strTable = strTable + ' </td>';
                strTable = strTable + '   </tr>';
            }
        }
        else 
        {
            strTable = strTable + '<tr>'
            strTable = strTable + '<td colspan=6 align=left>'
            strTable = strTable + 'Ingen forslag til søgningen!'
            strTable = strTable + '</td>'
            strTable = strTable + '</tr>'
        }
        strTable = strTable +' </table>'
        document.getElementById ('gvSuggest').innerHTML= strTable ;
   }

function GetInnerText (node)
{
    return (node.textContent || node.innerText || node.text) ;
}

function getmessagecontent() 
{ 
 // Salgstekst
 messagecontent="<table border=0 cellpadding=0 cellspacing=0 width=500px style='background-color:#E6E6E6;padding-left: 10px'><tr><td valign='top' ><div style='width: 120;text-decoration:none;text-align:left;cursor:default;background-color:#E6E6E6;color:black;font-size:1.0em;font-weight:bold'><b>Salgstekst:</b></div></td><td align=right><div style='width: 360px;text-decoration:none;text-align:right;cursor:default;background-color:#E6E6E6;color:black;font-size:1.0em;font-weight:bold' ><b>" + work_salgstekst + "</b></div></td></tr></table>"
 // Varenr
 messagecontent+="<table border=0 cellpadding=0 cellspacing=0 width=500px style='background-color:White;padding-left: 10px'><tr><td><div style='width: 240;text-decoration:none;text-align:left;cursor:default;background-color:white;color:black;font-size:1.0em;font-weight:bold'><b>Varenr.:</b></div></td><td align=right><div style='width: 240px;text-decoration:none;text-align:right;cursor:default;background-color:White;color:black;font-size:1.0em;font-weight:bold' ><b>" + work_matnr + "</b></div></td></tr></table>"
 // Ordre tilvækst
 messagecontent+="<table border=0 cellpadding=0 cellspacing=0 width=500px style='background-color:#E6E6E6;padding-left: 10px'><tr><td><div style='width: 240;text-decoration:none;text-align:left;cursor:default;background-color:#E6E6E6;color:black;font-size:1.0em;font-weight:bold'><b>Ordre tilvækst:</b></div></td><td align=right><div style='width: 240px;text-decoration:none;text-align:right;cursor:default;background-color:#E6E6E6;color:black;font-size:1.0em;font-weight:bold' ><b>" + work_OrdreTilvaekst + "</b></div></td></tr></table>"
 // Mindste købsmængde
 messagecontent+="<table border=0 cellpadding=0 cellspacing=0 width=500px style='background-color:white;padding-left: 10px'><tr><td><div style='width: 240;text-decoration:none;text-align:left;cursor:default;background-color:white;color:black;font-size:1.0em;font-weight:bold'><b>Mindste købsmængde:</b></div></td><td align=right><div style='width: 240px;text-decoration:none;text-align:right;cursor:default;background-color:White;color:black;font-size:1.0em;font-weight:bold' ><b>" + work_MinKvantum + "</b></div></td></tr></table>"
 // Enhed
 messagecontent+="<table border=0 cellpadding=0 cellspacing=0 width=500px style='background-color:#E6E6E6;padding-left: 10px'><tr><td><div style='width: 240;text-decoration:none;text-align:left;cursor:default;background-color:#E6E6E6;color:black;font-size:1.0em;font-weight:bold'><b>Salgsenhed:</b></div></td><td align=right><div style='width: 240px;text-decoration:none;text-align:right;cursor:default;background-color:#E6E6E6;color:black;font-size:1.0em;font-weight:bold' ><b>" + work_Salgsenhed + "</b></div></td></tr></table>"
// EAN
 messagecontent+="<table border=0 cellpadding=0 cellspacing=0 width=500px style='background-color:White;padding-left: 10px'><tr><td><div style='width: 240;text-decoration:none;text-align:left;cursor:default;background-color:white;color:black;font-size:1.0em;font-weight:bold'><b>EAN kode.:</b></div></td><td align=right><div style='width: 240px;text-decoration:none;text-align:right;cursor:default;background-color:White;color:black;font-size:1.0em;font-weight:bold' ><b>" + work_EANkode + "</b></div></td></tr></table>"

}

function delayCall(thisbox, matnr, description, EANkode, Salgsenhed, MinKvantum, OrdreTilvaekst, PrisPr, Salgstekst){
	delaytime = setTimeout( function(){ doMouseOverAct(thisbox, matnr, description, EANkode, Salgsenhed, MinKvantum, OrdreTilvaekst, PrisPr, Salgstekst)}, 500);
}

function doMouseOverAct(thisbox, matnr, description, EANkode, Salgsenhed, MinKvantum, OrdreTilvaekst, PrisPr, Salgstekst){
    
     work_matnr = matnr;
    work_descr = description;
    work_EANkode = EANkode;
    work_Salgsenhed = Salgsenhed;
    work_MinKvantum = MinKvantum;
    work_OrdreTilvaekst = OrdreTilvaekst;
    work_PrisPr = PrisPr;
    work_salgstekst = Salgstekst;
    getmessagecontent()
    newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
    newHTML = newHTML +  "<table width=500px style='border-color: White; height: 49px;' border=0 cellspacing=0 cellpadding=0><tr valign=top style='height: 49px'><td style='width: 94px; height: 49px;' ><a href='http://www.wuerth.dk/web/da/home/Forside.html'><img src='App_Themes/wuerth/Images/wuerth-logo.gif' alt='' style='border: none'/></a></td><td style='height: 49px'><table cellpadding=0 cellspacing=0 border=0 width=405px><tr><td align=left valign=top ><table border=0 cellpadding=0 cellspacing=0 width=405px style='background-color:White'><tr><td align=right><div style='width: 240px; text-align: right; cursor: default; background-color: white;color: black; font-size: 8pt; font-weight: bold'><b>" + work_matnr + "</b></div></td></tr></table><table border=0 cellpadding=0 cellspacing=0 width=405px style='background-color:White'><tr><td align=right><div style='width: 405px; text-align: right; cursor: default; background-color: white;color: black; font-size: large; font-weight: bold'><b>" + work_descr + "</b></div></td></tr></table> </td></tr></table></td></tr></table><br/>";
 	newHTML = newHTML + messagecontent;
   	newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + thisbox + '" border="0"></div>';
	newHTML = newHTML + '</div>';
	
    var div_tooltip=document.getElementById("trailimageid");
    div_tooltip.style.left=0;
    div_tooltip.style.top=0;
    div_tooltip.innerHTML=newHTML;    
    div_tooltip.style.visibility="visible";
}

function delayCallExtra(thisbox, matnr, description){
	delaytime = setTimeout( function(){ doMouseOverActExtra(thisbox, matnr, description)}, 500);
}

function doMouseOverActExtra(thisbox, matnr, description){
    
    work_matnr = matnr;
    work_descr = description;
    newHTML = '<div style="padding: 5px; background-color: #FFF; border: 1px solid #888;">';
    newHTML = newHTML +  "<table width=500px style='border-color: White; height: 49px;' border=0 cellspacing=0 cellpadding=0><tr valign=top style='height: 49px'><td style='width: 94px; height: 49px;' ><a href='http://www.wuerth.dk/web/da/home/Forside.html'><img src='App_Themes/wuerth/Images/wuerth-logo.gif' alt='' style='border: none'/></a></td><td style='height: 49px'><table cellpadding=0 cellspacing=0 border=0 width=405px><tr><td align=left valign=top ><table border=0 cellpadding=0 cellspacing=0 width=405px style='background-color:White'><tr><td align=right><div style='width: 240px; text-align: right; cursor: default; background-color: white;color: black; font-size: 8pt; font-weight: bold'><b>" + work_matnr + "</b></div></td></tr></table><table border=0 cellpadding=0 cellspacing=0 width=405px style='background-color:White'><tr><td align=right><div style='width: 405px; text-align: right; cursor: default; background-color: white;color: black; font-size: large; font-weight: bold'><b>" + work_descr + "</b></div></td></tr></table> </td></tr></table></td></tr></table><br/>";
 	newHTML = newHTML + '<div align="center" style="padding: 8px 2px 2px 2px;"><img src="' + thisbox + '" border="0"></div>';
	newHTML = newHTML + '</div>';
	
    var div_tooltip=document.getElementById("trailimageid");
    div_tooltip.style.left=0;
    div_tooltip.style.top=0;
    div_tooltip.innerHTML=newHTML;
    div_tooltip.style.visibility="visible";        
}

function doMouseOutAct(){
    var div_tooltip=document.getElementById("trailimageid");
    div_tooltip.style.visibility="hidden";div_tooltip.innerHTML="";
    clearTimeout(delaytime);
}
	    function ShowMList()
	    {
	        var divRef = document.getElementById("ctl00_MainContents_divCheckBoxList");
	        divRef.style.display = "block";
	        var divRefC = document.getElementById("ctl00_MainContents_divCheckBoxListClose");
	        divRefC.style.display = "block";
	    }
    	
	    function HideMList()
		{
	        document.getElementById("ctl00_MainContents_divCheckBoxList").style.display = "none";   
	        document.getElementById("ctl00_MainContents_divCheckBoxListClose").style.display = "none";   
	    }
	    
        function FindSelectedItems(sender,textBoxID)
        {       
            var cblstTable = document.getElementById(sender.id);
            var checkBoxPrefix = sender.id + "_";
            var noOfOptions = cblstTable.rows.length;
            var selectedText = "";
            for(i=0; i < noOfOptions ; ++i)
            {
                if(document.getElementById(checkBoxPrefix+i).checked)
                {
                    if(selectedText == "")                
                        selectedText = document.getElementById(checkBoxPrefix+i).parentNode.innerText;
                    else
                        selectedText = selectedText + "," + document.getElementById(checkBoxPrefix+i).parentNode.innerText;
                }
            }    
            document.getElementById(textBoxID.id).value = selectedText;   
        }
        
  function GetArticleImage(img, ref)
    {
        // this is used to detach the event to prevent loading again and again next times
        img.onload = null;
        
        // getting the image from a dynamic page with passing query string
        img.src = 'http://www.wuerth.dk/produktinfo/ProductImageThumbnailer.ashx?ref=' + ref + '&imagetype=Thumbnail';   
    }
    
     function GetArticlePrimaryImage(img, matno)
    {
        // this is used to detach the event to prevent loading again and again next times
        img.onload = null;
        
        // getting the image from a dynamic page with passing query string
         img.src = 'http://www.wuerth.dk/produktinfo/ImageThumbnailer.ashx?id=' +  matno + '&imagetype=Thumbnail';
          
    }
    
  function expandcollapseSubimglog(obj,row) {
  var div = document.getElementById(obj);
  var img = document.getElementById('img' + obj);
        
  if (div.style.display == "none")
   {
    div.style.display = "block";
     if (row == 'alt')
      img.src = "App_Themes/wuerth/Images/minus.gif";
     else
      img.src = "App_Themes/wuerth/Images/minus.gif";
    
    img.alt = "";
   }
  else
   {
    div.style.display = "none";
     if (row == 'alt')
      img.src = "App_Themes/wuerth/Images/plus.gif"; 
     else
      img.src = "App_Themes/wuerth/Images/plus.gif";
   
    img.alt = "";    
     } 
} 

function expandcollapse(obj,row) {
  var div = document.getElementById(obj);
  var img = document.getElementById('img' + obj);
        
  if (div.style.display == "none")
   {
    div.style.display = "block";
     if (row == 'alt')
      img.src = "App_Themes/wuerth/Images/b_collapse.gif";
     else
      img.src = "App_Themes/wuerth/Images/b_collapse.gif";
    
    img.alt = "";
    img.height = "16";
    img.width = "67"; 
   }
  else
   {
    div.style.display = "none";
     if (row == 'alt')
      { img.src = "App_Themes/wuerth/Images/b_expand.gif"; }
     else
      { img.src = "App_Themes/wuerth/Images/b_expand.gif"; }
   
    img.alt = "";
    img.height = "16";
    img.width = "39";
   }
} 

function expandcollapseSub(obj,row) {
  var div = document.getElementById(obj);
  var img = document.getElementById('img' + obj);
        
  if (div.style.display == "none")
   {
    div.style.display = "block";
     if (row == 'alt')
      img.src = "App_Themes/wuerth/Images/minus.gif";
     else
      img.src = "App_Themes/wuerth/Images/minus.gif";
    
    img.alt = "";
    document.getElementById('Mygrid' + obj).style.display = "block";
   }
  else
   {
    div.style.display = "none";
     if (row == 'alt')
      { img.src = "App_Themes/wuerth/Images/plus.gif"; }
     else
      { img.src = "App_Themes/wuerth/Images/plus.gif"; }
   
    img.alt = "";
    document.getElementById('Mygrid' + obj).style.display = "none";
     }
} 

function IAmSelected( source, eventArgs )
{
  document.getElementById('ctl00_MainContents_btnsearchbutton').click();
}

function KeyDownHandler() { 		
 var btn = document.getElementById('ctl00_MainContents_myAnimatedImage');
 btn.src = "App_Themes/wuerth/Images/spinner.gif";
	
}
		
function KeyUpHandler() { 
   var fld = document.getElementById('ctl00_MainContents_searchTextBox');
   var btn = document.getElementById('ctl00_MainContents_myAnimatedImage');
   
   if (fld.value.length > 0) 
   {
	btn.src="App_Themes/wuerth/Images/clear.gif";
   } 
   else 
   if (fld.value.length == 0 ) 
   {
    btn.src = "App_Themes/wuerth/Images/blind.gif";
   }
}
 
function showDiv() {

document.getElementById('myHiddenDiv').style.display =""; 
setTimeout('document.images["ctl00_MainContents_myAnimatedImage"].src="App_Themes/wuerth/Images/spinner.gif"', 100); 
} 

function clearAndFocus( el ) { 
 var btn = document.getElementById('ctl00_MainContents_myAnimatedImage');
 btn.src = "App_Themes/wuerth/Images/blind.gif";
 el.value = ''; 
 el.focus()
}

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}
