function Buttons(){
    inputs = document.getElementsByTagName('input');
    for(i = 0; i < inputs.length; i++){
        if(inputs[i].type != 'image')
        inputs[i].className+=' input';
        if(inputs[i].type == 'submit' || inputs[i].type == 'button')
        inputs[i].className+=' button';
    }
}
function Init(){

    Buttons();
	 var p=document.getElementById('selectoptions[attr_1]');
	if (p&&p[0].value=='---') {
	p.remove(0);
	p.selectedIndex=0;
	}
    /**
    * wy³±czamy autocomplete zeby nie kolidowac z hintami ajaxowymi
    * _i_ zachowac zgodnosc z xhtml
    */
   // var s = document.getElementById('search_query_words');
  //  s.setAttribute("autocomplete", "off");
//  	$("h3.toggler + ul:not([class*=visib])").slideUp().addClass("togglable");
	$("ul.toggle-on").prev("h3").css({"background-position":"98% -15px"});
 // 	$("h3.toggler + ul:not([class*=visib])").addClass("togglable");
  	$("h3.toggler + ul").addClass("togglable");
	
	
	$("h3.toggler").click(function(e){
			if (!$(this).next("ul").hasClass('toggle-on')){
				$(this).css({"background-position":"98% -15px"}).siblings('.toggler').css({"background-position":"98% top"})
		  		$(this).next("ul").slideDown().addClass('toggle-on').siblings(".togglable").slideUp().removeClass('toggle-on');//animate({"height":0});
				$(this).attr("title","Kliknij, aby rozwin±æ");
			}
			else{
				$(this).css({"background-position":"98% top"}).attr("title","Kliknij, aby rozwin±æ");		
			$(this).next("ul").slideUp().removeClass('toggle-on');
			
			//{"height":0});
		//		$(this).css({"background-position":"98% top"}).attr("title","Kliknij, aby rozwin±æ");		
			}
	  //		e.preventDefault();
		}).attr("title","Kliknij, aby rozwin±æ");
	
/*	$("h3.toggler").toggle(function(e){
			$(this).css({"background-position":"98% -15px"}).attr("title","Kliknij, aby zwin±æ").siblings('.toggler').css({"background-position":"98% top"});
	  		$(this).next("ul").slideDown().siblings(".togglable").slideUp().removeClass('toggle-on');//animate({"height":0});
	  //		e.preventDefault();
		},function(e){
			$(this).css({"background-position":"98% top"}).attr("title","Kliknij, aby rozwin±æ");		
			$(this).next("ul").slideUp().removeClass('toggle-on');//animate({"height":"100%"},"slow");
	 //		e.preventDefault();
//			e.stopPropagation();			
		}).attr("title","Kliknij, aby rozwin±æ");
		
		});*/
/*		$("h3.toggler").click(function(e){
			if (!$(this).next("ul").hasClass('toggle-on')){
				$(this).css({"background-position":"98% -15px"}).siblings('.toggler').css({"background-position":"98% top"})
		  		$(this).next("ul").slideDown().addClass('toggle-on').siblings(".togglable").slideUp().removeClass('toggle-on');//animate({"height":0});
			}
	  //		e.preventDefault();
		}).attr("title","Kliknij, aby rozwin±æ");*/
		
		$("h3.toggler a").click(function(){
			location.href=$(this).attr("href");
		});
		
	 /*	$("#spacer").css({"height":"300px","position":"relative","padding-bottom":"5px"});
		$("#photoCrop").css({"height":"300px","overflow":"hidden","position":"absolute","top":0,"left":0,"z-index":"10"}).hoverIntent(function(){
			var hg=$("#mainPhoto").css("height");
			$(this).animate({"height":hg});
		},function(){
			var hg=$("#spacer").css("height");
			$(this).animate({"height":hg});
		});*/
}

function showMovie(nr,closeText){
	var dc=document.getElementById('movieCont');
	if (dc&&dc.style){
	
		var pageSize	= getPageSize();

	var objBody		= document.getElementsByTagName("body").item(0);
	
	dc.style.height = pageSize[1] + "px";
	dc.style.display = 'block';

	
	//	dc.style.display='block';
		dc.innerHTML="<img src=\"/themes/base/user_came/img/blk.gif\" alt=\"\"/><div ><a href=\"javascript:closeMovie();\">"+closeText+"</a><object id=\"movieObject\" data=\"/photo/_flash/"+nr+".swf\" type=\"application/x-shockwave-flash\"><param name=\"movie\" value=\"/photo/_flash/"+nr+".swf\"/><param name=\"quality\" value=\"high\"/><param name=\"bgcolor\" value=\"#000000\"/></object></div>";
		if ((document.all) && (navigator.userAgent.indexOf('Opera')== -1)){
		dc.innerHTML="<img src=\"/themes/base/user_came/img/blk.gif\" alt=\"\"/><div><a href=\"javascript:closeMovie();\">"+closeText+"</a> <object ><param name=\"movie\" value=\"/photo/_flash/"+nr+".swf\"/><param name=\"quality\" value=\"high\"/><param name=\"bgcolor\" value=\"#000000\"/></object><embed id=\"jacp\" src=\"/photo/_flash/"+nr+".swf\" quality=\"high\" type=\"application/x-shockwave-flash\" bgcolor=\"#000000\" width=\"360\" height=\"300\"></div>";
		}

	
	
	}

}
function closeMovie(){
	var dc=document.getElementById('movieCont');
	if (dc&&dc.style){
		dc.style.display='none';
		dc.innerHTML="";
	
	}

}
function imageScale(sender, max_size) {
    p=0;
    if (sender.width > max_size) {
        p = (max_size / sender.width);
    }
    else {
        if (sender.height > max_size) {
            p = (max_size / sender.height);
        }
    }
    if(p > 0) {
        sender.width = p * sender.width;
    }
}


