function IsNumeric(strString)
{
	var strValidChars = "0123456789.";
	var strChar;
	var blnResult = true;

	if (strString.length == 0)
	{
		return false;
	}

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
	{
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
		{
			blnResult = false;
		}
	}
	return blnResult;
}

function IsValidEmail(src)
{
	var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
	var regex = new RegExp(emailReg);
	return regex.test(src);
}

function TextAreaMaxLength( field, countfield, maxlimit )
{

	if ( field.value.length > maxlimit )
	{
		field.value = field.value.substring( 0, maxlimit );
		alert( 'Textarea value can only be ('+ maxlimit + ') characters in length.' );
		return false;
	}
	else
	{
		//alert(countfield == null);
		if (countfield != '' && countfield != null)
		{
			countfield.value = maxlimit - field.value.length;
		}
	}
}

function trim(s)
{
	while (s.substring(0,1) == ' ')
	{
		s = s.substring(1,s.length);
	}
	while (s.substring(s.length-1,s.length) == ' ')
	{
		s = s.substring(0,s.length-1);
	}
	return s;
}

function getCFldName(oSel)
{
	var id;
	var selValue;
	var mOldvalue;
	
	id=oSel.selectedIndex;
	
	selValue=oSel.options[id].text;
	
	mOldvalue=document.forms[0].MemoBody.value;
	document.forms[0].MemoBody.value = mOldvalue + " " + selValue;	
}

function CheckEditable(ChkEdit, strSuffix, bSysField)
{
	if (ChkEdit.checked)
	{
		eval('document.FrmLayOut.HiddenChkBox_'+strSuffix+'.checked=false');		
						
	}
	else
	{
		eval('document.FrmLayOut.RequiredChkBox_'+strSuffix+'.checked=false');
	}	
}

function CheckRequired(ChkReq, strSuffix, bSysField)
{
	if (ChkReq.checked)
	{
		//if required it should be editable, check editable
		eval('document.FrmLayOut.EditableChkBox_'+strSuffix+'.checked=true');
		//if requied can not be hidden
		eval('document.FrmLayOut.HiddenChkBox_'+strSuffix+'.checked=false');
	}
	else
	{
		//if not required  it can be either editable or hidden
	}
}
function CheckHidden(ChkHidden, strSuffix, bSysField)
{
	if (ChkHidden.checked){
		//if it is hidden can not be editable and required
		eval('document.FrmLayOut.EditableChkBox_'+strSuffix+'.checked=false');
		eval('document.FrmLayOut.RequiredChkBox_'+strSuffix+'.checked=false');				
	}
	else
	{
		//if not hidden it may be both editable and required
	}
}

function GotoBC(nodeLocation, totalDiv)
{			
	for (var i=1; i <= totalDiv; i++)
	{
		if (i == nodeLocation)
		{
			document.getElementById("divBreadCrumb_" + i).style.display = "";
		}
		else
		{
			document.getElementById("divBreadCrumb_" + i).style.display = "none";
		}
	}
}


function bcAction(FormID, FormAction, FormTarget, iTab)
{
	if (iTab != '')
	{
		top.HeaderFrame.SelectTab(iTab);
	}
	if (FormAction != '')
	{
		bcRedirect(FormID, FormAction, FormTarget);
	}
}

function bcRedirect(FormID, FormAction, FormTarget)
{
	document.title="entellium";
	if (FormID == '')
	{
		if (FormTarget != '')
		{
			//document.getElementById(FormID).target = FormTarget;
			document.forms[0].target = FormTarget;
		}
		document.forms[0].method = "post";
		document.forms[0].action = FormAction;
		document.forms[0].submit();
	}
	else
	{
		if (FormTarget != '')
		{
			document.getElementById(FormID).target = FormTarget;
		}
		document.getElementById(FormID).method = "post";
		document.getElementById(FormID).action = FormAction;
		document.getElementById(FormID).submit();
	}	
}

function ChangeTitle(ntitle)
{
	if(ntitle)
	{
		top.document.title ='entellium' + ' - ' +  ntitle;
	}
	else
	{
		top.document.title =  'entellium';
	}
}	

function SwithMainAction(__form, __url, iTab )
{
    top.HeaderFrame.SelectTab(iTab);
    GotoURL(__form, __url);
}

function GotoURL(__form, __url)
{
	__form.action = __url;
	__form.method = "post";
	alert(__form);
	alert(__form.action);
	alert(__form.method);
	alert(__form.target);
	__form.submit();
}

