function Validator(frmname)
{
	
  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
function form_submit_handler()
{
	for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate())
		{
		  return false;
		}
	}
	if(this.addnlvalidation)
	{
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}
function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)
	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
    this.itemobj.focus();
		return false;
 }
 return true;
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}
function V2validateData(strValidateStr,objValue,strError) 
{ 
   
  
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    switch(command) 
    { 
        case "req": 
        case "required": 
         { 
           if(eval(objValue.value.length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" characters maximum "; 
               }//if 
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               alert(strError + "\n[Current length = " + objValue.value.length + " ]"); 
               return false;                 
             }//if 
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alpha-numeric characters allowed "; 
                }//if 
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "numfloat": 
        case "numericfloat": 
           { 
              var charpos = objValue.value.search("[^0-9.]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;               
           }//numericfloat 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only digits allowed "; 
                }//if               
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Only alphabetic characters allowed "; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 
              break; 
           }//alpha 
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": characters allowed are A-Z,a-z,0-9,- and _"; 
                }//if                             
                alert(strError + "\n [Error character position " + eval(charpos+1)+"]"); 
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid Email address "; 
                 }//if                                               
                 alert(strError); 
                 return false; 
               }//if 
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : value should be less than "+ cmdvalue; 
              }//if               
              alert(strError); 
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Should be a number "); 
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : value should be greater than "+ cmdvalue; 
               }//if               
               alert(strError); 
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
		 	if(objValue.value.length > 0)
			{
	            if(!objValue.value.match(cmdvalue)) 
	            { 
	              if(!strError || strError.length ==0) 
	              { 
	                strError = objValue.name+": Invalid characters found "; 
	              }//if                                                               
	              alert(strError); 
	              return false;                   
	            }//if 
			}
           break; 
         }//case regexp 
        case "dontselect": 
         { 
			
            if(objValue.selectedIndex == null) 
            { 
              alert("BUG: dontselect command for non-select Item"); 
              return false; 
            }
            
             if(objValue.selectedIndex == 0) 
            { 
             
			  alert(strError); 
              return false; 
            }
            
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             
             if(!strError || strError.length ==0) 
              { 
              strError = objValue.name+": Please Select one option "; 
              }//if                                                               
              alert(strError); 
              return false;                                   
             } 
             break; 
         }//case dontselect 
         
         case "checkbox": 
         { 
			
            
            
             if(objValue.checked == false) 
            { 
             
			  alert(strError); 
              return false; 
            }
            
            
             break; 
         }//case dontselect 
         
    }//switch 
    return true; 
}
/*
	Copyright 2003 JavaScript-coder.com. All rights reserved.
*/

/* checking for check box value i.e. one of the item should be selected */
function validateChkBox(field)
{
	var i, flag;
	field=document.getElementsByName (field)
	for (i = 0; i < field.length; i++)
	{
		if (field[i].checked)
		{
			flag = true;
			break;
		}
	}
	if (flag != true)
	{
		alert("Please select the required check box options.");
		return false;
	}
	else
		return true;		
}

/* checking for list box value i.e. one of the item should be selected */
function validateLst(field) 
{
	/*alert(field);
	//field=document.getElementByName(field)
	if (field.selectedIndex == -1) 
	{
		alert("Please select the required list box options.");
	    return false;
	}*/
	if (field == 1) 
	{
		alert("Please select the required list box options.");
	    return false;
	}
	else
	{	
		return true;
	}	
}

/* checking for radio button value i.e. one of the item should be selected */
function validateRdo(field) 
{
	field=document.getElementsByName(field)
	var i, flag;
	for (i = 0; i < field.length; i++)
	{
		if (field[i].checked)
		{
			flag = true;
			break;
		}
	}
	if (flag != true)
	{
		alert("Please select the required radio button options.");
		return false;
	}
	else
		return true;
}

/* checking for text box or text area value i.e. cannt be blank */
function validateText(field) 
{
	field=document.getElementById(field)
	if (field.value.length == 0)
	{
		alert("Please enter the Required text value.");
		field.focus();
		return false;
	}
	else
		return true;
}

/* checking for list box value i.e. one of the item should be selected */
function validateCboBox(field) 
{
	field=document.getElementById(field)
	if (field.selectedIndex == 0) 
	{
		alert("Please select the required combo box options.");
	    return false;
	}
	else
		return true;
}

/*function to check or uncheck all ticket checkbox*/
var checked = false;
function check(field) 
{
     if (!checked) 
     { // if checkboxes are not checked then check them
          for (i = 0; i < field.length; i++) 
          { // loop through the array of checkboxes & check them
               field[i].checked = true;
          }
          checked = true;
          return ;
     }
     else 
     {
          for (i = 0; i < field.length; i++) 
          { // loop through the array of checkboxes & uncheck them
               field[i].checked = false;
          }
          checked = false;
          return ;
     }
}
		
