<?php
class RCCWP_WritePostPage
{
	function ApplyCustomWritePanelAssignedCategories($content)
	{
		global $CUSTOM_WRITE_PANEL;
		
		$assignedCategoryIds = RCCWP_CustomWritePanel::GetAssignedCategoryIds($CUSTOM_WRITE_PANEL->id);
		foreach ($assignedCategoryIds as $categoryId)
		{
			$toReplace = 'id="in-category-' . $categoryId . '"';
			$replacement = $toReplace . ' checked="checked"';
			$content = str_replace($toReplace, $replacement, $content);
		}
		
		return $content;
	}
	
	function ApplyCustomWritePanelStandardFields()
	{
		global $CUSTOM_WRITE_PANEL;
		
		$displayCssIds = RCCWP_CustomWritePanel::GetStandardFieldCssIds($CUSTOM_WRITE_PANEL->id);
		$wpCssIds = RCCWP_Application::GetWpStandardFieldCssIds();
		
		$hideCssIds = array_diff($wpCssIds, $displayCssIds);
		
		if (empty($hideCssIds))
			return;
		
		if (in_array('postdiv', $hideCssIds))
		{
			array_push($hideCssIds, 'postdivrich');
		}
		
		array_walk($hideCssIds, create_function('&$item1, $key', '$item1 = "#" . $item1;'));
		$hideCssIdString = implode(', ', $hideCssIds);
		?>
		
		<style type="text/css"><?=$hideCssIdString?> {display: none !important;}</style>
		
		<?php
	}
	
	function HideCustomWritePanelExternalFields()
	{
		global $CUSTOM_WRITE_PANEL;
		
		$hideCssIds = RCCWP_CustomWritePanel::GetHiddenExternalFieldCssIds($CUSTOM_WRITE_PANEL->id);
		if (empty($hideCssIds))
			return;
			
		array_walk($hideCssIds, create_function('&$item1, $key', '$item1 = "#" . $item1;'));
		$hideCssIdString = implode(', ', $hideCssIds);
		?>
		
		<style type="text/css"><?=$hideCssIdString?> {display: none !important;}</style>
		
		<?php	
	}
	
