var typeOfAction=10;
var SHOPFLAG=1;
var checkKDFormular=false;
var dragobjekt = null;
var dragx = 0;
var dragy = 0;
var posx = 0;
var posy = 0;
var ressourcePath='users/pictures/';
var browser=(navigator.appName.indexOf("Microsoft") > 0)?1:0;
var infoWinVisible=false;
var currWHandle='';

draginit();


function draginit() {
  document.onmousemove = drag;
  document.onmouseup = dragstop;
}

function dragstart(element) {
  dragobjekt = element;
  dragx = posx - dragobjekt.offsetLeft;
  dragy = posy - dragobjekt.offsetTop;
}

function dragstop() {
  dragobjekt=null;
}

function drag(ereignis) 
{
  posx = document.all ? window.event.clientX : ereignis.pageX;
  posy = document.all ? window.event.clientY : ereignis.pageY;
  if(dragobjekt != null) 
  {
    dragobjekt.style.left = (posx - dragx) + "px";
    dragobjekt.style.top = (posy - dragy) + "px";
  }
}



gui=new skinProperty();
gui.mainIcon=ressourcePath+"infowin.gif";
gui.minIcon=ressourcePath+"w_down.gif";	
gui.maxIcon=ressourcePath+"w_full.gif";	
gui.closeIcon=ressourcePath+"w_close_black.gif";
gui.bgColor='fff';
gui.normalBorderWidth='1';
gui.normalBorderColor1='ddd';
gui.normalBorderColor2='777';
gui.barBgColor='984454';
gui.barBgColorNonFocus="984454";
gui.windowTitleColor='fff';
gui.windowTitleFont='sans-serif';
gui.windowTitleSize='13';
gui.windowTitleWeight='bold';
gui.windowTitleStyle='normal';
gui.contBorderWidth='1';
gui.contBorderColorL='';
gui.contBorderColorO='777';	
gui.contBorderColorR='';		
gui.contBorderColorU='';			
gui.contBgColor='f5f5ff';	
// gui.contColor='984454';		
gui.contColor='000';		
gui.contFont='sans-serif';





function putInBasketAjax(v,artid,pd)
{
	fld=eval('document.F1.FFF'+v);
	typeOfAction=100;
	_de="common/shopajax.php";
	_qu="mod=100&SID="+sid+"&ARTID="+artid+"&FF2="+fld.value+"&PD="+pd;
	
	/* alert(_qu);
		return;
	*/
	
	sndReqPOST(_de,_qu);
	fld.value='';
}

function deleteBasket(v)
{
	if (! confirm("Wollen Sie wirklich den gesamten Warenkorb löschen?"))
	{
		return;
	}
	typeOfAction=440;
	_de="common/shopajax.php";
	_qu="mod=440&SID="+sid;
	sndReqPOST(_de,_qu);
}

function enterOption3()
{
	// document.GKOA.GA[2].value="checked";
	document.GKOA.GA[2].checked=true;
}

