// history.forward();
// call this function to ignore any event in the parent 
// window when the child window is open.
// 
function childWindowExists(e){
	//e.
}
// call this function on body key press event to close the window on pressing esc key.
function escKeyCloseWindow(e){
	if(e.keyCode == 27)
		window.close();
}
// Function to validate maxlength of textarea
function validateLength(controlName, maxLength)
{
	var myValue=controlName.value;
	if(myValue.length > maxLength)
	{
	
		return false;
	}
	return true;
}

function writeStatusBarMessage()
{
    window.status = statusMessage;
    return true;
}

function hideStatusBarMessage()
{
    window.status = '';
    return true;
}


sortitems = 1;  // Automatically sort items within lists? (1 or 0)

function moveAll(fbox, tbox) 
{
	for(var i=0; i<fbox.options.length; i++) 
	{
		if(fbox.options[i].value != "0") 
		{
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		}
	}
	BumpUp(fbox);
	if (sortitems) SortD(tbox);
}

function move(fbox, tbox) 
{
	for(var i=0; i<fbox.options.length; i++) 
	{
		if(fbox.options[i].selected && fbox.options[i].value != "0") 
		{
			var no = new Option();
			no.value = fbox.options[i].value;
			no.text = fbox.options[i].text;
			tbox.options[tbox.options.length] = no;
			fbox.options[i].value = "";
			fbox.options[i].text = "";
		}
	}
	BumpUp(fbox);
	if (sortitems) SortD(tbox);
}

function BumpUp(box)  
{
	for(var i=0; i<box.options.length; i++) 
	{
		if(box.options[i].value == "")  
		{
			for(var j=i; j<box.options.length-1; j++)  
			{
				box.options[j].selected = false;
				box.options[j].value = box.options[j+1].value;
				box.options[j].text = box.options[j+1].text;
			}
			var ln = i;
			break;
		}
	}
	if(ln < box.options.length)  
	{
		box.options.length -= 1;
		BumpUp(box);
	}
}

function SortD(box)  
{
	var temp_opts = new Array();
	var temp = new Object();
	for(var i=0; i<box.options.length; i++)  
	{
		temp_opts[i] = box.options[i];
	}
	for(var x=0; x<temp_opts.length-1; x++)  
	{
		for(var y=(x+1); y<temp_opts.length; y++)  
		{
			if(temp_opts[x].text > temp_opts[y].text)  
			{
				temp = temp_opts[x].text;
				temp_opts[x].text = temp_opts[y].text;
				temp_opts[y].text = temp;
			}
		}
	}

	for(var i=0; i<box.options.length; i++)  
	{
		box.options[i].value = temp_opts[i].value;
		box.options[i].text = temp_opts[i].text;
	}
}

/*
0 if the dates are same 
-1 if the first one is an earlier date 
1 if the first one is a later date 
*/
function compareDates (value1, value2) {
   var date1, date2;
   var month1, month2;
   var year1, year2;
   var dateseperator = "/";
   
   date1 = convertToInt(value1.substring (0, value1.indexOf (dateseperator)));
   month1 = convertToInt(value1.substring (value1.indexOf (dateseperator)+1, value1.lastIndexOf (dateseperator)));
   year1 = convertToInt(value1.substring (value1.lastIndexOf (dateseperator)+1, value1.length));

   date2 = convertToInt(value2.substring (0, value2.indexOf (dateseperator)));
   month2 = convertToInt(value2.substring (value2.indexOf (dateseperator)+1, value2.lastIndexOf (dateseperator)));
   year2 = convertToInt(value2.substring (value2.lastIndexOf (dateseperator)+1, value2.length));

   if (year1 > year2) return 1;
   else if (year1 < year2) return -1;
   else if (month1 > month2) return 1;
   else if (month1 < month2) return -1;
   else if (date1 > date2) return 1;
   else if (date1 < date2) return -1;
   else return 0;
} 

function getCurrentDate(){
	var date=new Date();
	var sDate;
	sDate = date.getDate() + "/" + (date.getMonth()+1) + "/" + date.getFullYear(); 		
	return sDate;
}

