var bV=parseInt(navigator.appVersion);
var NS4= (document.layers) ? true : false;
var IE4=((document.all)&&(bV>=4)) ? true : false;
var DOM=(!document.layers && !document.all && bV>=4) ? true : false;

// A hack to guess if the browser supports the DOM
var capable = (NS4 || IE4 || DOM) ? true : false;

var active;
function startclose(){
     active = window.setTimeout("closeAll()",1000);
}
function stopclose(){
     if(active){
		window.clearTimeout(active);
	}
}

function expandIt(el, id, OffsX, OffsY) {
	if (!capable) return;
	// closeAll();
	
	var coords;
	var MouseX=0;
	var MouseY=0;
	if (DOM || IE4) {
		coords = {x: 0, y: 0};
		var element = document.getElementById('POSER_'+id);
		while (element) {
			coords.x += element.offsetLeft;
			coords.y += element.offsetTop;
			element = element.offsetParent;
		}
	} else if (NS4) {
		var element = document.links['POSER_'+id];
		coords = {x: element.x, y: element.y};
	} else {
		return false;
	}
	
	if (coords){
		var poserX = coords['x'];
		var poserY = coords['y'];
	}
	MouseX=(poserX+OffsX);
	MouseY=(poserY+OffsY);
	
	if(DOM) {
		whichEl = document.getElementById(el);
		whichEl.style.top = MouseY+"px";
		whichEl.style.left = MouseX+"px";
		whichEl.style.visibility = "visible";
		whichEl.style.display = "block";
	} else if (IE4) {
		document.all[eval('el')].style.top = MouseY+"px";
		document.all[eval('el')].style.left = MouseX+"px";
		document.all[eval('el')].style.display = "block";
		document.all[eval('el')].style.visibility = "visible";
	} else if(NS4) {
		whichEl = eval("document." + el);
		whichEl.top = parseInt(MouseY);
		whichEl.left = parseInt(MouseX);  
		whichEl.visibility = "show";
		whichEl.display = "block";
	} 
}

function closeAll(){
  closeAllByName("child");
  closeAllByName("subchild");
}

function closeAllByName(name){
	stopclose();
	if (NS4) {
		for (i=0; i<document.layers.length; i++) {
			whichEl = document.layers[i];
			if (whichEl.id.toLowerCase().indexOf(name) != -1) {
				whichEl.visibility = "hide";
				whichEl.display = "none";
			}
		}
	} else if(IE4) {
		tempColl = document.all.tags("DIV");
		for (i=0; i<tempColl.length; i++) {
			whichEl = tempColl(i);
			if (whichEl.className.indexOf(name) != -1){
				whichEl.style.display = "none";
				whichEl.style.visibility = "hidden";
			}
		}
	} else if(DOM) {
		tempColl = document.getElementsByTagName("DIV");
		for (i=0; i<tempColl.length; i++) {
			whichEl = tempColl[i];
			if (whichEl.className.indexOf(name) != -1){
				whichEl.style.visibility = "hidden";
				whichEl.style.display = "none";
			}
		}
	}
}


function checkAForm(F){
	var error=0;
	var error_msg="Leider sind folgende Fehler aufgetreten:\n\n";
	
	if(F.vorname.value==''){
	error=1;
	error_msg+="\tVorname ist leer.\n";
	}
	if(F.nachname.value==''){
	error=1;
	error_msg+="\tNachname ist leer.\n";
	}
	if(!validateEMail(F.email.value)){
	error=1;
	error_msg+="\tE-Mail ist falsch.\n";
	}
	
	if(error==1){
		alert(error_msg);
		return false;
	} else {
	
		new Ajax.Updater('KontaktanfrageContent', '/PHPMAILER/sendForm.php', {
			asynchronous: true,
			onLoading: function(){ $('AFsubmit').value='Please Wait'; $('AFsubmit').disabled=true; },
			onComplete: succesRetourAjax,
			onFailure: errorRetourAjax,
			parameters: Form.serialize($('AForm'))
		}
		);
		return false;
	
	}
}

function succesRetourAjax (t)
{
   // alert(t.responseText);
    if (t.responseText == "OK")
    {

        $('KontaktanfrageContent').innerHTML = '<p>'+KontaktanfrageOKMessage+'</p>';
    }
    else
    {
        $('KontaktanfrageContent').innerHTML = '<p>'+KontaktanfrageFailedMessage+'</p>';
    }
}

function errorRetourAjax (t){
        $('KontaktanfrageContent').innerHTML = '<p>'+KontaktanfrageFailedMessage+'</p>';
}

function validateEMail(s)
{
 var a = false;
 var res = false;
 if(typeof(RegExp) == 'function')
 {
  var b = new RegExp('abc');
  if(b.test('abc') == true){a = true;}
  }

 if(a == true)
 {
  reg = new RegExp('^([a-zA-Z0-9\\-\\.\\_]+)'+'(\\@)([a-zA-Z0-9\\-\\.]+)'+'(\\.)([a-zA-Z]{2,4})$');
  res = (reg.test(s));
 }
 else
 {
  res = (s.search('@') >= 1 && s.lastIndexOf('.') > s.search('@') && s.lastIndexOf('.') >= s.length-5)
 }
 return(res);
}
var currentID = new Array();
var currentNUM = new Array();
var Simages = new Array();
function showSmallImage(ids,number){
	var ziel = "IMG"+ids;

	if(ziel){
		$(ziel).src = Simages[ids][number]['s'];
		currentID[ids] = ids;
		currentNUM[ids] = number;
	}
	return false;
}

function showBig(ids){

	var f1=window.open(Simages[currentID[ids]][currentNUM[ids]]['b'],currentID[ids],'height='+( parseInt(Simages[currentID[ids]][currentNUM[ids]]['h']) + 20)+',width='+( parseInt(Simages[currentID[ids]][currentNUM[ids]]['w']) + 20));
	f1.focus();
	return false;

}

function open_function(url,width,height,options) { 
	self.msgWindow = open(url, "Window", "width=" + width + ",height=" + height + ",screenX=" + (screen.width-width)/2 + ",screenY=" + (screen.height-height)/2 + ",dependent=yes" + ",left=" + (screen.width-width)/2 + ",top=" + (screen.height-height)/2 + options );
	if (self.msgWindow) { 
		self.msgWindow.focus();
		if (self.msgWindow.opener == null) self.msgWindow.opener = self;
	}
}

function get_url (url, k0 ,v0 ,k1 ,v1 ,k2 ,v2 ,k3 ,v3 ,k4 ,v4 ) { 
	if (k0 && v0) url += "?" + k0 + "=" + escape(v0); if (k1 && v1) url += "&" + k1 + "=" + escape(v1); 
	if (k2 && v2) url += "&" + k2 + "=" + escape(v2); if (k3 && v3) url += "&" + k3 + "=" + escape(v3);
	if (k4 && v4) url += "&" + k4 + "=" + escape(v4); 
	return url;
}