/* Go through all the check boxes. return an array of all the ones
   that are selected (their position numbers). if no boxes were checked,
   returned array will be empty (length will be zero) */

function getSelectedCheckbox(buttonGroup)
{
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) 
   { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) 
      {
         if (buttonGroup[i].checked) 
         {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } 
   else 
   { // There is only one check box (it's not an array)
      if (buttonGroup.checked) 
      { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
} // function ends

/* Function return an array of values selected in the check box group. if no boxes
   were checked, returned array will be empty (length will be zero) */

function getSelectedCheckboxValue(buttonGroup) 
{
	var retArr = new Array(); // set up empty array for the return values
	var selectedItems = getSelectedCheckbox(buttonGroup);
	if (selectedItems.length != 0) 
	{ // if there was something selected
		retArr.length = selectedItems.length;
		for (var i=0; i<selectedItems.length; i++) 
		{
			if (buttonGroup[selectedItems[i]]) 
			{ // Make sure it's an array
				retArr[i] = buttonGroup[selectedItems[i]].value;
			} 
			else 
			{ // It's not an array (there's just one check box and it's selected)
				retArr[i] = buttonGroup.value;// return that value
			}
		}
	}
	return retArr;
} // function ends

/*Function to delete any leading or trailing (left or right) spaces from a string
  returns a trimed string*/

function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
		return"";
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
		return "";
	else
		return TRIM_VALUE;
} //End Function

/*Function to delete any leading (left) spaces from a string
  returns a trimed string*/

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
		return"";
	var iTemp = v_length -1;

	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	} //End While
	return strTemp;
} //End Function

/*Function to delete any trailing (right) spaces from a string
  returns a trimed string*/

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
		return"";
	var v_length = VALUE.length;
	var strTemp = "";

	var iTemp = 0;

	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	} //End While
	return strTemp;
} //End Function

/*Function to convert a string in proper case 
  returns a converted string*/

function PCase(STRING)
{
	var strReturn_Value = "";
	var iTemp = STRING.length;
	if(iTemp==0)
		return"";
	var UcaseNext = false;
	strReturn_Value += STRING.charAt(0).toUpperCase();
	for(var iCounter=1;iCounter < iTemp;iCounter++)
	{
		if(UcaseNext == true)
			strReturn_Value += STRING.charAt(iCounter).toUpperCase();
		else
			strReturn_Value += STRING.charAt(iCounter).toLowerCase();
		var iChar = STRING.charCodeAt(iCounter);
		if(iChar == 32 || iChar == 45 || iChar == 46)
			UcaseNext = true;
		else
			UcaseNext = false;
		if(iChar == 99 || iChar == 67)
		{
			if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109)
				UcaseNext = true;
		}
	} //End For
	return strReturn_Value;
} //End Function

/*Function to remove extra space between words also coverts the first word in proper case
  returns a formated string */

function TextTidy(VALUE)
{
	var STRING = VALUE;
	var strReturn_Value = "";
	var iTemp = STRING.length;
	if(iTemp==0)
		return"";
	var stri = " i ";
	var strI = " I ";
	
	while(STRING.indexOf(stri) > -1)
		STRING = STRING.replace(stri,strI);

	while(STRING.indexOf("  ") > -1)
		STRING = STRING.replace("  "," ");

	var UcaseNext = false;
	strReturn_Value += STRING.charAt(0).toUpperCase();

	for(var iCounter=1;iCounter < iTemp;iCounter++)
	{
		if(UcaseNext == true)
			strReturn_Value += STRING.charAt(iCounter).toUpperCase();
		else
			strReturn_Value += STRING.charAt(iCounter);
	
		var iChar = STRING.charCodeAt(iCounter);
		if(iChar == 46 || iChar == 33 || iChar == 63)
		{
			if(STRING.charCodeAt(iCounter+1)==32)
			{
				strReturn_Value += (STRING.substring(iCounter+1,iCounter+2)) + " ";
				iCounter+=1;
			}
			UcaseNext = true;
		}
		else if(iChar==13 && STRING.charCodeAt(iCounter+1)==10)
		{
			iCounter+=1;
			//Comment out the next line if you want to stop capitalization on a new line
			UcaseNext = true;
		}
		else if(iChar==44 && STRING.charCodeAt(iCounter+1)!=32)
			strReturn_Value += (STRING.substring(iCounter,iCounter)) + " ";
		else
			UcaseNext = false
		if(iChar == 99 || iChar == 67)
		{
			if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109)
				UcaseNext = true;
		}
	} //End For
	return strReturn_Value;
} //End Function

