/*
 * jQuery Extension
 * http://www.honlapteszt.hu/
 *
 * Copyright (c) 2009 Verdes János
 * Dual licensed under the MIT and GPL licenses.
 *
 */

function populateElement(selector, defvalue) {
    jQuery(selector).each(function() {
        if(jQuery.trim(this.value) == "") {
            this.value = defvalue;
        }
    });
  
    jQuery(selector).focus(function() {
        if(this.value == defvalue) {
            this.value = "";
        }
    });
    
    jQuery(selector).blur(function() {
        if(jQuery.trim(this.value) == "") {
            this.value = defvalue;
        }
    });
}



/*
 * Document.Ready | Form CAPTCHA
 */
var vnobotform_load=false
var vnobotformpass=''
function formcaptcha() {                               
    jQuery("form.nobot").submit(function() {                   
            mi2=new Array("ad","ch","ec")
            var mi=88;var dc="hlia";var mas="";mas=parseInt(dc+mi+dc);mas+="";mas=mas.substr(1,1);
            mas=String.fromCharCode(mas.charCodeAt(0)+10)        
            faction=self.location.href
            if (faction.charAt(faction.length-1)!='/') {
                faction+='/'
            }
            if (typeof(jQuery(this).attr('antiboturl'))!='undefined') {
                faction=jQuery(this).attr('antiboturl')+'/'
            } 
            faction+='chec'+mas             
            if (vnobotformpass==jQuery(this).attr("id")) {                
                jQuery("#jquery-overdiv-nobotform-load p.fc").html(vnobotform_m1)
                jQuery("#jquery-overdiv-nobotform-load div.lbr").hide()
                jQuery("#jquery-overdiv-nobotform-load p.res").html(vnobotform_m2)
                jQuery(this).attr("action",faction.replace(/\/check$/,"/apply"))                
                return true
            } else {                
                jQuery("#jquery-overdiv-nobotform-load p.res").html('')
                jQuery("#jquery-overdiv-nobotform-load p.res2").html('')
                jQuery("#jquery-overdiv-nobotform-load div.lbr").show()
                nobotform_on()
                jQuery.post(faction,jQuery(this).serialize(),function(data) {                    
                    data=data.split('[rn]');
                    if (data[0]=='[0]') {
                        jQuery("#jquery-overdiv-nobotform-load div.lbr").hide()
                        jQuery("#jquery-overdiv-nobotform-load").css("height","280px")
                        jQuery("#jquery-overdiv-nobotform-load p.res").html(data[1])
                        jQuery("#jquery-overdiv-nobotform-load p.res2").html('<button onclick="nobotform_off()">'+vnobotform_m3+'</button>')
                    } else {
                        vnobotformpass=data[0]
                        jQuery("form#"+vnobotformpass).submit()
                    }                    
                }) 
                return false;
            }            
    })
}

jQuery(document).ready(function() {
    formcaptcha()    
})

function nobotform_on() {
    if (vnobotform_load) {
        var arrPageSizes = ___getPageSize();        
        var arrPageScroll = ___getPageScroll();
        jQuery('#jquery-overdiv-nobotform').show().fadeTo("fast",0.33);        
        jQuery('#jquery-overdiv-nobotform-load').css({
                    top:	            arrPageScroll[1]+75,
        		    left:	            Math.round((arrPageSizes[2]-450)/2)
    			}).show();    	
    } else {
        vnobotform_load=true
        var arrPageSizes = ___getPageSize();        
        var arrPageScroll = ___getPageScroll(); 
        jQuery('body').append('<div id="jquery-overdiv-nobotform"></div><div id="jquery-overdiv-nobotform-load"><p class="fc">'+vnobotform_chk+'...</p><div class="lbr"><img src="/images/core/loading-bar.gif?'+Math.round(Math.random() * 999999999)+'" /></div><p class="res">&nbsp;</p><p class="res2"></p></div>');        
        jQuery('#jquery-overdiv-nobotform').css({
                    position:           'absolute',
                    top:                '0px',
                    left:               '0px',
                    zIndex:             '9988',
    				backgroundColor:	'#FFF',
    				opacity:			0,
    				width:				arrPageSizes[0],
    				height:				arrPageSizes[1]
    			}).fadeTo("fast",0.33);
    	jQuery('#jquery-overdiv-nobotform-load').css({
                    position:           'absolute',
                    top:	            arrPageScroll[1]+75,
        		    left:	            Math.round((arrPageSizes[2]-450)/2),
                    zIndex:             '9999',
                    width:              '450px',
                    height:             '150px'
    			}).show();
    			
    }    
}

