﻿function MenuMouseOver(obj, num)
{
    var d = e("HREF" + num);
    if(d)
        d.className = 'HREFSelT';
}

function MenuMouseOut(obj, num)
{
    var d = e("HREF" + num);
    if(d)
        d.className = 'HREFUSel';
}

function setImage(obj, source)
{
    e(obj).src = source;
}

function PHt()
{
    if( window.innerHeight && window.scrollMaxY ) // Firefox 
    {
        pageWidth = window.innerWidth + window.scrollMaxX;
        pageHeight = window.innerHeight + window.scrollMaxY;
    }
    else 
    if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {   
        pageWidth = document.body.scrollWidth;
        pageHeight = document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
        pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
        pageHeight = document.body.offsetHeight + document.body.offsetTop; 
    }
    if(pageHeight<document.body.offsetHeight)
        pageHeight=document.body.offsetHeight;
    
    if(navigator.appName.toLowerCase().indexOf("microsoft internet explorer") >= 0)
        pageHeight = parseInt(pageHeight + 100);
    else
        pageHeight = parseInt(pageHeight + 80);
    
    return parseInt(pageHeight);
}

function PWt()
{
    if( window.innerHeight && window.scrollMaxY ) // Firefox 
    {
        pageWidth = window.innerWidth + window.scrollMaxX;
        pageHeight = window.innerHeight + window.scrollMaxY;
    }
    else 
    if( document.body.scrollHeight > document.body.offsetHeight ) // all but Explorer Mac
    {   
        pageWidth = document.body.scrollWidth;
        pageHeight = document.body.scrollHeight;
    }
    else // works in Explorer 6 Strict, Mozilla (not FF) and Safari
    { 
        pageWidth = document.body.offsetWidth + document.body.offsetLeft; 
        pageHeight = document.body.offsetHeight + document.body.offsetTop; 
    }
    
    if(pageWidth<document.body.offsetWidth)
        pageWidth = document.body.offsetWidth;
    
    return pageWidth;
}

function GetTopOffset(obj) {
    var obj; //=e(object); 
    if(typeof(obj)=='object')
        obj=obj;
    else
        obj = e(obj);
        
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return curtop;
}


function GetLeftOffset(obj) {
    var obj; //=e(object); 
    if(typeof(obj)=='object')
        obj=obj;
    else
        obj = e(obj);
        
    var curleft = 0;
      var curtop = 0;
      if (obj.offsetParent) {
            do {
                  curleft += obj.offsetLeft;
                  curtop += obj.offsetTop;
            } while (obj = obj.offsetParent);
      }
      return curleft;
}

