var w = 800, h = 600;
w = screen.availWidth;
h = screen.availHeight;

//------------------------------------------------------------------------------
function todaysDate(field){
	field.value = getDateStr();
}

//------------------------------------------------------------------------------
function getDateStr(){
  var today = new Date()
  var year = today.getYear()
  if(year<1000) year+=1900
  var todayStr = today.getDate() + '.' + (today.getMonth()+1) + '.' + year;
  return todayStr
  }
//------------------------------------------------------------------------------
function formatEnteredDateValue(sourceControl) {

	if (isDate(sourceControl)) return true;
		
	var value = sourceControl.value;
	var year, month, day, monthday = '';
	
	if (value.length > 6) {
		year = value.substring(value.length - 4, value.length);
		monthday = value.substring(0, value.length - year.length);
	}
	else if (value.length == 6) {
		year = value.substring(value.length - 2, value.length);
		monthday = value.substring(0, value.length - year.length);
	}
	else if (value.length >= 4) {
		year = value.substring(value.length - 2, value.length);
		monthday = value.substring(0, value.length - year.length);
	}

	if (monthday.length == 2) {
		day = monthday.substring(0,1);
		month = monthday.substring(1,2);
	}
	else if(monthday.length == 3) {
		day = monthday.substring(0,2);
		month = monthday.substring(2,3);
		if (day <= 31 && month <= 12) {
		}
		else {
			day = monthday.substring(0,1);
			month = monthday.substring(2,3);
		}
	}
	else if(monthday.length == 4) {
		day = monthday.substring(0,2);
		month = monthday.substring(2,4);
	}
	else {
		return false;
	}
	
	while (day.length < 2) day = '0' + day;
	while (month.length < 2) month = '0' + month;
	if (year.length == 2) year = (year < 40) ? (2000 + (year*1)) : (1900 + (year*1));	
	
	sourceControl.value = (day + '.' + month + '.' + year);
	if (isDate(sourceControl)) return true;
	return false;
		
}
//------------------------------------------------------------------------------
function rHI(theRow) {
	var prevClassName = theRow.className;
	theRow.className = 'rowHighlight';
	theRow.setAttribute('roldclsName', prevClassName);
}
//------------------------------------------------------------------------------
function rLO(theRow) {
	var prevClassName = theRow.getAttribute('roldclsName');
	theRow.className = prevClassName;
}
//------------------------------------------------------------------------------
function getlayer(layerName) {if (document.layers) {return eval('document.' + layerName);}else {if (document.all) {return eval('document.all.' + layerName + '.style');}else {return eval('document.getElementById("' + layerName + '").style');}}}
//------------------------------------------------------------------------------
function submitform(formname,action) {
	SetWaitCursor(true);
	bProcessingPostRequest=true;
	gHandleBrowserOnUnload = false;
	document.forms[formname].action.value=action;
	document.forms[formname].submit();
}
//------------------------------------------------------------------------------
function openwindow (url, newHeight, newWidth) {
	var wndHeight = 600;
	var wndWidth = 700;
	if (newHeight) wndHeight = newHeight;
	if (newWidth) wndWidth = newWidth;

	if (url.indexOf('?')==-1)
		url+='?rnd=' + Math.floor(10000000*Math.random());
	else
		url+='&rnd=' + Math.floor(10000000*Math.random());
	window.open(url,'','scrollbars=yes,toolbar=yes,location=no,directories=no,resizable=yes,copyhistory=no,left=50,top=50,height=' + wndHeight + ',width=' + wndWidth);
}
//------------------------------------------------------------------------------
function openwindow1 (url,width,height,FormToSend,FieldPattern) {
	var leftPos = (w-width)/2, topPos = (h-height)/2;
	if (FormToSend)
	{
		if (url.indexOf('?')==-1)
			url+='?data=';
		else
			url+='&data=';	
		url+=AutoFormContents(document.forms[FormToSend].elements,FieldPattern);
	}

	if (url.indexOf('?')==-1)
		url+='?rnd=' + Math.floor(10000000*Math.random());
	else
		url+='&rnd=' + Math.floor(10000000*Math.random());

	window.open(url,'','scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,left=' + leftPos + ',top=' + topPos + ',height=' + height + ',width=' + width);
}
//------------------------------------------------------------------------------
function openwindow2 (url,width,height){
	var leftPos = (w-width)/2, topPos = (h-height)/2;

	if (url.indexOf('?')==-1)
		url+='?rnd=' + Math.floor(10000000*Math.random());
	else
		url+='&rnd=' + Math.floor(10000000*Math.random());

	window.open(url,'','scrollbars=yes,toolbar=no,location=no,directories=no,resizable=yes,copyhistory=no,left=' + leftPos + ',top=' + topPos + ',height=' + height + ',width=' + width);
}


