function trimAll(sString)
{
  while (sString.substring(0,1) == ' ')
  {
     sString = sString.substring(1, sString.length);
  }
  while (sString.substring(sString.length-1, sString.length) == ' ')
  {
     sString = sString.substring(0,sString.length-1);
  }
  return sString;
}

function checkQuantityInput(inputId,buttonId)
{
  var myinput = inputId.value;
  myinput = myinput.replace(".",",");
  inputId.value = myinput;
  
    
  if(inputId.value.length ==1 && inputId.value == ",")
    inputId.value="0,";
  
  if(inputId.value.length ==1 && inputId.value == "0")
    inputId.value="";
  
  var numericExpression = /^(-)?(\d*)(\,?)(\d*)$/;
	
  if(inputId.value.match(numericExpression)){
    inputId.style.backgroundColor = "white";
    return inputId.value;
  }else{
	  inputId.focus();
    inputId.style.backgroundColor = "#B2211E"; 
    inputId.value="";
    return false;
  }
}
function checkInputForNumbersAndComma(e,id)
{
  var keycode;
  var keychar;
  var numcheck;
  var myid = document.getElementById(id);
  var myinput = myid.value;
  
  if(window.event) // IE
    {
      keycode = window.event.keyCode;
      if(keycode !=8) { 
        if(keycode == 44){
           myinput = myid.value;
           if(myinput.search(/\,/) == -1){
            if(myinput.length == 0)
              document.getElementById(id).value = "0" + myinput;
            else
              document.getElementById(id).value=myinput;
           }
           else
            e.returnValue = false;
         }
        if(keycode == 46){
           keycode = 44;
           myinput = myid.value;
           e.returnValue = false;
           if(myinput.search(/\,/) == -1){
            if(myinput.length == 0)
              document.getElementById(id).value = "0,";
            else
              document.getElementById(id).value=myinput+',';
           }
         }
        myinput = myid.value;
        keychar = String.fromCharCode(keycode);
        if(myinput.search(/\,/) == -1){ 
          numcheck = /^(\d*)(\,?)(\d*)$/;
          return numcheck.test(keychar);
        }
        else{
          numcheck = /^(\d*)(\,?)(\d*)$/;
          return numcheck.test(keychar);
        }
      }
    }
  else if(e.which) // Netscape/Firefox/Opera
    {
      keycode = e.which;
      if(keycode !=8){  
        if(keycode == 44){
           myinput = myid.value;
           if(myinput.search(/\,/) == -1){
              if(myinput.length == 0)
                document.getElementById(id).value = "0" + myinput;
              else
                document.getElementById(id).value = myinput;
            }
           else
              e.preventDefault();
        }
        if(keycode == 46){
           keycode = 44;
           myinput = myid.value;
           e.preventDefault();
           if(myinput.search(/\,/) == -1){
            if(myinput.length == 0)
              document.getElementById(id).value = "0,";
            else
              document.getElementById(id).value=myinput+',';
           }
        }
        /*
        if(keycode == 48){
          //document.getElementById(id).value = "";
          myinput = myid.value;
          alert(myinput);
          if(myinput.length == 0)
          document.getElementById(id).value = "0,";
          e.preventDefault();
        }
        */
        myinput = myid.value;
        keychar = String.fromCharCode(keycode);
        if(myinput.search(/\,/) == -1){ 
          numcheck = /^(\d*)(\,?)(\d*)$/;
          return numcheck.test(keychar);
        }
        else{
          numcheck = /^(\d*)(\,?)(\d*)$/;
          return numcheck.test(keychar);
        }
      }
    }
}
function checkInputForNumbers(e)
{
  var keycode;
  var keychar;
  var numcheck;
  
  if(window.event) // IE
    {
      keycode = window.event.keyCode;
      if(keycode !=8) { 
        keychar = String.fromCharCode(keycode);
        numcheck = /^(\d*)$/;
        return numcheck.test(keychar);
      }
    }
  else if(e.which) // Netscape/Firefox/Opera
    {
      keycode = e.which;
      if(keycode !=8){  
        keychar = String.fromCharCode(keycode);
        numcheck = /^(\d*)$/;
        return numcheck.test(keychar);
      }
    }
}

function FIND(item) {
  if (document.all) return(document.all[item]);
  if (document.getElementById) return(document.getElementById(item));
  return(false);
}

function bookmark(anchor){
  if(window.external) {
    window.external.AddFavorite(anchor.getAttribute('href'), anchor.getAttribute('title'));
    return false;
  }
  return true;
}


var st1;
var st2;
var thetop=-1;
var flagdivvisible=0;
var oMyDiv;
var boxMyDiv;

function writeContentDoc(Doc, TargetId) {
   if(!oMyDiv) oMyDiv=document.createElement("div");
   oMyDiv.innerHTML=Doc;
   var oInsertTarget=document.getElementById(TargetId);
   oInsertTarget.innerHTML=oMyDiv.innerHTML;
}

function writeContentBox(Doc, TargetId) {
   if(!boxMyDiv) boxMyDiv=document.createElement("div");
   boxMyDiv.innerHTML=Doc;
   var oInsertTarget=document.getElementById(TargetId);
   oInsertTarget.innerHTML=boxMyDiv.innerHTML;
}

function writeContent(url, DocTargetId, writeFunc) {
   makeHttpRequest("GET",WebServerScriptUrlSSL+url+'&rand='+Math.floor(Math.random()*1000000),'', false, writeFunc, DocTargetId);
}

function getop(){
  if (navigator.appName == "Netscape") {
    return window.pageYOffset;
  }
  else {
    return (document.body.scrollTop)?document.body.scrollTop:document.documentElement.scrollTop;
  }
}

function refreshlocation(){
    if(flagdivvisible && thetop!=getop()){
      centerDiv();
    }
    if(!flagdivvisible) {
      if(st2) clearTimeout(st2);
      return;
    }
    st2=setTimeout("refreshlocation()",10);
}

function centerDiv(){
  var suffix="";
  if(FIND('divbasketpopup').style.left.indexOf('px')>=0){
    suffix="px";
  }
  FIND('divbasketpopup').style.left=Math.floor((screen.availWidth-280)/2)+suffix;
  FIND('divbasketpopup').style.top=Math.floor(screen.availHeight/2-148)+getop()+suffix;
  thetop=getop();
}

function appendProductURL(formular){
  var urlstr = "";
  var productParams = new Array('ChangeObjectID','ProductID','Quantity');
  for(var i=0;i<productParams.length;i++){
    urlstr += "&"+productParams[i]+"="+eval("formular."+productParams[i]+".value");  
  }
  return urlstr;
}

function divpopup(url,formular){
  url+=appendProductURL(formular);
  writeContent(url,'divbasketpopup','writeContentDoc');  
  if(st1){clearTimeout(st1)};
  centerDiv();
  FIND('divbasketpopup').style.visibility='visible';
  flagdivvisible=1;
  st1=setTimeout("flagdivvisible=0;FIND('divbasketpopup').style.visibility='hidden'",7000);
  refreshlocation();
}

function closedivpopup(){
  FIND('divbasketpopup').style.visibility='hidden';
  flagdivvisible=0;    
}

