var init = function() {
    jMenu();
    blocksResize();
}

/* produkty - fiszka usuwanie klasa dla ostatniego li */
function lastLi(param,fi) {
    var liList, ulTag, liTag;
    var ulList = $(param);
    for (var i = 0; i < ulList.length; i++)
    {
	ulTag = ulList[i];
	liList = ulTag.getElementsByTagName("li");
	if (fi == 1)liList[0].className = "firstchild";
	liTag = liList[liList.length - 1];
	liTag.className = "lastchild";
    }
}

/* funkcja do popupow */

function openWindowSc(file,szer,wys,scrollec){
	wys = (!wys)?(300):(wys);
	szer = (!szer)?(400):(szer);
	scrollec = (!scrollec)?('no'):('yes');
	if (ms) var xMax = screen.width, yMax = screen.height
	else if (nn) var xMax = window.outerWidth, yMax = window.outerHeight
	var xOffset = (xMax - szer)/2, yOffset = (yMax - wys)/2; 
	nameOknaP = "PopupLMSc2004" + Math.floor(Math.random()*100000);
	okienko = window.open(file,nameOknaP ,'scrollbars='+scrollec+',height='+wys+',width='+szer+',screenX='+xOffset+',screenY='+yOffset+',top='+yOffset+',left='+xOffset+',resizable=yes');
}
function openMapWindow(){
    window.open('/gazetki/gazetka_15_07_2009/1507_1808_index.html','_blank');
  //  window.open('http://www.domzpomyslem.pl/ ','_blank');
}

function openMapWindow2(){
    window.open('/gazetki/gazetka_06_08_2009/0608_1808_index.html','_blank');
}

function openBanerLink(pos) {
    if ( pos == 1) {
         window.open('/gazetki/gazetka_18_02_2009/1802_0303_index.html ','_blank');
    } else if ( pos == 2 ) {
         window.open('/gazetki/gazetka_04_02_2009/0402_0303_index.html ','_blank');
    }
}

/* uslugi - ustawianie wysokosci bloczkow */
function blocksResize(){    
    if (document.getElementById('cell01') != null ) var block01 = document.getElementById('cell01');
    if (document.getElementById('cell02') != null ) var block02 = document.getElementById('cell02');
    if (document.getElementById('cell03') != null ) var block03 = document.getElementById('cell03');
    if (document.getElementById('cell04') != null ) var block04 = document.getElementById('cell04');    
    
    IE = false;
		
	if (/MSIE (6\.\d+);/.test(navigator.userAgent))
       {
	    if (block01 != null && block02 != null)
	    {
		if (block01.offsetHeight > block02.offsetHeight) block02.style.height = block01.offsetHeight + "px";
		if (block02.offsetHeight > block01.offsetHeight) block01.style.height = block02.offsetHeight + "px";
	    }
	    if (block03 != null && block04 != null)
	    {
		if (block03.offsetHeight > block04.offsetHeight) block04.style.height = block03.offsetHeight + "px";
		if (block04.offsetHeight > block03.offsetHeight) block03.style.height = block04.offsetHeight + "px";
	    }
	   
       }
       else
       {
	    if (block01 != null && block02 != null)
	    {
		if (block01.offsetHeight > block02.offsetHeight) block02.style.minHeight = block01.offsetHeight + "px";
		if (block02.offsetHeight > block01.offsetHeight) block01.style.minHeight = block02.offsetHeight + "px";
	    }
	    if (block03 != null && block04 != null)
	    {
		if (block03.offsetHeight > block04.offsetHeight) block04.style.minHeight = block03.offsetHeight + "px";
		if (block04.offsetHeight > block03.offsetHeight) block03.style.minHeight = block04.offsetHeight + "px";
	    }
       }
}

// dodany hover dla selecta
function showHideBox(id, obj) {
    var el = document.getElementById(id);
    if (obj != null) var bg = document.getElementById(obj);
    if(el.style.display == "block"){
	el.style.display = "none";
	if (obj != null) bg.style.backgroundPosition = "0 0";
    }
    else {
	el.style.display = "block";
	if (obj != null) bg.style.backgroundPosition = "0 -19px";
    }
}

function hideBox(id, obj) {
    document.getElementById(id).style.display = "none";
    if (obj != null) var bg = document.getElementById(obj);
    if (obj != null) bg.style.backgroundPosition = "0 0";
}

function showBox(id, obj) {
    document.getElementById(id).style.display = "block";
    if (obj != null) var bg = document.getElementById(obj);
    if (obj != null) bg.style.backgroundPosition = "0 -19px";
}

function selectItem(box, hidden, value, valueText) {
    document.getElementById(box).innerHTML=valueText;
    document.getElementById(hidden).value=value;
}

function changeMail(id, value) {
    document.getElementById('label_'+id).innerHTML='Adres e-mail';
    document.getElementById(id).innerHTML=value;
    document.getElementById(id).href="mailto:"+value;
     document.getElementById('mail_info').style.display="inline";
}


/* produkty - zmiana tla pod checkboxami */
function labelU(obj) {
    obj.className = "labelU";
    obj.parentNode.style.background = "#ddf7c4";
}
function labelN(obj) {
    obj.className = "labelN";
    obj.parentNode.style.background = "#f2f2f2";
}
function runScript(scriptURL, script_id){
     var head = document.getElementsByTagName('head').item(0)
    var scriptTag = document.getElementById(script_id);
     if(scriptTag)
         head.removeChild(scriptTag);
    script = document.createElement('script');
    script.src = scriptURL;
     script.type = 'text/javascript';
    script.id = script_id;
     head.appendChild(script)

}

