
function findBrowser()
{

	var agt=navigator.userAgent.toLowerCase();

	if(agt.indexOf("msie") != -1)
	{
		return "IE";
	}
	else if(agt.indexOf("firefox") != -1)
	{
		return "FF";
	}
	else if(agt.indexOf("opera") != -1)
	{
		return "OP";
	}
	else if(agt.indexOf("safari") != -1)
	{
		return "SAF";
	}
}


function openWin(theURL,winName,features) {
	window.open(theURL,winName,features);
}

function openPhotoBrowser()
{
	openWin('/admin/editors/photo_browser','photoBrowser','scrollbars=yes,width=750px,height=600px');
}

function openPhotoBrowserExperts()
{
	openWin('/admin/experts/photo_browser','photoBrowser','scrollbars=yes,width=750px,height=600px');
}

function openVideoBrowser()
{
	openWin('/admin/editors/video_browser','videoBrowser','scrollbars=yes,width=750px,height=500px');
}

function openVideoBrowserExperts()
{
	openWin('/admin/experts/video_browser','videoBrowser','scrollbars=yes,width=750px,height=500px');
}

function openAddPhoto()
{
	openWin('/admin/editors/photo_editor/action.add','photoBrowser','scrollbars=yes,width=850px,height=600px');
}

function openArticleBrowser()
{
    openWin('/admin/editors/editor_picks/action.articlepop','articleBrowser','scrollbars=yes,width=850px,height=600px');	
}

function openArticleBrowserExperts()
{
    openWin('/admin/experts/expert_picks/action.articlepop','articleBrowser','scrollbars=yes,width=850px,height=500px');	
}

function openListingsBrowser()
{
    openWin('/admin/editors/article_editor/action.addListing','listingBrowser','scrollbars=yes,width=850px,height=500px');	
}

function openNewAuthor()
{
	openWin('/admin/editors/author_editor/action.add','authorBrowser','scrollbars=yes,width=850px,height=200px');
}


function openTagEditor()
{
	openWin('/admin/editors/tag_editor/action.add','tagEditor','scrollbars=yes,width=850px,height=450px');
}


function videoRemove()
{
	var videoObjLength = document.getElementById('video_files').options.length;
	for(i=0;i<videoObjLength;i++)
	{
		if(document.getElementById('video_files').options[i].selected)
		{
			var selOption = document.getElementById('video_files').options[i];
			selOption.parentNode.removeChild(selOption);
		}
	}
}

function addVideo(videoID,videoName)
{
	//check existing option
	var bFalseVideo = 0;

	var existingOpts = document.getElementById('video_files').options.length;

	if(existingOpts > 0 )
	{
		for(i=0;i<existingOpts;i++)
		{
			var optID = document.getElementById('video_files').options[i].value.split("_");
			if(parseInt(optID[1]) == parseInt(videoID))
			{
				bFalseVideo = 0;
				break;
			}
			else
			{
				bFalseVideo = 1;
			}
		}

		if(bFalseVideo == 1)
		{
			var videoOption = new Option(videoName,'video_'+videoID);
			document.getElementById('video_files').options[existingOpts++] = videoOption;
		}
	}
	else
	{
		var videoOption = new Option(videoName,'video_'+videoID);
		document.getElementById('video_files').options[0] = videoOption;
	}
}



function articleRemove()
{
	var articleObjLength = document.getElementById('article_files').options.length;
	for(i=0;i<articleObjLength;i++)
	{
		if(document.getElementById('article_files').options[i].selected)
		{
			var selOption = document.getElementById('article_files').options[i];
			selOption.parentNode.removeChild(selOption);
		}
	}
}


function addArticle(articleID,articleName)
{
	//check existing option
	var bFalseArticle = 0;

	var existingOpts = document.getElementById('article_files').options.length;

	if(existingOpts > 0 )
	{
		for(i=0;i<existingOpts;i++)
		{
			var optID = document.getElementById('article_files').options[i].value.split("_");
			if(parseInt(optID[1]) == parseInt(articleID))
			{
				bFalseArticle = 0;
				break;
			}
			else
			{
				bFalseArticle = 1;
			}
		}

		if(bFalseArticle == 1)
		{
			var articleOption = new Option(articleName,'article_'+articleID);
			document.getElementById('article_files').options[existingOpts++] = articleOption;
		}
	}
	else
	{
		var articleOption = new Option(articleName,'article_'+articleID);
		document.getElementById('article_files').options[0] = articleOption;
	}
}

function addPhoto(x,photoID)
{

	var currentElements = new Array();
	var showElements = new Array();
	var elementsValues = new Array();
	var bFalse = '';

	var nodes = document.getElementById('photo_row').childNodes.length;


	//alert(nodes.length);

	if(nodes > 0)
	{
		for(i=0;i<nodes;i++)
		{
			currentElements.push(document.getElementById('photo_row').childNodes[i].id);
		}

		for(z=0;z<currentElements.length;z++)
		{

			if(parseInt(currentElements[z]) == parseInt(photoID))
			{
				var bFalse = 0;
				break;
			}
			else
			{
				bFalse = 1;
			}
		}
	}
	else
	{
		bFalse = 1;
	}


	if(bFalse == 1)
	{

		var img = document.createElement('img');
		img.setAttribute("src","/images/photos/"+x);
		img.setAttribute("id",photoID);
		img.setAttribute("border","1");
		img.setAttribute("hspace","5");
		img.setAttribute("vspace","5");
		img.onclick = new Function("removePhoto("+photoID+")");

		var hiddenElement = document.createElement('input');
		hiddenElement.type = "hidden";
		hiddenElement.name = "photos[]";
		hiddenElement.value = photoID;

		document.getElementById('photo_row').appendChild(img);

		document.getElementsByTagName('form')[0].appendChild(hiddenElement);

		if((nodes%4) == 0 )
		{
			if(nodes > 4)
			{
				if(document.getElementById('photo_row').lastChild.nodeName == "BR")
				{
					document.getElementById('photo_row').removeChild(document.getElementById('photo_row').lastChild);
				}
				if(document.getElementById('photo_row').firstChild.nodeName == "BR")
				{
					document.getElementById('photo_row').removeChild(document.getElementById('photo_row').firstChild);
				}
			}

			var BR = document.createElement('br');
			document.getElementById('photo_row').appendChild(BR);
		}
	}
}

function removePhoto(photoID)
{
	var element = document.getElementById(photoID);
	element.parentNode.removeChild(element);

	var hiddenLength = document.getElementsByName('photos[]').length;
	

	if(hiddenLength > 0)
	{
		for(x=0;x<hiddenLength;x++)
		{
			if(document.getElementsByName('photos[]')[x].value == photoID)
			{
				document.getElementsByName('photos[]')[x].value = '';
				document.getElementsByName('photos[]')[x].length = hiddenLength-1;
				document.getElementsByName('photos[]')[x].parentNode.removeChild(document.getElementsByName('photos[]')[x]);
				break;
			}
		}
	}
}


function selectAllLists()
{
	var Taglists = document.getElementById('multibox').options.length;
	for(i=0;i<Taglists;i++)
	{
		document.getElementById('multibox').options[i].selected = "selected" ;
	}

	var VideoLists = document.getElementById('video_files').options.length;
	for(z=0;z<VideoLists;z++)
	{
		document.getElementById('video_files').options[z].selected = "selected";
	}
}