var len;

var indexes;

var arrStateCity;

var arrStateCityVals;



var arrState;

var arrStateVals;

var arrCity;

var arrCityVals;

var val;

var count;

var form;



var dlen;

var dindexes;

var dval;

var dval2;

var dcount;

var arrDegreeSpec;

var arrDegreeSpecVals;

var arrFunctSpec;

var arrFunctSpecVals;



var validWorldPhoneChars = "0123456789-+ ";

var validNumbers = "0123456789";

// ********



function checkstdelimeter(sText,actualval,name1)

{

	sText = actualval;

   for (i = 0; i < sText.length; i++) { 

			Char = sText.charAt(i); 

			j=i+1;

			if (Char == "<" && j <= sText.length ) {

					if (sText.charAt(j)=="\""){ 

						alert(name1 +" Don't Use < After ? Or ? After > Characters");

						return(0);

					}

				}

  }

  

  for (i = 0; i < sText.length; i++) { 

			Char = sText.charAt(i); 

			j=i+1;

			if (Char == "\"" && j <= sText.length ) {

					if (sText.charAt(j)==">"){ 

							alert(name1 +" Don't Use < After ? Or ? After > Characters");

							return(0);

					}

				}

  }

    return(1);

}





function isAlphabetic(sText)
{

	   var ValidChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ.- ';

	   var IsValid=true;

	   var Char;

	   for (i = 0; i < sText.length && IsValid == true; i++) 

			{ 

				Char = sText.charAt(i); 

				if (ValidChars.indexOf(Char) == -1) 

					{

						IsValid = false;

					}

			}

		return IsValid;

}

	
function checkPositiveInteger(field,name) {

		var fieldValue = field.value;

		//Check for non-integer or negative entries 

		if(isNaN(fieldValue) || parseInt(fieldValue) <= 0 || fieldValue.indexOf(".") != -1)	

		{

			field.focus();

			if(name != null)

				alert("Please provide a numeric value for "+name);

			else

				alert("Please provide a numeric value only.");

			field.select();

			field.focus();

			return false;

		}

		return true;

}



function checkFloat(field,name) {

		var fieldValue = field.value;

		//Check for negative entries 

		if(isNaN(fieldValue) || parseInt(fieldValue) <= 0)	

		{

			field.focus();

			if(name != null)

				alert("Please provide a numeric value for "+name);

			else

				alert("Please provide a numeric value only.");

			field.select();

			field.focus();

			return false;

		}

		if(fieldValue.indexOf(".") != -1)

		{

			var substring1 = fieldValue.substring(fieldValue.indexOf(".")+1,fieldValue.length);

			if(substring1.length > 2)

			{

			field.focus();

			if(name != null)

				alert("Please provide only two digits after decimal for "+name);

			else

				alert("Please provide only two digits after decimal.");

			field.select();

			field.focus();

			return false;

			}

				

		}



		return true;

}



function trim( instr ) {

    	var reFirst = /\S/;		// regular expression for first non-white char

    	var reLast = /\s+$/;	// regular expression for first white char after last non-white char

    	var firstChar = instr.search(reFirst);

    	var lastChar = instr.search(reLast);

    	

    	if( lastChar == -1 ) 

			lastChar = instr.length;    	

    	outstr = instr.substring( firstChar, lastChar );

    	return outstr;

}



function checkBlank(field,name)
{
	if(trim(field.value) == "")
	{	
		field.focus();
		if(name != null)
			alert(name+" field should not be blank.");
		else
			alert("This field should not be blank.");

		field.value = "";
		field.focus();
		return false;
	}
	return true;
}
//New function added to display correct error/ warning msgs.



function checkBlankNew(field,msg)

{

	if(trim(field.value) == "")

	{	

		field.focus();

		if(msg != null)

			//alert(name+" can not be left blank.");

			alert(msg);

		else

			alert("This field is Mandatory");



		field.value = "";

		field.focus();

		return false;

	}

	return true;

}



function replaceQuotes(field)
{
	if(trim(field.value) != ""){
		if(!parseText(field.value,field))
		{
			alert(" Please Enter Valid Characters  " ) ;
			field.focus();
			return false;
		}
		var myRegExp = /'/g;
		var newString = field.value.replace(myRegExp,"`");
		field.value = newString;
	}
	return true;
}

function isEmail (emailIn){
	var isEmailOk = false;
	var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/
	if(emailIn.search(filter) != -1)
		isEmailOk = true;
	if(emailIn.indexOf("..") != -1)
		isEmailOk = false;
	if(emailIn.indexOf(".@") != -1)
		isEmailOk = false;
	return isEmailOk;
} // Ends 

/********************************************************added by lokesh*****/ 

