﻿String.prototype.endsWith = function(str) 
{return (this.match(str+"$")==str)}

function PrinterFriendly()
{
    var url = window.location.href;
    if (url.toLowerCase().indexOf(".aspx") < 0)
    {
        if (url.lastIndexOf("/") != (url.length - 1))
            url = url + "/";
        
        url = url + "Default.aspx";
    }
    if (url.indexOf("?") < 0)
        url = url + "?Printable=1";
    else
        url = url + "&Printable=1";
        
    var printer = window.open(url,'PinterWin','height=600,width=800,toolbar=yes,menubar=yes,location=no,status=no,scrollbars=yes');
    printer.focus();
    return true;
}
function SubmitSearch()
{
    document.getElementById("SearchCriteria").value = document.getElementById("SearchInput").value;
    document.getElementById("SearchForm").submit();
}
function openFriendWin()
{
    var tellFriend = window.open('','FriendWin','height=600,width=800,toolbars=no,location=no,statusbar=no,scrollbars=yes');
    tellFriend.document.write('<form id="FriendForm" name="FriendForm" action="http://www.rims.org/AMTemplate.cfm?template=EmailToFriend.cfm" method="POST" TARGET="FriendWin"><input type="hidden" name="ThisPage" value="' + window.location + '"></form>');
    tellFriend.document.close();
    var friendForm = tellFriend.document.getElementById("FriendForm");
    friendForm.submit();
}
/* 
Derived from a script by Alejandro Gervasio. 
Modified to work in FireFox by Stefan Mischook for Killersites.com

How it works: just apply the CSS class of 'column' to your pages' main columns.
*/
matchColumns=function(){ 
     var divs,contDivs,maxHeight,divHeight,d,newHeight; 
     // get all <div> elements in the document 
     divs=document.getElementsByTagName('div'); 
     contDivs=[]; 

     // initialize maximum height value 
     maxHeight=0; 

     // iterate over all <div> elements in the document 
     for(var i=0;i<divs.length;i++){ 
          // make collection with <div> elements with class attribute 'container' 
          if(/\bcolumn\b/.test(divs[i].className)){ 
                d=divs[i]; 
                contDivs[contDivs.length]=d; 
                // determine height for <div> element 
                if(d.offsetHeight)
                     divHeight=d.offsetHeight;
                else if(d.style.pixelHeight)
                     divHeight=d.style.pixelHeight;					 

                // calculate maximum height 
                maxHeight=Math.max(maxHeight,divHeight); 
          } 
     } 
     // assign maximum height value to all of container <div> elements 
     for(var i=0;i<contDivs.length;i++){ 
        d = contDivs[i];
        newHeight = maxHeight;
        if (d.style.borderTopWidth && d.style.borderTopWidth.endsWith('px'))
            newHeight = newHeight - d.style.borderTopWidth.substring(0,d.style.borderTopWidth.length - 2);			
        if (d.style.borderBottomWidth && d.style.borderBottomWidth.endsWith('px'))
            newHeight = newHeight - d.style.borderBottomWidth.substring(0,d.style.borderBottomWidth.length - 2);	
        contDivs[i].style.height=newHeight + "px"; 
     }
} 

// Runs the script when page loads 

window.onload=function(){ 

     if(document.getElementsByTagName){ 

          matchColumns();			 

     } 

} 


function clearForm(formIdent) 
{ 
    if (formIdent == '')
        formIdent = 'aspnetForm';
        
    var form, elements, i, elm; 
    form = document.getElementById ? document.getElementById(formIdent) : document.forms[formIdent]; 

	if (document.getElementsByTagName)
	{
		elements = form.getElementsByTagName('input');
		for( i=0, elm; elm=elements.item(i++); )
		{
			if (elm.getAttribute('type') == "text")
				elm.value = '';
			else if (elm.getAttribute('type') == "checkbox")
			    elm.checked = false;
		}
		elements = form.getElementsByTagName('select');
		for( i=0, elm; elm=elements.item(i++); )
		{
			elm.options.selectedIndex=0;
		}
	}

	// Actually looking through more elements here
	// but the result is the same.
	else
	{
		elements = form.elements;
		for( i=0, elm; elm=elements[i++]; )
		{
			if (elm.getAttribute('type') == "text")
				elm.value = '';
			else if (elm.getAttribute('type') == "checkbox")
			    elm.checked = false;
		}
	}
	return false;
}

function rdoAddSubscribed_CheckedChanged(labeleGroupName, labelEmail, txtSubscriptionEmailID, lnkBtnChangeEmailID,  labelSubscriptionMsg, lnkSave, lnkCancel, showSubscriptionMsg) {
        var subscriptionMsgDisplay = document.getElementById(showSubscriptionMsg).style.display;
        document.getElementById(labeleGroupName).style.fontWeight = "bold";
        document.getElementById(txtSubscriptionEmailID).value = document.getElementById(labelEmail).innerHTML;
        if (subscriptionMsgDisplay == "block") {
            document.getElementById(labelEmail).style.display = "inline";
            document.getElementById(txtSubscriptionEmailID).style.display = "none";
            document.getElementById(lnkBtnChangeEmailID).style.display = "inline";
            document.getElementById(labelSubscriptionMsg).style.display = "none";
            document.getElementById(lnkSave).style.display = "none";
            document.getElementById(lnkCancel).style.display = "none";
        }
    }

    function rdoNotSubscribed_CheckedChanged(labeleGroupName, rdoRealTime, rdoDailyDigest, rdoPDA, rdoNoEmails) {
        document.getElementById(labeleGroupName).style.fontWeight = "normal";
        document.getElementById(rdoRealTime).disabled = true;
        document.getElementById(rdoDailyDigest).disabled = true;
        document.getElementById(rdoPDA).disabled = true;
        document.getElementById(rdoNoEmails).disabled = true;
    } 
