<?

/*
FlexCMS (http://www.flexcms.com)
Flexible, Powerful, Affordable.

Contents of this file are protected by the copyright
notice found at http://www.flexcms.com/flex/pages/copyright.html,
and its usage is subject to the terms of the licensing agreement 
available at http://www.flexcms.com/flex/pages/license.html
*/


			
		
		if ($row['BlockContents'] != '') {
		
		$ItemsArray = explode ('^^^^',$row['BlockContents']);
		// the first line is the separator, everything after that is menu items
																
		if ($ItemsArray[0] != '') {
			list ($LinksCount, $LinkPrefix, $LinkSuffix) = explode('%%%',$ItemsArray[0]);
		}
		else {
			/*$LinksCount = '';
			
			if ($LocationCounter == 1 || $LocationCounter == 2) {
				$LinkPrefix = '<br> - ';
			}
			else {
				$LinkPrefix = '&nbsp;&nbsp;&nbsp;&nbsp;- ';
			}*/
		}
							
	
		$LinkTextA = '';
		$LinkURLA = '';
		
														
		// >>>> starts at one, as the first item is the spacer
		for ($g = 1; $g < count($ItemsArray); $g++) {
			
			if ($ItemsArray[$g] != '') {
	
				list ($LinkText,$LinkURL) = explode ('%%%',$ItemsArray[$g]);
								
							
				$LinkTextA[] = $LinkText;
				$LinkURLA[] = $LinkURL;
			
						
			} // end if row != ''
								
		} // end loop
							
											
		$BGColor = '#f1f1f1';
							
		for ($g = 0; $g < count($LinkTextA); $g++) {
		
			if ($g == 0) {
				$JSArray1 = '"'.str_replace('"','&#34;',$LinkTextA[$g]).'"';
				$JSArray2 = '"'.str_replace('"','&#34;',$LinkURLA[$g]).'"';
			}
			else {
				$JSArray1 .= ',"'.str_replace('"','&#34;',$LinkTextA[$g]).'"';
				$JSArray2 .= ',"'.str_replace('"','&#34;',$LinkURLA[$g]).'"';
			}
		
			
			if ($BGColor == '#f1f1f1') {
				$BGColor = '#ffffff';
			}
			else {
				$BGColor = '#f1f1f1';
			} 
			
							
			$ItemsBlock .= '
				<tr bgcolor="'.$BGColor.'">
				<td><font face="'.$FontFace.'" size="2" color="#222222">'.$LinkTextA[$g].'</td>
				<td><font face="'.$FontFace.'" size="2" color="#222222"><a href="'.$LinkURLA[$g].'" target="_blank"><font color="#222222">'.$LinkURLA[$g].'</a></td>
				<td align="center"><font face="'.$FontFace.'" size="2" color="#222222"><a href="javascript:EditItem('.$g.')"><font color="#222222">'.$MsgText[0][155].'</a></td>
				<td align="center"><font face="'.$FontFace.'" size="2" color="#222222"><a href="javascript:DeleteItem('.$g.')"><font color="#222222">'.$MsgText[0][156].'</a></td>
				</tr>';
								
	
		} // end loop
		
		} // end if not empty in the db
		else {
		$ItemsBlock = '<tr><td colspan="8"><font face="'.$FontFace.'" size="2" color="#222222">'.$MsgText[0][195].'</td></tr>';
		}
		
		$PMBStuff = '<input type="hidden" name="BlockContents" value="'.str_replace('"','&#34;',$row['BlockContents']).'"><input type="hidden" name="ReturnToBW" value=""><br><table width="95%" border="0" cellspacing="0">
    <tr>
      <td bgcolor="#c0c0c0"><table width="100%" border="0" cellpadding="6" cellspacing="0" align="center">
    <tr>
      <td bgcolor="#f6f6f6"><font color="#222222"><b>'.$MsgText[0][227].'</b><br><br><table width="100%" border="0" cellpadding="4" cellspacing="0"><tr>
				<td><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][198].'</b></td>
			    <td><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][197].'</b></td>
			    <td align="center"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][155].'</b></td>
				<td align="center"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][156].'</b></td>
				</tr>'.$ItemsBlock.'</table>
				
				<input type="hidden" name="CurrentlyBeingEdited" value="-1">

