var _strOrderFormNoAgb = "Bitte lesen Sie die AGBs und best\xE4tigen Sie diese um mit der Bestellung fortzufahren!";
var actCartStatus = true;
var helpStatus = false;

// hightlight
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// open_window
function showclip(w,h,l,t,scrolling) {
	clipviewer = window.open("kontaktformular.php", "Clip", "width="+w+",height="+h+",left="+l+",top="+t+",scrollbars="+scroll);
	clipviewer.focus();
}

function weitere_infos(w,h,l,t,itemid) {
	clipviewer = window.open("more_info.php?itemID="+itemid, "Clip", "width="+w+",height="+h+",left="+l+",top="+t+",scrollbars");
	clipviewer.focus();
}

function bild_laden(w,h,l,t) {
	clipviewer = window.open("load_picture.htm", "Clip", "width="+w+",height="+h+",left="+l+",top="+t);
	clipviewer.focus();
}

function priceHint(){
	alert('Bitte beachten Sie, dass bei Speichern des Landes alle Preise gel?scht werden, wenn Sie dem Land die eigenen Preise entziehen!');
}

// formular
var werte=new Array();

werte["user_name"]="Benutzername";
werte["password"]="Passwort";
werte["search_string"]="Name / Artikelnr.";
werte["firma"]="Firma";
werte["name"]="Name (*)";
werte["prename"]="Vorname (*)";
werte["strasse"]="Strasse (*)";
werte["ort"]="Ort (*)";
werte["email"]="E-mail (*)";
werte["telefon"]="Telefon ";
werte["artikelname"]="Artikelname";
werte["kurzbeschreibung"]="Kurzbeschreibung";
werte["langbeschreibung"]="Langbeschreibung";
werte["moreInfos"]="weitere Infos";
werte["artnr"]="Art.-Nr.";
werte["inhalt"]="Inhalt";


var imOnFocus = new Array();

function clearValue(obj){
	if(obj.value == werte[obj.name]){
		obj.value="";
	}
}

function checkValue(obj){
	if (imOnFocus.length>0){
		if(imOnFocus[0].value==""){
			imOnFocus[0].value = werte[imOnFocus[1]];
		}
	}
	if(obj.value == werte[obj.name]){
		obj.value="";
	}
	imOnFocus[0] = obj;
	imOnFocus[1] = obj.name;
}

function swapImage(){
var i, x, a = swapImage.arguments;
 x = a[0]
 x.src = a[1];
}
function switchHelpVisibility(){
	if(!helpStatus){
		obj = document.getElementById('help');
		obj.style.display='block';
	}
	else{
		obj = document.getElementById('help');
		obj.style.display='none';
	}
	helpStatus = !helpStatus;
}

function calculateWarenkorbHeight(show,item_amount,first_height,item_height,max_height,hide){
	var newHeight,calculatedHeight,maxHeight;
	if( hide || !actCartStatus){
	//	newHeight = item_height+10;
		newHeight = 0;
	}
	else{

		maxHeight = max_height;

		calculatedHeight = (item_amount-1)*item_height + first_height;
		if(show && item_amount !=0){
			newHeight = calculatedHeight;
		}
		else{
			newHeight = 0;
		}
		if(newHeight > maxHeight){
			newHeight = maxHeight;
		}
	}
	//alert('*,'+newHeight);
	top.document.getElementById('main_frameset').rows='*,'+newHeight;
}




function checkPaymentForm()
{
	form = document.paymentForm;

	if(form.agb.checked)
	{
		document.paymentForm.submit();
	}
	else{
		alert(_strOrderFormNoAgb);
		form.agb.focus();
	}
}

