function Trim(str){
str=str.replace(/(^[\s\u3000]*)|([\s\u3000]*$)/g, "");
return str;
}

function IsPositiveFloat(_str){
var tmp_str = Trim(_str);
var pattern = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/; 
return pattern.test(tmp_str); 
}

function isFloat(val) {
    if(!val || (typeof val != "string" || val.constructor != String)) {
      return(false);
    }
    var isNumber = !isNaN(new Number(val));
    if(isNumber) {
      if(val.indexOf('.') != -1) {
        return(true);
      } else {
        return(false);
      }
    } else {
      return(false);
    }
  }
  function isPositiveInteger(val){
      if(val==null){return false;}
      if (val.length==0){return false;}
      for (var i = 0; i < val.length; i++) {
            var ch = val.charAt(i)
            if (ch < "0" || ch > "9") {
            return false
            }
      }
      return true;
}

function FIND(item) {
  if (document.all) return(document.all[item]);
  if (document.getElementById) return(document.getElementById(item));
  return(false);
}

function showselect (id) {
  FIND(id).className='flagsbox';
} 
function hideselect (id) {
  FIND(id).className='';
}
function BarterShowHide(id) {
  if(FIND(id).style.display=='block') {
    FIND(id).style.display='none';
  }
  else {
    FIND(id).style.display='block';
  }
}

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','BarterPrice');
  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;    
}

/* function clickIE4(){if (event.button==2){return false;}}
function clickNS4(e){if (document.layers||document.getElementById&&!document.all){if (e.which==2||e.which==3){return false;}}}
if (document.layers){document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS4;}else if (document.all&&!document.getElementById){document.onmousedown=clickIE4;}
document.oncontextmenu=new Function("return false")


 disable right click 
var isNS = (navigator.appName == "Netscape") ? 1 : 0;
if(navigator.appName == "Netscape") document.captureEvents(Event.MOUSEDOWN||Event.MOUSEUP);
function mischandler(){
 return false;
}
if ( document.images ) {
  for ( var pic=0; pic<document.images.length; pic++ ) {
      document.images[pic].oncontextmenu = mischandler;
  }
}
/* END disable right click */
