<?php
// If it's not ta Hungarian server we load the index.htm insted of the index.php
if(!preg_match('/zsolozsma/i',$_SERVER['HTTP_HOST'])) {
	echo file_get_contents('index.htm');
	exit;
}

// We need the session to save the setting in session and cookies
session_start();


$base_url = "http://".$_SERVER['HTTP_HOST']; 

/* left side panel only in the "main" page */
if(!array_key_exists('qt',$_REQUEST)) $panel = true; else $panel = false;


/* default values */
if($_REQUEST == array()) { $_GET['today'] = 1; $_GET['qt'] = $_REQUEST['qt'] = 'pdt';}



/* GET and SET the OPTIONS */
$options = array(
	'of1c'=>1,'of1s'=>1,'of1r'=>1,'of1o'=>1,'of1t'=>1,'of1pr'=>1,'of1spspc'=>1,'of1zspc'=>0,'of1sp'=>0,'of1dps'=>0,'of1z95'=>0,'of1prz'=>1,'of1vkp'=>0,'of1v'=>0,'of0v'=>0,'of0cit'=>1,'of2ff'=>0,'of2nav'=>1,'of2rm'=>0,'of2btnu'=>0,'of2nr'=>0,'of0zjvne'=>0,'of0nanne'=>1,'of0tkne'=>1,'of0fn'=>0,'of0bo'=>0,'of1ps3'=>0,'of0bf'=>0,
	'of3'=>'lelkipásztorok – papok','f'=>'CSS szerint','s'=>'CSS szerint',
	'o0'=>0,'o1'=>0,'o2'=>0,'o3'=>0,
	'of5vnpc'=>0,'of5vnhrch'=>0,'of5vnv'=>0,
	'of0r'=>1,
	'o5'=>2);
foreach($options as $opt=>$default) {
	$_GETPOST = array_merge($_GET, $_POST);
	if(array_key_exists($opt,$_GETPOST)) $options[$opt] = $_GETPOST[$opt];
	elseif(array_key_exists($opt,$_COOKIE)) $options[$opt] = $_COOKIE[$opt];
	elseif(array_key_exists($opt,$_SESSION)) $options[$opt] = $_SESSION[$opt];
	else $options[$opt] = $default;
	
	$_REQUEST[$opt] = $options[$opt];
	$_SESSION[$opt] = $options[$opt];
	$_POST[$opt] = $options[$opt];
	setcookie($opt, $options[$opt], 2592000 + time(),'/');	
	//echo $opt."=".$options[$opt]."<br>";
}


/* Other vars */
$imaorak = array(
	'' => '',
	'mi' => 'imhiv',
	'mpc' => 'olv',
	'mrch' => 'reg',
	'mpred' => 'de',
	'mna' => 'del',
	'mpo' => 'du',
	'mv' => 'est',
	'mk' => 'bef',
	'*' => 'mind',
	'mdet' => 'setkozos',
	); 
$honapok = array('január'=>'01','február'=>'02','március'=>'03','április'=>'04','május'=>'05','június'=>'06','július'=>'07','augusztus'=>'08','szeptember'=>'09','október'=>10,'november'=>11,'december'=>12);
$napok2rov = array('hétfő'=>'het','kedd'=>'ked','szerda'=>'szer','csütörtök'=>'csut','péntek'=>'pen','szombat'=>'szom','vasárnap'=>'vas');
$idok2rov = array('adventi idő I (dec.16-ig)'=>'advI','adventi idő II (dec.16 után)'=>'advII','karácsony nyolcada'=>'kar8','karácsonyi idő I (Urunk megjelenéséig)'=>'karI','karácsonyi idő II (Urunk megjelenése után)'=>'karII','évközi idő'=>'evk','nagyböjti idő I (Virágvasárnapig)'=>'nagybI','nagyböjti idő II (Nagyhét)'=>'nagybII','szent három nap'=>'sz3nap','húsvét nyolcada'=>'husv8','húsvéti idő I (Urunk mennybemeneteléig)'=>'husvI','húsvéti idő II (Urunk mennybemenetele után)'=>'husvII');
$imaorak2rov = array('I. esti dicséret'=>'estI','befejező imaóra I.e.d.után'=>'befI','imádságra hívás'=>'imhiv','olvasmányos imaóra'=>'olv','reggeli dicséret'=>'reg','délelőtt'=>'de','délben'=>'del','délután'=>'du','II. esti dicséret'=>'estII','befejező imaóra II.e.d.után'=>'befII');

