var smsdebug=false;
var xmlDoc=0;
var smsxml="mobile_sms.xml";
lists=new Array("from","timestamp","");
smsstatus=new Array("font-weight:bold","");
var xindexary=new Array();
var smsary=new Array();
var smsaryitems=new Array("value","index","from","timestamp","status","ts");
var smsaryitemsc=smsaryitems.length;
var smsnum=0;
var from_phone = [];
var sary=new Array()
var smsarys2=new Array()
smserrmsgary=new Array(
GetElmCont("smsinbox_13","Send Failed!")
,GetElmCont("smsinbox_11","Modem isn't Ready!")+" "+GetElmCont("smsinbox_16","Please check the SIM card inserted or not.")
,GetElmCont("smsinbox_17","SIM card is locked! Cannot read SMS from SIM card.")
,GetElmCont("smsinbox_19","Modem is busy by Phone call! Please wait...")
,"","","","","",""
,""
,GetElmCont("smsinbox_12","Send OK!")
,GetElmCont("smsinbox_13","Send Failed!")
,GetElmCont("smsinbox_11","Modem isn't Ready!")+" "+GetElmCont("smsinbox_16","Please check the SIM card inserted or not.")
,GetElmCont("smsinbox_18","AT Command Failed!")
,GetElmCont("smsinbox_20","Modem is busy by phone call!SMS will be sent automatically later.")
,"","","",""
,""
,GetElmCont("smsinbox_14","Delete OK!")
,GetElmCont("smsinbox_15","Delete failed!")
,GetElmCont("smsinbox_11","Modem isn't Ready!")+" "+GetElmCont("smsinbox_16","Please check the SIM card inserted or not.")
,GetElmCont("smsinbox_18","AT Command Failed!")
,GetElmCont("smsinbox_21","Modem is busy by phone call!SMS will be deleted automatically later.")
)
idoffsets=1;
function loadXMLDocs2(dname)
{
var t=new Date();
if(dname.indexOf("?")!=-1)dname+="&ZT="+t.getTime()
else dname+="?ZT="+t.getTime()
return loadXMLDocs(dname)
}
function readsmsinfo(xd)
{
if(xd.getElementsByTagName("smslist")==null)return
xsmsinfo_received=xd.getElementsByTagName("smslist")[0].getAttribute("received")
xsmsinfo_new=xd.getElementsByTagName("smslist")[0].getAttribute("new")
xsmsinfo_total=xd.getElementsByTagName("smslist")[0].getAttribute("total")
ddiv=document.getElementById("smssta_received")
if(ddiv!=null) ddiv.innerHTML=xsmsinfo_received
ddiv=document.getElementById("smssta_new")
if(ddiv!=null) ddiv.innerHTML=xsmsinfo_new
ddiv=document.getElementById("smssta_total")
if(ddiv!=null) ddiv.innerHTML=xsmsinfo_total
}
function createsmslist(xmlurl,xd)
{
if(arguments.length==1)xmlDoc=loadXMLDocs2(xmlurl);
else xmlDoc=xd;
if(xmlDoc.getElementsByTagName("sms").length<=0)return
xsmsx=xmlDoc.getElementsByTagName("sms");
for(x0=0;x0<xsmsx.length;x0++)
{
if(xsmsx[x0].getAttribute("timestamp")=="")continue;
for(x1=0;x1<smsaryitems.length;x1++)
{
smss=smsaryitems[x1]
if(smss=="value") smsary[smsary.length]=xsmsx[x0].childNodes[0].nodeValue
else if(smss=="ts")
{
ts=xsmsx[x0].getAttribute("timestamp")
smsary[smsary.length]=parseInt(Date.parse(ts))
sary[sary.length]=parseInt(Date.parse(ts))
}
else smsary[smsary.length]=xsmsx[x0].getAttribute(smsaryitems[x1])
}
}
return smsary;
}
function sortMsg(tp,ary0,ary1)
{
ary1.sort()
if(tp==1)ary1.reverse()
items=smsaryitems.length
for(s0=0;s0<ary1.length;s0++)
{
ss=findstrInArr(ary1[s0],ary0)-items+1
for(s1=0;s1<items;s1++)
{
smsarys2[smsarys2.length]=ary0[ss+s1]
}
}
return smsarys2
}
function findstrInArr(findstr,arr)
{
for (xxx in arr)
{
if(arr[xxx]==findstr)return xxx
}
return 0
}
function getsmsprofile2(ary,smsno,smsattr)
{
ix=(arguments.length==1)?0:findstrInArr(smsattr,smsaryitems)
ixs=parseInt(smsno*smsaryitemsc)+parseInt(ix)
return ary[ixs]
}
function delsms()
{
var t=new Date();
var checkbox = document.getElementsByName("sms_del");
var del_str = "";
var delay_time = 2000;
strs = "&Sdelsms=";
if(arguments.length==0)
{
for(var a=0;a<checkbox.length;a++)
{
if(checkbox[a].checked)
{
del_str += (del_str == "")?checkbox[a].value:","+checkbox[a].value;
delay_time += 1000;
}
}
document.getElementById('hidefm').src = "mobile_sms2.htm?Ncmd=3"+strs+del_str+"&Nindex="+Nindex+"&csrftok="+get_csrf_token();
}
document.getElementById("_asmsinbox_0").disabled = true;
setTimeout("sms_read()",delay_time);
swids("t_detail_sms",false);
}
function showlist2(tp2,prexmlDoc)
{
var div = document.getElementById("d_sms_inbox");
var strs = "";
var button = "";
sary = [];
smsary = [];
smsarys2 = [];
var xsmsinfo_received = prexmlDoc.getElementsByTagName("smslist")[0].getAttribute("received");
sms_num = parseInt(xsmsinfo_received);
smsarys=sortMsg(tp2,createsmslist(1,prexmlDoc),sary);
/*smsnum=smsarys.length/smsaryitemsc;
if(smsnum<=0)return*/
strs += "<table width=100% border=0 align=center cellpadding=0 cellspacing=0 class='staball'>";
strs += "<tr>";
strs += "<th width='5%'><span id='_0'>ID</span></th>";
strs += "<th width='15%'><span id='_0'>From Phone Number</span></th>";
strs += "<th width='20%'><span id='_0'>Timestamp</span></th>";
strs += "<th width='15%'><span id='_0'>SMS Text Preview</span></th>";
strs += "<th width='45%'><span id='_0'>Actions</span></th>";
strs += "</tr>";
for(s=0;s<sms_num;s++)
{
xindex=getsmsprofile2(smsarys,s,"index")
xindexary[s]=xindex;
xsmsstatus=getsmsprofile2(smsarys,s,"status")
strs+="<tr id='ss"+s+"0'>"
strs+="<td align=center>"+(s+1)+"</td>";
for(l=0;l<lists.length;l++)
{
if(l == 0){from_phone[s] = getsmsprofile2(smsarys,s,lists[l]);}
xtds=(lists[l]=="")?getsmsprofile2(smsarys,s):getsmsprofile2(smsarys,s,lists[l])
strs+="<td style="+smsstatus[xsmsstatus]+" id='ss"+s+(l+1)+"'>"+xtds+"</td>";
}
button = "<td>";
button += "<input type='button' value='Detail' onclick='show_detail("+xindex+",\"t_detail\")'>";
button += "<input type='checkbox' name='sms_del' value="+xindex+">";
button += "<input type='button' value='Reply' onclick='sms_replay("+s+")'>";
button += "<input type='button' value='Forward' onclick='show_detail("+xindex+",\"t_sms_text\")'>";
button += "</td>";
strs += button;
strs += "</tr>";
}
strs += "</table>";
if(div != null)
{
div.innerHTML = strs;
}
}
function chkExist(arr,findstr)
{
for (x in arr)
{
if(arr[x]==findstr)return true
}
return false
}
function add2ary(ary,itm)
{
if(!chkExist(ary,itm))
{
pushed = ary.push(itm);
}
ary.sort()
return ary
}
function removeFromary(ary,itm)
{
for (x in ary)
{
if(ary[x]==itm)removed = ary.splice(x, 1)
}
return ary
}
function getsmsxml(func2,qf)
{
var tt=new Date();
urlss="mobile_sms.xml?Ncmd="+func2+"&Nqueryflag="+qf+"&Nindex="+Nindex;
if(arguments.length==3)urlss+=arguments[2]
return loadXMLDocs(urlss+"&ZT="+tt.getTime())
}
function showerrmsg(xdmsg,msgary,sid)
{
if(xdmsg!=null)
{
ddiv=document.getElementById(sid)
if(ddiv) ddiv.innerHTML=msgary[xdmsg]
swid(sid,true)
}
}
function sms_replay(index)
{
document.getElementById("t_new_sms").style.display = "";
document.getElementById("t_sms_tophone").value = from_phone[index];
document.getElementById("t_sms_text").value = "";
}
function show_sms_list()
{
xmlDocs2=null;
var t=new Date()
xmlDoc=getsmsxml(0,1)
timer=setTimeout("show_sms_list()",3000);
if(xmlDoc==null)return;
if(xmlDoc.getElementsByTagName("smsstatus")==null)return;
xsms=xmlDoc.getElementsByTagName("smsstatus")[0].childNodes[0].nodeValue;
errmsgs=xmlDoc.getElementsByTagName("errmsg")[0].childNodes[0].nodeValue;
readsmsinfo(xmlDoc);
if(xsms==null)return;
if(xsms==1)
{
document.getElementById("_asmsinbox_0").disabled = false;
showlist2(document.forms[0].Nsort.value,xmlDoc);
clearTimeout(timer);
}
}
function sms_read()
{
document.getElementById('hidefm').src = '/mobile_sms2.htm?Ncmd=0&Nindex='+Nindex+"&csrftok="+get_csrf_token();
setTimeout("show_sms_list()",3000);
}
function show_detail(index,id)
{
var urlss="mobile_sms.xml?Ncmd=1&Nmsgindex="+index+"&Nqueryflag=0&Nindex="+Nindex;
var xmlDoc = null;
var xmlDoc = loadXMLDocs(urlss)
var table = (id == "t_detail")?"t_detail_sms":"t_new_sms";
var div = document.getElementById("d_sms_text");
var div_content = "";
var sms_object;
document.getElementById("t_sms_tophone").value = "";
if(xmlDoc==null)return;
if(xmlDoc.getElementsByTagName("detail")==null)return;
detial = xmlDoc.getElementsByTagName("detail")[0].childNodes[0].nodeValue;
if(detial==null)return;
if(xsms==1)
{
if(id != "t_detail")
{
div.innerHTML = "";
div_content = "<textarea cols=\"60\" rows=\"8\" id=\"t_sms_text\" onkeyup=\"chkS(this,'t')\" style=\"margin-left:5px\">";
div_content += detial;
div_content += "</textarea>";
div.innerHTML = div_content;
sms_object = document.getElementById("t_sms_text");
chkS(sms_object,'t');
}
else
{
document.getElementById(id).innerHTML = replacelink(detial);
}
}
swids(table,true)
}
function replacelink(t)
{//����²�T���e �Ϻ��}���W�s�� ex www.yahoo.com.tw
var regexp = /((http\:\/\/|https\:\/\/|ftp\:\/\/|www\.*?)(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?)/gi;
var tmp = "";
tmp = t.replace(regexp, function(word){
wods=""
if(word.substring(0,3)=="www"){
wods+='<a href="http://'+word+'" target=_blank>'+word+'</a>'
}
else wods+='<a href="'+word+'" target=_blank>'+word+'</a>'
return wods;
})
return tmp;
}
function sms_send()
{
var current_count = document.getElementById("t_sms_text").value.length;
if(document.getElementById("t_sms_tophone").value==""){
alert("Receivers cannot be empty.");
return false;
}
else if(current_count>SMS_TEXT_LIMIT_CHAR){
alert("Text Message exceeds max length. Please check Text Message again.");
return false;
}
else{
var phone = document.getElementById('t_sms_tophone').value;
var text = document.getElementById('t_sms_text').value;
var received = sms_phone_csid+"="+encodeURIComponent(phone);
var message = sms_text_csid+"="+encodeURIComponent(text);
var xmlurl="hide.htm?"+received+message+"&Nindex="+Nindex+"&csrftok="+get_csrf_token();
$.ajax({
url:xmlurl,
type:"GET",
dataType:"html",
error:function(){
},
success:function(){
call_sms_server();
}
});
}
}
function call_sms_server(){
var t=new Date()
var xmlurl2 = "mobile_sms2.htm?Ncmd=2&Nindex="+Nindex+"&ZT="+t.getTime();
$.ajax({
url:xmlurl2,
type:"GET",
dataType:"html",
error:function(){
},
success:function(){
setTimeout("chk_send()",3000);
swid('errmsg',false,'waitmsg',true);
}
});
}
function chk_send()
{
xmlDocs2=null;
var t=new Date()
xmlDoc=getsmsxml(2,1)
timer=setTimeout("chk_send()",3000)
if(xmlDoc == null)return;
xsms = xmlDoc.getElementsByTagName("smsstatus")[0].childNodes[0].nodeValue
errmsgs = xmlDoc.getElementsByTagName("errmsg")[0].childNodes[0].nodeValue
if(xsms == null)return;
else if(xsms==2)showerrmsg(errmsgs,smserrmsgary,"errmsg")
else if(xsms==1)
{
showerrmsg(errmsgs,smserrmsgary,"errmsg")
clearTimeout(timer)
}
swid('errmsg',xsms!=0,'waitmsg',xsms==0)
show_sms_folder_list()
}
var mapping_arr = new Array(
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
""
)
var mapping_device_arr = new Array(
"1",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
"0",
""
)
function chg_interface(page)
{
var inter = document.getElementById("s_interface");
GURL(page+".htm?Nindex="+inter.value+"&Nrefresh=1");
}
function sms_send_folder(){
show_sms_folder_list()
}
function show_sms_folder_list(){
var t=new Date()
xmlDoc=getsmsxml(4,1)
timer=setTimeout("show_sms_folder_list()",3000);
if(xmlDoc==null)return;
readsms_folder_info(xmlDoc);//show Sent SMS
document.getElementById("_asmsinbox_1").disabled = false;
showlist2_sent(xmlDoc);
clearTimeout(timer);
}
function readsms_folder_info(xd){
if(xd.getElementsByTagName("sms_sent_folder")==null)return
var xsmsinfo_Sent=xd.getElementsByTagName("sms_sent_folder")[0].getAttribute("sent")
ddiv=document.getElementById("smssta_sent")
if(ddiv!=null) ddiv.innerHTML=xsmsinfo_Sent;
}
function showlist2_sent(prexmlDoc){
var div = document.getElementById("d_sms_sent_folder");
var strs = "";
var button = "";
var xsmsinfo_sent = prexmlDoc.getElementsByTagName("sms_sent_folder")[0].getAttribute("sent");
sms_sent_num = parseInt(xsmsinfo_sent);
strs += "<table width=100% border=0 align=center cellpadding=0 cellspacing=0 class='staball'>";
strs += "<tr>";
strs += "<th width='5%'><span id='_0'>ID</span></th>";
strs += "<th width='15%'><span id='_0'>Receivers</span></th>";
strs += "<th width='20%'><span id='_0'>Timestamp</span></th>";
strs += "<th width='15%'><span id='_0'>SMS Text Preview</span></th>";
strs += "<th width='45%'><span id='_0'>Actions</span></th>";
strs += "</tr>";
for(var s=0;s<sms_sent_num;s++)
{
xsmsphone=xml_getvalue(prexmlDoc,"phone_number",s)
xsmstime_stamp=xml_getvalue(prexmlDoc,"time_stamp",s)
xsmsdetail=xml_getvalue(prexmlDoc,"detail",s)
strs+="<tr id='sent"+s+"'>"
strs+="<td align=center>"+(s+1)+"</td>";
strs+="<td>"+xsmsphone+"</td>";
strs+="<td>"+xsmstime_stamp+"</td>";
strs+="<td>"+xsmsdetail+"</td>";
button = "<td>";
button += "<input type='button' value='Detail' onclick='show_detail_sent("+s+")'>";
button += "<input type='checkbox' name='sms_sent_del' value="+s+">";
button += "</td>";
strs += button;
strs += "</tr>";
}
strs += "</table>";
if(div != null)
{
div.innerHTML = strs;
}
}
function show_detail_sent(index){
swids("sent_detail_sms",true);
var urlss="mobile_sms.xml?Ncmd=5&Nmsgindex="+index+"&Nindex="+Nindex;
var xmlDoc = loadXMLDocs(urlss);
if(xmlDoc==null)return;
if(xmlDoc.getElementsByTagName("detail")==null)return;
var smsDetail = xml_getvalue(xmlDoc,"detail_sent",0);
document.getElementById("sent_detail").innerHTML = replacelink(smsDetail);
}
function delsms_sent()
{
var t=new Date();
var checkbox = document.getElementsByName("sms_sent_del");
var del_str = "";
var delay_time = 2000;
strs = "&SdelsmsSent=";
if(arguments.length==0)
{
for(var a=0;a<checkbox.length;a++)
{
if(checkbox[a].checked)
{
del_str += (del_str == "")?checkbox[a].value:","+checkbox[a].value;
delay_time += 1000;
}
}
document.getElementById('hidefm').src = "mobile_sms2.htm?Ncmd=4"+strs+del_str+"&Nindex="+Nindex+"&csrftok="+get_csrf_token();
}
document.getElementById("_asmsinbox_1").disabled = true;
setTimeout("show_sms_folder_list()",delay_time);
swids("sent_detail_sms",false);
}