var gbSubmitted = new Boolean(false);
function SubmitOnce() 
{
   if (gbSubmitted == false)
   {
        gbSubmitted = true;
        return true;
   }
   else
   {
        alert("You have already submitted this form. If you have had no response then please Refresh/Reload and try again.");
        return false;
   }
}


function jsValue(objValue) {
	var dblValue=0;
	dblValue=parseFloat(objValue);
	if (isNaN(dblValue)) return 0;	
	return dblValue;
}

function jsLTRIM(strText) {
	var i=0;   
	for (i=0;i<strText.length;i++) if (strText.charCodeAt(i)!=32) break;
	return strText.substr(i);   
}

function jsRTRIM(strText) {
	var i=0;   
	for (i=strText.length-1;i>=0;i--) if (strText.charCodeAt(i)!=32) break;
	return strText.substr(0,i+1);   
}

function jsTRIM(strText) {   
	return jsLTRIM(jsRTRIM(strText));
}

function jsFormatNumber(cyValue, iDecPlaces) {	
	var strText, dblValue, dStr, pStr;
	strText='';
	cyValue= jsValue(cyValue );
	
	dblValue=Math.abs((Math.round(cyValue*100)/100));
	strText=''+dblValue;
	
	if (strText.indexOf('.')<0) strText+='.'
	
	dStr=strText.substr(0,strText.indexOf("."));
	
	dNum=dStr-0;
	if (iDecPlaces) {
		pStr=strText.substr(strText.indexOf("."));
		while (pStr.length<(iDecPlaces+1)) pStr+="0";
		strText = dStr + pStr;
		}
	else strText = dStr;
	if (cyValue<0) strText='-' + strText;
	return strText;
}


function jsCurrency( cyValue ) {
	return jsFormatNumber(cyValue,2);
	}


	
function jsRight( strValue, iCount ) {
	var strText = new String(strValue);
	if (iCount<1) iCount=0;
	if (iCount<strText.length) {
		var i=strText.length-iCount;
		return strText.substring(i,i+iCount);
	}
	else return strText;
}

function jsLeft( strValue, iCount ) {
	var strText = new String(strValue);
	if (iCount<1) iCount=0;
	return strText.substring(0,iCount);
}


function jsFormatDateTime( oDate ) {
	var d, m, y, h, mi;
	if (oDate == null) return '';
	d=oDate.getDate();
	m=oDate.getMonth()+1;
	y=oDate.getFullYear();				
	h=oDate.getHours();
	mi=oDate.getMinutes();	
	if (h || mi) return	jsRight('00' + m,2) + '/' + jsRight('00'+d,2) + '/' + jsRight('0000'+y,4) +' '+ jsRight('00'+h,2) + ':' + jsRight('00'+mi,2);
	return jsRight('00' + m,2) + '/' + jsRight('00'+d,2) + '/' + jsRight('0000'+y,4);

}


function jsFormatDate( oDate ) {
	var d, m, y;	
	if (oDate == null) return'';
	d=oDate.getDate();
	m=oDate.getMonth()+1;
	y=oDate.getFullYear();				

	return jsRight('00' + m,2) + '/' + jsRight('00'+d,2) + '/' + jsRight('0000'+y,4);
}


