// the base url
var baseURL = 'http://www.thannermoebel.at';

// Opens the map location in a new window
function openMap() {
    openWindow(baseURL + '/index.php?surface=company&page=map', 990, 683);
}

// Helper function for opening windows
function openWindow(url, w, h) {
   var padding;
   (navigator.appName == "Microsoft Internet Explorer") ? (padding = 0) : (padding = 0);

   var screenw = screen.availWidth;
   var screenh = screen.availHeight;
   var winw = (w + 15 + padding);
   var winh = (h + 15 + padding);
   var posx = (screenw / 2) - (winw / 2);
   var posy = (screenh / 2) - (winh / 2);

   var mywin = window.open(url,"mywin","top="+posy+",left="+posx+",width="+winw+",height="+winh+",menubar=no,locationbar=no,statusbar=no,resizable=no,toolbar=no,dependent=yes,scrollbars=yes");
   mywin.focus();
}

// Resizes and moves a window
function resizeWindow(w, h) {
    var padding;
   (navigator.appName == "Microsoft Internet Explorer") ? (padding = 0) : (padding = 0);

   var screenw = screen.availWidth;
   var screenh = screen.availHeight;
   var winw = (w + 15 + padding);
   var winh = (h + 15 + padding);
   var posx = (screenw / 2) - (winw / 2);
   var posy = (screenh / 2) - (winh / 2);

   window.resizeTo(winw, winh);
   window.moveTo(posx, posy);
}

// Prints the map
function printMap() {
    document.getElementById("buttons").style.display = "none";
    window.print();
}

// opens the gallery
function openGallery(galleryId) {
    openWindow(baseURL + '/index.php?surface=gallery&page=gallery&id=' + galleryId, 800, 600);
}

// opens the product view
function showProduct(productId, categoryId) {
    openWindow(baseURL + '/index.php?surface=services&page=product&id=' + productId + '&category=' + categoryId, 1030, 570);
}

// opens a single tipp
function openTipp(tippId) {
    openWindow(baseURL + '/index.php?surface=tipps&page=showtipp&id=' + tippId + '&window=1', 640, 480);
}

// hides an element
function hideElement(elementId) {
    document.getElementById(elementId).style.display = "none";
}

// prints a product
function printProduct() {
    // hide some layery
    document.getElementById("BottomContainer").style.display = "none";

    // print the window
    window.print();
}

// checks a category
function checkProductMail() {
    // get the vars
    var name  = document.getElementById("name").value;
    var email  = document.getElementById("email").value;
    var receiver_email  = document.getElementById("receiver_email").value;
    var text  = document.getElementById("text").value;

    var errors = false;

    // check the  title
    if(name.length <= 0) {
        errors = true;
        document.getElementById("name").className = "text error";
    }
    else {
        document.getElementById("name").className = "text";
    }

    // check the  email
    if(email.length <= 0) {
        errors = true;
        document.getElementById("email").className = "text error";
    }
    else {
        document.getElementById("email").className = "text";
    }

    // check the  title
    if(receiver_email.length <= 0) {
        errors = true;
        document.getElementById("receiver_email").className = "text error";
    }
    else {
        document.getElementById("receiver_email").className = "text";
    }

    // check the  title
    if(text.length <= 0) {
        errors = true;
        document.getElementById("text").className = "Default error";
    }
    else {
        document.getElementById("text").className = "Default";
    }



    // errors?
    if(errors) {
        return false;
    }
    else {
        return true;
    }
}