//
// Termék hozzáadása a kosárhoz
//
function addProductToCart(productId){
	var addProductToCartRequest=new Ajax.Request('index.php?site=AJAXAddProductToCart&productId='+productId, {method: 'post',onSuccess:function(transport){refreshCartQuantity(transport.responseText);}});
}
function addPackageToCart(packageId){
	var addPackageToCartRequest=new Ajax.Request('index.php?site=AJAXAddPackageToCart&packageId='+packageId, {method: 'post',onSuccess:function(transport){refreshCartQuantity(transport.responseText);}});
}

function createFBLB(){
	setTimeout(function () {$('FBLB_cont').innerHTML=('<iframe id="faceBookLikeBoxIFrameOrig" src="http://www.facebook.com/plugins/likebox.php?href=http%3A%2F%2Fwww.facebook.com%2Fscolarklub&amp;width=280&amp;colorscheme=light&amp;show_faces=false&amp;stream=true&amp;header=false&amp;height=395" scrolling="no" frameborder="0" style="border:none; background:#FFF; overflow:hidden; width:280px; height:395px;" allowTransparency="true"></iframe>');}, 1000);
}

function refreshCartQuantity(newQuantity){
	if($('headerTopMiddleCartQuantity')!=''){
		$('headerTopMiddleCartQuantity').update(newQuantity);
		$('headerTopMiddleCartQuantityText').update('db / fizet&eacute;s');
		$('headerShoppingCart').style.color='#c42b24';
	}
}

function setAddedToCartTooltip(element){
	if(element.length){
		element.each(function(elementItem){
			if(elementItem.className=='bookLimited'){
				/*new Tip(elementItem.up(),'<span style="color:red;">Ez a term&eacute;k. korl&aacute;tozottan kaphat&oacute;.<br />Elk&eacute;pzelhető, hogy a beszerz&eacute;se t&ouml;bb hetet is ig&eacute;nybe vesz.</span>',{
					duration: 0.3,
					showOn: 'mouseover',
					hideOn: false,
					hideAfter: 1,
					stem: 'topMiddle',
					hook: { target: 'bottomMiddle', tip: 'topMiddle' },
					offset: { x: 0, y: -10 },
					width: 'auto'
				});*/
				new Tip(elementItem,'Kos&aacute;rba ker&uuml;lt a korl&aacute;tozottan kaphat&oacute; term&eacute;k.<br />Elk&eacute;pzelhető, hogy a term&eacute;k beszerz&eacute;se t&ouml;bb hetet is ig&eacute;nybe vesz.',{
					duration: 0.3,
					showOn: 'click',
					hideOn: false,
					hideAfter: 2,
					stem: 'bottomMiddle',
					hook: { target: 'topMiddle', tip: 'bottomMiddle' },
					offset: { x: 0, y: 10 },
					width: 'auto'
				});
			}
			else{
				new Tip(elementItem,'A term&eacute;k a kos&aacute;rba ker&uuml;lt.',{
					duration: 0.3,
					showOn: 'click',
					hideOn: false,
					hideAfter: 2,
					stem: 'bottomMiddle',
					hook: { target: 'topMiddle', tip: 'bottomMiddle' },
					offset: { x: 0, y: 10 },
					width: 'auto'
				});
			}
		});
	}
	else{
		//Ha bizonyos elemet akarunk, nem listát, tehát az element.length UNDEFINED
		if(element.length!==0){			
			new Tip(element,'A term&eacute;k a kos&aacute;rba ker&uuml;lt.',{
			duration: 0.3,
			showOn: 'click',
			hideOn: false,
			hideAfter: 2, 
			stem: 'bottomMiddle',
			hook: { target: 'topMiddle', tip: 'bottomMiddle' },
			offset: { x: 0, y: 10 },
			width: 'auto'
			});
		}
	}
}

function searchOnEnterKey(e){
    if (!e) e = window.event;
    if (e.keyCode) code = e.keyCode;
    else if (e.which) code = e.which;
    if (code == 13) {
      doSearch();
      return false;
    } else {
      return true;
    }
}
function doSearch(){
	window.location='index.php?site=search&searchString='+encodeURIComponent($F('searchField'));
}

//
// Bal oldali panel magasságának beállítása
//
function setLeftPanelHeight(){
	if(parseInt($('mainPanel').offsetHeight)>parseInt($('leftPanel').offsetHeight)){
		$('leftPanel').style.height=$('mainPanel').offsetHeight+'px';
	}
}

//
// Rövidleírásokból TAG-ek eltávolítása
//
function shortDescRemoveTags(){
	var shortDescs=$$('.bookDescContainer');
	for(i=0;i<shortDescs.length;i++){
		shortDescs[i].innerHTML=shortDescs[i].innerHTML.stripScripts().stripTags();
	}
}

//
// Kijelentkezés
//
function logOut(){
	var logoutRequest=new Ajax.Request('index.php?site=AJAXProcessLogin&logOut=1', {method: 'post',onSuccess:function(transport){refreshPage();}});
}

//
// Aktuális oldal frissítése
//
function refreshPage(){
	//alert(window.location);
	window.location.reload();
}

//
// string elott és mögött lévo whitespaceek levágása
//
function trimWhiteSpaces(str) { 
    str.replace(/^\s*/, '').replace(/\s*$/, ''); 
   return str;
} 

//Változók kiolvasása URL-bol
//pl: ....php/site=new&foo=bar -> vars['foo']==bar, vars['site']==new
function getUrlVars()
{
    var vars = [], hash;
    var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
	
    for(var i = 0; i < hashes.length; i++)
    {
        hash = hashes[i].split('=');
        vars.push(hash[0]);
        vars[hash[0]] = hash[1];
    }
 
    return vars;
}

//
//Internet Explorer verzió check
//
function getInternetExplorerVersion()
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
  var rv = -1; // Return value assumes failure.
  if (navigator.appName == 'Microsoft Internet Explorer')
  {
    var ua = navigator.userAgent;
    var re  = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
    if (re.exec(ua) != null)
      rv = parseFloat( RegExp.$1 );
  }
  return rv;
}

function checkVersion(){
  var ver = getInternetExplorerVersion();
  if ( ver > -1 ){
    if ( ver >= 7.0 ){
		return true;
	}
    else{
      newLoc = "index.php?site=browserDownload";
	  if(window.location.href.search('browserDownload')==-1){
	  	window.location=newLoc;
	  }
	  return false
	}
  }
  else{
  	return true;
  }
}
