function AjaxRequest(requestType, targetUrl, parameters, resultDiv, startFunc, endFunc, errorFunc, repeatCount){
	if (!repeatCount && repeatCount != 0) repeatCount=2;
	if (startFunc) startFunc();
   $.ajax({
      type: requestType,
      url: targetUrl,
      timeout: 5000, 
      data: parameters,
      contentType: "application/x-www-form-urlencoded",
      dataType: "html",
      success: function(response) {
         $('#'+resultDiv).html(response);
         if (endFunc) endFunc();
      },
			error: function( objAJAXRequest, strError ){
//				if (strError == 'timeout'){
					if (repeatCount < 0){
						if (errorFunc) errorFunc(parameters);
					}else{
						AjaxRequest(requestType, targetUrl, parameters, resultDiv, startFunc, endFunc, errorFunc, --repeatCount);
					}
//				}else{
//					alert(strError);
//				}
			}
   });
 }



var http_request = false;
function ReplaceLoadingTable(LoadingDiv,tekst) {
   if(document.getElementById(LoadingDiv)){
      document.getElementById(LoadingDiv).innerHTML = tekst;
      document.getElementById(LoadingDiv).style.display = "block";
   }
}
function makePOSTRequest(url, parameters, resultdiv) {
   http_request = false;
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
      http_request = new XMLHttpRequest();
      if (http_request.overrideMimeType) {
      	// set type accordingly to anticipated content type
         //http_request.overrideMimeType('text/xml');
         http_request.overrideMimeType('text/html');
      }
   } else if (window.ActiveXObject) { // IE
      try {
         http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } catch (e) {
         try {
            http_request = new ActiveXObject("Microsoft.XMLHTTP");
         } catch (e) {}
      }
   }
//    alert(http_request);
   if (!http_request) {
      alert('Cannot create XMLHTTP instance');
      return false;
   }
   
   http_request.onreadystatechange = function() {
      if (http_request.readyState == 4) {
         if (http_request.status == 200) {
            //alert(http_request.responseText);
            result = http_request.responseText;
            document.getElementById(resultdiv).innerHTML = result;
         } else {
            alert('There was a problem with the request.');
         }
      }
   }
   http_request.open('POST', url, true);
   http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
   http_request.setRequestHeader("Content-length", parameters.length);
   http_request.setRequestHeader("Connection", "close");
   http_request.send(parameters);
}

function getClient() {
  // convert all characters to lowercase to simplify testing
  var agt=navigator.userAgent.toLowerCase()
  var apv=navigator.appVersion.toLowerCase()
  this.major = parseInt(navigator.appVersion)
  this.minor = parseFloat(navigator.appVersion)
  // browserversion
  this.opera = (agt.indexOf('opera')!=-1);
  this.ns  = ((agt.indexOf('mozilla')!=-1) && ((agt.indexOf('spoofer')==-1) && (agt.indexOf('compatible') == -1)))
  this.ns4 = (this.ns && (this.minor >= 4.03) && (this.major < 5))
  this.ns6 = (this.ns && (this.major == 5) || this.opera)
  this.gecko = (this.ns && (this.major >= 5))
  this.ie   = (agt.indexOf("msie") != -1)
  this.ie4  = (this.ie && (this.major == 3))
  this.ie45 = (agt.indexOf('msie 4.5') != -1);
  this.ie5  = (this.ie && (this.major == 4))
  // platform
  this.mac = (apv.indexOf("macintosh")>0);
  this.win = (apv.indexOf("win")>0);	
  // compatible browsers
  this.ie4comp = ((this.ie4 && !this.mac) || this.ie45 || this.ie5)
  this.ns4comp = (this.ns4);
  this.ns6comp = (this.gecko || this.ns6);
  this.comp = (this.ie4comp || this.ns4comp || this.ns6comp);
  return (this)
}

var is = new getClient();

function printURL() {
	var header = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><title>Printable version</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
	header += '<link rel="stylesheet" href="/css/default.css" type="text/css"><style>body {background-color: #ffffff; margin: 0px; padding: 0px;}</style></head>';
	header += '<body onLoad="window.print();">';
	header += '<table align="center"><tr><td width="100%" bgcolor="#ffffff">';
	var footer = '</td></tr></table></body></html>';

	var strInner = document.body.innerHTML;
	var startPos = strInner.lastIndexOf("<!-- print_start -->");	
	var endPos = strInner.lastIndexOf("<!-- print_end -->");
	strInner = strInner.substring(startPos+20, endPos);
		
	if (strInner.lastIndexOf("<!-- print_pause_on -->") > -1){
		var str1 = "<!-- print_pause_on -->";
		var str2 = "<!-- print_pause_off -->";
		startPos = strInner.lastIndexOf(str1);	
		endPos = strInner.lastIndexOf(str2);
		if (endPos > startPos){
			leftStr = strInner.substring(0, startPos);
			rightStr = strInner.substring(endPos + str2.length, strInner.length);
			strInner =	 leftStr + rightStr;
		}
	}
	var xwin = window.open("/code/printable.php", "PrintVersion", "menubar=yes, scrollbars=yes, resizable=yes, width=625, toolbar=yes, statubar=no");
	xwin.document.write(header+strInner+footer);
}

function isPPC() {
	if (navigator.appVersion.indexOf("PPC") != -1) return true;
	else return false;
}

function sendPage(mailHeadline){
	if(!isPPC()) {
		window.location="mailto:\?subject\=" + mailHeadline + "&body=" + mailHeadline + ": " + window.location;
	}else { 
		window.location="mailto:\?body=" + mailHeadline + ": " + window.location;
	}
}