/*
 * Long urls to SHORT urls.
 *
 * Redirect/refresh the page based on the cgi settings 'qt'
 */
if(array_key_exists('go', $_POST) AND $_POST['go'] == 'Mutasd') {
	switch($_POST['qt']) {
		case 'pdt':
			/* e.g.: /2012/05/07 = one specific day  */ 
			if($_POST['d']<10) $_POST['d'] = '0'.$_POST['d'];
			header( 'Location: '.$base_url.'/'.$_POST['r'].'/'.$honapok[utf8_encode($_POST['m'])].'/'.$_POST['d'] ) ;
			break;
		
		case 'par':
			/* e.g.: /2012/unnepek = feasts of the year */
			header( 'Location: '.$base_url.'/'.$_POST['ar'].'/unnepek' ) ;
			/* TODO: ünnepek in .htaccess */
			break;
			
		case 'pmr':
			/* e.g.: /2012/03 = page of one month */
			header( 'Location: '.$base_url.'/'.$_POST['rr'].'/'.$honapok[utf8_encode($_POST['mr'])] ) ;
			break;
			
		case 'ptab':
			//http://breviar.sk/cgi-bin/l.cgi?qt=pdnes&rfrom=2010&rto=2030&j=hu&
			/* e.g.: /unnepek/2012-2030 = feasts in the years 2012-2030 */ 
			if(array_key_exists('hl', $_POST)) {setcookie('hl', $_POST['hl'], 2592000 + time(),'/'); }
			header( 'Location: '.$base_url.'/unnepek/'.$_POST['rfrom'].'-'.$_POST['rto'] ) ;
			break;
		
		case 'plo':
			/* e.g.: fourth week, ordinary time */
			header('Location: '.$base_url.'/'.$_POST['lr'].'/'.$idok2rov[iconv('cp1250','UTF-8', $_POST['lo'])].'/'.$_POST['t'].'het/'.$napok2rov[utf8_encode($_POST['dvt'])].'/'.$imaorak2rov[$_POST['p']]);
			/*
			p reggeli dicséret
			dvt szerda
			lr A
			lo évközi idő
			t 1	
			*/
			break;
	}
	

}

if(array_key_exists('p',$_GET) AND (array_key_exists('qt', $_REQUEST) AND $_REQUEST['qt'] == 'pdt')) $_GET['p'] = array_search($_GET['p'], $imaorak); 

$_GET['j'] = 'hu'; //Only with hungarian yet..

/* if /tomorrow OR /yesterday we must find the year, month, day */
if((array_key_exists('tomorrow',$_GET) AND $_GET['tomorrow'] == 1) OR (array_key_exists('yesterday',$_GET) AND $_GET['yesterday'] == 1) OR (array_key_exists('today',$_GET) AND $_GET['today'] == 1)) {
	if(array_key_exists('tomorrow',$_GET) AND $_GET['tomorrow'] == 1) { $op = +1; }
	elseif(array_key_exists('yesterday',$_GET) AND $_GET['yesterday'] == 1) { $op = -1; }
	else $op = 0;

	$day = mktime(0,0,0,date("m"),date("d")+$op,date("Y"));

	$_GET['r'] = date("Y", $day);
	$_GET['m'] = date("m", $day);
	$_GET['d'] = date("d", $day);
}
if(array_key_exists('qt', $_GET) AND $_GET['qt'] != 'plo') { $_GET['qt'] == 'pdnes';}
elseif(!array_key_exists('r',$_GET) AND !array_key_exists('ar',$_GET) AND !array_key_exists('rfrom',$_GET)) $_GET['qt'] = 'pdnes'; 
elseif(array_key_exists('qt',$_GET)) $_GET['qt'] = $_GET['qt'];
else $_GET['qt'] = $_REQUEST['qt'] = 'pdt';

if($_GET['qt'] == 'plo') {
	$_GET['lr'] = $_GET['lr']; //a-b-c
	$_GET['lo'] = $_GET['lo'];
	$_GET['t'] = $_GET['t'];  //1-31 week
	$_GET['p'] = $_GET['p'];
}

echo breviar_page();

/*
	download a cgi generated page
 */