function checkRegisterForm()
{
   form = document.registerform;
   if(form.nick.value == "")
   {
      alert(_strRegisterFormNoNick);
      form.nick.focus();
      return false;
   }
   if(form.pw.value == "")
   {
      alert(_strRegisterFormNoPw);
      form.pw.focus();
      return false;
   }
   if(form.pwconfirm.value == "")
   {
      alert(_strRegisterFormNoPwConfirm);
      form.pwconfirm.focus();
      return false;
   }
   if(form.pwconfirm.value != form.pw.value)
   {
      alert(_strRegisterFormPwNotIdentical);
      form.pwconfirm.focus();
      return false;
   }
   if(form.anrede.value == "")
   {
      alert(_strRegisterFormNoTitle);
      form.anrede.focus();
      return false;
   }
   if(form.vorname.value == "")
   {
      alert(_strRegisterFormNoFirstName);
      form.vorname.focus();
      return false;
   }
   if(form.nachname.value == "")
   {
      alert(_strRegisterFormNoName);
      form.nachname.focus();
      return false;
   }

   if(form.strasse.value == "")
   {
      alert(_strRegisterFormNoStreet);
      form.strasse.focus();
      return false;
   }

   if(form.ort.value == "")
   {
      alert(_strRegisterFormNoCity);
      form.ort.focus();
      return false;
   }

   var chkPLZ = 1;
   if(chkPLZ == - 1)
   {
      alert(_strRegisterFormWrongPLZ);
      form.plz.focus();
      return false;
   }

   if(form.vorwahl.value == "")
   {
	   alert(_strRegisterFormNoPreSelection);
	   form.vorwahl.focus();
	   return false;
   }

   if(form.vorwahl.value != "")
   {
	   var chkZ = 1;
	   for(i = 0; i < form.vorwahl.value.length;++i)
	   {
		   if((form.vorwahl.value.charAt(i) < "0" || form.vorwahl.value.charAt(i) > "9") && form.vorwahl.value.charAt(i) != "/" && form.vorwahl.value.charAt(i) != " " && form.vorwahl.value.charAt(i) != "-" && form.vorwahl.value.charAt(i) != "\\")
		   {
			   chkZ = - 1;
		   }
	   }
	   if(chkZ == - 1)
	   {
		   alert(_strRegisterFormWrongPhone);
		   form.vorwahl.focus();
		   return false;
	   }
   }

   if(form.telefon.value == "")
   {
	   alert(_strRegisterFormNoPhoneNumber);
	   form.telefon.focus();
	   return false;
   }

   if(form.telefon.value != "")
   {
      var chkZ = 1;
      for(i = 0; i < form.telefon.value.length;++i)
      {
         if((form.telefon.value.charAt(i) < "0" || form.telefon.value.charAt(i) > "9") && form.telefon.value.charAt(i) != "/" && form.telefon.value.charAt(i) != " " && form.telefon.value.charAt(i) != "-" && form.telefon.value.charAt(i) != "\\")
         {
            chkZ = - 1;
         }
      }
      if(chkZ == - 1)
      {
         alert(_strRegisterFormWrongPhone);
         form.telefon.focus();
         return false;
      }
   }
   if(form.telefax.value != "")
   {
      var chkZ = 1;
      for(i = 0; i < form.telefax.value.length;++i)
      {
         if((form.telefax.value.charAt(i) < "0" || form.telefax.value.charAt(i) > "9") && form.telefax.value.charAt(i) != "/" && form.telefax.value.charAt(i) != " " && form.telefax.value.charAt(i) != "-" && form.telefax.value.charAt(i) != "\\")
         {
            chkZ = - 1;
         }
      }
      if(chkZ == - 1)
      {
         alert(_strRegisterFormWrongFax);
         form.telefax.focus();
         return false;
      }
   }
   if(form.werber_nachname.value == "")
   {
	   alert(_strRegisterFormNoReferrerName);
	   form.werber_nachname.focus();
	   return false;
   }
   if(form.werber_ort.value == "")
   {
	   alert(_strRegisterFormNoReferrerCity);
	   form.werber_ort.focus();
	   return false;
   }
   if(form.email.value == "")
   {
	   alert(_strRegisterFormNoEmail);
	   form.email.focus();
	   return false;
   }
   if(form.email_confirm.value != form.email.value)
   {
      alert(_strRegisterFormNotIdenticalEmail);
      form.email.focus();
      return false;
   }
   email_regexp = form.email.value.match(/^.+@{1}.+[.]{1}.{1,4}$/);
   if(!email_regexp)
   {
   	   alert(_strRegisterFormWrongEmail);
	   form.email.focus();
	   return false;
   }

   return true;
}

