

//-------------------------------------------------------------------
//function fnLoadPngs() 
//-------------------------------------------------------------------
function fnLoadPngs() {
	var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
	var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);

	for (var i = document.images.length - 1, img = null; (img = document.images[i]); i--) {
		if (itsAllGood && img.src.match(/\.png$/i) != null) {
			var src = img.src;
			img.style.width = img.width + "px";
			img.style.height = img.height + "px";
			img.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')"
			img.src = "/images/spacer.gif";
		}
	img.style.visibility = "visible";
	}
}


//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// MISC. FUNCTIONS
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


//-------------------------------------------------------------------
//function AddCommunityCategory()
//-------------------------------------------------------------------
function AddCommunityCategory()
{
	alert('hi');
}


//-------------------------------------------------------------------
//function additem(existingSelectName, selectedSelectName)
//-------------------------------------------------------------------
function additem(frmname,existingSelectName, selectedSelectName) {

	eval('var existingSel = document.'+frmname+'.'+existingSelectName+'.selectedIndex;');
	
	eval('var existingTxt = document.'+frmname+'.'+existingSelectName+'.options[existingSel].text;');
	eval('var existingVal = document.'+frmname+'.'+existingSelectName+'.options[existingSel].value;');
	eval('var m2len = document.'+frmname+'.'+selectedSelectName+'.length;');
	
    eval('document.'+frmname+'.'+selectedSelectName+'.options[m2len] = new Option(existingTxt,existingVal);');
}

//-------------------------------------------------------------------
//function addcategoryitem(existingSelectName, selectedSelectName)
//-------------------------------------------------------------------
function addcheckboxitem() 
{	
	
	//add a new category
	if (document.blogitem.newcategory.value != "")
	{	
		//set vars
		eval('var m2len = document.blogitem.chosenpsandcs.length;');	
		var newTxt = document.blogitem.newcategory.value;
		var newVal = 'c_' + document.blogitem.newcategory.value;
				
		//move the data
		eval('document.blogitem.chosenpsandcs.options[m2len] = new Option(newTxt,newVal);');
		
		//reset
		document.blogitem.newcategory.value = "";
		
	}	
	//add and existing category
	else
	{
	
		var str = "";
		var obj, existingTxt, existingVal;			
		
		for (i=0; i<document.blogitem.length;i++) {
		
			//get all the elements
			obj = document.blogitem.elements[i];
			eval('var m2len = document.blogitem.chosenpsandcs.length;');
			valexists = false;
			
			//a checkbox
			if (obj.type == "checkbox")
			{
				//personal category
				if (obj.id.substr(0,3) == "acc")
				{
								
					//move the data
					if (obj.checked)
					{						
						//get vals
						existingTxt = obj.name;
						existingVal = "c" + obj.id.substr(3);
						
						//make sure it doesn't already exist
						for (j=0;j<document.blogitem.chosenpsandcs.length;j++)
						{
							if (existingVal == document.blogitem.chosenpsandcs.options[j].value)
							{
								valexists = true;
								break;
							}							
						}
					
						if (!valexists)
							document.blogitem.chosenpsandcs.options[m2len] = new Option(existingTxt,existingVal);	
					}
				}
				//community category
				else if (obj.id.substr(0,3) == "ccc")
				{	
					//move the data
					if (obj.checked)
					{
						
						//get vals
						existingTxt = obj.name;
						existingVal = "p" + obj.id.substr(3);
						
						//make sure it doesn't already exist
						for (j=0;j<document.blogitem.chosenpsandcs.length;j++)
						{
							if (existingVal == document.blogitem.chosenpsandcs.options[j].value)
							{
								valexists = true;
								break;
							}							
						}
					
						if (!valexists)
							document.blogitem.chosenpsandcs.options[m2len] = new Option(existingTxt,existingVal);	
					}
				}
			}
		} 		
	}		
}
//-------------------------------------------------------------------
//function addcategoryitem(existingSelectName, selectedSelectName)
//-------------------------------------------------------------------
function addcategoryitem(frmname,existingSelectName, selectedSelectName) {
	
	
	//get vals
	eval('var m2len = document.'+frmname+'.'+selectedSelectName+'.length;');	
	
	//add a new category
	if (document.blogitem.newcategory.value != "")
	{
		
		var newTxt = document.blogitem.newcategory.value;
		var newVal = 'c_' + document.blogitem.newcategory.value;
		
		//move the data
		eval('document.'+frmname+'.'+selectedSelectName+'.options[m2len] = new Option(newTxt,newVal);');
		eval('generateCheckBox(cat2, "'+newTxt+'", "c'+newVal+'","");');
		
		document.blogitem.newcategory.value == "";
		
	}	
	//add and existing category
	else
	{
	
		//get vals
		eval('var existingSel = document.'+frmname+'.'+existingSelectName+'.selectedIndex;');	
		eval('var existingTxt = document.'+frmname+'.'+existingSelectName+'.options[existingSel].text;');
		eval('var existingVal = document.'+frmname+'.'+existingSelectName+'.options[existingSel].value;');
				
		//add flag
		existingVal = 'c_' + existingVal;
	
		//move the data
		eval('document.'+frmname+'.'+selectedSelectName+'.options[m2len] = new Option(existingTxt,existingVal);');	
		
	}	
	
}

