/********************************************************/
/** JAVASCRIPT LIBRARY V1.00 WEBSHOP SYSTEM            **/
/********************************************************/
/** Copyright: (C) 2009 RightVision GmbH               **/
/********************************************************/
var deftxt 	= " Tierärztebedarf J. Lehnecke GmbH ";
var defsuch	= "Suchbegriff";
var loaderpage = "/data/loader.html";
var remoteUser = '';
/********************************************************************************/
/* Fehlerbehandlungsroutine:                                                    */ 
/* Aufruf eines NotesAgenten, der das "webdoc" Document automatisch abspeichert */
/********************************************************************************/
function sendScriptError(Nachricht, Datei, Zeile) {
	var domainName = 'lehnecke.de';
	var errorMessage = 'ScriptFehler in Datei ' + Datei + ' Zeile ' + Zeile + ': ' + Nachricht;
	var ajaxURL = '/rvha_error/org=' + domainName + '&cust=' + remoteUser + '&err=' + errorMessage;
	try {
		ajaxGETRequest(ajaxURL, function(){});
	} catch(err) {}
	return false;	// Browser zeigt den Fehler an.
}
window.onerror = sendScriptError;
function ajaxGETRequest(url, callbackFunction) { 
	var http_request = false; 
	if (window.XMLHttpRequest) { // Mozilla, Safari,...
		http_request = new XMLHttpRequest();
	} else if (window.ActiveXObject) { // IE
		try {
			http_request = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (err) {}
	} 
	if (!http_request) {
		try {
			alert('Fehler: XMLHTTP-Instanz kann nicht erstellt werden.');
		} catch(err) {}
		return false;
	}	
	if (url.indexOf('ts=') <= 0) {
		url = url + "&amp;ts=" + new Date().getTime();
	}
	http_request.open('GET', url, true);
	http_request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
	http_request.onreadystatechange = function() { 
			if (http_request.readyState != 4)  { return; }
			callbackFunction(http_request); 
		}	
	http_request.send(null); 
}
/********************************************************/
/** Warenkorbfunktionen                                **/
/********************************************************/
var mouse_x_pos = 0;
var mouse_y_pos = 0;
var scrOfX = 0;
var scrOfY = 0;
var window_size_x = 0;
var window_size_y = 0;
function getMousePosition(e,callUser) { 
	if (e == undefined) e = window.event; 
	if (e.pageX || e.pageY) {  
		mouse_x_pos = e.pageX;  
		mouse_y_pos = e.pageY; 
	} 
	else if (e.clientX || e.clientY) {  
		mouse_x_pos = e.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;  
		mouse_y_pos = e.clientY + document.body.scrollTop + document.documentElement.scrollTop; 
	}
	try {
		document.MausKoordinaten.mPositionX.value = mouse_x_pos;
		document.MausKoordinaten.mPositionY.value = mouse_y_pos;
	} catch(err) {}
}

function getScrollXY() {
	if( typeof( window.pageYOffset ) == 'number' ) {
		//Netscape compliant
		scrOfY = window.pageYOffset;
		scrOfX = window.pageXOffset;
	} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
		//DOM compliant
		scrOfY = document.body.scrollTop;
		scrOfX = document.body.scrollLeft;
	} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
		//IE6 standards compliant mode
		scrOfY = document.documentElement.scrollTop;
		scrOfX = document.documentElement.scrollLeft;
	}
}

function getWindowSize() {
	if( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		window_size_x = window.innerWidth;
		window_size_y = window.innerHeight;
	} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		window_size_x = document.documentElement.clientWidth;
		window_size_y = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		window_size_x = document.body.clientWidth;
		window_size_y = document.body.clientHeight;
	}
}

function getUploadFileName(indexFeldName) {
	var temps0 = document.forms[0].elements["Upload0" + indexFeldName];
	var dateiname = temps0.value.toUpperCase();
	if (dateiname.search(/./) != -1) {
       document.forms[0].elements["UploadedFileName" + indexFeldName].value = temps0.value;
	}
}

