<?php
/**
 * @version		$Id: sef.php 21097 2011-04-07 15:38:03Z dextercowley $
 * @copyright	Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

jimport('joomla.plugin.plugin');

/*
if(version_compare(JVERSION,'3.0.0','ge')) {
  if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR); 
  JLoader::register('JDate', JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'joomla3'.DS.'date.php'); 
 // require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'joomla3'.DS.'date.php'); 
// Joomla! 1.7 code here
}
*/

/**
 * Joomla! SEF Plugin
 *
 * @package		Joomla.Plugin
 * @subpackage	System.sef
 */
//require_once(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'language.php'); 
class plgSystemOpc extends JPlugin
{
    public function onAfterRoute() {
	$app = JFactory::getApplication();

		if ($app->getName() != 'site') {
			return true;
		}
		
	if (!file_exists(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'language.php')) return;
	
	require_once(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'language.php'); 

	OPCLang::loadLang(); 
	
	// echo JRequest::getVar('task')."<br />"; 
	//  echo JRequest::getVar('view'); 
	  // test format: 
	  $format = JRequest::getVar('format', 'html'); 
	  $option = JRequest::getCmd('option'); 
	  
	  $tmpl = JRequest::getVar('tmpl', ''); 
	  
	   
	  if (($tmpl == 'component') && ($format != 'opchtml')) return; 
	  
	  // speed up json requests 

	  $okformat = array('opchtml', 'html'); 
	  if (!in_array($format, $okformat)) return; 
	  
	  $doc = JFactory::getDocument(); 
	  $class = get_class($doc); 
	  $class = strtolower($class); 
	 
	  $format = str_replace('jdocument', '', $class); 
	  if (!in_array($format, $okformat)) return; 
	
	  $app = JFactory::getApplication();
	  if ($app->isAdmin()) return; 
	  
	  if (!defined('DS')) define('DS', DIRECTORY_SEPARATOR); 
	 
	  require_once(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_virtuemart'.DS.'helpers'.DS.'config.php');
	  VmConfig::loadConfig(true); 
	  require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'loader.php'); 
	  OPCloader::getSetShopperGroup(true); 
	   

	  
	  if (!defined('JPATH_OPC'))
	  define('JPATH_OPC', JPATH_SITE.DS.'components'.DS.'com_onepage'); 
	  $format = JRequest::getVar('format', 'html'); 
	  
	  $option = JRequest::getCmd('option'); 
	   $session = JFactory::getSession();
	   
	    if ($option == 'com_k2')
	  {
	     $view = JRequest::getWord('view');
		  if ($view == 'item')
		  {
		 $task = JRequest::getWord('task'); 
		 $id = JRequest::getVar('id'); 
		 $itemid = JRequest::getInt('Itemid', 0); 
		 $lang = JRequest::getWord('lang'); 
		 $url = 'index.php?option=com_k2&view='.$view.'&id='.$id;
		 
		 if (!empty($itemid))
		 $url .= '&Itemid='.$itemid; 
         $u = JRoute::_($url);
		 
	     $session->set('lastcontiuelink', $u, 'opc');
		 }
	  }
	  
	  $set = array('com_virtuemart', 'com_user', 'com_users', 'com_onepage'); 
	  $set2 = array('com_user', 'com_users'); 
	  
	  
	  
	  
	  if (in_array($option, $set))
	  include(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'config'.DS.'onepage.cfg.php'); 
	  else return; 
	  
	  if (!empty($opc_calc_cache))
	  if (!class_exists('calculationHelper'))
	  if (file_exists(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'calculationh_patched.php'))
	  require_once(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'calculationh_patched.php'); 
	  
	  $task = JRequest::getCMD('task');
	   $view = JRequest::getVar('view'); 
	   
	   if (stripos($task, 'reset')!==false) 
	   {
	   return; 
	   }
	   if (stripos($task, 'login')!==false) 
	   {
	   return; 
	   }
	   if (stripos($task, 'remind')!==false) 
	   {
	   return; 
	   }
	    
	   if (stripos($view, 'reset')!==false) 
	   {
	   return; 
	   }
	   if (stripos($view, 'login')!==false) 
	   {
	   return; 
	   }
	   if (stripos($view, 'remind')!==false) 
	   {
	   return; 
	   }
	   
	   
	  //index.php?option=com_users&task=registration.activate&token=64e7109fe98d1f9988f9e6560f9b644a
	  $user = JFactory::getUser(); 
	  $uid = $user->get('id');
	    
   	  //if(version_compare(JVERSION,'1.7.0','ge') || version_compare(JVERSION,'1.6.0','ge') || version_compare(JVERSION,'2.5.0','ge')) 
	  if (($task == 'registration.activate') && ($option == 'com_users'))
	  {
		  
	  
	  //if (!empty($uid))
	   {
		   
		   $blocked = $user->get('block');
		   $uParams	= JComponentHelper::getParams('com_users');
		   $useractivation = $uParams->get('useractivation');
		   //if (!empty($blocked))
		   if ($useractivation == 1)
		   {
			   
			// if user is already logged in with a blocked account we need to enable the activation here   
			$db		= JFactory::getDBO(); 
			$token = JRequest::getVar('token', null, 'request', 'alnum');
			if (empty($token)) return; 
			// Get the user id based on the token.
			$db->setQuery(
			'SELECT '.$db->quoteName('id').' FROM '.$db->quoteName('#__users') .
			' WHERE '.$db->quoteName('activation').' = '.$db->Quote($token) .
			' AND '.$db->quoteName('block').' = 1 limit 1'
			);
			$userId = (int) $db->loadResult();
			if ((!empty($userId)) && ($userId > 0))
			{
				
				/*
			$q = 'update #__users set (block=0, activation='') where id = '.$userId.' limit 1'; 
			$db->setQuery($q); 
			$db->query(); 
			   */
				$user = JFactory::getUser($userId);
				$user->set('activation', '');
				$user->set('block', '0');
				if ($user->save())
				{
					
					   $jlang =& JFactory::getLanguage(); 
   	 

				$jlang->load('com_users', JPATH_SITE, 'en-GB', true); 
				$jlang->load('com_users', JPATH_SITE, $jlang->getDefault(), true); 
				$jlang->load('com_users', JPATH_SITE, null, true); 

				$mainframe = JFactory::getApplication();
				$mainframe->enqueueMessage(JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'), 'notice');
				$msg = JText::_('COM_USERS_REGISTRATION_ACTIVATE_SUCCESS'); 
				$link = JRoute::_('index.php?option=com_users&view=login'); 
				
				JRequest::setVar('task', null); 
				JRequest::setVar('layout', null); 
				JRequest::setVar('option', 'com_users'); 
				JRequest::setVar('view', 'login'); 
				
				//$mainframe->redirect($link, $msg, 'notice'); 
				//$mainframe->close(); 
				
				
				
				return; 
				}
				else
				{
					
				}
				//$this->setRedirect(JRoute::_('index.php?option=com_users&view=login', false));
			}
			/*
			ob_start(); 
					$options = array('silent' => true, 'skip_joomdlehooks'=>true );
					$mainframe = JFactory::getApplication(); 
					$mainframe->logout($uid, $options); 
					ob_get_clean(); 
			*/
		   }
	   }
	  
	  return;
	  }
	  $this->_currentUser = JFactory::getUser();
	 
	  if ($uid <= 0)
	  {
	 
	  if (($view == 'profile') && ($task == 'saveUser'))
	  {
	   //return; 
	  JRequest::setVar('option', 'com_virtuemart'); 
	  JRequest::setVar('view', 'user'); 
	  }
	  
	  if (!empty($op_redirect_joomla_to_vm))
	   {
	        if (in_array($option, $set2))
			{
	         $view = JRequest::getWord('view', ''); 
			
			 // allowed tasks
			 
			 
			 $set3 = array('user.logout', 'logout', 'user.login', 'login', 'reset', 'remind'); 
			 if ((in_array($task, $set3)) || (in_array($view, $set3)))
			 {
			 
			 return; 
			 }
			 
			 // do not redirect, but show the proper page: 
			 JRequest::setVar('option', 'com_virtuemart'); 
			 JRequest::setVar('view', 'user'); 
			 JRequest::setVar('task', 'display'); 
			 JRequest::setVar('layout', 'edit'); 
			  JRequest::setVar('controller', 'user'); 
			 
			}
	   }
	  }
	  
	  //if (stripos($format, 'html')!==false)
	  if(('com_virtuemart' == $option) || ('com_onepage' == $option)) {
	 
	  $controller = JRequest::getWord('controller', JRequest::getWord('view', 'virtuemart'));
	  $view = JRequest::getWord('view', 'virtuemart'); 
	  $task = JRequest::getCMD('task');
	   
	  $session = JFactory::getSession();
	  
	   $session = JFactory::getSession();
	  if (($view == 'productdetails') && (empty($task)))
	   {
	    // /index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=1&virtuemart_category_id=1
		 $id = JRequest::getInt('virtuemart_product_id', 0); 
		 if (!empty($id))
		 {
		
		 $cid = JRequest::getInt('virtuemart_category_id', 0); 
		 $url = 'index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id='.$id; 
		
		 if (!empty($cid))
		 $url .= '&virtuemart_category_id'.$cid; 
		 
		 $itemid = JRequest::getInt('Itemid', 0); 
		 if (!empty($itemid))
		 $url .= '&Itemid='.$itemid; 
		 
		 $u = JRoute::_($url);
		 
	     $session->set('lastcontiuelink', $u, 'opc');
		
		}
	   }
	 
	  /*
	  $ot1 = JRequest::getVar('opcuniq', ''); 
	  if (!empty($ot1))
	   {
	     $rand2 = $session->get('opcuniq', '');
	   }
      $rand2 = $session->get('opcuniq', '');
	  $finished = (int)$session->get($rand2, 0); 
	  
	  
	  if (($view == 'opc') && (($task == 'checkout') || ($task=='')))
	  if ($finished > 0)
	   {
	     // we alredy had the checkout here and we need to disable double payment and redirect the user to some other page
		 // will redirect the page to the frontpage of VM
		 
		 JRequest::setVar('controller', 'virtuemart'); 
		 JRequest::setVar('view', ''); 
		 JRequest::setVar('layout', 'default'); 
		 JRequest::setVar('format', 'html'); 
		 
		 return; 
	   }
	  */
	  // site refresh, logout, hacking attempt protection
	  if (($view == 'opc') && ($task!='opc') && ($task!='checkout') && (($task!='tracker')))
	  {
	  
	  	 JRequest::setVar('controller', 'virtuemart'); 
		 JRequest::setVar('view', 'virtuemart'); 
		 JRequest::setVar('layout', 'default'); 
		 JRequest::setVar('format', 'html'); 

		 // we can safely remove all variables in session: 
		 if (($task!='tracker') && ($task != 'opc'))
		 {
		  $session = JFactory::getSession();
          $session->clear('opcuniq');
	      $session->clear($rand2); 
		 }
		 return; 
	  }
	   
	  
	  
	  ///index.php?option=com_virtuemart&view=opc&controller=opc&task=checkout
	  if (($view == 'opc') && ($task == 'checkout'))
	   {
	     // disable key captcha: 
		 $first_name = JRequest::getVar('first_name', ''); 
		 JRequest::setVar('opc_first_name', $first_name); 
		 JRequest::setVar('first_name', null); 
		 unset($_POST['first_name']); 
		 unset($_GET['first_name']); 
		 unset($_REQUEST['first_name']); 
		
	   }
	  
	  if ($task == 'edit') return; 
	  /*
	  if (!defined('JPATH_COMPONENT'))
	  define('JPATH_COMPONENT', JPATH_SITE.DS.'components'.DS.'com_virtuemart');
	  */
	  
	  // dont' proceed OPC when user is logged and is editing the address: 
	  $user = JFactory::getUser(); 
	  if (!empty($user->id))
	   {
	     // virtuemart_user_id[]=51&virtuemart_userinfo_id=18
		 $virtuemart_user_id = JRequest::getVar('virtuemart_user_id', ''); 
		 $virtuemart_userinfo_id = JRequest::getVar('virtuemart_userinfo_id', ''); 
		 //http://vm2onj25.rupostel.com/index.php?option=com_virtuemart&view=user&task=editaddresscart&addrtype=BT&virtuemart_userinfo_id=11&cid[]=51
		 if (($view=='user') && ($task == 'editaddresscart') && (!empty($virtuemart_userinfo_id))) return;
	     if (($view=='user') && ($task == 'editaddressST') && (!empty($virtuemart_user_id)) && (!empty($virtuemart_userinfo_id)))
		  {
		 
		  return;
		  }
	   }
	  
	  $layout = JRequest::getVar('layout', ''); 
	  if (($view == 'user') && ($layout == 'edit'))
	  {
	   return;
	  }

	  
	  if  ($view == 'cart2')
	   {
	     $view = 'opc'; 
		 
		 $_POST['view'] = 'opc'; 
		 $_GET['view'] = 'opc'; 
		 $_REQUEST['view'] = 'opc';
		 $controller = 'opc';
		JRequest::setVar('view', 'opc'); 
		JRequest::setVar('task', 'cart'); 
	   }
	  
	  
	  if ((($view == 'cart') || ($view == 'opc') ) || (($view=='user') && ($task=='editaddresscheckout')) || ($task == 'pluginUserPaymentCancel'))
		{
		
             // require_once(dirname(__FILE__) . DS . 'loader.php');
			  //overrides'.DS.'vmplugin.php'); 
			  if (!class_exists('VirtueMartViewCart'))
			  {
			    if (function_exists('ini_set'))
			    @ini_set('memory_limit','128M');
                require_once(JPATH_OPC.DS.'overrides'.DS.'virtuemart.cart.view.html.php'); 
			  }
			  else
			  {
			     // opc will not load because some other extension is using cart view override
			  }
			  
			 if ($view == 'user')
		     {
			 if (!class_exists('VirtueMartViewUser'))
			 require_once(JPATH_OPC.DS.'overrides'.DS.'virtuemart.user.view.html.php'); 
			  JRequest::setVar('layout', 'default'); 
			  JRequest::setVar('view', 'cart'); 
			 }
			 if (!class_exists('vmPlugin'))
			 require_once(JPATH_OPC.DS.'overrides'.DS.'vmplugin.php'); 
			 else
			  {
			    
			  }
			 //include_once(JPATH_OPC.DS.'overrides'.DS.'cart.php'); 
			 
			 
		}
		else return;
			 
			 
		if ($controller =='opc')
	    {
		
	     if (strpos($controller, '..')!==false) die('?'); 
	     require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'controllers'.DS.'opc.php'); 
		 
		 // fix 206 bug here:
		 /*
		 if (!class_exists('VmFilter'))
		 require_once(JPATH_SITE.DS.'components'.DS.'com_onepage'.DS.'overrides'.DS.'vmfilter.php'); 
		 */
		 
	    }
		
		 	$layout = JRequest::getVar('layout'); 
	if (($view == 'user') && empty($task) && ($layout=='default'))
	 {
	   JRequest::setVar('default', null); 
	   unset($_REQUEST['layout']); 
	   
	 }
	
			 // We need to fix a VM206 bugs when a new shipping address cannot be added, savecartuser
		if( ('user'==$view && (('savecartuser' == $task) || ('editaddresscart' == $task)) ))
		{
		 

		   if ('ST' == JRequest::getCMD('address_type'))
		   {
		     if (!isset($_POST['shipto_virtuemart_userinfo_id']))
			  {
			    $_POST['shipto_virtuemart_userinfo_id'] = '0'; 
				JRequest::setVar('shipto_virtuemart_userinfo_id', 0); 
	
			  }
		    
		   }
		   if ('BT' == JRequest::getCMD('address_type'))
		   {
		     if (isset($_POST['shipto_virtuemart_userinfo_id']))
			  {
			    JRequest::setVar('shipto_virtuemart_userinfo_id', null); 
			    unset($_POST['shipto_virtuemart_userinfo_id']); 
				
			  }
		   }
		   
		   
		   // this fixes vm206 bug: Please enter your name. after changing BT address
		   if ('BT' == JRequest::getCMD('address_type'))
		   {
		     $user = JFactory::getUser();
			 
			 
			 //$x = JRequest::getVar('name'); 
		     if (!isset($_POST['name']))
			  {
			    if (!empty($user->name)) 
				{
				  $_POST['name'] = $user->name; 
				  JRequest::setVar('name', $_POST['name']); 
				}
				else
				{
			     $_POST['name'] = $user->get('first_name', '').' '.$user->get('middle_name', '').' '.$user->get('last_name', ''); 
				 JRequest::setVar('name', $_POST['name']); 
				}
				
			  }
			 
		   }
		   
		 }
		
	 // let's enable silent registration when show login is disabled, but only registered users can checkout: 
		 $t1 = JRequest::getCmd('controller', '', 'post'); 
		 $t2 = JRequest::getCmd('view', 'user', 'post'); 
		 $t3 = JRequest::getCmd('address_type', '', 'post'); 
		 $t4 = JRequest::getCmd('task', 'saveUser', 'post'); 
		 $t4 = strtolower($t4); 
		 
		 if (($t1 == 'user') && ($t2 == 'user') && ($t3 == 'BT') && ($t4=='saveuser'))
		  {
		  
		    $t5 = JRequest::getVar('username'); 
			if (empty($t5))
			 {
			    $email = JRequest::getVar('email'); 
				if (!empty($email))
				 {
				   JRequest::setVar('username', $email); 
				 }
				// address name: 
				$name = JRequest::getVar('name'); 
				if (empty($name))
				 {
				    $firstname = JRequest::getVar('first_name', 'default'); 
					$lastname = JRequest::getVar('last_name', ' address'); 
					JRequest::setVar('name', $firstname.' '.$lastname); 
				 }
				 
			 }
			 JRequest::setVar('task', 'saveUser'); 
			 
	 
			 if (!empty($newitemid))
			  JRequest::setVar('Itemid', $newitemid); 
			 
			
			 
		   
		  }
	
	
			 
	if( ('user'==$view && (('savecartuser' == $task) || (strpos($task, 'editadd')!==false ))) )
	{
	//if (!defined('JPATH_COMPONENT')) define('JPATH_COMPONENT', JPATH_SITE.DS.'components'.DS.'com_virtuemart'); 
	
	
	if ($view != 'opc')
	$config = array ( "base_path"=> JPATH_SITE.DS.'components'.DS.'com_virtuemart',  "layout"=>  "default" );
	else $config = array ( "base_path"=> JPATH_SITE.DS.'components'.DS.'com_onepage',  "layout"=>  "default" );
	
	$OPCloader = new OPCloader($config); 
	
	  
	
	if (!class_exists('VirtueMartCart'))
	   require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
	$cart =& VirtueMartCart::getCart();
	
	if ($view != 'opc')
	if (!$OPCloader->logged($cart))
	 {
	      // we will load OPC for all edit address links for unlogged
		  JRequest::setVar('view', 'cart'); 
	
	 }
	}
	
	 if( (('cart'==$view || (('opc'==$view)))))
	 {
	 include(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'config'.DS.'onepage.cfg.php'); 
	 
	 if (!empty($newitemid))
	 {
	   $GLOBALS['Itemid'] = $newitemid; 
	   $_REQUEST['Itemid'] = $newitemid; 
	   $_POST['Itemid'] = $newitemid; 
	   $_GET['Itemid'] = $newitemid; 
	 }
	 }
	 
	 // we don't need any further code from ajax
		// return;
	  // next few lines update user's access rights for each view of the page
	  // there is a bug in joomla 1.7 to joomla 2.5.x which does not update the cached authLevels variable of the user in some cases (right after registration)
	  if(version_compare(JVERSION,'1.7.0','ge') || version_compare(JVERSION,'1.6.0','ge') || version_compare(JVERSION,'2.5.0','ge')) {
	  $instance = JFactory::getSession()->get('user');
	  if ((!empty($instance->id) && (empty($instance->opc_checked))))
	  {
	   $u = new JUser((int) $instance->id);
	   $u->opc_checked = true; 
	   JFactory::getSession()->set('user', $u); 
	  }
	  }
	 // this part disables taxes for US mode an all pages unless a proper state is selected
	  
	  if ($view != 'cart' && ($view != 'opc'))
	  if (!empty($opc_usmode)) 
	  {
	   if (!class_exists('VirtueMartCart'))
	   require(JPATH_VM_SITE . DS . 'helpers' . DS . 'cart.php');
	   $cart =& VirtueMartCart::getCart();
	   
	  
	   
	   if (empty($cart->ST) && (!empty($cart->BT)))
	   {
	    if (empty($cart->BT['virtuemart_state_id'])) $cart->BT['virtuemart_state_id'] = ' '; 
		//$GLOBALS['st_opc_state_empty'] = true; 
		$GLOBALS['opc_state_empty'] = true; 
	   }
	   else
	   if (empty($cart->ST) && (empty($cart->BT)))
	   {
	   $cart->BT = array(); 
	   $cart->BT['virtuemart_state_id'] = ' '; 
	   $GLOBALS['opc_state_empty'] = true; 
	   }
	   if (!empty($cart->ST))
	   {
	     if (empty($cart->ST['virtuemart_state_id'])) $cart->BT['virtuemart_state_id'] = ' '; 
		 $GLOBALS['st_opc_state_empty'] = true; 	
	   }
	   
	  }

          }
		  
		 
	  
	
	}
	
