function CreateBookmarkLink() {
    title = "citip";
    // Blogger - Replace with <$BlogItemTitle$>
    // MovableType - Replace with <$MTEntryTitle$>

    url = "http://www.citip.co.il";
    // Blogger - Replace with <$BlogItemPermalinkURL$>
    // MovableType - Replace with <$MTEntryPermalink$>
    // WordPress - <?php bloginfo('url'); ?>

    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
        return true;
    }
}
String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/,"");
}
/**
 * This validates that the search form on the top of the page was filled correctly
 * 
 * We are restricting only city, but if street is specified, must be valid on
 * 
 * Test cases:
 * 1. On the search page, search for city and street, then add house number and try to search.
 *    See that it doesn't throw error
 * 
 */
function validateSearchForm(cityAutoSuggestObject, streetAutoSuggestObject) {
    errormessage = '';
    if (!cityAutoSuggestObject.citybool) {
        errormessage += 'נא בחר עיר מהרשימה\n';
    }
    // If nothing selected, and not empty street, throw error    
    if ((!streetAutoSuggestObject.streetbool) && (document.getElementById('street').value != "")) {
        //alert(document.getElementById('street'));
        errormessage += 'נא בחר רחוב מהרשימה';
    }
	
    var lookit = document.getElementById('freetexthome');
    if (lookit == undefined) {
        lookit = document.getElementById('freetext');
    }
    if (lookit.value != '') {
        document.searchbox.submit();
    } else {
        if (errormessage == '') {
            document.searchbox.submit();
        } else {
            errormessage = errormessage.replace(/,+$/,"");
            errormessage = errormessage.replace(/\n+$/,"");
            alert(errormessage);
        }
    }
}
function changecaptcha() {
    var futdate = new Date();
    var expdate = futdate.getTime();
    document.getElementById('captchaimage').src = "/scripts/captcha.php?t=" + expdate;
}

function updateClickedStat(publisherId){
    var xmlhttp;  // The variable that makes Ajax possible!

    try{
        // Opera 8.0+, Firefox, Safari
        xmlhttp = new XMLHttpRequest();
    } catch (e){
        // Internet Explorer Browsers
        try{
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try{
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e){
                // Something went wrong
                alert("Sorry but your broswer does not support Ajax");
                return false;
            }
        }
    }



    xmlhttp.open("GET", "/scripts/updateClickStat.php?publisherId="+publisherId, true);
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send();

    return false;
}


/**
 * This will validate the impression fill form
 */

function impValidate(toCheckEmail, cityAutoSuggestObject, streetAutoSuggestObject) {
    //alert('nadav');
    errors = '';
    if (toCheckEmail) emailField = document.impform.email.value;
    houseNum = document.impform.housenumber.value;
    appNum   = document.impform.appartmentnumber.value;
    if (!cityAutoSuggestObject.citybool)
        errors += 'נא לבחור עיר מהרשימה\n';
    if (!streetAutoSuggestObject.streetbool)
        errors += 'נא לבחור רחוב מהרשימה\n';
    if (!isNumeric(houseNum) || isEmpty(houseNum))
        errors += 'מספר בית חייב להיות מספר\n';
    if (!isNumeric(appNum) || isEmpty(appNum)) {
            errors += 'מספר דירה חייב להיות מספר\n';
    }
    if (toCheckEmail) errors += checkEmail(emailField);
    if (document.impform.fromyear.value == 'nan')
        errors += 'נא למלא תקופת מגורים משנת\n';
    if (document.impform.toyear.value == 'nan')
        errors += 'נא למלא תקופת מגורים עד שנה\n';
    var fromYear = parseInt(document.impform.fromyear.value);
    var toYear = parseInt(document.impform.toyear.value);
    if (toYear < fromYear)
        errors += 'שנת עזיבת הבית אינה יכולה להיות לפני שנת הכניסה אליו\n';
    if (document.impform.comments.value.length > 1000)
        errors += 'שדה הערות נוספות מוגבל ל20 שורות\n';
    if (errors == '') {
        document.impform.submit();
    } else {
        errors = errors.replace(/\n+$/,"");
        // I don't know what is the logic of this bubble if
        //if (!ibubble) {
            alert(errors);
        //}
    }
}
function checkEmail(email) {
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email)) {
        return 'כתובת מייל שגוייה\n';
    } else {
        return '';
    }
}
function isNumeric(elem){
    var numericExpression = /^[0-9]+$/;
    if(elem.match(numericExpression)){
        return true;
    }else{
        return false;
    }
}
function isEmpty(elem) {
    if (elem == '') {
        return true;
    } else {
        return false;
    }
}
function checkNumber(strng) {
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.";
    }
    var stripped = strng.replace(/[\(\)\.\-\ ]/g, '');
    //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
        error = "The phone number contains illegal characters.";
    }
    if (!(stripped.length == 10)) {
        error = "The phone number is the wrong length. Make sure you included an area code.\n";
    }
}

/**
 * I don't have a clue what this function does rather than just
 * delete the OPTIONAL text
 */
function checkname(that) {
    if (that.value == 'אופציונלי') {
        that.value = '';
        that.style.color = '#000000';
    } else if (that.value == '') {
        //that.value = 'אופציונלי';
        that.style.color = '#676767';
    }
}
