
//***********************************************************************
//Project name	:	PNGCSM.NET Application
//Module		:	General
//Description	:	Common Javascript for input validation at client side 
//			
//Developed by	:	Mayur Shrimali
//Release Date	:	01-01-2006
//***********************************************************************
//.........Formatted string to check text entered by User................
var spNChar=/^[a-zA-Z0-9 ]/;
var spChar=/^[a-zA-Z ]/;
var spNums=/^[0-9]/;
var spFloat=/^[.0-9]/;
var dtCh= "-";

//.........Global Wrapper function will be called from each form and each
// control validation....................................................
/*		Parameter		Desciprtion
		PassCtl		:	Control name to be validated	
		ValidType   :	Validation type e.g. "B","N","A" detail specified below
		CustomName	:	Name string to be displayed in message box
		Min			:	Minimum value
		Max			:	Maximum value
		Expression	:	Regular expression to be validated */
		
	MsgSelectDeactivateEligible = "You have not selected any record for Deactivation. \nPlease select record(s) to DEACTIVATE." ;
	MsgSelectEditEligibleOne= "You have not selected any record for Editing. \nPlease select a record." ;
	MsgSelectAssignEligibleOne= "You have not selected any record for Assigning Visual. \nPlease select a record to Assign Visual." ;
	MsgSelectDeleteEligible = "You have not selected any record for Deleting. \nPlease select record(s) to DELETE." ;
	MsgSelectAssignEligibleMore = "You have selected more than one record for Assigning Visual.\nPlease select only one record to Assign Visual." ;
	//MsgSelectAssignEligibleOne= "You have not selected any record for Assigning/Removing. \nPlease select a record to ASSIGN/REMOVE." ;
	//MsgSelectEditEligibleMore= "You have selected more than one record for Assigning/Removing.\nPlease select only one record to ASSIGN/REMOVE." ;
	MsgSelectEditEligibleMore= "You have selected more than one record for Editing.\nPlease select only one record to Edit." ;
	MsgSendConfirm = "Are you sure you want to SEND this message?";
	MsgAssignConfirm = "Are you sure you want to Assign?";
	MsgSaveConfirm = "Are you sure you want to SAVE the record?";
	//MsgSaveConfirm1 = "Do you really want to generate the call and inward the material ?";
	MsgDeleteConfirm = "Are you sure you want to DELETE the record(s)?";
	MsgDeactivateConfirm = "Are you sure you want to DEACTIVATE the record(s)?";
	MsgContinueConfirm="Are you sure you want to Continue?";
	MsgScheduleConfirm="Are you sure you want to Schedule?";
	MsgScheduleUpdateConfirm="All previous initial inspection scheduled will be set to inactive. Are you sure you want to Continue?";
	MsgPocketPCReturn="You are about to update the Pocket PC's return. Are you sure you want to Continue?";
	MsgSelectActivateOnly="One or more selected records are already deactivated.\n Please select only active records to DEACTIATE."
	MsgSelectReturn="You have not selected any Pocket PC To Return . \nPlease select Pocket PC(s) to Return."
	MsgReturnConfirm = "Are you sure you want to Return the Pocket PC(s)?";
	
function ValidateForm(PassCtl,ValidType,CustomName,Min,Max,Expression)
{
	
	//................Standard Message Strings...........................
	//CustomName = " Field " + CustomName;
	MsgBlank ="Please enter " + CustomName;
	MsgNumber = "Please enter digits in " + CustomName + ".";
	MsgValidAlpha = "Please enter alphabetic characters in " + CustomName + ".";
	MsgValidAlphaNum="Please enter alpha-numeric characters in " + CustomName + ".";
	MsgValidFloat="Please enter valid number in " + CustomName + ".";
	
	MsgLowRange = "Please enter less then " + Max + " characters in " + CustomName + ".";
	MsgHighRange = "Please enter more then " + Min + " characters in " + CustomName + ".";
	MsgLowValue ="Please enter value less than or equal to " + Max + " in " + CustomName + ".";
	MsgHighValue = "Please enter value more than or equal to " + Min + " in " + CustomName + ".";
	if (Expression==""){
		MsgCustomFormat = "Please enter decimal value in respected field." ;
	}
	else{
		MsgCustomFormat = "Please enter value in : {" + Expression + "} format." ;
	}
	MsgValidEmail = "Please enter valid Email in " + CustomName + ".";
	MsgDateCompare = "Date should be less than or equal to current date"
	
	//................Executes respective function accroding to ValidType............
	switch(ValidType)
	{
		case "B": //Blank validation
			return	IsBlank(PassCtl)
			break;
		case "NB": // Number validation
			return IsNumberAllowNull(PassCtl)
			break;
		case "N": // Number validation
			return IsNumber(PassCtl)
			break;	
		case "A": // Alphabetic string validation
			return IsValidString(PassCtl)
			break;
		case "AB": // Alphabetic string validation
			return IsValidStringAllowNull(PassCtl)
			break;	
		case "AN": //Alpha-Numeric string validation
			return IsAlphaNumeric(PassCtl)
			break;
		case "L": //Length validation
			return IsValidLength(PassCtl,Min,Max)
			break;
		case "R": //Range validation
			return IsValidRange(PassCtl,Min,Max)
			break;	
		case "D": //Decimal places validation
			return IsFloat(PassCtl,Min,Max)
			break;
		case "DB": //Decimal places validation
			return IsFloatAllowNull(PassCtl,Min,Max)
			break;		
		case "E":  //Email validation
			return  ApplyStyle(PassCtl,IsValidEmail(PassCtl))
			break;
		case "FM": //Custom String validation
			return validateCustom(PassCtl,Expression)
			break;
		case "DTNOW": //Date Compare
			return compareTodateDate(PassCtl)
			break;
		}
		
}

// compare 2 dates (dd/mon/yyyy)
function CompareDate(dt1,dt2,strMsg){
	dt1=dt1.value;
	dt2=dt2.value;
	var pos1=dt1.indexOf(dtCh)
	var pos2=dt1.indexOf(dtCh,pos1+1)
	
	var Day=parseInt(dt1.substring(0,pos1))
	var Month=parseInt(convertToNumericMon(dt1.substring(pos1+1,pos2)))
	var Year=parseInt(dt1.substring(pos2+1))

	var pos1_2=dt1.indexOf(dtCh)
	var pos2_2=dt1.indexOf(dtCh,pos1_2+1)
	
	var Day_2=parseInt(dt2.substring(0,pos1_2))
	var Month_2=parseInt(convertToNumericMon(dt2.substring(pos1_2+1,pos2_2)))
	var Year_2=parseInt(dt2.substring(pos2_2+1))
		 
	if ( Date.parse(Month+"/"+Day+"/"+Year) > Date.parse(Month_2+"/"+Day_2+"/"+Year_2) ){
		fireMessage(strMsg);
		return false;
	}
	return true;
}
/*
// COMPARE today's DATES
function CompareToDate(dt1){

	var pos1=dt1.indexOf(dtCh)
	var pos2=dt1.indexOf(dtCh,pos1+1)
	
	var day=parseInt(dt1.substring(0,pos1))
	var month=parseInt(dt1.substring(pos1+1,pos2)+%m)
	var year=parseInt(dt1.substring(pos2+1))

	if (Date.parse(month+"/"+day+"/"+year)>Date.parse(Date())){
		fireMessage(MsgDateCompare);
		Ret_val = false;
		return ApplyStyle(ctl,Ret_val);
	}
	return true;
}*/

// Blank validation
function IsBlank(ctl) 
{
  
	    var Ret_val = true;
	    ctl.value= trim(ctl.value);
	    if (ctl.value=="")
	    {
		    fireMessage(MsgBlank);
		    Ret_val = false;
	    }else 
	    { Ret_val = true;
	    }	
	    return ApplyStyle(ctl,Ret_val);
	
}

// Number validation
function IsNumber(ctl)
{
	var mname =ctl.value;
	//var Ret_val = IsBlank(ctl);
	var Ret_val = true;
	if (Ret_val)
	{
		for(i=0; i < mname.length;i++)
		{
			var spcheck=mname.charAt(i);
			if(spNums.test(spcheck)==false)
			{
				Ret_val = false;
				break;
			}
			
		}
		if (!Ret_val ) fireMessage(MsgNumber);
	}	
	return ApplyStyle(ctl,Ret_val);
}


