function showElement(theid)
{
	document.getElementById(theid).style.display='';
}
function hideElement(theid)
{
	document.getElementById(theid).style.display='none';
}
function setDestinationCount(num)
{
	document.dropForm.destinationCount.value=num;
}

function regularUpload()
{
	document.dropForm.ruri.value = "RegularUpload.jsp";
	validate();
	if(validate())	
		proceed();
}

function enhancedUpload()
{
	document.dropForm.ruri.value = "Enhanced.jsp";
	if(validate())
		proceed();
}
var featureList=[ "ajax2", "dialog", "calendar" ];

function PositionFooter(){
	 var flt = OAT.Dom.getLT( $( 'footer' ));
	 var fwh = OAT.Dom.getWH( $( 'footer' ));
	 var tclt = OAT.Dom.getLT( $( 'spacer' ));
	 var tcwh = OAT.Dom.getWH( $( 'spacer' ));
	 var tcBottom = tclt[1] + tcwh[1];
	 var vp = OAT.Dom.getViewport();
	 
	 if( tcBottom > vp[1] ){
		   OAT.Dom.moveBy( 'footer', 0, tcBottom - flt[1] + fwh[1] );
		   return;
		   }
	
	if( flt[ 1 ] != ( vp[ 1 ] - fwh[1] ) ){
		OAT.Dom.moveBy( 'footer', 0, vp[1] - ( fwh[1] * 2 ) - flt[1] );
		}
		
	}

function LoadContent( optObj ){	
		
	var options = {};
	
	for (var p in optObj) { options[p] = optObj[p]; }
	
	var ajxoptions = { 
		type: OAT.AJAX.TYPE_TEXT,
		onerror:function( request ){ alert( "request returned " + request.getStatus() ); }
			}
			
	function afterLoad( request ){ 
		var content = request;
		var bodstart = 0;
		if( request.search( '<body>' )  >= 0 ){ 
			bodstart = request.search( '<body>' ) + 6;
			content = request.substr( bodstart, request.search( '</body>' ) - bodstart );
			}
		options.el.innerHTML = content;
	}
		
	OAT.AJAX.GET( options.url, false, afterLoad, ajxoptions );
}


function InitSetisReady(){
	// populate the dropdowns from xml
	for( var i = 0; i < document.forms.length; ++i ){
		SDForm.FillFormSelOpts( document.forms[i] );
		}
		
	// Add an isEmpty function to all forms and don't send if no inputs.
	for( var i = 0; i < document.forms.length; ++i ){
    document.forms[i].isempty = function(){  els = this.elements; 
								for( var v=0; v< els.length; ++v ) {
									switch ( els[v].type) { 
											case "text": case "hidden": case "password": case "textarea":
												if( els[v].value != '' ){ return( false ); }
												break; 
											case "checkbox": 
												if( els[v].checked ){ return( false ); } 
												break;
											case "SELECT": case "select-one":  
												if( els[v].selectedIndex != 0 ){ return( false ); } 
												break; 
										} 
									}
								return( true );
							}
	}
}

function init(){
	
	// this form uses the OAT framework
	OAT.Preferences.showAjax = false;
	OAT.Preferences.imagePath = "/_sd/images/oat/";	
	
	
	// if the user is using Opera hide the footer
	if( OAT.Browser.isOpera ){ OAT.Dom.hide( 'footer' ); }
	
	// Allocate a dialog to show loading process
	LoadDlog = new OAT.Dialog(  'Progress....' , 'Activity', {modal:1, buttons:0,width:OAT.Dom.getWH( 'Activity' )[0] + 20});
	LoadDlog.show(); // display it
	
	// Allocate an order complete dialog
	OrdComplete = new OAT.Dialog(  'Order Status....' , 'OrderComplete', { modal:1, 
																			buttons:0,
																			resize: false,
																			width:OAT.Dom.getWH( 'OrderComplete' )[0] + 20
																		});

		
	// use OAT's calander function for date picking in datedue filed
	tDate = new Date();	
	var c = new OAT.Calendar();
	c.weekStartIndex = 6;
	window.cal = c;
	var openRef = function(event) {
      var callback = function(date) {
          $("DateDue").value = date[1]+"/"+date[2]+"/"+date[0];
      }
      var coords = OAT.Dom.position("DateDue");
      var y = OAT.Browser.isIE ? tDate.getYear() : tDate.getYear() + 1900;
      c.show(coords[0],coords[1]+30,callback, [ y, tDate.getMonth() + 1 , tDate.getDate() ] );
	}
	OAT.Dom.attach("DateDue","click",openRef); 
    OAT.Dom.attach("DateDue","keyup",function(){ $('DateDue').value = ''; openRef(); } );
	
	
  // initialize the form library
	SDForm.init();
	

}
