﻿function changeImage(Control, url, Active)
{
  //only change if inactive
  if(!Active)
  {
    Control.style.backgroundImage = "url(" + url + ")"; 
  }  
}

function changeMenuItemBackGround(Control, Color, Active)
{
  //only change if inactive
  if(!Active)
  {
    Control.style.backgroundColor = Color; 
  }  
}

function clearContactForm()
{
  var name = document.getElementById('ctl00_MainContent_txtName');
  var email = document.getElementById('ctl00_MainContent_txtEmail');
  var msg = document.getElementById('ctl00_MainContent_txtMessage');
  var errorMsg = document.getElementById('ctl00_MainContent_lblMessage');
  
  if(name != null){ name.value = "";  }
  if(email != null){ email.value = "";  }
  if(msg != null){ msg.value = "";  }
  if(errorMsg != null){ errorMsg.innerHTML = "";  }
}

/// ************************** MoneyBox ***************************** ///

function mbKeyDown(sender, value)
{
   //set the inputkey to the code of the pressed key
   var inputKey =  event.keyCode;
   //the returnCode will return if the entered key is valid
   var returnCode = true;   
   //alert(event.keyCode);
   //if the delete key was pressed, then empty the timebox
//   if(inputKey == 46)
//   {
//      sender.value = ""; //reset the value
//   }
  
   //we only want to allow numeric numbers from the keyboard and numpad 
   if ( (inputKey > 47 && inputKey < 58) || (inputKey > 95 && inputKey < 106) || inputKey == 8 || inputKey == 46 || inputKey == 59 || inputKey == 9 || inputKey == 188  || inputKey == 190 || inputKey == 110 || event.ctrlKey || inputKey == 39 || inputKey == 37) // numbers  188(,) 190(.) 110 (.numpad) 
   {
      //check if a separator was entered and handle it
      if(inputKey == 188 || inputKey == 190 || inputKey == 110)
      {
        //let the function handle the separator
        mbHandleSeparator(sender);
        returnCode = false;
        event.keyCode = 0;           
      }
      
      //we block shift shortcuts and we only allow one separator
      if(event.shiftKey || (event.ctrlKey && inputKey == 86))// || !mbDigitAllowed(sender,value,2,',')) //we only block ctrl + v (paste), but copy is allowed
      {
        returnCode = false;
        event.keyCode = 0; 
      }    
   }
   else
   {   
    returnCode = false;
    //alert(inputKey);
    //we also block the shift key, but you can't set the keycode to 0 then. Every other key which is not allowed we do
    if(!event.shiftKey)
    {    
      event.keyCode = 0;
    }  
   }
   event.returnValue = returnCode;  
}

function mbKeyUp(sender, value, numberOfDigitsAllowed, currencyDecimalSeparator)
{
  //here we check if the max number of digits are entered
  
  //check if the value contains the separator
  if(sender.value.indexOf(currencyDecimalSeparator) >= 0)
  {
    //now we want to break the whole number and digits apart into an array
    var curArr = sender.value.split(currencyDecimalSeparator);  

    //we have to take action, when the entered digits are bigger then the allowed value
    if(curArr != null && curArr.length == 2 && (curArr[1].toString().length > numberOfDigitsAllowed))
    {
      //alert('hierrr');
      //remove the last digit
      var digits = curArr[1].substr(0,numberOfDigitsAllowed);
      //recreate the currency
      sender.value = curArr[0] + currencyDecimalSeparator + digits;
    }
  }  
}

function mbHandleSeparator(sender)
{
  //the culture decimal separator has been set in the code behind in the attribute CultureDecimalSeparator.. get it
  var separatorKeyCode = sender.getAttribute("CurrencyDecimalSeparator");
    
  //check if the separator already has been entered
  if(sender.value.indexOf(separatorKeyCode) >= 0)
  {
    return;
  }
  else
  {
    //we add the separator
    sender.value = sender.value + separatorKeyCode;
  }
}

//function mbDigitAllowed(sender, value, numberOfDigitsAllowed, currencyDecimalSeparator)
//{
//  //check if the value contains the separator
//  if(sender.value.indexOf(currencyDecimalSeparator) >= 0)
//  {
//    //now we want to break the whole number and digits apart into an array
//    var curArr = sender.value.split(currencyDecimalSeparator);  

//    //we have to take action, when the entered digits are bigger then the allowed value
//    if(curArr != null && curArr.length == 2 && (curArr[1].toString().length > numberOfDigitsAllowed))
//    {
//      //remove the last digit
//      var digits = curArr[1].substr(0,numberOfDigitsAllowed);
//      //recreate the currency
//      sender.value = curArr[0] + currencyDecimalSeparator + digits;      
//      return false;
//    }
//  }    
//  return true;
//}