function IsNumberAllowNull(ctl)
{
	var mname =ctl.value;
	var Ret_val = true;
	if (Ret_val)
	{
		for(i=0; i < mname.length;i++)
		{
			var spcheck=mname.charAt(i);
			if(spNums.test(spcheck)==false)
			{
				Ret_val = false;
				break;
			}
			
		}
		if (!Ret_val ) fireMessage(MsgNumber);
	}	
	return ApplyStyle(ctl,Ret_val);
}

//Alphabetic characters validation
function IsValidString(ctl) 
{
	var mname =ctl.value;
	var Ret_val = IsBlank(ctl);
	if (Ret_val)
	{
		for(i=0; i < mname.length;i++)
		{
			var spcheck=mname.charAt(i);
			if(spChar.test(spcheck)==false)
			{
				Ret_val = false;
				fireMessage(MsgValidAlpha);
				break;
			}
		}
	}	
	return ApplyStyle(ctl,Ret_val);
}
//Alphabetic characters validation
function IsValidStringAllowNull(ctl) 
{
	var mname =ctl.value;
	var Ret_val = true;
	for(i=0; i < mname.length;i++)
	{
		var spcheck=mname.charAt(i);
		if(spChar.test(spcheck)==false)
		{
			Ret_val = false;
			fireMessage(MsgValidAlpha);
			break;
		}
	}
	return ApplyStyle(ctl,Ret_val);
}


//Alpha-numeric charactes validation
function IsAlphaNumeric(ctl) 
{
	mname =ctl.value;
	Ret_val = IsBlank(ctl);
	if (Ret_val)
	{
		for(i=0; i < mname.length;i++)
		{
			var spcheck=mname.charAt(i);
			if(spNChar.test(spcheck)==false)
			{
				Ret_val = false;
				break;
			}
		}
		if (!Ret_val) fireMessage(MsgValidAlphaNum);
		return ApplyStyle(ctl,Ret_val);
	}else 
	{return false;	}
	
}
//range validation
function IsValidRange(ctl,MinSize,MaxSize)
{
	fieldValue =ctl.value;
	Ret_val = IsNumber(ctl);
	if (Ret_val)
	{
		if (!( (parseFloat(fieldValue) >= MinSize) && (parseFloat(fieldValue) <= MaxSize) ))
			{
				if (parseFloat(fieldValue) < MinSize)
					fireMessage (MsgHighValue);
				else if (parseFloat(fieldValue) > MaxSize)
					fireMessage(MsgLowValue);
				Ret_val= false;
			}
	}
	return ApplyStyle(ctl,Ret_val);
}

 //String length validation
function IsValidLength(ctl,valMin,valMax)
{
	mname =ctl.value;
	if (valMin != ""){Ret_val=IsBlank(ctl);}
	else{Ret_val=true;}
	if (Ret_val)
	{
		if (valMin != "")
		{
			if( valMin >= mname.length)
			{
				fireMessage(MsgHighRange);
				Ret_val = false;
			}
		}
		if (Ret_val)
		{
			if (valMax != "")
			{	
				if(valMax < mname.length)
				{
					fireMessage(MsgLowRange);
					Ret_val = false;
				}
			}
		}	
	}			
	return ApplyStyle(ctl,Ret_val);
}
//Email validation
function IsValidEmail(ctl) 
{
	//IsBlank(ctl);
	
	var emailStr = ctl.value;
	
	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 (trim(emailStr) == "") return true;
	
	if (matchArray==null) 
	{
		fireMessage(MsgValidEmail)
		ctl.focus();
		return false;
	}
	
	var user=matchArray[1]
	var domain=matchArray[2]
	
	if (user.match(userPat)==null) 
	{
    	fireMessage(MsgValidEmail)
		ctl.focus();
		return false;
	}
	
	var IPArray=domain.match(ipDomainPat)
	
	if (IPArray!=null) 
	{
		for (var i=1;i<=4;i++) 
		{
	    		if (IPArray[i]>255) 
			{
			        fireMessage(MsgValidEmail)
			        ctl.focus();
					return false;
	    		}
		}
			return true;
	}
	
	var domainArray=domain.match(domainPat)
	if (domainArray==null) 
	{
		fireMessage(MsgValidEmail)
		ctl.focus();
		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) 
	{
	   fireMessage(MsgValidEmail)
	   return false;
	}
	if (len<2) 
	{
	   fireMessage(MsgValidEmail);
	   ctl.focus();
	   return false;
	}
		return true;
}
// Decimal number to be checked
function IsFloat(Ctl,Minval,Maxval ) 
{
	blnDotPresent = false;
	fieldValue = Ctl.value;
	//ret = IsBlank(Ctl);
	ret = true;
	for(i=0; i < fieldValue.length;i++)
	{
		var spcheck = fieldValue.charAt(i);
		if(spcheck == '.')
		{
			if( spFloat.test(spcheck) == false)
			{
				continue;
			}
			else
			{
				if(!blnDotPresent)
					blnDotPresent = true;
				else
				{
					ret = false;
					fireMessage (MsgCustomFormat);
					break;
				}
			}
		}
		else
			{
				if( spFloat.test(spcheck) == false)
				{
					ret = false;
					fireMessage (MsgCustomFormat);
					break;
				}
			
			}
	}
	if (ret)
	{
		if (Minval!=""){
			if (parseFloat(fieldValue) < Minval)
			{
				fireMessage (MsgHighValue);
				ret= false;
			}
		}
		else if(Maxval!="")
		{
			if (parseFloat(fieldValue) > Maxval)
			{
				fireMessage(MsgLowValue);
				ret= false;
			}
		}
	}
	return ApplyStyle(Ctl,ret);
}

// Decimal number to be checked
function IsFloatAllowNull(Ctl,Minval,Maxval ) 
{
	blnDotPresent = false
	fieldValue = Ctl.value;
	ret = true;
	if (fieldValue != "")
	{
	
		for(i=0; i < fieldValue.length;i++)
		{
			var spcheck = fieldValue.charAt(i);
			if(spcheck == '.')
			{
				if( spFloat.test(spcheck) == false)
				{
					continue;
				}
				else
				{
					if(!blnDotPresent)
						blnDotPresent = true;
					else
					{
						ret = false;
						fireMessage (MsgCustomFormat);
						break;
					}
				}
			}
			else
			{
				if( spFloat.test(spcheck) == false)
				{
					ret = false;
					fireMessage (MsgCustomFormat);
					break;
				}
			
			}
		}
		if (ret)
		{
			if (Minval!=""){
				if (parseFloat(fieldValue) < Minval)
				{
					fireMessage (MsgHighValue);
					ret= false;
				}
			}
			else if(Maxval!="")
			{
				if (parseFloat(fieldValue) > Maxval)
				{
					fireMessage(MsgLowValue);
					ret= false;
				}
			}
		}
	}	
	return ApplyStyle(Ctl,ret);
}


//Custom dataformat validation
function validateCustom(Obj,pattern) 
{
	if (!IsBlank(ctl))
	{
		var regex = new RegExp(pattern);
		if (!regex.test(Obj.value)) 
		{
			ApplyStyle(Obj,false);
			return false;
		}
		else 
		{
			ApplyStyle(Obj,true);
			return true;
		}
	}	
}

//To make textbox highlighted
function ApplyStyle(ctl,Return_val)
{
	if (Return_val)
	{
		ctl.className="TextBox_Normal"; //Normal stylesheet classname
	}else
	{
		ctl.className="TextBox_Selected"; //Error showing stylesheet classname
		ctl.style.visibility="visible";
			ctl.focus();
	}
	return Return_val;
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function



///////////////////////
// Rollover effect
//////////////////////////

// Code for Mouseover effect of the Images
<!--
<!--
function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);
// -->

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//Function for the validation of RePrint VIN
function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}

		


//-->

