
function isValueEntered(ele)
{
	if (ele.value.length==0)
	{
		return false
	}
	else
	{
		return true
	}
}
function isNumericReplaceComma(ele,isRequired,msgfldname)
{
	var valuewithoucomma=""
	valuewithoucomma=ele.value.replace(",","")
	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{
		return true
	}
	if(document.activeElement.name!=null)
	{
		if( document.activeElement.name.toLowerCase()=="btnclose" || document.activeElement.name.toLowerCase =="cmdclose" || document.activeElement.name.toLowerCase =="cmdcancel" )
		{
			return true
		}
	}
	
	if (document.activeElement.name != ele.name)
	{
		if (ele.value.length == 0 )
		{
			if (isRequired)
			{
				if (errEleNm =="" || ele.name == errEleNm)
				{
					err=true
					errEleNm= ele.name
					alert("Please Enter Value for the " + msgfldname)
					ele.focus()
					return false
				}
			}
			else
			{
				ele.value="0"
				errEleNm=""
				err=false
				return true
			}
		}
		//else if(isNaN(ele.value))
		else if(isNaN(valuewithoucomma))
		{
			if (errEleNm =="" || ele.name == errEleNm)
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Numeric Values for the " + msgfldname)
				ele.focus()
				return false
			}
		}
		else
		{
			errEleNm=""
			err=false
			return true
		}
	}
	//return true
}


function isNumericReplaceComma(ele,isRequired,msgfldname)
{
	var valuewithoucomma=""
	valuewithoucomma=ele.value.replace(",","")
	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{
		return true
	}
	if(document.activeElement.name!=null)
	{
		if( document.activeElement.name.toLowerCase()=="btnclose" || document.activeElement.name.toLowerCase =="cmdclose" || document.activeElement.name.toLowerCase =="cmdcancel" )
		{
			return true
		}
	}
	
	if (document.activeElement.name != ele.name)
	{
		if (ele.value.length == 0 )
		{
			if (isRequired)
			{
				if (errEleNm =="" || ele.name == errEleNm)
				{
					err=true
					errEleNm= ele.name
					alert("Please Enter Value for the " + msgfldname)
					ele.focus()
					return false
				}
			}
			else
			{
				ele.value="0"
				errEleNm=""
				err=false
				return true
			}
		}
		//else if(isNaN(ele.value))
		else if(isNaN(valuewithoucomma))
		{
			if (errEleNm =="" || ele.name == errEleNm)
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Numeric Values for the " + msgfldname)
				ele.focus()
				return false
			}
		}
		else
		{
			errEleNm=""
			err=false
			return true
		}
	}
	//return true
}



function isValidEmail(ele,checkIfNOTNULL)
{ 
	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{
		return true
	}
	if( document.activeElement.name=="cmdClose" || document.activeElement.name=="cmdCancel" )
	{
		return true
	}

	//var emailStr=document.updatebidderemail.email.value;
	/*if (! checkForNull(ele))
	{
		if (checkIfNOTNULL)
			return false // mean if the Null Email is NOT Allowed
		else
			return true// means if the Null Email is Allowed
	}*/
	if (! isValueEntered(ele))
	{
		if (checkIfNOTNULL)
			return false // mean if the Null Email is NOT Allowed
		else
			return true// means if the Null Email is Allowed
	}
	
	var emailStr=ele.value;
	var emailPat=/^(.+)@(.+)$/;
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var quotedUser="(\"[^\"]*\")";
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom=validChars + '+';
	var word="(" + atom + "|" + quotedUser + ")";
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray=emailStr.match(emailPat);
	
	/*if(theForm.email.value==""){
		return true;
	}*/
	if (matchArray==null) {
		err=true
		errEleNm= ele.name
		alert("email address seems incorrect (check @ and .'s)");
		ele.focus();
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];
	if (user.match(userPat)==null) {
		err=true
		errEleNm= ele.name
		alert("The username in Email ID doesn't seem to be valid.");
		ele.focus();
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null) {
		  for (var i=1;i<=4;i++) {
			if (IPArray[i]>255) {
				err=true
				errEleNm= ele.name
				alert("Destination IP address in Email ID is invalid!");
				ele.focus();
				return false;
			}
		}
	}  

	var domainArray=domain.match(domainPat);
	if (domainArray==null) {
		err=true
		errEleNm= ele.name
		alert("The domain name in Email ID doesn't seem to be valid.");
		ele.focus();
		return false;
	}

	var atomPat=new RegExp(atom,"g");
	var domArr=domain.match(atomPat);
	var len=domArr.length;
	if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
		err=true
		errEleNm= ele.name
		alert("The Email address must end in a three-letter domain, or two letter country.");
		ele.focus();
		return false;
	}
	if (len<2) {
		var errStr="This Email address is missing a hostname!";
		err=true
		errEleNm= ele.name
		alert(errStr);
		ele.focus();
		return false;
	  }
	 err=false
	 errEleNm= ""
	return true;
}