function rvAddCart(produkt,artikel) {
	anzahl = document.getElementById(artikel).value;
	if (anzahl.match(/\D/g) == null) {
		location.href = '/webshop.aspx&prod='+produkt+'&wko=b&o='+artikel+'&m='+anzahl;
	} else {
		alert('Nur numerische Werte für die Menge gültig.');
	}
}
function CheckNumber(field) {
	try {
		if (isNaN(document.getElementById(field).value)) {
			alert('In diesem Feld bitte nur Zahlen verwenden.');
			document.getElementById(field).focus();
			document.getElementById(field).select(); 
			return false;
		} else {
			return true;
		}
	} catch(err) {}
}

/********************************************************/
/** Bild/Picture-Funktionen                            **/
/********************************************************/

var PicCounter = 10;
var canClose = 0;
function OpenPic(breite,ID,richtung) {
 document.getElementById("PicArea-"+ID).style.display = "inline";
 if (PicCounter < breite) {
  document.getElementById(ID).style.display = "inline";
  document.getElementById("pix-"+ID).style.display = "inline";
  document.getElementById("pix-"+ID).style.width = PicCounter+"px";
  if (richtung == "width") {
	document.getElementById(ID).style.width = PicCounter+"px";
  } else {
	document.getElementById(ID).style.height = PicCounter+"px";
  }  
  PicCounter++; 
  PicCounter++;
  canClose = 0;  
  window.setTimeout("OpenPic("+breite+",'"+ID+"','"+richtung+"')",0);
 }
 else {
  document.getElementById("PicDesc-"+ID).style.display="block";
  canClose = 1;
 }
}
function ClosePic(ID) {
if (canClose == 1) {
	document.getElementById(ID).style.display="none";
	document.getElementById("PicDesc-"+ID).style.display="none";
	document.getElementById("PicArea-"+ID).style.display="none";
	document.getElementById("pix-"+ID).style.display="none";
	PicCounter = 10;
 }
}


/********************************************************/
/** Suchfunktionen ausgelagert in RVSearch.js          **/
/********************************************************/


/********************************************************/
/** Fenster und PopUp Funktionen                       **/
/********************************************************/

var myie5 = document.all && document.getElementById;
var myns6 = document.getElementById && !document.all;
var ns4 = document.layers;
var ie4 = document.all;
var ns6 = document.getElementById && !document.all;
var dragswitch = 0;
var nsx; 
var nsy;
var nstemp; 

function rvOpen(n,d,w,h) {
	var l = screen.availWidth - w - 10;
	var win = window.open(d,n,"width="+w+",height="+h+",status=no,toolbar=no,menubar=no,scrollbars=1,resizable=0,top=0,left="+l);
	win.focus();
}
function rvOpen2(n,d,w,h) {
	alert('Diese Seite arbeitet in vielen Bereichen mit PopUp-Fenstern.\nSollten Sie einen PopUp-Stopper aktiviert haben, geben Sie diese WebSite bitte für neue PopUps frei.\nDie Registrierung öffnet sich nach Klick auf OK...');
	var l = screen.availWidth - w - 10;
	var win = window.open(d,n,"width="+w+",height="+h+",status=no,toolbar=no,menubar=no,scrollbars=1,resizable=0,top=0,left="+l);
	win.focus();
}
function rvOpen3(n,d,w,h,x,y) {
	var win = window.open(d,n,"width="+w+",height="+h+",status=no,toolbar=no,menubar=no,scrollbars=1,resizable=0,top="+x+",left="+y);
	win.focus();
}
function rvWin(n,d,w,h) {
	var l = screen.availWidth - w;
	var win = window.open(d,n,"width="+w+",height="+h+",status=yes,toolbar=yes,menubar=yes,scrollbars=1,resizable=1,top=0,left="+l);
	win.focus();
}
function rvPrint(n) {
	var win = window.open(n,"PrintView","width=150,height=150,top=1,left=1,status=No,menubar=No,scrollbars=No, 		resizable=No,toolbar=No,alwaysLowered=Yes");
}