/////////////////////////////common script for All view page 


	// Called to render rows of grid
	function ReloadColor(FormName)
	{	
		CheckedNo= 0;
		SelectColumn=0;
		currentClass="tableSelectedRow";
		var len =FormName.elements.length;
		for (i=0;i<len;i++)
		{
			if (FormName.elements(i).type=="checkbox")
			{
				SelectColumn++;
				if (FormName.elements(i).checked==true)
				{
					CheckedNo++;
					FormName.elements(i).parentElement.parentElement.style.classname="tableSelectedRow";
				}
				else
				{
					if (SelectColumn%2==0)
					{
						FormName.elements(i).parentElement.parentElement.className="tableRows"; //alter
					}else
					{
						FormName.elements(i).parentElement.parentElement.className="tableRows";
					}
				}
			}	
		}
		return CheckedNo;
	}

	function ReloadColorDeactivated(FormName)
	{	
		CheckedNo= 0;
		selectColumn = 0;
		currentClass="tableSelectedRow";
		var len =FormName.elements.length;
		for (i=0;i<len;i++)
		{
			if (FormName.elements(i).type=="checkbox")
			{
				selectColumn++;
				if (FormName.elements(i).checked==true)
					{
						CheckedNo++;
					}
					
				if (FormName.elements(i).parentElement.parentElement.className != "Deactivated" )
				{
					if (FormName.elements(i).checked==true)
					{
						FormName.elements(i).parentElement.parentElement.style.classname="tableSelectedRow";
					}else
					{
						if (selectColumn%2==0)
						{
							FormName.elements(i).parentElement.parentElement.className="tableRows"; //alter
						}else
						{
							FormName.elements(i).parentElement.parentElement.className="tableRows";
					}	}
				}
			}
		}		
		return CheckedNo;
	}
		
		
function DeactivatedCount(FormName)
	{	
		CheckedNo= 0;
		var len =FormName.elements.length;
		for (i=0;i<len;i++)
		{
			if (FormName.elements(i).parentElement.parentElement.className == "Deactivated" )		
			{
				if (FormName.elements(i).type=="checkbox")
				{
					if (FormName.elements(i).checked==true)
					{
						CheckedNo++;
					}
				}
			}	
		}
		return CheckedNo;
	}
	//Individual items' color are toggled		
	function ChangeColorDeactivated(e,FormName)
	{
		currentClass=e.parentElement.parentElement.className;
		if (currentClass != "Deactivated")
		{
			if(e.checked == true )
			{
				if (currentClass=="tableSelectedRow")
				{
					currentClass="tableRows";
				}
				else
				{
					currentClass=e.parentElement.parentElement.className;
				}
				e.parentElement.parentElement.className ="tableSelectedRow";
			}
			else
			{
				temp = e.parentElement.parentElement.className;
				e.parentElement.parentElement.className=currentClass;
				currentClass=temp;
			}
		}		 
		ReloadColorDeactivated(FormName);
	}
	function ChangeColor(e,FormName)
	{
		if(e.checked == true)
		{
			if (currentClass=="tableSelectedRow")
			{
				currentClass="tableRows";
			}
			else
			{
				currentClass=e.parentElement.parentElement.className;
			}
			e.parentElement.parentElement.className ="tableSelectedRow";
		}
		else
		{
			temp = e.parentElement.parentElement.className;
			e.parentElement.parentElement.className=currentClass;
			currentClass=temp;
			e.parentElement.parentElement.className="tableRows"; //alter
		} 
		ReloadColor(FormName);
	}
	

	// function for blinking error message.
	var x=1; 
	function countDown() 
	{
		if(x < 6){
			if (tdMsgAssist.style.visibility=="hidden"){
				tdMsgAssist.style.visibility="visible";
			}
			else {
					tdMsgAssist.style.visibility="hidden";
				}	
			x = x+1;
		}
		if (x == 6) {
			clearInterval(counter); // clearing loop
			tdMsgAssist.style.visibility="visible";
			x=1;
		}
	} 

	// when message is fired
	function fireMessage(msg){		
		tdMsgAssist.innerText=msg;	
		tdMsgAssist.style.fontWeight="bold";	
		counter = window.setInterval("countDown()", 500);
	}

	function ViewPage(CallType,FormName,totalcheck)
	{
			if (CallType=='E') //Edit
			{
				if (totalcheck == 0)
				{
					fireMessage(MsgSelectEditEligibleOne);
					return false;
				}else
				{
					if (totalcheck == 1)
					{
						FormName.submit();
					}else
					{
						fireMessage(MsgSelectEditEligibleMore);	
						return false;
					}
				}
			}
			
			else if (CallType=='D') //Delete
			{
				if (totalcheck == 0)
				{
					fireMessage(MsgSelectDeleteEligible);	
					return false;
				}
				else
				{
					if (totalcheck >= 1)
					{
						if (confirm(MsgDeleteConfirm)) 
						{ FormName.submit();}
						else
						{ return false;}
					}
				}
			}
			else if (CallType=='V') //Assign
			{
				if (totalcheck == 0)
				{
					fireMessage(MsgSelectAssignEligibleOne);	
					return false;
				}
				else
				{
	
					if (totalcheck == 1)
					{
						//FormName.submit();
						 confirm(MsgContinueConfirm);
					}else
					{
						fireMessage(MsgSelectAssignEligibleMore);	
						return false;
					}
				}
			}
			else if (CallType=='A') //Deactivation
			{
				//selDeactivated = DeactivatedCount(FormName);
				if (totalcheck != 0)
				{
					if (confirm(MsgDeactivateConfirm)) 
						{ FormName.submit();}
						else
						{ return false;}
				
				}
				if (totalcheck == 0)
				{
					fireMessage(MsgSelectDeactivateEligible);	
					return false;
				}
			
			}
			else if (CallType=='R') //Return
			{
				if (totalcheck == 0)
				{
					fireMessage(MsgSelectReturn);	
					return false;
				}
				else
				{
					if (totalcheck >= 1)
					{
						if (confirm(MsgReturnConfirm)) 
						{ FormName.submit();}
						else
						{ return false;}
					}
				}
			}
			else if (CallType=='S') //Assigning
			{
				if (totalcheck == 0)
				{
					fireMessage(MsgSelectAssignEligibleOne);	
					return false;
				}else
				{
					if (totalcheck == 1)
					{
						FormName.submit();
					}else
					{
						fireMessage(MsgSelectAssignEligibleMore);	
						return false;
					}
				}
			}
	}	
 
 function ValidatePhoneNumber(phoneNum) {
	var segments;		// Breaks up the phone numbers into area code, city code and number
	var i;
		
	// Check to see if they put any "( )" around the area code
	// If so we'll strip those out.
	phoneNum = phoneNum.replace("(", "");
	phoneNum = phoneNum.replace(")", "");
	
	switch (phoneNum.length) {
		case 7:																		/* The XXXXXXX case */
			//if(!isNaN(phoneNum))										// Check to see if they're real numbers
			//	return true;
			return false;
			break;
						
		case 8:																		/* The XXX-XXXX case */
			//segments = phoneNum.split("-");
			//if (segments.length == 2) {
			//	if((segments[0].length == 3) && (segments[1].length == 4)) {
			//		for (i = 0; i < 2; i++) {						// Check to see if they're real numbers
			//			if (isNaN(segments[i]))
			//				return false;
			//		}
			//		return true;
			//	}
			//}
			return false;
			break;
			
		case 10:																	/* The XXXXXXXXXX case */
			//if(!isNaN(phoneNum))										// Check to see if they're real numbers
			return false;
				//return true;
			break;
			
		case 12:																	/* The XXX-XXX-XXXX case */
			segments = phoneNum.split("-");
			if (segments.length == 3) {
				if((segments[0].length == 3) && (segments[1].length == 3) && (segments[2].length == 4)) {
					for (i = 0; i < 3; i++) {						// Check to see if they're real numbers
						if (isNaN(segments[i]))
							return false;
					}
					return true;
				}
			}
			break;
				
		default:																	/* If non of the above then fail it */
			break;
	}
	return false;
}			

	
	function Save_Confirm()
	{
		return confirm(MsgSaveConfirm );
	}
	function Save_Confirm(msg)
	{
		return confirm(msg);
	}
	function Assign_Confirm()
	{
		return confirm(MsgAssignConfirm );
	}
	function Return_Confirm()
	{
		return confirm(MsgPocketPCReturn);
	}
	function Schedule_Confirm()
	{
		return confirm(MsgScheduleConfirm);
	}
	function ScheduleUpdate_Confirm()
	{
		return confirm(MsgScheduleUpdateConfirm);
	}
	function Continue_Confirm()
	{
		return confirm(MsgContinueConfirm);
	}
	function Send_Confirm()
	{
		return confirm(MsgSendConfirm);
	}
	function Delete_Confirm()
	{
		return confirm(MsgDeleteConfirm);
	}

