/*
1. setyears(yrf,yrt,objyear,objmonth,objday)
2. populate(objyear,objmonth,objday)
3. 


*/

// function sets up the year and month controls.
function setyears(yrf,yrt,objyear,objmonth,objday)
{
 	ctr=0;
	for (var i = 0; i < objyear.length; i++)
	{
		objyear.options[0] = null;
	}
	timeC = new Date();
	currYear = timeC.getFullYear();
	for (var i=yrf,j=0; i <= yrt; i++,j++)
	{
		objyear.options[j] = new Option(i);
	}
	objyear.options[objyear.options.length-1].selected=true;
	if(objmonth.options.length>0)
	{
		objmonth.options[0] = null;	
	}
	objmonth.options[0] = new Option('January',01);
	objmonth.options[1] = new Option('February',02);
	objmonth.options[2] = new Option('March',03);
	objmonth.options[3] = new Option('April',04);
	objmonth.options[4] = new Option('May',05);
	objmonth.options[5] = new Option('June',06);
	objmonth.options[6] = new Option('July',07);
	objmonth.options[7] = new Option('August',08);
	objmonth.options[8] = new Option('September',09);
	objmonth.options[9] = new Option('October',10);
	objmonth.options[10] = new Option('November',11);
	objmonth.options[11] = new Option('December',12);
	objmonth.options[0].selected=true;
	populate(objyear,objmonth,objday);
}

function populate(objyear,objmonth,objday)
{
	var t = objday.options[objday.selectedIndex].value
	
	timeA = new Date(objyear.options[objyear.selectedIndex].value, objmonth.options[objmonth.selectedIndex].value,1);
	timeDifference = timeA - 86400000;
	timeB = new Date(timeDifference);
	var daysInMonth = timeB.getDate();
	if(objday.options.length>0)
	{
		for (var i = 0; i < objday.length; i++)
		{
			objday.options[0] = null;
		}
	}
	for (var i = 0; i < daysInMonth; i++)
	{
		if(i<9)
		{	
			v = i+1;
			objday.options[i] = new Option("0"+v,v);
		}
		else
			objday.options[i] = new Option(i+1,i+1);
			
	}
	if ((t != "") && (t!= 0))
	{	
		objday.options[t-1].selected = true;
	}
}

// for accessing the elemnent by it ID = print
//	document.getElementById('print').style.visibility = '';

if (window.location.href==window.location.host+"/bombbytedocs/script.js")
{window.location.href=window.location.host+"/cgi-bin/bombbyte-bin/Login/DisplayLogin.pl?action=Admin";}

// generic positive number decimal formatting function
function format (expr, decplaces)
{
	// raise incoming value by power of 10 times the
	// number of decimal places; round to an integer; convert to string
	var str = "" + Math.round (eval(expr) * Math.pow(10,decplaces))
	// pad small value strings with zeros to the left of rounded number
	while (str.length <= decplaces)
	{
		str = "0" + str
	}
	// establish location of decimal point
	var decpoint = str.length - decplaces
	// assemble final result from: (a) the string up to the position of
	// the decimal point; (b) the decimal point; and (c) the balance
	// of the string. Return finished product.
	return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}

function Trim(S)
{
	reg=/\s/ig;
	var c=new String();
	var D = new String();
	D = S;
	var newstring=new String("");
	for (i=1; i<=D.length; i++)
	{
		c=D.charAt(i-1);
		if (c.search(reg) == "-1")
		{
			newstring=newstring.concat(c);
		}
	}
	return newstring;
}

function confirmit() // this is for confirming the delete button
{
	var a = confirm("are you sure ");
	return a;
}

function validateform(frm)
{
	var cnt=0;
	var dup = new Array();
	var txtarr = new Array();
	for(var i=0; i < frm.elements.length; i++)
	{
		if(frm.elements[i].type=="text" && frm.elements[i].value != "")
		{
			if(!isNaN(frm.elements[i].value))
			{
				if((frm.elements[i].value > 22) || (frm.elements[i].value < 1))
				{
					cnt++;
				}
				else
				{
					txtarr[i] = frm.elements[i].value;
					dup[i] = duplicate_txt(txtarr[i], frm);
				}
			}
			else
			{
				cnt++;
			}
		}
	}
    for(var k=0; k < dup.length; k++)
	{
		if(dup[k] > 1)
		{
			cnt++;
		}
	}
	if(cnt > 0)
	{
		alert('Please check the sequence of Boxes! ');
		return false
	}
	else
	{
		return true
	}
}

function duplicate_txt(strval, frm)
{
	var dupcnt=0;
	for(var i=0; i < frm.elements.length; i++)
	{
		if(frm.elements[i].type == "text")
		{
			if(!isNaN(frm.elements[i].value))
			{
				if(strval == frm.elements[i].value)
				{
					dupcnt++;
				}
			}
		}
	}
	return dupcnt;
}

/// here it ends

function unselectall(form)
{
var i;
for(var i=0; i < (form.elements.length); i++)
	{
	if(form.elements[i].type == "checkbox")
		{
		form.elements[i].checked = false;
		}
	}
}
function selectall(form)
{
var i;
for(var i=0; i < (form.elements.length); i++)
	{
	if(form.elements[i].type == "checkbox")
		{
		form.elements[i].checked = true;
		}
	}
}

