﻿// JScript File
function Validator(frmname,btnobj)
{
	
	
  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;
	}*/
	
	//alert(this.formobj.elements[btnobj])
	if(this.formobj.elements[btnobj]!=null)
	{
	    this.formobj.elements[btnobj].onclick=form_submit_handler;
	}
	//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()
{
    var objParent=this.form; //document.forms["aspnetForm"];
	for(var itr=0;itr < objParent.elements.length;itr++)
	{
	    
		if(objParent.elements[itr].validationset &&
	   !objParent.elements[itr].validationset.validate())
		{   
		  return false;
		}
	}
	if(objParent.addnlvalidation)
	{
	  str =" var ret = "+objParent.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
	//return false;
}
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))
 {
    try
    {
    this.itemobj.focus();
    }
    catch(e){}
		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;
}
//This Function is created By Amit Sharma on 17/Sept/2008 for vaidate SSN No for 
function isValidSSN(value) { 
    var re = /^([0-6]\d{2}|7[0-6]\d|77[0-2])([ \-]?)(\d{2})\2(\d{4})$/; 
    if (!re.test(value)) { return false; } 
    var temp = value; 
    if (value.indexOf("-") != -1) { temp = (value.split("-")).join(""); } 
    if (value.indexOf(" ") != -1) { temp = (value.split(" ")).join(""); } 
    if (temp.substring(0, 3) == "000") { return false; } 
    if (temp.substring(3, 5) == "00") { return false; } 
    if (temp.substring(5, 9) == "0000") { return false; } 
    return true; 
}

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(trimAll(objValue.value).length) == 0) 
           { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              }//if 
              alert(strError); 
              return false; 
           }//if 
           break;             
         }//case required 
         case"lstonereq": //Created By amit Sharma on 17/Sept/2008 in two text Box at least one req
         {
         if((eval(document.getElementById(cmdvalue).value.length) == 0 ) && (eval(objValue.value.length) == 0))
         {
         
            if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : Required Field"; 
              } 
              alert(strError); 
              return false; 
           }
           break; 
         }
         // case date
          case "date":
        {
//            if( ! isDate(objValue.value)) 
//            { 
//              if(!strError || strError.length ==0) 
//              { 
//                strError = objValue.name + " : Should be Date only"; 
//              }//if 
//              alert(strError); 
              
              return isDate(objValue.value); 
           //}//if 
           break;    
        }// end case date
        // created by Chetan Pareek to check those date fields 
        //which are not mandatory but if value entered it should be date only
        case "dateornull":
        {
//            if( ! isDate(objValue.value)) 
//            { 
//              if(!strError || strError.length ==0) 
//              { 
//                strError = objValue.name + " : Should be Date only"; 
//              }//if 
//              alert(strError); 
              if(eval(objValue.value.length) > 0)
              {
                return isDate(objValue.value); 
              }
           //}//if 
           break;    
        }// end case date
        ///<createdBy>Khushant dhingra</createdBy>
        ///<Summary>Compare input date with Current date, Input date should be less then current date</Summary>
        case "dateCompare":
        {   
           var strDate= document.getElementById("txtCurrDate").value;   // Changed by TR to get server date
           if(isDateMDY(objValue.value))
           {
                var dtCurr = new Date(strDate);
                var bD = objValue.value.split('/');
                if(bD.length==3)
                {
                 var  dtBirth=   new Date(bD[2], bD[0]-1, bD[1]);
                }
                
                var dtEnterdt = dtBirth;//new Date(objValue.value);
                if((dtEnterdt - dtCurr) > 0)
                {
                    if(!strError || strError.length ==0) 
                    { 
                        strError = "Date should be less than current date"; 
                    }
                    
                    alert(strError); 
                      
                    return false;
                }
                else
                {
                    return true;
                }
           }
           break;    
        }// end case date
        case "dateCompareCanNull":
        {
       
            var strDate= document.getElementById("txtCurrDate").value;   // Changed by KD to get server date
            if(eval(objValue.value.length) > 0)
            {
               if(isDateMDY(objValue.value))
               {
                    var dtCurr = new Date(strDate);
                    var bD = objValue.value.split('/');
                    if(bD.length==3)
                    {
                     var  dtBirth=   new Date(bD[2], bD[0]-1, bD[1]);
                    }
                    var dtEnterdt = dtBirth;//new Date(objValue.value);
                    if((dtEnterdt - dtCurr) > 0)
                    {
                        alert('Date should be less than current date');
                        return false;
                    }
                    else
                    {
                        return true;
                    }
               }
             }
           break;    
        }// end case date
        ///<createdBy>Khushant dhingra</createdBy>
        ///<Summary>Compare input date with Current date, Input date should be less then current date</Summary>
        case "dateGrtrThnCurrDateCanNull":
        {
            var strDate= document.getElementById("txtCurrDate").value;   // Changed by KD to get server date
            if(eval(objValue.value.length) > 0)
            {
                if(isDate(objValue.value))
                {
                    var dtCurr = new Date(strDate);
                    var bD = objValue.value.split('/');
                    if(bD.length==3)
                    {
                     var  dtBirth=   new Date(bD[2], bD[1]-1, bD[0]);
                    }
                    var dtEnterdt = dtBirth;//new Date(objValue.value);
                    if((dtEnterdt - dtCurr) < 0)
                    {
                        alert('Date should be greater than or Equal to the current date');
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
            }
            break;    
        }
        case "dateGrtrThnCurrDate":  //Changed by dinkar sharma (dd/MM/yyyy to mm/dd/yyyy)
        {
            var strDate= document.getElementById("txtCurrDate").value;   // Changed by KD to get server date
            if(isDateMDY(objValue.value))
            {
            
                var dtCurr = new Date(strDate);
                var bD = objValue.value.split('/');
                if(bD.length==3)
                {
                 var  dtBirth=   new Date(bD[2], bD[0]-1,bD[1]);
                 
                }
                var dtEnterdt = dtBirth;//new Date(objValue.value);
                if((dtEnterdt - dtCurr) < 0)
                {
                    alert('Date should be greater than or Equal to the current date');
                    return false;
                }
                else
                {
                    return true;
                }
            }
           break;    
        }// end case date
        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 "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 "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 
              if(objValue.value==".")
              {
                alert("Please enter valid Number.");
                return false;
              }
              if(objValue.value.split('.').length > 2)
              {
                  alert("Please enter valid Number.");
                  return false;
              }
              break;               
           }//numericfloat 
        case "onlydigits": 
            {
                var iKeyCode;
	            iKeyCode = event.keyCode;
	            if( iKeyCode < 44 || iKeyCode > 57 ||iKeyCode == 47)
	            {
	            event.keyCode = 0;
	            alert(strError); 
	            }
	            break;
            }
        case "  ": 
           { 
              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 "SSNNo": 
          { 
               if(!isValidSSN(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Enter a valid SSN No"; 
                 }//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 
         //create by khushant to match passwords
         case "match": 
         { 
            if(!objValue.value.match(document.getElementById(cmdvalue).value)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = "New and Confirm password should be matched"; 
              }//if                                                               
              alert(strError); 
              return false;                   
            }//if 
           break;             
         }//case match 
         //case Check From date > to date
         //Naresh
         //Modified by Amit Sharma 
         //date 04/01/08
         case "datematch":
         {
            
         if((eval(document.getElementById(cmdvalue).value.length) > 0 ) && (eval(objValue.value.length) > 0))
         {
        
//         if(eval(cmdvalue.value.length) > 0)
//           {
           //alert("hi2");
            if(isDateMDY(document.getElementById(cmdvalue).value) && isDateMDY(objValue.value))
           {
                var objDtSecond = document.getElementById(cmdvalue).value.split('/');
                var objDtFirst = objValue.value.split('/');
                if(objDtFirst.length==3)
                {
                 var  dtFirst=   new Date(objDtFirst[2], objDtFirst[0]-1, objDtFirst[1]);
                }
                if(objDtSecond.length==3)
                {
                 var  dtSec=   new Date(objDtSecond[2], objDtSecond[0]-1, objDtSecond[1]);
                }
                //var dtEnterdt = dtBirth;//new Date(objValue.value);
                if((dtFirst - dtSec) > 0)
                {
                    if(!strError || strError.length ==0) 
                      { 
                        strError = "Date should be less"; 
                      }//if                                                               
                      alert(strError);
                    return false;
                }
                else
                {
                    return true;
                }
//           }
           }}
           break;    
           
//            var iOut = 0;
//            var bufferA = Date.parse(objValue.value) ;
//            var bufferB = Date.parse(document.getElementById(cmdvalue).value);
//            
////            // check that the start parameter is a valid Date. 
////            if (isNaN (bufferA) || isNaN (bufferB)) 
////            {
////               // alert("Check the start, end date\n"); 
////                return false;
////            }
//            var number = bufferB-bufferA ;
//            iOut = parseInt(number / 86400000) ;
//            iOut += parseInt((number % 86400000)/43200001) ;
//	        if (iOut < 0)
//	        {
//		        alert(strError); 
//		        return false
//	        }
//	        break; 
         }
          
        case "dateequal":
         {
             if((eval(document.getElementById(cmdvalue).value.length) > 0 ) && (eval(objValue.value.length) > 0))
             {
        
                if(isDate(document.getElementById(cmdvalue).value) && isDate(objValue.value))
               {
                    var objDtSecond = document.getElementById(cmdvalue).value.split('/');
                    var objDtFirst = objValue.value.split('/');
                    if(objDtFirst.length==3)
                    {
                     var  dtFirst=   new Date(objDtFirst[2], objDtFirst[1]-1, objDtFirst[0]);
                    }
                    if(objDtSecond.length==3)
                    {
                     var  dtSec=   new Date(objDtSecond[2], objDtSecond[1]-1, objDtSecond[0]);
                    }
                    //var dtEnterdt = dtBirth;//new Date(objValue.value);
                    if((dtFirst - dtSec) != 0)
                    {
                        if(!strError || strError.length ==0) 
                          { 
                            strError = "Date should be same"; 
                          }//if                                                               
                          alert(strError);
                        return false;
                    }
                    else
                    {
                        return true;
                    }
                }
           }
        break;    
        }
         case "datematchornull":
         {
            if(objValue.value!=null && objValue.value!= '')
            {
            if(isDateMDY(objValue.value))
           {
                var objDtSecond = document.getElementById(cmdvalue).value.split('/');
                var objDtFirst = objValue.value.split('/');
                if(objDtFirst.length==3)
                {
                 var  dtFirst=   new Date(objDtFirst[2], objDtFirst[0]-1, objDtFirst[1]);
                }
                if(objDtSecond.length==3)
                {
                 var  dtSec=   new Date(objDtSecond[2], objDtSecond[0]-1, objDtSecond[1]);
                }
                //var dtEnterdt = dtBirth;//new Date(objValue.value);
                if((dtFirst - dtSec) > 0)
                {
                    if(!strError || strError.length ==0) 
                      { 
                        strError = "Date should be less"; 
                      }//if                                                               
                      alert(strError);
                    return false;
                }
                else
                {
                    return true;
                }
           }
           }
           break;    
           }
         
         case "dateGrtrThn":
         {
            if(isDate(document.getElementById(cmdvalue).value) && isDate(objValue.value))
           {
                var objDtSecond = objValue.value.split('/');
                var objDtFirst = document.getElementById(cmdvalue).value.split('/');
                if(objDtFirst.length==3)
                {
                 var  dtFirst=   new Date(objDtFirst[2], objDtFirst[1]-1, objDtFirst[0]);
                }
                if(objDtSecond.length==3)
                {
                 var  dtSec=   new Date(objDtSecond[2], objDtSecond[1]-1, objDtSecond[0]);
                }
                //var dtEnterdt = dtBirth;//new Date(objValue.value);
                if((dtFirst - dtSec) > 0)
                {
                    if(!strError || strError.length ==0) 
                      { 
                        strError = "Date should be greater"; 
                      }//if                                                               
                      alert(strError);
                    return false;
                }
                else
                {
                    return true;
                }
           }
           break; 
        }
        //Naresh Avasthi For check Valid Time
        case "time":
        {
              
              var sArrTime = ""; 
             // alert(objValue.value);
              if(eval(objValue.value.length) > 0)
              {
                var sTime = objValue.value;
                //alert (sTime)
                if (sTime==":")
                {
                    alert("Please enter a valid Time.");
                    return false;
                }
                else 
                {
                    sArrTime = objValue.value.split(':');
                   
                    if (sArrTime.length>2)
                    {
                        alert("Please enter a valid Time.");
                        return false;
                    }
                    else if (sArrTime.length==2)
                    {
                         if(sArrTime[0].length>2 || sArrTime[1].length>2)
                         {
                            alert("Please enter a valid Time.");
                            return false;
                         }
                        
                        if( parseInt(sArrTime[0])>24)
                        {
                            alert("Please enter a valid Time.");
                            return false;
                        }
                        if(parseInt(sArrTime[0])==24)
                        {
                            if( parseInt(sArrTime[1])>0)
                            {
                                alert("Please enter a valid Time.");
                                return false;
                            }
                        }
                        if( parseInt(sArrTime[1])>59)
                        {
                            
                            alert("Please enter a valid Time.");
                            return false;
                        }
                        if(sArrTime[0]="" || !sArrTime[0])
                        {
                            alert("Please enter a valid Time.");
                            return false;
                        }
                        if(sArrTime[1]="" || !sArrTime[1])
                        {
                            alert("Please enter a valid Time.");
                            return false;
                        }
                        
                       
                    }
                    else  
                    {
                        if (sArrTime.length==1)
                        {
                            if( parseInt(sArrTime[0])>24)
                            {
                               alert("Please enter a valid Time.");
                               return false;
                            }
                        }
                    
                    }
                }
              }
              return true;
           break;    
        }
    }//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 strDay=dtStr.substring(0,pos1) //strMonth
	var strMonth=dtStr.substring(pos1+1,pos2)//strDay
	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 : dd/mm/yyyy.")
		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 != 4 || year==0)
	{
		alert("Please enter a valid 4 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
}

/// This Function is created By Amit Sharma for date Valdation In MM/dd/yyyy fromat on 05/Sept/2008

function isDateMDY(dtStr)
{
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1) //strMonth
	var strDay=dtStr.substring(pos1+1,pos2)//strDay
	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/yyyy.")
		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 != 4 || year==0)
	{
		alert("Please enter a valid 4 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) ;
    if(isNaN (bufferA))
    {
        alert(" Please enter start date" ) ;
        return false;
    }
    if(isNaN (bufferB))
    {
        alert(" Please enter end date" ) ;
        return false;
    }
    
    if(!isDate(start) || !isDate(end))
    {
        return false;
    }
    
    // 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;
}

//created by khushant dhingra to trim a string from both sides
function trimAll(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

//created by khushant dhingra to trim a string from right side
function rightTrim(sString) 
{
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
        sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

//created by khushant dhingra to trim a string from left side
function leftTrim(sString) 
{
    while (sString.substring(0,1) == ' ')
    {
        sString = sString.substring(1, sString.length);
    }
    return sString;
}
function stopEnterinCtl(e, btn)
{

    if(e.keyCode == 13)
    {

        document.getElementById(btn).focus();
        //e.keyCode = 0;
    }
}

function MatchDate(objValue,cmdvalue,sMsg)
{
    
    
      if(document.getElementById(objValue).value!=null && document.getElementById(objValue).value!= '')
         {
        
            if(isDate(document.getElementById(cmdvalue).value) && isDate(document.getElementById(objValue).value))
           {
                var objDtSecond = document.getElementById(cmdvalue).value.split('/');
                var objDtFirst = document.getElementById(objValue).value.split('/');
                if(objDtFirst.length==3)
                {
                 var  dtFirst=   new Date(objDtFirst[2], objDtFirst[1]-1, objDtFirst[0]);
                }
                if(objDtSecond.length==3)
                {
                 var  dtSec=   new Date(objDtSecond[2], objDtSecond[1]-1, objDtSecond[0]);
                }
                if((dtFirst - dtSec) > 0)
                {
                   
                      alert(sMsg);
                    return false;
                }
                else
                {
                    return true;
                }

           }
         }
}

// Created By Naresh 
// Date 13/08/2008
// Match Date With Current date
function MatchWithCurDate(objValue,sMsg)
{
      if(document.getElementById(objValue).value!= '')
         {
                var StrDate= document.getElementById("txtCurrDate").value;
                var dtSec = new Date(StrDate);
                var objDtFirst = document.getElementById(objValue).value.split('/');
                if(objDtFirst.length==3)
                {
                 var  dtFirst=   new Date(objDtFirst[2], objDtFirst[1]-1, objDtFirst[0]);
                }
                if((dtFirst - dtSec) < 0)
                {
                    alert(sMsg);
                    return false;
                }
                else
                {
                    return true;
                }
           }
}


function NumericnDecOnly(e, obj)
{   
    if(document.getElementById(obj).value.split('.').length >1 && e.keyCode == 46)
    {
        e.keyCode = 0;
    }
    if((e.keyCode < 48 || e.keyCode > 57) && (e.keyCode != 46))
    {   
        e.keyCode = 0;
    }
}

/*  From Commonfunctions   */
// JScript File
var ConcatenateSymbol = '¶';
var winopen;
function OpenWindow(url,name,menubar,resizable,scrollbars,toolbar, height, width)
{
    var properties = "toolbar = "+ toolbar +", height = " + height;
    properties = properties + ", width=" + width +", menubar="+menubar+", resizable="+resizable+",scrollbars="+scrollbars;
    var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt;
    if(navigator.appName == "Microsoft Internet Explorer") 
    {
        //screenY = document.body.offsetHeight;
        screenY = window.screen.height;
        screenX = window.screen.width;
        }
        else {
        screenY = window.outerHeight
        screenX = window.outerWidth
        }
    
    //alert(navigator.appName);
    //alert(screenX);
    //alert(screenY);
    
    var leftvar = (screenX - width)/2;
    var rightvar = (screenY - height)/2;
    if(navigator.appName == "Microsoft Internet Explorer") 
    {
        leftprop = leftvar;
        topprop = rightvar;
    }
    else 
    {
        leftprop = (leftvar - pageXOffset);
        topprop = (rightvar - pageYOffset);
    }
    properties = properties + ", left = " + leftprop;
    properties = properties + ", top = " + topprop;
    
    //alert(properties);
    
    //Below block is placed in try catch to ignore the error because if site is running in mozilla then there is "permission denied"
    //issue generated when try to close window
    //and on docotor summary report page we should required to open popup one after anohter
    //as when check doctor summary detail for one then if try to open another after that then popup will not be opened]
    //as code was throwing as issue for permission denied
    try
    {
        if (winopen != null && winopen && winopen.open && !winopen.closed)
        {   
            winopen.close();
        }
    }
    catch(e){}
    
    winopen = window.open(url,name,properties);
    
    //if (winopen != null)
        //winopen.focus();
    if (winopen==null || typeof(winopen)=="undefined") 
	{
	    alert("The popup's have been blocked in your browser.\n so you may not be able to view correct functionality.\n Please disable the popup blocking.");
	}
	else
	{
	    winopen.focus();
	}
}
function CloseWindow()
{
    if(winopen!=null)
    {
        if (winopen && winopen.open && !winopen.closed) winopen.close();
    }
    //alert('hi');
}
function ConfirmDel()
{
    return confirm("Are you sure you want to delete this record ?");
}
function ChkDate(dtStr)
{
    var strDate= document.getElementById("txtCurrDate").value;   // Changed by KD to get server date
    var dt = new Date(strDate);
    var dt2 = new Date(document.getElementById(dtStr).value);
    if((dt2 - dt) > 0)
    {
        alert("Date should be less than current date");
        document.getElementById(dtStr).value = "";
    }
}
function AddressClear(Country,State,Disrtict,City)
{
  var arr = document.getElementById(Country).options;
         for(var i =0; i < arr.length; i++)
            {
                strDDServCode = document.getElementById(Country).options[i].text;
                strTServCode = 'INDIA';
                if(strDDServCode == strTServCode)
                {
                    document.getElementById(Country).selectedIndex = Math.abs(i);
                     break; 
                }
                else
               {
                     document.getElementById(Country).selectedIndex=0;
                }
                
            }
            
          arr = document.getElementById(State).options;
         for(var i =0; i < arr.length; i++)
            {
                strDDServCode = document.getElementById(State).options[i].text;
                strTServCode = 'RAJASTHAN';
                if(strDDServCode.toLowerCase() == strTServCode.toLowerCase())
                {
                    document.getElementById(State).selectedIndex = Math.abs(i);
                    break;  
                }
                else
               {
                     document.getElementById(State).selectedIndex=0;
                }
            }
             arr = document.getElementById(Disrtict).options;
         for(var i =0; i < arr.length; i++)
            {
                strDDServCode = document.getElementById(Disrtict).options[i].text;
                strTServCode = 'Jaipur';
                if(strDDServCode.toLowerCase() == strTServCode.toLowerCase())
                {
                    document.getElementById(Disrtict).selectedIndex = Math.abs(i);
                    break;  
                }
                else
               {
                     document.getElementById(Disrtict).selectedIndex=0;
                }
            }
             arr = document.getElementById(City).options;
         for(var i =0; i < arr.length; i++)
            {
                strDDServCode = document.getElementById(City).options[i].text;
                strTServCode = 'Jaipur';
                if(strDDServCode.toLowerCase() == strTServCode.toLowerCase())
                {
                    document.getElementById(City).selectedIndex = Math.abs(i);
                    break;  
                }
                else
               {
                     document.getElementById(City).selectedIndex=0;
                }
            }
}

function Print()
{
    try
    {
        window.print();
        setTimeout("window.close();", 3*1000 ); //  The 2*1000 equals 2 seconds.
        
    }
    catch(e)
    {
        alert(e);
    }
}

function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.


    var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm|aM|pM|Am|Pm))?$/;

    var matchArray = timeStr.match(timePat);
    if (matchArray == null) 
    {
        alert("Time is not in a valid format.");
        return false;
    }
    hour = matchArray[1];
    minute = matchArray[2];
    second = matchArray[4];
    ampm = matchArray[6];

    if (second=="") { second = null; }
    if (ampm=="") { ampm = null }

    if (hour < 0  || hour > 23) 
    {
        alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
        return false;
    }
    if (hour <= 12 && ampm == null) 
    {
        if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) 
        {
            alert("You must specify AM or PM.");
            return false;
        }
    }
    if  (hour > 12 && ampm != null) 
    {
        alert("You can't specify AM or PM for military time.");
        return false;
    }
    if (minute<0 || minute > 59) 
    {
        alert ("Minute must be between 0 and 59.");
        return false;
    }
    if (second != null && (second < 0 || second > 59)) 
    {
        alert ("Second must be between 0 and 59.");
        return false;
    }
return true;
}