function jsText2Date(strDateText) {	
	var d=0, m=0, y=0, th=0, tm=0;
	var p = new Array();		
	var i, bNewWord=true, iWordCount = 0, j;	
	var strLocalDate = new String(strDateText);
	for (i=0;i<strLocalDate.length;i++) 
		{
			switch (strLocalDate.charAt(i)) {
				case ' ':
				case '/':
				case ':':
				case '.':
				case '-':
					bNewWord=true;
					break;
					
				default:
					if (bNewWord) {
						iWordCount++;
						p[iWordCount]='';
						bNewWord=false;												
						}
					p[iWordCount] += strLocalDate.charAt(i);
				}			
		};	
	
	//Test for Year between 1900-2099
	for (i=1; i<=iWordCount;i++) {
		j=jsValue(p[i]);
		if (j>=1900 && j<=2099 && p[i].length) {
			y=j;
			p[i]='';
			break;
			}
		}
		
	//Test for Month Name
	for (i=1; i<=iWordCount;i++) {
		switch (p[i].toUpperCase()) {
			case 'JAN':
			case 'JANUARY':
				m=1;
				p[i]='';
				break;
			case 'FEB':
			case 'FEBRUARY':
				m=2;
				p[i]='';
				break;
			case 'MAR':
			case 'MARCH':
				m=3;
				p[i]='';
				break;
			case 'APR':
			case 'APRIL':
				m=4;
				p[i]='';
				break;
			case 'MAY':
				m=5;
				p[i]='';
				break;
			case 'JUN':
			case 'JUNE':
				m=6;
				p[i]='';
				break;
			case 'JUL':
			case 'JULY':
				m=7;
				p[i]='';
				break;
			case 'AUG':
			case 'AUGUST':
				m=8;
				p[i]='';
				break;
			case 'SEP':
			case 'SEPTEMBER':
				m=9;
				p[i]='';
				break;
			case 'OCT':
			case 'OCTOBER':
				m=10;
				p[i]='';
				break;
			case 'NOV':
			case 'NOVEMBER':
				m=11;
				p[i]='';
				break;
			case 'DEC':
			case 'DECEMBER':
				m=12;
				p[i]='';
				break;
			}
		}

		
	//set Month to next non blank numeric field if month isn't already set
	if (! m ) for (i=1; i<=iWordCount;i++) {
		j=jsValue(p[i]);
		if (j>=1 && j<=12  && p[i].length) {
			m=j;
			p[i]='';
			break;
			}
		}
		
	//Set Day to first non blank numeric field
	for (i=1; i<=iWordCount;i++) {
		j=jsValue(p[i]);
		if (j>=1 && j<=31  && p[i].length) {
			d=j;
			p[i]='';
			break;
			}
		}

		
	//set Year to next non blank numeric field if year isn't already set
	if (! y ) for (i=1; i<=iWordCount;i++) {
		j=jsValue(p[i]);
		if ( ((j>=0 && j<=99)  || (j>=1900  && j<=2099) )  && p[i].length ) {
			y=j;
			p[i]='';
			break;
			}
		}

	//set Hour to next non blank numeric field if year isn't already set
	if (! th ) for (i=1; i<=iWordCount;i++) {
		j=jsValue(p[i]);
		if ( j>=0 && j<=23   && p[i].length ) {
			th=j;
			p[i]='';
			break;
			}
		}

	//set Minutes to next non blank numeric field if year isn't already set
	if (! tm ) for (i=1; i<=iWordCount;i++) {
		j=jsValue(p[i]);
		if ( j>=0 && j<=59   && p[i].length ) {
			tm=j;
			p[i]='';
			break;
			}
		}
		
	if (y<40) y +=2000;
	if (y<=99) y +=1900;

	switch (m) {
		case 1:
		case 3:
		case 5:
		case 7:
		case 8:
		case 10:
		case 12:
			if (d>31) d=31;
			break;
		case 2:
			if ( (y % 4) ==0) if (d>29) d=29;
			if ( (y % 4) ) if (d>28) d=28;
			break;
		default:
			if (d>30) d=30;
		}
	if (d==0) return null;
	if (th || tm) return new Date(y,(m-1),d, th, tm);	
	return new Date(y,(m-1),d);	
}

function jsHTMLEncode(strText) {
	var str=new String(strText);
	return str.replace(/"/g, '&quot;');
}

function AskFreeTypeChoice(strPromptTitle, oName,n) {
	var o=eval('document.frmRecord.' + oName);
	var strCode='', i;
	i=n+1;
	if ( o.options[i] != null ) strCode = o.options[i].text 
	strCode = prompt(strPromptTitle,strCode);
//	strCode = vb_Prompt('Please Choose Your Free Type Entry', strCode);
	if ( strCode != null ) {
		o.options[i] = null;
		o.options[i] = new Option(strCode, strCode);
		o.selectedIndex = i;
		}

}