function displayTRs()
{	

	var row = document.getElementById("tr_field_15949");
	if (row.style.display == '')  
	{
		// display/hide the other rows also	
		row.style.display = 'none';
        document.getElementById("tr_field_17287").style.display = 'none';
		document.getElementById("tr_field_15955").style.display = 'none';
		document.getElementById("tr_field_15953").style.display = 'none';
		document.getElementById("tr_field_15959").style.display = 'none';
		document.getElementById("tr_field_15957").style.display = 'none';
		document.getElementById("expandIMG").src = '../images/Expand_large.gif';
	}
	else 
	{
		row.style.display = '';
        document.getElementById("tr_field_17287").style.display = '';
		document.getElementById("tr_field_15955").style.display = '';
		document.getElementById("tr_field_15953").style.display = '';
		document.getElementById("tr_field_15959").style.display = '';
		document.getElementById("tr_field_15957").style.display = '';
		document.getElementById("expandIMG").src = '../images/Collapse_large.gif';
	}
}

function displayCoTRs()
		{	
			var row = document.getElementById("tr_field_16127");
			if (row.style.display == '')  
			{
				// display/hide the other rows also	
				row.style.display = 'none';
				document.getElementById("tr_field_16127").style.display = 'none';
				document.getElementById("tr_field_16129").style.display = 'none';
				document.getElementById("tr_field_16131").style.display = 'none';
				document.getElementById("tr_field_16133").style.display = 'none';
				document.getElementById("tr_field_16134").style.display = 'none';
				document.getElementById("expandIMG").src = '../images/Expand_large.gif';
				
			}
			else 
			{
				row.style.display = '';
				document.getElementById("tr_field_16127").style.display = '';
				document.getElementById("tr_field_16129").style.display = '';
				document.getElementById("tr_field_16131").style.display = '';
				document.getElementById("tr_field_16133").style.display = '';
				document.getElementById("tr_field_16134").style.display = '';
				document.getElementById("expandIMG").src = '../images/Collapse_large.gif';
			}
		}
		
	function displaySpecDiv()
		{	
			var row = document.getElementById("specialties");
			if (row.style.display == '')  
			{
				// display/hide the other rows also	
				row.style.display = 'none';
				document.getElementById("specialties").style.display = 'none';
				document.getElementById("expandIMG2").src = '../images/Expand_large.gif';
				
			}
			else 
			{
				row.style.display = '';
				document.getElementById("specialties").style.display = '';
				document.getElementById("expandIMG2").src = '../images/Collapse_large.gif';
			}
		}

		
function delPayment(id,returnURL) {
  	    var ok = confirm('Are you sure you want to delete the record');
        if (ok) {
            window.location.href ='../thirdgen/user/index.cfm?action=deleteFormData&deleteFormDataId='+id+'&returnTo='+escape(returnURL)
        }
    }
	
function locationLookup(memtype)
{
  //  eval("var currentValue = document.f_."+fld+".value");
  //  eval("var currentValueDisplay = document.f_."+fld+"_display.value");
  //  eval("var currentValueListSource = document.f_."+fld+"_listsource.value");
  
  //  pickWindowUrl = "/thirdgen/form/pickListValue.cfm?currentValue="+escape(currentValue)
  //  pickWindowUrl += "&currentValueDisplay="+escape(currentValueDisplay)
  //  pickWindowUrl += "&listSource="+escape(currentValueListSource)
  //  pickWindowUrl += "&functiontoRunOnClose=externalLookupDone931"
  //  pickWindowUrl += "&fld="+escape(fld)
  //  pickWindowUrl += "&frm="+931
  //  thePickWindow=open(pickWindowUrl,"pickwin","top=10,left=10,width=800,height=400,scrolling=auto,scrollbars=yes")        
	
	pickWindowUrl = "../custom/memAdmin_locatPick.cfm?memtype="+escape(memtype)
//    pickWindowUrl += "&currentValueDisplay="+escape(currentValueDisplay)
    thePickWindow=open(pickWindowUrl,"pickwin","top=10,left=10,width=800,height=400,scrolling=auto,scrollbars=yes")        
	
	
}

