function user_validate_login() {
    var f = document.form_user_login;
    
    //if (isBlank(f.user_login.value) || isBlank(f.user_password.value) || isBlank(f.user_secureimage_code.value) ) {
    
    if ( isBlank(f.user_login.value) || isBlank(f.user_password.value) ) {
        alert(_jt("Please fill all the fields to login."));
        return false;
    }

    //all went well - let's do some effects
    document.getElementById('user_btn_submit').disabled = true;
    document.getElementById('user_btn_submit').value = '.. ' + _jt("processing") + ' ..'; 
    return true;   
    //f.submit();
}


function user_validate_registration() {

	var f = document.form_user_register;

    //aufix some fields
    f['user_login'].value = TrimAll(f['user_login'].value);
    
	
	var user_login = f['user_login'].value;
	var user_password = f['user_password'].value;
	var user_password_repeat = f['user_password_repeat'].value;
	var user_email = f['user_email'].value;
	var user_firstname = f['user_firstname'].value;
	var user_lastname = f['user_lastname'].value;
	var user_birth_date_month = f['user_birth_date_month'].value;
	var user_birth_date_day = f['user_birth_date_day'].value;
	var user_birth_date_year = f['user_birth_date_year'].value;
	var user_address = f['user_address'].value;
	var user_city = f['user_city'].value;
	var user_state = f['user_state'].value;
	var user_zip = f['user_zip'].value;
	var user_country = f['user_country'].value;
	var user_phone = f['user_phone'].value;
	var user_secureimage_code = f['user_secureimage_code'].value;

	
	//check if all fields are filled
	if ( isBlank(user_login) || 
         isBlank(user_password) ||
         isBlank(user_email) || 
         isBlank(user_firstname) || 
         isBlank(user_lastname) || 
         isBlank(user_address) || 
         isBlank(user_city) || 
         isBlank(user_state) ||
         isBlank(user_zip) ||  
         isBlank(user_secureimage_code)
       ) {
        alert(_jt("Please fill all the required fields."));
        return;
    }  

    //check user_login
	var test_pattern = /^[A-Za-z0-9]{5,32}$/;
	if (!test_pattern.test(user_login)) {
		alert(_jt("Invalid Username. \n Please use 5 to 25 characters and use only english letters and/or numbers. \n Please re-enter."));
		return;
	}
	
    //check user_password
	if (user_password.length < 5 || user_password.length > 32) {
		alert(_jt("Invalid Password. \n Please use 5 to 32 characters. A combination of latin letters, numbers and symbols - not spaces please. \n Please re-enter."));
		return;
	}	

    //check user_password repeat
	if (user_password != user_password_repeat) {
		alert(_jt("The passwords do not match. \n Please re-enter."));
		return;
	}
	
    //check email
    var test_pattern = /[\w-]+@([\w-]+\.)+[\w-]+/;
	if (!test_pattern.test(user_email)) {
		alert(_jt("Invalid Email address. Please re-enter."));
		return;
	}
            
    //check if birth date is valid
    if ( !Date.isValid(user_birth_date_month + '/' + user_birth_date_day + '/' + user_birth_date_year, 'M/d/yyyy') ) {
        alert(_jt("The date of birth you entered does not seem valid. Please re-enter."));
        return;
    }
    

    //check if tos is checked
    if (f['user_check_agree'].checked == false) {
        alert(_jt("To register in our site, please make sure you Agree to our terms."));
        return;
    }
        


    //all went well - let's do some effects
    document.getElementById('user_btn_submit').disabled = true;
    document.getElementById('user_btn_submit').value = '.. ' + _jt("processing") + ' ..';
    
    //submit
	f.submit();
	

}



