/**************************************************
//CommonOutside/com.js - 8-5-2009
***************************************************/

// google search - called from NET 2+ header button
function doGoogleSearch(id) {
    document.location.href = 'http://mesaaz.gov/search/default.aspx?cx=015015829240626729465%3Az3vghkx_ztm&cof=FORID%3A11%3B&ie=UTF-8&q='
        + urlGoogleEncode(document.getElementById(id).value);
}

// google search - called from NET 2+ header textbox
// does not work for firefox (handles events differently)
function doGoogleSearchFromTextbox(id) {
    if (window.event) {
        if (window.event.keyCode == 13) {
            event.returnValue = false;
            event.cancel = true;
            doGoogleSearch(id);
        }
    }
}

// used by doGoogleSearch()
function urlGoogleEncode(clearString) {
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9_.]*)/;

    while (x < clearString.length) {
        var match = regex.exec(clearString.substr(x));

        if (match != null && match.length > 1 && match[1] != '') {
            output += match[1];
            x += match[1].length;
        } else {
            if (clearString[x] == ' ')
                output += '+';
            else {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }
            x++;
        } // end if match
    } // end while
    return output;
} 

/* header */
function headerDoSearch(){
	var box = document.getElementById("headerSearchTextBox");
	window.location="/Search/Default.aspx?search="+box.value;
}
function headerDoSearchFromTextbox(){
    if (window.event){
        if (window.event.keyCode ==13){
          event.returnValue=false;
            event.cancel=true;
            var box = document.getElementById("headerSearchTextBox");
    	    window.location="/Search/Default.aspx?search="+box.value;
        }
    }
}
function headerDoSearch2(site){
	var box = document.getElementById("headerSearchTextBox");
	window.location = site+"/Search/Default.aspx?search="+box.value;
}
function headerDoSearchFromTextbox2(site){
    if (window.event){
        if (window.event.keyCode ==13){
          event.returnValue=false;
            event.cancel=true;
            var box = document.getElementById("headerSearchTextBox");
    	    window.location = site+"/Search/Default.aspx?search="+box.value;
        }
    }
}
function turnOn(imageId,site) {
	if (document.images) {
		var number = parseInt(imageId.substring(3));
		var but = document.getElementById(imageId);
		but.src = '/CommonOutside/'+site+'/images/nav'+number+'_on.gif';
	}
}
function turnOff(imageId,site) {
	if (document.images) {
		var number = parseInt(imageId.substring(3));
		var but = document.getElementById(imageId);
		but.src = '/CommonOutside/'+site+'/images/nav'+number+'_off.gif';
	}
}
function preloadImages(count,site) {
	if (document.images) {
		count=count+1;
		var imageName=new Array();
		var imageOn = new Array(count);
		var imageOff= new Array(count);
		imageName[0] = "";
		
		for (i=1; i<count; i++){
			imageName[i] = "nav"+i;
			imageOn[i] = new Image();
			imageOff[i]= new Image();
			imageOn[i].src = '/CommonOutside/'+site+'/images/'+imageName[i] + '_on.gif';
			imageOff[i].src = '/CommonOutside/'+site+'/images/'+imageName[i] + '_off.gif';
		}
	}
}

/* general use */
function closeWindow() {
	window.open('','_parent','');
	window.close();
}
function listGoTo(source){
	var list = document.getElementById(source);
	var url = list.options[list.selectedIndex].value;
	if (url!=''){
	
		// maybe open in new window
		var newWindow = false;
		var endIndex ;
		endIndex = url.toLowerCase().indexOf(" target=")
		if (endIndex > -1){
			newWindow = true; 
			url = url.substring(0,endIndex);
		}
		
		if (newWindow){
			var win = window.open(url,"","");
			win.focus();
		}else{
			window.location=url;
		}
	}
 }
function popupNoBorder(url,width,height) {
	var props = "fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width="+width+",height="+height+",top=20,left=20";
	Win = window.open( url,"", props);
	Win.focus();
}
function setFocus(id) {
	document.getElementById(id).focus();
}

/********* LEGACY - leave in for early headers still out there *****/
function doSearch(){
	var box = document.getElementById("headerSearchTextBox");
	window.location="/Search/Default.aspx?search="+box.value;
}
