/*  
	Magnat Sp z o.o.
	© All rights reserved
*/


function LinkConfirm(text,link)
{
	var confrm = confirm(text);
	
	if (confrm) 
	{ 
    var mform = document.createElement('form');
    var minput = document.createElement('input');
    var dbody = document.getElementsByTagName('body');
    var mbody = dbody[0];
    mform.action = link;
    mform.method = 'post';
    minput.type = 'hidden';
    minput.name = 'confirm';
    minput.value = '1';
    mform.appendChild(minput);
    mbody.appendChild(mform);
    mform.submit();
    
	/*	window.location = link; */
	} 
}

function SubmitConfirm(text)
{
	var confrm = confirm(text);
	return confrm;
}

function checkall(bol,form){
  var forma = document.getElementById(form); 
	for (var i=0;i<forma.elements.length;i++)
	{
		var e=forma.elements[i];
		if (e.type=='checkbox')
		{
			e.checked=bol;
		}
	}
}


function UploadCheckBoxClick(chbox,btnid,upload,save)
{
    var upbtn = document.getElementById(btnid);
	if(chbox.checked == 1)
	{
		upbtn.value = save;
	} else {
		upbtn.value = upload;
	}
}

function UploadScrCheckBoxClick(chbox,btnid,upload,save)
{
    var upbtn = document.getElementById(btnid);
   	var manulathumb = document.getElementById('manualthumb');
	var autothumbA = document.getElementById('autothumbA');
	var autothumbB = document.getElementById('autothumbB');
	var autothumbchbox = document.getElementById('autothumbchbox');

	if(chbox.checked == 1)
	{
		upbtn.value = save;
		manulathumb.style.display = "block";
		autothumbA.value = "0";
		autothumbB.value = "0";
		autothumbchbox.checked = 0;
		
	} else {
		upbtn.value = upload;
		manulathumb.style.display = "none";
		autothumbA.value = "1";
		autothumbB.value = "1";
		autothumbchbox.checked = 1;
	}
}

function AutoThumbClick(chbox,divid)
{
	var manulathumb = document.getElementById(divid);
	var autothumbA = document.getElementById('autothumbA');
	var autothumbB = document.getElementById('autothumbB');
	
	if(chbox.checked == 1)
	{
		manulathumb.style.display = "none";
		autothumbA.value = "1";
		autothumbB.value = "1";
	} else {
		manulathumb.style.display = "block";
		autothumbA.value = "0";
		autothumbB.value = "0";
	}
	
}

function getAjax() 
{
	var xhttp;
          
	if (!xhttp && typeof XMLHttpRequest != "undefined") 
	{
		try 
		{
			xhttp = new XMLHttpRequest();
		} catch (e) {
			xhttp = false;
		}
	}
	
	return xhttp;
}

function RateOnlyLogged(caption)
{
	var rating_caption = document.getElementById("rating_captions");
	rating_caption.innerHTML = caption;
}

function SendRate(rate,url,caption)
{
	for(i=1; i<6; i++)
	{
		if(i<=rate) { set="rating_set"; } else { set="rating_unset"; }
		var rate_set = document.getElementById("rating_"+i);
		rate_set.className = set;
		rate_set.onmouseover = null;
		rate_set.onclick = null;
	}
	
	var request = getAjax();
	if(request!=false)
	{
		request.onreadystatechange = function(){ 
		if( request.readyState == 4 && request.status == 200 ) 
			{  
				var rating_caption = document.getElementById("ratingcaption");
				var user_rate = document.getElementById("userrate");
				var rate_count = document.getElementById("ratingcount");
				var rate_cnt = parseInt(rate_count.innerHTML);
				rate_cnt++;
				rate_count.innerHTML = rate_cnt;
				rating_caption.innerHTML = caption;
				user_rate.innerHTML = rate;	
			}
		}
		request.open("GET", url, true);
		request.send(null);
	}	
}

function SendRatePost(rate,url,params,caption)
{
	for(i=1; i<6; i++)
	{
		if(i<=rate) { set="rating_set"; } else { set="rating_unset"; }
		var rate_set = document.getElementById("rating_"+i);
		rate_set.className = set;
		rate_set.onmouseover = null;
		rate_set.onclick = null;
	}
	
	var request = getAjax();
	if(request!=false)
	{
		request.onreadystatechange = function(){ 
		if( request.readyState == 4 && request.status == 200 ) 
			{  
				var rating_caption = document.getElementById("ratingcaption");
				var user_rate = document.getElementById("userrate");
				var rate_count = document.getElementById("ratingcount");
				var rate_cnt = parseInt(rate_count.innerHTML);
				rate_cnt++;
				rate_count.innerHTML = rate_cnt;
				rating_caption.innerHTML = caption;
				user_rate.innerHTML = rate;	
			}
		}
		request.open("POST", url, true);
		request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    request.setRequestHeader("Content-length", params.length);
    request.setRequestHeader("Connection", "close");
		request.send(params);
	}	
}


function rating(rate)
{	
	for(i=1; i<6; i++)
	{
		if(i<=rate) { set="rating_set"; } else { set="rating_unset"; }
		document.getElementById('rating_'+i).className = set;
	}
}