//------------------------------------------------------------------------------
function confirmaction(formname,action,message) {
	if (window.confirm(message)) {
		gHandleBrowserOnUnload = false;
		document.forms[formname].action.value=action;document.forms[formname].submit();
	}
}
//------------------------------------------------------------------------------
function submitform1(form,action,parameters) {
	SetWaitCursor(true);
	bProcessingPostRequest=true;
	document.forms[form].elements['parameters'].value=parameters;
	submitform(form,action);
}
//------------------------------------------------------------------------------
function confirmaction1(formname,action,message,parameters) {
	document.forms[form].elements['parameters'].value=parameters;
	if (window.confirm(message)) {
		document.forms[formname].action.value=action;document.forms[formname].submit();
	}
}
//------------------------------------------------------------------------------
function openwindowmax(URL)
{
	var wOpen;
	var sOptions;
	sOptions = 'status=yes,menubar=yes,scrollbars=yes,resizable=yes,toolbar=yes';
	sOptions = sOptions + ',width=' + (screen.availWidth - 10).toString();
	sOptions = sOptions + ',height=' + (screen.availHeight - 122).toString();
	sOptions = sOptions + ',screenX=0,screenY=0,left=0,top=0';
	wOpen = window.open( '', '', sOptions );
	wOpen.location = URL;
	wOpen.focus();
	wOpen.moveTo( 0, 0 );
	wOpen.resizeTo( screen.availWidth, screen.availHeight );
}
//------------------------------------------------------------------------------
function changeCursor(control,how) {
	if (!how) {
		how = 'auto';
	}
	control.style.cursor = how;
	document.body.style.cursor = how;
}
//------------------------------------------------------------------------------
function EncodeRemoteData(data){
	var encoded="";
	encoded=data;
	while(encoded.indexOf('%')!=-1) encoded=encoded.replace('%','[PERCENT]');
	while(encoded.indexOf('&')!=-1) encoded=encoded.replace('&','[AMP]');
	while(encoded.indexOf('@')!=-1) encoded=encoded.replace('@','[AT]');
	while(encoded.indexOf('+')!=-1) encoded=encoded.replace('+','[PLUS]');
	while(encoded.indexOf('-')!=-1) encoded=encoded.replace('-','[MINUS]');
	while(encoded.indexOf('<')!=-1) encoded=encoded.replace('<','[LT]');
	while(encoded.indexOf('>')!=-1) encoded=encoded.replace('>','[GT]');
	while(encoded.indexOf('\r')!=-1) encoded=encoded.replace('\r','');
	while(encoded.indexOf('\n')!=-1) encoded=encoded.replace('\n','[CRLF]');
	while(encoded.indexOf('"')!=-1) encoded=encoded.replace('"','[QUOTE]');
	encoded = escape(encoded);
	return encoded;
}
//------------------------------------------------------------------------------
function AutoFormContents(elements,nameprefix)
{
	var buffer='';
	for( var i = 0; i < elements.length; i++ )
	{	
		if (elements[i].type!='button' && elements[i].type!='undefined' && elements[i].name)
		  if (!elements[i].disabled && elements[i].name.substring(0,nameprefix.length) == nameprefix) 
		  { 
			if (buffer!='') buffer+='@';
			switch(elements[i].type){
				case 'hidden':
				case 'text':
				case 'textarea':
				case 'select-one':
				  buffer+=elements[i].name+'='+EncodeRemoteData(elements[i].value);
				  break;
				case 'radio':
					if (elements[i].checked) buffer+=elements[i].name+'='+EncodeRemoteData(elements[i].value);
					break;
			}
		}						  						
	}
	return buffer;
}	
//------------------------------------------------------------------------------
function setPageTitle(sData) {
	if (document.all['pgTitle']) {
		var theData = new String(sData);
		var re = /\n/g;
		theData = theData.replace(re, '<br>');
		StoreDataToDiv('pgTitle', theData);
	}
}
//------------------------------------------------------------------------------
function setPageSubTitle(sData) {
	if (document.all['pgSubTitle']) {
		var theData = new String(sData);
		var re = /\n/g;
		theData = theData.replace(re, '<br>');
		StoreDataToDiv('pgSubTitle', theData);
	}
}
//------------------------------------------------------------------------------
function SetDivVisibility(item,value)
{
	var e
	e = getlayer(item);
	if (value) 
		e.visibility="visible";
	else
		e.visibility="hidden";
}		
//------------------------------------------------------------------------------
function bgCChange(src,c) {
	src.style.background = c;
}
//------------------------------------------------------------------------------
function SetDate(field,day,month,year){document.forms['DCONFORM'].elements[field].value=day+'.'+month+'.'+year;}
//------------------------------------------------------------------------------
function StoreDataToDiv(divname, data) {
	if (document.all[divname]) {
		document.all[divname].innerHTML='';
		document.all[divname].insertAdjacentHTML('afterBegin',data);
	}
	indicateMandatoryFields();
	self.status='Done'; //#ra 30.04.2002 - this ensures that the IE progress update correctly after a change to the page from Javascript
}
//------------------------------------------------------------------------------
function CheckExtendedFieldAttributes()
{
var i;
var fieldFormat = '';
var fieldLength = 0;
for (i=0;i<document.all.length;i++) 
	{	
		try
		{
			fieldFormat = document.all(i).getAttribute("format");
			fieldLength = 0;
			if ('undefined' != document.all(i).value) {
				fieldLength = document.all(i).value.length;
			}
			fieldLength = document.all(i).value;
			if (document.all(i).getAttribute("required") == 1) {
				if (fieldLength == 0) {
					setFieldBgColor(document.all(i), "#FFCC33");
				}
			}
		}
		catch(err){  }
	}
}
//------------------------------------------------------------------------------
function setFieldBgColor(field, color) {
	field.style.backgroundColor = color;
}
//------------------------------------------------------------------------------
function isNumber(ctl)
{
var intStr,matchArray;
var valPat = /^(\d*)$/;
var matchArray = ctl.match(valPat); // is the format ok?

if (matchArray == null)
{
return false;
}
return true;
}
//------------------------------------------------------------------------------
function isAmount(ctl)
{
	var allowedChars = '01234567890.,-';
	var c,i;
	for (i=0;i<ctl.length;i++) {
		c = ctl.substr(i,1);
		if (allowedChars.indexOf(c) < 0) return false;
	}
	return true;
}
//------------------------------------------------------------------------------
function isInRange(what, lbound, ubound) {
	return ((what >= lbound) && (what <= ubound));
}