// It will check weather entered value has "_,_" or not.

function HasSeperator(compfields,compmsgs)
{	
	var comfldsArr,msgArr
	var ele
	msgArr=compmsgs.split(",")
	comfldsArr=compfields.toLowerCase().split(",")
	
	for(var i=0;i<comfldsArr.length;i++)
	{
		ele=document.getElementById(comfldsArr[i])
			
		if(comfldsArr[i].substr(0,3).toLowerCase() == "txt" || comfldsArr[i].substr(0,3).toLowerCase() == "cal")
		{
			if(ele.value != "")
			{
				var val;
			val = ele.value;
			if(val.search(/_,_/) != -1)
			{
			 alert("Remove _,_ from '" + msgArr[i] + "'");
			 ele.focus()
			 return false;
			}
			
			}
		}
	}
	return true
}
// It will check weather required value is entered or not.

function AreDetailsComplete( compfields,compmsgs)
{	
	var comfldsArr,msgArr
	var ele
	msgArr=compmsgs.split(",")
	comfldsArr=compfields.toLowerCase().split(",")
	//alert('length is : ' + comfldsArr.length);
	for(var i=0;i<comfldsArr.length;i++)
	{
		//alert('object name' + comfldsArr[i])
		ele=document.getElementById(comfldsArr[i])
		//alert('value is ' + ele.value)
		if(comfldsArr[i].substr(0,3).toLowerCase() == "ddl")
		{
			if(ele.selectedIndex == 0)
			{
				alert("Please select '" + msgArr[i] + "' from the list" +".")
				ele.focus()
				return false
			}
		}
		else if(comfldsArr[i].substr(0,3).toLowerCase() == "txt" || comfldsArr[i].substr(0,3).toLowerCase() == "cal" || comfldsArr[i].substr(0,3).toLowerCase() == "lbl")
		{
			if(ele.value == "")
			{
					alert("Please enter value for '" + msgArr[i] +"'.")
					ele.focus()
					return false
			}
			
		}
		else if(comfldsArr[i].substr(0,3).toLowerCase() == "hdn" )
		{
			//alert(ele.value);
			if(ele.value == "")
			{
					alert("Please select value for '" + msgArr[i] +"'.")
					//ele.focus()
					return false
			}
			
		}
		
	}
	return true
}

//it is required for nonconfrec form to check whether values are entered or not
function AreDetailsComplete1( compfields,compmsgs)
{

	var comfldsArr,msgArr
	var ele
	msgArr=compmsgs.split(",")
	comfldsArr=compfields.toLowerCase().split(",")
//	alert('length is : ' + comfldsArr.length);
	for(var i=0;i<comfldsArr.length;i++)
	{
		//alert('object name' + comfldsArr[i])
		//alert('object name' + comfldsArr[i].substr(3,comfldsArr[i].length-1))
		ele=document.getElementById(comfldsArr[i].substr(3,comfldsArr[i].length-1))
		//alert('first3 characters ' +comfldsArr[i]);
		//alert('value is ' + ele.value)
			if(comfldsArr[i].substr(0,3).toLowerCase() == "ddl")
		{
			if(ele.selectedIndex == 0)
			{
				alert("Please select '" + msgArr[i] + "' from the list" +".")
				ele.focus()
				return false
			}
		}
		else if(comfldsArr[i].substr(0,3).toLowerCase() == "txt")
		{
			if(ele.value == "")
			{
					alert("Please enter value for '" + msgArr[i] +"'.")
					ele.focus()
					return false
			}
			
		}
		
	}
	return true
}
// It will check weather entered value is numeric or not.