/* Function to Validate whether the new password and confirm password are same. */
function ValidatePassword(NewPassword, ConfirmNewPassword)
{
	//alert(NewPassword + " n ");
	//alert(ConfirmNewPassword + " c");
	//alert(NewPassword == ConfirmNewPassword);
  if(NewPassword == ConfirmNewPassword)
	return true;
  else
  {
    alert("The new password and confirm password doesn't match.");
    return false;
  }
}

/*This function 
  first removes any special characters
  trims the text
  remove extra spaces between words
  converts the text in proper case 
  return the formated text*/
function ProperFormat(sText)
{
	sText = RemoveSpecialCharacters(sText);
	sText = Trim(sText);
	sText = TextTidy(sText);
	sText = PCase(sText);
	return sText;
}

/*This function 
  first removes any special characters
  trims the text
  remove extra spaces between words
  return the formated text*/
function PartialFormat(sText)
{
	sText = RemoveSpecialCharacters(sText);
	sText = Trim(sText);
	sText = TextTidy(sText);
	return sText;
}

/* Remove special characters from a string
   retuns a without special characters string.*/
function RemoveSpecialCharacters(sText) 
{
	var re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$|\./g;
	// remove special characters like "$" and "," etc...
	return sText.replace(re, "");
}
 
/* Detect special characters in text box. Or any character you subsitute for the special characters.
	    var iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?";
        for (var i = 0; i < document.formname.fieldname.value.length; i++) 
        {
                if (iChars.indexOf(document.formname.fieldname.value.charAt(i)) != -1) 
                {
					alert ("The box has special characters. \nThese are not allowed.\n");
					return false;
				}
        }
 */
 
/* Function to check the type of file uploaded */

function TestFileType(fileName, fileTypes, GroupName) 
{
	var ext_pos, aFileTypes, iCnt;
	if (!fileName || !fileTypes) 
		return;
	
	//get the part AFTER the LAST period.
	ext_pos = fileName.lastIndexOf('.');
	
	aFileTypes = fileTypes.split(",");
	
	for (iCnt = 0; iCnt < aFileTypes.length; iCnt++)
	{
		if (fileName.substring(ext_pos + 1) == aFileTypes[iCnt] && (GroupName != 'Administrator'))
		{
			alert("Please upload files that do not have extension in : " + aFileTypes.join(", ") + ". \nPlease select a new file and try again. \nTo do this you must be an Administrator.");
			return false;
		}
	}
	return true;
}
/* Function to remove all spaces entered by user */
function removeSpaces(string) 
{
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
		tstring += splitstring[i];
	return tstring;
}


// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s)
{
	var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) 
			return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}

function DaysArray(n) 
{
	for (var i = 1; i <= n; i++) 
	{
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	
	if (strDay.charAt(0)=="0" && strDay.length>1) 
		strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) 
		strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) 
	{
		if (strYr.charAt(0)=="0" && strYr.length>1) 
			strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1)
	{
		alert("The date format should be : mm/dd/yy.")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12)
	{
		alert("Please enter a valid month.")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month])
	{
		alert("Please enter a valid day.")
		return false
	}
	if (strYear.length != 2 || year==0)
	{
		alert("Please enter a valid 2 digit year.")
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false)
	{
		alert("Please enter a valid date.")
		return false
	}
	return true
}

 function ValidateDateDiff(start, end, current, bDaily) 
 {
    var iOut = 0;
    
    var startMsg = "Check the start, end and current date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var bufferA = Date.parse(start) ;
    var bufferB = Date.parse(end) ;
    var bufferC = Date.parse(current) ;
    	
    // check that the start parameter is a valid Date. 
    if (isNaN (bufferA) || isNaN (bufferB) || isNaN(bufferC)) 
    {
        alert(startMsg) ;
        return false;
    }
        
    var number = bufferB-bufferA ;
    
    iOut = parseInt(number / 86400000) ;
    iOut += parseInt((number % 86400000)/43200001) ;
    
	if (bDaily == true && iOut < 0)
	{
		alert("Date cannot be greater than " + current + ".")
		return false
	}
	else
	{
		if (bDaily == true && iOut > 0)
			return true
	}

    if (iOut == 0 && bDaily == true)
		return true
		
	if (bDaily == false)
	{
		if (iOut < 0)
		{
			alert("From date cannot be greater than to date.")
			return false
		}
		
		if ((bufferA > bufferC) || (bufferB > bufferC))
		{
			alert("From and to date cannot be greater than " + current + ".")
			return false
		}
		else
			return true
	}
}

 function ValidateDiff(start, end) 
 {
    var iOut = 0;
    
    var startMsg = "Check the start, end date\n"
        startMsg += "must be a valid date format.\n\n"
        startMsg += "Please try again." ;
		
    var bufferA = Date.parse(start) ;
    var bufferB = Date.parse(end) ;
    	
    // check that the start parameter is a valid Date. 
    if (isNaN (bufferA) || isNaN (bufferB)) 
    {
        alert(startMsg) ;
        return false;
    }
        
    var number = bufferB-bufferA ;
    
    iOut = parseInt(number / 86400000) ;
    iOut += parseInt((number % 86400000)/43200001) ;
    
	if (iOut < 0)
	{
		alert("From date cannot be greater than to date.")
		return false
	}
	else
		return true
}

