/* ---------------------------------------------------------------------------------------------------
   ---------------------------------------------------------------------------------------------------
   ePages 5 - Scripts $Revision: 1.71.4.2 $
   ---------------------------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

/* ---------------------------------------------------------------------------------------------------
   - General Functions -------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

function openWindow(URL,windowName,features) {
  if(features=="PopUp") {
    features="width=790, height=580, toolbar=no, status=no, resizable=yes, menubar=no, location=no, scrollbars=yes";
  }
  if(features=="PopUpPrint") {
    features="width=790, height=580, toolbar=yes, status=no, resizable=yes, menubar=yes, location=no, scrollbars=yes";
  }
  if(features=="RTE" || windowName=="RTE") {
    features="width=864, height=580, toolbar=no, status=no, resizable=yes, menubar=no, location=no, scrollbars=yes";
  }
  if(features=="HelpWindow") {
    features="width=800, height=580, toolbar=no, status=no, resizable=yes, menubar=no, location=no, scrollbars=yes";
    windowName="WWHFrame";
   }
  if(features=="StylePreview") {
    features="width=470, height=310, toolbar=no, status=no, resizable=no, menubar=no, location=no, scrollbars=no";
    windowName="StylePreview";
   }
  if(features=="DetailedImageView") {
    features="width=800, height=800, toolbar=no, status=no, resizable=yes, menubar=no, location=no, scrollbars=yes";
    windowName="StylePreview";
   }
  if(features=="CheckLink") {
    splittedString = URL.split('//');
    if(splittedString[0].toLowerCase() != "http:") {
      URL ="http://"+URL;
    }
    features="toolbar=yes, status=yes, resizable=yes, menubar=yes, location=yes, scrollbars=yes";
  }

  newwin=window.open(URL,windowName,features);
  newwin.focus();
}


function OnCheckAll( form, name, checked ) {
// used to mark all check boxes in a list as "checked"
    for( var i=0; i<form.length; i++ ) {
        var input = form[i];
        if( input.nodeName == 'INPUT' )
            if( input.type == 'checkbox' && input.name == name && ! input.disabled )
                if( input.checked != checked )
                    input.checked = checked;
    }
}

function DeactivateButton(Button) {
// function to disable an input field
// Button must be an input/button object
     Button.disabled="true";
}

function changeImage(ImageID, ImageURL, ImageTitle) {
// changes the image url & title of an image element (specified by its id attribute)
  document.getElementById(ImageID).src = ImageURL;
  if (ImageTitle) {
    document.getElementById(ImageID).alt = ImageTitle;
  }
}

function OptionToChangeAction(select) {
  select.form.ChangeAction.value = select.options[select.selectedIndex].value;
}

function toggleDisplay(elementId) {
// this function switches the display properties of an element (specified by its id attribute)
// by changing the class name (HideElement / ShowElement)
  if (document.getElementById(elementId).className != 'HideElement') {
    document.getElementById(elementId).className = 'HideElement';
  } else {
    document.getElementById(elementId).className = 'ShowElement';
  }
}

function changeDataById(newdata, id) {
  myobject = document.getElementById(id);
  if(myobject.firstChild) {
    myobject.firstChild.data = newdata;
  } else {
    mydata = document.createTextNode(newdata);
    myobject.appendChild(mydata);
  }
}

function changeSample(newdata, group) {
// this function replaces the data in samp tags (newdata) which are specified
// by their title attributes (group)
    if(!newdata) newdata="";
    sampletags = document.getElementsByTagName("samp");
    for(i=0; i < sampletags.length; i++) {
      if(sampletags[i].getAttribute("title") == group) {
        if(sampletags[i].firstChild) {
          sampletags[i].firstChild.data = newdata;
        } else {
          mydata = document.createTextNode(newdata);
          sampletags[i].appendChild(mydata);
        }
      }
    }
}

function getSelectedData(selectElement) {
// scans all option tags in a select tag to find the data of the selected item
  myNode= selectElement.firstChild;
  while (myNode!=null) {
    if(myNode.value==selectElement.value && myNode.value!="") {
      return myNode.firstChild.data;
    }
    myNode = myNode.nextSibling;
  }
  return "";
}

function checkBrowser() {
   var userAgent = navigator.userAgent.toLowerCase()
   this.isIE = (userAgent.indexOf('msie') != -1);
   this.isGecko = (userAgent.indexOf('gecko') != -1 && userAgent.indexOf('safari') == -1);
   this.isOpera = (userAgent.indexOf('opera') != -1)
   this.isRTECompatible= (this.isIE || this.isGecko);
}

var browser = new checkBrowser();

function disableFormFieldsInElement(ElementId) {
// disables all form fields that are sub elements of a given ElementId
  userattrinputs = document.getElementById(ElementId).getElementsByTagName("input");
  for(i=0; i < userattrinputs.length; i++) {
    userattrinputs[i].disabled=true;
  }
  userattrtextareas = document.getElementById(ElementId).getElementsByTagName("textarea");
  for(i=0; i < userattrtextareas.length; i++) {
    userattrtextareas[i].disabled=true;
  }
  userattrselects = document.getElementById(ElementId).getElementsByTagName("select");
  for(i=0; i < userattrselects.length; i++) {
    userattrselects[i].disabled=true;
  }
}

function enableFormFieldsInElement(ElementId) {
// enables all form fields that are sub elements of a given ElementId
  userattrinputs = document.getElementById(ElementId).getElementsByTagName("input");
  for(i=0; i < userattrinputs.length; i++) {
    userattrinputs[i].disabled=false;
  }
  userattrtextareas = document.getElementById(ElementId).getElementsByTagName("textarea");
  for(i=0; i < userattrtextareas.length; i++) {
    userattrtextareas[i].disabled=false;
  }
  userattrselects = document.getElementById(ElementId).getElementsByTagName("select");
  for(i=0; i < userattrselects.length; i++) {
    userattrselects[i].disabled=false;
  }
}

function allowURLUpload() {
// requires
//   id "FileUpload" on the file upload input field
//   id "FileUpload2" on a hidden input field
  var FileUploadValue=document.getElementById('FileUpload').value;
  if(FileUploadValue.match(/http:../)||FileUploadValue.match(/https:../)){
    document.getElementById('FileUpload2').value=FileUploadValue;
    document.getElementById('FileUpload2').disabled=false;
    document.getElementById('FileUpload').disabled=true;
  }
}
/* ---------------------------------------------------------------------------------------------------
   - Special Functions -------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

function autofillAddress(changedObject) {
// this function fills out the "DisplayName" input field (name="DisplayName") automatically
// this function expects an object with the "changed" data --> CustomerGeneral.TabPage
  changedObject.form.DisplayName.value=changedObject.form.FirstName.value + ' ' + changedObject.form.LastName.value;
  if( changedObject.form.UserAlias ) {
    changedObject.form.UserAlias.value=changedObject.form.FirstName.value.slice(0,1) + changedObject.form.LastName.value;
  }
  if( changedObject.form.UserName ) {
    changedObject.form.UserName.value=changedObject.form.FirstName.value + ' ' + changedObject.form.LastName.value;
  }
}

function SFautofillAddress(FirstNameId, LastNameId, DisplayNameId) {
// this function fills out the "DisplayName" input field (name="DisplayName") automatically
  document.getElementById(DisplayNameId).value=document.getElementById(FirstNameId).value + ' ' + document.getElementById(LastNameId).value;
}

function setCurrentDate(currentDate, targetInputFieldID) {
// this function changes the value of an input field to the current date
  document.getElementById(targetInputFieldID).value=currentDate;
}

/* ---------------------------------------------------------------------------------------------------
   - Image as radioboxes / checkboxes ----------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

function checkMe(imageElement, checkElementName, imageURLactive, imageURLinactive) {
  checkID=imageElement.getAttribute("name");
  checkElements=document.getElementsByName(checkElementName);

  for(i=0; i< checkElements.length; i++) {                        // scan all checkElements in a group
    if(checkElements[i].getAttribute("id") == checkID) {          // change "checked" value
      if(checkElements[i].checked==true) {
        checkElements[i].checked=false;
      } else {
        checkElements[i].checked=true;
      };
      if(checkElements[i].type=="checkbox" && (PlayerStatus==0 || PlayerStatus==1)) {
        SlideShowStop();
      }

    }
  }

  for(i=0; i< checkElements.length; i++) {                        // this time scan all imagesElements in a group
    imageName=checkElements[i].getAttribute("id");
    imageInGroup = document.getElementsByName(imageName)[0];
    if(checkElements[i].checked == true) {
      imageInGroup.src=imageURLactive;
    } else {
      imageInGroup.src=imageURLinactive;
    }
  }
}

/* ---------------------------------------------------------------------------------------------------
   - Image Preview -----------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

var preloadInterval ="";

function preloadImage(ImageID) {
// ---------------------------------------------------------------------------------------------------
// preloadImage([id of an img tag])
// ---------------------------------------------------------------------------------------------------
// This function can be used in the previewArea only!
// It tests if the download of an image is complete. On positive result it:
//  - displays the image by changing its display properties
//  - changes the size of large images
//  - removes its own interval
//
// Usage example:
// if(preloadInterval!="") clearInterval(preloadInterval);            // remove possible old interval
// preloadInterval = setInterval("preloadImage('"+ImageID+"')",100);  // start this function in an interval

//settings for height and width according to source of functioncall
var ImgWidth = 190;
var ImgHeight= 140;
if(Caller == 1)
{
ImgWidth = 200;
ImgHeight = 200;
}


  if(document.getElementById(ImageID).complete) {                     // do nothing while the image is not uploaded yet

// create dummy image to get (non-cached) image width & height
    testImage=document.createElement("img");
    testImage.src=document.getElementById(ImageID).src;

    percent = 100;
    if(testImage.width != 0) {                                        // do nothing while the width is unset
      document.getElementById(ImageID).style.display="block";
      if(testImage.width> ImgWidth || testImage.height> ImgHeight) {
// resize large images
        horPercent = 100*ImgWidth/testImage.width;
        verPercent = 100*ImgHeight/testImage.height;
        if(horPercent > verPercent) {
            document.getElementById(ImageID).height =ImgHeight;
            document.getElementById(ImageID).width =testImage.width * verPercent / 100;
            percent = verPercent;
        }  else {
            document.getElementById(ImageID).width =ImgWidth;
            document.getElementById(ImageID).height =testImage.height * horPercent / 100;
            percent = horPercent;
        }
      } else {
// reset image sizes for 1:1 Images
        document.getElementById(ImageID).width = testImage.width;
        document.getElementById(ImageID).height = testImage.height;
      }
// calculate new postion
      newMarginLeft = document.getElementById(ImageID).width/2;
      newMarginTop = document.getElementById(ImageID).height/2;

      if (!browser.isOpera)
      {
        document.getElementById(ImageID).style.left="50%";
        if(browser.isIE && Layout == 'Broad')
        {document.getElementById(ImageID).style.left="10%";}
        document.getElementById(ImageID).style.top="50%";
        document.getElementById(ImageID).style.marginLeft="-"+newMarginLeft+"px";
        document.getElementById(ImageID).style.marginTop="-"+newMarginTop +"px";
      }
      else
      {
        document.getElementById(ImageID).style.margin='auto';
      }

      newTextnode= document.createTextNode("("+Math.floor(percent)+"%)");
      document.getElementById("Percentage").replaceChild(newTextnode, document.getElementById("Percentage").firstChild);
      document.getElementById("Loading").style.display="none";
      document.getElementById("Percentage").style.display="inline";
      clearInterval(preloadInterval);
    }
  }
}

function changePreviewImage(ImageID, ImageURL, ImageTitle) {
// changes the PreviewImage in the PreviewArea and starts the image preloader
  changeImage(ImageID, ImageURL, ImageTitle);
  document.getElementById(ImageID).style.display="none";      // hide preview image while loading
  document.getElementById("Loading").style.display="inline";  // display Loading info
  document.getElementById("Percentage").style.display="none"; // hide image size while loading

  if(preloadInterval!="") clearInterval(preloadInterval);
  preloadInterval = setInterval("preloadImage('"+ImageID+"')",100);
}

function resizeImage(ImageID, ImgWidth, ImgHeight)
{
  if(document.getElementById(ImageID).complete==true)
    {
    testImage=document.createElement("img");
    testImage.src=document.getElementById(ImageID).src;

    percent = 100;
    if(testImage.width != 0)              // do nothing while the width is unset
      {
      document.getElementById(ImageID).style.display="block";
        if (testImage.width< ImgWidth)
        {
            document.getElementById(ImageID).width = testImage.width;
            document.getElementById(ImageID).height = testImage.height;
          }
      }
    document.getElementById(ImageID).style.display="inline";
    newMarginLeft = document.getElementById(ImageID).width/2;
    newMarginTop = document.getElementById(ImageID).height/2;
    if (((!browser.isOpera)&&(testImage.height < ImgHeight))||((testImage.height < testImage.width)&&(!browser.isOpera)))
      {
       document.getElementById(ImageID).style.top="0";
       if(testImage.height < testImage.width)
       {document.getElementById(ImageID).style.marginTop = (ImgHeight/2) - (((ImgWidth*testImage.height)/testImage.width)/2) +"px";}
       else
       {document.getElementById(ImageID).style.marginTop = ImgHeight/2 - testImage.height/2 +"px";}
      }
    else
      {
      document.getElementById(ImageID).style.margin='auto';
      }
    }
    else
    {
      setTimeout("resizeImage('"+ImageID+"', 150, 150)",100);
    }
}

/* ---------------------------------------------------------------------------------------------------
   - SlideShow (BackOffice) --------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

var PlayerArray = new Array();
var PlayerCount=0;
var PlayerListLength =0;
var PlayerStatus = -1; // -1 = not started (initial), 0 = rotate, 1= stop
var PlayerInterval ="";
var Caller=0;


 // The player can be started by calling:
 // function SlideShowPlay(string)
 // function SlideShowSkip(integer, string);

 function initPlayer(productImagePath) {
 // This function scans all hidden checkboxes on the current page with the
 // name attribute "ImageSlideShow" and if the checkbox is "checked" the image
 // will be added to an image array
   imageArray=new Array();
   for(i =0; i<document.getElementsByName("ImageSlideShow").length; i++) {
      if(document.getElementsByName("ImageSlideShow")[i].checked==true) {
        // - The id attribute (of these checkboxes) contains an img identifier eg. "file_lii_1" "external_ssi_2".
        // - Depending on the first part oft the id the slideshow can make a difference between files on "our" server and an external URL
        //   file - files on "our" server
        //   external - an external URL
        var idcheck = document.getElementsByName("ImageSlideShow")[i].getAttribute("id");
        var splitter = idcheck.split('_');
        if(splitter[0]!="external") {
          fileName=productImagePath+document.getElementsByName("ImageSlideShow")[i].value;
        } else {
          fileName=document.getElementsByName("ImageSlideShow")[i].value;
        }
        // Create new Image
        bild = new Image();
        bild.src=fileName;
        // Add Image to the Image Array
        imageArray.push(bild);
      }
   }
   // return the Image Array
   return imageArray;
 }

 function rotatePicture() {
   if (PlayerStatus==0 && PlayerListLength>0) {
		 PlayerCount++;
		 if (PlayerCount==PlayerListLength) PlayerCount=0;
		 if (PlayerCount<0) PlayerCount=PlayerListLength-1;

     changePreviewImage("PreviewImage", PlayerArray[PlayerCount].src, PlayerArray[PlayerCount].src)

     if(PlayerInterval!="") clearInterval(PlayerInterval);
		 PlayerInterval = setInterval("rotatePicture()", 2000);
	 }
 }

function SlideShowInit(productImagePath){
  PlayerArray = initPlayer(productImagePath);
  PlayerListLength = PlayerArray.length;
  PlayerCount=-1;
  var Caller = 0;
  if (PlayerStatus==0) rotatePicture();
}

function SlideShowPlay(productImagePath){
   if (PlayerStatus==-1) {
     PlayerStatus=0;
	   SlideShowInit(productImagePath);
	 } else {
     PlayerStatus=0;
	   rotatePicture();
	 }
}

 function SlideShowSkip(direction, productImagePath) {
   if (PlayerStatus==-1) {
	   SlideShowInit(productImagePath);
   }
   PlayerStatus=1;                                                // stop Slide Show Player
   if(preloadInterval!="") clearInterval(preloadInterval);        // stop preload interval
   if(PlayerArray.length>0) {
     PlayerCount=PlayerCount+direction;
  	 if (PlayerCount==PlayerListLength) PlayerCount=0;
     if (PlayerCount<0) PlayerCount=PlayerListLength-1;

     changePreviewImage("PreviewImage", PlayerArray[PlayerCount].src, PlayerArray[PlayerCount].src)
   }
 }


function SlideShowPause(){
   PlayerStatus=1;
}

function SlideShowStop(){
        PlayerStatus=-1;                                               // stop Slide Show Player
        if(preloadInterval!="") clearInterval(preloadInterval);        // stop preload interval
        document.getElementById("PreviewImage").style.display="none";  // hide preview image if slideshow is running
        document.getElementById("Loading").style.display="none";       // hide Loading info
        document.getElementById("Percentage").style.display="none";    // hide image size while loading
}

/* ---------------------------------------------------------------------------------------------------
   - Dialog Area -------------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

var actualDialogArea = "";
var epagesDialog = new DialogArea();

function DialogArea() {
//  this function is used as constructor for an DialogArea-Object
  this.areaName = new Array();
  this.areaId = new Array();

  this.addArea = function(areaName, areaId) {
  //  this function is used to register the areas in a dialog
    this.areaName.push(areaName);
    this.areaId.push(areaId);
  }

  this.showArea = function(areaName) {
  //  this function is used to show an Area
    areaId="";
  // search for the AreaName in the epagesDialog Object
    for(i=0; i < this.areaName.length; i++) {
      if(this.areaName[i] == areaName) areaId = this.areaId[i];
    }
    document.getElementsByName(areaName)[0].className = 'ShowArea';
    document.getElementById(areaId).className='ShowElement';
    actualDialogArea = areaName;
  }

  this.hideArea = function(areaName) {
  //  this function is used to show an Area
    areaId="";
  // search for the AreaName in the epagesDialog Object
    for(i=0; i < this.areaName.length; i++) {
      if(this.areaName[i] == areaName) areaId = this.areaId[i];
    }
    document.getElementsByName(areaName)[0].className = 'HideArea';
    document.getElementById(areaId).className='HideElement';
    actualDialogArea = "";
  }

  this.toggleArea = function(areaName) {
  //  this function is used to toggle the view of an area
  //  and to hide all unselected areas
    if(actualDialogArea!=areaName) {
      this.showArea(areaName);
    } else {
      this.hideArea(areaName);
    }
  // loop through all dialog areas and hide them
    for(i=0; i<this.areaName.length; i++) {
      tempName=this.areaName[i]; tempId=this.areaId[i];
      if(areaName != tempName) {
        document.getElementsByName(tempName)[0].className = 'HideArea';
        document.getElementById(tempId).className = 'HideElement';
      }
    }
  }

  this.toggleAreaDisplay = function(areaName) {
  // this function is used to toggle the view of the specified area
  // display settings of other areas remain
    if(document.getElementsByName(areaName)[0].className == 'HideArea') {
      this.showArea(areaName);
    } else {
      this.hideArea(areaName);
    }
  }

  this.selectArea = function(areaName) {
  //  this function is used to show the selected area
  //  and to hide all the other areas
    this.showArea(areaName);
  // loop through all dialog areas and hide them
    for(i=0; i<this.areaName.length; i++) {
      tempName=this.areaName[i]; tempId=this.areaId[i];
      if(areaName != tempName) {
        document.getElementsByName(tempName)[0].className = 'HideArea';
        document.getElementById(tempId).className = 'HideElement';
      }
    }
  }

}

function appendDialogArea(formElement) {
  if(actualDialogArea!="") {
    formElement.action += "&DialogArea="+actualDialogArea;
  }
}

function toggleLink(LinkName){
  if(document.getElementsByName(LinkName)[0].className == 'ShowLink')
    {document.getElementsByName(LinkName)[0].className = 'HideLink';}
  else
    {document.getElementsByName(LinkName)[0].className = 'ShowLink';}
}

/* ---------------------------------------------------------------------------------------------------
   - Layout Selector ---------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

function highlightNavbar(box) {
  // mouseover effect
  classNames=box.className;
  classNamesArray=classNames.split(" ");
  firstClassName=classNamesArray[0];
  if(classNamesArray.length>1) {                                       // show mouseovereffect only if Navbar isn't selected
    if(classNamesArray[1]!="SelectedBoxMarker") {
      box.className=firstClassName+" MouseOverColor";
    }
  } else {
    box.className=firstClassName+" MouseOverColor";
  }
}

function resetNavbar(box) {
  // mouseover effect
  classNames=box.className;
  classNamesArray=classNames.split(" ");
  firstClassName=classNamesArray[0];
  secondClassName="";
  if(classNamesArray.length>1) {                                      // reset Navbar color only if it isn't selected
    secondClassName=classNamesArray[1];
    if(secondClassName=="SelectedBoxMarker") {
      secondClassName=" SelectedBoxMarker";
    } else {
      secondClassName="";
    }
  }
  box.className=firstClassName+secondClassName;
}

function selectNavbar(box) {
  // unselect all bars

    try{document.getElementById("Header").className="Header";} catch(exception) {  }
    try{document.getElementById("Top").className="Top";} catch(exception) {  }
    try{document.getElementById("Left").className="Left";} catch(exception) {  }
    try{document.getElementById("Content").className="Content";} catch(exception) {  }
    try{document.getElementById("Right").className="Right";} catch(exception) {  }
    try{document.getElementById("Bottom").className="Bottom";} catch(exception) {  }
    try{document.getElementById("Footer").className="Footer";} catch(exception) {  }

  // set class "SelectedBoxMarker" for selected bar
  classNames=box.className;
  firstClassName=classNames.split(" ")[0];
  box.className=firstClassName+" SelectedBoxMarker";
}

/* ---------------------------------------------------------------------------------------------------
   - Layout Designer ---------------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

function toggleNavbarDisplay(navbarStatus, elementName) {
// this function switches the display properties of an navbar element (specified by its name attribute)
  if(navbarStatus) {
    document.getElementById(elementName + 'IsVisible').value= '1';
    for(i=0; i<document.getElementsByName('Navbar' + elementName).length; i++) {
        document.getElementsByName('Navbar' + elementName)[i].style.display='';
    };
  } else {
    document.getElementById(elementName + 'IsVisible').value= '0';
    for(i=0; i<document.getElementsByName('Navbar' + elementName).length; i++) {
        document.getElementsByName('Navbar' + elementName)[i].style.display='none';
    };
  }
}

/* ---------------------------------------------------------------------------------------------------
   - MBO Search (Toolbar) ----------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */
function toggleExtender(object){
  // toggles between the image file names of the extend button
  // object => image node
  splittedFilename=object.src.split("/");
  lastItemNo=splittedFilename.length-1;
  lastItem=splittedFilename[lastItemNo];

  if(lastItem=="toolbar_ico_s_extend.gif") {
    splittedFilename[lastItemNo]="toolbar_ico_s_extend_open.gif";
  } else {
    splittedFilename[lastItemNo]="toolbar_ico_s_extend.gif";
  }
  object.src=splittedFilename.join("/");
}

/* ---------------------------------------------------------------------------------------------------
   - Order Search (Toolbar) --------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

// Reset functions

function clearOrderSearchForm() {
  orderSearchResetHiddenInputs();
  orderSearchResetSelectors();
  document.getElementById("CreationDateFrom").value="";
  document.getElementById("CreationDateTo").value="";
  document.getElementById("OrderAliasString").value="";
  document.getElementById("ProductAliasString").value="";
}

// Reset function for TpayTransactionsSearch
function clearTpaySearchForm(){
  document.getElementById("TransIDString").value="";
  document.getElementById("TransStatus").value="";
  document.getElementById("TransTimeFrom").value="";
  document.getElementById("TransTimeTo").value="";
}

// Reset function for WorldPayTransactionsSearch
function clearWorldPaySearchForm(){
  document.getElementById("TransIDString").value="";
  document.getElementById("TransTimeFrom").value="";
  document.getElementById("TransTimeTo").value="";
}

function orderSearchResetSelectors() {
  document.getElementById("StatusSelector1").value="";
  document.getElementById("StatusSelector2").value="";
  document.getElementById("StatusSelector3").value="";
  document.getElementById("StatusSelector4").value="";
}

function orderSearchResetHiddenInputs() {
  document.getElementById("ViewedOn").value='0';
  document.getElementById("CancelledOn").value='0';
  document.getElementById("InProcessOn").value='0';
  document.getElementById("PendingOn").value='0';
  document.getElementById("ReadyForShippingOn").value='0';
  document.getElementById("DispatchedOn").value='0';
  document.getElementById("ShippedOn").value='0';
  document.getElementById("PaidOn").value='0';
  document.getElementById("ClosedOn").value='0';
  document.getElementById("ArchivedOn").value='0';
}

function orderSearchSetValue(value) {
// This function sets the value of an hidden inputfield
// value => string (e.g ViewedOn, NotViewedOn -> There must be an hidden Inputfield with the id ViewedOn)
// strings containing Not -> value = 2
// other strings -> value = 1
  tempValueArray=value.split("Not");
  if(tempValueArray.length==1) {
    document.getElementById(tempValueArray[0]).value='1';
  } else {
    document.getElementById(tempValueArray[1]).value='2';
  }
}

function orderSearchSetHiddenInput() {
// This function resets all hidden inputfields and refreshes their values (depending on the Status Selectors)
  orderSearchResetHiddenInputs();
  value1= document.getElementById("StatusSelector1").value;
  value2= document.getElementById("StatusSelector2").value;
  value3= document.getElementById("StatusSelector3").value;
  value4= document.getElementById("StatusSelector4").value;

  if(value1) orderSearchSetValue(value1);
  if(value2) orderSearchSetValue(value2);
  if(value3) orderSearchSetValue(value3);
  if(value4) orderSearchSetValue(value4);
}

// Initialize Toolbar Form

var SelectorCount =0;

function orderSearchInitSelectors() {
  if(document.getElementById("ProductAliasString").value != "" ) SelectorCount=2;
  if(document.getElementById("StatusSelector2").value != "" ) SelectorCount=2;
  if(document.getElementById("StatusSelector3").value != "" ) SelectorCount=2;
  if(document.getElementById("StatusSelector4").value != "" ) SelectorCount=2;
  if(SelectorCount>1){
    toggleExtender(document.getElementById("ExtendImage"));toggleDisplay('ExtendedSearch');
  }
}

/* ---------------------------------------------------------------------------------------------------
   - Customer Search (Toolbar) -----------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

// Reset functions

function clearCustomerSearchForm() {
  document.getElementById("CustomerNameString").value="";
  document.getElementById("CustomerAliasString").value="";
  document.getElementById("EMailString").value="";
  document.getElementById("CustomerStreetString").value="";
  document.getElementById("CustomerZipcodeString").value="";
  document.getElementById("CustomerCityString").value="";
  document.getElementById("CustomerGroupID").value="";
  document.getElementById("UserAliasString").value="";
  document.getElementById("Revenue").value="";
  document.getElementById("CurrencyID").value="";
  document.getElementById("RevenueFrom").value="";
  document.getElementById("RevenueTo").value="";
  document.getElementById("ProductAliasString").value="";
  document.getElementById("ProductFrom").value="";
  document.getElementById("ProductTo").value="";
}


function customerSearchInit() {
  extended=0;
  if(document.getElementById("CustomerStreetString").value  !="") extended=1;
  if(document.getElementById("CustomerZipcodeString").value !="") extended=1;
  if(document.getElementById("CustomerCityString").value    !="") extended=1;
  if(document.getElementById("CustomerGroupID").value       !="") extended=1;
  if(document.getElementById("UserAliasString").value       !="") extended=1;
  if(document.getElementById("Revenue").value               !="") extended=1;
  if(document.getElementById("RevenueFrom").value           !="") extended=1;
  if(document.getElementById("RevenueTo").value             !="") extended=1;
  if(document.getElementById("ProductAliasString").value    !="") extended=1;
  if(document.getElementById("ProductFrom").value           !="") extended=1;
  if(document.getElementById("ProductTo").value             !="") extended=1;
  if(extended==1){
    toggleExtender(document.getElementById("ExtendImage"));toggleDisplay('ExtendedSearch');
  }
}

/* ---------------------------------------------------------------------------------------------------
   - Product Search (Toolbar) ------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */

function toggleToStockLevelSearch() {
  document.getElementById("MBO-StockLevel").className = 'ShowInlineElement';
  document.getElementById("MBO-AllStrings").className = 'HideElement';
  document.getElementById("MBO-StockLevel-Icon").className = 'ShowInlineElement';
  document.getElementById("MBO-AllStrings-Icon").className = 'HideElement';
  document.getElementById("Search").value="MBO-StockLevel";
}

function toggleToAllStringsSearch() {
  document.getElementById("MBO-StockLevel").className = 'HideElement';
  document.getElementById("MBO-AllStrings").className = 'ShowInlineElement';
  document.getElementById("MBO-StockLevel-Icon").className = 'HideElement';
  document.getElementById("MBO-AllStrings-Icon").className = 'ShowInlineElement';
  document.getElementById("Search").value="MBO-AllStrings";
}

// Reset Functions

function clearProductSearchForm() {
  document.getElementById("IsVisible").value="";
  document.getElementById("Visibility").value="";
  document.getElementById("ClassID").value="";
  document.getElementById("Alias").value="";
  document.getElementById("SearchString").value="";
  document.getElementById("StockLevel").value="";
  document.getElementById("StockWarn").checked=false;
}

// Set Values

function productSearchSetValue(value) {
// This function resets and sets the (new) value of an hidden inputfield
// value => string (e.g IsVisible, NotIsVisible
// value strings containing "Not" -> value = 2
// other strings -> value = 1
  document.getElementById("IsVisible").value='';
  if(value) {
    tempValueArray=value.split("Not");
    if(tempValueArray.length==1) {
      document.getElementById("IsVisible").value='1';
    } else {
      document.getElementById("IsVisible").value='2';
    }
  }
}

