/*called IN dsp_DocumentLibrary.cfm***********************************************************************************************/
function showImgs(did) {
        document.getElementById('look_'+did).style.display='inline';
        document.getElementById('edit_'+did).style.display='inline';
}
function hideImgs(did) {
        document.getElementById('look_'+did).style.display='none';
        document.getElementById('edit_'+did).style.display='none';
}

/*popup div layers and show grey overlay******************************************************************************************/
function showPopUp() //show the grey overlay 
{
document.getElementById("overlay").style.display = "";
}
function hidePopUp() //hide the grey overlay
{
document.getElementById("overlay").style.display = "none";
}

function LoadIFramePopUp(addr) {
    	var overlay = (typeof arguments[1] == 'undefined' || arguments[1] == '') ? 1:arguments[1];
    	var mylay = (typeof arguments[2] == 'undefined' || arguments[2] == '') ? 'mydiv':arguments[2];
    	var width = (typeof arguments[3] == 'undefined') ? 'auto':arguments[3];
    	var height = (typeof arguments[4] == 'undefined') ? 'auto':arguments[4];
	var hideoverlay = '';
	var fwidth = '';
	var fheight = '';
	if (overlay) {
		showPopUp('overlay');
		hideoverlay = 'hidePopUp(\'overlay\');';
	}
	if (!MM_findObj(mylay)) { createDiv(mylay,55,55);}
	var d = document.getElementById(mylay);
	d.style.width = width;
	d.style.height= height;
	if (width != 'auto') {
		fwidth = "width='"+ (width-5) + "'";
		d.style.width = width + "px";
	}
	if (height != 'auto') {
		fheight = "height='" + (height-5) + "'";
		d.style.height = height + "px";
	}
	d.innerHTML = '<iframe '+ fwidth + fheight +' frameborder="0" src="'+addr+'" id="myframe" name="myframe" ></iframe><br><a href="javascript:;" onClick="hidePopUp(\'overlay\');removeDiv(\'' + mylay + '\')" class="submit">Close</a>';
	if (width != 'auto') { centerDivH(d); }
	if (height != 'auto') { centerDivV(d); }
}
function LoadDocumentList(this_url) //change the hotness image in the prospect list div layer
{
	//use ajax to hit script that will switch hotness
	showLoading('DocumentListdiv');
	ajaxLoadPage(this_url,'DocumentListdiv',0);
}
function LoadDocumentFilter(this_url) //change the hotness image in the prospect list div layer
{
	//use ajax to hit script that will switch hotness
	showLoading('DocumentFilterdiv');
	ajaxLoadPage(this_url,'DocumentFilterdiv',0);
}
function ChangeFavorite(id) //change the hotness image in the prospect list div layer
{
        var path = (typeof arguments[1] == 'undefined') ? 'images/documents/' : arguments[1] + "/";
	//use ajax to hit script that will switch hotness
	var this_url='index.cfm?Fuse=private/DocumentLibrary&Page=ChangeFavorite&DOCUMENT_ID=' + id;
	ajaxLoadPage(this_url,'hiddenreturnframe',0);

	//change image
	ChangeFavoriteImage(id,path);
}
function ChangeFavoriteImage(id) //change the hotness image in the prospect list div layer
{
        var path = (typeof arguments[1] == 'undefined') ? 'images/documents/' : arguments[1] + "/";
       	var distid=id; 
		var img_name='star_img_' + distid;
		var el = document.getElementById(img_name);

				if (el)
				{
					document.MM_sr = []; // clear out swap image array
					if ( el.name == "staroff")
					{
					el.src= path + 'star_on.gif';
					el.name="staron";
					el.onmouseover = function() {};
					el.onmouseout = function() {};
					}
					else
					{
					el.src= path + 'star_off.gif';
					el.name="favoriteoff";
					el.onmouseover = function() {MM_swapImage(this.id,'',path + 'star_on.gif',1);return true;};
					el.onmouseout = function() {MM_swapImgRestore();};
					}
				}
}
function changefiltertypereturn() //change the hotness image in the prospect list div layer
{
				mdiv = MM_findObj('DocumentFilterdiv');
				mdiv.innerHTML = result;
				evalScripts(mdiv.innerHTML);
}

function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}