/*
NOTES:
The optional CheckTLD argument will verify that the address ends in a two-letter country or well-known TLD.
This can be disabled by sending a value of false.
Both routines use the TITLE attribute of the form element in validity warning messages.
*/

var knownDomsPat=/^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|pro|museum|co|uk)$/;

function ValidateDomain(FormField,NoWWW,CheckTLD) 
{
	// NoWWW and CheckTLD are optional, both accept values of true, false, and null.
	// NoWWW is used to check that a domain name does not begin with 'www.', eg. for WHOIS lokkups.
	DomainName=FormField.value.toLowerCase();
	if (CheckTLD==null) {CheckTLD=true}
	var specialChars="/\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars="\[^\\s" + specialChars + "\]";
	var atom=validChars + '+';
	var atomPat=new RegExp("^" + atom + "$");
	var domArr=DomainName.split(".");
	var len=domArr.length;
	if (len==1) {alert("Invalid domain name."); FormField.focus(); return false}
	for (i=0;i<len;i++) {if (domArr[i].search(atomPat)==-1) {alert("Invalid domain name."); FormField.focus(); return false}}
	if ((CheckTLD) && (domArr[domArr.length-1].length!=2) && (domArr[domArr.length-1].search(knownDomsPat)==-1)) {alert("Domain name must end in a well-known domain or two letter country."); FormField.focus(); return false}
	if ((NoWWW) && (DomainName.substring(0,4).toLowerCase()=="www.")) {alert("Invalid domain name starts with www."); FormField.focus(); return false}
	return true;
}

/*This is For Showing Contenent when checkbox is checked */

var enablepersist="off" //Enable saving state of content structure using session cookies? (on/off)
var collapseprevious="no" //Collapse previously open content when opening present? (yes/no)

var contractsymbol='- ' //HTML for contract symbol. For image, use: <img src="whatever.gif">
var expandsymbol='+ ' //HTML for expand symbol.


if (document.getElementById){
document.write('<style type="text/css">')
document.write('.switchcontent{display:none;}')
document.write('</style>')
}

function getElementbyClass(rootobj, classname){
var temparray=new Array()
var inc=0
var rootlength=rootobj.length
for (i=0; i<rootlength; i++){
if (rootobj[i].className==classname)
temparray[inc++]=rootobj[i]
}
return temparray
}

function sweeptoggle(ec){
var thestate=(ec=="expand")? "block" : "none"
var inc=0
while (ccollect[inc]){
ccollect[inc].style.display=thestate
inc++
}
revivestatus()
}


function contractcontent(omit){
var inc=0
while (ccollect[inc]){
if (ccollect[inc].id!=omit)
ccollect[inc].style.display="none"
inc++
}
}

function expandcontent(curobj, cid){

//alert(curobj);
var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")

if (ccollect.length>0){

if (collapseprevious=="yes")
contractcontent(cid)

document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"

if (showstateobj.length>0){ //if "showstate" span exists in header

if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()

}
}
}

function expandcontent1(curobj, cid){


var spantags=curobj.getElementsByTagName("SPAN")
var showstateobj=getElementbyClass(spantags, "showstate")
var ccollect="1,2";
if (ccollect.length>0){

if (collapseprevious=="yes")
contractcontent(cid)

document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="block")? "block" : "none"

if (showstateobj.length>0){ //if "showstate" span exists in header

if (collapseprevious=="no")
showstateobj[0].innerHTML=(document.getElementById(cid).style.display=="block")? contractsymbol : expandsymbol
else
revivestatus()

}
}
}

function revivecontent(){
contractcontent("omitnothing")
selectedItem=getselectedItem()
selectedComponents=selectedItem.split("|")
for (i=0; i<selectedComponents.length-1; i++)
document.getElementById(selectedComponents[i]).style.display="block"
}

function revivestatus(){
var inc=0
while (statecollect[inc]){
if (ccollect[inc].style.display=="block")
statecollect[inc].innerHTML=contractsymbol
else
statecollect[inc].innerHTML=expandsymbol
inc++
}
}