// Open een Rekenmodule popup.
function DownloadPDF(arg)
{
    OpenWindow('http://localhost:1234/PDF/pdf.aspx', '_self', 1, 1,0, 0);
}

// Open een Popup.
function OpenWindow(URL, WindowName, Width, Height, Resizable, Toolbar)
{
  	var ScreenX = screen.availWidth;
	var ScreenY = screen.availHeight;
	var PosX = (ScreenX / 2) - (Width / 2);
	var PosY = (ScreenY / 2) - (Height / 2);
	
	window.open(''+URL, ''+WindowName+'', 'width='+Width+',height='+Height+',status=0,scrollbars=1,toolbar='+Toolbar+',resizable='+Resizable+'');	
	
	//window.open(''+URL, ''+WindowName+'', 'left='+PosX+',top='+PosY+',width='+Width+',height='+Height+',status=0,scrollbars=1,toolbar='+Toolbar+',resizable='+Resizable+'');	
}


//Shows a popup with info
function ShowInfoPanel(panelID,info)
{
    //get the popup
    var popup = document.getElementById(panelID);
    
    if(popup != null)
    {
      //set the html in the popup
      popup.innerHTML = info;
      popup.style.display = 'block';      
    }  
}

//Hides a popup
function HideInfoPanel(panelID)
{
    //get the popup
    var popup = document.getElementById(panelID);
    
    if(popup != null)
    {
      //Clear and hide the popup
      popup.innerHTML = "";
      popup.style.display = 'none';      
    }  
}


var normalColor; 

function HighLightRow(row) 
{ 
  //set the normal color globally, we need it for the restore
  normalColor = row.style.backgroundColor; 
  row.style.backgroundColor = "#FFFF66"; 
  row.style.cursor='pointer';
  //At this point we use this for detail price info and subproducts
  //check if we need to show a popup and set it in a variable
  var htmlInfo = null;
  if(row.getAttribute("PriceInfo") != null)
  {
    //alert(this.getAttribute("PriceInfo"));
    htmlInfo = row.getAttribute("PriceInfo");
  }
  
  //or if it's the subproduct grid
  if(row.getAttribute("SubProductInfo") != null)
  {
    htmlInfo = row.getAttribute("SubProductInfo");
  }
  
  //or otherinfo field
  if(row.getAttribute("HTML_Info") != null)
  {
    htmlInfo = row.getAttribute("HTML_Info");
  }  
  
  //get the id of the popup and load the html
  if(row.getAttribute("InfoPanel") != null)
  {
    //exec the javascript function to show the popup
    ShowInfoPanel(row.getAttribute("InfoPanel"), htmlInfo);
  }  
} 

function RestoreRow(row) 
{ 
  row.style.backgroundColor = normalColor; 
  //hide the popup
  if(row.getAttribute("InfoPanel") != null)
  {
    //exec the javascript function to hide the popup
    HideInfoPanel(row.getAttribute("InfoPanel"));    
  }    
} 

function HideLabelToolTip(toolTipParentID)
{
  var ttID = toolTipParentID + "_lblToolTip";
  
  var toolTipParent = document.getElementById(toolTipParentID);
  if(toolTipParent != null)
  {
    //loop through the childs of the object
	  for (var i=0; i< toolTipParent.childNodes.length; i++) 
	  {
	    //the ID is equal, return that rider
	    if(toolTipParent.childNodes[i].Id == ttID)
	    {
	      //found... then remove
	      toolTipParent.removeChild(toolTipParent.childNodes[i]);
	      break;
	    }
	  } 
  }  
}

function ShowLabelToolTip(text,toolTipParentID)
{
  var toolTip = document.createElement("div");
  toolTip.innerHTML = text;
  toolTip.className = "LabelToolTip";
  toolTip.Id = toolTipParentID + "_lblToolTip";
  
  var toolTipParent = document.getElementById(toolTipParentID);
  if(toolTipParent != null)
  {
    //check if the tooltip wasn't added already
    if(!ChildObjectExists(toolTipParent,toolTip.Id))
    {
      toolTipParent.appendChild(toolTip);
    }
  }  
}

function ChildObjectExists(object,id)
{
   
    //loop through the childs of the object
	  for (var i=0; i< object.childNodes.length; i++) 
	  {
	    //the ID is equal, return that rider
	    if(object.childNodes[i].Id == id)
	    {
	      return true;
	    }
	  }  
	  return false;
}
