// MM ImageSwap
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

<!-- This script is based on the javascript code of Roman Feldblum (web.developer@programmer.net) -->
<!-- Original script : http://javascript.internet.com/forms/format-phone-number.html -->
<!-- Original script is revised by Eralper Yilmaz (http://www.eralper.com) -->
<!-- Revised script : http://www.kodyaz.com -->
<!-- Revised script by Kyle Johnson -->

function validatePhone(object,e){
	e = (e)? e : window.event;
	var keycode=(e.which) ? e.which : e.keyCode;
	var sub=false;
	
	if(keycode >= 48){
		var cursorposition=getCursor(object);
		
		var o = object.value;
		var p = object.value;
		p = p.replace(/[^\d]*/gi,"");
		p=p.substring(0,10);
		
		/*if (p.length < 3) {
			var dif=object.value.length-p.length;
			if(dif>1){
			 	sub=true;
			}
			object.value = "("+p;
		} 
		else*/ if(p.length>=3 && p.length < 6){
			var dif=object.value.length-p.length;
			if(dif>1){
			 	sub=true;
			}
			object.value =p.substring(0,3)+"-"+p.substring(3);
		} 
		else if(p.length >= 6){
			var dif=object.value.length-p.length;
			if(dif>2){
			 	sub=true;
			}
			
			object.value = p.substring(0,3)+"-"+p.substring(3,6)+"-"+p.substring(6);
		}
		else {
			object.value = p;
		}
		
		
		if(!sub&&(cursorposition==3||cursorposition==7)){
			cursorposition+=1;
		}
		if(sub){
			cursorposition-=1;
		}
		
		setCursor(object,cursorposition);
	}
}

function validateExt(object,e){
	e = (e)? e : window.event;
	var keycode=(e.which) ? e.which : e.keyCode;
	if(keycode >= 48){
		var cursorposition=getCursor(object);;
		var o = object.value;
		var p = object.value;
		var sub=false;
		
		p = p.replace(/[^\d]*/gi,"");
		
		var dif=object.value.length-p.length;
		if(dif==1){
			sub=true;
		}
		object.value = p;
		if(sub){
			cursorposition-=1;
		}
		setCursor(object,cursorposition);
	}
}

function validateZip(object,e){
	e = (e)? e : window.event;
	var keycode=(e.which) ? e.which : e.keyCode;
	if(keycode >= 48){
		var cursorposition=getCursor(object);
		var o = object.value;
		var p = object.value;
		var sub=false;
		
		p = p.replace(/[^\d]*/gi,"");
		
		if (p.length > 5) {
			var dif=object.value.length-p.length;
			if(dif>1){
			 	sub=true;
			}
			object.value = p.substring(0,5)+"-"+p.substring(5);
		}
		else {
			var dif=object.value.length-p.length;
			if(dif==1){
			 	sub=true;
			}
			object.value = p;
		}
		
		if(!sub&&cursorposition==6){
			cursorposition+=1;
		}
		if(sub){
			cursorposition-=1;
		}
		setCursor(object,cursorposition);
	}
}

function getCursor(object){
	if(!object.selectionEnd){
		var selrange=document.selection.createRange();
		var objrange=object.createTextRange();
		objrange.setEndPoint( 'EndToEnd', selrange );
		return objrange.text.length - selrange.text.length;
	}
	return object.selectionEnd;
}

function setCursor(object,cursorposition){
	if(object.selectionEnd){
		object.selectionEnd=cursorposition;
		object.selectionStart=cursorposition;
	}
	else{
		var txtRange = object.createTextRange();
		txtRange.moveStart( "character", cursorposition);
		txtRange.moveEnd( "character", cursorposition - object.value.length);
		txtRange.select();
	}
}

// ****** Show/Hide URL link DIV  **********
function CCContent(d) {
	if(document.getElementById(d)!=null){
	if(document.forms[0].website==null||document.forms[0].website[0].checked){
		document.getElementById(d).style.display = "block";
	}
	else{
		document.getElementById(d).style.display = "none";
	}}
}


// ****** Hide Status Bar Link  **********
var statusmsg=""

function hidestatus(){
window.status=statusmsg
return true
}


// ****** Character Count  **********
function taLimit(evt,textarea,limit,countID) {
	var e=window.event ? window.event : evt;
	var unicode=e.charCode ? e.charCode : e.keyCode;
	if (textarea.value.length>=limit*1 && unicode!=8){ 
		return false;
	}
	else { 

		return true;
	}
}

function taCount(textarea,limit,countID) {
	//incase there is a paste
	if(textarea.value.length>=limit*1){textarea.value=textarea.value.substring(0,limit);}
	document.getElementById(countID).innerHTML=(limit*1)-textarea.value.length;
}

// ******** Multiple Onload Functions ********

function groupResOnLoader(){
	taCount(document.getElementById('msg'),'225','introCount');
}
function groupResOnLoader2(){
	taCount(document.getElementById('comments'),'800','charCount');
	
}



// ******** THUMBNAIL PREVIEW MPI EXHIBIT ********

function InsertContent(tid) {
if(document.getElementById(tid).style.display == "none") {
	document.getElementById(tid).style.display = "";
	}
else {
	document.getElementById(tid).style.display = "none";
	}
}

// LOADER

var t_id = setInterval(animate,20);
var pos=0;
var dir=2;
var len=0;

function animate()
{
var elem = document.getElementById('progress');
if(elem != null) {
if (pos==0) len += dir;
if (len>32 || pos>79) pos += dir;
if (pos>79) len -= dir;
if (pos>79 && len==0) pos=0;
elem.style.left = pos;
elem.style.width = len;
}
}

function remove_loading() {
this.clearInterval(t_id);
var targelem = document.getElementById('loader_container');
targelem.style.display='none';
targelem.style.visibility='hidden';
var t_id = setInterval(animate,60);
}


// PREVIEW
/*
Simple Image Trail script- By JavaScriptKit.com
Visit http://www.javascriptkit.com for this script and more
This notice must stay intact
*/

var offsetfrommouse=[10,10]; //image x,y offsets from cursor position in pixels. Enter 0,0 for no offset
var displayduration=0; //duration in seconds image should remain visible. 0 for always.
var currentimageheight = 300;	// maximum image size.

var currentimagewidth = 400;	// maximum image size.
var timer;

function gettrailobj(){
if (document.getElementById)
return document.getElementById("preview_div").style
}

function gettrailobjnostyle(){
if (document.getElementById)
return document.getElementById("preview_div")
}


function truebody(){
return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}


function hidetrail(){	
	gettrailobj().display= "none";
	document.onmousemove=""
	gettrailobj().left="-500px"
	clearTimeout(timer);
}

function showtrail(imagename,title,showthumb){
	i = imagename
	t = title
	s = showthumb
	timer = setTimeout("show('"+i+"',t,s);",200);
}
function show(imagename,title,showthumb){
    var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

if( (navigator.userAgent.indexOf("Firefox")!=-1 || (navigator.userAgent.indexOf("Opera")==-1 && navigator.appVersion.indexOf("MSIE")!=-1)) && (docwidth>550 && docheight>400)) {

		document.onmousemove=followmouse; 
	
		newHTML = '<div class="border_preview"><div id="loader_container"><div id="loader"><div align="center">Loading Image...</div><div id="loader_bg"><div id="progress"> </div></div></div></div>';
	
		if (showthumb > 0){
    		newHTML = newHTML + '<div class="preview_temp_load"><img onload="javascript:remove_loading();" src="' + imagename + '" border="0"></div>';
		}

		newHTML = newHTML + '</div>';
		if(navigator.userAgent.indexOf("Firefox")==-1){
			newHTML = newHTML+'<iframe src="about:blank" scrolling="no" frameborder="0" width="338" height="200"></iframe>';
		}
		gettrailobjnostyle().innerHTML = newHTML;
		gettrailobj().display="block";
	}
}

function followmouse(e){

	var xcoord=offsetfrommouse[0]
	var ycoord=offsetfrommouse[1]

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth - offsetfrommouse[0]
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(window.innerHeight)

	if (typeof e != "undefined"){
		if (docwidth - e.pageX < currentimagewidth){
			if(navigator.userAgent.indexOf("Firefox")!=-1)	{xcoord = e.pageX - xcoord - currentimagewidth + 2*offsetfrommouse[0]} else{ xcoord = e.pageX - xcoord - currentimagewidth + 6*offsetfrommouse[0] ;} // Move to the left side of the cursor
			} else {
				xcoord += e.pageX;
			}
			if (docheight - e.pageY < (currentimageheight + 110)){
				ycoord += e.pageY - Math.max(0,(110 + currentimageheight + e.pageY - docheight - truebody().scrollTop));
			} else {
			ycoord += e.pageY;
			}
	} else if (typeof window.event != "undefined"){
		if (docwidth - event.clientX < currentimagewidth){
			xcoord = event.clientX + truebody().scrollLeft - xcoord - currentimagewidth + 2*offsetfrommouse[0]; // Move to the left side of the cursor
		} else {
			xcoord += truebody().scrollLeft+event.clientX
		}
		if (docheight - event.clientY < (currentimageheight + 110)){
			ycoord += event.clientY + truebody().scrollTop - Math.max(0,(110 + currentimageheight + event.clientY - docheight));
		} else {
			ycoord += truebody().scrollTop + event.clientY;
		}
	}

	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-offsetfrommouse[0]
	var docheight=document.all? Math.max(truebody().scrollHeight, truebody().clientHeight) : Math.max(document.body.offsetHeight, window.innerHeight)
	if(ycoord < 0) { ycoord = ycoord*-1; }
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
}

// ******** END THUMBNAIL PREVIEW MPI EXHIBIT ********

// ****** SET TEXT AREA BACKGROUND COLOR *************
function setbg(color)
{
document.getElementById("styled").style.background=color
}