function nobotform_off() {
    jQuery('#jquery-overdiv-nobotform').fadeTo("fast",0).hide();
    jQuery('#jquery-overdiv-nobotform-load').hide();
}

         /**
		 * getPageSize() by quirksmode.com
		 *
		 * @return Array Return an array with page width, height and window width, height
		 */
		function ___getPageSize() {
			var xScroll, yScroll;
			if (window.innerHeight && window.scrollMaxY) {	
				xScroll = window.innerWidth + window.scrollMaxX;
				yScroll = window.innerHeight + window.scrollMaxY;
			} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
				xScroll = document.body.scrollWidth;
				yScroll = document.body.scrollHeight;
			} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
				xScroll = document.body.offsetWidth;
				yScroll = document.body.offsetHeight;
			}
			var windowWidth, windowHeight;
			if (self.innerHeight) {	// all except Explorer
				if(document.documentElement.clientWidth){
					windowWidth = document.documentElement.clientWidth; 
				} else {
					windowWidth = self.innerWidth;
				}
				windowHeight = self.innerHeight;
			} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
				windowWidth = document.documentElement.clientWidth;
				windowHeight = document.documentElement.clientHeight;
			} else if (document.body) { // other Explorers
				windowWidth = document.body.clientWidth;
				windowHeight = document.body.clientHeight;
			}	
			// for small pages with total height less then height of the viewport
			if(yScroll < windowHeight){
				pageHeight = windowHeight;
			} else { 
				pageHeight = yScroll;
			}
			// for small pages with total width less then width of the viewport
			if(xScroll < windowWidth){	
				pageWidth = xScroll;		
			} else {
				pageWidth = windowWidth;
			}
			arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
			return arrayPageSize;
		};
		 /**
		 * getPageScroll() by quirksmode.com
		 *
		 * @return Array Return an array with x,y page scroll values.
		 */
		function ___getPageScroll() {
			var xScroll, yScroll;
			if (self.pageYOffset) {
				yScroll = self.pageYOffset;
				xScroll = self.pageXOffset;
			} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
				yScroll = document.documentElement.scrollTop;
				xScroll = document.documentElement.scrollLeft;
			} else if (document.body) {// all other Explorers
				yScroll = document.body.scrollTop;
				xScroll = document.body.scrollLeft;	
			}
			arrayPageScroll = new Array(xScroll,yScroll);
			return arrayPageScroll;
		};

/**
* getPosition() by quirksmode.com
*
* @return Array Return an array with x,y cursor coords values.
*/		
		
function ___getPosition(e) {
    e = e || window.event;
    var cursor = {x:0, y:0};
    if (e.pageX || e.pageY) {
        cursor.x = e.pageX;
        cursor.y = e.pageY;
    } 
    else {
        var de = document.documentElement;
        var b = document.body;
        cursor.x = e.clientX + 
            (de.scrollLeft || b.scrollLeft) - (de.clientLeft || 0);
        cursor.y = e.clientY + 
            (de.scrollTop || b.scrollTop) - (de.clientTop || 0);
    }
    return cursor;
}

		
/**
 * addOverlay() function
 */

var addOverlay_bool=false
function addOverlay() {
    if (addOverlay_bool) {
        jQuery('#jquery-overdiv').hide().fadeIn();
    } else {
        addOverlay_bool=true
        jQuery('body').append('<div id="jquery-overdiv"></div>');
        var arrPageSizes = ___getPageSize();
        jQuery('#jquery-overdiv').css({
                    position:           'absolute',
                    top:                '0px',
                    left:               '0px',
                    zIndex:             '90',
                    width:              '100%',
                    height:             '500px',
    				backgroundColor:	'#000',
    				opacity:			0.8,
    				width:				arrPageSizes[0],
    				height:				arrPageSizes[1]
    			}).hide().fadeIn();
    }
}