function ValidateRequiredFieldTextBox(txt, alertMessage, trimValueBeforeValidating){
	if( (txt == null) || (txt == 'undefined') ){
		alert("Undefined text control!");
		return true;
	}
	var val = txt.value;
	if(trimValueBeforeValidating){
		var val = TrimString(val);
		txt.value = val;
	}
	if(val == ""){
		alert(alertMessage);
		txt.focus();
		return false;
	}
	return true;
}

function ValidateIntegerFieldTextBox(txt, minValue, maxValue, emptyFieldMessage, invalidValueMessage, trimValueBeforeValidating){
	if( (txt == null) || (txt == 'undefined') ){
		alert("Undefined text control!");
		return true;
	}
	
	minValue = parseInt(minValue)
	maxValue = parseInt(maxValue)
	
	var val = txt.value;
	if(trimValueBeforeValidating){
		var val = TrimString(val);
		txt.value = val;
	}
	if(val == ""){
		alert(emptyFieldMessage);
		txt.focus();
		return false;
	}
	if(isNaN(val)){
		alert(invalidValueMessage);
		txt.focus();
		return false;
	}
	
	if(val < minValue){
		alert("Value should be at least " + minValue + "!");
		txt.focus();
		return false;
	}
	if(val > maxValue){
		alert("Value should be less than " + maxValue + "!");
		txt.focus();
		return false;
	}
	return true;
}

function ValidateDecimalFieldTextBox(txt, minValue, maxValue, emptyFieldMessage, invalidValueMessage, minValueMessage, maxValueMessage, trimValueBeforeValidating){
	if( (txt == null) || (txt == 'undefined') ){
		alert("Undefined text control!");
		return true;
	}
	
	var val = txt.value;
	if(trimValueBeforeValidating){
		var val = TrimString(val);
		txt.value = val;
	}
	if(val == ""){
		alert(emptyFieldMessage);
		txt.focus();
		return false;
	}
	if(!IsDecimal(val)){
		alert(invalidValueMessage);
		txt.focus();
		return false;
	}

	minvalue = parseFloat( minValue )
	maxValue = parseFloat( maxValue )
		
	if(val < minValue){
		alert(minValueMessage);
		txt.focus();
		return false;
	}
	
	if(val > maxValue){
		alert(maxValueMessage);
		txt.focus();
		return false;
	}
	return true;
}

function setFocus(ctl)
{
	if( (ctl != null) && (ctl != 'undefined') ){
		ctl.focus();
	}
	return true;
}


/*String Trim Function*/
function TrimString(str)
{
	var len,x,y;
	var ltrimstr,newstr;
	var flag1 = false
	var flag2 = false
	ltrimstr = "";
	len = str.length;
	for(x=0;x<len;x++){
		if ((str.substr(x,1)!=" ") || (flag1)){
			flag1 = true;
			ltrimstr = ltrimstr + str.substr(x,1);
		}
	}
	newstr = ltrimstr
	for(y=ltrimstr.length-1;y>0;y--){
		if ((ltrimstr.substr(y,1)==" ") && (flag2==false)){				
			newstr = ltrimstr.substr(0,y)
		}
		else
		{
			flag2 =true;
		}
	}

	return newstr;

}

/*This method and variable are used to identify if the user 
has updated any field in the datagrid so that he can be told 
to update the datagrid values so that correct values are sent
into database */
var isDataChanged = false;
function dataChanged(){
	isDataChanged = true;
}

/*
Need to include following line of html code in the parent page
<PUBLIC:ATTACH EVENT="ondetach" ONEVENT="cleanup()"></PUBLIC:ATTACH>
*/
/*Pops up new window*/
var OpenWin;
function WindowPopUp(page, windowname, dimension, coord) {
	OpenWin = this.open(page, windowname, "status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resize=yes," + dimension + ", " + coord);
	if ((document.window != null) && (!OpenWin.opener))
		OpenWin.opener = document.window;
	OpenWin.focus();
	OpenWin.opener.name="pop"
	document.body.attachEvent("onkeydown", showChildWindow);
	document.body.attachEvent("onmouseup", showChildWindow);
	OpenWin.attachEvent("onunload", hideChildWindow);
}