function get_cookie(Name) { 
var search = Name + "="
var returnvalue = "";
if (document.cookie.length > 0) {
offset = document.cookie.indexOf(search)
if (offset != -1) { 
offset += search.length
end = document.cookie.indexOf(";", offset);
if (end == -1) end = document.cookie.length;
returnvalue=unescape(document.cookie.substring(offset, end))
}
}
return returnvalue;
}

function getselectedItem(){
if (get_cookie(window.location.pathname) != ""){
selectedItem=get_cookie(window.location.pathname)
return selectedItem
}
else
return ""
}

function saveswitchstate(){
var inc=0, selectedItem=""
while (ccollect[inc]){
if (ccollect[inc].style.display=="block")
selectedItem+=ccollect[inc].id+"|"
inc++
}

document.cookie=window.location.pathname+"="+selectedItem
}

function do_onload(){
uniqueidn=window.location.pathname+"firsttimeload"
var alltags=document.all? document.all : document.getElementsByTagName("*")
ccollect=getElementbyClass(alltags, "switchcontent")
statecollect=getElementbyClass(alltags, "showstate")
if (enablepersist=="on" && ccollect.length>0){
document.cookie=(get_cookie(uniqueidn)=="")? uniqueidn+"=1" : uniqueidn+"=0" 
firsttimeload=(get_cookie(uniqueidn)==1)? 1 : 0 //check if this is 1st page load
if (!firsttimeload)
revivecontent()
}
if (ccollect.length>0 && statecollect.length>0)
revivestatus()
}

if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload

if (enablepersist=="on" && document.getElementById)
window.onunload=saveswitchstate

/* End for showing content when checkbox is checked*/



/* Validations at Arrow */


function textCounter(field,maxlimit) 
{
if (field.value.length > maxlimit) // if too long trim it
	field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
//else
//cntfield.value = maxlimit - field.value.length;
}


function checkForStringOfSpaces (String)
{
var count = 0 ;
for (var i = 0 ; i < String.length ; i++ )
{	
	if ( String.charAt(i) == " " )
		count++ ;
}

if ( count == String.length )
	return true; 
return false ;
}



function navigateValues(lst1,lst2,direction,subscriptToStartFrom)
{


	/* This function navigates all the values from one listbox to another 
	   list box , specified by the user in particular direction. user using the 
	   function will have to specify the perdefined search direction.
	   1. moveForward 
	   2. moveBackward
	   3. moveAllForward
	   4. moveAllBackward
	   
	   and the starting subscript as 'subscriptToStartFrom'. from here only transfer 
	   of text will occur.
	*/

	var IdentifyNavigation = direction;
	
	if ( IdentifyNavigation == "moveForward")
	{
		transferForward(lst1,lst2,subscriptToStartFrom);
		return true;
	}
	if ( IdentifyNavigation == "moveBackward")
	{
		transferBackward(lst1,lst2,subscriptToStartFrom);
		return true;
	}
	if ( IdentifyNavigation == "moveAllForward")
	{
		transferAllForward(lst1,lst2,subscriptToStartFrom);
		return true;
	}
	if ( IdentifyNavigation == "moveAllBackward")
	{
		transferAllBackward(lst1,lst2,subscriptToStartFrom);
		return true;
	}
	return false;
}

function transferForward(originbox,destinationbox,subscriptToStartFrom)
{

	var newindex = 0 ;
	var optionValue ; 
	var index ;
	var stringBefore , stringAfter , len ;
	
		for ( i = subscriptToStartFrom ; i < originbox.options.length ; i++ )
		{ 
			if (originbox.options[i].selected )
			{
				newindex = i ;
				var curr_index = destinationbox.options.length ;  
				index = elementsToBeDeleted.indexOf(originbox.options[i].value)
				if ( index != -1 ) 
				{
					stringBefore = elementsToBeDeleted.substring(0,index-1)
					len = originbox.options[i].value.length 
					stringAfter = elementsToBeDeleted.substring(index+len,elementsToBeDeleted.length)
					elementsToBeDeleted = stringBefore + stringAfter
				}
				
				var newOption = new Option (originbox.options[i].text, originbox.options[i].value) ;
				destinationbox.options[curr_index] = newOption ; 
				originbox.options[i] = null ;  
				i-- ;
			}
		}
}

function transferBackward(originbox,destinationbox,subscriptToStartFrom)
{
	/*====================================================================
	File Description    It is a generalized function which moves the text from
						one listbox to another in backward direction.
	====================================================================*/

	var newindex = 0 ;
	for ( i = subscriptToStartFrom ; i < destinationbox.options.length ; i++ )
	{ 
		if ( destinationbox.options[i].selected )
		{
			newindex = i ;
			var curr_index = originbox.options.length ;
			var newOption = new Option (destinationbox.options[i].text, destinationbox.options[i].value);
			if(elementsToBeDeleted=="")
			{	elementsToBeDeleted = destinationbox.options[i].value
			}
			else
			{	elementsToBeDeleted = elementsToBeDeleted + "," + destinationbox.options[i].value
			}
				
			originbox.options[curr_index] = newOption ; 
			destinationbox.options[i] = null ; 
			i-- ;
	    }
	}
} 

