
/*
 *	Javascript Common Functions 
 * *************************************************************************
 *  1.  trim(sText)
 *	2.  isValidChar(inputText, ValidChars)
 *	3.  isNumeric(sText)
 *	4.  isNumericWithDecimal(sText)
 *	5.  isAlphaNumeric(inputText)
 *	6.  emailCheck(ctrName, strMsg, focus) 
 *	7.  fnLstSelect(ctlname,value)
 *	8.  openBrWinCenter(theURL,winName,features, w_width, w_height) 
 *	9.  isNull(ctrName, msg, focus) 
 *  10. fnInteger(objEvent)
 *  11. fnFloat(objEvent)
 *	12. getCurrentDate()
 *  13. isNullForDiv
 *  14. emailCheckDiv()
 *  15. isAlphaNumeric()
 *  16. isAlphabetic()
 *  17. emailCheck()
 *  18. emailCheckForDiv()
 *  19. fnLstSelect()
 *  20. openBrWinCenter()
 *  21. isNull()
 *  22. fnInteger()
 *  23. fnFloat()
 *  24. getCurrentDate()
 *  25. isNullForDiv()
 *  26. emailCheckDiv()
 *  27. isAlphaNumeric()
 *  28. chkLength()
 *  29. showHideElement()
 *  30. setDivValue()
 *  31. getDivValue()
 *  32. checkMaxValidation()
 *  33. validateDate()
 *  34. checkRadioSelected()
 *  35. setFocus()
 *  36. isFileFormat()
 *  37. clearOtherText (strTextbox1, strTextbox2)
 *  38. checkDateGreaterThanToday(strDate)
 *  39. isValidFax(sText)
 * *************************************************************************
 */


/*
 * *************************************************************************
 * Name			: trim()
 * Description	: to remove unwanted spaces in the starting and ending of the text
 * Parameter	: text
 * Return value : String
 * Example		: str = trim(str) 
 * *************************************************************************
 */

function trim(sText) 
{
  while (sText.substring(0,1) == ' ') 
  {
    sText = sText.substring(1,sText.length);
  }
  while (sText.substring(sText.length-1,sText.length) == ' ') 
  {
    sText = sText.substring(0,sText.length-1);
  }
  return sText;
}

/*
 * *************************************************************************
 * Name			: isValidChar(inputText, ValidChars)
 * Description	: to check whether a string is valid
 * Parameter	: inputText  - text to be validated
 *                ValidChars - Valid characters list
 * Return value : true or false
 * Example		: isValidChar(str)
 * *************************************************************************
 */

function isValidChar(inputText, ValidChars)
{
	var Char;
	var i;

	// if length of the string is zero
	if (inputText.length <= 0)
		return false;

	// iterate each character in the string
	for(i=0;i<inputText.length;i++)
	{
		Char = inputText.charAt(i); 

		// if the character is found in the valid string
		if (ValidChars.indexOf(Char) == -1) 
		{
		  return false;
		}
	}
	return true;
}

/*
 * *************************************************************************
 * Name			: isNumeric(sText)
 * Description	: to check whether a string is numeric value
 * Parameter	: text
 * Return value : true or false
 * Example		: isNumeric(str)
 * *************************************************************************
 */

function isNumeric(sText) 
{
	var ValidChars = "0123456789";
	return isValidChar(sText, ValidChars);
}


/*
 * *************************************************************************
 * Name			: isNumericWithDecimal(sText)
 * Description	: to check whether a string is numeric value
 * Parameter	: text
 * Return value : true or false
 * Example		: isNumericWithDecimal(str)
 * *************************************************************************
 */