flag=true;
function funCheckAll(){
	for(i=0;i<=parseInt(document.forms[0].elements.length)-1;i++){
		if (document.forms[0].elements[i].type=="checkbox"){
			document.forms[0].elements[i].checked=flag;
		}
	}
	if (flag==false){
		flag=true;
	}
	else{
		flag=false;
	}
}

function isValidURL(ctl) { 
missinginfo="";
	if (ctl.value !="")				
	{
		  if ( (ctl.value == "") || (ctl.value.indexOf("http://") == -1) || (ctl.value.indexOf(".") == -1) || (ctl.value.indexOf(".")==ctl.value.lastIndexOf(".")) )
		   {
				missinginfo += "\n     -  Web site";
		   }							
		  if (missinginfo != "")
		   {
		  		missinginfo ="Wrong WebSite Address Format:Please Re-Enter (http://www.sitename.com)";
		  		alert(missinginfo);
				Ret_val = false;
				return ApplyStyle(ctl,Ret_val);
		    } 
	  }
		Ret_val = true;
		return ApplyStyle(ctl,Ret_val);
}

function convertToNumericMon(strinMon)
	{
	switch(strinMon)
	{
	
		case  "Jan" :
		case  "jan" :
		return 01  	
		break;
	
		case  "Feb" :
		case  "feb" :
		return 02 	
		break;
		
		case  "Mar" :
		case  "mar" :
		return 03 	
		break;
		case  "Apr" :
		case  "apr" :
		return 04 	
		break;
		case  "May" :
		case  "may" :
		return 05  	
		break;
		case  "Jun" :
		case  "jun" :
		return 06 	
		break;
		case  "Jul" :
		case  "jul" :
		return 07 	
		break;
		case  "Aug" :
		case  "aug" :
		return 08 	
		break;
		case  "Sep" :
		case  "sep" :
		return 09 	
		break;
		case  "Oct" :
		case  "oct" :
		return 10  	
		break;
		case  "Nov" :
		case  "nov" :
		return 11  	
		break;
		case  "Dec" :
		case  "dec" :
		return 12  	
		break;
		default:
		return 	strinMon;		
	}

			
	}

/**************************************************************
 DetectBrowser: Return a string that contains the current 
                browser name and version used.

 Parameters:

 Returns: String
***************************************************************/
function DetectBrowser()
{
	var temp = navigator.appName;
	temp = temp.toLowerCase();

	if (temp == 'microsoft internet explorer')
		return 'IE' + navigator.appVersion
	else
		return 'NS' + navigator.appVersion;
}

/**************************************************************
 OpenURL: Return a concatenated string with all the 'objects
          values' contained in a FORM HTML in the format:
          page_to_redirect.html/asp?object1=xxxx&object2=yyyyy&...

 Parameters:
      URL  = URL to redirect
      Form = Form name (be sure not to use QUOTES when passing
             the Form name)

 Returns: URL

 Example: var redirect = OpenURL('mytest.asp', frmMyForm)
          alert(redirect)
          window.nagivate(redirect)
***************************************************************/
function OpenURL(URL, Form)
{
	if (URL.length == 0 || URL == null)
		return (false);

	var form_length = Form.elements.length;
	var myform = Form;
	var mytype = '';
	var temp = URL + '?';

	for (var i = 0; i < form_length; i++)
	{
		mytype = myform.elements[i].type
		mytype = mytype.toLowerCase();
		if (mytype == 'text' || mytype == 'hidden' || mytype == 'select-one' ||
		    mytype == 'checkbox' || mytype == 'radio' || mytype == 'select-multiple')
		{
			var t = myform.elements[i].name
			if (t == null || t == '')
				t = myform.elements[i].id
			if (mytype == 'text' || mytype == 'hidden')
				temp = temp + t + "=" + escape(myform.elements[i].value);
			else if (mytype == 'checkbox' || mytype == 'radio')
				temp = temp + t + "=" + escape(myform.elements[i].checked);
			else if (mytype == 'select-one' || mytype == 'select-multiple')
				temp = temp + t + "=" + escape(myform.elements[i][myform.elements[i].selectedIndex].value);
			if (i < form_length - 1)
				temp = temp + "&";
		}
	}
	temp = temp.substring(temp, temp.length - 1)

	return temp;
} 

/**************************************************************
 DaysInMonth: Return number of days in a month.

 Parameters:
      dDate = Date to process. If date is null, false is
              returned.

 Returns: Integer
***************************************************************/
function DaysInMonth(dDate)
{
	if (dDate == null)
		return (false);

	dDate = new Date(dDate)

	var dt1, cmn1, cmn2, dtt, lflag, dycnt
	var temp1 = dDate.getMonth() + 1;
	var temp2 = dDate.getYear();
	dt1 = new Date(temp2, temp1 - 1, 1)
	cmn1 = dt1.getMonth()
	dtt = dt1.getTime() + 2332800000
	lflag = true
	dycnt = 28
	while (lflag)
	{
		dtt = dtt + 86400000
		dt1.setTime(dtt)
		cmn2 = dt1.getMonth()
		if (cmn1 != cmn2)
			lflag = false
		else
			dycnt = dycnt + 1;
	}
	if (dycnt > 31)
		dycnt = 31;

    return dycnt;
}

/**************************************************************
 Abs: Returns a value of the same type that is passed to it 
      specifying the absolute value of a number.

 Parameters:
      Number = The required number argument can be any valid 
               numeric expression. If number contains Null, 
               false is returned; if it is an uninitialized 
               variable, false is returned.

 Returns: Long
***************************************************************/
function Abs(Number)
{
	Number = Number.toLowerCase();
	RefString = "0123456789.-";

	if (Number.length < 1) 
		return (false);

	for (var i = 0; i < Number.length; i++) 
	{
		var ch = Number.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}

	if (Number < 0)
		return (Number * -1)

	return Number;
}

/**************************************************************
 Len: Returns a Long containing the number of characters in a 
      string or the number of bytes required to store a 
      variable.

 Parameters:
      string = Any valid string expression. If string contains 
               null, false is returned.

 Returns: Long
***************************************************************/
function Len(string)
{
	if (string == null)
		return (false);

	return String(string).length;
}

/**************************************************************
 Chr: Returns a String containing the character associated 
      with the specified character code.

 Parameters:
      CharCode = Long that identifies a character.

 Returns: String
***************************************************************/
function Chr(CharCode)
{
	return String.fromCharCode(CharCode);
}

/**************************************************************
 Asc: Returns an Integer representing the character code 
      corresponding to the first letter in a string

 Parameters:
      String = The required string argument is any valid 
               string expression. If the string if not in 
               the range 32-126, the function return ZERO

 Returns: Integer
***************************************************************/
function Asc(string)
{
	var symbols = " !\"#$%&'()*+'-./0123456789:;<=>?@";
	var loAZ = "abcdefghijklmnopqrstuvwxyz";
	symbols += loAZ.toUpperCase();
	symbols += "[\\]^_`";
	symbols += loAZ;
	symbols += "{|}~";
	var loc;
	loc = symbols.indexOf(string);
	if (loc > -1)
	{ 
		Ascii_Decimal = 32 + loc;
		return (32 + loc);
	}
	return (0);
}

/**************************************************************
 LTrim: Returns a String containing a copy of a specified 
        string without leading spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function LTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for (i = 0; i < String.length; i++)
	{
		if (String.substr(i, 1) != ' ' &&
		    String.substr(i, 1) != '\t')
			break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function RTrim(String)
{
	var i = 0;
	var j = String.length - 1;

	if (String == null)
		return (false);

	for(j = String.length - 1; j >= 0; j--)
	{
		if (String.substr(j, 1) != ' ' &&
			String.substr(j, 1) != '\t')
		break;
	}

	if (i <= j)
		return (String.substr(i, (j+1)-i));
	else
		return ('');
}

/**************************************************************
 RTrim: Returns a String containing a copy of a specified 
        string without both leading and trailing spaces 

 Parameters:
      String = The required string argument is any valid 
               string expression. If string contains null, 
               false is returned

 Returns: String
***************************************************************/
function Trim(String)
{
	if (String == null)
		return (false);

	return RTrim(LTrim(String));
}

