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 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 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,assignValue,allowSelection)
{
	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/category_ajax.aspx?DoAction=ExpandCategory&TopMenu=False&CatID='+scatid+'&ModuleID='+imoduleid+'&Offset='+ioffset+'&FormName='+sform+'&PopulateID='+spopulate+'&FromPage='+sfrompage+'&FromCat='+sfrompage+'&AppendName='+appendName+'&HonorSelection='+allowSelection+'&PortalID='+iportalid,'opencat'+scatid+appendName);
			} catch(e) {}
		}
	}
	if(assignValue == 1)
	{
		svalue.value = scatid;
	} else {
		svalue.value = '';
	}
	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';
			document.getElementById('idEditor').style.position='relative';
		} else {
			document.getElementById('idHideOptions').style.display='';
			document.getElementById('editorTitle').style.display='';
			document.getElementById('idEditor').style.position='';
		}
		try
		{
			//oEdit1.clearContent();
			var oEditor=eval("idContentoEdit1");
			oEditor.document.body.innerHTML="";
		} catch(e)
		{
			oEdit1.clearAll();
		}
		oEdit1.focus();
		xmlHttp = new ajaxXMLHttpRequest();
		xmlHttp.open("GET", '/cwadmin/admwpages_ajax.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;
				}
			}
			if(assignValue == 1)
			{
				document.frmBusiness.CatID.value = param;
			} else {
				document.frmBusiness.CatID.value = '';
			}
		}
	} 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 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;
    		}
  	}
}

function dropoffset()
{
	try
	{
		return parent.scrolloffset();
	} catch(e) {
		return 0;
	}
}

function getPageSize()
{
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY)
	{
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight)
	// all but Explorer Mac
	{
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	// Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
	{
		xScroll = document.body.offsetWidth - 250;
		yScroll = document.body.offsetHeight - 250;
	}

	var windowWidth, windowHeight;

	if (self.innerHeight)
	// all except Explorer
	{
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight)
	// Explorer 6 Strict Mode
	{
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	// other Explorers
	{
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if (yScroll < windowHeight)
		pageHeight = windowHeight;
	else
		pageHeight = yScroll;

	// for small pages with total width less then width of the viewport
	if (xScroll < windowWidth)
		pageWidth = windowWidth;
	else
		pageWidth = xScroll;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function submitLogin(formName,passwordId,usernameId)
{
	if (formName[usernameId].value == '' || formName[passwordId].value == '')
	{
		Modalbox.show('<div class=\'MB_warning\'><div>Username and/or Password is Required</div><p align=\"center\"><input type=\"button\" value=\"OK\" onclick=\"Modalbox.hide()\"/></p></div>', {title: 'The Following Fields Are Required:', width: 400});
	} else {
		formName[passwordId].value=calcMD5(formName[passwordId].value);
		formName.submit();
	}
}

function formatCurrency(val,currency)
{
	if(!val || isNaN(val) || val == '0') 
	{
		return '$0.00';
	}
	val=""+Math.round(100*val); 
	var dec_point=val.length-2;
	var first_part=val.substring(0,dec_point);
	var second_part=val.substring(dec_point,val.length);
	var result=first_part+"."+second_part;
	if(!currency){
		currency="";
	}
	result=currency+result;
	return result;
}

