<?php
if (empty($rowxxx[CATLIMIT]))
        $rowxxx[CATLIMIT] = 3;
?><script src="jumpbox.js"></script>

<script language="JavaScript">

function ChangeFieldName (val) {
        //--------------------------------------
        contents = document.FieldName.CATEGORY.value;
        contentsJB = document.FieldName.JBPOT.value;
        contentsCC = document.FieldName.CATC.value;
        //--------------------------------------
        var myString = contentsJB;
        var mySplitResult = myString.split("onClick");
        for(i = 0; i < mySplitResult.length; i++){ }
        //--------------------------------------

        if (i<="<?php echo $rowxxx[CATLIMIT]; ?>") {
                mySplitResult = val.split("|");

                if (mySplitResult[0]!="--") {

                        document.FieldName.CATC.value=i;

                        document.FieldName.CATEGORY.value=contents+mySplitResult[0];

                        document.FieldName.JBPOT.value=contentsJB+"<div id="+mySplitResult[0]+">"+mySplitResult[1]+
                        " <input type=\"button\" value=\"Delete\" onClick=\"DeleteThis('"+mySplitResult[0]+"|"+mySplitResult[1]+"')\"><br></div> ";

                        document.getElementById('elmID').innerHTML=contentsJB+"<div id="+mySplitResult[0]+">"+mySplitResult[1]+
                        " <input type=\"button\" value=\"Delete\" onClick=\"DeleteThis('"+mySplitResult[0]+"|"+mySplitResult[1]+"')\"><br></div> ";
                }
        }
        //--------------------------------------
}

function DeleteThis(s) {
        //--------------------------------------
        mySplitResult = s.split("|");
        //--------------------------------------

        var cat = document.getElementById('CATEGORY');
        cat.value = cat.value.replace(mySplitResult[0],'');

        //--------------------------------------

        var oNodeToRemove = document.getElementById("CATEGORY");
        oNodeToRemove

        //--------------------------------------

        var cat = document.getElementById('jbpot');
        cat.value = cat.value.replace('<div id='+mySplitResult[0]+'>'+mySplitResult[1]+' <input type="button" value="Delete" onClick="DeleteThis(\''+mySplitResult[0]+'|'+mySplitResult[1]+'\')"><br></div> ','');

        var oNodeToRemove = document.getElementById("jbpot");
        oNodeToRemove

        //--------------------------------------

        var ele = document.getElementById(mySplitResult[0]);
        ele.parentNode.removeChild(ele);

//--------------------------------------
}
</script>

<?php if ($_GET[d] == 1) {

          $sql            = "UPDATE PAGES SET
                IMAGENAME       = '$nil'
                WHERE ID        = '$_GET[id]'";
                $query = mysql_query($sql);

} ?>

<script language="JavaScript" type="text/javascript">
<!-- Begin
function verify() {
        var themessage = "The following fields can not be blank : ";
        if (document.FieldName.CATEGORY.value=="") {
                themessage = themessage + " | Category";
        } if (document.FieldName.HEADER.value=="") {
                themessage = themessage + " | Title";
        } if (document.FieldName.CAPTION.value=="") {
                themessage = themessage + " | Caption";
        }

if (themessage == "The following fields can not be blank : ") {
                document.FieldName.submit();
        } else {
                alert(themessage);
                return false;
        }
        }
//  End -->
</script>

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script src="sample.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">
function removeSpaces(string) {
 return string.split(' ').join('');
}
</script>

<?php
$login_form = "loginform.php";
require "authorize.php";
 
