

function confirm_del() {
    var reply = confirm("Are you sure ?");

    if(reply) {
        return true;
    } else {
        return false;
    }
}

function getfileextension(filename) {   
    if( filename.length == 0 ) return "";
    var dot = filename.lastIndexOf(".");
    if( dot == -1 ) return "";
    var extension = filename.substr(dot,filename.length);
    return extension;
}

function check_excel_import_csv(){
    filename = document.getElementById("get_file").value;
    if (filename == '') return false;
    if (getfileextension(filename) != '.csv') {
        alert("This is not csv file!");
        return false;
    }
    return true;
}

function confirm_del_entry() {
    var reply = confirm("This will permanantly delete this record!");

    if(reply) {
        return true;
    } else {
        return false;
    }
}

function viewform(m) {
    var w = 750;
    var h = 600;
    var scroll = 'yes';
    var settings;
    var LeftPosition;
    var TopPosition;
    var win;
        
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
    settings = settings + ',resizable=no,maximize=no,status=no,toolbar=no,directories=no,menubar=no,location=no';
          
    win = window.open(m, 'pre', settings);
    win.name = 'name';
    win.focus();
}

function viewform_issue(m) {
    var w = 350;
    var h = 90;
    var scroll = 'yes';
    var settings;
    var LeftPosition;
    var TopPosition;
    var win;
        
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
    settings = settings + ',resizable=no,maximize=no,status=no,toolbar=no,directories=no,menubar=no,location=no';
          
    win = window.open(m, 'pre', settings);
    win.name = 'name';
    win.focus();
}
function viewform_payment(m) {
    var w = 350;
    var h = 150;
    var scroll = 'no';
    var settings;
    var LeftPosition;
    var TopPosition;
    var win;
        
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
    settings = settings + ',resizable=no,maximize=no,status=no,toolbar=no,directories=no,menubar=no,location=no';
          
    win = window.open(m, 'pre', settings);
    win.name = 'name';
    win.focus();
}
function viewform_due(m) {
    var w = 360;
    var h = 120;
    var scroll = 'no';
    var settings;
    var LeftPosition;
    var TopPosition;
    var win;
        
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
    settings = settings + ',resizable=no,maximize=no,status=no,toolbar=no,directories=no,menubar=no,location=no';
          
    win = window.open(m, 'pre', settings);
    win.name = 'name';
    win.focus();
}

function viewform2(m) {
    var w = 300;
    var h = 250;
    var scroll = 'no';
    var settings;
    var LeftPosition;
    var TopPosition;
    var win;
        
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;
  
    settings = 'height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll;
    settings = settings + ',resizable=no,maximize=no,status=no,toolbar=no,directories=no,menubar=no,location=no';
          
    win = window.open(m, 'pre', settings);
    win.name = 'name';
    win.focus();
}

function select_promocodes(mark) { 
    for (i = 0; i < document.promocodes.elements.length; i++) {
        var item = document.promocodes.elements[i];
        if (item.name == "promocodes_id[]") {
            item.checked = mark;
        };
    }
}

/**
 *
 * show_input_price
 * @param listing_id
 * 
 * @return void
 * 
 **/
function show_input_price(listing_id) {
    if(listing_id != undefined) {
        document.getElementById('listing_id_' + listing_id).style.display = 'none';
        document.getElementById('show_input_price_' + listing_id).style.display = '';
    }
}

/**
 *
 * show_input_price
 * @param e
 * @param object
 * @param listing_id
 * 
 * @return void
 *
 **/
function set_price(e, object, listing_id) {
    if (e.which || e.keyCode) {
        if ((e.which == 13) || (e.keyCode == 13)) {

            var price = object.value;

            if(is_integer(price)) {

                var args = {
                    listing_id: listing_id,
                    price: price
                }

                if(xajax_set_price(args)) {
                    document.getElementById('show_input_price_' + listing_id).style.display = 'none';
                    document.getElementById('listing_id_' + listing_id).style.display = '';
                }
                
            } else {
                object.style.border = "solid red 1px";
            }
        }
    }
}

/**
 *
 * show_input_price_for_item
 * @param item_id
 *
 * @return void
 *
 **/
function show_input_price_for_item(item_id) {
    if(item_id != undefined) {
        document.getElementById('item_id_' + item_id).style.display = 'none';
        document.getElementById('show_input_price_' + item_id).style.display = '';
    }
}

/**
 *
 * set_price_for_item
 * @param e
 * @param object
 * @param item_id
 *
 * @return void
 *
 **/
function set_price_for_item(e, object, item_id) {
    if (e.which || e.keyCode) {
        if ((e.which == 13) || (e.keyCode == 13)) {

            var price = object.value;

            if(is_integer(price)) {

                var args = {
                    item_id: item_id,
                    price: price
                }
                if(xajax_set_price_for_item(args)) {
                    document.getElementById('show_input_price_' + item_id).style.display = 'none';
                    document.getElementById('item_id_' + item_id).style.display = '';
                }

            } else {
                object.style.border = "solid red 1px";
            }
        }
    }
}

/**
 *
 * is_integer
 * @param value
 *
 * @return string
 *
 **/
function is_integer(value) {
    return /^[-+]?[0-9]+$/.test(value);
}
