var vArgs;

//var isNN = (navigator.appName.indexOf("Netscape")!=-1);
var isNN =false;

//var iTmOut = setTimeout("TimeOutLogin()",1000);
// function will be use to show login screen once time out for session.
function TimeOutLogin()
{
	if( window.location.href.indexOf("default.asp") <= 0)
	{
		window.location.href = "default.asp";	
	}
}




//function use for lost focus for link tables (PAtient , Employee it will return name to specified control
// PASS +  as  | for QueryString
function CheckEdit(sCodeName,sDescName,sTitle,sWhere)
{
		var sParaField,RetW,sCodeValue;
		
		sCodeValue = document.all(sCodeName).value; 
		//alert(sCodeValue);
		
		if (sTitle == "EMP") 
			sParaField = "TableName=EMP&FieldName=EMPCODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=EMPNAME&ReturnFieldNm=" + sDescName ;
		
		if (sTitle == "ACC") 
			sParaField = "TableName=POS&FieldName=POS&FieldValue=" + sCodeValue + "&FieldType=1&Where=PAT='A'" + sWhere + "&ReturnField=POSDESC&ReturnFieldNm=" + sDescName ;
		
		if (sTitle == "POS") 
			sParaField = "TableName=POS&FieldName=POS&FieldValue=" + sCodeValue + "&FieldType=1&Where=PAT='P'" + sWhere + "&ReturnField=POSDESC&ReturnFieldNm=" + sDescName ;
		
		if (sTitle == "TOS") 
			sParaField = "TableName=POS&FieldName=POS&FieldValue=" + sCodeValue + "&FieldType=1&Where=PAT='T'" + sWhere + "&ReturnField=POSDESC&ReturnFieldNm=" + sDescName ;
	
		if (sTitle == "PHY") 
			sParaField = "TableName=PHY&FieldName=PHY&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=PHYNAME&ReturnFieldNm=" + sDescName ;

		if (sTitle == "PATIENT") 
			sParaField = "TableName=PATIENT&FieldName=PATNO&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=isnull(PAT_LAST,'') | ', ' | isnull(PAT_FIRST,'') | ' ' | isnull(MI_PAT,'')&ReturnFieldNm=" + sDescName ;
			
		if (sTitle == "ISNURE") 
			sParaField = "TableName=INSURE&FieldName=INSCODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=NAME_INSU&ReturnFieldNm=" + sDescName ;

		if (sTitle == "REF") 
			sParaField = "TableName=REFERRAL&FieldName=REFE_NO&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=ISNULL(REFE_LAST,'') | ' ' | ISNULL(REFE_MI,'') | ' ' | ISNULL(REFE_FIRST,'')&ReturnFieldNm=" + sDescName ;			

		if (sTitle == "FAC") 
			sParaField = "TableName=FAC&FieldName=FACODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=FACILITY&ReturnFieldNm=" + sDescName ;			

		if (sTitle == "GAUR") 
			sParaField = "TableName=GAUR&FieldName=GAURCODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=isnull(GNAME,'') |' '| isnull(GMI,'') |' '| isnull(GFNAME,'')&ReturnFieldNm=" + sDescName ;			

		if (sTitle == "DCODE") 
			sParaField = "TableName=DCODE&FieldName=DICODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=DES_DCO&ReturnFieldNm=" + sDescName ;																		
		
		if (sTitle == "PCODE") 
			sParaField = "TableName=PCODE&FieldName=PROCODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=DESC_PRO&ReturnFieldNm=" + sDescName ;
																					
		if (sTitle == "PRA") 
			sParaField = "TableName=PRA&FieldName=PRA&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=PRONAME&ReturnFieldNm=" + sDescName ;

		if (sTitle == "USER") 
			sParaField = "TableName=USER&FieldName=USERID&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=NAME&ReturnFieldNm=" + sDescName ;

		if (sTitle == "SignInNote") 
			sParaField = "TableName=SignInNote&FieldName=MSG_CODE&FieldValue=" + sCodeValue + "&FieldType=1&Where=" + sWhere + "&ReturnField=MSG_HEAD&ReturnFieldNm=" + sDescName ;
	    		
        if (sTitle == "PHR") 
			sParaField = "TableName=Pharmay&FieldName=PHRCODE&FieldValue=" + sCodeValue + "&FieldType=conStringField&Where=" + sWhere + "&ReturnField=PHRNAME&ReturnFieldNm=" + sDescName ;
        //alert(sDescName);
		//alert(sParaField);	
		if (sParaField != "") 
		{
			//RetW = window.open("FindFieldValue.asp?" + sParaField ,"_blank","height=1,width=1,top=15000,left=15000,resizable,scrollbars");
			RetW = window.showModalDialog("FindFieldValue.asp?" + sParaField ,window,"dialogTop: 10000px;dialogHeight: 10000px; dialogWidth: 10000px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		
		}
		
		if (document.all(sDescName).value == "") document.all(sCodeName).value = "";
		
		//alert(document.all(sCodeName).value);
		
		if (document.all(sCodeName).style.visibility != "hidden" && document.all(sCodeName).type != "hidden")
				document.all(sCodeName).focus(); 
	
}

function DisplayHelp(sTitle,sCodeField,sDescField,sType)
{
        
		var vAspFile,vCode;
		var retVal , vPara;

		vArgs = new Object();
		vArgs.iFields= 2;
		vArgs.RetVal= Array("","");
		
		if (sTitle == "LICENSE")
		{
			vAspFile ="frmLicense.asp";
			vCode = "OWN_ID";
			vArgs.RetVal= Array("OWN_ID");
			vArgs.sFields =Array("OWN_ID","OWN_LNAME" ,"OWN_FNAME","OWN_MI","OWN_CO");
		}
		
		if (sTitle == "PATIENT")
		{	
		    vAspFile ="frmDailyOperation.asp";
			vCode = "PATNO";
			//vArgs.RetVal= Array("PATNO");
			vArgs.sFields = Array("PATNO","MR_NO","PAT_LAST","PAT_FIRST" , "HPHONE_PAT","DOB_PAT","CITY_PAT","SSN_PAT");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "POS" || sTitle == "TOS" || sTitle == "ACC")
		{	
			//vAspFile ="frmProcedure.asp";
			vAspFile ="";
			vCode = "POS";
			vArgs.sFields =Array("POS","POSDESC");
		}
		
		if (sTitle == "PHARMACY")
		{	
			//vAspFile ="frmProcedure.asp";
			vAspFile ="";
			vCode = "PHRCODE";
			vArgs.sFields =Array("PHRCODE","PHRNAME","ADDRPHR","CT_PHR","ST_PHR","ZP_PHR","PH_PHR","FAX_PHR","CNT_PER");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "TODOACTION")
		{
			vAspFile ="frmToDoActionType.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Description");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		
		if (sTitle == "PLISTTYPE")
		{
			vAspFile ="frmPListType.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Description");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		
		if (sTitle == "ITSUSER")
		{	
			vAspFile ="frmITSUser.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","submitterID","PracticeID","ITSUserID","TSOUserID");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "GAURANTOR")
		{	
			vAspFile ="frmGuarantor.asp";
			vCode = "GAURCODE";
			//vArgs.sFields =Array("GAURCODE","GNAME","GFNAME","GMI","GARCT");
			vArgs.sFields =Array("GAURCODE","GNAME","GFNAME","GMI","GARCT","GDOB")
			vArgs.iFields= 1;
		}

		if (sTitle == "GAURANTOR1")
		{	
			vAspFile ="frmGuarantor.asp";
			vCode = "GAURCODE";
			vArgs.sFields =Array("GAURCODE", "GAURNAME","GAURCITY");
		}

		
		if (sTitle == "FACILITY")
		{	
			vAspFile ="frmFacility.asp";
			vCode = "FACODE";
			vArgs.sFields =Array("FACODE","FACILITY");
		}
		
		if (sTitle == "REFERRAL")
		{	
			vAspFile ="frmReferral.asp";
			vCode = "REFE_NO";
			vArgs.sFields =Array("REFE_NO","REFE_FIRST" , "REFE_LAST" , "REFE_MI" ,"REFE_CITY", "REFE_TELE");
			vArgs.iFields= 1;
			//vArgs.sDBFields =Array("REFE_NO","REFE_NAME")
		}
		
		if (sTitle == "INSURANCE")
		{	
			vAspFile ="frmInsurance.asp";
			vCode = "INSCODE";
			vArgs.sFields = Array("INSCODE", "NAME_INSU","CITY_INSU","STATE_INSU","ZIP_INSU","PHN1_INSU")
			vArgs.iFields= 1;
		}
		
		if (sTitle == "EMPLOYER")
		{	
			vAspFile ="frmEmployer.asp";
			vCode = "EMPCODE";
			vArgs.sFields =Array("EMPCODE", "EMPNAME","ADDREMP" , "CT_EMP" , "ST_EMP" ,  "PH_EMP");
		}
		
		if (sTitle == "PROCEDURES" || sTitle == "PCODE" || sTitle == "PCODES" || sTitle == "PCODEP")
		{
			vAspFile ="frmProcedure.asp";
			vCode = "PROCODE"
			vArgs.sFields =Array("PROCODE", "DESC_PRO");
		}	
		
		if (sTitle == "PRACTICE")
		{
			vAspFile ="frmPractice.asp"
			vCode = "PRA";
			vArgs.sFields =Array("PRA", "PRONAME");
		}	

	        if (sTitle == "PHYSICIAN")
		{
			vAspFile ="frmPhysician.asp"
			vCode = "PHY";
			vArgs.sFields =Array("PHY", "PHYNAME");
		}	
	
		if (sTitle == "DCODE")
		{
			vAspFile ="frmDiagnosis.asp"
			vCode = "DICODE";
			vArgs.sFields =Array("DICODE", "DES_DCO");
		}
		
		if (sTitle == "USER")
		{
			vAspFile ="frmUser.asp"
			vCode = "USERID";
			vArgs.sFields =Array("USERID", "NAME");
		}
		
		if (sTitle == "FAX_STATUS")
		{	
			//vAspFile ="frmProcedure.asp";
			vAspFile ="";
			vCode = "IDNO";
			vArgs.sFields =Array("IDNO", "FAX DATE","USER");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "CASE")
		{
			vAspFile ="frmCaseType.asp"
			vCode = "CASETYPE_CODE";
			vArgs.sFields =Array("CASETYPE_ID", "CASETYPE_NAME");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "MSG_BORD")
		{
			vAspFile ="MessageBord.asp";
			vCode = "MSG_CODE";
			vArgs.sFields =Array("CODE", "TITLE");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "AroraChart")
		{
			vAspFile ="frmAroraChart.asp";
			vCode = "CIDNO";
			vArgs.sFields =Array("CIDNO", "PATNO","PAT_NAME","ACDATE");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "USERGROUPS")
		{
			vAspFile ="frmUserGroups.asp";
			vCode = "GroupId";
			vArgs.sFields =Array("GroupId", "GroupName");
			vArgs.iFields= 1;
		}
		
		
		if (sTitle == "SignInNote")
		{
			vAspFile ="SignInNotes.asp";
			vCode = "MSG_CODE";
			vArgs.sFields =Array("MSG_CODE", "MSG_HEAD", "MSG_FOOT")
			vArgs.iFields= 1;
		}		


		if (sTitle == "RADIOLOGY")
		{
			vAspFile ="frmRadiology.asp"
			vCode = "RADIOLOGY";
			vArgs.sFields =Array("RD_NO", "RD_PATNO");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "SURG_IND")
		{
			vAspFile ="frmSurgIndications.asp"
			vCode = "ID_NO";
			vArgs.sFields =Array("ID_NO", "SURG_TYP","SURG_DESC");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "PROJ")
		{
			vAspFile ="frmProjectTypes.asp"
			vCode = "PROJID";
			vArgs.sFields =Array("PROJID","PROJNAME");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "FETAL")
		{
			vAspFile ="frmcAPP.asp";
			vCode = "POST_ID";
			vArgs.sFields =Array("POST_ID","edd","ssn","mothername");
			vArgs.iFields= 1;
		}
		
		if (sTitle == "REA")
		{
			vAspFile ="frmReasonMod.asp";
			vCode = "REASONID";
			vArgs.sFields =Array("REASONID","REASON");
			
		}
		if (sTitle == "DOSAGE")
		{
			vAspFile ="frmDosage.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Item","Dosage");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}

        if (sTitle == "Instruction")
		{
			vAspFile ="frmInstruction.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Item");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		
		if (sTitle == "Quantity")
		{
			vAspFile ="frmQuantity.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Item");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		
		if (sTitle == "VaccineSite")
		{
			vAspFile ="frmVaccineSite.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Name");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		
		if (sTitle == "Vaccine")
		{
			vAspFile ="frmVaccineMaster.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Name");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		
		if (sTitle == "VaccineManu")
		{
			vAspFile ="frmVaccineManufacturer.asp";
			vCode = "ID";
			vArgs.RetVal= Array("ID");
			vArgs.sFields =Array("ID","Name");
			vArgs.iFields= 1;
			//alert(sCodeField);
		}
		vPara ="Title=" + sTitle + "&AspFile=" + vAspFile + "&sCode="+ vCode +"&Mode=D";
		vPara += "&defval=" + document.all(sCodeField).value; 
		
		//retVal = window.showModalDialog("callSearch.asp?" + vPara ,window,"dialogHeight: 768px; dialogWidth: 1024px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		retVal = window.showModalDialog("frmSearch.asp?" + vPara ,window,"dialogHeight: 740px; dialogWidth: 1024px; edge: Raised; center: Yes; help: No; resizable: Yes; status: Yes;");
		
		if (retVal != "Back")
		{
			if (sCodeField != "")	
			document.all(sCodeField).value = vArgs.RetVal[0]; 
			document.all(sCodeField).onchange();
			//if (sDescField != "")	document.all(sDescField).value = vArgs.RetVal[1];
		
			if (sType == "P")
			{
				//window.location.href ="frmDailyOperation.asp?PATNO=" + document.all(sCodeField).value + "&Mode=D";
				//window.location.reload(true);
				document.forms(0).submit(); 
			}
		}
		
		//if (sTitle == "PATIENT")
		//{
		//	document.all['PATNO'].value = vArgs.RetVal[0];
		//	window.location.href ="frmDailyOperation.asp?PATNO=" + vArgs.RetVal[0] + "&Mode=D"
		//}
}

