var global_check=false;
$(function() {
                $('#container-1 > ul').tabs();
            });
$(function() {
                $('#container-2 > ul').tabs();
            });
$(function() {
                $('#container-3 > ul').tabs();
            });

$(function() {
                $('#container-4 > ul').tabs(); 
            });

$(function() {
                $('#container-5 > ul').tabs(); 
            });
$(function() {
                $('#container-6 > ul').tabs(); 
            });


function spm(id) {
	var url="../administration/general.php?spm=spm&id="+id;   
	window.location=url;
}

function userlist(status,page) { 
	
	//alert(page);
	var url="../administration/userlist.php?utype="+status+"&page="+page;
	window.location=url;
}


function confirmsms() {
	
	alert("YOU ARE TRYING TO TRANSMIT MESSAGE TO EVERY USER/RESELLER/SUBADMIN UNDER ALL TIER!");
}

function timedRefresh(timeoutPeriod) {
	setTimeout("location.reload(true);",timeoutPeriod);
}

function listuser(lmt)
{
		if(lmt=="0")
		{
			var url="../settings/transactions.php?page=1";
		}
		else
		{
			var url="../settings/transactions.php?page=1&list=yes&uid="+lmt;
		}
		window.location=url;
}

function setlimit(lmt,id,yes,value,condition,choice,page)
{
		//alert(lmt);
		//if(yes=="all")
		if((id!='' || id!='0') && (value!='' || value!='0'))
		{
			var url="../contacts/manage_contact.php?limit="+lmt+"&page="+page+"&value="+value+"&choice="+choice+"&condition="+condition+"&group="+id+"&Filter=1";
		}
		else
		{
		var url="../contacts/manage_contact.php?limit="+lmt+"&page="+page+"&Filter=2";
		}
		window.location=url;
}

function setlimit1(lmt,id,yes)
{
		
			var url="../logs/dlrstat.php?limit="+lmt+"&stime="+id+"&page=1";
		
		window.location=url;
}
function pagelimit(limit,time,page,id)
{
		
			var url="../logs/message_status.php?action=disp&limit="+limit+"&stime="+time+"&page="+page+"&userid="+id;
			
		
		
		window.location=url;
}

 

// Hide div using check box ////
 function EnableDisableDIV() {
              if ($("#schedule").attr("checked")) {
                  $("#datetime").show();
              } else {
              $("#datetime").hide();
              }             
          }         
function populate(number,iswhat)
{
if(document.getElementById(iswhat).value=="")
document.getElementById(iswhat).value=number;
else
document.getElementById(iswhat).value+=";"+number;
}
function addnumbers(whatdo)
{
var url="addnos.php?page=1&limit=10&what="+whatdo;
var width=580;
var height=560;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var params="menubar=0,toolbar=0,location=0,resizable=0,scrollbars=0,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top+ ",width=580,height=560";
mynewwindow=window.open(url,"myaddwindow",params);
}
function addtemp(whatdo)
{
	
var url="addtemp.php?what="+whatdo; 
var width=400;
var height=450;
var left = parseInt((screen.availWidth/2) - (width/2));
var top = parseInt((screen.availHeight/2) - (height/2));
var params="menubar=0,toolbar=0,location=0,resizable=0,scrollbars=0,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top+ ",width=400,height=450";

mynewwindow2=window.open(url,"myaddwindow2",params);
}
function ccheck(what)
{
var a=document.getElementById(what).value;
/*var m = '\n'; // needle
var c = 0;
for (var i=0;i<a.length;i++) {
if (m == a.substr(i,m.length))
c++;
} 
if(c!=0)
{
	c=c*2;
	c=c-1;
}*/
if(what=="txtmessage")
	{
			//alert(what);
	var total_length=a.length;
	
	var temp = new Array();
	temp = a.split(' ');
	var spaces=temp.length;
	spaces=spaces-1;
	var characters=total_length-spaces;

	//alert(total_length);
	//alert(spaces);
	//alert(characters);

	var unicode_char_len=characters*3;
	//alert (unicode_char_len);
	var unicode_spaces_len=spaces*1;
	var unicode_length=unicode_char_len+unicode_spaces_len;
	//alert(unicode_length);
	document.getElementById("chcount").value=unicode_length;
	var sms=(unicode_length/160);
	var tmp=Math.ceil(sms);
	document.getElementById("smscount").value=tmp;
}
else
{
	document.getElementById("chcount").value=a.length;
	var sms=(a.length/160);
	var tmp=Math.ceil(sms);
	document.getElementById("smscount").value=tmp;
}


}
 
 
function cchecktempmessage(what)
{
var a=document.getElementById(what).value;
document.getElementById("chcount").value=a.length;
var sms=(a.length/160);
var tmp=Math.ceil(sms);
document.getElementById("smscount").value=tmp;
}

