/*********************************************************************************************************
Replaces ALL instances of the given substring.
*********************************************************************************************************/
function JSTools_ReplaceAll(strStringToSearch, strLookingFor, strReplaceWith)
{
	var intIndexOfMatch = strStringToSearch.indexOf(strLookingFor);
	 

	// Keep looping while an instance of the target string
	// still exists in the string.
	while (intIndexOfMatch != -1)
	{
		// Relace out the current instance.
		strStringToSearch = strStringToSearch.replace(strLookingFor, strReplaceWith)
	 
		// Get the index of any next matching substring.
		intIndexOfMatch = strStringToSearch.indexOf(strLookingFor);
	}
	 

	// Return the updated string with ALL the target strings
	// replaced out with the new substring.
	return(strStringToSearch);
}

	
/*********************************************************************************************************
This will show a popup window for the url specified, with parameters to specify the look.
Parameters look like: JSTools_PopupWindow('<%=strDomain%>/airfares/destinations.asp', 'Destinations', 590, 660,'no','no','yes','no','no','no', 10, 100)
*********************************************************************************************************/
function JSTools_PopupWindow(url, windowname, w, h, blnToolbar, blnResize, blnScroll, blnMenubar, titlebar, directories, intTop, intLeft)
{
	if (! window.focus)return true;
	newWindow = window.open(url, windowname, 'width=' + w + ',height=' + h + ',toolbar=' + blnToolbar + ',directories=' + directories + ',modal=yes,status=yes,dialog=no,minimizable=no,location=no,resizable=' + blnResize + ',scrollbars=' + blnScroll + ',titlebar=' + titlebar + ',menubar=' + blnMenubar + ',top=' + intTop + ',left=' + intLeft);
}


/*********************************************************************************************************
Adds a function to the onload event for the page, if there is already one it adds it as well.
*********************************************************************************************************/
function addOnload(extraonloadfunction, paramlist) 
{
    var oldonload = window.onload;
    window.onload = function() 
    {
        //if there is an onload event already append it to the new event, otherwise just 
        //have the new event.
        if (onload) 
        {
            oldonload();
        }
        extraonloadfunction(paramlist);
    }
}

/*********************************************************************************************************
Removes leading and ending whitespaces.
*********************************************************************************************************/
function JSTools_Trim(str)
{
	var whitespace = ' \n\r\t\f\x0b\xa0\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u200b\u2028\u2029\u3000';
	for (var i = 0; i < str.length; i++) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(i);
			break;
		}
	}
	for (i = str.length - 1; i >= 0; i--) {
		if (whitespace.indexOf(str.charAt(i)) === -1) {
			str = str.substring(0, i + 1);
			break;
		}
	}
	return whitespace.indexOf(str.charAt(0)) === -1 ? str : '';
}