function transferAllBackward(originbox,destinationbox,subscriptToStartFrom)
{
	/*====================================================================
	File Description    It is a generalized function which moves all the elements from
						one listbox to another in backward direction.
	====================================================================*/

	var i = subscriptToStartFrom ;
	elementsToBeDeleted = ""
	while ( destinationbox.options.length > i )
	{
		var curr_index = originbox.options.length  ;
		var newOption = new Option (destinationbox.options[i].text, destinationbox.options[i].value) ;
		if(elementsToBeDeleted=="")
		{	elementsToBeDeleted = destinationbox.options[i].value
		}
		else
		{	elementsToBeDeleted = elementsToBeDeleted + "," + destinationbox.options[i].value
		}	
		originbox.options[curr_index] = newOption; 
		destinationbox.options[i] = null ;  // to delete the option that has been moved
	}
}

function transferAllForward(originbox,destinationbox,subscriptToStartFrom)
{
	/*====================================================================
	File Description    It is a generalized function which moves all the elements from
						one listbox to another in forward direction.
	====================================================================*/

	var i = subscriptToStartFrom ;
	elementsToBeDeleted = "" 
	while (originbox.options.length > i )
	{
	    var curr_index = destinationbox.options.length  ;
		index = elementsToBeDeleted.indexOf(originbox.options[i].value)
		if ( index != -1 ) 
		{
			stringBefore = elementsToBeDeleted.substring(0,index-1)
			len = originbox.options[i].value.length 
			stringAfter = elementsToBeDeleted.substring(index+len,elementsToBeDeleted.length)
			elementsToBeDeleted = stringBefore + stringAfter
		}

		var newOption = new Option (originbox.options[i].text, originbox.options[i].value) ;
		destinationbox.options[curr_index] = newOption ; 
		originbox.options[i] = null ;
	}
	return true;
}