function CheckIsIE() { 
	if (navigator.appName.toUpperCase() == 'MICROSOFT INTERNET EXPLORER') { return true;} 
	else { return false; } 
} 
function PrintIt() { 
	if (CheckIsIE() == true) 
	{ 
		document.wwframe.focus(); 
		document.wwframe.print(); 
	} else { 
		window.frames['wwframe'].focus(); 
		window.frames['wwframe'].print(); 
	} 
} 
function loadlayer(url,width,height,wleft,wtop,whead,scrolling) {
	var datum = new Date();
	if (!myie5&&!myns6) 
		rvOpen(url,whead,width,height);
		//window.open(url,"","width=width,height=height,scrollbars=1")
	else {
		document.getElementById("wwindow").visibilty ='visible';
		document.getElementById("wwindow").style.display='inline';
		document.getElementById("wwindow").style.width=initialwidth=width+"px";
		document.getElementById("wwindow").style.height=initialheight=height+"px";
		document.getElementById("wwindow").style.left=wleft+"px";
		document.getElementById("wwindow").style.top=wtop+"px";
		if ( scrolling == 'noscroll') {
			document.getElementById("wwframe").scrolling = 'no';
		}
		try {
		document.getElementById("wwframe").src=url;
		document.getElementById("wwname").innerHTML = '&nbsp;&nbsp;' + url;
		document.getElementById("wwdate").innerHTML = datum.getDate() + '.' + (datum.getMonth()+1) + '.' + datum.getYear() + '&nbsp;&nbsp;';
		document.getElementById("wwindow").style.top=myns6? window.pageYOffset*1+wtop+"px" : top.iecompattest().scrollTop*1+wtop+"px";
		} catch(err) {}
     }
}
function drag_dropns(name){ 
	if (!ns4) 
		return; 
	temp=eval(name); 
	temp.captureEvents(Event.MOUSEDOWN | Event.MOUSEUP); 
	temp.onmousedown=gons; 
	temp.onmousemove=dragns; 
	temp.onmouseup=stopns; 
} 
function gons(e){ 
	temp.captureEvents(Event.MOUSEMOVE); 
	nsx=e.x; 
	nsy=e.y; 
} 
function dragns(e){ 
	if (dragswitch==1){ 
		temp.moveBy(e.x-nsx,e.y-nsy); 
		return false; 
	} 
} 
function stopns(){ 
	temp.releaseEvents(Event.MOUSEMOVE); 
} 
function drag_drop(e){ 
	if (ie4&&dragapproved){ 
		crossobj.style.left=tempx+event.clientX-offsetx; 
		crossobj.style.top=tempy+event.clientY-offsety; 
		return false; 
	} 
	else if (ns6&&dragapproved){ 
		crossobj.style.left=tempx+e.clientX-offsetx; 
		crossobj.style.top=tempy+e.clientY-offsety; 
		return false; 
	} 
} 
function initializedrag(e){ 
	crossobj=ns6? document.getElementById("wwindow") : document.all.wwindow; 
	var firedobj=ns6? e.target : event.srcElement; 
	var topelement=ns6? "HTML" : "BODY"; 
	while (firedobj.tagName!=topelement&&firedobj.id!="dragbar"){ 
		firedobj=ns6? firedobj.parentNode : firedobj.parentElement; 
	} 
	if (firedobj.id=="dragbar"){ 
		offsetx=ie4? event.clientX : e.clientX; 
		offsety=ie4? event.clientY : e.clientY; 
		tempx=parseInt(crossobj.style.left); 
		tempy=parseInt(crossobj.style.top); 
		dragapproved=true; 
		document.onmousemove=drag_drop; 
	} 
} 
function hidebox(){
	document.getElementById("wwframe").src=loaderpage;
	document.getElementById("wwindow").style.display='none';
} 

