
// -----------------------------------------------------------

function Milleteknik_Debug()
{
  eraseCookie('milleCart');
}

//--------------------------------------------------
// Search
//--------------------------------------------------

function Milleteknik_Web_Search(objHandle, eventHandle, searchTextBoxId)
{
  console.log("searchTextBoxId: " + searchTextBoxId);

  if (!eventHandle) var eventHandle = window.event;
  if (eventHandle) eventHandle.cancelBubble = true;
  if (eventHandle.stopPropagation) eventHandle.stopPropagation();

  var searchTextBox = window.document.getElementById(searchTextBoxId);

  if (searchTextBox != null)
  {
    var searchVal = searchTextBox.value;
    window.document.location.href = "/soekresultat.aspx?search=" + searchVal;
    return false;
  }
}

function Milleteknik_Web_SearchKeyDown(objHandle, eventHandle, searchTextBoxId)
{
  console.log("searchTextBoxId: " + searchTextBoxId);

  if (!eventHandle) var eventHandle = window.event;
  if (eventHandle) eventHandle.cancelBubble = true;
  if (eventHandle.stopPropagation) eventHandle.stopPropagation();

  if ((eventHandle.which && eventHandle.which == 13) || (eventHandle.keyCode && eventHandle.keyCode == 13))
  {
    var searchTextBox = window.document.getElementById(searchTextBoxId);

    if (searchTextBox != null)
    {
      var searchVal = searchTextBox.value;
      window.document.location.href = "/soekresultat.aspx?search=" + searchVal;
      return false;
    }
  }
}

//--------------------------------------------------
// Username / Password
//--------------------------------------------------

function replaceUserName_Focus(obj)
{
  if (obj.value == 'Användarnamn')
  {
    obj.value = '';
  }
}

function replaceUserName_Blur(obj)
{
  if (obj.value == '')
  {
    obj.value = 'Användarnamn';
  }
}

var objTxt;
var objPass;

function replacePass_Focus(objTxtId, objPassId)
{
  objTxt = window.document.getElementById(objTxtId);
  objPass = window.document.getElementById(objPassId);

  objTxt.style[ "display"] = "none";
  objPass.style[ "display"] = "";

  setTimeout("objPass.focus();", 10);
}

function replacePass_Blur(objTxtId, objPassId)
{
  objTxt = window.document.getElementById(objTxtId);
  objPass = window.document.getElementById(objPassId);

  if (objPass.value == '')
  {
    objPass.style[ "display"] = "none";
    objTxt.style[ "display"] = "";
  }
}

//--------------------------------------------------
// Login
//--------------------------------------------------

function DoMilleLogin(userName, passWord)
{
  if (userName != null && passWord != null)
  {
    var textboxUsernameServer = window.document.getElementById("ContentPlaceHolderDefault_milleteknikLogin_UserName");
    var textboxPasswordServer = window.document.getElementById("ContentPlaceHolderDefault_milleteknikLogin_Password");
    var btnSubmitServer = window.document.getElementById("ContentPlaceHolderDefault_milleteknikLogin_Login");

    textboxUsernameServer.value = userName;
    textboxPasswordServer.value = passWord;

    eraseCookie('milleCart');

    btnSubmitServer.click();
  }
}

// CustomerCenter:

function Milleteknik_CustomerCenter_Login(textboxUsernameId, textboxPasswordId)
{
  var textboxUsername = window.document.getElementById(textboxUsernameId);
  var textboxPassword = window.document.getElementById(textboxPasswordId);

  if (textboxUsername != null && textboxPassword != null)
  DoMilleLogin(textboxUsername.value, textboxPassword.value);
}

function Milleteknik_CustomerCenter_KeyDown(textboxUsernameId, textboxPasswordId)
{
  if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
  {
    var textboxUsername = window.document.getElementById(textboxUsernameId);
    var textboxPassword = window.document.getElementById(textboxPasswordId);

    if (textboxUsername != null && textboxPassword != null)
    DoMilleLogin(textboxUsername.value, textboxPassword.value);

    /*
    // pop event bubble
    if (!eventHandle) var eventHandle = window.event;
    if (eventHandle) eventHandle.cancelBubble = true;
    if (eventHandle.stopPropagation) eventHandle.stopPropagation();
    */

    //return false;
  }
  else
  {
    return true;
  }
}