/*
USAGE -- 
  sourceListBox1 - first list box object
  sourceListBox2 - second list box object
  destinationListBox - list box where mapped values are to be displayed object
  
  e.g. - 
		mapListBoxes(window.document.frmAssociateSectionsWithClass.availableClasses, window.document.frmAssociateSectionsWithClass.availableSections, window.document.frmAssociateSectionsWithClass.selectedClassSections)		
*/
function mapListBoxes(sourceListBox1,sourceListBox2,destinationListBox)
{
	/*====================================================================
	File Description    It is a generalized function which maps the text from
						two listboxes to third listbox 
	====================================================================*/


	var i;
	var insideFor ;
	insideFor = false ;
	var newOptionText , newOptionValue ;
	var elementSelected ;
	var newOption ;
	
	len = sourceListBox1.options.length
	for(i=1 ;i<len;i++)
	{
		newOptionText = ""
		newOptionValue = "-2|-|"
		elementSelected = false
		
		if(sourceListBox1.options[i].selected==true)
		{	
			insideFor = true ;
			//if selected then putting in the array & removing from the list.
			newOptionText = sourceListBox1.options[i].text + " : " ; 
			newOptionValue = newOptionValue + sourceListBox1.options[i].value;

			for(j=1;j<sourceListBox2.options.length;j++)
			{
				if(sourceListBox2.options[j].selected==true)
				{
					//if selected then putting in the array.
					if ( ! elementSelected )
						newOptionText = newOptionText + sourceListBox2.options[j].text  ;
					else
						newOptionText = newOptionText + ", " + sourceListBox2.options[j].text  ;
						
					newOptionValue = newOptionValue + "|-|" + sourceListBox2.options[j].value 
					elementSelected = true
				}  
			}

			//if Sections Array has no value then do not do any thing.
			if ( elementSelected )
			{
				newOption = new Option(newOptionText,newOptionValue);
				//Inserting into Third List box the value of newString.
				if ( destinationListBox.options.length > 0 )
					k = destinationListBox.options.length;
				destinationListBox.options[k++]= newOption;
				
				// removing value from list box 1
				sourceListBox1.options[i]=null;
				len = sourceListBox1.options.length ;
				i-- ;
			}
			else
			{
				alert ("Please select value from " + sourceListBox2.options[0].text + " list box" )
				return false ;
			}
		}
	}
	
	if ( ! insideFor )
		alert ("Please select value from " + sourceListBox1.options[0].text + " list box" )

	}
		
		
		
		function Remove(sourceListBox1,destinationListBox)
		{
			for(var i=1;i<destinationListBox.options.length;i++)
			{
				
				if(destinationListBox.options[i].selected==true)
				{
					var newstring=destinationListBox.options[i].text;
				    var index=newstring.indexOf(" ");
				    index=index+2;
				    var finalString = newstring.substring(index,newstring.indexOf(":"));
				   var newOption= new Option(finalString,finalString);
			if(sourceListBox1.options.length>0)
				 var newindex=sourceListBox1.options.length;
			sourceListBox1.options[sourceListBox1.options.length]= newOption;
			destinationListBox.options[i]=null;
			i--;
				}
			}
		}
		
		
		
		function removeAll(sourceListBox1,destinationListBox)
		{
			for(var i=1;i<destinationListBox.options.length;i++)
			{
				 var newstring=destinationListBox.options[i].text;
				 var index=newstring.indexOf(" ");
				 index=index+2;
				 var finalString = newstring.substring(index,newstring.indexOf(":"));
				var newOption= new Option(finalString,finalString);
			if(sourceListBox1.options.length>0)
				 var newindex=sourceListBox1.options.length;
			sourceListBox1.options[sourceListBox1.options.length]= newOption;
			destinationListBox.options[i]=null;
			i--;
					
			}
		}


	function selectAllElements (listBoxName,subscriptToStartFrom)
	{
		var i ;
		len = listBoxName.options.length ;
		
		// to deselect all the elements present before this subscript
		//for ( i = 0 ;  i < subscriptToStartFrom ; i++ )
		//	listBoxName.options[i].selected = false ;
		
		// to select rest all the elements 
		for ( i = subscriptToStartFrom ; i < len ; i++ )
		{
			if (listBoxName.options[0].selected) {
			    listBoxName.options[0].selected = false;
			}
				listBoxName.options[i].selected = true

		}
	
	}
	
	
	/* Right Extraction */
	
	function Right(str, n)
	{
		if (n <= 0)
		   return "";
		else if (n > String(str).length)
		   return str;
		else {
		   var iLen = String(str).length;
		   return String(str).substring(iLen, iLen - n);
		}
	}

	/* Function For Date Range */
	
	function ChangeDateRange(pSelector) 
	{
		
		
		var	tToday		= new Date()
		var	tBeginDate	= new Date()
		var	tEndDate	= new Date()
		var	tDayOfWeek	= tToday.getDay()
		
		

		// Last Year
		if (pSelector.selectedIndex==0) {
			tBeginDate.setFullYear( tToday.getFullYear() - 1 )
			tBeginDate.setMonth(0)
			tBeginDate.setDate(1)

			tEndDate.setFullYear( tToday.getFullYear() - 1 )
			tEndDate.setMonth(11)
			tEndDate.setDate(31)
		}

		// Last Month
		if (pSelector.selectedIndex==1) {
			tBeginDate.setFullYear( tToday.getFullYear() )
			tBeginDate.setMonth( tToday.getMonth() - 1 )
			tBeginDate.setDate(1)

			tEndDate.setFullYear( tBeginDate.getFullYear() )
			tEndDate.setMonth( tBeginDate.getMonth() + 1)
			tEndDate.setDate(1)								// Set to first of next month
			tEndDate.setDate( tEndDate.getDate() - 1)		// Then subtract one day
		}

		// Last Week (weeks start on Sundays)
		if (pSelector.selectedIndex==2) {
			tBeginDate.setFullYear( tToday.getFullYear() )
			tBeginDate.setMonth( tToday.getMonth() )
			tBeginDate.setDate( tToday.getDate() - tDayOfWeek - 7)

			tEndDate.setFullYear( tBeginDate.getFullYear() )
			tEndDate.setMonth( tBeginDate.getMonth() )
			tEndDate.setDate( tBeginDate.getDate() + 6 )
		}

		// Yesterday
		if (pSelector.selectedIndex==3) {
			tBeginDate.setFullYear( tToday.getFullYear() )
			tBeginDate.setMonth( tToday.getMonth() )
			tBeginDate.setDate( tToday.getDate() - 1 )
			
			tEndDate.setFullYear( tToday.getFullYear() )
			tEndDate.setMonth( tToday.getMonth() )
			tEndDate.setDate( tToday.getDate() - 1 )
		}

		// Today
		if (pSelector.selectedIndex==4) {
			tBeginDate = tToday
			tEndDate = tToday
		}

		// This Week (weeks start on Sundays)
		if (pSelector.selectedIndex==5) {
			tBeginDate.setFullYear( tToday.getFullYear() )
			tBeginDate.setMonth( tToday.getMonth() )
			tBeginDate.setDate( tToday.getDate() - tDayOfWeek )

			tEndDate.setFullYear( tBeginDate.getFullYear() )
			tEndDate.setMonth( tBeginDate.getMonth() )
			tEndDate.setDate( tBeginDate.getDate() + 6 )
		}

		// This Month
		if (pSelector.selectedIndex==6) {
			tBeginDate.setFullYear( tToday.getFullYear() )
			tBeginDate.setMonth( tToday.getMonth() )
			tBeginDate.setDate( 1 )

			tEndDate.setFullYear( tToday.getFullYear() )
			tEndDate.setDate(1)								// Set to first of coming month
			tEndDate.setMonth( tToday.getMonth() + 1)
			tEndDate.setDate( tEndDate.getDate() - 1)		// Then subtract one day
		}

		// This Year
		if (pSelector.selectedIndex==7) {
			tBeginDate.setFullYear( tToday.getFullYear() )
			tBeginDate.setMonth( 0 )
			tBeginDate.setDate( 1 )

			tEndDate.setFullYear( tToday.getFullYear() )
			tEndDate.setMonth(11)
			tEndDate.setDate(31)
		}

		// Any Date
		if (pSelector.selectedIndex==8)
		{
		
			pSelector.form.frmdate.value = ""
			pSelector.form.todate.value = ""
			//pSelector.form.SelectDateRange_.value = pSelector.options[pSelector.selectedIndex].text
		}
		else {
			var smn=parseInt(tBeginDate.getMonth())+ parseInt(1);
			var emn=parseInt(tEndDate.getMonth())+ parseInt(1);
			
			pSelector.form.frmdate.value = smn + "/" +  tBeginDate.getDate() + "/" + Right(tBeginDate.getFullYear(),2)
			pSelector.form.todate.value =  emn + "/" + tEndDate.getDate() + "/" + Right(tEndDate.getFullYear(),2)
		}

	}
	