/**************************************************************
 Left: Returns a String containing a specified number of 
       characters from the left side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Left(String, Length)
{
	if (String == null)
		return (false);

	return String.substr(0, Length);
}

/**************************************************************
 Right: Returns a String containing a specified number of 
        characters from the right side of a string.

 Parameters:
      String = String expression from which the leftmost 
               characters are returned. If string contains null, 
               false is returned.
      Length = Numeric expression indicating how many characters 
               to return. If 0, a zero-length string ("") is 
               returned. If greater than or equal to the number 
               of characters in string, the entire string is 
               returned. 

 Returns: String
***************************************************************/
function Right(String, Length)
{
	if (String == null)
		return (false);

    var dest = '';
    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	String = dest;
	String = String.substr(0, Length);
	dest = '';

    for (var i = (String.length - 1); i >= 0; i--)
		dest = dest + String.charAt(i);

	return dest;
}

/**************************************************************
 Mid: Returns a String containing a specified number of 
      characters from a string

 Parameters:
      String = String expression from which characters are 
               returned. If string contains null, false is 
               returned.
      Start  = Number. Character position in string at which 
               the part to be taken begins. If Start is 
               greater than the number of characters in 
               string, Mid returns a zero-length string ("").
      Length = Number of characters to return. If omitted 
               false is returned. 

 Returns: String
***************************************************************/
function Mid(String, Start, Length)
{
	if (String == null)
		return (false);

	if (Start > String.length)
		return '';

	if (Length == null || Length.length == 0)
		return (false);

	return String.substr((Start - 1), Length);
}

/**************************************************************
 InStr: Returns a Long specifying the position of the first 
        occurrence of one string within another. Is String1
        or String2 are null, false is returned.

 Parameters:
      String1 = String expression being searched.
      String2 = String expression sought

 Returns: Integer
***************************************************************/
function InStr(String1, String2)
{
	var a = 0;

	if (String1 == null || String2 == null)
		return (false);

	String1 = String1.toLowerCase();
	String2 = String2.toLowerCase();

	a = String1.indexOf(String2);
	if (a == -1)
		return 0;
	else
		return a + 1;
}

/**************************************************************
 Sgn: Returns an Integer indicating the sign of a number. If
      Integer is not a number the functions return false.

 Parameters:
      Integer = The number argument can be any valid numeric 
                expression.

 Returns: Integer       -1 If Integer < 0
                         0 If Integer = 0
                         1 If Integer > 0
                     false If Parameter IS NOT NUMERIC
***************************************************************/
function Sgn(Integer)
{
	Number = Integer.toLowerCase();
	RefString = "0123456789-";

	if (Number.length < 1) 
		return (false);

	for (var i = 0; i < Number.length; i++) 
	{
		var ch = Number.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	if (Integer < 0)
		return (-1);
	else if (Integer == 0)
		return (0);
	else
		return (1);
}

/**************************************************************
 LBound: Returns a Long containing the smallest available 
         subscript for the indicated dimension of an array

 Parameters:
      array = Array to verify

 Returns: Integer       (-1 if Array does not contain
                            any subscript)
***************************************************************/
function LBound(array)
{
	var i = 0;
	var temp = '';

	if (array.length == 0)
		return (-1);

	for (i = 0; i < array.length; i++)
	{
		temp = array[i]
		if (temp != null)
		{
			var temp = i;
			return temp;
		}
	}
	return (-1);
}

/**************************************************************
 UBound: Returns a Long containing the largest available 
         subscript for the indicated dimension of an array

 Parameters:
      array = Array to verify

 Returns: Integer       (-1 if Array does not contain
                            any subscript)
***************************************************************/
function UBound(array)
{
	return (array.length - 1);
}

/**************************************************************
 Join: Returns a string created by joining a number of 
       substrings contained in an array.

 Parameters:
      array     = One-dimensional array containing substrings 
                  to be joined
      Delimiter = String character used to separate the 
                  substrings in the returned string. 
                  If delimiter is a zero-length string (""), 
                  all items in the list are concatenated 
                  with no delimiters. 

 Returns: String
***************************************************************/
function Join(array, Delimiter)
{
	var temp = '';

	if (array.length == 0)
		return '';

	if (Delimiter.length == 0)
		Delimiter = ' ';

	for (var i = 0; i < array.length; i++)
	{
		temp = temp + array[i]
		if (i < array.length - 1)
			temp = temp + Delimiter;
	}
	return temp;
}

/**************************************************************
 ReturnString: Returns a String containing a repeating 
               character string of the length specified

 Parameters:
      Number    = Length of the returned string. If number 
                  is less than 1, false is returned.
      Character = Character code specifying the character or 
                  string expression whose first character is 
                  used to build the return string. If character 
                  contains null, false is returned. 

 Returns: String
***************************************************************/
function ReturnString(Number, Character)
{
	var temp = '';

	if (Number < 1)
		return (false);

	if (Character.length == 0)
		return (false);

	if (Character.length > 1)
		Character = Character.charAt(0);

	for (var i = 0; i < Number; i++)
	{
		temp = temp + Character
	}

	return temp;
}

/**************************************************************
 Split: Returns a zero-based, one-dimensional array containing 
        a specified number of substrings

 Parameters:
      Expression = String expression containing substrings and 
                   delimiters. If expression is a zero-length 
                   string(""), Split returns an empty array, 
                   that is, an array with no elements and no 
                   data.
      Delimiter  = String character used to identify substring 
                   limits. If delimiter is a zero-length 
                   string (""), a single-element array 
                   containing the entire expression string 
                   is returned.

 Returns: String
***************************************************************/
function Split(Expression, Delimiter)
{
	var temp = Expression;
	var a, b = 0;
	var array = new Array();

	if (Delimiter.length == 0)
	{
		array[0] = Expression;
		return (array);
	}

	if (Expression.length == '')
	{
		array[0] = Expression;
		return (array);
	}

	Delimiter = Delimiter.charAt(0);

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Delimiter);
		if (a == -1)
		{
			array[i] = temp;
			break;
		}
		else
		{
			b = (b + a) + 1;
			var temp2 = temp.substring(0, a);
			array[i] = temp2;
			temp = Expression.substr(b, Expression.length - temp2.length);
		}
	}

	return (array);
}

/**************************************************************
 Space: Returns a String consisting of the specified number 
        of spaces

 Parameters:
      Number = Number of spaces you want in the string.

 Returns: String
***************************************************************/
function Space(Number)
{
	var temp = '';

	if (Number < 1)
		return '';

	for (var i = 0; i < Number; i++)
	{
		temp = temp + ' ';
	}
	return temp;
}

/**************************************************************
 Replace: Returns a string in which a specified substring has 
          been replaced with another substring a specified 
          number of times.

 Parameters:
      Expression = String expression containing substring to 
                   replace
      Find       = Substring being searched for.
      Replace    = Replacement substring.

 Returns: String
***************************************************************/
function Replace(Expression, Find, Replace)
{
	var temp = Expression;
	var a = 0;

	for (var i = 0; i < Expression.length; i++) 
	{
		a = temp.indexOf(Find);
		if (a == -1)
			break
		else
			temp = temp.substring(0, a) + Replace + temp.substring((a + Find.length));
	}

	return temp;
}

/**************************************************************
 IsChar: Returns a Boolean value indicating whether an 
         expression can be evaluated as a character (this 
         not only includes alpha chars but all symbols such as
         @#$%^&|\_+-/*="!?,.:;'(){}<>[]

 Parameters:
    - Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsChar(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a != -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 ReverseString: Returns a string in which the character order 
                of a specified string is reversed

 Parameters:
      Expression = The expression argument is the string whose 
                   characters are to be reversed. If expression 
                   is a zero-length string (""), a zero-length 
                   string is returned. If expression is null,
                   false is returned.

 Returns: String
***************************************************************/
function ReverseString(Expression)
{
	if (Expression == null)
		return (false);

    var dest = '';
    for (var i = (Expression.length - 1); i >= 0; i--)
		dest = dest + Expression.charAt(i);
    return dest;
}