// On close of child window detach the onkeydown and onmouseup events.
function hideChildWindow(){
	document.body.detachEvent("onkeydown", showChildWindow);
	document.body.detachEvent("onmouseup", showChildWindow)
}

// if the child window is open, then dont let the user work in 
// child window.
function showChildWindow(){
	OpenWin.focus();
	event.returnValue = false;
}

function WindowShowDialog(page, dimension, coord) {
	var returnValue;
	returnValue = this.showModalDialog(page, "", "toolbar=no,menubar=no,location=no,scrollbars=yes,resize=yes," + dimension + ", " + coord);
}

function closeWin() {
	if(OpenWin != null){
		OpenWin.close();
    }
}

// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}

function IsDecimal(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;
 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
      {
         IsNumber = false;
      }
   }
   return IsNumber;
}

/*
returns 0 if both are equal
returns -1 if d1 is less than d2
returns 1 if d2 is less than d1
*/
function compareDecimals(d1, d2)
{	
	
	var d1 = parseFloat(d1);
	var d2 = parseFloat(d2);
	if (d1 < d2){
		return -1;
	}
	else if (d2 < d1){
		return 1;
	}
	else{
		return 0;
	}
}

// this function converts string to integer
// reason for this besides having parseInt because
// parseInt("08") = 0, which is wrong.
function convertToInt(val){
	var len = val.length;
	var valcopy = val;
	for (var i=0; i < len - 1; i++){
		if(valcopy.substring(i, i + 1) == "0"){
			val = valcopy.substring(i + 1, len);
		}else{
			break;
		}
	}
	return parseInt(val);
}


/*______________Added by suni________________*/

//to validate invalid characters in name
function SpecialCharecter(a)
{
	var ab=a;
	for(x=0;x<ab.length;x++)
	{	
		a=ab.charAt(x);
		if((a=="!") || (a=="@") || (a=="#") || (a=="$") || (a=="%") || (a=="^") || (a=="&") || (a=="*") || (a=="("))
		{
			return true;
		}
		else if ((a==":") || (a==";") || (a=='"') || (a=="'") || (a=="<") || (a==",") || (a==">") || (a=="?") || (a=="/")||(a=="`"))
		{
			return true;
		}
		else if((a==="{") || (a==="}") || (a==")") || (a=="_") || (a==".") || (a==="=") || (a=="|") || (a=='[')|| (a=='~')||(a==']'))
		{
			return true;
		}
		
	}
	
return false;
}

