<?php
/*
osCommerce, Open Source E-Commerce Solutions 
http://www.oscommerce.com 

Copyright (c) 2003 osCommerce 

osCommRes, Services Oline 
http://www.oscommres.com 
Copyright (c) 2005 osCommRes 

Freeway eCommerce 
http://www.zac-ware.com/freeway 
Copyright (c) 2007 ZacWare

Released under the GNU General Public License
*/
// Set flag that this is a parent file
	define( '_FEXEC', 1 );
  require('includes/application_top.php');
  tep_get_last_access_file();
  require('includes/classes/split_page_results_event.php');  
  $action = (isset($HTTP_GET_VARS['action']) ? $HTTP_GET_VARS['action'] : '');  
  $rID= (isset($HTTP_GET_VARS['rID']) ? $HTTP_GET_VARS['rID'] : $HTTP_POST_VARS['reviews_id']);
  $page = (isset($HTTP_GET_VARS['page']) ? $HTTP_GET_VARS['page'] : 1);
  $server_date = getServerDate(true);
  if($action!=""){
  	if($action=='get_details')
  		get_content();
  	else if($action=='page_navigation'){ 
		echo 'page_navigation';
		print_record();	 	
	}else if($action=='edit'){
	 if(!$HTTP_GET_VARS['rID']) echo "new";
	 else if($HTTP_GET_VARS['rID']) echo "edit";			 
	 $reviews[] = array(); 
	 $products[] = array();
	 $product_array=array();
	 $reviews_query = tep_db_query("select r.reviews_id, r.products_id, r.customers_name, r.date_added, r.last_modified, r.reviews_read, rd.reviews_text, r.reviews_rating, r.admin_review from " . TABLE_REVIEWS . " r, " . TABLE_REVIEWS_DESCRIPTION . " rd where r.reviews_id = '" . (int)$rID . "' and r.reviews_id = rd.reviews_id");	      
     if(tep_db_num_rows($reviews_query)>0){
     	$reviews = tep_db_fetch_array($reviews_query);
     	$products_query = tep_db_query("select products_image_1,products_title_1 from " . TABLE_PRODUCTS . " where products_id = '" . (int)$reviews['products_id'] . "'");
     	$products = tep_db_fetch_array($products_query);	   	 
	 	if(is_array($reviews) && is_array($products)) $rInfo_array = array_merge($reviews, $products);
	 	else if(is_array($reviews)) $rInfo_array=$reviews;		    		  	 	
	 	else if(is_array($products)) $rInfo_array=$products;
     }
     if(is_array($rInfo_array))	$rInfo = new objectInfo($rInfo_array); 
 	 $today_date = getServerDate();
 	 $products_name_query = tep_db_query("select products_id, products_name from " . TABLE_PRODUCTS_DESCRIPTION . " where language_id = '" . (int)$languages_id . "'");
       while($products_name = tep_db_fetch_array($products_name_query)){
	   	if($products_name["products_name"]) $product_array[] = array('id' => $products_name["products_id"], 'text' => $products_name["products_name"]);
	 }
	?>
	<table border="0" width="100%" cellspacing="3" cellpadding="3" class="openContent">
      <?php if(!$HTTP_GET_VARS['rID']) { ?><tr style="cursor:pointer;cursor:hand;" class="openContent_top"><td width="80%" onClick="javascript:do_product_reviews('page_navigation',0);">&nbsp;</td><td width='5%' align='right' id='img_save'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href="javascript:do_product_reviews('page_navigation',0);"><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td></tr><?php } ?>
      <tr>
        <td><table border="0" width="100%" cellspacing="3" cellpadding="3">
 		<?php $disable=''; $display=''; if($HTTP_SESSION_VARS['actions'] != 'new_review' && $error_tag != ERROR_ADMIN_REVIEW) {  if($rInfo->admin_review == 'Y' || $rInfo->admin_review == 1){ $disable='readonly'; $display='display:none'; } else echo tep_draw_hidden_field('admin_review_flag','not_set'); } ?>
          <tr> <?php $_array=array('d','m','Y');  $replace_array=array('DD','MM','YYYY'); 	$date_format=str_replace($_array,$replace_array,EVENTS_DATE_FORMAT);?>
            <td class="main" valign="top"><b><?php echo ENTRY_PRODUCT; ?></b> <?php echo tep_draw_pull_down_menu('products_id',$product_array,$rInfo->products_id) ?><br><br><b><?php echo ENTRY_AUTHOR; ?></b> <?php echo '&nbsp;&nbsp;'.tep_draw_input_field('author_name',$rInfo->customers_name,$disable.' maxlength="64" ');   ?><br><br><b><?php echo ENTRY_DATE; ?></b> 
			<?php echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.tep_draw_input_field("review_date",isset($rInfo->date_added)?format_date($rInfo->date_added):format_date($today_date),$disable); ?> 
			<?php echo '<span id="calendar_id" style=\'' . $display . '\'>'; ?>
			<a href="javascript:show_calendar('review.review_date',null,null,'<?php echo $date_format;?>');" onMouseOver="window.status='Date Picker';return true;" onMouseOut="window.status='';return true;"><img border="none" src="images/icon_calendar.gif"/ ></a> </span> </td> 
            <td class="main" align="right" valign="top"><?php echo tep_product_small_image($rInfo->products_image_1, $rInfo->products_title_1,'hspace="5" vspace="5"'); ?></td>
          </tr>
        </table></td>
      </tr>
      <tr>
        <td>
		<table witdh="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td class="main" valign="top"><b><?php echo '<br>'.ENTRY_REVIEW; ?></b><br><br><?php echo tep_draw_textarea_field('reviews_text', 'soft', '80', '24', $rInfo->reviews_text,'id="reviews_text"'); ?></td>
          </tr>		           
		  <?php  
		  if($rInfo->admin_review == 'Y' || $rInfo->admin_review == 1 )
		  		$default_admin_review = true;						  
		  else
		  		$default_admin_review = false;
		  ?>
		  <tr> 
		  	<td class="main" valign="top"><br><b><?php echo ENTRY_ADMIN_REVIEW_CHECK; ?></b><?php echo tep_draw_checkbox_field('admin_review','',$default_admin_review,'',' onClick="javascript:void check_review(this);"'); ?></td>
		  </tr>		  
		   <tr>
        	<td class="main"><br><b><?php echo ENTRY_RATING; ?></b>&nbsp;<?php echo TEXT_BAD; ?>&nbsp;<?php for ($i=1; $i<=5; $i++) echo tep_draw_radio_field('reviews_rating',$i ,(($rInfo->reviews_rating==$i)?true:false) , $rInfo->reviews_rating) . '&nbsp;'; echo TEXT_GOOD; ?></td>
      	  </tr>
        </table></td>
      </tr>
      <tr>
        <td><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td>
      </tr>
     <tr align="right"><td width='80%' align='right'><input type='image' src='images/template/img_savel.gif' alt='save' title='save' border='0'>&nbsp;&nbsp;<a href="javascript:do_product_reviews(<?php echo (($HTTP_GET_VARS['rID'])?'\'get_details\','.$HTTP_GET_VARS['rID']:'\'page_navigation\',0');?>);"><img src='images/template/img_closel.gif' alt='close' title='close' border='0'></a>&nbsp;&nbsp;</td></tr>            
    </table>
<?php  
	}else if($action=='update_review'){       
    $error_tag = '';
	$error = false; 
	if(!$HTTP_GET_VARS['rID'] && $HTTP_POST_VARS['admin_review'] == 1){  
		$action_query=tep_db_query("select reviews_id from " . TABLE_REVIEWS . " where  products_id = '" . (int)$products_id . "' and admin_review = \"Y\"");
		if(tep_db_num_rows($action_query)>0){
			$action = 'edit';
			$error_tag = ERROR_ADMIN_REVIEW;
			$error = true;
		} 
	}elseif($HTTP_POST_VARS['admin_review_flag'] == 'not_set'){
		$actions_query = tep_db_query("select admin_review from " . TABLE_REVIEWS . " where products_id = '" . (int)$products_id . "' and admin_review = \"Y\"");
		if(tep_db_num_rows($actions_query)>0){
			if($HTTP_POST_VARS['admin_review'] == 1){
			$action="edit";
			$error_tag = ERROR_ADMIN_REVIEW;
			$error = true;
		}
	}	
	}elseif(isset($products_id)  &&  $HTTP_POST_VARS['admin_review']==1 && !$HTTP_GET_VARS['rID']){ 
		$admin_review = isset($HTTP_POST_VARS['admin_review']) ? 'Y' : 'N';
		$action_query=tep_db_query("select reviews_id,admin_review from " . TABLE_REVIEWS . " where admin_review = '" . $admin_review . "' and products_id = '" . (int)$products_id . "' and reviews_id='" . (int)$rID . "'");
		if(tep_db_num_rows($action_query)<=0){		
			$action = 'edit';
			$display_query = tep_db_query("select admin_review  from " . TABLE_REVIEWS . " where reviews_id = '" . (int)$rID . "'");
			$display_array = tep_db_fetch_array($display_query);
			$error = true;
			if($display_array["admin_review"] == 'N')
				$error_tag = ERROR_ADMIN_REVIEW;
			else	
		    	$error_tag =	ERROR_REVIEW_TAG;
	} 
   }
   if($error_tag!="") echo 'error'.$error_tag;
   else {    
        $reviews_text = tep_db_prepare_input($HTTP_POST_VARS['reviews_text']);
		$products_id = isset($HTTP_POST_VARS['products_id']) ? $HTTP_POST_VARS['products_id'] : '';
		$review_date = ($HTTP_POST_VARS['review_date']) ? tep_convert_date_raw($HTTP_POST_VARS['review_date']) : $server_date;
		$author = ($HTTP_POST_VARS['author_name']) ? $HTTP_POST_VARS['author_name'] : '';
		$admin_review = ($HTTP_POST_VARS['admin_review']==1) ? 'Y' : 'N';
		$reviews_rating = ($HTTP_POST_VARS['reviews_rating']) ? $HTTP_POST_VARS['reviews_rating'] : '';
		$customers_id = 0;
		
		if($reviews_rating=='') $reviews_rating='0';
		
				
		if(!$rID){ 
		  $sql_data_array = array('products_id' => $products_id,
		  						  'customers_id' => $customers_id,
								  'customers_name' => $author,
								  'date_added' => $review_date,
								  'last_modified' => $server_date,
								  'reviews_read' => '0',
								  'reviews_rating' => $reviews_rating,
								  'admin_review' => $admin_review);
		    tep_db_perform(TABLE_REVIEWS,$sql_data_array);
		    $rID=tep_db_insert_id();
		  	$sql_data_array = array('reviews_id' => $rID,
									'languages_id' => '1',
									'reviews_text' => $reviews_text);
		  echo 'new_review'.$rID.'^'.tep_get_products_name($products_id,$languages_id).'^'.$author.'^'.format_date($review_date);		   									
		  tep_db_perform(TABLE_REVIEWS_DESCRIPTION,$sql_data_array);
		  tep_set_session_value('actions','');		  
		}else {		  			
        	tep_db_query("update " . TABLE_REVIEWS . " set products_id = '" . $products_id . "', customers_name = '" . $author  . "', date_added = '" . $review_date  . "', admin_review = '" . $admin_review . "', reviews_rating = '" . (int)$reviews_rating . "', last_modified ='". $server_date ."' where reviews_id = '" . (int)$rID . "'");
       		tep_db_query("update " . TABLE_REVIEWS_DESCRIPTION . " set reviews_text = '" . tep_db_input($reviews_text) . "' where reviews_id = '" . (int)$rID . "'");
       		get_content();
		}
   }
   }else if($action=='delete_confirm'){  		
        tep_db_query("delete from " . TABLE_REVIEWS . " where reviews_id = '" . (int)$rID . "'");
        tep_db_query("delete from " . TABLE_REVIEWS_DESCRIPTION . " where reviews_id = '" . (int)$rID . "'");
        echo 'delete_success';        
  	}  
  	exit;
  }		    
  function print_record(){
  	global $page,$languages_id;?>
  	<table border="0" width="100%" cellspacing="0" cellpadding="0">
	  	<?php 
	  	$reviews_query_raw = "select r.reviews_id,r.products_id,r.customers_name, date_format(r.date_added,'%Y-%m-%d') as date_added, date_format(r.last_modified,'%Y-%m-%d') as last_modified,r.reviews_rating,rd.reviews_text from " . TABLE_REVIEWS . " r,".TABLE_REVIEWS_DESCRIPTION." rd where r.reviews_id=rd.reviews_id and rd.languages_id='$languages_id' order by r.reviews_id DESC ";
	    $reviews_split = new splitPageResultsEvent($page, MAX_DISPLAY_NEW_REVIEWS, $reviews_query_raw, $reviews_query_numrows);
	    $reviews_query = tep_db_query($reviews_query_raw);
	    $i=0;	   
	    if (tep_db_num_rows($reviews_query)>0){
	    while ($reviews = tep_db_fetch_array($reviews_query)) {      
	      $class="dataTableRowEven";
		  if($i%2==0) $class="dataTableRowOdd";
		  $i++;	      
	      echo '<tr class="'.$class.'" onclick="javascript:if(document.getElementById(\'head_'.$reviews['reviews_id'].'\').style.display==\'none\') do_product_reviews(\'get_details\',' . $reviews['reviews_id'].');">' . "\n";    
		?>
			<td>
			      <div id="data_<?php echo $reviews['reviews_id'];?>" style="cursor:pointer;cursor:hand;">
			        <table border="0" cellspacing="0" cellpadding="3" width="100%">
				        <tr>
			                <td class="dataTableContent" align="left" width="35%"><?php echo tep_image(DIR_WS_ICONS . 'preview.gif', ICON_PREVIEW) . '&nbsp;' . tep_get_products_name($reviews['products_id']); ?></td>
			                <td class="dataTableContent" align="left" width="35%"><?php echo $reviews['customers_name']; ?></td>				
			                <td class="dataTableContent" align="left" width="30%"><?php echo format_date($reviews['date_added']); ?></td>				
	              		</tr>
              		</table>
                 </div>
                 <div style="display:none" class="openContent" id="head_<?php echo $reviews['reviews_id'];?>"></div>
             </td>
            </tr> 		
<?php
     }	  
   } else { echo '<tr><td class=main id="no_record" align=center>No Records Found </td></tr>'; }	
?>
<tr><td class="main"  align="center">&nbsp;</td></tr>
      <tr>
        <td colspan="4"><table border="0" width="100%" cellspacing="0" cellpadding="2">
          <tr>
            <td class="smallText" valign="top"><?php echo $reviews_split->display_count($reviews_query_numrows, MAX_DISPLAY_NEW_REVIEWS, $page, TEXT_DISPLAY_NUMBER_OF_REVIEWS); ?></td>                    
            <td class="smallText" align="right"><?php echo $reviews_split->display_script_links($reviews_query_numrows, MAX_DISPLAY_NEW_REVIEWS, MAX_DISPLAY_PAGE_LINKS, $page,1,'do_product_reviews(\'page_navigation\'','1'); ?></td>
          </tr>				  
        </table></td>
      </tr>
 </table>
<?php  } 
function get_content(){
   	 global $languages_id,$rID;
   	   $str_vals="";		
	   $review_query = tep_db_query("select r.reviews_id,r.products_id,r.customers_name, date_format(r.date_added,'%Y-%m-%d') as date_added, date_format(r.last_modified,'%Y-%m-%d') as last_modified,r.reviews_rating,rd.reviews_text from " . TABLE_REVIEWS . " r,".TABLE_REVIEWS_DESCRIPTION." rd where r.reviews_id=rd.reviews_id and rd.languages_id='$languages_id' and r.reviews_id='$rID'");		 
	   if(tep_db_num_rows($review_query)>0){
		  $review = tep_db_fetch_array($review_query);
		  while(list($key,$vals)=each($review)){		
			if($key=='reviews_text')								
		 		$vals = str_replace("\n","", $vals);		
		 	if($key=='products_id')
		 		$vals=tep_get_products_name($vals,$languages_id);				 	 			 
			if($key=='date_added' || $key=='last_modified')
				$vals=format_date($vals);			 		
			$str_vals.=$vals.'^';
		 }
	  }else $str_vals="No Record Found";
		echo 'get_details'.$str_vals;
  }