<div align="center"><br><br>
<table align="center" width="50%" border="0" cellspacing="0">
    <tr>
      <td bgcolor="#d1d1d1">
<table width="100%" bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
	<tr><td colspan="2" bgcolor="#f1f1f1"><font size="2" color="#222222"><b>'.$MsgText[0][200].':</b></font><br></td></tr>
    <tr>
      <td width="25%"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][198].'</b></td>
      <td><input type="text" name="LinkText" size="25"></td>
    </tr>
	<tr>
      <td bgcolor="#f1f1f1"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][197].'</b></td>
      <td bgcolor="#f1f1f1"><input type="text" name="LinkURL" size="25" value="http://www."></td>
    </tr>
	<tr>
	<td colspan="2" bgcolor="#f1f1f1"><div align="center"><input type="button" value="'.$MsgText[0][206].'" onClick="SaveChanges();">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="button" value="'.$MsgText[0][207].'" onClick="SaveAsNew();"></div></td>	
	</tr>
</table>
</td>
    </tr>
</table></div>	
				
	<div align="center"><br><br>
<table align="center" width="50%" border="0" cellspacing="0">
    <tr>
      <td bgcolor="#d1d1d1">
<table bgcolor="#ffffff" border="0" cellpadding="3" cellspacing="0">
	<tr><td colspan="2" bgcolor="#f1f1f1"><font size="2" color="#222222"><b>'.$MsgText[0][208].':</b></font><br></td></tr>
    <tr>
      <td width="25%"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][228].'</b></td>
      <td><input type="text" name="LinksCount" size="5" value="'.$LinksCount.'"><br><font size="2" color="#222222">'.$MsgText[0][229].'</td>
    </tr>
	<tr>
      <td bgcolor="#f1f1f1"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][230].'</b></td>
      <td bgcolor="#f1f1f1"><input type="text" name="LinkPrefix" size="15" value="'.$LinkPrefix.'"><br><font size="2" color="#222222">'.$MsgText[0][231].'</font></td>
    </tr>
	<tr>
      <td bgcolor="#ffffff"><font face="'.$FontFace.'" size="2" color="#222222"><b>'.$MsgText[0][232].'</b></td>
      <td bgcolor="#ffffff"><input type="text" name="LinkSuffix" size="15" value="'.$LinkSuffix.'"><br><font size="2" color="#222222">'.$MsgText[0][233].'</font></td>
    </tr>
		<tr>
	<td colspan="2" bgcolor="#f1f1f1"><div align="center"><input type="button" value="'.$MsgText[0][123].'" onClick="SaveSettings();"></div></td>	
	</tr>
</table>
</td>
    </tr>
</table></div>
	
	</td>
    </tr>
</table>
</td>
    </tr>
</table><br><script language="JavaScript">

var LinkText = new Array('.$JSArray1.');
var LinkURL = new Array('.$JSArray2.');

var LineOne = "'.$ItemsArray[0].'";
var LinksCount = "'.$LinksCount.'";
var LinkPrefix = "'.$LinkPrefix.'";
var LinkSuffix = "'.$LinkSuffix.'";


