function deleteBlanks_1(entry)
{
	var len = entry.length ;
	var foundBlank = 1;
	while(foundBlank == 1 && len > 0) 
	{
		var indx = entry.indexOf(" ");
		if(indx == -1) 
			foundBlank = 0 ;
		else
			entry = entry.substring(0,indx) + entry.substring(indx+1,len);
		len = entry.length;
	}
	return entry;
}
function checktel(tel,valname)
{
	val1=tel.value;
	if (val1!="")
	{
		for (var i=0;i<val1.length;i++)
		{
			var val = val1.charAt(i);
			if ((val1.length<12 ) || (i!=7 && i!=3 && (val<"0" || val>"9") ) || ( (i==3 || i==7) && val!="-" ))
			{
				alert("Please enter "+ valname + " in the format 999-999-9999");
				tel.focus();
				tel.select();
				return false;
			}
		}
	}
	return true;
}

function isEmpty_1(val,valName)
{
	if (!deleteBlanks_1(val.value))
	{
		alert(valName + " is required");
		val.focus();
		return false;	
	}
	return true;
}

function isEmail_1(val)
{
	tmp = val.value;
	if (isEmpty_1(val,"Email Address"))
	{
		if (tmp.indexOf("@")<1 || tmp.indexOf(".")<1 || tmp.indexOf(".")>eval(tmp.length)-3 || tmp.length<6)
		{
			alert("Email Address is invalid")
			val.focus();
			val.select();
			return false;	
		}
	}
	else
		return false;
	return true;
}


// function added by team 08th Nov 2007.
function isValidText(frmElement, fieldName)
{
	myRegExp = new RegExp("[^a-z,\\s]", "i"); 
	if(myRegExp.test(frmElement.value)) {
		alert("Only Alphabets are allowed in " + fieldName);
		frmElement.focus();
		frmElement.select();
		retVal = false;
	}
	else {
		retVal = true;
	}
	return retVal;
}

function isTel(val1,val2,val3,valName) {
	inv=0;
	v=val1.value+val2.value+val3.value;
	if (v!="") {
		if (v.length<10)
			inv=1;
		for (var i=0;i<v.length && inv==0;i++) {
			if ( v.charAt(i)<"0" || v.charAt(i)>"9")
				inv=1;
		}
		if (inv==1) {
			//alert (valName + " is invalid")
			alert("Please enter "+ valName + " in the format 999-999-9999");
			val1.focus();
			val1.select();
			return false;
		}
	}
	return true;
}
// trim
function trim(str) 
{  if(str.charAt(0) == " ")
  {  str = trim(str.substring(1));
   }
  if (str.charAt(str.length-1) == " ")
  {  str = trim(str.substring(0,str.length-1));
  }
  return str;
}

// valid email 
function isEmail(val)
{
	var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	var returnval=emailfilter.test(val);
	return returnval;
}

// for contact
function redirect() {
	// form 
	var frm= document.myForm;
	
	//trim  existing values;
	frm.your_name.value=trim(frm.your_name.value);
	
	frm.email.value=trim(frm.email.value);	

	//checking for blanks;
	if (frm.your_name.value=='' || frm.your_name.value=='Your Name'){alert ('Name cannot be blank !!');frm.your_name.value='';frm.your_name.focus(); return false;}
	
	if (frm.email.value=='' || frm.email.value=='Your Email'){alert ('Email cannot be blank !!');frm.email.value='';frm.email.focus(); return false;}	
	
	
	
	
	
	if (frm.email.value==''){alert ('You must provide email');frm.email.focus(); return false;}
	if (!isEmail(frm.email.value)){alert('Invalid Email !!!');frm.email.focus(); return false;}
	


	//submit1, B1;
	return true;

}





/* for date validation */
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 strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
/*
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=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 : yyyy-mm-dd")
		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 isFuture(fDate)
{
	var a = new Date();
	var s =	fDate.split("/");	
	var frDate	=	new Date(s[2],s[0]-1,s[1]);	
	if (frDate>=a) return true; else return false;
}

function isGreater(fDate,fTDate)
{
	var s =	fDate.split("/");	
	var frDate	=	new Date(s[2],s[0]-1,s[1]);	
	var s1 =	fTDate.split("/");	
	var frDate1	=	new Date(s1[2],s1[0]-1,s1[1]);	
	if (frDate>=frDate1) return true; else return false;
}