function breviar_page() {
   global $base_url, $options;
  /* In the makegeturl() function we make a valid url to the l.cgi from $_GET values */
  $_GET = array_merge($_GET,array('o0'=>$options['o0'],'o1'=>$options['o1'],'o2'=>$options['o2']));
  $file = "/cgi-bin/l.cgi?".makegeturl($_GET);
  if((array_key_exists('hl', $_COOKIE) AND $_COOKIE['hl'] == 1) OR $_REQUEST['qt'] == 'ptab') $file .= "&hl=1";

  /*
   * Some settings are sent with POST method
   * so  we must set POST variables
   */
  
  $fields_string = makegeturl($options);
  $context = stream_context_create(array("http"=>array(
  		"method" => "POST",
  		"header" => "Content-Type: application/x-www-form-urlencoded\r\n" .
  		"Content-Length: ". strlen($fields_string) . "\r\n",
  		"content" => $fields_string,
  ))); 
  if(!$result = @file_get_contents($base_url.$file, false, $context)) { 
  	if(!$result = @file_get_contents('http://breviar.sk'.$file, false, $context)) { 
		echo 'Ideiglenes leállás történt. Elnézést kérünk.'; exit; 
	}
	}	  
  
  /*
   * Now we have all the original breviar.sk file in $result
   * 
   * $output = the new, converted breviar page
   */
  
  
  $output = '';
  
  	$result = $result;
	//changing the css files' relative path to absolute
	$result = preg_replace("/\/breviar.css/i",'http://breviar.sk/breviar.css',$result);
	$result = preg_replace("/href=\"\/(.*?).css/i",'href="http://breviar.sk/$1.css',$result);
	//$line = preg_replace("/\/breviar-invert-colors.css/i",'http://breviar.sk/breviar-invert-colors.css',$line);

	
	//Insert some lines before the </head>
	// see in breviar_header()
	$result = preg_replace("/(<\/head>)/i",breviar_header().'</head>',$result);
	
	//Insert the left side panel and other stuff in breviar_body()
	//$line = preg_replace("/(<body>)/i",'<body onscroll="gorget()">'.breviar_body().'<div id="content" style="margin-left:124px;">',$line); // FIXIT: miért fut lez sokszor??
	$result = preg_replace("/(<body>)/i",'<body >'.breviar_body().'<div id="content" style="margin-left:124px;">',$result); // FIXIT: miért fut lez sokszor??
	$result = preg_replace("/(<\/body>)/i",'</div></body>',$result);
	

	//change the <form>-s
	$result = preg_replace_callback("/<form action=\"\/cgi-bin\/l.cgi\?(.*)\" method=\"post\">/i",'form_replace',$result);
	$result = preg_replace_callback("/<a(.*?)href=\"\/cgi-bin\/l.cgi\?(.*?)\"(.*?)>/i",'a_replace_old',$result);
	//print_R($_REQUEST);
	if((array_key_exists('p',$_REQUEST) AND $_REQUEST['p'] != '') OR (isset($_REQUEST['d']) AND $_REQUEST['d'] == '*') OR (isset($_REQUEST['m']) AND $_REQUEST['m'] == '*') ) $result = preg_replace_callback("/<a href=\"\/cgi-bin\/l.cgi\?(.*?)\"(.*?)>(.{0,100})(<\/a>)/i",'a_replace',$result);
	
	$result = preg_replace("/(value=\"Mutasd\")/i",'value="Mutasd" name="go"',$result);	
	$result = preg_replace("/(type=\"reset\")/i",'type="submit"',$result);
	
	$result = preg_replace("/href=\"(\.\.)\//i",'href="http://breviar.sk/',$result);
	
	/* kiszedjük azt, ami nehéz */
	$result = preg_replace("/<input type=\"hidden\" name=\"of2rm\"(.*?)<br \/>/s",'',$result);

	
	//make the 3 "show/hide" with jquery
	$result = preg_replace("/(<\!--BEGIN: kalendárik-->)(.*?<p)(.*?)(>.*?)(<a.*?>)(.*?)(<\/a>)(<\/p>)(.*?)(<\!--END: kalendárik-->)/si",'$1$2 id="calendar-title" $3$4$6$8<div id="calendar-content" style="backgorund-color:red">$9</div>$10',$result);
	$result = preg_replace("/(<!-- heading -->.*?<span.*?elrejtés.*?\/span>)/s",'',$result);
	//$line = preg_replace("/(elrejt.{1}s)/",iconv('UTF-8','cp1250','naptár elrejtése'),$line);
	
	
	$output = $result;

  return $output;
}

