// JavaScript Document
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);
//				}
			}
   });
 }
 // JavaScript Document
//function JSonRequest(requestType, targetUrl, parameters, handleResponse, startFunc, endFunc, errorFunc, repeatCount){
function JSonRequest(requestType, targetUrl, parameters, handleResponse){
	/*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: "json",
      success: handleResponse//,
		/*error: function( objAJAXRequest, strError ){
				if (repeatCount < 0){
					if (errorFunc) errorFunc(parameters);
				}else{
					JSonRequest(requestType, targetUrl, parameters, handleResponse, startFunc, endFunc, errorFunc, --repeatCount);
				}
		}*/
   });
 }


function jQueryAjaxPost(targeturl,parameters,resultdiv){
   $.ajax({
      type: "POST",
      url: targeturl,
      data: parameters,
      contentType: "application/x-www-form-urlencoded",
      dataType: "html",
      success: function(response) {
         $('#'+resultdiv).html(response);
      }
   });
}
function jQueryAjaxGet(targeturl,parameters,resultdiv){
   $.ajax({
      type: "GET",
      url: "../code/navigate.php",
      data: parameters,
      contentType: "application/x-www-form-urlencoded",
      dataType: "html",
      success: function(response) {
         $('#'+resultdiv).html(response);
      }
   });
}

function preinit()
 {
 	x=document.location.href;
  if (document.location.search.indexOf("MIT") >0 || document.location.href.indexOf("mit.de") > 0) 
       return true;
 	if (x.indexOf("/marine/") >0 || x.indexOf("/garden/") >0 || x.indexOf("/garten/") >0  || x.indexOf("/industrie/") >0  || x.indexOf("/industry/") >0) 
 	 return false;
 	return true;
}

function init() {
	if (!(self.isLoaded))
	 {
	  is = new getClient();
	  if (preinit()==false)
	   {
		for (var i=0; i<document.images.length; i++) {
   		document.images[i].oncontextmenu = function() {return false;};
		  document.images[i].galleryimg = 'no';
   	}
   }
   	self.isLoaded = true;
   }
}
var is = null;

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)
}



// --------------------------------------------------------------------------------------------------
// Get Querystring Parameters

function getQueryStringParams() {
    GetParams = new Array();
    if (document.location.search) {
        QueryString = unescape(document.location.search.substring(1,document.location.search.length));
        KeyValuePairs = QueryString.split("&");
        for (i=0; i< KeyValuePairs.length; i++) {
            Param = KeyValuePairs[i].split("=");
            GetParams[Param[0]] = Param[1];
        }
    }
    return GetParams;
}


// --------------------------------------------------------------------
// Select randomly an Image out of an Array
// and change source of image tag

var currImageArrayIdx = 0;
var MainImageLoaded = false;

function showRandomImage(imageArray, imageId) {
    if (imageArray.length > 1) {
        if (document.getElementById) {
            var idx = Math.ceil(Math.random()*imageArray.length) - 1;
            while (idx == currImageArrayIdx) {
                idx = Math.ceil(Math.random()*imageArray.length) - 1;
            }
            currImageArrayIdx = idx;
        }
     	sn=imageArray[currImageArrayIdx];
    	if(sn.length>0 && sn.indexOf(".swf")<0) {
    		if(document.getElementById(imageId))
         document.getElementById(imageId).src = imageArray[idx];
      }
      else
      	{
      		 showRandomImage(imageArray, imageId);
      	}
    }
}


// --------------------------------------------------------------------
// Set Loading Status of MainImage
var random=1;
function setMainImageLoadState() {
	fname=(random==1) ? "Random":"Next";
    window.setTimeout("show"+fname+"Image(homeImages, 'MainImage')", 4500);
}

// --------------------------------------------------------------------
// Select next Image not Randomized 
function showNextImage(imageArray, imageId) {
    if (imageArray.length > 1) {
    	currImageArrayIdx =(currImageArrayIdx < (imageArray.length-1)) ? currImageArrayIdx+1:0;
    	sn=imageArray[currImageArrayIdx];
    	if(sn.length>0 && sn.indexOf(".swf")<0 ) {
        document.getElementById(imageId).src = imageArray[currImageArrayIdx];
      }
      else {
      	 showNextImage(imageArray, imageId);
      }
    }
}

function ReplaceLoadingTable(LoadingDiv,tekst) {
   if(document.getElementById(LoadingDiv)){
      document.getElementById(LoadingDiv).innerHTML = tekst;
      document.getElementById(LoadingDiv).style.display = "block";
   }
}

function openImageZoomWindow(imgURL,imgWidth,imgHeight){
   tmpStr = 'width='+(imgWidth + 30)+',height='+(imgHeight+50);
   tmpStr = 'toolbar=no,location=no,diretories=no,scrollbars=yes,status=no,menubar=no,resizable=yes,'+tmpStr;
   ImageZoomWindow = window.open(imgURL,'ImageZoomWindow',tmpStr);
   ImageZoomWindow.focus();
}
function openNewsImageZoomWindow(img,imgWidth,imgHeight){
alert(img);
   /*tmpStr = 'width='+(imgWidth + 30)+',height='+(imgHeight+50);
   tmpStr = 'toolbar=no,location=no,diretories=no,scrollbars=yes,status=no,menubar=no,resizable=yes,'+tmpStr;
   ImageZoomWindow = window.open(imgURL,'ImageZoomWindow',tmpStr);
   ImageZoomWindow.focus();*/
}

function ShowChildren(objName,targeturl,resultdiv,loadingtable) {
   obj = document.getElementById(objName);
   if(OpenedChildren[resultdiv] == true){
      OpenedChildren[resultdiv] = false;
      if(obj != "")
         obj.src = "../images/basic/template/ShopClassMenuClosed.gif";
      document.getElementById(resultdiv).onclick = "";
      var parameters = "ShowDiv=n";
      jQueryAjaxPost(targeturl,parameters,resultdiv);
   } else {
      OpenedChildren[resultdiv] = true;
      document.getElementById(resultdiv).style.display = "block";
      ReplaceLoadingTable(loadingtable,LoadingText);
      if(obj != "")
         obj.src = "../images/basic/template/ShopClassMenuOpened.gif";
      document.getElementById(resultdiv).onclick = "";
      var parameters = "ShowDiv=y";
      jQueryAjaxPost(targeturl,parameters,resultdiv);
   }
}