function checkRegEditForm()
{
   form = document.regeditform;

   if(form.nick.value == "")
   {
      alert(_strRegisterFormNoNick);
      form.nick.focus();
      return false;
   }
   if(form.pwconfirm.value != form.pw.value)
   {
      alert(_strRegisterFormPwNotIdentical);
      form.pwconfirm.focus();
      return false;
   }
   if(form.anrede.value == "")
   {
      alert(_strRegisterFormNoTitle);
      form.anrede.focus();
      return false;
   }
   if(form.vorname.value == "")
   {
      alert(_strRegisterFormNoFirstName);
      form.vorname.focus();
      return false;
   }
   if(form.nachname.value == "")
   {
      alert(_strRegisterFormNoName);
      form.nachname.focus();
      return false;
   }

   if(form.strasse.value == "")
   {
      alert(_strRegisterFormNoStreet);
      form.strasse.focus();
      return false;
   }

   if(form.ort.value == "")
   {
      alert(_strRegisterFormNoCity);
      form.ort.focus();
      return false;
   }

   var chkPLZ = 1;
   for(i = 0; i < form.plz.value.length;++i)
   if(form.plz.value.charAt(i) < "0" || form.plz.value.charAt(i) > "9") chkPLZ = - 1;
   if(chkPLZ == - 1)
   {
      alert(_strRegisterFormWrongPLZ);
      form.plz.focus();
      return false;
   }
   if(form.email.value == "")
   {
      alert(_strRegisterFormNoEmail);
      form.email.focus();
      return false;
   }
   if(form.email.value.indexOf('@') == - 1)
   {
      alert(_strRegisterFormWrongEmail);
      form.email.focus();
      return false;
   }
   if(form.telefon.value != "")
   {
      var chkZ = 1;
      for(i = 0; i < form.telefon.value.length;++i)
      {
         if((form.telefon.value.charAt(i) < "0" || form.telefon.value.charAt(i) > "9") && form.telefon.value.charAt(i) != "/" && form.telefon.value.charAt(i) != " " && form.telefon.value.charAt(i) != "-" && form.telefon.value.charAt(i) != "\\")
         {
            chkZ = - 1;
         }
      }
      if(chkZ == - 1)
      {
         alert(_strRegisterFormWrongPhone);
         form.telefon.focus();
         return false;
      }
   }
   if(form.telefax.value != "")
   {
      var chkZ = 1;
      for(i = 0; i < form.telefax.value.length;++i)
      {
         if((form.telefax.value.charAt(i) < "0" || form.telefax.value.charAt(i) > "9") && form.telefax.value.charAt(i) != "/" && form.telefax.value.charAt(i) != " " && form.telefax.value.charAt(i) != "-" && form.telefax.value.charAt(i) != "\\")
         {
            chkZ = - 1;
         }
      }
      if(chkZ == - 1)
      {
         alert(_strRegisterFormWrongFax);
         form.telefax.focus();
         return false;
      }
   }

   // checking if billing address is complete, if one field was entered.
   if(form.rechnung_vorname!="" || form.rechnung_nachname!="" || form.rechnung_firma!="" || form.rechnung_strasse!=""  || form.rechnung_plz!="" || form.rechnung_ort!=""){
   	if(form.rechnung_vorname == "" || form.rechnung_nachname == "" || form.rechnung_strasse == ""  || form.rechnung_plz == "" || form.rechnung_ort == ""){
   		alert(_strRegisterFormBillAddressNotComplete);
        form.rechnung_vorname.focus();
   		return false;
   	}
   }
   return true;
}

var day;
var month;
var year;
var hour;
var minute;
var second;
var clock_set = 0;