/********dsp_DOCUMENTLISTFILTER.cfm******************************************/
function SearchOptionChange()
{
	if (document.forms.ChangeFilterType.FilterType.value == "ALL_AVAILABLE")
		document.getElementById('searchoptionsdiv').style.display = 'none';
	else
		document.getElementById('searchoptionsdiv').style.display = 'block';
}
function LoadCollapseExpand(shID)
{
	cookiename='ListFilterStatus_' + shID;
	var img_name='collapse_expand_' + shID;
	var el = document.getElementById(img_name);
	var cookieid = readCookie(cookiename);
	if (cookieid && cookieid == 'expanded') {
					el.src="images/expanded.gif";
					el.name="expanded";
					document.getElementById(shID).style.display = 'block';
					createCookie(cookiename,'expanded',0);
	}
	else
	{
					el.src="images/collapsed.gif";
					el.name="collapsed";
					document.getElementById(shID).style.display = 'none';
					createCookie(cookiename,'collapsed',0);
	}
}
function showHideList(shID) {

		var img_name='collapse_expand_' + shID;
		var el = document.getElementById(img_name);
		cookiename='ListFilterStatus_' + shID;
				if (el)
				{
					if ( el.name == "collapsed")
					{
					el.src="images/expanded.gif";
					el.name="expanded";
					document.getElementById(shID).style.display = 'block';
					createCookie(cookiename,'expanded',0);
					}
					else
					{
					el.src="images/collapsed.gif";
					el.name="collapsed";
					document.getElementById(shID).style.display = 'none';
					createCookie(cookiename,'collapsed',0);
					}
				}
}

function ExpandCloseSecondaryList(div,closediv)
{
	//open these div layers
	thislen=listLen(div,'|');
	for(i=0; i<thislen; i++) 
	{
		j=i+1;
		thisdiv=listGetAt(div,j,'|');
		document.getElementById(thisdiv).style.display = 'block';
	}
	
	//close these div layers
	thislen=listLen(closediv,'|');
	for(i=0; i<thislen; i++) 
	{
		j=i+1;
		thisdiv=listGetAt(closediv,j,'|');
		document.getElementById(thisdiv).style.display = 'none';
	}
	
	
}
/*****************************************************************************************/








/* ColdFusion List Functions
   These functions manipulate lists just list ColdFusion does.
   (c) Digital Crew
   Happy Christmas. Knock yourself out.
   email: topper@digital-crew.com
   web: www.digital-crew.com   /   www.cftopper.com
*/
function listFind(c,n,d)
{
	if(arguments.length<3)d=",";
	var e = c.split(d);
	for(var i=0;i<c.length;i++) if( e[i]==n ) return i+1;
	return 0;
}
function listPrepend(c,n,d)
{
	if(arguments.length<3)d=",";
	return n+(c!=""?(d+c):"");
}
function listAppend(c,n,d)
{
	if(arguments.length<3)d=",";
	return (c!=""?(c+d):"")+n;
}
function listDeleteAt(c,p,d)
{
	if(arguments.length<3)d=",";
	var e = c.split(d);
	if(p<=e.length)
	{
		var n="";
		for(var i=0;i<p-1;i++) n=n+e[i]+d;
		for(var i=p;i<e.length;i++) n=n+e[i]+d;
		return (n.length<1 || n.charAt(n.length-1)!=d)?n:n.substring(0,n.length-1);
	}
	return c;
}
function listGetAt(c,p,d)
{
	if(arguments.length<3)d=",";
	var e = c.split(d);
	if( p >= 1 && p <= e.length )
	{
		return e[p-1];
	}
	return "";
}
function listSetAt(c,p,v,d)
{
	if(arguments.length<4) d=",";
	var e = c.split(d);
	if( p >= 1 && p <= e.length )
	{
		e[p-1] = v;//set the value
		//rebuild the string
		for( var i=0,c=""; i < e.length; i++ )
			c = (c!=""?(c+d):"")+e[i];
	}
	return c;
}
function listInsertAt(c,p,v,d)
{
	if(arguments.length<4) d=",";
	var e = c.split(d);
	if( p >= 1 && p <= e.length+1 )
	{
		e.splice( p-1, 0, v );//insert the value
		//rebuild the string
		for( var i=0,c=""; i < e.length; i++ )
			c = (c!=""?(c+d):"")+e[i];
	}
	return c;
}
function listLen(c,d)
{
	if( c == "" ) return 0;
	if(arguments.length<2)d=",";
	return c.split(d).length;
}

function clearCheckBox(name) {
	for (i=0; i<document.frm.elements.length; i++) { 
		el = document.frm.elements[i];
		if (el.type=="checkbox" && el.name.indexOf(name)!=-1){
			if (el.checked) {
				el.checked = false;
			}
		} 
	}
}
function setCheckBox(name) {
	for (i=0; i<document.frm.elements.length; i++) { 
		el = document.frm.elements[i];
		if (el.type=="checkbox" && el.name.indexOf(name)!=-1){
			if (el.checked == false) {
				el.checked = true;
			}
		} 
	}
}
function checkAllBox(name, checked) {
        var frm  = (typeof arguments[2] == 'undefined') ? document.frm : MM_findObj(arguments[2]);
	for (i=0; i<frm.elements.length; i++) { 
		el = frm.elements[i];
		if (el.type=="checkbox" && el.name.indexOf(name)!=-1){
			if (checked) {
				el.checked = true;
			} else {
				el.checked = false;
			}
		} 
	}
}
function checkBox(id) {
	document.getElementById(id).checked = true;
}
