function OpenWindow(getUrl,getTarget,getScrollbar,getMenubar,getHeight,getWidth,getResize,getToolbar,getLocation,getStatus)
{
	window.open(getUrl,getTarget,'top=0,left=0,scrollbars='+getScrollbar+',menubar='+getMenubar+',height='+getHeight+',width='+getWidth+',resizable='+getResize+',toolbar='+getToolbar+',location='+getLocation+',status='+getStatus+'')
}

function OpenFile(PageURL,WindowWidth,WindowHeight)
{
	window.open(PageURL,'FileViewer','toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=no,copyhistory=no,scrollbars=no,width=' + WindowWidth + ',height=' + WindowHeight + ',top=50,left=50');
}

function CaricaFoto(img)
{
  	foto1= new Image();
  	foto1.src=(img);
  	Controlla(img);
}

function Controlla(img){
  	if((foto1.width!=0)&&(foto1.height!=0))
  	{
    		viewFoto(img);
  	} else {
    		funzione="Controlla('"+img+"')";
    		intervallo=setTimeout(funzione,20);
  	}
}

function viewFoto(img)
{
  	largh=foto1.width+20;
  	altez=foto1.height+20;
  	stringa="width="+largh+",height="+altez;
  	finestra=window.open(img,"",stringa);
}

function OpenPrintView(PageURL)
{
	window.open(PageURL,'PrintViewer','toolbar=yes,location=no,directories=no,status=yes,menubar=yes,resizable=yes,copyhistory=no,scrollbars=yes');
}

function echo(arg)
{
	document.write(arg);
}

function map(maddr,mcity,mstate,mzip,mcountry)
{
	href='http://maps.google.com/maps?oi=map&q='+maddr+', '+mcity+', '+mstate+', '+mzip+', '+mcountry+'';
	window.open(unescape(href),'_blank','status=yes,resizable=yes,toolbar=yes,location=no,scrollbars=yes,width=500,height=500,top=0,left=0');
}

function removeSelectList(strSelect)
{
	while (strSelect.options.length > 0)
	{
	    strSelect.options[0] = null;
	}
}

function AddSelectList(strSelect, strText, strValue)
{
	var newOpt = new Option(strText, strValue);
	var selLength = strSelect.length;
	strSelect.options[selLength] = newOpt;
}

function GatherIDs(selectCtrl)
{
	var i;
	var j = 0;
	var outlist = "";
	for (i = 0; i < selectCtrl.options.length; i++) {
		if (j > 0) 
		{
			outlist = outlist + ",";
		}
		outlist = outlist + "|" + selectCtrl.options[i].value + "|";
		j++;
	}
	return outlist;
}

function addItems(fromCtrl, toCtrl)
{
	var i;
	var j;
	var itemexists;
	var nextitem;
	for (i = 0; i < fromCtrl.options.length; i++) {
		if (fromCtrl.options[i].selected) 
		{
			j = 0;
			itemexists = false;
			while ((j < toCtrl.options.length) && (!(itemexists))) 
			{
				if (toCtrl.options[j].value == fromCtrl.options[i].value) 
				{
					itemexists = true;
					alert(fromCtrl.options[i].value + " found!");
				}
				j++;
			}
			if (!(itemexists)) 
			{
				nextitem = toCtrl.options.length;
				toCtrl.options[nextitem] = new Option(fromCtrl.options[i].text);
				toCtrl.options[nextitem].value = fromCtrl.options[i].value;
			}
		}
	}
}

function removeItems(fromCtrl)
{
	var i = 0;
	var j;
	var k = 0;
	while (i < (fromCtrl.options.length - k)) {
		if (fromCtrl.options[i].selected) 
		{
			for (j = i; j < (fromCtrl.options.length - 1); j++) 
			{
				fromCtrl.options[j].text = fromCtrl.options[j+1].text;
				fromCtrl.options[j].value = fromCtrl.options[j+1].value;
				fromCtrl.options[j].selected = fromCtrl.options[j+1].selected;
			}
			k++;
		} else {
			i++;
		}
	}
	for (i = 0; i < k; i++) {
		fromCtrl.options[fromCtrl.options.length - 1] = null;
	}
}