function MultipleEmail (emailIn){

	var isEmailOk = false;
	var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/
	var LastCommaIndex = emailIn.lastIndexOf(',');	
	var separator = ",";
	lastemail = emailIn.substring(LastCommaIndex,emailIn.length);
	emailIn = emailIn.substring(0,emailIn.length);
	if (lastemail.length > 1)
	{
	}
	else
	{
		emailIn = emailIn.substring(0,LastCommaIndex);
	}
	var arrayOfStrings = emailIn.split(separator);
	var sizeArr  = arrayOfStrings.length;
	for (em=0;em<sizeArr ;em++ )
	{
		getemailIn = arrayOfStrings[em];
		if(getemailIn.search(filter) != -1)
		{
			isEmailOk = true;
		}
		else
		{
			isEmailOk = false;
			break;
		}
		if(getemailIn.indexOf("..") != -1)
		{
			isEmailOk = false;
		}
		if(getemailIn.indexOf(".@") != -1)
		{
			isEmailOk = false;
		}
		emailIn ="";
	}

	return isEmailOk;
} // Ends

/********************************************************/



function isSms (sms)

{

	var isSmsOk = false;

	var filter = /^[\+]?[0-9]{10,}\@[a-zA-Z0-9]+(\.[a-zA-Z][a-zA-Z]+)+$/



	if(sms.search(filter) != -1)

		isSmsOk = true;



	return isSmsOk;

}



function checkDate(day,month,year)
{
	var dd = parseInt(day.value);
	var mm = parseInt(month.value);
	var yyyy = parseInt(year.value);
	if((mm == 4 || mm == 6 || mm == 9 || mm == 11) && (dd > 30))
	{
		alert("Please select a valid date");
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}
	if(mm == 2)
	{
		if(dd > 29)
		{
			alert("Please select a valid date");
			day.value = '';
			month.value = '';
			year.value = '';		
			day.focus();
			return false;
		}
		else if (dd == 29) { 
				if(!( ((yyyy%4 == 0) && (yyyy%100 != 0)) || (yyyy%400 == 0) )) {
					alert("Please select a valid date");
					day.value = '';
					month.value = '';
					year.value = '';		
					day.focus();
					return false;	
				}
		}
	}
	return true;
}


