if(document.all && !document.getElementById) {
		document.getElementById = function(id) {
			 return document.all[id];
		}
	}		
			
function all(tagID)
{

	if(document.all)
		{
			return document.all[tagID];
		}
	else
		{
		return document.getElementsByName(tagID);
		}
}
			
			var firefoxCounterObj;
			var TotalProgress;
			var url;
			var xmlhttpShell;
			var locked = false;
			var timer;
/* Load Journal PopUp */
function  showJournalPop()
{
    var Jret_val = window.showModalDialog('/CRM/CRM_NewJournalEntry_Frame.html', '', 'dialogWidth:535px;dialogHeight:375px;');    
    return Jret_val != null;
}
/* autocomplete with params */

  function splitInfo(tb,hid)
  {
        var HIDDEN= document.getElementById(hid);
        var temp = tb.value;
        var vals =  temp.split('~');
        if ((vals.length > 1) && (HIDDEN != null))
        {
                tb.value = Trim(vals[0]);
                HIDDEN.value = Trim(vals[1]);
        }
   }


           var ie = (document.all) ? 1 : 0;
           var p = (ie) ? "filter" : "MozOpacity";

function op(n,v){
    if (v ==100){
       n.style[p] = '';
  }else{
   v = (ie) ? "alpha(opacity="+v+")" : v/100; 
    n.style[p] = v;
  }
  
}


function trimAnchor(URL)
{
       var ind = URL.indexOf('#');
      if (ind == -1 )  {return URL;}
        return URL.substring(0,ind) ;
}
/*----------------------------------------------------------*/
function CollapseAllDivs(subdivID)
{
       var divsInput = document.getElementById('subFolderDivs');
       if (divsInput != null) {
            var arr =  divsInput.value.split(',');
           for (i=0;i<arr.length;i++)
            {
                var tempDiv = document.getElementById('subdiv' + arr[i]);
                if (tempDiv != null) {if ('subdiv' + arr[i] != subdivID){tempDiv.style.display='none';}}
            }  
       }

}
function ExpandSibs(subdivID,targetUrl)
{
    CollapseAllDivs('subdiv' + subdivID);
    var subdiv = document.getElementById('subdiv' + subdivID);
    if (subdiv != null) {
        if (subdiv.style.display == 'none')
        {
            subdiv.style.display = '';
        }else{
        
            window.location=targetUrl;
        } 
   }else{
         window.location=targetUrl;
   }

}
/*----------------------------------------------------------*/

function showHidePanes(show,hide){
		document.getElementById(show).style.display = "block";
		var hideArr = hide.split(',');
		for (i=0;i< hideArr.length;i++)
		{
			document.getElementById(hideArr[i]).style.display = "none";
		}
}

function openInfoWindow (infoPage)
{
        // openInfoWindow opens the passed html page parameter in a remote window. 
        // You can create more remote windows by naming the new window object a 
        // different name. 

//var newwind = window.showHelp(infoPage);      
        var newWind = window.open(infoPage,'info','width=450,height=455,scrollbars=yes,toolbar=no,resizable=1');

        if (newWind.opener == null)
        {
                newWind.opener = window;
        }
        else
        {
                newWind.focus();
        }
}
function openSizedInfoWindow (infoPage,width,height)
{
        // openInfoWindow opens the passed html page parameter in a remote window. 
        // You can create more remote windows by naming the new window object a 
        // different name. 

//var newwind = window.showHelp(infoPage);      
        var newWind = window.open(infoPage,'info','width=' + width +',height=' + height + ',scrollbars=yes,menubar=no,resizable=1');

        if (newWind.opener == null)
        {
                newWind.opener = window;
        }
        else
        {
                newWind.focus();
        }
}


/*----------------------------------------------------------*/
function CAGperm(packID, rowFrom, rowTo, MyControl)
{	
	if (MyControl == null){return;}
	var ISchecked = MyControl.src.split('AllUsers')[1] != null;

	if (!ISchecked)
	{
		MyControl.src = MyControl.src.replace('NoneUsers','AllUsers');
		MyControl.alt = 'Check all';	
	}else{
		MyControl.src = MyControl.src.replace('AllUsers','NoneUsers');
		MyControl.alt = 'Uncheck all';				
	}


	var Cbs = document.getElementsByTagName('input');
	for (i=0;i<Cbs.length;i++)
	{
	   try
	   {
	    if ((Cbs[i].type == 'checkbox') && (!Cbs[i].disabled) && (Cbs[i].name.indexOf('MyGridHead') == -1))
              {
		if (Cbs[i].attributes['Pack'] != null)
		{
			if (parseInt(Cbs[i].attributes['Pack'].value) == packID)
			{
				if (Cbs[i].attributes['RowIndex'] != null)
				{
					if ( (parseInt(Cbs[i].attributes['RowIndex'].value) >= rowFrom) && (parseInt(Cbs[i].attributes['RowIndex'].value) <= rowTo))
					{
						Cbs[i].checked = ISchecked;
						var CBControlClientID = Cbs[i].id.substring(0,Cbs[i].id.length-3)
						UpdateCB(Cbs[i].id, CBControlClientID + '_CheckStatus');
					}
				}
			}
		}
             }
           }
	   catch(ex)
		{
			var x = 'asdfasdfas';
		}
		
	}

}
 /*----------------------------------------------------------*/