function isNumericWithDecimal(sText) 
{
	var ValidChars = "0123456789.";
	return isValidChar(sText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: isNumericSpace(sText)
 * Description	: to check whether a string is numeric value
 * Parameter	: text
 * Return value : true or false
 * Example		: isNumericSpace(str)
 * *************************************************************************
 */

function isNumericSpace(sText) 
{
	var ValidChars = "0123456789 -";
	return isValidChar(sText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: isAlphaNumeric(inputText)
 * Description	: to check whether a string is alphanumeric
 * Parameter	: text
 * Return value : true or false
 * Example		: isAlphaNumeric(str)
 * *************************************************************************
 */

function isAlphaNumeric(inputText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
	return isValidChar(inputText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: isAlphabetic(inputText)
 * Description	: to check whether a string is alphanumeric
 * Parameter	: text
 * Return value : true or false
 * Example		: isAlphabetic(str)
 * *************************************************************************
 */

function isAlphabetic(inputText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	return isValidChar(inputText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: isAlphaComDash(inputText)
 * Description	: to check whether a string is alphanumeric
 * Parameter	: text
 * Return value : true or false
 * Example		: isAlphabetic(str)
 * *************************************************************************
 */

function isAlphaComDash(inputText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ,-";
	return isValidChar(inputText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: emailCheck(str)
 * Description	: to check whether a string is valid email
 * Parameter	: text
 * Return value : true or false
 * Example		: emailCheck(str) 
 * *************************************************************************
 */

// valid chars : a-z, A-Z, 0-9, _, .
function emailCheck(ctrName, strMsg, focus) 
{
	var at="@";
	var dot=".";

	var str;
	var objValue;
	var strMessage;
	var flgValid = true;

	objCtrl = document.getElementById(ctrName);

	// if control is not found
	if (objCtrl != null)
		str = objCtrl.value;
	else
	{
		flgValid = false;
		str = "";
	}

	// checking valid character in email address
	flgValid = isValidEmailChars(str);
	

	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);


	// alert message
	if (trim(strMsg) != "")
		strMessage = strMsg;
	else
		strMessage = "Invalid E-mail ID";

	// validate email
	if (str.indexOf(at)==-1)
	   flgValid = false;

	else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   flgValid = false;

	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		flgValid = false;
	
	else if (str.indexOf(at,(lat+1))!=-1)
		flgValid = false;
	
	else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		flgValid = false;
	
	else if (str.indexOf(dot,(lat+2))==-1)
		flgValid = false;
	
	else if (str.substring(str.length-1,str.length)==".")
		flgValid = false;
	
	else if (str.indexOf(" ")!=-1)
		flgValid = false;
	
	// if validation fails
	if (flgValid == false)
	{
		alert(strMessage);
		if (focus == true)
		{
			objCtrl.focus();
		}
	}
	else {
		flgValid = true;					
	}
	
	return flgValid;	

}


/*
 * *************************************************************************
 * Name			: emailCheckForDiv(str)
 * Description	: to check whether a string is valid email
 * Parameter	: text
 * Return value : true or false
 * Example		: emailCheckForDiv(str) 
 * *************************************************************************
 */

// valid chars : a-z, A-Z, 0-9, _, .
function emailCheckForDiv(ctrName, strMsg, divName) 
{
	var at="@";
	var dot=".";

	var str;
	var objValue;
	var objDiv;
	
	var strMessage;
	var flgValid = true;

	objCtrl = document.getElementById(ctrName);
	objDiv = document.getElementById(divName);
	
	// if control is not found
	if (objCtrl != null)
		str = objCtrl.value;
	else
	{
		flgValid = false;
		str = "";
	}

	// checking valid character in email address
	flgValid = isValidEmailChars(str);
	

	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);


	// alert message
	if (trim(strMsg) != "")
		strMessage = strMsg;
	else
		strMessage = "Invalid E-mail ID";

	// validate email
	if (str.indexOf(at)==-1)
	   flgValid = false;

	else if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   flgValid = false;

	else if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		flgValid = false;
	
	else if (str.indexOf(at,(lat+1))!=-1)
		flgValid = false;
	
	else if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		flgValid = false;
	
	else if (str.indexOf(dot,(lat+2))==-1)
		flgValid = false;
	
	else if (str.substring(str.length-1,str.length)==".")
		flgValid = false;
	
	else if (str.indexOf(" ")!=-1)
		flgValid = false;
	
	//alert(flgValid);
	 
	// if validation fails
	if (flgValid == false)
	{
		//alert(strMessage);
		if (objDiv != null)
		{
			objDiv.innerHTML = strMessage;
			return false;  
		}

		else
			objDiv.innerHTML = "";
	}
	else
		return true;					
}

/*
 *  * *************************************************************************
 *  Function Name: fnLstSelect
 *  Description  : this function select an item in a list/Menu
 *  parameters   : ctlname - control name of the list box
 * 				   value - value or text of the list box to be selected
 *
 *  Example      : fnLstSelect("categoryId","1")
 * * *************************************************************************
*/

function fnLstSelect(ctlname,value)
{
	var selObj = document.getElementById(ctlname);
	var len;

	if (selObj != null)
	{
		// get the count of list items
		len = selObj.length;
		
		// iterate for each value in list
		for(i=0;i<len;i++)
		{
			// if the value matches
			if(selObj.options[i].value == value || selObj.options[i].text == value)
			{
				selObj.selectedIndex = i;
			}
		}
	}
}

/*
 * *************************************************************************
 * Name			: openBrWinCenter()
 * Description	: to show a popup window in centre of screen
 * Parameter	: theURL  - url of page 
 *				  winName - window name
 *                features - features for the popwidow other than height and width
 *				  w_width  - width of the screen
 *                w_height - height of the screen
 *  Return value: 
 *  Example		: openBrWinCenter("a.htm","popwin","height=300,width=300",300,300) 
 * *************************************************************************
 */

function openBrWinCenter(theURL,winName,features, w_width, w_height) 
{ 
	// calculate left and top values for window
	var left = parseInt((screen.width/2) - (w_width/2));
	var top = parseInt((screen.height/2) - (w_height/2));
	
	// if url is not empty
	if (theURL != "")
	{
		window.open(theURL,winName,"left=" + left + ",top=" + top + "," + features);
	}
}

/*
 * *************************************************************************
 * Name			: isNull()
 * Description	: to check null value in text box
 * Parameter	: ctrName  - control name (text box name)
 *				  msg      - message to be alerted
 *                focus    - to focus the control after alerting, give true or false
 *  Return value: true or false
 *  Example		: isNull("username","Enter username",true) 
 * *************************************************************************
 */

function isNull(ctrName, msg, focus) 
{
	var objCtrl;
	var objValue;

	// reference to the control
	objCtrl = document.getElementById(ctrName);
	
	// if control is not found
	if (objCtrl != null)
	{
		objValue = objCtrl.value;

		// check the value
		if (trim(objValue) == "")
		{
			if (trim(msg) != "") alert(msg);
			if (focus == true)   objCtrl.focus();
			return true;
		}
		else
			return false;
	}
	else
		return true;
}


/*
 * *************************************************************************
 * Name			: fnInteger()
 * Description	: this function return only integer values
 * Parameter	: event
 *
 *  Return value: true or false
 *  Example		: onkeypress="return fnInteger(event)"
 * *************************************************************************
 */

function fnInteger(objEvent)//this return integer value
{
	  var iKeyCode;
	  iKeyCode = objEvent.keyCode;

	  // if it is digit
	  if(iKeyCode>=48 && iKeyCode<=57) return true;

	  return false;
}

/*
 * *************************************************************************
 * Name			: fnFloat()
 * Description	: this function return only float values
 * Parameter	: event
 *
 *  Return value: true or false
 *  Example		: onkeypress="return fnFloat(event)"
 * *************************************************************************
 */

function fnFloat(objEvent)
{
	  var iKeyCode;
	  iKeyCode = objEvent.keyCode;

	  // if it is digit
	  if(iKeyCode>=48 && iKeyCode<=57) return true;
	  if(iKeyCode==46) return true;

	  return false;
}

/*
 * *************************************************************************
 * Name			: getCurrentDate()
 * Description	: this function return current system date // Saturday, March 4, 2006
 * Parameter	: 
 *
 *  Return value: String
 *  Example		: getCurrentDate()
 * *************************************************************************
 */

function getCurrentDate()
{
	var CurrDate;	
	var DateString;
	var CurrDay;
	var CurrMonth;
	var CurrYear;
	var weekDay;
	var day;
	var month;

	var strMonthArray = new Array("January", "February","March","April","May","June","July","August","September","October","November","December");
	var strWeekArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",  "Saturday");

	CurrDate = new Date();
	
	CurrDay   = CurrDate.getDate();;
	CurrMonth = CurrDate.getMonth();
	CurrYear  = CurrDate.getFullYear();
	weekDay   = CurrDate.getDay()
	
	day   = strWeekArray[weekDay];
	month = strMonthArray[CurrMonth];

	DateString = day + ", " + month + " " + CurrDay + ", " + CurrYear;

	return DateString;

}

/*
 * *************************************************************************
 * Name			: isNullForDiv()
 * Description	: to check null value in text box
 * Parameter	: ctrName  - control name (text box name)
 *				  msg      - message to be alerted
 *                divName    - name of the div where to show tbe error message
 *  Return value: true or false
 *  Example		: isNullForDiv("username","Enter username","div_username") 
 * *************************************************************************
 */

function isNullForDiv(ctrName, msg, divName) 
{
	var objCtrl;
	var objValue;
	var objDiv;

	// reference to the control
	objCtrl = document.getElementById(ctrName);
	objDiv = document.getElementById(divName);

	// if div is present
	if (objDiv != null) {
		objDiv.innerHTML = "";
	}

	// if control is not found
	if (objCtrl != null)
	{
		objValue = objCtrl.value;

		// check the value
		if (trim(objValue) == "")
		{
			//display message in div
			if (objDiv != null) {
				objDiv.innerHTML = msg;
			}
			return true;
		}
		else
			return false;
	}
	else
		return true;
}

/*
 * *************************************************************************
 * Name			: emailCheckDiv(str)
 * Description	: to check whether a string is valid email
 * Parameter	: text
 * Return value : true or false
 * Example		: emailCheckDiv(str) 
 * *************************************************************************
 */

// valid chars : a-z, A-Z, 0-9, _, .
function emailCheckDiv(ctrName, strMsg, divName) 
{
	var at="@";
	var dot=".";

	var str;
	var objValue;
	var objDiv;
	var flgValid = true;
	var strMessage;

	objCtrl = document.getElementById(ctrName);
	objDiv = document.getElementById(divName);

	// if control is not found
	if (objCtrl != null)
		str = objCtrl.value;
	else
		return false;

	// checking valid character in email address
	flgValid = isValidEmailChars(str) 


	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);

	// alert message
	if (trim(strMsg) != "")
		strMessage = strMsg;
	else
		strMessage = "Invalid E-mail ID";

	// validate email
	if (str.indexOf(at)==-1)
	   flgValid = false;

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	   flgValid = false;

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
		flgValid = false;
	
	if (str.indexOf(at,(lat+1))!=-1)
		flgValid = false;
	
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
		flgValid = false;
	
	if (str.indexOf(dot,(lat+2))==-1)
		flgValid = false;
	
	if (str.substring(str.length-1,str.length)==".")
		flgValid = false;
	
	if (str.indexOf(" ")!=-1)
		flgValid = false;
	
	// if validation fails
	if (flgValid == false)
	{
		if (objDiv != null)
			objDiv.innerHTML = strMessage;		
	} 
	else {
		if (objDiv != null)
			objDiv.innerHTML = "";	
		return true;		
	}	
	 
	return flgValid;			
}


/*
 * *************************************************************************
 * Name			: isAlphaNumeric(inputText)
 * Description	: to check whether a string is alphanumeric
 * Parameter	: text
 * Return value : true or false
 * Example		: isAlphaNumeric(str)
 * *************************************************************************
 */

function isValidEmailChars(inputText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789._@";
	return isValidChar(inputText, ValidChars);
}
 
 /* 
 * *************************************************************************
 * Name			: chkLength(cltName, length, message,divName)
 * Description	: to check whether the text entered in the field exceeds the limit.
 * Parameter	: cltName - name of the text field
 * 	              length  - limit of the characters in the text
 *                message - message to be displayed in the div tag
 *                divName - name of the div tag
 * Return value : -
 * Example		: chkLength("txt_ZONEADDRESS", 150, "This text box is restricted to 150 characters only...","div_zoneaddress")
 * *************************************************************************
 */
 
 	function chkLength(cltName, length, message,divName)
 	{

	var objCtrl;
	var objValue;
    var objDiv;
    
	// reference to the control
	objCtrl = document.getElementById(cltName);
	objDiv = document.getElementById(divName);
	
	// if control is not found
	if (objCtrl != null)
	{	  
	  objValue=objCtrl.value;
	  if(objValue.length >length)
	  {
	     objCtrl.value=objValue.substring(0,length-1);
	     if (objDiv != null)
	     {
	        objDiv.innerHTML = message;
	     }
	  }else{
	     if (objDiv != null)
	        objDiv.innerHTML = "";
	  }
 	}
 }
 
/*
 * *************************************************************************
 * Name			: showHideElement(objName, argValue)
 * Description	: to show or hide elements
 * Parameter	: objName - element name 
 *                argValue - value "show" or "hide"
 * Return value : 
 * Example		: showHideElement("txtName", "show")
 * *************************************************************************
 */
 
function showHideElement(objName, argValue)
 {
 	var objElement = document.getElementById(objName);
 	if (objElement != null)
 	{
 		if (argValue == "show")
 			objElement.style.visibility = "visible";
 		else
 			objElement.style.visibility = "hidden";
 	}
 }
 /*
 * *************************************************************************
 * Name			: setDivValue(objName, argValue)
 * Description	: to set the value for div tag
 * Parameter	: objName - element name 
 *                argValue - value to be dispalyed
 * Return value : 
 * Example		: setDivValue("txtName", "text")
 * *************************************************************************
 */
 function setDivValue(objName, argValue)
 {
 	var objElement = document.getElementById(objName);
 	if (objElement != null)
 	{
 		objElement.innerHTML = argValue;
 	}
 }

 /*
 * *************************************************************************
 * Name			: getDivValue(objName)
 * Description	: to set the value for div tag
 * Parameter	: objName - element name 
 *                argValue - value to be dispalyed
 * Return value : 
 * Example		: getDivValue("txtName")
 * *************************************************************************
 */
 function getDivValue(objName) 
 {
 	var objElement = document.getElementById(objName);
 	
 	if (objElement != null)
 		return objElement.innerHTML;
 	else
 		return "";
 }
  
  /*
 * *************************************************************************
 * Name			: checkMaxValidation()
 * Description	: to validate application form
 * Parameter	:  
 *                 
 * Return value : 
 * Example		: checkMaxValidation ("changed_name", "addtopage_name", "maximumno_name", "First Name", "div_firstName",numValidation)
 * *************************************************************************
 */
 
function checkMaxValidation (txtChangedName, chkAddtoPage, txtMaxNum, controlName, divMsg, numValidation)
{
	var objPage = document.getElementById(chkAddtoPage);
	var objMax  = document.getElementById(txtMaxNum);
	var objMsg  = document.getElementById(divMsg);
	var objChanged  = document.getElementById(txtChangedName);
	
	var flag = true;
	var temp = false;
	
	// if control is not present
	if (objPage == null) {
		//alert("objPage is null " + chkAddtoPage);
		return false;
	}
	
	if (objMax == null) {
		//alert("objMax is null "  + objMax);
		return false;
	}
	
	
	// if Add to page checkbox  is selected
	if (objPage.checked == true)
	{
		temp = false;
		
		// if changed name text is there
		if (objChanged != null)
		{
			if (isNullForDiv(txtChangedName,"Please enter changed name for '" + controlName + "'",divMsg))
			{
			    temp = true;
			    flag=false;
			}
		}
		
		//max number validation
		if (temp == false && numValidation == true)
		{	
			objMax.value = trim(objMax.value);
			
			// Null value checking
			if (isNullForDiv(txtMaxNum,"Please enter maximum number of characters for '" + controlName + "'",divMsg))
			{
			    flag=false;
			}
			
			// numeric validation      
			else if (isNumeric(objMax.value) == false)
			{	
				setDivValue(divMsg, "Please enter numeric value for 'Max. No.'");
				flag=false;	
			}
		}
	}

	
	if (flag==true) {
		//alert(chkAddtoPage + ", " + txtMaxNum + ", " +  controlName);
	}
	
	//return value
	return flag; 
}

/*
 * *************************************************************************
 * Name			: validateDate()
 * Description	: to validate date 
 * Parameter	: field - date value 
 *                 
 * Return value : true or false
 * Example		: validateDate ("12/31/2007")
 * *************************************************************************
 */	
 
	function validateDate(field)
    {

    	var dtCh="/";
    	var dtStr=field;
   	
    	var pos1=dtStr.indexOf(dtCh)
    	var pos2=dtStr.indexOf(dtCh,pos1+1)
		
		var myDayStr=dtStr.substring(0,pos1) 
		var myMonthStr=dtStr.substring(pos1+1,pos2)
		var myYearStr=dtStr.substring(pos2+1)
    	
    	var myMonthStr1;
    	//var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); 
    	var myMonth = new Array('01','02','03','04','05','06','07','08','09','10','11','12'); 
    	
		
		if (myMonthStr.length == 1 )
		{
			myMonthStr = "0" + myMonthStr;
		}

		var mnth = "";

    	for( var i=0; i<12;i++)
    	{
    		mnth=myMonth[i];

	        /*
			alert("myMonth[" + i + "]" + myMonth[i] + " mnth: " + parseInt(mnth) + " myMonthStr: " + parseInt(myMonthStr) + "  " + (mnth == myMonthStr) );

			if(parseInt(mnth) == parseInt(myMonthStr))
			{
			 myMonthStr1=i;
			} 
    		*/

			if(mnth == myMonthStr)
			{
				myMonthStr1=i;
			} 

    	}

    	var myDateStr = myDayStr + '-' + myMonth[myMonthStr1] + '-' + myYearStr;

		/* Using form values, create a new date object using the setFullYear function */
		var myDate = new Date();
		
		myDate.setFullYear( myYearStr, myMonthStr1, myDayStr );
		
		if ( myDate.getMonth() != myMonthStr1 ) 
		{
		  return false 
		} 
		else 
		{
		  return true
		}
   }  



/*
 * *************************************************************************
 * Name			: validateDate2()
 * Description	: to validate date 
 * Parameter	: field - date value 
 *                 
 * Return value : true or false
 * Example		: validateDate2 ("12-Jan-2007")
 * *************************************************************************
 */	
 
	function validateDate2(field)
    {

    	var dtCh="-";
    	var dtStr=field;
   	
    	var pos1=dtStr.indexOf(dtCh)
    	var pos2=dtStr.indexOf(dtCh,pos1+1)
		
		var myDayStr=dtStr.substring(0,pos1) 
		
		var myMonthStr=dtStr.substring(pos1+1,pos2)
		
		var myYearStr=dtStr.substring(pos2+1)
    	
    	var myMonthStr1;
    	var myMonth = new Array('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); 
    	//var myMonth = new Array('01','02','03','04','05','06','07','08','09','10','11','12'); 
    	
    	for( var i=0; i<12;i++)
    	{
    	  var mnth=myMonth[i];
	        
			if(trim(mnth) == trim(myMonthStr))
			{
			 myMonthStr1=i;
			
			 
			} 
    	  
    	}
    	
    	var myDateStr = myDayStr + '-' + myMonth[myMonthStr1] + '-' + myYearStr;

		/* Using form values, create a new date object using the setFullYear function */
		var myDate = new Date();
		
		myDate.setFullYear( myYearStr, myMonthStr1, myDayStr );
		
		if ( myDate.getMonth() != myMonthStr1 ) 
		{
		  return false 
		} 
		else 
		{
		  return true
		}
   }  



/*
 * *************************************************************************
 * Name			: checkRadioSelected()
 * Description	: to check any one of the radio button is checked 
 * Parameter	: sRadioName - name (not id) of the radio button
 *				  sCaption   - Caption of the radio button	 
 *                divName    - name of Div tag where you want to display error message
 *
 * Return value : true or false
 * Example		: checkRadioSelected("residence", "Residence Is", "div_residence")
 * *************************************************************************
 */	   
	function checkRadioSelected(frmName, sRadioName, sCaption, divName)
	{
		
		var i;
		var flag = false;
		var retValue = false;

		// reference to object and get no. of element for radio group
		var objRadio = eval("document." + frmName + "." + sRadioName );
		var objDiv = document.getElementById(divName);
		var len;
		
		if (typeof objRadio.length == 'undefined') // if only one control exists
		{
			if (objRadio.checked == false)
				setDivValue(divName, "Please select " + sCaption);
			else
				retValue = true;
		}
		else //if (len > 1) // if there exists more than one control
		{
			len = objRadio.length;
			
			for (i=0;i<len;i++)
			{
				// if any element is checked 
				if (objRadio[i].checked == true)
				{
					flag = true;
					break;
				}
			}
			 
			// if any element is checked 
			if (flag == true)
				retValue = true;
			else
				setDivValue(divName, "Please select " + sCaption);
		}

		return retValue;
	}

 /*
 * *************************************************************************
 * Name			: setFocus(objName)
 * Description	: to set the focus in the specified element
 * Parameter	: objName - element name 
 *                
 * Return value : true or false
 * Example		: setFocus("txtName")
 * *************************************************************************
 */
 
 function setFocus(objName) 
 {
 	var objElement = document.getElementById(objName);
 	 
 	if (objElement != null)
		objElement.focus();
 }

 /*
 * *************************************************************************
 * Name			: checkAddtoPage(objElement)
 * Description	: to select addtopage checkbox in application form
 * Parameter	: objName - reference to the object (pass the value 'this') 
 *                
 * Return value : 
 * Example		: onchange= "checkAddtoPage(this)"
 * *************************************************************************
 */
 
  function checkAddtoPage(objElement)
  {
	
	var arrValue;
	var elementId = objElement.id;
	var sAddtoPage = "";
	var sReqValidaion = "";
	var objChk = "";
	var objValid;
	
	// remove the text 'changed_'
	arrValue = elementId.replace("changed_","");

	sAddtoPage    = "addtopage_" + arrValue;
	sReqValidaion = "validationfor_" + arrValue;
	
	//get checkbox reference
	objChk   = document.getElementById(sAddtoPage);
	objValid = document.getElementById(sReqValidaion);
	
	//if element exists and value is not null, then select it
	if (objChk != null)
	{
		if (trim(objElement.value) != "") 
			objChk.checked = true;
			
		else {
			objChk.checked = false;
			if (objValid != null) {
				objValid.checked = false;
			}
		}
	}

  } 
  
 /*
 * *************************************************************************
 * Name			: getTextValue(objName)
 * Description	: to set the value for div tag
 * Parameter	: objName - element name 
 *                argValue - value to be dispalyed
 * Return value : 
 * Example		: getTextValue("txtName")
 * *************************************************************************
 */
 
 function getTextValue(objName) 
 {
 	var objElement = document.getElementById(objName);
 	
 	if (objElement != null)
 		return objElement.value;
 	else
 		return "";
 }

 /*
 * *************************************************************************
 * Name			: setTextValue(objName, strValue) 
 * Description	: to set the value for div tag
 * Parameter	: objName - element name 
 *                argValue - value to be dispalyed
 * Return value : 
 * Example		: setTextValue("txtName","")
 * *************************************************************************
 */
 
 function setTextValue(objName, strValue) 
 {
 	var objElement = document.getElementById(objName);
 	
 	if (objElement != null)
 		objElement.value = strValue;

 }

 /*
 * *************************************************************************
 * Name			: selectCheckbox(frmName, mainCheckName, childCheckName)
 * Description	: to select or unselect checkboxes on clicking main checkbox
 * Parameter	: frmName - <form> tag name 
 *                mainCheckName - main check box name
 *                childCheckName - child check box name
 * Return value : 
 * Example		: selectCheckbox('frmWelcome','chk_selectAll','chk_branchCode')
 * *************************************************************************
 */
 
	function selectCheckbox(frmName, mainCheckName, childCheckName)
	{      
		var flg;
		var length;
		var objMainchk;

		if (frmName == "" || mainCheckName == "" || childCheckName == "")
			return false;

		objMainchk = eval("document." + frmName + "." + mainCheckName);
		
		// if main check box is exists
		if(typeof objMainchk == 'object'){

			// if it is selected
			if(objMainchk.checked)
				flg=true;
			else
				flg=false;

			// child check boxes 
			var objchild = eval("document." + frmName + "." + childCheckName);

			// if there exists check boxes 
			if(typeof objchild == 'object'){

				length = eval("document." + frmName + "." + childCheckName + ".length");
				
				// select or unselect all check boxes
				if(typeof length != 'undefined'){
					for(var i=0; i < length; i++)
						eval("document." + frmName + "." + childCheckName + "[" + i + "].checked=" + flg);
				}else{
					eval("document." + frmName + "." + childCheckName + ".checked=" + flg);
				}
			}	
			
		}
	}
	
	 /*
	 * *************************************************************************
	 * Name			: isFileFormat(inputText)
	 * Description	: to check whether a string is valid filename
	 * Parameter	: text
	 * Return value : true or false
	 * Example		: isAlphabetic(str)
	 * *************************************************************************
	 */

	function isFileFormat(inputText)
	{
		var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890_.";
		return isValidChar(inputText, ValidChars);
	}

	 /*
	 * *************************************************************************
	 * Name			: clearOtherText (strTextbox1, strTextbox2)
	 * Description	: to clear one text box on entering data in other
	 * Parameter	: strTextbox1 : id of text box 1
	 * 				  strTextbox2 : id of text box 2
	 *
	 * Return value : true or false
	 * Example		: clearOtherText ("txt_card1", "txt_card2")
	 * *************************************************************************
	 */
	function clearOtherText (strTextbox1, strTextbox2)
	{
		var strText = trim(getTextValue(strTextbox1));
		
		if (strText != "" && isNumeric(strText)) {
			setTextValue(strTextbox2,"");
		}
	}

	 /*
	 * *************************************************************************
	 * Name			: checkDateGreaterThanToday (strDate)
	 * Description	: to check whether specified date is greater than today
	 * Parameter	: strDate : date value
	 *
	 * Return value : true or false
	 * Example		: checkDateGreaterThanToday ("25/02/2008")
	 * *************************************************************************
	 */
	function checkDateGreaterThanToday(strDate) {

		var arrDate = strDate.split("/");

		if (arrDate.length>= 3) {
		
			var date = new Date(arrDate[2],parseInt(arrDate[1])-1,arrDate[0]);
			var currDate = new Date();

			if (date > currDate) {
				return false;
			}
			else
				return true;
		}
	}	

	 /*
	 * *************************************************************************
	 * Name			: setCheckedValues(objCheckAll, objCheckSingle, i)
	 * Description	: to select or unselect checkbox (Select All) 
	 * Parameter	: objCheckAll : Object of Select All check box
	 *				: objCheckSingle : Object of individual check box
	 *
	 * Return value : 
	 * Example		: setCheckedValues(document.form1.chk_selectAll, document.form1.chk_cardNo, i);
	 * *************************************************************************
	 */
	 
	function setCheckedValues(objCheckAll, objCheckSingle, i)
	{      
		var flg=0;
		var total=0;
		
		var length = objCheckSingle.length;

		if(typeof length != 'undefined'){

			if(objCheckSingle[i].checked==false) {
				objCheckAll.checked=false;
			}		

			for(var j=0;j<length;j++)
			{
				if(objCheckSingle[j].checked==true)
					flg=1;
				else
					flg=0;

				total=total+flg;
			}

			if(total==length) {
				objCheckAll.checked=true;
			}

		} else {

			if(objCheckSingle.checked==false) {
				objCheckAll.checked=false;
			}

			if(objCheckSingle.checked==true) {
				objCheckAll.checked=true;
			}	
		}
	}

/*
 * *************************************************************************
 * Name			: isValidPhone(sText)
 * Description	: to check whether a string is a valid phone number
 * Parameter	: text
 * Return value : true or false
 * Example		: isValidPhone("+9198456 45698")
 * *************************************************************************
 */

function isValidPhone(sText) 
{
	var ValidChars = "0123456789 +-(),";
	return isValidChar(sText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: isValidFilename(str)
 * Description	: to check whether a string is a valid file name
 * Parameter	: text
 * Return value : true or false
 * Example		: isValidFilename("test.txt")
 * *************************************************************************
 */
 
function isValidFilename(str) {
   if (/^[^\\\/\:\*\?\"\<\>\|\.]+(\.[^\\\/\:\*\?\"\<\>\|\.]+)+$/.test(str)) {
      return true;
   }
   else {
      return false;
   }
}

	 /*
	 * *************************************************************************
	 * Name			: compareDates (strFromDate, strToDate)
	 * Description	: to compare two dates, return false if strFromDate is greater than strToDate
	 * Parameter	: strDate : date value
	 *
	 * Return value : true or false
	 * Example		: compareDates ("25/02/2008", "30/02/2008")
	 * *************************************************************************
	 */
	function compareDates(strFromDate, strToDate) {

		var arrFromDate = strFromDate.split("/");
		var arrToDate   = strToDate.split("/");
		
		if (arrFromDate.length>= 3 && arrToDate.length >= 3) {
		
			var fromDate = new Date(arrFromDate[2], arrFromDate[1]-1, arrFromDate[0]);
			var toDate   = new Date(arrToDate[2],   arrToDate[1]-1, arrToDate[0]);
			
			if (fromDate > toDate) {
				return false;
			}
			else
				return true;
		}
		else
			return false;
			
	}

/*
 * *************************************************************************
 * Name			: isAlphabeticWithoutSpace(inputText)
 * Description	: to check whether a string is alphanumeric
 * Parameter	: text
 * Return value : true or false
 * Example		: isAlphabeticWithoutSpace(str)
 * *************************************************************************
 */

function isAlphabeticWithoutSpace(inputText)
{
	var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
	return isValidChar(inputText, ValidChars);
}

/*
 * *************************************************************************
 * Name			: isValidFax(sText)
 * Description	: to check whether a string is a valid fax number
 * Parameter	: text
 * Return value : true or false
 * Example		: isValidPhone("+91-22-67603201")
 * *************************************************************************
 */

	function isValidFax(sText) 
	{
		var ValidChars = "0123456789 +-";
		return isValidChar(sText, ValidChars);
	}

/*
 * *************************************************************************
 * Name			: exportPageData(divName, fileName)
 * Description	: to export data in div tag to excel
 * Parameter	: divName  - Name of div 
 *				  fileName - File name 
 * Return value : 
 * Example		: exportPageData("div_Report", "report.xls")
 * *************************************************************************
 */

	function exportPageData(divName, fileName) {
		
		var strText = "";
		var objDiv = document.getElementById(divName);
	
		if (objDiv != null)
		{
			var strText = objDiv.innerHTML;
			var frm = window.open("","winPop","width=10,height=10");
			
			frm.document.write(strText);
	
			frm.document.write("<SCRIPT LANGUAGE=\"JavaScript\"> \n");
			frm.document.write(" document.execCommand('SaveAs','1','" + fileName + "'); \n");
			frm.document.write(" window.close(); \n");
			frm.document.write("</" + "SCRIPT> \n");
		}
	}

	/*
	 * *************************************************************************
	 * Name			: checkAgeLimit(strDate)
	 * Description	: to check whether 
	 * Parameter	: strDate  - date value to be checked 
	 *				  
	 * Return value : true or false
	 * Example		: checkAgeLimit("01/01/1975")
	 * *************************************************************************
	 */
 
	function checkAgeLimit(strDate) {

		var arrDate = strDate.split("/");
		
		if (arrDate.length == 3) {
		
			var date     = new Date(arrDate[2],parseInt(arrDate[1])-1,arrDate[0]);
			var currDate = new Date();
			var dtLimitDate = new Date(currDate.getFullYear()-100,currDate.getMonth(),currDate.getDate());

			if (date < dtLimitDate) {
				return false;
			}
			else
				return true;
		}
	}

/*
 * *************************************************************************
 * Name			: exportPageToExcel(objForm, divName, fileName)
 * Description	: to export data in div tag to excel
 * Parameter	: objForm - Form object 
 * 				  divName  - Name of div 
 *				  fileName - File name 
 * Return value : 
 * Example		: exportPageToExcel(this.form, "div_Report", "report")
 * *************************************************************************
 */ 

	function exportPageToExcel(objForm, divName, strFileName) {
		
		objForm.hdn_RepDivCont.value = getDivValue(divName);
		objForm.hdn_RepExcelName.value = strFileName;
			
		objForm.action = "../GenExcelFromHtml";
		objForm.submit();
		
	}
 

	// JavaScript Document
	
	// function to Check and Uncheck All Checkboxes 	
	function selectAllCheckBox(objCheckAll, objChkElement) {
		
		if (objCheckAll != null && objChkElement != null) {
			
			var chkValue = objCheckAll.checked;
			
			// if there is only one check box 
			if (typeof objChkElement.length == "undefined") {
				objChkElement.checked = chkValue ;
			}
			else {
				// more than one check box
				for (var i = 0; i < objChkElement.length; i++) {
					objChkElement[i].checked = chkValue ;
				}
			}
		}
	}

	function chkClick(objCheckAll, objChkElement) {
		
		if (objCheckAll != null && objChkElement != null) {
			
			var chkValue = false;
			var iCnt = 0;
			var total = 0;
				
			// if there is only one check box 
			if (typeof objChkElement.length == "undefined") {
				chkValue = objChkElement.checked;
			}
			else {
			
				iCnt = 0;
				total = -1;
				
				// more than one check box
				for (iCnt = 0; iCnt < objChkElement.length; iCnt++) {
					if (objChkElement[iCnt].checked == true) {
						total++;
					}
					else {
						total=-1;
						break;
					}
				}
				
				if (total == iCnt-1) {
					chkValue = true;
				}
			}
			
			objCheckAll.checked = chkValue;
		}
	}

	
