﻿// JScript File

    function validateDate(args)
    {
        var iDay, iMonth, iYear;
        var arrValues;
        arrValues = args.Value.split("/");
        iMonth = arrValues[0];
        iDay = arrValues[1];
        iYear = arrValues[2];

        var testDate = new Date(iYear, iMonth - 1, iDay);
        if ((testDate.getDate() != iDay) ||
          (testDate.getMonth() != iMonth - 1) ||
          (testDate.getFullYear() != iYear))
        {
            return false;
        }
          
        return true;
    }

    function Has_Value(ctrl){
        var txt = document.getElementById(ctrl);
        if(txt.value == "" || txt.value == null){
            return false;
        }
        return true;
    }

    function Is_Checked(ctrl){
        var chk = document.getElementById(ctrl);
        if(chk.checked == true){
            return true;
        }
        return false;        
    }    
    
    function Has_Rows(ctrl){
        var gv = document.getElementById(ctrl);
        if(gv != null){
	        if(gv.rows.length>=2) return true;
        }
        return false;
    }
    
    function Args_Has_Value(args){
        if(args.Value == "" || args.value == null){
            return false;
        }
        else{
            return true;
        }
    }

	function Validate_SelEquip(oSrc, args){
		var gv = document.getElementById("fvEvents_gvSelEquipment");
		var bValid = false;
		if(gv != null){
			var currRow;
			for(currRow = 1; currRow < gv.rows.length; currRow++){
				var ctl;
				var i = currRow + 1;
				if(i < 10){
					ctl = "fvEvents_gvSelEquipment_ctl0" + i + "_chkSelEquip";
				}
				else{
					ctl = "fvEvents_gvSelEquipment_ctl" + i + "_chkSelEquip";
				}
				var chk = document.getElementById(ctl);
				if(chk.checked == true){
					bValid = true;
					break;
				}
			}
		}
		args.IsValid = bValid;
	}
    
    function Check_State(oSrc, args){
        var id = oSrc.controltovalidate;
        var cbo = document.getElementById(id);
        var begin;
        var end = 0;
        
        begin = id.indexOf("_", 0);
        while (begin > 0){
            end = begin + 1;
            begin = id.indexOf("_", end);
        }
        id = id.substring(0,end) + 'cboCountry';
        if(Is_State_Required(id) && cbo.value ==""){
            args.IsValid = false;
        }
        else args.IsValid = true;
    }
    
    function Is_State_Required(ctrl){
        var cbo = document.getElementById(ctrl);
        if(cbo.value == "USA" || cbo.value == "Canada"){
            return true;
        }
        else{
            return false;
        }
    }