function EditItem(ItemNumber) {

	ArrayPosition = ItemNumber;

	document.forms["PostForm"].elements["LinkText"].value = LinkText[ArrayPosition];
	document.forms["PostForm"].elements["LinkURL"].value = LinkURL[ArrayPosition];
	
	document.forms["PostForm"].elements["CurrentlyBeingEdited"].value = ArrayPosition;

}
function SaveChanges() {

	ArrayPosition = document.forms["PostForm"].elements["CurrentlyBeingEdited"].value;
	
	if (ArrayPosition >= 0) {
	
	if (document.forms["PostForm"].elements["LinkText"].value != LinkText[ArrayPosition] || document.forms["PostForm"].elements["LinkURL"].value != LinkURL[ArrayPosition]) {


		LinkText[ArrayPosition] = document.forms["PostForm"].elements["LinkText"].value;
		LinkURL[ArrayPosition] = document.forms["PostForm"].elements["LinkURL"].value;
		
		
		var FinalBlockContents = LineOne;
		
		for (i = 0; i < LinkText.length; ++i) {
			
			if (LinkText[i] != \'\' && LinkText[i] != \'undefined\') {
			
				FinalBlockContents = FinalBlockContents + \'^^^^\' + LinkText[i] + \'%%%\' + LinkURL[i];
			
			}
		
		}
		
		document.forms["PostForm"].elements["BlockContents"].value = FinalBlockContents;
		document.forms["PostForm"].elements["ReturnToBW"].value = "y";
		document.forms["PostForm"].submit();

	}
	else {
		
		document.forms["PostForm"].elements["LinkText"].value = "";
		document.forms["PostForm"].elements["LinkURL"].value = "http://www.";
	
		document.forms["PostForm"].elements["CurrentlyBeingEdited"].value = "-1";
	
	}
	} // end if editing
	else {
	
		if (document.forms["PostForm"].elements["LinkText"].value == "") {
	
		alert("'.$MsgText[0][234].'");
	
	}
	else {
		ArrayPosition = LinkText.length;
	
		LinkText[ArrayPosition] = document.forms["PostForm"].elements["LinkText"].value;
		LinkURL[ArrayPosition] = document.forms["PostForm"].elements["LinkURL"].value;
		
		
		var FinalBlockContents = LineOne;
		
		for (i = 0; i < LinkText.length; ++i) {
				
			if (LinkText[i] != \'\' && LinkText[i] != \'undefined\') {
				
				FinalBlockContents = FinalBlockContents + \'^^^^\' + LinkText[i] + \'%%%\' + LinkURL[i];
			
			}
		
		}
			
		document.forms["PostForm"].elements["BlockContents"].value = FinalBlockContents;
		document.forms["PostForm"].elements["ReturnToBW"].value = "y";
		document.forms["PostForm"].submit();
	}
	
	}

}
function SaveAsNew() {

	ArrayPosition = LinkText.length;
	
	if (document.forms["PostForm"].elements["LinkText"].value == "") {
	
		alert("'.$MsgText[0][234].'");
	
	}
	else {
	
		LinkText[ArrayPosition] = document.forms["PostForm"].elements["LinkText"].value;
		LinkURL[ArrayPosition] = document.forms["PostForm"].elements["LinkURL"].value;
		
		
		var FinalBlockContents = LineOne;
		
		for (i = 0; i < LinkText.length; ++i) {
				
			if (LinkText[i] != \'\' && LinkText[i] != \'undefined\') {
				
				FinalBlockContents = FinalBlockContents + \'^^^^\' + LinkText[i] + \'%%%\' + LinkURL[i];
			
			}
		
		}
			
		document.forms["PostForm"].elements["BlockContents"].value = FinalBlockContents;
		document.forms["PostForm"].elements["ReturnToBW"].value = "y";
		document.forms["PostForm"].submit();
	}

}
function DeleteItem(ItemNumber) {

	var ArrayPosition = ItemNumber;

	var ConfirmDelete = confirm("'.$MsgText[0][216].'");
	
	if (ConfirmDelete == true) {
		
		LinkText[ArrayPosition] = "";
		LinkURL[ArrayPosition] = "";
		
		
		var FinalBlockContents = LineOne;
	
		for (i = 0; i < LinkText.length; ++i) {
			
			if (LinkText[i] != \'\' && LinkText[i] != \'undefined\') {
			
				FinalBlockContents = FinalBlockContents + \'^^^^\' + LinkText[i] + \'%%%\' + LinkURL[i];
			
			}
		
		}
			
		document.forms["PostForm"].elements["BlockContents"].value = FinalBlockContents;
		document.forms["PostForm"].elements["ReturnToBW"].value = "y";
		document.forms["PostForm"].submit();
	
	}

}
function SaveSettings() {

	var FinalBlockContents = document.forms["PostForm"].elements["LinksCount"].value + \'%%%\' +  document.forms["PostForm"].elements["LinkPrefix"].value + \'%%%\' +  document.forms["PostForm"].elements["LinkSuffix"].value;
		
	for (i = 0; i < LinkText.length; ++i) {
				
		if (LinkText[i] != \'\' && LinkText[i] != \'undefined\') {
				
			FinalBlockContents = FinalBlockContents + \'^^^^\' + LinkText[i] + \'%%%\' + LinkURL[i];
			
		}
		
	}
			
	document.forms["PostForm"].elements["BlockContents"].value = FinalBlockContents;
	document.forms["PostForm"].elements["ReturnToBW"].value = "y";
	document.forms["PostForm"].submit();


}

</script>';


?>