//-------------------------------------------------------------------
//function addPersonalCategory()
//-------------------------------------------------------------------
function addPersonalCategory()
{
	setItemTabs('div_categories');	
}

//-------------------------------------------------------------------
//function addperspectiveitem(existingSelectName, selectedSelectName)
//-------------------------------------------------------------------
function addperspectiveitem(frmname,existingSelectName, selectedSelectName) {
	
	//get vals
	eval('var existingSel = document.'+frmname+'.'+existingSelectName+'.selectedIndex;');	
	eval('var existingTxt = document.'+frmname+'.'+existingSelectName+'.options[existingSel].text;');
	eval('var existingVal = document.'+frmname+'.'+existingSelectName+'.options[existingSel].value;');
	eval('var m2len = document.'+frmname+'.'+selectedSelectName+'.length;');	
	
	//trim the txt
	if (existingTxt.lastIndexOf('-') != -1)
		existingTxt = existingTxt.substr(existingTxt.lastIndexOf('-')+2);
		
	//add flag
	existingVal = 'p_' + existingVal;
	
	//move the data
    eval('document.'+frmname+'.'+selectedSelectName+'.options[m2len] = new Option(existingTxt,existingVal);');          			
}

//-------------------------------------------------------------------
//function removeitem(selectName) 
//-------------------------------------------------------------------
function removeitem(frmname,selectName) {
	eval('var m2len = document.'+frmname+'.'+selectName+'.length;');
	eval('var selectOptions = document.'+frmname+'.'+selectName+'.options;');

	for (i=(m2len-1); i>=0; i--) {
		if (selectOptions[i].selected == true  && i!=0) {
			selectOptions[i] = null;
		}
	}
}
//-------------------------------------------------------------------
//function removeitem(selectName) 
//-------------------------------------------------------------------
function removeitem(frmname,selectName,hastitle) {
	eval('var m2len = document.'+frmname+'.'+selectName+'.length;');
	eval('var selectOptions = document.'+frmname+'.'+selectName+'.options;');

	for (i=(m2len-1); i>=0; i--) {
		if (hastitle)
		{
			if (selectOptions[i].selected == true  && i!=0) {
				selectOptions[i] = null;
			}
		}
		else
		{
			if (selectOptions[i].selected == true) {
				selectOptions[i] = null;
			}
		}
	}
}


//-------------------------------------------------------------------
//function hideLayer(layerName)
//-------------------------------------------------------------------
function hideLayer(layerName)
{
	if (document.getElementById) 
	{
		var targetElement = document.getElementById(layerName);
		
		targetElement.style.visibility = 'hidden';
		targetElement.style.display='none';
	}
}

//-------------------------------------------------------------------
//function showLayer(layerName)
//-------------------------------------------------------------------
function showLayer(layerName)
{
	if (document.getElementById) 
	{
		var targetElement = document.getElementById(layerName);
		
		targetElement.style.visibility = 'visible';
		targetElement.style.display='block';
	}
}

//-------------------------------------------------------------------
//function layerIsVisible(layerName)
//-------------------------------------------------------------------
function layerIsVisible(layerName)
{
	if (document.getElementById) 
	{
		var targetElement = document.getElementById(layerName);
		
		if (targetElement.style.visibility == 'visible')
			return true;
		else
			return false;
	}
	
	alert('Error in function layerIsVisible(layerName), contact administrator.');
	return false;
}

//-------------------------------------------------------------------
//function GetCurrentTab()
//-------------------------------------------------------------------
function GetCurrentTab()
{
	if (layerIsVisible("div_categories"))
		return "div_categories";
	if (layerIsVisible("div_details"))
		return "div_details";
	if (layerIsVisible("div_comments"))
		return "div_comments";
	if (layerIsVisible("div_images"))
		return "div_images";
	if (layerIsVisible("div_options"))
		return "div_options";
	if (layerIsVisible("div_attachments"))
		return "div_attachments";
	else
		return "";
}

