/******************************************************************
*                                                                 *
* This Library was created by the company                         *
* inet.solutions Daxberger & Krenner OEG (www.inet-solutions.biz) *
*                                                                 *
* It is neither allowed to use the code in any form nor           *
* to remove the copyright remarks without a special, written      *
* licence from the above mentioned company!!!                     *
*                                                                 *
*               © inet.solutions Daxberger & Krenner OEG, 2003    *
*                                                                 *
******************************************************************/

/**
 * Simple setter method
 *
 * @param form (the form number)
 * @param element (the element number in the specified form)
 */
function setFocus(form, element) {
  document.forms[form].elements[element].focus();
}

/**
 * simple image changer method
 */
function changeImg(imgNum, img) {
  document.images[imgNum].src = img;
}

/**
 * Opens a new window for a specified file 
 */
function openWindow(file, width, height) {
  win = window.open(file, "win", "width=" + width + ",height=" + height + ",status=yes,scrollbars=auto");  
  win.focus();
}

/**
 * Opens a new window for viewing AGB´s
 */
function showAGB() {
  var wizardUrl = "http://www.kinotakara-europa.com/agbs.php?lang=1";
  win = window.open(wizardUrl, "orderWin", "width=750,height=550,status=no,scrollbars=yes");  
  win.focus();
}

/**
 * Opens a new window for placing an order
 */
function orderProduct(amount) {
  var orderUrl = "https://www.ssl-page.com/kinotakara/index.php?besttmp_Menge=" + amount + "&besttmp_ArtID=7&best=1&lang=1&wkz=1&id=bestellung&nick=mdax&bestkomplett=1";
  win = window.open(orderUrl, "orderWin", "width=800,height=600,status=no,scrollbars=yes");  
  win.focus();
}

/**
 * Closes the current window
 */
function closeWindow() {
  this.close();
}
/**
 * Checks the validity of a form value
 * This one is just called from checkMandatoryFields()
 */
function isValid(value) {
  if (value != null &&
      value != "" &&
      value != " ") {
    return true;    	
  }
  return false;
}

/**
 * Checks the validity of an email address
 * This one is just called from checkMandatoryFields()
 */
function isValidEmail(email) {
  if (email.indexOf("@") == -1 ||
      email.indexOf("@") == 0  ||
      email.indexOf(".") == -1 ||
      email.length < 6) {
    return false;    	
  }
  return true;
}

/**
 * Checks the validity of a domain name
 */
function checkValidDomain() {
  var domainName = document.domainform.domain.value.toString().toLowerCase();
  var validChars = "abcdefghijklmnopqrstuvwxyz0123456789-";
  var selectedTld = document.domainform.tldext.options[document.domainform.tldext.selectedIndex].value;
  var i, retVal;
  
  if (isValid(domainName)) {
    for(i = 0; i < domainName.length; i++) {
      if (validChars.indexOf(domainName.charAt(i)) < 0) {

        alert("Der eingegebene Domainname ist ungültig!");
        document.forms[0].domain.focus();
        return false;

      	break;
      }
    }
  }
  else {
    return false;
  }

  if (myTld != "" && myTld  != selectedTld) {
    alert("Für das gewünschte Produkt ist nur die\nDomainendung \"" + myTld + "\" zulässig!");
    document.forms[0].tldext.focus();
    return false;
  }
  
  return true;
}

/**
 * Checks all mandatory fields of a form with
 * CLASS="mandatory" - Fields
 */
function checkMandatoryFields() {
  var allFilled = true;
  var fields = document.forms[0].elements;
  
  
  for (i = 0; i < fields.length; i++) {
    if (fields[i].className == "mandatory") {
      if (!isValid(fields[i].value)) {
      	alert("Bitte füllen Sie alle (!!!) markierten Eingabefelder aus.");
      	document.forms[0].elements[i].focus();
      	allFilled = false;
      	break;
      }
      if (fields[i].name && fields[i].name.indexOf("mail") != -1) {
      	if (!isValidEmail(fields[i].value)) {
          alert("Bitte geben Sie eine korrekte Mail Adresse ein.");
          document.forms[0].elements[i].select();
          allFilled = false;
          break;
        }
      }
    }
  }
  
  return allFilled;
}

/**
 * Checks the validity of an order
 */
function validateOrder() {
  var validOrder = document.domainform.validOrder.checked
  
  if (!validOrder) {
    alert("Sie müssen mindestens 18 Jahre alt, voll geschäftsfähig\nund mit unseren AGB´s einverstanden sein\num Ihre Bestellung aufgeben zu können!");
    document.forms[0].validOrder.focus();
    return false;
  }
  
  return true;
}