?>
<!doctype html public "-//W3C//DTD HTML 4.01 Transitional//EN">
<html <?php echo HTML_PARAMS; ?>>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=<?php echo CHARSET; ?>">
<title><?php echo TITLE; ?></title>
<link rel="stylesheet" type="text/css" href="includes/stylesheet.css">
<script language="javascript" src="includes/menu.js"></script>
<script language="JavaScript" src="includes/date-picker.js"></script>
<script language="javascript" src="includes/general.js"></script>
<script type="text/javascript" src="htmlarea/htmlarea.js"></script>
<script type="text/javascript" src="htmlarea/editor.js"></script>
<script type="text/javascript" src="includes/http.js"></script>
<script language="javascript">
var max_display="<?php echo MAX_DISPLAY_NEW_REVIEWS;?>";
var img_src="<?php echo HTTP_SERVER.DIR_WS_ADMIN.'images/';?>";
var rating=Array();
 	for(i=1;i<=5;i++) rating[i]="../images/stars_"+i+".gif";	 	
 function check_review(that){  
 	if(that.checked == true){
	document.forms['review'].review_date.value = '';
	document.forms['review'].author_name.value = '';
	document.getElementById('review_date').readOnly = true;
	document.getElementById('author_name').readOnly = true;
	document.getElementById('calendar_id').style.display="none";
	that.value='1';
	}
	else{
	document.getElementById('review_date').readOnly = false;
	document.getElementById('author_name').readOnly = false;
	document.getElementById('calendar_id').style.display="";
	that.value='0';
	}
 }
 function formValidate(){ 
 	var id=0;
	if(document.review && document.review.review_id) id=document.review.review_id.value;
	var span_details=document.getElementById("span_details");
	var span_edit=document.getElementById("span_edit");
	var span_delete=document.getElementById("span_delete");
	var loadings=document.getElementById("loading");
	var error_message = "";
	if(document.review.action_type) var action_type=document.review.action_type.value;
	if(span_details && span_details.style.display!="" && span_edit && span_edit.style.display=='' || document.getElementById("new_create") && document.getElementById("new_create").style.display==""){
	 	if(document.forms['review'].admin_review.checked == true && ( (document.forms['review'].reviews_text.value == "") || (str_trim(document.forms['review'].reviews_text.value)=="") ) )
				error_message = '\n<?php echo ERROR_REVIEWS_TEXT; ?>';
	 	else if(!document.forms['review'].admin_review.checked){
			if(document.forms['review'].author_name && ( (document.forms['review'].author_name.value=="") || (str_trim(document.forms['review'].author_name.value)=="") ) )
				error_message = '<?php echo ERR_AUTHOUR_NAME_EMPTY; ?>';
			if(document.forms['review'].review_date.value == "")				
				error_message = '<?php echo ERROR_REVIEW_DATE; ?>';
			if(document.forms['review'].reviews_text.value == "")
				error_message += '\n<?php echo ERROR_REVIEWS_TEXT; ?>';
		}
		if(error_message!=""){
			alert(error_message);
			return false;
		}else{
		  	if(span_delete) span_delete.innerHTML="";
		  	var ids="";		  	
		  	if(document.getElementById("new_create") && document.getElementById("new_create").style.display==""){
		  		if(span_edit) span_edit.innerHTML="";
		  		document.getElementById("new_create").style.display="none";
				change_new_image();
		  	} 
		  	if(action_type=='edit') ids="&rID="+id;
			command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=update_review');?>"+ids;
			if(loadings) loadings.style.display="";
			if(span_edit) span_edit.style.display="none";
			if(document.forms['review'].elements["reviews_rating"]){
				var frm=document.forms['review'].elements["reviews_rating"];
				for(i=0;n=frm.length,i<n;i++){
					if(frm[i].checked && document.review.reviews_rating_assign) document.review.reviews_rating_assign.value=i+1;					
				}
			}										 	
		}
	}else if(span_delete && span_delete.style.display==""){								
			span_details.innerHTML=span_edit.innerHTML="";
			command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=delete_confirm');?>&rID="+id;						
			if(loadings) loadings.style.display=""; 					
			if(span_delete) span_delete.style.display="none";			
	}	
	if(command!="") do_post_command('review',command);		
	return false;	
 }
 function hide_display(){
 	document.getElementById('admin_check_previews').style.display="none";
 } 	
 function change_new_image(){
 //document.getElementById('img_new').firstChild.src=document.getElementById('img_new').firstChild.src.replace('_hover.gif','.gif');
 document.getElementById('img_new').firstChild.src=img_src+'template/img_new.gif';
 display_flag=1;
 }		
 var previous_id='';
  function do_product_reviews(action,id,r_type,sta){
	     if(id==0 && action=='new'){
		  display_flag=0;
		  document.getElementById('img_new').firstChild.src=img_src+'template/img_new_hover.gif';
		  if(document.getElementById('no_record')) document.getElementById('no_record').style.display='none';
		 }
		 if(id==0 && action=='page_navigation') 
		 	if(document.getElementById('no_record'))
				document.getElementById('no_record').style.display='';
				change_new_image();
				var span_details=document.getElementById("span_details");
		 	 	var span_edit=document.getElementById("span_edit");			
				var span_delete=document.getElementById("span_delete");
				if(!sta) sta="";
				var obj=document.getElementById("page_1");
				if(action=='page_navigation' && obj && sta!=""){
		 	 		id=parseInt(obj.options[obj.selectedIndex].value);
		 	 		if(sta=='next') {
		 	 			if(obj.length==obj.selectedIndex+1) return;
		 	 			id+=1;
		 	 		}else if(sta=='prev') {
		 	 			if(obj.selectedIndex==0) return;
		 	 			id-=1;
		 	 		}
		 	 		if(id<=1) id=1;
		 	 	}else if(action=='page_navigation' && sta=="") id="";
		 	 	if(action=='page_navigation' && document.getElementById("new_create").style.display=="") {
		 	 		document.getElementById("new_create").innerHTML="";
		 	 		document.getElementById("new_create").style.display="none";
		 	 	}
		 	 	if(action=='new' && id==0 && document.review.review_id && document.review.review_id.value>0 && document.getElementById("head_"+document.review.review_id.value) && document.getElementById("data_"+document.review.review_id.value)){
					if(span_edit) span_edit.innerHTML="";
					document.getElementById("head_"+document.review.review_id.value).style.display="none";
					document.getElementById("data_"+document.review.review_id.value).style.display="";
					if(document.getElementById("new_create")) document.getElementById("new_create").style.display="";						
		 	 	}
		 	 	var res_display=document.getElementById("res_display"); 	 	 	 	 	 	 	 	 	 		 	  	 	
		 	 	if(res_display) res_display.style.display="none"; 	 		 	 	
		 	 	 if(action!='page_navigation' && document.review && document.review.review_id && document.review.review_id.value>0)  {
					var old_ids=document.review.review_id.value;			
					var pre_data_id=document.getElementById("data_"+old_ids);
					var pre_head=document.getElementById("head_"+old_ids);			
					var loadings=document.getElementById("loading");						
					if(loadings) loadings.style.display="none";
					if(action=='page_navigation' && pre_head && pre_head.innerHTML!='') pre_head.innerHTML="";									
				 }
				 if(document.review.review_id && id>0 && document.review.review_id.value>0 && document.review.review_id.value!=id){			   			   
					   if(pre_head && pre_head.style.display=="") pre_head.style.display="none";
					   if(pre_data_id && pre_data_id.style.display=="none") pre_data_id.style.display="";			   			   			  
					   document.review.review_id.value=id;			   
				 }
				 var img_save=document.getElementById("img_save");	
				 if(action!='page_navigation' && document.review && document.review.review_id) document.review.review_id.value=id;									 								 	 	 	 
		 	 	 if(action){
					var data_id=document.getElementById("data_"+id);
					var head=document.getElementById("head_"+id);
					var command="";
		 	 		switch(action){		 	 			
		 	 		 	case 'page_navigation':
		 	 			       var page="";
		 	 			       if(id!="") {
		 	 			       	page="&page="+id; 
		 	 			       	command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=page_navigation');?>"+page;
		 	 			       	if(document.getElementById("ajax_details")) document.getElementById("ajax_details").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
		 	 			       }		 	 			   	   
		 	 			break;
		 	 			case 'new':
						     if(span_edit) span_edit.innerHTML="";
		 	 				 if(document.review.action_type) document.review.action_type.value='new';
							 document.getElementById('img_new').firstChild.src=img_src+'template/img_new_hover.gif';
		 	 				 document.getElementById("new_create").style.display="";
							 document.getElementById("new_create").innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
		 	 				 if(document.review.action_type) document.review.action_type.value='new';
		 	 				 command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=edit');?>";
		 	 			break; 	 			 	 			
		 	 			case 'get_details':
		 	 			   if(document.getElementById("new_create")) {
		 	 			   		document.getElementById("new_create").innerHTML="";
		 	 			   		document.getElementById("new_create").style.display="none";
								change_new_image();
		 	 			   } 	 			   
		 	 			   if(head && head.style.display==""){
		 	 			   	  if(span_details.style.display==""){
		 	 			   	    head.style.display="none";
		 	 			   	  	data_id.style.display="";
		 	 			   	  }else {
		 	 			   	  	if(span_edit.style.display=="") span_edit.style.display="none";
		 	 			   	  	if(span_delete.style.display=="") span_delete.style.display="none"; 	 			   	  	 	 			   	  	
		 	 			   	  	span_details.style.display="";
		 	 			   	  	if(img_save) img_save.style.display="none"; 
		 	 			   	  	if(document.getElementById("img_ids")){
		 	 			   	  		var tr_obj=document.getElementById("img_ids"); 	 			   	  		
		 	 			   	  		if(tr_obj.childNodes[1].childNodes[0].src==img_src+'template/img_edit_hover.gif')	
		 	 			   	  			tr_obj.childNodes[1].childNodes[0].src=img_src+'template/img_edit.gif';
		 	 			   	  		if(tr_obj.childNodes[2].childNodes[0].src==img_src+'template/img_trash_hover.gif')	
		 	 			   	  			tr_obj.childNodes[2].childNodes[0].src=img_src+'template/img_trash.gif';	 	 			   	  			
		 	 			   	  	}	 			   	  	  	 			   	  	 	 			   	  	
		 	 			   	  }	 	 			    			   	   	 			   
		 	 			 }else { 	
						 	if(previous_id!='')
								if(document.getElementById('head_'+previous_id))
									document.getElementById('head_'+previous_id).innerHTML=''; 			 	 	 			 	
		 	 			 	if(data_id && data_id.style.display=="") data_id.style.display="none";
		 	 			 	if(pre_head && pre_head.style.display=="") pre_head.style.display="none"; 	 			 	
		 	 			 	if(head) {
		 	 			 	 	head.style.display=""; 	 			 	 	 	 			 	  	 			
		 	 			 		head.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";	 			 		
		 	 			 	}
		 	 			 	command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=get_details');?>&rID="+id; 	 			 	 	 			 	
							previous_id=id;
		 	 			 }
		 	 			break; 	 			 	 			
		 	 			case 'edit':
		 	 					span_edit.style.display="";
		 	 					span_delete.style.display=span_details.style.display="none";
		 	 					span_edit.innerHTML="<img src='images/24-1.gif' alt='Loading...' title='Loading...'>";
		 	 					if(document.review.action_type) document.review.action_type.value='edit';
		 	 					command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=edit');?>&rID="+id;
		 	 			break; 	 	 		
		 	 			case 'delete': 	 				 	 				 	 		 	 				
		 	 					span_delete.style.display="";
		 	 					span_edit.style.display=span_details.style.display="none";
		 	 					span_delete.innerHTML='<table border="0" cellspacing="2" cellpadding="1" width="100%"><tr><td width="17" align="center"><?php echo tep_image('images/template/img_trash.gif')?></td>'+
													  '<td width="500" align="left" class="inner_title"><?php echo TEXT_INFO_HEADING_DELETE_REVIEW;?></td></tr>'+
													  '<tr><td></td><td width="500" align="left" class="main"><?php echo TEXT_INFO_DELETE_REVIEW_INTRO;?></td></tr>'+											  				      					       
													  '<tr><td colspan="2"><?php echo tep_draw_separator('pixel_trans.gif',50,10);?></td></tr></table>'; 	 					
		 	 					if(img_save) img_save.style.display="";
		 	 			break;
		 	 			case 'close':
		 	 			  if(head && data_id){
		 	 			  	head.style.display="none";
		 	 			  	head.innerHTML="";
		 	 			  	data_id.style.display="";	
		 	 			  } 
		 	 			break;
		 	 		}
		 	 		if(command!="") do_get_command(command);
		 	 	}
		 	 }
		 	 
   function do_result(result){
   	  if(result!=""){
   	    if(result.substr(0,11)=='get_details') print_details('get_details',result.substr(11));
   	    else if(result.substr(0,4)=='edit') print_details('edit',result.substr(4));
   	    else if(result.substr(0,14)=='delete_success') print_details('delete_success',result.substr(14));
		else if(result.substr(0,15)=='page_navigation') print_details('page_navigation',result.substr(15));
		else if(result.substr(0,5)=='error') print_details('error',result.substr(5));
		else if(result.substr(0,10)=='new_review') print_details('new_review',result.substr(10));
		else if(result.substr(0,3)=='new' && result!="" && document.getElementById("new_create"))	{
			display_flag=0;
			document.getElementById("new_create").style.display="";
			document.getElementById("new_create").innerHTML=result.substr(3);
			<?php 	
		   		 if (HTML_AREA_WYSIWYG_DISABLE=='Enable') { ?>
		 			initEditor('reviews_text');
  	   	    <?php }?>  	   	    		
		}								 	 			 	 			 	 				 	 											   	
   	  }
   }
   
   function print_details(action,result){ 	 	 	 	 	 	 	 	 	 	
 	 	var no_result="";
		if(result.substr(0,15)=='No Record Found')
 	 		no_result="No Record Found";
 	 	else if(result!='' && result.length>0 && action!='edit' && result.substr(0,15)!='No Record Found'){
 	 		splt_str=result.split("^"); 	 		  	 		
 	 		var  review_id="";
			var  product_name="";
			var  authour="";						
			var  date_added="";
			var  last_modified="";
			var  reviews_rating="";
			var  reviews_text="";
 	 		review_id=splt_str[0]; 	 		
 	 		product_name=splt_str[1];
 	 		authour=splt_str[2];
 	 		date_added=splt_str[3];
 	 		last_modified=splt_str[4];
 	 		reviews_rating=splt_str[5];
 	 		reviews_text=splt_str[6];
 	 	}	  	 		 	 	 	 	  	 		 	  	 
 		if(document.review && document.review.review_id) var id=document.review.review_id.value; 		 		 		
 		var span_details=document.getElementById("span_details");	
 		var span_edit=document.getElementById("span_edit"); 	 		 	 		
 		var span_delete=document.getElementById("span_delete"); 						 
 		var head=document.getElementById("head_"+id); 		 		 		  
 		var data_id=document.getElementById("data_"+id);
 		var res_display=document.getElementById("res_display");
 		var img_save=document.getElementById("img_save");
 		var command="";
		if(img_save && action!='get_details') img_save.style.display="";		
 	 	switch(action){ 	 		 	 		 	 		 	 		
 	 		case 'get_details': 	 		 	 	 		 	 		
 	 		if(head  && no_result!="")
				head.innerHTML=no_result; 	 			 	 		
 	 		else if(head && no_result==""){
	 	 		if(data_id){
	 	 			data_id.innerHTML='<table border="0" cellpadding="3" cellspacing="0" width="100%">'+
						          '<tbody><tr>'+
						         	'<td class="dataTableContent" width="35%" align="left"><img src="images/icons/preview.gif" alt="Preview" title=" Preview " border="0">&nbsp;'+product_name+'</td>'+						         				         
					  			 	'<td class="dataTableContent" align="left" width="35%">'+authour+'</td>'+  
					  			 	'<td class="dataTableContent" align="left" width="40%">'+date_added+'</td>'+
						         '</tr>'+
						      	'</tbody></table>';
	 	 		}
	 	 		//do_product_reviews(action,id);
	 	 		include="<table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				"<tr heigth='40' class='openContent_top'>"+
				  '<td style="cursor:pointer;cursor:hand;" onclick="javascript:do_product_reviews(\'close\','+review_id+');" align="left" valign="middle" width="500" class="inner_title">&nbsp;&nbsp;'+product_name+'</td>'+
				  "<td width='70' align='left' class='main' valign='top'>"+
				  	"<table border='0' cellspacing='0' cellpadding='0' style='height:30px;display:inline;position:relative;'>"+
				  	    "<tr class='img_move' id='img_ids'>"+
				  	  		"<td class='cell_bg_popm_left' width='10'>&nbsp;</td>"+
				  	    	'<td width="10"  onclick="javascript:change_class(this,1);do_product_reviews(\'edit\','+review_id+');" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);"><img style="cursor:pointer;cursor:hand;" alt="Edit" title="Edit" src="images/template/img_edit.gif"></td>'+
				  	    	'<td width="10" onclick="javascript:change_class(this,1);do_product_reviews(\'delete\','+review_id+');" onmouseover="javascript:change_class(this,2);" onmouseout="javascript:change_class(this,3);"><img style="cursor:pointer;cursor:hand;" alt="Delete" title="Delete" src="images/template/img_trash.gif"></td>'+				  	    				  	    
				  	    	"<td class='cell_bg_popm_right' width='10'>&nbsp;</td>"+
						"</tr>"+
					 "</table>"+
				  '</td><td width="450" style="cursor:pointer;cursor:hand;" onclick="javascript:do_product_reviews(\'close\','+review_id+');">&nbsp;</td>'+
				 '<td width="85" align="right"><span  id="img_save" style="display:none;"><input type="image" src="images/template/img_savel.gif" alt="save" title="save" border="0">&nbsp;&nbsp;<a href="javascript:do_product_reviews(\'get_details\','+review_id+');"><img src="images/template/img_closel.gif" alt="close" title="close" border="0"></a>&nbsp;&nbsp;</span></td>'+
				"</tr>"+
				"<tr style='height:10'><td id='loading' style='display:none' colspan='5'><img src='images/24-1.gif' alt='Loading...' title='Loading...'></td></tr>"+				
				"<tr>"+
					  "<td colspan='8' class='main'><span style='display:none' id='span_edit'></span><span style='display:none'	id='span_delete'></span><span id='span_details'><table width='100%' border='0' cellspacing='0' cellpadding='0'>"+
				  		"<tr>"+
							"<td width='30%'>"+
				  				"<table width='100%' border='0' cellspacing='3' cellpadding='3' class='main'>";
				  					if(date_added!=""){
				  						include+="<tr>"+
					  						"<td align='left' width='25%' valign='top'><b><?php echo TEXT_DATE_ADDED;?></b></td>"+
					  						"<td align='left' width='45%' valign='top'>"+date_added+"</td>"+
				  						"</tr>";
				  					}	
				  					if(last_modified!=""){		  					
					  					include+="<tr>"+
					  						"<td align='left' width='25%'><b><?php echo TEXT_LAST_MODIFIED;?></b></td>"+
					  						"<td align='left' width='45%'>"+last_modified+"</td>"+
					  					"</tr>";						
				  					}							  					
				  					if(authour!=""){
					  					include+="<tr>"+
					  						"<td align='left' width='25%'><b><?php echo TEXT_AUTHOR_NAME;?></b></td>"+
					  						"<td align='left' width='45%' title='"+authour+"' alt='"+authour+"'>"+((authour.length>25)?authour.substr(0,25)+"...":authour)+"</td>"+
					  					"</tr>";
				  					}
				  					if(reviews_rating>0){		  					
					  					include+="<tr>"+
					  						"<td align='left' width='25%'><b><?php echo TABLE_HEADING_RATING;?></b></td>"+
					  						"<td align='left' width='45%'><img alt='"+reviews_rating+" Star' title='"+reviews_rating+" Star' src='"+rating[reviews_rating]+"'></td>"+
					  					"</tr>";
				  					}
				  			  include+="</table></td>";
					  		  		if(reviews_text) include+="<td align='left' valign='top' class='main'><div style='width:770;height:100;overflow:auto;'>"+reviews_text+"</div></td>";
					  		  include+="</tr>";
					include+="<tr><td colspan='8'><img src='images/pixel_trans.gif' border='0' alt='' width='100%' height='20'></td></tr></span>"+
				 "</td></tr></table>";			
			head.innerHTML=include;
 	 		} 	 			 	 		
 	 	break;
 	 	case 'edit': 	 		 	 		 	 		 	 		
			if(span_edit) span_edit.style.display="";			
 	 		if(span_edit && span_details){ 	 			 	 			
 	 			span_edit.innerHTML=result; 	 			
 	 			span_details.style.display='none';
 	 		}									
       <?php 	
		   if (HTML_AREA_WYSIWYG_DISABLE=='Enable') { ?>
		 		initEditor('reviews_text');
  	   <?php }?>					 		  														
 	 	break; 	 
 	 	case 'error':
 	 		if(res_display){
 	 			res_display.innerHTML=result;
 	 			res_display.style.display="";
 	 		}
 	 	break;		
 	 	case 'page_navigation':
 	 		if(document.getElementById("ajax_details"))
 	 		 document.getElementById("ajax_details").innerHTML=result;
 	 	break; 	 	 	 	
 	 	case 'delete_success':			  	    	  	    	
			 if(head && data_id) {
			 	var tbl_obj=head.parentNode.parentNode.parentNode.parentNode;			 				 				 	
			 	if(tbl_obj) tbl_obj.deleteRow(head.parentNode.parentNode.rowIndex);
			 	data_id.innerHTML=head.innerHTML="";
			 	data_id.style.display=head.style.display="none";			 		
			 }	
			 var len=1;		 				
			 if(res_display){
	    	 	res_display.innerHTML="<?php echo TEXT_REVIEW_DELETE_SUCCESS;?>";
 	    	 	res_display.style.display="";
 	    	 	var obj=document.getElementById("page_1");
 	    	 	if(obj) len=parseInt(obj.options[obj.selectedIndex].value);
 	    	 	command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=page_navigation');?>&page="+len;
				do_get_command(command);
 	    	 }
			 
 	 	break;
 	 	case 'new_review':
				command="<?php echo tep_href_link(FILENAME_PRODUCTS_REVIEWS,'action=page_navigation');?>&page=1";
				do_get_command(command);			 						
		break;
 	 	}
 	 	if(res_display.style.display=="") setTimeout("res_display.style.display='none'",2000); 	 	 	 	
 	 	clearTimeout();
	  } 
	  function change_class(obj,eve){/* 		 		 	 			 
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");				 		 			 
		 if(obj){		   		    		    
		    var img_get_src=obj.childNodes[0];
			if(img_get_src){			    
			    if(img_get_src.src==img_src+'template/img_new.gif'){				   		
			   		if(eve==1 || eve==2) img_get_src.src=img_src+'template/img_new_hover.gif';					
			   }else if(eve==3 && img_get_src.src==img_src+'template/img_new_hover.gif') 
			    	img_get_src.src=img_src+'template/img_new.gif';
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
				if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';		    		    		     		   	
		  }
		 }		 
	  */
	   		 		 	 	
		 var span_details=document.getElementById("span_details"); 
		 var span_edit=document.getElementById("span_edit");
		 var span_delete=document.getElementById("span_delete");				 		 			 
		 if(obj){
		    var img_get_src=obj.childNodes[0];
			if(img_get_src){
			    if(img_get_src.src==img_src+'template/img_edit.gif') {
					if(span_edit && span_edit.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_edit_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_edit_hover.gif' && span_edit && span_edit.style.display=="none") img_get_src.src=img_src+'template/img_edit.gif';
			    if(img_get_src.src==img_src+'template/img_trash.gif') {
					if(span_delete && span_delete.style.display=="" && eve==1 || eve==2){
					 	img_get_src.src=img_src+'template/img_trash_hover.gif';
					}  		   		 	 			 	 			
			    }else if(eve==3 && img_get_src.src==img_src+'template/img_trash_hover.gif' && span_delete && span_delete.style.display=="none") img_get_src.src=img_src+'template/img_trash.gif';		    		    		     		   	
		  }
		}
	  }	  
</script>
</head>
<body marginwidth="0" marginheight="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0" bgcolor="#FFFFFF" onLoad="SetFocus();">
<!-- header //-->
<?php require(DIR_WS_INCLUDES . 'header.php'); ?>
<!-- header_eof //-->
<!-- body //-->
<table border="0" width="100%" cellspacing="2" cellpadding="2">
  <tr> 
<!-- body_text //-->
    <td width="100%" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
      <tr>
        <td width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
		<?php if($error == true) { ?>
		<tr> <td style="color:red;"> <?php echo 'Error [ ' .$error_tag . ' ] '; ?>  </td>
		</tr>
		<?php } ?>          
        </table></td>
      </tr>
      <tr>
        <td  width="100%"><table border="0" width="100%" cellspacing="0" cellpadding="0">
          <tr><td id="res_display" class="main" style="display:none"></td></tr>
          <tr>
            <td valign="top">
            <?php echo tep_draw_form('review', FILENAME_PRODUCTS_REVIEWS, 'page=' . $page . '&rID=' . $rID . '','post','onSubmit=" return formValidate();"'); ?>
            <table border="0" width="100%" cellspacing="0" cellpadding="0">
              <tr class="dataTableHeadingRow" style="height:25px"><td colspan="3" class="pageHeading" align="left" valign="bottom"><a onMouseOver="javascript:do_hover_change(this,2);" onMouseOut="javascript:do_hover_change(this,1);" id="img_new" href="javascript:do_product_reviews('new',0);"><?php echo tep_image('images/template/img_new.gif');?></a></td></tr>	
              <tr><td colspan="3"><?php  echo tep_draw_separator('pixel_trans.gif',5,10); ?></td></tr>
              <tr class="dataTableHeadingRow">
                 <td class="dataTableHeadingContent" width="35%" align="left"><?php echo TABLE_HEADING_PRODUCTS; ?></td>
            	 <td class="dataTableHeadingContent" align="left" width="35%"><?php echo TABLE_HEADING_AUTHOR; ?></td>				
                 <td class="dataTableHeadingContent" align="left" width="30%"><?php echo TABLE_HEADING_DATE_ADDED; ?></td>                
              </tr>
              <tr>
              	<td colspan="3" id="ajax_details"><?php print_record(); ?>
    			</td>    		
          	 </tr>
          	 <tr><td colspan="3"><?php echo tep_draw_separator('pixel_trans.gif', '1', '10'); ?></td></tr>	
          	 <tr><td colspan="3" style="display:none" class="openContent" id="new_create"></td></tr>
          </table>
          <input type="hidden" name="review_id" id="review_id">            		            		                     	
		  <input type="hidden" name="action_type" id="action_type"> 		  
          </form>
          </td>         
         </tr>
        </table>
       </td>
      </tr>
     </table>     
     </td>
<!-- body_text_eof //-->
  </tr>
</table>
<!-- body_eof //-->
<!-- footer //-->
<?php require(DIR_WS_INCLUDES . 'footer.php'); ?>
<!-- footer_eof //-->
</body>
</html>
<?php require(DIR_WS_INCLUDES . 'application_bottom.php'); ?>
<script language="javascript">
	var display_flag=1;	
	function do_hover_change(element,mode){ 
		if(display_flag==1){
			if (element.mode && mode==element.mode) return;
			if (mode==2)
				element.firstChild.src=element.firstChild.src.replace(".gif","_hover.gif");
			else
				element.firstChild.src=element.firstChild.src.replace("_hover.gif",".gif");
		}
		element.mode=mode;
	} 
</script>