	public function onAfterDispatch2()
	{
	
	  $app = JFactory::getApplication();
	 
	  
	  
	  //if (stripos($format, 'html')!==false)
	  if('com_virtuemart' == JRequest::getCMD('option') && !$app->isAdmin()) {
	    JHTML::script('onepageiframe.js', 'components/com_onepage/assets/js/', false);
	  }
	 
	 
	  
	}
	
	
	
	/**
	 * Converting the site URL to fit to the HTTP request
	 */
	public function onAfterRender()
	{
	
	  $format = JRequest::getVar('format', 'html'); 
	  //if ($format != 'html') return;

		$app = JFactory::getApplication();

		if ($app->getName() != 'site') {
			return true;
		}
		
		if (!file_exists(JPATH_ROOT.DS.'components'.DS.'com_onepage'.DS.'helpers'.DS.'language.php')) return;
		
		$task = JRequest::getVar('task', ''); 
		$view = JRequest::getCMD('view'); 
		
		 if(('com_virtuemart' == JRequest::getCMD('option') && !$app->isAdmin()) && (('cart'==$view) || ($view=='pluginresponse'))) 
		 {
			 $buffer = JResponse::getBody();
		if ($task != 'checkout')
		{
		//Replace src links
		$base	= JURI::base(true).'/';
		
		 //orig opc: 
		 $buffer = str_replace('$(".virtuemart_country_id").vm2front("list",{dest : "#virtuemart_state_id",ids : ""});', '$("#virtuemart_country_id").vm2frontOPC("list",{dest : "#virtuemart_state_id",ids : ""});'."\n".'$("#shipto_virtuemart_country_id").vm2frontOPC("list",{dest : "#shipto_virtuemart_state_id",ids : ""});', $buffer); 
		 $buffer = str_replace('$(".virtuemart_country_id").vm2front("list",{dest : "#virtuemart_state_id",ids : ""});', '', $buffer); 
		 $buffer = str_replace('$("select.virtuemart_country_id").vm2front("list",{dest : "#virtuemart_state_id",ids : ""});', '', $buffer); 
		 $buffer = str_replace('$(".virtuemart_country_id").vm2front', '// $(".virtuemart_country_id").vm2front', $buffer); 
		 $buffer = str_replace('$("#virtuemart_country_id").vm2front', '// $("#virtuemart_country_id").vm2front', $buffer);
		 $buffer = str_replace('$("#shipto_virtuemart_country_id").vm2front', '// $("#shipto_virtuemart_country_id").vm2front', $buffer);
		 $inside = JRequest::getVar('insideiframe', ''); 
		 if (!empty($inside))
		  {
		    $buffer = str_replace('<body', '<body onload="javascript: return parent.resizeIframe(document.body.scrollHeight);"', $buffer); 
		  }
		 //$buffer = str_replace('$(".virtuemart_country_id").vm2front("list",{dest : "#virtuemart_state_id",ids : ""});', '', $buffer); 
		$buffer = str_replace('jQuery("input").click', 'jQuery(null).click', $buffer);
		$buffer = str_replace('#paymentForm', '#adminForm', $buffer);
		
		/*
		if (isset(VmPlugin::$ccount))
	    $buffer .= '<script type="text/javascript">console.log("positive cache: '.VmPlugin::$ccount.'")</script>';
		*/
		
		 }
		    if (class_exists('plgSystemBit_vm_change_shoppergroup'))
			{
				$js_text = "<script type=\"text/javascript\">location.reload()</script>";
				//$js_text = "location.reload()";
				$c = 0; 
				$buffer = str_replace($js_text, '', $buffer, $c); 
				
				 
				
			}
			
			JResponse::setBody($buffer);
		
		
		}

		
		
		return true;
	}
	// we will disable the 
	public function plgVmInterpreteMathOp($calc, $rule, $price, $revert)
	{
		return false; 
	}
	
	public function plgVmonSelectedCalculatePriceShipment(VirtueMartCart $cart, &$cart_prices, &$cart_prices_name) {
	  if (!empty($cart->virtuemart_shipmentmethod_id))
	  if (!empty(OPCcache::$cachedResult['currentshipping']))
	  if ($cart->virtuemart_shipmentmethod_id < 0)
	  {
		return OPCcache::getStoredCalculation($cart, $cart_prices, $cart_prices_name); 
	  }
	}

}
