/****************************************************************************
 *  This file is part of phpCubeMachine.                                    *
 *  phpCubeMachine is an open source framework for building php based       * 
 *  web applications.                                                       *
 *                                                                          *
 *  http://sourceforge.net/projects/phpcubemachine/                         *
 *                                                                          *
 *  Copyright (C)2008 - 2010 Jan Fuka, Czech Republic                       *
 *                                                                          *
 *                                                                          *
 *  phpCubeMachine is free software: you can redistribute it and/or modify  *
 *  it under the terms of the GNU General Public License as published by    *
 *  the Free Software Foundation, either version 3 of the License, or       *
 *  (at your option) any later version.                                     *
 *                                                                          *
 *  phpCubeMachine is distributed in the hope that it will be useful,       *
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 *  GNU General Public License for more details.                            *
 *                                                                          *
 *  You should have received a copy of the GNU General Public License       *
 *  along with phpCubeMachine.  If not, see <http://www.gnu.org/licenses/>. *
 ****************************************************************************/


/**
 * Implements dynamic site design.
 * 
 * Dependence: jQuery 1.3.x
 *
 */
 
/**
 * Constructor
 * @param array parArResizableDependence
 *    [{"element" : "...",
 *      "height" : {"ref_element" : "...", "depend_on" : ["...",...]},
 *      "width" : {"ref_element" : "...", "depend_on" : ["...",...]}},
 *      ...
 *    ]
 *
 *    - element - html.id element
 *    - ref_element - html.id element whose dimensions are taken as reference for calculating the size of the element
 *                  - if its value is "window", this is the actual browser window
 *                  - if its value is id of the element itself, size remains static
 *    - depend_on - html.id list of elements whose dimensions are deducted to determine the size of the element
 * 
 *    - Children elements must refer to their parents.
 *    - Order of dependency must comply with the DOM hierarchy of a document.
 *      Ie. that the definition of parents must always be defined before children. 
 */
function FlexibleLayout(parArResizableDependence)
{
    this.arResizableDependence = parArResizableDependence;
    
    /**
	 * Calculate the height of the element, css attributes: 
	 *      margin-top
	 *      border-top
	 *      padding-top 
	 *      margin-bottom
	 *      border-bottom
	 *      padding-bottom
	 * If the parameter "parBlHeightInclude" = "true",
	 * added to the attribute "height".
	 * 
	 * @param string parStrElementId
	 * @param boolean parBlHeightInclude
	 * @return int vyska elementu
	 * 
	 */
	this.getElementHeight = function(parStrElementId, parBlHeightInclude)
	{
	    var parStrElementId = "#" + parStrElementId;
	    var intReturn = 0;
	    if(parBlHeightInclude == true) intReturn += $(parStrElementId).height();
	    intReturn += parseInt($(parStrElementId).css("marginTop"))
	               + parseInt($(parStrElementId).css("marginBottom"))
	               + parseInt($(parStrElementId).css("borderTopWidth")) 
	               + parseInt($(parStrElementId).css("borderBottomWidth"))
	               + parseInt($(parStrElementId).css("paddingTop")) 
	               + parseInt($(parStrElementId).css("paddingBottom"));
	    return intReturn;
	}
	
	/**
	 * Calculate the width of the element, css attributes: 
	 *      margin-left
	 *      border-left
	 *      padding-left 
	 *      margin-right
	 *      border-right
	 *      padding-right
	 * If the parameter "parBlWidthInclude" = "true",
	 * added to the attribute "width".
	 * 
	 * @param string parStrElementId
	 * @param boolean parBlWidthInclude
	 * @return int sirka elementu
	 * 
	 */
	this.getElementWidth = function(parStrElementId, parBlWidthInclude)
	{
	    var parStrElementId = "#" + parStrElementId;
	    var intReturn = 0;
	    if(parBlWidthInclude == true) intReturn += $(parStrElementId).width();
	    intReturn += parseInt($(parStrElementId).css("marginLeft"))
	               + parseInt($(parStrElementId).css("marginRight"))
	               + parseInt($(parStrElementId).css("borderLeftWidth")) 
	               + parseInt($(parStrElementId).css("borderRightWidth"))
	               + parseInt($(parStrElementId).css("paddingLeft")) 
	               + parseInt($(parStrElementId).css("paddingRight"));
	    return intReturn;
	}
    
    /**
     * Changing the size of the element bound by the act. size of the browser window.
     * 
     */
    this.resize = function()
	{
	    var intElDependHeight = 0;
	    var intElDependWidth = 0;
	    
	    // pass individual items
	    for(intItemIndex in this.arResizableDependence) {
	        var strElName = this.arResizableDependence[intItemIndex]["element"];
	        
	        // height
	        var intRefElHeight = (this.arResizableDependence[intItemIndex]["height"]["ref_element"] == "window" ? $(window).height() : $("#" + this.arResizableDependence[intItemIndex]["height"]["ref_element"]).height());
	        var arHeightDependOn = this.arResizableDependence[intItemIndex]["height"]["depend_on"];
	        
	        // calculate height of individual dependent element
	        for(intDependOnItemIndex in arHeightDependOn) {
	            // find height for the elements
	            intElDependHeight += this.getElementHeight(arHeightDependOn[intDependOnItemIndex], true);
	        }
	        // set height of the element
	        intElHeight = this.getElementHeight(strElName, false);
	        $("#" + strElName).height(intRefElHeight - intElDependHeight - intElHeight);
	        intElDependHeight = 0;
	        
	        // width
	        var intRefElWidth = (this.arResizableDependence[intItemIndex]["width"]["ref_element"] == "window" ? $(window).width() : $("#" + this.arResizableDependence[intItemIndex]["width"]["ref_element"]).width());
	        var arWidthDependOn = this.arResizableDependence[intItemIndex]["width"]["depend_on"];
	        
	        // calculate width of individual dependent element
	        for(intDependOnItemIndex in arWidthDependOn) {
	            // find width for the elements
	            intElDependWidth += this.getElementWidth(arWidthDependOn[intDependOnItemIndex], true);
	        }
	        // set width of the element
	        intElWidth = this.getElementWidth(strElName, false);
	        $("#" + strElName).width(intRefElWidth - intElDependWidth - intElWidth);
	        intElDependWidth = 0;
	    }
	}
}