function CheckNumericValue(ele,numericmsgs)
{
			
			if((isNaN(ele.value)) || (ele.value < 0))
			{
					alert("Enter Positive Numeric Value for '" + numericmsgs +"'.")
					ele.focus()
					return false
			}
					
	return true
}

function CheckNumerics(ele,numericmsgs)
{
		if(isNaN(ele.value))
			{
					alert("Enter Positive Numeric Value for '" + numericmsgs +"'.")
					ele.focus()
					return false
			}
		if(ele.value <= 0)
			{
					alert(numericmsgs +" must be greater than Zero.")
					ele.focus()
					return false
			}	
					
	return true
}

function CheckNumericVal(ele,numericmsgs)
{
	var numeric = ele.value;
	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{
		return true
	}
	if(document.activeElement.name!=null)
	{
		if( document.activeElement.name.toLowerCase()=="btnclose" || document.activeElement.name.toLowerCase() =="cmdclose" || document.activeElement.name.toLowerCase() =="cmdcancel" || document.activeElement.name.toLowerCase()=="btncancel" )
		{
			return true
		}
	}	
			
		if(isNaN(ele.value))
			{
					alert("Enter Positive Numeric Value for '" + numericmsgs +"'.")
					ele.focus()
					return false
			}
		if(ele.value <= 0)
			{
					alert(numericmsgs +" must be greater than Zero.")
					ele.focus()
					return false
			}	
					
	return true
}
					
	


// It will check weather entered value must not be numeric like name fields.

function isAlphaNumeric(ele, MsgfldName)
{
	if(ele.value == '')
	{
		return true;
	}
	if(isNaN(ele.value))
	{
		return true;
	}
	else
	{
		alert("Please Enter non numeric Value for '" + MsgfldName + "'.")
		ele.focus()
		ele.value = '';
		return false
	}
}

// It will check weather entered date is in valid format or not.