function user_validate_account_personal() {

	var f = document.form_user_edit_personal;


	var user_email = f['user_email'].value;
	var user_firstname = f['user_firstname'].value;
	var user_lastname = f['user_lastname'].value;
	var user_birth_date_month = f['user_birth_date_month'].value;
	var user_birth_date_day = f['user_birth_date_day'].value;
	var user_birth_date_year = f['user_birth_date_year'].value;
	var user_address = f['user_address'].value;
	var user_city = f['user_city'].value;
	var user_state = f['user_state'].value;
	var user_zip = f['user_zip'].value;
	var user_country = f['user_country'].value;
	var user_phone = f['user_phone'].value;

	
	//check if all fields are filled
	if ( isBlank(user_email) || 
         isBlank(user_firstname) || 
         isBlank(user_lastname) || 
         isBlank(user_address) || 
         isBlank(user_city) || 
         isBlank(user_state) ||
         isBlank(user_zip)
       ) {
        alert(_jt("Please fill all the required fields."));
        return;
    }  	

    //check email
    var test_pattern = /[\w-]+@([\w-]+\.)+[\w-]+/;
	if (!test_pattern.test(user_email)) {
		alert(_jt("Invalid Email address. Please re-enter."));
		return;
	}
            
    //check if birth date is valid
    if ( !Date.isValid(user_birth_date_month + '/' + user_birth_date_day + '/' + user_birth_date_year, 'M/d/yyyy') ) {
        alert(_jt("The date of birth you entered does not seem valid. Please re-enter."));
        return;
    }
        

    //all went well - let's do some effects
    document.getElementById('user_btn_submit').disabled = true;
    document.getElementById('user_btn_submit').value = '.. ' + _jt("processing") + ' ..';
    
    //submit
	f.submit();
	

}