/******************************* Obsolete section - everything can be done in jQuery *******************************/

/*
 * Registrace akci pro postback informaci o clientovi
 * 
 */
// velikost okna po natazeni stranky
/*$(document).ready(function(){
    $.post("process-client-configuration", {window_width: $(window).width(), window_height: $(window).height()});
});*/

/**
 * Vrati timestamp
 * 
 */
function getTimestamp()
{
    var currentTime = new Date();
    return currentTime.getTime();
}

/**
 * Vrati sirku obrazovky
 * 
 */
function getScreenWidth()
{
    return window.screen.width;
}

/**
 * Vrati vysku obrazovky
 * 
 */
function getScreenHeight()
{
    return window.screen.height;
}

/**
 * Slouzi k vycentrovani objektu vudci obrazovce.
 * Vrati hor. pozici leveho horniho rohu.
 * 
 */
function getElementLeftScreenCenter(sirka) {
    sirka = Math.min(window.screen.width, sirka);
    return Math.round((window.screen.width - sirka) / 2);
}

/**
 * Slouzi k vycentrovani objektu vudci obrazovce.
 * Vrati vert. pozici leveho horniho rohu.
 * 
 */
function getElementTopScreenCenter(vyska) {
    vyska = Math.min(window.screen.height, vyska);
    return Math.round((window.screen.height - vyska) / 2);
}

/**
 * Zastresuje objekt XMLHttpRequest
 * Vracena data jsou poslana do callback funkce jako vstupni parametr
 * Typ parametru ( promenne ) je dan charakterem dat ( int, string, array, ... )
 * 
 * @param array parInitData - konfiguracni parametry
 * 							- parametry:	- method [ GET | POST ]
 * 											- url [ retezec url ]
 * 											- callBack [ nazev funkce ]
 * 							- napr: { 	"method" : "GET",
 *										"url" : "?access=ws&component=LastMinute&method=getDataJSON",
 *										"callBack" : callback }
 * 
 * ***** Unit test - example *****
 * 
 * Wrapper pro zpracovani dat
 * function callback( parData ) 
 * {
 *    alert( "callback = " + parData );
 * }
 *
 * var ajax = new AJAX( { 	"method" : "GET",
 *							"url" : "?access=ws&component=LastMinute&method=getDataJSON",
 *							"callBack" : callback } ); 
 *
 * ***** Unit test - examle *****  
 * 
 */