function isValidDate(dateStr1,isValue) {
	// dateStr must be of format month day year with either slashes
	// or dashes separating the parts. Some minor changes would have
	// to be made to use day month year or another format.
	// This function returns True if the date is valid.
	var dateStr
	//alert(isValue)
	if (isValue )
	{
	//alert('in first');
		dateStr=dateStr1;
	}
	else
	{
///	alert('in sec');
		dateStr=dateStr1.value;
	}
	//alert(dateStr)
	if (dateStr == "")
	{
		return true;
	}
	if (dateStr == " ")
	{
		return true;
	}
	
	var slash1 = dateStr.indexOf("/");
	if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
	// if no slashes or dashes, invalid date
	if (slash1 == -1) 
	{
		alert("Enter Valid Date ");
		//alert(dateStr1);
		dateStr1.focus()
		dateStr1.value = '';
		
		return false; 
	}
	var dateMonth = dateStr.substring(0, slash1)
	var dateMonthAndYear = dateStr.substring(slash1+1, dateStr.length);
	var slash2 = dateMonthAndYear.indexOf("/");
	if (slash2 == -1) { slash2 = dateMonthAndYear.indexOf("-"); }
	// if not a second slash or dash, invalid date
	if (slash2 == -1) 
	{
		 alert("Enter Valid Date ");
		 dateStr1.focus()
		 dateStr1.value = '';
		 return false; 
	}
	var dateDay = dateMonthAndYear.substring(0, slash2);
	var dateYear = dateMonthAndYear.substring(slash2+1, dateMonthAndYear.length);
	if ( (dateMonth == "") || (dateDay == "") || (dateYear == "") ) 
	{
		alert("Enter Valid Date ");
		dateStr1.focus()
		dateStr1.value = '';
		return false; 
	}
	// if any non-digits in the month, invalid date
	for (var x=0; x < dateMonth.length; x++) {
		var digit = dateMonth.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) 
		{ 
			alert("Enter Valid Date ");
			dateStr1.focus()
			dateStr1.value = '';
			return false; 
		}
	}
	// convert the text month to a number
	var numMonth = 0;
	for (var x=0; x < dateMonth.length; x++) {
		digit = dateMonth.substring(x, x+1);
		numMonth *= 10;
		numMonth += parseInt(digit);
	}
	if ((numMonth <= 0) || (numMonth > 12))
	{
		alert("Enter Valid Date ");
		dateStr1.focus()
		dateStr1.value = '';
		return false; 
	}
	// if any non-digits in the day, invalid date
	for (var x=0; x < dateDay.length; x++) {
		digit = dateDay.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) 
		{
			alert("Enter Valid Date ");
			dateStr1.focus()
			dateStr1.value = '';
			return false; 
		}
	}
	// convert the text day to a number
	var numDay = 0;
	for (var x=0; x < dateDay.length; x++) {
		digit = dateDay.substring(x, x+1);
		numDay *= 10;
		numDay += parseInt(digit);
	}
	if ((numDay <= 0) || (numDay > 31)) 
	{ 
		alert("Enter Valid Date ");
		dateStr1.focus()
		dateStr1.value = '';
		return false; 
	}
	// February can't be greater than 29 (leap year calculation comes later)
	if ((numMonth == 2) && (numDay > 29)) 
	{ 
		alert("Enter Valid Date ");
		dateStr1.focus()
		dateStr1.value = '';
		return false; 
	}
	// check for months with only 30 days
	if ((numMonth == 4) || (numMonth == 6) || (numMonth == 9) || (numMonth == 11)) { 
		if (numDay > 30) 
		{ 
			alert("Enter Valid Date ");
			dateStr1.focus()
			dateStr1.value = '';
			return false; 
		} 
	}
	// if any non-digits in the year, invalid date
	for (var x=0; x < dateYear.length; x++) {
		digit = dateYear.substring(x, x+1);
		if ((digit < "0") || (digit > "9")) 
		{ 
			alert("Enter Valid Date ");
			dateStr1.focus()
			dateStr1.value = '';
			return false; 
		}
	}
	// convert the text year to a number
	var numYear = 0;
	for (var x=0; x < dateYear.length; x++) {
		digit = dateYear.substring(x, x+1);
		numYear *= 10;
		numYear += parseInt(digit);
	}
	// Year must be a 2-digit year or a 4-digit year
	if ( (dateYear.length != 2) && (dateYear.length != 4) ) 
	{ 
		alert("Enter Valid Date ");
		dateStr1.focus()
		dateStr1.value = '';
		return false; 
	}
	// if 2-digit year, use 50 as a pivot date
	if ( (numYear < 50) && (dateYear.length == 2) ) { numYear += 2000; }
	if ( (numYear < 100) && (dateYear.length == 2) ) { numYear += 1900; }
	if ((numYear <= 0) || (numYear > 9999)) 
	{ 
		alert("Enter Valid Date ");
		dateStr1.focus()
		dateStr1.value = '';
		return false; 
	}
	// check for leap year if the month and day is Feb 29
	if ((numMonth == 2) && (numDay == 29)) {
		var div4 = numYear % 4;
		var div100 = numYear % 100;
		var div400 = numYear % 400;
		// if not divisible by 4, then not a leap year so Feb 29 is invalid
		if (div4 != 0) 
		{
			alert("Enter Valid Date ");
			dateStr1.focus()
			dateStr1.value = '';
			return false; 
		}
		// at this point, year is divisible by 4. So if year is divisible by
		// 100 and not 400, then it's not a leap year so Feb 29 is invalid
		if ((div100 == 0) && (div400 != 0)) 
		{ 
			alert("Enter Valid Date ");
			dateStr1.focus()
			dateStr1.value = '';
			return false; 
		}
	}
	// date is valid
	return true;
}