function spacecheck(a)
{
	var ab=a;
	for(x=0;x<ab.length;x++)
	{	
		a=ab.charAt(x);
		if(a==" ")
		{
			return true;
		}
	}
}
/*_____________End of code by suni________________*/

 
function isValidMail(val)
{
   s=val.substr(0,1);
   var ss,cnt1,cnt2;
   var r,re,cnt1,cnt2,r1,r2,re1,re2,re3;
   re=/@+\./;
  
   r=val.match(re);
   
   cnt1=cnt2=0;
   // is it containing @ and .,is @ or . is entered as the first character//
   if(r!=null || s=="@" || s=="." || val.indexOf('@',0)==-1 || val.indexOf('.',0)==-1)
   {
    return 1;
   }
     
   for(var i=0;i<val.length;i++)
   {
     var one = val.charAt(i) // is @ repeated twice?
      if(one=='@')
          cnt1=cnt1+1;
      else if(one=='.')
       {
        if((val.charAt(i))==(val.charAt(i+1)))// is . typed continuously?
        return 3;
       } 
   }
   //if @ is appearing more than 1 time
   if (cnt1>1)
   {
     return 2;   
   }
  return 0;
}
//PAN Validation 
//added by Karthikeyan.P for PAN validation
function PAN(sw)
{
 var PanExp=/^[A-Z]{5}[0-9]{4}[A-Z]{1}$/
 if (!isValid(PanExp,sw))
	{
	return false;	
	}
 else 
	{
	return true;
	}	
}	
/*-------------------------BP serial No Validation --------------------------------------*/
function validateSlNumber(SNo){
		//alert("test");
		//alert(SNo);
			if(SNo =="")
			{
				alert("Please enter a serial number");
				return false;
			}
			else
			{
				if(SNo == "bc")
				{
					//alert("blankcall")
					//__doPostBack('DetailsButton','');
					return true ;
				} 
				var s1=new String(SNo)
				//alert("s1 is " + s1);
				//var slDate = parseInt("200" + (parseInt(s1.charAt(0))) + GetMonth(s1.charAt(1))); // Commented by Prem for Serial no pattern change on Dec-11-2009
				var slDate = parseInt("20" + (parseInt(s1.charAt(0)))+ (parseInt(s1.charAt(1))) + GetMonth(s1.charAt(2)));
				//alert("sl date is  " + slDate);
				var sltoday = new Date();
				//alert("sltoday is  " + sltoday);
				var elMonth =new String("0" +parseInt(sltoday.getMonth()+1));
				//alert(elMonth);
				elMonth = elMonth.substr(elMonth.length - 2 , elMonth.length);
				//alert("el month is  " + elMonth);
				var elDate= parseInt(String(sltoday.getFullYear())+elMonth);
				//alert("eldate  is  " + elDate);
				
				//if(slDate>elDate){
				//alert("Serial number date cannot be greater than current date ");
					//return false;
				//}
				if(s1.length < 7)
				{
					alert("Please enter a serial number in 7 digits");
					return false;
				}
				for(i=0;i<s1.length;i++)
				{	
					//alert(" into the for loop " + i);	
					if(s1.charAt(i)==' ')
					{
						alert("Please enter a serial number without empty space");
						return false;
						break;
					}
					if(isLetter(s1.charAt(i))==false && isDigit(s1.charAt(i))==false)
					{
						alert("Please enter a serial number in valid format, Ex : 09AH123456 ");
						return false;
						break;
					}
					/*if(i==1)
					{
						//alert("into the if loop where i=1" +i);
						//alert(i);
						//alert(isDigit(SNo.charAt(i)));
						if(isDigit(SNo.charAt(i)))
						{
							//alert("isDigit in if condtion" + document.LogSCRForm.serialNumberTextbox.value.charAt(i));
							alert("Please enter a serial number in valid format");
							return false;
							break;
						}
					}*/
						//alert("isletter");
						/*if(isLetter(SNo.charAt(i)) == false )
						{
							alert("Please enter a serial number in valid format");
							return false;
							break;
						}
					if (i!=1)
						{
							if(isLetter1(SNo.charAt(i)))
							{
								alert("Please enter a serial number in valid format");
								return false;
								break;
							}
							
						}*/
					//if(i==0)// Commented by Prem for Serial no change on dec-11-2009
					if(i==0 || i==1)
					{
						//alert(document.getElementById('TextBox1').value.charAt(i));
						if(isLetter1(SNo.charAt(i)))
						{
							alert("Please enter a serial number in valid format");
							return false;
							break;
						}
					}
					//if(i==1)	// Commented by Prem for Serial no change on dec-11-2009
					if(i==2)
					{
						if(isLetter(SNo.charAt(i))== false)
						{
							alert("Please enter a serial number in valid format");
							return false;
							break;
						} //Added
					}
				}
				//Get end date 
				
				//__doPostBack('DetailsButton','');
				return true ;
			}
		}
