//It will store all the shared functions that are used to menu
Function.prototype.bind=function()   
{   
      var _method =this;   
      var   arg=arguments;   
      return function() {   
          _method.apply(window,arg);   
      }   
}

function readWSCookie(cookieName)
{
	var name = cookieName + "=";
	var arrCookies = document.cookie.split(';');
	for(var i=0;i < arrCookies.length;i++)
	{
		var c = arrCookies[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(name) == 0) return unescape(c.substring(name.length,c.length));
	}
	return null;
}

function setMSCookie(name, value) {	
			var time=new Date();
			time.setTime(time.getTime()+365*24*60*60*1000);
			document.cookie = name + "=" + escape(value) + "; expires="+time.toGMTString()
			+ "; path=/; domain=.morningstar.com";	
}

//arr a Array of all the control ids
//hid:the control id that needs to be highlighted
function HighLight(arr,hid)
{
    for(var i=0;i<arr.length;i++)
    {
        if(document.getElementById(arr[i]))
            (document.getElementById(arr[i])).className='text_c2';
    }
    if(document.getElementById(hid))
    {
        (document.getElementById(hid)).className='filteractive';
    }
}


//menuTitleId: the menu title value:the value need to be set to menu title
function SelectMenuItem(menuTitleId,value)
{
    if(document.getElementById(menuTitleId))
    {
        document.getElementById(menuTitleId).innerHTML=value;
    }
}


function ResetAllMenu(ids,values)
{
    if(ids.length!=values.length)
        return;
    for(var i=0;i<ids.length;i++)
    {
        if(document.getElementById(ids[i]))
        {
            document.getElementById(ids[i]).innerHTML=values[i];
        }        
    }
}


function getValue(name,value)
{
    if(value==null)
        return '';
     var reg = new RegExp(name+'=([^;]*)[;$]?', 'gi');
     var chk = value.match(reg);
     if(chk!=null)
        return RegExp.$1;
     else
        return '';
}

function addEvent( obj, type, fn) 
{
    if ( obj.attachEvent ) 
    {
      obj.attachEvent( 'on'+type, fn);
    } 
    else 
    {
      obj.addEventListener( type, fn, false );
    }
}