// Box:

function Milleteknik_Web_BoxLogin(textboxUsernameId, textboxPasswordId)
{
  var textboxUsername = window.document.getElementById(textboxUsernameId);
  var textboxPassword = window.document.getElementById(textboxPasswordId);

  if (textboxUsername != null && textboxPassword != null)
  DoMilleLogin(textboxUsername.value, textboxPassword.value);
}

function Milleteknik_Web_BoxKeyDown(textboxUsernameId, textboxPasswordId)
{
  if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13))
  {
    var textboxUsername = window.document.getElementById(textboxUsernameId);
    var textboxPassword = window.document.getElementById(textboxPasswordId);

    if (textboxUsername != null && textboxPassword != null)
    DoMilleLogin(textboxUsername.value, textboxPassword.value);

    /*
    // pop event bubble
    if (!eventHandle) var eventHandle = window.event;
    if (eventHandle) eventHandle.cancelBubble = true;
    if (eventHandle.stopPropagation) eventHandle.stopPropagation();
    */

    //return false;
  }
  else
  {
    return true;
  }
}

//--------------------------------------------------
// Shop
//--------------------------------------------------

function AddToCartDialog(nProductID)
{
  var w = 350, h = 160;

  if (document.all || document.layers)
  {
    w = screen.availWidth;
    h = screen.availHeight;
  }

  var popW = 350, popH = 200;

  var leftPos = (w - popW) / 2, topPos = (h - popH) / 2;

  window.open("/laegg-till-i-kundvagn.aspx?id=" + nProductID, "AddToCart", "width=" + popW + ", height=" + popH + ", top=" + topPos + ",left=" + leftPos + ", titlebar=no, toolbar=no, status=no, resizable=no, menubar=no, location=no, scrollbars=no");
}

function AddToCart(nProductID, nAmount)
{
  opener.AddToCartWithAmount(nProductID, nAmount);
  window.close();
}

function AddToCartWithAmount(nProductID, nAmount)
{
  var arrProducts =[];

  if (readCookie('milleCart'))
  {
    var strProducts = readCookie('milleCart');
    arrProducts = strProducts.split(',');
  }

  arrProducts.push(nProductID + "-" + nAmount);
  createCookie("milleCart", arrProducts.toString(), 30);

  document.location.href = document.location.href;
}

function AddToCartWithAmountTextBoxId(nProductID, amountTextBoxId)
{
  var amountTextBoxControl = document.getElementById(amountTextBoxId);
  var nAmount = amountTextBoxControl.value;
  AddToCartWithAmount(nProductID, nAmount);
}

function RemoveFromCart(nCartIndex)
{
  var arrProducts =[];

  if (readCookie('milleCart'))
  {
    var strProducts = readCookie('milleCart');
    arrProducts = strProducts.split(',');

    arrProducts.splice(nCartIndex, 1);
  }

  createCookie("milleCart", arrProducts.toString(), 30);

  document.location.href = document.location.href;
}

function GoCartCheckout_onclick()
{
  document.location.href = "/Kassa.aspx";
}

function MilleCart_Init()
{
  if (readCookie('milleCart'))
  {
    var strImageString = readCookie('milleCart');
    var arrItems = strImageString.split(',');
  }
}

function Milleteknik_SendOrder()
{
  document.location.href = document.location.href + '?s=1';
}

//--------------------------------------------------
// Newsletter
//--------------------------------------------------

function Milleteknik_Newsletter_SignUp(newsletterSignUpDivId)
{
  console.log("Milleteknik_Newsletter_SignUp, newsletterSignUpDivId:" + newsletterSignUpDivId);
  return;

  window.document.getElementById("formid").value = 2;
  window.document.getElementById("bwf").value = "bwf2d962ac86ae24d9e";
  window.document.getElementById("formurl").value = 2;
  window.document.getElementById("formrefurl").value = 2;
  window.document.getElementById("f4E492FA1AD769384D2070E8B72E9DA0F").value = window.document.getElementById("f4E492FA1AD769384D2070E8B72E9DA0F").value;
  window.document.getElementById("f42DEDCBC6B3395CCB27C0724B2587374").value = window.document.getElementById("f42DEDCBC6B3395CCB27C0724B2587374").value;
  window.document.getElementById("f235021692D4372B6653F0E2D9BC257BB").value = window.document.getElementById("f235021692D4372B6653F0E2D9BC257BB").value;

  var formBizWizard = window.document.forms[ "newsletterSignUpQuickForm"];
  formBizWizard.formurl.value = window.document.URL;
  formBizWizard.formrefurl.value = window.document.referrer;
  formBizWizard.submit();

  return false;
}