function contact_validate() {

    var f = document.form_contact;
    
    if ( isBlank(f.contact_name.value) || isBlank(f.contact_email.value) || isBlank(f.contact_message.value) || isBlank(f.contact_secureimage_code.value) ) {
        alert(_jt("Please fill all the fields."));
        return;
    }
    
    //check email
    var test_pattern = /[\w-]+@([\w-]+\.)+[\w-]+/;
	if (!test_pattern.test(f.contact_email.value)) {
		alert(_jt("Invalid Email address. Please re-enter."));
		return;
	}    

    //all went well - let's do some effects
    document.getElementById('contact_btn_submit').disabled = true;
    document.getElementById('contact_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    f.submit();
}


function user_validate_change_password() {
    var f = document.form_user_edit_password;
    
    if (isBlank(f.user_password_current.value) || isBlank(f.user_password_new.value) ) {
        alert(_jt("Please fill all the fields."));
        return;
    }

    //check user_password
	if (f.user_password_new.value.length < 5 || f.user_password_new.value.length > 32) {
		alert(_jt("Invalid New Password. \n Please use 5 to 32 characters. A combination of latin letters, numbers and symbols - not spaces please. \n Please re-enter."));
		return;
	}
	

    //check user_password repeat
	if (f.user_password_new.value != f.user_password_new_repeat.value) {
		alert(_jt("The passwords do not match. \n Please re-enter."));
		return;
	}
	
	
    //all went well - let's do some effects
    document.getElementById('user_btn_submit').disabled = true;
    document.getElementById('user_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    f.submit();
}



function user_validate_password_reset() {
    var f = document.form_user_reset_password;
    
    if (isBlank(f.user_email.value) || isBlank(f.user_secureimage_code.value) ) {
        alert(_jt("Please fill all the fields."));
        return;
    }

	
    //all went well - let's do some effects
    document.getElementById('user_btn_submit').disabled = true;
    document.getElementById('user_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    f.submit();
}



function user_avatar_delete_photo() {

    if ( confirm(_jt("Please confirm: remove current avatar picture?")) ) {
        location.href = '/user/account_profile_avatar_process.php?remove=true';
    }

}


function user_validate_avatar() {
    var f = document.form_user_edit_avatar;

    var user_avatar_file = f.user_avatar_file.value.toLowerCase();
    
    if (isBlank(user_avatar_file) ) {
        return;
    }
        

    var parts_field = user_avatar_file.split('.');
    
    var p = parts_field.length - 1;
    var file_extension = parts_field[p];

    if ( file_extension != 'jpg' &&
         file_extension != 'jpeg' &&
         file_extension != 'png' &&
         file_extension != 'gif') {
       
        alert(_jt("It seems that the file you are trying to upload has not the right extension. \n\n Allowed types of pictures are: jpg, png, gif"));
        return;
       
       }

	
    //all went well - let's do some effects
    document.getElementById('user_btn_submit').disabled = true;
    document.getElementById('user_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    f.submit();
}


//     var coin_amount = f.coin_amount.value;
//     if ( isBlank(coin_amount) ) {
//         alert(' Please fill the amount you wish to get from this offer. ');
//         return;
//     }
//     
//     coin_amount = coin_amount.replace('-', '');
//     coin_amount = coin_amount.replace(',', '.');
//     var fixedAmount = new Number(coin_amount);
//     coin_amount = fixedAmount.toFixed(2);
//     
//     if ( !isNumeric(coin_amount) ) {
//         f.coin_amount.value = '';
//         alert(' Wrong amount! Please enter a valid amount.');
//         return;
//     }
// 
//     f.coin_amount.value = coin_amount;    
//     

/******************************************************************************/
// coins
/******************************************************************************/


function coin_validate_new_offer() {
    var f = document.form_offer_get;
    

    var offer_title = f.offer_title.value;
    var offer_description = f.offer_description.value;
    var offer_photo1_file = f.offer_photo1_file.value.toLowerCase();
    var offer_photo2_file = f.offer_photo2_file.value.toLowerCase();
    var pm_courier = document.getElementById('pm_courier').checked;
    var pm_post = document.getElementById('pm_post').checked;
    var pm_internet = document.getElementById('pm_internet').checked;
    var pm_hand = document.getElementById('pm_hand').checked;
    var pm_other = document.getElementById('pm_other').checked;
    var offer_shipment_method_other = f.offer_shipment_method_other.value;
    var offer_category_custom = getInputValue(f.offer_category_custom);    
    var offer_price = f.offer_price.value;
    var user_check_agree = document.getElementById('user_check_agree').checked;
    
  
    //check obligatory fields
    
    //title        
    if ( isBlank(offer_title) ) {
        alert(_jt("Please fill the title of the offer."));
        return;
    }

    //comments - up to 55 chars
    f.offer_title.value = offer_title.substr(0,55);
    
        
    //descr
    if ( isBlank(offer_description) ) {
        alert(_jt("Please fill the description of the offer."));
        return;
    }
    
    //post method
    if ( !pm_courier && !pm_post && !pm_internet && !pm_hand && !pm_other) {
        alert(_jt("Please select at least one post method."));
        return;   
    }
    
    if ( pm_other && isBlank(offer_shipment_method_other) ) {
        alert(_jt("Please specify an alternative post method."));
        return;   
    }

    //category        
    if ( isBlank(offer_category_custom) ) {
        alert(_jt("Please select a subcategory for the offer."));
        f.offer_category_custom.selectedIndex = -1;
        return;
    }
    
    //check if tos is checked
    if (!user_check_agree) {
        alert(_jt("Please make sure you Agree to our terms."));
        return;
    }
    
    //check optional fields        

    //check price
    if ( !isBlank(offer_price) ) {
	    if ( !isInteger(offer_price) || offer_price < 1 || offer_price > 5000 ) {
	        f.offer_price.value = '';
	        alert(_jt("Wrong price! Please enter a valid amount."));
	        return;
	    }
	} 
    
            
    //check photo1
    if ( !isBlank(offer_photo1_file) ) {
        var parts_field = offer_photo1_file.split('.');
        
        var p = parts_field.length - 1;
        var file_extension = parts_field[p];
    
        if ( file_extension != 'jpg' &&
             file_extension != 'jpeg' &&
             file_extension != 'png' &&
             file_extension != 'gif') {
           
            alert(_jt("It seems that the file for photo 1 you are trying to upload has not the right extension. \n\n Allowed types of photos are: jpg, png, gif"));
            return;
           
        }        
    }
        
    //check photo2
    if ( !isBlank(offer_photo2_file) ) {
        var parts_field = offer_photo2_file.split('.');
        
        var p = parts_field.length - 1;
        var file_extension = parts_field[p];
    
        if ( file_extension != 'jpg' &&
             file_extension != 'jpeg' &&
             file_extension != 'png' &&
             file_extension != 'gif') {
           
            alert(_jt("It seems that the file for photo 2 you are trying to upload has not the right extension. \n\n Allowed types of photos are: jpg, png, gif"));
            return;
           
        }        
    }

	var offcateg = offer_category_custom.split('_');
	f.offer_category_id.value = offcateg[0];
	f.offer_subcategory_id.value = offcateg[1];
	
    //all went well - let's do some effects
    //popup mode - no effects....
    //document.getElementById('offer_btn_submit').disabled = true;
    //document.getElementById('offer_btn_submit').value = '.. ' + _jt("processing") + ' ..';
    alert(_jt("Please be patient! This may take a while! \n\n If a new window is not opened, please make sure you do not have any popup blocker for our site!"));    
    f.submit();
}



function coin_validate_insert() {


    var f = document.form_coin_insert;

    var coin_amount = f.coin_amount.value;
    var pm_creditcard = document.getElementById('pm_creditcard').checked;
    var pm_moneybookers = document.getElementById('pm_moneybookers').checked;
    var pm_western_union = document.getElementById('pm_western_union').checked;
    var pm_paypal = document.getElementById('pm_paypal').checked;
    var pm_imo = document.getElementById('pm_imo').checked;
    var pm_cheque = document.getElementById('pm_cheque').checked;
    var pm_bank_transfer = document.getElementById('pm_bank_transfer').checked;
    var pm_hand_to_hand = document.getElementById('pm_hand_to_hand').checked;
    var pm_other = document.getElementById('pm_other').checked;
    var coin_pay_method_other = f.coin_pay_method_other.value;
    var countries_all = document.getElementById('countries_all').checked;
    var countries_selected = document.getElementById('countries_selected').checked;
    var continents_selected = document.getElementById('continents_selected').checked;
    var coin_countries = document.getElementById('coin_countries');
    var coin_continent_europe = document.getElementById('coin_continent_europe').checked;
    var coin_continent_north_america = document.getElementById('coin_continent_north_america').checked;
    var coin_continent_south_america = document.getElementById('coin_continent_south_america').checked;
    var coin_continent_australia = document.getElementById('coin_continent_australia').checked;
    var coin_continent_asia = document.getElementById('coin_continent_asia').checked;
    var coin_continent_africa = document.getElementById('coin_continent_africa').checked;
    var coin_continent_antarctica = document.getElementById('coin_continent_antarctica').checked;
    var coin_comments = f.coin_comments.value;
       
    //amount
    if ( isBlank(coin_amount) ) {
        alert(_jt("Please fill the amount you are offering."));
        return;
    }
    
   
    if ( !isInteger(coin_amount) || coin_amount < 1 || coin_amount > 5000 ) {
        f.coin_amount.value = '';
        alert(_jt("Wrong amount! Please enter a valid amount."));
        return;
    }    
    
    
    //payment method
    if ( !pm_creditcard && !pm_moneybookers && !pm_western_union && !pm_paypal && !pm_imo && !pm_cheque && !pm_bank_transfer && !pm_hand_to_hand && !pm_other) {
        alert(_jt("Please select at least one payment method."));
        return;   
    }
    
    if ( pm_other && isBlank(coin_pay_method_other) ) {
        alert(_jt("Please specify an alternative payment method."));
        return;   
    }

    
    //areas
    if ( !countries_all && !countries_selected && !continents_selected) {
        alert(_jt("Please select an area from which you will accept offers."));
        return;   
    }    

    if ( countries_selected && coin_countries.selectedIndex == -1 ) {
        alert(_jt("Please select at least one country."));
        return;   
    }  

    if ( continents_selected && !coin_continent_europe  && !coin_continent_north_america  && !coin_continent_south_america  && !coin_continent_australia  && !coin_continent_asia  && !coin_continent_africa  && !coin_continent_antarctica ) {
        alert(_jt("Please select at least one continent."));
        return;   
    } 
    

    //comments - up to 256 chars
    f.coin_comments.value = coin_comments.substr(0,255);
            
    
    var queryString = $(f).formSerialize(); 
    queryString += '&width=600&height=400&modal=false&mode=preview_AJAX'; 
    var url_preview = 'insert_process.php?' + queryString;


    //show preview in thickbox
    //tb_remove();
    tb_show('', url_preview);
	
    //all went well - let's do some effects
    //document.getElementById('coin_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    //f.submit();


}



function search_validate_users() {

    var f = document.form_search_users;

    var search_user = f.search_user.value;
    
    if ( search_user == '') {
        alert(_jt("Please fill a username or at least a part of it."));
        return;      
    }
    
    if ( search_user.length < 3 ) {
        alert(_jt("Please enter at least 3 characters."));
        return;      
    }    
    
    //all went well - let's do some effects
    document.getElementById('search_btn_submit').disabled = true;
    document.getElementById('search_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    f.submit();
}


function validate_search_coins() {

    var f = document.form_search_coins;

    var smode = f.smode.value;
    
    if ( isBlank(smode) ) {
        alert(_jt("Please choose a method of search (exact amount or range) and fill the desired values."));
        return;
    }

    if ( smode == 'search_exact' ) {
        var search_amount1_from = f.search_amount1_from.value;

        if ( isBlank(search_amount1_from) ) {
            alert(' Please fill the exact amount. ');
            //let's make it easier for the user...
            search_coins_toggle_methods('div-form-search-exact', 'div-form-search-range');
            f.search_amount1_from.focus();
            return;
        }        

        
        if ( !isInteger (search_amount1_from) || search_amount1_from < 1 || search_amount1_from > 5000 ) {
            f.search_amount1_from.value = '';
            alert(_jt("Wrong amount for 'EXACT AMOUNT' field! Please enter a valid amount. \n\n Enter a numeric value from 1 to 5000"));
            return;
        }
    
    
        //this is what we need
        f.search_amount_from.value = search_amount1_from;
        f.search_amount_to.value = search_amount1_from;
            
    } else {

        //from
        var search_amount2_from = f.search_amount2_from.value;

        if ( isBlank(search_amount2_from) ) {
            alert(' Please fill the amount from. ');
            //let's make it easier for the user...
            search_coins_toggle_methods('div-form-search-range', 'div-form-search-exact');
            f.search_amount2_from.focus();
            return;
        }        

        
        if ( !isInteger(search_amount2_from) || search_amount2_from < 1 || search_amount2_from > 5000 ) {
            f.search_amount2_from.value = '';
            alert(_jt("Wrong amount for 'AMOUNT FROM' fields! Please enter a valid amount. \n\n Enter a numeric value from 1 to 5000"));
            return;
        }

    
        //to
        var search_amount2_to = f.search_amount2_to.value;

        if ( isBlank(search_amount2_to) ) {
            alert(' Please fill the amount to. ');
            //let's make it easier for the user...
            search_coins_toggle_methods('div-form-search-range', 'div-form-search-exact');
            f.search_amount2_to.focus();
            return;
        }        

        
        if ( !isInteger(search_amount2_to) || search_amount2_to < 1 || search_amount2_to > 5000 ) {
            f.search_amount2_to.value = '';
            alert(_jt("Wrong amount for 'AMOUNT TO' field! Please enter a valid amount. \n\n Enter a numeric value from 1 to 5000"));
            return;
        }
        
        //check if from < to
        if (search_amount2_from >= search_amount2_to) {
            //no error msg - just swap values!
            f.search_amount2_from.value = search_amount2_to;
            f.search_amount2_to.value = search_amount2_from;           
        }
            
        //this is what we need
        f.search_amount_from.value = search_amount2_from;
        f.search_amount_to.value = search_amount2_to;        
    
    }
    
    
    //currencies
    var a = new Array();
    var booChecked = false;
    for (var c = 0; c < f.search_currency.length; c++) {
        if (f.search_currency[c].checked) {
            booChecked = true;
            a.push(f.search_currency[c].value);
        }
    }
    if (!booChecked) {
        alert(_jt("Please select at least one currency."));
        return;
    }
    

    f.search_currencies.value = a;
    
    
    //all went well - let's do some effects
    document.getElementById('search_btn_submit').disabled = true;
    document.getElementById('search_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    f.submit();
}


/* coin/get.php + app/index.php */
function validate_search_coins_basic() {

    var f = document.form_search_coins;


    var search_amount1_from = f.search_amount1_from.value;

    if ( isBlank(search_amount1_from) ) {
        alert(_jt("Please fill an amount to search for."));
        return false;
    }        

    
    if ( !isNumeric(search_amount1_from) || search_amount1_from < 1 || search_amount1_from > 5000 ) {
        f.search_amount1_from.value = '';
        alert(_jt("Wrong amount for 'AMOUNT' field! Please enter a valid amount. \n\n Enter a numeric value from 1 to 5000"));
        return false;
    }

    //this is what we need
    f.search_amount_from.value = search_amount1_from;
    f.search_amount_to.value = search_amount1_from;
    
            
    //f.submit();
    return true;
}



function validate_search_offers()
{

    var f = document.form_search_offers;

//no validations required now... if the form is submitted empty, search results will redirect to offers listing default page

    //var search_keywords = f.search_keywords.value;
    //var search_title = document.getElementById('search_title').checked;
    //var search_description = document.getElementById('search_description').checked;

    //if ( isBlank(search_keywords) ) {
    //    alert(_jt("Please enter at least one keyword."));
    //    return false;
    //}
        
    //if ( !search_title && !search_description ) {
    //    f.search_title.checked = true;
    //}
    

    //all went well - let's do some effects
    document.getElementById('search_btn_submit').disabled = true;
    document.getElementById('search_btn_submit').value = '.. ' + _jt("processing") + ' ..';    
    //f.submit();
    return true;
    
}


function validate_pm_compose() {
    var f = document.form_pm_compose;
       
    if ( isBlank(f.pm_to_user.value) || isBlank(f.pm_subject.value)  || isBlank(f.pm_body.value) ) {
        alert(_jt("Please fill all the fields to continue."));
        return false;
    }

    //all went well - let's do some effects
    document.getElementById('pm_btn_submit').disabled = true; 
    document.getElementById('pm_btn_submit').value = '.. ' + _jt("processing") + ' ..';
       
    f.submit();
}


function validate_feedback_new() {
    var f = document.form_feedback_new;
       
    if ( ( !document.getElementById('radio-positive').checked && !document.getElementById('radio-negative').checked ) || isBlank(f.comments.value) ) {
        alert(_jt("Please fill all the fields to continue."));
        return false;
    }
    
    var continueSubmit = true;
    
    //if negative
    if ( document.getElementById('radio-negative').checked ) {
        if ( !confirm(_jt("Please confirm: \n\n You are about to leave Negative Feedback. \n Would you like to continue?")) ) {
            continueSubmit = false;                
        }
    }

    if ( continueSubmit ) {
        //all went well - let's do some effects
        document.getElementById('feedback_btn_submit').disabled = true; 
        document.getElementById('feedback_btn_submit').value = '.. ' + _jt("processing") + ' ..';
       
        f.submit();
    }
}


function validate_my_offer_remove_coin() {
    var f = document.form_my_offer_remove_coin;
       
    if ( isBlank(f.reason.value) ) {
        alert(_jt("Please provide a reason."));
        return false;
    }
    
    //all went well - let's do some effects
    document.getElementById('btn_my_offer_remove_coin_submit').disabled = true; 
    document.getElementById('btn_my_offer_remove_coin_submit').value = '.. ' + _jt("processing") + ' ..';
   
    f.submit();
    
}