function closeOverlay() {
    jQuery('#jquery-overdiv').fadeOut();
}
	

/**
 * POPunder message div
 */		
function addMessage(text,xwidth,xheight) {
    text='<div style="width:'+xwidth+'px;height:'+xheight+'px;padding:20px 20px 20px 20px">'+text+'</div>'
    if (!addOverlay_bool) {
        jQuery('body').append('<div id="jquery-overdiv-msg"></div>');        
        jQuery('#jquery-overdiv-msg').css({
                    position:           'absolute',
                    top:                '-1000px',
                    left:               '-1000px',
                    zIndex:             '120',
                    width:              (xwidth+40)+'px',
                    height:             (xheight+40)+'px',
                    border:             '2px solid #CCC',
    				backgroundColor:	'#FFF'
    			}).html('<div onclick="removeMessage()" class="ws_removemessage"></div>'+text).hide();
    } else {
        jQuery('#jquery-overdiv-msg').html('<div onclick="removeMessage()" class="ws_removemessage"></div>'+text)
    }
    addOverlay()
    var arrPageSizes = ___getPageSize();
    var arrPageScroll = ___getPageScroll(); 
    $('#jquery-overdiv-msg').css({
            top:	arrPageScroll[1]+Math.round((arrPageSizes[3]-xheight)/2),
    		left:	Math.round((arrPageSizes[2]-xwidth)/2)
        }).hide().show("slow");    
}
function removeMessage() {
    jQuery('#jquery-overdiv-msg').hide("slow");
    closeOverlay()
}	

/**
 * TR pointer
 */     

function tr_pointer() {
    jQuery("tr[id=pointer]").hover(function() {
        jQuery(this).find('td').css("backgroundColor","#FFFFCC")
    },function() {
        jQuery(this).find('td').css("backgroundColor","#FFFFFF")
    })
}

/**
 * webshop filter
 */

function ws_fil() {
    loading_on()
    query =jQuery("#ws_src_q").val()+"-"
    query+=jQuery("#ws_src_mi").val()+"-"
    query+=jQuery("#ws_src_ma").val()+"-"
    query+=jQuery("#ws_flt_katid").val()+"/"
        
    tmp=new Array    
    
    ws_filters=jQuery("#ws_filter_form input:checkbox:checked").each(function () {
        vl=jQuery(this).val().split('/')                
        if (typeof(tmp[vl[0]])=='undefined') {
            tmp[vl[0]]=vl[1]
        } else {
            tmp[vl[0]]+=';'+vl[1]
        }
    })
    for (var k in tmp) {
        query+=k+"_"+tmp[k]+"/"
    }
    var currentTime = new Date()
    currentTime=currentTime.getTime()
    jQuery.post("/ajax.php",{base: query,random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
        jQuery("#ws_main_div").html(data)
        init_imageover()
        loading_off()
    })    
}

function ws_fil2(vector) {
    checked=jQuery("#ws_cb"+vector).attr("checked")
    if (checked) {
        jQuery("#ws_cb"+vector).removeAttr("checked")
    } else {
        jQuery("#ws_cb"+vector).attr("checked","true")
    }
    ws_fil()        
    return false
}

/**
 * webshop top search
 */

function ws_do_src() {
    txa=jQuery("#ws_src_q").val()
    jQuery("#ws_flt_q").val(txa)
    txa=jQuery("#ws_src_mi").val()
    jQuery("#ws_flt_mi").val(txa)
    txa=jQuery("#ws_src_ma").val()
    jQuery("#ws_flt_ma").val(txa)
    jQuery("#ws_filter_form").attr("action","/post")
    jQuery("#ws_filter_form").submit()
}

var ws_cbenable=true
jQuery(document).ready(function() {
    jQuery("form[id=ws_src_form]").submit(function() {        
        ws_do_src()
        return false
    })    
    szminit()
})

