    //These functions Written by : SAMEER K
    //S/W Developer Boolean Information Systems Pvt. Ltd.

    /***************These function changes the color of the link on mouse move*************************/
    function changeColor(lnk)
	{
		var ln = document.getElementById(lnk.id);
		if(ln!=null)
		{
			ln.style.backgroundColor = "#ffffff";
			ln.style.color = "#ae1ee7";
//			ln.style.font.fontSize = "12px";
		//	ln.style.fontWeight = "medium";

		}
	}
	  function ValidateTelNumber()
    {
	    var key=window.event.keyCode;
		if (key <40 || key >57 )
		window.event.returnValue = false;
		if(key==42 || key==46)
		window.event.returnValue = false;
	}
	function phoneValidate()
	{
		var key=window.event.keyCode;
		if (key <40 || key >57 )
		window.event.returnValue = false;
		if(key==42 || key==46)
		window.event.returnValue = false;
	}
	
	function pinNumericWithDecimal()
    {
			var key = window.event.keyCode;
			if (key <48 || key >57)
			 window.event.returnValue  = false;
			 if (key ==46)
			 window.event.returnValue  = true;
	}

	function resetColor(lnk)
	{
		var ln = document.getElementById(lnk.id);
		if(ln!=null)
		{
			ln.style.backgroundColor = "#ffffff";
			ln.style.color = "#3c3d6f";
		}
	}
    /*****************End of Color changeing functions*****************************/
    function f1()
    {
		alert('hi boss');
    }

    function removeSpaces(txt)
    {
		var tx = document.getElementById(txt.id);
		tx.value = trimAll(tx.value);
    }
    function setMaxLength(txt)
    {
		var tx = document.getElementById(txt.id);
		if(tx.innerText.length>50)
		{
			alert('more than 50 chars');
			tx.focus();
			tx.select();
			return false;
		}
//		return false;
    }
    function checkMinLength(txt)
    {
		var tx = document.getElementById(txt.id);
		if(tx.value.length>0 && tx.value.length<6)
		{
			tx.select();
			return false;
		}
		else
			return true;

    }

    function ClearTexts()
    {
		var frm = document.forms[0];
		var arr = frm.getElementsByTagName("INPUT");
		var lst = frm.getElementsByTagName("SELECT");
		var txtarea = frm.getElementsByTagName("TEXTAREA");
		var divtag = frm.getElementsByTagName("DIV");
		var arrList = frm.getElementsByTagName("OPTION");


	/*	alert(arr.length);
		alert(arrList.length);
		alert(txtarea.length); */

		if(arr!=null)
		{
			for(var i=0; i<arr.length; i++)
			{
				if(arr[i].type=="text")
					arr[i].value = "";
				else if(arr[i].type=="checkbox")
					arr[i].checked = false;
			}
		}

		if(txtarea!=null)
		{
			for(var i=0; i<txtarea.length;i++ )
			{
//				alert(txtarea[i].innerHTML);
				txtarea[i].innerHTML = "";
			}
		}

		try
		{
		if(lst!=null)
		{
			var lnth = frm.getElementsByTagName("OPTION").length;

				for(var i=0; i<lnth; i++)
				{
					arrList[i].selected = false;
			//				arrList[i].options.selected = arrList[i].options[0].value;
				}
				arrList[0].selected = true;

		}
		}
		catch(e){}
		return false;
    }
    function setFocus(txt)
    {
//		alert(txt.id);
		document.forms[0].elements[0].focus();
    }

    //this function is to validate time
    function validateTimeNew(txt)
    {
//		alert('qc here');

		var bState = false;

		var ctl = document.getElementById(txt.id);
		ctl.value = ctl.value.toUpperCase();

		var chkAlpha = "bcdefghijklnoqrstuvwxyzBCDEFGHIJKLNOQRSTUVWXYZ~`!@#$%^&*()-_+=|\{}[];\"'<>,.?/";

		for(var i=0; i <ctl.value.length; i++)
		{
			if(chkAlpha.indexOf(ctl.value.charAt(i))>=1)
			{
				bState = true;
				break;
			}
		}

		if(bState)
		{
			alert("Invalid Time!");
			ctl.select();
			ctl.focus();
			return false;
		}

		if(ctl.value.length>0 && ctl.value.length<8)
		{
			if(ctl.value.indexOf(':')==-1)
			{
				alert("Invalid Time! : missing");
				ctl.select();
				ctl.focus();
				return false;
			}
			else if(ctl.value.indexOf(':')!=2 && ctl.value.indexOf(' ')!=5 && (ctl.value.indexOf('AM')!=6 || ctl.value.indexOf('PM')!=6))
			{
				alert("Invalid Time! here");
				ctl.select();
				ctl.focus();
				return false;
			}
		}
		if(findOccuranceOfChar(ctl.value,':'))
		{
			alert('Invalid Time! : char occured more than once');
			ctl.focus();
			ctl.select();
			return false;
		}
		if(findOccuranceOfChar(ctl.value,'AM'))
		{
			alert("Invalid Time! 'AM' occured more than once");
			ctl.focus();
			ctl.select();
			return false;
		}
		if(findOccuranceOfChar(ctl.value,'PM'))
		{
			alert("Invalid Time! 'PM' occured more than once");
			ctl.focus();
			ctl.select();
			return false;
		}

		if(ctl.value.indexOf(':')==2)
		{
			var hr = ctl.value.substring(0, ctl.value.indexOf(':'));
			if(hr.length==1)
			{
				hr = "0" + hr;
				ctl.value = hr + ctl.value.substring(ctl.value.indexOf(':')+1, ctl.value.length);
			}
			else if(hr.length ==2)
			{
				if(hr>12)
				{
					alert('Invalid Hours!');
					ctl.select();
					ctl.focus();
					return false;
				}
			}
		}
	}
    //This function restricts the user to fill the field and doesnt allow user to leave it blank
    function mustFill(txt)
	{
//	alert(txt.id);
		var t = document.getElementById(txt.id);
		if(t.value.length==0 || t.value=="")
		{
			alert("field can not be empty");
			t.select();
			t.focus();
			return false;
		}
	}

    //this function calculates mole value
    function calculateMole(txtactual, txtmolewt, txtmole)
    {
//		alert(txtactual.length);
		if(txtactual.length!=0 && txtmole.length>=0)
		{
//			alert(txtactual.length);
			var _txtactual = document.getElementById(txtactual.id);
			var num = getIndexNumberFromGrid(_txtactual);

			var str = _txtactual.id.substring(0, _txtactual.id.indexOf(num));

			_txtmole = str + num + "_" + txtmole;
			_txtmolewt =  str + num + "_" + txtmolewt;

			_txtmole = document.getElementById(_txtmole);
			_txtmolewt = document.getElementById(_txtmolewt);


			_txtmole.value = (_txtactual.value) /(_txtmolewt.innerText);
			_txtmole.value = _txtmole.value.substring(0, _txtmole.value.indexOf('.')+4);
			_txtmole.select();
			_txtmole.focus();

		}
		else
		{
			var _txtmole = document.getElementById(txtmole.id);
			var num = getIndexNumberFromGrid(_txtmole);

			var str = _txtmole.id.substring(0, _txtmole.id.indexOf(num));

			_txtactual = str + num + "_" + txtactual;
			_txtmolewt =  str + num + "_" + txtmolewt;

			_txtactual = document.getElementById(_txtactual);
			_txtmolewt = document.getElementById(_txtmolewt);


			_txtmole.value = (_txtactual.value) /(_txtmolewt.innerText);
			_txtmole.value = _txtmole.value.substring(0, _txtmole.value.indexOf('.')+4);

		}
    }


    //this function validates phone numbers
    function validatePhone(txt)
    {
		var _ctl = document.getElementById(txt.id);
		var _char = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/~`!@#$^&*()<>:;'{}|=+_.,[]\" ";

		var _bState = false;
		var _iCnt = 0;
		var _str = trimAll(_ctl.value);
		var _iIndex = 0;
//		if(_str.charAt(0)=='-'||_str.charAt(1)=='-'||_str.charAt(2)=='-')
//			_bState = true;
		for(i=0; i<_str.length; i++)
		{
			if(_str.charAt(i)=='-')
			{
				_iCnt++;
			}
			if(_char.indexOf(_str.charAt(i))!=-1)
			{
				_bState = true;
				break;
			}

		}
		_iIndex = _str.indexOf('-');
		if(_str.length>0)
		{
			if(_iIndex==-1)
				_bState = true;
			else if(_iCnt>1)
				_bState = true;
			else if(_str.substring(0, _iIndex).length< 3)
					_bState = true;
			else if(_str.substring(_iIndex+1,_str.length).length< 6)
				_bState = true;
		}
//			alert(_bState);
		if(_bState)
		{
			_ctl.focus();
			_ctl.select();
			alert('Phone no. must not be a mobile no. \n and should be in XXX-XXXXXXX format');
		}
    }
    function floatvalue()
	{
			var key=window.event.keyCode;
			if(key<48 || key >57)
			window.event.returnValue=false;
			if(key==46)
			{
			window.event.returnValue=true;
			}
			
	}
    
    function validationForFloatField(txt)
	 {
		    //alert(txt)			
			var intDecimalIndex=txt.value.indexOf('.');
			//alert(intDecimalIndex);
			var_txtLength=txt.value.length;
			//alert(var_txtLength);
			var_txtValue=txt.value;
			//alert(var_txtValue);
			iCount=0;
		    if(var_txtValue=="")
			{
			    return;
			}
			
			for(i=0;i<var_txtLength;i++)
		    {
		        if(var_txtValue.charAt(i)=='.')
			    {
				//alert(var_txtValue.charAt(i));
				iCount++
			    }
		    }
		    if(iCount>1)
		    {
				alert("Invalid Value.");
				
				txt.focus();
				txt.select();
				
				return;
			}
			else
			if(intDecimalIndex==0 )
			{
			    alert("Invalid Value.")
			   
				txt.focus();
			    txt.select();
			    return;
			}
			else
			if(var_txtValue.charAt(var_txtLength-1)=='.')
			{
			    alert("Invalid Value.")
			  
				txt.focus();
			    txt.select();
			    return;
			
			}
		}
		

    //this function validates pin code field
    function validatePinCode(txt)
    {
		var ctrl = document.getElementById(txt.id);
		var digits = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/~`!@#$^&*()<>:;'{}|=+-_.,[]\" ";
		var bState= false;

		var str_check = trimAll(ctrl.value);
		for(var i=0; i<str_check.length; i++)
		{
//			alert(str_check.charAt(i));
//			alert(digits.indexOf(str_check.charAt(i)));
			if(digits.indexOf(str_check.charAt(i))!=-1)
			{
				bState = true;
				break;
			}
		}
		if(bState)
		{
			alert("Entered Invalid Pin Code!");
			ctrl.focus();
			ctrl.select();
			return false;
		}
    }

    //this functin checks whether the fields like city, country, location are valid
    function validateCharFields(txt)
    {
    	var ctrl = document.getElementById(txt.id);
		var digits = " 0123456789/~`!@#$^&*()<>:;'{}|=+-_.,[]\" ";
		var bState= false;

		var str_check = trimAll(ctrl.value);
		for(var i=0; i<str_check.length; i++)
		{
			if(digits.indexOf(str_check.charAt(i))!=-1)
			{
				bState = true;
				break;
			}
		}
		if(bState)
		{
			ctrl.focus();
			ctrl.select();
		}
		else
			ctrl.value = str_check;
		return bState;
    }

    //this function is to validate CAS NUMBER
    function validateCasNo(txt)
    {
		var ctl = document.getElementById(txt.id);
		var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/~`!@#$^&*()<>:;'{}|=+-_.,[]\" ";
		var bState = false;
		var str_check = txt.value;

		for(var i=0; i<str_check.length; i++)
		{
//			alert(i + "___" +str_check.charAt(i));
//			alert(alphaCheck.indexOf(str_check.charAt(i)));
			if(alphaCheck.indexOf(str_check.charAt(i))!=-1 && alphaCheck.indexOf(str_check.charAt(i))!=75)
			{
				bState = true;
				break;
			}
		}
		if(bState)
		{
			alert("Invalid Cas No.!");
			ctl.focus();
			ctl.select();
			return false;
		}

    }
    function checkHtmlEditor(txt)
    {
//    alert(txt);
		var ctl = document.getElementById(txt);
		var str = trimAll(ctl.innerText);
		var bln_condition = false;
//		alert(ctl);
		if(str.length==0 || str=="")
		{
			bln_condition = true;
			ctl.focus();
		}
		return bln_condition;
    }
    //This function is used to validate the numeric fields
    function ValidateIsNumber(txt)
    {
		var bln_condition = true;
   		var ctl = document.getElementById(txt.id);

		if (isNaN(ctl.value))
		{
			alert("Please enter the number");
			ctl.select();
			bln_condition = false;

		}
		return bln_condition;
    }


//This function is to validate the Statio Metric Ratio if a user copy pastes some improper data

    function ValidateStatioRatio(txt)
    {

		var ctl = document.getElementById(txt.id);
		var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-~`!@#$%^&*()<>;'{}|=+-_.,[]\"";
		var bState = true;
		var str_check = ctl.value;
	//	alert(ctl.value);

		if(findOccuranceOfChar(ctl.value, ':'))
		{
			alert(': char occured more than once');
			txt.focus();
			txt.select();
			bState = false;
		}

	//	alert(bState);
		for(var i=0; i<str_check.length; i++)
		{
//			alert(i + "___" +str_check.charAt(i));
//			alert(alphaCheck.indexOf(str_check.charAt(i)));
			if(alphaCheck.indexOf(str_check.charAt(i))>=1)
			{
				alert(str_check.charAt(i) + ' is not allowed!');
				txt.focus();
				txt.select();
				bState = false;
				break;
			}
		}
/*		if(ctl.value.indexOf('%')==-1)
		{
			if(txt.value.length>0)
			{
			txt.value = txt.value + '%';
			txt.focus();
			txt.select();
			return false;
			}
		}
		else if(ctl.value.charAt(0)=='%')
		{
			alert('% sign must be followed by some positive value');
			txt.focus();
			txt.select();
			return false;
		}
		else if(ctl.value.charAt(0)=='0')
		{
			alert('Invalid Ratio');
			txt.focus();
			txt.select();
			return false;
		}
		if(checkAlpha(ctl.value))
		{
			alert('No Alpha characters allowed');
			txt.focus();
			txt.select();
			bState = false;
		}*/

		return bState;
	}

    function findOccuranceOfChar(str_check, chr)
    {
		var iCount = 0;

		for(i=0; i<str_check.length; i++)
		{
//			alert(str_check.charAt(i));
			if(str_check.charAt(i)==chr)
			{
				iCount++;
			}
		}

		if(iCount<=1)
			return false;
		else
			return true;
    }

    function checkAlpha(str_check)
    {
//		alert('i am in alpha check');
	   var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/-~`!@#$^&*()<>:;'{}|=+-_.,[]\"";
	   var bState = false;

		for(var i=0; i<str_check.length; i++)
		{
//			alert(i + "___" +str_check.charAt(i));
//			alert(alphaCheck.indexOf(str_check.charAt(i)));
			if(alphaCheck.indexOf(str_check.charAt(i))>=1)
			{
				bState = true;
				break;
			}
		}
		return bState;
    }

   function heightwidththickness()
   {
		var key=window.event.keyCode;

		if(key<48 || key>122)
		window.event.returnValue=false;

		if (key==58|| key==59 || key==61 || key==62 || key==63 || key==64||key==91 ||key==92||key==93||key==94||key==95||key==96)
		window.event.returnValue=false;

		if(key==32 || key==39 || key==46)
		window.event.returnValue=true;
   }

   function specialCases()
   {
   var key=window.event.keyCode;

		if(key<48 || key>122)
		window.event.returnValue=false;

		if (key==58|| key==59 || key==61 || key==62 || key==63 || key==64||key==91 ||key==92||key==93||key==94||key==95||key==96)
		window.event.returnValue=false;

		if(key==32)
		window.event.returnValue=true;
   }

  function StatioRatio()
  {
    var key = window.event.keyCode;
    if(key<48 || key >58)
    	window.event.returnValue=false;
    if(key==37)
      window.event.returnValue=true;
  }

   function casNO()
   {
    var key = window.event.keyCode;
	if(key<48 || key >57)
	window.event.returnValue=false;

	if(key==45 || key==35 )
	window.event.returnValue=true;
   }

    function pinNumeric()
    {
			var key = window.event.keyCode;
			if (key <48 || key >57)
			 window.event.returnValue  = false;
	}

	//This function is used for validateing the Address Textbox
	function address()
	{
			var key = window.event.keyCode;
			if(key==61 || key==43 || key==39 || key==34 || key==60 || key==62 || key==63 || key==47 || key==92) //key == 38)
			window.event.returnValue = false;
	}

	function addr()
	{
			var key = window.event.keyCode;
			if(key==61 || key==43 || key==39 || key==34 || key==60 || key==62 || key==63 || key==47 || key==92)
			window.event.returnValue = false;
	}
	function userName()
	{
		var key=window.event.keyCode;

		if(key<48 || key>122)
		window.event.returnValue=false;

		if (key==58 || key==59 || key==61 || key==63 || key==91 || key==92 ||  key==93 || key==94 || key==96)
		window.event.returnValue=false;

		if(key==46 || key==95)
		window.event.returnValue=true;
	}
	//This function is used for validateing the Contactno Textbox
	function Numeric()
	{

			var key=window.event.keyCode;
			//alert(key)
			if(key<48 || key >57)
			window.event.returnValue=false;

			if(key==41 || key==40 || key==45 || key==32 || key==46)
			window.event.returnValue=true;
	}


	//this function is used to validate UnitOfMeasurement
	function Measurement()
	{
	var key=window.event.keyCode;

	if(key<65 || key>122)
	window.event.returnValue=false;

	if (key==91 ||key==92||key==93||key==94||key==95||key==96)
	window.event.returnValue=false;

	if(key==46 || key==32)
	window.event.returnValue=true;
	}

	//This function is used for validateing the Name Textbox
	function nameChar()
	{
			var key=window.event.keyCode;
			if(key<65 || key>122)
			window.event.returnValue=false;

			if (key==91 ||key==92||key==93||key==94||key==95||key==96)
			window.event.returnValue=false;

			if(key==32||key==46 || key==45)
			window.event.returnValue=true;

	}
	function AlphaNumeric()
	{
			var key=window.event.keyCode;
			if(key<48 || key>122)
			window.event.returnValue=false;

			if (key==58|| key==59 || key==61 || key==62 || key==63 || key==64||key==91 ||key==92||key==93||key==94||key==95||key==96)
			window.event.returnValue=false;

			if(key==16 || key==46 ||key==47)
			window.event.returnValue=true;

			if(key==44 || key==32 || key==45)
			window.event.returnValue=true;
	}
	
	function ChkAlphaNumericForOnBlur(txt)
	{
	
		var flag = false;
		var str = document.getElementById(txt.id).value;
		str = trimAll(str);
		if(str.length == 0) return;
		var validstr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
		
		for(var i=0;i<str.length;i++)
		{
			if(validstr.indexOf(str.charAt(i))!=-1)
			{	
				flag = true;
			
				break;				
			}
											
		}
		
		if(flag == false)
		{
		alert('Field Should not be Numeric');
		txt.focus();
		txt.select();
		
		}
		
	
	}
		
	function date()
	{
	
			var key=window.event.keyCode;
			//alert(key)
			if(key<47 || key >57)
			window.event.returnValue=false;

			if(key==45 || key==47)
			window.event.returnValue=true;
	}
	function time()
	{
	var key=window.event.keyCode;
	if(key<47 || key>57)
		window.event.returnValue = false;
	if(key==58 || key==32 || key==65 ||key==77 || key==80 || key==97 ||key==109 || key==112)
		window.event.returnValue = true;
	}
	function Description()
	{
			var key= window.event.keyCode;
			if(key<48 || key>122)
			window.event.returnValue=false;

			if(key==58|| key==59|| key==63 || key==64|| key==91 ||key==92||key==93 || key==94||key==95||key==96)
			window.event.returnValue=false;

			if(key==40|| key==41 || key==32 || key==46 ||key==13)
			window.event.returnValue=true;
	}
	function pass()
	{
			var key=window.event.keyCode;
			if(key<48 || key>122)
			window.event.returnValue=false;

			if (key==58 || key==59 || key==60 || key==61 || key==62 || key==63 || key==64)
			window.event.returnValue = false;

			if (key==91 ||key==92||key==93||key==94||key==95||key==96)
			window.event.returnValue=false;

			if(key==13)
			window.event.returnValue=true;
	}
	function Molformula()
	{
			var key=window.event.keyCode;
			if(key<65 || key>122)
			window.event.returnValue=false;

			if (key <48 || key >57 )
			window.event.returnValue = false;

			if (key==91 ||key==92||key==93||key==94||key==95||key==96)
			window.event.returnValue=false;

			if(key==46 || key==32)
			window.event.returnValue=true;

			if(key==40 || key==41 || key==45 || key==95 )
			window.event.returnValue=true;
	}
	function moleWt()
	{
			var key=window.event.keyCode;
			if (key <48 || key >57 )
			window.event.returnValue = false;
			if(key==46)
			window.event.returnValue = true;
	}
	function phoneValidate()
	{
		var key=window.event.keyCode;
		if (key <40 || key >57 )
		window.event.returnValue = false;
		if(key==42 || key==46)
		window.event.returnValue = false;
	}
/*
function CheckAll(checkAllBox, chkname)
{
	//	alert('here');
	var actVar = checkAllBox.checked ;
	var frm = document.forms[0];
	var i=0;

	for(; i<frm.length; i++)
	{
		e = frm.elements[i];
		if ((e.type=='checkbox') && (e.name.indexOf(chkname)!= -1))
		{
			e.checked = actVar;
		}
	}
	// alert(i);
}
*/
function CheckAll(dg, chkall, chkname)
{
	var actvar = chkall.checked;
	var dtg = document.getElementById(dg);
	if(dtg!=null)
	{
		var arr_chk = dtg.getElementsByTagName("input");

		for(var i=0; i<arr_chk.length; i++)
		{
			if(arr_chk[i].type=="checkbox" && arr_chk[i].id.indexOf(chkname)!=-1)
			{
				arr_chk[i].checked = actvar;
			}
		}
	}
}
//This function is to check or uncheck the Main checkbox
function uncheck(chkMain,dtg)
{
	var dg = document.getElementById(dtg);
	var arr = dg.getElementsByTagName("INPUT");
	var ch =null;
	var count=0;

	for(var i=0; i<arr.length; i++)
	{
		if(arr[i].id.indexOf(chkMain)==-1)
		{
			if(arr[i].checked==true)
			{
				count = 1;
			}
			else
			{
				count = 0;
				break;
			}
		}
		else
		{
			ch = arr[i];
		}
	}
	if(count==1)
		ch.checked = true;
	else
		ch.checked = false;
}

function uncheckAll(chk, chkname,chkall)
{
var count =0;
var cl = event.srcElement;
//			alert(cl.id);
var frm = document.forms[0];
var ch = chk.id.substr(0, chk.id.indexOf('ctl'));
ch = ch + 'ctl1_' + chkall;
var chkl = document.getElementById(ch);

var i=0;

for(;i< frm.length; i++)
{
	if(frm.elements[i].type == 'checkbox' && frm.elements[i].id.indexOf(chkname)!=-1)
	{
//		alert(frm.elements[i].id);
		if(frm.elements[i].checked ==false)
		{
			count=1;
			break;
		}
		else
		{
			count=0;
		}
	}
}
if(count ==0)
	chkl.checked = true;
else
	chkl.checked = false;

}



function checkSelected()
{
var count=0;
var frm = document.forms[0];
for(i=0; i<frm.length; i++)
{
//		alert(frm[i].type);
	if(frm[i].type == 'checkbox')
	{
		chk = document.getElementById(frm[i].id);
		if(chk.checked)
		{
			count++;
			break;
		}
	}
}
if(count<=0)
	return false;
else
	return true;
}

function checkMe()
{
	var count=0;
	var frm = document.forms[0];
	for(i=0; i<frm.length; i++)
	{
	//		alert(frm[i].type);
		if(frm[i].type == 'checkbox')
		{
			chk = document.getElementById(frm[i].id);
			if(chk.checked)
			{
				count++;
				break;
			}
		}
	}

	if(count<=0)
	{
//			alert("First Select the Activity to be deleted!");
		return false;
	}
	else
	{
//			return confirm("Activity Parameters will also be deleted! Do you want to Delete?");
		return true;
	//	return;
	}
}



////////
// THIS BLOCK OF CODE IS USED TO REMOVE THE FLICARING EFFECT OF DATAGRID WEB SERVER CONTROL

   ///This function sets the scroll position of div to cookie.
//    function setScrollPos()
//    {
//		alert("alo re");
//        var divY = document.getElementById('div1').scrollTop;
        //document.cookie = "divPos=!*" + divY + "*!";
//    }
   ///Attaching a function on window.onload event.
//    window.onload = function()
////{
//        var strCook = document.cookie;
//        if(strCook.indexOf("!~")!=0)
//        {
//            var intS = strCook.indexOf("!~");
//            var intE = strCook.indexOf("~!");
//            var strPos = strCook.substring(intS+2,intE);
//            document.body.scrollTop = strPos;
//        }
        /// This condition will set scroll position od <div>.
//        if(strCook.indexOf("!*")!=0)
//        {
//            var intdS = strCook.indexOf("!*");
//            var intdE = strCook.indexOf("*!");
//            var strdPos = strCook.substring(intdS+2,intdE);
//            document.getElementById('div1').scrollTop = strdPos;
//        }
//    }
    /// Function to set Scroll position of page before postback.
//    function SetScrollPosition()
//    {
//        var intY = document.body.scrollTop;
//        document.cookie = "yPos=!~" + intY + "~!";
//    }
    /// Attaching   SetScrollPosition() function to window.onscroll event.
//    window.onscroll = SetScrollPosition;


////////

//This function is to Enable-disable textboxes in datagrid when the checkbox corresponding row is checked or unchecked

// THIS BLOCK OF CODE IS USED TO REMOVE THE FLICARING EFFECT OF DATAGRID WEB SERVER CONTROL

   ///This function sets the scroll position of div to cookie.
    function setScrollPos()
    {
		if(document.getElementById("div1") == null) return;
		
        var divY = document.getElementById("div1").scrollTop;
        document.cookie = "divPos=!*" + divY + "*!";
    }
   ///Attaching a function on window.onload event.
    window.onload = function()
    {
		if(document.getElementById("div1") == null) return;
		
        var strCook = document.cookie;
        if(strCook.indexOf("!~")!=0)
        {
            var intS = strCook.indexOf("!~");
            var intE = strCook.indexOf("~!");
            var strPos = strCook.substring(intS+2,intE);
            document.body.scrollTop = strPos;
        }
        /// This condition will set scroll position od <div>.
        if(strCook.indexOf("!*")!=0)
        {
            var intdS = strCook.indexOf("!*");
            var intdE = strCook.indexOf("*!");
            var strdPos = strCook.substring(intdS+2,intdE);
            document.getElementById('div1').scrollTop = strdPos;
        }
    }
    /// Function to set Scroll position of page before postback.
    function SetScrollPosition()
    {
        var intY = document.body.scrollTop;
        document.cookie = "yPos=!~" + intY + "~!";
    }
    /// Attaching   SetScrollPosition() function to window.onscroll event.
    window.onscroll = SetScrollPosition;


////////


function enableGridTextBoxes(dtg)
{
//alert('here');
//alert(dtg.id.substring(0, dtg.id.indexOf('_')));
	var dg = document.getElementById(dtg.id.substring(0, dtg.id.indexOf('_')));
	var arr = dg.getElementsByTagName('input');
	var cl = event.srcElement;
	var id = cl.id;
	var cnt=0;
	cnt = getGridColumnCount(dg);


//alert("no of colums in grid " + cnt);

	for(i=0; i<arr.length ; i++)
	{
		if(arr[i].id == cl.id)
		{
			if(arr[i].checked)
			{
				for(count=1;count<cnt; count++)
				{
					arr[i+count].disabled = false;
				}
				arr[i+1].focus();
				break;
			}
			else
			{
				for(count=1;count<cnt; count++)
				{
					arr[i+count].disabled = true;
				}
			}
		}
	}
}
//This function is written to disable the input boxes in the grid
function disableGridTextBoxes(dtg)
{
//	alert(dg);
	var dg = document.getElementById(dtg);

	var arr = dg.getElementsByTagName('input');
	var cnt=0;
	var str="_ctl";
//	alert(arr.length);

	cnt = getGridColumnCount(dg);

//	alert(cnt);

	for(i=0; i<arr.length; i++)
	{
		if(arr[i].type=='checkbox' && arr[i].checked==false)
		{
		for(count=1;count<cnt; count++)
		{
			arr[i+count].disabled = true;
		}
	//	break;
		}
	}
}
//This function is written to check whether atleast a checkbox is checked or not..
//if checked allow to proceed else stop the user from saving it

function fillDataIfChecked(dtg,column)
{
//alert('i am in fillDataIfChecked');
	var iFoundEmpty =0;
	var chkCount=0;
	var cnt=0;
	var dg = document.getElementById(dtg);
	var arr = dg.getElementsByTagName('input');

	cnt = getGridColumnCount(dg);

//	alert(cnt);
//	alert(column);

	for(i=0; i<arr.length ; i++)
	{
		if(arr[i].type == 'checkbox')
		{
			if(arr[i].checked)
			{
				for(count=1; count<cnt; count++)
				{
					chkCount++;
//					alert(arr[i+count].value);
//					alert(count);
					if(count!=column)
					{
						if(trimAll(arr[i+count].value).length==0 || trimAll(arr[i+count].value)=="")
						{
							arr[i+count].value = trimAll(arr[i+count].value);
							arr[i+count].focus();
							iFoundEmpty=1;
							break;
						}
						else
						{
							arr[i+count].value = trimAll(arr[i+count].value);
						}
					}
				}
//				break;

			}
		}
	}
	if(iFoundEmpty==1)
		return 1;
	else if(chkCount<1)
		return 2;
	else
		return 0;
}

function getGridColumnCount(dtg)
{
//	alert(' i am in getGridColumnCount ' + dtg);
	var dg = document.getElementById(dtg.id);
	var arr = dg.getElementsByTagName('input');
	var cnt=0;
	var str="_ctl";
//	alert(arr.length);
	var iIndex = arr[0].id.indexOf('_ctl') + str.length ;

	str = arr[0].id.substring(iIndex);

	var num = str.substring(0 , str.indexOf('_'));

//	alert(iIndex);

	for(i=0; i<arr.length; i++)
	{
		var str_new = arr[i].id.substring(iIndex);

		var num_new = str_new.substring(0,str_new.indexOf('_'));

//		alert('num= ' + num + "str_new = "+ str_new + "num_new = " + num_new);

		if(num == num_new)
			cnt++;
		else
			break;
	}
	return cnt;
}

//This function to enable or disable the TextArea fields in Grid on the checked or unchecked status of checkbox
//control in grid

function enable_disableGridTextArea(chk, txtarea, dg)
{
//	alert('here');
	var _chk = document.getElementById(chk.id);

	var _iIndex = getIndexNumberFromGrid(_chk);

	var _str = dg + "__ctl" + _iIndex + "_" + txtarea;
//	alert(_str);

		if(_chk.checked)
		{
			document.getElementById(_str).disabled = false;
			document.getElementById(_str).focus();
		}
		else
		{
//			document.getElementById(_str).style.color = 'white';
			document.getElementById(_str).disabled = true;
		}
}
function checkIfTextAreasEmpty(txt, dg)
{
//	alert('here');
	var _dtg = document.getElementById(dg);
	var _arr = _dtg.getElementsByTagName('Input');
	var iCnt =0;
	var bState = false;
	for(;iCnt<_arr.length; iCnt++)
	{
		if(_arr[iCnt].type == 'checkbox')
		{
			var _iIndex = getIndexNumberFromGrid(_arr[iCnt]);
			var _str = dg + "__ctl" + _iIndex + "_" + txt;

//			alert(_iIndex);
//			alert(_str);
//			alert(_arr[iCnt].checked);
//			alert(document.getElementById(_str).value.length);
			if(_arr[iCnt].checked && trimAll(document.getElementById(_str).value).length<=0)
			{
				document.getElementById(_str).value = trimAll(document.getElementById(_str).value);
				document.getElementById(_str).focus();
				bState = true;
				break;
			}
			else if(_arr[iCnt].checked && trimAll(document.getElementById(_str).value).length>0)
			{
				document.getElementById(_str).value = trimAll(document.getElementById(_str).value);
			}
		}
	}
	return bState;
}
//this function is to disable Text Areas on form_load event

function disableTextAreaFields(dtg,txt)
{
	var dg = document.getElementById(dtg);
	var arr_txt = dg.getElementsByTagName("input");
	var iIndex=0;
	var str = 0;
	for(i=0; i<arr_txt.length; i++)
	{
		if(arr_txt[i].type =="checkbox" && arr_txt[i].checked!=true)
		{
			iIndex = getIndexNumberFromGrid(arr_txt[i]);
			str = dtg + "__ctl" + iIndex + "_" + txt;
			document.getElementById(str).disabled = true;
		}

	}
}

function getIndexNumberFromGrid(obj)
{
//alert(obj.id);
	var str="_ctl";
//	alert(arr.length);
	var iIndex = obj.id.indexOf('_ctl') + str.length;

	str = obj.id.substring(iIndex);
	var num = str.substring(0 , str.indexOf('_'));

	return num;
}
//This function is to check if a checkbox in a grid is checked or not
// if none is checked it will return false or return true

function checkIfNoneSelectedFromGrid(dtg)
{
	var dg = document.getElementById(dtg);
	var arr = dg.getElementsByTagName('input');

	var iCount=0;
	var bState = false;
	for(;iCount<arr.length; iCount++)
	{
		if(arr[iCount].type=='checkbox' && arr[iCount].checked)
		{
			bState = true;
			break;
		}
	}
	return bState;
}
function validateForm()
{
	var bState=false;
	var frm = document.forms[0];
	var e = frm.elements;
	var str = "";
//	alert(e.length);
	for(i=0; i<e.length; i++)
	{

//		alert(e[i].type + " AND " +e[i].id);
		if((e[i].type=='text' || e[i].type=='textarea') && (e[i].id.indexOf("_ctl")==-1))
		{
			str = trimAll(e[i].value);
			e[i].value = str;
			if(str.length==0 || str=="" || str==null)
			{
				e[i].focus();
				bState = true;
				break;
			}
		}
	}
	return bState;
}
//This function is to validate quality compliance pages..
function validateQaulityCompliance()
{
	var frm = document.forms[0];
	var e = frm.elements;
	var iCount=0;
	var bState= false;
	var str = "";
	for(;iCount<e.length;iCount++)
	{
		if(e[iCount].type=="text" || e[iCount].type=="textarea")
		{
			str = trimAll(e[iCount].value);
			e[iCount].value = str;
			if(str.length==0 || str.value=="" || str==null)
			{
				e[iCount].focus();
				bState = true;
				break;
			}
		}
	}
	return bState;
}

function validateTime(txt)
{

	var ctl = document.getElementById(txt.id);
//	var strTime = "00:00" + " ";
//	ctl.value = strTime;

	var val = ctl.value.charAt(0);

	if(val>2)
	{
		val = "0";
		ctl.value = val + ctl.value.substring(ctl.value.charAt(0)+1, ctl.value.length);
	}
	else if(ctl.value.substring(0, ctl.value.indexOf(":"))>24)
	{
		alert("Invalid Hours");
		ctl.focus();
		ctl.select();
		return false;
	}
	else if(ctl.value.substring(ctl.value.indexOf(":")+1 , ctl.value.indexOf(" "))>59)
	{
		alert("Invalid Minutes");
		ctl.focus();
		ctl.select();
		return false;
	}
/*	else if(ctl.value.substring(ctl.value.indexOf(" ")+1,ctl.value.length)!="AM" || ctl.value.substr(ctl.value.indexOf(" ")+1,ctl.value.length)!="PM")
	{
		alert("AM/PM Not Specified");
		ctl.focus();
		ctl.select();
		return false;
	} */
}

function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}

	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}

	return sString;
}
function getID()
{
	var ctl = event.srcElement;
//	alert(ctl.id);
}


function TimeValidate(txt)
{

	var src =  document.getElementById(txt.id);

//	alert("i am here");
	// Checks if time is in HH:MM:SS AM/PM format.
	// The seconds and AM/PM are optional.

	var str = src.value;
	str = trimAll(str);
	if(str.length > 0)
	{
		var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|Am|aM|PM|pm|Pm|pM))?$/;

		var matchArray = str.match(timePat);
		if (matchArray == null)
		{
			alert("Time must be in HH:MM:SS AM/PM format");
//			document.getElementById(src.id).value = "";
			document.getElementById(src.id).select();
			document.getElementById(src.id).focus();
			return false;
		}
		var hour = matchArray[1];
		var minute = matchArray[2];
		var second = matchArray[4];
		var ampm = matchArray[6];

		if (second=="") { second = null; }
		if (ampm=="") { ampm = null; }
		if (hour < 0  || hour > 12)
		{
			alert("Hour must be between 1 and 12 ");
			document.getElementById(src.id).select();
			document.getElementById(src.id).focus();
			return false;
		}

		if (hour <= 12 && ampm == null)
		{
			//if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
			alert("You must specify AM or PM.");
			document.getElementById(src.id).select();
			document.getElementById(src.id).focus();
			return false;
		}

		if (minute < 0 || minute > 59)
		{
			alert ("Minute must be between 0 and 59.");
			document.getElementById(src.id).select();
			document.getElementById(src.id).focus();
			return false;
		}

		if (second != null && (second < 0 || second > 59))
		{
			alert ("Second must be between 0 and 59.");
			document.getElementById(src.id).select();
			document.getElementById(src.id).focus();
			return false;
		}
		src.value = trimAll(str.toUpperCase());
	}
}

function TimeValidate24hours(txt)
{

//alert(txt.id);
var src =  document.getElementById(txt.id);
var str = src.value;
str = trimAll(str);

if(str.length > 0)
{
var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?$/;

var matchArray = str.match(timePat);
if (matchArray == null) {
alert("Time is not in a valid format.");
document.getElementById(src.id).select();
document.getElementById(src.id).focus();
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
alert("Hour must be between 0 and 23");
document.getElementById(src.id).select();
document.getElementById(src.id).focus();
return false;
}

if (minute < 0 || minute > 59) {
alert ("Minute must be between 0 and 59.");
document.getElementById(src.id).select();
document.getElementById(src.id).focus();
return false;
}
if (second != null && (second < 0 || second > 59)) {
alert ("Second must be between 0 and 59.");
document.getElementById(src.id).select();
document.getElementById(src.id).focus();
return false;
}
return false;

}
}

	
	



function chkKeyPress()
{
//alert('Yogesh');
	var src = event.srcElement;
	var lnth = document.getElementById(src.id).value.length;
	//alert("length="+length);
	var key = window.event.keyCode;


	//document.getElementById('TextBox1').setFocus();
	//document.getElementById('TextBox1').value = "  :  :";

	if(lnth < 11)
	{
		switch(lnth)
		{
			case 0:
					if (key >=48 && key <=57 )
						window.event.returnValue = true;
					else
					{
						window.event.returnValue = false;
						return;
					}

			case 1:
					if (key >=48 && key <=57 )
						window.event.returnValue = true;
					else
					{
					//if(key)
						var k = document.getElementById(src.id).value;
						if(key == 58)
						{
							document.getElementById(src.id).value = "0"+k;
						}
						else
						{
							window.event.returnValue = false;
							return;
						}
					}
					//alert("i am here");
					break;
			case 2:
					var k = document.getElementById(src.id).value;
					if(k > 12)
					{
					//k=0;
						document.getElementById(src.id).value = "";
						//document.getElementById(src.id).value = k;
						//alert("Please Enter valid Hours");
						window.event.returnValue = false;
					}
					else
					{
					//alert("i am here ");
						document.getElementById(src.id).value +=":";
						if (key >=48 && key <=57 )
							window.event.returnValue = true;
						else
							window.event.returnValue = false;
					}
					//document.getElementById(src.id).value = k;
					break;
			case 3:
			case 4:
					//alert("i am in case 3 and 4");
					//alert("I AM IN CASE 4");
						if (key >=48 && key <=57 )
							window.event.returnValue = true;
						else
							{
							//if(key)
								var k = document.getElementById(src.id).value;
								if(key == 58)
								{
									document.getElementById(src.id).value = k.replace(k,k.substring(0,3)+"0"+k.substring(3,4));
									window.event.returnValue = true;
								}
								else if(key == 65 )
								{
									document.getElementById(event.srcElement.id).value = k.substring(0,3)+"0"+k.substring(3,4)+":00 "+String.fromCharCode(65)+String.fromCharCode(77);
									window.event.returnValue = false;
								}
								else if(key == 97)
								{
									document.getElementById(event.srcElement.id).value = k.substring(0,3)+"0"+k.substring(3,4)+":00 "+String.fromCharCode(97) + String.fromCharCode(109);
									window.event.returnValue = false;
								}
								else if(key == 80 )
								{
									document.getElementById(event.srcElement.id).value = k.substring(0,3)+"0"+k.substring(3,4)+":00 "+String.fromCharCode(80) + String.fromCharCode(77);
									window.event.returnValue = false;
								}
								else if(key == 112)
								{
									document.getElementById(event.srcElement.id).value = k.substring(0,3)+"0"+k.substring(3,4)+":00 "+String.fromCharCode(112) + String.fromCharCode(109);
									window.event.returnValue = false;
								}
								else
								{
									window.event.returnValue = false;
									return false;
								}

							}
							break;

			case 5:
					var k = document.getElementById(src.id).value.substring(3,5);

					if(k > 59)
					{
						//k=0;
						var j = document.getElementById(src.id).value;
						document.getElementById(src.id).value = "";
						/*if (document.selection)
						{
						document.getElementById(src.id).focus();
						sel = document.selection.createRange();
						sel.text = j.substring(0,3);
						document.getElementById(src.id).value = j.replace(j,j.substring(0,3));
						//document.getElementById(src.id).value.substring(3,5).selText();
						//document.getElementById(src.id).value = k;
						//alert("Please Enter Valid Minutes");*/
						window.event.returnValue = false;
					}
					else
					{
						//alert(" i am in else");
						if (key == 58 )
							window.event.returnValue = true;
						else if(key == 32)
							window.event.returnValue = true;
						else if(key == 65 || key == 97 || key == 80 || key == 112)
						{
							if(key == 65 )
								document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(65) + String.fromCharCode(77);
							else if(key == 97)
								document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(97) + String.fromCharCode(109);

							if(key == 80 )
								document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(80) + String.fromCharCode(77);
							else if(key == 112)
								document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(112) + String.fromCharCode(109);

							window.event.returnValue = false;
						}
						else
						{
							if(key >=48 && key <=57 )
							{
								document.getElementById(src.id).value += ":";
								window.event.returnValue = true;
							}
							else
							{
								window.event.returnValue = false;
							}

						}
					}
					break;

			case 6:
					if(key == 65 || key == 97 || key == 80 || key == 112)
					{
						var j =document.getElementById(event.srcElement.id).value;
						document.getElementById(event.srcElement.id).value = j.replace(j,j.substring(0,5));
						if(key == 65 )
							document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(65) + String.fromCharCode(77);
						else if(key == 97)
							document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(97) + String.fromCharCode(109);

						if(key == 80 )
							document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(80) + String.fromCharCode(77);
						else if(key == 112)
							document.getElementById(event.srcElement.id).value += ":00 "+String.fromCharCode(112) + String.fromCharCode(109);

						window.event.returnValue = false;
					}
					else if(key >=48 && key <=57 )
					{
						window.event.returnValue = true;
					}
					else
					{
						window.event.returnValue = false;
					}
					break;

			case 7:
					if(key == 65 || key == 97 || key == 80 || key == 112)
					{
						var j =document.getElementById(event.srcElement.id).value;
						//alert("j="+j);
						document.getElementById(event.srcElement.id).value = "";
						document.getElementById(event.srcElement.id).value = j.substring(0,6);
						//alert(document.getElementById(event.srcElement.id).value);
						if(key == 65 )
							document.getElementById(event.srcElement.id).value += "0"+j.substring(6,7)+" "+String.fromCharCode(65) + String.fromCharCode(77);
						else if(key == 97)
							document.getElementById(event.srcElement.id).value += "0"+j.substring(6,7)+" "+String.fromCharCode(97) + String.fromCharCode(109);
						else if(key == 80 )
							document.getElementById(event.srcElement.id).value += "0"+j.substring(6,7)+" "+String.fromCharCode(80) + String.fromCharCode(77);
						else if(key == 112)
							document.getElementById(event.srcElement.id).value += "0"+j.substring(6,7)+" "+String.fromCharCode(112) + String.fromCharCode(109);
						//alert(document.getElementById(event.srcElement.id).value);
							window.event.returnValue = false;
							return;
					}
					else if(key >=48 && key <=57 )
					{
						window.event.returnValue = true;
						return;
					}
					else
					{
						window.event.returnValue = false;
					}
					break;

			case 8:
					var k = document.getElementById(src.id).value.substring(6,8);
					if(k > 59)
					{
						document.getElementById(src.id).value = document.getElementById(src.id).value.substring(0,6);
						//alert("Please Enter Valid Seconds");
						window.event.returnValue = false;
						return;
					}
					else
					{
						if(key == 32)
						{
							window.event.returnValue = true;
							return;
						}
						else
						{
							//if(key == 65 || key == 97)
							document.getElementById(event.srcElement.id).value += " ";//+String.fromCharCode(key);
							window.event.returnValue = false;
						}
					}
					break;
			case 9:
					//alert(String.fromCharCode(key));
					if(key == 65 || key == 97 || key == 80 || key == 112)
					{
						if(key == 65 )
							document.getElementById(event.srcElement.id).value += String.fromCharCode(65) + String.fromCharCode(77);
						else if(key == 97)
							document.getElementById(event.srcElement.id).value += String.fromCharCode(97) + String.fromCharCode(109);

						if(key == 80 )
							document.getElementById(event.srcElement.id).value += String.fromCharCode(80) + String.fromCharCode(77);
						else if(key == 112)
							document.getElementById(event.srcElement.id).value += String.fromCharCode(112) + String.fromCharCode(109);

						window.event.returnValue = false;
					}
					else
						window.event.returnValue = false;
					break;

			case 10:
					if(key == 77 || key == 109)
						window.event.returnValue = true;
						//document.getElementById(event.srcElement.id).value += String.fromCharCode(key);
					else
						window.event.returnValue = false;
					break;
		}

	}
	else
	{
		window.event.returnValue = false;
	}
}
//To disable ExperimentUnitProcessActivities grid...
function DisableMyGrid(dtg)
{
	var dg = document.getElementById(dtg);
	var arrInput = dg.getElementsByTagName('Input');
	var arrTArea = dg.getElementsByTagName('textarea');

	for(var i=0; i<arrInput.length; i++)
	{
		if(arrInput[i].type=='text')
		{
			arrInput[i].disabled = true;
		}
	}
	for(var i=0; i<arrTArea.length ; i++)
	{
		arrTArea[i].disabled = true;
	}
}
function EnableMyGridTextBoxes(dtg, ch)
{
	var chk = document.getElementById(ch.id);
	var dg = document.getElementById(dtg);
	var arrInput = dg.getElementsByTagName('Input');
	var arrTArea = dg.getElementsByTagName('textarea');

	var num = getIndexNumberFromGrid(chk);

	if(chk.checked)
	{
		for(var i=0; i<arrInput.length; i++)
		{
			if(arrInput[i].type=='text' && arrInput[i].id.indexOf(num)!=-1)
			{
				arrInput[i].disabled = false;
//				arrInput[i].style.color = "red";
			}
		}
	}
	else
	{
		for(var i=0; i<arrInput.length; i++)
		{
			if(arrInput[i].type=='text' && arrInput[i].id.indexOf(num)!=-1)
			{
				arrInput[i].disabled = true;
//				arrInput[i].style.color = "red";
			}
		}
	}

	if(chk.checked)
	{
		for(var i=0; i<arrTArea.length; i++)
		{
			if(arrTArea[i].id.indexOf(num)!=-1)
			{
//				arrTArea[i].style.color = "red";
				arrTArea[i].disabled = false;
			}
		}
	}
	else
	{
		for(var i=0; i<arrTArea.length; i++)
		{
			if(arrTArea[i].id.indexOf(num)!=-1)
			{
				arrTArea[i].disabled = true;
//				arrTArea[i].style.color = "red";
			}
		}
	}
}

//These functions have been written by sameer k for ToDoList

//*********************ALL FOR TO DO LIST*************************
function checkDate(txt)
{
	var dt = document.getElementById(txt.id);
	if(dt.value.length>0)
	{
		var _month = dt.value.substr(3,2);
		var _day = dt.value.substr(0,2);
		var _yr = dt.value.substr(6, 10);

		var new_date =  _month + "/" + _day + "/" +_yr;
		var _date = document.getElementById('hdnDate').value;

		new_date = Date.parse(new_date);
		_date = Date.parse(_date);

		if(_date >new_date)
		{
			alert("Date can not be prior to Current Date");
			dt.select();
			dt.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
}
function checkTime(source, args)
{
	var blnValid = true;
	var dt = document.getElementById("TxtActDate");
	var tm = document.getElementById("TxtActTime");
	if(dt.value.length>0 && tm.value.length>0)
	{
		var _month = dt.value.substr(3,2);
		var _day = dt.value.substr(0,2);
		var _yr = dt.value.substr(6, 10);

		var new_date = _month + "/" + _day + "/" +_yr + " " + tm.value;
		var _date = document.getElementById('hdntime').value;

		new_date = Date.parse(new_date);
		_date = Date.parse(_date);

		if(_date >new_date)
		{
			tm.select();
			tm.focus();
			blnValid = false;
		}

	}
	args.IsValid = blnValid;
	return args.IsValid;
}
function getIDs(str)
{
	var dg = document.getElementById('dgToDo');
	var arr = dg.getElementsByTagName('INPUT');
	var ID="";
	for(var i=0; i<arr.length; i++)
	{
		if(arr[i].type=="text" && arr[i].id.indexOf(str)!=-1)
		{
			ID = arr[i].id;
			break;
		}
	}
	return ID;
}
function checkTimeInGrid(source, args)
{
	var blnValid = true;
//	alert(getIDs("txtDate"));
//	alert(getIDs("txtTime"));
	var dt = document.getElementById(getIDs("txtDate"));
	var tm = document.getElementById(getIDs("txtTime"));
	if(dt.value.length>0 && tm.value.length>0)
	{
		var _month = dt.value.substr(3,2);
		var _day = dt.value.substr(0,2);
		var _yr = dt.value.substr(6, 10);

		var new_date = _month + "/" + _day + "/" +_yr + " " + tm.value;
		var _date = document.getElementById('hdntime').value;

		new_date = Date.parse(new_date);
		_date = Date.parse(_date);

		if(_date >new_date)
		{
			tm.select();
			tm.focus();
			blnValid = false;
		}

	}
	args.IsValid = blnValid;
	return args.IsValid;
}
//************************END ALL FUNCTIONS FOR TO DO LIST*************************************

//*************************THIS FUNCTION IS TO CHECK DATE FROM SEARCH MODULE****************
//This function converts the UK Date into US date format..
function convertToUSDate(date)
{
	var strdt = new Date();
//	var enddt = new Date();

	var	_strdt = date;
	var index = _strdt.indexOf('/');
	var _day = _strdt.substring(0,index);
	var _strdt = _strdt.substring(index+1, _strdt.length);
	var _month = _strdt.substring(0,_strdt.indexOf('/'));
	var _year = _strdt.substring(_strdt.indexOf('/')+1);

	_strdt = _month + "/" + _day + "/" + _year;

	strdt = Date.parse(_strdt);
	return strdt;
}
//This function compares the from and to date from Search Page.
function checkSearchDate(txtFrom, txtTo)
{
	var txt_from = document.getElementById(txtFrom);
	var txt_to = document.getElementById(txtTo);

	if(txt_from!=null && txt_to!=null)
	{
		if(trimAll(txt_from.value).length>0 && trimAll(txt_to.value).length>0)
		{
			var date_from = convertToUSDate(trimAll(txt_from.value));
			var date_to = convertToUSDate(trimAll(txt_to.value));

			if(date_from > date_to)
			{
				alert("From Date field can not be prior to To Date field!");
				txt_from.select();
				txt_from.focus();
			}
		}
	}
}
//*************************END OF FUNCTIONS TO CHECK DATE FROM SEARCH MODULE****************

//This function displays and hides the dropdown lists on the click of the button.
function showDDL(ddl)
{
	var drp_down = document.getElementById(ddl);
	if(drp_down!=null)
	{
		if(drp_down.style.display=="inline")
		{
			drp_down.style.display = "none";
			drp_down.options[0].selected = true;
		}
		else
			drp_down.style.display = "inline";
	}
	return false;
}
//End of function showDDL(ddl)
//*******************This function is to check whether the Molecular weight range should be correct ***********
function checkMolWt(txt_chkTo, txt_chkwith)
{
	var txt_to = document.getElementById(txt_chkTo);

	if(txt_to!=null && trimAll(txt_to.value).length>0)
	{
		if(trimAll(txt_to.value).length >0 && (!isNaN (parseFloat(trimAll(txt_to.value)))))
		{
			var txt_with = document.getElementById(txt_chkwith);

			if(txt_with!=null && trimAll(txt_with.value).length>0)
			{
				if(trimAll(txt_with.value).length > 0 && (!isNaN(parseFloat(trimAll(txt_with.value)))))
				{
					if(txt_to.value < txt_with.value)
					{
						alert("From Value can not be greater than To value");
						txt_to.select();
						txt_to.focus();
					}
				}
				else
				{
					txt_with.select();
				}
			}
		}
		else
		{
			txt_to.select();
		}
	}
}
//*************** End of function checkMolWt(txt_chkTo, txt_chkwith)******************


//*****This function Hides Radio Button List and CheckBox List at page load**********
function hideRadios_dropdowns()
{
	var count =0;
	if(count<1)
	{
		var rdo = document.getElementsByTagName("INPUT");
		var rdo_lst_name = "";
		for(var i=0; i<rdo.length; i++)
		{
			if(rdo[i].type=="radio")
			{
				if(rdo_lst_name!=rdo[i].name)
				{
					rdo_lst_name = rdo[i].name;
					document.getElementById(rdo_lst_name).style.display = "none";
				}

			}
		}
		var ddl = document.getElementsByTagName("select");

		if(ddl!=null)
		{
			for (var i=0;i< ddl.length; i++)
			{
				if(ddl[i].id.indexOf('1')!=-1)
				{
					ddl[i].style.display = "none";
				}
			}
		}
		count=1;
	}
}

     function validateDropDown()
    {
alert('hi');
        var arr_ddl = document.getElementsByTagName("SELECT");
        var flg = false;
        for(var i=0; i<arr_ddl.length; i++) 
        {
            if(arr_ddl[i].options[arr_ddl[i].selectedIndex].value ==-1)
            {
        //		alert("Select " + arr_ddl[i].id.substring(3,arr_ddl[i].id.length));
	            var val = arr_ddl[i].options[0].text;
	            alert(val);
	            arr_ddl[i].focus();
	            flg = true;
	            break;
            }
        }
        return flg;
    }
    
//**********End of function hideRadios_dropdowns()***********

//**********This function Enables and disables Radio button List **************
function EnableDisableRadios(txt,tx, rdo)
{
	var rd = document.getElementById(rdo);
	var rd_lst = rd.getElementsByTagName("Input");
	var new_txt = document.getElementById(tx);
	if(new_txt==null)
	{
		if(trimAll(txt.value).length>0 && trimAll(txt.value)!='')
		{
			rd.style.display ="inline";
			rd_lst[0].checked = true;
		}
		else
		{
			rd.style.display ="none";
			for(var i=0;i<rd_lst; i++)
			{
				rd_lst[i].checked = false;
			}
		}
	}
	else
	{
		if(trimAll(txt.value).length>0 && trimAll(txt.value)!='' && trimAll(new_txt.value).length >0 && trimAll(new_txt.value)!='')
		{
			rd.style.display ="inline";
			rd_lst[0].checked = true;
		}
		else
		{
			rd.style.display ="none";
			for(var i=0;i<rd_lst; i++)
			{
				rd_lst[i].checked = false;
			}
		}

	}
}
//********End of function EnableDisableRadios(txt,tx, rdo)*************

			// this function can use to check wheater the txtbox value is greater then 0 or not it should be used from obblur
			function chkgreaterThenZero(txtControl)
			{
				var flag = true;
				var no = document.getElementById(txtControl.id).value;
				if(parseInt(no) <= 0)
				{
				flag = false;

				}
				if(flag == false)
				{
				alert("The Value should Be Greater Then Zero");
				txtControl.focus();
				}

			}

		
		function chkTimeWhileOnkeyPress()
		{
			var key = window.event.keyCode;
			
			//alert(key);
			if(key < 48 || key > 57 )
			{
				//alert(key+"in 1st");
				window.event.returnValue = false;
						
			}
			
			if(key == 58 )
			{
				//alert(key+"in 2nd");
				window.event.returnValue = true;
				
			}
			
			
			
		}
		
		
		function AllowDecimal(txt)
		{
			var key = window.event.keyCode;
			
			if(key < 48 || key > 57 )
			{
				//alert(key+"in 1st");
				window.event.returnValue = false;
						
			}
			
			if(key == 46)
			{
				var str = trimAll(document.getElementById(txt.id).value);
				
				if(str.indexOf('.') == -1)				
				{
					window.event.returnValue = true;
					
				}
				else
				{
					window.event.returnValue = false;
				
				}
				
			}
					
		}
		
		
		function chkLandLineFormat(txt)
		{
				 
				 
				if( txt.value=="")
				{
				return true;
				}
				
				if(txt.value.indexOf("-")==3)
				{
					return true;
				}
				else
				{
				//alert("Enter Valid LandLine Number.");
				txt.focus();
				txt.select();
				return false;
				}
		}
		
				function funcheckPercentageNumber(txt1)
		{			
			var intDecimalIndex=txt1.value.indexOf('.');			
			var intDecimalLength=txt1.value.length;
			
			
			 
			//alert(intDecimalLength);	
			if(txt1.value=="")
			{
			return;
			}
		if( intDecimalIndex >2)
		{
			alert("Percentage should be less than 100")
			txt1.focus();
			txt1.select();
			return;
		}
			if( intDecimalIndex >=0 && intDecimalIndex <=2)
				{
					if(intDecimalIndex==0 )
						{
							if(intDecimalLength==1 )
							{
							txt1.value="0"
							}
							else if(intDecimalLength>3 )
							{
							alert("Percentage should be less than 100")
							txt1.focus();
							txt1.select();
							}
							else
							{				 
							txt1.value="0"+txt1.value;
							}
						}
						else if(intDecimalIndex==1)
						{
							if(intDecimalLength==2 )
								{
									txt1.value=txt1.value+"0";
									return;
								}
							else if(intDecimalLength>4 )
								{
									alert("Percentage should be less than 100")
									txt1.focus();
									txt1.select();
								}				
						}		
						else if(intDecimalIndex==2)
						{
							if(intDecimalLength==3 )
								{
									txt1.value=txt1.value+"0";
									return;
								}
							else if(intDecimalLength>5 )
								{
									alert("Percentage should be less than 100")
									txt1.focus();
									txt1.select();
							}				
						}				
				}
			else
				{
					if(intDecimalLength>2)
						{
						alert("Percentage should be less than 100")
						txt1.focus();
						txt1.select();
						}
				}
			
		}
		  function funPinNumericPercentageNumber()
    {
			var key = window.event.keyCode;
			if (key <46 || key >57 || key==47)
				//alert(key)
			window.event.returnValue = false;
	}
	
	
	
	
	function validateOnlyNumber_NoDecimal(txt)
    {
   
		var ctrl = document.getElementById(txt.id);
		var digits = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/~`!@#$^&*()<>:;'{}|=+-_.,[]\" ";
		var fState= false;

		var str_check = trimAll(ctrl.value);
		for(var i=0; i<str_check.length; i++)
		{
			if(digits.indexOf(str_check.charAt(i))!=-1)
			{
				fState = true; 
				break;
			}
		}
		if(fState)
		{
			alert("Entere Valid Number.");
			ctrl.focus();
			ctrl.select();
			return false;
		}
    }
    
     function changeCheckState(checked)
    {
        var frm = document.forms[0];
        for (i=0; i<frm.length; i++) 
        {
            if (frm.elements[i].id.indexOf('CheckMail') != -1)
            {
                frm.elements[i].checked = checked;
            }
        }
    }
    
    
    	
    
      function checkAlphaNumNoSpChar(str_check)
    {
	   var alphaCheck = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ/123456789-_.";
	   var bState = false;

		for(var i=0; i<str_check.length; i++)
		{
			if(alphaCheck.indexOf(str_check.charAt(i))>=1)
			{
				bState = true;
				break;
			}
		}
		return bState;
    }		