// Quick (Home Page)

function Milleteknik_Newsletter_SignUpQuick(objHandle, eventHandle, milleteknikSignUpQuickTextBoxId)
{
  var milleteknikSignUpQuickTextBoxCtrl = window.document.getElementById(milleteknikSignUpQuickTextBoxId);
  var milleteknikSignUpQuickImageCtrl = window.document.getElementById("milleteknikSignUpQuickImage");

  //var milleteknikSignUpQuickIFrame = window.document.getElementById("iframeSignUpQuick");

  if (!eventHandle) var eventHandle = window.event;
  if (eventHandle) eventHandle.cancelBubble = true;
  if (eventHandle.stopPropagation) eventHandle.stopPropagation();

  if(milleteknikSignUpQuickTextBoxCtrl != null && milleteknikSignUpQuickImageCtrl != null)
  {
    var strUrl="http://www.kundkommunikation.se/milleteknik/BWHandleForm2.aspx?" +
      "formid=2&bwf=bwf2d962ac86ae24d9e&formurl=www.milleteknik.se&formrefurl=www.milleteknik.se&" +
      "f235021692D4372B6653F0E2D9BC257BB=" + milleteknikSignUpQuickTextBoxCtrl.value + "&fEC6AD626A61BA0A8B563000BDBE0C7EB=1";

    milleteknikSignUpQuickImageCtrl.src = strUrl;

    window.setTimeout("alert('Tack för din anmälan!')", 1000);

    return false;
  }
}

function Milleteknik_Newsletter_SignUpQuick_KeyDown(objHandle, eventHandle, milleteknikSignUpQuickTextBoxId)
{
  console.log("Milleteknik_Newsletter_SignUpQuick_KeyDown, milleteknikSignUpQuickTextBoxId:" + milleteknikSignUpQuickTextBoxId);

  if (!eventHandle) var eventHandle = window.event;
  if (eventHandle) eventHandle.cancelBubble = true;
  if (eventHandle.stopPropagation) eventHandle.stopPropagation();

  if ((eventHandle.which && eventHandle.which == 13) || (eventHandle.keyCode && eventHandle.keyCode == 13))
  {
    return Milleteknik_Newsletter_SignUpQuick(objHandle, eventHandle, milleteknikSignUpQuickTextBoxId);
  }
}

//--------------------------------------------------
// Complaint
//--------------------------------------------------

function Milleteknik_Complaint_Send(complaintDivId)
{
  var complaintDiv = window.document.getElementById(complaintDivId);

  alert("Anmäld! " + complaintDiv);
}

//--------------------------------------------------
// Footer
//--------------------------------------------------

function Milleteknik_FooterScript()
{
  if (window.document.getElementById("loginServerResponse") != null)
  {
    if (window.document.getElementById("loginServerResponseCell") != null)
    {
      window.document.getElementById("loginServerResponseCell").innerHTML = window.document.getElementById("loginServerResponse").innerHTML;
    }
  }

  // ---

  if (document.getElementById("ContentPlaceHolderDefault_milleLoginStatus") != null)
  {
    if (window.document.getElementById("milleLogout") != null)
    {
      window.document.getElementById("milleLogout").href = window.document.getElementById("ContentPlaceHolderDefault_milleLoginStatus").href;
    }

    if (window.document.getElementById("boxLogoutLink") != null)
    {
      window.document.getElementById("boxLogoutLink").href = window.document.getElementById("ContentPlaceHolderDefault_milleLoginStatus").href;
    }
  }
  
    // --- Javascript Slide-Show på förstasidan
  
  if(typeof(startit) != 'undefined')
  {
    if (ie4||dom)
      startit();
    else
      setInterval("rotateimage()",pause)
  }
}

//--------------------------------------------------

