﻿/**
 * When a textbox has lost focus and is empty, set
 * a clarifiing text given in the text parameter.
 */
function TextBoxOnBlur(textbox, text)
{
    if(textbox.value == "")
    {
        textbox.style.color = "#666666";
        textbox.value = text;
    }    
}

function SetContentPanel(contentpanelid, footerpanelid)
{
    var contentpanel = document.getElementById(contentpanelid);
    var footerpanel  = document.getElementById(footerpanelid);
    if(contentpanel.clientHeight < 400)
    {
        contentpanel.style.height = "400px";
        footerpanel.style.position = "absolute";
        footerpanel.style.top = "400px";
    }
}

/**
 * Clear the textbox if the text is equal to the text variable.
 */
function TextBoxOnFocus(textbox, text)
{
    if(textbox.value == text)
    {
        textbox.style.color = "";
        textbox.value = "";
    }    
}

/**
 * Changes the color of the row where the mouse is hovering above.
 */
function HighlightRow(row, color)
{
    row.style.backgroundColor = color;
    row.style.cursor = 'pointer';
}

/**
 * Changes the color of the row back to the original color.
 */
function LowerRow(row)
{
    row.style.backgroundColor = '';
}

function popUp(URL) 
{
    day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=600,height=400,left = 192,top = 144');");
}

/**
 * Check the email adres if correct, do not interfere, else display red border.
 */
function CheckEmailAddress(textboxid)
{
    var textbox = document.getElementById(textboxid);
    if(!isValidEmailAddress(textbox.value))
    {
        textbox.style.backgroundColor = "#f5ee31";
        textbox.style.color = "White";
        return false;
    }
    else 
    {
        textbox.style.backgroundColor = "";
        textbox.style.color = "";
        return true;
    }
}

/**
* Check the guestbookmessage form, do not interfere, else display red border.
*/
function CheckMessage(nameid, emailid, messageid) {
    var nametextbox = document.getElementById(nameid);
    var emailtextbox = document.getElementById(emailid);
    var messagetextbox = document.getElementById(messageid);

    /// Check the name input
    if (nametextbox.value.length < 3) {
        nametextbox.style.backgroundColor = "#f5ee31";
        return false;
    }
    else {
        nametextbox.style.backgroundColor = "";
        nametextbox.style.color = "";
    }

    /// Check the email input
    if (!isValidEmailAddress(emailtextbox.value)) {
        emailtextbox.style.backgroundColor = "#f5ee31";
        return false;
    }
    else {
        emailtextbox.style.backgroundColor = "";
        emailtextbox.style.color = "";
    }

    /// Check the message input
    if (messagetextbox.value.length < 3) {
        messagetextbox.style.backgroundColor = "#f5ee31";
        return false;
    }
    else {
        messagetextbox.style.backgroundColor = "";
        messagetextbox.style.color = "";
    }

    return true;
}

/**
 * Check if the email adres is valid, if valid, return true, otherwise false.
 */
function isValidEmailAddress(address)
{
    var regex = new RegExp(/^([.0-9a-z_-]+)@(([0-9a-z-]+\.)+[0-9a-z]{2,4})$/i);

    return regex.test(address);
}


function ShowHidePanel(panelid, invisiblepanelid)
{
    var panel = document.getElementById(panelid);
    
    if(panel.style.visibility != 'visible')
    {
        panel.style.visibility = 'visible';
    }
}
