// ***************************************************************************************
// Popis:       obecn� funkce
// Autor:       Tomas Mares
// Datum:       23.8.2004
// Historie:
// ***************************************************************************************

function bConfirmDelete (sURL, sQuery)
// potvrzeni vymazani dat
{
    if (confirm (sQuery)) self.location.href = sURL;
    return false;
}

function bHelp (sTopic,sURLParams)
// nove okno s napovedou
{
    window.open ('help.php?topic='+sTopic+'&'+sURLParams,'help','top=220, left=120, width=660,height=700, toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
    return false;
}

/**
* open new window with content of order for print
*
* @param	string	sURL
* @return	boolean			false
*/
function bOrderSummary (sURL)
{
    window.open (sURL,'summary','top=220, left=120, width=660,height=700, toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
    return false;
}

/**
* open new window with order for supplier for print
*
* @param	string	sURL
* @return	boolean			false
*/
function bPrintOrderSupplier (sURL)
{
	window.open (sURL,'supplier','top=220, left=120, width=660,height=700, toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
	return false;
}

/**
* open new window with invoice for print
*
* @param	string	sURL
* @return	boolean			false
*/
function bOrderInvoice (sURL)
{
    window.open (sURL,'invoice','top=100, left=120, width=660,height=700, toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
    return false;
}

function bEtiket (sURL)
{
//    window.open (sURL,'invoice','top=100, left=120, width=400,height=500, toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
    window.open (sURL,'invoice',' width=760,height=250, toolbar=no,location=no,directories=no,status=yes,scrollbars=auto, resizable=yes');
    return false;
}

function bReclamationPrint (sURL)
{
    window.open (sURL,'invoice','top=150, left=120, width=660,height=400, toolbar=no,location=no,directories=no,status=no,scrollbars=yes');
    return false;
}

function bRedir(sURL)
// presmerovani
{
    self.location.href = sURL;
    return false;
}

/**
* returns ASCII code of pressed key
*
* @param	event	e
* @return	integer		ASCII code
*/
function nGetKey (e)
{
	var code;

	if (!e)
		var e = window.event;	//MSIE
	if (e.keyCode)
		code = e.keyCode;		//IE and Mozilla/Gecko
	else
		if (e.which)
			code = e.which;		//NN4
	return code;
}

/**
* check pressed key, allow only number and date separators
* requires function nGetKey
* usage: <input type="text" onKeyPress="return bDateKey(event);">
*
* @param	event	eX
* @return	boolean		ASCII code
*/
function bDateKey (eX)
{
	nKey = nGetKey (eX);
	// allowed: Tab, Delete, BackSpace ,left cursor, right cursor, slash, comma,
	if (nKey == 9 || nKey == 46 || nKey == 8 || nKey == 37 || nKey == 39 || nKey == 47 || nKey == 44)
		return true;

	if (nKey<48 || nKey>57)
		return false;
}

/**
* check pressed key, allow only number
* requires function nGetKey
* usage: <input type="text" onKeyPress="return bNumericKey(event);">
*
* @param	event	eX
* @return	boolean		ASCII code
*/
function bNumericKey (eX)
{
	nKey = nGetKey (eX);
	// allowed: Tab, Delete, BackSpace ,left cursor, right cursor
	if (nKey == 9 || nKey == 46 || nKey == 8 || nKey == 37 || nKey == 39 || nKey == 13)
		return true;

	if (nKey<48 || nKey>57)
		return false;
}


function bNumericKeyPersonal (eX, sFormular)
{
	nKey = nGetKey (eX);
	if (nKey == 13) sFormular.submit();
	// allowed: Tab, Delete, BackSpace ,left cursor, right cursor
	if (nKey == 9 || nKey == 46 || nKey == 8 || nKey == 37 || nKey == 39 || nKey == 13)
		return true;

	if (nKey<48 || nKey>57)
		return false;
}

/**
* check pressed key, allow only number with floating point
* requires function nGetKey
*
* @param        event       eX
* @return       boolean         ASCII code
*/
function bFloatNumericKey (eX)
{
    var nKey = nGetKey (eX);
    // allowed: Tab, Delete, BackSpace, cursor, comma and point
    if (nKey == 8 || nKey == 9 || nKey == 37 || nKey == 39 || nKey == 46 || nKey == 44)
        return true;

    if (nKey < 48 || nKey > 57)
        return false;
}

/**
* check credit card number XXXX XXXX XXXX XXXX
*
* @param	string	sNumber
* @return	boolean
*/
function IsCreditCardNr (sNumber)
{
	//REM boudetovi se kontrola kreditkarty neibila, takze povolime cisla a mezery
	/*re = /^[0-9]{4} [0-9]{4} [0-9]{4} [0-9]{4}$/;*/
	 re = /^[0-9 ]*$/;
	return sNumber.search(re) == 0;
}

/**
* check email addres
*
* @param    string  sEmail  email address
* @return   boolean
*/
function IsEmail (sEmail)
{
    re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
    return sEmail.search(re) == 0;
}

function getBarcodes(sBarCode)
{
	var bc = new Barcode();
	var val = "";
	val = sBarCode; 
	bc.setCodeTable(bc.codeB()); 
	bc.setParentElement(bc.types[1]);
	bc.encode(val, bc.types[1], false, false);
}

function Money(b) 
{
  return ((A=Math.abs(b))<0.005) ? ' 0.00' : Sign(b) + EjU(A) 
}

function EjU(b) 
{
	b += 0.005 ; 
	var Integ = Math.floor(b)
 	return Integ + '.' + LZ(Math.floor(b*100) - Integ*100) 
}

function Sign(y) 
{
	return(y>0?'+':y<0?'-':' ')
}

function LZ(x) {return(x<0||x>9?"":"0")+x}

function nove_okno_calendar(URL)
{
	window.open(URL,'','width=240,height=143,toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=no,resizable=no, top=250, left=320');
}

function nove_okno_cis_stavy(URL)
{
	window.open(URL,'','width=300,height=200,toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=yes,resizable=no, top=250, left=320');
	return false;
}

function nove_okno_nahled(URL)
{
	iMyWidth = (window.screen.width/2) - (250 + 10);
	iMyHeight = (window.screen.height/2) - (150 + 25);
	iMyHeight = 50;
	iMyWidth = 50;
	Fokus = window.open(URL,'','width=300,height=200,toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=no,resizable=yes, top=' + iMyHeight + ', left=' + iMyWidth + ', screenX=' + iMyWidth + ',screenY=' + iMyHeight);
	Fokus.focus();
	return false;
}

