function check(wotForm, wotState) 
{
	for (i=0; i<wotForm.elements.length; i++) 
	{
		if (wotForm.elements[i].id.indexOf("delete_") == 0) 
			 wotForm.elements[i].checked = wotState ;
	}
}

function markBlock(obj, bg_color, border_color)
{
	obj.style.background = bg_color;
	obj.style.border = '1px solid '+border_color;
}

function unmarkBlock(obj, bg_color, border_color)
{
	obj.style.background = bg_color;
	obj.style.border = '1px solid'+border_color;
}

function potwierdz(question) 
{
	question = (question == null) ? "Czy kontynuować?" : question;
	var answer = window.confirm(question);
	
	if (answer)
		return true
	else
		return false;
}

function insertFlash(DivID, width, height, title, src)
{
	if(DivID != "")
	{
	  var d = document.getElementById(DivID);
	  
	  if (d)
	  d.innerHTML = 
	    '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" '+
	    'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0"'+
	    ' width="'+width+'" height="'+height+'" title="'+title+'">'+
		 '<param name="allowScriptAccess" value="sameDomain" />'+
	    '<param name="movie" value="'+src+'" />'+
	    '<param name="quality" value="high" />'+
		 '<param name="wmode" value="transparent" />'+
	    '<embed src="'+src+'" quality="high" wmode="transparent" '+
	    'pluginspage="http://www.macromedia.com/go/getflashplayer" '+
	    'type="application/x-shockwave-flash" allowScriptAccess="sameDomain" '+
		 'width="'+width+'" height="'+height+'" />'+
	    '<'+'/'+'object>'; 
	}
}	

window.onload=function()
{
	setMaxLength();
	fillup();

	var tmp = navigator.appName == 'Microsoft Internet Explorer' && navigator.userAgent.indexOf('Opera') < 1 ? 1 : 0;
	if(tmp) 
		var isIE = navigator.appName == 'Microsoft Internet Explorer' ? 1 : 0;

	if(fileLoadingImage != "")
		initLightbox();
/*		
	if(isIE)
		addIEInstant();
	else
		addInstant();
*/		
	if(!NiftyCheck())
   	return;
		
	Rounded("div#lefboxfirst", "top bl", "#ffffff", "#D7F0FA", "smooth");
	Rounded("div#lefboxsecund", "top bl", "#ffffff", "#E7F6FC", "border #CDE7F2");
	Rounded("div#boxact", "tl", "#ffffff", "#EEF9FE", "smooth");
	Rounded("div#boxact2", "tl", "#ffffff", "#EEF9FE", "smooth");
	Rounded("div#lefboxcontacy", "tl", "#ffffff", "#ffffff", "border #BEE4F3");
	Rounded("div#boxcenterpatient", "tl", "#ffffff", "#D7F0FA", "smooth");
	Rounded("div#boxcenterdoctor", "tl", "#ffffff", "#E7F6FC", "smooth");
	Rounded("div#left_side", "top bl", "#ffffff", "#EEF9FE", "border #E7F6FC");
	
	
}

function sprawdz(adres) 
{
	if (adres != "") 
	{
		var re = new RegExp("[^@]{1,}[@]{1}[^@.]{1,}[.]{1}[^@]{1,}","gi");
		var wynik = re.test(adres);
		
		if (wynik == true) 
			return true;
		else if(wynik == false) 
		{
			alert("Nieprawidłowy adres e-mail!");
			return false;
		}
	}
	else
	{
		alert("Proszę podać adres email!");
		return false;
	}
}

advAJAX.setDefaultParameters({
    onError : function(obj) { alert("Nie można nawiązać połączenia z serwerem, spróbuj później.");  }
});

function newsletter_add()
{
	var email = document.getElementById('news_adres').value;
	
	if(sprawdz(email))
	{
		advAJAX.post({
			url: "index.php5",
			
		   parameters : {
				"ajax"    : "run",
				"act"		 : "newsletter",
				"email"   : email,
				"sub"	    : "add"
		   },
			
			onSuccess : function(obj) 
			{ 
				if(obj.responseText != "")
					alert(obj.responseText); 
			}
		});
	}
}

function showPoll(poll_id, act)
{
	advAJAX.post({
		url: "index.php5",
		parameters : {
			"ajax"  : "run",
			"act"   : act,
			"sub"   : "showPoll",
			"id" 	  : poll_id
		},

		onSuccess : function(obj) 
		{ 
			document.getElementById('divpoll_'+poll_id).innerHTML = obj.responseText; 
		}
	});
}

function addVote(poll_id, act)
{
	advAJAX.post({
		url: "index.php5",
		parameters : {
			"ajax"  : "run",
			"act"   : act,
			"sub"   : "addVote",
			"id" 	  : poll_id
		},

		onSuccess : function(obj) 
		{ 
			if(obj.responseText == "")
				alert(obj.responseText);
			else
				document.getElementById('divpoll_'+poll_id).innerHTML = obj.responseText; 
		}
	});
}

function saveVote(poll_id, act)
{
	advAJAX.assign(document.getElementById("apoll_"+poll_id),
	{
		url: "index.php5",
		parameters : {
			"ajax"  : "run",
			"act"   : act,
			"sub"   : "saveVote",
			"id" 	  : poll_id
		},
	
		onInitialization : function(obj) 
		{
			//document.getElementById("submitBtn_"+poll_id).value = "Proszę czekać...";
		},
				
		onSuccess : function(obj) 
		{ 
			if(obj.responseText == "")
				alert(obj.responseText);
			else
				document.getElementById('divpoll_'+poll_id).innerHTML = obj.responseText; 
		}
	});
}

function imposeMaxLength(el, maxSize)
{
   if (!el.onblur)
		el.onblur = el.onclick = el.onmousedown = el.onmouseup = el.keypress = el.onkeydown = el.onkeyup = el.onmouseover = el.onmouseout = el.onfocus;
		
   if (el.value.length < maxSize) 
		el.maxlengthvalue = null;
   else if (el.value.length == maxSize) 
		el.maxlengthvalue = el.value;
   else 
		el.maxlengthvalue = el.value = (el.maxlengthvalue ? el.maxlengthvalue : el.value.substring(0, maxSize));
}

function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) 
	{
		if (x[i].getAttribute('maxlength')) 
		{
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() 
{
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
		
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

function NowaStrona(adres, x, y)
{
	window.open(adres,"_blank","height="+y+",width="+x+",status=no,toolbar=no,menubar=no,location=no");
}

function saveAnkieta()
{
	advAJAX.assign(document.getElementById("ankieta"),
	{
		disableForm : false,
		url: "index.php5",
		parameters : {
			"ajax"  : document.getElementById("ajax").value,
			"act"   : document.getElementById("act").value,
			"sub"   : document.getElementById("sub").value
		},
	
		onInitialization : function(obj) 
		{
			//document.getElementById("submitBtn_"+poll_id).value = "Proszę czekać...";
		},
				
		onSuccess : function(obj) 
		{
			if(obj.responseText == "OK")
			{
				alert("Dziękujemy za wypełnienie naszej ankiety!");
			}
		}
	});	
}

function print_page(adres, x, y)
{
	window.open(adres,"_blank","height="+y+",width="+x+",scrollbars=yes,status=no,toolbar=no,location=no,directories=no,resizable=no,menubar=no");
}

function show_flash(id) 
{
	document.getElementById(id).outerHTML = document.getElementById(id).outerHTML;
}