function validate_alphanum(str,fieldname,required)
{
	str1 = str.value
//	reg = /\d/
	reg = /^([a-zA-Z0-9 ])+$/
	
	if ((required==1) || (str1!=""))
	{
		if (str1.length<1)
		{
			alert("BICSIE Help: \n\n Please enter a valid value for "+fieldname+"\n\n");
			str.focus();
			return 0;
		}
		
		if (!reg.test(str1))
		{
			alert("BICSIE Help: \n\n"+fieldname+" can have only alpha numeric characters\n\n");
			str.focus();
			return 0;
		}

	}
}

////////////////////	Validates the APN number format /////////////////////

function validate_apnformat(num,apn)
{	
	reg1	= /[0-9]/
	reg2 = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/
	reg3	= /[A-Z]/
	
	var i=0;
	var num_array=num.value.split('-');
	var apn_array=apn.split('-');
	
	if(num_array.length!==apn_array.length) 
	{
		alert("Invalid APN# format");
		num.focus();
		return 0;
	}
	if((num_array[0].length	!== apn_array[0].length) || (num_array[1].length !== apn_array[1].length) || (num_array[2].length !== apn_array[2].length))
	{
		alert("Invalid APN# format");
		num.focus();
		return 0;
	}	

	if (reg3.test(apn_array[0]))
	{
		xobj 	= num_array[0].substr(3);
		yobj	= num_array[0].substr(0,3);
		
		if (!reg3.test(xobj))
		{
			alert("Invalid APN# format");
			num.focus();
			return 0;
		}
		if (!reg1.test(yobj))
		{
			alert("Invalid APN# format");
			num.focus();
			return 0;
		}
		xi = 1;
	}	
	else
	{
		xi = 0;
	}
	
	for (i=xi;i<num_array.length;i++) 
	{	
		
		if(!reg1.test(num_array[i]))
		{
			alert("Invalid APN# format");
			num.focus();
			return 0;
		}
		
		if(!reg2.test(num_array[i]))
		{
			alert("Invalid APN# format");
			num.focus();
			return 0;
		}		
	}
	return 1;
}



//	Checks if there is any alphabets if no then error

function validate_alphanumsp(str,fieldname,required)
{
	str1 = str.value
//	reg = /\d/
	reg = /[a-z0-9]/i
	
	if ((required==1) || (str1!=""))
	{
		if (str1.length<1)
		{
			alert("BICSIE Help: \n\n Please enter a valid value for "+fieldname+"\n\n");
			str.focus();
			return 0;
		}
		
		if (!reg.test(str1))
		{
			alert("BICSIE Help: \n\n"+fieldname+" must have atleast a single alphabet or number\n\n");
			str.focus();
			return 0;
		}

	}
}

function validate_word(field,alert_text,required)
{
	str	= field.value;
	
	reg_exp	= /\W/i;
	
	if ((str != '') || (required == 1))
	{
		
		if (str.length < 1)
		{
			alert(alert_text+' is mandatory');
			field.focus();
			return 0;
		}
		
		if (reg_exp.test(str))
		{
			alert(alert_text+' can have only alpha numerics and underscore (_)');
			field.focus();
			return 0;
		}
	}
}

function validate_radio(field,fieldname,required)
{
     if(getSelectedRadio(field) == -1)
     {
          alert("Please Select " + fieldname);
          field[0].focus();
          return 0;
     }
}