// It will converts string into date format.

function stringToDate(sd1)
{	
	var no;
	var tmp;
	var m,d,y;
	sd1=sd1.replace('-','/');	sd1=sd1.replace('-','/');
	sd1=sd1.replace(',','/');	sd1=sd1.replace(',','/');
	sd1=sd1.replace(';','/');	sd1=sd1.replace(';','/');
	no=0;
	tmp=no;
	no=sd1.indexOf("/",no);
	m=sd1.substring(tmp,no);
	no++;
	tmp=no;
	no=sd1.indexOf("/",no);
	d=sd1.substring(tmp,no);
	no++;
	tmp=no;
	no=no+4;
	y=sd1.substring(tmp,no);
	var d=new Date(y,m,d);
	return d;
}

// Confirmation before canceling the page

function ConfirmExit()
{

	if (confirm('All changes would be lost! Want to continue?'))
	{
		//window.close()
		return true
	}
	return false
}

// It will call when we want to delete any record.

function doSubmit(id,mode,selectedrow,listid)
{	
	if ( mode=="D" )
	{
		if ( confirm("Selected Record would be Deleted!!.Want to continue?"))
		{
			document.forms[0].action=document.forms[0].action.split("?")[0] + "?id=" + id + "&mode=" + mode +"&selectedrow="  + selectedrow + "&listid=" + listid
			//document.forms[0].action="<%=formname%>" + "?id=" + id + "&mode=" + mode +"&selectedrow="  + selectedrow
			document.forms[0].submit()
			return true;	
		}
		else
		return false
	}
	else
	{
		document.forms[0].action=document.forms[0].action.split("?")[0] + "?id=" + id + "&mode=" + mode +"&selectedrow="  + selectedrow
		//document.forms[0].action="<%=formname%>" + "?id=" + id + "&mode=" + mode +"&selectedrow="  + selectedrow
		document.forms[0].submit()
		return true;	
	}
	
}

// It will check weather entered time is valid or not