function loadwindow(url,width,height,wleft,wtop,whead) {
	if ( !ie5 && !ns6 ) {
		rvOpen(url,whead,width,height);
	} else {
		document.getElementById("EditWindow").style.display='';
		document.getElementById("EditWindow").style.width=initialwidth=width+"px";
		document.getElementById("EditWindow").style.height=initialheight=height+"px";
		document.getElementById("EditWindow").style.left=wleft+"px";
		document.getElementById("EditWindow").style.left=wleft+"px";
		document.getElementById("EditWindow").style.top=ns6? window.pageYOffset*1+wtop+"px" : top.iecompattest().scrollTop*1+wtop+"px";
		document.getElementById("EditFrame").src=url;
		scroll(0,0);
	}
}
function closeit() {
		document.getElementById("EditWindow").style.display="none";
}
function editclose() {
		document.getElementById("EditWindow").style.display="none";
		document.location.reload();
}

document.onmousedown=initializedrag
document.onmouseup=new Function("dragapproved=false")

/********************************************************/
/** Diverses                                           **/
/********************************************************/

function handleEventHillsSelector() {
	var formular = document.forms["formWarenkorb"];
	var selection = formular.elements["hillsSelector"].selectedIndex; 
	var auswahl = formular.elements["hillsSelector"].options[selection].text;
	//alert('Auswahl: ' + auswahl);
	location.href = "/webshop.aspx&showwko=2&orderhp=1&s=" + auswahl + "&rt=1";
}

function handleEventWKOAddressSelector(addressType) {
//
//	Formular: Warenkorb
//	Switch Display of Rechnungsanschrift / Lieferanschrift / Zahlungsdaten via AJAX
//
	var typeName = addressType.toUpperCase();
	var formular = document.forms["formWarenkorb"];
	var selection = formular.elements[typeName+"Selector"].selectedIndex; 
	var auswahl = formular.elements[typeName+"Selector"].options[selection].text;
	var ajaxObjectAddressSelector = new Object();
	ajaxObjectAddressSelector.basedomain = "http://" + window.location.hostname;
	ajaxObjectAddressSelector.ajaxobj = createAjaxObj();
	ajaxObjectAddressSelector.filetype = "txt";
	ajaxObjectAddressSelector.addrandomnumber = 1;
	ajaxObjectAddressSelector.getAjaxRequest = function(url, parameters, callbackfunc, filetype){
		ajaxObjectAddressSelector.ajaxobj = createAjaxObj();
		if (ajaxObjectAddressSelector.addrandomnumber == 1){
			var parameters = parameters + "&amp;ts=" + new Date().getTime();
		}
		if (this.ajaxobj){
			this.filetype = filetype;
			this.ajaxobj.onreadystatechange = callbackfunc;
			this.ajaxobj.open('GET', url + "?" + parameters, true);
			this.ajaxobj.send(null);
		}
	}
	function callbackFunction() {
		var responseBody = "";
		var myajax = ajaxObjectAddressSelector.ajaxobj;
		var myfiletype = ajaxObjectAddressSelector.filetype;
		if (myajax.readyState == 4){
			if (myajax.status == 200 | window.location.href.indexOf("http") == -1){
				if (myfiletype == "txt"){
					responseBody = myajax.responseText;
				} else {
					responseBody = myajax.responseXML;
				}
				if (responseBody.indexOf("<xmlresponse>") >= 0 ) {
					responseBody = responseBody.replace("<xmlresponse>", "");
					responseBody = responseBody.replace("</xmlresponse>", "");
				}
				if (responseBody.indexOf("##") > 0 ) {				
					var theSplit = responseBody.split("##");
					var theName = "";
					if (typeName == "RG") {
						if ( theSplit[1] != "" ) { theName = theName + "Kontoinhaber: " + theSplit[1] + "&nbsp;"; }
						if ( theSplit[2] != "" ) { theName = theName + "<br/>Konto-Nr.: XXX" + theSplit[2] + "&nbsp;"; }
						if ( theSplit[3] != "" ) { theName = theName + "<br/>Bankleitzahl: " + theSplit[3] + "&nbsp;"; }
						if ( theSplit[4] != "" ) { theName = theName + "<br/>" + theSplit[4] + "&nbsp;"; }	
					} else {
						if ( theSplit[1] != "" ) { theName = theName + "" + theSplit[1] + "&nbsp;"; }
						if ( theSplit[2] != "" ) { theName = theName + "<br/>" + theSplit[2] + "&nbsp;"; }
						if ( theSplit[3] != "" ) { theName = theName + "<br/>" + theSplit[3] + "&nbsp;"; }
						if ( theSplit[4] != "" ) { theName = theName + "<br/>" + theSplit[4] + "&nbsp;"; }			
					}
					if (typeName == "RE") {
						theName = theName + "<br/>" + theSplit[5] + "&nbsp;" + "<br/>" + theSplit[6] + " " + theSplit[7] + " " + theSplit[8] + "&nbsp;";
					}
					if (typeName == "WE") {
						theName = theName + "<br/>" + theSplit[5] + "&nbsp;" + "<br/>" + theSplit[6] + " " + theSplit[7] + " " + theSplit[8] + "&nbsp;";
					}					
					document.getElementById("Selected" + typeName).value = theSplit[0];
					document.getElementById("Display" + typeName).innerHTML = theName;					
					var was = window.location.href;
					if (was.indexOf("ts=") > 0) {	
						theSplit = was.split("ts=");
						was = theSplit[0] + "ts=" + new Date().getTime();
					}
				}
			}
		}
	}
	theSplit = auswahl.split(":");
	requestString = "OpenAgent&aw=" + theSplit[0] + "&tp=" + addressType + "&save=1";
	ajaxObjectAddressSelector.getAjaxRequest("/data/ajaxUpdateAnschrift.aspx", requestString, callbackFunction, "txt");
}