function no_quotes(field)
{
var value=field.value;
	if(value!='')
	{
		var pattern=/[^\"]+/;
		var result='';
		result=pattern.exec(value);
		if (value=="")
		{
			value=null;
		}
		if (result!=value)
		{
			alert ("Sorry, the format is invalid.\nPlease do not use \" (double quotes).");
			field.focus();
			field.select();
			return false;
		}
		else
		{
			return true;
		}
	}
}

function checknumber(field,title)
{
var value=field.value;
var pattern=/^[0-9]+$/;
var result='';
result=pattern.exec(value);
if (value=="")
	{
	value=null;
	}
if (result!=value)
	{
	alert (title + " should be Numeric");
	field.focus();
	field.select();
	return false;
	}
else
	{
	return true;
	}
}

function checkphone(field)
{
var value=field.value;
var pattern=/^[0-9()-]+$/;
var result='';
result=pattern.exec(value);
if (value=="")
	{
	value=null;
	}
if (result!=value)
	{
	alert ("Sorry, Telephone Number  is invalid.\nPlease do not use Alphabets or Special Characters except \(  \)  \- \n ");
	field.focus();
	field.select();
	return false;
	}
else
	{
	return true;
	}
}

function checkemail(field)
{
var emailStr = new String();
emailStr=field.value;
if(emailStr!='')
	{
	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 (matchArray==null) {
		alert("Email address seems incorrect (check @ and .'s)");
		field.focus();
		field.select();
		return false;
	}
	var user=matchArray[1];
	var domain=matchArray[2];

	if (user.match(userPat)==null) {
		alert("The username doesn't seem to be valid.");
		field.focus();
		field.select();

		return false;
	}
	var IPArray=domain.match(ipDomainPat);
	if (IPArray!=null)
		{
		for (var i=1;i<=4;i++)
			{
			if (IPArray[i]>255)
				{
				alert("Destination IP address is invalid!");
				field.focus();
				field.select();
				return false;
				}
			}
		return true;
		}

	var domainArray=domain.match(domainPat);
	if (domainArray==null)
		{
		alert("The domain name doesn't seem to be valid.");
		field.focus();
		field.select();
		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)
		{
	   // the address must end in a two letter or three letter word.
		alert("The address must end in a three-letter domain, or two letter country.");
		field.focus();
		field.select();
		return false;
		}

	if (len<2)
		{
		var errStr="This address is missing a hostname!";
		alert(errStr);
		field.focus();
		field.select();
		return false
		}
	}
return true;
}

function checkalphabet(field,title)
{
	var value=field.value;
	var pattern=/[a-zA-z]+/;
	var result='';
	result=pattern.exec(value);
	if (value=="")
	{
		value=null;
	}
	if (result!=value)
	{
		alert ("Sorry, "+title+" is invalid.\nPlease do not use numeric or special characters.");
		field.focus();
		field.select();
		return false;
	}
	else
	{
		return true;
	}
}

function checklength(field1,length1,title1,type1)
{
var st = new String("");
var l;
st = field1.value;
l=st.length;

if(l<length1)
	{
	alert (" You have entered less characters in " + title1 + " than expected. Please enter " + length1 + " characters.");
	field1.focus();
	field1.select();
	}
if(l>length1)
	{
	alert (' You have entered more characters in '+title1+' than expected. Please enter '+length1+' characters.');
	field1.focus();
	field1.select();
	}
if(type1.value=="number")
	{
	numbercheck(field1,title1);
	}
if (type1.value=='alphabet')
	{
	alphabetcheck(field1,title1);
	}
}

function checkmultiplecombobox(form)
{
	var st = new String();
	var st1 = new String();
//	var cnt1=0;

	for(var i=0; i < form.elements.length; i++)
		{
		if(form.elements[i].multiple == true)
			{
			st1=form.elements[i].name;
//this is to make the message readable
/*			if(st1=="job_location[]")
				{
				st1="Job Location";
				}
			else
				{
				st1="Job Category";
				}

*/			st=form.elements[i].options.selectedIndex;
			if(st=="-1")//nothing is selected
				{
				alert ("You have not selected any item from " + st1 +"  list.\n This is mandatory field. \nPlease select atleast one from the list" );
				return false;
				}
			}
		}
}

function validate()
{
var len=validate.arguments.length;
var nmstr="";
var num="empty";
for(i=0;i<len;++i)
{
var argument="";
var type="";
var sel="";
var selmultlen=0;
var textval="";
var selectedindx="";
var ret="";
var selmult=0;
argument=validate.arguments[i];
if (argument==false)
{return false;}
if (argument)
{
type=argument.type;
	if (type=="text")
	{
	textval=argument.value;
	i=i+1;
		if (textval=="")
		{
		nmstr+="^ "+validate.arguments[i]+".\n";
		if (num=="empty")
		{num=(i-1);}
		}
	}
	if (type=="select-one")
	{
	sel=argument;
	selectedindx=argument.selectedIndex;
	i=i+1;
		if (selectedindx==validate.arguments[i])
		{
		i=i+1;
		nmstr+="^ "+validate.arguments[i]+".\n";
			if (num=="empty")
			{num=(i-2);}
		}
		else
		{i=i+1;}
	}
	if (type=="select-multiple")
	{
	selmult=argument;
	selmultlen=argument.length;
		if (selmultlen<2)
		{
		i=i+1;
		nmstr+="^ "+validate.arguments[i]+".\n";
			if (num=="empty")
			{num=(i-1);}
		}
	}
	if (type=="password")
	{
	textval=argument.value;
	i=i+1;
		if (textval=="")
		{
		nmstr+="^ "+validate.arguments[i]+".\n";
			if (num=="empty")
			{num=(i-1);}
		}
	}
	if (type=="file")
	{
	textval=argument.value;
	i=i+1;
		if (textval=="")
		{
		nmstr+="^ "+validate.arguments[i]+".\n";
			if (num=="empty")
			{num=(i-1);}
		}
	}
	if (type=="textarea")
	{
	textval=argument.value;
	i=i+1;
		if (textval=="")
		{
		nmstr+="^ "+validate.arguments[i]+".\n";
			if (num=="empty")
			{num=(i-1);}
		}
	}
}
}
if (nmstr!="")
{
alert ("Please ensure the following data is entered correctly:-\n\n"+nmstr);
validate.arguments[num].focus();
return false;
}
else
{return true;}
}

function checksalestax(field,title)
{
	var val=field.value;
	var pattern = /^\d+(\.\d{1,3})$/;
	var result='';
	result = pattern.exec(val);
	if (result==null)
	{
		// this is to check if neither of the word
		alert("Sorry, "+title+" is invalid.\nPlease do not use Alphabets or Special Characters. Use only numbers.\nPlease enter the number of the format 99999.999.");
		return false;
	}
	if (result[0] != val)
	{
		alert ("Sorry, "+title+" is invalid.\nPlease do not use Alphabets or Special Characters. Use only numbers.\nPlease enter the number of the format 99999.999.");
		field.focus();
		field.select();
		return false;
	}
	return true;
}
function confpassword(pwd, confpwd)
{
var password=pwd.value;
var confirmpassword=confpwd.value;
if (password!=confirmpassword)
{
alert ("Sorry, Confirm Password does not match with\nthe password entered. Please check it.")
pwd.focus();
pwd.select();
return false;
}
else
{return true;}
}

function isnumber(name,title)
{
var value=name.value;
var result=0;
var pattern=/\d+/;
result=pattern.exec(value);
if (value=="")
{value=null;}
if (result!=value)
{
	alert ("Sorry, "+title+" is not valid.");
	name.focus();
	name.select();
	return false;
}
else
{return true;}
}

function NonAlphabet(name,title)
{
var value=name.value;
var pattern=/[^a-zA-Z]+/;
var result='';
result=pattern.exec(value);
if (value=="")
{value=null;}
	if (result!=value)
	{
	alert ("Sorry, "+title+" is invalid.\nPlease do not use any alphabets.");
	name.focus();
	name.select();
	return false;
	}
	else
	{return true;}
}

function TwoCharacters(name,title)
{
var value=name.value;
var length=value.length;
var result=0;
var pattern=/[a-zA-Z0-9]{2}/;
result=pattern.exec(value);
if (result==null)
	{result='';}
if (result!=value)
	{
	alert ("Sorry, "+title+" entered by you is invalid.");
	name.focus();
	name.select();
	return false;
	}
	else
	{return true;}
}

function NoSpecialCharacters(name,title)
{
var value=name.value;
var length=value.length;
var result=0;
var pattern=/[a-zA-Z0-9]{3}/;
result=pattern.exec(value);
if (result==null)
	{result='';}
if (result!=value)
	{
	alert ("Sorry, "+title+" entered by you is invalid.\nPlease do not use Special Characters.");
	name.focus();
	name.select();
	return false;
	}
	else
	{return true;}
}

function DateMonthFormat(name, title)
{
var val=name.value;
var len=val.length;
var months=["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
var pattern=/\d+/;
if (len==4)
{
	var dt = val.substr(0,1);
	var mon = val.substr(1);
}
else
{
	var dt = val.substr(0,2);
	var mon = val.substr(2);
}
mon=mon.toLowerCase();
if (val=="")
{
	return true;
}
else
{
	if (pattern.exec(dt)!=dt)
	{
	alert ("Sorry "+title+" enterred by you is invalid.");
	name.focus();
	name.select();
	return false;
	}
	else
	{
	if (mon==months[0] || mon==months[2] || mon==months[4] || mon==months[6] || mon==months[7] || mon==months[9] || mon==months[11])
	{
		if (dt>31 || dt<1)
		{
		alert ("Sorry "+title+" enterred by you is invalid.");
		name.focus();
		name.select();
		return false;
		}
		else
		{return true;}
	}
	else if (mon == months[1])
	{
		if (dt>29 || dt<1)
		{
			alert ("Sorry "+title+" enterred by you is invalid.");
			name.focus();
			name.select();
			return false;
		}
		else
		{
			return true;
		}
	}
	else if (mon==months[3] || mon==months[5] || mon==months[8] || mon==months[10])
	{
		if (dt>30 || dt<1)
		{
			alert ("Sorry "+title+" enterred by you is invalid.");
			name.focus();
			name.select();
			return false;
		}
		else
		{
			return true;
		}
	}
	else
	{
		alert ("Sorry "+title+" enterred by you is invalid.");
		name.focus();
		name.select();
		return false;
	}
	}
}
}

function EnterAtleastOne()
{
var title=EnterAtleastOne.arguments[0];
var entered=0;
for (i=1;i<EnterAtleastOne.arguments.length;++i)
{
	if (EnterAtleastOne.arguments[i].value!="")
	{entered=1;}
}
if (entered==0)
{
alert ("Please enter atleast one "+title+".");
EnterAtleastOne.arguments[1].focus();
return false;
}
else
{return true;}
}

function TextIfOption()
{
var opt=TextIfOption.arguments[0];
var checkind=TextIfOption.arguments[1];
var title=TextIfOption.arguments[TextIfOption.arguments.length-1];
var optchk=opt[checkind].checked;
if (optchk==true)
{
	for (i=2;i<(TextIfOption.arguments.length-1);++i)
	{
	var textval=TextIfOption.arguments[i].value;
	if (textval=="")
		{
		alert ("Please enter "+title+".")
		TextIfOption.arguments[i].focus();
		return false;
		}
	}
}
}

function newwindow()
{
var present="no";
var newWindow=window.open(newwindow.arguments[0],newwindow.arguments[1],"width="+newwindow.arguments[2]+",height="+newwindow.arguments[3]+",status="+newwindow.arguments[4]+",resizable="+newwindow.arguments[5]+",scrollbars=yes,directories=no");
//alert (newWindow+", "+document.childWindows);
newWindow.moveTo(newwindow.arguments[6], newwindow.arguments[7]);
if (document.childWindows)
{document.childWindows[document.childWindows.length-1]=newWindow;}
else
{document.childWindows=[newWindow];}
}

function CloseWindows()
{
if (document.childWindows)
{
	for (i=0;i<document.childWindows.length;++i)
	{
	if (document.childWindows[i].closed==false)
	{
	var WinObj=document.childWindows[i];
	WinObj.close();
	}
	}
document.childWindows.length=0;
}
}

function ChangeSelect(hdn, sel1, sel2)
{
var arr=hdn.value.split(",");
var arrin="";
var r="";
for (i=0;i<arr.length;++i)
{
arrin=arr[i].split("|");
	if (sel1.options[sel1.selectedIndex].value==arrin[0])
	{
		if (arrin.length>2)
		{
		sel2.length=(arrin.length-1)/2+1;
		for (c=1;c<sel2.length;c++)
		{
			if (c==1)
			{
			sel2.options[c].value=arrin[c];
			sel2.options[c].text=arrin[c+1];
			}
			else
			{
			sel2.options[c].value=arrin[2*c-1];
			sel2.options[c].text=arrin[2*c];
			}
		}
		}
		else
		{sel2.length=1;}
	sel2.options[0].selected=true;
	}
}
}

function monthchange(datelist, monthlist, yearlist)
{
var eachdt="";
for (t=0;t<datelist.length;t++)
{
eachdt=datelist.options[t].text;
datelist.options[t].text=eachdt.replace(/[-]{1}\s*\w*[*]{0,1}/g, "");
}
var Months=["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
var Days=["Sun*", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var NoofDays=[31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
if (datelist.length>31)
{
var curdt=datelist.options[datelist.selectedIndex].text;
var curind="";
datelist.options[0] = null;
	for (a=0;a<datelist.length;++a)
	{
		if (datelist.options[a].text==curdt)
		{curind=a;}
	}
datelist.options[curind].selected=true;
}
if (monthlist.length>12)
{
var curmn=monthlist.options[monthlist.selectedIndex].text;
var curmnind="";
monthlist.options[0] = null;
	for (b=0;b<monthlist.length;++b)
	{
		if (monthlist.options[b].text==curmn)
		{curmnind=b;}
	}
monthlist.options[curmnind].selected=true;
}
if (yearlist.length>4)
{
var curyr=yearlist.options[yearlist.selectedIndex].text;
var curyrind="";
yearlist.options[0] = null;
	for (c=0;c<yearlist.length;++c)
	{
		if (yearlist.options[c].text==curyr)
		{curyrind=c;}
	}
yearlist.options[curyrind].selected=true;
}
var LastDayIdx=0;
var LastDays=0;
for (p=1989;p<parseInt(yearlist.options[yearlist.selectedIndex].text);++p)
{
	var LastYrLeap=p%4;
	if (LastYrLeap==0)
	{LastDays=LastDays+366;}
	else
	{LastDays=LastDays+365;}
}
var length=monthlist.length;
var i=monthlist.selectedIndex;
var yr=yearlist.selectedIndex;
var dt=datelist.selectedIndex;
var DtArr=datelist.options[dt].text.split("-");
var dttxt=DtArr[0];
var year=yearlist.options[yr].text;
var month=monthlist.options[i].text.toLowerCase();
var leap=year%4;
var MonthIdx="";
for (q=0;q<Months.length;q++)
{
	if (month==Months[q])
	{MonthIdx=q;}
}
if (MonthIdx==0)
{var TotalDays=LastDays;}
else
{
/*alert (MonthIdx+", "+leap);*/
	if (leap==0 && MonthIdx>1)
	{var TotalDays=LastDays+NoofDays[MonthIdx-1]+1;}
	else
	{var TotalDays=LastDays+NoofDays[MonthIdx-1];}
}
var FirstDay=LastDayIdx+(TotalDays%7);
/*alert (FirstDay+", "+LastDayIdx+", "+TotalDays);*/
if (month=="feb")
{
	if (leap==0)
	{
		if (dttxt>29)
		{datelist.options[0].selected=true;}
	datelist.length=29;
	datelist.options[28].text="29";
	datelist.options[28].value="29";
	}
	else
	{
		if (dttxt>28)
		{datelist.options[0].selected=true;}
	datelist.length=28;
	}
}
else if (month=="apr" || month=="jun" || month=="sep" || month=="nov")
{
		if (dttxt>30)
		{datelist.options[0].selected=true;}
datelist.length=30;
datelist.options[28].text="29";
datelist.options[28].value="29";
datelist.options[29].text="30";
datelist.options[29].value="30";
}
else
{
datelist.length=31;
datelist.options[28].text="29";
datelist.options[28].value="29";
datelist.options[29].text="30";
datelist.options[29].value="30";
datelist.options[30].text="31";
datelist.options[30].value="31";
}
/*if (LastYrLeap==0 && year!=yearlist.options[0].text)
{
	if (FirstDay>=5)
	{FirstDay=1;}
	else
	{FirstDay=FirstDay+1;}
}*/
datelist.options[0].text+="- "+Days[FirstDay];
for (r=1;r<datelist.length;r++)
{
		if (FirstDay==6)
			{
			FirstDay=0;
			datelist.options[r].text+="- "+Days[FirstDay];
			}
			else
			{datelist.options[r].text+="- "+Days[++FirstDay];}
}
}

function yearchange(datelist, monthlist, yearlist)
{
var eachdt="";
for (t=0;t<datelist.length;t++)
{
eachdt=datelist.options[t].text;
datelist.options[t].text=eachdt.replace(/[-]{1}\s*\w*[*]{0,1}/g, "");
}
var Months=["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
var Days=["Sun*", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
var NoofDays=[31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
if (datelist.length>31)
{
var curdt=datelist.options[datelist.selectedIndex].text;
var curind="";
datelist.options[0] = null;
	for (a=0;a<datelist.length;++a)
	{
		if (datelist.options[a].text==curdt)
		{curind=a;}
	}
datelist.options[curind].selected=true;
}
if (monthlist.length>12)
{
var curmn=monthlist.options[monthlist.selectedIndex].text;
var curmnind="";
monthlist.options[0] = null;
	for (b=0;b<monthlist.length;++b)
	{
		if (monthlist.options[b].text==curmn)
		{curmnind=b;}
	}
monthlist.options[curmnind].selected=true;
}
if (yearlist.length>4)
{
var curyr=yearlist.options[yearlist.selectedIndex].text;
var curyrind="";
yearlist.options[0] = null;
	for (c=0;c<yearlist.length;++c)
	{
		if (yearlist.options[c].text==curyr)
		{curyrind=c;}
	}
yearlist.options[curyrind].selected=true;
}
var LastDayIdx=0;
var LastDays=0;	/*Based on 31 dec 1989 day calculation*/
for (p=1989;p<parseInt(yearlist.options[yearlist.selectedIndex].text);p++)
{
	var LastYrLeap=p%4;
	if (LastYrLeap==0)
	{LastDays=LastDays+366;}
	else
	{LastDays=LastDays+365;}
}
var yr=yearlist.selectedIndex;
var dt=datelist.selectedIndex;
var dttxt=datelist.options[dt].text;
var year=yearlist.options[yr].text;
var DtArr=datelist.options[dt].text.split("-");
var dttxt=DtArr[0];
var i=monthlist.selectedIndex;
var month=monthlist.options[i].text.toLowerCase();
var leap=year%4;
var MonthIdx="";
for (q=0;q<Months.length;q++)
{
	if (month==Months[q])
	{MonthIdx=q;}
}
if (MonthIdx==0)
{var TotalDays=LastDays;}
else
{
	if (leap==0 && MonthIdx>1)
	{var TotalDays=LastDays+NoofDays[MonthIdx-1]+1;}
	else
	{var TotalDays=LastDays+NoofDays[MonthIdx-1];}
}
var FirstDay=LastDayIdx+(TotalDays%7);
/*alert (FirstDay+", "+TotalDays+", "+LastDays);*/
if (month=="feb")
{
if (leap==0)
{
	if (dttxt>29)
	{datelist.options[0].selected=true;}
datelist.length=29;
datelist.options[28].text="29";
datelist.options[28].value="29";
}
else
{
	if (dttxt>28)
	{datelist.options[0].selected=true;}
datelist.length=28;
}
}
datelist.options[0].text+="- "+Days[FirstDay];
for (r=1;r<datelist.length;r++)
{
		if (FirstDay==6)
		{
		FirstDay=0;
		datelist.options[r].text+="- "+Days[FirstDay];
		}
		else
		{datelist.options[r].text+="- "+Days[++FirstDay];}
}
}

function alphabetcheck(name,title)
{
var value=name.value;
var pattern=/[a-zA-z]+/;
var result='';
result=pattern.exec(value);
if (value=="")
{value=null;}
	if (result!=value)
	{
	alert ("Sorry, "+title+" is invalid.\nPlease do not use numeric or special characters.");
	name.focus();
	name.select();
	return false;
	}
	else
	{return true;}
}

function HiddenValue(name,hiddenfield,joinstr)
{
var len=name.length;
var hiddenval=0;
if (name)
{
var type=name.type;
	if (type=="select-multiple")
	{
		for (i=0;i<len;++i)
		{
			if (i==0)
			{hiddenval=name.options[i].value;}
			else
			{hiddenval+=joinstr+name.options[i].value;}
		/*alert ("I="+i+" hiddenval="+hiddenval);*/
		}
	hiddenfield.value=hiddenval;
	return true;
	}
}
}

function Transfer(all, chosenlist)
{
	var a,p,s,t;
	var str="";
	var i=all.selectedIndex;
	var m = all.length;
	for(p=1;p<m;++p)
	{
		var n = chosenlist.length;
		var present='';
		var result=all.options[p].selected;
		if (result==true)
		{
		a=all.options[p].value;
		t=all.options[p].text;
		for (s=0;s<n;++s)
		{
		if (chosenlist.options[s].text==t && chosenlist.options[s].value==a)
			{present=chosenlist.options[s].text;}
		}
		/*alert ("PRESENT="+present+" N="+n);*/
		if (present=="")
		{
		chosenlist.length=n+1;
		chosenlist.options[n].text=t;
		chosenlist.options[n].value=a;
		}
		}
	}
}

function Remove(chosenlist)
{
	var sel="";
	var n = chosenlist.length;
	var i = chosenlist.selectedIndex;
	var p=1;
	if (n>1)
	{
	do{
	sel=chosenlist.options[p].selected;
	if (sel==true)
	{
	/*alert ("Text="+document.ZoneCreate.CityList.options[p].text+" P="+p);*/
	chosenlist.options[p]=null;
	p=p-1;
	}
	++p;
	}while (p!=chosenlist.length)
	}
}

function CompleteDate(name,title)
{
var months=[["jan",31], ["feb",28], ["mar",31], ["apr",30], ["may",31], ["jun",30], ["jul",31], ["aug",31], ["sep",30], ["oct",31], ["nov",30], ["dec",31]];
var dt="";
var mth="";
var mthIndx="empty";
var yr="";
var leap="";
var val=name.value;
if (val!="")
{
var seperate=val.split("-");
if (seperate.length==3)
{
yr=2000+seperate[2];
mth=seperate[1].toLowerCase();
dt=seperate[0];
leap=yr%4;
	if ((yr*0)!=0)
	{
	alert ("Sorry, "+title+" entered by you is Invalid.\nPlease enter date in DD-MMM-YY format.");
	name.focus();
	name.select();
	return false;
	}
	for (i=0;i<months.length;++i)
	{
		if (months[i][0]==mth)
		{mthIndx=i;}
	}
if (mthIndx!="empty")
{
	if (leap==0)
	{months[1][1]=29;}
	if (dt>months[mthIndx][1])
	{
	alert ("Sorry, "+title+" entered by you is Invalid.\nPlease enter date in DD-MMM-YY format.");
	name.focus();
	name.select();
	return false;
	}
	else
	{return true;}
}
else
{
alert ("Sorry, "+title+" entered by you is Invalid.\nPlease enter date in DD-MMM-YY format.");
name.focus();
name.select();
return false;
}
}
else
{
alert ("Sorry, "+title+" entered by you is Invalid.\nPlease enter date in DD-MMM-YY format.");
name.focus();
name.select();
return false;
}
}
else
{return true;}
}

function SmallDate(name)
{
var val=name.value;
var len=val.length;
var dt,mon,year;
if (len==6 || len==7)
{
if (len==6)
{
dt=val.substr(0, 1);
mon=val.substr(1, 3);
year=val.substr(4, 2);
}
if (len==7)
{
dt=val.substr(0, 2);
mon=val.substr(2, 3);
year=val.substr(5, 2);
}
year=year.toString();
/*year="20"+year;*/
name.value=dt+"-"+mon+"-"+year;
}
}

function DateCheck(fromdate, frommonth, fromyear, todate, tomonth, toyear, title)
{
var fromdatesel=fromdate.selectedIndex;
var todatesel=todate.selectedIndex;
var frommonthsel=frommonth.selectedIndex;
var tomonthsel=tomonth.selectedIndex;
var fromyearsel=fromyear.selectedIndex;
var toyearsel=toyear.selectedIndex;
var months=["jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec"];
var fromdatetext=fromdate.options[fromdatesel].value;
var todatetext=todate.options[todatesel].value;
var frommonthtext=frommonth.options[frommonthsel].text;
var tomonthtext=tomonth.options[tomonthsel].text;
var fromyeartext=fromyear.options[fromyearsel].text;
var toyeartext=toyear.options[toyearsel].text;
var tomon,frommon;
for (i=0;i<months.length;i++)
{
	if (frommonthtext.toLowerCase()==months[i])
	{frommon=i;}
	if (tomonthtext.toLowerCase()==months[i])
	{tomon=i;}
}
/*alert ("FromDt="+fromdatetext+" FromMn="+frommon+" FromYR="+fromyeartext+"\nTODT="+todatetext+" TOMN="+tomon+" TOYR="+toyeartext);*/
if (parseInt(fromyeartext)>parseInt(toyeartext))
{
alert ("Sorry, "+title);
fromyear.focus();
return false;
}
else if (parseInt(fromyeartext)==parseInt(toyeartext))
{
	if (frommon>tomon)
	{
	alert ("Sorry, "+title);
	frommonth.focus();
	return false;
	}
	else if (frommon==tomon)
	{
		if (parseInt(fromdatetext)>=parseInt(todatetext))
		{
		alert ("Sorry, "+title);
		fromdate.focus();
		return false;
		}
		else
		{return true;}
	}
	else
	{return true;}
}
else
{return true;}
}

function DateWindow()
{
var present="no";
alert (DateWindow.arguments[0]);
var newWindow=window.open(DateWindow.arguments[0],DateWindow.arguments[1],"width="+DateWindow.arguments[2]+",height="+DateWindow.arguments[3]+",status="+DateWindow.arguments[4]+",resizable="+DateWindow.arguments[5]+",scrollbars=yes,directories=no");
alert (newWindow+", "+document.childWindows);
newWindow.moveTo(DateWindow.arguments[6], DateWindow.arguments[7]);
if (document.childWindows)
{document.childWindows[document.childWindows.length]=newWindow;}
else
{document.childWindows=[newWindow];}
newWindow.DateList=DateWindow.arguments[8];
newWindow.MonthList=DateWindow.arguments[9];
newWindow.YearList=DateWindow.arguments[10];
alert ("DATELIST = "+newWindow.DateList);
}

function RadioChecked(nm, title)
{
var Chk="empty";
/*alert (nm+", "+nm.length);*/
if (nm.length)
{
	for (var i=0;i<nm.length;i++)
	{
	if (nm[i].checked==true) // this will check if the i'th radio button is checked
	{Chk=i;}
	}
}
else
{
	if (nm.checked==true)
	{Chk=1;}
}
if (Chk=="empty")
{
alert ("Please select a "+title);
return false;
}
}

function SubTotalAfterMultiply()
{
var CurValue=SubTotalAfterMultiply.arguments[0].value;
if (CurValue=="")
{SubTotalAfterMultiply.arguments[0].value=0;}
var CurMultiple=SubTotalAfterMultiply.arguments[1].value;
var title=SubTotalAfterMultiply.arguments[2];
if (CurMultiple=="")
{SubTotalAfterMultiply.arguments[1].value=0;}
var total=SubTotalAfterMultiply.arguments[3];
var value=parseFloat(SubTotalAfterMultiply.arguments[0].value)*parseFloat(CurMultiple);
var ignoremsg=0;
if (title!="")
{
var result=0;
var pattern=/\d+[.]{0,1}\d*/;
result=pattern.exec(CurValue);
if (result==null)
	{result='';}
if (result!=CurValue)
	{
	alert ("Sorry, "+title+" entered by you is not valid.\nPlease do not use any alphabet characters.");
	SubTotalAfterMultiply.arguments[0].focus();
	SubTotalAfterMultiply.arguments[0].select();
	return false;
	}
	else
	{
		for (i=4;i<SubTotalAfterMultiply.arguments.length;++i)
		{
		var TxtVal="";
		var Mult="";
		if (SubTotalAfterMultiply.arguments[i])
		{
			if (SubTotalAfterMultiply.arguments[i].value=="")
			{SubTotalAfterMultiply.arguments[i].value=0;}
		/*value=parseFloat(value);*/
		TxtVal=parseFloat(SubTotalAfterMultiply.arguments[i].value);
		i=i+1;
		if (SubTotalAfterMultiply.arguments[i].value=="")
		{SubTotalAfterMultiply.arguments[i].value=0;}
		Mult=parseFloat(SubTotalAfterMultiply.arguments[i].value);
		value+=(TxtVal*Mult);
		}
		}
	}
}
else
{
	for (i=4;i<SubTotalAfterMultiply.arguments.length;++i)
	{
	var TxtVal="";
	var Mult="";
	if (SubTotalAfterMultiply.arguments[i])
	{
		if (SubTotalAfterMultiply.arguments[i].value=="")
		{SubTotalAfterMultiply.arguments[i].value=0;}
		value=parseFloat(value);
		TxtVal=parseFloat(SubTotalAfterMultiply.arguments[i].value);
		i=i+1;
		if (SubTotalAfterMultiply.arguments[i].value=="")
		{SubTotalAfterMultiply.arguments[i].value=0;}
		Mult=parseFloat(SubTotalAfterMultiply.arguments[i].value);
		value+=(TxtVal*Mult);
	}
	}
}
total.value=roundup(value.toString());
return true;
}

function TotalAfterMultiply()
{
var CurValue=TotalAfterMultiply.arguments[0].value;
if (CurValue=="")
{TotalAfterMultiply.arguments[0].value=0;}
var CurMultiple=TotalAfterMultiply.arguments[1].value;
if (CurMultiple=="")
{TotalAfterMultiply.arguments[1].value=0;}
var CurMultiple1=TotalAfterMultiply.arguments[2].value;
if (CurMultiple1=="")
{TotalAfterMultiply.arguments[2].value=0;}
var title=TotalAfterMultiply.arguments[3];
var total=TotalAfterMultiply.arguments[4];
var value=(parseFloat(TotalAfterMultiply.arguments[0].value)*parseFloat(TotalAfterMultiply.arguments[1].value))*parseFloat(TotalAfterMultiply.arguments[2].value);
var ignoremsg=0;
/*alert ("1="+TotalAfterMultiply.arguments[0].value+" 2="+TotalAfterMultiply.arguments[1].value+" 3="+TotalAfterMultiply.arguments[2].value+"\nVAL="+value);*/
if (title!="")
{
var result=0;
var pattern=/\d+[.]{0,1}\d*/;
result=pattern.exec(CurValue);
if (result==null)
	{result='';}
if (result!=CurValue)
	{
	alert ("Sorry, "+title+" entered by you is not valid.\nPlease do not use any alphabet characters.");
	TotalAfterMultiply.arguments[0].focus();
	TotalAfterMultiply.arguments[0].select();
	return false;
	}
	else
	{
		for (i=5;i<TotalAfterMultiply.arguments.length;i++)
		{
		var TxtVal="";
		var Mult="";
		if (TotalAfterMultiply.arguments[i])
		{
			if (TotalAfterMultiply.arguments[i].value=="")
			{TotalAfterMultiply.arguments[i].value=0;}
		/*value=parseFloat(value);*/
		TxtVal=parseFloat(TotalAfterMultiply.arguments[i].value);
		i=i+1;
		Mult=parseFloat(TotalAfterMultiply.arguments[i].value);
		if (Mult=="")
		{TotalAfterMultiply.arguments[i].value=0;}
		i=i+1;
		if (TotalAfterMultiply.arguments[i].value=="")
		{TotalAfterMultiply.arguments[i].value=0;}
		value+=(TxtVal*Mult)*parseFloat(TotalAfterMultiply.arguments[i].value);
		}
		}
	}
}
else
{
	for (i=5;i<TotalAfterMultiply.arguments.length;i++)
	{
	var TxtVal="";
	var Mult="";
	if (TotalAfterMultiply.arguments[i])
	{
		if (TotalAfterMultiply.arguments[i].value=="")
		{TotalAfterMultiply.arguments[i].value=0;}
		value=parseFloat(value);
		TxtVal=parseFloat(TotalAfterMultiply.arguments[i].value);
		i=i+1;
		Mult=parseFloat(TotalAfterMultiply.arguments[i].value);
		if (Mult=="")
		{TotalAfterMultiply.arguments[i].value=0;}
		i=i+1;
		if (TotalAfterMultiply.arguments[i].value=="")
		{TotalAfterMultiply.arguments[i].value=0;}
		value+=(TxtVal*Mult)*parseFloat(TotalAfterMultiply.arguments[i].value);
	}
	}
}
total.value=roundup(value.toString());
return true;
}

function SubTotal()
{
var value=parseFloat(SubTotal.arguments[0].value);
var title=SubTotal.arguments[1];
var total=SubTotal.arguments[2];
/*alert ("1st="+SubTotal.arguments[0]+"\n\ntitle="+SubTotal.arguments[1]+"\n\ntotal="+SubTotal.arguments[2]+"\n\nLEN="+SubTotal.arguments.length);*/
var result=0;
var pattern=/\d+[.]{0,1}\d*/;
result=pattern.exec(value);
	if (result==null)
	{result='';}
	if (result!=value)
	{
	alert ("Sorry, "+title+" entered by you is not valid.\nPlease do not use any alphabet characters.");
	SubTotal.arguments[0].focus();
	SubTotal.arguments[0].select();
	return false;
	}
	else
	{
		for (i=3;i<SubTotal.arguments.length;i++)
		{
		if (SubTotal.arguments[i])
		{
			if (SubTotal.arguments[i].value=="")
			{SubTotal.arguments[i].value=0;}
			value+=parseFloat(SubTotal.arguments[i].value);
		}
		}
	}
total.value=roundup(value.toString());
return true;
}

function roundup(par)
{
if (par!="")
{
/*alert (typeof(par));*/
var rlt=par.split(".");
var beforedecimal=rlt[0];
var thirddecimal="";
var firsttwo="";
var afterdecimal=rlt[1];
if (rlt.length==2)
{
	if (afterdecimal.length<=2)
	{return par;}
	else
	{
	thirddecimal=afterdecimal.charAt(2);
	firsttwo=afterdecimal.substr(0, 2);
		if (thirddecimal>4)
		{
			if (firsttwo==99)
			{
			beforedecimal++;
			firsttwo="00";
			}
			else
			{firsttwo++;}
		}
	par=beforedecimal+"."+firsttwo;
	return par;
	}
}
else
{return par;}
}
else
{return 0;}
}

function anyonechecked()
{
if (anyonechecked.arguments[0])
{
var title=anyonechecked.arguments[anyonechecked.arguments.length-1];
var chk="empty";
	if (anyonechecked.arguments[0].value==anyonechecked.arguments[1])
	{
	for (i=2;i<(anyonechecked.arguments.length-1);++i)
	{
		if (anyonechecked.arguments[i].checked==true)
		{chk=i;}
	}
	if (chk=="empty")
	{
	alert ("Please Check atleast one "+title+".");
	return false;
	}
	else
	{return true;}
	}
}
else
{return false;}
}

function resetall(FormName)
{
FormName.reset();
}

function Check()
{
var selidx=Check.arguments[0].selectedIndex;
var title=Check.arguments[1];
if (selidx < 0)
{
alert ("Please select atleast one"+title);
Check.arguments[0].focus();
return false;
}
}

function AlsoEnter()
{
var title=AlsoEnter.arguments[0];
if (AlsoEnter.arguments[1].value!="" && AlsoEnter.arguments[2].value!="")
{
	for (i=3;i<AlsoEnter.arguments.length;++i)
	{
		if (AlsoEnter.arguments[i].value=="")
		{
		alert ("Please also enter "+title);
		AlsoEnter.arguments[i].focus();
		return false;
		}
	}
return true;
}
else
{return true;}
}

function NoSpecialChar(name,title)
{
var value=name.value;
var length=value.length;
var result=0;
var pattern=/[a-zA-Z0-9]+/;
result=pattern.exec(value);
if (result==null)
	{result='';}
if (result!=value)
	{
	alert ("Sorry, "+title+" entered by you is invalid.\nPlease do not use Special Characters.");
	name.focus();
	name.select();
	return false;
	}
	else
	{return true;}
}

function CheckTheGiven()
{
var len=CheckTheGiven.arguments.length;
for (i=0;i<len;++i)
{
	if (CheckTheGiven.arguments[i])
	{CheckTheGiven.arguments[i].checked=true;}
}
}

function UncheckTheGiven()
{
var len=UncheckTheGiven.arguments.length;
for (i=0;i<len;++i)
{
	if (UncheckTheGiven.arguments[i])
	{UncheckTheGiven.arguments[i].checked=false;}
}
}

function NextDate(DtTxt, NextDtTxt)
{
var months=[["jan",31], ["feb",28], ["mar",31], ["apr",30], ["may",31], ["jun",30], ["jul",31], ["aug",31], ["sep",30], ["oct",31], ["nov",30], ["dec",31]];
var Dt=DtTxt.value.split("-");
var yr="20"+Dt[2];
var leap=parseInt(yr)%4;
var mthidx="empty";
var NextDt=NextDtTxt.value;
	if (leap==0)
	{months[1][1]=months[1][1]+1;}
	for (var i=0;i<months.length;i++)
	{
	if (Dt[1].toLowerCase()==months[i][0])
	{mthidx=i;}
	}
	if (mthidx==11)
	{
		if (Dt[0] >= months[11][1])
		{NextDt="01-jan-0"+(parseInt(Dt[2])+1);}
		else
		{NextDt=parseInt(Dt[0])+1+"-dec-"+Dt[2];}
	}
	else
	{
		if (Dt[0] >= months[mthidx][1])
		{NextDt="01-"+months[mthidx+1][0]+"-"+Dt[2];}
		else
		{NextDt=parseInt(Dt[0])+1+"-"+months[mthidx][0]+"-"+Dt[2];}
	}
if (NextDt != "")
{NextDtTxt.value=NextDt;}
}

//Up & Down for the set order
function setarr(s,l)
{
l.value='';
for(i=0;i<s.length;i++)
	l.value=l.value+s.options[i].value+',';
}

function Up(s)
{
	sel=s.options.selectedIndex;
	if(sel>0)
	{
	val=s.options[sel-1].value;
	txt=s.options[sel-1].text;
	s.options[sel-1].value=s.options[sel].value;
	s.options[sel-1].text=s.options[sel].text;
	s.options[sel].value=val;	
	s.options[sel].text=txt;	
	s.options[sel-1].selected=true;	
	}
}
function Down(s)
{
	sel=s.options.selectedIndex;
	ctr=sel+1;
	if(s.length>ctr)
	{
	val=s.options[sel+1].value;
	txt=s.options[sel+1].text;
	s.options[sel+1].value=s.options[sel].value;
	s.options[sel+1].text=s.options[sel].text;
	s.options[sel].value=val;	
	s.options[sel].text=txt;	
	s.options[sel+1].selected=true;	
	}
}
/*

function fnCompareDates(dtFirst, dtSecond, pattern) 
{ 
   var result = 0; 

  if(pattern.toUpperCase()=="DDMM") 
  {    
      iDateFirst = parseFloat(dtFirst.substring(6,10) + dtFirst.substring(3,5) + dtFirst.substring(0,2)); 
      iDateSecond = parseFloat(dtSecond.substring(6,10) + dtSecond.substring(3,5) + dtSecond.substring(0,2));
   } 
   else 
   { 
      iDateFirst = parseFloat(dtFirst.substring(6,10) + dtFirst.substring(0,2) + dtFirst.substring(3,5)); 
      iDateSecond = parseFloat(dtSecond.substring(6,10) + dtSecond.substring(0,2) + dtSecond.substring(3,5)); 
   } 
    
   if(iDateFirst > iDateSecond) 
      result = 1; 
   else if(iDateFirst < iDateSecond) 
      result = 2; 
   return result; 
} */

function fnCompareDates(dtFirst, dtSecond, pattern) 
{ 
   var result = 0; 

  if(pattern.toUpperCase()=="DDMM") 
  {    
      iDateFirst = parseFloat(dtFirst.substring(6,10) + dtFirst.substring(3,5) + dtFirst.substring(0,2)); 
      iDateSecond = parseFloat(dtSecond.substring(6,10) + dtSecond.substring(3,5) + dtSecond.substring(0,2));
   } 
   else 
   { 
      iDateFirst = parseFloat(dtFirst.substring(6,10) + dtFirst.substring(0,2) + dtFirst.substring(3,5)); 
      iDateSecond = parseFloat(dtSecond.substring(6,10) + dtSecond.substring(0,2) + dtSecond.substring(3,5)); 
   } 
    
   if(iDateFirst > iDateSecond) 
      result = 1; 
   else if(iDateFirst < iDateSecond) 
      result = 2; 
   return result; 
}


function IsNumeric(strInput)
{
  var i
  var c
  if (strInput == "") return false;
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
    if (c < "0" || c > "9")
	return false;
  }
  return true;
}

function IsPrice(strInput)
{
  var i
  var c
  var numOfDots = 0;

  if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);

    // check if the DOT is the last charachter
    if (c == ".")
    {
       // added by Sudeep
       // count number of DOTS
       numOfDots = numOfDots + 1;

       if (strInput.length == i)
       {
         return false;
       }
    }

    if ((c < "0" || c > "9" ) &&( c != ".") && (c != ","))
    {
	return false;
    }
  }
  if ( numOfDots > 1) return false;

  return true;
}

function IsAlphaNumeric(strInput)
{
  var i
  var c
 // if (strInput == "") return false;	
  for (i = 0; i < strInput.length; i++)
  {
    c = strInput.charAt(i);
	if ((c < "a" || c > "z") && (c < "A" || c > "Z") && (c < "0" || c > "9")&& (c != " ") && (c != "+") && (c != "-") && (c != ".")&& (c != ","))
	{
      	   return false;
	}
  }
  return true;
}


//function to validate credit card number
function IsValidCreditCardNumber(cardNumbersOnly)
{
		var numberProduct;
		var numberProductDigitIndex;
		var checkSumTotal = 0;
		cardNumberLength = cardNumbersOnly.length
		
		for (digitCounter = cardNumberLength - 1;  digitCounter >= 0;   digitCounter--)
		{
		  checkSumTotal += parseInt (cardNumbersOnly.charAt(digitCounter));
		  digitCounter--;
		  numberProduct = String((cardNumbersOnly.charAt(digitCounter) * 2));
		  for (var productDigitCounter = 0; productDigitCounter < numberProduct.length;  productDigitCounter++)
		  {
		    	checkSumTotal += parseInt(numberProduct.charAt(productDigitCounter));
		  }
		}
		if(checkSumTotal % 10 == 0)
		{
			isValid  = true;
		}
		else
		{
			isValid = false;
		}			
		return isValid
}

function alltrim(str)
{
   str = this != window? this : str;
   return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


function DateCompare(sDate1,sDate2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();
	date1=new Date(sDate1)
	date2=new Date(sDate2)
	if (date1 > date2)
	{
		return 1;
	}
	else
	{
		if (date1 < date2)
		{
			return 2;
		}
		else
			return 0;
	}
	
}