function szminit() {    
    jQuery("div[id=fbg] div :checkbox").click(function() {
        ws_cbenable=false
        ws_fil()
    })
    jQuery("div[id=fbg] div").hover(function() {
        jQuery(this).css("text-decoration","underline")
    },function() {
        jQuery(this).css("text-decoration","none")
    }).click(function() {        
        if (ws_cbenable) {
            if (jQuery(this).find(":checkbox").attr('checked')==false) {
                jQuery(this).find(":checkbox").attr('checked',true)
            } else {
                jQuery(this).find(":checkbox").attr('checked',false)
            }
            ws_fil()
        } else {
            ws_cbenable=true
        }
    })
    jQuery("div[id=fbg] p[class=mt] a").click(function() {  
        loading_on();
        var currentTime = new Date()
        currentTime=currentTime.getTime()
        jQuery.post("/ajax.php",{szmenu: jQuery(this).parent().attr("id"),random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
            data=data.split('[/$/]')            
            jQuery("p#"+data[0]).html(data[1])
            jQuery("div[id=fbg] div :checkbox").unbind('click')
            jQuery("div[id=fbg] div").unbind('hover').unbind('click')
            jQuery("div[id=fbg] p[class=mt] a").unbind('click') 
            szminit()           
            loading_off()
        })
    })
}


function ws_compare() {
    target=''
    jQuery("input[name=cmpr\\\[\\\]]:checked").each(function() {
        target+=jQuery(this).val()+'-'
    })
    if (target!='') {
        window.open('/compare/'+target.substr(0,target.length-1)+'.html')
    }
}
function kosarba(unid,mennyiseg,fizar,pagereload) {
    loading_on()
        jQuery.post("/ajax.php",{"kosar" : unid ,"item" : mennyiseg ,"fizar" : fizar},function(data) {
            if (pagereload) {
                top.location.reload()
            } else {
                top.location.href='/cart/'
                /*data=data.split("[rn]")
                jQuery("#ws_cart").html(data[0]) 
                addMessage(data[1],400,300)*/
            }
        })        
}

function add_cart(unid,fizar) {
    if (arguments.length==2) {
        kosarba(unid,document.getElementById('item_'+unid).value,fizar,false)
    } else {
        kosarba(unid,document.getElementById('item_'+unid).value,fizar,true)
    }
}

function add_cart2(unid,fizar) {    
    kosarba(unid,1,fizar,false)
}

var _openeddiv=0
var _opentimer=false

function dd_i(id) {
    
    if (_opentimer!=false) {
        clearTimeout(_opentimer)
    }
    
    if (_openeddiv!=0) {
        document.getElementById("dd_"+_openeddiv).style.display='none'
    }
    _openeddiv=id
    document.getElementById("dd_"+_openeddiv).style.display='block'
}

function dd_o() {    
    _opentimer=setTimeout('dd_o2()',200)
}

function dd_o2() {    
    document.getElementById("dd_"+_openeddiv).style.display='none'
    _openeddiv=0
}

/**
* Image mouseover 
*/
var jarrPageSizes  = '';
jQuery(function() {
    jarrPageSizes  = ___getPageSize();
    jQuery('body').append('<div id="jquery-imageover"></div>');    
    jQuery('#jquery-imageover').css({
                position:           'absolute',
                top:                '-200px',
                left:               '-200px',
                zIndex:             '11',
				backgroundColor:	'#FFF',
				border:             '1px solid #999',
				width:              '10px',
				height:             '10px'
			}).hide();
    init_imageover()
})
function init_imageover() {
    jQuery("img[rel=tooltip]").hover(function(e) {        
        src=jQuery(this).attr("src").split('/')
        //tmp=src[3].split('x')
        //iew=Math.round(tmp[0]*3)
        //ieh=Math.round(tmp[1]*3)
        
        iew=400
        ieh=400
        
        f=src[4]        
        pos_jimover(e.pageX,e.pageY,iew,ieh)
        pos_addimg(f,iew,ieh)         
    },function() {
        jQuery('#jquery-imageover').hide()
    }).mousemove(function(e) {        
        src=jQuery(this).attr("src").split('/')
        //tmp=src[3].split('x')
        //iew=Math.round(tmp[0]*3)
        //ieh=Math.round(tmp[1]*3)
        
        iew=400
        ieh=400
        
        pos_jimover(e.pageX,e.pageY,iew,ieh)       
    
    })
}
function pos_jimover(cursorX,cursorY,w,h) {
    var jarrPageScroll = ___getPageScroll();
    jtop=cursorY+35-Math.round(h/2)
    jleft=cursorX+35
    
    if (jtop+h>jarrPageScroll[1]+jarrPageSizes[3]) {
        jtop-=Math.round(h/2)
        jtop-=35
    }
    
    if (jleft+w>jarrPageScroll[0]+jarrPageSizes[2]) {
        jleft-=w
        jleft-=35
        jleft-=35
    }
    
    if (jtop<jarrPageScroll[1]) {
        jtop=jarrPageScroll[1]
    }
    
    jQuery('#jquery-imageover').css({
                top:                jtop,
                left:               jleft,
				width:              w,
				height:             h
			}).show();
			
    
}