function getY( oElement )
{
    if(typeof(oElement)!= 'object')
        oElement = e(oElement);
        
    var iReturnValue = 0;
    while( oElement != null ) 
    {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}


function getX( oElement )
{
    if(typeof(oElement)!= 'object')
        oElement = e(oElement);
        
    var iReturnValue = 0;
    while( oElement != null ) 
    {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

//global function to get object by element id
function g(nam){return document.getElementById(nam);}
function e(obj){return ((typeof(obj) == "object")?obj:(g(obj))?g(obj):g("ctl00_CPH1_" + obj)?g("ctl00_CPH1_" + obj):g("ctl00_" + obj)?g("ctl00_" + obj):null);}

//start of functions to set and get value or inner HTML
function g_vl(obj){return trim(obj);}
function s_vl(obj, d){e(obj).value = trim(d);}
function g_hl(obj){return trim(e(obj).innerHTML);}
function s_hl(obj, d){ e(obj).innerHTML = trim(d);}
//end of functions to set and get value or innerHTML

//to hide and show
function s_o(obj){e(obj).style.display="block";}
function h_o(obj){e(obj).style.display="none";}

//to generate random number
function rnd(){return Math.random();}

function hideBg()
{
    try
    {
        var d = e("ModLay");
        d.style.height = PHt() + "px";
        d.style.width = PWt() + "px";
        d.style.display = "none";
    }
    catch(err)
    {
    
    }
}

function showBg()
{
    var d = e("ModLay");
    d.style.height = PHt() + "px";
    d.style.width = PWt() + "px";
    d.style.display="block";
    //d.style.zIndex = 20;
}

function SModalHW()
{
    var d = e("ModLay");
    d.style.height = parseInt(PHt()) + "px";
    d.style.width = PWt() + "px";
    d.style.display="block";
    //d.style.zIndex = 10;
}

var Aout;
function ALERT(msg)
{
    if(msg == "" || !msg)
        return;
    try
    {
        if(Aout)
            window.clearTimeout(Aout);
        Aout = window.setTimeout("CLEAR();", 5000);
    }
    catch(err)
    {
    
    }
    e("MErr").innerHTML = msg;
    e("MErr").style.display = "block";
}

function CLEAR()
{
    s_hl("MErr", "");
    e("MErr").innerHTML="";
    e("MErr").style.display = "none";
}

function NALERT(msg)
{
    if(msg == "" || !msg)
        return;
    
    if(Aout)
    {
        window.clearTimeout(Aout);   
    }
    e("MErr").innerHTML = msg;
    e("MErr").style.display = "block";
}

function L_Words(sentence, num)
{
    try
    {
        var text,t,rettext = "";
        sentence = trim(sentence);
        if(sentence.indexOf(" ") > 0)
        {
            t = sentence.split(" ");
            var i;
            for(i=0;i<t.length;i++)
            {
                if(t[i].length > num)
                {
                    t[i] = L_Words(t[i], num);
                }
                rettext += t[i] + " ";
            }
        }
        else
        {
            if(sentence.length > num)
            {
                var i=0, len = num;
                var t;
                while(i<sentence.length)
                {
                    rettext += sentence.substring(i, i + len) + " ";

                    i += len;                    
                    if((i+len) > sentence.length)
                        len = sentence.length - i;

                }
            }
            else
                rettext = sentence;
        }
        
        return rettext;
    }
    catch(err)
    {
        return sentence;
    }
}

function XHtO()
{

    var xmlHttp=null;
    try
      {
      // Firefox, Opera 8.0+, Safari
      xmlHttp=new XMLHttpRequest();
      }
    catch (e)
      {
      // Internet Explorer
      try
        {
        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
        }
      catch (e)
        {
        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
      }
    return xmlHttp;
}

var gobj;
function LdCtry(obj)
{
    if(typeof(obj) != 'object')
        obj = e(obj);
    gobj = obj;
    loadXMLDoc("../rsc/ctry.xml");
}

var xmlhttp;
function loadXMLDoc(url)
{

    xmlhttp=XHtO();
    
    if (xmlhttp!=null)
    {
      xmlhttp.onreadystatechange=onResponse;
      xmlhttp.open("GET",url,true);
      xmlhttp.send(null);
    }
    else
    {
      alert("Your browser does not support XMLHTTP.");
    }
}

function onResponse()
{
    if(xmlhttp.readyState!=4) return;
    if(xmlhttp.status != 200)
    {
      //alert("Problem retrieving XML data");
      return;
    }

    txt="<table border='1'>";
    x=xmlhttp.responseXML.documentElement.getElementsByTagName("ct_inf");
    var key, name;
    for (i=0;i<x.length;i++)
    {
        xx=x[i].getElementsByTagName("key");
        key = xx[0].firstChild.nodeValue;
        xx=x[i].getElementsByTagName("nam");
        name =xx[0].firstChild.nodeValue;
        var itm = new Option(name.toLowerCase(), key);
        gobj.options.add(itm);
    }
    setDefCtry();
}



/* to get photo */

function LdPoto(obj)
{
    if(typeof(obj) != 'object')
        obj = e(obj);
    gobj = obj;
    loadPoto("../ht_sv/gpoto.aspx?q=" + rnd());
}

function loadPoto(url)
{

    xmlhttp=XHtO();
    
    if (xmlhttp!=null)
    {
      xmlhttp.onreadystatechange=onPRes;
      xmlhttp.open("GET",url,true);
      xmlhttp.send(null);
    }
    else
    {
      alert("Your browser does not support XMLHTTP.");
    }
}

function onPRes()
{
    if(xmlhttp.readyState!=4) return;
    if(xmlhttp.status != 200)
    {
      //alert("Problem retrieving photo information");
      return;
    }
    var txt = xmlhttp.responseText;
    if(!txt || txt !="")
    {
        var t = txt.split("^");
        var name = t[0];
        var ht = parseInt(t[1]);
        var wd = parseInt(t[2]);
        gobj.src = "../udat/usr/tnails/" + name;
        if(wd > ht && wd > 150)
            gobj.style.width = "150px";
    }
}
/* end of loading photo */

function setFrmHt(ht)
{
    e("IFrm").style.height = parseInt(ht) + "px";
}

function F_Res(n_win, n_docel, n_body) {
	var n_result = n_win ? n_win : 0;
	if (n_docel && (!n_result || (n_result > n_docel)))
		n_result = n_docel;
	return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}

function s_Left() {
	return F_Res (
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function s_Top() {
	return F_Res (
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}

function f_clientWidth()
{
	return F_Res (
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}

function f_clientHeight() {
	return F_Res (
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}

function SPr(num, code)
{
    var loc = top.window.location + "";
    loc = loc.replace(/&/g, "$");
    loc = loc.toLowerCase();
    top.window.location = "../pgview/vpage.aspx?from=" + loc + "&pkey=" + num;
}

function AddId(id, obj)
{
    var d = e(obj);
    if(d.value == "")
        d.value = id;
    else
    {
        d.value += "," + id;
    }
    return false;
}

function RemId(id, obj)
{
    var d = e(obj);
    if(d.value == "")
        return;
    if(d.value == id)
    {
        d.value = "";
        return;
    }
    else
    {
        var cols = (d.value + "").split(",");
        var i, t = "";
        for(i=0;i<cols.length;i++)
        {
            if(cols[i] != id)
                t += cols[i] + ",";
        }
        if(t.length > 0)
            t = t.substring(0, t.length - 1)
        d.value = t;
    }
    return;
}

function Count(obj)
{
    var d = e(obj);
    if(d.value == "")
        return 0;
    var rows = trim(d).split(",");

    return rows.length;
}

function Add_row(obj, row)
{
    var d = e(obj);
    
    if(d.value == "")
        d.value = row;
    else
    {
        d.value += "<~>" + row;
    }
    return false;
}

function Rem_row(obj, id)
{
    var d = e(obj);
    if(d.value == "")
        return;
    var rows = (d.value + "").split("<~>");
    var i, t = "";
    for(i=0;i<rows.length;i++)
    {
        var cols = rows[i].split("<^>");
        if(id != cols[0])
            t += rows[i] + "<~>";
    }
    if(t.length > 0)
        t = t.substring(0, t.length - 3)

    d.value = t;

    return;
}

function R_Cnt(obj)
{
    var d = e(obj);
    if(d.value == "")
        return 0;
    var rows = trim(d).split("<~>");

    return rows.length;
}

function GetIds(obj)
{
    var ids = [];
    var count = 0;
    var alld = trim(e(obj));
    if(alld == "")
        return null;
    var rows = alld.split("<~>");
    var i;
    for(i=0;i<rows.length;i++)
    {
        var cols  = rows[i].split("<^>");
        ids[count] = cols[0];
        count++;
    }
    return ids;
}

function isExists(obj, source)
{
    if(source == null)
        return false;
    var i;
    for(i=0;i<source.length;i++)
    {
        if(trim(obj) == trim(source[i]))
            return true;
    }
    return false;
}

function istxtExists(obj, source)
{
    if(source == null)
        return false;
    if(obj == source)
        return true;
    var i;
    for(i=0;i<source.length;i++)
    {
        if(trim(obj) == trim(source[i]))
            return true;
    }
    return false;
}

function tFocus(obj, txt)
{
    if(trim(obj) == txt)
    {
        obj.value = "";
    }
}

function tBlur(obj, txt)
{
    if(trim(obj) == "" || trim(obj) == txt)
    {
        obj.value = txt;
    }
}

function GUNBId(userid)
{
    userid = parseInt(userid);
    if(userid == 0)
        return (new MsgPoto("Pagesite", "logo.jpg", 35, 126, "Pagesite"));
    var alldata = e("hdnUsrInfo").value;

    var rows = alldata.split("<~>");
    var totalCount = rows.length;
    var i;
    for(i=0;i<totalCount;i++)
    {
        var Cols = rows[i].split("<^>");
        if (userid == parseInt(Cols[0]))
        {

            if(Cols.length > 2)
            {
                //alert("identity flag: "  + Cols[8] + ", originid: " + Cols[6] + ", from id: " + Cols[0]);
                if(Cols[8] == "1" && Cols[6] != Cols[0])
                {
                    var tobj = GAUNBId(Cols[6]);
                    return (new MsgPoto(tobj.uname + "(" + Cols[1] + ")", tobj.name, tobj.height, tobj.width, Cols[1]));
                }
                else
                    return (new MsgPoto(Cols[1], Cols[2], Cols[3], Cols[4], Cols[1]));
            }
            else
                return (new MsgPoto(Cols[1], "photonotavail.jpg", 75, 75, Cols[1]));
        }
    }
    return (new MsgPoto("unknown", "photonotavail.jpg", 75,75, "unknown"));
}

function GAUNBId(userid)
{
    userid = parseInt(userid);
    if(userid == 0)
        return (new MsgPoto("Pagesite", "logo.jpg", 35, 126, "Pagesite"));
    var alldata = e("hdnUsrInfo").value;
    var rows = alldata.split("<~>");
    var totalCount = rows.length;
    var i;
    for(i=0;i<totalCount;i++)
    {
        var Cols = rows[i].split("<^>");
        if (userid == parseInt(Cols[0]))
        {
            if(Cols.length > 2)
                return (new MsgPoto(Cols[1], Cols[2], Cols[3], Cols[4], Cols[1]));
            else
                return (new MsgPoto(Cols[1], "photonotavail.jpg", 75, 75, Cols[1]));
        }
    }
    return (new MsgPoto("unknown", "photonotavail.jpg", 75,75, "unknown"));
}


function GetPgInfo(pid)
{
    pid = parseInt(pid);
    
    var alldata = e("hdnAtPgInfo").value;
    var rows = alldata.split("<~>");
    var totalCount = rows.length;
    var i;
    for(i=0;i<totalCount;i++)
    {
        var Cols = rows[i].split("<^>");
        if (pid == parseInt(Cols[0]))
        {
            if(Cols.length > 2)
                return (new MsgPoto(Cols[1], Cols[3], Cols[9], Cols[10]));
            else
                return (new MsgPoto(Cols[1], "default.jpg", 75, 75));
        }
    }
    return (new MsgPoto("unknown", "default.jpg", 75,75));
}




function setDDL(dt, obj)
{
    var obj = e(obj);
    var arr = obj.options;
    var index;
    var i;
    for(i=0;i<arr.length;i++)
    {
        if(arr[i].value == dt)
        {
            obj.selectedIndex = i;
            break;
        }
    }
}

function GSeaBlu(obj, txt)
{
    if(trim(obj) == "")
    {
        obj.value = txt;
    }
}

function GSeaFoc(obj, txt)
{
    if(trim(obj) == txt)
    {
        obj.value = "";
    }
}

function GSeF(obj, txt)
{
    obj = e(obj);
    if(trim(obj) == txt)
        obj.value = "";
}

function GSeB(obj, txt)
{
    obj = e(obj);
    if(trim(obj) == "")
        obj.value = txt;
}

function GVal(txt)
{
    var d = e("tSearch");
    if(trim(d) == "" || trim(d) == txt)
    {
        ALERT("please enter text to search...");
        d.focus();
        return false;
    }
    Redir("../sea/search.aspx?srch=" + trim(d));
    return false;
}

function GSeapress(obj, eve, txt)
{
    var keyCode = eve.keyCode ? eve.keyCode : eve.which ? eve.which : eve.charCode;

    if(keyCode==13)
    {
        try
        {
            if(GVal(txt)==true)
            {
                Redir("../sea/search.aspx?srch=" + e(obj).value);
                return false;
            }    
            else
                return false;
        }
        catch(err)
        {
            Redir("../sea/search.aspx?srch=" + e(obj).value);
            return false;
        }
    }
}

function Redir(URL)
{
    var cpg = window.location + "";
    if(cpg.indexOf("sea/search.aspx") > 0)
    {
        var stype;
        var d;
        d = e("rdoMine");
        if(d.checked == true)
            stype="mine";
        else
            stype="all";
        URL += "&typ=" + stype;
    }
    window.location = URL;
}

function RId(id, obj, rsep, csep)
{
    obj = e(obj);
    var dt = trim(obj);
    if(dt == "")
    {
        obj.value = "";
        return;
    }
    if(dt.indexOf(rsep) < 0)
    {
        if(dt.indexOf(csep) < 0)
        {
            if(dt == id)
                obj.value = "";
        }
        else
        {
            var Cs = dt.split(csep);
            if(Cs[0] == id)
                obj.value = "";
        }
        return;
    }
    else
    {
        if(dt.indexOf(csep) > 0)
        {
            var rows = dt.split(rsep);
            var i, t = "";
            for(i=0;i<rows.length;i++)
            {
                var cols = rows[i].split(csep);
                if(id != cols[0])
                    t += rows[i] + rsep;
            }
            if(t.length > 0)
                t = t.substring(0, t.length - rsep.length)

            obj.value = t;
        }
        else
        {
            var cols = dt.split(rsep);
            var i, t = "";
            for(i=0;i<cols.length;i++)
            {
                if(cols[i] != id)
                    t += cols[i] + rsep;
            }
            if(t.length > 0)
                t = t.substring(0, t.length - rsep.length)
            obj.value = t;
        }
        return;
    }
}

/* Row processing universal function starts here */
//to remove a row
function RRById(id, obj, rsep, csep)
{
    var dt = trim(e(obj));
    obj = e(obj);
    if(dt == "")
        return;
    if(dt.indexOf(rsep) < 0)
    {
        if(dt.indexOf(csep) < 0)
        {
            if(dt == id)
                obj.value = "";
        }
        else
        {
            var Cs = dt.split(csep);
            if(Cs[0] == id)
                obj.value = "";
        }
        return;
    }
    else
    {
        if(dt.indexOf(csep) > 0)
        {
            var rows = dt.split(rsep);
            var i, t = "";
            for(i=0;i<rows.length;i++)
            {
                var cols = rows[i].split(csep);
                if(id != cols[0])
                    t += rows[i] + rsep;
            }
            if(t.length > 0)
                t = t.substring(0, t.length - rsep.length)

            obj.value = t;
        }
        else
        {
            var cols = dt.split(rsep);
            var i, t = "";
            for(i=0;i<cols.length;i++)
            {
                if(cols[i] != id)
                    t += cols[i] + rsep;
            }
            if(t.length > 0)
                t = t.substring(0, t.length - rsep.length)
            obj.value = t;
        }
        return;
    }
}

function getColbId(id, obj, cnum, rsep, csep)
{
    var dt = trim(e(obj));
    if(dt == "")
        return "";
    if(dt.indexOf(rsep) < 0)
    {
        if(dt.indexOf(csep) < 0)
        {
            if(dt == id)
                return id;
        }
        else
        {
            var Cs = dt.split(csep);
            if(Cs[0] == id)
                return Cs[cnum];
        }
        return "";
    }
    else
    {
        if(dt.indexOf(csep) > 0)
        {
            var rows = dt.split(rsep);
            var i, t = "";
            for(i=0;i<rows.length;i++)
            {
                var cols = rows[i].split(csep);
                if(id == cols[0])
                    return cols[cnum];
            }
            return "";
        }
        else
        {
            var cols = dt.split(rsep);
            if(cols[0] == id)
                    return cols[cnum];
        }
        return "";
    }
}

//to find existance
function isRFund(id, obj, rsep, csep)
{
    var dt = trim(e(obj));
    if(dt == "")
        return false;
    if(dt.indexOf(rsep) < 0)
    {
        if(dt.indexOf(csep) < 0)
        {
            if(dt == id)
                return true;
        }
        else
        {
            var Cs = dt.split(csep);
            if(Cs[0] == id)
                return true;
        }
        return false;
    }
    else
    {
        if(dt.indexOf(csep) > 0)
        {
            var rows = dt.split(rsep);
            var i, t = "";
            for(i=0;i<rows.length;i++)
            {
                var cols = rows[i].split(csep);
                if(id == cols[0])
                    return true;
            }
            return false;
        }
        else
        {
            var cols = dt.split(rsep);
            if(cols[0] == id)
                    return true;
        }
        return false;
    }
}

//to update a column by id
function UORById(id, obj, cnum, ndata, rsep, csep)
{
    var dt = trim(e(obj));
    obj = e(obj);
    if(dt == "")
        return;
    if(dt.indexOf(rsep) < 0)
    {
        if(dt.indexOf(csep) < 0)
        {
            if(dt == id)
                obj.value = ndata;
            return;
        }
        else
        {
            var Cs = dt.split(csep);
            if(Cs[0] == id)
            {
                Cs[cnum] = ndata;
            }
            
            var i;
            var ttxt = "";
            for(i=0;i<Cs.length;i++)
            {
                ttxt += Cs[i] + csep;
            }
            if(ttxt.length > 0)
                ttxt = ttxt.substring(0, ttxt.length - csep.length);
            
            obj.value = ttxt;
        }
        return;
    }
    else
    {
        if(dt.indexOf(csep) > 0)
        {
            var rows = dt.split(rsep);
            var i, t = "";
            for(i=0;i<rows.length;i++)
            {
                var cols = rows[i].split(csep);
                if(id != cols[0])
                    t += rows[i] + rsep;
                else
                {
                    cols[cnum] = ndata;
                    
                    var j;
                    var ttxt = "";
                    for(j=0;j<cols.length;j++)
                    {
                        ttxt += cols[j] + csep;
                    }
                    if(ttxt.length > 0)
                        ttxt = ttxt.substring(0, ttxt.length-csep.length);
                    t += ttxt + rsep;
                }
            }
            
            if(t.length > 0)
                t = t.substring(0, t.length - rsep.length)
            obj.value = t;
        }
        else
        {
            var cols = dt.split(rsep);
            var i, t = "";
            for(i=0;i<cols.length;i++)
            {
                if(cols[i] != id)
                    t += cols[i] + rsep;
                else
                {
                    cols[i] = ndata;
                    t += cols[i] + rsep;
                }
            }
            
            if(t.length > 0)
                t = t.substring(0, t.length - rsep.length)
            obj.value = t;
        }
        return;
    }
}


//to get new id
function getNId(obj, rsep, csep)
{
    var dt = trim(e(obj));
    obj = e(obj);
    if(dt == "")
        return 1;
    
    if(dt.indexOf(rsep) < 0)
    {
        if(dt.indexOf(csep) < 0)
        {
            return parseInt(dt) + 1;
        }
        else
        {
            var Cs = dt.split(csep);
            return parseInt(Cs[0]) + 1;
        }
    }
    else
    {
        if(dt.indexOf(csep) > 0)
        {
            var rows = dt.split(rsep);
            var i, t = "";
            var max = 0;
            for(i=0;i<rows.length;i++)
            {
                var cols = rows[i].split(csep);
                if(max < parseInt(cols[0]))
                    max = cols[0];
            }
            return parseInt(max) + 1;
        }
        else
        {
            var cols = dt.split(rsep);
            var i, t = "";
            var max = 0;
            for(i=0;i<cols.length;i++)
            {
                if(max < parseInt(cols[i]))
                    max = cols[i];
            }
            return parseInt(max) + 1;
        }
    }
}

// to add a new row
function AR2Obj(row, obj, rsep)
{
    obj = e(obj);
    var dt = trim(e(obj));
    if(dt == "")
        obj.value = trim(row);
    else
        obj.value = dt + rsep + trim(row);
}

//to insert a row
function InsRow(row, obj, id, rsep, csep)
{
    obj = e(obj);
    var dt = trim(e(obj));
    if(dt == "")
        obj.value = trim(row);
    else
    {
        var i, pos = -1;
        var txt= "";
        var rows = dt.split(rsep);
        
        for(i=0;i<rows.length;i++)
        {
            var cols = rows[i].split(csep);
            if(cols[0] == id)
            {
                pos = i;
                break;
            }
        }
        
        for(i=0;i<rows.length;i++)
        {
            if(i == pos)
                txt += rows[i] + rsep + row + rsep;
            else
                txt += rows[i] + rsep;
        }
        
        if(pos == -1)
            txt += row + rsep;
        
        if(txt.length>0)
            txt = txt.substring(0, txt.length - rsep.length);

        obj.value = txt;
    }
}

//to row count
function R_Ct(obj, rsep)
{
    var dt = trim(e(obj));
    if(dt == "")
        return 0;
    
    if(dt.indexOf(rsep) < 0)
        return 1;
    
    var ct = dt.split(rsep);
    
    return ct.length;
    
}
//to move a row up in order
function movUp(id, obj, rsep, csep)
{
    obj = e(obj);
    var dt = trim(e(obj));
    if(dt == "")
        return true;
    var rows = dt.split(rsep);
    var i, pos;
    for(i=0;i<rows.length;i++)
    {
        var cols = rows[i].split(csep);
        if(cols[0] == id)
        {
            pos = i;
            break;
        }
    }
    if(pos == 0)
        return false;
    var txt = "";
    for(i=0;i<rows.length;i++)
    {
        if(i == pos)
            continue;
        if((i+1) == pos)
        {
            txt += rows[i + 1] + rsep + rows[i] + rsep;
        }
        else
            txt += rows[i] + rsep;
    }
    
    if(txt.length > 0)
        txt = txt.substring(0, txt.length - rsep.length)
    
    obj.value = txt;
    return true;
}

//to move a row to top

function mov2Top(id, obj, rsep, csep)
{
    obj = e(obj);
    var dt = trim(e(obj));
    if(dt == "")
        return true;
    var rows = dt.split(rsep);
    var i, pos;
    for(i=0;i<rows.length;i++)
    {
        var cols = rows[i].split(csep);
        if(cols[0] == id)
        {
            pos = i;
            break;
        }
    }
    if(pos == 0)
        return false;
    
    var txt = "";
    
    txt += rows[pos] + rsep;
    var tpos = -1;
    
    for(i=0;i<rows.length;i++)
    {
        if(i == pos)
            continue;
        txt += rows[i] + rsep;
    }
    
    if(txt.length > 0)
        txt = txt.substring(0, txt.length - rsep.length)
    
    obj.value = txt;
    return true;
}

//to move a row down in order
function movDown(id, obj, rsep, csep)
{
    obj = e(obj);
    var dt = trim(e(obj));
    if(dt == "")
        return true;
    var rows = dt.split(rsep);
    var i, pos;
    for(i=0;i<rows.length;i++)
    {
        var cols = rows[i].split(csep);
        if(cols[0] == id)
        {
            pos = i;
            break;
        }
    }

    if(pos == rows.length - 1)
        return false;
    var txt = "";
    for(i=0;i<rows.length;i++)
    {
        if(i == pos)
            continue;
        if((i-1) == pos)
        {
            txt += rows[i] + rsep + rows[i - 1] + rsep;
        }
        else
            txt += rows[i] + rsep;
    }
    
    if(txt.length > 0)
        txt = txt.substring(0, txt.length - rsep.length)
    
    obj.value = txt;
    return true;
}

//to move a row to bottom

function mov2Bottom(id, obj, rsep, csep)
{
    obj = e(obj);
    var dt = trim(e(obj));
    if(dt == "")
        return true;
    var rows = dt.split(rsep);
    var i, pos;
    for(i=0;i<rows.length;i++)
    {
        var cols = rows[i].split(csep);
        if(cols[0] == id)
        {
            pos = i;
            break;
        }
    }
    
    if(pos == rows.length - 1)
        return false;
    
    var txt = "";
    for(i=0;i<rows.length;i++)
    {
        if(i == pos)
            continue;
        txt += rows[i] + rsep;
    }
    
    txt += rows[pos] + rsep;
    
    if(txt.length > 0)
        txt = txt.substring(0, txt.length - rsep.length)
    
    obj.value = txt;
    return true;
}

/* Row processing universal function ends here */