/**********************************************************************************************
 OpenHandel - Copyright (C) 2004 - Studio Artist X, Steven Ottenhoff, Jisse Reitsma, Marc van der Wurff
   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
***********************************************************************************************/

/* $Id: checks.js,v 1.8 2005/09/29 16:00:19 alexander Exp $ */

function PopupPic(locatie) { 
    window.open("popup.html?"+locatie, "", "resizable=1,HEIGHT=200,WIDTH=200");
}

function isPrijs( getal ){
    
    str=getal.toString();
    komma=false;
    var tel=0;
    for( var i=0; i<str.length; i++ ){
        var kar=str.charAt(i);
        if( kar>=0 && kar<10 ){
            if( komma==true ){
                tel++;    
                if( tel>3 ) return false;
            }
            continue;
        }    else if( kar==',' && komma==false ){
            komma=true;
            tel++;
            continue;
        }    else return false;
    }
    if( tel<1 && komma==true ) return false;
    else return true;
}

            
function checkAdFields(form) {
    check=true;
    var naam = form.naam.value;
    var email = form.email.value;
    /*var telefoon = form.telefoon.value;
    var telefoon = parseInt(telefoon); */
    var plaats = form.plaats.value;
    var provincie = form.provincie.value;
    var titel = form.titel.value;
    var omschrijving = form.omschrijving.value;
    var bedrag = form.bedrag.value;

    if ( naam.length<2 || naam.length>40 ) {
        alert("Naam verplicht invullen, min 2 en max. 40 karakters!");
        //    naam.focus();
        check=false;
    }    else if ( email.length<9 || email.length>40 ){
        alert("Email verplicht invullen, min. 9 en max. 40 karakters!");
        //    email.focus();
        check=false;
    } else if ( email.indexOf( '@',0 )==-1 || email.indexOf( '.',0 )==-1 ){
        alert("Geen geldig emailadres? Probeer het opnieuw.");
        //    email.focus();
        check=false;
        /*
    } else if (isnan(telefoon.length)) {
        alert("Uw telefoon moet 10 cijfers bevatten!");
        //    telefoon.focus();
        check=false; */
    }    else if ( plaats.length<2 || plaats.length>40 ){
        alert("Plaats verplicht invullen, min. 2 en max. 40 karakters!");
        //    plaats.focus();
        check=false;
    } else if ( titel.length<10 || titel.length > 60 ){
        alert("Titel verplicht invullen, min. 10 en max. 60 karakters!");
        //    titel.focus();
        check=false;
    } else if ( omschrijving.length<100){
        alert("Uw advertentie omschrijving is te kort! Min 100 karakters vereist!");
        //    omschrijving.focus();
        check=false;
    } else if ( bedrag.length<1 || bedrag.length>10 ){
        alert("Prijs verplicht invullen, min. 1 en maximaal 10 cijfers!");
        //    prijs.focus();
        check=false;
    } else if ( !isPrijs( bedrag ) ){
        alert("Prijs is niet geldig of is geen getal!");
        //    prijs.focus();
        check=false;
    }
    return check;
}

function checkBidFields( form ){
    check=true;
    var naam = form.naam.value;
    var email = form.email.value;
    var plaats = form.plaats.value;
    var provincie = form.provincie.value;
    var bedrag = form.bedrag.value;
    var opmerking = form.opmerking.value;

    if ( naam.length<2 || naam.length>40 ) {
        alert("Naam verplicht invullen, min 2 en max. 40 karakters!");
        //    naam.focus();
        check=false;
    } else if ( email.length<9 || email.length>40 ){
        alert("Email verplicht invullen, min 9 en max. 40 karakters!");
        //    email.focus();
        check=false;
    } else if ( email.indexOf( '@',0 )==-1 || email.indexOf( '.',0 )==-1 ){
        alert("Geen geldig emailadres? Probeer het opnieuw.");
        //    email.focus();
        check=false;
    }    else if ( plaats.length<2 || plaats.length>40 ){
        alert("Plaatsnaam verplicht invullen, min 2 en max. 40 karakters!");
        //    plaats.focus();
        check=false;
    } else if ( bedrag.length<1 || bedrag.length>10 ){
        alert("Bedrag mag min. 1 en maximaal 10 cijfers hebben!");
        //    prijs.focus();
        check=false;
    } else if ( !isPrijs( bedrag ) ){
        alert("Prijs is niet geldig of is geen getal!");
        //    prijs.focus();
        check=false;
    } else if ( opmerking.length>40){
        alert("Opmerking mag max. 40 karakters hebben!");
        check=false;
    }
    return check;        
}

function checkSearchFields( form ){
    check=true;
    var keyword1=form.keyword1.value;
    var keyword2=form.keyword2.value;
    var lowprice=form.lowprice.value;
    var highprice=form.highprice.value;

    if( keyword1.length>80 || keyword2.length>80 ){
        alert("Zoekwoorden zijn te lang, max 80 karakters per tekstveld");
        check=false;
    } 
    if ( lowprice.length>0 ){
        if( !isPrijs( lowprice ) ){
            alert("Minimumprijs is incorrect!");
            check=false;
        }
    } 
    if( highprice.length>0 ){
        if( !isPrijs( highprice ) ){
            alert("Maximumprijs is incorrect!");
            check=false;
        }
    }
    return check
}