function searchOver (what) {
    document.getElementById(what).className = 'HintHighlight';
    showHints();
}
function searchOut (what) {
    document.getElementById(what).className = 'HintUnHighlight';
}
function searchDown (str) {
    document.getElementById('search_query_words').value = str;
}
var timeout=1000;
var oldQuery='';
function hintMe() {
    query=document.getElementById('search_query_words').value;
    /*hint.className='searchDivHidden';*/
    document.getElementById('searchHint').style.visibility='visible';
    if (query != oldQuery) {
        oldQuery=query;
        if (query && query.length>3) {
            window.setTimeout('xajax_searchHints(query);',timeout);
        } else {
            hideHints();
        }
    }
}
function showHints() {
    query=document.getElementById('search_query_words').value;
    if (query && query.length>3) {
        hint=document.getElementById('searchHint');
        if (hint.style.visibility!='visible') hint.style.visibility='visible';
    }
}
function hideHints() {
    hint=document.getElementById('searchHint');
    hint.style.visibility='hidden';
}
function auto_off() {

    alert(s.toString);
}

function hide_list(list)
{
    list.style.display='none';
}

function show_list(list)
{
    list.style.display='block';
}

function visible(list)
{
    if ((list.style.display=='block') || list.style.display=='')
    return true;

    return false;
}

function _$(id)
{
    return document.getElementById(id);
}

function ShowBox(id, ms, timer) {
    var timer=(timer==null) ? 0 : timer;
    var objref=document.getElementById(id);

    var scrOfX = 0, scrOfY = 0;
    if( typeof( window.pageYOffset ) == 'number' ) {
        //Netscape
        scrOfY = window.pageYOffset;
        scrOfX = window.pageXOffset;
    } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
        //DOM
        scrOfY = document.body.scrollTop;
        scrOfX = document.body.scrollLeft;
    } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
        //IE6
        scrOfY = document.documentElement.scrollTop;
        scrOfX = document.documentElement.scrollLeft;
    }
    //  wysrodkowanie w pionie
    var topBoxOffset=scrOfY+(screen.availHeight/3)-(objref.offsetHeight/2);
    //	wysrodkowanie w poziomie
    var leftBoxOffset=scrOfX+(screen.availWidth/2)-(objref.offsetWidth/2);

    objref.style.top=topBoxOffset+"px";
    objref.style.left=leftBoxOffset+"px";
    if (timer < ms) {
        objref.style.display="block";
        timer+=10;
        setTimeout("ShowBox('"+id+"',"+ms+","+timer+")",1);
    } else {

        objref.style.display="none";

    }
}

function zagielCheckOrderValue(value, message) {
    if (value < 100) {
        window.alert(message);
        return false;
    } else {
        return true;
    }
}

function zagielProductCalcLink(shopNo, value, message) {

    if (zagielCheckOrderValue(value, message)) {
        window.open('https://www.zagiel.com.pl/kalkulator/index_smart.php?action=getklientdet_si_rata&shopNo='+shopNo+'&goodsValue='+value,'Policz_rate','width=630,height=500,directories=no,location=no,menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');
    }
}

//*******************************************************************************/
// getPageSize() - Returns array with page width, height and window width, height
// Core code from - quirksmode.org, Edit for Firefox by pHaez
//*******************************************************************************/
function getPageSize() {	
	var xScroll, yScroll, windowWidth, windowHeight;
	var isFrame=false;
	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.scrollWidth;
		yScroll = (isFrame ? parent.innerHeight : self.innerHeight) + (isFrame ? parent.scrollMaxY : self.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.getElementsByTagName("html").item(0).offsetWidth;
		yScroll = document.getElementsByTagName("html").item(0).offsetHeight;
		
		// Strict mode fixes
		xScroll = (xScroll < document.body.offsetWidth) ? document.body.offsetWidth : xScroll;
		yScroll = (yScroll < document.body.offsetHeight) ? document.body.offsetHeight : yScroll;
	}
	
	if (self.innerHeight) {	// all except Explorer
		windowWidth = (isFrame) ? parent.innerWidth : self.innerWidth;
		windowHeight = (isFrame) ? parent.innerHeight : 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.getElementsByTagName("html").item(0).clientWidth;
		windowHeight = document.getElementsByTagName("html").item(0).clientHeight;
		
		// Strict mode fixes...
		windowWidth = (windowWidth == 0) ? document.body.clientWidth : windowWidth;
		windowHeight = (windowHeight == 0) ? document.body.clientHeight : windowHeight;
	}
	
	// for small pages with total height/width less then height/width of the viewport
	var pageHeight = (yScroll < windowHeight) ? windowHeight : yScroll;
	var pageWidth = (xScroll < windowWidth) ? windowWidth : xScroll;
	
	return new Array(pageWidth, pageHeight, windowWidth, windowHeight);
};

function validateEmail(elementValue){
var emailPattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/; return emailPattern.test(elementValue); } 

function checkForm(){
	if (document.zapytaj.imie.value==""){
		alert(fillName);
		return false;
	}
	else if (document.zapytaj.adres1.value==""){
		alert(fillAddress);
		return false;
	}
	else if (document.zapytaj.mail.value==""){
		alert(fillMail);
		return false;
	}
	else if (!validateEmail(document.zapytaj.mail.value)){
		alert(correctMail);
		return false;
	}
 /*	else if (document.zapytaj.firma.value==""){
		alert(fillCompany);
		return false;
	}
 	else if (document.zapytaj.telefon.value==""){
		alert(fillPhone);
		return false;
	}*/
 	else if (document.zapytaj.tresc.value==""){
		alert(fillQuestion);
		return false;
	}
	return true;
}