/**
 * Opens calendar window.
 *
 * @param   string      calendar.php parameters
 * @param   string      form name
 * @param   string      field name
 * @param   string      edit type - date/timestamp
 */
function openCalendar(form, field, type) {
    window.open("./calendar/calendar.php", "calendar", "width=400,height=200,status=yes");
    dateField = eval("document." + form + "." + field);
    dateType = type;
}

/**
 * Formats number to two digits.
 *
 * @param   int number to format.
 */
function formatNum2(i, valtype) {
    f = (i < 10 ? '0' : '') + i;
    if (valtype && valtype != '') {
        switch(valtype) {
            case 'month':
                f = (f > 12 ? 12 : f);
                break;

            case 'day':
                f = (f > 31 ? 31 : f);
                break;

            case 'hour':
                f = (f > 24 ? 24 : f);
                break;

            default:
            case 'second':
            case 'minute':
                f = (f > 59 ? 59 : f);
                break;
        }
    }

    return f;
}

/**
 * Formats number to four digits.
 *
 * @param   int number to format.
 */
function formatNum4(i) {
    return (i < 1000 ? i < 100 ? i < 10 ? '000' : '00' : '0' : '') + i;
}

/**
 * Initializes calendar window.
 */
function initCalendar() {
    if (!year && !month && !day) {
        /* Called for first time */
        if (window.opener.dateField.value) {
            value = window.opener.dateField.value;
            if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
                if (window.opener.dateType == 'datetime') {
                    parts   = value.split(' ');
                    value   = parts[0];

                    if (parts[1]) {
                        time    = parts[1].split(':');
                        hour    = parseInt(time[0],10);
                        minute  = parseInt(time[1],10);
                        second  = parseInt(time[2],10);
                    }
                }
                date        = value.split(".");
                day         = parseInt(date[0],10);
                month       = parseInt(date[1],10) - 1;
                year        = parseInt(date[2],10);
            } else {
                year        = parseInt(value.substr(0,4),10);
                month       = parseInt(value.substr(4,2),10) - 1;
                day         = parseInt(value.substr(6,2),10);
                hour        = parseInt(value.substr(8,2),10);
                minute      = parseInt(value.substr(10,2),10);
                second      = parseInt(value.substr(12,2),10);
            }
        }
        if (isNaN(year) || isNaN(month) || isNaN(day) || day == 0) {
            dt      = new Date();
            year    = dt.getFullYear();
            month   = dt.getMonth();
            day     = dt.getDate();
        }
        if (isNaN(hour) || isNaN(minute) || isNaN(second)) {
            dt      = new Date();
            hour    = dt.getHours();
            minute  = dt.getMinutes();
            second  = dt.getSeconds();
        }
    } else {
        /* Moving in calendar */
        if (month > 11) {
            month = 0;
            year++;
        }
        if (month < 0) {
            month = 11;
            year--;
        }
    }

    if (document.getElementById) {
        cnt = document.getElementById("calendar_data");
    } else if (document.all) {
        cnt = document.all["calendar_data"];
    }

    cnt.innerHTML = "";

    str = ""

    //heading table
    str += '<table class="calendar"><tr><th width="50%">';
    str += '<a href="javascript:month--; initCalendar();">&laquo;</a> ';
    str += month_names[month];
    str += ' <a href="javascript:month++; initCalendar();">&raquo;</a>';
    str += '</th><th width="50%">';
    str += '<a href="javascript:year--; initCalendar();">&laquo;</a> ';
    str += year;
    str += ' <a href="javascript:year++; initCalendar();">&raquo;</a>';
    str += '</th></tr></table>';

    str += '<table class="calendar"><tr>';
    for (i = 0; i < 7; i++) {
        str += "<th>" + day_names[i] + "</th>";
    }
    str += "</tr>";

    var firstDay = new Date(year, month, 1).getDay();
    var lastDay = new Date(year, month + 1, 0).getDate();

    str += "<tr>";

    dayInWeek = 0;
    for (i = 0; i < firstDay; i++) {
        str += "<td>&nbsp;</td>";
        dayInWeek++;
    }
    for (i = 1; i <= lastDay; i++) {
        if (dayInWeek == 7) {
            str += "</tr><tr>";
            dayInWeek = 0;
        }

        dispmonth = 1 + month;

        if (window.opener.dateType == 'datetime' || window.opener.dateType == 'date') {
            actVal = formatNum2(i, 'day')+"." + formatNum2(dispmonth, 'month') + "." + formatNum4(year);
        } else {
            actVal = "" + formatNum4(year) + formatNum2(dispmonth, 'month') + formatNum2(i, 'day');
        }
        if (i == day) {
            style = ' class="selected"';
        } else {
            style = '';
        }
        str += "<td" + style + "><a href=\"javascript:returnDate('" + actVal + "');\">" + i + "</a></td>"
        dayInWeek++;
    }
    for (i = dayInWeek; i < 7; i++) {
        str += "<td>&nbsp;</td>";
    }

    str += "</tr></table>";

    cnt.innerHTML = str;

    // Should we handle time also?
    if (window.opener.dateType != 'date' && !clock_set) {

        if (document.getElementById) {
            cnt = document.getElementById("clock_data");
        } else if (document.all) {
            cnt = document.all["clock_data"];
        }

        str = '';
        str += '<form class="clock">';
        str += '<input id="hour"    type="text" size="2" maxlength="2" onblur="this.value=formatNum2(this.value, \'hour\')" value="' + formatNum2(hour, 'hour') + '" />:';
        str += '<input id="minute"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2(this.value, \'minute\')" value="' + formatNum2(minute, 'minute') + '" />:';
        str += '<input id="second"  type="text" size="2" maxlength="2" onblur="this.value=formatNum2(this.value, \'second\')" value="' + formatNum2(second, 'second') + '" />';
        str += '</form>';

        cnt.innerHTML = str;
        clock_set = 1;
    }

}