if ($login == fail) {} else { 

$SQL         = "SELECT * from PAGES WHERE ID = '$_GET[id]'";
$result = @mysql_query( $SQL ); 
$row         = @mysql_fetch_array( $result );
//-------------------------------------------

if (empty($_GET[qt])) 
        $qt = insert; else $qt = $_GET[qt];

if ($_GET[qt] == insert) 
        $id = $nil;
//-----------------


?>
<span class="font1"><b>Submit an Article</b></span><br>
<span class="idevfont4"><b>Create your article below.</b></span><br>
<br>
<form action="index.php?page=query&amp;add_listing=1" method="post" enctype="multipart/form-data" name="FieldName" id="form">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td class="greenbox"> 
<input type="hidden" name="controller" value="PAGES~<?php echo $qt; ?>~account_listings~<?php echo $_GET[id]; ?>" />
<input type="hidden" name="OWNER" value="<?PHP ECHO $_SESSION[username]; ?>" />
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="td4" colspan="2"> <b> Page Content</b></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="td4"  width="50%">Article Title</td>
<td class="td4"  width="50%"> 
<input type="text" name="HEADER" size="40"  class="textarea100" value="<?php echo $row[HEADER]; ?>">
</td>
</tr>
<tr> 
<td class="td4"  width="50%"> Article Caption</td>
<td class="td4"  width="50%"> 
<input type="text" name="CAPTION" size="40"  class="textarea100" value="<?php echo $row[CAPTION]; ?>">
</td>
</tr>
<?php if ($row[ID] != $nil) { ?>
<?php IF ($row[IMAGENAME] != $NIL) { 

 $filename = "$svr_rootscript/product_images/$row[IMAGENAME].jpg";
        if (file_exists($filename)) $ext = jpg;

 $filename = "$svr_rootscript/product_images/$row[IMAGENAME].png";
        if (file_exists($filename)) $ext = png;
?>
<?php } ?>
<?PHP } ?>
<tr> 
<link href="sample.css" rel="stylesheet" type="text/css" />
<td class="td4" colspan="2"> 
<textarea class="ckeditor" cols="80" id="editor1" name="PAGECONTENT"><?php echo $row[PAGECONTENT]; ?></textarea>
</td>
</tr>
</table>
<br>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="td4" colspan="2"> <b> Page Settings 
<input type="hidden" name="SHOWADS" value="1">
</b></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="td4"  width="50%"> 
<div id="Layer1" style="position:absolute; width:200px; height:115px; z-index:1; visibility: hidden"> 
<textarea id="jbpot" name="JBPOT" cols="40" rows="10"><?php echo html_entity_decode($row[JBPOT]); ?></textarea>
<input type="text" name="CATEGORY" id="CATEGORY" value="<?php echo $row[CATEGORY]; ?>">
<input type="text" id = "CATC" name="CATC" value="<?php echo $row[CATC]; ?>">
</div>
<table cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="font3"> 
<div align=right id="elmID"> 
<?php if ($_GET[qt] == update) echo html_entity_decode($row[JBPOT]);  else { ?>
Category(s) (Max: 
<?php echo $rowxxx[CATLIMIT]; ?>
) 
<?PHP } ?>
</div>
</td>
</tr>
</table>
</td>
<td class="td4"  width="50%"> 
<table width="100%" cellspacing="0" cellpadding="0">
<tr> 
<td> 
<div id="txtHint"> 
<select name="JUMPBOX" size="8" onChange="showCategory(this.value)">
<option selected value = "<?php echo $row[CATEGORY]; ?>"> 
<?PHP ECHO $rowlookup[TITLE]; ?>
</option>
<option>- - - - - - - - - - - - - - - - - - - -</option>
<?PHP $SQLct = "SELECT * from CATEGORIES WHERE CATEGORY = '$nil' ORDER BY TITLE ASC"; $resultct = @mysql_query( $SQLct ); while( $rowct = @mysql_fetch_array( $resultct ) ) { ?>
<?PHP
        $sql_peer = "SELECT count(*) FROM CATEGORIES WHERE CATEGORY = '$rowct[ID]'";
        $res_peer = mysql_query($sql_peer);
        $row_peer = mysql_fetch_row($res_peer);
        ?>
<option <?php if (!empty($row_peer[0])) { ?>style="font-weight: bold"<?PHP } ?> value="<?php echo $rowct[ID]; ?>"> 
<?php echo $rowct[TITLE]; ?>
</option>
<?PHP } ?>
</select>
<br>
<input disabled type="button" value="Add Category" onMouseDown="ChangeFieldName('-<?PHP echo $q; ?>-|<?php echo $row_disp[TITLE]; ?>')" onClick="showCategory('')">
</div>
</td>
</tr>
</table>
</td>
</tr>
<tr> 
<td class="td4"  width="50%">Header Photo (JPG/PNG format)</td>
<td class="td4"  width="50%"> 
<input type="hidden" name="IMAGENAME" value="<?php if ($row[IMAGENAME] == $nil || $_GET['clone'] == 1) echo $imagename; else echo $row[IMAGENAME]; ?>">
<input type="file" name="1" size="40" class="textarea100">
</td>
</tr>
<?php if ($row[ID] != $nil) { ?>
<?php IF ($row[IMAGENAME] != $NIL) { 

 $filename = "$svr_rootscript/product_images/$row[IMAGENAME].jpg";
        if (file_exists($filename)) $ext = jpg;

 $filename = "$svr_rootscript/product_images/$row[IMAGENAME].png";
        if (file_exists($filename)) $ext = png;
?>
<tr> 
<td class="td4"  width="50%">Current Image</td>
<td class="td4"  width="50%"> 
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr> 
<td><img src="../product_images/<?php echo $row[IMAGENAME]; ?>.<?php echo $ext; ?>" width="100"></td>
<td width="100%">&nbsp;</td>
<td><a href="?page=addpage&id=<?php echo $_GET[id]; ?>&qt=<?php echo $_GET[qt]; ?>&d=1"><img src="../images/delete-icon.png" width="48" height="48" border="0"></a></td>
</tr>
</table>
</td>
</tr>
<?php } ?>
<?PHP } ?>
<tr> 
<td class="td4"  width="50%"> Header Photo Width (Default 128px)</td>
<td class="td4"  width="50%"> 
<input type="text" name="WIDTH" size="40"  class="textarea100" value="<?php echo $row[WIDTH]; ?>">
</td>
</tr>

</table>
<br>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="td4" colspan="2"> <b> Search Engine Optimization</b></td>
</tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tr> 
<td class="td4"  width="50%"> Meta Keywords</td>
<td class="td4"  width="50%"> 
<input type="text" name="METAKEY" size="40" class="textarea100" value="<?php echo $row[METAKEY]; ?>">
</td>
</tr>
<tr> 
<td class="td4"  width="50%"> Meta Description</td>
<td class="td4"  width="50%"> 
<input type="text" name="METADESC" size="40" class="textarea100" value="<?php echo $row[METADESC]; ?>">
</td>
</tr>
<tr> 
<td class="td4"> 
<?PHP if ($rowxxx[STATUS] == '') $rowxxx[STATUS] = Pending; ?>
<input type="hidden" name="STATUS" value="<?PHP if ($row[STATUS] == '') { ?><?php echo $rowxxx[STATUS]; ?><?PHP } else { echo $row[STATUS]; } ?>">
<input type="hidden" name="hiddenField">
</td>
<td class="td4"> 
<input type="button" value="Submit" onClick="verify();" />
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
<?PHP } ?>
