/**
 * common javascript functions
 *
 * @package	Topmodel
 */

/**
 * 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)
		return true;

	if (nKey<48 || nKey>57)
		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 credit card number XXXX XXXX XXXX XXXX
*
* @param    string  sNumber
* @return   boolean
*/
function IsCreditCardNr (sNumber)
{
	//REM zakaznici asi neumi spravne vyplnit cislo kreditky, 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 PopupRelated (sURL)
{
	window.open (sURL, "popup_win", "location=no, status=no, scrollbars=yes, toolbar=no, menubar=no, top=100, left=100")
	return false;
}

function BonusHowWorks (sURL)
{
	window.open (sURL,'','top=220, left=120, width=550,height=240, toolbar=no,location=no,directories=no,status=no,scrollbars=no');
	return false;
}

function PopupAllOffers (sURL)
{
	window.open (sURL, "popup_win", "location=no, status=no, scrollbars=yes, toolbar=no, menubar=no, top=100, left=100, width=260,height=550")
	return false;
}

function nove_okno_cis_tnt(URL)
{
	window.open(URL,'','width=800,height=400,toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=yes,resizable=yes, top=30, left=30');
}


function print_win(URL)
{
	window.open(URL,'','width=800,height=400,toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=yes,resizable=yes, top=30, left=30');
	return false;
}

function nove_okno_nahled(URL)
{
	//iMyWidth = (window.screen.width/2) - (250 + 10);
	//iMyHeight = (window.screen.height/2) - (150 + 25);
	iMyWidth = 10;
	iMyHeight = 10;
	iMyHeight = 50;
	Fokus = window.open(URL,'','width=800,height=600,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;
}

function open_win_help_order_shipping(URL)
{
	window.open(URL,'','width=500,height=150,toolbar=no,location=no,directories=no,status=no,menuBar=no,scrollbars=no,resizable=yes, top=30, left=30');
	return false;
}

/*Zobrazuje popisek k baneru za pozici mysi*/
function info_banner_aero_expo(text){
	document.getElementById('id_info').innerHTML = text;
	document.getElementById('id_info').className = 'visible_info';
	nastav_pozici('id_info');
}

var is_DHTML=window.Event?true:false;
var Y_pos = 1;
var X_pos = 1;
function zjisti_pozici(evnt)
{
	//X_pos=evnt.pageX;
	//Y_pos=evnt.pageY;
	
	if (is_DHTML && (navigator.userAgent.indexOf("Opera")== -1)) {
   	if (evnt.pageX){
      		X_pos=evnt.pageX;
      		Y_pos=evnt.pageY;
    	}
  	}
  	else{
    		X_pos=(event.clientX + document.body.scrollLeft);
    		Y_pos=(event.clientY + document.body.scrollTop);
  	}
      	
      	
}
document.onmousemove = zjisti_pozici;

function nastav_pozici(info)
{
	document.getElementById('id_info').style.left = (X_pos + 10)+'px';
	document.getElementById('id_info').style.top=(Y_pos+10)+'px';
}