var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "Nieznana przeglądarka";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "nieznana wersja";
		this.OS = this.searchString(this.dataOS) || "nieznany system operacyjny";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		}
	]

};
BrowserDetect.init();

function chose_link(value) {

	if(value == 1) {

		$_('type1_').disabled = false;
		$_('type2_').disabled = true;		
	}
	else {
	
		$_('type1_').disabled = true;	
		$_('type2_').disabled = false;			
	}
}

function $_(pole) {

	return document.getElementById(pole);;
}
function del_date(pole) {

	$_(pole).value='';
}
function second_add(ob) {

	$_(ob).style.display = $_('second_add_div').style.display == "none"? "inline" : "none";
}

function check_candel(id) {

	if ($_('del_'+id).checked) {
	
		if ($_('qq_'+id).value > 0) {
		
			alert("Podany produkt nie może być usunięty dopóki stanowi część pakietu");
			$_('del_'+id).checked = false;
		}
	}
}

function superoffer(id,ile) {

	$_('chosen').value = id;
			
	for (var i=0; i<ile; i++) {
	
		if (i == id) {
		
			$_('div_'+i).style.display = 'block';
			$_('span_'+i).className = 'super_link_chosen';
		}	
		else $_('div_'+i).style.display = 'none';
	}
	super_link(id,ile);
}

function super_link(id,ile) {

	var wybrany = $_('chosen').value;
		
	for (var i=0; i<ile; i++) {
	
		if (i == id && i != wybrany) $_('span_'+i).className = 'super_link_over';
		else if (i == wybrany) $_('span_'+i).className = 'super_link_chosen';
		else $_('span_'+i).className = 'super_link';
	}
}

function super_link_off(ile) {

	var wybrany = $_('chosen').value;
		
	for (var i=0; i<ile; i++) {
	
		if (i != wybrany) $_('span_'+i).className = 'super_link';
		else $_('span_'+i).className = 'super_link_chosen';
	}
}

function hideloader() {
	
	$_('ajax_loader').style.display = 'none';
	$_('ajax_loader2').style.display = 'none';
}
function close_preview() {

	$_('ajax_cart').style.display = 'none';
	$_('ajax_cart_content').style.display = 'none';
}
function showloader(info) {
	
	if (info == '') info = 'Ładowanie...';
	$_('ajax_loader_info').innerHTML = info;
	$_('ajax_loader').style.display = 'block';
	$_('ajax_loader2').style.display = 'block';	
}

function show_price2(id) {

	var price = $_('price_div');
	
	if (id == 1) price.style.display = 'block';
	else if (id == 2) price.style.display = 'block';
	else price.style.display = 'none';
}

function addfavorites(){
	
	var tytul = 'Carrick Polska';
	var adres = 'http://www.carrick.pl';
	
	//FireFox
  if (window.sidebar) { 

      window.sidebar.addPanel(tytul, adres, ""); 

	//IE
  } else if (window.external) {

			window.external.AddFavorite(adres, tytul); 
	}
	else if (window.opera) {
	
		var f = document.getElementById('fav');
		f.setAttribute('href', adres);
		f.setAttribute('title', tytul);
		f.setAttribute('rel','sidebar');	
	}
}

function spr_text() { 

	var text	= $_('text');
	var q	= $_('q');

	// maksymalna ilość znaków
  var maxlen = 1000;
  var normal = 0;
  var enters = 0; 
	
	if (navigator.appName == "Netscape") {
	
	for (i=0; i<text.value.length; i++) { 

		if (text.value.charAt(i) == "\n") { //gdy enter
       normal++; 
       enters++; 
			}
		else {normal++;}		
	}
	
	q.value = maxlen - normal - enters;
	
  if (normal+enters>maxlen) { 	
      text.value = text.value.substring(0,maxlen-enters-3) + '...';
			
		q.value = 0; 	
    alert("Maksymalna długość wpisu to " + maxlen +"!"); 			
		}
	}//Netscape
	
	else {
	
	for (i=0; i<text.value.length; i++) { 

		normal++;
  }
	
	q.value = maxlen - normal;
	
  if (normal>maxlen) { 	
      text.value = text.value.substring(0,maxlen-3) + '...';
			
		q.value = 0; 	
    alert("Maksymalna długość wpisu to " + maxlen +"!"); 			
		}	

	}//else
}	