function GetMonth(month)
{
	switch (month){
	case "a" :
				{
					return "01";
				}
	case "b" :
				{
					return "02";
					
				}
				
	case "c" :
				{
					return "03";
				}
				
	case "d" :
				{
					return "04";
				}
				
	case "e" :
				{
					return "05";
				}
				
	case "f" :
				{
					return "06";
				}
				
	case "g" :
				{
					return "07";
				}
				
	case "h" :
				{
					return "08";
				}
				
	case "i" :
				{
					return "09";
				}
				
	case "j" :
				{
					return "10";
				}
				
	case "k" :
				{
					return "11";
				}
				
	case "l" :
				{
					return "12";
				}
	}
}		
		function isDigit (c){  
		//alert("isdigit c= " + c);
		return ((c >= "0") && (c <= "9"))
		}
		function isLetter1 (c){  
		//alert("isLetter1"  +c);
		return (((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) )
		}
		// Validate is the user entered the characters only
		function isLetter (c){   
		//alert( "isLetter" + c);
		return (((c >= "a") && (c <= "l")) || ((c >= "A") && (c <= "L")) );
		}
/*---------------------------------------------------------------------------------------*/
//function to validate phone
function phone( sw )
{				
	var phoneexp = /^[(]+[0-9]{2}[)][0-9]{5}|[0-9]{3}[)][0-9]{6}|[0-9]{3}[)][0-9]{7}|[0-9]{3}[)][0-9]{8}|[0-9]{3}[)][0-9]{9}|[0-9]{3}[)][0-9]{10}$/
									
	if (!isValid( phoneexp , sw ))
	{	
		return false ;
	}
	else
	{
		return true ;
	}
}
// end iof function specialChars
function isValid(pattern, str)
{
	return pattern.test(str)
}
/*_____________code by Soumya________________*/

function ValidateGridTextBox(txt, alertMessage, trimValueBeforeValidating)
{
	
	if((txt != null) || (txt != 'undefined'))
	{
		var val = txt.value;
		if(trimValueBeforeValidating)
		{
			var val = TrimString(val);
			txt.value = val;
		}
		if(val == "" || val == 0)
		{
			alert(alertMessage);
			txt.focus();
			return false;
		}
		
	 }
	 return true;
}

function ValidateDecimalGridTextBox(txt, alertMessage,invalidValueMessage, trimValueBeforeValidating)
{
	
	if((txt != null) || (txt != 'undefined'))
	{
		var val = txt.value;
		if(trimValueBeforeValidating)
		{
			var val = TrimString(val);
			txt.value = val;
		}
		if(val == "")
		{
			alert(alertMessage);
			txt.focus();
			return false;
		}
		if(!IsDecimal(val))
		{
			alert(invalidValueMessage);
			txt.focus();
			return false;
		}
		
	}
	return true;
}

function ValidateCurrentDate(txt,EmptyFieldAlertMessage,invalidEntryAlertMessage, trimValueBeforeValidating)
{
	
	// To Validate the date field,it Should not be greater than the current date
	var val =txt.value;
	var date=new Date();
	var sDate = getCurrentDate();
	
	if(trimValueBeforeValidating)
	{
		var val = TrimString(val);
		txt.value = val;
	}
	if(val == "")
	{
		alert(EmptyFieldAlertMessage);
		txt.focus();
		return false;
	}
	if (val != null)
	{
		var retCompare = compareDates(val ,sDate);
		if (retCompare==1)
		{ 
			alert(invalidEntryAlertMessage);
			val = "";
			return false;
		}
	}
	return true;
		
}

