function openActionRequiredOptions() {
    return $('#actionReqActionOptionsPopup').html();
}

function auctionSaveAlert() {
    return '<div class="popupContainer" style="padding-top:15px;height:62px;">' +
    '<div><label class="labelColorFont" style="font-size:11px;">You are in the middle of create auction. The auction will be saved to saved auctions.</label></div>' +
    '<div style="clear:left; padding:10px 0; margin-left:145px;height:20px;">' +
    '<div class="action okButton" id="accept" style="float:left;"><a></a></div>' +
    '<div class= "linkClass"><a>cancel</a></div>' +
    '</div>' +
    '</div>';
}

// temp header.
var headerHtml = '<div class="header">' +
'<div class="logo" href="http://www.uk-liquidation.co.uk/" title="UK-Liquidation.co.uk"></div>' +
//'<div class="businessImageContainer">' +
//'<a class="mcAfee" href="https://www.scanalert.com/RatingVerify?ref=www.liquidation.com" target="_blank" ><img border="0" src="https://images.scanalert.com/meter/www.liquidation.com/31.gif" alt="HACKER SAFE certified sites prevent over 99.9% of hacker crime." /></a>' +
//'<a class="businessImage" href="http://www.bbbonline.org/cks.asp?id=11000171" title="Click to verify BBB accreditation and to see a BBB report." ></a>' +
'</div>'+
'<div style="float:right;margin-top:25px;text-align:right;color:#0077aa;font-weight:bold;"><label id="seller_name"></label><br/>'+
'<a href="/logout" style="text-Decoration:underline;cursor:pointer;">logout</a></div>' +
'</div>' +
'<div class="mainNav">' +
' <div class="mainNavleft">' +
' <ul>' +
' <li><a href="'+_LSIURL+'/account/main">account home</a></li>' +
' <li><a href="#" style="background-color:#305BA4">seller tools</a></li>' +
' </ul>' +
'</div>' +
'<div class="mainNavright">' +
' <a href="'+_LSIURL+'/account/main"><div class="backIcon"></div></a>' +
' </div>' +
'</div>';


var footerHtml = '<table width="643" align="right">' +
'<tbody><tr>' +
'<td width="643" align="center" colspan="2">' +
'<p>Copyright &copy; 2009 <a target="_blank" href="http://www.liquidityservicesinc.com/">Liquidity Services, Inc.</a> | <a target="blank" href="http://investor.liquidityservicesinc.com/phoenix.zhtml?c=195189&amp;p=irol-IRHome"><font color="#000000"><b>NASDAQ: LQDT</b></font></a></p>' +
'<p>All rights reserved.</p>' +
'</td>' +
'</tr>' +
'</tbody></table>';


function showLoadingStatus() {
    $('#loadingDiv').show();
    $('div.headerLabel2').hide();
}

function showAuctionData(data,type) {
    $('#loadingDiv').hide();
    if (data.result.length != 0) {
        $('#onePixLine').show();
        $('#filterOptions').show();
        $('#auctionItems').show();
        $('div.tableBody').show();
        $('div.tableFooter').show();
        if(type)
            $('div.headerLabel2 label').html("Listing all " + data.count + " "+type).parent().show();
    } else {
    $('#auctionItems').show();
    $('div.tableBody').hide();
    $('div.tableFooter').hide();
    $('div.tableHeader').show();
    $('#onePixLine').show();
    $('#filterOptions').show();
    if(type)
        $('div.headerLabel2 label').html("There are no "+type+" in this section").parent().show();
}
}

function allowdecimal(val){
    var rg = /^\d*(\.\d{1,3})?$/;
    return rg.test(val);
}
function setpagination(val){
    if(!SEARCH_DATA) SEARCH_DATA = {}
    SEARCH_DATA.per_page = val;
    SEARCH_DATA.page = 1;
    initLocal(SEARCH_DATA);
}

String.prototype.camelCase = function() {
    var s = this;
    var x = s.split("_");
    var temp = "";
    for (var i = 0; i < x.length; i++) {
        temp += x[i].slice(0,1).toUpperCase().concat(x[i].slice(1,x[i].length));
        if (typeof x[i + 1] != "undefined" && typeof x[i + 1] != "null") {
            temp += " "
        }
    }
    return temp;
};

