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 strMonth=dtStr.substring(0,pos1)
	var strDay=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 : mm/dd/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 echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}
function  txtPhVal(e)
{
	Key=window.event.keyCode
	if ((Key>=48 && Key<=57) || Key==45 || Key==46)
		window.event.keycode; 
	else 
		window.event.keyCode=0;
}	

function  LockTextBox(e)
{
	Key=window.event.keyCode
	window.event.keyCode=0;
}



function trim(st)
{
//alert(st);
	if(st.length > 0)
	{
		re = / +$/g; 
		newval = st.replace(re,"");
		re = /^ +/g;
		newvala = newval.replace(re,"");
		return newvala;
	}
	return "";
}
function IsDate(mMonth, mDay, mYear)
{
	mMonth = parseInt(mMonth);
	mDay = parseInt(mDay);
	mYear = parseInt(mYear);
	var mLeap = false;
	if ( mYear%4 == 0 )
		mLeap = true;
	if ( mMonth == 1 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 2 )
	{
		if ( mLeap )
		{
			if ( mDay < 1 || mDay > 29 )
				return false;
			else
				return true;
		}
		else
		{
			if ( mDay < 1 || mDay > 28 )
				return false;
			else
				return true;
		}
	}
	else if ( mMonth == 3 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 4 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 5 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 6 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 7 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 8 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 9 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 10 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 11 )
	{
		if ( mDay < 1 || mDay > 30 )
			return false;
		else
			return true;
	}
	else if ( mMonth == 12 )
	{
		if ( mDay < 1 || mDay > 31 )
			return false;
		else
			return true;
	}
	else
	{
		return false;
	}
}
// this function opens the popoup window
function WinOpenS(winname,w,h,leftcor,topcor,pname)
{
	window.open( pname , winname, "scrollbars=1,statusbar=no,menubar=no,toolbar=no,resize=null,top=" + topcor + ",left=" + leftcor + ",width=" + w + ",height="+h ).focus();
}
// this function opens the popoup window
function WinOpenFull(winname,w,h,leftcor,topcor,pname)
{
	window.open( pname , winname, "scrollbars=0,statusbar=no,menubar=no,toolbar=no,resizable=no,top=" + topcor + ",left=" + leftcor + ",width=" + w + ",height="+h ).focus();
}

function IsEmailValid(email)
{
	email = trim(email);
	valid_chars_for_email = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_-@.";
	if ( email == "" )			// pending Email validation
	{
		return false;
	}
	for ( i=0; i < email.length; i++ )
	{
		ch =  "" + email.charAt(i);
		num = valid_chars_for_email.indexOf(ch);
		if ( num == -1 )
		{
			return false;
		}
	}
	if ( email.indexOf('@') == -1 )
	{
		return false;
	}
	if ( email.indexOf('.') == -1 )
	{
		return false;
	}
	return true;
}

function CompareDate(day1, month1, year1, day2, month2, year2)
{
	day1 = day1 * 1;
	month1 = month1 * 1;
	year1 = year1 * 1;
	day2 = day2 * 1;
	month2 = month2 * 1;
	year2 = year2 * 1;
	if ( (year2 == year1) && (month2 == month1) && (day2 == day1) )
	{
		return 0;			// Equal
	}
	else if ( ((year2 > year1)) || ( (year2 == year1) && (month2 > month1) ) || ( (year2 == year1) && (month2 == month1) && (day2 > day1)) )
	{
		return 2;			//  The second date is greater
	}
	else
	{
		return 1;			// The First Date is greater
	}
}


function ValidateNumeric( ctrl )
{
	var mVal = document.getElementById(ctrl).value;
	mVal = trim(mVal);
	if ( isNaN(mVal) || mVal == "" )
	{
		alert (ctrl.title + " Must Be A Numeric Value");
		ctrl.focus();
		return false;
	}
	else 
	{
		return true;
	}
}


