//Expand form with a new File fields if needed.
function Expand(){


if(nfiles<10){
  nfiles++;

document.all['nfiles'].value =  nfiles;

// =  nfiles;
//  var adh = '<BR> File '+nfiles+' : <input type="file" name="File'+nfiles+'">';
//  var adh = '<TR><TD valign=top class=control_label_TD nowrap>&nbsp;&nbsp;&nbsp;File 4 Title&nbsp;:</td><TD class=form_control_TD><INPUT onkeydown="dataChanged = true;" class="form_control"  TYPE="text" NAME="f_4_name" SIZE=40 MAXLENGTH=255 VALUE="" ></TD></tr>' +
//			'<TR><TD valign="top" class="control_label_TD" width="" nowrap>&nbsp;&nbsp;&nbsp;File 4&nbsp;:</td><TD class="form_control_TD"><input type=hidden name=f_4_file_old value=""><INPUT  onkeydown="dataChanged = true;" class="form_control"  TYPE=file NAME="f_4_file" SIZE=40 MAXLENGTH=4000>&nbsp;&nbsp;<font color="#000000"><INPUT type=checkbox name=f_4_file_del value=1>Delete?<small><br>(<a name="f_4_file_prv" id="f_4_file_prv" target="_img" href="/Files/Admin/"></a>)&nbsp;</small></font></TD></tr>';

//  files.insertAdjacentHTML('beforeEnd',adh);
	var oTR1 = files.insertRow(3+(nfiles*2));
	var oTR2 = files.insertRow(4+(nfiles*2));

	oTR1.insertCell();
	oTR1.insertCell();
	oTR2.insertCell();
	oTR2.insertCell();


	oTR1.cells(0).innerHTML = '&nbsp;&nbsp;&nbsp;File ' + nfiles + ' Title&nbsp;:';
	oTR1.cells(0).vAlign = 'top';
	oTR1.cells(0).noWrap = true;
	oTR1.cells(0).className = 'control_label_TD';
	
	oTR1.cells(1).innerHTML = '<INPUT onkeydown="dataChanged = true;" class="form_control"  TYPE="text" NAME="f_' + nfiles + '_name" SIZE=40 MAXLENGTH=255 VALUE="" >';
	oTR1.cells(1).vAlign = 'top';
	oTR1.cells(1).noWrap = true;
	oTR1.cells(1).className = 'form_control_TD';


	oTR2.cells(0).innerHTML = '&nbsp;&nbsp;&nbsp;File ' + nfiles + '&nbsp;:';
	oTR2.cells(0).vAlign = 'top';
	oTR2.cells(0).noWrap = true;
	oTR2.cells(0).className = 'control_label_TD';

	oTR2.cells(1).innerHTML = '<input type=hidden name=f_' + nfiles + '_file_old value=""><INPUT  onkeydown="dataChanged = true;" class="form_control"  TYPE=file NAME="f_' + nfiles + '_file" SIZE=40 MAXLENGTH=4000>&nbsp;&nbsp;<font color="#000000"><INPUT type=checkbox name=f_' + nfiles + '_file_del value=1>Delete?<small><br>(<a name="f_' + nfiles + '_file_prv" id="f_' + nfiles + '_file_prv" target="_img" href="/Files/Admin/"></a>)&nbsp;</small></font>';
	oTR2.cells(1).vAlign = 'top';
	oTR2.cells(1).noWrap = true;
	oTR2.cells(1).className = 'form_control_TD';

//	files.rows(15).innerHTML='<td>sdsd</td>';
//	alert(files.rows.length);
//}else{
	
}


if(nfiles==10)document.all['btnAddFile'].disabled = true;

  return false;
}



			function baseOnLoad_Action()
			{

				// hash should be applied before Focus is set
				// 			 
//				setFocusByDefault();
			}
			
			function setFocusByDefault()
			{
				// set focus for first met element at first met form
				// search from elements: text, textarea, file, select
				for (var i = 0; i < document.forms.length; i++)
				{
					var frm = document.forms[i];
					for (var j = 0; j < frm.elements.length; j++)
					{
						var el = frm.elements[j];
//
						if ((el.type == 'text' || el.type == 'textarea' || el.type.search('select') || el.type == 'file' != -1) && el.id!='programs')
						{
						    // we need it to skip non visible controls like select boxes for Calendar
							try
							{
								el.focus();
								return;
							}
							catch(error) {}
//							return;
						}
					}
				}				
			}




function changeToolStyle(srcDiv,state)
{
	if(state == "out")
	{
		srcDiv.style.cursor='deafult';
		srcDiv.children[0].style.textDecoration='none';
	}
	else if(state == "over")
	{
		srcDiv.style.cursor='hand';
		srcDiv.children[0].style.textDecoration='underline';
	}
}

function changeImage(Image, newsrc)
{
	if (frmMain[Image]!='undefined')	
		frmMain[Image].src = newsrc;
}




function confirmDelete() {
	if( confirm("\nAre you sure you want to delete this record?\n\n")) {
		frmMain.btnAction.value = "Delete";
		frmMain.ListSearchText.value='';
		frmMain.submit();
	}
}
 
//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str){
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str){
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str){return LTrim(RTrim(str));}
//-------------------------------------------------------------------
// isNull(value)
//   Returns true if value is null
//-------------------------------------------------------------------
function isNull(val){return(val==null);}

//-------------------------------------------------------------------
// isBlank(value)
//   Returns true if value only contains spaces
//-------------------------------------------------------------------
function isBlank(val){
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isInteger(value)
//   Returns true if value contains all digits
//-------------------------------------------------------------------
function isInteger(val){
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
		}
	return true;
	}

//-------------------------------------------------------------------
// isNumeric(value)
//   Returns true if value contains a positive float value
//-------------------------------------------------------------------
function isNumeric(val){return(parseFloat(val,10)==val);}

//-------------------------------------------------------------------
// isDigit(value)
//   Returns true if value is a 1-character digit
//-------------------------------------------------------------------
function isDigit(num) {
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
	}

function checkDate(inDate) {
	var dateStr = inDate.value;
	if (arguments.length == 2) if (arguments[1] == true && isBlank(dateStr)) return true;
	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/; // requires 4 digit year

	var matchArray = dateStr.match(datePat); // is the format ok?
	if (matchArray == null) {
		alert(dateStr + " Date is not in a valid format.")
        inDate.focus();
		return false;
	}
	
	month = matchArray[1]; // parse date into variables
	day = matchArray[3];
	year = matchArray[4];


	if (month < 1 || month > 12) { // check month range
		alert("Month must be between 1 and 12.");
        inDate.focus();		
		return false;
	}

	if (day < 1 || day > 31) {
		alert("Day must be between 1 and 31.");
        inDate.focus();		
		return false;
	}
	
	if ((month==4 || month==6 || month==9 || month==11) && day==31) {
		alert("Month "+month+" doesn't have 31 days!")
        inDate.focus();		
		return false;
	}

	if ( !( (year >= 1 && year <= 99) || (year >= 1000 && year <= 9999) ) ) {
		alert("Year must be between 01 and 99 or 1000 and 9999.");
        inDate.focus();		
		return false;
	}

	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day>29 || (day==29 && !isleap)) {
			alert("February " + year + " doesn't have " + day + " days!");
			inDate.focus();			
			return false;
		}
	}
	return true;
}

function getField(fld, i) {
	if (fld.length == undefined)
		return fld;
	else
		return fld[i];
}