/**************************************************************
 StrConv: Returns a String converted as specified in the
          Parameters Section.

 Parameters:
      String     = String expression to be converted.
      Conversion = Number specifying the type of conversion 
                   to perform.
                   1 = TO UPPER CASE
                   2 = to lower case
                   3 = To Proper Case
                   If Conversion is null or not specified 1
                   is set as default.

 Returns: String
***************************************************************/
function StrConv(String, Conversion)
{
	var index;
	var tmpStr;
	var tmpChar;
	var preString;
	var postString;
	var strlen;

	if (Conversion == null || Conversion.length == 0)
		Conversion = '1';

	if (Conversion != '1' && Conversion != '2' && Conversion != '3')
		Conversion = '1';

	if (Conversion == '1')
		return String.toUpperCase();

	if (Conversion == '2')
		return String.toLowerCase();

	//Proper Case
	tmpStr = String.toLowerCase();
	strLen = tmpStr.length;
	if (strLen > 0)
	{
		for (index = 0; index < strLen; index++)
		{
			if (index == 0)
			{
				tmpChar = tmpStr.substring(0, 1).toUpperCase();
				postString = tmpStr.substring(1, strLen);
				tmpStr = tmpChar + postString;
			}
			else
			{
				tmpChar = tmpStr.substring(index, index + 1);
				if (tmpChar == " " && index < (strLen - 1))
				{
					tmpChar = tmpStr.substring(index + 1, index + 2).toUpperCase();
					preString = tmpStr.substring(0, index + 1);
					postString = tmpStr.substring(index + 2,strLen);
					tmpStr = preString + tmpChar + postString;
				}
			}
		}
	}
	return tmpStr;
}

/**************************************************************
 ComboAdd: Add a new item to a SELECT HTML object at runtime.

 Parameters:
      Object = SELECT Object ID
      Value  = Value of the String ... <option VALUE="?????">....</option>
      String = String to add.

 Returns: None
***************************************************************/
function ComboAdd(Object, Value, String)
{
	Value = Trim(Value)
	String = Trim(String)

	if (Value.length < 1 || String.length < 1)
		return false

	Object[Object.length] = new Option(String, Value);
	Object.selectedIndex = Object.length;
}

/**************************************************************
 ComboDel: Delete the current/selected item from a SELECT 
           HTML object at runtime.

 Parameters:
      Object = SELECT Object ID

 Returns: None
***************************************************************/
function ComboDel(Object)
{
	var selected_index = Object.selectedIndex
	if (selected_index >= 0)
	{
		Object.options[Object.selectedIndex] = null;
		if (selected_index > 0)
			Object.selectedIndex = selected_index
		else
			Object.selectedIndex = 0;
	}
}

/**************************************************************
 FormatNumber: Returns an expression formatted as a number.

 Parameters:
      Expression            = Expression to be formatted.
      NumDigitsAfterDecimal = Numeric value indicating how
                              many places to the right of the
                              decimal are displayed.

 Returns: String
***************************************************************/
function FormatNumber(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec;
	}
	else
	{
		return strWhole + "." + strDec;
	}
}

/**************************************************************
 FormatCurrency: Returns an expression formatted as a currency 
                 value using the currency symbol $.

 Parameters:
      Expression = Expression to be formatted.

 Returns: String
***************************************************************/
function FormatCurrency(Expression)
{
	var iNumDecimals = 2;
	var dbInVal = Expression;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-$" + strWhole + "." + strDec;
	}
	else
	{
		return "$" + strWhole + "." + strDec;
	}
}

/**************************************************************
 FormatPercent: Returns an expression formatted as a 
                percentage (multipled by 100) with a 
                trailing % character

 Parameters:
      Expression = Expression to be formatted.

 Returns: String
***************************************************************/
function FormatPercent(Expression, NumDigitsAfterDecimal)
{
	var iNumDecimals = NumDigitsAfterDecimal;
	var dbInVal = Expression * 100;
	var bNegative = false;
	var iInVal = 0;
	var strInVal
	var strWhole = "", strDec = "";
	var strTemp = "", strOut = "";
	var iLen = 0;

	if (dbInVal < 0)
	{
		bNegative = true;
		dbInVal *= -1;
	}

	dbInVal = dbInVal * Math.pow(10, iNumDecimals)
	iInVal = parseInt(dbInVal);
	if ((dbInVal - iInVal) >= .5)
	{
		iInVal++;
	}
	strInVal = iInVal + "";
	strWhole = strInVal.substring(0, (strInVal.length - iNumDecimals));
	strDec = strInVal.substring((strInVal.length - iNumDecimals), strInVal.length);
	while (strDec.length < iNumDecimals)
	{
		strDec = "0" + strDec;
	}
	iLen = strWhole.length;
	if (iLen >= 3)
	{
		while (iLen > 0)
		{
			strTemp = strWhole.substring(iLen - 3, iLen);
			if (strTemp.length == 3)
			{
				strOut = "," + strTemp + strOut;
				iLen -= 3;
			}
			else
			{
				strOut = strTemp + strOut;
				iLen = 0;
			}
		}
		if (strOut.substring(0, 1) == ",")
		{
			strWhole = strOut.substring(1, strOut.length);
		}
		else
		{
			strWhole = strOut;
		}
	}
	if (bNegative)
	{
		return "-" + strWhole + "." + strDec + "%";
	}
	else
	{
		return strWhole + "." + strDec + "%";
	}
}

/**************************************************************
 FormatDateTime: Returns an expression formatted as a date or 
                 time. If DateTime is null then false is
                 returned.

 Parameters:
      DateTime   = Date/Time expression to be formatted
      FormatType = Numeric value that indicates the date/time 
                   format used. If omitted, GeneralDate is used
                   0 = Very Long Date/Time Format (Mon Jul 10, 12:02:30 am EDT 2000)
                   1 = Long Date/Time Format (Monday, July 10, 2000)
                   2 = Short Date (1/10/00)
                   3 = Long Time (4:20 PM)
                   4 = Military Time (14:43)

 Returns: String
***************************************************************/
function FormatDateTime(DateTime, FormatType)
{
	if (DateTime == null)
		return (false);

	if (FormatType < 0)
		FormatType = 1;

	if (FormatType > 4)
		FormatType = 1;

	var strDate = new String(DateTime);

	if (strDate.toUpperCase() == "NOW")
	{
		var myDate = new Date();
		strDate = String(myDate);
	}
	else
	{
		var myDate = new Date(DateTime);
		strDate = String(myDate);
	}

	var Day = new String(strDate.substring(0, 3));
	if (Day == "Sun") Day = "Sunday";
	if (Day == "Mon") Day = "Monday";
	if (Day == "Tue") Day = "Tuesday";
	if (Day == "Wed") Day = "Wednesday";
	if (Day == "Thu") Day = "Thursday";
	if (Day == "Fri") Day = "Friday";
	if (Day == "Sat") Day = "Saturday";	

	var Month = new String(strDate.substring(4, 7)), MonthNumber = 0;
	if (Month == "Jan") { Month = "January"; MonthNumber = 1; }
	if (Month == "Feb") { Month = "February"; MonthNumber = 1; }
	if (Month == "Mar") { Month = "March"; MonthNumber = 1; }
	if (Month == "Apr") { Month = "April"; MonthNumber = 1; }
	if (Month == "May") { Month = "May"; MonthNumber = 1; }
	if (Month == "Jun") { Month = "June"; MonthNumber = 1; }
	if (Month == "Jul") { Month = "July"; MonthNumber = 1; }
	if (Month == "Aug") { Month = "August"; MonthNumber = 1; }
	if (Month == "Sep") { Month = "September"; MonthNumber = 1; }
	if (Month == "Oct") { Month = "October"; MonthNumber = 1; }
	if (Month == "Nov") { Month = "November"; MonthNumber = 1; }
	if (Month == "Dec") { Month = "December"; MonthNumber = 1; }

	var curPos = 11;
	var MonthDay = new String(strDate.substring(8, 10));
	if (MonthDay.charAt(1) == " ")
	{
		MonthDay = "0" + MonthDay.charAt(0);
		curPos--;
	}	

	var MilitaryTime = new String(strDate.substring(curPos, curPos + 5));
	var Year = new String(strDate.substring(strDate.length - 4, strDate.length));

	// Format Type decision time!
	if (FormatType == 1)
		strDate = Day + ", " + Month + " " + MonthDay + ", " + Year;
	else if (FormatType == 2)
		strDate = MonthNumber + "/" + MonthDay + "/" + Year.substring(2,4);
	else if (FormatType == 3)
	{
		var AMPM = MilitaryTime.substring(0,2) >= 12 && MilitaryTime.substring(0,2) != "24" ? " PM" : " AM";
		if (MilitaryTime.substring(0,2) > 12)
			strDate = (MilitaryTime.substring(0,2) - 12) + ":" + MilitaryTime.substring(3,MilitaryTime.length) + AMPM;
		else
		{
			if (MilitaryTime.substring(0,2) < 10)
				strDate = MilitaryTime.substring(1,MilitaryTime.length) + AMPM;
			else
			strDate = MilitaryTime + AMPM;
		}
	}	
	else if (FormatType == 4)
		strDate = MilitaryTime;

	return strDate;
}