function ValidateEmpty(ctrl,alertstr)
{
    var mVal = document.getElementById(ctrl).value;
	mVal = trim(mVal);
	if ( mVal == "" )
	{
		alert (alertstr);
		document.getElementById(ctrl).focus();
		return false;
	}
//	else 
//	{
//		return true;
//	}
//	
}
function ValidateImage(ctrl)
{
	if (ctrl.value.length)
	{
		var iPos = ctrl.value.lastIndexOf(".")
		var sExt = ctrl.value.substring(iPos);
//		if((sExt.toUpperCase()=='.JPEG') || (sExt.toUpperCase()=='.JPG') || (sExt.toUpperCase()=='.GIF') || (sExt.toUpperCase()=='.BMP') || (sExt.toUpperCase()=='.PNG') )
		if((sExt.toUpperCase()=='.JPEG') || (sExt.toUpperCase()=='.JPG') || (sExt.toUpperCase()=='.GIF') || (sExt.toUpperCase()=='.BMP') || (sExt.toUpperCase()=='.PNG') )
		{
			return true;
		}
		else
		{
			alert("Please enter valid image.");
			ctrl.focus();
			ctrl.select();
			return false;
		}                       
	}
	else
	{
		alert("Please select the file to be uploaded");
		ctrl.focus();
		ctrl.select();
		return false;
	}
}

function ClearCombo(ctrl)
{
	len = ctrl.options.length;
	for ( i = 0; i < len; i++ )
		ctrl.options[0] = null;
}

	//   Returns the digits after Decimal
function DigitsAfterDecimal(Num)
{
	Num = Num + "";
	Digits = 0;
	Flag = false;
	for ( i=0; i < Num.length; i++ )
	{
		if (Flag)
		{
			Digits++;
		}
		if (Num.charAt(i) == ".")
		{
			Flag = true;
		}
	}
	return Digits;
}

function IfContainsDecimal(Num)
{
	Num = Num + "";
	var mFlag = false;
	for ( i=0; i < Num.length; i++ )
	{
		if (Num.charAt(i) == ".")
		{
			mFlag = true;
		}
	}
	return mFlag;
}

function ShowPicture( imgctrl, ctrl )
{
	imgctrl.style.visibility = "visible";
	imgctrl.src = "file://" + ctrl.value;
}

//This function moves selected Item from List to Another
function MoveSelectedItem ( lstSource, lstTarget )
{
	if (lstSource.selectedIndex != -1)
	{
		var value = lstSource.options[lstSource.selectedIndex].value;
		var text =  lstSource.options[lstSource.selectedIndex].text;
		lstSource.options[lstSource.selectedIndex] = null;
		lstTarget.options[lstTarget.options.length] = new Option(text, value, null ,null );
	}
	else
	{
		alert("First select an Item");
	}
}

		//  This function moves all the items from a list to another
function MoveAllItems ( lstSource, lstTarget )
{
	var Slen = lstSource.options.length;
	var Tlen = lstTarget.options.length;
	if ( Slen )
	{
		for ( i=0; i < Slen; i++ )
		{
			var value = lstSource.options[0].value;
			var text =  lstSource.options[0].text;
			lstSource.options[0] = null;
			lstTarget.options[Tlen + i] = new Option(text, value, null ,null );
		}
	}
	else
	{
		alert("Source List doesnt have any Item");
	}
}

			//   This function returns the Values of a Listbox in a format of
			//		v1,v2,v2,v4,vn.
function GetListValues( lstctrl  )
{
	var len = lstctrl.options.length;
	var str = "";
	for( i=0; i < len; i++ )
	{
		str = str + lstctrl.options[i].value + ",";
	}
	return str;
}

//pradeep
 function KeyDownHandler(btn)
   {  
        // process only the Enter key
        if (event.keyCode == 13)
        {
            // cancel the default submit
            event.returnValue=false;
            event.cancel = true;
            // submit the form by programmatically clicking the specified button
            btn.click();
        }
    }


function addOnCon(objfrom,objto)
{
    
	
	var index = parseInt(objfrom.selectedIndex);
	
	
	if (index<0)
	{	
	return false;
	}
	index2 = parseInt(objto.length);
	if (index2==0)
	{
		var newopt = new Option;
		newopt.value = objfrom[index].value;
		newopt.text = objfrom[index].text;
		objto.options[0] = newopt;	
		//objto.options[0].selected = true;	
	}	
	if (index2>0)
	{
		var values = objfrom[index].value;
		for(i=0; i<=objto.length-1;i++)
		{			
			if(objto[i].value==values)
			{	
				alert("Already Exist in List");
				return false;
			}					
		}			
			var newopt = new Option;
			newopt.value=objfrom[index].value;
			newopt.text=objfrom[index].text;			
			objto.options[index2] = newopt;
			//objto.options[index2].selected = true;
	}	
	
}

