var g_reseller_username;
var g_reseller_password;
var g_reseller_groupname;
var g_reseller_level;
var g_reseller_credit;
var g_reseller_expired_time;
var g_reseller_email;
var g_reseller_user_no;
var g_reseller_auto_renew;

function close_modal_Reseller() {
   var modal = document.getElementById('PanelModalReseller');
   modal.style.display = "none";
   call_get_reseller();
}

function open_modal_Reseller()
{
	var modal = document.getElementById('PanelModalReseller');
	modal.style.display = "block";
}
function close_modal_Reseller_Update() {
   var modal = document.getElementById('PanelModalResellerUpdate');
   modal.style.display = "none";
}

function open_modal_Reseller_Update(user_no, resellername)
{
		
	g_token=find_cookie_value("token");
	g_reseller_user_no=user_no;

 	var cgi_url = "/server/get_reseller_profile?token="+encodeURI(g_token)+"&name="+encodeURI(resellername)+
	 "&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = xmlHttp.onreadystatechange = function(){
	 	if (xmlHttp.readyState == 4) 
	 	{
			var i=0;
			var j=0;
			var str;
			var groupname;
			var response = xmlHttp.responseText.split("\r\n");
			var modal = document.getElementById('PanelModalResellerUpdate');
			modal.style.display = "block";
			while (1)
			{
			   	if (response[i]==0) break;
			   	
				g_item=document.getElementById("update_userno");
				g_item.innerText=g_reseller_user_no;
			   	
		
	
				strlength=response[i].length;
				g_reseller_username=response[i].slice(5,strlength);
				i=i+1;	
				g_item=document.getElementById("update_username");
				g_item.innerText=g_reseller_username;
		
				strlength=response[i].length;
				g_reseller_password=response[i].slice(9,strlength);
				i=i+1;	
				g_item=document.getElementById("update_password");
				g_item.value=g_reseller_password;
				
				strlength=response[i].length;
				g_reseller_groupname=response[i].slice(6,strlength);
				i=i+1;	
		
			 	g_item=document.getElementById("update_group");
				g_item.value=g_reseller_groupname;
			
				strlength=response[i].length;
				g_reseller_level=response[i].slice(6,strlength);
				i=i+1;	
	
				g_item=document.getElementById("update_level");
				g_item.value=g_reseller_level;
				
				strlength=response[i].length;
				g_reseller_credit=response[i].slice(7,strlength);
				i=i+1;	
				g_item=document.getElementById("update_total_credit");
				g_item.value=g_reseller_credit
				
				strlength=response[i].length;
				g_reseller_expired_time=response[i].slice(13,strlength);
				i=i+1;	
				g_item=document.getElementById("update_expired_time");
				g_item.value=g_reseller_expired_time;
				
				strlength=response[i].length;
				g_reseller_email=response[i].slice(6,strlength);
				i=i+1;	
			 	g_item=document.getElementById("update_email");
				g_item.value=g_reseller_email;
				
				strlength=response[i].length;
				g_reseller_auto_renew=response[i].slice(11,strlength);
				i=i+1;	
	
				g_item=document.getElementById("update_auto_renew");
				g_item.value=g_reseller_auto_renew;
			}
	
		}
	 };
	 xmlHttp.send(null);

	
}

