﻿

function searchCheck(beginDate, endDate, beginDay, endDay, beginBudget, endBudget,setOut,goal) {

    if (beginDate != "" && (chkDate(beginDate) == 0)) {
        alert("日期格式输入有误!");
 
    } else if (endDate != "" && chkDate(endDate) == 0) {
        alert("日期格式输入有误!");

    } else if (beginDay != "" && chkNum(beginDay)==0) {
        alert("天数必须为数字!");

    } else if (endDay != "" && chkNum(endDay) == 0) {
        alert("天数必须为数字!");
  
    } else if (beginBudget != "" && chkNum(beginBudget) == 0) {
        alert("预算金额必须为数字!");
      
    } else if (endBudget != "" && chkNum(endBudget) == 0) {
        alert("预算金额必须为数字!");
      
    } else {
    var searchVal = "";
    if (setOut != "") {
        searchVal += "&depatureCity=" + decodeURIComponent(setOut);
    } else {
        searchVal += "&depatureCity="
    }
    if (goal != "") {
        searchVal += "&target=" + goal;
    } else {
    searchVal += "&&target="
    }
     searchVal += "&beginDate=" + beginDate + "&endDate=" + endDate + "&beginDay=" + beginDay + "&endDay=" + endDay + "&beginBudget=" + beginBudget + "&endBudget=" + endBudget;
     window.open("SearchList.aspx?ActionType=Search" + searchVal);
    }   
}





//验证是否为数字
function chkNum(num) {
    var i, j, strTemp;
    strTemp = "0123456789";
    if (num.length <= 0) {
        return 0;
    }
    for (var i = 0; i < num.length; i++) {
        j = strTemp.indexOf(num.charAt(i));
        if (j == -1) {
            return 0;
        }
    }
    return 1;
}

//验证时间格式
function chkDate(date) {
    var dateStr;
    if (date != "" && date.length > 0) {
        dateStr = date.length;
    } else {
        return 0;
    }

    var tmpy = "";
    var tmpm = "";
    var tmpd = "";

    var status = 0;

    for (var i = 0; i < dateStr; i++) {
        var tmpStr = date.charAt(i);
        if (tmpStr == "-") {
            status++;
        }

        if (status > 2) {
            return 0;
        }

        if (tmpStr != "-" && status == 0) {
            tmpy += tmpStr;
        }

        if (tmpStr != "-" && status == 1) {
            tmpm += tmpStr;
        }

        if (tmpStr != "-" && status == 2) {
            tmpd += tmpStr;
        }
    }

    if (isNaN(tmpy) || isNaN(tmpm) || isNaN(tmpd)) {
        return 0;
    }

    if (tmpy.length != 4 || tmpm.length > 2 || tmpd.length > 2) {
        return 0;
    }

    if (!((1 <= tmpm) && (12 >= tmpm) && (1 <= tmpd) && (31 >= tmpd))) {
        return 0;
    }

    if (!(tmpy % 4 == 0) && (tmpm == 2) && (tmpd >= 29)) {
        return 0;
    }

    if ((tmpm <= 7) && (tmpm % 2 == 0) && (tmpd >= 31)) {
        return 0;
    }

    if (tmpm >= 8 && (tmpm % 2 == 1) && (tmpd >= 31)) {
        return 0;
    }

    if (tmpm == 2 && tmpy == 30) {
        return 0;
    }

}