function pos_addimg(f,w,h) {
    jQuery('#jquery-imageover').html('<img src="/webimages/thumbs/'+w+'x'+h+'/'+f+'" width="'+w+'" height="'+h+'">')
}

/**
 * sorrendezés ajax
 */
function ajax_setorder(order) {
    var currentTime = new Date()
    currentTime=currentTime.getTime()
    jQuery.post("/ajax.php",{setorder: order,random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
        ws_fil()
    })
}

/**
 * csillagozás, kívánság lista ajax
 */
function add_star(order) {
    loading_on()
    var currentTime = new Date()
    currentTime=currentTime.getTime() 
    jQuery.post("/ajax.php",{add_star: order,random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
        data=data.split('[rn]')
        classname=$("a[unid=_"+data[0]+"]").attr('class')
        $("div[unid=A_"+data[0]+"]").html(data[1])      
        if (data[2]!='m') {
            if (classname=='defwish') {
                $("a[unid=_"+data[0]+"]").attr('class','defstarwish')
            } else {
                $("a[unid=_"+data[0]+"]").attr('class','defstar')
            }            
        } else {
            if (classname=='defstarwish') {
                $("a[unid=_"+data[0]+"]").attr('class','defwish')
            } else {
                $("a[unid=_"+data[0]+"]").attr('class','defnorm')
            }
        }
        $("div#ws_star_list").html(data[3])
        loading_off()               
    })
}
function add_wish(order) {
    loading_on()
    var currentTime = new Date()
    currentTime=currentTime.getTime()
    jQuery.post("/ajax.php",{add_wish: order,random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
        data=data.split('[rn]')
        classname=$("a[unid=_"+data[0]+"]").attr('class')
        $("div[unid=B_"+data[0]+"]").html(data[1])        
        if (data[2]!='m') {            
            if (classname=='defstar') {
                $("a[unid=_"+data[0]+"]").attr('class','defstarwish')
            } else {
                $("a[unid=_"+data[0]+"]").attr('class','defwish')
            }            
        } else {
            if (classname=='defstarwish') {
                $("a[unid=_"+data[0]+"]").attr('class','defstar')
            } else {
                $("a[unid=_"+data[0]+"]").attr('class','defnorm')
            }
        }
        $("div#ws_wish_list").html(data[3])
        loading_off()               
    })
}

/**
 * loading
 */
 
/**
 * loading
 */
 