//------------------------------------------------------------------------------
function isDate(textField) { 
	a=textField.value;
	dotpos1= a.indexOf('.');
	dotpos2= a.lastIndexOf('.');
	if (dotpos1>0 && dotpos1<3 && dotpos2==a.length-5 && dotpos2>=dotpos1+1) {
	d = a.substring(0,dotpos1);
	m = a.substring(dotpos1+1,dotpos2);
	y = a.substring(dotpos2+1,a.length);
	if (isInRange(y,1901,2099) && isInRange(m,1,12) && isInRange(d,1,31)) {
		if ((m==4 || m==6 || m==9 || m==11) && d>30) 
			return false
		else
			if (m==2) 
				if (d>29) 
					return false
				else 
					if (d==29 && ((y/4)!=parseInt(y/4))) 
						return false
			else 
				return true
	else
		return true
	}
	else
	return false
  }
  else
	return false
}
//------------------------------------------------------------------------------
function isTime(textField) { 
	a=textField.value;
	dotpos1= a.indexOf(':');
	dotpos2= a.lastIndexOf(':');
	if (dotpos1>0 && dotpos1<3 && dotpos2==a.length-3 && dotpos2>=dotpos1+1) {
		h = a.substring(0,dotpos1);
		m = a.substring(dotpos1+1,dotpos2);
		s = a.substring(dotpos2+1,a.length);
		if (isInRange(h,0,24) && isInRange(m,0,60) && isInRange(s,0,60)) 
			return true
		else
			return false
	}
	else
		return false
}
//------------------------------------------------------------------------------
function isValidCurrencyCode(textField) {
	var theCode = textField.value.toUpperCase();
	if (theCode.length == 0) return true;
	if (!validCurrenciesList) {
		alert('validCurrenciesList not defined in page!');
		return true;
	}
	var arCurrencies = validCurrenciesList.split(',');
	for (var i = 0; i<arCurrencies.length; i++) {
		if (theCode == arCurrencies[i]) {
			return true;
		}
	}
	return false;
}
//------------------------------------------------------------------------------
function validateInputFields() {
	var result = 0;
	result += validateForm('input'); 
	result += validateForm('select-one');
	result += validateForm('select');
	return result;
}
function setErrBgColor(c) {
	c.style.backgroundColor='#ffcc33';
}
function setOkBgColor(c) {
	//c.style.backgroundColor='#FFFF99';
}
//------------------------------------------------------------------------------
function validateForm(TagType)
{

var e;
var c;
var validationCounter = 0;

for( e = new Enumerator( document.all.tags( TagType ) ); !e.atEnd(); e.moveNext() )
{
c = e.item();

// If the field isn''t required, disabled or read-only, we exit this iteration
if ( c.disabled || c.readonly || c.style.display == "none" || (c.type != "text" && c.type != "select" && c.type != "select-one"))
continue;
// Once there the field is required

try
{
	// Focus the field
	//c.focus(); // Will raise an error if the field is hidden but then it can''t be mandatory => OK
	// Check if we got a value
	if ( c.value == "" && c.required == "1" )
	{
		if(!errControl) errControl = c;
		setErrBgColor(c);
		validationCounter++;
		continue;
	}

	setOkBgColor(c);
	var errControl;

	// Only continue if the value is not empty
	if ( c.value == "" ) {
		continue;
	}
	
	// Is it a ZIPcode ?
	if ( c.format == "ZIP" && !isValidZIP(c.value) ) 	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}

	// Is it a number ?
	if ( c.format == "numeric" && !isNumber(c.value) )  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}

	// Is it a amount ?
	if ( c.format == "amount" && !isAmount(c.value) )  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}

	// Is it a date ?
	if ( c.format == "date" && (!formatEnteredDateValue(c)) )  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}
	
	// PL at 07/08/2007
	// 116013 DCON net customization
	// allow US format date add a format 'date_us'
	// Is it a US date format
	if ( c.format == "date_us" && (!formatEnteredDateValue_US(c)) )  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}
	
	// Is it a time ?
	if ( c.format == "time" && !isTime(c))  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}
	
	// Is it a currency code ?
	if ( c.format == "currency" && !isValidCurrencyCode(c))  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}

	// Is it a email address ?
	if ( c.format == "email" && !isEmail(c.value) )  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}

	// Has it the right length ?
	if ( c.minlength && c.value.length < c.minlength )  	{ if(!errControl) errControl = c; setErrBgColor(c); validationCounter++;}
} // end try
catch (err)
{}
}
if (errControl) {
	errControl.focus(); 
}
return validationCounter;
}
//------------------------------------------------------------------------------


