<!--hide this script from non-javascript-enabled browsers 
/*
####################################     
# File Name: functions.js
# Created By: Umesh Mundhe
# Created On: November 18 ,2005
# Updated By: Amol Divalkar
# This file contain all the common javascript functions
####################################
*/
	/*
     #############################################################################
     # Function Name: isBlank()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Function to check wether given value is blank or not.    
     # Parameters: string strValue : string. 
     # ON SUCCESS: Returns TRUE if value is blank.     
     # ON FAILURE: Returns FLASE  if value is not blank.     
     #############################################################################
	 */

	 function isBlank(strValue)
	 {
		 for(var i = 0; i < strValue.length; i++)
		 {
			 var c = strValue.charAt(i);
			 if ((c != ' ') && (c != '\n') && (c != '\t')) return false;
		 }
		 return true; 
	 }
	function matchExpression(expression,inputString)
	{
		if(inputString.search(expression)==-1)
		{
			return false;
		}
		else
		{
			return true;
		}
	}	
	/*
     #############################################################################
     # Function Name: isValidEmail()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Validate an email address.
     # Parameters: string strEmail : Email address
     # ON SUCCESS: Returns TRUE if string is in valid email format.     
     # ON FAILURE: Returns FLASE if string is not in valid email format.
     #############################################################################
	 */
	function isValidEmail(inputString)
	{
		var expression = /^[^\s]+@[^\.][^\s]{1,}\.[A-Za-z]{2,10}$/;
		if (isBlank(inputString))
		{
			return false;
		}	
		return matchExpression(expression,inputString);
	}
	
	function isValidUserName(inputString)
	{
		var expression = /^[a-zA-Z0-9]{6,}$/;
		return matchExpression(expression,inputString);
	}
	
	/*
     #############################################################################
     # Function Name: isValidString()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Checks if field value contains only alphanumeric and '_' charactes. Also checks  that alphabetical chars. and '_' must have to be come first and followed by numbers. It returns false if above conditions will not satisfy otherwise true.
     # Parameters: string strVal : string to be validated
     # ON SUCCESS: Returns TRUE if string is in valid format.  
     # ON FAILURE: Returns FLASE if string is not in valid format.  
     #############################################################################
	 */
	 function isValidString(strVal) 
	 {
		 var regex = /^[_]*[a-zA-Z_]+[a-zA-Z0-9_]+$/; 
		 if (isBlank(strVal))
		 {
			return false;
		 }		
		 return matchExpression(regex,strVal);
	 }


	/*
     #############################################################################
     # Function Name: IsAlphaNumeric()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Checks if field value contains only alphanumeric charecters.
     # Parameters: string strVal : string to be validated
     # ON SUCCESS: Returns TRUE if string is valid.     
     # ON FAILURE: Returns FLASE if string is not valid.     
     #############################################################################
	 */
	 function IsAlphaNumeric(strVal) 
	 {
		 var regex = /^[a-zA-Z]+[0-9]+[a-zA-Z0-9]*$/; 
		 if (isBlank(strVal))
		 {
			return false;
		 }		
		 return matchExpression(regex,strVal);
	 }

	function IsAlpha(strVal) 
	 {
		var regex = /^[a-zA-Z]*$/; 
		if (isBlank(strVal))
		{
			return false;
		}		
		return matchExpression(regex,strVal);
		
	 }
	function IsNumber(strVal) 
	{
		var regex = /^[0-9]*$/; 
		if (isBlank(strVal))
		{
			return false;
		}		
		return matchExpression(regex,strVal);
		 
	 }
	function IsNotAlphaNumeric(strVal) 
	 {
		 var regex = /^[^a-zA-Z0-9]*$/; 
		 if (isBlank(strVal))
		 {
			return false;
		 }		
		 return matchExpression(regex,strVal);
	 }
	 
     /*#############################################################################
     # Function Name: IsValidPhone()
     # Created By: Siddharth Thakar 
     # Created on: 13 Jul 2007
     # Purpose: Checks if field value contains only alphanumeric charecters.
     # Parameters: string strVal : string to be validated
     # ON SUCCESS: Returns TRUE if string is valid.     
     # ON FAILURE: Returns FLASE if string is not valid.     
     #############################################################################
	 */
	 function IsValidPhone(strVal) 
	 {
		 var regex = /[0-9]{10,}/; 
		 if (isBlank(strVal))
		 {
			return false;
		 }		
		 return matchExpression(regex,strVal);
	 }

	/*
     #############################################################################
     # Function Name: checkFileType ()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: It checks the file types.
     # Parameters: obj fld : object of file inout type 
	 #					   string strTypes : valid file types seperated by " "
     # ON SUCCESS: Returns TRUE if object contain valid file type.
     # ON FAILURE: Returns FLASE if object contain invalid file type.
     #############################################################################
	 */
	 function checkFileType(fld, strTypes) 
	 {
		 var strTypeList="";
		 strArray = strTypes.split(" "); 
		 for (i = 0;i<strArray.length;i++) 
		 {
			 if ( i < strArray.length && i > 0) 
			 {
				 strTypeList += "|";
			 }
                strTypeList += "."+strArray[i];
		 }
		 exp="("+strTypeList+")$"; 
		 var regex = new RegExp(exp);
		 if(!regex.test(fld.value)) 
		 {
			 return false; 
		 }
         return true; 
	 }

	/*
     #############################################################################
     # Function Name: isFileSize()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: It ckecks the size of the image file. You can check either in terms of width and height of image or size of image in bytes.
     # Parameters: obj fld : object of file input type for which we want to check size
	 #					   int size : Max file size allowed
     # ON SUCCESS: Returns TRUE file size is less than or equal to max size allowed.
     # ON FAILURE: Returns FLASE  file size is greater than max size allowed.
     #############################################################################
	 */

	 /* ********** Commented By Jayashree ************************
	 function isFileSize(fld, size) 
	 {
	     alert(fld.value);
		 var img = new Image(); 
		 img.src = fld.value; 
		 //alert(img.fileSize);
		 // var Dimensions = img.width + 'x' + img.height; 
		 // var File Size = img.fileSize; 
		alert(img.fileSize);
		alert(size);
		 if(img.fileSize > size) 
		 {
			 return false; 
		 }
		 else
		 {
		      return true; 
	     }
	 }
	*************************************************************/

	/*
     #############################################################################
     # Function Name: LTrim ()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Remove leading spaces.
     # Parameters: string str : String Value
     # ON SUCCESS: Remove leading spaces and return the string.     
     #############################################################################
	 */
	 function LTrim(str)
	 {
		 if(str==null)
		{
			return str;
		}
		for(var i=0;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i++);
		return str.substring(i,str.length);
	 }

	/*
     #############################################################################
     # Function Name: RTrim ()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Remove trailing spaces.
     # Parameters: string str : String Value
     # ON SUCCESS: Remove trailing spaces and return the string.      
     #############################################################################
	 */

	 function RTrim(str)
	 {
		 if(str==null)
		{
			return str;
		}
		for(var i=str.length-1;str.charAt(i)==" " || str.charAt(i)=="\n" || str.charAt(i)=="\t";i--);
		return str.substring(0,i+1);
	 }

	/*
     #############################################################################
     # Function Name: Trim ()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Remove leading and trailing spaces.
     # Parameters: string str : String Value
     # ON SUCCESS: Remove leading and trailing spaces and return the string.     
     #############################################################################
	 */

	 function Trim(str)
	 {
		 return LTrim(RTrim(str));
	 }


	/*
     #############################################################################
     # Function Name: stripHTMLTags ()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: A simple routine to strip HTML tags from supplied string It's not very clever but it's quite useful. Everything between each "<" and the subsequent ">" is ignored hence it could get confused with any javascript comparisons or comments that contain comparisons.
     # Parameters: string str : String Value
     # ON SUCCESS: Removes html tags from string and return string.     
     #############################################################################
	 */

	 function stripHTMLTags(str) 
	 {
		 var mystr=""; 
		 var chr=""; 
		 var skip=false; 
		 var skipcancel=false; 
		 for (x=0; x<str.length; x++) 
		 {
			 if (skipcancel==true)
			 {
				 skip=false;
			 } 
			 chr=str.charAt(x); 
			 if (chr=="<")
			 {
				 skip=true;skipcancel=false;
			 } 
			 else if (chr==">" && skip==true)
			 {
				 skipcancel=true;
			 } 
			 if (skip==false) 
			 {
				 mystr=mystr+chr; 
			 }
		 }
		 return mystr; 
	 } 

	/*
     #############################################################################
     # Function Name: isValidTime()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Checks if time is in HH:MM:SS format. The seconds are optional.
     # Parameters: string strTime : Time 
     # ON SUCCESS: Returns TRUE if strTime contains time in HH:MM:SS format.
     # ON FAILURE: Returns FLASE  if strTime does not contains time in HH:MM:SS format.
     #############################################################################
	 */

	 function isValidTime(strTime) 
	 {
		 var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?$/; 
		 var matchArray = strTime.match(timePat); 
		 if (matchArray == null) 
		 {
			 return false; 
		 }

		 hour = matchArray[1]; 
		 minute = matchArray[2]; 
		 second = matchArray[4]; 

		 if (isBlank(second)) 
		 {
			 second = null; 
		 }
		 
		 if (hour < 0  || hour > 23) 
		 {
			 return false; 
		 }

		 if (minute<0 || minute > 59) 
		 {
			 return false; 
		 }
		 
		 if (second != null && (second < 0 || second > 59)) 
		 { 
			 return false; 
		 }
		 return true; 
	 }

	/*
     #############################################################################
     # Function Name: isValidNumber()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Checks if the passed string contain valid number or not. 
     # Parameters: string numval : Number to check 
     # ON SUCCESS: Returns TRUE if value is numeric.     
     # ON FAILURE: Returns FLASE  if value is not numeric.
     #############################################################################
	 */

	 function isValidNumber(numval) 
	 {
		 if (isBlank(numval))
		 {
			 return false;
		 }
		 var myRegExp = new RegExp("^[/+|/-]?[0-9]*[/.]?[0-9]*$"); 
		 return myRegExp.test(numval); 
	 }

	/*
     #############################################################################
     # Function Name: isValidInterval()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Check we ther the passed value is valid interval or not ( i.e. 1 Year, 1 day, 20 days etc).
     # Parameters: string interval : Value
     # ON SUCCESS: Returns TRUE parameter contains valid interval.   
     # ON FAILURE: Returns FLASE  parameter is not a valid interval.
     #############################################################################
	 */

	 function isValidInterval(interval) 
	 {
		 var strIntervals = new Array("yrs","year","years","mos","month","months","day","days","week","weeks","hrs","hour","hours","mins","min","minutes","secs","sec","second","seconds"); 
		 strArray = interval.split(" "); 
		 
		 // need at least two items 
		 if (strArray.length < 2) 
		 {
			 return false;
		 }
		 
		 // check all pairs of values to be valid intervals (e.g 2 hrs 5 mins) 
		 for (i = 0;i<strArray.length-1;i=i+2) 
		 {
			 if (isNaN(strArray[i]))
			 {
				 return false;
			 }
			 found=false; 
			 for (var x = 0;x<strIntervals.length;x++) 
			 {
				 if (strArray[i+1].toUpperCase() == strIntervals[x].toUpperCase()) 
				 {
					 found=true;
				 }
			 }
			 if (!found)
			 {
				 return false;
			 }
		 }
		 return true; 
	 }


	/*
     #############################################################################
     # Function Name: isValidDate()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Checks if date is in MM-DD-YYYY format  format. 
     # Parameters: string d : Date
	 #                    
     # ON SUCCESS: Returns TRUE if value is blank.     
     # ON FAILURE: Returns FLASE  if value is not blank.     
     #############################################################################
	 */

	 function isValidDate(d) 
	 {
		 //var strDatestyle = "US"; //United States date style 
		 var strDatestyle = "EU";  //European date style 
		 var strDate; 
		 var strDateArray; 
		 var strDay; 
		 var strMonth; 
		 var strYear; 
		 var intDay; 
		 var intMonth; 
		 var intYear; 
		 var booFound = false; 
		 var strSeparatorArray = new Array("-"," ","/","."); 
		 var intElementNr; 
		 var err = 0; 
		 var strMonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); 
		 strDate = d; 
		 if (strDate.length < 1) 
		 {
			 return false; 
		 }
		 
		 if (strDate.toLowerCase()=="today" || strDate.toLowerCase()=="now")
		 {
			 return true;
		 }
		 
		 for (intElementNr = 0; intElementNr < strSeparatorArray.length; intElementNr++) 
		 {
			 if (strDate.indexOf(strSeparatorArray[intElementNr]) != -1) 
			 {
				 strDateArray = strDate.split(strSeparatorArray[intElementNr]); 
				 if (strDateArray.length != 3) 
				 {
					 err = 1; 
					 return false; 
				 }
				 else 
				 {
					 strDay = strDateArray[0]; 
					 strMonth = strDateArray[1]; 
					 strYear = strDateArray[2]; 
				 }
				 booFound = true; 
			 }
		 }

		 if (booFound == false) 
		 {
			 if (strDate.length>5) 
			 {
				 strDay = strDate.substr(0, 2); 
				 strMonth = strDate.substr(2, 2); 
				 strYear = strDate.substr(4); 
			 }
			 else 
			 {
				 return false; 
			 }
		 }

		 // verify year part   2 or 4 digits 
		 if (strYear.length != 2 && strYear.length != 4) 
		 {
			 return false;
		 }

		 if (isNaN(strYear))
		 {
			 return false;
		 }
		 
		 // US style (swap month and day) 
		 if (strDatestyle == "US") 
		 {
			 strTemp = strDay; 
			 strDay = strMonth; 
			 strMonth = strTemp; 
		 }

		 // verify 1 or 2 digit integer day 
		 if (strDay.length<1 || strDay.length>2) 
		 {
			 return false;
		 }
		 
		 if (isNaN(strDay))
		 {
			 return false;
		 }
		 
		 // month may be digits of characters, hence following check 
		 intMonth = parseInt(strMonth, 10); 
		 if (isNaN(intMonth)) 
		 {
			 for (i = 0;i<12;i++) 
			 {
				 if (strMonth.toUpperCase() == strMonthArray[i].toUpperCase()) 
				 {
					 intMonth = i+1; 
					 strMonth = strMonthArray[i]; 
					 i = 12; 
				 }
			 }
			 if (isNaN(intMonth)) 
			 {
				 err = 3; 
				 return false; 
			 }
		 }

		 intDay=parseInt(strDay,10); 
		 intYear = parseInt(strYear, 10); 

		 if (intMonth>12 || intMonth<1) 
		 {
			 err = 5; 
			 return false; 
		 }

		 // day in month check 
		 if (intDay < 1 || intDay > 31)
		 {
			 return false;
		 }
		 
		 if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth == 11) && (intDay > 30)) 
		 {
			 return false; 
		 }

		 if (intMonth == 2) 
		 {
			 if (LeapYear(intYear)) 
			 {
				 if (intDay > 29) 
				 {
					 return false;
				 }
			 }
			 else 
			 {
				 if (intDay > 28) 
				 {
					 return false;
				 }
			 }
		 }

		 if (intYear<=99)
		 {
		      intYear=intYear+2000;
	     }
		 return intDay+"/"+intMonth+"/"+intYear; 
	 }

	/*
     #############################################################################
     # Function Name: isValidDateTime()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: check a composite date/time field  assume date is everything up to first space  and time is everything after first space.
     # Parameters: string strDateTime : Date time string in DD-MM-YYYY HH:MM:SS
     # ON SUCCESS: Returns TRUE date time is valid.
     # ON FAILURE: Returns FLASE  date time is invalid.
     #############################################################################
	 */

	 function isValidDateTime(strDateTime) 
	 {
		 var dt = Trim(strDateTime); 
		 var intMatch; 
		 var intDateOnly = false; 
		 if (strDateTime.toLowerCase()=="today" || strDateTime.toLowerCase()=="now")
		 {
			 return true;
		 }
		 
		 intMatch=dt.indexOf(":"); 
		 if (intMatch < 0) 
		 {
			 intDateOnly = true; 
			 intMatch=dt.length; 
		 }
		 else 
		 {
			 intMatch=dt.indexOf(" "); 
		 }
		 
		 if (intMatch < 0) 
		 {
			 return false;
		 }
		 
		 // check date 
		 if (!isValidDate(dt.substr(0,intMatch)))
		 {
			 return false;
		 }
		 
		 // check time 
		 if (!intDateOnly) 
		 {
			 if (!isValidTime(dt.substr(intMatch+1,dt.length-intMatch)))
			 {
				 return false;
			 }
		 }
		 return true; 
	 }

	/*
     #############################################################################
     # Function Name: LeapYear()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: check year wether it is a leap year or not.
     # Parameters: string intYear : Year
     # ON SUCCESS: Returns TRUE given year is leap year.
     # ON FAILURE: Returns FLASE  given year is not a leap year.
     #############################################################################
	 */

	 function LeapYear(intYear) 
	 {
		 if (intYear % 100 == 0) 
		 {
			 if (intYear % 400 == 0) 
			 {
				 return true; 
			 }
		 }
		 else 
		 {
			 if ((intYear % 4) == 0) 
			 { 
				 return true; 
			 }
		 }
		 return false; 
	 }

	/*
     #############################################################################
     # Function Name: isEarlierOrEqual()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: This function will accept start date and end date and will check for date format and it will also check wether end date is earlier than start date.
     # Parameters: string start : Start date 
	 #                    string end  : End date 
     # ON SUCCESS: Returns TRUE If both date are in valid format and start date is earlier than end date.
     # ON FAILURE: Returns FLASE If either of date are not in valid format or end date is before start date.
     #############################################################################
	 */

	 function isEarlierOrEqual(start,end) 
	 {
		 // convert dates to dd/mm/yyyy 
		 var myStart = isValidDate(start,true);
		 var myEnd = isValidDate(end,true); 
		 if (myStart=="" || myEnd=="") 
		 {
			 return false; 
		 }

		 var startparts= myStart.split("/"); 
		 var endparts=myEnd.split("/"); 

		 if (Date.UTC(startparts[2],startparts[1],startparts[0]) <= Date.UTC(endparts[2],endparts[1],endparts[0])) 
		 {
			 return true; 
		 }
		 else 
		 {
			 return false; 
		 }
	 }

	/*
     #############################################################################
     # Function Name: isTimeEarlierOrEqual()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: This function will accept start time and end time and will check for time format and it will also check wether end time is earlier than start time.
     # Parameters: string start : Start time 
	 #                    string end  : End time 
     # ON SUCCESS: Returns TRUE If both time are in valid format and start time is earlier than end time.
     # ON FAILURE: Returns FLASE If either of time are not in valid format or end time is before start time.
     #############################################################################
	 */

	 function isTimeEarlierOrEqual(start,end) 
	 {
		 // convert times to UTC dates 
		 if (start=="" || end=="") 
		 {
			 return false; 
		 }
		 var startparts= start.split(":"); 
		 var endparts=end.split(":"); 
		 if (Date.UTC(2000,1,1,startparts[0],startparts[1]) <= Date.UTC(2000,1,1,endparts[0],endparts[1])) 
		 {
			 return true; 
		 }
		 else 
		 {
			 return false; 
		 }
	 } 

	/*
     #############################################################################
     # Function Name: NewWindow()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: This function will open passed url in new window.
     # Parameters: string url : Url
	 #                    string title : Window Title
	 #                    string w : window width
	 #                    string h : window height 
	 #                    string scroll : boolean value will indicate wether window should contain scroll bars or not (true/false, 'yes'/ 'no')
	 #                    string resize : boolean value will indicate wether window is resizable or not (true/false, 'yes'/ 'no')
     # ON SUCCESS: open url in new window.     
     #############################################################################
	 */

	 function NewWindow(url, title, w, h, scroll, resize) 
	 {
		 
		 if (scroll==true || scroll=='yes') 
		 {
			 scroll='yes'; 
		 }
		 else 
		 {
			 scroll='no'; 
		 }
		 if (resize==true || resize=='yes') 
		 {
			 resize=', resizable'; 
		 }
		 else 
		 {
			 resize=''; 
		 }
		 var winl = (screen.width - w) / 2; 
		 var wint = (screen.height - h) / 2; 
		 winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+resize;
		 win = window.open(url, title, winprops);
	 }


	/*
     #############################################################################
     # Function Name: DisplayStatusMsg()
     # Created By: PHP Team   
     # Created on: 12  Sep 2005
     # Purpose: Display passed string in status bar.
     # Parameters: string msgStr : value
     # ON SUCCESS: Display passed string in status bar. 
     #############################################################################
	 */

	 function DisplayStatusMsg(msgStr)
	 { 
	    status=msgStr; document.MM_returnValue = true; 
	 }
	/*
     #############################################################################
     # Function Name: fnSetFocus()
     # Created By: Siddharth Thakar   
     # Created on: 1 Aug 2007
     # Purpose: Set focus on the first input field of the page.
     #############################################################################
	 */
	 
	 function fnSetFocus()
	 {
		var arr = new Array();
		arr = document.getElementsByTagName("input");
		var i =0;
		for (i =0 ; i <= arr.length; i++)
		{
			if (arr[i].type == "text")
			{
				arr[i].focus();
				break; 
			}
		}
	 }	
// stop hiding --> 
