function grayOut(vis, options) {  
// Pass true to gray out screen, false to ungray  
// options are optional.  This is a JSON object with the following (optional) properties  
// opacity:0-100         
// Lower number = less grayout higher = more of a blackout  
// zindex: #             
// HTML elements with a higher zindex appear on top of the gray out  
// bgcolor: (#xxxxxx)    // Standard RGB Hex color code  // 


var options = options || {};  
var zindex = options.zindex || 150;
var opacity = options.opacity || 50;
var opaque = (opacity / 100);  
var bgcolor = options.bgcolor || '#000000';  
var dark=document.getElementById('darkenScreenObject');  
if (!dark) {
	// The dark layer doesn't exist, it's never been created.  So we'll    // create it here and apply some basic styles.    // If you are getting errors in IE see: http://support.microsoft.com/default.aspx/kb/927917
	var tbody = document.getElementsByTagName("body")[0];
	var tnode = document.createElement('div');// Create the layer.
	        
	tnode.style.position='absolute';                 // Position absolutely   
	tnode.style.top='0px';                           // In the top    
	tnode.style.left='0px';                          // Left corner of the page   
	tnode.style.overflow='hidden';                   // Try to avoid making scroll bars                
	tnode.style.display='none';                      // Start out Hidden    
	tnode.id='darkenScreenObject';                   // Name it so we can find it later   
	tbody.appendChild(tnode);                            // Add it to the web page   
	dark=document.getElementById('darkenScreenObject');  // Get the object. 
	}
	
	
	 if (vis) {    
	 // Calculate the page width and height   
	 if( document.body && ( document.body.scrollWidth || document.body.scrollHeight ) ) 
	 {       
	 	var pageWidth = document.body.scrollWidth+'px';  
		var pageHeight = document.body.scrollHeight+'px';  
	} 
	else if( document.body.offsetWidth )
	{     
		var pageWidth = document.body.offsetWidth+'px';   
		var pageHeight = document.body.offsetHeight+'px';  
		} 
	else {    
		var pageWidth='100%'; 
		var pageHeight='100%';  
		}      
		//set the shader to cover the entire page and make it visible.   
		dark.style.opacity=opaque;                    
		dark.style.MozOpacity=opaque;                 
		dark.style.filter='alpha(opacity='+opacity+')'; 
		dark.style.zIndex=zindex;         
		dark.style.backgroundColor=bgcolor; 
		dark.style.width= pageWidth;   
		dark.style.height= pageHeight;  
		dark.style.display='block';      
		}
		else {    
		dark.style.display='none';  
		}
		}
		
function isGray()
{
	var dark=document.getElementById('darkenScreenObject');  
	if (!dark) {
		return false;
	}
	else if (dark.style.display=='none')
			return false;
	else
		return true;
}		
		
function showModal(divId)
	{
		
		
		var x = 0;
		var y = 40;
		var element      = document.getElementById(divId);
		if (element){
		grayOut(true);
		element.style.display = "block";
		element.style.zIndex= 200;
		var width        = window.innerWidth  ? window.innerWidth  : document.documentElement.clientWidth;
		var height       = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight;

  		element.style.position = "absolute";
 
		element.style.left = (document.documentElement.scrollLeft+(width -element.clientWidth )/2+x)+'px';
 	 	element.style.top  = (document.documentElement.scrollTop +y)+'px';
		}
	
	}
	
	function hideModal(divId)
	{
		grayOut(false);
		document.getElementById(divId).style.display = "none";
	}
	
	 function getRadioValue(radioObject) {
          var value = null
          for (var i=0; i<radioObject.length; i++) {
               if (radioObject[i].checked) {
                    value = radioObject[i].value;
                    break ;
               }
          }
          return value
     }
	 
	 function updateHtml(idString, html)
	{
		obj = document.getElementById(idString);
		if (obj)
		{
			obj.innerHTML = html;	
		}
	}
	function getInnerHtml(idString)
	{
		obj = document.getElementById(idString);
		if (obj)
		{
			return obj.innerHTML;	
		}
		else
			return null;
	}
	
	function objectExists(idString)
	{
		obj = document.getElementById(idString);
		if (obj)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
	function hideObject(objId)
	{
		document.getElementById(objId).style.display = "none";
	}
	function showObject(objId)
	{
		document.getElementById(objId).style.display = "inline";
	}
	function getTextOfSelectedOption(objId)
	{		
		obj = document.getElementById(objId);	
		var w = obj.selectedIndex;		
		var text = obj.options[w].text;		
		return text;
	}
	
	function getCookie(c_name)
	{
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
		  if (c_start!=-1)
			{ 
			c_start=c_start + c_name.length+1; 
			c_end=document.cookie.indexOf(";",c_start);
			if (c_end==-1) c_end=document.cookie.length;
			return unescape(document.cookie.substring(c_start,c_end));
			} 
		  }
		return "";
	}
	function setCookie(c_name,value,expiredays)
	{
		//var exdate=new Date();	
		//exdate.setDate(exdate.getDate()+expiredays);
		var today      = new Date(); 
		var exdate = new Date(today.getTime() + (expiredays * 86400000));
		document.cookie=c_name+ "=" +escape(value)+
		((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
	}

	 function expandProfile(id)
	 {
		if ( document.getElementById("profileExpanded" + id).style.visibility == 'hidden' || document.getElementById("profileExpanded" + id).style.display == 'none'  || document.getElementById("profileExpanded" + id).style.visibility == '')
		{
			obj = document.getElementById('expandProfileLink' + id);
			obj.src = '/images/collapse.png';
			
			document.getElementById("profileExpanded" + id).style.visibility = 'visible'; 
			document.getElementById("profileExpanded" + id).style.display = 'inline'; 
			//document.getElementById("profileExpanded" + id).style.width = '500px';
			//document.getElementById("profileExpanded" + id).style.height = '140px';
			document.getElementById("profileExpanded" + id).style.height = '100%';
			document.getElementById("profileExpanded" + id).style.width = '100%';
			
			//updateHtml("expandProfileLink" + id, 'Collapse');
			lastClickWasToExpand = id;
		}
		else
		{
			obj = document.getElementById('expandProfileLink' + id);
			obj.src = '/images/expand.png';
			
			document.getElementById("profileExpanded" + id).style.visibility = 'hidden'; 
			document.getElementById("profileExpanded" + id).style.display = 'none'; 
			document.getElementById("profileExpanded" + id).style.width = '0px';
			document.getElementById("profileExpanded" + id).style.height = '0px';
			//updateHtml("expandProfileLink" + id, 'Expand Profile');
			
			lastClickWasToExpand = "";
		}		
	 }
	 
	 function newMsgSound() {
		try{
		  var thissound=document.getElementById("sound1");
		  thissound.Play();
		}
		catch(err)
		{

		}
	}
	function sentMsgSound() {
		try{
			var thissound=document.getElementById("sound2");
			thissound.Play();
		}
		catch(err)
		{
		
		}
	}
	
	function limitChars(obj, limit)
	{
		var numChars = obj.value.length;
		if(numChars > limit) {
			obj.value = obj.value.substring(0, limit);
		}
	}