function selectAllList() { 
var aSelect = document.form2["select[]"]; 
var aSelectLen = aSelect.length; 
for(i = 0; i < aSelectLen; i++) { 
aSelect.options[i].selected = true; 
} 
} 

function deleteme(link1,what1,what2,mssg,limit,filter,groupid,condition,value,choice,page)
{
	
	var dol1=link1;
	var filter=filter;
	if(!what1)
	var what1=0;
	var myalert=confirm(mssg,2,2);
	if(myalert)
	{
		if(filter==2)
		{
			var url="../contacts/manage_contact.php?link="+dol1+"&delete1="+what1+"&Filter=2&limit="+limit+"&groupid="+groupid+"&condition="+condition+"&value="+value+"&choice="+choice+"&page="+page;
		}
		else
		{
			var url="../contacts/manage_contact.php?link="+dol1+"&delete1="+what1+"&group="+what2+"&Filter=1&limit="+limit+"&page="+page;
		}
	window.location=url;
	}
}


function cdma(link1,what1,mssg) 
{
	var dol1=link1;
	if(!what1)
	var what1=0;
	var myalert=confirm(mssg,2,2);
	if(myalert)
	{
	var url="../administration/websettings.php?link="+dol1+"&delete1="+what1;
	window.location=url;
	}
}

function delcontacts(id,group,limit,page,con,choice,value)
{	
	var msg="You are about to delete the selected contacts permanently!";
	var myalert=confirm(msg);
	
	if(myalert)
	{
	var chkbox="";
	var formname="delcontacts";
	var count=document.myForm.ids.length;
	for (var i=0; i<count; i++)
	{
	if (document.myForm.ids[i].checked==true)
	{
		chkbox=chkbox+document.myForm.ids[i].value+",";
	}
	}
	var url ="../contacts/manage_contact.php?link="+formname+"&ids="+chkbox+"&group="+group+"&limit="+limit+"&page="+page+"&condition="+con+"&choice="+choice+"&value"+value+"&Filter=Filter";
	//alert(url);
	window.location=url;
	}

}

function deletecontact(id,gid,gname)
{

	var url="../messaging/managecontacts.php?link=deletecontact&ConId="+id+"&set=a&gid="+gid+"&gname="+gname;
	var myalert=confirm("You are about to delete the contact!");
	if(myalert)
	{
	window.location=url;
	}
}



function dolinkcontacts(groupid,start,end,s1,s2,s3,s4,s5)
{
	if(!myparams)
	var myparams=0;
	var url="../contacts/manage_contact.php?group="+groupid+"&start="+start+"&end="+end+"&value="+s1+"&filter="+s2+"&choice="+s3+"&condition="+s4+"&limit="+s5;
	window.location=url;
}