	function CustomFieldCollectionInterface()
	{
		global $CUSTOM_WRITE_PANEL;
		
		if (!isset($CUSTOM_WRITE_PANEL))
			return;
		
		$customFields = array();
		$customFields = RCCWP_CustomWritePanel::GetCustomFields($CUSTOM_WRITE_PANEL->id);
		?>
		<style type="text/css">.form-table td{background-color:#fff;margin-bottom:0;border:none;} .form-table input, .form-table textarea{border-color:#ccc;}</style>
		<div id="freshpagediv" class="postbox">
			<h3><a class="togbox">+</a> Freshpage Panel</h3>
			<div class="inside">
			<table class="form-table" border="0">
		
		<?php
		foreach ($customFields as $field)
		{
			RCCWP_WritePostPage::CustomFieldInterface($field);
		}
		?>
		
			</table>
		</div>
		</div>
		<input type="hidden" name="rc-custom-write-panel-verify-key" id="rc-custom-write-panel-verify-key" value="<?=wp_create_nonce('rc-custom-write-panel')?>" />
		<input type="hidden" name="rc-cwp-custom-write-panel-id" value="<?=$CUSTOM_WRITE_PANEL->id?>" />
		<!-- rc_cwp_submit_buttons -->
		
		<?php
	}
	
	function CustomFieldInterface($customField)
	{
		switch ($customField->type)
		{
			case 'Textbox' :
				RCCWP_WritePostPage::TextboxInterface($customField);
				break;
			case 'Multiline Textbox' :
				RCCWP_WritePostPage::MultilineTextboxInterface($customField);
				break;
			case 'Checkbox' :
				RCCWP_WritePostPage::CheckboxInterface($customField);
				break;
			case 'Checkbox List' :
				RCCWP_WritePostPage::CheckboxListInterface($customField);
				break;
			case 'Radiobutton List' :
				RCCWP_WritePostPage::RadiobuttonListInterface($customField);
				break;
			case 'Dropdown List' :
				RCCWP_WritePostPage::DropdownListInterface($customField);
				break;
			case 'Listbox' :
				RCCWP_WritePostPage::ListboxInterface($customField);
				break;
			case 'File' :
				RCCWP_WritePostPage::FileInterface($customField);
				break;
			case 'Image' :
				RCCWP_WritePostPage::PhotoInterface($customField);
				break;
			case 'Date' :
				RCCWP_WritePostPage::DateInterface($customField);
				break;
			case 'Audio' :
				RCCWP_WritePostPage::AudioInterface($customField);
				break;
			default:
				;
		}
	}
	
	function CheckboxInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$value = RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name);
			$checked = $value == 'true' ? 'checked="checked"' : '';
		}
		?>
		
		<tr>
		<td>
		<label for="<?=$inputName?>">
		<input type="hidden" name="<?=$inputName?>" value="false" />
		<input tabindex="3" class="checkbox" name="<?=$inputName?>" value="true" id="<?=$inputName?>" type="checkbox" <?=$checked?> />
		<?=$customFieldTitle?>
		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</label>
		</td>
		</tr>
		
		<?php
	}
	
	function CheckboxListInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		
		$values = array();
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$values = RCCWP_CustomField::GetCustomFieldValues($_REQUEST['post'], $customField->name);
		}
		else
		{
			$values = $customField->default_value;
		}
		?>
		
		<tr>
		<td>
		<fieldset style="border:1px solid #ddd;padding:10px;">
		<legend style="padding:3px;font-weight:bold;"><?=$customFieldTitle?></legend>
		
		<?php
		foreach ($customField->options as $option) :
			$option = attribute_escape(trim($option));
			$checked = in_array($option, (array)$values) ? 'checked="checked"' : '';
		?>
		
			<label for="" class="selectit">
				<input tabindex="3" id="<?=$option?>" name="<?=$inputName?>[]" value="<?=$option?>" type="checkbox" <?=$checked?>/>
				<?=attribute_escape($option)?>
			</label><br />
		
		<?php
		endforeach;
		?>
			</fieldset>
			<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldName?>" />
			<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}
	
	function DropdownListInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}
		else
		{
			$value = $customField->default_value[0];
		}
		?>
		
		<tr>
		<td>
		<label for="<?=$inputName?>"><?=$customFieldTitle?></label><br />
		<select tabindex="3" name="<?=$inputName?>">
			<option value="">--Select--</option>
		
		<?php
		foreach ($customField->options as $option) :
			$option = attribute_escape(trim($option));
			$selected = $option == $value ? 'selected="selected"' : '';
		?>
		
			<option value="<?=$option?>" <?=$selected?>><?=$option?></option>
		
		<?php
		endforeach;
		?>
		
		</select>	
		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}
	
	function ListboxInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		$inputSize = (int)$customField->properties['size'];
		
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$values = RCCWP_CustomField::GetCustomFieldValues($_REQUEST['post'], $customField->name);
		}
		else
		{
			$values = $customField->default_value;
		}
		?>
		
		<tr>
		<td>
		<label for="<?=$inputName?>"><?=$customFieldTitle?></label><br />
		<select tabindex="3" id="<?=$inputName?>" name="<?=$inputName?>[]" multiple size="<?=$inputSize?>">
		
		<?php
		foreach ($customField->options as $option) :
			$option = attribute_escape(trim($option));
			$selected = in_array($option, (array)$values) ? 'selected="selected"' : '';
		?>
			
			<option value="<?=$option?>" <?=$selected?>><?=$option?></option>
			
		<?php
		endforeach;
		?>
		
		</select>
		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}
	
	function MultilineTextboxInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		$inputHeight = (int)$customField->properties['height'];
		$inputWidth = (int)$customField->properties['width'];
		
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}
		?>
		
		<tr>
		<td>
		<label for="<?=$inputName?>"><?=$customFieldTitle?></label><br />
		<textarea tabindex="3" id="<?=$inputName?>" name="<?=$inputName?>" rows="<?=$inputHeight?>" cols="<?=$inputWidth?>"><?=$value?></textarea>
		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}
	
	function TextboxInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		$inputSize = (int)$customField->properties['size'];
		
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}
		?>
		
		<tr>
		<td>
		<label for="<?=$inputName?>"><?=$customFieldTitle?></label><br />
		<input tabindex="3" id="<?=$inputName?>" name="<?=$inputName?>" value="<?=$value?>" type="text" size="<?=$inputSize?>" />
		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}
	

	function FileInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		$urlName = RC_Format::GetInputName( $customField->name . '_url' );
		$filepath = RC_Format::GetInputName( $customField->name . '_filepath' );

		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}

		?>
		
		<tr>
		<td>
		<label for="<?=$inputName?>"><?=$customFieldTitle?></label>
		<?php if( $value ){ echo '(<a href="' . $value . '" target="_blank">View Current</a>)'; } ?>
		</td>
		</tr>
		<tr>
		<td>
		<input tabindex="3" 
			id="<?=$inputName?>" 
			name="<?=$inputName?>" 
			type="file"
			style="visibility:hidden;height:0px"
			/>
		
		<input tabindex="3" 
			id="<?=$filepath?>" 
			name="<?=$filepath?>" 
			type="hidden" 
			size="46"
			onchange="var postForm=document.getElementById('post');postForm.encoding='multipart/form-data';"
			/>



		<div id='upload_iframe_<?=$filepath?>'>
		<iframe id='upload_internal_iframe_<?=$filepath?>' src='./../wp-content/plugins/fresh-page/RCCWP_upload.php?input_name=<?=$filepath?>&type=0' frameborder='' scrolling='0' style="border-width: 0px; height: 75px;width: 800px;vertical-align:top;"></iframe>
		</div>
		<div id="upload_progress_<?=$filepath?>" style="visibility:hidden;height:0px"></div>





		<input type="hidden" name="rc_cwp_meta_ids[]" 	 value="<?=$customFieldId?>" 	/>
		<input type="hidden" name="rc_cwp_meta_keys[]" 	 value="<?=$inputName?>" 	/>
		<input type="hidden" name="rc_cwp_meta_files[]"	 value="<?=$inputName?>" 	/>
		<input type="hidden" name="<?=$inputName?>_last" value="<?=$value?>" 		/>
		</td>
		</tr>
		
		<?php
	}


	function PhotoInterface($customField)
	{
		$customFieldId 	= '';
		$customFieldName= attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName 		= RC_Format::GetInputName($customField->name);
		$urlName 		= RC_Format::GetInputName( $customField->name . '_url' );
		$filepath 		= RC_Format::GetInputName( $customField->name . '_filepath' );
		$params 		= $customField->properties['params'];
		$noimage 		= "";

		global $countImageThumbID;
		$imageThumbID = "";
		$imageThumbID = "img_thumb_".++$countImageThumbID;

		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
//			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
			$value = RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name);
			
			if(!(strpos($value, 'http') === FALSE))
				$hidValue = str_replace('"', "'", $value);
			$value = stripslashes(trim("\<img src=\'".$value."\' class=\"freshout\" \/\>"));
		}
		else
		{
			$noimage = "<img src='./../wp-content/plugins/fresh-page/images/noimage.jpg' />";
		}
		if($hidValue == '')
		{
			$noimage = "<img src='./../wp-content/plugins/fresh-page/images/noimage.jpg' />";
		}

		include_once('RCCWP_Options.php');
		$useSnipshot = RCCWP_Options::Get('use-snipshot');
	
		?>
		
		<tr>
			<td><label for="<?=$inputName?>"><?=$customFieldTitle?></label> <span id="spanImageSize"></span></td>
		</tr>
		<tr>
			<td>
				<table width="650px" border="0">
					<tr>
						<td rowspan="3" width="25%">
							<?php
								if($value != "")
								{ 
									if(!(strpos($value, '<img src') === FALSE))
									{
										$valueLinkArr = explode("'", $value);
										$valueLink = $valueLinkArr[1];
										//$valueLink = $value;
		
										if(!(strpos($value, '&sw') === FALSE))
										{
											// Calculating Image Width/Height
											$arrSize = explode("=",$value);
											$arrSize1 = explode("&",$arrSize[3]);
											$arrSize2 = explode("&",$arrSize[4]);
		
											$imageWidth = $arrSize1[0];
											$imageHeight = $arrSize2[0];
											// END
		
											$valueArr = explode("&sw", $value);
											$valueArr = explode("'", $valueArr[1]);
											$value = str_replace("&sw".$valueArr[0]."'", "&sw".$valueArr[0]."&w=150&h=120' align='left' id='".$imageThumbID."'", $value);
										}
										else if(!(strpos($value, '&w') === FALSE))
										{
											// Calculating Image Width/Height
											$arrSize = explode("=",$value);
											$arrSize1 = explode("&",$arrSize[3]);
											$arrSize2 = explode("'",$arrSize[4]);
		
											$imageWidth = $arrSize1[0];
											$imageHeight = $arrSize2[0];
											// END
		
											$valueArr = explode("&", $value);
											$valueArr = explode("'", $valueArr[2]);
											$value = str_replace($valueArr[0], "&w=150&h=120' align='left' id='".$imageThumbID."'", $value);
										}
										else
										{
											// Calculating Image Width/Height
											$arrSize = explode("&",$params);
											$arrSize1 = explode("=",$arrSize[1]);
											$arrSize2 = explode("=",$arrSize[2]);
		
											$imageWidth = $arrSize1[1];
											$imageHeight = $arrSize2[1];
											// END
		
											$valueArr = explode("'", $value);
											$value = str_replace($valueArr[1], $valueArr[1]."&w=150' id='".$imageThumbID."' align='left", $value);
										}
										if(!empty($imageWidth))
										{
										?>
										<script language="javascript">
											document.getElementById('spanImageSize').innerHTML = " &nbsp; (<?php echo $imageWidth; echo ' x '; echo $imageHeight; ?>)";
										</script>

										<?php
										}
											echo '<a href="' . $valueLink . '" target="_blank">' . $value .'</a>';
									 }
								 }
								 echo $noimage;
								 $arrSize = explode("phpThumb.php?src=",$valueLink);
								 $arrSizeext = explode("&",$arrSize[1]);
								 if (sizeof($arrSizeext) > 1){
								 	$ext = substr($arrSizeext[0],-4, -1);
									$fileLink = substr($arrSizeext[0],0, -1);
								 }
								 else	{
									$ext = substr($arrSizeext[0],-3);
									$fileLink = $arrSizeext[0];
									}
							 ?>
						</td>
					</tr>
					<tr>
						<td>
							<input tabindex="3" 
								id="<?=$inputName?>" 
								name="<?=$inputName?>" 
								type="file"
								style="visibility:hidden;height:0px"
								/>
							
							<input tabindex="3" 
								id="<?=$filepath?>" 
								name="<?=$filepath?>" 
								type="hidden" 
								size="46"
								onchange="var postForm=document.getElementById('post');postForm.encoding='multipart/form-data';"
								/>

							
					
								<div id='upload_iframe_<?=$filepath?>'>
								<iframe id='upload_internal_iframe_<?=$filepath?>' src='./../wp-content/plugins/fresh-page/RCCWP_upload.php?input_name=<?=$filepath?>&type=1' frameborder='' scrolling='0' style="border-width: 0px; height: 75px;width: 800px;vertical-align:top;"></iframe>
								</div>
								<div id="upload_progress_<?=$filepath?>" style="visibility:hidden;height:0px"></div>
					
							

							
						</td>
					</tr>

				</table>
				<input type="hidden" name="rc_cwp_meta_ids[]" 	 value="<?=$customFieldId?>" 	/>
				<input type="hidden" name="rc_cwp_meta_keys[]" 	 value="<?=$inputName?>" 	/>
				<input type="hidden" name="rc_cwp_meta_files[]"	 value="<?=$inputName?>" 	/>
				<input type="hidden" name="rc_cwp_meta_photos[]" value="<?=$inputName?>" 	/>
				<input type="hidden" name="<?=$inputName?>_last" id="<?=$inputName?>_last" value="<?=$hidValue?>"		/>
				<input type="hidden" name="<?=$inputName?>_params" value="<?=$params?>"		/>
				<script type="text/javascript" src="http://jquery.com/src/latest/"></script>
				<script type="text/javascript" src="<?php bloginfo("url"); ?>/wp-content/plugins/fresh-page/js/greybox.js"></script>
				<link href="<?php bloginfo("url"); ?>/wp-content/plugins/fresh-page/css/greybox.css" rel="stylesheet" type="text/css" media="all" />
				<script type="text/javascript">
				  var GB_ANIMATION = true;
				  $(document).ready(function(){
					$("a.greybox").click(function(){
					  var t = this.title || $(this).text() || this.href;
					  GB_show(t,this.href,470,600);
					  return false;
					});
				  });
	
				  $(document).ready(function(){
					$("a.greybox1").click(function(){
					  var t = this.title || $(this).text() || this.href;
					  var myWidth = 0, myHeight = 0;
					  if( typeof( window.innerWidth ) == 'number' ) {
						//Non-IE
						myWidth = window.innerWidth;
						myHeight = window.innerHeight;
					   } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
						//IE 6+ in 'standards compliant mode'
						myWidth = document.documentElement.clientWidth;
						myHeight = document.documentElement.clientHeight;
					   }

					  GB_show(t,this.href,myHeight- 55,myWidth-55);
					  return false;
					});
				  });
				
				function setCookie(c_name,value,expiredays)
				{
					var exdate=new Date();
					exdate.setDate(exdate.getDate()+expiredays);
					document.cookie=c_name+ "=" +escape(value)+
					((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
				}
				function prepareUpdatePhoto(){	
					document.getElementById('<?=$filepath?>').value = '<?=basename($fileLink)?>';	
					document.getElementById('<?=$filepath?>').onchange();
					document.getElementById("<?=$inputName?>_last").value = '0';
					return true;
				}	
				</script>
				<?php
					if(isset($_REQUEST['post']) && $hidValue != '')
					{
						if ($useSnipshot){ 
							
							
							//echo "<br/> Snipshot selected <br />";
				?>
							<div align="left"> 
								<ul>
									<li style="list-style:none;"><a target="_blank" href="http://services.snipshot.com/?snipshot_input=<?php echo urlencode($arrSize[1])."&snipshot_callback=".urlencode(get_bloginfo("url")."/wp-content/plugins/fresh-page/RCCWP_SnipshotCallback.php");?>&snipshot_output=file&snipshot_callback_agent=user&test=hello&snipshot_output_options=<?php echo urlencode("{\"filetype\":\"$ext\"}")?>" title="Fresh Post" class="greybox1" id="lnkCropper" onclick="prepareUpdatePhoto()"> <strong>Edit</strong> </a></li>
								</ul>
							</div>

				<?php
						}else{
				?>
							<div align=="left"> 
								<ul>
									<li style="list-style:none;"><a href="<?php bloginfo("url");?>/wp-content/plugins/fresh-page/cropper.php?id=<?php echo $valueLink; ?>&url=<?php echo $_SERVER['REQUEST_URI']; ?>&imageThumbId=<?php echo $imageThumbID;?>" title="Fresh Post" class="greybox" id="lnkCropper"> <strong>Crop</strong> </a></li>
								</ul>
							</div>
				<?php 	
						} 
					}
				?>
				<script type="text/javascript">
				function exchangeValues(e, id)
				{
					document.getElementById(document.getElementById('parent_text_'+id.substring(10)).value).value = e;
					document.getElementById(document.getElementById('hidImgValue'+id.substring(10)).value).value = e;
				}
				</script>
				<!-- Used to store name of URL Field -->
				<input type="hidden" name="parent_text_<?php echo $countImageThumbID; ?>" id="parent_text_<?php echo $countImageThumbID; ?>" value="<?php echo $filepath; ?>"/>
				<input type="hidden" name="hidImgValue<?php echo $countImageThumbID; ?>" id="hidImgValue<?php echo $countImageThumbID; ?>" value="<?php echo $inputName; ?>_last" />
			</td>
		</tr>
		<?php
	}
	
	function RadiobuttonListInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		
		if (isset($_REQUEST['post']))
		{
			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}
		else
		{
			$value = $customField->default_value[0];
		}
		?>
		
		<tr>
		<td>
		<fieldset style="border:1px solid #ddd;padding:10px;">
		<legend style="padding:3px;font-weight:bold;"><?=$customFieldTitle?></legend>
		
		<?php
		foreach ($customField->options as $option) :
			$option = attribute_escape(trim($option));
			$checked = $option == $value ? 'checked="checked"' : '';
		?>
			<label for="" class="selectit">
				<input tabindex="3" id="<?=$option?>" name="<?=$inputName?>" value="<?=$option?>" type="radio" <?=$checked?>/>
				<?=$option?>
			</label><br />
		<?php
		endforeach;
		?>
		</fieldset>
		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}

	function DateInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);

		global $wpdb;

		$sQuery = "SELECT * FROM wp_rc_cwp_custom_field_properties WHERE custom_field_id='".$customField->id."'";
		$result = $wpdb->get_results($sQuery);

		$arrDateFormat = explode('"', $result[0]->properties);
		$dateFormat = $arrDateFormat[3];