/*
 * to insert some code after <body> tag
 */
function breviar_body() {
	global $base_url;
	/* css for the panel on the left side */
               $return = '
               <div id="arrow" style="
               		position:absolute;
               		top:0;
               		/*color:white;*/';
	
	global $panel; if($panel) $return .=' left: 128px;">&lt;&lt;'; else $return .='left: 0px;">&gt;&gt;';

	$return .= '</div>
               <div id="navigation" style="
               			background-color: #630;
               			//margin-top: -20px;
               			//margin-left: -10px;
               			height: 100%;
               			position: fixed;
               			float:left;
               			top: 0px;';
	global $panel; if($panel) $return .=' left: 0px;'; else $return .='left: -124px;';
			
			$return .='width:108px;
               			color: white;
						font-family: Cambria, Verdana, Tahoma, Georgia, Sans-Serif;
						font-size: 90%;
						padding:8px;
						">';
               /* settings of the panel on the left side */
               $return.='
               	<!--<p>&nbsp;</p>-->
               	<p><a  class="menu"  style="font-size: 130%; color:red;" href="http://zsolozsma.katolikus.hu/2014/02/zsolozsma-most-mar-elerheto-iphone-es-ipad-eszkozokon" >Már iOS-re is!</a></p>
               	<!--<p><a  class="menu"  href="'.$base_url.'">Az Imaórák Liturgiája</a></p>-->
				<p  class="menu" ><a  class="menu" href="/" ><strong>Imádságok &gt;&gt;</strong></a></p>
				<p class="menu"><a  class="menu" href="'.$base_url.'/hu/docs/ord-rch.htm">Általános rész</a></p>
				<p><a class="menu" href="'.$base_url.'/hirek">Hírek</a></p>
				<p><a class="menu" href="'.$base_url.'/letoltes" >Letöltés <br></a></p>
				<p><a class="menu" href="'.$base_url.'/info">Tájékoztató</a></p>
				<p><a class="menu" href="'.$base_url.'/faq">FAQ</a></p>
				<!--<p><a  class="menu" href="'.$base_url.'/cimlap" target="_top">címlap <f&#337;oldal></a></p>-->
<hr style="height: 0.2mm;
	size: 1px;
	width: 75%; 
	text-align: left; 
	color: gray;">						
<p class="patka menu" style="font-size: 71%; 
	text-align: left;">© 1999-2012 
	<br><a class="menu" href="mailto:videky-hu@breviar.sk">Juraj Vidéky</a>
	<br><a class="menu" href="mailto:eleklaszlo@freemail.hu">Elek László</a>
	<br><a class="menu" href="mailto:blahoju2@gmail.com">Blahó Julianna</a>
	<br><a class="menu" href="http://malezi.hu">MALEZI</a>

</p>
               </div>';
               
        return $return;    
      }

      
/*
 * Insert some stuff before </head>
 */
