function openSubWindow(strURL)
{
    if (isInternetExplorer())
    {
        window.open(strURL, "_blank", "height=500,width=600,menubar=0,toolbar=0,titlebar=0,status=1,resizable=1,left=" + parseInt((screen.width/2) - 300) + ",top=" + parseInt((screen.height/2) - 250));
    }
    else
    {
    
        window.open(strURL, "_blank", "height=600,width=600,menubar=0,toolbar=0,titlebar=0,status=1,resizable=1,left=" + parseInt((screen.width/2) - 300) + ",top=" + parseInt((screen.height/2) - 250));
    }
}
function openLookupWindow(strURL)
{
window.open(strURL, "_blank", "height=300,width=350,menubar=0,toolbar=0,titlebar=0,resizable=0,left=" + parseInt((screen.width/2) - 175) + ",top=" + parseInt((screen.height/2) - 150));
}
function openModalWindow(strURL)
{
var w = window.showModalDialog(strURL, "_blank", "dialogHeight:500px; dialogWidth:600px; help:no; status:no");
}
function openLargeSubWindow(strURL)
{
window.open(strURL, "_blank", "height=600,width=800,menubar=0,toolbar=0,titlebar=0,status=1,scrollbars=yes,resizable=yes,left=" + parseInt((screen.width/2) - 400) + ",top=" + parseInt((screen.height/2) - 400));
}
function openFeatureWindow(strURL)
{
window.open(strURL, "_blank", "height=650,width=800,menubar=0,toolbar=0,titlebar=0,scrollbars=yes,resizable=yes,left=" + parseInt((screen.width/2) - 400) + ",top=" + parseInt((screen.height/2) - 325));
}
function openInvoiceWindow(strURL)
{
var w = window.open(strURL, "_blank", "height=650,width=800,menubar=1,toolbar=0,titlebar=0,scrollbars=yes,resizable=yes,left=" + parseInt((screen.width/2) - 400) + ",top=" + parseInt((screen.height/2) - 400));
}
function openHelp(strCode, intTopic)
{
var w = window.open("help.aspx?code=" + strCode + "&topic=" + intTopic, "_blank", "height=450,width=450,menubar=0,toolbar=0,titlebar=0,scrollbars=yes,resizable=0,left=" + parseInt((screen.width/2) - 225) + ",top=" + parseInt((screen.height/2) - 225));
}
function openSmallWindow(strURL)
{
var w = window.open(strURL, "_blank", "height=450,width=450,menubar=0,toolbar=0,titlebar=0,scrollbars=yes,resizable=0,left=" + parseInt((screen.width/2) - 225) + ",top=" + parseInt((screen.height/2) - 225));
}
function openAttach(strURL)
{
window.open(strURL, "_blank", "height=300,width=375,menubar=0,toolbar=0,titlebar=0,status=1,scrollbars=no,resizable=no,left=" + parseInt((screen.width/2) - 200) + ",top=" + parseInt((screen.height/2) - 200));
}
function openPreviewWindow()
{
var w = window.open('admin_html_preview.aspx', "_blank", "height=500,width=600,menubar=0,toolbar=0,titlebar=0,status=1,resizable=0,scrollbars=yes,left=" + parseInt((screen.width/2) - 300) + ",top=" + parseInt((screen.height/2) - 250));
return w;
}
function openAutoTextWindow(strURL)
{
var w = window.open(strURL, "_blank", "height=525,width=325,menubar=0,toolbar=0,titlebar=0,status=1,resizable=0,scrollbars=no,left=" + parseInt((screen.width/2) - 100) + ",top=" + parseInt((screen.height/2) - 300));
}

/*-------------------------------------------------------------------------------
* By default, the form will automatically try to submit when the enter key is pressed.
* This is because the Search button will appear to be pressed since it is the only submit
* button on most forms. If you want to stop this from happening on a particular page, simply
* do the following 3 things:
* 1. Include this file in the web form using script tags
* 2. Set the blnAllowSubmit = false in the click event of the button
* 3. In the form tag, include onsubmit="return VerifySubmit();" This will check the submission and cancel it one time.
*
* This will do a one-time stoppage of the submission event allowing you to have other buttons that
* trigger on the enter key, but will not disable the search button entirely in case the user uses the
* the search field.
*------------------------------------------------------------------------------*/
var blnAllowSubmit = true;

function VerifySubmit()
{    
    if (blnAllowSubmit)
    {
        return true;
    }
    else
    {
        blnAllowSubmit = true;
        return false;
    }
}

var intLastLength = 0;
	
function lookupSelect(pstrSearch, plstLookup, phidValue)
{
	var intLength = pstrSearch.length;
	var check = false;
	
	var re = new RegExp("^" + pstrSearch, "i"); 
	for (var i = 0; i < plstLookup.options.length; i++)
	{
		if (check == false)
		{
			check = true;
			if ((intLength > intLastLength) && (intLength != 1))
			{
				intLastLength = intLength;
				if (plstLookup.selectedIndex > -1)
				{
					i = plstLookup.selectedIndex;
				}
			}
			else
			{
				intLastLength = 0;
			}
		}
						
		if (re.test(plstLookup.options[i].text))
		{
			plstLookup.selectedIndex = i;
			if (phidValue != null)
			{
				phidValue.value = plstLookup.options[plstLookup.selectedIndex].text;
			}
			break;
		}
		else
		{
			if (phidValue != null)
			{
				phidValue.value = '';
			}		
		}
		
	}
}

