﻿var DSS;
if (!DSS) DSS = {};
else if (typeof DSS != "object")
    throw new Error("DSS already exists and is not an object");
    
if (DSS.Utilities)
    throw new Error("DSS.Utilities already exsists");

DSS.Utilities = {
    HtmlEncode: function(textToEncode)
    {
        var result = textToEncode;

        var amp = /&/gi;
        var gt = />/gi;
        var lt = /</gi;        

        var html_gt = "&gt;";
        var html_lt = "&lt;";
        var html_amp = "&amp;";
        
        result = result.replace(amp, html_amp);        
        result = result.replace(lt, html_lt);
        result = result.replace(gt, html_gt);       

        return result;
    },
    
    addXmlParameter: function(name,type,value){
        var result;
        result =  '<pRow>'+
                    '<colName>'+DSS.Utilities.HtmlEncode(name)+'</colName>'+
                    '<colType>'+DSS.Utilities.HtmlEncode(type)+'</colType>' + 
                    '<colValue>'+DSS.Utilities.HtmlEncode(value==null? "":value)+'</colValue>'+
                '</pRow>';
        return result;
    },
    
    input2KieuTruongSQL: function(kieuInput){
        var result;
        if(kieuInput==1 || kieuInput ==2){
            result = "12";
        }else if(kieuInput==3){
            result = "11";
        }else if(kieuInput==9){
            result = "4";
        }else if(kieuInput==8 || kieuInput ==10){
            result = "8";
        }else{
            result = "12";
        }        
        return result;
    },
    
    addXmlParameterSession: function(name,value){
        var result;
        result =  '<pRow>'+
                    '<SesName>'+DSS.Utilities.HtmlEncode(name)+'</SesName>'+
                    '<SesValue>'+DSS.Utilities.HtmlEncode(value)+'</SesValue>' +                     
                '</pRow>';
        return result;
    }
}

String.prototype.xreplace=function(toberep,repwith){
	var temp = this;
	var i = temp.indexOf(toberep);
	while(i > -1){
		temp = temp.replace(toberep, repwith);
		i = temp.indexOf(toberep, i + repwith.length + 1);
	}
	return temp;
}

gridprocessing = function(img,lb,b,text){
    imgVis = b ? "visible" : "hidden";
    img.setStyle("visibility",imgVis);
    lb.setControlText(text);
}

loadINF = function(table,img,lb){
    table.request();
    gridprocessing(img,lb,true,"Load ding...");
}