function CAG(cbName,ONCB,OFFCB)
{
    //gg;
	var CB = document.getElementById(ONCB);
	if (CB != null)
	{
		if (CB.src.split('AllUsers')[1] == null)
		{
					var CBS = all(cbName);
					CB.src = CB.src.replace('NoneUsers','AllUsers');
					CB.alt = 'Check all users';	
						
					if (CBS == null) return false;
					if (CBS.tagName){
						CBS.checked=false;
					}else{
						for( i = 0; i != CBS.length; i=i+1) {
							CBS[i].checked = false;
						}
					}
							
		}else{

					var CBS = all(cbName);
  					CB.src = CB.src.replace('AllUsers','NoneUsers');
					CB.alt = 'Uncheck all users';				
    
					if (CBS == null) return false;
					if (CBS.tagName){
						CBS.checked=true;
					}else{
						for( i = 0; i != CBS.length; i=i+1) {
							CBS[i].checked = true;
						}
					}
		}
	}
}

/*----------------------------------------------------------*/

function PasteEditorStuff(str)
{
	var editorID = document.getElementById ('hidden_editorID');
	var item = document.getElementById (editorID.value);
	var editor=CuteEditor_GetEditor(item);
	var Ox = document.createElement('div');
	Ox.innerHTML = str;
	//editor.InsertElement(Ox) ;
	//CuteEditor_GetEditor(item).ExecCommand('PasteHTML',false,str);
	editor.ExecCommand("PasteHTML",true,str);
	}
			
	var sURL = unescape(window.location.pathname);
	function refreshAndRestart()
	{
	    //  This version of the refresh function will cause a new
	    //  entry in the visitor's history.  It is provided for
	    //  those browsers that only support JavaScript 1.0.
	    //
	    window.location.href = sURL;
	    
	}
	function refresh()
	{
		window.location.reload( true );
		//history.go();
		//__doPostBack('');
	}
		//******************************************* image uploader *************************
function confirm_ImageDelete(cbName)
{
var counter = 0
var CBS = all(cbName);
if (CBS == null) return false;
if (CBS.tagName){
	if (CBS.checked) counter = 1;
}else{
	for( i = 0; i != CBS.length; i=i+1) {
	if (CBS[i].checked) counter = counter + 1;
	}
}
if (counter == 0) {
alert("You did not select any Images to remove");
return false;
}
 if (confirm("Are you sure you want to remove these " + counter + " Images?")==true)
    return true;
  else
    return false;
}
//**************************************************************************************************
		function showSplashTimedOnStart(WaitTime)
		{
			var Dis = document.getElementById('DisableScreen');
			Dis.style.visibility = 'visible';
			//Dis.style.z-index = '999999';
			var I = document.getElementById('Coverup');
			I.style.visibility = 'visible';
			var D = document.getElementById('CoverupDiv');
			D.style.visibility = 'visible';
			//D.style.z-index = '999999';
			setTimeout('hideSplash();',WaitTime);
		}
		
		
		function sS(IsCallBack,WaitTime)
		{
			/*SplashTimer = setInterval(DoTheSplash(IsCallBack),WaitTime);*/
			if (IsCallBack)
			{
					SplashTimer = setInterval('DoTheSplash(true);',WaitTime);
			}else{
					SplashTimer = setInterval('DoTheSplash(false);',WaitTime);	
			}
			
			//block screen actions
			var Dis = document.getElementById('DisableScreen');
			if (Dis == null){ return true;}
			Dis.style.visibility = 'visible';
			//Dis.style.z-index = '999999';
			
			//hide message for 3 secs
			var I = document.getElementById('Coverup');
			I.style.visibility = 'hidden';
			//I.style.z-index = '-1';
			var D = document.getElementById('CoverupDiv');
			D.style.visibility = 'hidden';
			//D.style.z-index = '-1';
		}
		
		function DoTheSplash(IsCallBack)
		{
			//stop timer
			if (typeof SplashTimer != 'undefined')
			{clearInterval(SplashTimer);}
			var Dis = document.getElementById('DisableScreen');
			if (Dis != null)
			{
						Dis.style.visibility = 'hidden';
						//Dis.style.z-index = '-1';
			}
			//show message
			var I = document.getElementById('Coverup');
			I.style.visibility = 'visible';
			//I.style.z-index = '999999';
			var D = document.getElementById('CoverupDiv');
			D.style.visibility = 'visible';
			//D.style.z-index = '999999';
			if (IsCallBack) 
			{	
					startTimer();
			}else{
					if(firefoxCounterObj != null){
						if(firefoxCounterObj.firstChild) 
						{
								firefoxCounterObj.removeChild(firefoxCounterObj.firstChild);
						}
					}
					if (TotalProgress != null){
						if(TotalProgress.firstChild) {
								TotalProgress.removeChild(TotalProgress.firstChild);
						}
					}
			}
		}
					
		
		function hideSplash()
		{
			var I = document.getElementById('Coverup');
			var D = document.getElementById('CoverupDiv');
			I.style.visibility = 'hidden';
			//I.style.z-index = '-1';
			D.style.visibility = 'hidden';
			//D.style.z-index = '-1';
			var Dis = document.getElementById('DisableScreen');
			Dis.style.visibility = 'hidden';
			//Dis.style.z-index = '-1';
		try { 
				clearInterval(SplashTimer);
				} 
			catch (e) 
				{ } 
			
		}
		

		////////////////////////////////////////////// Forms /////////////////////////////////////////////////////////
		
		function addTagToTB(ddlID,tbID)
		{
		    var DDl = document.getElementById(ddlID);
		    var TB =  document.getElementById(tbID);
		    if ((DDl != null) && (TB != null)){
		        var Op = DDl.options[DDl.selectedIndex]; 
		        TB.value = TB.value + Op.value;
    		}
		}
		
		function toggleCheckBoxStat(cbID)
		{
			var arrayCB =  cbID.split(',');

			if (cbID.indexOf(',') == -1){
					var theCB = document.getElementById(cbID);
					if (theCB != null){theCB.checked = !theCB.checked ;}
			}else{
					for( i = 0; i != arrayCB.length; i=i+1) {
						var theCB = document.getElementById(arrayCB[i]);
						if (theCB != null){theCB.checked = false ;}
					}
			}
		}