/**************************************************************
 IsNumber2: Returns a Boolean value indicating whether an 
           expression can be evaluated as a number (this
           includes values like $15,656.00)

 Parameters:
      Expression = Variant containing a numeric expression or 
                   string expression.

 Returns: Boolean
***************************************************************/
function IsNumber2(Expression)
{
	Expression = Expression.toLowerCase();
	RefString = "0123456789.-";

	if (Expression.length < 1) 
		return (false);

	for (var i = 0; i < Expression.length; i++) 
	{
		var ch = Expression.substr(i, 1)
		var a = RefString.indexOf(ch, 0)
		if (a == -1)
			return (false);
	}
	return(true);
}

/**************************************************************
 Mask: Returns a Boolean if the specified Expression match
       the specified Mask.

 Parameters:
      Expression = String to validate
      Mask       = String that can contain the following
                   options:
                   9 = only numbers (0..9)
                   X = only letters (a..z or A..Z)
                   * = Anything...
 Example: alert(Mask("(954) 572-4419", "(999) 999-9999")); => TRUE
          alert(Mask("33351-820", "99999-9999"));          => FALSE
          alert(Mask("This is a test", "XXXXXX"));         => FALSE
          alert(Mask("This 34 a test", "**************")); => TRUE

 Returns: Boolean
***************************************************************/
function Mask(Expression, Mask)
{
	Mask = Mask.toUpperCase();
	LenStr = Expression.length;
	LenMsk = Mask.length;
	if ((LenStr == 0) || (LenMsk == 0))
		return (false);
	if (LenStr != LenMsk)
		return (false);
	TempString = '';
	for (Count = 0; Count <= Expression.length; Count++)
	{
		StrChar = Expression.substring(Count, Count + 1);
		MskChar = Mask.substring(Count, Count + 1);
		if (MskChar == '9')
		{
			if(!IsNumber2(StrChar))
				return (false);
		}
		else if (MskChar == 'X')
		{
			if(!IsChar(StrChar))
				return (false);
		}
		else if (MskChar == '*')
		{
			if(!IsAlphanumeric(StrChar))
				return (false);
		}
		else
		{
			if (MskChar != StrChar) 
				return (false);
		}
	}
	return (true);
}

/**************************************************************
 IsEmail: Returns a Boolean if the specified Expression is a
          valid e-mail address. If Expression is null, false
          is returned.

 Parameters:
      Expression = e-mail to validate.

 Returns: Boolean
***************************************************************/
function IsEmail(Expression)
{
	if (Expression == null)
		return (false);

	var supported = 0;
	if (window.RegExp)
	{
		var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;
	}
	if (!supported) 
		return (Expression.indexOf(".") > 2) && (Expression.indexOf("@") > 0);
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	return (!r1.test(Expression) && r2.test(Expression));
}

/**************************************************************
 DayOfWeek: Returns a String specifying a name of the day
            for a given date.

 Parameters:
      dDate = Date to evaluate. The Date can be one of the
              following formats: '7/6/2000' or 'July 4, 1830'

 Returns: String
***************************************************************/
function DayOfWeek(dDate)
{
	var ar = new Array();
	ar[0] = "Sunday";   ar[1] = "Monday"; ar[2] = "Tuesday";  ar[3] = "Wednesday";
	ar[4] = "Thursday";	ar[5] = "Friday"; ar[6] = "Saturday";
	var dow = new Date(dDate);
	var day = dow.getDay();
	return ar[day];
}

/**************************************************************
 AddDays: Returns a Date containing a date to which a 
          specified days interval has been added to the
          current date.

 Parameters:
      DaysToAdd = Numeric expression that is the interval of 
                  days you want to add to the actual date.

 Returns: Date/String
***************************************************************/
function AddDays(DaysToAdd)
{
	var newdate = new Date();
	var newtimems = newdate.getTime() + (DaysToAdd * 24 * 60 * 60 * 1000);
	newdate.setTime(newtimems);
	return newdate.toLocaleString();
}

/**************************************************************
 AllowOnly: This function allow entering just the specified
            Expression to a textbox or textarea control.

 Parameters:
      Expression = Allowed characters.
                   a..z => ONLY LETTERS
                   0..9 => ONLY NUMBERS
                   other symbols...

 Example: use the onKeyPress event to make this function work:
          //Allows only from A to Z
          onKeyPress="AllowOnly('a..z');"

          //Allows only from 0 to 9
          onKeyPress="AllowOnly('0..9');"

          //Allows only A,B,C,1,2 and 3
          onKeyPress="AllowOnly('abc123');"

          //Allows only A TO Z,@,#,$ and %
          onKeyPress="AllowOnly('a..z|@#$%');"

		  //Allows only A,B,C,0 TO 9,.,,,+ and -
          onKeyPress="AllowOnly('ABC|0..9|.,+-');"

 Remarks: Use the pipe "|" symbol to separate a..z from 0..9 and symbols

 Returns: None
***************************************************************/
function AllowOnly(Expression)
{
	Expression = Expression.toLowerCase();
	Expression = Replace(Expression, 'a..z', 'abcdefghijklmnopqrstuvwxyz');
	Expression = Replace(Expression, '0..9', '0123456789');
	Expression = Replace(Expression, '|', '');

	var ch = String.fromCharCode(window.event.keyCode);
	ch = ch.toLowerCase();
	Expression = Expression.toLowerCase();
	var a = Expression.indexOf(ch);
	if (a == -1) 
		window.event.keyCode = 0;
}

/**************************************************************
 LeapYear: Return a Boolean if the speficied Year is a Leap
           Year

 Parameters:
      Year = Numeric expression that represents the Year.

 Returns: Boolean
***************************************************************/
function LeapYear(Year)
{    
	if(Year % 4 == 0 && Year % 100 != 0 || Year % 400 ==0)
		return true;
	return false;
}


function highlight()
{
	event.srcElement.style.background = "Navy" //<= change value to change background color
	event.srcElement.style.color = "White"     //<= change value to change fore color
	if (event.srcElement.toolTip != '')
		window.status = event.srcElement.toolTip
}

function lowlight()
{
	event.srcElement.style.backgroundColor = "#D4D0C8"
	event.srcElement.style.color = "Black"
	window.status = ''
}

/**************************************************************
 IsDate: Returns a Boolean (true) if the date is true, false
         is not

 Parameters:
	- DateStr: String date in format (MM/DD/YYYY)

 Returns: Boolean
***************************************************************/
function IsDate(dateStr)
{
	// Checks for the following valid date formats:
	// MM/DD/YYYY   MM-DD-YYYY

	var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

	var matchArray = dateStr.match(datePat)
	if (matchArray == null)
		return false

	month = matchArray[1]
	day = matchArray[3]
	year = matchArray[4]
	if (month < 1 || month > 12)
		return false

	if (day < 1 || day > 31)
		return false

	if ((month==4 || month==6 || month==9 || month==11) && day==31)
		return false

	if (month == 2)
	{
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
		if (day>29 || (day==29 && !isleap))
			return false;
	}
	return true;
}

/**************************************************************
 CheckBoxes: Checks, unchecks or switch the values of the
             checkboxes in a form.

 Parameters:
    - f_form: String. Name of the Form <FORM...>
    - Start : Number: Checkbox to start with (0 to start from 
              the first one
    - Length: Number: How many checkboxes after the Start 
              you want to check, uncheck or switch
    - Method: Strign: c = Check, u = Uncheck, s = Switch

 Returns: None
***************************************************************/
function CheckBoxes(f_form, Start, Length, Method)
{
	var s_type = ''

	Method = Method.toLowerCase()

	if (Start == 0) {Start = 0} else {Start = Start - 1}
	if (Length == 0) {Length = f_form.elements.length}

	for (var i = Start; i < Start + Length; i++)
	{
		s_type = f_form.elements[i]
		if (s_type.type == 'checkbox')
		{
			if (Method == 'c')
				s_type.checked = true
			if (Method == 'u')
				s_type.checked = false
			if (Method == 's')
				s_type.checked = !s_type.checked
		}
	}

	return
}

