// email obfuscator
jQuery(document).ready(function(){
    jQuery('a.email').each(function(){
        e = this.rel.replace('/','@');
        this.href = 'mailto:' + e;
        
        jQuery(this).text(e);
    });
});

function ShowWindow(url, width, height, resizable) 
{    
    if (isNaN(width)) { width = 740; resizable = 1; }
    if (isNaN(height)) height = 566;
    
    width = (width) ? width+18 : width;
    
    if ( isNaN(resizable) ) { resizable = 0; }
    
    LeftPosition = (screen.width)  ? (screen.width-width)/2 : 100;
    TopPosition  = (screen.height) ? (screen.height-height)/2 : 100;
    
    var winPopup = window.open(url,'okienko','width='+width+',height='+height+',top='+TopPosition+',left='+LeftPosition+',resizable='+resizable+',scrollbars=yes,menubar=no');
}

jQuery(document).ready(function() {

    // MENU
    jQuery("div#menu #m1, div#menu #m2, div#menu #m3, div#menu #m4").bind("mouseover",function(){
        if ( jQuery(this).attr("class") != 'active' ){
            //jQuery(this).css("background-position", "0px -32px");
            jQuery(this).css("opacity", 0.8);
        }
    });

    jQuery("div#menu #m1, div#menu #m2, div#menu #m3, div#menu #m4").bind("mouseout",function(){
        if ( jQuery(this).attr("class") != 'active' ){
            //jQuery(this).css("background-position", "0px 0px");
            jQuery(this).css("opacity", 1.0);
        }
    });
    
    
    /*********BUTTONS **************/
    // OBLICZ CENE
    jQuery("a.oblicz_cene").bind("click", function(){
        //jQuery(this).attr("href", "javascript:ShowWindow('https://www.link4.pl/kalkulator_ubezpieczenia_OC_AC/?action=calculator',970,650)");
    });
    // WS_LOGOWANIE
    jQuery(".WSLogowanie").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('https://www.link4.pl/kalkulator_ubezpieczenia_OC_AC/?action=calculator#',970,650)");
    });    
    // OBLICZ SKLADKE
    jQuery("a.oblicz_skladke").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('https://www.link4.pl/kalkulator_ubezpieczenia_OC_AC/?action=calculator',970,650)");
    });
    // KONTAKT Z LINK4
    jQuery("a.kontakt_z_link4").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('/index.php/mid/4/fid/501/form_ver/2', 600, 566)");
    });
    
    
    
    // WNIOSEK
    jQuery("a.popup_wniosek").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('https://www.link4.pl/kalkulator_ubezpieczenia_OC_AC/?action=calculator',970,650)");
    });
    
    
    // ZAPAMIETANA POLISA
    jQuery("a.popup_zap_polisa").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('https://www.link4.pl/kalkulator_ubezpieczenia_OC_AC/?action=calculator#',970,650)");
    });
    
    // KONTAKT
    jQuery("a.popup_kontakt").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('/index.php/mid/4/fid/501/form_ver/1', 600, 566)");
    });
    
    // KONTAKT
    jQuery("a.popup_kontakt2").bind("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('/index.php/mid/4/fid/501/form_ver/2', 600, 566)");
    });
    
    // POMOC 
    jQuery("a.popup").one("click", function(){
        jQuery(this).attr("href", "javascript:ShowWindow('"+this.href+"', 730, 566, 1)");
    });    
    
    // POPUP
    jQuery("a.popup_window").bind("click", function(){
        var img = jQuery(this).attr("href");
        var size = jQuery(this).attr("rel");
        
        size = (size) ? ","+size : "";
       
        jQuery(this).attr("href", "javascript:ShowWindow('../popup.php?img="+img+"'"+size+")");
    });
    
    // KONTAKT TOP MENU - dla Life podmieniamy linki
	/*
    var url = new String(document.location);
    if ( url.match(/i_10_|art_10_/) )
    {
        jQuery("#t_icon3").attr("href", jQuery("#t_icon3").attr("rel"));
    }
    */
    var phref = new String(document.location);
    if ( phref.match(/internal|test/) )
    {
        // przepisywanie
		if (phref.match(/mid=3|mid=42/)) {
			$('a').each(function() {
				if (this.href!="" && this.href!=null) {
					if (this.href.match(/art_[0-9]{1,}_[0-9]{1,}/)) {
						
						var tb = this.href.split("_");
						this.href = "/index.php?mid=3&fid=2&article_id="+tb[2]+"&sp="+tb[1];
					}
					if (this.href.match(/i_[0-9]{1,}_[0-9]{1,}/)) {
						
						var tb = this.href.split("_");
						this.href = "/index.php?mid=42&fid=259&page_id="+tb[2]+"&sp="+tb[1];
					}					
				}
			});
        }
    }
    
});


function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