function SetupDivByCB(DivID,CbID)
{
	var d = document.getElementById(DivID);
	var cb = document.getElementById(CbID);
	
	if (cb.checked){
		d.style.visibility = 'visible';
	}else{
		d.style.visibility = 'hidden';
	}
}
function SetupDivByDDL(DivID,DdlID,visibleIndexes)
{
	var d = document.getElementById(DivID);
	var ddl = document.getElementById(DdlID);
	
	var delimit = visibleIndexes.split(',');
	for( i = 0; i != delimit.length; i=i+1) {
		if (parseInt(delimit[i]) ==  ddl.selectedIndex){
		d.style.visibility = 'visible';
		return;
		}
	}
	
	d.style.visibility = 'hidden';
}

function UpdateDDLselection(text,value,textID,hiddenID)
{
	var TheText = document.getElementById(textID);
	TheText.innerText = text;
	TheText.innerHTML = text;
	
	var TheHidden = document.getElementById(hiddenID);
	TheHidden.value = value;
	
}

function openSizedInfoWindow (infoPage,szw,szh,szr,szs)
{
        // openInfoWindow opens the passed html page parameter in a remote window. 
        // You can create more remote windows by naming the new window object a 
        // different name. 

//var newwind = window.showHelp(infoPage);      
try{
        var newWind=window.open(infoPage,'info','width='+szw+',height='+szh+',resizable='+szr+',scrollbars='+szs+',top=0,left=0');
        try{newWind.moveTo(screen.availWidth/2-(parseInt(szw)/2),screen.availHeight/2-(parseInt(szh)/2));}catch(ex2){}
} catch(ex){alert('Popup window cannot be open, Please enable Popups on this site to continue.');}
  
        if (newWind.opener == null)
        {
                newWind.opener = window;
        }
        else
        {
                newWind.focus();
        }
}
 
      
 function Trim(str)
{
     str =    str.replace(/^\s*|\s*$/g,"");
     for (i=0;i<str.length;i++)
    {
        if (str.charAt(i) != ' '){return str;}
    }  
   return ''; 
} 


function getSel()
{
	var txt = '';
	var foundIn = '';
	if (window.getSelection)
	{
		txt = window.getSelection();
		foundIn = 'window.getSelection()';
	}
	else if (document.getSelection)
	{
		txt = document.getSelection();
		foundIn = 'document.getSelection()';
	}
	else if (document.selection)
	{
		txt = document.selection.createRange().text;
		foundIn = 'document.selection.createRange()';
	}
	else return;
	return txt;
}
function RefreshTab(objFoc)
{

}

//-------------------------------------------------------------------------
// tie buttons to enter keys

    function doTieClick(buttonName,e)
    {//the purpose of this function is to allow the enter key to point to the correct button to click.
        var key;

         if(window.event)
              key = window.event.keyCode;     //IE
         else
              key = e.which;     //firefox
    
        if (key == 13)
        {
            //Get the button the user wants to have clicked
            var btn = document.getElementById(buttonName);
            if (btn != null)
            { //If we find the button click it
                btn.click();
                event.keyCode = 0
            }
        }

    }