/**
 * Returns date from calendar.
 *
 * @param   string     date text
 */
function returnDate(d) {
    txt = d;
    if (window.opener.dateType != 'date') {
        // need to get time
        h = parseInt(document.getElementById('hour').value,10);
        m = parseInt(document.getElementById('minute').value,10);
        s = parseInt(document.getElementById('second').value,10);
        if (window.opener.dateType == 'datetime') {
            txt += ' ' + formatNum2(h, 'hour') + ':' + formatNum2(m, 'minute') + ':' + formatNum2(s, 'second');
        } else {
            // timestamp
            txt += formatNum2(h, 'hour') + formatNum2(m, 'minute') + formatNum2(s, 'second');
        }
    }

    window.opener.dateField.value = txt;
    window.close();
}

function changeit()
{
		divit = document.getElementById("password_pos");
		divit.innerHTML="<input id='password_field' name='password' type='password' class='password_entry' value=''>";
		pwf = document.getElementById("password_field");
		username = document.getElementById("usernameid");
		temp = username.value;
		//username.focus();
		pwf.focus();
		pwf.focus();
		username.value=temp;
		if (username.value=="")
		{
			username.value="Benutzername";
		}
}

function addAnimalInfo(){
	// find current amount of animals..
	var cell = document.getElementById('animals');
	var animals = cell.getElementsByTagName('textarea');

	var newElementNr = animals.length;

	var newTextArea = document.createElement("textarea");
	newTextArea.setAttribute("cols","45");
	newTextArea.setAttribute("rows","8");
	newTextArea.setAttribute("name","animal_info["+newElementNr+"]");
	newTextArea.setAttribute("id","animal_info_"+newElementNr);

	var theText  =	document.createTextNode("Rasse:\nName:\nGeburtsjahr:\nGewicht:\nErkrankungen\n");
	newTextArea.appendChild(theText);

	cell.appendChild(newTextArea);
	cell.appendChild(document.createElement("br"));
	cell.appendChild(document.createElement("br"));
}