function getSelectedRadio(buttonGroup)
{
     
   // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) // if the button group is an array (one button is not an array)
   {
      for (var i=0; i<buttonGroup.length; i++)
      {
         
         if (buttonGroup[i].checked)
         {
            
            return i;
         }
      }
   }
   else
   {
    
      if (buttonGroup.checked) {
                                   return 0;
                                } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
} // Ends the "getSelectedRadio" function

function validate_date(in_date,fieldname,required)
{
	date_arr = in_date.split("/");

	if (date_arr.length > 0)
	{ 
		mon = date_arr[0];
		day = date_arr[1];
		yea = date_arr[2];
	}
	else
	{
		if (required == 0)
		{
			return 1;
		}
	}
	
//	if ((!mon) && (!day) && (!yea) && (required == 0))
	if ((mon==0) && (day==0) && (yea==0) && (required == 0))
	{
		return 1;
	}
	
	month_days = [31,28,31,30,31,30,31,31,30,31,30,31];

	reg=/\D/;

	if ((required==1) || (((date_arr[0]!="") || (date_arr[1]!="") || (date_arr[2]!="")) && (in_date!="")))
	{

		if ((mon==2) && ((yea%4)==0))
			month_days[1] = 29;

		if ((reg.test(mon)) || (reg.test(day)) || (reg.test(yea)))
		{
			alert("BICSIE Help: \n\n Please enter a valid date (mm/dd/yyyy) for "+fieldname+"\n\n");
			return 0;
		}
		if ( ((mon<1) || (mon>12)) || ((day<1) || (day>month_days[mon-1])) || (yea.length!=4))
		{
			alert("BICSIE Help: \n\n Please enter a valid date (mm/dd/yyyy) for "+fieldname+"\n\n");
			return 0;
		}
		return 1;
	}

}



function checkemail(field,fieldname,required)
{	// valid email check
	
	str	= field.value;
	
	var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
	var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
	var reg3 = /[a-zA-Z]/i;//--- should have atleast a single alphabet

	if ((required==1) || (str.length>0))
	{
		if ((!reg1.test(str)) && reg2.test(str) && (reg3.test(str))) // if syntax is valid
		{
		   return 1;//return true;
		}
		else
		{
			alert("BICSIE Help: \n\n Please enter Valid Email Account for " + fieldname+"\n\n" );
			field.focus();
			return 0;
		}
	}

}


function validate_number(num,fieldname,required)
{
	num1 = num.value;
//	reg_exp = /[0-9.]/g
	reg_exp = /^((\d+(\.\d*)?)|((\d*\.)?\d+))$/

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (num1=="")
		{
			alert("BICSIE Help: \n\n "+fieldname+" is mandatory\n\n");
			num.focus();
			return 0;
		}

		if (!reg_exp.test(num1))
		{
			alert("BICSIE Help: \n\n Can not have strings in "+fieldname+"\n\n");
			num.focus()
			return 0;
		}

		num1 = parseInt(num1)
		if (isNaN(num1))
		{
			alert("BICSIE Help: \n\n Please enter a valid number for "+fieldname+"\n\n");
			num.focus();
			return 0;
		}
	}


}

function validate_ndigit(num,fieldname,digits,required)
{
	num1 = num.value;
	reg_exp = /[^0-9.]/g

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (reg_exp.test(num1))
		{
			alert("Can not have strings in "+fieldname);
			num.focus()
			return 0;
		}

		if (isNaN(num1))
		{
			alert("Please enter a valid number for "+fieldname);
			num.focus();
			return 0;
		}
		if (num1.length!=digits)
		{
			alert("Please enter a "+digits+" digit number for "+fieldname);
			num.focus();
			return 0;
		}
	}
}

function validate_range(num,fieldname,low_val,high_val,required)
{

	num1 = num.value;
	reg_exp = /[^0-9.]/g

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (reg_exp.test(num1))
		{
			alert("Can not have strings in "+fieldname);
			num.focus()
			return 0;
		}

		if (isNaN(num1))
		{
			alert("Please enter a valid number for "+fieldname);
			num.focus();
			return 0;
		}
		if ((num1<low_val) || (num1>high_val))
		{
			alert("Range for "+fieldname+" is invalid.");
			num.focus();
			return 0;
		}
	}
}

function validate_integer(num,fieldname,required)
{
	num1 = num.value;
	reg_exp = /[^0-9]/g

//	reg_exp=/(^\d+$)|(^\d+\.\d+$)/

	if ((required==1) || (num1.length>0))
	{
		if (reg_exp.test(num1))
		{
			alert("BICSIE Help: \n\nCan not have strings in "+fieldname+"\n\n");
			num.focus()
			return 0;
		}

		if ((isNaN(num1)) || (num1.length<1))
		{
			alert("BICSIE Help: \n\nPlease enter a valid number for "+fieldname+"\n\n");
			num.focus();
			return 0;
		}
	}
}


