function showCalendar(fmName,fdName){
     window.open('/oit/gis/OIT_TravelGuide/calendar.html?frmName=' + fmName + '&fldName=' + fdName + '&srvrDt=' + svrDt,'calwindow',config='width=225,height=225');
}

function showHelp(){
     window.open('/oit/gis/OIT_TravelGuide/searchHelp.htm','helpwindow',config='width=750,height=450,scrollbars=yes,resizable=yes ');
}
function showmapHelp(){
     window.open('/oit/gis/OIT_TravelGuide/mapHelp.htm','helpwindow',config='width=750,height=450,scrollbars=yes,resizable=yes ');
}

function changeFocus(){
    document.getElementById("goSubmit").focus();
}

function resetForm(){
    location.href = progName;
}

function populateCatName(){
     with (document.forms[frmName]){
          if (category_idn.selectedIndex > 0){
             categoryName.value = category_idn.options[category_idn.selectedIndex].text;
          }
          else {
                categoryName.value = "";
          }
     }
}

var abcs = "abcdefghijklmnopqrstuvwxyz ";

function doAddrValidation(strAddr,strCSZ,formName){
         if (strAddr == ""){
             alert("Please enter the address");
             document.forms[formName].street.focus();
             return false;
          }
          if (strAddr.charAt(0) == " "){
             alert("Please enter the address from the starting position");
             document.forms[formName].street.focus();
             return false;
          }

          if (strCSZ == ""){
             alert("Please enter a street address with \n city, state or \n zip");
             document.forms[formName].cityStateZip.focus();
             return false;
          }

          if (strCSZ.charAt(0) == " "){
             alert("Please enter a street address with \n city, state or \n zip \n from the starting position");
             document.forms[formName].cityStateZip.focus();
             return false;
          }
          if (strCSZ.indexOf(",") == -1){
             if (strCSZ.length != 5){
                alert("Please enter a street address with \n city, state or \n zip\n\nZip codes must be a five digit number");
                document.forms[formName].cityStateZip.focus();
                return false;
             }
             for (z = 0; z < strCSZ.length; z++){
                 if (strCSZ.charAt(z) < "0" || strCSZ.charAt(z) > "9"){
                    alert("Please enter a street address with \n city, state or \n zip\n\nZip codes must be a five digit number");
                    document.forms[formName].cityStateZip.focus();
                    return false;
                 }
             }

          }
          if (strCSZ.indexOf(",") != -1){
             arrCSZ = strCSZ.split(",");
             var theCity = arrCSZ[0];
             var theState = arrCSZ[1];
             theCity = trim(theCity);
             theState = trim(theState);
             theCity = theCity.toLowerCase();
             theState = theState.toLowerCase();

             for (az1 = 0; az1 < theCity.length; az1++){
                 if (abcs.indexOf(theCity.charAt(az1)) == -1){
                    alert("Please enter a street address with \n city, state or \n zip\n\nZip codes must be a five digit number");
                    document.forms[formName].cityStateZip.focus();
                    return false;
                 }
             }
             for (az2 = 0; az2 < theState.length; az2++){
                 if (abcs.indexOf(theState.charAt(az2)) == -1){
                    alert("Please enter a street address with \n city, state or \n zip\n\nZip codes must be a five digit number");
                    document.forms[formName].cityStateZip.focus();
                    return false;
                 }
             }
          }
          return true;
}

function doPlaceValidation(thePlace,formName){
           thePlace = thePlace.toLowerCase();
           if (thePlace == ""){
              alert("Please enter the Place name");
              document.forms[formName].place.focus();
              return false;
           }
           if (thePlace.charAt(0) == " "){
              alert("Please enter the Place name from starting position");
              document.forms[formName].place.focus();
              return false;
           }
           for (az3 = 0; az3 < thePlace.length; az3++){
                 if (abcs.indexOf(thePlace.charAt(az3)) == -1){
                    alert("Please enter a town or place name only.\nNo special characters (* , . / etc)");
                    document.forms[formName].place.focus();
                    return false;
                 }
           }
           return true;
}