?>
		<!-- Calendar Control -->
		<link rel="stylesheet" type="text/css" href="<?php bloginfo('url');?>/wp-content/plugins/fresh-page/css/epoch_styles.css" /> <!--Epoch's styles-->
		<script type="text/javascript" src="<?php bloginfo('url');?>/wp-content/plugins/fresh-page/js/epoch_classes.js"></script> <!--Epoch's Code-->
		<!-- Calendar Control -->

		<script type="text/javascript">
			var bas_cal, dp_cal, ms_cal; // declare the calendars as global variables
			window.onload = function () {
				__DATE_FORMAT = "<?php echo $dateFormat; ?>";
				dp_cal  = new Epoch('dp_cal','popup',document.getElementById('date_field'));
			}; 
		</script>	

<?php
		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}
		?>
		
		<tr>
		<td>

	<!--Datepicker container. The <input> text element is required, the button element is optional-->

		<label for="<?=$inputName?>"><?=$customFieldTitle?></label><br />
		<input tabindex="3" id="date_field" name="<?=$inputName?>" value="<?=$value?>" type="text" size="<?=$inputSize?>" />
		<input type="button" value="..." onclick="dp_cal.toggle();" />

		<input type="hidden" name="rc_cwp_meta_ids[]" value="<?=$customFieldId?>" />
		<input type="hidden" name="rc_cwp_meta_keys[]" value="<?=$inputName?>" />
		</td>
		</tr>
		
		<?php
	}

	function AudioInterface($customField)
	{
		$customFieldId = '';
		$customFieldName = attribute_escape($customField->name);
		$customFieldTitle = attribute_escape($customField->description);
		$inputName = RC_Format::GetInputName($customField->name);
		$urlName = RC_Format::GetInputName( $customField->name . '_url' );
		$filepath = RC_Format::GetInputName( $customField->name . '_filepath' );
		

		if (isset($_REQUEST['post']))
		{
			$customFieldId = $customField->id;
			$valueOriginal = RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name);
			if (!empty($valueOriginal))
				$value = stripslashes(trim("\<div style=\'padding-top:3px;\'\>\<object classid=\'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\' codebase='\http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0\' width=\'95%\' height=\'20\' wmode=\'transparent\' \>\<param name=\'movie\' value=\'http://www.freshoutmedia.com/singlemp3player.swf?file=".$valueOriginal."\' wmode=\'transparent\' /\>\<param name=\'quality\' value=\'high\' wmode=\'transparent\' /\>\<embed src=\'http://www.freshoutmedia.com/singlemp3player.swf?file=".$valueOriginal."' width=\'50\%\' height=\'20\' quality=\'high\' pluginspage=\'http://www.macromedia.com/go/getflashplayer\' type=\'application/x-shockwave-flash\' wmode=\'transparent\' \>\</embed\>\</object\>\</div\>"));
//			$value = attribute_escape(RCCWP_CustomField::GetCustomFieldValue($_REQUEST['post'], $customField->name));
		}

		?>
		
		<tr>
		<td><br/>
		<label for="<?=$inputName?>"><?=$customFieldTitle?></label>
		<?php if( $value ){ echo $value; } ?><br/>
		</td>
		</tr>
		<tr>
		<td>
		<input tabindex="3" 
			id="<?=$inputName?>" 
			name="<?=$inputName?>" 
			type="file"
			style="visibility:hidden;height:0px"
			/>
		
		<input tabindex="3" 
			id="<?=$filepath?>" 
			name="<?=$filepath?>" 
			type="hidden" 
			size="46"
			onchange="var postForm=document.getElementById('post');postForm.encoding='multipart/form-data';"
			/>
		
		
		
			<div id='upload_iframe_<?=$filepath?>'>
			<iframe id='upload_internal_iframe_<?=$filepath?>' src='./../wp-content/plugins/fresh-page/RCCWP_upload.php?input_name=<?=$filepath?>&type=2' frameborder='' scrolling='0' style="border-width: 0px; height: 75px;width: 800px;vertical-align:top;"></iframe>
			</div>
			<div id="upload_progress_<?=$filepath?>" style="visibility:hidden;height:0px"></div>
		
	


		<input type="hidden" name="rc_cwp_meta_ids[]" 	 value="<?=$customFieldId?>" 	/>
		<input type="hidden" name="rc_cwp_meta_keys[]" 	 value="<?=$inputName?>" 	/>
		<input type="hidden" name="rc_cwp_meta_files[]"	 value="<?=$inputName?>" 	/>
		<input type="hidden" name="<?=$inputName?>_last" value="<?=$valueOriginal?>" 		/>
		</td>
		</tr>
		
		<?php
	}

	function RelocateWpSubmitButtons($content)
	{
		$pattern = '(<p class="submit".*?\/p>)(.*?)(<!-- rc_cwp_submit_buttons -->)';  // all those Save, Publish, etc buttons
		$replacement = '$2$1';
		$content = preg_replace('/' . $pattern . '/s', $replacement, $content);
		return $content;
	}
}
?>