/* ---------------------------------------------------------------------------------------------------
   - Shop Search (Toolbar) ---------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */
// Reset Functions

function clearShopSearchForm() {
  document.getElementById("Alias").value="";
  document.getElementById("ShopTypeID").value="";
  document.getElementById("StoreID").value="";
  document.getElementById("IsClosed").checked=false;
  document.getElementById("IsDeleted").value="";
}

/* -----------------------------------------------------------------------------------------
   - Newsletter + Ebay ---------------------------------------------------------------------
   ----------------------------------------------------------------------------------------- */

  function addTLE( tlename, elementId ) {
      insertAtCursor( window.document,
                      window.document.getElementById( elementId ),
                      "#" + tlename );
  }
  function addString( str, elementId ) {
      insertAtCursor( window.document,
                      window.document.getElementById( elementId ),
                      str );
  }
  function insertAtCursor(myDoc, myField, myValue) {
    //IE support
    if (myDoc.selection) {
      myField.focus();
      sel = myDoc.selection.createRange();
      sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == '0') {
      var startPos = myField.selectionStart;
      var endPos = myField.selectionEnd;
      myField.value = myField.value.substring(0, startPos)
                    + myValue
                    + myField.value.substring(endPos, myField.value.length);
      myField.selectionStart = startPos + myValue.length;
      myField.selectionEnd = startPos + myValue.length;
    } else {
      myField.value += myValue;
    }
  }