//-------------------------------------------------------------------
//function GetCategoriesAndPerspectives()
//-------------------------------------------------------------------
function GetCategoriesAndPerspectives()
{
	//document.blogitem.categorieslist.value = ""
	//document.blogitem.perspectiveslist.value = ""
	var numcats = document.blogitem.chosenpsandcs.length;
	var p = 0
	var c = 0
	
    for (i=0; i<numcats ; i++)
	{
		
		pncVal = document.blogitem.chosenpsandcs.options[i].value;		
		
		//perspective
		if(pncVal.slice(0,2) == 'p_')
		{
		
			p++;
			
			if (p==1)
				document.blogitem.perspectiveslist.value=pncVal.slice(2);
			else
				document.blogitem.perspectiveslist.value=document.blogitem.perspectiveslist.value+"|"+pncVal.slice(2);
				
		}
		//category
		else if(pncVal.slice(0,2) == 'c_')
		{
		
			c++;
		
			if (c==1)
				document.blogitem.categorieslist.value=pncVal.slice(2);
			else
				document.blogitem.categorieslist.value=document.blogitem.categorieslist.value+"|"+pncVal.slice(2);
		}
		//error!
		else
			alert('Error in GetCategoriesAndPerspectives()');			
			
    }
    
}

//-------------------------------------------------------------------
//function isIE()
//-------------------------------------------------------------------
function isIE()
{
	 if(navigator.appName == "Microsoft Internet Explorer") return true;
	 else return false;
}

//-------------------------------------------------------------------
//function isInt()
//-------------------------------------------------------------------
function isInt(num)
{	
	return (parseInt(num) == num);
}

//-------------------------------------------------------------------
//function setItemTabs(layerName)
//-------------------------------------------------------------------
function setItemTabs(layerName)
{

	//save on every tab!
	document.blogitem.tab.value = layerName;
	SubmitForm();
	return;
		
	//need to save when the current tab is one of these
	if ((GetCurrentTab() == "div_details") || (GetCurrentTab() == "div_categories") || (GetCurrentTab() == "div_options") || (GetCurrentTab() == "div_comments"))
	{
		//submit and redirect to approp. tab
		document.blogitem.tab.value = layerName;
		SubmitForm();
		return;
	}	

	//nothing needs to be saved
	switch (layerName) 
	{ 	
	case "div_categories": 
		showLayer('div_categories');
		hideLayer('div_details');
		hideLayer('div_comments');
		hideLayer('div_images');
		hideLayer('div_options');
		hideLayer('div_attachments');
				
		//change color
		document.getElementById('a_categories').className='menuButtonsOn';
		document.getElementById('a_details').className='menuButtons';
		document.getElementById('a_comments').className='menuButtons';
		document.getElementById('a_images').className='menuButtons';
		document.getElementById('a_options').className='menuButtons';
		document.getElementById('a_attachments').className='menuButtons';
		
		break; 
	case "div_details" : 
		hideLayer('div_categories');
		showLayer('div_details');
		hideLayer('div_comments');
		hideLayer('div_images');
		hideLayer('div_options');
		hideLayer('div_attachments');
				
		//change color
		document.getElementById('a_categories').className='menuButtons';
		document.getElementById('a_details').className='menuButtonsOn';
		document.getElementById('a_comments').className='menuButtons';
		document.getElementById('a_images').className='menuButtons';
		document.getElementById('a_options').className='menuButtons';
		document.getElementById('a_attachments').className='menuButtons';
		break; 
	case "div_comments" : 
		hideLayer('div_categories');
		hideLayer('div_details');
		showLayer('div_comments');
		hideLayer('div_images');
		hideLayer('div_options');
		hideLayer('div_attachments');
		
		//change color
		document.getElementById('a_categories').className='menuButtons';
		document.getElementById('a_details').className='menuButtons';
		document.getElementById('a_comments').className='menuButtonsOn';
		document.getElementById('a_images').className='menuButtons';
		document.getElementById('a_options').className='menuButtons';
		document.getElementById('a_attachments').className='menuButtons';
		break; 
	case "div_images" : 
		hideLayer('div_categories');
		hideLayer('div_details');
		hideLayer('div_comments');
		showLayer('div_images');
		hideLayer('div_options');
		hideLayer('div_attachments');
		
		//change color
		document.getElementById('a_categories').className='menuButtons';
		document.getElementById('a_details').className='menuButtons';
		document.getElementById('a_comments').className='menuButtons';
		document.getElementById('a_images').className='menuButtonsOn';
		document.getElementById('a_options').className='menuButtons';
		document.getElementById('a_attachments').className='menuButtons';
		break; 
	case "div_options" : 
	
		hideLayer('div_categories');
		hideLayer('div_details');
		hideLayer('div_comments');
		hideLayer('div_images');
		showLayer('div_options');
		hideLayer('div_attachments');
		
		//change color
		document.getElementById('a_categories').className='menuButtons';
		document.getElementById('a_details').className='menuButtons';
		document.getElementById('a_comments').className='menuButtons';
		document.getElementById('a_images').className='menuButtons';
		document.getElementById('a_options').className='menuButtonsOn';
		document.getElementById('a_attachments').className='menuButtons';
		
		break; 
		
	case "div_attachments" : 
	
		hideLayer('div_categories');
		hideLayer('div_details');
		hideLayer('div_comments');
		hideLayer('div_images');
		hideLayer('div_options');
		showLayer('div_attachments');
		
		//change color
		document.getElementById('a_categories').className='menuButtons';
		document.getElementById('a_details').className='menuButtons';
		document.getElementById('a_comments').className='menuButtons';
		document.getElementById('a_images').className='menuButtons';
		document.getElementById('a_options').className='menuButtons';
		document.getElementById('a_attachments').className='menuButtonsOn';
		
		break; 
		
	default : 
		break;
	} 
		
}

