function validate_email(form_id, email, err){
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var address = document.forms[form_id].elements[email].value;
    if (reg.test(address) == false) {
        document.getElementById(err).innerHTML = "wpisz poprawny e-mail";
        return false;
    }
}

var newsletter_email='';
function validate_newsletter() {
	var ret=false;
	
	var errTxt='wpisz poprawny e-mail';
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	
	if ($("#newslemail").val()!=errTxt) {
		newsletter_email = $("#newslemail").val();
	    if (reg.test(newsletter_email) == false) {
	    	$("#newslemail").addClass("emailerr");
	    	$("#newslemail").val(errTxt);
	    	$("#newslemail").click(function() {
	    		$("#newslemail").val(newsletter_email);
	    		$("#newslemail").removeClass("emailerr");
	    		$("#newslemail").unbind('click');
	    	});
	    }
	    else {
	    	ret=true;
	    }
	}
	return ret;
}

function tabs_click(tabs, def){
    tablist = tabs.split("|");
    var defid = def.id;
    
    for (i = 0; i < tablist.length; i++) {
        if (tablist[i] == defid) {
            $('#' + tablist[i]).attr("src", $('#' + tablist[i]).attr("src").replace(/(\_[oa])?\.gif/, "_a.gif"));
            $('#' + tablist[i] + "_d").show();
        }
        else {
            $('#' + tablist[i]).attr("src", $('#' + tablist[i]).attr("src").replace(/(\_[oa])?\.gif/, ".gif"));
            $('#' + tablist[i] + "_d").hide();
        }
    }
}

function tabs_init(tabs, def){
    tablist = tabs.split("|");
    
    for (i = 0; i < tablist.length; i++) {
        $('#' + tablist[i]).addClass("hand");
        $('#' + tablist[i]).click(function(){
            tabs_click(tabs, this)
        });
        $('#' + tablist[i]).mouseover(function(){
            if (!this.src.match(/\_a\.gif/)) 
                this.src = this.src.replace(/(\_o)?\.gif/, "_o.gif")
        });
        $('#' + tablist[i]).mouseout(function(){
            if (!this.src.match(/\_a\.gif/)) 
                this.src = this.src.replace(/(\_o)?\.gif/, ".gif")
        });
        if (tablist[i] == def) {
            $('#' + tablist[i]).attr("src", $('#' + tablist[i]).attr("src").replace(/(\_o)?\.gif/, "_a.gif"));
            $('#' + tablist[i] + "_d").show();
        }
        else {
            $('#' + tablist[i] + "_d").hide();
        }
    }
}

function getElementsById(sId){
    var outArray = new Array();
    if (typeof(sId) != 'string' || !sId) {
        return outArray;
    };
    
    if (document.evaluate) {
        var xpathString = "//*[@id='" + sId.toString() + "']"
        var xpathResult = document.evaluate(xpathString, document, null, 0, null);
        while ((outArray[outArray.length] = xpathResult.iterateNext())) {
        }
        outArray.pop();
    }
    else 
        if (document.all) {
        
            for (var i = 0, j = document.all[sId].length; i < j; i += 1) {
                outArray[i] = document.all[sId][i];
            }
        }
        else 
            if (document.getElementsByTagName) {
            
                var aEl = document.getElementsByTagName('*');
                for (var i = 0, j = aEl.length; i < j; i += 1) {
                
                    if (aEl[i].id == sId) {
                        outArray.push(aEl[i]);
                    };
				};
				
			};
    
    return outArray;
}

function mainmenu(){
    $(" #nav ul ").css({
        display: "none"
    }); // Opera Fix
    $(" #nav li").hover(function(){
        $(this).find('ul:first').css({
            visibility: "visible",
            display: "none"
        }).show(50);
    }, function(){
        $(this).find('ul:first').css({
            visibility: "hidden"
        });
    });
}


function bm(m){
    return m + '@' + location.hostname.replace(/^(www\.)/, "")
}

function wm(m){
    document.write('<a h' + 'ref="mai' + 'lto:' + bm(m) + '">' + bm(m) + '</' + 'a>');
}

function addOption(value, text, id){
    selectbox = document.getElementById(id);
    
    var optn = document.createElement("OPTION");
    optn.text = text;
    optn.value = value;
    
    selectbox.options.add(optn);
}

function go(l, n){
    if (n) {
        window.open(l, '_blank');
    }
    else {
        window.location = l;
    }
}

function colorize_rows(id){
    var trs = document.getElementById(id).getElementsByTagName("tr");
    var name = '';
    for (var i = 0; i < trs.length; i++) {
        name = trs[i].className;
        trs[i].onmouseover = function(){
            this.className = 'over';
        }
        if (name == '') {
            trs[i].onmouseout = function(){
                this.className = '';
            }
        }
        else {
            trs[i].onmouseout = function(){
                this.className = name;
            }
        }
    }
}

function BuildUrl(id){
	
    var str = $('#prodform').attr("action");
    
	if (id == 1) {
		if ($('#sel1').val() !='') {
			str = str + $('#sel1').val()+"/";;
		}
	}
	else {
		if ($('#sel1').val() !='') {
			str = str + $('#sel1').val()+"/";
		}
		if ($('#sel2').val() !='') {
			str = str + $('#sel2').val()+"/";
		}
		
		if ($('#sel4').val() =='' && $('#sel3').val()!='') {
			str = str + $('#sel3').val()+".html";
		}
		
		if ($('#sel3').val()=='' && $('#sel4').val()!='') {
			str = str + $('#sel4').val()+".html";
		}
		
		if ($('#sel4').val() !='' && $('#sel3').val()!='') {
			str = str + $('#sel3').val()+","+$('#sel4').val()+".html";;
		}
	}
		
    $('#prodform').attr("action", str).submit();
	
    return true;
}

var Pid=new Array();

function doOnLoad(){
    $('#showroom').load(defUrl + 'get.php?id=1');

	if (Pid.length>0) {
		Show(0);	
	}
	
}

(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
})(jQuery);


function cut(string, start, length) {
	
	myTruncatedString = string.substring(start,length);
	return myTruncatedString;
	
}

function showAbuse(elem) {
	$("#abuse #abuseErr").hide();
	$("#abuse").show();
	
	$("#abuse #abuseID").val(elem);
	var e = $("#"+elem);
	var offset = e.offset();

	$("#abuse").offset({ top: (offset.top-80), left: offset.left });
	
}
function abuseReset() {
	$("#abuse textarea").val('');
	$("#abuse").hide();
}

function abuseSent() {
	if ($("#abuse textarea").val()=='') {
		$("#abuse #abuseErr").hide();
		$("#abuse #abuseErr").animate({"opacity": "show"}, 500);
	}
	else {
		$.post(defUrl + 'Naduzycia/', { text: $("#abuse textarea").val(), url: window.location.href, id: $("#abuse #abuseID").val() },
		function(data){
			if (data=='OK') {
				abuseReset();
			}
			else {
				$("#abuse #abuseErr").hide();
				$("#abuse #abuseErrSave").hide();
				$("#abuse #abuseErrSave").animate({"opacity": "show"}, 500);
			}
		});
	}
}



   function Show(id){
           
		    for (i = 0; i < Pid.length; i++) {
                document.getElementById(Pid[i]).style.display = "none";
				document.getElementById("t"+Pid[i]).style.backgroundColor = "";
				document.getElementById("t"+Pid[i]).style.color = "black";
            }
            
            document.getElementById(id).style.display = "";
			document.getElementById("info").innerHTML = "";
			document.getElementById("t"+id).style.backgroundColor = "#BB1925";
				document.getElementById("t"+id).style.color = "white";

        }



