// konfiguracja sifra
function sifrConf() {
	var arial = {  
	   src: '/swf/sifr.swf' 
	}; 
	
	window.arial = arial;
	
	sIFR.useStyleCheck = true;
	sIFR.activate(arial);
}

function sifrReplace() {
	sIFR.replace(arial, {
		selector: 'a.head'
		,css: ['.sIFR-root {color:#000000; font-size:16px; font-weight:bold; text-decoration:none; cursor:pointer;}']
		,wmode: 'transparent'
	});

	sIFR.replace(arial, {
		selector: 'h3.head, #brands dt, #data > h3, #data div.boxSmall h3, #data form h3, #tools h3'
		,css: ['.sIFR-root {color:#000000; font-size:16px; font-weight:bold;}']
		,wmode: 'transparent'
	});
	
	sIFR.replace(arial, {
		selector: 'dl.press dt a, dl.magazines dt a, dl.websites dt a, dl.projects dt a, #bottomBox h3'
		,css: ['.sIFR-root {color:#000000; font-size:15px; font-weight:bold; cursor:pointer;}']
		,wmode: 'transparent'
	});

	sIFR.replace(arial, {
		selector: '#error #data h2'
		,css: ['.sIFR-root {color:#000000; font-size:16px; font-weight:bold;}']
		,wmode: 'transparent'
	});

	sIFR.replace(arial, {
		selector: '#data h2'
		,css: ['.sIFR-root {color:#ffffff; font-size:16px; font-weight:bold;}']
		,wmode: 'transparent'
	});

}


// otwierania linku o klasie openNew w nowym oknie
function newWindow() {
	var hyperlink = document.getElementsByTagName('a');
	
	for (var i=0; i<hyperlink.length; i++) {
		if (String(hyperlink[i].className).match('openNew')) {
			hyperlink[i].onclick = function () {
				window.open(this.href);
				return false;
			}
		}
	}
}


// drukowanie
function printWindow() {
	var hyperlink = document.getElementsByTagName('a');
	
	for (var i=0; i<hyperlink.length; i++) {
		if (hyperlink[i].className == "print") {
			hyperlink[i].onclick = function () {
				window.open(this.href,"drukuj", "height=600,width=800,top=100,left=100,scrollbars=yes,resizable=yes,status=no");
				return false;
			}
		}
	}
}
function printIt () {
	window.print();
}


// obsluga submenu
function subMenu() {
	var uls = document.getElementById('leftMenu').getElementsByTagName('ul');
	for (var i=0; i<uls.length; i++) {
		
		if (String(uls[i].className).match('subMenu') && !String(uls[i].className).match('Second')) {
			var submenu = uls[i];
			//alert(uls[i].className);
			submenu.parentNode.getElementsByTagName('span')[0].onclick = function () {
				if (submenu.style.display != "block") {
					this.className = "down";
						submenu.style.display = "block";
					//alert(submenu.style.display);
				}
				else {
					this.className = "";
					submenu.style.display = "none";
				}
			}
		}

	}
}


// czyszczenie inputa
function clearInput() {
	if (document.getElementById('print') == null) {
		var inputSearch = document.getElementById('search').getElementsByTagName('input')[0];
		var valueSearch = inputSearch.getAttribute('value');
		inputSearch.onfocus = function () {
			this.setAttribute("value", "");
		}
	}
	if (document.getElementById('newsletter')) {
		var inputNewsletter = document.getElementById('newsletter').getElementsByTagName('input')[0];
		var valueNewsletter = inputNewsletter.getAttribute('value');
		inputNewsletter.onfocus = function () {
			this.setAttribute("value", "");
		}
	}
	if (document.getElementById('contact')) {
		var inputContact = document.getElementById('contact').getElementsByTagName('input');
		for (var i=0; i<inputContact.length; i++) {
			inputContact[i].onfocus = function () {
				var valueContact = this.getAttribute('value');
				this.setAttribute("value", "");
			}
		var textareaContact = document.getElementById('contact').getElementsByTagName('textarea')[0];
		var textareaValueContact = textareaContact.innerHTML;
			textareaContact.onfocus = function () {
				this.innerHTML = "";
			}
		}
	}
}

// pokazywanie pomocy
function help() {
	var question = document.getElementById('questionsList').getElementsByTagName('dt');
	var span = document.getElementById('questionsList').getElementsByTagName('span');
	for (var i=0; i<question.length; i++) {
		question[i].onclick = function () {
		var question = this.getElementsByTagName('a')[0];
			var questionId = String(question.href).split('#')[1];
			document.getElementById(questionId).style.display = "block";
			return false;
		}
	}
	for (var i=0; i<span.length; i++) {
		if (span[i].className == "hide") {
			span[i].onclick = function () {
				this.parentNode.style.display = "none";
			}
		}
	}
}


function remove_head() {
	var heads = document.getElementById('data').getElementsByTagName('h3');
	//alert(document.getElementById('data').innerHTML);
	for (var i=0; i<heads.length; i++) {
		if(heads[i].className.match('head')) {
			var as = heads[i].getElementsByTagName('a');
			for (var j=0; j<as.length; j++) {
				//alert(as[j].innerHTML);
				if(as[j].className.match('head')) {
					heads[i].className='';
					//alert(as[j].innerHTML);
				}
			}
			//alert(heads[i].innerHTML);
			//alert(as.length);
		}

	}
}
function checkUncheckAll(theElement) { 
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
    if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	   theForm[z].checked = theElement.checked;
	  }
  }
}
// onload
sifrConf();
window.onload = function js() {
	remove_head();
	sifrReplace();
	newWindow();
	printWindow();
	clearInput();
	if (document.getElementById('questionsList')) {help();}
	if (document.getElementById('print')) {printIt();}
	if (document.getElementById('leftMenu')) {subMenu();}
}
