/*********************************************************************** 
			This file contains all javascript functions 
		that are commonly used acroos this web application
************************************************************************/
// trims only leading spaces
function LTrim(inputString) 
{
   // Removes leading spaces from the passed string.
   var retValue = inputString;
   retValue = retValue.replace(/^[\s]+/g,"");
   return retValue; 	   
} 

// trims only trailing spaces
function RTrim(inputString) 
{
   // Removes trailing spaces from the passed string.
   var retValue = inputString;
   retValue=retValue.replace(/[\s]+$/g,"");
   return retValue; 	   
} 

// trims leading and trailing white spaces.
function LRTrim(inputString) 
{
   // Removes leading and trailing spaces from the passed string.
   var retValue = inputString;
   retValue = retValue.replace(/^[\s]+/g,"");
   retValue=retValue.replace(/[\s]+$/g,"");
   return retValue; 	   
} 


function HasSpace(s)
{
	alert(s.indexOf(" "));
	if (s.indexOf(" ") > -1)
	{
		return true;
	}
	else
	{
		return false;
	}
}

// open a pop-up window for FAQ.
function FAQ(FAQlink)
{
	childWindow = open(FAQlink,"UNFIFAQ","scrollbars=no,resizable=yes,width=800,height=450" );
	childWindow.focus();
	if (childWindow.opener == null) childWindow.opener = self;
}

// close the FAQ pop-up window when user leaves current parent window.
function CloseFAQ()    // close pop-up window if it is open 
{
	if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) 
    if(childWindow != null) if(!childWindow.closed) childWindow.close() 
}

//window.onunload = CloseHELP; 

// open a pop-up window for HELP.
// example: HREF="javascript:HELP('/Documentation/OnlineHelp/Webhelp/iCDOhelp.htm');"
function HELP(HELPlink)
{
    childWindow = open(HELPlink,"UNFIHELP","scrollbars=no,resizable=yes,width=900,height=450" );
	childWindow.focus();
	if (childWindow.opener == null) childWindow.opener = self;
}

// close the HELP pop-up window when user leaves current parent window.
function CloseHELP()    // close pop-up window if it is open 
{
	if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) 
    if(childWindow != null) if(!childWindow.closed) childWindow.close() 
}

//open a child window
function OpenPopWin(file,window,width,height,toolbar,location) 
{
    var top = Math.floor(screen.height / 2 - height / 2);
    var left = Math.floor(screen.width / 2 - width / 2);
	
	var sToolbar = toolbar;
	if (typeof toolbar!="undefined" && (toolbar.toUpperCase()=="YES" || toolbar.toUpperCase()=="1"))
	{
		// this command display the Status Bar and Location Bar (when the "location" argument is YES)
			
		childWindow=open(file, window,"resizable=yes,scrollbars=yes,status=yes,location="+location+",toolbar=" + sToolbar + ",menubar=yes,width=" 
			+ width + ",height=" + height + ",top=" + top + ",left=" + left);	
	}
	else
	{
		// this command does not display Status Bar and Location Bar
		
		childWindow=open(file, window,"resizable=yes,scrollbars=yes,toolbar=" + sToolbar + ",menubar=yes,width=" 
			+ width + ",height=" + height + ",top=" + top + ",left=" + left);
    }
    
    childWindow.focus();
    if (childWindow.opener == null) childWindow.opener = self;
}

//open a child window
function OpenPopWin(file,window,width,height,toolbar,location,menu) 
{

    var top = Math.floor(screen.height / 2 - height / 2);
    var left = Math.floor(screen.width / 2 - width / 2);
	
	var sToolbar = toolbar;
	if (typeof toolbar!="undefined" && (toolbar.toUpperCase()=="YES" || toolbar.toUpperCase()=="1"))
	{
		// this command display the Status Bar and Location Bar (when the "location" argument is YES)
			
		childWindow=open(file, window,"resizable=yes,scrollbars=yes,status=yes,location="+location+",toolbar=" + sToolbar + ",menubar="+menu+",width=" 
			+ width + ",height=" + height + ",top=" + top + ",left=" + left);	
	}
	else
	{
		// this command does not display Status Bar and Location Bar
		
		childWindow=open(file, window,"resizable=yes,scrollbars=yes,toolbar=" + sToolbar + ",menubar="+menu+",width=" 
			+ width + ",height=" + height + ",top=" + top + ",left=" + left);
    }
    
    childWindow.focus();
    if (childWindow.opener == null) childWindow.opener = self;
}

function ClosePopWin()    // close pop-up window if it is open 
{
	if (navigator.appName != "Microsoft Internet Explorer" 
      || parseInt(navigator.appVersion) >=4) 
    if(childWindow != "undefined") if(!childWindow.closed) childWindow.close() 
}
 
 
<!-- Application:	firstFocus.js			(javascript)			-->
<!-- Comments:		Added to place cursor within first user field in ASP pages.	-->
<!--21-Dec-2001 .CvM Added from web to put focus to first field. -->


<!-- Original:  Tom Khoury (softricks@hotmail.com) -->
<!-- Compatibility:  IE 3.0+, NS 3.0+, Mac/Win -->
<!-- Web Site:  http://javascript.about.com/library/scripts/blfirstfocus.htm -->
<!--  places the cursor within the first user field upon painting a screen. -->

function firstFocus()  
{
  if (document.forms.length > 0)  {
    var TForm = document.forms[0];
    for (var ii=0; ii<TForm.length; ii++)  {
		if ((TForm.elements[ii].type == "text") ||
			(TForm.elements[ii].type == "textarea") ||
			(TForm.elements[ii].type == "select-one"))  {
        
        if (TForm.elements[ii].type != "select-one")
			document.forms[0].elements[ii].select();
        document.forms[0].elements[ii].focus();
        break;
        }
      }
    }	
}

// open a calendar popup window
function calendarPicker(strURL,strField)
{
	calendarPopup = window.open(strURL + '/DatePicker.aspx?field=' + strField,'calendarPopup','width=262,height=168,top=420,left=600,resizable=yes');
	calendarPopup.focus();
}

function ShelfLabelSampleImage(strURL,strImage)
{
	ShelfLabelSample = window.open(strURL + '/ShelfLabelSampleImage.aspx?strImage=' + strURL+strImage,'ShelfLabelSample','width=650,height=600,top=100,left=100,resizable=yes,scrollbars=yes');
	ShelfLabelSample.focus();
}

function handleEnter (field, event) {
		var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
		if (keyCode == 13) {
			var i;
			for (i = 0; i < field.form.elements.length; i++)
				if (field == field.form.elements[i])
					break;
			i = (i + 1) % field.form.elements.length;
			field.form.elements[i].focus();
			return false;
		} 
		else
		return true;
	}      