function KDFCheck()
{
	d=document.KDF;
	errFlag=false;
	afmMessage='';
	if (! checkKDFormular)
	{
		return;
	}
	while (true)
	{
		if (d.KD_NAME.value=='')
		{
			afmMessage= "Bitte geben Sie Ihren Nachnamen ein...";
			fc=d.KD_NAME;
			errFlag=true;
			break;
		}
		if (d.KD_STRASSE.value=='')
		{
			afmMessage= "Bitte geben Sie Ihre Adresse ein...";
			fc=d.KD_STRASSE;
			errFlag=true;
			break;
		}
		if (d.KD_LAND.value=='')
		{
			afmMessage= "Bitte geben Sie Land und Postleitzahl ein...";
			fc=d.KD_LAND;
			errFlag=true;
			break;
		}
		if (d.KD_PLZ.value=='')
		{
			afmMessage= "Bitte geben Sie Land und Postleitzahl ein...";
			fc=d.KD_PLZ;
			errFlag=true;
			break;
		}
		if (d.KD_ORT.value=='')
		{
			afmMessage= "Bitte geben Sie Ihren Wohnort ein...";
			fc=d.KD_ORT;
			errFlag=true;
			break;
		}
		if (d.KD_PW1)
		{
			if (d.KD_PW1.value=='')
			{
				afmMessage= "Bitte geben Sie Ihr persönliches Passwort ein...";
				fc=d.KD_PW1;
				errFlag=true;
				break;
			}
			if (d.KD_PW2.value=='')
			{
				afmMessage= "Bitte wiederholen Sie Ihr persönliches Passwort...";
				fc=d.KD_PW2;
				errFlag=true;
				break;
			}
			if (d.KD_PW1.value != d.KD_PW2.value)
			{
				afmMessage= "Passwörter nicht identisch, bitte wiederholen Sie die Passwordeingabe...";
				fc=d.KD_PW1;
				errFlag=true;
				break;
			}
		}
		if (d.GOA.value == 1)
		{
			if (d.KD_MAIL.value=='' && d.KD_TEL.value=='')
			{
				afmMessage= "Bitte geben Sie Ihre E-Mailadresse oder Ihre Telefonnummer ein...";
				fc=d.KD_MAIL;
				errFlag=true;
				break;
			}
			else
			{
				if (d.KD_MAIL.value !='')
				{
					if (! emailcheck(d.KD_MAIL.value))
					{
						afmMessage= "Irgendwie sieht Ihre E-Mailadresse nicht nach E-Mailadresse aus...";
						fc=d.KD_MAIL;
						errFlag=true;
						break;
					}
					break;	
				}
				break;
			}
			break;
		}	
		if (d.GOA.value == 2)
		{
			if (d.KD_MAIL.value=='')
			{
				afmMessage= "Bitte geben Sie Ihre E-Mailadresse ein...";
				fc=d.KD_MAIL;
				errFlag=true;
				break;
			}
			else
			{
				if (! emailcheck(d.KD_MAIL.value))
				{
					afmMessage= "Irgendwie sieht Ihre E-Mailadresse nicht nach E-Mailadresse aus...";
					fc=d.KD_MAIL;
					errFlag=true;
					break;
				}
			}
			break;
		}	
		break;
	}	
	if (afmMessage != '')
	{
		alert(afmMessage);
		fc.focus();
	}
	return ! errFlag;	
}



function checkUserPwd(v,_pw)
{
	d=document.KDF;
	if (_pw.value == '')
	{
		if (v == 1)
		{
			alert("Geben Sie bitte Ihr persönliches Password an.")
			// d.KD_PW1.focus();
		}
		if (v == 2)
		{
			alert("Wiederholen Sie bitte Ihr persönliches Password.")
			// d.KD_PW2.focus();
		}
	}
	if (v == 2)
	{
		if (d.KD_PW1.value != _pw.value)
		{
			alert("Die beiden Passwörter stimmen nicht überein, bitte wiederholen Sie die Eingabe...")
			d.KD_PW1.value='';
			_pw.value='';
			d.KD_PW1.focus();
		}
	}
}