function rvWait(mytext1) {
// Automatische Positionierung:
// Layer wird über den aktiven Fensterbereich des Browser's gelegt.
// RVtme 13.08.2009
	getScrollXY();
	getWindowSize();
	document.getElementById("LoadWait").style.left = "0px";
	document.getElementById("LoadWait").style.top = scrOfY + "px";
	document.getElementById("LoadWait").style.width = window_size_x + "px";
	document.getElementById("LoadWait").style.height = window_size_y + "px";
	var mytext = '<strong>'+mytext1+'</strong><br/><br/><span class="LoadWaitB">bitte warten...</span>';
	document.getElementById("LoadWaitText").innerHTML = mytext;
	document.getElementById("LoadWait").style.visibility = 'visible';
}

function ReplaceViaAjax(url,parm,id,timer) {
	var mytimer = timer; 
	var mydiv = id;
	var myurl = url;
	var myparm = parm;
	opacity('rvloader',0,100,500); 
	callajax(myurl,myparm,mydiv); 
	mystring = 'opacity(\'rvloader\',100,0,1000)';
	setTimeout(mystring,2000);
	if ( mytimer > 0 ) {
		mystring = 'ReplaceViaAjax(\'' + myurl + '\',\'' + myparm + '\',\'' + mydiv + '\',\'' + mytimer + '\')';
		setTimeout(mystring,mytimer);
	}
}
function sleep(ms) {
	var start = new Date().getTime();
	var cur = start
	var msecs = ms*1000;
	while( cur - start < msecs )
	{
		cur = new Date().getTime();
	}
} 
function AddBookmark(URL,TITLE){
	if (window.sidebar) { // Mozilla Firefox Bookmark
	window.sidebar.addPanel(TITLE, URL,"");
	} else if( window.external ) { // IE Favorite
	window.external.AddFavorite( URL, TITLE); }
	else if(window.opera && window.print) { // Opera Hotlist
	return true; }
}
function RVCopyLink(url) {
	if (url === '') {
		alert('Link ist leer....');
	} else {
		window.clipboardData.setData('Text',url);
	}
}
function SendMail(address) {
	var myNewString = address.replace(" AT ","@");
	location.href = "mailto:" + myNewString;
}

/********************************************************/
/** FADING-Effekte                                           **/
/********************************************************/

