// ===============================================================================================================
// Mike's & Makki's Javascript Functions
// © by Mike Adlmannseder & Makki Raab 2003
// ---------------------------------------------------------------------------------------------------------------
// Version: 1.0
// Letzte Änderung: 08.04.2003 - Details siehe admin.txt

// ===============================================================================================================
// funktion: Rollover aller Menubuttons
// ===============================================================================================================
function rollover(img_name, img_action)
{
        var imgPathTop="../../images/menu/";
        var mnuItemsTop=new Array("catering", "betrieb", "produkte", "knoblauch", "news", "kontakt", "cafe", "gastro");
        var btnOnTop=new Array();
        var btnOffTop=new Array();

        for(x=0;x<mnuItemsTop.length;x++) {
      var currItemTop=mnuItemsTop[x];
          if(currItemTop == clicked){
                    btnOnTop[currItemTop]=new Image();
                    btnOnTop[currItemTop].src=imgPathTop+currItemTop+"_o.gif";
                    btnOffTop[currItemTop]=new Image();
                    btnOffTop[currItemTop].src=imgPathTop+currItemTop+"_o.gif";
        }
        else{
                  btnOnTop[currItemTop]=new Image();
                  btnOnTop[currItemTop].src=imgPathTop+currItemTop+"_o.gif";
                  btnOffTop[currItemTop]=new Image();
                  btnOffTop[currItemTop].src=imgPathTop+currItemTop+".gif";
        }
}
        if(document.images) {
          switch(img_action) {
            case 0: document.images[img_name].src=btnOffTop[img_name].src;break;
            case 1: document.images[img_name].src=btnOnTop[img_name].src;break;
          }
        }
}

// ===============================================================================================================
// funktion:  markiert den ausgewählten Menuepunkt
// ===============================================================================================================
        function preselect()
        {
        if(document.images) {
			if(clicked!="none"){
                document.images[clicked].src="../../images/menu/"+clicked+"_o.gif";
              /*  if(subclicked!="none"){ 
                      document.images[subclicked].src="../../images/menu/"+subclicked+"_o.gif";
                }*/
			}
        }
}

// ===============================================================================================================
// funktion:  im Querystring wird die Abteilung übergeben und die entsprechende Seite im Frameset aufgerufen
// ===============================================================================================================

function getSection(query){
                var section=query.substr(9, query.length-1);
                return section;
        }


// ===============================================================================================================
// funktion: ruft ein neues Fenster mit bestimmten Eigenschaften auf
// ===============================================================================================================

function News(meineSeite,meinName,w,h,scroll){
                LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
                TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
                Fenster = window.open(meineSeite,meinName,settings)
}

function popup(file){
      window.open(file, "_blank", "width=550, height=550");
}

function popup_knoblauch(file){
      window.open(file, "_blank", "width=550, height=270");
}

function openWindow(meineSeite,meinName,w,h,scroll){
                LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
                TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
                Fenster = window.open(meineSeite,meinName,settings)
}

function loadSite(site, menu){
	top.logo.location.href = "../lohnsburger/"+menu+".htm";
	top.main.location.href = "../"+site+"/"+site+".asp";
}

// ===============================================================================================================
// funktion: ruft ein neues Fenster mit bestimmten Eigenschaften auf
// ===============================================================================================================

function News(meineSeite,meinName,w,h,scroll){
                LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
                TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
                settings ='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable'
                Fenster = window.open(meineSeite,meinName,settings)
        }
		
// ===============================================================================================================
// funktionen: Validate form
// ===============================================================================================================
function strip(filter,str){
  var i,curChar;
  var retStr = '';
  var len = str.length;
  for(i=0; i<len; i++){
    curChar=str.charAt(i);
    if(filter.indexOf(curChar)<0)
      retStr += curChar;
  }
  return retStr;
}

// ============================================================================================
// The first three functions are relatively self-explanatory. The notEmpty() function accepts
// any value other than white space. The validateInteger() and validateFloat() functions ensure
// that the controls only accept numeric values by first parsing the string and then checking
// whether the result is numeric with the isNaN() method.
// ============================================================================================
function notEmpty(str){
  if(strip(" \n\r\t",str).length==0)
    return false;
  else
     return true;
}

function validateInteger(str){
  str = strip(' \n\r\t',str);
  //remove leading zeros, if any
  while(str.length > 1 && str.substring(0,1) == '0'){
    str = str.substring(1,str.length);
  }
  var val = parseInt(str);
  if(isNaN(val))
    return false;
  else
     return true;
}

