/***
 * This page contains all the common javascript used to validate the data
 * it is used for common validation
 * @author     		MediTab Software Inc. 
 * @copyright  		1997-2005 The MediTab Software Inc.
**/
	
	/***
	 * Variable declaration for alert nessage, alert fields, field style and fields focus
	**/
	var strAlertMessage			=	"";	
	var strAlertfield;
	var strStyle				=	"";
	var strFocus				=	"";
	var strReOneOrMoreDigits 	= 	/[\d+]/;
	var strReNoDigits 			= 	/[^\d]/gi;
	var selcount				=	0;
	var itercount				=	0;
	var modalWin;
	var strCallHttpResponseOFunction = Array();
	
	/***
	 * This function is the main function which is used to validate data of hte form
	 * @param  		FORMID 				String		id of form
	 * @return 		true/false			Boolean 	having value true or falsetrue or false
	**/
	
	/***
	 * cases....
	 * Ap : Alphabetic
	 * Dt : Date
	 * In : Integer
	 * Dc : Decimal
	 * Zp : Zip
	 * Em : Email
	 * Ph : Phone
	 * Fx : Fax
	 * Ta : Normal Required Field
	 * Ur : URL
	 * Ft : float
	 * R  : Required Field
	
	 * Required Field should come after data type... e.g. ApRtxt_name
	**/
	function checkValid(FORMID)
	{
		var frmname		=	document.getElementById(FORMID);
		var blnflag		=	true;
		strAlertMessage	=	"";	// reset the alert nessage
		alertfield		=	"";
		strStyle		=	"";
		strFocus		=	"";
		selcount		=	0;
		itercount		=	0;
		
		//Get no of elements of form...
		var frmcnt		=	document.getElementById(FORMID).elements.length;
	
		for(var i=0;i<frmcnt;i++)
		{
			try
			{
				MESSAGE	=	eval("LBL_"+frmname.elements[i].name);
			}
			catch(e)
			{
				MESSAGE	=	"Field";
			}
			// handling of various textbox validations
			if(frmname.elements[i].type=='text' && !frmname.elements[i].name.match(/\[]/))		
			{	
				// first 2 characters of the textbox name are to identify type of validation...
				var ChkType	=	frmname.elements[i].name.substr(0,2);
				//third character is to identify required field...
				var RChr	=	frmname.elements[i].name.substr(2,1);
				
				//alert(frmname.elements[i].name+' '+ChkType+'    '+RChr+'  ');			
				
				var REQUIRED="";
				if(RChr=="R")
				{
					REQUIRED	=	true;
				}					
				else
				{
					REQUIRED	=	false;	
				}
				//Generate name of the field...
				
				FIELD_NAME	=	eval("document."+FORMID+"."+frmname.elements[i].name);			
				switch(ChkType)
				{
					case "Ap" :
					
						if(!checkAlpha(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Dt" :
						if(!checkDate(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "In" :
						if(!checkInteger(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Ft" :
						var arrName=frmname.elements[i].name.split("txt");
						var strRequired=arrName[0].substr(arrName[0].length - 1 ,1);
						if(strRequired == 'R')
						{
							REQUIRED=true;
							var strLength = (arrName[0].length - 1);
						}					
						else
						{
							REQUIRED=false;
							var strLength = (arrName[0].length);
						}
						var ChkCharID = arrName[0].substr(2 ,strLength - 2); 
						if(!checkFloat(FIELD_NAME,MESSAGE,ChkCharID,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Dc" :
						if(!checkDecimal(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Zp" :
						if(!checkZip(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Em" :
						if(!checkEmail(FIELD_NAME,MESSAGE,REQUIRED))
						{	//alert("z");
							blnflag = false;
						}
					break;
					case "Ph" :
						if(!checkPhone(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Fx" :
						if(!checkFax(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
					break;
					case "Ta" :
						if(REQUIRED == true)
						{
							if(checkBlank(FIELD_NAME,MESSAGE))
							{
								blnflag = false;
							}
						}
					break;
					case "Ur" :
						if(!checkURL(FIELD_NAME,MESSAGE,REQUIRED))
						{
								blnflag = false;
						}
					break;
						
				}			
			}
			else if(frmname.elements[i].type=='textarea')
			{			
				var ChkType	=	frmname.elements[i].name.substr(0,2);
				//third character is to identify required field...
				var RChr	=	frmname.elements[i].name.substr(2,1);
				var REQUIRED=	"";
				if(RChr=="R")
				{
					REQUIRED	=	true;
				}					
				else
				{
					REQUIRED	=	false;	
				}
				//Generate name of the field...
				
				FIELD_NAME	=	eval("document."+FORMID+"."+frmname.elements[i].name);
				
				if(frmname.elements['hid_editor'] != undefined)
				{
					if(frmname.elements['hid_editor'].name == 'hid_editor')
					{
						var strValue 		= 	getTxtAreaValue(frmname.elements[i].name);
						FIELD_NAME.value 	= 	strValue;
					}
				}
				if(REQUIRED == true)
				{
					//alert(FIELD_NAME);
					if(checkBlank(FIELD_NAME,MESSAGE))
					{
						blnflag 	= 	false;
					}
				}	
			}
			else if(frmname.elements[i].type=='password')		// handling of various textbox validations
			{
				var RChr=frmname.elements[i].name.substr(2,1);
				var REQUIRED="";
				if(RChr=="R")
				{
					REQUIRED	=	true;
				}					
				else
				{
					REQUIRED	=	false;	
				}
				FIELD_NAME=eval("document."+FORMID+"."+frmname.elements[i].name);
				if(REQUIRED == true)
				{
					//alert(FIELD_NAME);
					if(checkBlank(FIELD_NAME,MESSAGE))
					{
						blnflag = 	false;
					}
				}		
			}
			else if(frmname.elements[i].type=='checkbox')		// handling of checkbox validations
			{
				// for checkbox first character to identify the required field
				var RChr	=	frmname.elements[i].name.substr(0,1);
				var REQUIRED=	"";
				if(RChr=="R")
				{
					REQUIRED	=	true;
				}					
				else
				{
					REQUIRED	=	false;	
				}
	
				if(REQUIRED == true)
				{
					//Generate name of the field...
					FIELD_NAME=eval("document."+FORMID+"."+frmname.elements[i].name);
					if(!checkMultiSelectBox(FIELD_NAME,MESSAGE,REQUIRED))
					{
						blnflag = false;
					}
				}
			}
			else if(frmname.elements[i].type=='radio')			// handling of radio button validations
			{
				// for checkbox first character to identify the required field
				var RChr=frmname.elements[i].name.substr(0,1);
				var REQUIRED	=	"";
				if(RChr=="R")
				{
					REQUIRED	=	true;
				}					
				else
				{
					REQUIRED	=	false;	
				}
				//Generate name of the field...
				FIELD_NAME=eval("document."+FORMID+"."+frmname.elements[i].name);
				if(REQUIRED==true)
				{
					if(!checkMultiSelectBox(FIELD_NAME,MESSAGE,REQUIRED))
					{
						blnflag = false;
					}
				}
			}
			else if(frmname.elements[i].type=='file' && !frmname.elements[i].name.match(/\[]/))
			{
				// for file input the first character to identify the required field
				var RChr	=	frmname.elements[i].name.substr(0,1);
				var REQUIRED=	"";
				if(RChr=="R")
				{
					REQUIRED=true;
				}					
				else
				{
					REQUIRED=false;	
				}
				//Generate name of the field...
				FIELD_NAME=eval("document."+FORMID+"."+frmname.elements[i].name);
				if(RChr=="R")
				{
					var strType=frmname.elements[i].name.substr(4,3);
				}
				else
				{
					var strType=frmname.elements[i].name.substr(3,3);	
				}
				strType=strType.toUpperCase()
				if(strType=="IMG")
				{
					var EXTENSIONS="jpg,jpeg,png,gif";	// valid file extensions				
				}
				else if(strType=="DOC")	
				{
					var EXTENSIONS="txt,doc,pdf,xls,csv";	// valid file extensions	
				}
				else if(strType=="VID")	
				{
					var EXTENSIONS="mp3,3gp,gif,avi,mpeg";	// valid file extensions
				}
				else
				{
					var EXTENSIONS="";	// valid file extensions
				}
				if(!checkFileName(FIELD_NAME,MESSAGE,REQUIRED,EXTENSIONS))
				{
							blnflag = false;
				}			
			}
			else if(frmname.elements[i].type=='select-one')			// handling of select box validations
			{
				// for file input the first character to identify the required field
				var RChr=frmname.elements[i].name.substr(0,1);
				var REQUIRED="";
				var multi=false;
				if(RChr=="R")
				{
					REQUIRED=true;
				}					
				else
				{
					REQUIRED=false;	
				}
				//Generate name of the field...
				var sfldname;
				if(frmname.elements[i].name.match(/\[]/))	// array of select fields
				{
					multi = true;
					sfldname=frmname.elements[i];	// get the select field element for select array
				}
				else
				{
					FIELD_NAME=eval("document."+FORMID+"."+frmname.elements[i].name);					
				}
	
	
				if(REQUIRED == true && multi == false)
				{
					// if select then check for  selected according to required or not				
					if(checkSelectBox(FIELD_NAME,MESSAGE,REQUIRED))
					{
							blnflag = false;
					}			
				}
				else
				{
					// for select array atleast on selected
					if(multi == true)
					{
						// if select array then check for atleast one selected
						if(checkMultiDropDownBox(sfldname,MESSAGE,REQUIRED)) 
						{					
								blnflag = false;
						}	
	
					}
					
				}
	
			}
			else
			{
	
			}
		}

	// alert the fields and set the error style for the required fields
	if(blnflag == false && strAlertMessage!="")
	{
		strAlertMessage="Following errors:\n\n" + strAlertMessage;	
		alert(strAlertMessage);	
		eval(strStyle);
		eval(strFocus);
		return false;
	}
	else
	{
		eval(strStyle);
		return true;
	}
	
}
	
	/***
	 * This function is used to check for the empty fields
	 * It Will display tne message if the mendatory filed is Null
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @return		true/false		Bollean
	**/
	function checkBlank(FIELD_NAME,MESSAGE)
	{
		// If value is null then alert message...
		// Call Trim function to trim the value
		if(Trim(FIELD_NAME.value) == '')
		{
			strAlertMessage+="\nPlease enter value for "+MESSAGE+".";
			if(FIELD_NAME.type!='textarea')
			{
				setStyle(FIELD_NAME);
			}
			return true;
		}
		else
		{	
			if(FIELD_NAME.type!='textarea')
			{
				resetStyle(FIELD_NAME);			
			}
			return false;	
		}
	}

	/***
	 * This function is used to check for the alphabatic values for the field
	 * It Will display tne message if the field value is not alphabetic
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkAlpha(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		
		// Regular expression for alphabetic validation...
		if(FIELD_NAME.value.search(/^[A-Za-z]*$/))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{	
			resetStyle(FIELD_NAME);			
			return true;	
		}
	}

	/***
	 * This function is used to check for the date validation for the field
	 * It Will display tne message if the field value is not proper date format
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkDate(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// Call isDate function to validate Date...
			if(!isDate(FIELD_NAME.value))
			{
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
		}
		resetStyle(FIELD_NAME);
		return true;
	}

	/***
	 * This function is used to compare date
	 * It  Will compare start date & end date. if start date>end date then it will give alert message
	 * @param  		START_DATE 		String		Sart Date
	 * @param  		END_DATE 		String		End Date
	 * @param 		MESSAGE_START	String 		Lable of start date
	 * @param 		MESSAGE_END		String 		lable of end date
	 * @return		true/false		Bollean
	**/
	function dateCompare(START_DATE,END_DATE,MESSAGE_START,MESSAGE_END)
	{
		// If both start date & end date are not null then...
		sadate	=	Array();
		eadate	=	Array();
		sadate	=	START_DATE.value.split("-");
		eadate	=	END_DATE.value.split("-");
	
		sdate	=	new Date(sadate[2],sadate[0]-1,sadate[1]);
		edate	=	new Date(eadate[2],eadate[0]-1,eadate[1]);
	
		// Compare both start date & end date. if start date is greater then end date then alert message...
		if(sdate>edate)	
		{
			alert(MESSAGE_END+" can not be less than "+MESSAGE_START+".");
			fldname=END_DATE;
			setStyle(END_DATE);
			eval(strStyle);
			END_DATE.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	/***
	 * This function is used to check for future date
	 * It Will compare date with cureeent date
	 * @param  		CURRENT_DATE	String		current date
	 * @param 		FIELD_DATE		String 		Date to be compared
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @return		true/false		Bollean
	**/
	function checkFutureDate(CURRENT_DATE,FIELD_DATE,MESSAGE)
	{
		// If both Current date & date to be compared are not null then...
		sadate	=	Array();
		cdate	=	Array();
		sadate	=	FIELD_DATE.value.split("-");
		cadate	=	CURRENT_DATE.value.split("-");
		sdate	=	new Date(sadate[2],sadate[0]-1,sadate[1]);
		cdate	=	new Date(cadate[2],cadate[0]-1,cadate[1]);
	
		// Compare both current date & field date. if field date date is greater then current date then alert message...
		if(sdate>cdate)	
		{
			alert(MESSAGE+' can not be future date.');
			fldname=FIELD_DATE;
			setStyle(FIELD_DATE);
			eval(strStyle);
			FIELD_DATE.focus();
			return false;
		}
		else
		{
			return true;
		}
	}

	/***
	 * This function is used to check for integer value of the field
	 * It Will check for numeric value
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkInteger(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		// Regular expression for numeric validation...
		if(FIELD_NAME.value.search(/^[0-9]*$/))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);			
			return true;
		}
	}

	/***
	 * This function is used to check for float value of the field
	 * It Will check for float value
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param 		CHARNO			Integer		floating point position
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkFloat(FIELD_NAME,MESSAGE,CHARNO,REQUIRED)
	{
		// Get the validation string...
		var stringsearch="/^[0-9]+(\.)?[0-9]{0,"+CHARNO+"}$/";
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		if(FIELD_NAME.value.search(eval(stringsearch)))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);			
			return true;
		}
	}

	/***
	 * This function is used to check for decimal value of the field
	 * It Will check for decimal value
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkDecimal(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		if(isNaN(FIELD_NAME.value))
		{
			strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);			
			return true;
		}
	}

	/***
	 * This function is used to check for valid zip value of the field
	 * It Will check for zip code. Zip code can be of 5 or 9 characters
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkZip(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		// Allow numbers only...
		// valid zip should contain 5 or 9 digits...
		if(FIELD_NAME.value!="")
		{
			// Regular expression for zip code validation...
			if(FIELD_NAME.value.search(/^\d\d\d\d\d(\d\d\d\d)?$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{	
				resetStyle(FIELD_NAME);			
				return true;	
			}
		}
		else
		{	
			resetStyle(FIELD_NAME);			
			return true;	
		}
	}
	
	/***
	 * This function is used to check for valid Phone number value of the field
	 * It Will check for phone number. Phone number can be greater then 10 characters
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkPhone(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field...
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// It will allow 0 to 9 and x or X on 11th position
			// Regular expression for phone number validation...
			if(FIELD_NAME.value.search(/^[0-9]{10}[0-9Xx]?[0-9]{0,3}$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{	
				resetStyle(FIELD_NAME);			
				return true;	
			}
		}
		else
		{	
			resetStyle(FIELD_NAME);			
			return true;	
		}
	}

	/***
	 * This function is used to check for valid fax number value of the field
	 * It Will check for fax number. Fax Number can be of 10 characters
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkFax(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// Regular expression for fax number validation...
			if(FIELD_NAME.value.search(/^[0-9]{10}$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else
			{	
				resetStyle(FIELD_NAME);			
				return true;	
			}
			
		}
		else
		{	
				resetStyle(FIELD_NAME);			
				return true;	
		}
	}

	/***
	 * This function is used to check for valid email value of the field
	 * It Will check For Valid Email.
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkEmail(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value!="")
		{
			// Regular expression for email validation...
			if(FIELD_NAME.value.search(/^[\w-\.]+@[\w-\.]+\.\w+$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
		}
		else
		{	
			resetStyle(FIELD_NAME);
			return true;	
		}
	}

	/***
	 * Date validation functions
	 * Main function name is: isDate
	**/

	/***
	 * DHTML date validation script. 
	**/
	// Declaring valid date character, minimum year and maximum year

	var dtCh= "-";
	var minYear=1900;
	var maxYear=2100;
	
	/***
	 * This function is used to check for the integer values
	 * It will check all the characters are numbers or not...
	 * @param		s 				String
	 * @return		true/false		Boolean		
	**/
	function isInteger(s)
	{
		var i;
		for (i = 0; i < s.length; i++)
		{   
			// Check that current character is number.
			var c = s.charAt(i);
			if (((c < "0") || (c > "9"))) return false;
		}
		// All characters are numbers.
		return true;
	}
	/***
	 * This function is used to strip characters
	 * @param		s 				String
	 * @param		bag				String
	 * @return		returnString	String	
	**/
	function stripCharsInBag(s, bag)
	{
		var i;
		var returnString = "";
		// Search through string's characters one by one.
		// If character is not in bag, append to returnString.
		for (i = 0; i < s.length; i++)
		{   
			var c = s.charAt(i);
			if (bag.indexOf(c) == -1) returnString += c;
		}
		return returnString;
	}

	/***
	 * This function is used to check number of days in february
	 * @param		year 			Integer
	 * @return		days			Integer	
	**/
	function daysInFebruary (year)
	{
		// February has 29 days in any year evenly divisible by four,
		// EXCEPT for centurial years which are not also divisible by 400.
		return (((year % 4 == 0) && ((!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
	}


	/***
	 * This function makes day Array...
	 * if month = 2(feb)  	then days = 29
	 * if mont = 4,6,9,11 	then days=30
	 * else 				days=31
	 * @param		n		integer		month
	 * @reurn		this	integer		number of days
	**/
	function DaysArray(n) 
	{
		for (var i = 1; i <= n; i++) 
		{
			this[i] = 31
			if (i==4 || i==6 || i==9 || i==11) 
			{
				this[i] = 30
			}
			if (i==2) 
			{
				this[i] = 29
			}
	   } 
	   return this
	}
	
	/***
	 * This function is used to check date format
	 * It will check whether date format is correct or not
	 * @param 		dtStr			String		Date to be checked
	 * @return 		true/false		Boolean		
	**/
	function isDate(dtStr)
	{
		var daysInMonth 	= 	DaysArray(12)
		var pos1			=	dtStr.indexOf(dtCh)
		var pos2			=	dtStr.indexOf(dtCh,pos1+1)
		var strMonth		=	dtStr.substring(0,pos1)
		var strDay			=	dtStr.substring(pos1+1,pos2)
		var strYear			=	dtStr.substring(pos2+1)
		strYr				=	strYear
		if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
		if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
		for (var i = 1; i <= 3; i++) 
		{
			if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
		}
		
		month	=	parseInt(strMonth)
		day		=	parseInt(strDay)
		year	=	parseInt(strYr)
		if (pos1==-1 || pos2==-1)
		{
			// If two "-" are not there in date then date is invalid...
			strAlertMessage+="\nInvalid date.The date format should be : mm-dd-yyyy";
			return false
		}
		if (strMonth.length<1 || month<1 || month>12)
		{
			// Checking for month format...
			strAlertMessage+="\nPlease enter a valid month";
			return false
		}
		if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
		{
			// Checking for day format...
			strAlertMessage+="\nPlease enter a valid day";
			return false
		}
		if (strYear.length != 4 || year==0 || year<minYear || year>maxYear)
		{
			// Checking for Year Format...
			strAlertMessage+="\nPlease enter a valid 4 digit year between "+minYear+" and "+maxYear;
			return false
		}
		if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
		{
			// Check whether it is integer or not...
			strAlertMessage+="\nPlease enter a valid date";
			return false
		}
		return true
	}

	/***
	 * This function is used to format date
	 * It Will convert date in specific format.
	 * @param 		DATE			String		Date to be formated
	 * @param		DATE_FORMAT		String		Date Format
	 * @return 		FDate			String		Formated date
	**/
	function formatDate(DATE,DATE_FORMAT)
	{
		FDate			=	DATE.split('-');	
		FirstFC			=	DATE_FORMAT.substr(0,1);
		SecondFC		=	DATE_FORMAT.substr(2,1);
		ThirdFC			=	DATE_FORMAT.substr(4,1);
		AddChr			=	DATE_FORMAT.substr(1,1);	
		var MONTH_NAMES	=	new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec');
		if(FirstFC=='Y' || FirstFC=='y')
		{
			// Check For First Place For Year...
			if(FirstFC=='Y')
			{
				FirstFC=FDate[0];	
			}
			else
			{
				FirstFC=FDate[0].substr(2,2);
			}
		}
		else if(FirstFC=='M' || FirstFC=='m')
		{
			// Check For First Place For Month...
			if(FirstFC=='M')	
			{
				FirstFC=MONTH_NAMES[FDate[1]-1];	
			}
			else
			{
				FirstFC=FDate[1];	
			}
		}
		else
		{
			FirstFC=FDate[2];
		}
		if(SecondFC=='Y' || SecondFC=='y')
		{
			// Check For Second Place For Year...
			if(SecondFC=='Y')
			{
				SecondFC=FDate[0];	
			}
			else
			{
				SecondFC=FDate[0].substr(2,2);
			}
		}
		else if(SecondFC=='M' || SecondFC=='m')
		{	
			// Check For Second Place For Month...
			if(SecondFC=='M')	
			{
				SecondFC=MONTH_NAMES[FDate[1]-1];	
			}
			else
			{
				SecondFC=FDate[1];	
			}
		}
		else
		{
			SecondFC=FDate[2];	
		}
		if(ThirdFC=='Y' || ThirdFC=='y')
		{
			// Check For Third Place For Year...
			if(ThirdFC=='Y')
			{
				ThirdFC=FDate[0];	
			}
			else
			{
				ThirdFC=FDate[0].substr(2,2);
			}
		}
		else if(ThirdFC=='M' || ThirdFC=='m')
		{
			// Check For Third Place For Month...
			if(ThirdFC=='M')	
			{
				ThirdFC=MONTH_NAMES[FDate[1]-1];	
			}
			else
			{
				ThirdFC=FDate[1];	
			}
		}
		else
		{
			ThirdFC=FDate[2];	
		}
		FDate=FirstFC+AddChr+SecondFC+AddChr+ThirdFC;
		return FDate;
	}

	/***
	 * This function is used to Select & Deselect All Checkboxes
	 * @param 		CHECKBOX_ARRAY	String		Field name
	 * @param		CHECKALL		String		Field name
	 * @return 		Void
	**/
	function checkAll(CHECKBOX_ARRAY,CHECKALL) 
	{
		var name=document.getElementsByName(CHECKBOX_ARRAY);
		var field = name.length;
		for (i = 0; i < field; i++) 
		{
			var str=eval(name[i]);
			str.checked=document.getElementById(CHECKALL).checked;
		}
	}

	/***
	 * This function is used to check for selected Check box.
	 * It will alert message if all the checkboxws are deselected
	 * @param 		FIELD_NAME		String		Name of the field
	 * @return 		true/false		Boolean
	**/
	function checkSelect(FIELD_NAME)
	{
		var field=document.getElementsByName(FIELD_NAME);
		var chkselect = false;
		for(var i=0;i<field.length;i++)
		{
			var str=eval(field[i]);
			if(str.checked)
			{
				chkselect=true;
				break;
			}
		}
		if(chkselect == false)
		{
			strAlertMessage+="\nPlease select atleast one checkbox.";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		else
		{
			resetStyle(FIELD_NAME);
			return true;
		}
	}

	/***
	 * This function is used for Convert string in Uppercase.
	 * @param 		objId			String		Name of the field
	 * @return 		objId			String		Value of field in uppercase
	**/
	function ftoupper(objId)
	{
		sId = objId.value
		objId.value = sId.toUpperCase() ;
	}

	/***
	 * This function is used for Convert string in Lowercase.
	 * @param 		objId			String		Name of the field
	 * @return 		objId			String		Value of field in lowercase
	**/
	function ftolower(objId)
	{
		sId = objId.value
		objId.value = sId.toLowerCase() ;
	}

	/***
	 * This function is used to trim the string
	 * It will remove spaces from the string
	 * @param 		str				String		Value of the field
	 * @return 		substr			String		string without space
	**/
	function Trim(str)
	{ 
	 	lenstr = str.length
	 	substr = str
	 	for (i=0;i<lenstr;i++)
	 	{
			c = str.charAt(i);	
			if(c == ' ' || c == '\n'  || c == '\r')
				substr = str.substring(i+1,str.length)
			else
				break   
		}
	 	lenstr = substr.length
	 	str = substr 
	 	for (i=lenstr-1;i=0;i--)
		{
			c = str.charAt(i);
			if (c == ' '||c == '\n'||c == '\r')
				substr = str.substring(0,i-1)		
			else
				break   
		}   
	 	return substr	
	}

	/***
	 * This function will check for the valid url
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkURL(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value != "")
		{
			// Regular expression for url validation
			if(FIELD_NAME.value.search(/^((www.)|(((http)(s)?\:\/\/)(www.)?))[\w\/\-\._\-\~?&=:]+\w+$/))
			{
				strAlertMessage+="\nPlease enter valid "+MESSAGE+".";
				return false;
			}
		}
		return true;
	
	}

	/***
	 * This function is used to check value for selectbox.
	 * It will alert message if all the value of select box is blank
	 * @param 		FIELD_NAME		String		Name of the field
	 * @return 		true/false		Boolean
	**/
	function checkSelectBox(FIELD_NAME,MESSAGE)
	{
		// If value is null then alert message...
		if(FIELD_NAME.value == '')
		{
			strAlertMessage+="\nPlease select atleast one value for "+MESSAGE+".";
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return true;
		}
		else
		{
			resetStyle(FIELD_NAME);
			return false;
		}
	}

	/***
	 * This function is used to compare two numbers
	 * @param 		NUMBER1		Integer		Name of First field
	 * @param		NUMBER2		Integer		Name if Second Field
	 * @param		MESSAGE1	String		First Message To BE displayed
	 * @param		MESSAGE2	String		Second Message To BE Displayed
	**/
	function numberCompare(NUMBER1,NUMBER2,MESSAGE1,MESSAGE2)
	{
		if(NUMBER1.value > NUMBER2.value)
		{
			strAlertMessage+="\n"+MESSAGE1+" is greater than "+MESSAGE2;
			fldname=FIELD_NAME;
			setStyle(FIELD_NAME);
			return false;
		}
		return true;
	}

	/***
	 * This function will Check For at least one Checked Check Box
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkMultiSelectBox(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Boolean flag for the check box...
		var blncflag	=	false;					
		var i			=	0;
		var fldname		=	"";
	
		if(FIELD_NAME.length!=undefined)	
		{
			// If multiple check boxes
			for(i=0;i<FIELD_NAME.length && blncflag==false;i++)
			{	
				fldname=FIELD_NAME[i];
				if(FIELD_NAME[i].checked)
				{	
					blncflag=true;	
				}
			}
		}
		else								
		{	// If single check box...	
			fldname=FIELD_NAME;
			if(FIELD_NAME.checked)
			{	
				blncflag=true;	
			}
		}
		if(blncflag==false)
		{	
			if(strAlertfield!=fldname.name || strAlertfield=="")
			{
				if(strAlertfield=="")
				{
					strAlertfield=fldname.name;
				}
				strAlertMessage+="\nPlease select the " + MESSAGE+" ";								
				setStyle(fldname);
			}
			if(strAlertfield!="" && strAlertfield!=fldname.name)
			{
				strAlertfield=fldname.name;
			}
			return false;
		}
		else
		{	
			resetStyle(fldname);		
			return true;	
		}
	}
	
	/***
	 * This function will Check For at least one selected Select Box
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @return		true/false		Bollean
	**/
	function checkMultiDropDownBox(FIELD_NAME,MESSAGE,REQUIRED)
	{
		// Boolean flag for the select box...
		var blncflag	=	false;					
		var i			=	0;
		var fldname		=	"";
		var maxcount	=	document.getElementsByName(FIELD_NAME.name).length;
		itercount		=	itercount+1;
		
		// If multiple options or not
		if(FIELD_NAME.length!=undefined)	
		{
			for(i=0;i<FIELD_NAME.length && blncflag==false;i++)
			{	
				fldname=FIELD_NAME[i];
				// If a non null option has been selected...
				if(fldname.selected && fldname.value!="")
				{
					selcount=selcount+1;
					blncflag=true;
				}
			}
		}
		else								
		{	
			fldname=FIELD_NAME;
			if(FIELD_NAME.selected)
			{	
				blncflag=true;	
			}
		}
	
		// If no select boxes of the select array have been set then set the alert message...
		if(blncflag==false && selcount==0 && itercount==maxcount)
		{
			if(alertfield!=fldname.name || alertfield=="")
			{
				if(alertfield=="")
				{
					fldname=FIELD_NAME;
					alertfield=fldname.name;
				}
				// If none of array of select boxes have been set...
				if(selcount==0 && itercount==maxcount)
				{
					selcount=selcount+1;
					alertMessage+="\nPlease select the " + MESSAGE+" ";								
				}
			}

			// If none of array of select boxes have been set...
			if(selcount==0 && itercount==maxcount)
			{
				return false;
			}
			else
			{
				return true;	
			}
		}
		else
		{				
			return true;	
		}
	}
	
	/***
	 * This function will Check For at Valid File Types and required files
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @param 		MESSAGE			String 		Message to be displayed
	 * @param		REQUIRED		Bollean		true/false
	 * @param		EXTENSIONS		String		file extensions
	 * @return		true/false		Bollean
	**/
	function checkFileName(FIELD_NAME,MESSAGE,REQUIRED,EXTENSIONS)
	{
		// Check For Mendatory field
		if(REQUIRED && checkBlank(FIELD_NAME,MESSAGE)) {return false;}
		if(FIELD_NAME.value != '' && EXTENSIONS!='')
		{
			// The array of valid file types...
			var arrfiletypes=new Array();	
			// Get the valid file types in the array...
			arrfiletypes=EXTENSIONS.split(',');
			// This boolean flag indicates a valid file type...
			var blnvalidflag=false;	
			// Separate filename and the extension...
			var arrfilename=new Array();		
			// Get the file extension in an array...
			arrfilename=FIELD_NAME.value.split('.');	
			// Check the file extension validity...
			if(arrfilename.length>1)
			{
				// Check the file extension validity...
				for(var c=0;c<arrfiletypes.length && blnvalidflag==false;c++) 
				{
					var strMainExt=arrfilename[arrfilename.length-1].toUpperCase();
					var strExt=arrfiletypes[c].toUpperCase();
					if(strMainExt==strExt)
					{
						// File type is valid so set the flag...
						blnvalidflag=true;					
						break;
					}
				}
			}
			else
			{
				// File type is not valid so set the flag...	
				blnvalidflag=false;					
			}
			if(blnvalidflag == false)					
			{
				// File is not a valid file type...
				strAlertMessage+="\nPlease select a valid "+MESSAGE+" of following types "+EXTENSIONS;
				fldname=FIELD_NAME;
				setStyle(FIELD_NAME);
				return false;
			}
			else										
			{	
				// File is valid...
				resetStyle(FIELD_NAME);				
				return true;	
			}
		}
	}

	/***
	 * This function will set style for the control
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @return		Void
	**/
	function setStyle(FIELD_NAME)
	{
		if(FIELD_NAME!=undefined)
		{
			if(navigator.appName=="Netscape")
			{
				if(strFocus=="")
				{
					if(document.getElementById(FIELD_NAME.id)!=undefined)
					{
						strFocus="document.getElementById('"+FIELD_NAME.id +"').focus();";
					}
					else if(document.getElementsByName(FIELD_NAME.name)!=undefined)
					{
						if(document.getElementsByName(FIELD_NAME.name).length>1)
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"')[0].focus();";
						}
						else
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"').focus();";	
						}
					}
				}
				// Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name +"').className='err';\n";			
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByName('"+FIELD_NAME.name + "').className='err';\n";					
				}
			}
			else
			{
				if(strFocus=="")
				{
					if(document.getElementById(FIELD_NAME.id)!=undefined)
					{
						strFocus="document.getElementById('"+FIELD_NAME.id +"').focus();";
					}
					else if(document.getElementsByName(FIELD_NAME.name)!=undefined)
					{
						if(document.getElementsByName(FIELD_NAME.name).length>1)
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"')[0].focus();";
						}
						else
						{
							strFocus="document.getElementsByName('"+FIELD_NAME.name +"').focus();";	
						}

					}
				}			
			    // Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name + "').className='err';\n";
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByName('"+FIELD_NAME.name + "').className='err';\n";	
				}
			}
		}
	}

	/***
	 * This function will reset style for the control
	 * @param  		FIELD_NAME 		String		Name of the field
	 * @return		Void
	**/
	function resetStyle(FIELD_NAME)
	{
		if(FIELD_NAME!=undefined)
		{
			if(navigator.appName=="Netscape")
			{
	
				// Cross browser script set the class attribute of the control 
				if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name +"').className='comn-input';\n";			
				}
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByTagName('"+FIELD_NAME.name + "').className='comn-input';\n";					
				}
			}
			else
			{
				// Cross browser script set the class attribute of the control 
				/*if(document.getElementById(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementById('"+FIELD_NAME.name + "').className='comn-input';\n";
				}*/
				if(document.getElementsByTagName(FIELD_NAME.name)!=undefined)
				{
					strStyle+="document.getElementsByTagName('"+FIELD_NAME.name + "').className='comn-input';\n";	
				}
			}
		}
	}

	/***
	 * This function will open the popup window
	 * @param  		url 		String		url of the popup page
	 * @param		width		Integer		width of the popup window
	 * @param		height		Integer		height of the popup window
	 * @return		false		Boolean
	**/
	function popup(url,width,height)
	{
		leftPosition=(screen.width)?(screen.width-width)/2:100;
		topPosition=(screen.height)?(screen.height-height)/2:100;
		testwindow=window.open(url+"&width="+width+"&height="+height, "preview", 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width='+width+',height='+height+',left='+leftPosition+',top = '+topPosition+'');
		return false;
	}
	
	/***
	 * This function will set Max Length on Set Focus.
	 * This function pass text box value and string format like data format("##-##-####")
	 * @param  		strTextBox 		String		Name of the field
	 * @param		strFormat		String		format
	 * @return		Void
	**/
	function onFocusMask(strTextBox,strFormat) 
	{
		var strVal = strTextBox.value;
		if(strVal.length == 0 || strVal == null) 
		{
			var i = strFormat.indexOf('#');
			strTextBox.value = strFormat.substring(0,i);
		}
		setCaretAtEnd(strTextBox);
		// set just in case.
		strTextBox.maxlength = strFormat.length;
	}
	
	/***
	 * This function will pass blank value when no digit founds.
	 * @param  		strTextBox 		String		Name of the field
	 * @return		Void
	**/
	function onBlurMask(strTextBox) 
	{
		var strVal = strTextBox.value;
		// if no digits....nada entered.....blank it.
		if(strReOneOrMoreDigits.test(strVal) == false) 
		{
			strTextBox.value = '';
		}
	}

	/***
	 * This function will pass all the value to Masking function get Mask Value
	 * @param  		strTextBox 		String		Name of the field
	 * @param		strEvt			String		"EVENT" for events property 
	 * @param		strFormat		String		Maks Format like ("##-##-####")
	 * @return		Void
	**/
	function doMask(strTextBox,strEvt,strFormat) 
	{
		var keyCode = strEvt.which ?strEvt.which : strEvt.keyCode;
		
		// Enter, backspace, delete and tab keys are allowed thru
		if(keyCode == 13 || keyCode == 8 || keyCode == 9 || keyCode == 46)
			return true;
		
		// KeyCodes so that it can be used
		var keyCharacter = cleanKeyCode(keyCode);
		
		// Grab the strTextBox value and the mask
		var strVal = strTextBox.value;
		var mask = strFormat;
		
		// Simple Regex to check if key is a digit
		if(strReOneOrMoreDigits.test(keyCharacter) == false)
			return false;
		
		// Get value minus any masking by removing all non-numerics
		strVal = strVal.replace(strReNoDigits,'');			
		
		// Mask it...val holds the existing TextBox.value + the current keystroke
		strTextBox.value = MaskValue(strVal,mask);
		setCaretAtEnd(strTextBox);
		return false;
	}

	/***
	 * This function will return Mask Formated value to DoMask Function.
	 * @param  		strValue 		String		Text box value
	 * @param		strMask			String		Maks Format 
	 * @return		retVal			String		Mask Formated value
	**/
	function MaskValue(strValue,strMask) 
	{
		var retVal = strMask;
		var strVal = strValue;
		
		// Loop thru mask and replace #'s with current value one at a time
		for(var i=0;i<strVal.length;i++) 
		{
			retVal = retVal.replace(/#/i, strVal.charAt(i));
		}
		retVal = retVal.replace(/#/gi, "");
		return retVal;
	}

	/***
	 * This function will Return Formated String Key Code
	 * @param  		intKey 		Integer		int Key Code Genrated By Event Property.
	 * @return		intKey		String		Formated String Key Code
	**/
	function cleanKeyCode(intKey)
	{
		switch(intKey)
		{
			case 96: return "0"; break;
			case 97: return "1"; break;
			case 98: return "2"; break;
			case 99: return "3"; break;
			case 100: return "4"; break;
			case 101: return "5"; break;
			case 102: return "6"; break;
			case 103: return "7"; break;
			case 104: return "8"; break;
			case 105: return "9"; break;
			default: return String.fromCharCode(intKey); break;
		}
	}

	/***
	 * This function will set value Charcter at the End.
	 * @param  		strField 		String		field value
	 * @return		Void
	**/
	function setCaretAtEnd (strField) 
	{
	  if (strField.createTextRange) 
	  {
		var strRange = strField.createTextRange();
		strRange.moveStart('character', strField.value.length);
		strRange.collapse();
		strRange.select();
	  }
	}
	/**
	* This method is used to create the XMLHttpRequest Object
	* XMLHttpRequest this is the core AJAX object. It handles all the requests and responses
	* @return the http object.
   **/
function createRequestObject()
{
	//declare the variable to hold the object.
	var objRequest; 
	//find the browser name
	var strBrowser = navigator.appName;
	
	//Check the type of browser and acc. create the object.
	if(strBrowser == "Microsoft Internet Explorer"){
		objRequest = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		objRequest = new XMLHttpRequest();
	}
	
	//return the object
	return objRequest;
}

	/**
	 * This method is used to call the page which will return the requested HTML control through ajax.
	 * @param	string		strFieldName	having the name of the field
	 * @param	string		strFieldId		having the table constant anf field Id.
	 * @param	string		strRequestvars	having the var name and the html field name whose value is to be passed in that var
	**/
	function getHTMLControl(strFieldName,strFieldId,strRequestVars)
	{	
		
		// Created an Instance of the XMLHttpRequest object
		var objHttp = createRequestObject();
	
		//Set the url of the file which will return the HTML control
		strUrl="index.php?file=./../../base/meditab/med_getHTMLControl";
		
		//Add the selected values in the query string
		strUrl+="&"+strFieldName+"="+document.getElementById("hid_sel"+strFieldName).value;
		
		//Add the field id in the query string
		strUrl+="&strFieldId="+strFieldId;
	
		//Add the request variables to the query string if required
		if(strRequestVars!='')
		{
			arrRequestVars	=	strRequestVars.split(",");
			for(intRequestVars=0; intRequestVars<arrRequestVars.length; intRequestVars++)
	
			{
				arrVars	=	arrRequestVars[intRequestVars].split("=");		
				strVarName	=	arrVars[0];
				strVarValue	=	document.getElementById(arrVars[1]).value;
				
				strUrl+="&"+strVarName+"="+strVarValue;
	
			}
		}
	
		try{
			if(strUrl!=undefined && (objHttp.readyState==0 || objHttp.readyState==4))
			{
				objHttp.open('get', strUrl);
				objHttp.onreadystatechange =	function() { handleSingleHttpResponse(objHttp); };
				objHttp.send(null);				
			}
		}
		catch(e)
		{
			return false;
		}
	}
	
	/**
	 * This is a handle to the http request which will get the request from the http object 
	 * and replace the contents of the corresponding division.
	 * @param	object	objHttp is the http object for this particular response.
	**/
	function handleSingleHttpResponse(objHttp)
	{
		//The last time the function is called when the response is ready.		
		if(objHttp.readyState == 4 && objHttp.status == 200)
		{	
			strHtmlControl	=	objHttp.responseText;
			arrHtmlControl	=	strHtmlControl.split("!@#***#@!");
			strDivName		=	arrHtmlControl[1];
			document.getElementById(strDivName).innerHTML = arrHtmlControl[2];
			eval(strCallHttpResponseOFunction);
			strCallHttpResponseOFunction="";	
		}
	}
	
	function getHTMLControlMulti(strFieldName,strFieldId,strRequestVars,strCombo)
	{	
		var arrControl;
		arrControl = strCombo.split("&&");
		var objHttp = createRequestObject();
		// Created an Instance of the XMLHttpRequest object
		//Set the url of the file which will return the HTML control
		strUrl="index.php?file=./../../base/meditab/med_getHTMLControl";
		
		//Add the selected values in the query string
		strUrl+="&"+strFieldName+"="+document.getElementById("hid_sel"+strFieldName).value;
		
		//Add the field id in the query string
		strUrl+="&strFieldId="+strFieldId;
	
		//Add the request variables to the query string if required
		if(strRequestVars!='')
		{
			arrRequestVars	=	strRequestVars.split(",");
			for(intRequestVars=0; intRequestVars<arrRequestVars.length; intRequestVars++)
			{
				arrVars		=	arrRequestVars[intRequestVars].split("=");		
				strVarName	=	arrVars[0];
				strVarValue	=	document.getElementById(arrVars[1]).value;
				strUrl+="&"+strVarName+"="+strVarValue;
			}
	
	
		}
		try
		{
			if(strUrl!=undefined && (objHttp.readyState==0 || objHttp.readyState==4))
			{
				objHttp.open('get', strUrl);
				objHttp.onreadystatechange =	function() { handleMultiHttpResponse(objHttp,arrControl); };
				objHttp.send(null);
			}
		}
		catch(e)
		{
			return false;
		}
	}
	
	/**
	 * This is a handle to the http request which will get the request from the http object 
	 * and replace the contents of the corresponding division.
	 * @param	object	objHttp is the http object for this particular response.
	**/
	function handleMultiHttpResponse(objHttp,arrControl)
	{
		//The last time the function is called when the response is ready.		
		if(objHttp.readyState == 4 && objHttp.status == 200)
		{	
			strHtmlControl	=	objHttp.responseText;
			arrHtmlControl	=	strHtmlControl.split("!@#***#@!");
			strDivName		=	arrHtmlControl[1];
			document.getElementById(strDivName).innerHTML = arrHtmlControl[2];
			var arrNewControl = Array();
			arrNewControl = arrControl[0].split("','");
			var strCombo = "";
			for(var intControl = 1; intControl < arrControl.length; intControl++)
			{
				strCombo += arrControl[intControl] +"&&";
			}
			strCombo 			= 	strCombo.substr(0,strCombo.length-2);
			arrNewControl[0] 	= 	arrNewControl[0].substr(1,arrNewControl[0].length);
			arrNewControl[2] 	= 	arrNewControl[2].substr(0,arrNewControl[2].length-1);
			if(strCombo != "")
			{
				getHTMLControlMulti(arrNewControl[0],arrNewControl[1],arrNewControl[2],strCombo);
			}
			else
			{
				getHTMLControl(arrNewControl[0],arrNewControl[1],arrNewControl[2]);
			}
		}
	}

	/**
	  * This function is to not allow to set focus to the opener page if a modal dialog box has been opened in that page
	*/
	function checkBeforeSettingFocus()
    {	
		if (modalWin!=null && modalWin!='' && !modalWin.closed)
		{	
		
			self.blur();
			modalWin.focus();
		}
	}


	/**
	  * This function to open dialogbox in both i.e as well mozilla
	  * @param	strURL			string
	  * @param	strArguments	string
	  * @param	strFeatures		string
	*/
	function showDialog(strURL,strArguments,strFeatures)
	{
		//Check whether url has been passed or not
		if (strURL==null||strURL=='')
		{
			alert ("Invalid URL input.");
			return false;
		}
		
		//If arguments not passed then set it to blank
		if (strArguments==null||strArguments=='')
		{
			strArguments='';
		}
		
		//If features not passed then set the default features
		if (strFeatures==null||strFeatures=='')
		{
			strFeatures='dialogHeight: 400; dialogWidth: 900; center: Yes;';//default features
		}
		
	
		strFeatures = strFeatures.replace(/ /gi,'');
		arrFeatures = strFeatures.split(";");
		
		//Set the features of the dialog box
		strWinFeat = "directories=0,menubar=0,titlebar=0,toolbar=0,";
		for ( intFeatures in arrFeatures )
		{
			arrTmp = arrFeatures[intFeatures].split(":");
			strKey = arrTmp[0].toLowerCase();
			strValue = arrTmp[1];
			switch (strKey)
			{
				case "dialogheight":
					strWinFeat += "height="+strValue+",";
					intHeight = strValue;
					break;
				case "dialogwidth":
					strWinFeat += "width="+strValue+",";
					intWidth = strValue;
					break;
				case "dialogtop":
					strWinFeat += "top="+strValue+",";
					break;
				case "dialogleft":
					strWinFeat += "left="+strValue+",";
					break;
				case "resizable":
					strWinFeat += "resizable="+strValue+",";
					break;
				case "status":
					strWinFeat += "status="+strValue+",";
					break;
				case "center":
					if ( strValue.toLowerCase() == "yes" )
					{
						strWinFeat += "top="+((screen.availHeight-intHeight)/2)+",";
						strWinFeat += "left="+((screen.availWidth-intWidth)/2)+",";
					}
					break;
			}
		}
		modalWin=window.open(String(strURL),"",strWinFeat);
	
		if (strArguments!=null&&strArguments!='')
		{
			modalWin.dialogArguments=strArguments;
		}
	}
	
	
	
	// Function to get sub page data
	function getSubPageData(strUrl,strDiv)
	{	
		// Created an Instance of the XMLHttpRequest object
		var http = createRequestObject(); 
		try
		{
			if(strUrl!=undefined && (http.readyState==0 || http.readyState==4))
			{
				http.open('get', strUrl);
				http.onreadystatechange = function() { handleHttpResponseObject(http,strDiv,''); };
				http.send(null);				
			}
		}
		catch(e)
		{
			return false;
		}
	}
	
	function handleHttpResponseObject(http,strDiv,strEfunction)
	{
		// the last time the function is called when the response is ready.		
		if(http.readyState == 4 && http.status == 200)
		{	
			$strHtml=http.responseText;	
			document.getElementById(strDiv).innerHTML = $strHtml;
			addJavaScript(document.getElementById(strDiv));
			eval(strEfunction);
			eval(strCallHttpResponseOFunction);
			strCallHttpResponseOFunction="";
		}
	}
	
	
	function addJavaScript(strHtmlPage)
	{
		var strScript=strHtmlPage.getElementsByTagName('script');
		var strHead = document.getElementsByTagName("head")[0];
		if(document.getElementById("addScript"))
		{
			var node = document.getElementById('addScript');
			strHead.removeChild(node);
		}
		var scriptNode = document.createElement('script');
		scriptNode.id = 'addScript';
		scriptNode.type = 'text/javascript';
		scriptNode.language = 'javascript';
		var strText;
		strText = "";
		for(var x=0;x<strScript.length;x++)
		{
			with(window) 
			{ 
				strText = strText + " " + (strScript[x].text).replace('<!--','').replace('-->','');
			} 
		}
		if (window.navigator.appName.toLowerCase().indexOf("microsoft") > -1) 
		{   /// if ie
			scriptNode.text = strText;
		}
		else 
		{   // if mozzila
			scriptNode.innerHTML = strText;
		}
		
		document.getElementsByTagName("head")[0].appendChild(scriptNode);
	}
	
	/**
	 * FUnction to mask the time
	 */
	function onBlurTimeMask(strTextBox) 
	{
		var strVal = strTextBox.value;
		
		// if no digits....nada entered.....blank it.
		if(strReOneOrMoreDigits.test(strVal) == false) 
		{
			strTextBox.value = '';
			return false;
		}
		if(strVal.indexOf(":")!=strVal.lastIndexOf(":"))
		{
			strTextBox.value = '';
			return false;	
		}
		var blnchange=true;
		
		for(i=0;i<strVal.length;i++)
		{
			var c = strVal.charAt(i);
			
        	if (((c < "0") || (c > "9")) && c!=":")
			{
				blnchange=false;
				strVal = strVal.replace(strVal.charAt(i),'0');
			}
		}
		if(!blnchange)
		{
			strTextBox.value = strVal;
			return false;
		}
		var arrVal=strVal.split(":");
		if(arrVal[0]>12) arrVal[0]="00";
		if(arrVal[1]>59) arrVal[1]="00";
		strTextBox.value = arrVal[0]+":"+arrVal[1];
				
	}
	
	
	/**
  * This function will submit the search form
 **/
function submitSearchForm(objFrm)
{
	try
	{
		if(checkValidSearch(objFrm) == false) //general javascript validations for each field
		{
			return false; 
		}	
		//if some extra validation required	
		if(window.extraSearchValid)//check whether the function for extra validation exist or not
		{
			if(extraSearchValid()==false) //if the function returns false then return false
			{
				return false;	
			}
		}
		submitAjax(objFrm.name,'index.php',"post")
		return false;
	}
	catch(e)
	{
		return false;
	}
	
}
/**
  * This function will check date validation for search form
 **/
function checkValidSearch(objFrm)
{
	var FORMID = objFrm.name;
	var frmname=document.getElementById(FORMID);
	var blnflag=true;
	var strDtTo = "";
	var strDtToMsg = "";
	var strDtFrom = "";
	var strDtFromMsg = "";
	strAlertMessage = "";	// reset the alert nessage
	alertfield = "";
	strStyle = "";
	strFocus = "";
	selcount = 0;
	itercount = 0;
	var frmcnt=document.getElementById(FORMID).elements.length;
	for(var i=0;i<frmcnt;i++)
	{
		try
		{
			MESSAGE=eval("LBL_"+frmname.elements[i].name);
		}
		catch(e)
		{
			MESSAGE="Field";
		}
		// handling of various textbox validations for search
		if(frmname.elements[i].type=='text' && !frmname.elements[i].name.match(/\[]/))		
		{	
			// first 3 characters of the textbox name are to identify the search variables
			var chkSerch = frmname.elements[i].name.substr(0,3);
			if(chkSerch == "Sr_")
			{
				// forth and fifth carector to check type of validation
				var ChkType=frmname.elements[i].name.substr(3,2);
				
				//sixth character is to identify required field...
				var RChr=frmname.elements[i].name.substr(5,1);
				
				var REQUIRED="";
				if(RChr=="R")
				{
					REQUIRED = true;
				}					
				else
				{
					REQUIRED = false;	
				}
				//Generate name of the field...
				FIELD_NAME=eval("document."+FORMID+"."+frmname.elements[i].name);			
				switch(ChkType)
				{
					case "Dt" :
						if(frmname.elements[i].name.substr(frmname.elements[i].name.length-4,4) == 'from' && strDtFrom == "")
						{
							strDtFrom 		= 	FIELD_NAME;
							strDtFromMsg 	= 	MESSAGE;
						}
						else if(frmname.elements[i].name.substr(frmname.elements[i].name.length-2,2) == 'to')
						{
							strDtTo 		= 	FIELD_NAME;
							strDtToMsg 		= 	MESSAGE;
						}
						if(!checkDate(FIELD_NAME,MESSAGE,REQUIRED))
						{
							blnflag = false;
						}
						break;
				}
				if(strDtTo != "" && strDtFrom != "")
				{
					if(!dateCompare(strDtFrom,strDtTo,strDtFromMsg,strDtToMsg))
					{	
						return false;
					}
				}
			}
		}
	}
	if(blnflag == false && strAlertMessage!="")
	{
		strAlertMessage="Following errors:\n\n" + strAlertMessage;	
		alert(strAlertMessage);	
		eval(strStyle);
		eval(strFocus);
		return false;
	}
	else
	{
		eval(strStyle);
		return true;
	}
}

/**
Function will return the absolute top position of div id or td id........better use td id
*/
function getAbsoluteTop(strObjectId) 
{
	// Get an object top position from the upper left viewport corner
	// Tested with relative and nested objects
	objDiv	=	document.getElementById(strObjectId)
	
	// Get top position from the parent object
	intTop	=	objDiv.offsetTop           
	
	while(objDiv.offsetParent!=null) 
	{ 
		// Parse the parent hierarchy up to the document element
		oParent = objDiv.offsetParent  // Get parent object reference
		intTop += oParent.offsetTop // Add parent top position
		objDiv = oParent
	}
	// Return top position
	return intTop
}

// Custom ajax function which will directly returns data from the url and stops execution till that time...
function getURLData(strUrl)
{		
	
	try
	{
		var http = createRequestObject();
		if(strUrl!=undefined && (http.readyState==0 || http.readyState==4))
		{
			http.open('get', strUrl,false);
			http.send(null);
			return http.responseText;
		}
	}
	catch(e)
	{
		return false;
	}
}

/**
 * This function is used to get value of text area with HTML Editor
**/
function getTextAreaValue(strFramId,strFieldId)
{
	var oEditorarent		=	document.getElementById(strFramId).contentWindow.window;
	var FCK					=	oEditorarent.FCK ;
	var FCKConfig			=	oEditorarent.FCKConfig ;
	strTxtAreaName			=	eval('document.getElementById("'+strFieldId+'")');
	strTxtAreaVal			=	FCK.GetXHTML( FCKConfig.FormatSource);
	strTxtAreaName.value	=	strTxtAreaVal;
	return strTxtAreaName.value;
}	

//This function is used on OnClick event like onkeyup=checkNum(this).... used to check numeric
function OnKeyUpCheckNum(obj)
{
	if(isNaN(obj.value))
	{
		strVal	=	obj.value;
		if(strVal.length >=1)
			obj.value=strVal.substring(0,strVal.length-1);
	}
}

function getElement(element)
{
	var elm;
	if (document.getElementById) 
	{
		elm = document.getElementById(element);
	}
	else if (document.all) 
	{
		elm = document.all[element];
	}
	else if (document.layers) 
	{
		elm = document.layers[element];
	}
	return elm;
}