function strpos ( haystack, needle, offset ) {
    var i = ( haystack + '' ) .indexOf ( needle, ( offset || 0 ) );
    return i === -1 ? false : i;
}
function changeFormAdress ( id ) {
    var actualAdress = jQuery ( '#product' + id ) .attr ('action');
    actualAdress = actualAdress.substring ( 0, actualAdress.length - 5 );
    var commaPoint = strpos ( actualAdress, ',', 0 );
    while ( commaPoint ) {
        temp = commaPoint;
        commaPoint = strpos ( actualAdress, ',', commaPoint + 1 );
    }
    commaPoint = temp;
    var howMuch = parseInt ( jQuery ( '#product' + id + ' .howMuch' ) .attr ('value') );
    actualAdress = actualAdress.substring ( 0, commaPoint );
    actualAdress += ',' + howMuch + '.html';
    jQuery ( '#product' + id ) . attr ('action', actualAdress );
}
function validateHowMuch ( id, howMuchToValidate ) {
    jQuery ( '#product' + id + ' .maximumReach' ) .attr ( 'style', 'display:none' );
    jQuery ( '#product' + id + ' .minimumReach' ) .attr ( 'style', 'display:none' );
    var maximum = parseInt ( jQuery ( '#product' + id + ' .maxStore' ) . attr ( 'value' ) );
    var minimum = parseInt ( jQuery ( '#product' + id + ' .minStore' ) . attr ( 'value' ) );
    if ( howMuchToValidate > maximum ) {
        jQuery ( '#product' + id + ' .howMuch' ) .attr ( 'value', maximum );
        jQuery ( '#product' + id + ' .maximumReach' ) .attr ( 'style', 'display:block' );
    }
    if ( howMuchToValidate < minimum ) {
        jQuery ( '#product' + id + ' .howMuch' ) .attr ( 'value', minimum );
        jQuery ( '#product' + id + ' .minimumReach' ) .attr ( 'style', 'display:block' );
    }
}
function incrementCart ( id, howMuchIncrement ) {
    var howMuch = jQuery ( '#product' + id + ' .howMuch' ) .attr ( 'value' );
    howMuch = parseInt ( howMuch );
    howMuch += howMuchIncrement;
    //alert ( howMuch );
    jQuery ( '#product' + id + ' .howMuch' ) .attr ( 'value', howMuch );
    validateHowMuch ( id, howMuch );
    changeFormAdress ( id );
}
function decrementCart ( id, howMuchDecrement ) {
    var howMuch = jQuery ( '#product' + id + ' .howMuch' ) .attr ( 'value' );
    howMuch = parseInt ( howMuch );
    howMuch -= howMuchDecrement;
    //alert ( howMuch );
    jQuery ( '#product' + id + ' .howMuch' ) .attr ( 'value', howMuch );
    validateHowMuch ( id, howMuch );
    changeFormAdress ( id );
}