function checkTime(ele,isRequired,msgfldname)
{	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{	return true
	}
	if( document.activeElement.name=="cmdClose" || document.activeElement.name=="cmdCancel" )
	{	return true
	}
	if (document.activeElement.name != ele.name)
	{	if (ele.value.length == 0 )
		{	if (isRequired)
			{
				if (errEleNm =="" || ele.name == errEleNm)
				{
					err=true
					errEleNm= ele.name
					alert("Please Enter Time for the " + msgfldname)
					ele.focus()
					return false
				}
			}
			else
			{
				ele.value=""
				errEleNm=""
				err=false
				return true
			}
		}
		else 
		{
			st=ele.value;
			
			st=st.replace("/",":");	st=st.replace("/",":");	st=st.replace("/",":");
			st=st.replace("\\",":");st=st.replace("\\",":");st=st.replace("\\",":");
			st=st.replace(" ","");	st=st.replace(" ","");	st=st.replace(" ","");
			st=st.replace(" ","");	st=st.replace(" ","");	st=st.replace(" ","");
			st=st.replace(".",":");	st=st.replace(".",":");	st=st.replace(".",":");

		
			f=st.indexOf(":");	s=st.indexOf(":",f+1)
			
			if(f==-1)
			{
				ssf=st.indexOf("A");
				if(ssf==-1)
					ssf=st.indexOf("a");
				if(ssf==-1)
				{
					ssf=st.indexOf("P");
					if(ssf==-1)
						ssf=st.indexOf("p");
				}
				if(ssf==-1)
				{
					hh=st.substr(f+1);
					mm="00"
					ss="00"
				}else
				{
					hh=st.substr(f+1,ssf-(f+1));
					mm="00";
					ss="00"+st.substr(ssf);
				}

			}else
			{
				if(s==-1)
				{
					hh=st.substr(0,f);

					ssf=st.indexOf("A");
					if(ssf==-1)
						ssf=st.indexOf("a");
					if(ssf==-1)
					{
						ssf=st.indexOf("P");
						if(ssf==-1)
							ssf=st.indexOf("p");
					}
					if(ssf==-1)
					{
						mm=st.substr(f+1);
						ss="00"
					}else
					{
						mm=st.substr(f+1,ssf-(f+1));
						ss="00"+st.substr(ssf);
						
					}
				}else
				{
					
					hh=st.substr(0,f)
					mm=st.substr(f+1,s-(f+1))
					ss=st.substr(s+1)
				}
			}

			ssf=ss.indexOf("A");
			if(ssf==-1)
				ssf=ss.indexOf("a");

			sss=ss.indexOf("P");
			if(sss==-1)
				sss=ss.indexOf("p");

			if(ssf==-1 && sss==-1)
			{
				ss=ss.substr(0,2);
				ampm="AM";
			}else
			{
				
				if(ssf!=-1)
				{	ampm="AM";
					ss=ss.substr(0,ssf);
				}
				else
				{	ampm="PM";
					ss=ss.substr(0,sss);
				}
				
			}
			if(ss=="")ss=0;
			if(mm=="")mm=0;
			if(hh=="")hh=0;

			hh=Number(hh);
			if(isNaN(hh))
			{	err=true
				errEleNm= ele.name
				alert("Please Enter Valid Time(hour) for the " + msgfldname)
				ele.focus()
				return false
			}

			mm=Number(mm);
			if(isNaN(mm))
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Valid Time(minute) for the " + msgfldname)
				ele.focus()
				return false
			}

			ss=Number(ss);
			if(isNaN(ss))
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Valid Time(Second) for the " + msgfldname)
				ele.focus()
				return false
			}
			
			if(hh>=0 && hh<=24)
			{	
				if(hh>12 && hh<=24)
				{	hh=hh-12;
					ampm="PM";
				}
			}else
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Valid Hour for the " + msgfldname)
				ele.focus()
				return false
			}
			if(hh==0)hh=12;
			if(0>mm || mm>=59)
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Valid Minute for the " + msgfldname)
				ele.focus()
				return false
			}

			if(0>ss || ss>=59)
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Valid Second for the " + msgfldname)
				ele.focus()
				return false
			}
			hh=hh+"";
			if(hh.length==1)hh="0"+hh;
			mm=mm+"";
			if(mm.length==1)mm="0"+mm;
			ss=ss+"";
			if(ss.length==1)ss="0"+ss;
			
			ele.value=(hh+":"+mm+":"+ss+" "+ampm);

			errEleNm="";
			err=false;
			return true;
		}// end of if for len
	}// end of if of active element
	return true;
}

// It will check that entered data is more than define length in database

function checkEnteredTextLength(elename,csize,elemsg)
{
	var i;
	var status;
	status=0;
	
	if(elename.value.length > csize )
	{
		alert("Only " + csize + " characters are allowed for '" + elemsg + "'. Please reduce your contents");
		elename.focus();
		
		return false;
	}
	
	return true
}
/*
function readonlyfields(controlname)
{
	var comfldsArr
	var ele
	comfldsArr=controlname.toLowerCase().split(",")
	//alert('length is : ' + comfldsArr.length);
	for(var i=0;i<comfldsArr.length;i++)
	{
		alert('object name' + comfldsArr[i])
		ele=document.getElementById(comfldsArr[i])
		alert('value is ' + ele)
		ele.disabled=true;
	}
}
*/
function ClearValues(field)
{
	var comfldsArr
	var ele
	comfldsArr=field.toLowerCase().split(",")
	for(var i=0;i<comfldsArr.length;i++)
	{
		ele=document.getElementById(comfldsArr[i])
		if(comfldsArr[i].substr(0,3).toLowerCase() == "txt")
		{
			ele.value = '';
		}
		else if(comfldsArr[i].substr(0,3).toLowerCase() == "ddl")
		{
			ele.selectedIndex = 0;
		}
		else if(comfldsArr[i].substr(0,3).toLowerCase() == "chk")
		{
			ele.checked = false ;
		}
		
	}
}