function doRadiusValidation(theRadius,formName){
          var theNumbers = "1234567890.";
          var theDecimals = 0;
          for (n = 0; n < theRadius.length; n++){
                 if (theNumbers.indexOf(theRadius.charAt(n)) == -1){
                    alert("Invalid Radius");
                    document.forms[formName].radius.focus();
                    return false;
                 }
                 if (theRadius.charAt(n) == "."){
                    theDecimals = theDecimals + 1;
                    if (theDecimals > 1){
                       alert("Invalid Radius");
                       document.forms[formName].radius.focus();
                       return false;
                    }
                 }
           }
           var intRadius = parseInt(theRadius);
           if (intRadius > 100){
              alert("Select the Radius less than 100 miles");
              document.forms[formName].radius.focus();
              return false;
           }
           return true;
}

function doKeywordValidation(theKeyword,formName){
          theKeyword = theKeyword.toLowerCase();
          if (theKeyword.charAt(0) == " "){
             alert("Please enter the Keyword from starting position");
             document.forms[formName].keyword.focus();
             return false;
          }
          return true;
}

function doDateValidation(fromDate,endDt,formName){
				if (fromDate != ""){
					if (fromDate.charAt(0) == " "){
						alert("Please enter the From Date from starting position");
						document.forms[formName].frmDate.focus();
						return false;
					}

					if (!isDate(fromDate)){
						document.forms[formName].frmDate.focus();
						return false;
					}
				}

				if (endDt != ""){
					if (endDt.charAt(0) == " "){
						alert("Please enter the To Date from starting position");
						document.forms[formName].endDate.focus();
						return false;
					}

					if (!isDate(endDt)){
						document.forms[formName].endDate.focus();
						return false;
					}
				}

				if (fromDate != "" && endDt != ""){
					if (compareDts(fromDate,endDt) == "notokay"){
						alert("To Date must be greater than From Date");
						document.forms[formName].endDate.focus();
						return false;
					}
					var sysDt = svrDt;
					sysDt = sysDt.replace(/@/g,"/");
					var compResult = compareDts(sysDt,endDt);
					if (compResult == "notokay"){
						alert("To Date must be greater than or at least Today's(" + sysDt + ") Date");
						document.forms[formName].endDate.focus();
						return false;
					}
				}

				if (fromDate == "" && endDt != ""){
					var sysDt = svrDt;
					sysDt = sysDt.replace(/@/g,"/");
					var compResult = compareDts(sysDt,endDt);
					if (compResult == "notokay"){
						alert("To Date must be greater than or at least Today's(" + sysDt + ") Date");
						document.forms[formName].endDate.focus();
						return false;
					}
					else {
						document.forms[formName].frmDate.value = sysDt;
					}
				}
				return true;
}


function show(c) {
    if (document.getElementById && document.getElementById(c)!= null)
    node = document.getElementById(c).style.display='';
    else if (document.layers && document.layers[c]!= null)
    document.layers[c].display = '';
    else if (document.all)
    document.all[c].style.display = '';
}
function hide(c) {
    if (document.getElementById && document.getElementById(c)!= null)
    node = document.getElementById(c).style.display='none';
    else if (document.layers && document.layers[c]!= null)
    document.layers[c].display = 'none';
    else if (document.all)
    document.all[c].style.display = 'none';
}

function compareDts(firstDt,secondDt){
    var compareResult = "okay";
    var firstDate = new Date();
    firstDate.setTime(Date.parse(firstDt));
    var secondDate = new Date();
    secondDate.setTime(Date.parse(secondDt));
    if (secondDate < firstDate){
       compareResult = "notokay";
    }
    return compareResult;
}

function ltrim ( s )
{
	return s.replace( /^\s*/, "" );
}

function rtrim ( s )
{
	return s.replace( /\s*$/, "" );
}

function trim ( s )
{
	return rtrim(ltrim(s));
}

/**
 * DHTML date validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=2002;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   }
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/yyyy")
		return false
	}
	if (month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (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 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