function call_Add_Reseller(user_no)
{

 var username_id="username"; 
 var password_id="password"; 
 var group_id="group"; 
 var level_id="level"; 
 var total_credit_id="total_credit"; 
 var expired_time_id="expired_time"; 
 var email_id="email"; 
 var auto_renew_id="auto_renew"; 
 var username;
 var szpassword; 
 var group; 
 var level; 
 var total_credit; 
 var expired_time; 
 var email; 
 var auto_renew;

	var add_new_reseller_button=document.getElementById("add_new_reseller_button");
	var add_new_reseller_dialog_message=document.getElementById("add_new_reseller_dialog_message");
	var new_reselleritem =document.getElementById("userno");
	var new_resellernameitem;


var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var pos;
	var expired_time_temp;
 	var pos;
	var expired_time_temp;
	var alert_message;


	g_item=document.getElementById(username_id);
	new_resellernameitem=g_item;
	username=g_item.value;
	if (username.length==0)
	{
		alert("Reseller name is empty");
		return;
	}
	//alert(username);
	g_item=document.getElementById(password_id);
	szpassword=g_item.value;
	if (szpassword.length==0)
	{
		alert("Reseller password is empty");
		return;
	}
	//alert(szpassword);
 	g_item=document.getElementById(group_id);
 	group=g_item.value;
 	//alert(group);
	g_item=document.getElementById(level_id);
	level=g_item.value;
	//alert(level);

	g_item=document.getElementById(total_credit_id);
	total_credit=g_item.value;
	//alert(total_credit);
	if (total_credit.length==0)
	{
		alert("Reseller total credit is empty");
		return;
	}
	g_item=document.getElementById(expired_time_id);
	expired_time=g_item.value;
	//alert(expired_time);
	if (expired_time.length==0)
	{
		alert("Reseller total credit is empty");
		return;
	}
	
	g_item=document.getElementById(email_id);
	email=g_item.value;
	//alert(email);
	
	g_item=document.getElementById(auto_renew_id);
	auto_renew=g_item.value;
	

  	g_token=find_cookie_value("token");

 cgi_url = "/server/add_reseller?token="+encodeURI(g_token)
 	 +"&username="+encodeURI(username)
	 +"&password="+encodeURI(szpassword)
	 +"&group="+encodeURI(group)
	 +"&level="+encodeURI(level)
	 +"&total_credit="+encodeURI(total_credit)
	 +"&expired_time="+encodeURI(expired_time)
	 +"&email="+encodeURI(email)
	 +"&auto_renew="+auto_renew
	 +"&flag="+Math.random();
 //alert(cgi_url);
 //if (confirm(confirm_msg))
 //{
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response==1)
			{
				add_new_reseller_button.value="Add Next";
				var new_add_total_no=parseInt(user_no)+1;;
				add_new_reseller_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+username+' Added</font>';
				//alert(new_add_total_no);
				new_reselleritem.value=new_add_total_no;
				new_resellernameitem.value="";
				new_resellernameitem.focus();
				
			//	alert("Add Reseller Sucessfully");
			} else if (response==0)
			{
				alert("Failed to Add Reseller");
			} else if (response==2)
			{
				alert("Disk is error(FULL), Please contact administrator");
			}else if (response==3)
			{
				alert("The reseller is already in Database");
			}
			//call_get_reseller();
		}
	 };
	 xmlHttp.send(null);
 //}


}
function get_reseller()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var username;
    var szemail;
    var checkedflag;
    var credit;
    var credit_unit;
    var creator;
    var resellertype;
    var user_no;
 //   var szpassword;
    var user_title="<p>"+"Reseller List"+"</p>";
    var user_list;
    var i=0;
    var j=0;
    var user_no=1;
   var reseller_total_user_no=0;
	var total_user_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
   var content = parent.document.getElementById("content");
 
  	var menustr;
  	var menustr1;
  	var reseller_no;

	var content;
	var cellsize="16%";
	
	var ezcontent= document.getElementById("content");
	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	if (bMobileDevice)
	{
		str+='<td width="70%"><font face="Arial" color="#000000" size="4"><b>Reseller</b></font>';
	}else
	{
		str+='<td width="80%"><font face="Arial" color="#000000" size="4"><b>Reseller</b></font>';
	}
	str+='</td>';
	
	str+='<td align="right">';
	str+='<div class="navbar" style="background-color: #F5F6F8">';
		str+='<div class="menudropdown" style="background-color: #56C1D5">' ;
		    str+='<a href="javascript:open_modal_Reseller()">Add Reseller</a>';
		str+='</div>'; 
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button onclick="Button_get_reseller()" class="dropbtn"> '; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 
		
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;
	/*
	var menu_screen= document.getElementById("ezmenu");
	document.getElementById("menu_title_text").innerHTML='<font face="Arial" color=#000000 size="6">Reseller</font>';
	str='<div class="btn-group">';
		str+='<button class="button" onclick="callServer_System_Inquery()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Back</button>'; 
		str+='<button class="button" onclick="open_modal_Reseller()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Add Reseller</button>'; 
	str+='</div>';                              
	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";
	 HTML_str= '<table border="0" style="margin-top: 20px;" width=90% align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"><font face="Arial" size="2">No.</font></td>';
	      	HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Name</font></td>';
	      	HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Email</font></td>';
	      	HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Credit Balance</font></td>';
	      	HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Users</font></td>';
	      	HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Type</font></td>';
	      	HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Creator</font></td>';
	      HTML_str+='</tr>'+'<tr><td  colspan="7"><hr size="1" color="#66FFFF"></td></tr>';
	      	
	
	while (1)
	{
 	 	if (response[i]==0) break;
//		alert(response[i]);
	 	strlength=response[i].length;
   	    	username=response[i].slice(9,strlength);
 		i=i+1;
	
		strlength=response[i].length;
   	    	szemail=response[i].slice(6,strlength);
 		i=i+1;
 		
	 	strlength=response[i].length;
   	    	credit=response[i].slice(7,strlength);
 		i=i+1;
		//alert(credit);
	 	strlength=response[i].length;
   	    	creator=response[i].slice(8,strlength);
 		i=i+1;
	 	//alert(creator);
	 	strlength=response[i].length;
   	    	resellertype=response[i].slice(5,strlength);
   	    	//alert(resellertype);
 		i=i+1;
 	 	strlength=response[i].length;
   	    	reseller_total_user_no=response[i].slice(8,strlength);
   	    	//alert(user_no);
 		i=i+1;
 		
		HTML_str=HTML_str+
		   '<tr>';


 		HTML_str=HTML_str+'<td width="10" align="center"><font face="Arial"> <font size="2">'+user_no+'</font></td>'+
	        '<td width="'+cellsize+'" align="center" id="username'+user_no+'">'+
	       // "<a href='javascript:void(0)'"+' onclick=open_modal_Reseller_Update("'+user_no+'","'+username+'")>'+
 		' <font face="Arial" font size="2">'+
 		username+'</font>';
 		/* HTML_str+='<div id="PanelModalResellerUpdate" class="modal">'+
		'<div class="modal-content">'+
		'<span onclick="javascript:close_modal_Reseller_Update();" class="close">&times;</span>';
		HTML_str+='<table align="center">';
		
		HTML_str+='<tr><td><font face="Arial"><font size="2">No. : </font></td><td id=modal_userno></td></tr>';		
		HTML_str+='<tr><td><font face="Arial" font size="2">Name : </font></td><td id=update_username></td></tr>';
		HTML_str+='<tr><td><font face="Arial" font size="2">Password : </font></td><td>'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="update_password"'+
		 		' id=update_password'+
		 		' size="12"/'+
		 		'</font></td></tr>';
		HTML_str+='<tr><td><font face="Arial" font size="2">Group : </font></td><td>'+
		 	'<font face="Arial" size="2">'+
			'<select size="1" name="update_group" id=update_group>';
		for (j=0;j<g_total_group_no;j++)
		{
			groupname=g_groupname_array[j];
			HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
		}
		HTML_str+='<tr><td><font face="Arial"> <font size="2">Level: </font></td><td width="350" height="23">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" name="update_level" id="update_level">';
		HTML_str+='<option value="2">'+"Super Reseller"+'</option>'+
		'<option selected="selected" value="3">'+"Reseller"+'</option>';
		HTML_str+='</select></font></td></tr>';
		
		HTML_str+='<tr><td><font face="Arial" size="2">Total Credit : </font></td><td>'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="update_total_credit"'+
		 		' id=update_total_credit'+
		 		' size="7"/'+
		 		'</font></td></tr>';
		
		HTML_str+='<tr><td><font face="Arial" size="2">Expired Time : </font></td><td>'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input type="text" name="update_expired_time"'+
		 		' id="update_expired_time"'+
		 		' size="12"/></font></td></tr>';
		 	
		
		HTML_str+='<tr><td><font face="Arial"> <font size="2">Email: </font></td><td width="350" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input type="text" name="update_email"'+
		 		' id="update_email"'+
		 		' size="30"/></font></td></tr>';
		
		HTML_str+='<tr><td><font face="Arial"> <font size="2">Auto Renew: </font></td><td width="1" height="23">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" name="update_auto_renew" id="update_auto_renew">';
		HTML_str+='<option selected="selected" value="0">'+"OFF"+'</option>'+
		'<option value="1">'+"ON"+'</option>';
		HTML_str+='</select></font></td></tr>';
		
		HTML_str+='<td><input type="button" value="Save" onclick=call_Update_Reseller() name="Save" />';
		HTML_str+='&nbsp<input type="button" value="Cancel" onclick=close_modal_Reseller_Update() name="Cancel" />';
		//HTML_str+='&nbsp<input type="button" value="Restore Users" onclick=call_Restore_Reseller_Users() name="Restore Users" />
		*/
		
		//HTML_str+='</td></tr></table>';
		//'</div>'+
		//'</div></td>';
		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" font size="2">'+szemail+'</font></td>';
  		if (credit<0)
 		{
 
	 	      HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		' <input type="text" disabled name="credit"'+
	 		' id=credit'+user_no+' size="3" value="'+
	 		credit+'"/></font></td>';	
		   
		}else
 		{
 		
//			HTML_str+='<td width="'+cellsize+'" align="center">'+' <form><input type="checkbox" checked name="checkedflag'+user_no+'"'+
			//HTML_str+='<td width="10%" align="center">'+' <form><input type="checkbox" checked id="checkedflag'+user_no+'"'+
 			//' onclick="javascript:show_hide_credit_option('+user_no+')"'+'></td>';

	 	      HTML_str+='<td width="'+cellsize+'%" align="center">'+
	 		' <font face="Arial" font size="2">'+credit+'</font></td>';
	 		
;
 		}
 	     	HTML_str+='<td width="10%" align="center">'+
 		' <font face="Arial" font size="2">'+
 		reseller_total_user_no+'</font></td>';
	// alert(HTML_str);
 		if (resellertype==2)
 		{
	 	     	HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		"Super Reseller"+'</font></td>';
 	     	}else if (resellertype==3)
 	     	{
	 	     	HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		"Reseller"+'</font></td>';
 	     	}
 	     	
	      HTML_str+='<td width="'+cellsize+'%" align="center">'+
 		' <font face="Arial" font size="2">'+
 		creator+'</font></td>';
 	 		
	 		
	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=open_modal_Reseller_Update("'+user_no+'","'+username+'")><img src="/admin/edit.png"></img></a></td>';
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Reseller("'+user_no+'")><img src="/admin/del.png"></img></a>'+
	 		'</td>';
		
	      HTML_str+='</tr>';
		total_user_no++;
		user_no++;
		//alert(HTML_str);
    	}
        HTML_str=HTML_str+'</table>';
	reseller_no=total_user_no+1;
	//alert(reseller_no);
	
	
	menustr1='<td width="4%">';
	menustr1+='<div id="PanelModalReseller" class="modal">'+
	'<div class="modal-content">';
	menustr1+='<table align="center" cellpadding="0" cellspacing="10" >';
	menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>New Reseller</b></font></td><td colspan=2 align=right id=add_new_reseller_dialog_message name=add_new_reseller_dialog_message></td></tr>';
	menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
	
	menustr1+='<tr><td width="25%" ><font face="Arial"><font size="2">No.</font></td><td width="25%" height="23">'+
	' <font face="Arial" size="2">'+
	' <input style="padding: 5px;height:30;" type="text" name="userno"'+
	' id="userno"'+
	' size="16" value="'+reseller_no+
	'"/></font></td>';
	menustr1+='<td width="25%" ><font face="Arial" size="2">Total Credit : </font></td><td width="25%" >'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="total_credit"'+
	 		' id=total_credit'+
	 		' size="16"/'+
	 		'</font></td></tr>';
	
	if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	{
		menustr1+='<tr><td width="25%"><font face="Arial" font size="2">Name : </font></td><td width="25%">'+
		 	' <font face="Arial" size="2">'+
		 	' <input style="padding: 5px;height:30;"  type="text" name="username"'+
		 	' id=username'+
		 	' size="16"/'+
		 	'</font></td>';
		menustr1+='<td width="25%"><font face="Arial" font size="2">Password : </font></td><td width="25%">'+
		 		' <font face="Arial" size="2">'+
		 		' <input style="padding: 5px;height:30;"  type="text" name="password"'+
		 		' id=password'+
		 		' size="16"/'+
		 		'</font></td></tr>';
	}else if (g_user_authorization_mode==2)
	{
		menustr1+='<tr><td width="25%"><font face="Arial" font size="2">Password : </font></td><td width="75%"colspan=3>'+
		 		' <font face="Arial" size="2">'+
		 		' <input  style="padding: 5px;height:30;" type="text" name="password"'+
		 		' id=password'+
		 		' size="16"/'+
		 		'</font></td></tr>';			
	}		
	menustr1+='<tr><td width="25%"><font face="Arial" font size="2">Package</font></td><td width="25%">'+
	 	'<font face="Arial" size="2">'+
		'<select style="text-indent: 5;width:152;height:26;" size="1" name="group" id=group>';
	for (j=0;j<g_total_group_no;j++)
	{
		groupname=g_groupname_array[j];
		menustr1+='<option style="padding: 2px" value="'+groupname+'">'+groupname+'</option>';
	}
	menustr1+='</select></font></td>';
	menustr1+='<td><font face="Arial"> <font size="2">Level: </font></td><td width="350" height="23">'+
	' <font face="Arial"> <font size="2">'+
	' <select style="text-indent: 5;width:152;height:26;" size="1" name="level" id="level">';
	menustr1+='<option style="padding: 2px" value="2">'+"Super Reseller"+'</option>'+
	'<option selected="selected" style="padding: 2px" value="3">'+"Reseller"+'</option>';
	menustr1+='</select></font></td></tr>';
	
	
	menustr1+='<tr><td><font face="Arial" size="2">Expired Time : </font></td><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="expired_time"'+
	 		' id="expired_time"'+
	 		' size="16" value="MM/DD/YYYY" oninput="change_expired_time_input_color()"/></font></td>';
	 	
	
	menustr1+='<td><font face="Arial"> <font size="2">Email: </font></td><td width="350" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="email"'+
	 		' id="email"'+
	 		' size="16" value="@gmail.com" oninput="change_email_input_color()"/></font></td></tr>';
	 		
	menustr1+='<tr><td><font face="Arial"> <font size="2">Auto Renew</font></td><td colspan=3 width="1" height="23">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="auto_renew" id="auto_renew">';
	menustr1+='<option selected="selected" value="0">'+"OFF"+'</option>'+
	'<option value="1">'+"ON"+'</option>';
	menustr1+='</select></font></td></tr>';

	menustr1+='<tr>'+
	'<td colspan=2 width=50%><input id=add_new_reseller_button style="background-color:#4285F4; color:#fff; border-radius:6px; font-weight:bold; padding:10px 25px; width:100%;"  type="button" value="Add" onclick=call_Add_Reseller('+user_no+') name="Save" /></td>'+
	'<td colspan=2 width=50%><input style="background-color:#FF5722; color:#fff; border-radius:6px; font-weight:bold; padding:10px 25px; width:100%;"  type="button" value="Cancel" onclick=close_modal_Reseller() name="Cancel" /></td>'+
	'</tr></table>'+
	'</div>'+
	'</div></td>';
	

	menustr1+='<td width="4%">';
	menustr1+='<div id="PanelModalResellerUpdate" class="modal">'+
	'<div class="modal-content">';
	menustr1+='<table align="center" cellpadding="0" cellspacing="10" >';
	menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>Update Reseller</b></font></td><td colspan=2 align=right id=add_new_reseller_dialog_message name=add_new_reseller_dialog_message></td></tr>';
	menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
	
	menustr1+='<tr><td width="25%" ><font face="Arial"><font size="2">No.</font></td><td  id="update_userno" width="25%" height="23">'+
	' <font face="Arial" size="2"></font></td>';
	menustr1+='<td width="25%" ><font face="Arial" size="2">Total Credit : </font></td><td width="25%" >'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="update_total_credit"'+
	 		' id=update_total_credit'+
	 		' size="16"/'+
	 		'</font></td></tr>';
	
	if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	{
		menustr1+='<tr><td width="25%"><font face="Arial" font size="2">Name : </font></td><td id=update_username width="25%">'+
		 	' <font face="Arial" size="2"></font></td>';
		menustr1+='<td width="25%"><font face="Arial" font size="2">Password : </font></td><td width="25%">'+
		 		' <font face="Arial" size="2">'+
		 		' <input style="padding: 5px;height:30;"  type="text" name="update_password"'+
		 		' id=update_password'+
		 		' size="16"/'+
		 		'</font></td></tr>';
	}else if (g_user_authorization_mode==2)
	{
		menustr1+='<tr><td width="25%"><font face="Arial" font size="2">Password : </font></td><td width="75%"colspan=3>'+
		 		' <font face="Arial" size="2">'+
		 		' <input  style="padding: 5px;height:30;" type="text" name="update_password"'+
		 		' id=update_password'+
		 		' size="16"/'+
		 		'</font></td></tr>';			
	}		
	menustr1+='<tr><td width="25%"><font face="Arial" font size="2">Package</font></td><td width="25%">'+
	 	'<font face="Arial" size="2">'+
		'<select style="text-indent: 5;width:152;height:26;" size="1" name="update_group" id=update_group>';
	for (j=0;j<g_total_group_no;j++)
	{
		groupname=g_groupname_array[j];
		menustr1+='<option style="padding: 2px" value="'+groupname+'">'+groupname+'</option>';
	}
	menustr1+='</select></font></td>';
	menustr1+='<td><font face="Arial"> <font size="2">Level: </font></td><td width="350" height="23">'+
	' <font face="Arial"> <font size="2">'+
	' <select style="text-indent: 5;width:152;height:26;" size="1" name="update_level" id="update_level">';
	menustr1+='<option style="padding: 2px" value="2">'+"Super Reseller"+'</option>'+
	'<option selected="selected" style="padding: 2px" value="3">'+"Reseller"+'</option>';
	menustr1+='</select></font></td></tr>';
	
	
	menustr1+='<tr><td><font face="Arial" size="2">Expired Time : </font></td><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="update_expired_time"'+
	 		' id="update_expired_time"'+
	 		' size="16" value="MM/DD/YYYY""/></font></td>';
	 	
	
	menustr1+='<td><font face="Arial"> <font size="2">Email: </font></td><td width="350" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="update_email"'+
	 		' id="update_email"'+
	 		' size="16" value="@gmail.com"/></font></td></tr>';
	 		
	menustr1+='<tr><td><font face="Arial"> <font size="2">Auto Renew</font></td><td colspan=3 width="1" height="23">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="update_auto_renew" id="update_auto_renew">';
	menustr1+='<option selected="selected" value="0">'+"OFF"+'</option>'+
	'<option value="1">'+"ON"+'</option>';
	menustr1+='</select></font></td></tr>';

	menustr1+='<tr>'+
	'<td colspan=2 width=50%><input style="background-color:#4285F4; color:#fff; border-radius:6px; font-weight:bold; padding:10px 25px; width:100%;"   type="button" value="Save" onclick=call_Update_Reseller() name="Save" /></td>'+
	'<td colspan=2 width=50%><input style="background-color:#FF5722; color:#fff; border-radius:6px; font-weight:bold; padding:10px 25px; width:100%;"  type="button" value="Cancel" onclick=close_modal_Reseller_Update() name="Cancel" /></td>'+
	'</tr></table>'+
	'</div>'+
	'</div></td>';

	menustr='<table width=100%><tr>'+menustr1+
	      '</tr></table>';
	 content.innerHTML=menustr+HTML_str;
	 if (g_add_reseller_flag==1)
	{
		open_modal_Reseller();
	}
	g_add_reseller_flag=0;
	document.getElementById("expired_time").style.color = "#cccccc";
	 document.getElementById("email").style.color = "#cccccc";

	g_reseller_no=total_user_no;
	//alert(g_reseller_no);
 }

 
}
function change_email_input_color()
{
	document.getElementById("email").style.color = "#000000";
}
function change_expired_time_input_color()
{
	document.getElementById("expired_time").style.color = "#000000";
}
function call_process_reseller() {
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
   var content = parent.document.getElementById("content");
	

	content.innerHTML="";

  	
  	g_token=find_cookie_value("token");
  	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;

 cgi_url = "/server/query_reseller_index?token="+encodeURI(g_token)+"&flag="+Math.random();

 xmlHttp.open("GET", cgi_url, true);
 xmlHttp.onreadystatechange = get_reseller;
 xmlHttp.send(null);

}
function reseller_group_inquery_item()
{
 
 if (xmlHttp.readyState == 4) {

    var response = xmlHttp.responseText.split("\r\n");
    var group_name;
    var i=0;
	var group_active_no=0;
	while (1)
	{
//		alert(group_active_no);
 	 	if (response[i]==0) break;
//		alert(response[i]);
    	 	strlength=response[i+1].length;
   	    	g_groupname_array[group_active_no]=response[i+1].slice(5,strlength);
//  	    	alert(g_groupname_array[group_active_no]);
 		i=i+10;
		group_active_no++;
	}
	g_total_group_no=group_active_no;
 	call_process_reseller();
 }

 
}