function AJAX( parInitData )
{
	var xmlHttpRequest = null;
	var self = this;
	
	self.url = parInitData["url"];
	self.method = parInitData["method"];
	self.callBack = parInitData["callBack"];
	self.callBackError = null;

	self.done = false;
	
	/**
	 * Inicializace instance objektu
	 * 
	 */
	// Mozilla/Safari
    if (window.XMLHttpRequest) {
        self.xmlHttpRequest = new XMLHttpRequest( );
    }
    // IE
    else if (window.ActiveXObject) {
        self.xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
    }
	
	/**
	 * Odesle data metodou GET
	 * 
	 */
	self.doGet = function( )
	{
		// vytvori a nastavi spojeni
		self.xmlHttpRequest.open( 'GET', self.url, true );
	    self.xmlHttpRequest.onreadystatechange = self.makeData; 
	    self.xmlHttpRequest.send( null );
	}
	
	/**
	 * Odesle data metodou POST
	 * !!! Nedodelane !!!
	 * 
	 */
	/*self.doPost = function( )
	{
		// vytvori a nastavi spojeni
		self.xmlHttpRequest.open( 'POST', self.url, true );
		self.xmlHttpReq.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded" );
	    self.xmlHttpRequest.onreadystatechange = self.makeData; 
	    self.xmlHttpRequest.send( null );
	}*/
	
	/**
	 * Z retezce JSON vytvori platnou JS promennou
	 * Tuto promennnou posle jako parametr do wrapperu
	 * 
	 */
	self.makeData = function( )
	{
		try {
			if( self.xmlHttpRequest.readyState == 4 ) {
				if( self.xmlHttpRequest.status == 200 ) {
					// hack pro JS eval( ) - neumi zpracovat asociovane pole
					var data = eval( self.xmlHttpRequest.responseText );
					data = data[0];
					
					self.callBack( data );
					self.done = true;
				}
			}
		} catch ( e ) {
			// pripraveno pro dalsi pouziti
			//self.callBackError( );
		}
	}

	self.abortQuery = function( )
	{
		self.xmlHttpRequest.abort();
		self.done = true;
	}
	
	/**
	 * Workflow
	 * 
	 */ 
	if( self.method == "GET" ) {
		self.doGet( );
	} else {
		self.doPost( );
	}
}


/**
 * Objekt ResultSet
 *
 *  
 ***** Unit test - examle *****
 *	var rs = new RS( );
 *	rs.addColumn( 'col1' );
 *	rs.addColumn( 'col2' );
 *	rs.addColumn( 'col3' );
 *	rs.addRow( );
 *	rs.setValue( 'col1', 1 );
 *	rs.dump( 'dump1' );
 *	rs.addRow( );
 *	rs.setValue( 'col2', 2 );
 *	rs.dump( 'dump2' );
 *	rs.addRow( );
 *	rs.setValue( 'col3', 3 );
 *	rs.dump( 'dump3' );
 ***** Unit test - examle ***** 
 * 
 */
