url="";
//url="http://192.168.5.22/360";
var Oxml; var OxmlM; var strURL; var eSel; //neded to load data from database to dropdown
var ChatLSMsgId=0;
win= new Array(1000);
var js_prev_msg=0;
/////////////////////////////////////
function load_chat_msg_list()
{
//alert(js_prev_msg);
handler("chat.php","act=chat_msg_list&ChatSessionId="+this.document.frm.ChatSessionId.value+"&ChatLSMsgId="+ChatLSMsgId+"&js_prev_msg="+js_prev_msg);
js_prev_msg=0;
setTimeout("load_chat_msg_list()",1000);
}
/////////////////////////////////////
function js_load_private_chat(s_id,s_type)
{
    winObj=win[s_id];
    if (winObj != null)
    {
      // the window has already been created, but did the user close it?
      // if so, then reopen it. Otherwise make it the active window.
      if (!winObj.closed) {
        winObj.focus();
        return ;//winObj;
      }
      // otherwise fall through to the code below to re-open the window
    }
    win[s_id]=window.open("chat.php?act=chat_private&SId="+s_id+"&SType="+s_type,"User_Chat_Window_"+s_id,"toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=no,width=520,height=275");
    js_prev_msg=0;
}
/////////////////////////////////////
function char_count(t)
{
    val=t.value;
    if(parseInt(val.length)>=750)
    {
        return false;
    }
    limit=749;
    rem=parseInt(limit)-parseInt(val.length)
    loadInnerHtml("js_char_count",rem);
}
///////////////////////////////////
function isArray(a) {
    return isObject(a) && a.constructor == Array;
}
////////////////////////////////////////////////
function handler(php_file,act)
{
    strURL = url+php_file+"?"+act;
    //alert(strURL);
    //window.history.location(window.history.length+1)=strURL;
    //alert(window.history[0]);
    //window.copyhistory=strURL;
    load_db_innerHTML_data();
}
///////////////////////////////////////////////
function js_form_submit(ctrl)
{
    var sep="";
    var str="";
    var val="";
    for(i=0; i<ctrl.elements.length; i++)
    {
        val="";
        if(ctrl.elements[i].type=="radio" || ctrl.elements[i].type=="checkbox")
        {
            if(ctrl.elements[i].checked==true)
            {
                val=ctrl.elements[i].value;
            }
        }
        else if(ctrl.elements[i].type=="select-multiple" && ctrl.elements[i].name!="cs_unassigned")
        {
            aa=ctrl.elements[i].length;
            for(aaa=0;aaa<aa;aaa++)
            {
                //if(ctrl.elements[i].options[i].selected==true)
                {
                    val_=ctrl.elements[i].options[aaa].value;
                    val_=val_.replace("&","%26");
                    str=str+sep+ctrl.elements[i].name+"[]="+val_
                    sep="&";
                }
            }
        }
        else
        {
            val=ctrl.elements[i].value;
            val=val.replace(/\n/g,"<br>");
        }
        if(val!="")
        {
            str=str+sep+ctrl.elements[i].name+"="+val.replace("&","%26");
            sep="&";
        }
    }
    return str;
}
////////////////////////////////////////////////
function js_xml_form_submit(php_file,dat)
{
    strURL = url+php_file+"?"+dat;
    //alert(strURL);
    load_db_innerHTML_data();
}
/////////////////////////////////////
function loadInnerHtml(tag,val)
{
    aa1=document.getElementsByTagName('*');
    if(tag=="ChatLSMsgId")
    {
        ChatLSMsgId=val;
        return;
    }
    else if(tag=="js_chat_msg_list")
    {
        if(val!="")
        {
            ////window.location="#btm";
            parent.window.focus();
        }
        val=aa1[tag].innerHTML+val;
    }
    else if(tag=="js_load_private_chat_window")
    {
       eval(val);
       return;
    }
    else if(tag=="js_prev_msg")
    {
       js_prev_msg=1;
       //alert(js_prev_msg);
       return;
    }
    //alert(tag+"=>"+val);
    
    aa1[tag].innerHTML=val;
}
///functions to load values in dropdown without refreshing page
function load_db_innerHTML_data()
{
    //js_ls();
    strURL=strURL.replace("#","-");
    //alert(strURL);
    if (window.ActiveXObject)
    {
        /*Oxml = new ActiveXObject("Microsoft.XMLDOM");
        Oxml.async = true;
        Oxml.load(strURL);*/
        Oxml = new ActiveXObject("Microsoft.XMLDOM") 
        Oxml.async="false"
        Oxml.load(strURL);
        //Oxml.onreadystatechange = On_XmlRet_innerHTML;
        On_XmlRet_innerHTML();
        
        /*
          //code to avoid js error
             Oxml = new ActiveXObject("Microsoft.XMLDOM") 
            Oxml.async="false"
            Oxml.load(strURL);
            //Oxml.onreadystatechange = On_XmlRet_innerHTML;
            On_XmlRet_innerHTML();
        */
    }
  // code for Mozilla, etc.
    else if (document.implementation && document.implementation.createDocument)
    {
        //Oxml= document.implementation.createDocument("","ROOT",null);
        //Oxml = document.implementation.createDocument("","", null)
        if (window.XMLHttpRequest)
        {
            OxmlM= new XMLHttpRequest();
        }
        OxmlM.onreadystatechange = On_XmlRet_innerHTML_mozilla;
        OxmlM.open("GET", strURL, true);
        OxmlM.send(null);
        
       // Oxml.async=false;
        /*Oxml.load("b.xml");
        Oxml.load(strURL);
        Oxml.onload=On_XmlRet_innerHTML;
       On_XmlRet_innerHTML;*/
    }
  else
    {
    alert('Your browser cannot handle this script');
    }
    
}
////////////////////////////////
function On_XmlRet_innerHTML_ie()
{
    
    if(Oxml.readyState==4)
    {
        Oxml = document.implementation.createDocument("","", null)
        //Oxml.async=false;
        //Oxml.load("a.xml");
        Oxml.load("a.xml");
        Oxml.onload=On_XmlRet_innerHTML;
        On_XmlRet_innerHTML;
    }
}
////////////////////////////////
function On_XmlRet_innerHTML_mozilla()
{
    if(OxmlM.readyState==4)
    {
        Oxml = document.implementation.createDocument("","", null)
        //Oxml.async=false;
        Oxml.load("/a.xml");
        Oxml.onload=On_XmlRet_innerHTML;
        On_XmlRet_innerHTML;
    }
}
////////////////////////////////
function On_XmlRet_innerHTML()
{
    var rootnode;
    var intNodecnt;
    var intNodeLen;
    var ONodeAttr;
    var strTemp1,strTemp2;
    var obj;
    rootnode = Oxml.documentElement;
    intNodecnt = Oxml.getElementsByTagName("tag");
    intNodeLen = intNodecnt.length;
    for(var i = 0;i<intNodeLen;i++)
    {
        //code for IE
        if (window.ActiveXObject)
        {
            ONodeAttr = rootnode.childNodes(i).attributes;
            //oOption_sel = document.createElement("tag"); // Create the OPTION element
            strTemp1 = rootnode.childNodes(i).text;
            strTemp2 = ONodeAttr.getNamedItem("id").value;
           // strTemp2=strTemp2.replace(/_/g," ");
           // strTemp1=strTemp1.replace(/_/g," ");
            //strTemp2=strTemp2.replace(/&gt;/g,">");
            //strTemp1=strTemp1.replace(/&lt;/g,"<");
            //loadInnerHtml(strTemp2.replace(/~/g,"_"),strTemp1.replace(/~/g,"_"));
            loadInnerHtml(strTemp2,strTemp1);
        }
        else if (document.implementation && document.implementation.createDocument)
        {//code for MOZILLA
           //todo implement code to mozilla later
            strTemp1="";
            strTemp2="";
            obj=Oxml.getElementsByTagName("tag")[i].childNodes;
            for(var j=0;j<obj.length;j++)
            {
                strTemp1=strTemp1 + obj[j].nodeValue;
            }
            //strTemp1 = Oxml.getElementsByTagName("tag")[i].childNodes[0].nodeValue;
            strTemp2 = Oxml.getElementsByTagName("tag")[i].attributes[0].value;
            loadInnerHtml(strTemp2,strTemp1);

        }
    }
    //js_lh();
}
///////////////////////////////////
function getkey(e)
{
if (window.event)
return window.event.keyCode;
else if (e)
return e.which;
else
return null;
}
/////////////////////////////////////
function limitchar(e)
{
var goods="0123456789";
var key, keychar;
key = getkey(e);
if (key == null) return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();
if (goods.indexOf(keychar) != -1)
return true;
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
return true;
return false;
}
///////////////////////////////////////////////
function js_ls()
{
    document.getElementById('DivLoading').style.display = ''; //show
}
///////////////////////////////////////////////
function js_lh()
{
   
    document.getElementById('DivLoading').style.display = 'none'; //hide
    
}