//rollover for images
function roll(img_name, img_src)
   {
   document[img_name].src = img_src;
   }

//hide & show content for plus & minus signs
function setDisplay(objectID,state) {
	var object = document.getElementById(objectID);
	object.style.display = state;
}
function show (id) {
	setDisplay('plus'+id, 'none')
	setDisplay('minus'+id, 'block')
}
function hide (id) {
	setDisplay('minus'+id, 'none')
	setDisplay('plus'+id, 'block')
}


// from /docs/common/scripts/ugh_g_search.js and utils.js 

function gPopUp(url, w, h, title, features, target) {
	
	var newWin=null;
	target = target ? target : "_blank";
	//calculate the x, and y position of the popup to center it
	var left = (screen.width - w)/2;
	var top = (screen.height - h)/2;
	var settings = 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ', ' + features;	
	newWin = window.open(url, target, settings);
	newWin.focus();
	
}


var winCTR = 0 ;
var childWindow = new Array(20); 

function ugh_validSearch(keywords){

	if (keywords.match(/[A-Z]+/g) ||
		keywords.match(/[a-z]+/g) ||
		keywords.match(/[0-9]+/g)) {
		return true;
	}

	if (keywords.match(/^ *$/g)) {
		alert('Please provide keywords for your search.');
		return false;
	}
	alert('Your search is too general.  Please provide keywords for your search.');
	return false;
}

function ugh_submitSearch(searchKey, formObj, element) {
	
	var objSearchForm = (formObj) ? document[formObj] : document.frmSearch;  
	var elementValue = (element) ? objSearchForm.elements[element.name].value : objSearchForm.txtSearch.value;
    
	if (ugh_validSearch(elementValue)) {
	
		if(searchKey) {
			mystrng = elementValue + searchKey;
		} else {
        	mystrng = elementValue;
		}
		
		mystrng = mystrng.replace(/\%/g,"%25");
		mystrng = mystrng.replace(/\"/g,"%22");
		mystrng = mystrng.replace(/\#/g,"%23");
		mystrng = mystrng.replace(/\&/g,"%26");
		mystrng = mystrng.replace(/\+/g,"%2B");
		mystrng = mystrng.replace(/\,/g,"%2C");
		mystrng = mystrng.replace(/\./g,"%2E");
		mystrng = mystrng.replace(/\//g,"%2F");
		mystrng = mystrng.replace(/\:/g,"%3A");
		mystrng = mystrng.replace(/\;/g,"%3B");
		mystrng = mystrng.replace(/\</g,"%3C");
		mystrng = mystrng.replace(/\=/g,"%3D");
		mystrng = mystrng.replace(/\>/g,"%3E");
		mystrng = mystrng.replace(/\?/g,"%3F");
		mystrng = mystrng.replace(/\@/g,"%40");
		mystrng = mystrng.replace(/\[/g,"%5B");
		mystrng = mystrng.replace(/\]/g,"%5D");
		mystrng = mystrng.replace(/\^/g,"%5E");
		mystrng = mystrng.replace(/\'/g,"%60");
		mystrng = mystrng.replace(/\{/g,"%7B");
		mystrng = mystrng.replace(/\|/g,"%7C");
		mystrng = mystrng.replace(/\}/g,"%7D");
		mystrng = mystrng.replace(/\~/g,"%7E");
		mystrng = mystrng.replace(/ /g,"+");

        for (x = 0; x < mystrng.length; x++) {
            d = mystrng.charCodeAt(x);
            if (d == 8216 || d == 8217 || d == 8220 || d == 8221) {
                if (x == 0) {
                    if (d == 8216 || d == 8217) {
                        mystrng = "%27"
                            + mystrng.substring(1, mystrng.length);
                    } else {
                        mystrng = "%22"
                            + mystrng.substring(1, mystrng.length);
                    }
                } else if (x == mystrng.length) {
                    if (d == 8216 || d == 8217) {
                        mystrng = mystrng.substring(0, x) + "%27";
                    } else {
                        mystrng = mystrng.substring(0, x) + "%22";
                    }
                } else {
                    if (d == 8216 || d == 8217) {
                        mystrng = mystrng.substring(0, x)
                            + "%27"
                            + mystrng.substring(x + 1, mystrng.length);
                    } else {
                        mystrng = mystrng.substring(0, x)
                            + "%22"
                            + mystrng.substring(x + 1, mystrng.length);
                    }
                }
            }
        }
        ugh_g_openSearch('http://www.gartner.com/7_search/Search2Frame.jsp?keywords='+ mystrng);
    }
}

function ugh_g_openSearch(url){
	var w=850;
	var h=540;
	var features="location=no,scrollbars=yes,status=no,toolbar=no,resizable=yes";
	gPopUp(url, w, h, '', features, null);
}