function call_get_reseller(position, limit) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
   	g_token=find_cookie_value("token");
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	g_user_position=position;
	g_user_limit=limit;
	if (g_token!=0)
	{
		cgi_url = "/server/query_group?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = reseller_group_inquery_item;
		xmlHttp.send(null);
	}

}
function call_Update_Reseller()
{
	var username_id="update_username"; 
 var password_id="update_password"; 
 var group_id="update_group"; 
 var level_id="update_level"; 
 var total_credit_id="update_total_credit"; 
 var expired_time_id="update_expired_time"; 
 var email_id="update_email"; 
 var auto_renew_id="update_auto_renew"; 
 var username;
 var szpassword; 
 var group; 
 var level; 
 var total_credit; 
 var expired_time; 
 var email; 
 var auto_renew;



var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var pos;
	var expired_time_temp;
 	var pos;
	var expired_time_temp;
	var alert_message;


	g_item=document.getElementById(username_id);
	username=g_item.innerText;
	
	//alert(username);
	g_item=document.getElementById(password_id);
	szpassword=g_item.value;
	if (szpassword.length==0)
	{
		alert("Reseller password is empty");
		return;
	}
	//alert(szpassword);
 	g_item=document.getElementById(group_id);
 	group=g_item.value;
 	//alert(group);
	g_item=document.getElementById(level_id);
	level=g_item.value;
	//alert(level);

	g_item=document.getElementById(total_credit_id);
	total_credit=g_item.value;
	//alert(total_credit);
	if (total_credit.length==0)
	{
		alert("Reseller total credit is empty");
		return;
	}
	g_item=document.getElementById(expired_time_id);
	expired_time=g_item.value;
	//alert(expired_time);
	if (expired_time.length==0)
	{
		alert("Reseller total credit is empty");
		return;
	}
	
	g_item=document.getElementById(email_id);
	email=g_item.value;
	//alert(email);
	
	
	g_item=document.getElementById(auto_renew_id);
	auto_renew=g_item.value;
		

  	g_token=find_cookie_value("token");

 cgi_url = "/server/update_reseller?token="+encodeURI(g_token)
 	 +"&username="+encodeURI(username)
	 +"&password="+encodeURI(szpassword)
	 +"&group="+encodeURI(group)
	 +"&level="+encodeURI(level)
	 +"&credit="+encodeURI(total_credit)
	 +"&expired_time="+encodeURI(expired_time)
	 +"&email="+encodeURI(email)
	 +"&auto_renew="+auto_renew
	 +"&flag="+Math.random();
 //alert(cgi_url);
 //if (confirm(confirm_msg))
 //{
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response==1)
			{
			//	alert("Add Reseller Sucessfully");
			} else if (response==0)
			{
				alert("Failed to Add Reseller");
			} else if (response==2)
			{
				alert("Disk is error(FULL), Please contact administrator");
			}else if (response==3)
			{
				alert("The reseller is already in Database");
			}
			call_get_reseller();
		}
	 };
	 xmlHttp.send(null);
 //}

}
function Update_Reseller_Info() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    //	alert("Update Reseller Sucessfully");
    } else if (response==0)
    {
   	alert("Failed to Update Reseller");
    } else if (response==2)
    {
    	alert("Disk is error(FULL), Please contact administrator");
    }
    }
}
function Del_Reseller_Info() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    	alert("Delete Reseller Sucessfully");
    } else if (response==2)
    {
     	alert("Disk is error(FULL), Please contact administrator");  	
    } else if (response==0)
    {
   	alert("Failed to Delete Reseller");
    }
    	call_get_reseller();
    }
}