//-------------------------------------------------------------------
//function Trim(s) 
//-------------------------------------------------------------------
function Trim(s) 
{
  // Remove leading spaces and carriage returns
  
  while ((s.substring(0,1) == ' ') || (s.substring(0,1) == '\n') || (s.substring(0,1) == '\r'))
  {
    s = s.substring(1,s.length);
  }

  // Remove trailing spaces and carriage returns

  while ((s.substring(s.length-1,s.length) == ' ') ||(s.substring(s.length-1,s.length) == '\n') ||(s.substring(s.length-1,s.length) == '\r'))
  {
    s = s.substring(0,s.length-1);
  }
  return s;
}

//-------------------------------------------------------------------
//function WindowOpen(url)
//-------------------------------------------------------------------
function OpenWindow(url, height, width)
{
	eval('var options = "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=no, copyhistory=yes, width='+width+', height='+height+'"');
	var winname = "addedititem"
	var newwin = window.open(url,winname,options)
	newwin.focus();
}

//-------------------------------------------------------------------
//function WindowOpen(url)
//-------------------------------------------------------------------
function OpenWindowScroll(url, height, width)
{
	eval('var options = "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, width='+width+', height='+height+'"');
	var winname = "addedititem"
	var newwin = window.open(url,winname,options)
	newwin.focus();
}


//-------------------------------------------------------------------
//function WindowOpen(url)
//-------------------------------------------------------------------
function OpenWindowScrollByName(url, winname, height, width)
{
	eval('var options = "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, resizable=no, copyhistory=yes, width='+width+', height='+height+'"');
	var newwin = window.open(url,winname,options)
	newwin.focus();
}

//-------------------------------------------------------------------
//function MM_preloadImages()
// standard image preloader
//-------------------------------------------------------------------
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}


//--------------------------------------------------------------------
//This function compares the first date to the last date.
//returns TRUE if the range is valid
//function isDateRangeValid(first_date, last_date)
//--------------------------------------------------------------------
function isDateRangeValid(first_date,last_date)
{
	if (first_date!="" && last_date!="")
	{
		var fd= new Date(first_date);
		var ld= new Date(last_date);

		if (fd<=ld)
			return true;
		else
			return false;
	}
	else
		return false;
}

//--------------------------------------------------------------------
//This function checks the date passed to it.
//returns TRUE if the date is in the format mm/dd/yyyy or mm-dd-yyyy or mm.dd.yyyy
//function isDateFormatProper(strdate)
//--------------------------------------------------------------------
function isDateFormatProper(strdate)
{
	//check if the date entered in the box is valid
	//				mm				/ or -			dd				  / or -	 yyyy
	var re = /^(0[1-9]|1[0-2]|[1-9])(\/|\-)(0[1-9]|[12]\d|3[01]|[1-9])(\/|\-)(19|20)\d\d$/
	//re2 was a regExp to check valid days with months ie/ no feb 30 or April 31st etc...  but it doesn't work.
	//var re2= /^((0[1-9]|1[0-2]|[1-9])(\/|\-)(0[1-9]|[12]\d|[1-9])|(0[13-9]|1[0-2]|[13-9])(\/|\-)30|(0[13578]|1[02]|[13578])(\/|\-)31))(\/|\-)(19|20)\d\d$/i
	return re.test(strdate)
}