function ValidateSelectedTextBox(chkBox,txtBox,alertMessage, trimValueBeforeValidating)
{
	if(chkBox.checked==true)
	{
		if( (txtBox == null) || (txtBox == 'undefined') )
		{
			alert("Undefined text control!");
			return true;
		}
		var val = txtBox.value;
		var valchk=chkBox.checked
			
		if(trimValueBeforeValidating)
		{
			var val = TrimString(val);
			txtBox.value = val;
		}
		if((val == "") && (valchk==true))
		{
			alert(alertMessage);
			txtBox.focus();
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
	 return true;
	}
} 



/*_____________ End of code by Soumya ________________*/


/*_____________ code by Sankar ________________*/

	function dateDiff(value1,value2,Ctrl) 
	{
				date1 = new Date();
				date2 = new Date();
				diff  = new Date();
				//var value1=document.ExitForm.txtresigned.value;
				//var value2=document.ExitForm.txtlastday.value;
				var mydate1, mydate2;
				var month1, month2;
				var year1, year2;
				var dateseperator = "/";
				   
				mydate1 = convertToInt(value1.substring (0, value1.indexOf (dateseperator)));
				month1 = convertToInt(value1.substring (value1.indexOf (dateseperator)+1, value1.lastIndexOf (dateseperator)));
				year1 = convertToInt(value1.substring (value1.lastIndexOf (dateseperator)+1, value1.length));
				value1 = month1 + "/" + mydate1 + "/" + year1;
				
				mydate2 = convertToInt(value2.substring (0, value2.indexOf (dateseperator)));
				month2 = convertToInt(value2.substring (value2.indexOf (dateseperator)+1, value2.lastIndexOf (dateseperator)));
				year2 = convertToInt(value2.substring (value2.lastIndexOf (dateseperator)+1, value2.length));
				value2 = month2 + "/" + mydate2 + "/" + year2;
				
				date1temp = new Date(value1 + " 12:00:00AM");
				date1.setTime(date1temp.getTime());
				date2temp = new Date(value2  + " 12:00:00AM");
				date2.setTime(date2temp.getTime());

				diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

				timediff = diff.getTime();

				weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
				timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

				days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
				timediff -= days * (1000 * 60 * 60 * 24);
				Ctrl.value=weeks * 7 + days;
				
	}
	
	function ImIdle()
	{
		var MyPath= new String(document.location.href);
		var Found=new String(MyPath.indexOf("MyWeP",1));
		if(Found!="-1")
		{
			setTimeout("alert('Hi!! This page is not refreshed for last 10 minutes.. Please save/submit the information to avoid Timeout issues!!')",600000)	
		}
	}
	ImIdle();
/*_____________ End of code by Sankar ________________*/
/*_____________ Start of code by Kiran ________________*/
function validateEmail(str)
{
	str=TrimString(str);
		var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1)
	{
		return false;
	}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
	{
		return false;
	}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
	{
		return false;
	}
	if (str.indexOf(at,(lat+1))!=-1)
	{
		return false;
	}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
	{
		return false;
	}
	if (str.indexOf(dot,(lat+2))==-1)
	{
		return false;
	}
	if (str.indexOf(" ")!=-1)
	{
		return false;
	}
 	return true;				
}
/*_____________ Start of code by Kiran ________________*/



/*______ Code for Show /Hide object using its ID ________
__________ Start of code here by Karthik.P______________*/


function showHide(inID) 
	{
		var dis;
		var theobj;
		var theDisp;
		theobj=document.getElementById (inID);		
		/*alert(theobk);				
		dis = document.getElementByID (inID);
		document.getElementById(inID).style.display == "none" ? "block" : "none";*/
		theDisp = theobj.style.display == "none" ? "block" : "none";
		theobj.style.display = theDisp;
		
	}
/*____________End of Code By karthik.P___________________*/