function boxcheck(frm,stat)
{
	var frm_el=frm.elements;
	var frm_ln=frm_el.length;
        for (var i=0; i<frm_ln; i++)
        {
        	if(frm_el[i].type=="checkbox")frm_el[i].checked=stat;
		}
}

function OpenPageURL(WebPageURL)
{
	window.open(WebPageURL,"PageURL","resizeable=yes,scrollbars=no,width=400,height=100")
}

function adminnav_Height(sid,ipix)
{
	var iframeH=getPageSize()[1]-ipix;
	document.getElementById(sid).style.height=iframeH+'px';
}

function adminnav_Width(sid,ipix)
{
	var iframeH=getPageSize()[0]-ipix;
	document.getElementById(sid).style.width=iframeH+'px';
}

function URLEncode(sURL)
{
	var urldata=escape(sURL).replace(/\+/g,'%2B');
	return urldata
}

function left(str, n)
{
	if (n <= 0)
	    	return "";
	else if (n > String(str).length)
	    	return str;
	else
	    	return String(str).substring(0,n);
}

function right(str, n)
{
	if (n <= 0)
       		return "";
    	else if (n > String(str).length)
       		return str;
    	else 
    	{
       		var iLen = String(str).length;
       		return String(str).substring(iLen, iLen - n);
    	}
}

function expandTree(strURL,strID)
{
	xmlTreeHttp = new ajaxXMLHttpRequest();
  	
	xmlTreeHttp.open("GET", strURL, false);
	xmlTreeHttp.send(null);
  	if (xmlTreeHttp.readyState == 4) 
  	{
    		if (xmlTreeHttp.status == 200) 
    		{
      			document.getElementById(strID).innerHTML = xmlTreeHttp.responseText;
    		}
  	}
  	return false;
}

function fm_ExpandCat(scatid,scatname,imoduleid,ioffset,shascat,svalue,sform,spopulate,sfrompage,appendName,sadditional,iportalid)
{
	var i = 0;
	var param = '';
	var objvar = '';
	
	if(shascat != '' && shascat != '0')
	{
		if(document.getElementById('opencat'+scatid+appendName).style.display == '')
		{
			document.getElementById('opencat'+scatid+appendName).style.display='none';
			try
			{
				document.getElementById('folder'+scatid+appendName).src='/images/admin/tree/fm_close.gif';
			} catch(e) {}
		} else {
			try
			{
				document.getElementById('opencat'+scatid+appendName).style.display='';
				document.getElementById('folder'+scatid+appendName).src='/images/admin/tree/fm_open.gif';
				expandTree('/cwadmin/admcategory.aspx?DoAction=ExpandCategory&TopMenu=False&CatID='+scatid+'&ModuleID='+imoduleid+'&Offset='+ioffset+'&FormName='+sform+'&PopulateID='+spopulate+'&FromCat='+sfrompage+'&AppendName='+appendName+'&PortalID='+iportalid,'opencat'+scatid+appendName);
			} catch(e) {}
		}
	}
	svalue.value = scatid;
	document.getElementById('catName'+appendName).innerHTML='Selected Category: '+scatname;

	try
	{
		document.getElementById('ajaxpublicframe').src='/cwadmin/ajax.aspx?DoAction=PortalList&CatID='+document.getElementById('CatID').value+'&PortalID='+iportalid;
	}
	catch(e)
	{
	}
	
	// Page Editor Loader
	if(sfrompage == '2')
	{
		if(scatid != '')
		{
			document.getElementById('idHideOptions').style.display='none';
			document.getElementById('editorTitle').style.display='none';
		} else {
			document.getElementById('idHideOptions').style.display='';
			document.getElementById('editorTitle').style.display='';
		}
		oEdit1.clearContent();
		oEdit1.focus();
		xmlHttp = new ajaxXMLHttpRequest();
		xmlHttp.open("GET", '/cwadmin/admwpages.aspx?DoAction=ShowEditor&ModuleID='+imoduleid+'&Show=Editor&CatID='+scatid+'&PortalID='+iportalid, false);
		xmlHttp.send(null);
		oEdit1.insertHTML(xmlHttp.responseText);
	}
	
	// Business Directory Category Selection
	try
	{
		if(imoduleid == '20' && parseInt(document.frmBusiness.TotalCat.value) > 1)
		{
			param = '';
			for (i=1;i<=parseInt(document.frmBusiness.TotalCat.value);i++)
			{
				objvar = 'CatID'+i;
				if(i == 1)
				{
					param = param + document.frmBusiness[objvar].value;
				} else {
					param = param + ','+document.frmBusiness[objvar].value;
				}
			}
			document.frmBusiness.CatID.value = param;
		}
	} catch(e)
	{}
	
	// File Libraries Category Selection
	try
	{
		if(imoduleid == '10')
		{
			document.frmLibrary.CatType.value=sadditional;
			ajaxLoadPage('/library_ajax.aspx?DoAction=AJAXModify&CatID='+scatid+'&FileID='+document.frmLibrary.FileID.value+'&PortalID='+iportalid,'libraryDetails');
		}
	} catch(e)
	{}
}