/* -----------------------------------------------------------------------------------------
   - Ebay ----------------------------------------------------------------------------------
   ----------------------------------------------------------------------------------------- */
  function useBuyItNow(form, isEnabled) {
  // function for Wizard-Page: MBO-ViewEbayWizardDetailsStep
  // BuyItNow activated -> Quntity =1, IsPrivate = disabled and select "no"
    if (isEnabled) {
      form.Quantity.value=1;
      form.Quantity.disabled=true;
      if (form.BuyItNowPrice != null) {
        form.BuyItNowPrice.disabled=false;
      }
      form.IsPrivate[0].checked=true;
      form.IsPrivate[0].disabled=true;
      form.IsPrivate[1].disabled=true;
    } else {
      form.Quantity.disabled=false;
      if (form.BuyItNowPrice != null) {
        form.BuyItNowPrice.disabled=true;
      }
      form.IsPrivate[0].disabled=false;
      form.IsPrivate[1].disabled=false;
    }
  }

/* ---------------------------------------------------------------------------------------------------
   - Ebay Search (Toolbar) ---------------------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */
// Reset Functions

function clearEbaySearchForm() {
  document.getElementById("Status").value="";
  document.getElementById("EbayShopEnvironment").value="";
  document.getElementById("ExternalAuctionIdString").value="";
  document.getElementById("StartTimeFrom").value="";
  document.getElementById("StartTimeTo").value="";
  document.getElementById("EndTimeFrom").value="";
  document.getElementById("EndTimeTo").value="";
}

/* ---------------------------------------------------------------------------------------------------
   - eBay Statistics Search (Toolbar/PBO) ------------------------------------------------------------
   --------------------------------------------------------------------------------------------------- */
// Reset Functions

function clearEbayStatisticsSearchForm() {
  document.getElementById("EbayCallType").value="0";
  document.getElementById("EbayEnvironment").value="0";
  document.getElementById("DateFrom").value="";
  document.getElementById("DateTo").value="";
  document.getElementById("Interval").value="1";
  document.getElementById("IntervalType").value="DAYS";
}

