var xmlhttp
/*@cc_on @*/
/*@if (@_jscript_version >= 5)
  try {
  xmlhttp=new ActiveXObject("Msxml2.XMLHTTP")
 } catch (e) {
  try {
	xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
  } catch (E) {
   xmlhttp=false
  }
 }
@else
 xmlhttp=false
@end @*/

if (!xmlhttp && typeof XMLHttpRequest != 'undefined')
{
  try {
	xmlhttp = new XMLHttpRequest ();
  }
  catch (e) {
  xmlhttp = false}
}

function myXMLHttpRequest ()
{
  var xmlhttplocal;
  try {
  	xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")}
  catch (e) {
	try {
	xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")}
	catch (E) {
	  xmlhttplocal = false;
	}
  }

  if (!xmlhttplocal && typeof XMLHttpRequest != 'undefined') {
	try {
	  var xmlhttplocal = new XMLHttpRequest ();
	}
	catch (e) {
	  var xmlhttplocal = false;
	}
  }
  return (xmlhttplocal);
}

var mnmxmlhttp = Array ();
var mnmString = Array ();
var mnmPrevColor = Array ();
var responsestring = Array ();
var myxmlhttp = Array ();
var responseString = new String;


function hlasuj (user, id, htmlid, md5, value, karma)
{
  	if (xmlhttp) {
		url = "/hlasuj.php";
		content = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value + "&karma=" + karma;
		anonymous_vote = true;
        if (anonymous_vote == false && user == '0') {
            window.location="/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    
    			mnmxmlhttp[htmlid].send (content);
    			errormatch = new RegExp ("^ERROR:");
    
    			target1 = document.getElementById ('mnms-' + htmlid);
    
    
    			mnmPrevColor[htmlid] = target1.style.backgroundColor;
    			//target1.style.background = '#c00';
    			//target1.style.backgroundColor = '#FF9D9F';
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					mnmString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (mnmString[htmlid].match (errormatch)) {
    						mnmString[htmlid] = mnmString[htmlid].substring (6, mnmString[htmlid].length);
    						// myclearTimeout(row);
    						// resetrowfull(row);
    						changemnmvalues (htmlid, true);
    					} else {
    						changemnmvalues (htmlid, false);
    					}
    				}
    			}
    		}
    	}
	}
}



function changemnmvalues (id, error)
{
	var vote_text = "";
    split = new RegExp ("~--~");
	b = mnmString[id].split (split);
	//alert(id);
	target_hlas_div = document.getElementById ('hlas_div-' + id);
	target1 = document.getElementById ('mnms-' + id);
	target11 = document.getElementById ('votetext-' + id);
	target2 = document.getElementById ('mnmlink-' + id);
	if (error) {
		target2.innerHTML = " ";
		return false;
	}
	if (b.length <= 3) {
        if(b[0] == 0 || b[0] > 4) vote_text = 'hlasov';
        if(b[0] == 1) vote_text = 'hlas';
        if(b[0] > 1 && b[0] < 5) vote_text = 'hlasy';
        
	 target1.innerHTML = '<div class="rating"><h3>' + b[0] + '<br /><span id="votetext-"' + id +'>' + vote_text + '</span></h3></div>';
//		target11.innerHTML = vote_text + '</span></h3></div>'; //rating div end tag ??
		//target1.style.backgroundColor = mnmPrevColor[id];
	//	target2.innerHTML = '<img src="/asdf_img/buttons/uz_hlasoval_b.gif" alt="{#PLIGG_Visual_Vote_Cast#}" width="60" height="23" border="0" />';
		
		//target_hlas_div.innerHTML = '<div class="rating"><h3>' + b[0] + '<br /><span id="votetext-"' + id +'>' + vote_text + '</span></h3></div> <img src="/asdf_img/buttons/uz_hlasoval_b.gif" alt="{#PLIGG_Visual_Vote_Cast#}" width="60" height="23" border="0" />';
    target_hlas_div.innerHTML = '<a href="'+ target1 +'" id="mnms-"'+ id +'><div class="rating"><h3>' + b[0] + '<br /><span id="votetext-"' + id +'>' + vote_text + '</span></h3></div></a> <img src="/asdf_img/buttons/uz_hlasoval_b.gif" alt="{#PLIGG_Visual_Vote_Cast#}" width="60" height="23" border="0" />'; 
	}
	return false;
}

/*bonz tlacitka*/

