function popupSelector(selectpage)
{
	window.open(selectpage,'popuppage',
	'width=550,height=500','toolbar=no,location=no,directories=no,status=no',
	'menubar=yes,scrollbar=yes,resizable=yes,copyhistory=no');
}

function setParentFormField()
{
	if(!document.forms[0].pageid.length) {
                var id_val = document.forms[0].pageid.value;
                var title_val = document.forms[0].pagetitle.value;
        } else {
                for (var i=0; i < document.forms[0].pageid.length; i++) {

                        if (document.forms[0].pageid[i].checked) {
                                var id_val = document.forms[0].pageid[i].value;
                                var title_val = document.forms[0].pagetitle[i].value;
                        }

                }
        }
		
		//alert (id_val+ ' - ' + title_val);
        //var div_section = <?php echo "'".$divsection."'"; ?> ;
        //<?php
        //echo "window.opener.document.myform.".$idfield.".value = id_val;";
		window.opener.document.forms[0].DefaultPageID.value = id_val;
        //echo "window.opener.document.myform.".$titlefield.".value = title_val;";
		window.opener.document.myform.DefaultPageTitle.value = title_val;
        //?>
        //window.opener.document.getElementById(div_section).innerHTML="<a href=\"../page.php?pageid="+id_val+"\">"+title_val+"</a>";
		window.opener.document.getElementById('selecthomepage').innerHTML="<a href=\"../index.php?pageid="+id_val+"\">"+title_val+"</a>";

        window.close();
}

function setMenuFieldValues()
{
	document.forms[0].menutitle.value = document.forms[0].pagetitle.value;
	
}

function fn_xStandard() {
        document.getElementById('editor1').EscapeUnicode = true;
        document.getElementById('xhtml1').value = document.getElementById('editor1').value;
        document.myform.submit();
}


function addInfoBox() 
{		
	var pagetype_val = document.forms[0].pagetype.value;
	var selection_type_val = document.forms[0].infobox_selection_type.value;
	var infobox_title = document.forms[0].infobox_title.value;
	
	for (var i=0; i < document.forms[0].infobox_format.length; i++) {
			
		if (document.forms[0].infobox_format[i].checked) {
			var infobox_format = document.forms[0].infobox_format[i].value;
				}
	}	

	if (selection_type_val == "mostrecent") {
		 
		var selectionnumber_val = document.forms[0].selectionnumber.value;
		var sql_txt_suffix = " ORDER BY pagedate DESC LIMIT " + selectionnumber_val;
		var infobox_details = "<strong>Selection:</strong> Most Recent " + pagetype_val + " articles. <br /> <strong>Number of articles: </strong>" + selectionnumber_val + "<br /> <strong>Format: </strong>" + infobox_format;
		}
			
	if (selection_type_val == "all") {
		var sql_txt_suffix = " ORDER BY pagedate DESC";
		var infobox_details = "<strong>Selection:</strong> All " + pagetype_val + " articles.<br /> <strong>Format: </strong>" + infobox_format;
		} 
	
	if (selection_type_val == "individual") {
				
			// FIRST GET THE VALUE OF THE SELECTED RADIO BUTTON
			if(!document.forms[0].pageid.length) {
				var id_val = document.forms[0].pageid.value;
				var title_val = document.forms[0].pagetitle.value;		
		
				} else {
				
				for (var i=0; i < document.forms[0].pageid.length; i++) {
			
						if (document.forms[0].pageid[i].checked) {
							var id_val = document.forms[0].pageid[i].value;
							var title_val = document.forms[0].pagetitle[i].value;
							}
				}
			}
			// ---------------------------------------------------------------------

		var sql_txt_suffix = " AND pageid = " + id_val + " ORDER BY pagedate DESC"; 		
		var infobox_details = "<strong>Selection:</strong> Individual " + pagetype_val + " article. <i>" + title_val + "</i><br /> <strong>Format: </strong>" + infobox_format;
		}
	
	var sql_txt_prefix = "SELECT pageid, pagetitle, METAdescription FROM pages WHERE pagetype = '" + pagetype_val + "' ";	
				
			window.opener.document.forms[0].infobox.value = sql_txt_prefix + sql_txt_suffix;
			window.opener.document.forms[0].infobox_title.value = infobox_title;
			window.opener.document.forms[0].infobox_format.value = infobox_format;
			
			var infobox_details_compiled = "<p><strong>InfoBox Title: </strong>"+infobox_title+"<br />"+infobox_details+"</p>";
			
			window.opener.document.forms[0].infobox_details.value = infobox_details_compiled;
			
			window.opener.document.getElementById('infobox_display_detail').innerHTML = infobox_details_compiled;
			window.close();			
}


function infoBoxRefreshFields()
{
		var selector_type_val = document.forms[0].infobox_selection_type.value;
		var pagetype_val = document.forms[0].pagetype.value;
		var infobox_title = document.forms[0].infobox_title.value;
		
			for (var i=0; i < document.forms[0].infobox_format.length; i++) {
			
						if (document.forms[0].infobox_format[i].checked) {
							var infobox_format = document.forms[0].infobox_format[i].value;
							}
				}		
				
			// CLEAR EVERYTHING THAT IS TO THE RIGHT OF THE FIRST '?' IN THE URL

				var url_delim_index = location.href.indexOf("?");
				var url_string = location.href;
				var url_stripped = url_string.substring(0 , url_delim_index);

				window.location = url_stripped + "?pagetype=" + pagetype_val + "&infobox_selection_type=" + selector_type_val + "&infobox_title=" + infobox_title + "&infobox_format=" + infobox_format;
}

function removeInfoBox()
{	
	document.forms[0].infobox.value = "";
	document.forms[0].infobox_title.value = "";
	document.forms[0].infobox_details.value = "";
	document.forms[0].infobox_format.value = "";
	document.getElementById('infobox_display_detail').innerHTML = "";	
}

function launchPage(pageid)
{
	var url_delim_index = location.href.indexOf("?");
	var url_string = location.href;
	var url_stripped = url_string.substring(0 , url_delim_index);

	window.location = url_stripped + "?pageid=" + pageid;
}



function launchMe(url_val) 
{
	window.location = url_val;
}

function changeRow(id, newClass)
{
	identity = document.getElementById(id);
	identity.className = newClass;
}