function DisplayHelp1(sTitle,sCodeField,sDescField,sType)
{
        
		var vAspFile,vCode;
		var retVal , vPara;

		vArgs = new Object();
		vArgs.iFields= 2;
		vArgs.RetVal= Array("","");
		
		
		if (sTitle == "PATIENT")
		{	
		    vAspFile ="frmDailyOperation.asp";
			vCode = "PATIENT_ID";
			vArgs.RetVal= Array("PATIENT_ID");
			vArgs.sFields = Array("PATIENT_ID","L_NAME","F_NAME","M_NAME");
			vArgs.iFields= 1;
		}
		
		
		vPara ="Title=" + sTitle + "&AspFile=" + vAspFile + "&sCode="+ vCode +"&Mode=D";
		vPara += "&defval=" + document.all(sCodeField).value; 
		
		//retVal = window.showModalDialog("callSearch.asp?" + vPara ,window,"dialogHeight: 768px; dialogWidth: 1024px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		retVal = window.showModalDialog("frmPatientSearch.asp?" + vPara ,window,"dialogHeight: 740px; dialogWidth: 1024px; edge: Raised; center: Yes; help: No; resizable: Yes; status: Yes;");
		
		if (retVal != "Back")
		{
			if (sCodeField != "")	
			document.all(sCodeField).value = vArgs.RetVal[0]; 
			document.all(sCodeField).onchange();
			//if (sDescField != "")	document.all(sDescField).value = vArgs.RetVal[1];
		
			if (sType == "P")
			{
				//window.location.href ="frmDailyOperation.asp?PATNO=" + document.all(sCodeField).value + "&Mode=D";
				//window.location.reload(true);
				document.forms(0).submit(); 
			}
		}
		
		//if (sTitle == "PATIENT")
		//{
		//	document.all['PATNO'].value = vArgs.RetVal[0];
		//	window.location.href ="frmDailyOperation.asp?PATNO=" + vArgs.RetVal[0] + "&Mode=D"
		//}
}