function ResetFormAction()
{
	document.forms[0].action=document.forms[0].action.split("?")[0];
	return true;
}
function chkpassword()
		{
			if (document.getElementById("txtNewPassword").value != document.getElementById("txtConfirmPassword").value)
			{
				
				alert("New password and Confirm password must be same.")
				document.getElementById("txtConfirmPassword").focus()
				return false
			}
			return true
		}
		
function MM_openBrWindow(theURL,winName,features) { //v2.0
	var wd,ht,i,tmp;
	var len
	len=features.length
	if(len!=0)
	{
		features=features.toLowerCase()
		for(i=0;i<(len)/4;i++)features=features.replace(" ","")	
		tmp=features.indexOf("width=")+6;
		wd=parseInt(features.substr(tmp));
		tmp=features.indexOf("height=")+7;
		ht=parseInt(features.substr(tmp));
		//if(features.indexOf("top=")==-1)
		features=features+",top=" +((window.screen.height/2)-(ht/2))+",left="+((window.screen.width/2)-(wd/2))
		w=window.open(theURL,winName,features);
		w.focus();
	}else
	{
		w=window.open(theURL,winName,features);
		w.resizeTo(window.screen.width,window.screen.height); 
		w.moveTo(0,0);                		
		w.focus();
	}
	
}
	
function cannotEdit()
{
	alert('You cannot Edit this record as this time.  \n\n Record is either Locked or it is Read Only');
	return false;
}

function cannotDelete()
{
	alert('You cannot Delete this record as this time. \n\n Record is either Locked or it is Read Only');
	return false;
}

function EditFunction(id,ctrlname,fldvalue)
		{
		ResetFormAction();
		if ('<%=mode%>'=='M')
		{ alert('You are in Edit Mode. Please Save or Cancel Changes!!');
		return false;
		} 
		document.forms[0].action=document.forms[0].action.split('?')[0]+ "?id=" + id + '&mode=M'//& CType(myDataGridItem.Cells(2).Controls(0), Label).Text & "&mode=M'" & ";
		document.all(ctrlname).value=fldvalue //" & CType(myDataGridItem.Cells(3).Controls(0), Label).Text & "'; 
			document.forms[0].submit(); 
			return false;
		}
		
function confirmDelete()
	{
	
		if ( confirm("Selected Record would be Deleted!!.Want to continue?"))
		{
		//	document.forms[0].action=document.forms[0].action.split("?")[0] + "?id=" + id + "&mode=" + mode +"&selectedrow="  + selectedrow + "&listid=" + listid
			//document.forms[0].action="<%=formname%>" + "?id=" + id + "&mode=" + mode +"&selectedrow="  + selectedrow
			document.forms[0].submit()
			return true;	
		}
		else
		return false
}


////////function to move focus --Vimal/////////////////
function checkKey()
{
	var oSource = window.event.srcElement
	
	if (window.event.keyCode == 13 && oSource.type != 'submit' )
	{
		alert("inside")
		window.event.keyCode = 9
	}

}
function ConfirmCancel()
{
	if (confirm('All changes would be lost! Want to continue?'))
	{
		return true
	}
	return false
}
/*  Added By : Viral Mewada
	Added On : 9th sep, 2005
*/
function alphanumeric(alphane,MSGfld)
{
	var numeric = alphane.value;
	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{
		return true
	}
	if(document.activeElement.name!=null)
	{
		if( document.activeElement.name.toLowerCase()=="btnclose" || document.activeElement.name.toLowerCase() =="cmdclose" || document.activeElement.name.toLowerCase() =="cmdcancel" || document.activeElement.name.toLowerCase()=="btncancel" )
		{
			return true
		}
	}

	for(var j=0; j<numeric.length; j++)
		{
		  var alpha = numeric.charAt(j);
		  var val = alpha.charCodeAt(0);
		  if((val > 47 && val<59) || (val > 64 && val<91) || (val > 96 && val<123))
		   {
		   }
		  else
		   {
			 alert("Please Enter alphanumeric Value for " + MSGfld)
			 alphane.focus()
			 return false;
		   }
		}
 return true;
}