function kd_info(v)
{
	
	html1='<p style="margin-left:5px;margin-top:5px;">'
	html2='<br><br><a href="javascript:infoWinClose()">Fenster schliessen...</a></p>';
	
	switch(v)
	{
		case 1:
		{
			tx='Ihre persönlichen Daten und Ihre Adressangaben werden nicht gespeichert. Wir benötigen diese Daten nur zum Versenden Ihrer Bestellung. Die Angabe von Emailadresse und/oder Telefonnummer ist notwendig, damit wir bei Fragen zu Ihrer Bestellung mit Ihnen Kontakt aufnehmen können.<br>Sobald die Lieferung erfolgt ist, werden auch Ihre Angaben zur Lieferadresse gelöscht.<br>Sollten Sie die Absicht haben, öfter bei Weinhandel-Kohlbacher zu bestellen, empfehlen wir Ihnen die Eintragung in die Kundenkartei.';
			wH=290;
			break;
		}
		case 2:
		{
			tx='Eine Eintragung in unsere Kundenkartei empfiehlt sich, wenn Sie mit uns zufrieden sind und öfter bei Weinhandel-Kohlbacher bestellen wollen. Der Eintrag erspart Ihnen die Angabe Ihrer Daten bei der Bestellung und ermöglicht es Ihnen auf Wunsch, Newsletter und aktuelle Angebote von Weinhandel-Kohlbacher zu erhalten. Zu diesem Zweck klicken Sie bitte in das entsprechende Kästchen am Ende des Formulars.<br><br>Sie erhalten nach dem Aufüllen des Formulars Ihr persönliches Password an die von Ihnen angegebene Emailadresse gesandt.<br><br>Auf entsprechenden Wunsch werden Sie jederzeit wieder aus unserer Kundenkartei gelöscht.';
			wH=370;
			break;
		}
		case 3:
		{
			tx='Geben Sie bitte Ihre Emailadresse und Ihr Password an. Sollten Sie das Password vergessen haben, geben Sie bitte nur die Emailadressen an und drücken Sie auf die Weiter-Taste. Sie erhalten danach die Möglichkeit, das Password an die angegebene Emailadresse senden zu lassen.<br><br>Haben Sie Email und Password eingeben, sehen Sie nach dem Drücken der Weiter-Taste die von Ihnen bei der Eintragung angegebenen Daten. Für den Fall, daß die Lieferadresse von der angegebenen Adresse verschieden ist, füllen Sie bitte das Formular mit den Angaben zur Liederadresse Ihrer Bestellung aus.';
			wH=350;
			break;
		}
		
	}


	if (! infoWinVisible)
	{
		currWHandle=infoWin('Information',250,300,250,wH,'')
		infoWinVisible=true;
	}	


	
	document.getElementById(currWHandle+'CONT').innerHTML=html1+tx+html2;
}
function infoWinClose()
{
	// document.getElementById(ID).style.display='none';
	document.getElementById("BODY").removeChild(document.getElementById(currWHandle));
	infoWinVisible=false;
	currWHandle='';
}