function validate_string(str,fieldname,required)
{
	str1 = str.value
	reg = /\d/
	
	sp_reg	= /\S/
	
	if ((required==1) || (str1.length>0))
	{
		if (reg.test(str1))
		{
			alert(" BICSIE Help: \n\n Can not have numbers in "+fieldname+"\n\n");
			str.focus();
			return 0;
		}
		if (str1.length<1)
		{
			alert("BICSIE Help: \n\n"+fieldname+" is mandatory\n\n");
			str.focus();
			return 0;
		}
		
		if (!sp_reg.test(str1))
		{
			alert("BICSIE Help: \n\n Please enter a valid entry for "+fieldname+"\n\n");
			str.focus();
			return 0;
		}
	}
}



function validate_url(field,display,required)
{
	if ((field.value!="") || (required==1))
	{
		web=field.value;
  		s1=web.substring(0,10);
		dot=web.substring(10,11);
	  	s2=s1.toLowerCase();

		if(s2!="http://www" || dot!=".")
		{
			alert(display+" URL is invalid\n Usage: www.yourURLsitename.com ");
			field.focus();
			return 0;
		}
	}
 }


function validate_datetime(date_time,fieldname,required)
{  
	if ((required == 1) || (date_time.value != ''))
	{
		if ((date_time.value == '') && (required == 1))
		{
			alert(fieldname+' is mandatory');
			return 0;
		}
		
		
		vdate_time = date_time.value.split(" ");

		if (vdate_time.length != 2)
		{
			alert('Invalid date time format for '+fieldname+' \nValid Format : mm/dd/yyyy hh:mm:ss');
			date_time.focus();	
			return 0;
		}	 
	

		vdt	=  vdate_time[0];
	
		flag	= validate_date(vdt,fieldname,1);
	
		if (flag == 0)
		{
			date_time.focus();
			return false;
		}

		if (vdate_time[1] != '')
		{
			vtime	= vdate_time[1];
			vtime	= vtime.split(":");
	
			if (vtime.length == 3)
			{
				vhours	= vtime[0] * 1;
				vmin	= vtime[1] * 1;
				vsec	= vtime[2] * 1;

				if ((vhours > 23) || (vhours < 0) || (isNaN(vhours)) )
				{
					alert('Invalid Hour.Please Enter Hour Between Zero and 23');
					date_time.focus();
					return 0;
				}
			
				if ((vmin > 59) || (vmin < 0) || (isNaN(vmin)) )
				{
					alert('Invalid Minutes.Please Enter Minutes Between Zero and 59');
					date_time.focus();
					return 0;	
				}
			
				if ((vsec > 59) || (vsec < 0) || (isNaN(vsec)) )
				{
	 				alert('Invalid Seconds.Please Enter Seconds Between Zero and 59');
					date_time.focus();
					return 0;	
				}
			}
			else
			{
				alert('Please Enter Proper Time Format For '+fieldname +'  \n\t\tFormat hh:mm:ss');
				date_time.focus();
				return 0;	
			}
		}
		else
		{
			alert('Please Enter Time For '+fieldname +'  \n\tFormat hh:mm:ss');			date_time.focus();
			return 0;
		}

	}
}

function pull_datechk(tmp_month,tmp_day,tmp_year,disp_val,required)
{

	if (((tmp_month.value!='') || (tmp_day.value!='') || (tmp_year.value!='')) || (required == 1))
	{

		if (tmp_month.value == '')
		{
			alert('Please select the month for '+disp_val);
			tmp_month.focus();
			return false;
		}

		if (tmp_day.value == '')
		{
			alert('Please select the day for '+disp_val);
			tmp_day.focus();
			return false;
		}

		if (tmp_year.value == '')
		{
			alert('Please select the year for '+disp_val);
			tmp_year.focus();
			return false;
		}

		dt=new Date(tmp_year.value,tmp_month.value-1,tmp_day.value);	

		temp_day=dt.getDate();

		if (temp_day!=(tmp_day.value))
		{
			alert("Please select valid date for "+disp_val);
			tmp_month.focus();	
			return 0;
		}
	}

}

