function mytrim(val)
{
val1 = "";
val2="";
ctrr = 0;
lngth = val.length;
for (i=0; i<lngth; i++)
{
if (val.charCodeAt(i) != 32)
{
for(j=i;j<lngth;j++)
{
if (val.charCodeAt(j) != 13 && val.charCodeAt(j) != 10 )
	{	
	val1 += val.charAt(j); 
	}
}
break;
} 
}
if (val1 != "")
{
lngth = val1.length
ctrr=lngth;
for (k=0; k<lngth; k++)
{
ctrr=ctrr-1;
if (val1.charCodeAt(ctrr) != 32)
{
for(l=0;l<lngth-k;l++)
{
val2 += val1.charAt(l); 
}
val1=val2;
break;
}
}
}
return val1;
}

function chkemail(email)
{
	var emailvalid=true;
	
		if (email.value.length < 5)
		{
			emailvalid=false;
		}
		else 
		{
						
			var flag = "false";
			var flag1 = "false";
			var flag2="true";
			for (var i = 1; i < email.value.length; i++) 
			{
				var ch = email.value.substring(i, i + 1);
				if (ch == ".")
				{	
					flag = "true";
				}	
				if (ch == "@")
				{	
					flag1 = "true";
				}
				if (ch==" ")
				{
					flag2="false";
				}

			}
			if (flag == "false" || flag1 == "false" || flag2 == "false")
			{
				emailvalid=false;
			}
		}
		return emailvalid;
}
 function IsNumeric(sText)
 {
   var ValidChars = "0123456789";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
 }
 function isBlank(txtString)
{
newValue = txtString.replace(/&nbsp;/,'');
newValue = newValue.replace("<P>",'');
newValue = newValue.replace("</P>",'');
if (newValue.length == 0)
	return true
else
	return false;
}

function isnumeric(param)
{
ret_val = true;
var n = 0;
var dctr =0;
n=param.length;
for (i=0;i<n;i++)
{
chkchar = param.charAt(i);
if (parseFloat(chkchar)) 
	ret_val = true;
else if (chkchar == "0")
	ret_val = true;
else if (chkchar == '.')
	{
	ret_val = true;
	dctr += 1
	}
else
	{
	ret_val = false;
	
	break;
	}
}
if (ret_val && dctr > 1)
	{
	ret_val = false;
	
	}
return ret_val
}

function isnumber(param,message)
{
ret_val = true;
var n = 0;
n=param.length;
for (i=0;i<n;i++)
{
chkchar = param.charAt(i);
if (parseFloat(chkchar)) 
	ret_val = true;
else if (chkchar == "0")
	ret_val = true;
else
	{
	ret_val = false;
	alert("Please enter digit in "+ message + " field");	
	break;
	}
}
return ret_val
}

function isinteger(param,message)
{
ret_val = true;
var n = 0;
n=param.length;
for (i=0;i<n;i++)
{
chkchar = param.charAt(i);
if (parseFloat(chkchar)) 
	ret_val = true;
else if (chkchar == "0")
	ret_val = true;
else
	{
	ret_val = false;
	alert("Please enter integer value in "+ message + " field");	
	break;
	}
}
return ret_val
}


function val_email(str)
{
  ret_val=true;
  var at="@"
  var dot="."
  var lat=str.indexOf(at)
  var lstr=str.length-1
  var ldot=str.indexOf(dot)
  if (str.indexOf(at)==-1){
	 ret_val=false;
  }
 
  if (ret_val && (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)){
	 ret_val=false;
  }
  if (ret_val && (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.lastIndexOf(dot)==lstr)){
	 ret_val=false;
  }
 
   if (ret_val && (str.indexOf(at,(lat+1))!=-1)){
	 ret_val=false;
   }
 
   if (ret_val && (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)){
	 ret_val=false;
   }
 
   if (ret_val && (str.indexOf(dot,(lat+2))==-1)){
	 ret_val=false;
   }
  
   if (ret_val && (str.indexOf(" ")!=-1)){
	 ret_val=false;
   }
  return ret_val;
}





function chkdate(Sdate,message)
{
		var err=0
		var psj=0
		var b="";
		a=Sdate
		if (a.length != 10) err=1
		b = a.substring(0, 2)
		c = a.substring(2, 3)
		d = a.substring(3, 5)
		e = a.substring(5, 6)
		f = a.substring(6, 10)
		if ( (b>0 && b <= 12) && (d >0 && d <= 31) && (f >1900 && f<=2099))
		  err = 0
		else
		  err = 1
		if (c != '/') err = 1
		if (e != '/') err = 1
		if (b==4 || b==6 || b==9 || b==11)
		{
		if (d==31) err=1
		}
		if (b==2)
		{
		var g=parseInt(f/4)
		if (isNaN(g))
		{
		err=1
		}
		if (d>29) err=1
		if (d==29 && ((f/4)!=parseInt(f/4))) err=1
		}
		if (err==1)
		{
		alert(message)
		return false
		}		
		else
		{
		return true;
		}
}
function isgreater(date1,date2)
{
var chkdate1 = new Date(date1.substr(6,4), date1.substr(0,2),date1.substr(3,2));
var chkdate2 = new Date(date2.substr(6,4), date2.substr(0,2),date2.substr(3,2));
if (chkdate1.getTime() >= chkdate2.getTime())
	return true;
else
	return false;
}	