function RS( )
{
	this.data = Array( );		// data
	this.columnList = Array( );	// seznam sloupcu ['col1', 'col2', ...]
	this.currentRow = -1;		// akt. radek []
	this.rowCount = 0;			// pocet radku
	this.foreachFlag = false;	// priznak pro bezici foreach
	
	
	/**
	 * Smaze radek, kde dany sloupec obsahuje danou hodnotu
	 * !!! NN 4.0, MSIE 4.0 !!!
	 * @param parColumnName
	 * @param parValue
	 * @return cislo radku / false
	 * 
	 */
	this.deleteRowByValue = function( parColumnName, parValue )
	{
		var row = this.searchRowByValue( parColumnName, parValue ); 
		if( row != -1 )	this.deleteRow( row );
	}
	
	/**
	 * Smaze aktualni radek
	 * !!! NN 4.0, MSIE 4.0 !!!
	 * 
	 */
	/*this.deleteCurrentRow = function( )
	{
		if( this.currentRow != -1 ) {
			var currentRow = this.currentRow;
			this.data.splice( this.currentRow, 1 );
			this.currentRow = currentRow - 1;
			this.rowCount = this.data.length;
		}
	}*/
	
	/**
	 * Smaze radek
	 * !!! NN 4.0, MSIE 4.0 !!!
	 * @param parRowNumber [ 0 ... ]
	 * 
	 */
	this.deleteRow = function( parRowNumber )
	{
		//alert( parRowNumber + ' - ' + this.currentRow );
		//this.dump( 'begin' );
		var currentRow = this.currentRow;
		this.data.splice( parRowNumber, 1 );
		//this.dump( 'end' );
		this.currentRow = currentRow - 1;
		this.rowCount = this.data.length;
	}
	
	/**
	 * Nalezne radek, kde dany sloupec obsahuje danou hodnotu
	 * @param parColumnName
	 * @param parValue
	 * @return cislo radku / -1
	 * 
	 */
	this.searchRowByValue = function( parColumnName, parValue )
	{
		/*while( this.foreach( ) == true ) {
			if( this.getValue( parColumnName ) == parValue ) {
				return this.currentRow;
			}
		}*/
		for( row in this.data ) {
			//alert( this.data[row][parColumnName] + '-' + parValue );
			if( this.data[row][parColumnName] == parValue ) {
				return row;
			}
		}
		return -1;
	}
	
	/**
	 * Projde cely RS a nad kazdym radkem provede akci
	 * @return true / false ( EOF )
	 * 
	 * Priklad:
	 * while( this.objednavkaData.foreach( ) == true ) {
	 *		this.objednavkaData.setValue( 'cena', 123 );	
	 *	}
	 * 
	 */
	this.foreach = function( )
	{
		// test na bezici foreach -> inicializace
		if( this.foreachFlag == false ) {
			this.currentRow = -1;
		}
		this.foreachFlag = true;
				
		// test na EOF
		if( this.currentRow + 1 == this.rowCount ) {
			this.currentRow = 0;
			this.foreachFlag = false;
			return false;
		} else {
			this.currentRow++;
			return true;
		}
	}
	
	/**
	 * Importuje data
	 * @param parData - Data RS ( indexovane pole asociovanych poli )
	 *
	 */
	this.importData = function( parData )
	{
		// test na prazdna data
		if( parData.length > 0 ) {
			// vytvoreni columnListu
			var columnList = parData[0];
			for( columnName in columnList ) {
				this.columnList.push( columnName );
			}
			
			// naplneni dat
			this.data = parData;
			
			// posunuti curzoru na 1. radek
			this.currentRow = 0;
			// nastaveni citace radku
			this.rowCount = this.data.length;
		}
	}
	
	/**
	 * Exportuje data
	 * @return Data RS ( indexovane pole asociovanych poli )
	 *
	 */
	this.exportData = function( )
	{
		return this.data;
	}	
	
	/**
	 * Prida sloupec
	 *
	 */
	this.addColumn = function( parColumnName )
	{
		this.columnList.push( parColumnName );		
	}
	
	/**
	 * Prida prazdny radek
	 *
	 */
	this.addRow = function( )
	{
		var rsRow = Array( );
		// vysosnuti seznamu sloupcu
		for( var item in this.columnList ) {
			var columnName = this.columnList[item];
			rsRow[columnName] = null;
		}
		// pridani radku
		this.data.push( rsRow );
		// posunuti curzoru na novy radek
		this.currentRow = this.rowCount;
		// nastaveni citace radku
		this.rowCount += 1;
	}
	
	/**
	 * Nastavi hodnotu v danem radku a sloupci
	 *
	 */
	this.setValue = function( parColumnName, parValue )
	{
		this.data[this.currentRow][parColumnName] = parValue;		
	}
	
	/**
	 * Ziska hodnotu v danem radku a sloupci
	 *
	 */
	this.getValue = function( parColumnName )
	{
		return this.data[this.currentRow][parColumnName];		
	}
	
	/**
	 * Dumpuje obsah RS
	 *
	 */
	this.dump = function( parTitle )
	{
		var dumpStr = '<style>.dump_table {	z-index: 1000; text-align: center; font-size: 10px;} .dump_table th { background-color: fuchsia; } .dump_table td { background-color: aqua; } </style>';
		dumpStr += '<h1 style="color: navy">' + parTitle + '</h1>';
		dumpStr += '<table border="1" cellspacing="1" cellpadding="1" class="dump_table">';
		dumpStr += '<tr><th>' + this.columnList.join( '</th><th>' ) + '</th></tr>';
		for( rowIndex in this.data ) {
			var row = this.data[rowIndex];
			dumpStr += '<tr>';
			for( columnName in row ) {
				dumpStr += '<td>' + row[columnName] + '</td>';
			}
			dumpStr += '</tr>';
		}		
		dumpStr += '</table>';
		dump( dumpStr );
		dumpStr = '';		
	}
}