function SetWaitCursorForElement(element,show,ToggleDisabled)
{
		try
		{	
			if (show)
			{
				element.style.cursor="wait";
				if (ToggleDisabled) 
				{
					element.setAttribute("originaldisabledstate",element.disabled);
					element.disabled=true;
				}
			}
			else
			{
				element.style.cursor = '';
				if (ToggleDisabled) element.disabled=element.getAttribute("originaldisabledstate");
			}
					
		}
		catch(err){}
}

function SetWaitCursorForGroupOfTags(tagtype,show,ToggleDisabled)
{	
	var i;
	var coll;
	coll = document.all.tags(tagtype);
	if (coll!=null)
	{
	    for (i=0; i<coll.length; i++) 
				SetWaitCursorForElement(coll[i],show,ToggleDisabled);
	}
}

function SetWaitCursor(show)
{
	//running through document.all would be simpler, but is too slow!
	SetWaitCursorForElement(document.body,show,false);
	SetWaitCursorForGroupOfTags("input",show,false);
	SetWaitCursorForGroupOfTags("a",show,false);	//Don't disable links -> they look completely stupid!
}

// commented <script> tag here makes interdev colorize properly
//
//  jsrsClient.asp - javascript remote scripting client include
//  
//  Author:  Brent Ashley [jsrs@megahuge.com]
//
//  make asynchronous remote calls to server without client page refresh
//
//  see license.txt for copyright and license information