//nction call_Del_User(user_no,username,szpassword,expired_time,paymodel,user_point)
function call_Del_Reseller(user_no)
{
 var username_id="username"+user_no; 
 var username;

var confirm_msg;
 	var cgi_url;
	var cookieStr;

 
	g_item=document.getElementById(username_id);
	username=g_item.innerText;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Delete Reseller: "+username+" ?";
// cgi_url = "/server/del_user?token="+encodeURI(g_token)+"&user_no="+encodeURI(user_no)+"&username="+encodeURI(username)+"&flag="+Math.random();
 cgi_url = "/server/del_reseller?token="+encodeURI(g_token)+"&username="+encodeURI(username)+"&flag="+Math.random();
  // alert(cgi_url);
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Del_Reseller_Info;
	 xmlHttp.send(null);
 }
 

}
function call_Restore_Reseller_Users()
{
 var username_id="update_username"; 
 var username;
var str;
var confirm_msg;
 	var cgi_url;
	var cookieStr;

 
	g_item=document.getElementById(username_id);
	username=g_item.innerText;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Restore "+username+" Users from Panel DB?";
 cgi_url = "/server/restore_reseller_users?token="+encodeURI(g_token)+"&username="+encodeURI(username)+"&flag="+Math.random();
 // alert(cgi_url);
 if (confirm(confirm_msg))
 {
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			//alert(response);
			if (response>=1)
			{
				str="Restore Reseller "+response+" Users";
				alert(str);
			} else if (response==0)
			{
				alert("Failed to ARestore");
			} else if (response==2)
			{
				alert("Disk is error(FULL), Please contact administrator");
			}
			call_get_reseller();
		}
	 };
	 xmlHttp.send(null);
 }
 

}