function getDate()
{
    var strDate= document.getElementById("txtCurrDate").value;   // Changed by KD to get server date
    var today= new Date(strDate);
    var todayStr;
    var day=0; var month=0; var year=0;
    day= today.getDate();
    month= today.getMonth()+1;
    year= today.getFullYear();
    todayStr= day + "/" + month + "/" + year;
    return todayStr;
}


function formatTime(textField) {
  now = new Date();
  hour = now.getHours();
  min = now.getMinutes();
  sec = now.getSeconds();


    if (min <= 9) {
      min = "0" + min;
    }
    if (sec <= 9) {
      sec = "0" + sec;
    }
    if (hour > 12) {
      hour = hour - 12;
      add = " PM";
    } else {
      hour = hour;
      add = " AM";
    }
    if (hour == 12) {
      add = " PM";
    }
    if (hour == 00) {
      hour = "12";
    }

    textField.value = ((hour<=9) ? "0" + hour : hour) + ":" + min + ":" + sec + add;
  }


function NumericValueOnly(e)
{
    if(!(e.keyCode >= 48 && e.keyCode <= 57))
    {
        e.keyCode = 0; 
    }
}

function OnlyDecimal(event,txtObj)
    {
        //alert(txtObj);
        var keycode = event.charCode ? event.charCode : event.keyCode;
        //if the key isn't the backspace key (which we should allow)
        if( keycode != 8 )
        { 
            //if not a number
            if( (keycode < 48 || keycode > 57) && keycode!=46  )
            {         
            //disable key press
            return false;
            }//end if
            else
            {
            
            // enable keypress
            // checking if more than one decimals
            var arr= window.document.getElementById(txtObj).value.split('.');
            if(arr.length>1 && keycode==46)
            {
                return false;
            }
            return true;
            }//end else
          }//end if
        else
        {
            // enable keypress
            return true;
        }//end else
   }
   
   function chkDecimal(e, obj)
    {
        if(e.keyCode == 46)
        {
            if(document.getElementById(obj).value.split('.').length > 2)
            {
                e.keyCode = 0;
            }
        }
        else if(!(e.keyCode >= 48 && e.keyCode <= 57))
        {
            e.keyCode = 0; 
        }
    }
    
    function imposeMaxLength(Object, MaxLen)
    {
        
        return (Object.value.length <= MaxLen);
    }
    function OnPasteText(obj,MaxLen)
    {
        var iInsertLength = maxlgth - obj.value.length;
          var sData = window.clipboardData.getData("Text").substr(0,iInsertLength);
          var sFinalData = obj.value + ' ' + sData;
          obj.value = sFinalData;
          return false;
    }
    
    
    
    
    /*
    
    Crated by Amit Sharma 1/04/2008
     Pass two ID First for Time Slot(8-9 AM) and second in which time are fill like 8:00:00 AM
    
    
    */
    function TimeFill(ControlID,ValueChangedID)
        {
         var slot =document.getElementById(ControlID).options[document.getElementById(ControlID).selectedIndex].text;
         var arrTimeSlot=slot.split("-");
         sAmTslot = slot.substring(slot.length -2,slot.length);
        sAmTslot=sAmTslot.toUpperCase();
        var str;
        str=arrTimeSlot[0]+":00:00 "+sAmTslot;
        document.getElementById(ValueChangedID).value=str;   
         return true;  
        }
        
    function KeyPressTimeFill(e,ControlID)
	 {
	
	 if(e.keyCode==58)
	 {
	 event.keyCode = 0;
	 document.getElementById(ControlID).value=document.getElementById(ControlID).value+":00:00 ";
	 
	 }
	 if(e.keyCode==97)
	 {
	 event.keyCode = 0;
	 document.getElementById(ControlID).value=document.getElementById(ControlID).value+"AM";
	 
	 }
	 if(e.keyCode==112)
	 {
	 event.keyCode = 0;
	 document.getElementById(ControlID).value=document.getElementById(ControlID).value+"PM";
	 
	 }
	 }
	 
	 ///Function check decimel
