function toggle( targetId ){
  if (document.getElementById){
    target = document.getElementById( targetId );
    if (target.style.display == "none"){
      target.style.display = "inline";
    } else {
      target.style.display = "none";
    }
  }
}

function toggle_block(targetId) {
    if (document.getElementById) {
        target = document.getElementById(targetId);
        if (target.style.display == "none") {
            target.style.display = "block";
        } else {
            target.style.display = "none";
        }
    }
}

function hideElement( targetId ) {
  try { 
    if (document.getElementById){
      target = document.getElementById( targetId );
      target.style.display = "none";
    }    
  } catch(e) {}
}

function showElement( targetId ) {
  try { 
    if (document.getElementById){
      target = document.getElementById( targetId );
      target.style.display = "inline";
    }    
  } catch(e) {}
}

function sanitizePageNumbers( targetId )
    {
    try {
	    elem = document.getElementById( targetId );
	    topPageNumbers = elem.rows[0].cells[0];   
	    bottomPageNumbers = elem.rows[elem.rows.length - 1].cells[0];  
	    txt = topPageNumbers.innerHTML 
	    /*
	    Reqt Change - show even if only one page
	    if (txt.toLowerCase() == '<span>1</span>') {
		    topPageNumbers.innerHTML = '';
		    bottomPageNumbers.innerHTML = '';
		    return;
	    }
	    */ 
    	
	    // If the first occurrence of ... is at the beginning of the line
	    // i.e. ... 6 7 8 9 10 ...
	    // then replace it with <
	    if(txt.indexOf('>...<') < 300) {
	      txtMore = txt.replace(/>...</, '><<');
	      // Replace the remaining ... with >
	      txtMore = txtMore.replace(/>...</, '>><');
	    } else {
	      txtMore = txt.replace(/>...</, '>><');	
	    }			

	    topPageNumbers.innerHTML = 'page ' +  txtMore;
	    bottomPageNumbers.innerHTML = 'page ' + txtMore; 	 
    } catch (e) {  }
    }    

function suppressPageNumbers( targetId )
{
   try {
     badString = "<SPAN>1</SPAN>";
     lowerBadString = "<span>1</span>";
     elem = document.getElementById( targetId );
     topPageNumbers = elem.rows[0].cells[0];   
     bottomPageNumbers = elem.rows[elem.rows.length - 1].cells[0];   
   if(topPageNumbers.innerHTML == badString || topPageNumbers.innerHTML == lowerBadString) {   
       topPageNumbers.innerHTML = "&nbsp;";
   }
   if(bottomPageNumbers.innerHTML == badString || bottomPageNumbers.innerHTML == lowerBadString) {   
       bottomPageNumbers.innerHTML = "&nbsp;";
   }      
   } catch (e) { }
}

function textCounter(field, maxlimit) {
    if (field.value.length > maxlimit) { // if too long...trim it!
        field.value = field.value.substring(0, maxlimit);
        alert('Cannot exceed ' + maxlimit + ' characters.');
     }
}

function clearField(field) {
    if(field.value == "(Note: 300 characters maximum.)") {
    field.value = "";
    }  
}

function blank(a) {
 a.value='';
}

function setMaxLength() {         
        var x = document.getElementsByTagName('textarea');
        var counter = document.createElement('div');
        counter.className = 'counter';
        for (var i = 0; i < x.length; i++) {
            if (x[i].getAttribute('maxlength')) {
                var counterClone = counter.cloneNode(true);
                counterClone.relatedElement = x[i];
                counterClone.innerHTML = '<span>0</span>/' + +x[i].getAttribute('maxlength')+'<span class=\"smallmsg\"/> (Maximum '+x[i].getAttribute('maxlength')+' characters.)</span> ';                                 
                x[i].parentNode.insertBefore(counterClone, x[i].nextSibling);
                x[i].relatedElement = counterClone.getElementsByTagName('span')[0];
                x[i].onkeyup = x[i].onchange = x[i].onkeydown = checkMaxLength;
                x[i].onkeyup();
            }
        }
    }

    function checkMaxLength() {
        var maxLength = this.getAttribute('maxlength');
        var currentLength = this.value.length;
        if (currentLength > maxLength) {
            val1 = this.value;
            this.value = val1.substr(0, maxLength);
            this.relatedElement.className = 'toomuch';
        }
        else {
            this.relatedElement.className = '';
        }
        this.relatedElement.firstChild.nodeValue = currentLength;
        // not innerHTML
    }

    function setMaxLength_1() {
        var x = document.getElementsByTagName('textarea');
        var counter = document.createElement('div');
        counter.className = 'counter';
        for (var i = 0; i < x.length; i++) {
            if (x[i].getAttribute('maxlength')) {                                
                x[i].onkeyup = x[i].onchange = x[i].onkeydown = checkMaxLength_1;
                x[i].onkeyup();
            }
        }
    }

    function checkMaxLength_1() {
        elem = document.getElementById('charmsg');            
        var maxLength = this.getAttribute('maxlength');
        var currentLength = this.value.length;
        var charsleft = maxLength - currentLength;
        if (charsleft < 0) {charsleft = 0; }
        elem.innerText = charsleft+' characters left';           
        if (currentLength >= maxLength)
        {
            val1 = this.value;
            this.value = val1.substr(0,maxLength);
            elem.className = 'toomuch';
        }
        else {
            elem.className = 'characters';
            }        
    }
    
     function DoSearch(key) {        
        __doPostBack('12C70397-87CD-43C7-B7B6-680EAA05766C', key);
    }
    
    function CreateThumbnail(img, w, h) {
    //alert(w * (img.width / img.height) );
    img.removeAttribute("width"); 
    //img.width = w * (img.width / img.height) ; 

    	if(img.width >= img.height)
				img.height = h * (img.height / img.width);  
			else
				img.width = w * (img.width / img.height);  
    }
    
    function ShowNonMemberMessage()
    {
			alert('You must be a LawLink member and logged in to take this action and view this page.');
			return;
    }