function bonzuj (user, id, htmlid, md5, value, type)
{
  	if (xmlhttp) {
		url = "/bonzuj.php";
		content = "id=" + id + "&user=" + user + "&md5=" + md5 + "&value=" + value + "&type=" + type;
		anonymous_vote = true;
        if (anonymous_vote == false && user == '0') {
            window.location="/login.php?return="+location.href;
        } else {
    		mnmxmlhttp[htmlid] = new myXMLHttpRequest ();
    		if (mnmxmlhttp) {
    			mnmxmlhttp[htmlid].open ("POST", url, true);
    			mnmxmlhttp[htmlid].setRequestHeader ('Content-Type',
    					   'application/x-www-form-urlencoded');
    			mnmxmlhttp[htmlid].send (content);
    			errormatch = new RegExp ("^ERROR:");
    			
    			mnmxmlhttp[htmlid].onreadystatechange = function () {
    				if (mnmxmlhttp[htmlid].readyState == 4) {
    					mnmString[htmlid] = mnmxmlhttp[htmlid].responseText;
    					if (mnmString[htmlid].match (errormatch)) {
    						mnmString[htmlid] = mnmString[htmlid].substring (6, mnmString[htmlid].length);
    						// myclearTimeout(row);
    						// resetrowfull(row);
    						changebonzvalues (htmlid, true, type);
    					} else {
    						changebonzvalues (htmlid, false, type);
    					}
    				}
    			}
    		}
    	}
	}
}

function changebonzvalues (id, error, type)
{
	var vote_text = "";
    split = new RegExp ("~--~");
	b = mnmString[id].split (split);
	
	if(type == 'links'){
		target_bonz_div = document.getElementById ('bonz_div-' + id);
		target2 = document.getElementById ('bonzlink-' + id);
	} else if (type='comments'){
		
		target_bonz_div = document.getElementById ('bonzc_div-' + id);
		target2 = document.getElementById ('bonzcomms-' + id);
	}
	if (error) {
		target_bonz_div.innerHTML = '<b>' + b + '</b>';
		return false;
	}
	if (b.length <= 3) {
     target_bonz_div.innerHTML = '<div>&#270;akujeme za nahl&#225;senie nevhodn&#233;ho pr&#237;spevku</div>'; 
	}
	return false;
}


function enablebutton (button, button2, target)
{
	var string = target.value;
	button2.disabled = false;
	if (string.length > 0) {
		button.disabled = false;
	} else {
		button.disabled = true;
	}
}

function checkfield (type, form, field)
{
	url = '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);

	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
		//alert('|'+ responsestring +'|');
		
			if (responsestring == 'OK1') {
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:green">"' + field.value + 
						'": meno ešte nie je zaregistrované môžete ho použiť </span>';
				form.submit.disabled = '';
			} else if (responsestring == 'OK2') {
			//	alert('jajajajjaja');
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:black">"' + field.value + 
						'": emailová adresa ešte nie je zaregistrovaná môžete ho použiť </span>';
				form.submit.disabled = '';
			}  else {
			//	alert('badbad bad');
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:red">"' + field.value + '": ' +
				responsestring + '</span>';
				form.submit.disabled = 'disabled';
			}
		}
	}
  checkitxmlhttp.send (null);
  return false;
}

function checkfield_edit(type, form, field)
{
	url = '/checkfield.php?type='+type+'&name=' + field.value;
	checkitxmlhttp = new myXMLHttpRequest ();
	checkitxmlhttp.open ("GET", url, true);

	checkitxmlhttp.onreadystatechange = function () {
		if (checkitxmlhttp.readyState == 4) {
		responsestring = checkitxmlhttp.responseText;
		//alert('|'+ responsestring +'|');
		
			if (responsestring == 'OK1') {
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:green">Alias/login je voľný </span>';
				form.submit.disabled = '';
			}  else {
			//	alert('badbad bad');
				document.getElementById (type+'checkitvalue').innerHTML = '<span style="color:red">"' + field.value + '": ' +
				responsestring + '</span>';
				form.submit.disabled = 'disabled';
			}
		}
	}
  checkitxmlhttp.send (null);
  return false;
}

function clklog (user, id)
{
  	if (xmlhttp) {
		url = "/clklog.php";
		content = "id=" + id + "&user=" + user ;
		mnmxmlhttp[id] = new myXMLHttpRequest ();
		if (mnmxmlhttp) {
			mnmxmlhttp[id].open ("POST", url, true);
			mnmxmlhttp[id].setRequestHeader ('Content-Type',
					   'application/x-www-form-urlencoded');
			mnmxmlhttp[id].send (content);
			
		}
    	
	}
}