function DecimalCheck(ID)
   {
   //alert(ID);
   var objValue=document.getElementById(ID);
   //alert(objValue);
   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 
              if(objValue.value==".")
              {
                alert("Please enter valid Number.");
                return false;
              }
              if(objValue.value.split('.').length > 2)
              {
                  alert("Please enter valid Number.");
                  return false;
              }
              return true;             
   }
   
   //Created By Khushant Dhingra
   //Helps to fetch code while changing drop down value
   function FindCode(txtObj, ddObj)
    {   
        document.getElementById(txtObj).value = "";
        if(document.getElementById(ddObj).selectedIndex > 0)
        {
            document.getElementById(txtObj).value = document.getElementById(ddObj).value.split(ConcatenateSymbol)[1];
        }
    }
    
   //Created By Khushant Dhingra
   //Helps to find value on the basis of text box value
   function FindValue(txtObj, ddObj)
    {   
        var found = false;
        var strDD = new String();
        var strTxt = new String();
        if(document.getElementById(txtObj).value != "")
        {
            var arr = document.getElementById(ddObj).options;
            for(var i =1; i < arr.length; i++)
            {
                strDD = document.getElementById(ddObj).options[i].value.split(ConcatenateSymbol);
                strTxt = document.getElementById(txtObj).value;
                if(strDD[1].toLowerCase() == strTxt.toLowerCase())
                {
                    document.getElementById(ddObj).selectedIndex = Math.abs(i);
                    return;
                }
                else
                {
                    found = false;
                }
            }
            
            if(found == false)
            {
                alert("Please Enter a Valid Code");
                document.getElementById(txtObj).value="";
                document.getElementById(txtObj).focus();
            }
        }
    }