function validate_password(str,fieldname,required)
{
	str1 = str.value
	
	reg	= /\s/
	
	if ((required==1) || (str1.length>0))
	{
		if (reg.test(str1))
		{
			alert("Can not have spaces in "+fieldname);
			str.focus();
			return 0;
		}
		if (str1.length<1)
		{
			alert(fieldname+" is mandatory");
			str.focus();
			return 0;
		}
	}

}

function validate_zip(zip1,zip2,display,required)
{
	reg_zip1 = /^[a-zA-Z0-9]+$/
	reg_zip2 = /^[a-zA-Z0-9]+$/ 		// both zip1 and zip2 contains alphanumeric values
	
	zip1val = zip1.value;
	zip2val = zip2.value;
	
	if ((required==1) || ((zip1val!="") || (zip2val!="")))
	{
		if (zip1.value=="")
		{
			alert("Please enter value for "+display+" Zip1");
			zip1.focus();
			return 0;
		}

/*		
		if (zip2.value=="")
		{
			alert("Please enter value for "+display+" Zip2");
			zip2.focus();
			return 0;
		}
*/		

		if (zip1val.length>5)
		{
			alert(display+" Zip1 length is invalid");
			zip1.focus();
			return 0;
		}

		if (zip2val.length>4)
		{
			alert(display+" Zip2 length is invalid");
			zip2.focus();
			return 0;
		}		
		
		if (!(reg_zip1.test(zip1val)))
		{
			alert("Invalid characters in "+display+" Zip1");
			zip1.focus();
			return 0;
		}

		if ( zip2.value!="" &&  !(reg_zip2.test(zip2val)))
		{
			alert("Invalid characters in "+display+" Zip2");
			zip2.focus();
			return 0;
		}
	}
}


//	Right trim

function rtrim_field(str)
{
	var spc_reg	= /\s*$/;
	
	mat	= str.match(spc_reg);
	str	= str.replace(mat,'');

	return str;
}

//	Left trim

function ltrim_field(str)
{
	var spc_reg	= /^\s*/;
	
	mat	= str.match(spc_reg);
	str	= str.replace(mat,'');

	return str;
}

//	Trim

function trim_field(str)
{
	str	= rtrim_field(str);
	
	str	= ltrim_field(str);
	
	return str;
}


// credit card expiration month validation

function credit_exp_validation(temp_month,temp_year,req)
{

	today_date		= new Date();

	today_month		= today_date.getMonth();

	today_year		= today_date.getYear();

	today_month		= (today_month * 1) + 1;

	if((temp_month.value == '') && (req == '1'))
	{
		alert('BICSIE Help: \n\nPlease select the credit card expiration month\n\n');
		temp_month.focus();
		return false;
	}

	if((temp_year.value == '') && (req == '1'))
	{
		alert('BICSIE Help: \n\nPlease select the credit card expiration year\n\n');
		temp_year.focus();
		return false;
	}

	if ((temp_month.value < today_month) && (temp_month.value != '') && (temp_year.value==today_year))
	{
		alert('BICSIE Help: \n\nPlease select valid credit card expiration month\n\n');
		temp_month.focus();
		return false;
	}

	if((temp_year.value < today_year) && (temp_year.value != ''))
	{
		alert('BICSIE Help: \n\nPlease select valid credit card expiration year\n\n');
		temp_year.focus();
		return false;
	}
}

function validate_time(fname,dname,req)
{
	
	fval	= fname.value;
	
	reg_exp	= /[^0-9:]/;
	
	if (reg_exp.test(fval))
	{
		alert('Invalid time format for "'+dname+'".\nValid format hh:mm:ss');
		fname.focus();
		return false;
	}
	
	pecs	= fval.split(':');
	
	if (pecs.length != 3)
	{
		alert('Invalid time format for "'+dname+'".\nValid format hh:mm:ss (24 hour format)');
		fname.focus();
		return false;
	}
	
	if ((pecs[0].value>23) || (pecs[1].value > 60) || (pecs[2].value > 60))
	{
		alert('Please enter time in 24 hour format for "'+dname+'".\nValid format hh:mm:ss');
		fname.focus();
		return false;
	}
}
function newwindow(path)
{
//	self.close();
	var display=path;
	var win2=window.open(display,'_new','left=1,right=1,top=0,width=750,height=400,toolbar=no,menubar=yes,scrollbars=yes,status=no,resizable=yes,location=no');
}