function validateFloat(str){
  str = strip(' \n\r\t',str);
  //remove leading zeros, if any
  while(str.length > 1 && str.substring(0,1) == '0'){
    str = str.substring(1,str.length);
  }
  var val = parseFloat(str);
  if(isNaN(val))
    return false;
  else
     return true;
}

// ============================================================================================
// The validateUSPhone(), validateSSN(), and validateZip() functions are similar in that
// they strip off all of the characters that people commonly enter for phone numbers.
// The functions then check the length of the resulting numeric character string. In addition,
// because Social Security numbers and Zip Codes are numeric, the validateSSN() and
// validateZip() functions also ensure that the entered data is a valid integer.
// Note that the validateUSPhone() function doesn't force phone numbers to be integers so
// that phone numbers represented by characters are passed through.
// ============================================================================================
function validateUSPhone(str){
  str = strip("*() -./_\n\r\t\\",str);
  if(str.length == 10 || str.length == 7)
    return true;
  else
     return false;
}

function validatePhoneNr(str){
  var valid = "0123456789-+/() ";
  str = strip(" \n\r\t",str);
  for(var i=0;i<str.length;i++) {
    temp=""+str.substring(i,i+1);
    if(valid.indexOf(temp)=="-1")
      return false;
  }
  return true;
}

function validateSSN(str){
  str = strip(" -.\n\r\t",str);
  if(validateInteger(str) && str.length == 9)
    return true;
  else
     return false;
}

function validateZip(str){
  str = strip("- \n\r\t",str);
  if(validateInteger(str) && (str.length==9 ||
     str.length==5))
    return true;
  else
     return false;
}

// ============================================================================================
// The credit card validation rule deserves a bit more attention. After stripping out garbage
// characters, I took advantage of the fact that all Visa card account numbers begin with a 4,
// all MasterCard accounts begin with a 5, all Discover card accounts begin with a 6, and all
// American Express cards begin with a 3. I got the card type from the drop-down list next to
// the credit card entry text field. If the first character isn't correct based on the type,
// the validateCC() function immediately returns false and the data fails the test.
// In addition, credit ards have a fixed number of digits: Amex accounts all contain 15 digits,
// and Visa, MasterCard, and Discover card accounts all contain 16 digits. Therefore, the
// function improves the validation by checking that the data begins with the correct number
// and is the correct length.
// ============================================================================================
function validateCC(str,type){
  str = strip("-./_\n\r\t\\",str);
  if(type=="1")
    if(str.charAt(0)!="4")
      return false;
  if(type=="2")
    if(str.charAt(0)!="5")
      return false;
  if(type=="3")
    if(str.charAt(0)!="6")
      return false;
  if(type=="4")
    if(str.charAt(0)!="3")
      return false;
  if(validateInteger(str) &&
     ((str.length==15&&type=="4") ||
     str.length==16))
    return true;
  else
     return false;
}

// ============================================================================================
// The validateDate() function first creates a Date object from the string. It then checks
// whether the valueOf() method of the Date object is numeric or non-zero. If the valueOf()
// method is non-numeric or zero, the string passed to the function does not represent a valid
// instance in time and, therefore, fails the test.
// ============================================================================================
function validateDate(str){
  var dateVar = new Date(str);
  if(isNaN(dateVar.valueOf()) ||
    (dateVar.valueOf() ==0))
    return false;
  else
     return true;
}

// ============================================================================================
// The validateEMail() function strips out unwanted characters and then checks for the presence
// of both the "@" and "." characters. While it is possible to fool the rule, you'd be
// surprised at how many people will first attempt to avoid entering a valid e-mail address and
// then, after prompting, simply supply their e-mail address.
// ============================================================================================
function validateEMail(str){
  str = strip(" \n\r\t",str);
  if(str.indexOf("@") > -1 && str.indexOf(".") > -1)
    return true;
  else
     return false;
}

// ============================================================================================
// Validate Checkbox
// ============================================================================================
function validateCheckbox(tempobject){
  if(tempobject.checked)
    return true;
  else
     return false;
}

// ============================================================================================
// Stellt fest ob das Feld Pflicht ist oder nicht
// ============================================================================================
function isRequired(str){
  str = strip(" \n\r\t",str);
  if(str.indexOf("req") > -1)
    return true;
  else
     return false;
}