/**************************************************************
 DateDiff: Returns the Difference between two dates in weeks,
           days, hours, minutes & seconds

 Parameters:
    - Date1: First Date
    - Date2: Second Data

 Returns: String containing the weeks, days, hours, minutes &
          seconds between the two dates.
***************************************************************/
function DateDiff(Date1, Date2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();

	date1temp = new Date(Date1);
	date1.setTime(date1temp.getTime());
	date2temp = new Date(Date2);
	date2.setTime(date2temp.getTime());

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;

	return (weeks + " weeks, " + days + " days, " + hours + " hours, " + mins + " minutes, and " + secs + " seconds");
}

/**************************************************************
 MinutesDiff: Returns the number of minutes between two dates.

 Parameters:
    - Date1: First date
    - Date2: Second data

 Returns: Number
***************************************************************/
function MinutesDiff(Date1, Date2)
{
	date1 = new Date();
	date2 = new Date();
	diff  = new Date();

	date1temp = new Date(Date1);
	date1.setTime(date1temp.getTime());

	date2temp = new Date(Date2);
	date2.setTime(date2temp.getTime());

	diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
	timediff = diff.getTime();

	weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
	timediff -= weeks * (1000 * 60 * 60 * 24 * 7);

	days = Math.floor(timediff / (1000 * 60 * 60 * 24)); 
	timediff -= days * (1000 * 60 * 60 * 24);

	hours = Math.floor(timediff / (1000 * 60 * 60)); 
	timediff -= hours * (1000 * 60 * 60);

	mins = Math.floor(timediff / (1000 * 60)); 
	timediff -= mins * (1000 * 60);

	secs = Math.floor(timediff / 1000); 
	timediff -= secs * 1000;

	return (mins + (hours * 60) + (days * 24 * 60) + (weeks * 7 * 24 * 60))
}



/**************************************************************
                               Tips
 **************************************************************/

/*
 - Want to keep a window in top of other? 
   use: <body onblur="self.focus()"> on the window you want to
        keep in top

 - Want to make a textbox read only?
   use: <INPUT TYPE="text" NAME="output" SIZE="30" onFocus="this.blur()">

 - Want to highlight the whole textbox or textarea box?
   use: <INPUT TYPE="text" NAME="output" SIZE="30" onFocus="this.select();">
*/

function LCase(Value) {
	return Value.toString().toLowerCase();
}
function UCase(Value) {
	return Value.toString().toUpperCase();
}
function InStrRev(StringCheck, StringMatch, Start, Compare) {
	if (Start == 0 || Start < -1) {
		alert("Invalid Start argument\n\nInStrRev function (js2vb.js)"); return "";
	}
	if (Len(StringMatch) == 0) return Start;
	if (Compare == 1) {StringCheck = LCase(StringCheck); StringMatch = LCase(StringMatch);}
	if (Start > 1) {
		return Left(StringCheck, Start).lastIndexOf(StringMatch) + 1;
	} else {
		return StringCheck.lastIndexOf(StringMatch) + 1;
	}
}
function IsNull(Expression) {
	return (Expression == null);
}
function IsEmpty(Expression) {
	return (Expression.toString().length == 0);
}
function IsObject(Expression) {
	return (typeof Expression == "object");
}
function IsArray(VarName) {
	return (VarName.constructor.toString().indexOf("Array") == -1);
}
function MonthName(Month, Abbreviate) {
	var months = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
	if (Month < 1 || Month > 13) {
		alert("Invalid Month argument\n\nMonthName function (js2vb.js)"); return "";
	}
	var retval = months[Month - 1]; 
	if (Abbreviate) retval = Left(retval, 3);
	return retval;
}
function WeekdayName(Weekday, Abbreviate, FirstDayOfWeekValue) {
	var weekdays = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
	if (Weekday < 1 || Weekday > 7) {
		alert("Invalid Weekday argument\n\nWeekdayName function (js2vb.js)"); return "";
	}
	if (FirstDayOfWeekValue < 0 || FirstDayOfWeekValue > 7) {
		alert("Invalid FirstDayOfWeekValue argument\n\nWeekdayName function (js2vb.js)"); return "";
	}
	var addval = (FirstDayOfWeekValue > 1) ? FirstDayOfWeekValue : 0;
	if (Weekday + addval > 7) addval -= 7;
	return weekdays[Weekday + addval - 1];
}

// setting Hot Keys >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
function netscapeKeyPress(e) { // for netscape 
    if (e.modifiers == 2) {
        //if (e.which == 25) alert('Ctrl and y pressed'); 
    }
    else if (e.modifiers == 4) { 
        if (e.which == 83) {alert('Shift and S pressed'=Save);}
        if (e.which == 78) {alert('Shift and N pressed=New');}
        if (e.which == 69) {alert('Shift and E pressed=Edit');}
        if (e.which == 86) {alert('Shift and V pressed=View');}
    }
}
function microsoftKeyPress() {// for IE
	//alert(window.event.keyCode);
    if (window.event.ctrlKey) {
        //if (window.event.keyCode == 5 ) alert('Ctrl and e pressed');        
        if (window.event.keyCode == 19) {document.getElementById('imgSave').click();}//alert('Shift and S pressed=Save');}
        if (window.event.keyCode == 14) {document.getElementById('imgAdd').click();}//alert('Shift and N pressed=New');
        if (window.event.keyCode == 5) {document.getElementById('imgEdit').click();}//alert('Shift and E pressed=Edit');}
        if (window.event.keyCode == 22) {document.getElementById('imgView').click();}//alert('Shift and V pressed=View');}

    }
    else if (window.event.shiftKey) {
		//if (window.event.keyCode == 83) {document.getElementById('imgSave').click();}//alert('Shift and S pressed=Save');}
        //if (window.event.keyCode == 78) {document.getElementById('imgAdd').click();}//alert('Shift and N pressed=New');
        //if (window.event.keyCode == 69) {document.getElementById('imgEdit').click();}//alert('Shift and E pressed=Edit');}
        //if (window.event.keyCode == 86) {document.getElementById('imgView').click();}//alert('Shift and V pressed=View');}
    }
}
if (navigator.appName == 'Netscape') {
    window.captureEvents(Event.KEYPRESS);
    window.onKeyPress = netscapeKeyPress;
}

function funCancel(){
	//window.history.back(-1);
	document.forms[0].reset();
}
document.onkeydown=BlockSingleQuot;	
function BlockSingleQuot(e)
{
//
     if(window.event && (event.keyCode==39 || event.keyCode==222))
     {
       return false;
     }
}

function ChkNumber(field, e ,ln) 
        {        
            var strCheck = '0123456789';
            if(ln<=field.value.length && ln!=0) return false;
            var whichCode = (window.Event) ? e.which : e.keyCode;        
            if (whichCode == 13) return true;  // Enter
            if (whichCode == 8) return true;  // Delete
            key = String.fromCharCode(whichCode);  // Get key value from key code        
            if (strCheck.indexOf(key) == -1) 
            {
                    e.keyCode=0;
                    return false;  // Not a valid key        
            }
         }	
function checkdate(input)
{

    var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity
    var returnval=false;
    if(input.value.split("-").length==3)
    {
        var monthfield=input.value.split("-")[1]
        monthfield=convertToNumericMon(monthfield);
        if(monthfield.toString().length==1)
            monthfield='0' + monthfield
        var dayfield=input.value.split("-")[0]
        
        var yearfield=input.value.split("-")[2]
        var inputStr=dayfield+ '/' + monthfield  + '/' + yearfield;
        
        if (!validformat.test(inputStr))
            fireMessage("Invalid Date Format.")
        else
        { //Detailed check for valid date ranges
//            var monthfield=input.value.split("/")[0]
//            var dayfield=input.value.split("/")[1]
//            var yearfield=input.value.split("/")[2]
            var dayobj = new Date(yearfield, monthfield-1, dayfield)
            if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))
                fireMessage("Invalid Day, Month, or Year range detected.")
            else
                returnval=true
        }
    }
    else
    {
        fireMessage("Invalid Date Format.")
    }
    
    if (returnval==false) input.select()
    return returnval
}