function CancelURL(URL)
{
	if((URL.substr(0, 7).toLowerCase())!= 'http://')
	{
		var  strhttp = 'http://';
	}
	else
	{
		var  strhttp= '';
	}
	document.FrmInput.action = strhttp + URL;
	document.FrmInput.method = "get"
	document.FrmInput.submit();
}

function FormSubmit(__form, Action, ValidateFields)
{
	var bError = false;
	var bError2 = false;
	var bError3 = false;
	var bError4 = false;
	var message = '';
	var message2 = '';
	var message3 = '';
	var message4 = '';
	var strNumFields ;
	var strDecimalFields;
	message = 'The following are required fields.\n\n'
	message2 = 'The following field(s) requires numeric input\n\n'
	message3 = 'You can only enter a value of up to 8 decimal places on the following field(s)\n\n'
	message4 = 'You can only enter up to 10 digits before the decimal, and up to 8 digits following it on The following field(s)\n\n'
	if (ValidateFields != "" && Action !=5)
	{
		var arrFields = ValidateFields.split(",");
		for (var i=0; i < arrFields.length; i++)
		{
			var FieldItem = arrFields[i].split("*");
			if (eval("document.FrmInput."+FieldItem[0]+".value") == "" )
			{
			message = message +'   * ' + FieldItem[1]+ '\n'
			bError = true;
			}

		}
	}
	strNumFields =document.getElementById('NumericField').value;
	strDecimalFields = document.getElementById('DecimalField').value;
	
	if (strNumFields != "" && Action !=5)
	{
		var arrNumFields = strNumFields.split(",");
		for (var i=0; i < arrNumFields.length; i++)
		{
			var FieldNumItem = arrNumFields[i].split("*");
			if (IsNumeric(eval("document.FrmInput."+FieldNumItem[0]+".value") )== false)
			{
			message2 = message2 +'   * ' + FieldNumItem[1]+ '\n'
			bError2 = true;
			}

		}
	}
	
	if (strDecimalFields != "" && Action !=5)
	{
		var arrDecFields = strDecimalFields.split(",");
		for (var i=0; i < arrDecFields.length; i++)
		{
			var FieldDecItem = arrDecFields[i].split("*");
			if (IsNumeric(eval("document.FrmInput." + FieldDecItem[0] + ".value") )== false)
			{
				message2 = message2 +'   * ' + FieldDecItem[1]+ '\n'
				bError2 = true;
			}
			else
			{
				var FieldValue = eval("document.FrmInput." + FieldDecItem[0] + ".value");
				FieldValue = FieldValue.replace("-","");
				FieldValue = FieldValue.replace("+","");
				var FieldCheckDec = FieldValue.split(".");
				
				if (FieldCheckDec.length > 2)
				{
					message2 = message2 +'   * ' + FieldDecItem[1]+ '\n'
					bError2 = true;
				}
				else if (FieldCheckDec[1].length > 8)
				{
					message3 = message3 +'   * ' + FieldDecItem[1]+ '\n'
					bError3 = true;
				}
				else if (FieldCheckDec[0].length > 10)
				{
					message4 = message4 +'   * ' + FieldDecItem[1]+ '\n'
					bError4 = true;
				}
			}
		}
	}
	
	

	if (bError==false && bError2==false && bError3==false && bError4==false) 
	{
		if (Action == 2)
		{
			GotoURL(__form, "http://www.entelliumblue.net/esam/eCCAdmin/Tier2/FormLayout.asp?Action=1");
		}
		else
		{
			GotoURL(__form, "?Action=" + Action);
		}
	}
	else
	{
		if (bError==true )
		{
			alert(message);
		}
		else if (bError2==true)
		{
			alert(message2);
		}
		else if (bError3==true)
		{
			alert(message3);
		}
		else if (bError4==true)
		{
			alert(message4);
		}
	}
}

function SetTime()
{
	var d = new Date();
	var year = d.getFullYear();
	var day = d.getDate();
	var month = d.getMonth();
	var hours = d.getHours();
	var minutes = d.getMinutes();
	var seconds = d.getSeconds();
	var shortMonths = new shortMonthArray();

	if (hours==0)
	{
		hours = 24;
	}
}

function shortMonthArray() 
{
	this[0] = "Jan";	this[1] = "Feb";	this[2] = "Mar";
	this[3] = "Apr";	this[4] = "May";	this[5] = "Jun";
	this[6] = "Jul";	this[7] = "Aug";	this[8] = "Sep";
	this[9] = "Oct";	this[10] = "Nov";	this[11] = "Dec";
	return (this);
}