var linkvalue;

function runloader() {
	linkvalue = "";
	
}

function runchecker() {
    if (window.event.srcElement.tagName == "A") {  //this line checks if the srcElement is an Anchor tag
		//alert("You clicked: " + window.event.srcElement.tagName);
		
		//check if they are staying on the same domain name
		if (window.event.srcElement.hostname != "www.maricopa.gov") {  //assume these sites are clerkofcourt.maricopa.gov or www.maricopa.gov
			//alert("You clicked a link\n" + "The value was: " + window.event.srcElement.href + "\nThe host was: " + window.event.srcElement.hostname) ; //this alerts that they clicked a link

			linkvalue = window.event.srcElement.href;
			//rununloader();  -  don't need to rununloader - it will happen when you let them leave the page
			//event.returnValue = false;   - don't want to cancel their link			

		}
		else {
			linkvalue = "none";
		
		}
	}
}


function rununloader(){
var visitcount = getCookie("visits");

//read the visitcount cookie and alert, for debugging
//alert(visitcount);

		//check if this is not a off site link click, it it is than ask them to fill out the survey
		if (linkvalue != "none"){
			if ((visitcount == "1") || (visitcount == "2") || (visitcount == "5")){
			
				//alert("You will be asked to fill out a survey");
				MM_openBrWindow('/suggestionbox/popup.html','Popup','width=350,height=317');
				linkvalue="";
			}
		}
			linkvalue="";				
}
//end rununloader()



function getCookie(Name) {   
	var search = Name + "="   
	if (document.cookie.length > 0) {// if there are any cookies      
		offset = document.cookie.indexOf(search)       
		if (offset != -1) { // if cookie exists          
			offset += search.length; 
			// set index of beginning of value         
			end = document.cookie.indexOf(";", offset)
			// set index of end of cookie value         
			if (end == -1)             
				end = document.cookie.length         
			return unescape(document.cookie.substring(offset, end))      
		}    
	}
}


function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}


