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].className='button';
	}
}
function Init(){
	Buttons();
	/**
	* wyłączamy autocomplete zeby nie kolidowac z hintami ajaxowymi
	* _i_ zachowac zgodnosc z xhtml
	*/
	var s = document.getElementById('search_query_words');
	if (s) s.setAttribute("autocomplete", "off");
	var t1 = document.getElementById('etos');
	if (t1){
	t2=t1.getElementsByTagName('a');
	for(i = 0; i < t2.length; i++){
		t2[i].target="_blank";
	}
	}
}

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 add2fav(){
writeBookmarkLink('http://e-styl.com', 'Drogeria internetowa e-styl.com');
}
function cBL(url, title) {
	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			return window.sidebar.addPanel(title, url, "");
		} else if( window.external ) { // IE Favorite
			return window.external.AddFavorite( url, title); 
		} else if(window.opera && window.print) { // Opera Hotlist
			return true; 
		}
	} catch(err) {
		// do nothing
	}
  //	alert('Could not create a bookmark on your client.\n\nTo return to ' + title + ' you must manually create a bookmark to: \n' + url + '.');
}

function writeBookmarkLink(url, title) {
var tst='Dodaj do ulubionych';
	try {
		if (window.sidebar) { // Mozilla Firefox Bookmark
			return document.write('<a href="#" onclick="cBL(\'' + url + '\', \'' + title + '\')");">'+tst+'</a>'); 
		} else if (window.external) { // IE Favorite
			return document.write('<a href="#" onclick="cBL(\'' + url + '\', \'' + title + '\')");">'+tst+'</a>'); 
		} else if (window.opera && window.print) { // Opera Hotlist
			return document.write('<a rel="sidebar" href="#" onclick="' + url + '" title="' + title + '">'+tst+'</a>');
		} 
	} catch(err) {
		// do nothing
	}
  //	return document.write('To return to ' + title + ' create a bookmark to: <a style="color: white;" href="' + url + '">' + url + '</a>');
  return;	
}

function checkCode(){
	var id1=document.getElementById('post2');
	var id2=document.getElementById('city2');
	var id3=document.getElementById('descript');	
   var regex = /^[0-9]{2}\-[0-9]{3}$/;

	//najpierw sprawdzenie poprawnosci pol	
	if (id1 && id2){
		if (id1.value.length<5){
			alert("Wypełnij kod pocztowy E-PRZESYŁKI");
			return false;		
		}
		else if (!regex.test(id1.value)){
			alert("Popraw kod pocztowy E-PRZESYŁKI:\npowinien być w formacie XX-XXX");
			return false;				
		}
		else if (id2.value.length<1){
			alert("Wypełnij nazwę placówki E-PRZESYŁKI");
			return false;
		}
	}
	
	/* zaczynamy zabawe */
	var str=id3.value.indexOf('*** E-PRZESYŁKA: '); // szukamy poczatku tekstu z e-przesylka

	var end=-1;
	if (str!=-1){
		end=id3.value.indexOf(" ***",str+4); // i konca
		if (end!=-1)
			end+=5;
	}
	var newText="*** E-PRZESYŁKA: "+id1.value+", "+id2.value+" ***"; // nowy tekst
	if (str != -1 && end != -1){
		var toRep=id3.value.substr(str,end-str); // podmieniamy stara zawartosc

		id3.value=id3.value.replace(toRep,newText);
	}
	else{
		id3.value+=newText; // albo dodajemy, jeśli jeszcze nie bylo
	}
	return true;
}