/**
 * Objekt Template
 * Slouzi k dynamickemu managementu obsahu
 * 
 * Implementuje operace pro nasledujici promenne:
 * 		skalarni promenna
 * 		data objektu RS
 * 		vypadavaci sekce
 * 
 * Priklad:
 *		>>> Template example <<<
 *		<br><br>
 *		<div id="tmpl_str" name="tmpl_str"></div>
 *		<script>
 *		// definice promennych
 *		var var1 = 123;
 *		var arData = [
 *				{ "col1" : 11, "col2" : 12, "col3" : 13  },
 *				{ "col1" : 21, "col2" : 22, "col3" : 23  },
 *				{ "col1" : 31, "col2" : 32, "col3" : 33  },
 *			];
 *		var if_var2 = true;
 *		var if_var4 = false;
 *		var var3 = '456';
 *		var var5 = '789';
 *		
 *		// definice sablony
 *		var tmplStr = 'Skalarni promenna: {var1}<br><br>Data RS: <table border="1">{rs_data}<tr><td>{rs_data.col1}</td><td>{rs_data.col2}</td><td>{rs_data.col3}</td></tr>{/rs_data}</table><br>Vypadavaci sekce:<br>Promenna se zobrazi >>>{if_var2}{var3}{/if_var2}<<<<br>Promenna se nezobrazi >>>{if_var4}{var5}{/if_var4}<<<';
 *		
 *		// naplneni a vyrendrovani sablony
 *		var tmpl = new Template( );
 *		tmpl.loadTemplate( tmplStr );
 *		tmpl.setProperty( "var1", var1 );
 *		tmpl.setProperty( "rs_data", arData );
 *		tmpl.setProperty( "if_var2", if_var2 );
 *		tmpl.setProperty( "if_var4", if_var4 );
 *		tmpl.setProperty( "var3", var3 );
 *		tmpl.setProperty( "var5", var5 );
 *		
 *		var tmplStr = tmpl.render( );
 *		
 *		// zobrazeni vyrendrovaneho obsahu
 *		innerHTMLWrite( 'tmpl_str', tmplStr, false );
 *		</script>
 *		<br>
 *		>>> Template example <<<
 *
 */