function locationLookupDone(id)
{
   // var reQUOT = new RegExp ('_QUOT_', 'gi')
   // var reDBQUOT = new RegExp ('_DBQUOT_', 'gi')
   // eval("var fieldValueHandle = document.f_."+fld)
   // eval("var fieldDisplayHandle = document.f_."+fld+"_display")
   // fieldValueHandle.value=id
   // fieldDisplayHandle.value=dv.replace(reQUOT,"'").replace(reDBQUOT,'"')
    
  //  if (typeof customExternalLookupDone931 != "undefined")
   // {
    //    customExternalLookupDone931(fld,id,dv,customReturnValues)
    //}
	
	 eval("var parentTreeNodeID = document.nodePick.parentTreeNodeID");
    parentTreeNodeID.value=id;
}	

function memPick(urlPrefix)
{
	pickWindowUrl = urlPrefix+"memPick.cfm"
    thePickWindow=open(pickWindowUrl,"pickwin","top=10,left=10,width=800,height=400,scrolling=auto,scrollbars=yes")        
}

function memLookupDone(id)
{
	 eval("var memberId = document.selectMember.utnid_pfdid");
    memberId.value=id;
}	

function debtorLookupDone(id,coName)
{
	 eval("var compName = document.pmtForm.debtor_display");
	 eval("var debtorId = document.invoicePmt.debtorCode");
	 var reQUOT = new RegExp ('_QUOT_', 'gi')
	 var reDBQUOT = new RegExp ('_DBQUOT_', 'gi')
    compName.value=coName.replace(reQUOT,"'").replace(reDBQUOT,'"');
	debtorId.value=id;
	document.getElementById("invoiceSub").disabled = false;
}	

function searchVal()
		{
			var theVal = document.getElementById("searchText").value;
			
			if (theVal.length < 2)
			{
				alert("You must search on at least 2 characters");
				document.getElementById("searchText").focus();
			}
			else
			{
				
				document.getElementById("searchForm").submit();
			}
		}
		

		function g_trim1009(ts) {
    if (ts) {
        ts=""+ts
        for (;ts.charAt(ts.length-1)==' ';) 
            ts=ts.substring(0,ts.length-1);
        for (;ts.charAt(0)==' ';)
            ts=ts.substring(1,ts.length);
    }
    return ts;
}
// Returns the shortname of the supplied month number
function g_getshtmnth1009(monthno)
{
	var m=new Array(12);
	m[1]="Jan";		m[2]="Feb";		m[3]="Mar";		m[4]="Apr";
	m[5]="May";		m[6]="Jun";		m[7]="Jul";		m[8]="Aug";
	m[9]="Sep";		m[10]="Oct";	m[11]="Nov";	m[12]="Dec";
	if (monthno>=1 && monthno <=12)	return m[monthno];
	else return false;
}
	
// Returns the month number of the supplied month name. eg g_getmnthnum(January) returns 1
function g_getmnthnum1009(monthname)
{
	var sm=monthname.substring(0,3).toLowerCase()
	for (x=1;x<=12;x++)	{
			if (sm==g_getshtmnth1009(x).toLowerCase())
			return x;
		}
	return false;
}
	
// Checks if the number of days is valid for the supplied month and year.	
function g_chkdaysmnth1009(days,month,year)
{
	if (month==1 || month==3 || month==5 || month==7 || month==8 || month==10 || month==12)
		if (days>=1 && days <=31) return true;
		else return false; 
	if (month==4 || month==6 || month==9 || month==11)
		 if (days>=1 && days <=30) return true;
		 else return false; 
	if (month==2) 
		if (days>=1 && days <=28) return true;
		else
			if (days==29) 
			 	if (parseInt(year/4,10)==(year/4)) return true;
				else return false;
			else return false;
}