function loadContent(el, url) {
    $.ajax( { 
	type:'GET',
	url: url,
	success:function(transport){
	    $(el).html(transport);
	}
    });
}

function cutAdvice(string,id) {				
    //skracanie tekstu dla sifra - optymalnie 116 znakow
    var intro = '';
    var words = string.split(" ");
    for (i=0;i<=words.length;i++)
    {
	if (intro.length <= 100) intro += words[i] + ' ';	
    }
    intro += '...';				    
    if (string.length > 100) document.getElementById(id).innerHTML = intro;
}
// wyszarzanie uslug
function whereServ(city){                
    $('.jquery-selectbox-currentItem').text('zmieñ sklep');
    $('li').removeClass('matched');
    $('li').removeClass('unmatched');
    if (city!=''){	    
	    var sublist = $('li.single-shop');	    	    	    	    
	    for (i=0; i<sublist.length; i++) {		
		var compare = sublist[i].firstChild.innerHTML;		
		var no_space = compare.replace( /\s/g, '_');
		sublist[i].firstChild.innerHTML = no_space;
		var li_parent = sublist[i].parentNode.parentNode.parentNode.parentNode;				
		if( compare != city) {		    		    		    		    		    
		    if (li_parent.className != 'matched'){
			li_parent.className = 'unmatched';
		    }
		}
		if( compare == city) {		    		    
		    li_parent.className = 'matched';
		}
	    }
	    /* drugi loop dla ie */
	    for (j=0; j<sublist.length; j++) {		
		var compare = sublist[j].firstChild.innerHTML;		
		var no_space = compare.replace( /\s/g, '_');
		sublist[j].firstChild.innerHTML = no_space;
		var li_parent = sublist[j].parentNode.parentNode.parentNode.parentNode;				
		if( compare != city) {		    		    		    
		    if (li_parent.className != 'matched'){
			li_parent.className = 'unmatched';
		    }
		}
		if( compare == city) {		    
		    li_parent.className = 'matched';
		}
	    }
    }
    //var new_city = $('.jquery-selectbox-currentItem').text();
    $('.jquery-selectbox-currentItem').text('zmieñ sklep');
    //$('#theShop').text(new_city);
}
function stringReplace(string){
    string = string.replace( /\s/g, '_');
    string = string.replace( /[±]/g, '&#261|');
    string = string.replace( /[æ]/g, '&#263|');
    string = string.replace( /[¡]/g, '&#260|');
    string = string.replace( /[Æ]/g, '&#262|');
    string = string.replace( /[³]/g, '&#322|');
    string = string.replace( /[Ê]/g, '&#280|');
    string = string.replace( /[ê]/g, '&#281|');
    string = string.replace( /[£]/g, '&#321|');
    string = string.replace( /[Ñ]/g, '&#323|');
    string = string.replace( /[ñ]/g, '&#324|');
    string = string.replace( /[¦]/g, '&#346|');    
    string = string.replace( /[¶]/g, '&#347|');
    string = string.replace( /[¬]/g, '&#377|');
    string = string.replace( /[¼]/g, '&#378|');
    string = string.replace( /[¿]/g, '&#380|');    
    string = string.replace( /[¯]/g, '&#379|');    
    string = string.replace( /[ó]/g, '&#243|');    
    string = string.replace( /[Ó]/g, '&#211|');       
    return string;    
}
function stringDecode(string){
    string = string.replace( '&#261|', '±');
    string = string.replace( '&#263|', 'æ');
    string = string.replace( '&#260|', '¡');
    string = string.replace( '&#262|', 'Æ');
    string = string.replace( '&#322|', '³');
    string = string.replace( '&#280|', 'Ê');
    string = string.replace( '&#281|', 'ê');
    string = string.replace( '&#321|', '£');
    string = string.replace( '&#323|', 'Ñ');
    string = string.replace( '&#324|', 'ñ');
    string = string.replace( '&#346|', '¦');    
    string = string.replace( '&#347|', '¶');
    string = string.replace( '&#377|', '¬');
    string = string.replace( '&#378|', '¼');
    string = string.replace( '&#380|', '¿');    
    string = string.replace( '&#379|', '¯');    
    string = string.replace( '&#243|', 'ó');    
    string = string.replace( '&#211|', 'Ó');    
    return string;
}
function show_advice(url) {
    $('#watch_advice param[name=movie]').attr('value',url+'&hl=pl&fs=1&showinfo=0&rel=0');
     $('#watch_advice embed').attr('src',url+'&hl=pl&fs=1&showinfo=0&rel=0');


}
function drogaDoSklepu(szer, dlug) {
    /*szer = szer.replace(/([0-9]{2})\.([0-9]{2})([0-9]{2})([0-9]{1,2})/,'$1\+$2\'$3\.$4',szer);
    dlug = dlug.replace(/([0-9]{2})\.([0-9]{2})([0-9]{2})([0-9]{0,2})/,'$1\+$2\'$3\.$4',dlug);
    
    while (szer.length < 11) {
	szer += '0';
    }
     while (dlug.length < 11) {
	dlug += '0';
    }
     szer += '+N';
     dlug += '+E';
    */
     document.location.href='http://forum.leroymerlin.pl/googlemap/?szer='+szer+'+N&dlug='+dlug+'+E';
     
   /* szer = szer.replace(/\./,'+',szer);
    szer  = szer + '+N';
    dlug = szer.replace(/\./,'+',dlug);
    dlug = dlug + '+E';*/
   // alert(szer+' '+dlug);
    
}