function CodeChange(sCtl)
{
	sCtl.value = sCtl.value;
	window.location.reload(true);
}


function GoToUrl(sUrl)
{
	window.location.href =sUrl;
}

function OpenFormInNewMode(sFile)
{	
		var retVal;	
 		
		retVal = window.showModalDialog(sFile ,window,"dialogHeight: 768px; dialogWidth: 1024px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		
		window.location.reload(true);
		
}



function SetFormReturnValue(sVal)
{
   parent.dialogArguments.vArgs.RetVal[0] =sVal; 
   parent.close();
}


function EnableDisableForm(frm , bFlag)
{
   	var i;
	
	//alert(frm);
	//alert(bFlag);
	 
	 i = frm.all.length;
          for (i =0 ; i < frm.all.length; i++)
	  {

		      	//alert(frm.all(i).type + '  - ' + frm.all(i).name);

			if (frm.all(i).type == "radio")
				frm.all(i).disabled =bFlag;
			
			if (frm.all(i).type == "textarea")
				frm.all(i).disabled =bFlag;
				
			if (frm.all(i).type == "file")
				frm.all(i).disabled =bFlag;
				
			if (frm.all(i).type == "text")
				frm.all(i).disabled =bFlag;		
		
			if (frm.all(i).type == "button")
				frm.all(i).disabled =bFlag;
				
			if (frm.all(i).type == "password")
				frm.all(i).disabled =bFlag;				
				
			if (frm.all(i).type == "radio")
				frm.all(i).disabled =bFlag;	
			
			if (frm.all(i).type == "select-one")
				frm.all(i).disabled =bFlag;
			
			if (frm.all(i).type == "reset")
				frm.all(i).disabled =bFlag;
				
			if (frm.all(i).type == "checkbox")
				frm.all(i).disabled =bFlag;				
	  } 
	
}



function SetNextTab(input, e) 
{
	len = input.maxLength;
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if(input.value.length >= len && !containsElement(filter,keyCode)) 
	{
			input.value = input.value.slice(0, len);
			temp=input.form[(getIndex(input)+1) % input.form.length];
			if(temp.visiblity=='visible') temp.focus();
			if (temp.type=="text" || temp.type=="textarea")
					temp.select();
	}

	function containsElement(arr, ele) 
	{
		var found = false, index = 0;
		while(!found && index < arr.length)
		if(arr[index] == ele)
				found = true;
		else
				index++;
		
		return found;
	}

	function getIndex(input) 
	{
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1)
		if (input.form[i] == input)
			index = i;
		else 
			i++;

		return index;
	}

	return true;
}