/* End Date Value */	
function MsgForSpecialCharacterInTextBox(objText)
{
		// remove special characters like "$" and "," etc...
		var iChars = "!@#$%^&*()+=-[]\\\';,/{}|\":<>?' '";
		for (var i = 0; i < objText.value.length; i++) 
		{
											               							 
		        if (iChars.indexOf(objText.value.charAt(i)) != -1) 
		        {
					window.alert ("The box has special characters. \nThese are not allowed.\n");
					objText.focus();
					return false;
				}
		}
		return true;
}

			
		
		
/* 
Function for Radio Button (According to Radio Button value Msg will be flaged) 
// Control Name,Radio Button number,Error Msg,Length of the control,Lable Name
*/
function ValidateSerachinall(objText,i,strError,strLength,strLengthMsg)
{
	
	if (!strLengthMsg) 
	{
		var strLengthMsg="Requested Field";
		var strTextMsg="value";
	}
	else
	{
		var strLengthMsg=strLengthMsg;
		var strTextMsg=strLengthMsg;	
	}
	
	strLengthError="Max length for "+strLengthMsg+" is " + strLength;
	if (i==1)
	{
	
		
	
		if (!V2validateData("req",objText,strError))
		{
			objText.focus();
			return false;
		}
							
		if (!isNaN(objText.value))
		{
				window.alert("Please Enter correct " + strTextMsg);
				objText.focus();
				return false;		
		}
											
		if (!V2validateData("maxlen=" + strLength,objText,strLengthError))
		{
			objText.focus();
			return false;
		}
		
		
											
		if (!MsgForSpecialCharacterInTextBox(objText))
		{
		
			objText.focus();
			return false;									
		}	
		
		
											
	}

	if (i==2)
	{
											
			/*	if (!validateText(objText,strError))
				{
					
					return false;
				}*/
				
				if (!V2validateData("req",objText,strError))
				{
					objText.focus();
					return false;
				}
											
				if (!isNaN(objText.value))
				{
						window.alert("Please Enter correct " + strTextMsg);
						objText.focus();
						return false;		
				}
											
				
				
				if (!V2validateData("maxlen=" + strLength,objText,strLengthError))
				{
					objText.focus();
					return false;
				}
													
				if (!MsgForSpecialCharacterInTextBox(objText))
				{
		
					objText.focus();
					return false;									
				}	


	}

	if (i==3)
	{
	// to check format of mail
												
				if (!V2validateData("req",objText,strError))
				{
					objText.focus();
					return false;
				}
				
				if (!V2validateData("maxlen=" + strLength,objText,strLengthError))
				{
					objText.focus();
					return false;
				}
				
				if (!V2validateData("email",objText))
				{
					objText.focus();
					return false;
				}									
				
			
	}

	if (i==4)
	{
				if (!V2validateData("req",objText,strError))
				{
					objText.focus();
					return false;
				}
				
				if (!V2validateData("maxlen=" + strLength,objText,strLengthError))
				{
					objText.focus();
					return false;
				}
									
	}
	return true;
}

