/*********************************************************************** 
			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;
}

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() 
}
 
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") ||  
			(TForm.elements[ii].type == "select-multiple"))  {
			if ((TForm.elements[ii].type == "text") || (TForm.elements[ii].type == "textarea"))
				TForm.elements[ii].select();
			TForm.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 WriteCopyRightYear()
{
	var today = new Date();
	var year  = y2k(today.getYear());
	year = year < 1000) ? year + 1900 : number; 
	document.write(year);
}
*/

// enable / disable a button
function ToggleButton(oButton, intEnable)
{	
	// enable the "Submit" button once it's done.
	if (oButton != null)
	{	
		if (intEnable == 1)
			oButton.disabled = false;
		else
			oButton.disabled = true;				
	}
}


// button click event		
function clickButton(e, buttonid){ 
var bt = document.getElementById(buttonid); 
	if (typeof bt == 'object'){ 
			if(navigator.appName.indexOf("Netscape")>(-1)){ 
				if (e.keyCode == 13){ 																
					return valclickButton(bt);
				} 
			} 
			if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
				if (event.keyCode == 13){ 	
					return valclickButton(bt);
				} 
			} 
	} 
} 	

function clickButton2(e, buttonid){ 
	var bt = document.getElementById(buttonid); 		
		if (typeof bt == 'object' ){ 
				if(navigator.appName.indexOf("Netscape")>(-1)){ 							
					 return valclickButton2();
				} 
				if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 							
					return valclickButton2();
				} 
		} 
	}
function valclickButton(bt){

	if (document.forms[0].elements['ProductsMenu_txtProductSearch'].value =="")
	{
		alert('A search criterion is required to conduct a product search.');
		return false;
	}else{
		bt.click(); 
		return false; 
	}
}

function valclickButton2(){
	if (document.forms[0].elements['ProductsMenu_txtProductSearch'].value =="")
	{
		alert('A search criterion is required to conduct a product search.');
		return false;
	}
	else
	{	
		return true;											
	}
}
	
 		