function lookupSelectByValue(pstrSearch, plstLookup)
{
	//does the same thing as lookupSelect, but checks the value of the drop
	//down options for an exact match rather than a begins with query.
	var intLength = pstrSearch.length;
	var check = false;
	
	plstLookup.selectedIndex = -1;
	
	for (var i = 0; i < plstLookup.options.length; i++)
	{
		//only do this the first time.
		if (check == false)
		{
			check = true;
			if ((intLength > intLastLength) && (intLength != 1))
			{
				intLastLength = intLength;
				if (plstLookup.selectedIndex > -1)
				{
					i = plstLookup.selectedIndex;
				}
			}
			else
			{
				intLastLength = 0;
			}
		}
						
		if (parseInt(plstLookup.options[i].value) == parseInt(pstrSearch))
		{
			plstLookup.options[i].selected = true;
			break;
		}
		
	}
}
function loadOneItemIntoDDL(ddlLoad, intID, strValue)
{
	ddlLoad.innerHTML = '';
	
	var fieldOpt = document.createElement('option');
	fieldOpt.setAttribute('value', intID);
	fieldOpt.innerHTML = strValue;

	ddlLoad.appendChild(fieldOpt);
}

function processKeyStroke()
{
	switch (window.event.keyCode)
	{
		case 2:		//CTRL + SHIFT + b
			var range = document.selection.createRange();
			range.text = "<b>" + range.text + "</b>";
			break;
		case 3:		//CTRL + SHIFT + c
			var range = document.selection.createRange();
			range.text = "&gt;";
			break;
		case 4:		//CTRL + SHIFT + d
			var range = document.selection.createRange();
			range.text = "<td>" + range.text + "</td>";
			break;
		case 9:		//CTRL + SHIFT + i
			var range = document.selection.createRange();
			range.text = "<i>" + range.text + "</i>";
			break;
		case 12:	//CTRL + SHIFT + l
			var range = document.selection.createRange();
			range.text = "<li>" + range.text + "</li>";
			break;
		case 15:	//CTRL + SHIFT + o
			var range = document.selection.createRange();
			range.text = "&lt;";
			break;
		case 18:	//CTRL + SHIFT + r
			var range = document.selection.createRange();
			range.text = "<br>";
			break;			
		case 20:	//CTRL + SHIFT + t
			var range = document.selection.createRange();
			range.text = "<table cellpadding=\"0\" cellspacing=\"0\" width=\"100%\"></table>";
			break;
		case 21:	//CTRL + SHIFT + u
			var range = document.selection.createRange();
			range.text = "<u>" + range.text + "</u>";
			break;
		case 23:	//CTRL + SHIFT + w
			var range = document.selection.createRange();
			range.text = "<tr>" + range.text + "</tr>";
			break;

	}
}

/*************************************************
This function parses an XML date of the following format.
yyyy-mm-ddThh:mm:ss.#######-05:00 (GMT)
2007-01-04T19:00:04.6230000-05:00

intFormat - specifies the format to return
0 returns mm/dd/yyyy
1 returns mm/dd/yyyy hh:mm:ss
2 returns mm/dd

*************************************************/
function parseXMLDataSetDate(strValue, intFormat)
{
	//first split on the decimal and trash the back half
	var strHalves = strValue.split('.');

	//now split the date and time on the T character
	var strParts = strHalves[0].split('T');
	var strDateParts = strParts[0].split('-');

	//finally reassemble 
	var strReturn;
	switch (intFormat)
	{
		case 0:
			strReturn = strDateParts[1] + '/' + strDateParts[2] + '/' + strDateParts[0];
			break;
		case 1:
			strReturn = strDateParts[1] + '/' + strDateParts[2] + '/' + strDateParts[0] + ' ' + strParts[1];
			break;
		case 2:
			strReturn = strDateParts[1] + '/' + strDateParts[2];
			break;
	}
	return strReturn;
}
function formatCurrency(num) 
{
num = num.toString().replace(/\$|\,/g,'');
if(isNaN(num))
    num = "0";

sign = (num == (num = Math.abs(num)));
num = Math.floor(num*100+0.50000000001);
cents = num%100;
num = Math.floor(num/100).toString();

if (cents < 10)
    cents = "0" + cents;
    
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3)) + ',' + num.substring(num.length-(4*i+3));
    
return (((sign)?'':'-') + '$' + num + '.' + cents);
}

//
String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
function isInternetExplorer(fltVersion)
{
	var blnReturn = false;
	
	if (window.navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER')
	{
		if (fltVersion != null)
		{
			var strVersion = window.navigator.appVersion;
			var fltApp = parseFloat(strVersion.split(';')[1].replace('MSIE', '').trim());
			if (fltApp >= fltVersion)
			{
				blnReturn = true;
			}
			else
			{
				blnReturn = false;
			}
		}
		else
		{		
			blnReturn = true;
		}
	}
	else
	{
		blnReturn = false;
	}
	return blnReturn;
}