// Examines a text field and tries to convert it into a recognised date.	
function g_checkdate1009(fd_datefield,date_format,no_change,clear_it)
{
	if (!date_format) date_format="DD/MM/YYYY"
	date_format=date_format.toUpperCase()
	var datefield = g_trim1009(fd_datefield.value)
	if (g_trim1009(datefield)=='')
	{
		if (!no_change) // If this has a value, don't fire the pagechanged event
			if (typeof pagechanged != "undefined") 
				pagechanged()
		return true;
	}
	//convert slashes to dashes
	while (datefield.indexOf("/") != -1) 
	{  // The end of the next line is not commented out. Only the editor thinks so!
		datefield = datefield.replace(/\//g,"-"); 
	}
	// convert spaces to dashes
	while (datefield.indexOf(" ") != -1) 
	{  // The end of the next line is not commented out. Only the editor thinks so!
		datefield = datefield.replace(/\ /g,"-"); 
	}
	// remove commas
	while (datefield.indexOf(",") != -1) 
	{  // The end of the next line is not commented out. Only the editor thinks so!
		datefield = datefield.replace(/\,/g,""); 
	}
	var delim1 = datefield.indexOf("-");   		// find the first dash
	var delim2 = datefield.lastIndexOf("-");	// find the last dash
	if (delim1 != -1 && delim1 == delim2) {		// if both can't be found then give up
		alert ('Date format not valid.');
		if (clear_it)
			fd_datefield.value=""
		else
		{
			fd_datefield.focus();
			fd_datefield.select();
		}
		return false;
	}
	if (delim1 != -1) 
	{	 // There are delimiters
		if (date_format=="MMM-DD-YYYY")
		{
			var mmstring=datefield.substring(0,delim1);	// extract the month part
			var dd=parseInt(datefield.substring(delim1+1,delim2),10);	// extract the day part
		} else
		{ // Assume Euro Date
			var dd=parseInt(datefield.substring(0,delim1),10);	// extract the day part
			var mmstring=datefield.substring(delim1+1,delim2);	// extract the month part
		}
		if (isNaN(mmstring)) { //if the month isn't a number, check for a month name.
			var mm=g_getmnthnum1009(mmstring);	// convert the monthname to a number
			if (isNaN(mm)) { 	// if it couldn't be converted, then exit.
				alert('Date format not valid. Month name not found');
				if (clear_it)
					fd_datefield.value=""
				else
				{
					fd_datefield.focus();
					fd_datefield.select();
				}
				return false;
			}
		} else { var mm=parseInt(mmstring,10); } // the month is a number, so keep it
		var yyyy=parseInt(datefield.substring(delim2+1,datefield.length),10); // get the year part
	} else 
	{ // there are no delimitors. Assume a date format of DDMMYY[YY] or MMDDYY[YY]
		if (date_format=="MMM-DD-YYYY")
		{
			var mm=parseInt(datefield.substring(0,2),10);	// get the month part
			var dd=parseInt(datefield.substring(2,4),10);	// get the day part
		} else
		{
			var dd=parseInt(datefield.substring(0,2),10);	// get the day part
			var mm=parseInt(datefield.substring(2,4),10);	// get the month part
		}
		var yyyy=parseInt(datefield.substring(4,datefield.length),10);	// get the year part
	}
	yyyy=parseInt(g_trim1009((yyyy+"    ").substring(0,4)))
	if (isNaN(dd) || isNaN(mm) || isNaN(yyyy)) {	// All the fields need to be numeric
		alert('Date format not valid - Non numeric entries');
		if (clear_it)
			fd_datefield.value=""
		else
		{
			fd_datefield.focus();
			fd_datefield.select();
		}
		return false;
	}
	if (mm<1 || mm >12) {	// month as to be 1 to 12 
		alert('Date format not valid. Invalid month');
		if (clear_it)
			fd_datefield.value=""
		else
		{
			fd_datefield.focus();
			fd_datefield.select();
		}
		return false;
	}
	if (yyyy < 100)		// If the year had only 2 digits
		if (yyyy > 30) yyyy+=1900; else yyyy+=2000;		// add to it. Pivot year is 1930
	if (yyyy < 1753) {	// SQL doesn't like less than 1753
		alert('Date not valid. Invalid Year');
		if (clear_it)
			fd_datefield.value=""
		else
		{
			fd_datefield.focus();
			fd_datefield.select();
		}
		return false;
	}

	if (!g_chkdaysmnth1009(dd,mm,yyyy)) {	// Check the number of days is valid for this month.
		alert('Date format not valid. Invalid days');
		if (clear_it)
			fd_datefield.value=""
		else
		{
			fd_datefield.focus();
			fd_datefield.select();
		}
		return false;
	}
	if (date_format=="MMM-DD-YYYY")
	{
		fd_datefield.value=""+g_getshtmnth1009(mm)+" "+dd+", "+yyyy;	// Format the return date as MMM-DD-YYYY
	} else
	{
		fd_datefield.value=""+dd+"/"+mm+"/"+yyyy;	// Format the return date as dd/mm/yyyy
	}
	return true;
}

function validate(fieldName,maxLimit) {
    var formField = eval("document.forms[0]." + fieldName);
    var counter = formField.value.length;
    var textAreaValue = formField.value;
    if(counter > maxLimit) {
        // reverse the value to eliminate the last char.
        textAreaValue = rev(textAreaValue);
        textAreaValue=textAreaValue.substring(1, textAreaValue.length);
        //reverse back to get the original string
        formField.value = rev(textAreaValue);
        alert('Too much data in the text area.\n Maximum characters allowed are ' + maxLimit);
    }
}

function rev(text){
    var backwards="";
    for(count=text.length; count >= 0; count--)
    backwards+=text.substring(count,count-1);
    return(backwards);
}
	
		function popupwindowfield_dateFrom(datename)
		{
			theValue='document.all.' + datename + '.value'
			UrlForPopUp = '../thirdgen/util/calendar/jscalwin.cfm?cha=no&format=dd%2Fmm%2Fyyyy&datefield=' + datename
			if( eval(theValue) != '') {
				theValue = eval(theValue)
				UrlForPopUp = UrlForPopUp + '&formdate=' + escape(theValue)
			}
			if (typeof datewindow != "undefined") {
				if (datewindow && !datewindow.closed)
					datewindow.close();
			}
		    var W=195;
		    var H=225;
			H=H+20+2;
		    W=W+2;
		    s = ",width="+W+",height="+H;
		    datewindow=window.open(UrlForPopUp,"jsdatewindow","left=600,top=80,location=0,directories=0,status=0,menubar=0,scrollbars=no,toolbar=0,resizable=0"+s);
		    datewindow.resizeTo(Math.ceil(W),Math.ceil(H));
		    datewindow.moveTo(600,80);
		}
		
		function popupwindowfield_dateTo(datename)
		{
			theValue='document.all.' + datename + '.value'
			UrlForPopUp = '../thirdgen/util/calendar/jscalwin.cfm?cha=no&format=dd%2Fmm%2Fyyyy&datefield=' + datename
			if( eval(theValue) != '') {
				theValue = eval(theValue)
				UrlForPopUp = UrlForPopUp + '&formdate=' + escape(theValue)
			}
			if (typeof datewindow != "undefined") {
				if (datewindow && !datewindow.closed)
					datewindow.close();
			}
		    var W=195;
		    var H=225;
			H=H+20+2;
		    W=W+2;
		    s = ",width="+W+",height="+H;
		    datewindow=window.open(UrlForPopUp,"jsdatewindow","left=600,top=80,location=0,directories=0,status=0,menubar=0,scrollbars=no,toolbar=0,resizable=0"+s);
		    datewindow.resizeTo(Math.ceil(W),Math.ceil(H));
		    datewindow.moveTo(600,80);
		}