function infoWin(caption,xpos,ypos,xlen,ylen,optModul)
{
	guiBorderWidth=gui.normalBorderWidth;
	guiBorderColor1=gui.normalBorderColor1;
	guiBorderColor2=gui.normalBorderColor2;	
	if (optModul != '')
	{
		modul=optModul;
	}
	else
	{
		modul=idCreate();
	}	
	
	var wMain = document.createElement("div");
	/*
	var nI = document.createAttribute("onmousedown");
	nI.nodeValue = "pir_bringToFront(this)";	
	wMain.setAttributeNode(nI);
	*/
	nI = document.createAttribute("id");
	nI.nodeValue = modul;
	wMain.setAttributeNode(nI);
	var nI = document.createAttribute("style");
	nI.nodeValue = "position:absolute;top:"+ypos+"px;left:"+xpos+"px;width:"+xlen+"px;height:"+ylen+"px;z-index:200;background-color:#"+gui.bgColor+";border-style:solid;border-width:"+guiBorderWidth+";border-color:#"+guiBorderColor1+" #"+guiBorderColor2+" #"+guiBorderColor2+" #"+guiBorderColor1+";overflow:hidden;";
	wMain.setAttributeNode(nI);
	document.getElementById("BODY").appendChild(wMain);
	w = document.createElement("div");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"BAR";	
	w.setAttributeNode(nI);
	nI = document.createAttribute("onmousedown");
	if (browser != 1)
	{
		nI.nodeValue = "dragstart(this.parentNode)";	
	}
	else
	{
		nI.nodeValue = drgs;
	}	
	w.setAttributeNode(nI);
	document.getElementById(modul).appendChild(w);
	nI = document.createAttribute("style");
	nI.nodeValue = "position:absolute;top:0px;	left:0px;height:25px;width:100%;padding-top:3px;padding-right:2px;text-align:right;background-color:#"+gui.barBgColor+";";	
	w.setAttributeNode(nI);

	// CONTENT --------------------------------------------------------------------------------------	
	w = document.createElement("div");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"CONT";	
	w.setAttributeNode(nI);
	document.getElementById(modul).appendChild(w);
	nI = document.createAttribute("style");
	// nI.nodeValue = "position:absolute;top:26px;left:0px;height:100%;width:100%;padding-top:3px;padding-right:2px;text-align:right;background-color:#"+gui.barBgColor+";";	
	nI.nodeValue = "position:absolute;top:26px;left:0px;height:100%;width:100%;padding-top:3px;padding-right:2px;";	
	if (gui.contBgColor != '')
	{
		nI.nodeValue += "background-color:#"+gui.contBgColor+";";
	}
	if (gui.contFont != '')
	{
		nI.nodeValue += "font-family:"+gui.contFont+";";
	}
	if (gui.contColor != '')
	{
		nI.nodeValue += "color:#"+gui.contColor+";";
	}
	if (gui.contBorderColorL != '')
	{
		nI.nodeValue += "border-left:"+gui.contBorderWidth+"px solid #"+gui.contBorderColorL+";";
	}
	if (gui.contBorderColorO != '')
	{
		nI.nodeValue += "border-top:"+gui.contBorderWidth+"px solid #"+gui.contBorderColorO+";";
	}
	if (gui.contBorderColorR != '')
	{
		nI.nodeValue += "border-right:"+gui.contBorderWidth+"px solid #"+gui.contBorderColorR+";";
	}
	if (gui.contBorderColorU != '')
	{
		nI.nodeValue += "border-bottom:"+gui.contBorderWidth+"px solid #"+gui.contBorderColorU+";";
	}

	// alert(nI.nodeValue);
	
	w.setAttributeNode(nI);

	
	// TITLE-BAR --------------------------------------------------------------------------------------	
	w = document.createElement("img");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"ICON";	
	w.setAttributeNode(nI);
	document.getElementById(modul+"BAR").appendChild(w);
	document.getElementById(modul+"ICON").src=gui.mainIcon;	
	nI = document.createAttribute("style");
	nI.nodeValue = "position:absolute;top:1px;left:2px;height:23px;width:51;";	
	w.setAttributeNode(nI);
	// --------------------------------------------------------------------------------------
	w = document.createElement("div");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"TITLE";
	w.setAttributeNode(nI);
	// --------------------------------------------------------------------------------------
	w = document.createElement("span");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"CAPTION";	
	w.setAttributeNode(nI);
	var c=document.createTextNode(caption);
	w.appendChild(c);
	document.getElementById(modul+"BAR").appendChild(w);
	nI = document.createAttribute("style");
	nI.nodeValue = "position:absolute;top:5px;left:60px;color:#"+gui.windowTitleColor+";font-family:"+gui.windowTitleFont+";font-size:"+gui.windowTitleSize+";font-weight:"+gui.windowTitleWeight+";font-style:"+gui.windowTitleStyle+";";	
	w.setAttributeNode(nI);
	// --------------------------------------------------------------------------------------
	wSpan = document.createElement("span");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"CONTROL";	
	wSpan.setAttributeNode(nI);
	document.getElementById(modul+"BAR").appendChild(wSpan);

	// --------------------------------------------------------------------------------------
	w = document.createElement("img");
	nI = document.createAttribute("id");
	nI.nodeValue = modul+"ICONCLOSE";	
	w.setAttributeNode(nI);
	document.getElementById(modul+"CONTROL").appendChild(w);
	document.getElementById(modul+"ICONCLOSE").src=gui.closeIcon;	
	nI = document.createAttribute("onclick");
	nI.nodeValue = "infoWinClose('"+modul+"')";	
	w.setAttributeNode(nI);
	
	return modul;
}


// *********************************************************************************************************************************
//
//
//
// *********************************************************************************************************************************