/* ---------------------------------------------*/

/* Created by Khushant Dhingra to confirm the response while making a record active/inactive */
/* Pass 1 in value if try to make a record inactive and 0 if active */
function ConfirmActiveInactive(value)
{
    if(value==1) 
    {    
        return confirm("Are you sure you want to make this record Inactive?");
    }
    else
    {
        return confirm("Are you sure you want to make this record Active?");
    }
}

/*Cretaed By Amit Sharma on 09/Sept/2008 for SHow and Hide textBox */

function setVisibility(divID) 
{
  var visibility=document.getElementById(divID).style.display ;
   if (visibility == "none")
   {
    //var txtBoxID = txtID.divID;
    document.getElementById(divID).style.display = "";
    //document.getElementById(txtBoxID).value = "" ;
   }
   else
   {
    //var txtBoxID = txtID.divID;
    document.getElementById(divID).style.display = 'none';
    //document.getElementById(txtBoxID).focus() ;
   }
   
}

/*Cretaed By Amit Sharma on 10/Oct/2008 for PrintData */
function PrintReport(RootPath,GrdID,Message)
{ 
  if(!ExeclGridDataValidation(GrdID,Message))
    {
    return false;
    }
    var strPath=RootPath +"Reports/PrintData.aspx";
    
    OpenWindow(strPath,'PrintData',0,0,1,0, 500, 800)
        
}

/*Cretaed By Amit Sharma on 10/Oct/2008 for Grid Data row validation */
function ExeclGridDataValidation(GrdID,Message)
{
    if(document.getElementById(GrdID)!=null)
    {
        if(document.getElementById(GrdID).rows.length==1)
        {
            alert(Message);
            return false;
        }
    }
    else
    {
        alert(Message);
        return false;
    }
    return true;
}
/*Cretaed By Amit Sharma on 13/Oct/2008 for Open SummaryDetails Report*/
function SummaryDetailsPopUp(Path)
{ 
    OpenWindow(Path,'SummaryDetails',0,0,1,0, 500, 800);
        
}

function IsPopupBlock()
{
    if(!IsPopupBlocker())
	    alert("The popup's have been blocked in your browser.\n so you may not be able to view correct functionality.\n Please disable the popup blocking.");
}

function IsPopupBlocker() {
    var oWin = window.open("","testpopupblocker","width=100,height=50,top=5000,left=5000");
	
	if (oWin==null || typeof(oWin)=="undefined") 
	{
	    return false;
	} 
	else 
	{
	    oWin.close();
		return true;
	}
}
