/***********************************************************************

	External JavaScript Utility for common functionality to be
	included on all pages on the site.

***********************************************************************/

function leavingSite() {
	var msg = "You are now leaving arentfox.com";
	if (confirm(msg)) 
		return true;
	else
		return false;
}

function newWin(url,w,h) {
		objNewWin = window.open("","win",'status=1,scrollbars=0,resizable=1,width=' + w + ',height=' + h);
        objNewWin.location = url;
        objNewWin.focus();
}

function newWinFullScreen(url,windowname){
	objNewWin = window.open("", windowname, 'resizable=1,type=fullWindow,scrollbars=1');
    objNewWin.location = url;
    objNewWin.focus();
}

function displayWindow(url, width, height) {
	if (!window.Win || Win.closed)
	    var Win = window.open(url,"displayWindow",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=1' );
	else
		Win.location = url;
		Win.focus();
}


function addBookmark(addUrl, addName) {
	myUserAgent = navigator.userAgent.toLowerCase();
	if (myUserAgent.indexOf("msie") != -1) {
		var addName = "ArentFox.com - " + addName;
		window.external.AddFavorite(addUrl, addName);
	}
	else {
		alert ('If you are using Netscape or Mozilla, you can press CTRL+D on your keyboard to bookmark this site.')	
	}
}

function changemainimage(imgsrc){
	if(document.mainimg){
		document.mainimg.src = imgsrc;
	}
}


// links back to the window that opened the current window.
function linkToOpener(url) {
	window.opener.location = url;
	window.opener.focus();
}

function setBorder(element,color){
	if(document.getElementById){
		document.getElementById(element).style.borderColor=color;
	}else if(document.all) {
		document.all[element].style.borderColor=color;
	}
}

function renderhtml(elemt,txt) {
	if(document.getElementById){
		document.getElementById(elemt).innerHTML = txt;
	}else if (document.all){
   		document.all[elemt].innerHTML = txt;
	}else if (document.layers){
   		document.w1.document.w2.document.write(txt);
   		document.w1.document.w2.document.close();
	}
}

function renderWindowVideo(elemt,src){
	var html = "<object classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0\" width=\"275\" height=\"400\" id=\"AF_Video_Bill_NY\" align=\"middle\"><param name=\"allowScriptAccess\" value=\"sameDomain\" />";
		   html += "<param name=\"movie\" value=\""+ src +"\" />";
		   html += "<param name=\"loop\" value=\"false\" />";
		   html += "<param name=\"quality\" value=\"high\" />";
		   html += "<param name=\"bgcolor\" value=\"#ffffff\" />";
		   html += "<embed src=\"+ src +\" loop=\"false\" quality=\"high\" bgcolor=\"#ffffff\" width=\"275\" height=\"400\" name=\"AF_Video_Bill_NY\" align=\"middle\" allowScriptAccess=\"sameDomain\" type=\"application/x-shockwave-flash\" pluginspage=\"../external.html?link=http://www.macromedia.com/go/getflashplayer\" />";
		   html += "</object>";
	
	if(document.getElementById){
		document.getElementById(elemt).innerHTML = html;
	}else if (document.all){
   		document.all[elemt].innerHTML = html;
	}
	
	//<img id=\"mainimg\" name=\"mainimg\" src=\"images/1x1clear.gif\" width=\"1\" height=\"1\"/>
	
}

function switchImage(elemt,imgsrc){
	if(document.getElementById){
		document.getElementById(elemt).src = imgsrc;
	}else if (document.all){
   		document.all[elemt].src = imgsrc;
	}
}

function bioPaSearch(term,appDir) {
	var theForm = document.forms[0];
	if(term == "") {
		alert("Please enter a Search Term.");
		return false;
	}
	var searchterm = URLEncode(term);
	location = appDir + "/search/term/" + searchterm;
}

function bioPaEnterEvent(term,appDir,objEvent) { 
    if ((objEvent.which && objEvent.which == 13) || (objEvent.keyCode && objEvent.keyCode == 13)) {
		bioPaSearch(term,appDir);
		return false;
    } else return true;
} 

function ExcludeEnterEvent(objEvent) { 
    if ((objEvent.which && objEvent.which == 13) || (objEvent.keyCode && objEvent.keyCode == 13)) {
		return false;
    } else return true;
} 


function URLEncode(plaintext )
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    /*
			    alert( "Unicode Character '" + ch + "' cannot be encoded using standard URL encoding.\n" +
				        "(URL encoding only supports 8-bit characters.)\n" +
						"A space (+) will be substituted." );
				*/
				encoded += "+";
				
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};

function roll_over(img_name, img_src)
{
	document.mainimg.src = img_src;
};