String.prototype.reverseCamelCase = function() {
    var s = this;
    //Fix for UPC and UOM
    if(s.valueOf()==="UOM"){
        return "uom";
    }
    else if(s.valueOf()==="UPC Code"){
        return "upc_code";
    }
    //Fix ends here
    var x = s.split(" ");
    var temp = "";
    for (var i = 0; i < x.length; i++) {
        temp += x[i].slice(0,1).toLowerCase().concat(x[i].slice(1,x[i].length));
        if (typeof x[i + 1] != "undefined" && typeof x[i + 1] != "null") {
            temp += "_"
        }
    }
    return temp;
};

String.prototype.wordwrap = function() {
    var s = (this!=null) ? this.replace(/&#/g,"&amp;#") : "";
    return ((s.length > 30) ? s.substr(0, 28) + "..." : s).toString();
};

String.prototype.replaceAmpHash = function() {
    var s = (this!=null) ? this.replace(/&#/g,"&amp;#") : "";
    return s;
};

Array.prototype.has=function(v,i){
    for (var j=0;j<this.length;j++){
        if (this[j]==v) return (!i ? true : j);
    }
    return false;
}

function removeFromArray(array, from, to) {
    var rest = array.slice((to || from) + 1 || array.length);
    array.length = from < 0 ? array.length + from : from;
    return array.push.apply(array, rest);
}

function allowNumbersOnly(e, decimal) {
    var key;
    var keychar;
    if(window.event)key = (window.event.which) ? window.event.which : window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    keychar = String.fromCharCode(key);
    if(e.shiftKey){
         return false;
    }
    if((key > 47 && key < 58) || key == 46)return true;
    if((key > 95 && key < 106) || key == 110) return true;
    if(e.ctrlKey){       //keys check to allow ctrl+c, ctrl+v and ctrl+x
        if(e.keyCode == 67 || e.keyCode == 86 ||e.keyCode == 90 || e.keyCode == 65)
            return true;
        else
            return false;
    }
    if(decimal){
        if(key == 190)
            return true;
    } else{
        if(key == 190)
            return false;
    }
    if (key > 31 && (key < 46 || key > 57)  && (key != 190) &&(key !=37) &&(key !=39))return false;
    if ((key == 47))return false;
    else return true;
    if(decimal && (keychar == ".")) return true;
}

function allowAlphaOnly(e) {
    var key;
    if (window.event)key = window.event.keyCode;
    else if (e) key = e.which;
    else return true;
    if ((key == null) || (key == 0) || (key == 8) || (key == 9) || (key == 13) || (key == 27) || (key == 46) || (key == 37 ) || ( key == 39) || (key == 35 ) || ( key == 36)) return true;
    else if ((key >= 65 && key <= 90) || (key == 32))return true;
    else return false;
}

function getIEVersionNumber() {
    var ua = navigator.userAgent;
    var MSIEOffset = ua.indexOf("MSIE ");
    if (MSIEOffset == -1) {
        return 0;
    } else {
    return parseFloat(ua.substring(MSIEOffset + 5, ua.indexOf(";", MSIEOffset)));
}
}

function sortCountry(arr1,arr2){
    var arrTexts = new Array();
    var arrValues = new Array();
    var arrOldTexts = new Array();
    var result = new Array();
    for(var i = 0; i < arr1.length; i++)  {
        arrTexts[i] = arr1[i];
        arrValues[i] = arr2[i];
        arrOldTexts[i] = arr1[i];
    }
    arrTexts.sort();
    for(var j = 0; j < arr1.length; j++)  {
        arr1[j].text = arrTexts[j];
        for(var k = 0; k < arr1.length; k++)
            {
                if (arrTexts[j] == arrOldTexts[k])
                    {
                        arr1[j] = arrValues[k];
                        k = arr1.length;
                        var obj = new Object();
                        obj.name = arr1[j];
                        obj.value =  arrTexts[j];
                        result.push(obj);
                    }
                }
            }
            return result;
        }
        
        function loadCountryList(data){
            var arr1 = new Array();
            var arr2 = new Array();
            for(var j in data.result.country_code.values){
                arr1.push(data.result.country_code.values[j]);
                arr2.push(j);
            }
            return sortCountry(arr1,arr2);
        }
        
        function loadConditionList(data){
            var result = [];
            for(var j in data.result[0].value){
                result.push({"name":j,"value":data.result[0].value[j]});
            }
            return result;
        }
        
        function generateOptionsHTML(result,type) {
            var items = "";
            items = '<option value="">-- select a '+type+' --</option>';
            for(var i = 0;i<result.length;i++){
                items += '<option value ="'+result[i].name+'">'+result[i].value+'</option>';
            }
            return items;
        }
        function generateStateHTML(result,type){
            var dHtml = '<option value="">-- select a '+type+' --</option>';
            for(var i = 0; i < result.length; i++){
                for(var j in result[i]){
                    dHtml += '<option value ="'+j+'">'+result[i][j]+'</option>';
                }
            }
            return dHtml;
        }
        function getDisplayTime(t) {
            var d = new Date(t * 1000);
            t = new Date(d.toDateString());
            return [t.getDate() + "/" + (t.getMonth() + 1) + "/" + t.getFullYear(), d];
        }
        
        function getCalDateInSec(d){
            var t = new Date(d.toDateString())
            //var t = new Date(d.toUTCString())
            return t.getTime()/1000;
        }
        
        function clone_custom(obj){
            if(obj == null || typeof(obj) != 'object')
                return obj;
            var temp = obj.constructor(); // changed (twice)
            for(var key in obj)
                temp[key] = clone_custom(obj[key]);
            
            return temp;
        }
        
        function clone(obj){
            if(obj == null || typeof(obj) != 'object')
                return obj;
            var temp = new obj.constructor(); // changed (twice)
            for(var key in obj)
                temp[key] = clone(obj[key]);
            
            return temp;
        }
        
        
        function missingTab4(auction,size){
            if(auction["missingdata"].has("address1") || auction["missingdata"].has("size_classification")){
                return true;
            }
            if(size == "PACK") {
                if(auction["missingdata"].has("length") || auction["missingdata"].has("height") || auction["missingdata"].has("width") || auction["missingdata"].has("width")){
                    return true;
                }
                else{
                    return false;
                }
            }else if(size == "LTL" || size == "TRUCK") {
            if( auction["missingdata"].has("number_of_pallets_per_lot") || auction["missingdata"].has("pallet_weight")){
                return true;
            } else{
            return false;
        }
    }  
    return false;      
    
}

function missingTab1(auction){
    if(auction["missingdata"].has("subcategory_id")){
        return true;
    }else{
    return false;
}
}
function missingTab2(auction){
    if(auction["missingdata"].has("description") ||auction["missingdata"].has("inventory") || auction["item_count"]==0){
        return true;
    }else{
    return false;
}
}
function missingTab3(auction){
    if(auction["missingdata"].has("images") || auction["photo_count"]== 0){
        return true;
    }else{
    return false;
}
}

function getElementWithId(elem_id){
    var elem = null;
    if(document.getElementById(elem_id)){
        elem = document.getElementById(elem_id);
    }else{
    elem=$('#'+elem_id);
}
//  console.log(elem);
return elem!=null?elem:null;
}

function escapeHTML(str) {
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    return div.innerHTML;
}

function unescapeHTML(str) {
    var div = document.createElement('div');
    div.innerHTML = str.replace(/<\/?[^>]+>/gi, '');
    return div.childNodes[0] ? div.childNodes[0].nodeValue : '';
}
$.fn.autoEllipsis = function(text, options) {
    if (!options) options = {};
    var elements = $(this);
    var lines = options.lines || 1;
    var truncationChr = options.trucationChar || "&#x2026;"
    var showTitle = options.showTitle || true;
    $.each(elements, function() {
        var element = $(this);
        var width = options.width || element.attr("offsetWidth") - element.getPadding("right") - element.getPadding("left");
        var eleHeight = options.height || element.attr("offsetHeight");
        var originalText = text || element.html();
        originalText = unescapeHTML(originalText);
        element.html("");
        var mySpan = document.createElement("span");
        mySpan = $(mySpan).addClass("autowrapSpan");
        element.append(mySpan);
        mySpan.html('<span>' + escapeHTML(originalText) + '</span>');
        if (mySpan.attr("offsetWidth") > width || (eleHeight > 0 && mySpan.attr("offsetHeight") > eleHeight)) {
            var displayText = originalText;
            mySpan.html('');
            for (var x = 0; (lines == 0 || x < lines); x++) {
                if (x > 0) {
                    mySpan.append("<br/>");
                }
                var newspan = document.createElement("span");
                newspan = $(newspan);
                mySpan.append(newspan);
                var i = 1;
                var thisLine = displayText;
                newspan.html(escapeHTML(thisLine));
                i = displayText.length * width / newspan.attr("offsetWidth");
                thisLine = displayText.substr(0, i);
                newspan.html(escapeHTML(thisLine));
                if (newspan.attr("offsetWidth") > width) {
                    while (newspan.attr("offsetWidth") > width && i > 0) {
                        thisLine = displayText.substr(0, i);
                        i--;
                        newspan.html(escapeHTML(thisLine));
                    }
                } else {
                while (newspan.attr("offsetWidth") <= width && i <= displayText.length) {
                    thisLine = displayText.substr(0, i);
                    i++;
                    newspan.html(escapeHTML(thisLine));
                }
            }
            if (newspan.attr("offsetWidth") > width) {
                thisLine = thisLine.substr(0, thisLine.length - 1);
                newspan.html(escapeHTML(thisLine));
            }
            displayText = displayText.substr(thisLine.length, displayText.length);
            if (displayText.length == 0 || thisLine.length == 0) {
                break;
            }
        }
        if (truncationChr != null && displayText != '') {
            var beforeTruncation = thisLine;
            newspan.html(escapeHTML(thisLine) + truncationChr);
            while (newspan.attr("offsetWidth") > width) {
                if (thisLine.length - 1 < 0) {
                    newspan.html(escapeHTML(beforeTruncation));
                    break;
                }
                thisLine = thisLine.substr(0, thisLine.length - 1);
                newspan.html(escapeHTML(thisLine) + truncationChr);
            }
        }
    } else {
    element.innerHTML = originalText;
}
if (showTitle) {
    element.attr("title",originalText);
}
});
}
$.fn.getPadding = function(side) {
    var paddingStr = $(this).css("padding-" + side);
    if (paddingStr.indexOf("px") != -1) {
        paddingStr = paddingStr.substr(0, paddingStr.length - 2);
        return parseInt(paddingStr);
    }
    return 0;
}
//
//function clone_array(arr) {
// var i, _i, temp;
//    if( typeof arr !== 'object' ) {
//     return arr;
//    }
//    else {
//        if(arr.concat) {
//         temp = [];
//            for(i = 0, _i = arr.length; i < _i; i++) {
//             temp[i] = arguments.callee(arr[i]);
//            }
//        }
//        else {
//         temp = {};
//            for(i in arr) {
//             temp[i] = arguments.callee(arr[i]);
//            }
//        }
//     return temp;
//    }
//}
//
//function clone(obj){
//    if(obj == null || typeof(obj) != 'object') return obj;
//    if(obj.constructor == Array) {
//        return clone_array(obj);
//    }
//    var temp2 = {};
//    for(var key in obj) temp2[key] = clone(obj[key]);
//    return temp2;
//}

var COMMONS_CONFIG = {
    GET_COUNTRY_LIST : null,
    YEAR_RANGE:[],
    CONDITION :[],
    ARR1 : null,
    ARR2: null
}

//method to block/unblock the ui.
function pageBlock(throbber,message){
    if($('.bodyOverlay + div').attr("class") == "overlayMessage"){
        $('.bodyOverlay + div').remove();
    }
    if(throbber)
        $('.bodyOverlay').after("<div class='overlayMessage'><h2>"+message+"</h2></div>");
    else
        $('.bodyOverlay').after("<div class='overlayMessage'><h3>"+message+"</h3></div>"); 
    $('.bodyOverlay').show();
    if(jQuery.browser.msie){
        $("body select").each(function(){      //hiding select elements to avoid IE6 select issue.
            $(this).hide();
        })
    }
}

function  pageUnblock(){
    $('.bodyOverlay').hide();
    if($('.bodyOverlay').next().attr("class") == "overlayMessage"){
        $('.bodyOverlay').next().remove();
    }
    if(jQuery.browser.msie){
        $("body select").each(function(){     
            $(this).show();
        })
    }
}