/*

ver   date       comment
-----------------------
1.00  22Aug2000  release
1.01  06Sep2000  change location.href=url to location.replace(url) to help avoid history
1.02  12Sep2000  comment out unique string to reduce history clutter
1.03  22Sep2000  add jsrsEvalEscape so quotes and newlines in parms won't choke
1.04  23Jan2001  ie4.x bug fix, debug utility: 
  hidden iframes must be inserted in space which has been visibly rendered on screen.  
  - moved insertion point to top of body to reduce/eliminate likelihood of this being unrendered space.
  - changed DIV to SPAN to avoid line break insertion into page flow
  added jsrsDebugInfo()
  - see comment for instruction on how to use it
1.05  06Feb2001  escape jsrsError return value, use try/catch in dispatch
1.06  13Feb2001  added no-nonsense copyright and license, starting to plan for NS6

1.1   14Feb2001  Mozilla/NS6 compatibility
  - the code expects NS4, IE4+, or Mozilla (incl NS6).
  - it's up to you to tell the user if they don't have the right browser.
1.11  15Feb2001  NS6 was not reloading on recall 
  - set src to '' before reloading
  - thanks to Murray Cash

*/

// callback pool needs global scope
var jsrsContextPoolSize = 0;
var jsrsContextMaxPool = 10;
var jsrsContextPool = new Array();
var jsrsBrowser = jsrsBrowserSniff();

// constructor for context object
function jsrsContextObj( contextID ){
  
  // properties
  this.id = contextID;
  this.busy = true;
  this.callback = null;
  this.container = contextCreateContainer( contextID );
  
  // methods
  this.callURL = contextCallURL;
  this.getPayload = contextGetPayload;
  this.setVisibility = contextSetVisibility;
}

//  method functions are not privately scoped 
//  because Netscape's debugger chokes on private functions
function contextCreateContainer( containerName ){
  // creates hidden container to receive server data 
  var container;
  switch( jsrsBrowser ) {
    case 'NS':
      container = new Layer(100);
      container.name = containerName;
      container.visibility = 'hidden';
      container.clip.width = 100;
      container.clip.height = 100;
      break;
    
    case 'IE':
      document.body.insertAdjacentHTML( "afterBegin", '<span id="SPAN' + containerName + '"></span>' );
      var span = document.all( "SPAN" + containerName );
      var html = '<iframe name="' + containerName + '" src=""></iframe>';
      span.innerHTML = html;
      span.style.display = 'none';
      container = window.frames[ containerName ];
      break;
      
    case 'MOZ':  
      var span = document.createElement('SPAN');
      span.id = "SPAN" + containerName;
      document.body.appendChild( span );
      var iframe = document.createElement('IFRAME');
      iframe.name = containerName;
      span.appendChild( iframe );
      container = iframe;
      break;
  }
  return container;
}

function contextCallURL( URL ){
  switch( jsrsBrowser ) {
    case 'NS':
      this.container.src = URL;
      break;
    case 'IE':
      this.container.document.location.replace(URL);
      break;
    case 'MOZ':
      this.container.src = '';
      this.container.src = URL; 
      break;
  }  
}

function contextGetPayload(){
  switch( jsrsBrowser ) {
    case 'NS':
      return this.container.document.forms['jsrs_Form'].elements['jsrs_Payload'].value;
    case 'IE':
      return this.container.document.forms['jsrs_Form']['jsrs_Payload'].value;
    case 'MOZ':
      return window.frames[this.container.name].document.forms['jsrs_Form']['jsrs_Payload'].value; 
  }  
}

function contextSetVisibility( vis ){
  switch( jsrsBrowser ) {
    case 'NS':
      this.container.visibility = (vis)? 'show' : 'hidden';
      break;
    case 'IE':
      document.all("SPAN" + this.id ).style.display = (vis)? '' : 'none';
      break;
    case 'MOZ':
      document.getElementById("SPAN" + this.id).style.visibility = (vis)? '' : 'hidden';
      this.container.width = (vis)? 250 : 0;
      this.container.height = (vis)? 100 : 0;
      break;
  }  
}

