// Extension of the String object by trim command
  String.prototype.leftTrim = function () {
    return (this.replace(/^\s+/,""));
  };
  String.prototype.rightTrim = function () {
    return (this.replace(/\s+$/,""));
  };
//kombiniert "leftTrim" und "rightTrim";
  String.prototype.basicTrim = function () {
    return (this.replace(/\s+$/,"").replace(/^\s+/,""));
  };
//dampft leerzeichen(-sequenzen) innerhalb einer zeichenkette auf ein einzelnes "space" ein;
  String.prototype.superTrim = function () {
    return(this.replace(/\s+/g," ").replace(/\s+$/,"").replace(/^\s+/,""));
  };

//zugabe: entfernt alle leerzeichen aus einer zeichenkette;
  String.prototype.removeWhiteSpaces = function () {
    return (this.replace(/\s+/g,""));
  };


function bindContentToggleAction( buttonIdMin, buttonIdMax, contentId ){
  //initial hide MaxButton
  $(buttonIdMax).hide();
    $(buttonIdMin).click(function () {
        $(contentId).hide();
        $(this).hide();
        $(buttonIdMax).show();
    });
    
    $(buttonIdMax).click(function () {
        
        $(contentId).show();
        $(this).hide();
        $(buttonIdMin).show(); 
    });
}


//todo: check how to archive that all cells rollover when just one is selected.
//classname with dot: e.g. .classname
//overClass without dot: e.g. over
function createRolloverElement(classname, overClass){

   var clicked = false;
   
   $(classname).hover(function(){
      $(this).addClass(overClass);
      $(this).next().addClass('overR');
      $(this).prev().addClass('overL');
      }
    ,function(){         
      $(this).removeClass(overClass);
      $(this).next().removeClass('overR');
      $(this).prev().removeClass('overL');
    });
  $(classname).click(function(){
      // add extra css class to prohibit that the hover effect will clear the active effect.
      $(classname).removeClass(overClass+'s');
      $(classname).next().removeClass('overRs');
      $(classname).prev().removeClass('overLs');
      $(this).addClass(overClass+'s');
      $(this).next().addClass('overRs');
      $(this).prev().addClass('overLs');
      
      if((this.id == "orgButton")||
          (this.id == "tranButton")||
          (this.id == "destButton")||
          (this.id == "discButton")
        )
      {
        $("#cdmpWarningFilterText").addClass('cdmpShow');
      }
      else
      {
        $("#cdmpWarningFilterText").removeClass('cdmpShow');
      }
      
  });
}

function activeTab(tabID){
  //clear all Tab Buttons
  $(".cdmpTabItemM").removeClass('overMs');
  $(".cdmpTabItemM").next().removeClass('overRs');
  $(".cdmpTabItemM").prev().removeClass('overLs');
  $(tabID).addClass('overMs');
  $(tabID).next().addClass('overRs');
  $(tabID).prev().addClass('overLs');
  
  if((tabID == "#orgButton")||
    (tabID == "#tranButton")||
    (tabID == "#destButton")||
    (tabID == "#discButton")
    )
  {
    $("#cdmpWarningFilterText").addClass('cdmpShow');
  }
  else
  {
    $("#cdmpWarningFilterText").removeClass('cdmpShow');
  }
}

//todo: check how to archive that all cells rollover when just one is selected.
//classname with dot: e.g. .classname
//overClass without dot: e.g. over
// just rollover effect. clicked effect won´t change anything
function createRolloverElement2(classname, overClass){

   var clicked = false;
   
   $(classname).hover(function(){
      $(this).addClass(overClass);
      $(this).next().addClass('overR');
      $(this).prev().addClass('overL');
      }
    ,function(){         
      $(this).removeClass(overClass);
      $(this).next().removeClass('overR');
      $(this).prev().removeClass('overL');
    });
  
}

function activateTabButton(tab){
  if(tab == 1)
  {
    //activate 1
    activateTab("#cdmpButton1");
  }
  else if(tab == 2)
  {
    //activate 2
    activateTab("#cdmpButton2");
  }
  else if(tab == 3)
  {
    //activate 3
    activateTab("#cdmpButton3");
  }
  else if(tab == 4)
  {
    //activate 4
    activateTab("#cdmpButton4");
  }
  else
  {
    //deactivate all
  }
}
function activateTab(tab)
{
  $(tab).addClass('overMs');
    $(tab).next().addClass('overRs');
    $(tab).prev().addClass('overLs');
}
  
