﻿function CheckEmailField(txtEmail)
{
    if (txtEmail.value == "")
    {
        txtEmail.value = "הכנס כתובת אימייל"
        txtEmail.style.textAlign = "right";
    }

    return true;
}

function URLEncode(clearString)
{
    var output = '';
    var x = 0;
    clearString = clearString.toString();
    var regex = /(^[a-zA-Z0-9א-ת_.]*)/;
    var hebRegEx = /(^[0-9א-ת_.]*)/;
    var matchHe = hebRegEx.exec(clearString);

    if (matchHe != null && matchHe.length > 1 && matchHe[1] != '')
    {
        return URLencodeHeb(clearString);
    }

    while (x < clearString.length)
    {
        var match = regex.exec(clearString.substr(x));
        if (match != null && match.length > 1 && match[1] != '')
        {
            output += match[1];
            x += match[1].length;
        }
        else
        {
            if (clearString[x] == ' ')
            {
                output += '+';
            }
            else
            {
                var charCode = clearString.charCodeAt(x);
                var hexVal = charCode.toString(16);
                output += '%' + (hexVal.length < 2 ? '0' : '') + hexVal.toUpperCase();
            }

            x++;
        }
    }
    return output;
}
// Retrieved from: http://www.htmlcodetutorial.com/forms/index_famsupp_157.html
function SubmitOnEnter(myfield, e)
{
    var keycode;
    if (window.event)
        keycode = window.event.keyCode;
    else if (e)
        keycode = e.which;
    else
        return true;
    if (keycode == 13)
    {
        SearchSite();
        return false;
    }
    else
        return true;
}

function URLencodeHeb(strText)
{
    strText = strText;
    strText = strText.replace(/א/g, "%E0");
    strText = strText.replace(/ב/g, "%E1");
    strText = strText.replace(/ג/g, "%E2");
    strText = strText.replace(/ד/g, "%E3");
    strText = strText.replace(/ה/g, "%E4");
    strText = strText.replace(/ו/g, "%E5");
    strText = strText.replace(/ז/g, "%E6");
    strText = strText.replace(/ח/g, "%E7");
    strText = strText.replace(/ט/g, "%E8");
    strText = strText.replace(/י/g, "%E9");
    strText = strText.replace(/כ/g, "%EB");
    strText = strText.replace(/ל/g, "%EC");
    strText = strText.replace(/מ/g, "%EE");
    strText = strText.replace(/נ/g, "%F0");
    strText = strText.replace(/ס/g, "%F1");
    strText = strText.replace(/ע/g, "%F2");
    strText = strText.replace(/פ/g, "%F4");
    strText = strText.replace(/צ/g, "%F6");
    strText = strText.replace(/ק/g, "%F7");
    strText = strText.replace(/ר/g, "%F8");
    strText = strText.replace(/ש/g, "%F9");
    strText = strText.replace(/ת/g, "%FA");
    strText = strText.replace(/ם/g, "%ED");
    strText = strText.replace(/ן/g, "%EF");
    strText = strText.replace(/ף/g, "%F3");
    strText = strText.replace(/ץ/g, "%F3");
    strText = strText.replace(/ך/g, "%EA");
    strText = strText.replace(/ /g, "%20");

    return strText;
}

function SearchSite()
{
    window.open('http://www.google.com/cse?cx=partner-pub-5671485341584480:a1kt66-nmc5&hl=iw&inlang=iw&ie=ISO-8859-8-I&q=' +
        URLEncode(document.getElementById('q').value) + '&sa=%E7%E9%F4%E5%F9&siteurl=www.civileng.co.il', "_blank");
}

function PutBanner(p_id)
{
    if (typeof (OA_output[p_id]) == "undefined" || OA_output[p_id] == "")
    {
        return;
    } 
    else
    {
        document.write("<div class='banner_space'></div>");
        document.write(OA_output[p_id]);
    }
}
