var objAjax;

function getAjaxObj() {
	var objAjax = null;
	try {
		// Firefox, Opera 8.0+, Safari
		objAjax= new XMLHttpRequest();
	}
	catch (e) {
		// Internet Explorer
		try {
			objAjax = new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			objAjax = new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return objAjax;
}

function toggle(id) {
	var c = git(id).className;
	if (c.indexOf('hide') > -1) {
		c = c.replace(/hide/g, '');
		c = c.replace(/  /g, '');
	} else {
		if (c.length > 0)
			c += ' ';
		c += 'hide';
	}
	git(id).className = c;
}

function git(i) {
	return document.getElementById(i);
}

function clearField() { 
	if (document.getElementById('search').value == 'Search...') {
		document.getElementById('search').value = '';
		}
	}

function rePop() {
	if (document.getElementById('search').value == '') {
		document.getElementById('search').value = 'Search...';
		}
	}

function parkImgSwap(file) {
	loc = '/site/CMSv2/image/parksAndRecreation/parks/' + file;
	document.getElementById('mainImg').src = loc;
	}

function goto() {
	var dest = document.getElementById('goto').value;
	if (dest != '') {
		window.location.href = "#" + dest;
		}
	}

function confDel() {
	var check = confirm("You are about to delete information from your account.  Are you sure you wish to proceed?");
	if (check == true) {
		return true;
	} else {
		return false;
	}
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		var relvalue = anchor.getAttribute("rel");
		if (anchor.getAttribute("href")) {
			var external = /external/;
			var relvalue = anchor.getAttribute("rel");
			if (external.test(relvalue)) { anchor.target = "_blank"; }
			}
		}
	}
window.onload = externalLinks;

var errStr = '';
var errIDstr = ':';


function markTrbl(formID) {
	var x = document.getElementById(formID);
	for (i = 0; i < x.length; i++) {
		var id = x.elements[i].id;
		if (id.length > 0 && errIDstr.indexOf(id) >= 0) {
			x.elements[i].style.backgroundColor = '#900';
			x.elements[i].style.color = '#fff';
			} else {
			if (x.elements[i].type != 'button' && x.elements[i].type != 'submit') {
				x.elements[i].style.backgroundColor = '';
				x.elements[i].style.color = '';
				}
			}
		}
	}	


function validate(formID,args) {
var prob = false;
	for (x = 0; x < arguments.length; x++) {
		if (arguments[x] == false) {
			prob = true;
			}
		}
	if (prob == true) {
		markTrbl(formID);
		errIDstr = ':';
		if (errStr != '') { alert(errStr); }
		errStr = '';
		return false;
		} else {
		return true;
		}
	}
	
function oldValidate(formID,args) {
var prob = false;
	for (x = 0; x < arguments.length; x++) {
		if (arguments[x] == false) {
			prob = true;
			}
		}
	if (prob == true) {
		markTrbl(formID);
		errIDstr = ':';
		if (errStr != '') { alert(errStr); }
		errStr = '';
		return false;
		} else {
		return true;
		}
	}


function req(tag,tot) {
var prob = false;
	for (x = 1; x <= tot; x++) {
		if (document.getElementById(tag + x).value == '') {
			errIDstr += tag + x + ":"	
			prob = true;
			}
		}
	if (prob == true) {
		errStr += "Please enter all the required (highlighted) fields\n";
		return false;
		} else {
		return true;
		}
	}

function comp(tag1,tag2,desc) {
	if (document.getElementById(tag1).value != document.getElementById(tag2).value) {
		errStr += "The " + desc + " values you entered did not match.  Please re-enter\n";
		errIDstr += tag1 + ":" + tag2 + ":"
		return false;
		} else {
		return true;
		}
	}


function minVal(tag,val,desc) {
	if (document.getElementById(tag).value.length < val) {
		errStr += "The " + desc + " field value must not be less than " + val + " characters in length\n";
		errIDstr += tag + ":";
		return false;
		} else {
		return true;
		}
	}


function chkBox(tag,desc) {
	if (document.getElementById(tag).checked == false) {
		errStr += "The " + desc + " box must be checked\n";
		errIDstr += tag + ":";
		return false;
		} else {
		return true;
		}
	}


function noLinks(tag) {
	if (document.getElementById(tag).value.toLowerCase().indexOf("href") >= 0) {
		errStr += "Links are not allowed in this form\n";
		errIDstr += tag + ":";
		return false;
		} else {
		return true;
		}
	}


function cNumber(tag) {
inpStr = document.getElementById(tag).value;
var prob = false;
	for (i = 0; i < inpStr.length; i++) {
		if (isNaN(inpStr.charAt(i))) {
			prob = true;
			}
		}
	if (prob == true) {
		errStr += "Only numbers are allowed in this field\n";
		errIDstr += tag + ":";
		return false;
		} else {
		return true;
		}
	}


function cEmail(tag) {
	var email = document.getElementById(tag).value;
	var prob = false;
	atPos = email.indexOf("@");
	if (atPos < 0) { prob = true; }
	if (email.indexOf(".", atPos) < 0) { prob = true; }
	if (prob == true) {
		errStr += "Invalid Email Address Detected\n";
		errIDstr += tag + ":";
		return false;
		} else {
		return true;
		}
	}


function delAccount() {
	var check = confirm("You are about to permanently delete your account from our records. If you " +
	"wish to proceed, press 'OK', otherwise, press 'Cancel'.");
	if (check == true) {
		return true;
	} else {
		return false;
	}
}


// Flash Movie Integration
function MM_CheckFlashVersion(reqVerStr,msg){
  with(navigator){
    var isIE  = (appVersion.indexOf("MSIE") != -1 && userAgent.indexOf("Opera") == -1);
    var isWin = (appVersion.toLowerCase().indexOf("win") != -1);
    if (!isIE || !isWin){  
      var flashVer = -1;
      if (plugins && plugins.length > 0){
        var desc = plugins["Shockwave Flash"] ? plugins["Shockwave Flash"].description : "";
        desc = plugins["Shockwave Flash 2.0"] ? plugins["Shockwave Flash 2.0"].description : desc;
        if (desc == "") flashVer = -1;
        else{
          var descArr = desc.split(" ");
          var tempArrMajor = descArr[2].split(".");
          var verMajor = tempArrMajor[0];
          var tempArrMinor = (descArr[3] != "") ? descArr[3].split("r") : descArr[4].split("r");
          var verMinor = (tempArrMinor[1] > 0) ? tempArrMinor[1] : 0;
          flashVer =  parseFloat(verMajor + "." + verMinor);
        }
      }
      // WebTV has Flash Player 4 or lower -- too low for video
      else if (userAgent.toLowerCase().indexOf("webtv") != -1) flashVer = 4.0;

      var verArr = reqVerStr.split(",");
      var reqVer = parseFloat(verArr[0] + "." + verArr[2]);
  
      if (flashVer < reqVer){
        if (confirm(msg))
          window.location = "http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash";
      }
    }
  } 
}

/////////////////////////////////// Date functions
///////////////////////////////////////////////////////////////////////////////////////
var dtCh= "/";
var minYear=1900;
var maxYear=2100;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strMonth=dtStr.substring(0,pos1)
	var strDay=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : mm/dd/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 || 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
}