function roll(obj,sta,lay){
  iSrc=document[obj];
  if(document.layers && lay){iSrc=document.layers[lay].document[obj];}
  if(sta.length>1){iSrc.src="img"+sta;return;}
  iSrc.src=iSrc.src.substring(0,iSrc.src.lastIndexOf('_')+1)+sta+".gif";
}
function pops(loc,w,h){
	window.open(loc,'view','width='+w+',height='+h+',resizable=1,scrollbars=1,toolbar=0,statusbar=0,menubar=0');
	return false;
}


function WithDialog()
{
	VSTwain1.StartDevice()
	VSTwain1.maxImages=1
	VSTwain1.autoCleanBuffer=1
	if (VSTwain1.SelectSource() == 1)
	{
	  VSTwain1.ShowUI=1
	  VSTwain1.Acquire()
	}
}
function WithOutDialog()
{
	VSTwain1.StartDevice();
	VSTwain1.Register('Conrad Strabone','billworx.com','D1755CA997981905C7895308B92CB0EF6D3E9AFA4868D4DD234AA123A12A634E51F2AF795A26DD205636C9B4DD555929E1A855F5EB3A08AFE930915CF7739DC2D342F1E87691D05F191B39160A89F615FB067487C958A30CA2B299621DACFE203B8D60DB780EA26C88CC788C26377A3E4CF9B51EFAE60FADC90E8DDE29677E3172A872E730C8A15557D5BF3088C1F4203DB49FE055FE9ECD4A934B0710B104BB');
	VSTwain1.maxImages = 100;
	VSTwain1.autoCleanBuffer = 1;
	VSTwain1.disableAfterAcquire = 1;
	VSTwain1.tiffMultiPage = 1;
	VSTwain1.tiffCompression = 4;
	if (VSTwain1.SelectSource() == 1)
	{
		VSTwain1.ShowUI = 0;
	  VSTwain1.OpenDataSource()
		VSTwain1.unitOfMeasure = 0;
		VSTwain1.pixelType     = 0;
		VSTwain1.resolution    = 200;
		
		if (VSTwain1.feederPresent == 1)
		{
			VSTwain1.feederEnabled = 1;
			if (VSTwain1.errorCode != 0) {
				VSTwain1.Acquire();
				alert('Do NOT submit the ticket during the scanning and uploading process. Wait until "File Uploaded" in red text appears on the ticket.\n\nIf you try to submit the ticket during the process your scan will NOT be attached properly.');
			}
			else {
       	VSTwain1.autoFeed = 1
				VSTwain1.xferCount = -1;
				if (VSTwain1.feederLoaded == 1)
				{
					VSTwain1.Acquire();
					alert('Do NOT submit the ticket during the scanning and uploading process. Wait until "File Uploaded" in red text appears on the ticket.\n\nIf you try to submit the ticket during the process your scan will NOT be attached properly.');
				}
			}
		}
		else
		{
			
			VSTwain1.Acquire();
			alert('Do NOT submit the ticket during the scanning and uploading process. Wait until "File Uploaded" in red text appears on the ticket.\n\nIf you try to submit the ticket during the process your scan will NOT be attached properly.');
		}
	}
}
function UploadStatus()
{
	var statString = VSTwain1.ftpStateString
	if (VSTwain1.ftpState == 10)
	  statString = statString + " Uploaded " + String(VSTwain1.ftpBytesUploaded) + " bytes from " + String(VSTwain1.ftpBytesTotal) + " bytes."
	window.status = statString
	if ((VSTwain1.ftpState == 13) || (VSTwain1.ftpErrorCode != 0))
	{
	  if (VSTwain1.ftpErrorCode == 0) {
		 alert('Image uploaded successfully!')

		 }
	  else {alert(VSTwain1.ftpErrorString)}
	}
	else
	  setTimeout("UploadStatus()",10)
}
function UploadStatus2(filename)
{
	var statString = VSTwain1.httpStateString
	if (VSTwain1.httpState == 4)
	  statString = statString + " Uploaded " + String(VSTwain1.httpBytesUploaded) + " bytes from " + String(VSTwain1.httpBytesTotal) + " bytes."
	window.status = statString
	if ((VSTwain1.httpState == 6) || (VSTwain1.httpErrorCode != 0))
	{
	  if (VSTwain1.httpErrorCode == 0){
			alert('Image uploaded successfully!');
			document.forms[0].file.style.display = 'none';
			document.all.scanned.style.display = 'inline';
			document.forms[0].button2.value= 'Re-Scan';
		}
	  else {alert(VSTwain1.httpErrorString)}
	}
	else
	  setTimeout("UploadStatus2(filename)",10)
}

function UploadToFtpServer()
{
	document.Form1.BUpload.disabled = 1
	document.Form1.BCancel.disabled = 0
	var ftpServer = String(document.Form1.ftpServer.value)
	var ftpUser = String(document.Form1.ftpUser.value)
	var ftpPassw = String(document.Form1.ftpPassw.value)
	VSTwain1.SetFtpServerParams(ftpServer,21,ftpUser,ftpPassw,"")
	if (VSTwain1.errorCode != 0)
	{
	  alert(VSTwain1.errorString)
	  document.Form1.BUpload.disabled = 0
	  document.Form1.BCancel.disabled = 1
	}
	else
	{
	  VSTwain1.SetFtpServerAdvParams(1,20)
	  var ftpPath = String(document.Form1.ftpPath.value)
	  if (VSTwain1.SaveImageToFtp(0,ftpPath) == 0)
	  {
	    alert(VSTwain1.errorString)
	    document.Form1.BUpload.disabled = 0
	    document.Form1.BCancel.disabled = 1
	  }
	  else setTimeout("UploadStatus()",10)
	}
}
function CancelUploadToFtpServer()
{
 	VSTwain1.ftpCancel = 1
	document.Form1.BUpload.disabled = 0
	document.Form1.BCancel.disabled = 1
}

function UploadToHttpServer(customerid,userid,ticketid)
{
	url = 'http://www.billworx.com/upload.cfm&customerid=' + customerid + '&userid=' + userid + '&ticketid=' + ticketid;
	VSTwain1.SetHttpServerParams(url,"",5)
	if (VSTwain1.errorCode != 0)
	{
	  alert(VSTwain1.errorString)
	  document.Form2.BUpload.disabled = 0
	  document.Form2.BCancel.disabled = 1
	}
	else
	{
		filename  = 'c:\\bw_' + customerid + '_' + userid + '_' + ticketid + '.tif';
		filename2 = 'c:\bw_' + customerid + '_' + userid + '_' + ticketid + '.tif';
		if (VSTwain1.SetHttpFileFromDisk(filename) == 0 )
		{
        alert(VSTwain1.errorString)
    }

	  if (VSTwain1.SaveImageToHttp(0,"file",filename2) == 0)
	  {
	    alert(VSTwain1.errorString)
	  }
	  else{
			alert('Upload image to Billworx?\nIf OK, please wait for upload confirmation before updating the ticket.');
			setTimeout("UploadStatus2(filename)",10)
		}
	}
}
function CancelUploadToHttpServer()
{
 	VSTwain1.httpCancel = 1
	document.Form2.BUpload.disabled = 0
	document.Form2.BCancel.disabled = 1
}
function OnPageUnload()
{
	VSTwain1.StopDevice()
}