// end of context constructor

function jsrsGetContextID(){
  var contextObj;
  for (var i = 1; i <= jsrsContextPoolSize; i++){
    contextObj = jsrsContextPool[ 'jsrs' + i ];
    if ( !contextObj.busy ){
      contextObj.busy = true;      
      return contextObj.id;
    }
  }
  // if we got here, there are no existing free contexts
  if ( jsrsContextPoolSize <= jsrsContextMaxPool ){
    // create new context
    var contextID = "jsrs" + (++jsrsContextPoolSize);
    jsrsContextPool[ contextID ] = new jsrsContextObj( contextID );
    return contextID;
  } else {
    alert( "jsrs Error:  context pool full" );
    return null;
  }
}

function jsrsExecute(rspage,parameters, callback, visibility ){
  // call a server routine from client code
  //
  // rspage      - href to asp file
  // callback    - function to call on return 
  //               or null if no return needed
  //               (passes returned string to callback)
  // func        - sub or function name  to call
  // parm        - string parameter to function
  //               or array of string parameters if more than one
  // visibility  - optional boolean to make container visible for debugging
  
  // get context
  var contextObj = jsrsContextPool[ jsrsGetContextID() ];
  contextObj.callback = callback;

  var vis = (visibility == null)? false : visibility;
  contextObj.setVisibility( vis );

  // build URL to call
  var URL = rspage;

  // always send context
  URL += "&C=" + contextObj.id + "&rndnum=" + Math.floor(10000000*Math.random());
  if (parameters!=null) URL+="&" + parameters
  // make the call
    
  contextObj.callURL( URL );
  SetWaitCursor(true);
  return contextObj.id;
}

function jsrsLoaded( contextID ){
  // get context object and invoke callback
  
  SetWaitCursor(false);
  
  var contextObj = jsrsContextPool[ contextID ];
  if( contextObj.callback != null){
    contextObj.callback( jsrsUnescape( contextObj.getPayload() ), contextID );
  }
  // clean up and return context to pool
  contextObj.callback = null;
  contextObj.busy = false;
}

function jsrsError( contextID, str ){
  alert( unescape(str) );
  jsrsContextPool[ contextID ].busy = false
}