function stuff_date(cdate)
{
var mm,dd,yyyy,d
a = cdate.substring(0,cdate.indexOf('/'));
b = cdate.substring(cdate.indexOf("/")+1, cdate.lastIndexOf('/'));
c = cdate.substring(cdate.lastIndexOf("/")+1,cdate.length);
if (a.length ==1)
	a="0" + a;
if (b.length==1)
	b="0" + b;
if (c.length==2)
	{
	today = new Date();
	today = today.getFullYear();
	var today1 = today+" ";
	today = today1.substring(0,2);
	c = today + c;
	}
d = a + "/" + b + "/" + c
return d;
}


function checkFields(form,fldName,fldMsg)
{
	var fldRef,fldType;
	for (y=0; y < fldName.length; y++)
	{
		if (fldName[y] != "")
		{
			fldRef = form.elements[fldName[y]];
			//check for text or textarea field
			if (fldRef.type == "text" || fldRef.type == "textarea" || fldRef.type == "password" || fldRef.type == "hidden" )
			{
				if (mytrim(fldRef.value).length == 0)
				{
					alert("Please enter " + fldMsg[y] + ".");
					fldRef.focus();
					return false;
				}
			}
			//check for select-one or select-multiple field
			else if ((fldRef.type == "select-one") || (fldRef.type == "select-multiple"))
			{
				if (fldRef.options[fldRef.selectedIndex].value == "0")
				{
					alert("Please select " + fldMsg[y] + ".");
					fldRef.focus();
					return false;
				}
			}
			//check for radio buttons
			else if (fldRef[0].type == "radio")
			{
				var optChecked = false;
				for (i=0; i<fldRef.length;i++)
				{
					if (fldRef[i].checked)
					{
						optChecked = true;
					}
				}
				if (!optChecked)
				{
					alert("Please specify " + fldMsg[y] + ".");
					fldRef[0].focus();
					return false;
				}
			}
		}
	}
	return true;
}

function isValidZip(numval) {
	var valid = "0123456789-";
	var hyphencount = 0;
	if (numval.length!=5 && numval.length!=10) {
		return false;
	}
	for (i=0;i<numval.length;i++){
		if(valid.indexOf(numval.charAt(i))==-1){
			return false;
		}
	}
	if (numval.length==10) {
		if(numval.charAt(5)!="-"){
			return false;
		}
	}
	return true;
}

/*function isValidPhoneNumber(numval) {
	var valid = "0123456789-";
	var hyphencount = 0;
	if (numval.length!=12) {
		return false;
	}
	for (i=0;i<numval.length;i++){
		if(valid.indexOf(numval.charAt(i))==-1){
			return false;
		}
	}
	if (numval.charAt(3) != "-" || numval.charAt(7) != "-" )
	{
	return false;
	}
	return true;
}*/

function isValidPhoneNumber(numval) {
 var valid = "0123456789-";
 var hyphencount = 0;
 var ret_val=true; 
 if (numval.length!=12)
 {
  ret_val =  false;
 }
 if (ret_val)
 {
 for (i=0;i<numval.length;i++)
 {
  if(valid.indexOf(numval.charAt(i))==-1)
   ret_val=false;
  else if ( (i != 3 && i != 7) && !(parseInt(numval.charAt(i)) >= 0 && parseInt(numval.charAt(i)) <=9) )
	ret_val=false;
  }
 if (ret_val && (numval.charAt(3) != "-" || numval.charAt(7) != "-" ))
 {
 ret_val=false;
 }
 }
 if (!ret_val)
 {
	
 //alert(message);
 }
 return ret_val;
}




function chkFileExtension(fileName)
{
ret_val=true;
ctr = fileName.lastIndexOf(".")
if (fileName.length > 0 )
{
if (ctr < 0)
	{
	alert("Please select file with valid file name extension");
	ret_val =false;
	}
else
	{
	tmpFile = fileName.substring(ctr+1,fileName.length)
	if (tmpFile.toUpperCase() != "GIF" && tmpFile.toUpperCase() != "BMP" && tmpFile.toUpperCase() != "JPEG" && tmpFile.toUpperCase() != "JPG")
		{
		alert("Please select file with valid file name extension");
		ret_val = false;	
		}
	else
		ret_val =true;
	}
}
return ret_val;
}