/*----------- Added by Abhishek M  (checkForChar)----------------*/
/*This function takes a string and a character and checks whether the character is present in the string*/
function checkForChar(str, chr)
{
    var i;
    for (i = 0; i < str.length; i++)
    {   
        var c = str.charAt(i);  
        if (c == chr)         
			return true;
    }
    return false;
}
/*  This function receives two dates in string format(DD/MM/YYYY) and returns the diference between those in terms of DAYS*/
/*  ***NOTE*** : Dates need to be validated before using this function*/
function dateDifInDays(date1, date2)//date format : DD/MM/YYYY ; preferably, date1>date2 (date1<date2 returns in rerms of negative value)
{
	var day1 = convertToInt(date1.substring(0, date1.indexOf("/")));			
	var month1 = convertToInt(date1.substring(date1.indexOf("/")+1, date1.lastIndexOf("/")));
	var year1 = convertToInt(date1.substring (date1.lastIndexOf ("/")+1, date1.length));
	
	var day2 = convertToInt(date2.substring(0, date2.indexOf("/")));			
	var month2 = convertToInt(date2.substring(date2.indexOf("/")+1, date2.lastIndexOf("/")));
	var year2 = convertToInt(date2.substring (date2.lastIndexOf ("/")+1, date2.length));
	
	var newDate1=new Date(year1, month1-1, day1+1); //Month will be 0-11 in JavaScript BUT the input will be 1-12 -> month-1
	var newDate2=new Date(year2, month2-1, day2+1); 
	
	//Set 1 day in milliseconds
	var one_day=1000*60*60*24;//1000 milliseconds=1 second; 1000msec X 60sec X 60min X 24hr = ONE DAY
	
	//Calculate difference btw the two dates, and convert to days
	var diff=Math.ceil((newDate1.getTime()-newDate2.getTime())/(one_day));
	return diff;
}
function formatFloatNum(expr, decplaces) 
{ 
	// Convert the number to a string 
	var str = expr.toString(); 
	var point = str.indexOf(".");
	//alert(point);
	var newstring;
	if (point!= -1) // point doesn't exists in the given expr
		newstring = str.substring(0, Number(point) + Number(decplaces) + 1); 
	else 
		newstring=str;
	return(newstring); 
} 
/*--------------------End of Code By Abhishek M-------------------*/
/*---------------------------------------------------------------*/
 function getTINfirsttwodigit(state)
		    {   
				var code ;
				
				switch(TrimString(state))
				{
					case "AP":
						{ 
						code="28"; 
						break;
						}
					case "AN":
						{ 
						code="35"; 
						break;
						}
					case "AR":
						{ 
						code="12"; 
						break;
						}
					case "AS":
						{ 
						code="18"; 
						break;
						}
					case "BIH":
						{
						code="10";
						break;
						}
					case "CH":
						{
						code="04";
						break;
						}
					case "CT":
						{
						code="22";
						break;
						}
					case "DL":
						{
						code="07";
						break;
						}
					case "DD": 
						{
						code="25";
						break;
						}
					case "GOA":
						{
						code="30";
						break;
						}
					case "GJ":
						{
						code="24";
						break;
						}
					case "HR":
						{
						code="06";
						break;
						}					
					case "HP":
						{
						code ="02";
						break;
						}
					case "J&K":
						{
						code="01";
						break;
						}
					case "JH":
						{
						code="20";
						break;
						}
					case "KA":
						{
						code="29";
						break;
						}
					case "KL":
						{
						code="32";
						break;
						}
					case "LD":
						{
						code="31";
						break;
						}
					case "MP":
						{
						code="23";
						break;
						}
					case "MAH":
						{
						code="27";
						break;
						}
					case "MN":
						{
						code="14";
						break;
						}
					case "MEG":
						{
						code="17";
						break;
						}
					case "MZ":
						{
						code="15";
						break;
						}
					case "NAG":
						{
						code="13";
						break;
						}
					case "OR":
						{
						code="21";
						break;
						}
					case "PY":
						{
						code="34";
						break;
						}
					case "PU":
						{
						code="03";
						break;
						}
					case "RJ":
						{
						code="08";
						break;
						}
					case "SI":
						{
						code="11";
						break;
						}
					case "TN":
						{
						code="33";
						break;
						}
					case "TR":
						{
						code="16";
						break;
						}
					case "UP":
						{
						code="09";
						break;
						}
					case "UR":
						{
						code="05";
						break;
						}
					case "UT":
						{
						code="05";
						break;
						}	
					case "WB":
						{
						code="19";
						break;
						}
					case "OT":
						{
						code="00";
						break;
						}
					case "DNH":
						{
						code="26";
						break;
						}
					case "SL":
						{
						code="36";
						break;
						}
					case "PO":  // Added By Raghavendra On 17-feb-2010 for pondichery
						{
						code="34";
						break;
						}	
					default:
						{
						code="00"
						break;
						}
				}				
				return code;
		    }
		    
		   	function Leftstr(str, n)
			{
			   if (n <= 0)
					 return "";
			   else if (n > String(str).length)
					 return str;
			   else
					 return String(str).substring(0,n);
			}
/************************************************************************************/
function blink(elId){
					var html = '';
					if(document.all){
						html += 'var bl = document.all.' + elId + ';';
						}
					else if(document.getElementById){
						html += 'var bl = document.getElementById("' + elId + '");';
						}
					html += 'bl.style.visibility = ' + 'bl.style.visibility == "hidden" ? "visible" : "hidden"';
					if(document.all || document.getElementById){
						setInterval(html, 500);
						}
			}	
			