function GetZipCodeDetails(fldZip1,fldZip2,fldCity,fldSt)
{
	var sParaField;
	sParaField = "TYPE=ZIP&ZIP=" + document.getElementById(fldZip1).value + "&City=" + document.getElementById(fldCity).value + "&State=" + document.getElementById(fldSt).value; //+ document.getElementById(fldZip2).value ;
	if (sParaField != "") 
	{
		var RetV = window.showModalDialog("GetRecords.asp?" + sParaField ,window,"dialogTop: 10000px;dialogHeight: 1px; dialogWidth: 1px; edge: Raised; center: Yes; help: No; resizable: Yes; status: No;");
		document.getElementById(fldCity).value 	= RetV[0];
		document.getElementById(fldSt).value 	= RetV[1];	
	}
}

function IsValidNumber(dbVal)
{
	var sChars = "1234567890.-";
	var sStr = new String(dbVal);
						
	for(var i=0;i<sStr.length;i++)
	{
		if (sChars.indexOf(sStr.charAt(i)) < 0)
			return false;
	}
						
	return true;
}


function IsValidString(sText)
{
	if (sText.indexOf(",",1) >= 0 ||  sText.indexOf("\'",1) >= 0  ||  sText.indexOf("\"",1) >= 0 ||  sText.indexOf("*",1) >= 0 ||  sText.indexOf("%",1) >= 0)
	{
		return false;
	}
	return true;
}