function checkForName(param,message)
{
ret_val=true;
/*txtparam = mytrim(param);
ret_val = true;
var n = 0;
n=txtparam.length;
for (i=0;i<n;i++)
{
chkchar = txtparam.charAt(i);
if (parseInt(chkchar)) 
	{
	alert(message);
	ret_val = false;
	break;
	}
}*/

var name= mytrim(param);
var validchars="abcdefghijklmnopqrstuvwxyz ";
var len=name.length;
var i;
var ch;
for(i=0; i<len; i++)
   {
   ch=name.substring(i,i+1);
   if( validchars.indexOf(ch.toLowerCase()) == -1)
      {
	   alert(message);	
	   return false;
      }
   }
return ret_val;
}


function show_CategoryList()
{
	var ctr = document.addprogram.selSubCategory.options.length;
	for (;ctr>=0;ctr--)
	{
	document.addprogram.selSubCategory.options.remove(ctr);
	}
	var o=(document.addprogram.selCategory.options[addprogram.selCategory.selectedIndex].value)-1
	if(o!=2000)
	{

		if (o >= 0)
		{
		ctr=0;
		for (var i=0;i<atour12[0].length;i++)
		{
		if (parentArray[i] == document.addprogram.selCategory.options[addprogram.selCategory.selectedIndex].value)
			{
			document.addprogram.selSubCategory.options[ctr]=new Option(atour12[0][i].text,atour12[0][i].value)
			ctr=ctr+1
			}
			}
		}
	}
}

function isBefore(timeStr1,timeStr2)
{
	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
	timeStr1=timeStr1.toLowerCase();
	timeStr2=timeStr2.toLowerCase();
	var matchArray1 = timeStr1.match(timePat);
	var matchArray2 = timeStr2.match(timePat);
	hour1 = parseInt(matchArray1[1]);
	hour2 = parseInt(matchArray2[1]);
	minute1 = parseInt(matchArray1[2]);
	minute2 = parseInt(matchArray2[2]);
	ampm1 = matchArray1[6];
	ampm2 = matchArray2[6];

	if(hour1==hour2 && minute1==minute2 && ampm1==ampm2)
		return false;
	else if(hour1 > hour2 && (ampm2!="pm" || ampm1==ampm2))
		return false;
	else if(hour1 == hour2 && minute1 > minute2 && (ampm2!="pm" || ampm1==ampm2) )
		return false;
	else if(ampm1=="pm" && ampm2!=ampm1)
		return false;
	else
		return true;
}

function checkcreditcard()
	{
	ret_val=true;
	var chka;
	if(document.form1.cardNumber.value.length < "14")
	{
		alert("Please enter valid credit card number");
		document.form1.cardNumber.focus();
		ret_val=false;
	}
	else
	{
		var chck1, i;

		for(i=0; i<document.form1.cardNumber.value.length; i++)
		{
			chck1=document.form1.cardNumber.value.substring(i,i+1);

			if(isNaN(chck1) == true)
			{
				alert("Please enter valid credit card number");
				document.form1.cardNumber.focus();
				break;
				ret_val=false;
				
			}
		}
	}
	return ret_val;
	}

function billingHelp(txtid)
{
txturl = "billingHelp.asp?txtid="+txtid
window.open(txturl,'newWin1','height=500,width=510,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,left=0,top=0')
}


 function formatNumber(myNum, numOfDec) 
   { 
      var decimal = 1 
      for(i=1; i<=numOfDec;i++) 
         decimal = decimal *10 

      var myFormattedNum = (Math.round(myNum * decimal)/decimal).toFixed(numOfDec) 
     return  myFormattedNum 
   } 
   

function checkforDecimal(txtValue)
{
ret_val=true;
intPositions = txtValue.indexOf(".");
if (intPositions>=0)
{
	intPositions = txtValue.substring(txtValue.lastIndexOf(".")+1,txtValue.length);
	if (intPositions.length > 2)
	{
	ret_val=false;
	}
}
return ret_val;
}

function checkForSeperator(val)
{
entercount=0;
commacount=0;
lngth = val.length;
ret_val=true;
seperator=""
for (i=0; i<lngth; i++)
{
if (val.charCodeAt(i) == 44)
	{	
	commacount=commacount+1 
	seperator="comma";
	}
else if (val.charCodeAt(i) == 13)
	{
	entercount=entercount+1
	seperator="enter";
	}
}
if (parseInt(commacount) > 0 && parseInt(entercount) > 0)
	{
	ret_val=false;
	seperator="both";
	}
else if (parseInt(commacount) == 0 && parseInt(entercount) == 0)
	{
	seperator="none";
	}
return seperator;
}


function checkExtension(extension)
{
ret_val=true;
if (extension.lastIndexOf(".gif")== -1 && extension.lastIndexOf(".jpg")== -1 && extension.lastIndexOf(".png")== -1)
	{
	ret_val=false;
	}
return ret_val;
}