/**
 * 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_za_mysi(text){
	document.getElementById('id_info').innerHTML = text;
	document.getElementById('id_info').className = 'visible_info';
	nastav_pozici_info('id_info');
}

function popup_prazdniny(text){
	document.getElementById('id_popup_prazdniny').innerHTML = '<img src="images2/popup3/popup-'+text+'.jpg" />';
	document.getElementById('id_popup_prazdniny').className = 'id_popup_prazdniny_visible';
	nastav_pozici_popup('id_popup_prazdniny');
}

var is_DHTML=window.Event?true:false;
var Y_pos = 1;
var X_pos = 1;
function zjisti_pozici(e)
{
	
  if (!e) e = window.event; // works on IE, but not NS (we rely on NS passing us the event)

  if (e)
  { 
    if (e.pageX || e.pageY)
    { // this doesn't work on IE6!! (works on FF,Moz,Opera7)
      X_pos = e.pageX;
      Y_pos = e.pageY;
      algor = '[e.pageX]';
      if (e.clientX || e.clientY) algor += ' [e.clientX] '
    }
    else if (e.clientX || e.clientY)
    { // works on IE6,FF,Moz,Opera7
      X_pos = e.clientX + document.body.scrollLeft;
      Y_pos = e.clientY + document.body.scrollTop;
      algor = '[e.clientX]';
      if (e.pageX || e.pageY) algor += ' [e.pageX] '
    }  
  }

	
	
	//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(lupa)
{
	document.getElementById('id_lupa').style.left = (X_pos + 10)+'px';
	document.getElementById('id_lupa').style.top=(Y_pos+10)+'px';
}

function nastav_pozici_info(lupa)
{
	document.getElementById('id_info').style.left = (X_pos + 10)+'px';
	document.getElementById('id_info').style.top=(Y_pos+50)+'px';
}

function nastav_pozici_vseobecna(id) {
	document.getElementById(id).style.left = (X_pos + 20)+'px';
	document.getElementById(id).style.top=(Y_pos-10)+'px';
}

function nastav_pozici_popup(lupa)
{
	document.getElementById('id_popup_prazdniny').style.left = (X_pos + 20)+'px';
	document.getElementById('id_popup_prazdniny').style.top=(Y_pos-100)+'px';
}

function NajdiPozici(obj) {
		var curleft = curtop = 0;
		if (obj.offsetParent) {
		do {
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		} while (obj = obj.offsetParent);
		}
		return [curleft,curtop];
	}
	
function zobraz_kosik(){
	pozice=NajdiPozici(document.getElementById('cart'));
	leva = pozice[0]-440;
	horni = pozice[1]-12;
	document.getElementById('cart-bublina').style.left=leva+'px';
	document.getElementById('cart-bublina').style.top=horni+'px';
	document.getElementById('cart-bublina').className = 'visible-cart-bublina';
}

function schovej_kosik(){
	document.getElementById('cart-bublina').className = 'skryte-cart-bublina';
}

function nastav_aktivni(OBJECT){
	OBJECT.style.filter = 'alpha(opacity=80)';
	OBJECT.style.opacity = '0.8';
}
	
function nastav_neaktivni(OBJECT){
	OBJECT.style.filter = 'alpha(opacity=100)';
	OBJECT.style.opacity = '1';
}