var vraddOverlay_load=false
pic1= new Image(220,19); 
pic1.src='/images/core/loading-bar.gif';
function loading_on() {
    if (vraddOverlay_load) {
        jQuery('#jquery-overdiv-load').show().fadeTo("fast",0.33);
        var arrPageSizes = ___getPageSize();        
        var arrPageScroll = ___getPageScroll();
        jQuery('#jquery-overdiv-msg-load').css({
                    top:	            arrPageScroll[1]+Math.round((arrPageSizes[3]-19)/2),
        		    left:	            Math.round((arrPageSizes[2]-220)/2)
    			}).show();
    } else {
        vraddOverlay_load=true
        jQuery('body').append('<div id="jquery-overdiv-load"></div><div id="jquery-overdiv-msg-load"><img src="/images/core/loading-bar.gif" width="220" height="19"></div>');
        var arrPageSizes = ___getPageSize();        
        var arrPageScroll = ___getPageScroll(); 
        jQuery('#jquery-overdiv-load').css({
                    position:           'absolute',
                    top:                '0px',
                    left:               '0px',
                    zIndex:             '9988',
    				backgroundColor:	'#FFF',
    				opacity:			0,
    				width:				arrPageSizes[0],
    				height:				arrPageSizes[1]
    			}).fadeTo("fast",0.33);
    	
    	jQuery('#jquery-overdiv-msg-load').css({
                    position:           'absolute',
                    top:	            arrPageScroll[1]+Math.round((arrPageSizes[3]-19)/2),
        		    left:	            Math.round((arrPageSizes[2]-220)/2),
                    zIndex:             '9999',
                    width:              '220px',
                    height:             '19px'
    			}).show();
    }
}

function loading_off() {
    jQuery('#jquery-overdiv-load').fadeTo("fast",0).hide();
    jQuery('#jquery-overdiv-msg-load').hide();
} 

jQuery(function() {
    jQuery("#emailsubmit").click(function() {
        if (jQuery("#ekatalog").val()=='') {
            alert("Kérem adja meg az e-mail címét!")
        } else {
            var currentTime = new Date()
            currentTime=currentTime.getTime()
            jQuery.post("/ajax.php",{ekatalog: jQuery("#ekatalog").val(),ref:top.location.href,random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
                //
            })
            alert("Köszönöm, hamarosan értesítjük e-mailben!")
        }
    })
    jQuery("#emailsubmit2").click(function() {
        if (jQuery("#ekatalog2").val()=='') {
            alert("Kérem adja meg az e-mail címét!")
        } else {
            var currentTime = new Date()
            currentTime=currentTime.getTime()
            jQuery.post("/ajax.php",{ekatalog: jQuery("#ekatalog2").val(),ref:top.location.href,random1:Math.round(Math.random() * 999999999),time:currentTime},function(data) {
                //
            })
            alert("Köszönöm, hamarosan értesítjük e-mailben!")
        }
    })
})    
function login() {    
    addMessage('<form id="doform_login" action="http://nobot/" class="nobot" method="post" antiboturl="/login">'
    +'<input type="hidden" name="doformid" value="doform_login" />'
    +'<input type="hidden" name="referer" value="'+self.location.href+'" />'
    +'<b style="font-size:22px">Bejelentkezés</b><br /><br /><table class="p10" width="100%"><tr>'
    +'<td width="120">E-mail:</td><td><input name="email" style="width:200px" /></td></tr><tr>'
    +'<td>Jelszó</td><td><input type="password" name="password" style="width:200px" /></td></tr><tr><td>&nbsp;</td>'
    +'<td><input type="submit" value="BEJELENTKEZÉS..." class="loginbutton" /></td></tr></table></form>'
    +'<p>&nbsp;</p><form id="doform2_login" class="nobot" action="http://nobot/" method="post" antiboturl="/my-account/lost-password"><b style="font-size:22px">Elfelejtett jelszó</b><br /><br /><table class="p10" width="100%"><tr><td width="120">Elfelejtett jelszó:</td><td><input name="email" style="width:200px" /></td></tr><tr><td>&nbsp;</td><td><input type="submit" value="Jelszó küldése e-mailben..." class="loginbutton" /></td></tr></table><input type="hidden" name="doformid" value="doform2_login" /></form></td><td></div>'
    ,493,370)
    formcaptcha()
}

var vnobotform_chk='Adatok ellenőrzése';
var vnobotform_m1='Az oldal töltődik';
var vnobotform_m2='Az ellezőrzés nem talált hibát. Kérem várjon, míg az oldal betöltődik';
var vnobotform_m3='&lt;&lt;&lt; vissza a javításhoz';
var ws_regsuccess='';
                                                                                                                                                                                                                                                                                                                                                                                                                
$(function() {
    if (self.location.hash.indexOf("password-email-sent")!=-1) {
            alert("A megadott e-mail címre elküldtem az e-mail címhez tartozó jelszót")
    }
})
    
    