function jqCheckAll(id,name,flag)
{
	
   if (flag == 0)
   {
      $("form#" + id + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', false);
   }
   else
   {
      $("form#" + id + " INPUT[@name=" + name + "][type='checkbox']").attr('checked', true);
   }
}


function deletegroup(gid)
{
	var url="../contacts/managegroup.php?action=delete&gid="+gid;
	var myalert=confirm("You are about to delete the Group!");
	if(myalert) 
	{
		window.location=url;
	}
}

$(document).ready(function() {
     $('#cancel').click(function(){
         $('#egroup').hide('slow');
     });
 });


function copytogrp(id,group,limit,page,thick)
{
	var chkbox="";
	var dol="copytogrp";
	var groupid=document.myForm.groupid;
	for (var i=0; i<document.myForm.ids.length; i++)
	{
		
	if (document.myForm.ids[i].checked==true)
	{
		
		tmp=document.myForm.ids[i].value;
		var temparray = new Array();
		temparray=tmp.split("*");
		chkbox=chkbox+temparray[0]+"*";
		
	}
	}
	//var url="../contacts/manage_contact.php?action=contact&chkbox="+chkbox+"&Filter=2&page="+page+"&group="+group+"&limit="+limit;
	var url="../contacts/copy_contact.php?chkbox="+chkbox+"&Filter=1&page=1&group="+group+"&limit="+limit+"&"+thick;
	window.location=url;

}

function pagechange(p)   
{
	var url="websettings.php?p="+p;
	location.href=(url);
}

function editprofile(id)
{
	 	
	var url="../settings/profile.php?action=editprofile&userid="+id;
	window.location=url;
}

function resetpassword(id)
{
	 	
	var url="../settings/profile.php?action=resetpassword&userid="+id; 
	window.location=url;  
}

function uselect(userid)
{
	if(userid!=1)
	{
		document.getElementById('adrounting').style.display="none";
		document.getElementById('norouting').style.display="none";
		document.getElementById('segroute').style.display="none";
	document.getElementById('deroute').style.display="none";
	document.getElementById('noroute').style.display="none";
	}
	else
	{
		document.getElementById('adrounting').style.display="inline";
		document.getElementById('norouting').style.display="inline";
		
		document.getElementById('segroute').style.display="none";
	document.getElementById('deroute').style.display="none";
	document.getElementById('noroute').style.display="none";
	}
}

function email1()
{
	document.getElementById('segroute1').style.display="inline";
	document.getElementById('deroute1').style.display="none";
	document.getElementById('noroute1').style.display="none";
	
}

function emailsms1()
{
	document.getElementById('deroute1').style.display="inline";
	document.getElementById('segroute1').style.display="none";
	document.getElementById('noroute1').style.display="none";
}
function sms1()
{
	document.getElementById('noroute1').style.display="inline"; 
	document.getElementById('segroute1').style.display="none";
	document.getElementById('deroute1').style.display="none";
	
}

function segmented()
{
	document.getElementById('segroute').style.display="inline";
	document.getElementById('deroute').style.display="none";
	document.getElementById('noroute').style.display="none";
	document.getElementById('mnroute').style.display="none";
}
function application()
{
	document.getElementById('deroute').style.display="none";
	document.getElementById('segroute').style.display="none";
	document.getElementById('noroute').style.display="none";
	document.getElementById('mnroute').style.display="none";
}
function defaultr()
{
	document.getElementById('deroute').style.display="inline";
	document.getElementById('segroute').style.display="none";
	document.getElementById('noroute').style.display="none";
	document.getElementById('mnroute').style.display="none";
}
function numroute()
{
	document.getElementById('noroute').style.display="inline";
	document.getElementById('deroute').style.display="none";
	document.getElementById('segroute').style.display="none";
	document.getElementById('mnroute').style.display="none";
}
function manroute()
{
	document.getElementById('mnroute').style.display="inline";
	document.getElementById('noroute').style.display="none";
	document.getElementById('deroute').style.display="none";
	document.getElementById('segroute').style.display="none";
	
}
function introute()
{
	document.getElementById('mnroute').style.display="none";
	document.getElementById('noroute').style.display="none";
	document.getElementById('deroute').style.display="inline";
	document.getElementById('segroute').style.display="none";
}

function googlead()
{
	document.getElementById('google1').style.display="inline";
	document.getElementById('user1').style.display="none";
}
function userad()
{
	document.getElementById('user1').style.display="inline"; 
	document.getElementById('google1').style.display="none";
	
}

function copytogrp(id,field)
{
	var chkbox="";
	for (var i=0; i<document.form8.reg.length; i++)
	{
		
	if (document.myForm.ids[i].checked==true)
	{
		
		tmp=document.myForm.ids[i].value;
		var temparray = new Array();
		temparray=tmp.split("*");
		chkbox=chkbox+temparray[0]+"*";
		
	}
	}
	//var url="../contacts/manage_contact.php?action=contact&chkbox="+chkbox+"&Filter=2&page="+page+"&group="+group+"&limit="+limit;
	var url="../contacts/copy_contact.php?chkbox="+chkbox+"&Filter=1&page=1&group="+group+"&limit="+limit+"&"+thick;
	window.location=url;

}

function copytogrp1()
{
	
	var chkbox="";
	var chkbox1="";
		
	for (var i=0; i<document.form8.ids.length; i++)
	{
		
	if (document.form8.ids[i].checked==true)
	{
		tmp=document.form8.ids[i].value;
		var temparray = new Array();
		temparray=tmp.split("*");
		chkbox=chkbox+temparray[0]+"*";
		//alert("yes"+chkbox);
	}
		
	else
	{
		tmp1=document.form8.ids[i].value;
		var temparray1 = new Array();
		temparray1=tmp1.split("*");
		chkbox1=chkbox1+temparray1[0]+"*";
		//alert("non"+chkbox);
	}
	}
	var url="../administration/websettings.php?chkbox="+chkbox+"&chkbox1="+chkbox1+"&action=field";
	window.location=url;

}

function usertype(btype)
{
	var url="../administration/websettings.php?btype="+btype+"#fragment-2";
	window.location=url;
}

function multiling(m)
{
	//alert(m);
	if(m=='1')
	{
		document.getElementById('nonmulti').style.display="none";
		document.getElementById('vcard').style.display="none";
		document.getElementById('translControl55').style.display="inline";
		document.getElementById('multilin').style.display="inline";
		document.getElementById('schd').style.display="inline";
		document.getElementById('schdchk').style.display="inline";
		document.getElementById('schdtitle').style.display="inline";
		document.getElementById('msgcount').style.display="inline";		
		document.getElementById('template').style.display="inline";
		
	}
	else if(m=='4')
	{
		document.getElementById('translControl55').style.display="none";
		document.getElementById('multilin').style.display="none";
		document.getElementById('nonmulti').style.display="none";
		document.getElementById('vcard').style.display="inline";
		document.getElementById('schd').style.display="none";
		document.getElementById('schdchk').style.display="none";
		document.getElementById('schdtitle').style.display="none";
		document.getElementById('msgcount').style.display="none";
		document.getElementById('template').style.display="none";
	}
	else
	{
		document.getElementById('translControl55').style.display="none";
		document.getElementById('multilin').style.display="none";
		document.getElementById('vcard').style.display="none";	
		document.getElementById('nonmulti').style.display="inline";
		document.getElementById('schd').style.display="inline";
		document.getElementById('schdchk').style.display="inline";
		document.getElementById('schdtitle').style.display="inline";
		document.getElementById('msgcount').style.display="inline";
		document.getElementById('template').style.display="inline";
		
	}
}

function listcountry()
{
	document.getElementById('listcon').style.display="inline";
}

function listnormal()
{
	document.getElementById('listcon').style.display="none"	;
}

function paymode(id)
{
	if(id==0)
	{
		document.getElementById('paytitle').style.display="none";
		document.getElementById('paymode').style.display="none";
	}
	
	if(id==1)
	{
		document.getElementById('paytitle').style.display="inline";
		document.getElementById('paymode').style.display="inline";
	}
}

function trim(s)
	{
		//alert(s);
	var l=0; var r=s.length -1;
	while(l < s.length && s[l] == ' ')
	{	l++; }
	while(r > l && s[r] == ' ')
	{	r-=1;	}
	return s.substring(l, r+1);
	}

function credittype(id)
{
	var myString = id;

	var mySplitResult = myString.split("-");
	
	var int=mySplitResult[7];	////Credit Type
	//alert(int);
	var int1=trim(int);	////////For Trimming	
	
	var amnt=mySplitResult[8];	//International Credit Amount	
	var amnt1=trim(amnt);
	//alert(amnt);
	
	if(int1=="International")
	{	//alert(int1);		
		document.getElementById('intfield').style.display="inline";
		document.getElementById('intfield').innerHTML=amnt1+" USD";
		document.getElementById('normfield').style.display="none";
	}
	if(int1=="Normal")
	{
		//alert(int1);
		document.getElementById('intfield').style.display="none";
		document.getElementById('normfield').style.display="inline";
	}
	

}

function calculat(id)
{
	if(id==2)
	{
		var credit=document.form2.addcredits.value;
		//alert(credit);
		var country=document.form2.country.value;
		//alert(country);
		
		var credval=country.split("-");
		var cid=credval[0];
		var val=credval[1];
		//alert(val);
		
		var credperval=credit*val;
		
		document.getElementById('amttext').style.display="inline";
		document.getElementById('amtfield').style.display="inline";
		document.getElementById('amtfield').innerHTML="<input name='amount' type='text' value='"+credperval+"' readonly='readonly' /> USD";
	}
	if(id==1)
	{
			
		document.getElementById('amttext').style.display="none";
		document.getElementById('amtfield').style.display="none";
		document.getElementById('amtfield').innerHTML="";
	}
}

function normalpay(id)
{
	if(id==2)
	{
		document.getElementById('amttext').style.display="inline";
		document.getElementById('amtfield').style.display="inline";
		document.getElementById('normtext').style.display="inline";
		document.getElementById('normfield').style.display="inline";
	}
	if(id==1)
	{
		document.getElementById('amttext').style.display="none";
		document.getElementById('amtfield').style.display="none";
		document.getElementById('normtext').style.display="none";
		document.getElementById('normfield').style.display="none";
	}
}

function deletekey(type,id)
{
	if(type=="longcode")
	{
		var url="../codes/managelongcodekey.php?action=delete&id="+id;
		var myalert=confirm("You are about to delete the Keyword!");
		if(myalert)
			window.location=url;
	}
	else if(type=="longcodesubkey")
	{
		var url="../codes/managesublongcodekey.php?action=delete&id="+id;
		var myalert=confirm("You are about to delete the SubKeyword!");
		if(myalert)
			window.location=url;
	}
}
function changekeyword(value)
{
	//alert(value);
	var paramstring="type=longcodekeyword&value="+value;
	$.ajax({url:'../ajax.php',data:paramstring,type:'POST',success:function(data){$("#keychange").html(data)}});
}

function spamcheck(what,spamstr)
{
	var a=document.getElementById(what).value;
	a = a.toUpperCase();
	var temp = new Array();
	temp = spamstr.split(':');
	document.getElementById("spamkey").innerHTML="";
	var index=0;
	while(index<temp.length)
	{
		if(a.search(temp[index]) > -1)
		{
			document.getElementById("spamkey").innerHTML="Remove the spam keyword "+temp[index]+" from your content";
			return false;
		}
		index++;	
	}

	return true;

}

function validateUsername(user){
	var paramstring="user="+user;
	var strDomain='';
	window.document.getElementById('response_span').innerHTML="Checking Availability...";
	$.ajax({url:'../useravailability.php',data:paramstring,type:'POST',success:function(data){if(data=='1'){document.getElementById('response_span').style.color='green';window.document.getElementById('response_span').innerHTML="Username Available.";global_check=true;}else{document.getElementById('response_span').style.color='red';window.document.getElementById('response_span').innerHTML="Username Already Exist.";}}});
}
function global_check1()
{
return global_check;
}
function addsimiley(value1)
{
	var what='message';
	var obj=document.getElementById(what)
	obj.value+=value1;
	var len=value1.length;
	var a=document.getElementById(what).value;
	document.getElementById("chcount").value=a.length;
	var sms=((a.length)/160);
	var tmp=Math.ceil(sms);
	document.getElementById("smscount").value=tmp;
}