function IsValidDate(sDate)
{
	var arrDt = sDate.split("/");
	if(arrDt.length == 3) {
		
		if (!IsValidNumber(arrDt[0]))
			return false;
		if(arrDt[0] < 1 || arrDt[0] > 12)
			return false; 
		
		if (!IsValidNumber(arrDt[1]))
			return false;
		if(arrDt[1] < 1 || arrDt[1] > 31)
			return false; 
		
		if (!IsValidNumber(parseInt(arrDt[2])))
			return false;
			
	}else 
		return false;
	
	return true;
}
function SetFocus(ctl){
	try{	
		if (ctl.type != "hidden") {
			if (ctl.visibility != null){
			  if (ctl.visibility == "visible")
					ctl.focus();
			}else
				ctl.focus();
		}
	}catch(e){
		return false;
	}
	
}
	
function ValidateControls()
{
	   for(var iFrm=0;iFrm<document.forms.length;iFrm++) {
			var frmObj = document.forms(iFrm);
			//alert(frmObj.length);
			for(var iCtl=0;iCtl<frmObj.length;iCtl++){
				if (frmObj.item(iCtl) != null){
					var ctl = frmObj.item(iCtl);
					//alert(frmObj.item(iCtl).tagname);
					//alert(iCtl);
					if (ctl.tagName.toUpperCase() == "SELECT"){
						// mandatory field		
						if (ctl.mandatory != null) {
							if(ctl.mandatory.toString() != "undefined"){
								if (ctl.selectedIndex < 0){
										alert("Please enter valid value !!");
										SetFocus(ctl);														
										return false;
								}
							}
						}
					}
					if(ctl.tagName.toUpperCase() == "INPUT" || ctl.tagName.toUpperCase() == "TEXTAREA"){
					// mandatory field		
						if (ctl.mandatory != null) {
							if(ctl.mandatory.toString() != "undefined"){
								if (ctl.value == ""){
										alert("Please enter valid value !!");
										SetFocus(ctl);														
										return false;
								}
							}
						}
					//Length Validation
						if (ctl.maxlength != null) {
							if(ctl.maxlength.toString() != "undefined"){
								if (ctl.value.length >= ctl.maxlength) {
									alert("Value can't be grater then " + ctl.maxlength + " characters !!!");
									SetFocus(ctl);														
									return false;
								}
							}
						}
					//Validation	
						if (ctl.validate != null) {
							if(ctl.validate.toString() != "undefined"){
								if(ctl.validate.toUpperCase() == "TEXT"){
										if(!IsValidString(ctl.value)){
											alert("Please don't enter characters \' \" , * %  !!!");
											SetFocus(ctl);
											return false;
										}
								}
								if(ctl.validate.toUpperCase() == "NUM")
								        {
								        //alert(ctl.value)
								        if (ctl.value != "")
								        {
								        //alert(ctl.value)
										if(!IsValidNumber(ctl.value))
										{
											alert("Please enter valid numeric value !!!");
											SetFocus(ctl);
											return false;	
										}
										}
										//else
										//{
										//return true;
										//}
								}
								if(ctl.validate.toUpperCase() == "DATE"){
									 if (ctl.value != ""){
										if(!IsValidDate(ctl.value)){
											alert("Please enter valid Date in format mm/dd/yyyy !!!");
											SetFocus(ctl);
											return false;	
										}
									 }
								}
							}
						}
					}
				}
			}
		} 
					   
		return true;
}

function formatAmt(dblVal,ideci){
	if (!isNaN(parseFloat(dblVal))){
		var str =dblVal.toString();
		var strArr =str.split(".");  
		if( strArr.length > 1){
			if (strArr[1].length > ideci){
				return  strArr[0] +"."+ strArr[1].substr(0,ideci); 
			}else{
			        return  strArr[0] +"."+ strArr[1]; 
			}
		}else{
			return strArr[0] +".00"; 
		}
	}else{
		return  "0.00"; 
	}
}