function check_for_date(flag,fromdate,frommonth,fromyear,todate,tomonth,toyear)
{
     fromMon = frommonth;
     toMon = tomonth;
     fyear = fromyear;
     fday = fromdate;
     tday = todate;

     var MonthArray = Array('January','February','March','April','May','June','July','August','September','October','November','December');

     fobj_date = new Date(Date.UTC(fromyear, fromMon, fromdate, 0, 0, 0));
     ftimeA = new Date(fromyear,frommonth,1);
     ftimeDiff = ftimeA ;


     ftimeB = new Date(ftimeDiff);
     fcDate = ftimeB.getDate();
    
     fcYear = ftimeB.getFullYear();
     
     fcMonth_temp = ftimeB.getMonth();
     fcMonth = MonthArray[fcMonth_temp];

     tobj_date = new Date(Date.UTC(toyear, toMon, todate, 0, 0, 0));
     ttimeA = new Date(toyear,tomonth,1);
     ttimeDiff = ttimeA;
     ttimeB = new Date(ttimeDiff);
     tcDate = ttimeB.getDate();
     tcYear = ttimeB.getFullYear();
    
     tcMonth_temp = ttimeB.getMonth();
     tcMonth = MonthArray[tcMonth_temp];

     dateDiff = tobj_date - fobj_date;

     startdate = new Date(Date.UTC(2005, 11, 01, 0, 0, 0));
     startdateA = new Date(2005,12,1);
     startdatediff = startdateA;


     enddate = new Date(Date.UTC(2006, 05, 31, 0, 0, 0));
     enddateA = new Date(2020,06,1);
     enddatediff = enddateA ;
     
     fbdate = fobj_date.getDate();
     tbdate = tobj_date.getDate();
     fbmonth = fobj_date.getMonth();
     tbmonth = tobj_date.getMonth();
     fbyear = fobj_date.getYear();
     tbyear = tobj_date.getYear();
     
     bdateDiff = tbdate - fbdate;

     var currentDate = new Date();
     cbdate = currentDate.getDate();
     cbmonth = currentDate.getMonth();
     cbmonth_temp = currentDate.getMonth();
     cbyear = currentDate.getYear();
     cbmonth = cbmonth + 1;

     if(cbmonth < 10)
          cbmonth = '0'+cbmonth;

     if(fbyear < cbyear)
     {
          alert(cNoCurrDate);
          document.all.fromdate.value = cbdate;
          document.all.frommonth.value = cbmonth;
          document.all.fromyear.value = cbyear;
          return false;
     }
     if(fbyear == cbyear && fbmonth < cbmonth_temp)
     {
          alert(cNoCurrDate);
          document.all.fromdate.value = cbdate;
          document.all.frommonth.value = cbmonth;
          document.all.fromyear.value = cbyear;
          return false;
     }
     if(fbyear == cbyear && fbmonth == cbmonth_temp && fbdate < cbdate)
     {
          alert(cNoCurrDate);
          document.all.fromdate.value = cbdate;
          document.all.frommonth.value = cbmonth;
          document.all.fromyear.value = cbyear;
          return false;
     }
     alert(startdatediff);return false;
     if((ftimeDiff<startdatediff) || (ttimeDiff>enddatediff))
     {
          alert("Your dates are outside the 2005/2006 winter season.  The standard  winter season runs from 1st Dec 2005 - 31st May 2006.  Please try some new dates");
               
              
          return false;
     }    
}
function validdate(temp_month,temp_date,temp_year,temp_month1,temp_date1,temp_year1)
{

     month = temp_month;
     date  = temp_date;
     year  = temp_year;
     month1 = temp_month1;
     date1 = temp_date1;
     year1 = temp_year1;


     if(year1 < year)
     {

          alert(cSelectValidYear);
          temp_year1.focus();
          return false;
      }
      if(date1 < date)
      {

          alert(cSelectValidDate);
          temp_date1.focus();
          return false;
      }
      if(month1 < month)
      {

          alert(cSelectValidMonth);
          temp_month1.focus();
          return false;
      }

}