function cat_ExpandCat(scatid,imoduleid,ioffset,shascat,expandonly,iportalid)
{
	if(shascat != '')
	{
		if(document.getElementById('mopencat'+scatid).style.display == '')
		{
			document.getElementById('mopencat'+scatid).style.display='none';
			try
			{
				document.getElementById('mfolder'+scatid).src='/images/admin/tree/fm_close.gif';
			} catch(e) {}
		} else {
			try
			{
				document.getElementById('mopencat'+scatid).style.display='';
				document.getElementById('mfolder'+scatid).src='/images/admin/tree/fm_open.gif';
				expandTree('/cwadmin/admcategory.aspx?DoAction=ExpandManageCategory&TopMenu=False&CatID='+scatid+'&ModuleID='+imoduleid+'&Offset='+ioffset+'&PortalID='+iportalid,'mopencat'+scatid);
			} catch(e) {}
		}
	}
	if(expandonly == 'false')
	{
		var sURL = '/cwadmin/admcategory.aspx?DoAction=CategoryModify&CatID='+scatid+'&ModuleID='+imoduleid+'&Offset='+ioffset+'&PortalID='+iportalid;
		ajaxLoadPage(sURL,'catModify');
	}
}

function fm_scrollSelected(scatid)
{
	try
	{
		document.getElementById('catSelection').scrollTop=document.getElementById('catSelect'+scatid).offsetTop;
	} catch(e)
	{}
}

function clickCategory(scatid)
{
	try
	{
		if(document.getElementById('UpdateCatID').value.indexOf(scatid) == 1)
		{
			document.getElementById('UpdateCatID').value=document.getElementById('UpdateCatID').value.replace(','+scatid,'');
		} else {
			document.getElementById('UpdateCatID').value=document.getElementById('UpdateCatID').value+','+scatid;
		}
	}
	catch(e)
	{}
}

function checkAll(fmobj)
{
  	for (var i=0;i<fmobj.elements.length;i++) 
  	{
    		var e = fmobj.elements[i];
    		if ( (e.name != 'checkall') && (e.type=='checkbox') && (!e.disabled) ) 
    		{
      			e.checked = fmobj.checkall.checked;
    		}
    		if (e.name == 'ModCatID') 
		{
			clickCategory(e.value);
    		}
  	}
}

function dropCalendar(sfield,sid,smonth,syear)
{
	if(document.getElementById(sid).style.display=='' && smonth=='' && syear=='')
	{
		document.getElementById(sid).style.display='none';
	} else {
		ajaxLoadPage('dcalendar.aspx?Field='+sfield+'&ID='+sid+'&Month='+smonth+'&Year='+syear,sid,'no','no');
		document.getElementById(sid).style.display='';
	}
}

function assignCalendar(sfield,svalue,sid)
{
	sfield.value=svalue;
	document.getElementById(sid).style.display='none';
}

function dropoffset()
{
	try
	{
		return parent.scrolloffset();
	} catch(e) {
		return 0;
	}
}