function isNumeric(ele,isRequired,msgfldname)
{
	if( document.activeElement.tagName=="A" )// this condi is needed as if user wants to leave the page without entry
	{
		return true
	}
	if(document.activeElement.name!=null)
	{
		if( document.activeElement.name.toLowerCase()=="btnclose" || document.activeElement.name.toLowerCase()=="cmdclose" || document.activeElement.name.toLowerCase() =="cmdcancel" || document.activeElement.name.toLowerCase()=="btncancel" )
		{ 
			return true;
		}
	}
	if (document.activeElement.name != ele.name)
	{
		if (ele.value.length == 0 )
		{
			if (isRequired)
			{
				if (errEleNm =="" || ele.name == errEleNm)
				{
					err=true
					errEleNm= ele.name
					alert("Please Enter Value for the " + msgfldname)
					ele.focus()
					return false
				}
			}
			else
			{
				ele.value="0"
				errEleNm=""
				err=false
				return true
			}
		}
		else if(isNaN(ele.value))
		{
			if (errEleNm =="" || ele.name == errEleNm)
			{
				err=true
				errEleNm= ele.name
				alert("Please Enter Numeric Values for the " + msgfldname)
				ele.focus()
				return false
			}
		}
		else
		{
			errEleNm=""
			err=false
			return true
		}
	}
	//return true
}
function ClosewindowConfirm()
		{
			if(confirm("Window will be closed,Continue?")==true) 
				{
					window.close()
					return true;
				}
			else
				{ 
					return 	false;
					
				}	
		}
function ClosewindowAndSubmit()
		{
			if(confirm("Window will be closed,Continue?")==true) 
				{
					window.opener.document.Form1.submit();
					window.close()
					return true;
				}
			else
				{ 
					return 	false;
					
				}	
		}
		
function IsLessThanOrEqual(ele, valueToCompare, Msg)
			{
				if (CheckNumericValue(ele,Msg))
				{
					if (parseInt(ele.value) > valueToCompare)
						{
							alert(Msg + " must be less than or equal to " + valueToCompare);
							ele.focus();
							return false;
						}
					else
						return true;
				}
				ele.focus();
				return false;
			}
			
			function setSampleSentValues()
			{
			//window.opener.document.SampleProductSent.txtproductcode.value='" & CType(e.Item.FindControl("productcode"), Label).Text & "'; 
			}
			
			function checkdate(dateStr1,isValue)
			{
	
	// dateStr must be of format month day year with either slashes
	// or dashes separating the parts. Some minor changes would have
	// to be made to use day month year or another format.
	// This function returns True if the date is valid.
	var dateStr
	//alert(isValue)
	if (isValue )
	{
	//alert('in first');
		dateStr=dateStr1;
	}
	else
	{
///	alert('in sec');
		dateStr=dateStr1.value;
	}
	//alert(dateStr)
	if (dateStr == "")
	{
		return true;
	}
	if (dateStr == " ")
	{
		return true;
	}
	
	var slash1 = dateStr.indexOf("/");
	if (slash1 == -1) { slash1 = dateStr.indexOf("-"); }
	// if no slashes or dashes, invalid date
	if (slash1 == -1) 
	{
		alert("Enter Valid Date ");
		//alert(dateStr1);
		dateStr1.focus()
		dateStr1.value = '';
		
		return false; 
	}
			}
			
function Trim(str)
{
	while(str.charAt(0) == (" ") )
	{
		str = str.substring(1);
	}
	while(str.charAt(str.length-1) == " " )
	{
		str = str.substring(0,str.length-1);
	}
	return str;
}

function checkMaxRow (textarea, maxrow) 
{
var cantidad = textarea.value.match(/\n+/g);
var cuenta = cantidad?cantidad.length:0;
   	if (cuenta < maxrow) 
    	{ return true;}
  	else
	{
	textarea.selected = false;
	return false;}
}