function breviar_header() {
 global $base_url;
 
 $return = '';
 $return .= '<meta property="fb:admins" content="1819502454" />';
 $return .= '<link rel="stylesheet" type="text/css" href="'.$base_url.'/custom.css">';
 
 $return .= '	<link rel="SHORTCUT ICON" href="'.$base_url.'/favicon.ico" type="image/x-icon" />';
 
 /* Insert GOOGLE ANALYTICS, if we are not working on localhost */  
 $return .= " 
 <script type=\"text/javascript\">
	var _gaq = _gaq || [];
		_gaq.push(['_setAccount', 'UA-24682599-1']);
		_gaq.push(['_trackPageview']);
	(function() {
		var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
		ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
		var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
 </script>";
 
 /* Insert JQUERY for the OPTIONS */
 $return .= '
	<script type="text/javascript" src="'.$base_url.'/jquery-1.3.2.js"></script>
	<script type="text/javascript" src="'.$base_url.'/jquery.cookie.js"></script>';
 
 $return .="
 <script type=\"text/javascript\">                                         
   $(document).ready(function() {
		$('#calendar-title').click(function() {
			if ($('#calendar-content').is(':hidden')) {
				$('#calendar-content').slideDown('slow', function() {
				});
				$(this).text('(naptár elrejtése)');
				if($.cookie('o2') == 2168) { $.cookie('o2', 0, { expires: 7 }); }

			} else {
				$('#calendar-content').slideUp('slow');
				$(this).text('(naptár megjelenítése)');
				if($.cookie('o2') == 0) { $.cookie('o2', '2168', { expires: 7 }); }
			}
		});
	
	});
 </script> 
 ";
 
 /*
	14456 = minden csukva
	12408 = csak naptár nyitva
	10360 = csak egyes nyitva
	6264 = csak más nyitva
	8312 = naptár és egyes nyitva
	4216 = naptár és más nyitva
	2168 = más és egyes nyitva
	null = minden nyitva
 */
 
/* INSERT SLIDEBAR to the left */ 
$return .= '<style type="text/css">
		p.menu {
			font-family: Cambria, Verdana, Tahoma, Georgia, Sans-Serif; 
			color: #FFFFFF; 
			text-style: normal; 
		}
 
		a.menu { font-family: Cambria, Verdana, Tahoma, Georgia, Sans-Serif; color: #FFFFFF; text-decoration: none; }
		a.menu:hover { color: #FFFFFF; background-color: #000000; text-decoration:none; }
		a.menu:active { color: #FFFFFF; text-decoration: none; }
		a.menu img { border: none }
  </style>';
  
$return .= "<script>
	function gorget(){
        navigation.style.top=document.body.scrollTop+'px';
        arrow.style.top=document.body.scrollTop+'px';
	}
</script>";

$return.="<script type=\"text/javascript\">
	$(function() {
              
        $(arrow).click(function() {
			if($('#navigation').css('left') == '0px'){
    			$('#navigation').stop().animate({left:'-124px'},200);
    			$('#arrow').stop().animate({left:'4px'},200);
    			$('#content').stop().animate({margin:'0px 0px 0px 0px'},200);
    			$('#arrow').html('&gt;&gt;');			
			};
			if($('#navigation').css('left') == '-124px'){
       			$('#navigation').stop().animate({left:'0px'},200);
       			$('#arrow').stop().animate({left:'128px'},200);
       			$('#content').stop().animate({margin:'0px 0px 0px 124px'},200);
       			$('#arrow').html('&lt;&lt;');
     		};
 		});
    });
</script>";
  
  return $return;
} 


/*
 * Function to adjust/check the links on the <form>-s
 */
function form_replace($matches) {
  global $base_url; global $imaorak;

  ///cgi-bin/l.cgi?qt=pdnes&j=hu
  
 $tmps = explode('&amp;',$matches[1]);
 foreach($tmps as $ts) {
	$tmp = explode('=',$ts);
	if(count($tmp) >= 2)	$$tmp[0] = $tmp[1];
 }
 //return "sörhas";
 if(isset($qt) AND $qt == 'par') return "<form action=\"".$base_url."/".$ar."/unnepek\" method=\"post\" >";

 if(isset($qt) AND $qt == 'pdnes' AND !isset($p) AND !isset($r) AND !isset($m) AND !isset($d)) return "<form action=\"".$base_url."/".date('Y/m/d')."\" method=\"post\" >";
 
 
 if(!isset($p))  $p = '';
 if(!isset($r)) $r = $_GET['r']; 
 if(!isset($m)) $m = $_GET['m']; if($m<10 and $m!='*' and strlen($m)<2) $m = '0'.$m; 
 if(!isset($d)) $d = $_GET['d']; if($d<10 and $d!='*' and strlen($d)<2) $d = '0'.$d;
 if(isset($ds)) $ds = $ds."/"; else $ds = '';
 if($r=='') {$r = date('Y'); $m = date('m'); $d = date('d');}
 if($d=='*' AND $m!='*')  $return = "<form action=\"".$base_url."/".$r."/".$m."/".$ds.$imaorak[$p]."\" method=\"post\" >"; 
 elseif($m=='*') $return = "<form action=\"".$base_url."/".$r."/".$ds.$imaorak[$p]."\" method=\"post\" >"; 
 else $return = "<form action=\"".$base_url."/".$r."/".$m."/".$d."/".$ds.$imaorak[$p]."\" method=\"post\" >"; 
 //pdet
 return $return;
}

/*
 * Function to check the links in the <a> tags
 */
function a_replace($matches) {
	//print_R($matches);
	
	global $base_url; global $imaorak; 	global $options;


	$tmps = explode('&amp;',$matches[1]);
	foreach($tmps as $ts) {
		$tmp = explode('=',$ts);
		//print_R($tmp); echo "<br>";
		if(count($tmp) >= 2)	$$tmp[0] = $tmp[1];
		if(array_key_exists($tmp[0],$options)) $options[$tmp[0]] = $tmp[1];
	} //echo "<br>";
	if(isset($p)) {
		preg_match("/^([a-z]{1,5})/",$p,$match);
		if(count($match)>0) $p = $match[1];
	}
	//echo "--".$p."--";
	//return "s�rhas";
	if(!isset($p))  $p = '';
	if(!isset($r)) $r = $_GET['r'];
	if(!isset($m)) $m = $_GET['m']; if($m<10 and $m!='*' and strlen($m)<2) $m = '0'.$m;
	if(!isset($d)) $d = $_GET['d']; if($d<10 and $d!='*' and strlen($d)<2) $d = '0'.$d;
	if(isset($ds)) $ds = $ds."/"; else $ds = '';
	if($r=='') {
		$r = date('Y'); $m = date('m'); $d = date('d');
	}
	if($d=='*' AND $m!='*')  $url = $base_url."/".$r."/".$m."/".$ds.$imaorak[$p];
	elseif($m=='*') $url = $base_url."/".$r."/".$ds.$imaorak[$p];
	else $url = $base_url."/".$r."/".$m."/".$d."/".$ds.$imaorak[$p];
	//pdet
	//$return .= $matches[1];
if($_REQUEST['qt'] == 'pdt') {
	$form = "</form><form action=\"".$url."\" method=\"post\">";
	foreach($options as $opt=>$val) $form .= "<input type='hidden' name='$opt' value='$val'>";
	$form .= "<input type='submit' value='".$matches[3]."'>";
	$form .= "</form>";
	
	$return = $form;
} else $return = "<a href=\"".$url."\">".$matches[3]."</a>";

	return $return; 
}

function a_replace_old($matches) {
//	print_R($matches);
	
	global $base_url; global $imaorak; 	global $options;


	$tmps = explode('&amp;',$matches[2]);
	foreach($tmps as $ts) {
		$tmp = explode('=',$ts);
		//print_R($tmp); echo "<br>";
		if(count($tmp) >= 2)	$$tmp[0] = $tmp[1];
		if(array_key_exists($tmp[0],$options)) $options[$tmp[0]] = $tmp[1];
		if(isset($qt) AND $qt == 'pst')  return "<a".$matches[1]."href=\"". $base_url."/cgi-bin/l.cgi?".$matches[2]."\"".$matches[3].">";
	} //echo "<br>";
	if(isset($p)) {
		preg_match("/^([a-z]{1,5})/",$p,$match);
		if(count($match)>0) $p = $match[2];
	}
	//echo "--".$p."--";
	//return "s�rhas";
	if(!isset($p))  $p = '';
	if(!isset($r)) $r = $_GET['r'];
	if(!isset($m)) $m = $_GET['m']; if($m<10 and $m!='*' and strlen($m)<2) $m = '0'.$m;
	if(!isset($d)) $d = $_GET['d']; if($d<10 and $d!='*' and strlen($d)<2) $d = '0'.$d;
	if(isset($ds)) $ds = $ds."/"; else $ds = '';
	if($r=='') {
		$r = date('Y'); $m = date('m'); $d = date('d');
	}
	if($d=='*' AND $m!='*')  $url = $base_url."/".$r."/".$m."/".$ds.$imaorak[$p];
	elseif($m=='*') $url = $base_url."/".$r."/".$ds.$imaorak[$p];
	else $url = $base_url."/".$r."/".$m."/".$d."/".$ds.$imaorak[$p];
	//pdet
	//$return .= $matches[1];

	$return = "<a".$matches[1]."href=\"".$url."\"".$matches[3].">";

	return $return; 
}

function makegeturl($array) {
	$geturl = "";
    foreach($array as $key=>$value) { $geturl .= $key.'='.$value.'&'; }
    rtrim($geturl,'&');	
	return $geturl;
}