function toggleSubmenu( subMenuID, subMenuItems) {
  
    $(subMenuID).bind("mouseenter",function(){
             hideAllSubmenues();
             $(subMenuItems).show();//}
//          ,function(eventObj){//alert(eventObj.target +"::"+ subMenuItems);
           //if (eventObj.relatedTarget.id != subMenuItems) 
           //$(subMenuItems).hide();
          });
    $(subMenuItems).bind("mouseleave",function(){
             $(subMenuItems).show();//}
//          ,function(eventObj){//alert(eventObj.target +"::"+ subMenuItems);
           //if (eventObj.relatedTarget.id != subMenuItems) 
           $(subMenuItems).hide();
          });
}


//activation of menu rollover effect for triangle graphic

function registerNavigationRollover(menuID, TriangleID) {

  $(menuID).hover(function(){
        imgsrc = $(TriangleID).attr("src");
        matches = imgsrc.match(/Over/);
        clicked = false;
        if (!matches) {
          imgsrcON = imgsrc.replace(/.gif$/,"Over.gif");
          $(TriangleID).attr("src", imgsrcON);
        }
      }
        ,function(){
        if(!clicked)
        {
          imgsrcOFF = imgsrcON.replace(/Over.gif$/,".gif");
          $(TriangleID).attr("src", imgsrcOFF);
        }
      });
      
    
    $(menuID).click(function(){
    
        clicked = true;
        imgsrc = $(TriangleID).attr("src");
        imgsrcOFF = imgsrc.replace(/Over.gif$/,".gif");
      
      if(TriangleID == '#Menu1Triangle')
      {
        $(TriangleID).attr("src", imgsrc);
        $('#Menu2Triangle').attr("src", imgsrcOFF);
        $('#Menu3Triangle').attr("src", imgsrcOFF);
      }
      else if(TriangleID == '#Menu2Triangle')
      {
        $(TriangleID).attr("src", imgsrc);
        $('#Menu1Triangle').attr("src", imgsrcOFF);
        $('#Menu3Triangle').attr("src", imgsrcOFF);
      }
      else if(TriangleID == '#Menu3Triangle')
      {
        $(TriangleID).attr("src", imgsrc);
        $('#Menu1Triangle').attr("src", imgsrcOFF);
        $('#Menu2Triangle').attr("src", imgsrcOFF);
      }
    });  
}


function createRowHighlighting(tableID, hiddenID) {
  hiddenID = hiddenID || 0;
  //jquery even != tablesorter even row. 

  $(tableID+" > tbody tr:odd").click(function(){
    hasHighlight = $(this).hasClass('highlight');
    $(tableID+" > tbody tr").removeClass('highlight');
    $(tableID+" > tbody tr:even").addClass('even');
    $(tableID+" > tbody tr:odd").addClass('odd');
    if(!hasHighlight)
    {
     $(this).addClass('highlight');
    } 
  }).dblclick(function(){
        if(hiddenID != 0){
          $(hiddenID).trigger('click');
        }
        if($(this).hasClass('highlight')==false){
          $(this).click();
        }
  });

  $(tableID+" > tbody tr:even").click(function(){
    hasHighlight = $(this).hasClass('highlight');
    $(tableID+" > tbody tr").removeClass('highlight');
    $(tableID+" > tbody tr:odd").addClass('odd');
    $(tableID+" > tbody tr:even").addClass('even');
    if(!hasHighlight)
    {
     $(this).addClass('highlight');
    }
  }).dblclick(function(){
        if(hiddenID != 0){
          $(hiddenID).trigger('click');
        }
        if($(this).hasClass('highlight')==false){
          $(this).click();
        }
  });
      

}

function checkAwb(){
    var msg="";
    document.form_awb.awbnumber.value=document.form_awb.awbnumber.value.basicTrim();
      var re = new RegExp("^([0-9]{3})?-?[0-9]{8}$"); 
	  if (document.form_awb.awbnumber.value.match(re)) {
	    return true;
	  } else {
		alert (" AWB number seems to be invalid\n");
		document.form_awb.awbnumber.select();
	  }
	return false;
}

/* Begin Paging Tool */
/* marker if some rows have changed*/
var hasChanged=0;
function checkChanged(){
	if(this["selitem"]==undefined){
		if (hasChanged==1&&!confirm("Data has been changed! Continue?\nChanges on edited items will be lost.")){
			return false;
		}
	} else {
		if ((selitem>=0||hasChanged==1)&&!confirm("There is a row in edit Mode or data has been changed! Continue?\nChanges on edited items will be lost.")){
			return false;
		}
	}
	return true;
}

function doPaging(actionurl){
	if(checkChanged()){
		window.location.href=actionurl;
	}
}
/* End Paging Tool */
