﻿/**
* Check the email adres if correct, do not interfere, else display red border.
*/
function CheckSearchInput(textboxid, targetid) {
    var textbox = document.getElementById(textboxid);
    if ((textbox.value == 'Type hier uw zoektekst...') || (textbox.value.length < 3)) 
    {
        textbox.style.color = "Red";
        var target = document.getElementById(targetid);
        return false;
    }
    else 
    {
        textbox.style.color = "#9d9da1";
        return true;
    }
}

/**
 * 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() 
{
    var contentpanel = document.getElementById("ctl00_cpContent_pnlPageContent");
    if (contentpanel == null)
        contentpanel = document.getElementById("ctl00_cpContent_pnlDynamicPageContent");
    var bottompanel = document.getElementById("ctl00_pnlBottom");
    var copyright = document.getElementById("ctl00_pnlCopyright");
    if ((contentpanel != null) && (bottompanel != null) && (copyright != null)) 
    {
        if (contentpanel.clientHeight > 735) {
            copyright.style.top = (contentpanel.clientHeight + 255) + "px";
        }
        else {
            copyright.style.top = (contentpanel.clientHeight + 635) + "px";
        }
    }
}

function CheckFriend(nameid, emailid, senderid) {
    var nametextbox = document.getElementById(nameid);
    var emailtextbox = document.getElementById(emailid);
    var sendertextbox = document.getElementById(senderid);

    /// Check the message input
    if (sendertextbox.value.length < 3) {
        sendertextbox.style.border = "1px solid red";
        return false;
    }
    else {
        sendertextbox.style.border = "";
    }


    /// Check the name input
    if (nametextbox.value.length < 3) {
        nametextbox.style.border = "1px solid red";
        return false;
    }
    else {
        nametextbox.style.border = "";
    }

    /// Check the email input
    if (!isValidEmailAddress(emailtextbox.value)) {
        emailtextbox.style.border = "1px solid red";
        return false;
    }
    else {
        emailtextbox.style.border = "";
    }

    return true;
}

/**
 * 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 = "#64afd3";
        //textbox.style.color = "#FFFFFF";
        return false;
    }
    else 
    {
        textbox.style.backgroundColor = "";
        //textbox.style.color = "";
        return true;
    }
}

/**
* Check the 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.borderColor = "red";
        return false;
    }
    else {
        nametextbox.style.borderColor = "";
    }

    /// Check the email input
    if (!isValidEmailAddress(emailtextbox.value)) {
        emailtextbox.style.borderColor = "red";
        return false;
    }
    else {
        emailtextbox.style.borderColor = "";
    }

    /// Check the message input
    if (messagetextbox.value.length < 3) {
        messagetextbox.style.borderColor = "red";
        return false;
    }
    else {
        messagetextbox.style.borderColor = "";
    }

    return true;
}

/**
* Check the form, do not interfere, else display red border.
*/
function CheckRequest(nameid, emailid) {
    var nametextbox = document.getElementById(nameid);
    var emailtextbox = document.getElementById(emailid);

    /// Check the name input
    if (nametextbox.value.length < 3) {
        nametextbox.style.backgroundColor = "#64afd3";
        nametextbox.style.color = "#FFFFFF";
        return false;
    }
    else {
        nametextbox.style.backgroundColor = "";
        nametextbox.style.color = "";
    }

    /// Check the email input
    if (!isValidEmailAddress(emailtextbox.value)) {
        emailtextbox.style.backgroundColor = "#64afd3";
        emailtextbox.style.color = "#FFFFFF";
        return false;
    }
    else {
        emailtextbox.style.backgroundColor = "";
        emailtextbox.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';
    }
}

/**
* Adds the given URL to the favorites of the browser.
*/
function addFavorite() {
    title = "Polispark.nl";
    url = "http://www.polispark.nl/";

    if (window.sidebar) // Mozilla Firefox Bookmark
    {
        window.sidebar.addPanel(title, url, "");
    }
    else if (window.external)  // IE Favorite
    {
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print)  // Opera Hotlist
    {
        alert("Druk op CTRL+D om toe te voegen aan favorieten");
    }
}