function isDateBeforeSystemDate(day,month,year,cday,cmonth,cyear)
{	
	var dd = parseInt(day.value);
	var mm = parseInt(month.value);
	var yyyy = parseInt(year.value);

	if(cyear.value < yyyy)
	{
		alert("Date should be before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}

	if((cyear.value == yyyy) && (cmonth.value < mm))
	{
		alert("Date should be before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}

	if((cyear.value == yyyy) && (cmonth.value == mm)  && (cday.value <= dd))
	{
		alert("Date should be before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}

	return true;
}

function isDateBeforeToday(day,month,year)
{

	var dd = parseInt(day.value);
	var mm = parseInt(month.value);
	var yyyy = parseInt(year.value);
	var today = new Date();
	if(today.getFullYear() < yyyy)
	{
		alert("Date should be before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}

	if((today.getFullYear() == yyyy) && ((today.getMonth() + 1) < mm))
	{
		alert("Date should be before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}

	if((today.getFullYear() == yyyy) && ((today.getMonth() + 1) == mm)  && (today.getDate() < dd))
	{
		alert("Date should be before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}
	return true;
}



function isDateBeforeToday1(day,month,year)
{
	var dd = parseInt(day.value);
	var mm = parseInt(month.value);
	var yyyy = parseInt(year.value);
	var today = new Date();
	if(today.getFullYear() < yyyy)
	{
		alert("Death Date should be today's date or before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}
	if((today.getFullYear() == yyyy) && ((today.getMonth() + 1) < mm))
	{
		alert("Death Date should be today's date or before today's date");			
		day.value = '';
		month.value = '';
		year.value = '';		
		day.focus();
		return false;
	}

	if((today.getFullYear() == yyyy) && ((today.getMonth() + 1) == mm)  && (today.getDate() < dd))
	{
		alert("Death Date should be today's date or before today's date");			
		day.focus();
		return false;
	}
	return true;
}

function isDateAfterToday(day,month,year)
{
	var dd = parseInt(day.value);
	var mm = parseInt(month.value);
	var yyyy = parseInt(year.value);
	var today = new Date();
	if(today.getFullYear() > yyyy)
	{
		alert("Date should be after today's date");			
		day.focus();
		return false;
	}

	if((today.getFullYear() == yyyy) && ((today.getMonth() + 1) > mm))
	{
		alert("Date should be after today's date");			
		day.focus();
		return false;
	}

	if((today.getFullYear() == yyyy) && ((today.getMonth() + 1) == mm)  && (today.getDate() > dd))
	{
		alert("Date should be after today's date");			
		day.focus();
		return false;
	}
	return true;
}

function compareDates(day1,month1,year1,day2,month2,year2)
{
	var dd1 = parseInt(day1.options[day1.selectedIndex].value);
	var mm1 = parseInt(month1.options[month1.selectedIndex].value);
	var yyyy1 = parseInt(year1.options[year1.selectedIndex].value);
	var dd2 = parseInt(day2.options[day2.selectedIndex].value);
	var mm2 = parseInt(month2.options[month2.selectedIndex].value);
	var yyyy2 = parseInt(year2.options[year2.selectedIndex].value);

	if(yyyy1 > yyyy2)
	{
		alert("'To Date' should be after 'From Date'");			
		day1.focus();
		return false;
	}

	if((yyyy1 == yyyy2) && (mm1 > mm2))
	{
		alert("'To Date' should be after 'From Date'");			
		day1.focus();
		return false;
	}

	if((yyyy1 == yyyy2) && (mm1 == mm2)  && (dd1 > dd2))
	{
		alert("'To Date' should be after 'From Date'");			
		day1.focus();
		return false;
	}

	return true;

}


function compareDates1(cboDeathDay,cboDeathMonth,cboDeathYear,cboBirthDay,cboBirthMonth,cboBirthYear)
{
	var dd1 = parseInt(cboDeathDay.options[cboDeathDay.selectedIndex].value);
	var mm1 = parseInt(cboDeathMonth.options[cboDeathMonth.selectedIndex].value);
	var yyyy1 = parseInt(cboDeathYear.options[cboDeathYear.selectedIndex].value);
	var dd2 = parseInt(cboBirthDay.options[cboBirthDay.selectedIndex].value);
	var mm2 = parseInt(cboBirthMonth.options[cboBirthMonth.selectedIndex].value);
	var yyyy2 = parseInt(cboBirthYear.options[cboBirthYear.selectedIndex].value);

	if(yyyy1 < yyyy2)
	{
		alert("Death Date should be greater than Birth Date");			
		cboDeathDay.focus();
		return false;
	}

	if((yyyy1 == yyyy2) && (mm1 < mm2))
	{
		alert("Death Date should be greater than Birth Date");			
		cboDeathDay.focus();
		return false;
	} 

	if((yyyy1 == yyyy2) && (mm1 == mm2)  && (dd1 < dd2))
	{
		alert("Death Date should be greater than Birth Date");			
		cboDeathDay.focus();
		return false;
	}

	return true;
}



function mandatoryValidate(field1,name)
{
	val = field1.options[field1.selectedIndex].value;
	if(parseInt(val) == -1){
		field1.focus();
		if(name != null)
			alert("Please select some value for "+name);
		else
			alert("Please select some value for this field");
		field1.focus();
		return false;
	}
		return true;
}

function mandatoryValidateList(field1,name)
{
	val =field1.selectedIndex;

	if(parseInt(val) == -1){
		field1.focus();
		if(name != null)
			alert("Please select some value for "+name);
		else
			alert("Please select some value for this field");
		field1.focus();
		return false;
	}
	return true;
}





function mandatoryValidateNew(field1,msg)

	{

	val = field1.options[field1.selectedIndex].value;

	if(parseInt(val) == -1){

		field1.focus();

		if(msg != null)

			alert(msg);

		else

			alert("Please select some value for this field");

		field1.focus();

		return false;

	}

		return true;

	}

	

// for pasing text

function parseText(text,field) {
	var finaltext = "";
	for(var i = 0; i < text.length ; i++)
	{
		var charCode = text.charCodeAt(i);
		if(charCode == 39 ) {
			finaltext += "`";
		}
		else if(charCode == 9 ) {
			finaltext += " ";
		}
		else if(charCode == 10) {

				finaltext += text.charAt(i);
		}
		else if( !(charCode >= 33 && charCode <= 126 ) ) {

			finaltext += " ";
		}
		else {
			finaltext +=  text.charAt(i);
		}
	}
	field.value = finaltext;
	return true;
}


function replaceSplchar(i,code,str)

{

		var temp=""+str ;

		var replaceWith = "";

		if(code == 183)

			replaceWith ="-";

		else if(code == 8226)

			replaceWith ="-";

		else if(code == 8217)

			replaceWith ="`";

		else if(code == 8216)

			replaceWith ="`";

		else if(code == 8220)

			replaceWith ="\"";

		else if(code == 8221)

			replaceWith ="\"";

		else if(code == 8211)

			replaceWith ="-";

		else if(code == 9)

			replaceWith ="  ";

		else if(code == 8230)

			replaceWith =".";

		else

			replaceWith =" ";

	

		temp = str.substring(0,i) +replaceWith + str.substring(i+1,str.length);		

	return temp;

}



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++)

    {   

        // Check that current character isn't whitespace.

        var c = s.charAt(i);

        if (bag.indexOf(c) == -1) returnString += c;

    }

    return returnString;

}



function checkPhone(strPhone){

s=stripCharsInBag(strPhone,validWorldPhoneChars);

if (s.length == 0)

	return true;

else 

	return false;

}

function checkNumbers(strPhone){

s=stripCharsInBag(strPhone,validNumbers);

if (s.length == 0)

	return true;

else 

	return false;

}

function checkcity(sText)

{

    var ValidChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ";

    var IsNumber=true;

    var Char;

	if(sText.length==0)	

	{

	  return false;

	}

	else

	{

    for (i = 0; i < sText.length && IsNumber == true; i++) 

    { 

        Char = sText.charAt(i); 

        if (ValidChars.indexOf(Char) == -1) 

        {

            IsNumber = false;

        }

    }  

    return IsNumber;

   }	

}