function removeOnCon(objto)
{
	
	var indexRemove = parseInt(objto.selectedIndex);
	if (indexRemove<0)
	{	
		alert("Please Select The Item .")
		objto.focus();
		return false;
	}
	objto.remove(indexRemove);
}

function GetListValues( lstctrl  )
{
   var len = lstctrl.options.length;
   var str = "";
   for( i=0; i < len; i++ )
   {
      str = str + lstctrl.options[i].value + ",";
   }
   return str;
}


//Pradeep
function PollOptionCheck()
{
	var pollopt =0;
	var opt=0;
	for (var x = 0; x < document.forms[0].pollanswer.length; x++)
	{
		if (document.forms[0].pollanswer[x].checked)
			{
			opt= document.forms[0].pollanswer[x].value;
			pollopt=1;
			}
	}
	
	if (pollopt==0)
	{
		alert("Please select atleast one answer.");
	}
	else
	{
			
		var Hiddenpollqid = ""; 
		Hiddenpollqid = document.forms[0].HiddenPollQuestion.value ;				
		window.open("ThanksPollResponse.aspx?qid=" + Hiddenpollqid + "&opt=" + opt ,"Poll","top=5,left=30,toolbars=no,maximize=yes,resize=yes,width=400,height=200,location=no,directories=no,scrollbars=no");
		
		}	
}


//Pradeep
function Pollresult()
{
	
	
		
		var HiddenPollQuestion = ""; 
		HiddenPollQuestion = document.forms[0].HiddenPollQuestion.value ;		
		
		var HiddenPollQuestionText = "";
		HiddenPollQuestionText = document.forms[0].HiddenPollQuestionText.value ;					
		window.open("Pollresult.aspx?HiddenPollQuestion=" + HiddenPollQuestion + "&HiddenPollQuestionText=" + HiddenPollQuestionText ,"Poll","top=5,left=30,toolbars=no,maximize=yes,resize=yes,width=400,height=450,location=no,directories=no,scrollbars=no");
		
}


//Pradeep
function ValidationOptionCheck()
{
	var pollopt =0;
	var opt=0;
	for (var x = 0; x < document.forms[0].radiobutton.length; x++)
	{
		if (document.forms[0].radiobutton[x].checked)
			{
			opt= document.forms[0].radiobutton[x].value;
			pollopt=1;
			}
	}
	
	if (pollopt==0)
	{
		alert("Please select atleast one answer.");
		return false;
	}
	else
	{
		
		return true;	
		//var Hiddenpollqid = ""; 
		//Hiddenpollqid = document.forms[0].HiddenPollQuestion.value ;				
		//window.open("ThanksPollResponse.aspx?qid=" + Hiddenpollqid + "&opt=" + opt ,"Poll","top=5,left=30,toolbars=no,maximize=yes,resize=yes,width=400,height=250,location=no,directories=no,scrollbars=no");
		
		}	
}

//Pradeep
function ValidationOptionCheckBox()
{
	var pollopt =0;
	var opt=0;
	for (var x = 0; x < document.forms[0].chkb.length; x++)
	{
		if (document.forms[0].chkb[x].checked)
			{
			opt= document.forms[0].chkb[x].value;
			pollopt=1;
			}
	}
	
	if (pollopt==0)
	{
		alert("Please select atleast one answer.");
		return false;
	}
	else
	{
		
		return true;	
		//var Hiddenpollqid = ""; 
		//Hiddenpollqid = document.forms[0].HiddenPollQuestion.value ;				
		//window.open("ThanksPollResponse.aspx?qid=" + Hiddenpollqid + "&opt=" + opt ,"Poll","top=5,left=30,toolbars=no,maximize=yes,resize=yes,width=400,height=250,location=no,directories=no,scrollbars=no");
		
		}	
}

	
		// this function opens the popoup window
function WinOpenSS(winname,w,h,leftcor,topcor,pname)
{
	window.open( pname , winname, "scrollbars=1,statusbar=no,menubar=no,toolbar=no,resize=yes,top=" + topcor + ",left=" + leftcor + ",width=" + w + ",height="+h ).focus();
}

		//new by pradeep
		function Roundof(val)
		{
		var dd = val ;
		
		return Math.round(dd*100)/100;
		}