function handleShopResponse(counterVar)
{
	if (typeof(counterVar) == undefined)
	{
		xcounterVar = 0;
	}
	else
	{
		xcounterVar = counterVar +1;
	}
	if (resObject.readyState == 4)
	{
		if (typeOfAction == 100)
		{
			res=resObject.responseText;
			if (res == 'OK')
			{
				alert("Artikel wurde in Warenkorb gelegt...");
			}
			else
			{
				if (res == 'ERROR-21')
				{
					alert("Keine Menge angegeben, wiederholen Sie bitte die Eingabe...");
				}
				if (res == 'ERROR-22')
				{
					alert("Bitte nur ganzzahlige Mengen angegeben, Weinhandel-Kohlbacher verkauft keine halben Sachen...");
				}
				if (res == 'ERROR-23')
				{
					alert("Geben Sie bitte ein ganze Zahl als Menge ein...");
				}
				if (res == 'ERROR-31' || res == 'ERROR-32')
				{
					alert("SERVER-Fehler:Datenbank, "+res+", versuchen Sie bitte die Eingabe zu wiederholen...");
				}
			}
			return;
		}
		if (typeOfAction == 440)
		{
			res=resObject.responseText;
			if (res == 'OK')
			{
				alert("Warenkorb wurde geleert...");
				location.reload(true);
			}
			else
			{
				alert(res);

			}
			return;
		}
	}	
	else
	{
		if (xcounterVar < 1000)
		{
			window.setTimeout('handleShopResponse(xcounterVar)',100);
		}	
	}
	
}

function emailcheck(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);
}
function skinProperty()
{
	this.mainIcon='';
	this.minIcon='';
	this.maxIcon='';
	this.closeIcon='';
	this.normalBorderWidth='';
	this.normalBorderColor1='';
	this.normalBorderColor2='';	
	this.nonMovableBorderWidth='';
	this.nonMovableBorderColor='';
	this.nonCloseBorderWidth='';
	this.nonCloseBorderColor='';
	this.bgColor='';
	this.barBgColor='';
	this.windowTitleColor='';	
	this.windowTitleFont='';
	this.windowTitleSize='';
	this.windwoTitleWeight='';
	this.windowTitleStyle='';
	this.barBgColorNonFocus='';
	this.contBorderWidth='';
	this.contBorderColorL='';
	this.contBorderColorO='';	
	this.contBorderColorR='';		
	this.contBorderColorU='';			
	this.contBgColor='';	
	this.contColor='';		
	this.contFont='';
}

function idCreate()
{
	_id='';
	for (i=1;i < 11;i++)
	{
		_id+=String.fromCharCode(((Math.random()*25).toFixed(0)*1)+65);
	}
	return _id;
}


function checkClientLogin()
{
	d=document.GKOA;
	errFlag=false;
	afmMessage='';
	if (d.CSBUL.value=='2')
	{
		return true;
	}

	while (true)
	{
		if (d.KD_MAIL.value=='')
		{
			afmMessage= "Bitte geben Sie Ihre E-Mailadresse ein...";
			if (d.CSBUL.value == '1')
			{
				afmMessage += "\n\nOhne Angabe Ihrer E-Mailadresse kann Ihnen\n das Password nicht zugesandt werden.";	
			}
			fc=d.KD_MAIL;
			errFlag=true;
			break;
		}
		else
		{
			if (! emailcheck(d.KD_MAIL.value))
			{
				afmMessage= "Irgendwie sieht Ihre E-Mailadresse nicht nach E-Mailadresse aus...";
				fc=d.KD_MAIL;
				errFlag=true;
				break;
			}
		}
		if (d.KD_PWD.value=='' && d.CSBUL.value =='')
		{
			afmMessage= "Bitte geben Sie Ihr persönliches Password ein oder\nklicken Sie auf 'Password zusenden' für den Fall,\ndaß Sie Ihr Password vergessen haben ...";
			fc=d.KD_PWD;
			errFlag=true;
			break;
		}
		break;
	}	
	if (afmMessage != '')
	{
		alert(afmMessage);
		fc.focus();
	}
	return ! errFlag;	
}

function checkSubmitButtonUserLogin(v)
{
	if (v == 0)
	{
		document.GKOA.CSBUL.value='';
	}
	else
	{
		document.GKOA.CSBUL.value=v;
	}
}

