function cekmail(obj){
    // var field = form.email;
    // var str = field.value;
    var str = did(obj).value;
    if (window.RegExp) {
        var reg1str = "(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)";
        var reg2str = "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$";
        var reg1 = new RegExp(reg1str);
        var reg2 = new RegExp(reg2str);
        if (!reg1.test(str) && reg2.test(str)) 
            return true;
        return false;
    }
    else {
        if (str.indexOf("@") >= 0) 
            return true;
        return false;
    }
}

function number_format(number){
    var str = '', nh, c, x;
    nh = number.toString();
    c = 1;
    for (x = nh.length - 1; x >= 0; x--, c++) {
        str += nh.charAt(x);
        if (c % 3 == 0 && c != nh.length) 
            str += '.';
    }
    str = str.split("");
    str.reverse();
    str = str.join("");
    return str;
}

function numbersonly(e){
    var unicode = e.charCode ? e.charCode : e.keyCode
    // if the key isn't the backspace, left, right, del, tab (which we should
    // allow)
    if (unicode != 8 && unicode != 37 && unicode != 39 && unicode != 46 &&
    unicode != 9) {
        if (unicode < 48 || unicode > 57) // if not a number
            return false // disable key press
    }
}

function get_product_type_detail(){
    var arg = arguments;
    $.ajax({
        type: 'POST',
        url: Path + 'browse/get_search_product_type_detail',
        data: {
            id: $('#sel_product_type').val()
        },
        beforeSend: function(){
            $('#search_value').attr('disabled', true);
            $('#sel_product_type_detail').attr('disabled', true);
            $('#sel_product_type_detail').html('<option>' + str_loading + '</option>');
        },
        success: function(options){
            $('#sel_product_type_detail').html(options);
        },
        complete: function(){
            $('#search_value').attr('disabled', false);
            $('#sel_product_type_detail').attr('disabled', false);
            if (arg[0] != undefined) {
                $('#sel_product_type_detail').val(arg[0]).attr('selected', 'selected');
            }
        }
    });
    /* protorype version
     new Ajax.Updater('sel_product_type_detail', Path + 'browse/get_search_product_type_detail', {
     parameters: {
     id: $F('sel_product_type')
     },
     onLoading: function(){
     $('search_value').disable();
     $('sel_product_type_detail').disable();
     $('sel_product_type_detail').update('<option>' + str_loading + '</option>');
     },
     onComplete: function(){
     $('search_value').enable();
     $('sel_product_type_detail').enable();
     for (i = 0; i < $('sel_product_type_detail').length; i++) {
     if ($('sel_product_type_detail').options[i].text == arg[0]) {
     $('sel_product_type_detail').options[i].defaultSelected = true;
     }
     }
     }
     })
     */
}

function main_search(){
    temp = $('#sel_product_type_detail').val().split('_');
    filter = temp[0];
    search_field = temp[1];
    if (filter == 'product') {
        window.location = Path + 'browse/search/?type=' + $('#sel_product_type').val() + '&table=Product&field=' +
        temp[1] +
        '&value=' +
        $('#search_value').val();
    }
    if (filter == 'manufacturer') {
        window.location = Path +
        'browse/search/?type=' +
        $('#sel_product_type').val() +
        '&table=Manufacturer&field=name&value=' +
        $('#search_value').val();
    }
    if (filter == 'did') {
        window.location = Path + 'browse/search/?type=' + $('#sel_product_type').val() + '&did=' + temp[1] + '&value=' +
        $('#search_value').val();
    }
}

function get_big_image(image_name){
	$.ajax({
		type: 'POST',
		data: {
			image: image_name
		},
		url: Path + 'browse/get_big_image',
		beforeSend:function(){
			$('#big_image').html('<img src="' + Path + 'img/ajax-loader.gif"');
		},
		success:function(response){
			$('#big_image').html(response);
		}
	});
/*
    new Ajax.Updater('big_image', Path + 'browse/get_big_image', {
        parameters: {
            image: image_name
        },
        onLoading: function(){
            $('big_image').update('<img src="' + Path + 'img/ajax-loader.gif"');
        }
    });
*/
}

function remove_watchlist(id){
    if (confirm(str_remove_watchlist)) {
        window.location = Path + 'member/remove_watchlist/' + id;
    }
    return false;
}

function remove_wishlist(id){
    if (confirm(str_remove_wishlist)) {
        window.location = Path + 'member/remove_wishlist/' + id;
    }
    return false;
}

function request_refund(){
    if ($('#RefundBank').val() != '' && $('#RefundAccount').val() != '') {
        if (confirm(str_refund_confirm)) {
            return true;
        }
    }
    else {
        if ($('#RefundBank').val() == '') {
            $('RefundBankError').html(str_must_be_filled);
        }
        if ($('#RefundAccount').val() == '') {
            $('#RefundAccountError').html(str_must_be_filled);
        }
        return false;
    }
}