function opacity(id, opacStart, opacEnd, millisec) { 
	var speed = Math.round(millisec / 100); 
	var timer = 0; 
	if(opacStart > opacEnd) { 
		for(i = opacStart; i >= opacEnd; i--) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
            	timer++; 
        	} 
	} else if(opacStart < opacEnd) { 
		for(i = opacStart; i <= opacEnd; i++) { 
			setTimeout("changeOpac(" + i + ",'" + id + "')",(timer * speed)); 
           		timer++; 
		}
	} 
} 
function changeOpac(opacity, id) { 
    var object = document.getElementById(id).style; 
    object.opacity = (opacity / 100); 
    object.MozOpacity = (opacity / 100); 
    object.KhtmlOpacity = (opacity / 100); 
    object.filter = "alpha(opacity=" + opacity + ")"; 
} 
function shiftOpacity(id, millisec) { 
    //if an element is invisible, make it visible, else make it ivisible 
    if(document.getElementById(id).style.opacity == 0) { 
        opacity(id, 0, 100, millisec); 
    } else { 
        opacity(id, 100, 0, millisec); 
    } 
} 

/********************************************************/
/** Diverses 2                                         **/
/********************************************************/

function playsound(surl,svol) {
	document.getElementById("rvsound").innerHTML="<embed src='"+surl+"' hidden=true autostart=true loop=false volume="+svol+" />";
}

function showText(id) {
	var c_visible = "visibleText";
	var c_invisible = "invisibleText";
	for(i = 2; i <= 4; i++) {
		var n = document.getElementById("text_" + i);
		n.className = ("text_" + i == id ? (n.className == c_visible ? c_invisible : c_visible) : c_invisible); 
	}
}

function getSelectedRadio(buttonGroup) {
  // returns the array number of the selected radio button or -1 if no button is selected
   if (buttonGroup[0]) { // if the button group is an array (one button is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            return i
         }
      }
   } else {
      if (buttonGroup.checked) { return 0; } // if the one button is checked, return zero
   }
   // if we get to this point, no radio button is selected
   return -1;
}

function getSelectedRadioValue(buttonGroup) {
   // returns the value of the selected radio button or "" if no button is selected
   var i = getSelectedRadio(buttonGroup);
   if (i == -1) {
      return "";
   } else {
      if (buttonGroup[i]) { // Make sure the button group is an array (not just one button)
         return buttonGroup[i].value;
      } else { // The button group is just the one button, and it is checked
         return buttonGroup.value;
      }
   }
}

function getSelectedCheckbox(buttonGroup) {
   // Go through all the check boxes. return an array of all the ones
   // that are selected (their position numbers). if no boxes were checked,
   // returned array will be empty (length will be zero)
   var retArr = new Array();
   var lastElement = 0;
   if (buttonGroup[0]) { // if the button group is an array (one check box is not an array)
      for (var i=0; i<buttonGroup.length; i++) {
         if (buttonGroup[i].checked) {
            retArr.length = lastElement;
            retArr[lastElement] = i;
            lastElement++;
         }
      }
   } else { // There is only one check box (it's not an array)
      if (buttonGroup.checked) { // if the one check box is checked
         retArr.length = lastElement;
         retArr[lastElement] = 0; // return zero as the only array value
      }
   }
   return retArr;
}

function getSelectedCheckboxValue(buttonGroup) {
   // return an array of values selected in the check box group. if no boxes
   // were checked, returned array will be empty (length will be zero)
   var retArr = new Array(); // set up empty array for the return values
   var selectedItems = getSelectedCheckbox(buttonGroup);
   if (selectedItems.length != 0) { // if there was something selected
      retArr.length = selectedItems.length;
      for (var i=0; i<selectedItems.length; i++) {
         if (buttonGroup[selectedItems[i]]) { // Make sure it's an array
            retArr[i] = buttonGroup[selectedItems[i]].value;
         } else { // It's not an array (there's just one check box and it's selected)
            retArr[i] = buttonGroup.value;// return that value
         }
      }
   }
   return retArr;
}

