var emptyString = /^\s*$/ ;
var proceed = 2;  
var global_valfield;	// retain valfield for timer thread
var nbsp = 160;		// non-breaking space char


function trim(str)
{
  return str.replace(/^\s+|\s+$/g, '');
}

function setFocusDelayed()
{
  global_valfield.focus();
}

function setfocus(valfield)
{
  // save valfield in global variable so value retained when routine exits
  global_valfield = valfield;
  setTimeout( 'setFocusDelayed()', 100 );
}


function commonCheck    (valfield,   // element to be validated
                         required)   // true if required
{
  if (!document.getElementById) 
    return true;  // not available on this browser - leave validation to the server

  if (emptyString.test(valfield.value)) {
    if (required) {
      alert (id_Errore + ": " + id_val_req);  
      setfocus(valfield);
      return false;
    }
    else {
      return true;  
    }
  }
  return proceed;
}


function validateQty    (valfield,   // element to be validated
                         required)   // true if required
{
  var stat = commonCheck (valfield, required);
  if (stat != proceed) return stat;

  var tfld = trim(valfield.value);
  var qtyRE = /^\d*[\.|\,]*\d*$/
  if (!qtyRE.test(tfld)) {
    alert (id_Errore + ": " + id_qty_num_req);
    setfocus(valfield);
    return false;
  }
  else {
 	return true;
  }
}

function getHTTPObject() {
if (typeof XMLHttpRequest != 'undefined') {
return new XMLHttpRequest();
}
try {
return new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
return new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
return false;
}

var http = getHTTPObject();
var blocco ='';

function handleHttpResponse() {

if (http.readyState == 4) {
var temp = http.responseText;
document.getElementById("PHPDATA").innerHTML=temp;
}
}


function LoadData(url){
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponse;
http.send(null);
}

function handleHttpResponseVar() {
if (http.readyState == 4) {
var temp = http.responseText;
document.getElementById(blocco).innerHTML=temp;
}
}


function LoadDataVar(url,blk){
    blocco=blk;
http.open("GET", url, true);
http.onreadystatechange = handleHttpResponseVar;
http.send(null);
}


function II_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=II_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function II_swapImage() { //v3.0
  var i,j=0,x,a=II_swapImage.arguments; document.II_src=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=II_findObj(a[i]))!=null){document.II_src[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function II_swapImgRestore() { //v3.0
  var i,x,a=document.II_src; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function II_preloadimages() { //v3.0
  var d=document; if(d.images){ if(!d.II_p) d.II_p=new Array();
    var i,j=d.II_p.length,a=II_preloadimages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.II_p[j]=new Image; d.II_p[j++].src=a[i];}}
}

function II_showHideLayers() { //v6.0
  var i,p,v,obj,args=II_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=II_findObj(args[i]))!=null) { v=args[i+2];

    if (obj.style) { 
		obj=obj.style; 
		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 
		}

		obj.visibility=v; 
   }
}





function II_sHL(obj,p,v) { //v6.0
//  var p,v,obj;

//		v=(v=='show')?'visible':(v=='hide')?'hidden':v; 

		if (v=='hide')
		 {
			alert(v);
			setTimeout("obj.visibility='hidden'",1000); 
		}
		else {obj.visibility='visible';}		

}



function im_w(im,wi,he){
window.name='windowOpener';
ww=wi+20;
wh=he+20;
//alert(im+" "+ww+" "+wh);
whandle=window.open(im,'popUp','width='+ww+',height='+wh+',menubar=no,location=no,directories=no,status=no,toolbar=no,resizable=no,topmargin=0,leftmargin=0');
}

function im_wp(im,wi,he){
window.name='windowOpener';
ww=wi+120;
wh=he+20;
//alert(im+" "+ww+" "+wh);
whandle=window.open(im,'ImageDataWindow','width='+ww+',height='+wh+',menubar=no,location=no,directories=no,status=no,toolbar=no,resizable=no,topmargin=0,leftmargin=0');
whandle.focus();

}





function pause(numberMillis) {
        var now = new Date();
        var exitTime = now.getTime() + numberMillis;
        while (true) {
            now = new Date();
            if (now.getTime() > exitTime)
                return;
        }
}


function SetDivPosition(){
        var intY = document.getElementById("myDiv").scrollTop;
//	alert(intY);
}

var scrlY = 0;