function jsrsUnescape( str ){
  // payload has slashes escaped with whacks
  return str.replace( /\\\//g, "/" );
}

function jsrsBrowserSniff(){
  if (document.layers) return "NS";
  if (document.all) return "IE";
  if (document.getElementById) return "MOZ";
  return "OTHER";
}

/////////////////////////////////////////////////
//
// user functions

function jsrsArrayFromString( s, delim ){
  // rebuild an array returned from server as string
  // optional delimiter defaults to ~
  var d = (delim == null)? '~' : delim;
  return s.split(d);
}

function jsrsDebugInfo(){
  // use for debugging by attaching to f1 (works with IE)
  // with onHelp = "return jsrsDebugInfo();" in the body tag
  var doc = window.open().document;
  doc.open;
  doc.write( 'Pool Size: ' + jsrsContextPoolSize + '<br><font face="arial" size="2"><b>' );
  for( var i in jsrsContextPool ){
    var contextObj = jsrsContextPool[i];
    doc.write( '<hr>' + contextObj.id + ' : ' + (contextObj.busy ? 'busy' : 'available') + '<br>');
    doc.write( contextObj.container.document.location.pathname + '<br>');
    doc.write( contextObj.container.document.location.search + '<br>');
    doc.write( '<table border="1"><tr><td>' + contextObj.container.document.body.innerHTML + '</td></tr></table>' );
  }
  doc.write('</table>');
  doc.close();
  return false;
}

function setAndEnableField(field,value){
	if (!field) return;
	field.disabled=false;
	field.value=value;
}

function dconField(fieldname) {
	if (!document.forms['DCONFORM'].elements[fieldname]) {
		//alert('warning: form element with name ' + fieldname + ' does not exist!');
		return;
	}
	return dconformField(fieldname).value;
}

function dconformField(fieldname) {
	if (!document.forms['DCONFORM'].elements[fieldname]) {
		//alert('warning: form element with name ' + fieldname + ' does not exist!');
		return;
	}
	return document.forms['DCONFORM'].elements[fieldname];
}

function isDCONFormField(fieldname) {
	return (document.forms['DCONFORM'].elements[fieldname]);
}

function setComboToDefault(cbo,value) {
	var i;
	for (i=0;i<cbo.options.length;i++) {
		if (cbo.options[i].value == value) {
			cbo.options[i].selected = true;
			return;
		}
	}
}

function closewindowfocusopener() {
	if (window.opener) window.opener.focus();
	window.close();
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
//------------------------------------------------------------------------------

function FormatRegionCode(regionCode, countryCode){
	var ret = ""; 
	regionCode = trim(regionCode);
	if (regionCode.length > 0)
	{
		if (regionCode.indexOf("-") == -1)
			ret = countryCode + "-" + regionCode;
		else
			ret = regionCode;
	}
	
	return ret.toUpperCase();
}



// PL at 07/08/2007
// 116013 DCON net customization
// allow US format date
//begin modifications
function getDateStr_US(){
	var today = new Date()
	var year = today.getYear()
	if(year<1000) year+=1900
	var todayStr = (today.getMonth()+1) + '/' + today.getDate() + '/' + year;
	return todayStr
}
		  
function SetDate_US(field,day,month,year){document.forms['DCONFORM'].elements[field].value=month+'/'+day+'/'+year;}
			
function isDate_US(textField) { 
	a=textField.value;
	dotpos1= a.indexOf('/');
	dotpos2= a.lastIndexOf('/');
	if (dotpos1>0 && dotpos1<3 && dotpos2==a.length-5 && dotpos2>=dotpos1+1) {
	m = a.substring(0,dotpos1);
	d = a.substring(dotpos1+1,dotpos2);
	y = a.substring(dotpos2+1,a.length);
	if (isInRange(y,1901,2099) && isInRange(m,1,12) && isInRange(d,1,31)) {
		if ((m==4 || m==6 || m==9 || m==11) && d>30) 
			return false
		else
			if (m==2) 
				if (d>29) 
					return false
				else 
					if (d==29 && ((y/4)!=parseInt(y/4))) 
						return false
			else 
				return true
	else
		return true
	}
	else
	return false
  }
  else
	return false
}

function formatEnteredDateValue_US(sourceControl) {
	if (isDate_US(sourceControl)) return true;
					
	var value = sourceControl.value;
	var year, month, day, monthday = '';
				
	var arDateParts = value.split('/');

	if (arDateParts.length == 3) {
		month = arDateParts[0];
		day = arDateParts[1];
		year = arDateParts[2];
	}
	else {
		if (value.length == 8) {
			monthday = value.substring(0,4);
			month = value.substring(0,2);
			day = value.substring(2,2);
			year = value.substring(4,8);
		}
		else if (value.length > 6 && !arDateParts.length) {
			year = value.substring(value.length - 4, value.length);
			monthday = value.substring(0, value.length - year.length);
		}
		else if (value.length == 6) {
			year = value.substring(value.length - 2, value.length);
			monthday = value.substring(0, value.length - year.length);
		}
		else if (value.length >= 4) {
			year = value.substring(value.length - 2, value.length);
			monthday = value.substring(0, value.length - year.length);
		}

		if (monthday.length == 2) {
			month = monthday.substring(0,1);
			day = monthday.substring(1,2);
		}
		else if(monthday.length == 3) {
			month = monthday.substring(0,2);
			day = monthday.substring(2,3);
			if (day <= 31 && month <= 12) {
			}
			else {
				month = monthday.substring(0,1);
				day = monthday.substring(2,3);
			}
		}
		else if(monthday.length == 4) {
			month = monthday.substring(0,2);
			day = monthday.substring(2,4);
		}
		else {
			return false;
		}
	}
				
	while (day.length < 2) day = '0' + day;
	while (month.length < 2) month = '0' + month;
	if (year.length == 2) year = (year < 40) ? (2000 + (year*1)) : (1900 + (year*1));	
				
	sourceControl.value = (month + '/' + day + '/' + year);
	if (isDate_US(sourceControl)) return true;
	return false;
}

//end modifications