function Template( )
{
	// property
	this.template = '';
	this.property = [];
	
	/**
	 * Natahne sablonu
	 *
	 */
	this.loadTemplate = function( parTemplateStr )
	{
		// osetreni aktivnich znaku
		parTemplateStr = parTemplateStr.replace( '\'', '\'' );
		
		this.template = "this.template = '" + parTemplateStr + '\';';		
	}
	
	/**
	 * Naplni hodnotu promenne
	 *
	 */
	this.setProperty = function( parTagName, parTagValue )
	{
		// test na skalarni promennou, vypadavaci sekci nebo data RS
		if( parTagValue instanceof Array ) {
			// data RS
			this.iterate( parTagName, parTagValue );
		} else if( parTagValue == true || parTagValue == false ) {
			// vypadavaci sekce
			if( parTagValue == true ) {
				this.template = this.template.replace( '{' + parTagName + '}', '' );
				this.template = this.template.replace( '{/' + parTagName + '}', '' );
			} else {
				var beginTag = '{' + parTagName + '}';
				var endTag = '{/' + parTagName + '}';
				var posBeginTag = this.template.indexOf( beginTag );
				var posEndTag = this.template.indexOf( endTag ) + endTag.length;
				var subStr = this.template.substring( posBeginTag, posEndTag );
				this.template = this.template.replace( subStr, '' );
			}
		} else {
			// skalarni promenna
			this.template = this.template.replace( '{' + parTagName + '}', parTagValue );
			this.property[ parTagName ] = parTagValue;
		}
	}
	
	/**
	 * Pripravi naplneni RS
	 *  
	 */
    this.iterate = function( parTagName, parTagValue )
    {
	    // {var} -> this.doIterate($this->pole, '
	    this.template = this.template.replace( '{' + parTagName + '}', '\' + this.doIterate( \'' + parTagName + '\', \'' );
	    
	    // {/var} -> ')
	    this.template = this.template.replace( '{/' + parTagName + '}', '\') + \'' );
	    
	    // registrace property
	    this.property[parTagName] = parTagValue;
    }
    
    
    // naplni RS
    this.doIterate = function( parPropertyName, parTemplate  )
    {
	    propertyValue = this.property[parPropertyName];
	    ret = "";
	    
	    for( row in propertyValue ) {
		    templateTmp = parTemplate;
		    for( columnName in propertyValue[row] ) {
		    	var columnValue = propertyValue[row][columnName];
		    	
		    	// test na boolean promennou
		    	if( typeof columnValue == 'boolean' ) {
		    		// boolean promenna
		    		// vypadavaci sekce bude zobrazena
					if( columnValue == true ) {
						templateTmp = templateTmp.replace( '{' + parPropertyName + '.' + columnName + '}', '' );
						templateTmp = templateTmp.replace( '{/' + parPropertyName + '.' + columnName + '}', '' );
					} else {
						// vypadavaci sekce nebude zobrazena
						var beginTag = '{' + parPropertyName + '.' + columnName + '}';
						var endTag = '{/' + parPropertyName + '.' + columnName + '}';
						var posBeginTag = templateTmp.indexOf( beginTag );
						var posEndTag = templateTmp.indexOf( endTag ) + endTag.length;
						var subStr = templateTmp.substring( posBeginTag, posEndTag );
						templateTmp = templateTmp.replace( subStr, '' );
					}
		    	} else {
		    		// skalarni promenna
		    		templateTmp = templateTmp.replace( '{' + parPropertyName + '.' + columnName + '}', columnValue );	
		    	}
		    }
		    ret += templateTmp;
	    }
	    return ret;
    }
    
    /**
     * Vrati retezec sablony 
     */
    this.render = function(  )
    {
		//alert( this.template );
		eval( this.template );
		//alert( this.template );
		return this.template;
    }
	
	
	/**
	 * Vrati sablonu
	 *
	 */
	this.getTemplate = function()
	{
		return this.template;
	}
}


/**
 * Vrati html element s danym jmenem
 * @param parElementName Nazev html elementu
 * @return html element / null
 *
 */
function getElement( parElementName )
{
	return document.getElementById( parElementName );
}


/**
 * Vrati hodnotu html elementu s danym jmenem ( Id )
 * @param elementName Nazev html elementu
 * @return html element.value / null
 *
 */
function getElementValue( parElementName )
{
	var e = document.getElementById( parElementName );
	return e.value; 
}


/**
 * Provede http redirect na dane url
 * @param parUrl url adresa 
 * 
 */
function httpRedirect( parUrl )
{
	window.location = parUrl;
}

/**
 * Do daneho html prvku vypise text
 * 
 */
function innerHTMLWrite( parElementName, parText, parAdd )
{
	var eElement = getElement( parElementName );
	
	if( parAdd == true ) {
		var text = eElement.innerHTML + parText;
	} else {
		var text = parText;
	}
	eElement.innerHTML = text;
}

/**
 * Vypise info text
 * ve strance musi byt prvek
 * <span name="dump" id="dump"></span>
 */
function dump( parMsg )
{
	var eDump =  getElement( 'dump' );
	var strDump = eDump.innerHTML + parMsg;
	
	eDump.innerHTML = strDump;
}

/**
 * Převezme GET parametr a vrátí jeho hodnotu nebo null, pokud ho nenajde.
 * 
 */
function getParam( parName )
{
	name = parName.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
	var regexS = "[\\?&]"+name+"=([^&#]*)";
	var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return null;
  else
    return results[1];
}

/**
 * Odesle pozadavek pres POST.
 * 
 * @param string parStrUrl
 * @param array arElementList
 * 
 */
function postToHost(parStrUrl, arElementList)
{
    // create the new form
    var submitForm = document.createElement("FORM");
    document.body.appendChild(submitForm);
    submitForm.method = "POST";
    
    // create new hidden elements and add to form
    for(var elementKey in arElementList) {
        var newElement = document.createElement("input");
        newElement.type = "hidden";
        newElement.name = elementKey;
        newElement.id = elementKey;
        newElement.value = arElementList[elementKey];
        submitForm.appendChild(newElement);
    }
    
    // set Url and submit form
    submitForm.action= parStrUrl;
    submitForm.submit();
}
/******************************* Obsolete section - everything can be done in jQuery *******************************/
