var xmlHttp = new XMLHttpRequest();


var g_provider_limit=0;
var g_provider_position=0;
var g_total_provider_no=0
var g_edit_no=1;
var g_balancer=0;
var g_current_serverip = "";
var g_current_panelport="0";
var g_server_http_ip_port="";
var g_license_key="";

var sortable_list=null;
var sortable_listItems = null;

var g_ToleranceRatio=0;
var g_ReconnectionRatio=0;
var g_DSPRatio=0;

// Version
var ENTERPRISE = 1;
var BALANCER = 2;
var BLOCKCHAIN_PUBLIC = 3;
var BLOCKCHAIN_PRIVATE = 4;
var BLOCKCHAIN_FREE = 5;
var BLOCKCHAIN_STANDARD = 6;
var g_Ezserver_Version=ENTERPRISE;
// Work FOlder
var g_work_folder_position=0;
var g_work_folder_limit=0;

// Blockchain
var g_blockchain_nodes_position=0;
var g_blockchain_nodes_limit=0;

var g_categoryclickedItemValue=null;
// 
var UPLOAD_USER_XML =1;
var UPLOAD_CHANNEL_XML =2;
var UPLOAD_MOVIE_XML =3;
var UPLOAD_SERIES_XML =4;
var UPLOAD_CHANNEL_M3U =5;
var UPLOAD_MOVIE_M3U =6;
var UPLOAD_SERIES_M3U =7;
var UPLOAD_XTREAM_DB_CONTENT =8;
var UPLOAD_XTREAM_DB_USERS = 9;
var UPLOAD_XTREAM_DB =10;
var UPLOAD_CHANNEL_CATEGORY_ICON =11;
var UPLOAD_MOVIE_CATEGORY_ICON =12;
var UPLOAD_SERIES_CATEGORY_ICON =13;
var EDIT_UPLOAD_CHANNEL_CATEGORY_ICON = 14
var EDIT_UPLOAD_MOVIE_CATEGORY_ICON =15;
var EDIT_UPLOAD_SERIES_CATEGORY_ICON =16;
var UPLOAD_CHANNEL_ICON_PATH=17;
var UPLOAD_MOVIE_ICON_PATH=18;
var UPLOAD_QRCODE_ICON_PATH=20

// User, Channel, Movie Line No
var bMobileDevice=0;
var JSONSystemInfo;
var JSONWorkFolder;
var JSONBlockchain;

var g_constant_limit=20;
var g_sequence_constant_limit=10;
var g_add_user_flag=0;
var g_add_group_flag=0;
var g_add_reseller_flag=0;
var g_add_channel_flag=0;
var g_add_movie_flag=0;
var g_add_series_flag=0;
var g_add_balancer_flag=0;
//var bStartSearch=false;
var g_SearchInput;
//
var g_P2P_Option;
var g_P2P_DisableKey;
// Transcoder var.
var g_transcoder_setting_option=0;
var g_uptime='';
var g_balancer_no=0;
var g_plus=0;

var g_channel_name_order_flag=0;
var g_channel_category_order_flag=0;
var g_movie_name_order_flag=0;
var g_movie_category_order_flag=0;
var g_series_name_order_flag=0;
var g_series_category_order_flag=0;
var g_user_name_order_flag=0;
var g_user_group_order_flag=0;
var g_user_expired_date_order_flag=0;
var version_date;
 
var g_token=0;
var g_item=0;
var g_ch_src;
var g_status_item;
var g_refresh_item;
var g_chtype_item;
var g_ch_play_id_item;
var g_Channel_Edit_Mode=0;
var g_Channel_Updated=0;
var g_Movie_Edit_Mode=0;
var g_Movie_Updated=0;
var g_total_movie_no=1;
var g_total_series_no=1;
var HTML_Menu_Bar_Str;
var g_content;
var g_blacklist_remove_item;
var total_player_no=1000;
var g_macid;
var g_user_id;
var g_password;
var g_ch_no=1;
var g_video_itemid= Array();
var g_file_path;
var vlc_monitorTimerId = 0; 
var prevState = 0; 
var g_channel_no=1;
var g_remove_all_button;
var g_username;
var g_groupname_array = new Array();
var g_paymodel_array = Array("pre","post","free");
var g_total_group_no=0;
var g_timer;
var g_current_timestamp;
var g_dvr_timestamp=0;
var bdvr_on;
var g_video_path;
var g_server_dvr_sec;
var g_cur_sec;
var g_dvr_sec;
var g_delaytime_array = Array("Delay 5 sec.","Delay 10 sec.","Delay 20 sec.","Delay 30 sec.","Delay 40 sec.","Delay 50 sec.",
				"Delay 1 min.","Delay 3 min.","Delay 5 min.","Delay 10 min.","Delay 20 min.","Delay 30 min.","Delay 40 min.","Delay 50 min.",
				"Delay 1 hr.","Delay 2 hr.","Delay 3 hr.","Delay 4 hr.","Delay 5 hr.","Delay 6 hr.","Delay 7 hr.","Delay 8 hr.","Delay 9 hr.","Delay 10 hr.","Delay 11 hr.","Delay 12 hr.")
var g_delayvalue_array = Array("delay,5,sec.","delay,10,sec.","delay,20,sec.","delay,30,sec.","delay,40,sec.","delay,50,sec.",
				 "delay,1,min.","delay,3,min.","delay,5,min.","delay,10,min.","delay,20,min.","delay,30,min.","delay,40,min.","delay,50,min.",
				"delay,1,hr.","delay,2,hr.","delay,3,hr.","delay,4,hr.","delay,5,hr.","delay,6,hr.","delay,7,hr.","delay,8,hr.","delay,9,hr.","delay,10,hr.","delay,11,hr.","delay,12,hr.")
var g_server_timer;
var g_user_authorization_mode=1;
var g_httpport;
var g_System_timer=0;

var g_Query_Channel_Status_timer=0;
var g_Query_Online_Player_timer=0;
var g_Get_Channel_Statistics_timer=0;

var bSystem_Inquery_Panel=0;
var bQuery_Channel_Status=0;
var bQuery_Online_Player=0;
var bGet_Channel_Statistics=0;
var g_checkedstring='0';
var g_copy_paste=0;

var g_reseller_no=0;
var g_player_filter_no=0;
var g_total_ch_no=0;
var g_balancer_server_no=0;
var g_edge_server_no=0;
var g_cur_year;
var g_cur_month;
var g_total_program_no=0;
var g_program_no=0;
var g_show_free_version=0;
var g_user_no=0;
var g_cur_userno=0;
var g_active_player_no=0;
var g_search_user_item= new Object();
var g_search_channel_item= new Object();
var g_search_movie_item= new Object();
var g_search_series_item= new Object();
var g_search_player_item= new Object();
var g_AddMultipleUserWindow;
var g_current_content;
var g_username_item;
var g_server_ip_array = new Array();
var g_totoal_server_ip_no=0;
var g_selectedcounter=0;
var g_goto_item=new Object();
var TableBackgroundNormalColor = "#FFFFFF";
var TableBackgroundMouseoverColor = "#F4F4F4";
var TableMenuBackgroundNormalColor = "#F4F4F4";
var TableMenuBackgroundMouseoverColor = "#EBEBEB";
//var g_total_user_no=0;
var g_user_position=0;
var g_channel_position=0;
var g_movie_position=0;
var g_series_position=0;
var g_active_connection_position=0;
var g_total_user_no=0;
var g_multiple_user_no;
var g_search_result = new Array();
var g_user_limit=0;
var g_channel_limit=0;
var g_movie_limit=0;
var g_series_limit=0;
var g_active_connection_limit=0;
var g_user_found_position=0;
var g_channel_found_position=0;
var g_movie_found_position=0;
var g_series_found_position=0;
var g_movie_selected_position=1;
var g_series_selected_position=1;
var g_channel_selected_position=1;
var g_user_selected_position=1;
var g_current_button_id="home_button";
var g_show_off_channel=0;
var g_active_channel_no=0;
var g_expired_user_no=0;
var g_expired_user=0;
var g_UserDetailWindow=null;
var g_search_text='';
var Channel_Categories_tems=[];
var g_ChannelDetailWindow=false;
var g_MovieDetailWindow=false;
var g_UserDetailWindow=false;
var g_start_search_option=0;
var g_search__player_text;

    class XHREventTarget {
        constructor(xhr) {
            let evtTypes = ['loadstart', 'progress', 'abort', 'error', 'load', 'time', 'loadend'];

            let handlers = evtTypes.reduce((handlers, evtType) => {
                handlers[evtType] = new Set();
                return handlers;
            }, {});

            evtTypes.forEach(evtType => {
                xhr[`on${evtType}`] = function(evt) {
                    handlers[evtType].forEach(handler => handler.call(xhr, evt));
                };
            });

            this.xhr = xhr;
            this.handlers = handlers;
        }

        addEvt(evtType, handler) {
            this.handlers[evtType].add(handler);
            return this;
        }

        removeEvt(evtType, handler) {
            this.handlers[evtType].delete(handler);
            return this;
        }       
    }

    class XHRUpload extends XHREventTarget {
        constructor(xhr) {
            super(xhr);
        }
    }

     class XHR extends XHREventTarget {
        constructor() {
            super(new XMLHttpRequest());

            let xhr = this.xhr;
            let handlers = this.handlers;
            handlers['readystatechange'] = new Set();

            xhr.onreadystatechange = function(evt) {
                handlers['readystatechange']
                    .forEach(handler => handler.call(xhr, evt));
            };
        }

        open(method, url, paraObj, async = true, username = null, password = null) {
            let openUrl = paraObj ? `${url}?${params(paraObj)}` : url; 
            this.xhr.open(method, openUrl, async, username, password);
            return this;
        }

        addHeaders(headers) {
            Object.keys(headers)
                  .forEach(name => this.xhr.setRequestHeader(name, headers[name]));
            return this;
        }

        send(body = null) {
            this.xhr.send(body);
            return this;
        }

        uploadXHR() {
            if(this.upload === undefined) {
                this.upload = new XHRUpload(this.xhr.upload);
            }
            return this.upload;
        }
    }
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari",
			versionSearch: "Version"
		},
		{
			prop: window.opera,
			identity: "Opera",
			versionSearch: "Version"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			   string: navigator.userAgent,
			   subString: "iPhone",
			   identity: "iPhone/iPod"
	    },
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]


};
function ChangeBackgroundColor(row) { row.style.backgroundColor = TableBackgroundMouseoverColor; }
function RestoreBackgroundColor(row) { row.style.backgroundColor = TableBackgroundNormalColor; }
function RestoreMenuBackgroundColor(row) 
{ 
	if (row.id!=g_current_button_id)
	{
		row.style.backgroundColor = TableMenuBackgroundNormalColor; 
	}
}
function ChangeMenuBackgroundColor(row) 
{ 
	if (row.id!=g_current_button_id)
	{
		row.style.backgroundColor = TableMenuBackgroundMouseoverColor; 
	}
}


function change_link(new_url, new_width, new_height)
{
   var content= document.getElementById("content");
	if ((new_width>0) && (new_height>0))
	{
		content.innerHTML='<iframe frameborder="0" width='+new_width+' height='+new_height+' src="'+new_url+'"></iframe>';	
	} else
	{
		content.innerHTML='<iframe frameborder="0"'+new_url+'"></iframe>';	
	}
	

 
}


function find_cookie_value(keystrinp)
{ 
	var restring;
	var str;
	var substr1;
	var pos1, pos2;
	
	str=document.cookie;
	//alert(str);
	//alert(keystr);
	keystr=keystrinp+location.hostname
	pos1=str.indexOf(keystr);
	//alert(pos1);
	subchar=str.substring(pos1+keystr.length,pos1+keystr.length+1);
	//alert(subchar);
	if (subchar==';')
	{
		return 0;
	}else
	{
		substr1=str.substring(pos1+keystr.length+2,str.length);
		//alert(substr1);
		pos1=substr1.indexOf(']');
		restring=substr1.substring(0,pos1);
		//alert(restring);
		return restring;
	}
	
	
}
function add_cookie_value(keystr,keyvalue)
{
	//alert(document.cookie);
	document.cookie=keystr+location.hostname+'=['+keyvalue+']';
}
function Clear_cookie()
{
	document.cookie='token'+location.hostname+'=';
	document.cookie='userid'+location.hostname+'=';
	document.cookie='password'+location.hostname+'=';
	document.cookie='dir_path'+location.hostname+'=';
	document.cookie='video_path'+location.hostname+'=';

}

function encode64(input) {  

 var keyStr = "ABCDEFGHIJKLMNOP" +  

              "QRSTUVWXYZabcdef" +  

              "ghijklmnopqrstuv" +  

              "wxyz0123456789+/" +  

              "=";  
  // input = encodeURI(input);  

    var output = "";  

    var chr1, chr2, chr3 = "";  

    var enc1, enc2, enc3, enc4 = "";  

    var i = 0; 
  
 
    do {  

       chr1 = input.charCodeAt(i++);  

       chr2 = input.charCodeAt(i++);  

       chr3 = input.charCodeAt(i++);  

  

       enc1 = chr1 >> 2;  

       enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);  

       enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);  

       enc4 = chr3 & 63;  

  

    /*   if (isNaN(chr2)) {  

          enc3 = enc4 = 64;  

       } else if (isNaN(chr3)) {  

          enc4 = 64;  

       }  
*/
  

       output = output +  

          keyStr.charAt(enc1) +  

          keyStr.charAt(enc2) +  

          keyStr.charAt(enc3) +  

          keyStr.charAt(enc4);  
  
       chr1 = chr2 = chr3 = "";  

       enc1 = enc2 = enc3 = enc4 = "";  

    } while (i < input.length);  

  

    return output;  

}  
function Update_Setting() {
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    /*
    if (g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
    {
	    const DSPSlider = document.getElementById("DSPSlider");
	    const DSPValue = document.getElementById("DSPValue");
	    
	    let DSPRatio = parseFloat(DSPSlider.value).toFixed(2);
	
	    var nThreadholdConnection=parseInt(parseFloat(document.getElementById("max_streaming_no").value)*parseFloat(DSPRatio));
	    var nThreadholdConnection1=parseInt(document.getElementById("max_streaming_no").value)-nThreadholdConnection;
	    DSPValue.textContent = `${DSPRatio}`;
	    document.getElementById("DSPNote").innerHTML='<font face="Arial" size="2">( System switches to P2P mode up to <b>'+ nThreadholdConnection1 +'</b> connections. )'+'</font>';
    }
    */
    alert(response);
   }
}     
function save_setting() {
	// Get the city and state from the web form
	var http_base_port = document.getElementById("http_base_port").value;
	var http_apps_port = document.getElementById("http_apps_port").value;
	var httpport = document.getElementById("httpport").value;
	var https_base_port = document.getElementById("https_base_port").value;
	var https_apps_port = document.getElementById("https_apps_port").value;
	var https_port = document.getElementById("https_port").value;
	
	var rtmpport;
	var rtsp_base_port;
 	var igmpip;
	var igmpport;
	
	var blockchain_server_port;
	var blockchain_streaming_port;
	var blockchain_main_dns;
	var blockchain_main_port;
	var blockchain_server_region;
	var blockchain_server_group;
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		alert("Only for Formal version");
		return;
	}

  if ((g_Ezserver_Version == ENTERPRISE) || (g_Ezserver_Version == BALANCER))
  {
	rtmpport = document.getElementById("rtmpport").value;
	igmpip = document.getElementById("igmpip").value;
	igmpport = document.getElementById("igmpport").value;
 }else if ((g_Ezserver_Version==BLOCKCHAIN_PUBLIC) || g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
 {
	blockchain_server_port = document.getElementById("blockchain_server_port").value;
	blockchain_streaming_port = document.getElementById("blockchain_streaming_port").value;
	if (document.getElementById("blockchain_node_type").checked==true)
 	{
		blockchain_main_dns="";
		blockchain_main_port="";
	}else
	{
		//blockchain_server_port="";
		blockchain_main_dns = document.getElementById("blockchain_main_dns").value;
		blockchain_main_port = document.getElementById("blockchain_main_port").value;
	}
	blockchain_server_region = document.getElementById("blockchain_server_region").value;
	blockchain_server_group = document.getElementById("blockchain_server_group").value;
 }
 //alert(blockchain_server_port);

 var ch_input_buffer_no = document.getElementById("ch_input_buffer_no").value;
 var ch_streaming_prebuffer_no = document.getElementById("ch_streaming_prebuffer_no").value;
 //var ch_streaming_bitrate_tolerance = document.getElementById("ch_streaming_bitrate_tolerance").value;
 var ch_streaming_bitrate_tolerance = g_ToleranceRatio;
 var max_streaming_no = document.getElementById("max_streaming_no").value;
 var system_log = document.getElementById("system_log").value;
 var admin_system_log = document.getElementById("admin_system_log").value;
 var pagination_limit_no = document.getElementById("pagination_limit_no").value;
 //var transcoder_path = document.getElementById("transcoder_path").value;
 var transcoder_path;
 
 //var ch_reconnection_interval = document.getElementById("ch_reconnection_interval").value;
 var ch_reconnection_interval = g_ReconnectionRatio;
 var DSP_rate=g_DSPRatio;
 var alert_player_duration = document.getElementById("alert_player_duration").value;
 var blacklist;
 if (document.getElementById("blacklist").checked==true)
 {
 	blacklist=1;
 }else
 {
 	blacklist=0;
 }
  
 var dvr_duration = document.getElementById("dvr_duration").value;
// var catch_up_tv_epg = document.getElementById("catch_up_tv_epg").value;
 var extract_ts_epg;
 //var xmltv_epg_url = document.getElementById("xmltv_epg_url").value;
 var xmltv_epg_url="";
 var p2p_cmd_port=1720;
 //alert(p2p_cmd_port);
  var p2p_data_port=1730;
 // alert(p2p_data_port);
  var p2p_switch=0;
 /* if (g_P2P_DisableKey==0)
  {
  	  p2p_data_port = document.getElementById("p2p_data_port").value;
  	  p2p_cmd_port = document.getElementById("p2p_cmd_port").value;
	  if (document.getElementById("p2p_option").checked)
	  {
	  	p2p_switch=1;
	  }
  }
  */
  //alert(p2p_switch);
//  var url = "/cgi-bin/cgi_ezserver?httpport=" + encodeURI(httpport)+
  	g_token=find_cookie_value("token");
  	if (document.getElementById("extract_ts_epg").checked==true)
  	{
  		extract_ts_epg=1;
  	}else
  	{
  		extract_ts_epg=0;
  	}
  var url = "/server/save_config?token="+encodeURI(g_token)+"&http_base_port=" + encodeURI(http_base_port)+"&http_apps_port=" + encodeURI(http_apps_port)+"&httpport=" + encodeURI(httpport)+
  "&https_base_port=" + encodeURI(https_base_port)+"&https_apps_port=" + encodeURI(https_apps_port)+"&https_port=" + encodeURI(https_port)+
  "&rtsp_base_port=" + encodeURI(rtsp_base_port)
  
	if ((g_Ezserver_Version == ENTERPRISE) || (g_Ezserver_Version == BALANCER))
	{
		url+="&rtmpport=" + encodeURI(rtmpport)+
		"&igmpip=" + igmpip+
		"&igmpport=" + encodeURI(igmpport);
	}else if ((g_Ezserver_Version==BLOCKCHAIN_PUBLIC) || g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
	{
	
 		url+="&blockchain_server_port=" + encodeURI(blockchain_server_port)+
 		"&blockchain_streaming_port=" + encodeURI(blockchain_streaming_port)+
 		"&blockchain_main_dns=" + encodeURI(blockchain_main_dns)+
 		"&blockchain_main_port=" + encodeURI(blockchain_main_port)+
	 	"&blockchain_server_region=" + blockchain_server_region+
	  	"&blockchain_server_group=" + encodeURI(blockchain_server_group)+
	  	"&DSP_rate=" + DSP_rate;
	}

  url+="&p2p_switch=" + p2p_switch+
  "&p2p_cmd_port=" + p2p_cmd_port+
  "&p2p_data_port=" + p2p_data_port+
 "&ch_input_buffer_no=" + encodeURI(ch_input_buffer_no)+
  "&ch_streaming_prebuffer_no=" + encodeURI(ch_streaming_prebuffer_no)+
  "&ch_streaming_bitrate_tolerance=" + encodeURI(ch_streaming_bitrate_tolerance)+
  "&max_streaming_no=" + encodeURI(max_streaming_no)+
  "&system_log=" + encodeURI(system_log)+
  "&admin_system_log=" + encodeURI(admin_system_log)+
  "&pagination_limit_no=" + encodeURI(pagination_limit_no)+
  "&transcoder_path=" + encodeURI(transcoder_path)+
  "&ch_reconnection_interval=" + encodeURI(ch_reconnection_interval)+
  "&alert_player_duration=" + encodeURI(alert_player_duration)+
  "&blacklist=" + encodeURI(blacklist)+
  "&dvr_duration=" + encodeURI(dvr_duration)+
  "&extract_ts_epg=" + encodeURI(extract_ts_epg)+
  "&xmltv_epg_url=" + xmltv_epg_url+
  "&flag="+Math.random();
  //alert(url);
   //var confirm_msg="Update Setting?";
	if (g_token!=0)
	{
		//if (confirm(confirm_msg))
		//{
			g_constant_limit=parseInt(pagination_limit_no);
			//g_sequence_constant_limit=g_constant_limit;
		// Open a connection to the server
		xmlHttp.open("GET", url, true);
		
		// Setup a function for the server to run when it's done
		xmlHttp.onreadystatechange = Update_Setting;
		
		
		// Send the request
		xmlHttp.send(null);
		//}
	}
}

function switch_main_slave()
{
	if (document.getElementById("blockchain_node_type").checked==false)
	{
		document.getElementById("blockchain_server_port_hr").style="block;";
		/*document.getElementById("blockchain_server_port_text").style="display: none;";
	    	document.getElementById("blockchain_server_port_img").style="display: none;";
	    	document.getElementById("blockchain_server_port").style="display: none;";
	    	*/
	}else
	{
		document.getElementById("blockchain_server_port_hr").style="display: none;";
		/*document.getElementById("blockchain_server_port_text").style="block;";
	    	document.getElementById("blockchain_server_port_img").style="block;";
	    	document.getElementById("blockchain_server_port").style="block;padding: 5px;height:30;";
	    	*/
	    	
	}
	
}

/*
function submitForm() {
   document.getElementById('responseMessage').innerText = 'Join Ezserver Cloud';
    document.getElementById("submitBtn").disabled = true;
    document.getElementById("queryBtn").disabled = false;
    document.getElementById("deleteBtn").disabled = false;
    document.getElementById("firstForm").style.display = "block"; // Show the first form
    document.getElementById("secondForm").style.display = "none";
      document.getElementById("deleteForm").style.display = "none"; // Show the second form
   document.getElementById('submit').value = 'Submit';
    document.getElementById("password").placeholder = "Enter the password to edit in the future";
    
}
function queryData() {

    document.getElementById('responseMessage').innerText = 'Query and Update Service';
  document.getElementById("submitBtn").disabled = false;
    document.getElementById("queryBtn").disabled = true;
    document.getElementById("deleteBtn").disabled = false;
    document.getElementById("secondForm").style.display = "block"; // Show the second form
    document.getElementById("firstForm").style.display = "none"; 
     document.getElementById("deleteForm").style.display = "none"; // Show the second form
   document.getElementById('query').value = 'Query';
    document.getElementById("password").placeholder = "Enter Passowrd";
}

function deleteEntry() {
    document.getElementById('responseMessage').innerText = 'Delete Service';
  document.getElementById("submitBtn").disabled = false;
    document.getElementById("queryBtn").disabled = false;
    document.getElementById("deleteBtn").disabled = true;
    document.getElementById("deleteForm").style.display = "block"; // Show the second form
    document.getElementById("secondForm").style.display = "none"; // Show the second form
    document.getElementById("firstForm").style.display = "none"; 
    document.getElementById('deletesubmit').value = 'Delete';
    document.getElementById("password").placeholder = "Enter Passowrd";

}
*/
/*
function get_profile() {
	var post_url="/server/get_profile?token="+encodeURI(g_token)+"&flag="+Math.random();
	var formData = new FormData();
	var service_url;
	if (location.protocol == 'https:') {
		service_url="https://"+location.hostname+":"+g_api_httpport;
	}else if (location.protocol == 'http:') {
		service_url="http://"+location.hostname+":"+g_api_httpport;
		//service_url="http://"+"192.168.0.8"+":"+g_api_httpport;
	}
	//alert(service_url);
	//alert(g_password);
	formData.append('simpledomain', service_url); 
	formData.append('simplepassword', g_password);
    	fetch(post_url, {
                method: 'POST',
                body: formData
               //body: new FormData(document.getElementById('updateServiceForm'))
            })
            .then(response => {
                if (!response.ok) {
                    throw new Error(`HTTP error! status: ${response.status}`);
                }
                return response.text();
            })
            .then(response => {
                //alert(response);
                const jsonResponse1 = JSON.parse(response);
			
                if (jsonResponse1.message=="No matching records found.")
                {
                	document.getElementById('responseMessage').innerText="Service Not Register.";
                	document.getElementById('domain').value =service_url;
                	document.getElementById('icon').value = "https://www.ezhometech.com/ezserver_cloud/img/default.png";
                	document.getElementById('password').value =g_password;
                }else if (response.length > 0) {
		    // Show the relevant table data
		       
			//alert(jsonResponse1);
			jsonResponse=jsonResponse1[0];
			//alert(jsonResponse);
			
			//alert(jsonResponse.status);
			//document.getElementById("firstForm").style.display = "block"; // Show the first form				 
			document.getElementById('responseMessage').innerText=jsonResponse.status;
			//console.log(jsonResponse);
			document.getElementById('domain').value = jsonResponse.domain;
			// Set the values of the input fields or other elements
			document.getElementById('service').value = jsonResponse.service;
			document.getElementById('provider').value = jsonResponse.provider;
			document.getElementById('email').value = jsonResponse.email;
			document.getElementById('icon').value = jsonResponse.icon;
			document.getElementById('country').value = jsonResponse.country;
			document.getElementById('category').value=jsonResponse.category;
			
			document.getElementById('description').value = jsonResponse.description;
			document.getElementById('password').value = jsonResponse.password;
			document.getElementById('submit').style.display = "block";
			document.getElementById('submit').value = 'Update';
			document.getElementById("serviceForm").action = "javascript:update_service_url()";
		 
		} else {
			document.getElementById('responseMessage').innerText=response;
		
		}
            })
            .catch(error => {
                alert(`Error: ${error.message}`);
            });
             
             
}
*/
function order_ezserver() {
    //window.location.href = "https://www.ezhometech.com/price.htm";
    window.open("https://www.ezhometech.com/price.htm", "_blank");
}


function license_key_dialog()
{
	var main_screen= document.getElementById("main_screen");
	var str="";
	
	if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
		bMobileDevice=1;
	}
	
	
	if (bMobileDevice)
	{
		str='<p style="margin-top: 50%;"></p>';
	}else
	{
		str='<p style="margin-top: 10%;"></p>';
	}
		str+='<div align="center">'+
		  '<table id=login_rcorners align="center" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">'+
		    '<tr>'+
		      '<td width="100%" bordercolorlight="#DFDFDF" bordercolordark="#F3F3F3" height="100%" valign="middle">'+
		        '<div align="center">'+
		          '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="481">'+
		            '<tr>'+
		              '<td colspan="2" align="center" height="30">'+
		                '<p style="margin-left: 0"><b><font face="Arial" color="#0000bb" size="7">Ezserver</font></b></td>'+
		            '</center>'+
		            
		          '</tr>'+
		            '<tr>'+
		              '<td colspan="2"align="center" height="30">'+
		                '<p style="margin-left: 0"><font face="Arial" color="#888888" size="4">Unlicensed Server</font></td>'+
		            '</center>'+
		            
		          '</tr>'+
		          
		          '<center>'+
		          '<tr>'+
		            '<td colspan="2" width="100%">'+
		              '<p style="margin-left: 25";margin-top: -20"><font face="Arial" size="2" color="#679DF6">License Key</font></td>'+
		          '</tr>'+
		          
		          '<tr>'+
		            '<td colspan="2" width="100%">'+
		              '<p style="margin-left: 25;margin-top: -10"><input autofocus type="text" id="license_key" size="50" style="text-indent: 5;height:40;background-color: #FAFFBD; opacity:0.5;color: #000000; border-style: solid; border-width: 1"></p>'+
		              '</td>'+
		          '</tr>'+
		          
		        
		          '<tr>'+
		           '<td width="50%">'+
		       	    '<p align="left" style="padding: 5px;margin-left: 25; margin-right: 25;;margin-top: -5"><button style="width:100%;height:50;" class="button button3" onclick="GetLicenseActivation()" name="copy" />Copy Key</button>'+
			    '</td>'+
		          '<td width="50%">'+
		       	    '<p align="left" style="padding: 5px;margin-left: 25; margin-right: 25;;margin-top: -5"><button style="width:100%;height:50;" class="button button3" onclick="order_ezserver()" name=order" />Order</button>'+
			    '</td>'+ 
		       
		          '</tr>'+
		          
		        '</table>'+
		      '</div>'+
		    '</td>'+
		  '</tr>'+
		  '</table>'+
		  '<table>'+
		          '<tr>'+
		            '<td width="50%" valign="bottom" height="71">'+
		              '<p align="center"><font size="2" color="#679DF6" face="Arial">Ezhometech Inc.</font></td>'+
		          '</tr>'+'</table>';
		'</div>';
		
	

	main_screen.innerHTML=str;
	document.getElementById("license_key").value=g_license_key;
	
	
}

function get_license_key() {
	var get_url="/server/get_profile?"+"&flag="+Math.random();
	xmlHttp.open("GET", get_url, true);
	xmlHttp.onreadystatechange = function(){
	
		if (xmlHttp.readyState == 4) {
			var response= xmlHttp.responseText;
			if (response.length > 0) {
			    // Show the relevant table data
			       const jsonResponse = JSON.parse(response);
			       const profile = jsonResponse.profile;
			      
			       g_license_key=profile.key;
			       
			       license_key_dialog();
			}
		}
	}
	xmlHttp.send(null);
}
function get_profile() {
//	var get_url="/server/get_profile?token="+encodeURI(g_token)+"&flag="+Math.random();
	var get_url="/server/get_profile?"+"&flag="+Math.random();
	xmlHttp.open("GET", get_url, true);
	xmlHttp.onreadystatechange = function(){
	
		if (xmlHttp.readyState == 4) {
			var response= xmlHttp.responseText;
			if (response.length > 0) {
			    // Show the relevant table data
			       const jsonResponse = JSON.parse(response);
			       const profile = jsonResponse.profile;
				//alert(jsonResponse1);
				
				
				//alert(jsonResponse.status);
				//document.getElementById("firstForm").style.display = "block"; // Show the first form				 
				//document.getElementById('responseMessage').innerText=profile.status;
				//console.log(jsonResponse);
				//document.getElementById('domain').value = jsonResponse.domain;
				// Set the values of the input fields or other elements
				
				document.getElementById('license_key').value = profile.key;
				document.getElementById('tmdbkey').value = profile.tmdbkey;
				
				document.getElementById('service').value = profile.service;
				document.getElementById('provider').value = profile.provider;
				document.getElementById('email').value = profile.email;
				document.getElementById('icon').value = profile.icon;
				//document.getElementById('country').value = jsonResponse.country;
				//document.getElementById('category').value=jsonResponse.category;
				
				//document.getElementById('description').value = jsonResponse.description;
				//document.getElementById('password').value = jsonResponse.password;
				//document.getElementById('submit').style.display = "block";
				//document.getElementById('submit').value = 'Update';
				//document.getElementById("serviceForm").action = "javascript:update_service_url()";
			 
			} else {
				document.getElementById('responseMessage').innerText=response;
			
			}
		}
	}
	xmlHttp.send(null);
}
function save_profile() {
	
	var tmdbkey=document.getElementById('tmdbkey').value;
	var service=document.getElementById('service').value;
	var provider=document.getElementById('provider').value;
	var email=document.getElementById('email').value;
	var icon=document.getElementById('icon').value;
	//alert(service);
	var get_url="/server/save_profile?token="+encodeURI(g_token)+
		'&tmdbkey='+tmdbkey+
		'&service='+service+
		"&provider="+provider+
		"&email="+email+
		"&icon="+icon+
		"&flag="+Math.random();
	//alert(get_url);
				
	xmlHttp.open("GET", get_url, true);
	xmlHttp.onreadystatechange = function(){
	
		if (xmlHttp.readyState == 4) {
			alert(xmlHttp.responseText);
		}
	}
	xmlHttp.send(null);
}
	

function copyToClipboard() {
   
	var inputElement = document.querySelector('#license_key');
	inputElement.select();
	document.execCommand('copy');
	
}
function GetLicenseActivation() {

	copyToClipboard();
	alert("Start Ezserver again after ezserver license is activated...");

}
function Button_Manage_Profile()
{
	
	var str;
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	var content;
	var cellsize="15%";
	
	var ezcontent= document.getElementById("content");
	ezcontent.innerHTML='</div><div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="80%";
	
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Manage Profile</b></font>';
	str+='</td>';
	
	
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;
	
	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";
	str="";
	//str+='<div style="display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 20px;">';
	//str+='<button id="submitBtn" class="round-button" onclick="submitForm()" style="width: 8%; min-width: 80px; padding: 5px;" disabled>Submit</button>';
	//str+='<button id="queryBtn" class="round-button" onclick="queryData()" style="width: 8%; min-width: 80px; padding: 5px;">Query</button>';
	//str+='<button id="deleteBtn" class="round-button" onclick="deleteEntry()" style="width: 8%; min-width: 80px; padding: 5px;">Delete</button>';
	//str+='</div>';
	str+='<center>';
	str+='<div class="row">';      
	       	
		    
	       	str+='<div class="col text-center" style="margin-top: 10px;margin-bottom: 0px;">';
   
                
	       	str+='<h4 id="responseMessage"  style="margin-top: 0px;font-size:28px;color:#000000;">Profile</h4>';
	       	str+='</div>';   	
	str+='</div>';
	
	str+='<div class="row text-left" style="width:50%; font-family: Arial;">';
	
		str+='<div id="firstForm">';
			
			str+='<table border="0" style="margin-top: 0px; font-family: Arial; font-size: 14px; width: 100%;" align="center">';
				str+='<tr>';
				str+='<td>';
				//str+='<form id="serviceForm" action="javascript:save_profile()" method="POST" enctype="multipart/form-data" >';
				//str+='<form id="serviceForm" action="" method="POST" enctype="multipart/form-data" >';
				str+='<table width="100%" border="0">';
				/*
				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><label for="domain">Domain Name URL: (with API port: default 17000)</label><br>';
				str+='<input type="text" id="domain" name="domain" style="margin-top: 0px;margin-bottom: 20px; width: 100%; padding: 5px;height:30; color: #0;" placeholder="http://xxx.xxx.xxx:17000" required></td>';
				str+='</tr>';
				*/
				str += '<tr style="font-family: Arial; font-size: 16px;">';
				str += '<td>';
				str += '<label for="license_key">License Key:</label><br>';
				str += '<div style="display: flex; align-items: center;">';
				str += '<input type="text" id="license_key" name="license_key" readonly style="margin-top: 0px; margin-bottom: 20px; width: 100%; padding: 5px; height: 30px; color: #000; flex: 1;">';
				str += '<button onclick="copyToClipboard()" style="margin-left: 10px; padding: 0; background: none; border: none; cursor: pointer;">';
				str += '<img src="/admin/copy.png" alt="Copy" style="width: 30px; height: 30px;">';
				str += '</button>';
				str += '</div>';
				str += '</td>';
				str += '</tr>';

				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><label for="tmdbkey">TMDB Key:</label><br>';
				str+='<input type="text" id="tmdbkey" name="tmdbkey" style="margin-top: 0px;margin-bottom: 20px; width: 100%; padding: 5px;height:30; color: #0;" placeholder="Enter your TMDB Key" required></td>';
				str+='</tr>';
				
				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><label for="service">Service Name:</label><br>';
				str+='<input type="text" id="service" name="service" style="margin-top: 0px;margin-bottom: 20px; width: 100%; padding: 5px;height:30; color: #0;" placeholder="Enter service name" required></td>';
				str+='</tr>';

				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><label for="provider">Service Provider Name:</label><br>';
				str+='<input type="text" id="provider" name="provider" style="margin-top: 0px;margin-bottom: 20px; width: 100%; padding: 5px;height:30; color: #0;" placeholder="Enter service company or provider name" required></td>';
				str+='</tr>';

				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><label for="email">Service Support Email:</label><br>';
				str+='<input type="text" id="email" name="email" style="margin-top: 0px;margin-bottom: 20px; width: 100%; padding: 5px;height:30; color: #0;" placeholder="Enter Support Email ID for users" required></td>';
				str+='</tr>';
				
				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><label for="Icon">Service Icon URL: (recommended size Width: 240px, Height: 350px</label><br>';
				str+='<input type="text" id="icon" name="icon" style="margin-top: 0px; margin-bottom: 20px; width: 100%; padding: 5px; height: 30px; color: #0;" required placeholder="http://xxx.xxx.xxx/1.jpg"></td>';
				str+='</tr>';

                              

  				 			
				str+='<tr style="font-family: Arial; font-size: 16px;">';
				str+='<td><input class="round-button" onclick="javascript:save_profile()" style="width: 100%;" id="submit" value="Save"></td>';
				
				
				str+='</tr>';
				
				//str+='</table></form></td></tr>';
				str+='</table></td></tr>';
			str+='</table>';
			
	
                       
		str+='</div>';
  
		
		
		
		
		 	  
	str+='</div>';
	str+='</center>';
	
	content.innerHTML=str;
	get_profile();
	
}
function callServer_Setting()
{
	
//	  var url = "/cgi-bin/cgi_ezserver?token="+encodeURI(g_token)+"&value_creation"+"&flag="+Math.random();
	  var url = "/server/get_config?token="+encodeURI(g_token)+"&flag="+Math.random();
var str;

bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	var content;
	var cellsize="15%";
	
	var ezcontent= document.getElementById("content");
	ezcontent.innerHTML='</div><div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="80%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Setting</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+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="callServer_Setting()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 

		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">Setting</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+='</div>';                              
	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";
	/*var search_field= document.getElementById("title_search_field");
	var search_button= document.getElementById("title_search_button");
	search_field.hidden=true;
	search_button.hidden=true;
	*/

	
	str='<table border="0" style="margin-top: 20px;" width=90% align="center">'+
	'<tr><td colspan="4">'+
		'<p align="left"><font face="Arial" size="2"><b>HTTPS Setting</b></font>'+
		'</td></tr>'+
		
		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Panel port</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="3"> <input style="padding: 5px;height:30;" type="text" name="https_base_port" id="https_base_port" size="16"/></font>'+
		'&nbsp;<img  align="center" title="for Chrome to manage panel" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+

		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">API port</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="https_apps_port" id="https_apps_port" size="16"/></font>'+
		'&nbsp;<img  align="center" title="for Stalker portal, XCIPTV" width=12 height=12 src="/admin/info.png"></img>'+

		'</td>'+
		'</tr>'+
				
		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Streaming port</font></p>'+
		'</td>'+
		'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="https_port" id="https_port" size="16"/></font>'+
		'&nbsp;<img  align="center" title="for VLC, IPTV Smarter" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+

		'<td width="25%" height="23">'+
		'</td>'+
		'</tr>'+
		
		'<tr><td colspan="4">'+
		'<p align="left"><font face="Arial" size="2"><b>HTTP Setting</b></font>'+
		'</td></tr>'+
		
		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Panel port</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="3"> <input style="padding: 5px;height:30;" type="text" name="http_base_port" id="http_base_port" size="16"/></font>'+
		'&nbsp;<img  align="center" title="for Chrome to manage panel" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+

		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">API port</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="http_apps_port" id="http_apps_port" size="16"/></font>'+
		'&nbsp;<img  align="center" title="for Stalker portal, XCIPTV" width=12 height=12 src="/admin/info.png"></img>'+

		'</td>'+
		'</tr>';
				

		if ((g_Ezserver_Version == ENTERPRISE) || (g_Ezserver_Version == BALANCER) || (g_Ezserver_Version == BLOCKCHAIN_STANDARD))
		{
			str+='<tr>'+
			'<td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Streaming port</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="httpport" id="httpport" size="16"/></font>'+
			'&nbsp;<img  align="center" title="for VLC, IPTV Smarter" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'<td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">RTMP Streaming port</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="rtmpport" id="rtmpport" size="16"/></font>'+
			'&nbsp;<img  align="center" title="RTMP Streaming Port for players" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'</tr>'+
	
			 '<tr><td id=Multicast_Section_HR colspan="4"><hr size="1" color="#66FFFF"></td></tr>'+
			'<tr id=Multicast_Section><td>'+
			'<p align="left"><font face="Arial" size="2"><b>Multicasting Streaming Setting</b></font>'+
			'</td></tr>'+
			'<tr id=Multicast_Section_IP><td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Multicast Output IP</font>'+
			'</p>'+
			'</td>'+      
			'<td><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="igmpip" id="igmpip" size="16"/></font>'+
			'&nbsp;<img  align="center" title="Local Network Streaming as Hotel, Hospital, (0.0.0.0: disabled)" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
	
	
			'<td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Multicast Output Port</font>'+
			'</p>'+
			'</td>'+      
			'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="igmpport" id="igmpport" size="16"/></font>'+
			'&nbsp;<img  align="center" title="Multicasting Streaming Port for players" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'</tr>';
	
			
		}else if ((g_Ezserver_Version==BLOCKCHAIN_PUBLIC) || g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
		{
			str+='<tr>'+
			'<td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Streaming port</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="httpport" id="httpport" size="16"/></font>'+
			'&nbsp;<img  align="center" title="for VLC, IPTV Smarter" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
	
			'<td width="25%" height="23">'+
			'</td>'+
			'<td width="25%" height="23">'+
			'</td>'+
			'</tr>'+
	
			 '<tr><td colspan="4"><hr size="1" color="#66FFFF"></td></tr>'+
			'<tr><td>'+
			'<p align="left"><font face="Arial" size="2"><b>Blockchain Setting</b></font>'+
			'</td></tr>'+
			'<tr><td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Region</font>'+
			'</p>'+
			'</td>'+      
			'<td><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="blockchain_server_region" id="blockchain_server_region" size="16"/></font>'+
			'&nbsp;<img  align="center" title="Server IP Location" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
	
	
			'<td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Group ID</font>'+
			'</p>'+
			'</td>'+      
			'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="blockchain_server_group" id="blockchain_server_group" size="16"/></font>'+
			'&nbsp;<img  align="center" title="Server Group" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'</tr>'+
	
			'<tr>'+
			'<td width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Main / Slave Node</font>'+
			'</p>'+
			'</td>'+      
			'<td height="23"><p align="left">'+
			'<label class="switch"><input type="checkbox" id="blockchain_node_type" onchange=switch_main_slave()><span class="slider round"></span></label>'+
			'&nbsp;<img style="margin-top: 30px;" align="center" title="Enable Main Node" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'<td id=blockchain_server_port_text width="25%" height="23">'+
			'</td>'+
			'<td width="25%" height="23">'+
			'</td>'+
			'</tr>'+
			'<tr>'+
			'<td id=blockchain_server_port_text width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Control port</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="blockchain_server_port" id="blockchain_server_port" size="16"/></font>'+
			'&nbsp;<img id=blockchain_server_port_img align="center" title="Blockchain Port for Slave Node connection" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'<td id=blockchain_streaming_port_text width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Streaming port</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="blockchain_streaming_port" id="blockchain_streaming_port" size="16"/></font>'+
			'&nbsp;<img id=blockchain_streaming_port_img align="center" title="Blockchain Streaming Port fore connection" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'</tr>'+
			'<tr id="blockchain_server_port_hr">'+
			'<td id=blockchain_main_dns_text width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Main Node Domain Name / IP</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="blockchain_main_dns" id="blockchain_main_dns" size="16"/></font>'+
			'&nbsp;<img id=blockchain_main_dns_img align="center" title="Main Node Location" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+

			'<td id=blockchain_main_port_text width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Main Control port</font></p>'+
			'</td>'+
			'<td width="25%" height="23"><p align="left"> <font size="2"> <input  style="padding: 5px;height:30;" type="text" name="blockchain_main_port" id="blockchain_main_port" size="16"/></font>'+
			'&nbsp;<img id=blockchain_main_port_img align="center" title="Main Node Control port" width=12 height=12 src="/admin/info.png"></img>'+
			'</td>'+
			'</tr>';
		}
				
		str+='<tr><td  colspan="4"><hr size="1" color="#66FFFF"></td></tr>'+
		'<tr><td>'+
		'<p align="left"><font face="Arial" size="2"><b>Channel Setting:</b></font>'+
		'</td></tr>'+
		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Channel Input Buffer No.</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="ch_input_buffer_no" id="ch_input_buffer_no" size="16"/></font>'+
		'&nbsp;<img  align="center" title="Cache for input streaming" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+

		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Channel Streaming Prebuffer No.</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="ch_streaming_prebuffer_no" id="ch_streaming_prebuffer_no" size="16"/></font>'+
		'&nbsp;<img  align="center" title="Speed up channel zapping time, the value must be smaller than Channel Input Buffer No." width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+
		'</tr>';


		/*
		if (g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
		{
			str+='<tr>'+
			'<td for="ToleranceSlider" width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Video Input Quality</font>'+
			'</p>'+
			'</td>'+ 
			'<td>'+
			'<font face="Arial" size="2">SD <input type="range" id="ToleranceSlider" min="0" max="1" step="0.01" value="0.0" />'+
			'<span id="ToleranceValue">0.0</span></font>'+
			'</td>'+     
			'<td for="ToleranceSlider" width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Dynamic Streaming Rate</font>'+
			'</p>'+
			'</td>'+ 
			'<td>'+
			'<font face="Arial" size="2"><input type="range" id="DSPSlider" min="0" max="1" step="0.01" value="0.0" />'+
			'<span id="DSPValue">0.0</span></font>'+
			'</td>'+     
	
			'</tr>'+
	
			'<tr>'+
			'<td for="ReconnectionSlider" width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Channel Reconnection Interval</font>'+
			'</p>'+
			'</td>'+      
			'<td>'+
			'<font face="Arial" size="2"><input type="range" id="ReconnectionSlider" min="0" max="60" step="1" value="0" />'+
			'<span id="ReconnectionValue">0 sec.</span></font>'+
			'</td>'+     
	
			'<td id="DSPNote" style="text-indent: 5" colspan=2 width="50%" height="23">'+
			'</td>'+     
			'</tr>';
		}else
		{
			*/
			str+='<tr>'+
			'<td for="ToleranceSlider" width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Video Input Quality</font>'+
			'</p>'+
			'</td>'+ 
			'<td>'+
			'<font face="Arial" size="2">SD <input type="range" id="ToleranceSlider" min="0" max="0.99" step="0.01" value="0.0" />'+
			'<span id="ToleranceValue">0.0</span></font>'+
			'</td>'+     
			'<td for="ReconnectionSlider" width="25%" height="23">'+
			'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Channel Reconnection Interval</font>'+
			'</p>'+
			'</td>'+      
			'<td>'+
			'<font face="Arial" size="2"><input type="range" id="ReconnectionSlider" min="0" max="60" step="1" value="0" />'+
			'<span id="ReconnectionValue">0 sec.</span></font>'+
			'</td>'+     
			'</tr>';
		//}
		

		str+='<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">DVR Duration</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="dvr_duration" id="dvr_duration" size="16"/></font>'+
		'&nbsp;<img  align="center" title="Record live streams, Unit: minute" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+
		
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">UDP EPG Extraction</font>'+
		'</p>'+
		'</td>'+      
		'<td height="23"><p align="left">'+
		'<label class="switch"><input type="checkbox" id="extract_ts_epg"><span class="slider round"></span></label>'+
		'&nbsp;<img style="margin-top: 30px;" align="center" title="Value: 0 (disabled), 1 (Extract EPG program from UDP input streams)" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+

		'</tr>';


		str+='<tr><td  colspan="4"><hr size="1" color="#66FFFF"></td></tr>'+
		'<tr><td>'+
		'<p align="left"><font face="Arial" size="2"><b>System Setting:</b></font>'+
		'</td></tr>'+
		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Max. Streaming No.</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="max_streaming_no" id="max_streaming_no" size="16"/></font>'+
		'</font>'+ 
		'<font size="2">'+
		'</td>'+

		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Pagination Limit Number</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="pagination_limit_no" id="pagination_limit_no" size="16"/></font>'+
		'&nbsp;<img  align="center" title="Pagination Limit Number for Channel/Movie/User Window" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+
		'</tr>'+

		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">System Log Lines</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="system_log" id="system_log" size="16"/></font>'+
		'&nbsp;<img  align="center" title="Value: 0 (disabled), 1 (enabled), xxxx (xxxx lines)" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Admin. System Log Lines</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="admin_system_log" id="admin_system_log" size="16"/></font>'+
		'</font>'+
		'&nbsp;<img  align="center" title="Value: 0 (disabled), 1 (enabled), xxxx (xxxx lines)" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+
		'</tr>'+



		 '<tr><td  colspan="4"><hr size="1" color="#66FFFF"></td></tr>'+
		'<tr><td>'+
		'<p align="left"><font face="Arial" size="2"><b>Security Setting:</b></font>'+
		'</td></tr>'+

		'<tr>'+
		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Alert Player Duration</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="alert_player_duration" id="alert_player_duration" size="16"/></font>'+
		'&nbsp;<img  align="center" title="for longer time connection, Unit: hours" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+

		'<td width="25%" height="23">'+
		'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Blacklist Option</font>'+
		'</p>'+
		'</td>'+      
		'<td width="25%" height="23">'+
		'<label class="switch"><input type="checkbox" id="blacklist"><span class="slider round"></span></label>'+
		//'<p align="left"> <font face="Arial"> <font size="2"> <input style="padding: 5px;height:30;" type="text" name="blacklist" id="blacklist" size="16"/></font>'+
		'&nbsp;<img style="margin-top: 30px;" align="center" title="moniotor and block illegal IP" width=12 height=12 src="/admin/info.png"></img>'+
		'</td>'+
		'</tr>'+


		

		
		'<tr>'+
		'<td colspan=4 align=center><input type="button" style="margin-top:10px;width:50%;height:40;background-color: #5089DE;color: #ffffff;"  value=Save onclick="javascript:save_setting();" name="Save" /></td>'+
		
		'</font>'+
		'</td>'+  
		'</tr>'+
		'</table>';
		content.innerHTML=str;
	   	g_token=find_cookie_value("token");
		if (g_token!=0)
		{
			 xmlHttp.open("GET", url, true);
			 xmlHttp.onreadystatechange = function(){
			 	
			 	if (xmlHttp.readyState == 4) {
				    var response= xmlHttp.responseText.split("\r\n");
					i=0;
				     document.getElementById("http_base_port").value =response[0];
				     document.getElementById("http_apps_port").value =response[1];
				    document.getElementById("httpport").value =response[2];
				    g_httpport=response[2];
				   // document.getElementById("rtsp_base_port").value =response[3];
				   if ((g_Ezserver_Version == ENTERPRISE) || (g_Ezserver_Version == BALANCER) || (g_Ezserver_Version == BLOCKCHAIN_STANDARD))
				   {
					document.getElementById("igmpip").value =response[4];
					document.getElementById("igmpport").value =response[5];
					document.getElementById("rtmpport").value =response[6];
				     
				    }else if ((g_Ezserver_Version==BLOCKCHAIN_PUBLIC) || g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
				    {
					    document.getElementById("blockchain_server_region").value =response[4];
					    document.getElementById("blockchain_server_group").value =response[5];
					    document.getElementById("blockchain_server_port").value =response[6];
					    //alert(response[28]);
					    if (response[28].length>0)
					    {
					    	document.getElementById("blockchain_node_type").checked=false;
					    	//document.getElementById("blockchain_server_port_text").style="display: none;";
					    	//document.getElementById("blockchain_server_port_img").style="display: none;";
					    	//document.getElementById("blockchain_server_port").style="display: none;";
					    }else
					    {
					    	document.getElementById("blockchain_node_type").checked=true;
					    	document.getElementById("blockchain_server_port_hr").style="display: none;";
					    }
				    }


				    document.getElementById("ch_input_buffer_no").value =response[7];
				    document.getElementById("ch_streaming_prebuffer_no").value =response[8];
				    //document.getElementById("ch_streaming_bitrate_tolerance").value =response[9];
				    
				         // Get references to the slider and value elements
				    const ToleranceSlider = document.getElementById("ToleranceSlider");
				    const ToleranceValue = document.getElementById("ToleranceValue");
				
				    ToleranceSlider.value=response[9];
				    g_ToleranceRatio = parseFloat(ToleranceSlider.value).toFixed(2);
				    // Set the initial value based on the default value of the slider
				    let ToleranceRatio = parseFloat(ToleranceSlider.value).toFixed(2);
				   // ToleranceValue.style.fontFamily ="Arial";
				   // ToleranceValue.style.fontSize="16px";
				    ToleranceValue.textContent = "HD ("+`${ToleranceRatio}`+")";
				
				    // Add an event listener to the slider to update the value when changed
				    ToleranceSlider.addEventListener("input", function () {
				      g_ToleranceRatio = parseFloat(this.value).toFixed(2);
				      ToleranceValue.textContent = "HD ("+`${g_ToleranceRatio}`+")";
				    });

				    
				    document.getElementById("max_streaming_no").value =response[10];
				    document.getElementById("system_log").value =response[11];
				    document.getElementById("admin_system_log").value =response[12];
				    document.getElementById("pagination_limit_no").value =response[13];
				   //document.getElementById("transcoder_path").value =response[14];
				    
				   // document.getElementById("ch_reconnection_interval").value =response[15];
				    
				        // Get references to the slider and value elements
				    const ReconnectionSlider = document.getElementById("ReconnectionSlider");
    				    const ReconnectionValue = document.getElementById("ReconnectionValue");
				    
				    ReconnectionSlider.value=response[15];
				    g_ReconnectionRatio = parseFloat(ReconnectionSlider.value);
				    // Set the initial value based on the default value of the slider
				    let ReconnectionRatio = parseFloat(ReconnectionSlider.value);
				    ReconnectionValue.textContent = `${ReconnectionRatio}`+' sec.';
				
				    // Add an event listener to the slider to update the value when changed
				    ReconnectionSlider.addEventListener("input", function () {
				      g_ReconnectionRatio = parseFloat(this.value);
				      ReconnectionValue.textContent = `${g_ReconnectionRatio}`+' sec.';
				    });

				    document.getElementById("alert_player_duration").value =response[16];
				    //document.getElementById("blacklist").value =response[17];
				    if (response[17]==1)
				    {
				    	document.getElementById("blacklist").checked=true;
				    }else
				    {
				    	document.getElementById("blacklist").checked=false;
				    }
				    document.getElementById("dvr_duration").value =response[18];
				   // document.getElementById("extract_ts_epg").value =response[19];
				    if (response[19]==1)
				    {
				    	document.getElementById("extract_ts_epg").checked=true;
				    }else
				    {
				    	document.getElementById("extract_ts_epg").checked=false;
				    }
				    	

				   // document.getElementById("xmltv_epg_url").value =response[20];
				    i=20;
					if (g_Ezserver_Version==BLOCKCHAIN_PUBLIC)
					{
						i++;
						i++;
						i++;
						i++;
						 document.getElementById("blockchain_server_region").disabled=true;
						 document.getElementById("blockchain_server_group").disabled=true;
					}else if (g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
					{
						i++;
						i++;
						i++;

						
						document.getElementById("blockchain_streaming_port").value =response[i];
						i++;
					}else if ((g_Ezserver_Version == ENTERPRISE) || (g_Ezserver_Version == BALANCER) || (g_Ezserver_Version == BLOCKCHAIN_STANDARD))
					{
						i++;
						i++;
						i++;
						i++;

					}else if (g_Ezserver_Version == BLOCKCHAIN_STANDARD)
					{
						
						i++;
						//p2p_streaming=response[i];
							
						//alert(p2p_streaming);
						
						//if (p2p_streaming==1)
						//{
						//    document.getElementById("p2p_option").checked=true;
						//}
						
						i++;
						//alert(response[i]);
						//p2p_cmd_port=response[i];
						//document.getElementById("p2p_cmd_port").value =p2p_cmd_port;
						
						i++;
						//p2p_data_port=response[i];
						//document.getElementById("p2p_data_port").value =p2p_data_port;
						
					 	i++;
						
						//g_P2P_DisableKey=response[i];
						
						//if (g_P2P_DisableKey=="1")
						//{
							
						//	 document.getElementById("P2P_Section_HR").style="display: none;";
						//	 document.getElementById("P2P_Section_Port").style="display: none;";
						//	 document.getElementById("P2P_Section").style="display: none;";
						//}
						 document.getElementById("Multicast_Section_HR").style="display: none;";
						 document.getElementById("Multicast_Section").style="display: none;";
						 document.getElementById("Multicast_Section_IP").style="display: none;";
					}
					i++;	
				     document.getElementById("https_base_port").value =response[i];
				     i++;
				     document.getElementById("https_apps_port").value =response[i];
				     i++;
				    document.getElementById("https_port").value =response[i];
				    i++;
				    //alert(response[28]);
				    if (g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
				    {
				    	    if (response[28].length>0)
					    {
					    	
					    	document.getElementById("blockchain_main_dns").value=response[i];i++;
					    	document.getElementById("blockchain_main_port").value=response[i];i++;
					    }else
					    {
					    	i++;
					    	i++;
					    }
					    /*
					    // Get references to the slider and value elements
					    const DSPSlider = document.getElementById("DSPSlider");
					    const DSPValue = document.getElementById("DSPValue");
					    DSPSlider.value=response[i];
					    //alert(response[i]);
					    g_DSPRatio = parseFloat(DSPSlider.value).toFixed(2);
					    
					    i++;
					
					    // Set the initial value based on the default value of the slider
					    let DSPRatio = parseFloat(DSPSlider.value).toFixed(2);
					    var nThreadholdConnection=parseInt(parseFloat(document.getElementById("max_streaming_no").value)*parseFloat(DSPRatio));
					    var nThreadholdConnection1=parseInt(document.getElementById("max_streaming_no").value)-nThreadholdConnection;
					    DSPValue.textContent = `${DSPRatio}`;
					    document.getElementById("DSPNote").innerHTML='<font face="Arial" size="2">( System switches to P2P mode up to <b>'+ nThreadholdConnection1 +'</b> connections. )'+'</font>';
					
					    // Add an event listener to the slider to update the value when changed
					    DSPSlider.addEventListener("input", function () {
					      g_DSPRatio = parseFloat(this.value).toFixed(2);
					      nThreadholdConnection=parseInt(parseFloat(document.getElementById("max_streaming_no").value)*parseFloat(g_DSPRatio));
					      nThreadholdConnection1=parseInt(document.getElementById("max_streaming_no").value)-nThreadholdConnection;
					    document.getElementById("DSPNote").innerHTML='<font face="Arial" size="2">( System switches to P2P mode up to <b>'+ nThreadholdConnection1 +'</b> connections. )'+'</font>';
					      DSPValue.textContent = `${g_DSPRatio}`;
					    });
					    */

				    }
				    

			//   call_user_authorization_mode();
				
				  //   show_uptime();
				 
				 	//g_server_timer=setInterval(function(){show_uptime()},300*1000);
				 
				  }
			 }
			 xmlHttp.send(null);
		}
	

}
/*
function callServer_P2PSetting()
{
	
	var url = "/server/get_p2p_config?token="+encodeURI(g_token)+"&flag="+Math.random();
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function(){
			var content_str = parent.document.getElementById("content");
			var response= xmlHttp.responseText.split("\r\n");
			var p2p_streaming;
			var p2p_connection;	
			if (xmlHttp.readyState == 4) 
			{
				str='<p align="left" style="margin-top: 5; margin-left: 25"><table border="0" cellpadding="0" cellspacing="5" border>'+
					'<tr>'+
					'<td height="23">'+
					'<p align="left" style="margin-left: 5; margin-top: 10"><font face="Arial"><button class="button button2" onclick="javascript:save_p2psetting();" name="B1" />Save</button>'+
					'<td height="23">'+
					'</td>'+  
			
					'</font>'+
					'</td>'+  
					'</tr>'+
					
					
					'<tr>'+
					'<td width="120" height="23">'+
					'<p align="left" style="text-indent: 5"><font face="Arial" size="2">1. Routecast:</font>'+
					'</p>'+
					'</td>'+ 
					'<td><label class="switch"><input type="checkbox" id="p2p_option"><span class="slider round"></span></label>'+     
					
					'</td>'+
					
					'</tr>'+
			
					'<tr>'+
					'<td width="240" height="23">'+
					'<p align="left" style="text-indent: 5"><font face="Arial" size="2">2. P2P Cmd Port :</font>'+
					'</p>'+
					'</td>'+      
					'<td width="20" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input type="text" name="p2p_cmd_port" id="p2p_cmd_port" size="2"/></font>'+
					'</font>'+
					'</td>'+
					'</tr>'+
					'<tr>'+
					'<td width="240" height="23">'+
					'<p align="left" style="text-indent: 5"><font face="Arial" size="2">3. P2P Data Port :</font>'+
					'</p>'+
					'</td>'+      
					'<td width="20" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input type="text" name="p2p_data_port" id="p2p_data_port" size="2"/></font>'+
					'</font>'+
					'</td>'+
					'</tr>'+
					
					'</table>';
				content_str.innerHTML=str;
				
				var strlength=response[0].length;
			 	
			 	
		   	    	p2p_streaming=response[0].slice(14,strlength);
		     	 	//alert(p2p_streaming);
		   	    	
				if (p2p_streaming==1)
				{
				    document.getElementById("p2p_option").checked=true;
				}
				strlength=response[1].length;
			 	p2p_cmd_port=response[1].slice(13,strlength);
				document.getElementById("p2p_cmd_port").value =p2p_cmd_port;
				
				strlength=response[2].length;
			 	p2p_data_port=response[2].slice(14,strlength);
				document.getElementById("p2p_data_port").value =p2p_data_port;
				
				
		
			}
		};
		 xmlHttp.send(null);
	}
	

}
*/
/* function callServer_Wallet()
{
	
	var url = "/server/get_wallet?token="+encodeURI(g_token)+"&flag="+Math.random();
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function(){
			var content_str = parent.document.getElementById("content");
			var response= xmlHttp.responseText.split("\r\n");
			var bitcoin_addr;
			if (xmlHttp.readyState == 4) 
			{
				str='<p align="left" style="margin-top: 5; margin-left: 25"><table border="0" cellpadding="0" cellspacing="5" border>'+
					'<tr>'+
					'<td height="23">'+
					'<p align="left" style="margin-left: 5; margin-top: 10"><font face="Arial"><button class="button button2" onclick="javascript:save_wallet();" name="B1" />Save</button>'+
					'<td height="23">'+
					'</td>'+  
			
					'</font>'+
					'</td>'+  
					'</tr>'+
					
					
			
					'<tr>'+
					'<td width="240" height="23">'+
					'<p align="left" style="text-indent: 5"><font face="Arial" size="2">My Bitcoin Address :</font>'+
					'</p>'+
					'</td>'+      
					'<td width="200" height="23"><p align="left"> <font face="Arial"> <font  size="2"> <input type="text" name="bitcoin_addr" id="bitcoin_addr" size="35"/></font>'+
					'</font>'+
					'</td>'+
					'</tr>'+

					
					'</table>';
				content_str.innerHTML=str;
				
				var strlength=response[0].length;
			 	
			 	
		   	    	bitcoin_addr=response[0].slice(8,strlength);
		     	 	//alert(bitcoin_addr);
		     	 	document.getElementById("bitcoin_addr").value =bitcoin_addr;
		     	 	if (bitcoin_addr=="3Eq2dRU87gMaGp8f7Cm3KFHXnkMp3j5pSp")
		     	 	{
		     	 		document.getElementById("bitcoin_addr").style.color = "#cccccc";
		     	 	}
		   	    					
		
			}
		};
		 xmlHttp.send(null);
	}
	

}
function save_wallet() {
  var bitcoin_addr = document.getElementById("bitcoin_addr").value;
  g_token=find_cookie_value("token");

  	
  var url = "/server/save_wallet?token="+encodeURI(g_token)+"&bitcoin=" + bitcoin_addr+"&flag="+Math.random();
	if (g_token!=0)
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function(){
		
			if (xmlHttp.readyState == 4) {
				var response = xmlHttp.responseText;
				alert(response);
			}
		};
		xmlHttp.send(null);
		
	}
}
*/
function save_p2psetting() {
  // Get the city and state from the web form
  var p2p_switch=0;
  var p2p_cmd_port = document.getElementById("p2p_cmd_port").value;
  var p2p_data_port = document.getElementById("p2p_data_port").value;
  g_token=find_cookie_value("token");

  if (document.getElementById("p2p_option").checked)
  {
  	p2p_switch=1;
  }
 
  	
  var url = "/server/save_p2p_config?token="+encodeURI(g_token)+"&p2p_switch=" + p2p_switch+"&p2p_cmd_port=" + p2p_cmd_port+"&p2p_data_port=" + p2p_data_port+"&flag="+Math.random();
	if (g_token!=0)
	{
		xmlHttp.open("GET", url, true);
		xmlHttp.onreadystatechange = function(){
		
			if (xmlHttp.readyState == 4) {
				var response = xmlHttp.responseText;
				alert(response);
			}
		};
		xmlHttp.send(null);
		
	}
}
function callServer_Init()
{	
	var url = "/server/get_config?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		 xmlHttp.open("GET", url, true);
		 xmlHttp.onreadystatechange = Init_Config;
		 xmlHttp.send(null);
	}
}

function login()
{
	var cgi_url;
	var encrypt_str;
	var userid_pass;
	g_user_id = document.getElementById("user_id").value;
	g_password = document.getElementById("password").value;
	userid_pass=g_user_id+':'+g_password;
	encrypt_str=encode64(userid_pass);
	
	
	//g_server_http_ip_port="http://"+g_current_serverip+":"+g_current_panelport;
	
	//cgi_url = g_server_http_ip_port+"/token/createtokenbased64?encrpty="+encodeURI(encrypt_str)+"&flag="+Math.random();
	cgi_url = "/token/createtokenbased64?encrpty="+encodeURI(encrypt_str)+"&flag="+Math.random();
	xmlHttp.open("GET", cgi_url);
	xmlHttp.onreadystatechange = function(){
		var login_status = document.getElementById("login_status");
		var login_password_text = document.getElementById("login_password_text");
		
		var browser_name;
		//var content = parent.document.getElementById("main_screen");
		
		if (xmlHttp.readyState == 4) 
		{
        		
			var response = xmlHttp.responseText;
			if (response.search("-1")>0)
			{
				id_check_flag=0;
				login_status.innerHTML='<p style="margin-left: 25; margin-top: 0"><font face="Arial" size="2" color="#ff0000"><b>Parameter error.</b></font>';
			} else if (response.search("-2")>0)
			{
				id_check_flag=0;
				login_password_text.innerHTML='<p style="margin-left: 25; margin-top: 0"><font face="Arial" size="2" color="#ff0000">Enter your passowrd</font>';
				login_status.innerHTML='<p style="margin-left: 25; margin-top: 0"><font face="Arial" size="2" color="#ff0000"><b>Wrong user name or password.</b></font>';
				
				
			} else if (response.search("-3")>0)
			{
				id_check_flag=0;
				login_status.innerHTML='<p style="margin-left: 25; margin-top: 0"><font face="Arial" size="2" color="#ff0000"><b>User time expired. Contact panel owner.</b></font>';
			} 
			else if (response.search("-4")>0)
			{
				get_license_key();
			}
			else {
				
					g_token=response.slice(6,response.length-2);
					add_cookie_value("token",g_token);
					add_cookie_value("userid",g_user_id);
					add_cookie_value("password",g_password);
					id_check_flag=1;
					get_balancer();
					//callServer_Init();
				
			}
		}
	
	};
	
	xmlHttp.send(null);
}
/*
function ClearUsernameInput()
{
	document.getElementById("user_id").value='';
	document.getElementById("user_id").style.opacity=1;
}
function ClearPasswordInput()
{
	document.getElementById("password").type="password";
	document.getElementById("password").value='';
}
*/
function ShowPassword()
{
	x=document.getElementById("password");
	if (x.type === "password") {
	    x.type = "text";
	  } else {
	    x.type = "password";
	  }
}
/* 
function login_dialog()
{
	var main_screen= document.getElementById("main_screen");
	var str="";
	
	if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
		bMobileDevice=1;
	}
	
	
	if (bMobileDevice)
	{
		str='<p style="margin-top: 50%;"></p>';
	}else
	{
		str='<p style="margin-top: 10%;"></p>';
	}
		str+='<div align="center">'+
		  '<table id=login_rcorners align="center" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">'+
		    '<tr>'+
		      '<td width="100%" bordercolorlight="#DFDFDF" bordercolordark="#F3F3F3" height="100%" valign="middle">'+
		        '<div align="center">'+
		          '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="481">'+
		            '<tr>'+
		              '<td align="center" height="30">'+
		                '<p style="margin-left: 0"><b><font face="Arial" color="#0000bb" size="7">Ezserver</font></b></td>'+
		            '</center>'+
		            
		          '</tr>'+
		            '<tr>'+
		              '<td align="center" height="30">'+
		                '<p style="margin-left: 0"><font face="Arial" color="#888888" size="4">Admin Only</font></td>'+
		            '</center>'+
		            
		          '</tr>'+
		          
		          '<center>'+
		          '<tr>'+
		            '<td width="100%">'+
		              '<p style="margin-left: 25";margin-top: -20"><font face="Arial" size="2" color="#679DF6">Username</font></td>'+
		          '</tr>'+
		          
		          '<tr>'+
		            '<td width="100%">'+
		              '<p style="margin-left: 25;margin-top: -10"><input autofocus type="text" id="user_id" size="50" style="text-indent: 5;height:40;background-color: #FAFFBD; opacity:0.5;color: #000000; border-style: solid; border-width: 1" placeholder="Enter Your Username"></p>'+
		              '</td>'+
		          '</tr>'+
		          
		          '<tr>'+
		            '<td id="login_password_text" width="100%">'+
		             '<p style="margin-left: 25;margin-top: -5"><font face="Arial" size="2" color="#679DF6">Password</font></td>'+
		          '</tr>'+
		          
		          '<tr>'+
		            '<td width="100%">'+
		                '<p style="margin-left: 25;margin-top: -20; margin-right: 25; margin-bottom: 0"><input type="password" id="password" size="50" style="text-indent: 5;height:40;color: #679DF6; background-color: #cccccc; border-style: solid; border-width: 1" placeholder="Enter Your Password"><br><br><input type="checkbox" onclick="ShowPassword()"><font face="Arial" style="font-size:12px;">Show Password</font></p>'+
		              '</td>'+
		          '</tr>'+
		         
		          '<tr>'+
		            '<td id="login_status" width="100%">'+
		             '<p style="margin-left: 25;margin-top: -5"><font face="Arial" size="2" color="#ff0000"></font></td>'+
		          '</tr>'+
	
		          '<tr>'+
		            
		          '<td width="100%">'+
		       	    '<p align="left" style="margin-left: 25; margin-right: 25;;margin-top: -5"><button style="width:100%;height:50;" class="button button3" onclick="javascript:login();" name="Login" />LOGIN</button>'+
			    '</td>'+
		          '</tr>'+
		          
		        '</table>'+
		      '</div>'+
		    '</td>'+
		  '</tr>'+
		  '</table>'+
		  '<table>'+
		          '<tr>'+
		            '<td width="50%" valign="bottom" height="71">'+
		              '<p align="center"><font size="2" color="#679DF6" face="Arial">Ezhometech Inc.</font></td>'+
		          '</tr>'+'</table>';
		'</div>';
		
	

	main_screen.innerHTML=str;
	
	
}
*/
function login_dialog() {
    var main_screen = document.getElementById("main_screen");
    var str = "";

    bMobileDevice = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ? 1 : 0;

 
    if (bMobileDevice) 
    {
      str += '<div style="display: flex; justify-content: center; align-items: center; min-height: 100vh; width: 100%;">' +  
	   '<table id="login_rcorners" cellpadding="0" cellspacing="0" style="border:0; width: 100%; padding: 0; margin: 0;">' +  
	   '<tr>' +  
	   '<td style="width: 100%; text-align: center; vertical-align: middle; background-color: #ffffff;">' +  
	   '<table cellpadding="0" cellspacing="0" style="border:0; width: 100%; padding: 0; margin: 0;">';

	// Enlarged Title (Double Size)
	str += '<tr>' +  
	       '<td align="center" height="60" style="padding: 20px;">' +  
	       '<p style="margin: 10px 0;"><b><font face="Arial" color="#0000bb" style="font-size: 96px;">Ezserver</font></b></p>' +  
	       '</td>' +  
	       '</tr>';
	
	// Enlarged Subtitle (Double Size)
	str += '<tr>' +
	       '<td align="center" height="60">' +
	       '<p><font face="Arial" color="#888888" style="font-size: 48px;">Admin Only</font></p>' +
	       '</td>' +
	       '</tr>';
	
	// Enlarged Username Label (Double Size)
	str += '<tr>' +
	       '<td width="100%" style="padding: 10px;">' +
	       '<p style="margin-left: 50px;"><font face="Arial" style="font-size: 40px; color:#679DF6;">Username</font></p>' +
	       '</td>' +
	       '</tr>';
	
	// Enlarged Input Field (Double Size)
	str += '<tr>' +
	       '<td width="100%" style="padding: 50px;">' +
	       '<p><input autofocus type="text" id="user_id" style="width:100%; height:80px; background-color: #FAFFBD; border: 2px solid #ccc; padding: 20px; font-size: 40px;" placeholder="Enter Your Username"></p>' +
	       '</td>' +
	       '</tr>';
	
	// Enlarged Password Label (Double Size)
	str += '<tr>' +
	       '<td width="100%" style="padding: 10px;">' +
	       '<p style="margin-left: 50px;"><font face="Arial" style="font-size: 40px; color:#679DF6;">Password</font></p>' +
	       '</td>' +
	       '</tr>';
	
	// Enlarged Password Field (Double Size)
	str += '<tr>' +
	       '<td width="100%" style="padding: 50px;">' +
	       '<p>' +
	       '<input type="password" id="password" style="width:100%; text-indent: 10px; height:80px; color: #679DF6; background-color: #cccccc; border-style: solid; border-width: 2px; font-size: 40px;" placeholder="Enter Your Password">' +
	       '<br><br>' +
	       '<input type="checkbox" onclick="ShowPassword()" style="width:30px; height:30px;">' +
	       '<font face="Arial" style="font-size: 32px;">Show Password</font>' +
	       '</p>' +
	       '</td>' +
	       '</tr>';
	
	// Enlarged Login Button (Double Size)
	str += '<tr>' +
	       '<td width="100%" style="padding: 50px;">' +
	       '<p>' +'<button style="width:100%; height:100px; font-size: 48px;" class="button button3" onclick="javascript:login();" name="Login">LOGIN</button></p>' +
	       '</td>' +
	       '</tr>';
	
	// Enlarged Footer Text (Double Size)
	str += '<tr>' +
	       '<td align="center" width="100%" style="padding: 20px;">' +
	       '<p><font face="Arial" style="font-size: 36px; color:#679DF6;">Ezhometech Inc.</font></p>' +
	       '</td>' +
	       '</tr>';
	
	str += '</table>';	
	str += '</div>';


    }else
    {
       str += '<div style="margin-top: 10%;" align="center">' +
        '<table id="login_rcorners" align="center" border="0" cellpadding="0" cellspacing="0" width="100%" height="100%">' +
        '<tr>' +
        '<td width="100%" bordercolorlight="#DFDFDF" bordercolordark="#F3F3F3" height="100%" valign="middle">' +
        '<div align="center">' +
        '<table border="0" cellpadding="0" cellspacing="0" width="100%" height="481">';


        
       
       str +='<tr>' +  
       '<td align="center" height="30">' +  
       '<p><b><font face="Arial" color="#0000bb" size="7">Ezserver</font></b></p>' +  
       '</td>' +  
       '</tr>';

	    str += '<tr>' +
	        '<td align="center" height="30">' +
	        '<p><font face="Arial" color="#888888" size="4">Admin Only</font></p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '<tr>' +
	        '<td width="100%">' +
	        '<p style="margin-left: 25;"><font face="Arial" size="2" color="#679DF6">Username</font></p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '<tr>' +
	        '<td width="100%">' +
	        '<p style="margin-left: 25;margin-right: 25;"><input autofocus type="text" id="user_id"  style="width:100%;text-indent: 5; height:40; background-color: #FAFFBD; opacity:0.5; color: #000000; border-style: solid; border-width: 1" placeholder="Enter Your Username"></p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '<tr>' +
	        '<td id="login_password_text" width="100%">' +
	        '<p style="margin-left: 25;"><font face="Arial" size="2" color="#679DF6">Password</font></p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '<tr>' +
	        '<td width="100%">' +
	        '<p style="margin-left: 25;margin-right: 25;">' +
	        '<input type="password" id="password"  style="width:100%;text-indent: 5; height:40; color: #679DF6; background-color: #cccccc; border-style: solid; border-width: 1" placeholder="Enter Your Password">' +
	        '<br><br>' +
	        '<input type="checkbox" onclick="ShowPassword()">' +
	        '<font face="Arial" style="font-size:12px;">Show Password</font>' +
	        '</p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '<tr>' +
	        '<td id="login_status" width="100%">' +
	        '<p style="margin-left: 25;"><font face="Arial" size="2" color="#ff0000"></font></p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '<tr>' +
	        '<td width="100%">' +
	        '<p align="left" style="margin-left: 25; margin-right: 25;"><button style="width:100%; height:50px;" class="button button3" onclick="javascript:login();" name="Login">LOGIN</button></p>' +
	        '</td>' +
	        '</tr>';
	
	    str += '</table>' +
	        '</div>' +
	        '</td>' +
	        '</tr>' +
	        '</table>';
	
	    str += '<table width="100%">' +
	        '<tr>' +
	        '<td width="' + (bMobileDevice ? "100%" : "50%") + '" valign="bottom" height="71">' +
	        '<p align="center"><font size="2" color="#679DF6" face="Arial">Ezhometech Inc.</font></p>' +
	        '</td>' +
	        '</tr>' +
	        '</table>' +
	        '</div>';
        }

    main_screen.innerHTML = str;
}


function goto_line_no(panel_type){
	var total_no;
 	var line_no;
 	var goto_id;
	var i;
	var bFound=0;
	
	if(panel_type==1)
	{
		line_no = document.getElementById("title_search_field").value;
		total_no=g_total_ch_no;
		goto_id="chname";
	}else if(panel_type==2)
	{
		line_no = document.getElementById("title_search_field").value;
		total_no=g_total_movie_no;
		goto_id="moviename";
	}else if(panel_type==3)
	{
		line_no = document.getElementById("title_search_field").value;
		total_no=g_user_no;
		goto_id="username";
	}
	
	if (g_goto_item.value!=null)
	{
		g_goto_item.style.backgroundColor = "#ffffff";
	}
	for (i=1;i<=total_no;i++)
	{
		if (i==line_no)
		{
			goto_id=goto_id+i;
			g_goto_item= document.getElementById(goto_id);
			g_goto_item.focus();
			g_goto_item.style.backgroundColor = "#ffff00";
			bFound=1;
		}
		
	}
	if(bFound==0)
	{
		if (line_no==0)
		{
			i=1;
		}else
		{
			i=total_no;
		}
		goto_id=goto_id+i;
		g_goto_item= document.getElementById(goto_id);
		g_goto_item.focus();
		g_goto_item.style.backgroundColor = "#ffff00";
	
	}
}
function change_page_no()
{
	g_constant_limit=parseInt(document.getElementById("page_no").value);
	//alert(g_constant_limit);
	if (g_start_search_option==1)
	{
		Button_get_all_user();
	}else if (g_start_search_option==2)
	{
		Button_Server_CH_Inquery();
	}else if (g_start_search_option==3)
	{
		Button_Server_Movie_Inquery();
	}else if (g_start_search_option==4)
	{
		Button_Server_Series_Inquery();
	}else if (g_start_search_option==5)
	{
		calllist_auto_active_player_info(false);
	}else if (g_start_search_option==6)
	{
		Button_Server_XMLTV_Inquery();
	}
	
}

function CloseSearch()
{
	if (g_start_search_option==1)
	{
		g_SearchInput.value='Search Users...';
 	}else 	if (g_start_search_option==2)
	{
		g_SearchInput.value='Search Channels...';
 	}else 	if (g_start_search_option==3)
	{
		g_SearchInput.value='Search Movies...';
  	}else 	if (g_start_search_option==4)
	{
		g_SearchInput.value='Search Series...';
  	}else 	if (g_start_search_option==5)
	{
		g_SearchInput.value='Search Players...';
 	}
}
function ClearSearchInput() {
	
	if (g_start_search_option==1)
	{
		if (g_SearchInput.value=="Search Users...")
		{
			g_SearchInput.value='';
		 	g_SearchInput.style.opacity=1;
	 	}
 	}else 	if (g_start_search_option==2)
	{
		if (g_SearchInput.value=="Search Channels...")
		{
			g_SearchInput.value='';
		 	g_SearchInput.style.opacity=1;
	 	}
 	}else 	if (g_start_search_option==3)
	{
		if (g_SearchInput.value=="Search Movies...")
		{
			g_SearchInput.value='';
		 	g_SearchInput.style.opacity=1;
	 	}
  	}else 	if (g_start_search_option==4)
	{
		if (g_SearchInput.value=="Search Series...")
		{
			g_SearchInput.value='';
		 	g_SearchInput.style.opacity=1;
	 	}
  	}else 	if (g_start_search_option==5)
	{
		if (g_SearchInput.value=="Search Players...")
		{
			g_SearchInput.value='';
		 	g_SearchInput.style.opacity=1;
	 	}
 	}
 }
function SearchInput()
{
	if (g_start_search_option==1)
	{
		callServer_search_user();
	}else if (g_start_search_option==2)
	{
		callServer_search_channel();
	}else if (g_start_search_option==3)
	{
		callServer_search_movie();
	}else if (g_start_search_option==4)
	{
		callServer_search_series();
	}else if (g_start_search_option==5)
	{
		callServer_search_player();
	}else if (g_start_search_option==6)
	{
	}
}
function callServer_search_user() {
	var cgi_url;
	var searchvalue = g_SearchInput.value;
	var position=g_user_found_position+1;
	g_search_text=searchvalue;
	
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_users?token="+encodeURI(g_token)+"&position="+g_user_position+"&1imit="+g_user_limit+ "&searchvalue=" +searchvalue+"&flag="+Math.random();
		xmlHttp.open("GET", cgi_url, true);
		
		xmlHttp.onreadystatechange = get_users;
		xmlHttp.send(null);
	}

}

function callServer_search_channel() {
	var cgi_url;
	var searchvalue = g_SearchInput.value;
	var position=g_channel_found_position+1;
	g_search_text=searchvalue;
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_channels?token="+encodeURI(g_token)+"&position="+g_channel_position+"&limit="+g_channel_limit+ "&searchvalue=" +searchvalue+"&flag="+Math.random();
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = get_channels;
		xmlHttp.send(null);
	}

}
function callServer_search_movie() {
	var cgi_url;
	var searchvalue =g_SearchInput.value;
	var position=g_movie_found_position+1;
	g_search_text=searchvalue;
	
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_movies?token="+encodeURI(g_token)+"&position="+g_movie_position+"&limit="+g_movie_limit+ "&searchvalue=" +searchvalue+"&flag="+Math.random();
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = get_movies;
		xmlHttp.send(null);
	}

}
function callServer_search_series() {
	var cgi_url;
	var searchvalue =g_SearchInput.value;
	var position=g_series_found_position+1;
	g_search_text=searchvalue;
	
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_series?token="+encodeURI(g_token)+"&position="+g_series_position+"&limit="+g_series_limit+ "&searchvalue=" +searchvalue+"&flag="+Math.random();
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = get_series;
		xmlHttp.send(null);
	}

}
function callServer_all_player(){
	var position=1;
	var limit=g_constant_limit;
	g_search__player_text=null;
	g_active_connection_position=position;
	//alert(g_active_connection_position);
   	calllist_active_player_info(position,limit);
}
function callServer_search_player(){
 	var cgi_url;
	var searchvalue = g_SearchInput.value;
	var position=1;
	var limit=g_constant_limit;
	g_search_text=searchvalue;
	//g_search__player_text=searchvalue;
	//alert(g_search__player_text);
   	calllist_active_player_info(position,limit)

}

/*
function search_user(){
 	var user_id = document.getElementById("user_search_field").value;
	var i;
	var username_id;
	var username;
	var bFound=0;
	var bFirstFound=0;
	if (g_search_user_item.value!=null)
	{
		g_search_user_item.style.backgroundColor = "#ffffff";
	}
	for (i=1;i<=g_user_no;i++)
	{
		username_id="username"+i;
		username=document.getElementById(username_id).value;
		if (username.search(user_id)>=0)
		{
			g_search_user_item=document.getElementById(username_id);
			if (bFirstFound==0)
			{
				g_search_user_item.focus();
				bFirstFound=1;
			}
			g_search_user_item.style.backgroundColor = "#ffff00";
			bFound=1;
			//return;
		}else
		{
			g_search_user_item=document.getElementById(username_id);
			g_search_user_item.style.backgroundColor = "#ffffff";
		}
			
	}
	if(bFound==0)
	{
		alert("Not Found");
	}
}
*/
function search_channel_name(){
 	var channel_id = document.getElementById("channel_search_field").value;
	var i;
	var channelname_id;
	var channelname;
	var bFound=0;
	var bFirstFound=0;
	if (g_search_channel_item.value!=null)
	{
		g_search_channel_item.style.backgroundColor = "#ffffff";
	}
	for (i=1;i<=g_total_ch_no;i++)
	{
		channelname_id="chname"+i;
		channelname=document.getElementById(channelname_id).value;
		if (channelname.search(channel_id)>=0)
		{
			g_search_channel_item=document.getElementById(channelname_id);
			if (bFirstFound==0)
			{
				g_search_channel_item.focus();
				bFirstFound=1;
			}

			g_search_channel_item.style.backgroundColor = "#ffff00";
			bFound=1;
			//return;
		}else
		{
			g_search_channel_item=document.getElementById(channelname_id);
			g_search_channel_item.style.backgroundColor = "#ffffff";
		}
	}
	if(bFound==0)
	{
		alert("Not Found");
	}
}
function search_movie_name(){
 	var movie_id = document.getElementById("movie_search_field").value;
	var i;
	var moviename_id;
	var moviename;
	var bFound=0;
	var bFirstFound=0;
	//alert(movie_id);
	if (g_search_movie_item.value!=null)
	{
		g_search_movie_item.style.backgroundColor = "#ffffff";
	}
	for (i=1;i<=g_total_movie_no;i++)
	{
		moviename_id="moviename"+i;
		moviename=document.getElementById(moviename_id).value;
		//alert(moviename);
		if (moviename.search(movie_id)>=0)
		{
			g_search_movie_item=document.getElementById(moviename_id);
			if (bFirstFound==0)
			{
				g_search_movie_item.focus();
				bFirstFound=1;
			}
			g_search_movie_item.style.backgroundColor = "#ffff00";
			bFound=1;
			//return;
		}else
		{
			g_search_movie_item=document.getElementById(moviename_id);
			g_search_movie_item.style.backgroundColor = "#ffffff";
		}
	}
	if(bFound==0)
	{
		alert("Not Found");
	}
}
/*
function search_player(){
 	var player_id = document.getElementById("player_search_field").value;
	var i;
	var playername_id;
	var playername;
	var playerip_id;
	var playerip;
	var playermac_id;
	var playermac;
	var bFound=0;
	var bFirstFound=0;

	if (g_search_player_item.innerText!=null)
	{
		g_search_player_item.style.backgroundColor = "#CCFFFF";
	}
	for (i=1;i<=g_active_player_no;i++)
	{
		playername_id="username"+i;
		
		playername=document.getElementById(playername_id).innerText;
		if (playername.search(player_id)>=0)
		{
			g_search_player_item=document.getElementById(playername_id);
			if (bFirstFound==0)
			{
				g_search_player_item.focus();
				bFirstFound=1;
			}
			g_search_player_item.style.backgroundColor = "#ffff00";
			bFound=1;
			//return;
		}else
		{
			g_search_player_item=document.getElementById(playername_id);
			g_search_player_item.style.backgroundColor = "#CCE1E6";
		}
		playerip_id="userip"+i;
		
		playerip=document.getElementById(playerip_id).innerText;
		if (playerip.search(player_id)>=0)
		{
			g_search_player_item=document.getElementById(playerip_id);
			if (bFirstFound==0)
			{
				g_search_player_item.focus();
				bFirstFound=1;
			}
			g_search_player_item.style.backgroundColor = "#ffff00";
			bFound=1;
			//return;
		}else
		{
			g_search_player_item=document.getElementById(playerip_id);
			g_search_player_item.style.backgroundColor = "#CCE1E6";
		}
		playermac_id="usermac"+i;
		
		playermac=document.getElementById(playermac_id).innerText;
		if (playermac.search(player_id)>=0)
		{
			g_search_player_item=document.getElementById(playermac_id);
			if (bFirstFound==0)
			{
				g_search_player_item.focus();
				bFirstFound=1;
			}
			g_search_player_item.style.backgroundColor = "#ffff00";
			bFound=1;
			//return;
		}else
		{
			g_search_player_item=document.getElementById(playermac_id);
			g_search_player_item.style.backgroundColor = "#CCE1E6";
		}
			
	}
	if(bFound==0)
	{
		alert("Not Found");
	}
}
*/
function login_out_return() {
  
var ch_up_flag=0;
  
  if (xmlHttp.readyState == 4) 
  {
    var response = xmlHttp.responseText;
	//var content = parent.document.getElementById("content");
	//var detail = parent.document.getElementById("detail");

 /*        ch_up_flag=find_cookie_value("ch_up_flag");       
         if (ch_up_flag==1)
         {
         	callezserver_refresh_channel();
         	Clear_Channel_update();
         }*/
      /*   content.innerHTML='<table border="1" cellpadding="0" cellspacing="0" width="100%" height="451"><tr>'+
              '<td width="100%" height="449"><p align="center"><font face="Arial" size="5">EZserver Management</font></td>'+
              '</tr></table>';
         detail.innerHTML='';
*/
    	g_token=0;	
    	if (g_System_timer>0)
    	{
    		clearInterval(g_System_timer);
    		g_System_timer=0;
    		//clearInterval(g_Query_Channel_Status_timer);
    		//clearInterval(g_Query_Online_Player_timer);
    	}
 	Clear_cookie();
    // login_status.innerHTML="";
//     menu_main_title.innerHTML="";
	
	login_dialog();
 
   }

}
 window.onbeforeunload = function() {
	if (find_cookie_value("token"))
	{
        	return "Are you sure you want to leave?";
        }
        
    }


function logout()
{
	var cgi_url;
  //var login_status = document.getElementById("login_status");
   var confirm_msg="Logout?";
  var cookieStr;
  var firstpos;
  var endpos;
 	//var content = parent.document.getElementById("content");

	 if (confirm(confirm_msg))
	{
  
          // content.innerHTML='<p align="center" style="margin-top: 30"><font face="Arial" size="5">EZserver Management</font>';
	//content.innerHTML='';
     	g_token=find_cookie_value("token");
  	g_user_id=find_cookie_value("userid");
  	g_password=find_cookie_value("password");
 	 cgi_url = "/token/destroytoken?token="+encodeURI(g_token)+"&flag="+Math.random();
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = login_out_return;
	 xmlHttp.send(null);

	}
}

function init() {

       menu_top.innerHTML='<center><table border="0" cellpadding="0" cellspacing="0">'+
	   '<tr><td>'+
	   '<p style="text-indent: 5"><font face="Arial" size="2" color="#FFFFFF">User ID: </font></p>'+
	   '</td>'+      
	   '<td>'+ 
	   '<font face="Arial"> <font size="2"> <input type="text" name="user_id" id="user_id" size="20" value="root"/></font></font>'+
	   '</td>'+
	   
	   
	   '<td>'+
	   '<p style="text-indent: 5"><font face="Arial" size="2" color="#FFFFFF">Password: </font></p>'+    
	   '</td>'+ 
	                                   
	   '<td> <font face="Arial" size="2"> <input type="password" name="password" id="password" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="OK" onclick="javascript:login();" name="B1" /></font>'+
	   '</td></tr>'+
	   '</table>';
	   Clear_cookie();
	 //  streaming_port();

}
function show_drv_time_cur_time(timestamp)
{
	var cur_video_time=document.getElementById("cur_video_time");
	var dvr_video_time=document.getElementById("dvr_video_time");
	var d=new Date();
	
	var cur_sec=d.getTime();
	var cur_hours=d.getHours();
	var cur_minutes=d.getMinutes();
	var cur_seconds=d.getSeconds();
	var cur_time;

	var dvr_sec;
	var dvr_d;
	var dvr_hours;
	var dvr_minutes;
	var dvr_seconds;
	var dvr_time;
	g_cur_sec=cur_sec;

	g_dvr_sec+=1000;
	//dvr_sec=cur_sec-(g_current_timestamp-g_dvr_timestamp);
	dvr_d=new Date(g_dvr_sec);
	dvr_hours=dvr_d.getHours();
	dvr_minutes=dvr_d.getMinutes();
	dvr_seconds=dvr_d.getSeconds();
		
	
	cur_time= (cur_hours < 10 ? "0" + cur_hours : cur_hours) + ":" + (cur_minutes < 10 ? "0" + cur_minutes : cur_minutes) + ":" + (cur_seconds  < 10 ? "0" + cur_seconds : cur_seconds);
	if (bdvr_on)
	{
		cur_video_time.innerHTML='<p align="center"><font face="Arial" size="2">'+cur_time+'</font>';
	}
	

	dvr_time= (dvr_hours < 10 ? "0" + dvr_hours : dvr_hours) + ":" + (dvr_minutes < 10 ? "0" + dvr_minutes : dvr_minutes) + ":" + (dvr_seconds  < 10 ? "0" + dvr_seconds : dvr_seconds);
	dvr_video_time.innerHTML='<p align="center"><font face="Arial" size="2">'+dvr_time+'</font>';
	//g_current_timestamp+=1000;
	//g_dvr_timestamp+=1000;

}
function Get_Dvr_Starting_Time()
{
 if (xmlHttp.readyState == 4) {
  	var response = xmlHttp.responseText;
  	var d=new Date(response);
 //	alert(response);

  	g_server_dvr_sec=d.getTime();
  //	alert(g_server_dvr_sec);
  	
   	
  }
}
function play_channel(chno,container,dvr_on)
{
	var vlc;
	var vlc_id;
	var flash_video_window;
	var path;
	var video_path;
	var browser_name;
	var str;
	var pos1;
	var browser_name;
	//var video_area = parent.document.getElementById("video_area");
	//var backword_button_id = parent.document.getElementById("backword_button_id");
	//var forward_button_id = parent.document.getElementById("forward_button_id");
	//var to_live_button_id = parent.document.getElementById("to_live_button_id");
	//var cur_video_time = parent.document.getElementById("cur_video_time");
	//var time_text_id = parent.document.getElementById("time_text_id");
	var httpport = g_httpport;
//	var httpport = 8000;

	var  cgi_url;
	var d=new Date();
	var VideoWindow;

	bQuery_Channel_Status=0;
 	//cgi_url= "/server/query_dvr_starting_time?token="+encodeURI(g_token)+ "&ch_no=" +chno+"&flag="+Math.random();
	//xmlHttp.open("GET", cgi_url, true);
	//xmlHttp.onreadystatechange = Get_Dvr_Starting_Time;
	//xmlHttp.send(null);
	//video_area.innerHTML='';
	
	//g_cur_sec=d.getTime();
	//g_dvr_sec=g_cur_sec;
//	video_path=path.substring(43,path.length-11)+'?u=root&p=1234';
	
  	//path=find_cookie_value("video_path");
  	
  	
	//alert(path);
 	//g_user_id=find_cookie_value("userid");
  	//g_password=find_cookie_value("password");

  	//video_path=path+'?u='+g_user_id+':p='+g_password;
	g_token=find_cookie_value("token");
 // 	video_path="http://"+location.host+"/ch"+chno+".flv"+'?token='+g_token;
 //alert(container);
	BrowserDetect.init();
	browser_name=BrowserDetect.browser;
	if (container.search("flv")>=0)
	{// flash	
  			video_path="http://"+location.hostname+":"+httpport+"/ch"+chno+"."+container+'?token='+g_token+':server_ip_port='+location.hostname+":"+httpport;
  		
	}	
	else if (container.search("ch")>=0)
	{
		if (browser_name.search("Safari")==0)
		{ // Apple	
 	 		video_path="http://"+location.hostname+":"+httpport+"/ch"+chno+"."+"m3u8"+'?token='+g_token+':server_ip_port='+location.hostname+":"+httpport;
 		} else
  		{ // VLC 
	 		video_path="http://"+location.hostname+":"+httpport+"/"+chno+"."+container+'?token='+g_token+':server_ip_port='+location.hostname+":"+httpport;
  		}
	}
  	g_video_path=video_path;
 	alert(video_path);
 	//g_current_timestamp=0;
	//g_dvr_timestamp=0;
	//bdvr_on=0;
	 str="<head><title>CH "+chno+"</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body>';
//	str='';
 	if (video_path.search("flv")>0)
	{
		if (browser_name.search("Explorer")==0)
		{
			str+='<object>'+
			'<param name="allowFullScreen" value="true" />'+
			'<param name="allowscriptaccess" value="always" />'+
			'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220" flashvars="src='+video_path+'&autoPlay=true">'+ 
			'</embed>'+
			'</object>';	
		} else 
		{
			str+='<param name="allowFullScreen" value="true"></param>'+
			'<param name="allowscriptaccess" value="always"></param>'+
			'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" autoplay="yes" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220" flashvars="src='+video_path+'&autoPlay=true">';
		
	
		}
	}else if (video_path.search("m3u8")>0)
	{ // APPLIE
	 	str+='<video src="'+video_path+'" controls autoplay>';
	 		//alert(str);

	}else if (video_path.search("ch")>0) 
	{ // VLC
		  
		 if (browser_name.search("Explorer")==0)
 		 {
 		 	str+='<OBJECT id="VIDEO" width="100%" height="100%" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">'+
			'<PARAM NAME="URL" VALUE="'+video_path+'">'+
			'<PARAM NAME="AutoStart" VALUE="True">'+
			'</OBJECT>';
			 
    		}else
		{
			str+='<embed type="application/x-vlc-plugin" name="player" autoplay="yes" loop="no" '+
			'target="'+video_path+'">';
		}		

	}
	
	str+='</body>';
	
	/* 
	time_text_id.innerHTML='<p align="center"><font face="Arial" size="2">Current Time</font></p>';
	if (dvr_on)
	{
		backword_button_id.innerHTML='<p align="right"><input type="button" value="<<" onclick="javascript:dvr_for_backward(0);" name="B1" /></p>';
		//forward_button_id.innerHTML='<p align="left"><input type="button" value=">>" onclick="javascript:dvr_for_backward(1);" name="B2" /></p>';
	}else
		{
			backword_button_id.innerHTML='';
			forward_button_id.innerHTML='';
			to_live_button_id.innerHTML='';
			cur_video_time.innerHTML='';
		}
		
	g_current_timestamp=0;
	g_timer=setInterval(function(){show_drv_time_cur_time(0)},1000);
	*/
	 VideoWindow= window.open("", "", "top=100, left=100, width=320, height=240"); 
	VideoWindow.document.write(str); 

	//flash_video_window=document.getElementById("flash_video_window");

	//alert(str);
	
	
}
function play_movie(movie_no)
{
	 var movie_src_id="moviesrc"+movie_no; 
	 var movie_src_name="moviename"+movie_no; 
	var movie_src;
	 var movie_name;
	var vlc;
	var vlc_id;
	var flash_video_window;
	var path;
	var video_path;
	var browser_name;
	var str;
	var pos1;
	var browser_name;
	 g_item_name=document.getElementById(movie_src_id);
	 movie_src = g_item_name.value;
	 g_item_name=document.getElementById(movie_src_name);
	 movie_name = g_item_name.value;
	//var video_area = parent.document.getElementById("video_area");
	//var backword_button_id = parent.document.getElementById("backword_button_id");
	//var forward_button_id = parent.document.getElementById("forward_button_id");
	//var to_live_button_id = parent.document.getElementById("to_live_button_id");
	//var cur_video_time = parent.document.getElementById("cur_video_time");
	//var time_text_id = parent.document.getElementById("time_text_id");
	var httpport = g_httpport;
//	var httpport = 8000;

	var  cgi_url;
	var d=new Date();
	var VideoWindow;

 	//cgi_url= "/server/query_dvr_starting_time?token="+encodeURI(g_token)+ "&ch_no=" +chno+"&flag="+Math.random();
	//xmlHttp.open("GET", cgi_url, true);
	//xmlHttp.onreadystatechange = Get_Dvr_Starting_Time;
	//xmlHttp.send(null);
	//video_area.innerHTML='';
	
	//g_cur_sec=d.getTime();
	//g_dvr_sec=g_cur_sec;
//	video_path=path.substring(43,path.length-11)+'?u=root&p=1234';
	
  	//path=find_cookie_value("video_path");
  	
  	
	//alert(path);
 	//g_user_id=find_cookie_value("userid");
  	//g_password=find_cookie_value("password");

  	//video_path=path+'?u='+g_user_id+':p='+g_password;
	g_token=find_cookie_value("token");
 // 	video_path="http://"+location.host+"/ch"+chno+".flv"+'?token='+g_token;
 //alert(container);
	BrowserDetect.init();
	browser_name=BrowserDetect.browser;
	video_path="http://"+location.hostname+":"+httpport+"/"+movie_name+'?token='+g_token+':server_ip_port='+location.hostname+":"+httpport;
  	g_video_path=video_path;
 	//alert(video_path);
 	//g_current_timestamp=0;
	//g_dvr_timestamp=0;
	//bdvr_on=0;
	 str="<head><title>Movie "+movie_no+"</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body>';
//	str='';
//alert(movie_src);
 	if (movie_src.search("flv")>0)
	{
		
		if (browser_name.search("Explorer")==0)
		{

			str+='<object>'+
			'<param name="allowFullScreen" value="true" />'+
			'<param name="allowscriptaccess" value="always" />'+
			'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220" flashvars="src='+video_path+'&autoPlay=true">'+ 
			'</embed>'+
			'</object>';	
			
		} else 
		{
			
			
			str+='<param name="allowFullScreen" value="true"></param>'+
			'<param name="allowscriptaccess" value="always"></param>'+
			'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" autoplay="yes" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220" flashvars="src='+video_path+'&autoPlay=true">';
			
		
	
		}
		
	}else if (movie_src.search("mp4")>0)
	{ // APPLIE
	 	str+='<video src="'+video_path+'" controls autoplay>';
	 		//alert(str);

	}else if (movie_src.search("ts")>0) 
	{ // VLC
		  
		 if (browser_name.search("Explorer")==0)
 		 {
 		 	str+='<OBJECT id="VIDEO" width="100%" height="100%" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">'+
			'<PARAM NAME="URL" VALUE="'+video_path+'">'+
			'<PARAM NAME="AutoStart" VALUE="True">'+
			'</OBJECT>';
			 
    		}else
		{
			str+='<embed type="application/x-vlc-plugin" name="player" autoplay="yes" loop="no" '+
			'target="'+video_path+'">';
		}		

	}
	
	str+='</body>';
	
	
	 VideoWindow= window.open("", "", "top=100, left=100, width=320, height=240"); 
	VideoWindow.document.write(str); 

	
	
}
function play_movie_by_name(movie_name,movie_src)
{
	//var movie_src_id="moviesrc"+movie_no; 
	 //var movie_src_name="moviename"+movie_no; 
	//var movie_src;
	 //var movie_name;
	var vlc;
	var vlc_id;
	var flash_video_window;
	var path;
	var video_path;
	var browser_name;
	var str;
	var pos1;
	var browser_name;
	 //g_item_name=document.getElementById(movie_src_id);
	 //movie_src = g_item_name.value;
	 //g_item_name=document.getElementById(movie_src_name);
	 //movie_name = g_item_name.value;
	//var video_area = parent.document.getElementById("video_area");
	//var backword_button_id = parent.document.getElementById("backword_button_id");
	//var forward_button_id = parent.document.getElementById("forward_button_id");
	//var to_live_button_id = parent.document.getElementById("to_live_button_id");
	//var cur_video_time = parent.document.getElementById("cur_video_time");
	//var time_text_id = parent.document.getElementById("time_text_id");
	var httpport = g_httpport;
//	var httpport = 8000;

	var  cgi_url;
	var d=new Date();
	var VideoWindow;

 	//cgi_url= "/server/query_dvr_starting_time?token="+encodeURI(g_token)+ "&ch_no=" +chno+"&flag="+Math.random();
	//xmlHttp.open("GET", cgi_url, true);
	//xmlHttp.onreadystatechange = Get_Dvr_Starting_Time;
	//xmlHttp.send(null);
	//video_area.innerHTML='';
	
	//g_cur_sec=d.getTime();
	//g_dvr_sec=g_cur_sec;
//	video_path=path.substring(43,path.length-11)+'?u=root&p=1234';
	
  	//path=find_cookie_value("video_path");
  	
  	
	//alert(path);
 	//g_user_id=find_cookie_value("userid");
  	//g_password=find_cookie_value("password");

  	//video_path=path+'?u='+g_user_id+':p='+g_password;
	g_token=find_cookie_value("token");
 // 	video_path="http://"+location.host+"/ch"+chno+".flv"+'?token='+g_token;
 //alert(container);
	BrowserDetect.init();
	browser_name=BrowserDetect.browser;
	video_path="http://"+location.hostname+":"+httpport+"/"+decodeURI(movie_name)+'?token='+g_token+':server_ip_port='+location.hostname+":"+httpport;
	//alert(video_path);
  	g_video_path=video_path;
 	//alert(video_path);
 	//g_current_timestamp=0;
	//g_dvr_timestamp=0;
	//bdvr_on=0;
	 str="<head><title>Movie "+movie_name+"</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body>';
//	str='';
//alert(movie_src);
 	if (movie_src.search("flv")>0)
	{
		
		if (browser_name.search("Explorer")==0)
		{

			str+='<object>'+
			'<param name="allowFullScreen" value="true" />'+
			'<param name="allowscriptaccess" value="always" />'+
			'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220" flashvars="src='+video_path+'&autoPlay=true">'+ 
			'</embed>'+
			'</object>';	
			
		} else 
		{
					
			str+='<param name="allowFullScreen" value="true"></param>'+
			'<param name="allowscriptaccess" value="always"></param>'+
			'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" autoplay="yes" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="300" height="220" flashvars="src='+video_path+'&autoPlay=true">';
			
		
	
		}
		
	}else if (movie_src.search("mp4")>0)
	{ // APPLIE
		str+='<video controls width=320 height=240 autoplay>'+
		'<source src="'+video_path+'" type="video/mp4">'+
		'</video>';
		//alert(str);
		

	}else if (movie_src.search("ts")>0) 
	{ // VLC
		  
		 if (browser_name.search("Explorer")==0)
 		 {
 		 	str+='<OBJECT id="VIDEO" width="100%" height="100%" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">'+
			'<PARAM NAME="URL" VALUE="'+video_path+'">'+
			'<PARAM NAME="AutoStart" VALUE="True">'+
			'</OBJECT>';
			 
    		}else
		{
			str+='<embed type="application/x-vlc-plugin" name="player" autoplay="yes" loop="no" '+
			'target="'+video_path+'">';
		}		

	}
	
	str+='</body>';
	
	
	 VideoWindow= window.open("", "", "top=100, left=100, width=340, height=260"); 
	VideoWindow.document.write(str); 

	
	
}
//function dvr_response()
function dvr_for_backward(sign)
{

  	var video_window;
	var path;
	var video_path;
	var browser_name;
	var str;
	var pos1;
	var browser_name;
	var backid=document.getElementById("back");
	var to_live_button_id=document.getElementById("to_live_button_id");
	var time_text_id=document.getElementById("time_text_id");
	var cur_video_time=document.getElementById("cur_video_time");
	var timestamp;
	
	bdvr_on=1;
	
	//if (xmlHttp.readyState == 4) 
	//{	
	//	var response = xmlHttp.responseText;
		if (sign==0)
		{
			g_dvr_sec-=30*1000;
			forward_button_id.innerHTML='<p align="left"><input type="button" value=">>" onclick="javascript:dvr_for_backward(1);" name="B2" /></p>';

		}
		
		else if (sign==1)
		{
			g_dvr_sec+=30*1000;
			backword_button_id.innerHTML='<p align="right"><input type="button" value="<<" onclick="javascript:dvr_for_backward(0);" name="B1" /></p>';
		}


	//	var request_time_stamp;
	//	alert(g_dvr_timestamp);
	//	alert(g_current_timestamp);
		//alert(g_skip_value);
		// FLV
//		request_time_stamp=parseFloat(response)+g_skip_value*1000;
//		g_dvr_timestamp=g_dvr_timestamp+g_skip_value*1000;
		path=g_video_path;
		if (g_dvr_sec>g_cur_sec)
		{
			g_dvr_sec=g_cur_sec;
			forward_button_id.innerHTML='';
			to_live_button_id.innerHTML='';
			cur_video_time.innerHTML='';
			time_text_id.innerHTML='<p align="center"><font face="Arial" size="2">Cur Time</font></p>';
			bdvr_on=0;
		  	video_path=path;

		} else if (g_dvr_sec<=g_server_dvr_sec)
		{
			g_dvr_sec=g_server_dvr_sec;
			to_live_button_id.innerHTML='<p align="center"><input type="button" value="To Live" onclick="javascript:dvr_to_live();" name="B2" /></p>';
			time_text_id.innerHTML='<p align="center"><font face="Arial" size="2">DVR Time</font></p>';
			timestamp=g_dvr_sec-g_server_dvr_sec;	
		  	video_path=path+":timestamp="+timestamp;
			//backword_button_id.innerHTML='';
		}else
		{
			to_live_button_id.innerHTML='<p align="center"><input type="button" value="To Live" onclick="javascript:dvr_to_live();" name="B2" /></p>';
			time_text_id.innerHTML='<p align="center"><font face="Arial" size="2">DVR Time</font></p>';
			timestamp=g_dvr_sec-g_server_dvr_sec;
		  	video_path=path+":timestamp="+timestamp;

		}
		
	//	alert(request_time_stamp);
		//g_dvr_timestamp=request_time_stamp;
	  	
	  	
		//alert(path);
	 	//g_user_id=find_cookie_value("userid");
	  	//g_password=find_cookie_value("password");
	
	  	//video_path=path+'?u='+g_user_id+':p='+g_password;
		g_token=find_cookie_value("token");
		//timestamp=g_dvr_sec-g_server_dvr_sec;

	  	//video_path=path+":timestamp="+timestamp;
	 	//alert(video_path);
	 
	 	BrowserDetect.init();
		browser_name=BrowserDetect.browser;
		if (video_path.search("flv")>0)
		{
			if (browser_name.search("Explorer")==0)
			{
				str='<object>'+
				'<param name="allowFullScreen" value="true" />'+
				'<param name="allowscriptaccess" value="always" />'+
				'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="src='+video_path+'&autoPlay=true">'+ 
				'</embed>'+
				'</object>';	
			} else if (browser_name.search("Safari")==0)
			{
		
			}else
			{			
				str='<param name="allowFullScreen" value="true"></param>'+
				'<param name="allowscriptaccess" value="always"></param>'+
				'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true"  flashvars="src='+video_path+'&autoPlay=true">';
			}
				
						
				
	
		} else if (video_path.search("m3u8")>0)
		{
			if (browser_name.search("Safari")==0)
			{
				str='<video src="'+video_path+':server_ip_port='+location.host+'" controls autoplay>';
			}
			
		}else if (video_path.search("ch")>0) 
		{
			 if (browser_name.search("Explorer")==0)
	 		 {
	 		 	str='<OBJECT id="VIDEO" width="100%" height="100%" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">'+
				'<PARAM NAME="URL" VALUE="'+video_path+'">'+
				'<PARAM NAME="AutoStart" VALUE="True">'+
				'</OBJECT>';
				 
	    		}else
			{
				str='<embed type="application/x-vlc-plugin" name="player" autoplay="yes" loop="no" '+
				'target="'+video_path+'">';
			}	
		}
		
		

		
		video_window=document.getElementById("video_area");
	
		//alert(str);
		video_window.innerHTML=str;
	//}

}
function dvr_to_live()
{

  	var video_window;
	var path;
	var video_path;
	var browser_name;
	var str;
	var pos1;
	var browser_name;
	var backid=document.getElementById("back");
	var time_text_id=document.getElementById("time_text_id");
	var cur_video_time=document.getElementById("cur_video_time");
	var timestamp;

	var to_live_button_id=document.getElementById("to_live_button_id");
	bdvr_on=0;
	//if (xmlHttp.readyState == 4) 
	//{	
	//	var response = xmlHttp.responseText;
	

		
	//	alert(request_time_stamp);
		path=g_video_path;
		g_dvr_sec=g_cur_sec;
		timestamp=g_dvr_sec-g_server_dvr_sec;
		g_token=find_cookie_value("token");
//	  	video_path=path+":timestamp="+timestamp;
	  	video_path=path;
	 	//alert(video_path);

	 
	 	BrowserDetect.init();
		browser_name=BrowserDetect.browser;
		if (video_path.search("flv")>0)
		{
			if (browser_name.search("Explorer")==0)
			{
				str='<object>'+
				'<param name="allowFullScreen" value="true" />'+
				'<param name="allowscriptaccess" value="always" />'+
				'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="src='+video_path+'&autoPlay=true">'+ 
				'</embed>'+
				'</object>';	
			} else if (browser_name.search("Safari")==0)
			{
		
			}else
			{			
				str='<param name="allowFullScreen" value="true"></param>'+
				'<param name="allowscriptaccess" value="always"></param>'+
				'<embed src="/flash_player10_1/StrobeMediaPlayback.swf" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" flashvars="src='+video_path+'&autoPlay=true">';
			}
				
						
				
	
		} else if (video_path.search("m3u8")>0)
		{
			if (browser_name.search("Safari")==0)
			{
				str='<video src="'+video_path+':server_ip_port='+location.host+'" controls autoplay>';
				//alert(str);
			}
			
		}else if (video_path.search("ch")>0) 
		{ // VLC
			  
			 if (browser_name.search("Explorer")==0)
	 		 {
	 		 	str='<OBJECT id="VIDEO" width="100%" height="100%" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject">'+
				'<PARAM NAME="URL" VALUE="'+video_path+'">'+
				'<PARAM NAME="AutoStart" VALUE="True">'+
				'</OBJECT>';
				 
	    		}else
			{
				str='<embed type="application/x-vlc-plugin" name="player" autoplay="yes" loop="no" '+
				'target="'+video_path+'">';
			}		
		}
		

		
		video_window=document.getElementById("video_area");
	
		//alert(str);
		video_window.innerHTML=str;
		to_live_button_id.innerHTML='';
		time_text_id.innerHTML='<p align="center"><font face="Arial" size="2">Current Time</font></p>';
		cur_video_time.innerHTML='';
		forward_button_id.innerHTML='';
	//}

}

function get_system_log()
{
    if (xmlHttp.readyState == 4) {

	var response = xmlHttp.responseText;
	var content = parent.document.getElementById("content");
	var str;
	var str1;
	var iret;
	var totalret=0;
	var HTML_str='';
	var i=1;
	

	str1=response;
	while (1)
	{
		iret=str1.search("\n");
		//alert(iret);
		totalret+=iret;
	 	if (iret==-1) break;
	 	str=str1.substring(0,iret);
	 	//alert(str);
	 	HTML_str=HTML_str+'<font face="Arial" size="2">'+str+'</font><br>';
	 	str1=response.substring(totalret+i,response.length);
	 	//alert(str1);
	 	i++;
	 	
	}
	
	
	content.innerHTML='<table><tr><td><p align="right"><font face="Arial" size="2"><a href='+"'javascript:void(0)'"+' onclick=callServer_get_system_log()>Refresh</a></font></td></tr>'+
	'<tr><td>'+HTML_str+'</td></tr>'+
	'<tr><td><p align="right"><font face="Arial" size="2"><a href='+"'javascript:void(0)'"+' onclick=callServer_get_system_log()>Refresh</a></font></td></tr>'+
	'</table>';
	//alert(content.innerHTML);
    }
}

function callServer_get_system_log() {
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 	var content = parent.document.getElementById("content");
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;

 	content.innerHTML='<table><tr><td><p align="right"><font face="Arial" size="2">Loading</font></p></td></tr></table>';
	if (g_token!=0)
	{
		cgi_url="/log/system.log"			
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = get_system_log;
		xmlHttp.send(null);
	}

}

function CH_inquery()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var ch_no;
    var ch_name;
    var ch_src;
    var ch_icon;
    var ch_category;
    var ch_type;
    var ch_status;
    var ch_bitrate;
    var ch_play_id;
    var ch_title="<p>"+"Channel List"+"</p>";
    var ch_list;
    var i=0;
    var j=0;
    var box_no=1;
	var ch_active_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content = parent.document.getElementById("content");
  //var detail = parent.document.getElementById("detail");
  var dvr_folder_on=0;
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var more_keyword=null;


	content.innerHTML="";
//	detail.innerHTML="";
	
	g_search_channel_item.value=null;

	 HTML_str= '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_ch_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="100" align="center"><font face="Arial" size="2">Channel Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="140" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Type</font></td>'+
	      '<td width="120" align="center"><font face="Arial" size="2">Status(Uptime)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
 	 '</tr>'+'<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
 	
	while (1)
	{
 	 	if (response[i]==0) break;
		//alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
   	    	ch_no=response[i].slice(3,strlength);
     	 	strlength=response[i+1].length;
   	    	ch_name=response[i+1].slice(5,strlength);
     	 	strlength=response[i+2].length;
   	    	ch_src=response[i+2].slice(4,strlength);
     	 	strlength=response[i+3].length;
   	    	ch_icon=response[i+3].slice(5,strlength);
     	 	strlength=response[i+4].length;
 	    	ch_category=response[i+4].slice(9,strlength);
     	 	strlength=response[i+5].length;
   	    	ch_type=response[i+5].slice(5,strlength);
   	    	if (ch_type.search("dvr")>=0)
   	    	{
   	    		dvr_folder_on=1;
   	    	}else
   	    	{
   	    		dvr_folder_on=0;
   	    	}
   	    	strlength=response[i+6].length;
  	    	ch_status=response[i+6].slice(7,strlength);
  	    	//alert(ch_status);
  	    	strlength=response[i+7].length;
  	    	ch_bitrate=response[i+7].slice(8,strlength);
   	    		
   	    	

 		i=i+8;
		ch_active_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		   '<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+ch_no+
	 		' id=checkbox'+ch_no+'></td>'+
		      '<td width="20" align="center"><font face="Arial" size="2">'+ch_no+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="chname"'+
	 		' id=chname'+ch_no+
	 		' size="20" value="'+
	 		decodeURI(ch_name)+'"/></font></td>'+
		      '<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" title="'+ch_src+'" name="chsrc"'+
	 		' id=chsrc'+ch_no+
	 		' size="30" value="'+
	 		ch_src+'"/></font></td>'+
		      '<td width="140" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" title="'+ch_icon+'" name="chicon"'+
	 		' id=chicon'+ch_no+
	 		' size="20" value="'+
	 		ch_icon+'"/></font></td>'+
		      '<td width="10" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="chcategory"'+
	 		' id=chcategory'+ch_no+
	 		' size="15" value="'+
	 		decodeURI(ch_category)+'"/></font></td>'+
	 		
		      '<td width="60" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		
			' <select size="1" name="chtype" id=chtype'+ch_no+'>';
			//alert(ch_type);
			if (ch_type.search("live")>=0)
			{
				HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("delay")>=0)
			{
				for (k=0;k<g_delaytime_array.length;k++)
				{
					
					if (ch_type.search(g_delayvalue_array[k])==0)
					{
						break;
					}
				}
				//alert(k);
				HTML_str+='<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					if (j!=k)
					{
						HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					}else 
					{
						HTML_str+='<option selected="selected" value="'+g_delayvalue_array[k]+'">'+g_delaytime_array[k]+'</option>';
					}
											
				}
			}else if (ch_type.search("dvr")>=0)
			{
				HTML_str+='<option selected="selected" value="dvr">'+"DVR"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("inactive")>=0)
			{
				HTML_str+='<option selected="selected" value="inactive">'+"Inactive"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("movie")>=0)
			{
				HTML_str+='<option selected="selected" value="movie">'+"Movie"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}
			/* else if (ch_type.search("hls")>=0)
			{
				HTML_str+='<option selected="selected" value="hls">'+"HLS"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}
			*/
			HTML_str+='</select></font></td>';
			
			//alert(ch_status);		

			if (ch_status.search("OFF")>=0)
			{
		      		HTML_str+='<td id=chstatus'+ch_no+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
			}else
			{
		      		HTML_str+='<td id=chstatus'+ch_no+' width="100" align="center"><font face="Arial" size="2">'+ch_status+'</font></td>';

			}
	      		HTML_str+='<td id=chbitrate'+ch_no+' width="100" align="center"><font face="Arial" size="2">'+ch_bitrate+'</font></td>';
		
			add_keyword="Add";
			del_keyword="Del";
			save_keyword="Save";
			refresh_keyword="Refresh";
			play_keyword="Play";
			more_keyword="More";
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_Channel("'+ch_no+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Copy_10_Channels("'+ch_no+'")>'+
			' <img border="0" id="copybutton" alt="Copy 10 channels" title="Copy 10 channels" src="add_multiple_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_CH_Update("'+ch_no+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Channel("'+ch_no+'")>'+
			' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
			
			
			HTML_str+='<td id=querystatusbutton'+ch_no+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_Query_One_Channel_Status("'+ch_no+'")>'+
			' <img border="0" id="querybutton" alt="Query" title="Query" src="query_icon.PNG"></a></td>';

			
			
			HTML_str+='<td id=refreshchannelbutton'+ch_no+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Refresh_A_Channel("'+ch_no+'")>'+
			' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
			
			
			HTML_str+='<td id=morechannelbutton'+ch_no+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Get_Server_IP("'+ch_no+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
			
			HTML_str+='<td align="center" id=ch_play_id'+ch_no+'>';
			if (ch_src.search("rtmp")==0)
			{
			    HTML_str+="<a href='javascript:void(0)'"+
			    ' onclick=play_channel("'+ch_no+'",'+'"flv"'+','+dvr_folder_on+')>'+
			    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
			}
			else
			{
			    HTML_str+="<a href='javascript:void(0)'"+
			    ' onclick=play_channel("'+ch_no+'",'+'"ch"'+','+dvr_folder_on+')>'+
			    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
			}				
			
							
			HTML_str+='</tr>';
			
				
		    
		box_no++;
     }
      //    content.innerHTML=HTML_str;
      // alert(menu_main.innerHTML);
      
  	      
      	      HTML_Menu_Bar_Str='<td id=ch_menu_bar>';
      	      if (g_show_free_version==1)
      	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
	 	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	 
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
      	      }else
      	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_channel()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
	 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_channel()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	 
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_channel()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	
	      }


 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_channel()>"+
	      '<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';

 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_channel()>"+
	      '<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';

	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_CH_Inquery()>"+
	      '<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
	      
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_CH_Inquery()>"+
	      '<font size="2" face="Arial">Auto Query</font></a>'+'&nbsp&nbsp&nbsp';

	      if (g_show_free_version==1)
	      {
	          HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
	          HTML_Menu_Bar_Str+="<a href='javascript:void(0)' id='ImportBtn' onclick=call_import_channel()>"+
		     '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
	      
 	      //HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_channel_definition()>"+
	      //'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';

	      HTML_Menu_Bar_Str+='</td>';

	if (ch_active_no==0)
	{	
		i=1;
		ch_src="";
		ch_icon="";
		ch_name="";
		ch_category="";
		ch_status="";
		ch_bitrate="";
	      HTML_str=HTML_str+'<tr>'+
	      '<td width="20" align="center">'+
		' <input type="checkbox" name=checkbox'+i+
		' id=checkbox'+i+'></td>'+
	      '<td width="100" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chname"'+
		' id=chname'+i+
		' size="14"/'+
		'</font></td>'+
	      '<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chsrc"'+
		' id=chsrc'+i+
		' size="30"/'+
		'</font></td>'+
	      '<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chicon"'+
		' id=chicon'+i+
		' size="30"/'+
		'</font></td>'+
	      '<td width="10" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chcategory"'+
		' id=chcategory'+i+
		' size="10"/'+
		'</font></td>'+
		
	      '<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <select size="1" name="chtype" id=chtype'+i+'>';
		
		HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
		'<option value="movie">'+"Movie"+'</option>'+
		'<option value="dvr">'+"DVR"+'</option>'+
		//'<option value="hls">'+"HLS"+'</option>'+
		'<option value="inactive">'+"Inactive"+'</option>';
		for (j=0;j<g_delaytime_array.length;j++)
		{
			
			HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
			
		}
		HTML_str+='</select></font></td>';
	
		HTML_str+='<td id=chstatus'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
		HTML_str+='<td id=chbitrate'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+'<b>'+ch_bitrate+'</b>'+'</font></td>';
	      	HTML_str+=
	      		'<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Channel("'+i+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	
	      		'<td id=copy_id_button align="center">'+
		       ' <font face="Arial" size="2"></font></a></td>'+
	      	      
		      '<td id=save_id_button align="center">'+		      
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Channel()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+
	      	      
		      '<td id=del_id_button  align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
	
		      
		      '<td id=querystatusbutton align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
	
		      '<td id=refreshchannelbutton'+i+' align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      
		      '<td id=more_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      
		      '<td align="center" id=ch_play_id'+i+' align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>';
	
	}
	

 	content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Channel Total: '+ ch_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td><font face="Arial" size="2"> <input name="channel_search_field" id="channel_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_channel_name();" name="search_channel_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(1);" name="goto_channel_no" /></font>'+	   
	   '</td></tr>'+
	'</table>'+HTML_str+'</table>';
	
	g_total_ch_no=ch_active_no;
	
	// alert(g_Query_Channel_Status_timer);
	/*bQuery_Channel_Status=1;
	if (g_Query_Channel_Status_timer==0)
	{
		g_Query_Channel_Status_timer=setInterval(function(){callServer_Query_Channel_Status_Timer()},10*1000);
		// alert(g_Query_Channel_Status_timer);
	}
	*/

/*	if (g_Channel_Edit_Mode==1)
	{
		bQuery_Channel_Status=0;
	}else
	{	
		bQuery_Channel_Status=1;
		if (g_Query_Channel_Status_timer==0)
		{
			g_Query_Channel_Status_timer=setInterval(function(){callServer_Query_Channel_Status_Timer()},10*1000);
			// alert(g_Query_Channel_Status_timer);
		}
	}
*/	

 
 }

 
}
function Preview_CH_inquery()
{
   var content = parent.document.getElementById("content");
   var str;
   var buffer;
   var i;
 //  var path;
   var trstart=0;
   var strtext;
   var video_path;
   var browser_name;
   var buffer_video_text;
  // var media_text;
 //  var media_text_path;
     var ch_no;
    var ch_name;
    var ch_src;
   var ch_type;
     var dvr_folder_on=0;

 
  if (xmlHttp.readyState == 4) {
  var response = xmlHttp.responseText.split("\r\n");
   // alert(g_file_path);
     str='';
     strtext='';
      	  BrowserDetect.init();
  	  browser_name=BrowserDetect.browser;
 	g_token=find_cookie_value("token");
 	//alert(g_token);
	if (g_token==0) return; 


        for (i=0;;i=i+8)
  	{
	//  alert(response[i]);
	    if (response[i]==0)
  	    {
  	    	break;
 	    } else
  	    {
 	 	strlength=response[i].length;
	 //	alert(strlength);
   	    	ch_no=response[i].slice(3,strlength);
   	    	//alert(ch_no);
     	 	strlength=response[i+1].length;
   	    	ch_name=response[i+1].slice(5,strlength);
     	 	strlength=response[i+2].length;
   	    	ch_src=response[i+2].slice(4,strlength);
   	    	//alert(ch_src);
     	 	strlength=response[i+3].length;
   	    	picture_path=response[i+3].slice(11,strlength);
   	    	//alert(picture_path);
     	 	strlength=response[i+5].length;
   	    	ch_type=response[i+5].slice(5,strlength);
  	    	//picture_path='/'+g_file_path.replace("videos","pictures")+'/ch'+ch_no+'.jpg';;
	  	//media_text_path='/'+picture_path.replace("videos","text")+'/ch'+ch_no+'.htm';;
	    	if (trstart==0)
  	    	{
  	    		str+='<tr>';
  	    		strtext+='<tr>';
  	    	} 
  		if (ch_type.search("dvr")>=0)
   	    	{
   	    		dvr_folder_on=1;
   	    	}else
   	    	{
   	    		dvr_folder_on=0;
   	    	}
	  	 

		if (ch_src.search("rtmp")==0)
		{
			str+='<td width="16%" valign="middle" align="center" height="185">'+
			'<a style="text-decoration:none"'+ 
			"href='javascript:void(0)'"+
		    	' onclick=play_channel("'+ch_no+'",'+'"flv"'+','+dvr_folder_on+')>'+
			'<img border="0" src="'+picture_path+'" width="150" height="213"></a></td>';
			strtext+='<td width="16%" valign="middle" align="center" height="23"><font size="2" color="#000000" face="Arail">'+decodeURI(ch_name)+'</font></td>';
		}
		else
		{
			str+='<td width="16%" valign="middle" align="center" height="185">'+
			'<a style="text-decoration:none"'+ 
			"href='javascript:void(0)'"+
		    	' onclick=play_channel("'+ch_no+'",'+'"ch"'+','+dvr_folder_on+')>'+
			'<img border="0" src="'+picture_path+'" width="150" height="213"></a></td>';
			strtext+='<td width="16%" valign="middle" align="center" height="23"><font size="2" color="#000000" face="Arail">'+decodeURI(ch_name)+'</font></td>';
		}	
 		

		trstart++;
		if (trstart==5)
  	    	{
  	    		str+='</tr>';
  	    		strtext+='</tr>';
  	    		str+=strtext;
  	    		strtext='';
  	    		trstart=0;
 	    		
  	    	}
 		//alert(str);
 		
  	    } 
      }
  	if (trstart!=0)
 	{
 	  	    		str+='</tr>';
	  	    		strtext+='</tr>';
	  	    		str+=strtext;
	}
 	content.innerHTML='<center><table border="0" cellpadding="10" cellspacing="0" width="100%">'+str+'</table></center>';
   }
  	
}
function Preview_callServer_CH_Inquery() {
  var content = parent.document.getElementById("content");

 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/query_channel_list?token="+encodeURI(g_token)+"&flag="+Math.random();
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Channel Preview Loading...<p>';
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Preview_CH_inquery;
		xmlHttp.send(null);
	}

}
function Button_Server_System_Inquery() {
    //document.getElementById('home_button').onmousedown=function () {
   /* document.getElementById('homebutton').src = 
    "home_down.PNG";
   // };
    document.getElementById('home_button').onmouseout=function () {
    document.getElementById('homebutton').src = 
    "home.PNG";
    };
    */
   // document.getElementById(g_current_button_id).style.color = "#cccccc";
   // document.getElementById('home_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
    g_current_button_id='home_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
   Callserver_System_Inquery();
}


function Button_Get_Channel_Statistics() {
/*    document.getElementById('statisticsbutton').src = 
    "statistics_down.PNG";
    document.getElementById('statistics_button').onmouseout=function () {
    document.getElementById('statisticsbutton').src = 
    "statistics.PNG";
    };
    */
  //  document.getElementById(g_current_button_id).style.color = "#cccccc";
  // document.getElementById('statistics_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //  g_current_button_id='statistics_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    bGet_Channel_Statistics=0;
    callServer_Get_Channel_Statistics();
}
function Button_Import_Xtream_DB() {

	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
	   callServer_Import_Xtream_DB();
}
function Button_Server_EPG_Inquery() {
   
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    callServer_Get_EPG_Info();
}
function Button_Server_XMLTV_Inquery() {
    var position=1;
    var limit=g_constant_limit;
    g_xmltv_limit=g_constant_limit;

	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
	callServer_Get_XMLTV_Info(position,limit);
}
function Button_Get_Stream_provider() {
    var position=1;
    var limit=g_constant_limit;
    g_provider_limit=g_constant_limit;

	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
	callServer_Get_Stream_Provider(position,limit);
}
function Button_add_user() {
	g_add_user_flag=1;
	Button_get_all_user();
	
}
function Button_add_android_user() {
	g_add_user_flag=2;
	Button_get_all_user();
	
}
function Button_add_mag_user() {
	g_add_user_flag=3;
	Button_get_all_user();
	
}
function Button_add_active_code() {
	g_add_user_flag=4;
	Button_get_all_user();
	
}


function Button_get_all_user() {
   // document.getElementById('user_button').onmousedown=function () {
   /* document.getElementById('userbutton').src = 
    "user_down.PNG";
    //};
    document.getElementById('user_button').onmouseout=function () {
    document.getElementById('userbutton').src = 
    "user.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('user_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
//	g_current_button_id='user_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    var position=1;
    var limit=g_constant_limit;
    g_copy_paste=0;
    if (g_user_no<limit)
    {
    	limit=g_user_no;
    }
    g_user_name_order_flag=0;
    g_user_group_order_flag=0;
    g_user_expired_date_order_flag=0;
//	document.getElementById("title_search_field").value="";
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    call_get_users(position,limit);
    
}
function Button_Add_New_CH() {
	g_add_channel_flag=1;
	Button_Server_CH_Inquery();
}

function Button_Server_CH_Inquery() {
   // document.getElementById('channel_button').onmousedown=function () {
   /* document.getElementById('channelbutton').src = 
    "channel_down.PNG";
    //};
    document.getElementById('channel_button').onmouseout=function () {
    document.getElementById('channelbutton').src = 
    "channel.PNG";
    };
    */
 //    document.getElementById(g_current_button_id).style.color = "#cccccc";
 // document.getElementById('channel_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //  g_current_button_id='channel_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    var position=1;
    var limit=g_constant_limit;
    if (g_total_ch_no<limit)
    {
    	limit=g_total_ch_no;
    }
    g_channel_name_order_flag=0;
    g_channel_category_order_flag=0
//    	document.getElementById("title_search_field").value="";
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    call_get_channels(position,limit);
 
  //  callServer_CH_Inquery();
}
function Button_Add_New_Movie()
{
	g_add_movie_flag=1;
	Button_Server_Movie_Inquery();
}
function Button_Upload_Movies()
{
	
	g_add_movie_flag=2;
	Button_Server_Movie_Inquery();
}

function Button_Server_Movie_Inquery() {
   // document.getElementById('movie_button').onmousedown=function () {
   /* document.getElementById('moviebutton').src = 
    "movie_down.PNG";
    //};
    document.getElementById('movie_button').onmouseout=function () {
    document.getElementById('moviebutton').src = 
    "movie.PNG";
    };
    */
 //  document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('movie_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //  g_current_button_id='movie_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    var position=1;
    var limit=g_constant_limit;
    if (g_total_movie_no<limit)
    {
    	limit=g_total_movie_no;
    }
    g_movie_name_order_flag=0;
    g_movie_category_order_flag=0;
	//document.getElementById("title_search_field").value="";
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    call_get_movies(position,limit);
//  callServer_Movie_Inquery();
}
function Button_Add_New_Series() {
	g_add_series_flag=1;
	Button_Server_Series_Inquery();
}
function Button_Server_Series_Inquery() {
  // document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
  // g_current_button_id='series_button';
	//document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    var position=1;
    var limit=g_constant_limit;
    if (g_total_series_no<limit)
    {
    	limit=g_total_series_no;
    }
    g_series_name_order_flag=0;
    g_series_category_order_flag=0;
    	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    call_get_series(position,limit);
//  callServer_Movie_Inquery();
}
function Button_Add_New_Group() {
	g_add_group_flag=1;
	Button_Server_group_Inquery();
}
function Button_Server_group_Inquery() {
   // document.getElementById('group_button').onmousedown=function () {
   /* document.getElementById('groupbutton').src = 
    "group_down.PNG";
    //};
    document.getElementById('group_button').onmouseout=function () {
    document.getElementById('groupbutton').src = 
    "group.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('group_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
//   g_current_button_id='group_button';
 //	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
 	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
  callServer_group_Inquery();
}
function Button_active_player_info() {
    //document.getElementById('player_button').onmousedown=function () {
   /* document.getElementById('playerbutton').src = 
    "player_down.PNG";
    //};
    document.getElementById('player_button').onmouseout=function () {
    document.getElementById('playerbutton').src = 
    "player.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('player_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
  // g_current_button_id='player_button';
 // 	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
  bQuery_Online_Player=0;
    var position=1;
    var limit=g_constant_limit;
    alert(g_System_timer);
    	if (g_System_timer)
	{
		alert("111111111111");
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    g_search__player_text=null;
    //document.getElementById("title_search_field").value="";
     calllist_active_player_info(position,limit);
}
function Button_alert_player_info() {
    //document.getElementById('alert_player_button').onmousedown=function () {
    /* document.getElementById('alertplayerbutton').src = 
    "alert_player_down.PNG";
    //};
    document.getElementById('alert_player_button').onmouseout=function () {
    document.getElementById('alertplayerbutton').src = 
    "alert_player.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
  // document.getElementById('alert_player_button').style.color = "#ffffff";
///	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //   g_current_button_id='alert_player_button';
 //	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
 	//document.getElementById("title_search_field").value="";
g_search__player_text=null;
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
  calllist_alert_player_info();
}
function Button_Add_New_Reseller() {
	g_add_reseller_flag=1;
	Button_get_reseller();
}
function Button_get_reseller() {
    //document.getElementById('reseller_button').onmousedown=function () {
    /* document.getElementById('resellerbutton').src = 
    "reseller_down.PNG";
    //};
    document.getElementById('reseller_button').onmouseout=function () {
    document.getElementById('resellerbutton').src = 
    "reseller.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
  // document.getElementById('reseller_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
    //g_current_button_id='reseller_button';
  //	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
  	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
 call_get_reseller();
}
function Button_player_filter() {
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
			alert("Only for Formal version");
			return;
	}	


    //document.getElementById('player_filter_button').onmousedown=function () {
   /* document.getElementById('playerfilterbutton').src = 
    "player_filter_down.PNG";
    //};
    document.getElementById('player_filter_button').onmouseout=function () {
    document.getElementById('playerfilterbutton').src = 
    "player_filter.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('player_filter_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //   g_current_button_id='player_filter_button';
  //	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
  	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
 call_player_filter();
}
function Button_mac_blocker() {
    //document.getElementById('mac_blocker_button').onmousedown=function () {
   /* document.getElementById('macblockerbutton').src = 
    "mac_blocker_down.PNG";
    //};
    document.getElementById('mac_blocker_button').onmouseout=function () {
    document.getElementById('macblockerbutton').src = 
    "mac_blocker.PNG";
    };
    */
 //    document.getElementById(g_current_button_id).style.color = "#cccccc";
 // document.getElementById('mac_blocker_button').style.color = "#ffffff";
	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
   g_current_button_id='mac_blocker_button';
	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    call_mac_blocker();
}
function Button_Server_blacklist_Inquery() {
    //document.getElementById('blacklist_button').onmousedown=function () {
    /* document.getElementById('blacklistbutton').src = 
    "blacklist_down.PNG";
    //};
    document.getElementById('blacklist_button').onmouseout=function () {
    document.getElementById('blacklistbutton').src = 
    "blacklist.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('blacklist_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
//   g_current_button_id='blacklist_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    callServer_blacklist_Inquery();
}
function Button_Get_Work_Folder() {
 	var position=1;
    var limit=g_constant_limit;
   	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
 callServer_get_work_folder(position,limit);

 
}
function Button_Server_blockchain_Inquery() {
 	var position=1;
    var limit=g_constant_limit;
   	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
 callServer_get_blockchain_nodes(position,limit);

 
}
function Refresh_Server_blockchain()
{
  	var position=1;
        var limit=g_constant_limit;
	 
	 var str;
	 str='<button class="dropbtn" onclick="Refresh_Server_blockchain()">'; 
					    str+='<i class="fa fa-refresh fa-spin"></i>';
					    str+='</button>';
					    
	 document.getElementById("blockchain_refresh_btn").innerHTML=str;
	 document.getElementById("blockchain_refresh_btn").disabled=true;
	 callServer_get_blockchain_nodes(position,limit);

}
function sync_blockchain_nodes()
{
  var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
 g_token=find_cookie_value("token");
 cgi_url = "/server/sysn_blockchain_nodes?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	
	 xmlHttp.open("GET", cgi_url, true);
	 
	 var str;
	 str='<button class="dropbtn" onclick="Refresh_Server_blockchain()">'; 
					    str+='<i class="fa fa-refresh fa-spin"></i>';
					    str+='</button>';
	    
	    
	 document.getElementById("blockchain_sync_btn").innerHTML=str;
	 document.getElementById("blockchain_sync_btn").disabled=true;
	    
	  xmlHttp.onreadystatechange = function() {
	  	if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			
			 var str;
			 str='<a href="javascript:sync_blockchain_nodes()">Sync Nodes</a>';
			 str+='</button>';					 
			 document.getElementById("blockchain_sync_btn").innerHTML=str;
		 	 document.getElementById("blockchain_sync_btn").disabled=false;


    		}
	  };
	 xmlHttp.send(null);
 


}
function Button_Add_New_balancer() {
	g_add_balancer_flag=1;
	Button_Server_balancer_Inquery();
}
function Button_Server_balancer_Inquery() {
    //document.getElementById('blacklist_button').onmousedown=function () {
    /* document.getElementById('balancerbutton').src = 
    "balancer_down.PNG";
    //};
    document.getElementById('balancer_button').onmouseout=function () {
    document.getElementById('balancerbutton').src = 
    "balancer.PNG";
    };
    */
//    document.getElementById(g_current_button_id).style.color = "#cccccc";
 //  document.getElementById('balancer_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //  g_current_button_id='balancer_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    callServer_balancer_Inquery();
}
function Button_Setting() {
    //document.getElementById('setting_button').onmousedown=function () {
    /* document.getElementById('settingbutton').src = 
    "setting_down.PNG";
    //};
    document.getElementById('setting_button').onmouseout=function () {
    document.getElementById('settingbutton').src = 
    "setting.PNG";
    };
    */
 //  document.getElementById(g_current_button_id).style.color = "#cccccc";
  // document.getElementById('setting_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //  g_current_button_id='setting_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    callServer_Setting();
}
function Button_Manage_Service() {
    
	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
    Button_Manage_Profile();
}
//function Button_Wallet() {
 //   callServer_Wallet();
//}
/*
function Button_P2P() {
    //document.getElementById('setting_button').onmousedown=function () {
    
 //  document.getElementById(g_current_button_id).style.color = "#cccccc";
  // document.getElementById('setting_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
 //  g_current_button_id='setting_button';
//	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    callServer_P2PSetting();
}
*/
function Button_restart() {
    //document.getElementById('restart_button').onmousedown=function () {
    /* document.getElementById('restartbutton').src = 
    "restart_down.PNG";
    //};
    document.getElementById('restart_button').onmouseout=function () {
    document.getElementById('restartbutton').src = 
    "restart.PNG";
    };
    */
 //  document.getElementById(g_current_button_id).style.color = "#cccccc";
	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
   g_current_button_id='restart_button';
	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    callserver_restart();
}
function Button_shutdown() {
    //document.getElementById('shutdown_button').onmousedown=function () {
    /* document.getElementById('shutdownbutton').src = 
    "shutdown_down.PNG";
    //};
    document.getElementById('shutdown_button').onmouseout=function () {
    document.getElementById('shutdownbutton').src = 
    "shutdown.PNG";
    };
    */
 //   document.getElementById(g_current_button_id).style.color = "#cccccc";
  //  document.getElementById('shutdown_button').style.color = "#ffffff";
//	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
  //   g_current_button_id='shutdown_button';
 // 	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";
 callserver_shutdown();
}
function Button_get_system_log() {
    //document.getElementById('log_button').onmousedown=function () {
    /* document.getElementById('logbutton').src = 
    "log_down.PNG";
    //};
    document.getElementById('log_button').onmouseout=function () {
    document.getElementById('logbutton').src = 
    "log.PNG";
    };
    */
 //  document.getElementById(g_current_button_id).style.color = "#cccccc";
  //  document.getElementById('log_button').style.color = "#ffffff";
	document.getElementById(g_current_button_id).style.backgroundColor = TableMenuBackgroundNormalColor;
   g_current_button_id='log_button';
	document.getElementById(g_current_button_id).style.backgroundColor = "#E2E2E2";

    callServer_get_system_log();
}
function callServer_CH_Inquery() {
 // var ch_no = document.getElementById("ch_no").value;
  var content = parent.document.getElementById("content");

 //var url = "/cgi-bin/cgi_eziptv?channel_inquery="+encodeURI(ch_no)+"&flag="+Math.random();
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/query_channel_list?token="+encodeURI(g_token)+"&flag="+Math.random();
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Channel Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = CH_inquery;
		xmlHttp.send(null);
	}

}

function callezserver_all_channel() {

	//var button_id = document.getElementById("channel_on_off_button");
	g_show_off_channel=0;
	g_channel_position=1;
	g_channel_limit=g_constant_limit;
	call_get_channels(g_channel_position,g_channel_limit);

}

function get_off_channel()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    //alert(response);
    if (response==0)
    {
   	alert("No OFF channel");
    }else if (response>0)
    {
	g_off_channel_no=response;
    	g_show_off_channel=1;
    	//alert(g_channel_position);
    	g_channel_position=1;
    	if (g_off_channel_no>g_constant_limit)
    	{
		g_channel_limit=g_constant_limit;
	}else
	{
		g_channel_limit=g_off_channel_no;
	}
	call_get_channels(g_channel_position,g_channel_limit);
    }
    	
  }
}
function callezserver_off_channel()
{
	var cgi_url;
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/get_off_channel_no?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = get_off_channel;
	xmlHttp.send(null);	
}
var g_total_channel_category_no=0;
var g_Channel_Categories_tems=[];
var g_Channel_Categories_icons=[];
var g_total_movie_category_no=0;
var g_Movie_Categories_tems=[];
var g_Movie_Categories_icons=[];
var g_total_series_category_no=0;
var g_Series_Categories_tems=[];
var g_Series_Categories_icons=[];

function call_get_channels_post() 
{
  	var cgi_url;
	var cookieStr;
	var i=0;
	var folder_name;
	var strlength;
	if (xmlHttp.readyState == 4) {
	
	var response = xmlHttp.responseText.split("\r\n");
	g_total_channel_category_no=0;
		for (i=0;;i++)
	  	{
		    if (response[i]==0)
	  	    {
	  	    	break;
	 	    } else
	  	    {
	  	    	strlength=response[i].length;
		  	folder_name=response[i].substring(9);
	 	    	g_Channel_Categories_tems[g_total_channel_category_no]=decodeURI(folder_name); 
	 	    	i++;
	 	    	g_Channel_Categories_icons[g_total_channel_category_no]=response[i].substring(5); 
	 	    	//alert(g_Channel_Categories_tems[g_total_channel_category_no]);
	 	    	g_total_channel_category_no++;
	 	    	i++;
	    	   } 
	      	}
	      	//alert(g_total_channel_category_no);
	  	g_token=find_cookie_value("token");
		if (g_token!=0)
		{
			if (g_show_off_channel==0)
			{
				cgi_url = "/server/get_channels?token="+encodeURI(g_token)+"&position="+g_channel_position+"&limit="+g_channel_limit+"&flag="+Math.random();
			}else if (g_show_off_channel==1)
			{
				cgi_url = "/server/get_channels?token="+encodeURI(g_token)+"&position="+g_channel_position+"&limit="+g_channel_limit+"&offchannel=1"+"&flag="+Math.random();
			}
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = get_channels;
			xmlHttp.send(null);
		}
	}

}
function call_get_channels(position,limit)
{
	var cgi_url;
	g_token=find_cookie_value("token");
	g_channel_position=position;
	g_channel_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_channel_category?token="+encodeURI(g_token)+"&icon=1"+"&serverid=1"+"&flag="+Math.random();
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = call_get_channels_post;
		xmlHttp.send(null);
	}
}
function call_get_movies_post() 
{
  	var cgi_url;
  	var i=0;
  	var folder_name;
  	var strlength;
   	if (xmlHttp.readyState == 4) {
   	var response = xmlHttp.responseText.split("\r\n");
  	g_total_movie_category_no=0;
   		for (i=0;;i++)
	  	{
		    if (response[i]==0)
	  	    {
	  	    	break;
	 	    } else
	  	    {
	  	    	strlength=response[i].length;
		  	folder_name=response[i].substring(9);
	 	    	g_Movie_Categories_tems[g_total_movie_category_no]=folder_name; 
	 	    	i++;
	 	    	g_Movie_Categories_icons[g_total_movie_category_no]=response[i].substring(5); 
	 	    	//alert(g_Movie_Categories_tems[g_total_movie_category_no]);
	 	    	g_total_movie_category_no++;
	 	    	i++;
	    	   } 
	      	}
	 	g_token=find_cookie_value("token");
  		if (g_token!=0)
		{
			cgi_url = "/server/get_movies?token="+encodeURI(g_token)+"&position="+g_movie_position+"&limit="+g_movie_limit+"&flag="+Math.random();
	
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = get_movies;
			xmlHttp.send(null);
		}
	}

}
function call_get_movies(position,limit) 
{
  	var cgi_url;
	var cookieStr;
 
   	g_token=find_cookie_value("token");
	g_movie_position=position;
	g_movie_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		cgi_url = "/server/get_movie_category?token="+encodeURI(g_token)+"&icon=1"+"&serverid=1"+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = call_get_movies_post;
		xmlHttp.send(null);
	}

}
/*
function call_get_channels(position,limit) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 	//alert(position);
 	//alert(limit);
   	g_token=find_cookie_value("token");
	g_channel_position=position;
	g_channel_limit=limit;
	//alert(g_channel_limit);
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		if (g_show_off_channel==0)
		{
			cgi_url = "/server/get_channels?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&flag="+Math.random();
		}else if (g_show_off_channel==1)
		{
			cgi_url = "/server/get_channels?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&offchannel=1"+"&flag="+Math.random();
		}
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = get_channels;
		xmlHttp.send(null);
	}

}
*/

function close_movie_modal() {
   var modal = document.getElementById('PanelModal');
   modal.style.display = "none";
   call_get_movies(g_movie_position,g_movie_limit);
}
function close_modal() {
   var modal = document.getElementById('PanelModal');
   modal.style.display = "none";
}

function call_Edit_Work_Folder(i)
{
	var modal = document.getElementById('PanelUpdateWorkFolderModal');
	modal.style.display = "block";
	document.getElementById('updateselectedbl').value=JSONWorkFolder.folder[i].server_name;
	document.getElementById('updatefoldertype').value=JSONWorkFolder.folder[i].type;
	document.getElementById('updateselectedpath').value=JSONWorkFolder.folder[i].directory;
	if (JSONWorkFolder.folder[i].status == '1')
	{
		document.getElementById('updateenabled').checked = true;
	}else
	{
		document.getElementById('updateenabled').checked = false;
	}

}
function close_update_work_folder_modal() {
   var modal = document.getElementById('PanelUpdateWorkFolderModal');
   modal.style.display = "none";
   callServer_get_work_folder(g_work_folder_position,g_work_folder_limit);
}
function open_work_folder_modal()
{
	var modal = document.getElementById('PanelWorkFolderModal');
	modal.style.display = "block";
}
function close_work_folder_modal() {
   var modal = document.getElementById('PanelWorkFolderModal');
   modal.style.display = "none";
   callServer_get_work_folder(g_work_folder_position,g_work_folder_limit)
}
function open_blockchain_node_modal(i)
{
	var modal = document.getElementById('PanelEditBlockchainNodeModal');
	modal.style.display = "block";
}
function close_blockchain_node_modal() {
   var modal = document.getElementById('PanelEditBlockchainNodeModal');
   modal.style.display = "none";
}
function open_modal()
{
	var modal = document.getElementById('PanelModal');
	modal.style.display = "block";
	
}
function open_xmltv_modal()
{
	var modal = document.getElementById('PanelModalAddXMLTV');
	modal.style.display = "block";
}
function close_xmltv_modal() {
   var modal = document.getElementById('PanelModalAddXMLTV');
   modal.style.display = "none";
   callServer_Get_XMLTV_Info(g_xmltv_position,g_xmltv_limit);
}

function open_user_modal()
{
	var modal = document.getElementById('PanelModal');
	var user_level = document.getElementById("user_level");
	modal.style.display = "block";
	if (g_add_user_flag==1)
	{		
		 document.getElementById('new_user_text').innerHTML='<font face="Arial" size="6"><b>New User</b></font>';
	}else if (g_add_user_flag==2)
	{
		 document.getElementById('new_user_text').innerHTML='<font face="Arial" size="6"><b>New Android Device</b></font>';
		 document.getElementById('username_text').innerHTML='<font face="Arial" size="2">MAC Address</font>';
		 
		 document.getElementById('password').value='';
		 document.getElementById('password').disabled=true;
		  
		 document.getElementById('macid_text').innerHTML='<font face="Arial" size="2">Device Type</font>';
		 document.getElementById('macid').value='android';
		 document.getElementById('macid').disabled=true;
		 user_level.remove(2);
		 user_level.remove(2);
		 user_level.remove(2);
		 user_level.remove(2);
		 
	}else if (g_add_user_flag==3)
	{
		 document.getElementById('new_user_text').innerHTML='<font face="Arial" size="6"><b>New Mag STB</b></font>';
		 document.getElementById('username_text').innerHTML='<font face="Arial" size="2">MAC Address</font>';

		 document.getElementById('password').value='';
		 document.getElementById('password').disabled=true;
		  
		 document.getElementById('macid_text').innerHTML='<font face="Arial" size="2">Device Type</font>';
		 document.getElementById('macid').value='mag';
		 document.getElementById('macid').disabled=true;
		 user_level.remove(2);
		 user_level.remove(2);
		 user_level.remove(2);
		 user_level.remove(2);
	}else if (g_add_user_flag==4)
	{
		 document.getElementById('new_user_text').innerHTML='<font face="Arial" size="6"><b>New Active Code</b></font>';
		 document.getElementById('username_text').innerHTML='<font face="Arial" size="2">Active Code</font>';
		 
		 var ranpass=Math.floor(Math.random() * 10000000000) + 1;
		 document.getElementById('username').value=ranpass;
		 
		 document.getElementById('rating_password').value="1234";
		 
		 
		 document.getElementById('password').value='';
		 document.getElementById('password').disabled=true;
		  
		 document.getElementById('macid_text').innerHTML='<font face="Arial" size="2">Device Type</font>';
		 document.getElementById('macid').value='activecode';
		 document.getElementById('macid').disabled=true;
		 user_level.remove(2);
		 user_level.remove(2);
		 user_level.remove(2);
		 user_level.remove(2);
	}
	
}
function close_user_modal() {
   var modal = document.getElementById('PanelModal');
   modal.style.display = "none";
   call_get_users(g_user_position,g_user_limit);
}
function open_setting_modal()
{
	var modal = document.getElementById('PanelModalSetting');
	modal.style.display = "block";
}
function close_setting_modal() {
   var modal = document.getElementById('PanelModalSetting');
   modal.style.display = "none";
}
function callezserver_get_mass_first_channel()
{
	
	var cgi_url;
	var category_id="mass_edit_chcategory";
	var chtype_id="mass_edit_chtype";
	var netip_id="mass_edit_input_adapter";
	var buffersize_id="mass_edit_buffer_size";
	var tolerance_id="mass_edit_tolerance";
	var cacheondemandflag_id="mass_edit_cacheondemandflag";
	var catch_up_days_id="mass_edit_catch_up_days";
	var http_user_agent_id="mass_edit_http_user_agent";
	
	var forwardflag_id="mass_edit_forwardflag";;
	var bitratetypeflag_id="mass_edit_HLSType";
	var mobilebitrate_id="mass_edit_mobilebitrate";
	var sdbitrate_id="mass_edit_sdbitrate";
	var hdbitrate_id="mass_edit_hdbitrate";
	var mobilewidth_id="mass_edit_mobilewidth"
	var sdwidth_id="mass_edit_sdwidth";
	var hdwidth_id="mass_edit_hdwidth";
	var mobileheight_id="mass_edit_mobileheight";
	var sdheight_id="mass_edit_sdheight";
	var hdheight_id="mass_edit_hdheight";
	var videoformat_id="mass_edit_videoformat";
	var videoaspect_id="mass_edit_videoaspect";
	var audioformat_id="mass_edit_audioformat";
	var preset_id="mass_edit_preset";

   
	var category;
	var chtype;
	var buffersize;
	var tolerance;
	var forwardflag;
	var cacheondemandflag;
	var netip;
	var catch_up_days;
	var epg_channel_id;
	var http_user_agent;
	var bitratetypeflagarray;
	var bitratetypeflag;
	var mobilebitrate;
	var sdbitrate;
	var hdbitrate;
	var mobilewidth;
	var sdwidth;
	var hdwidth;
	var mobileheight;
	var sdheight;
	var hdheight;
	var videoaspect;
	var preset;  
	var videoformat;
	var audioformat;
	var i=0;	
	
   	g_token=find_cookie_value("token");

	cgi_url = "/server/get_mass_first_channel?token="+encodeURI(g_token)+"&flag="+Math.random();
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText.split("\r\n");
			var i=0;
			
			while (1)
			{			
	 	 		if (response[i]==0) break;
				//alert(response[i]);
			 	category=response[i].substring(6);
			 	
			 	i++;
			 	chtype=response[i];
			 	
			 	i++;
			 	http_user_agent=response[i];
			 	i++;
			 	netip=response[i];
			 	//alert(netip);
			 	i++;
			 	buffersize=response[i];
			 	i++;
			 	tolerance=response[i];
			 	i++;
			 	catch_up_days=response[i];
			 	i++;
			 	forwardflag=response[i];
			 	i++;
			 	cacheondemandflag=response[i];
			 	i++;
			 	bitratetypeflag=response[i];
			 	//alert(bitratetypeflag);
			 	i++;
			 	mobilebitrate=response[i];
			 	i++;
			 	sdbitrate=response[i];
			 	i++;
			 	hdbitrate=response[i];
			 	i++;
			 	mobilewidth=response[i];
			 	i++;
			 	sdwidth=response[i];
			 	i++;
			 	hdwidth=response[i];
			 	i++;
			 	mobileheight=response[i];
			 	i++;
			 	sdheight=response[i];
			 	i++;
			 	hdheight=response[i];
			 	i++;
			 	//alert(response[i]);
			 	videoaspect=response[i].substring(6);
			 	i++;
			 	preset=response[i].substring(6);
			 	//alert(preset);
			 	i++;
			 	videoformat=response[i].substring(6);
			 	i++;
			 	audioformat=response[i].substring(6);			 	
				//alert(response[i]);
				i++
			}
			
			//document.getElementById(category_id).value=category;;
			document.getElementById(chtype_id).value=chtype;
			document.getElementById(http_user_agent_id).value=http_user_agent;
			document.getElementById(netip_id).value=netip;
			document.getElementById(buffersize_id).value=buffersize
			document.getElementById(tolerance_id).value=tolerance;
			document.getElementById(catch_up_days_id).value=catch_up_days;
			document.getElementById(forwardflag_id).value=forwardflag;
			if (cacheondemandflag==1)
			{
				document.getElementById(cacheondemandflag_id).checked=true;
			}else
			{
				document.getElementById(cacheondemandflag_id).checked=false;
			}
			//alert(bitratetypeflag);
			if (bitratetypeflag==1)
			{
				document.getElementById(bitratetypeflag_id).checked=true;
			}else
			{
				document.getElementById(bitratetypeflag_id).checked=false;
			}
			
	/*
			for (j=0;j<2;j++)
			{
				if (j!=bitratetypeflag)
				{
					bitratetypeflag_id="mass_edit_HLSType"+j;
					document.getElementById(bitratetypeflag_id).checked=false;
				}else
				{
					bitratetypeflag_id="mass_edit_HLSType"+bitratetypeflag;
					document.getElementById(bitratetypeflag_id).checked=true;
				}
			
			}
			if (bitratetypeflag==2)
			{
				if (mobilewidth==0)
				{
					mobilewidth="Auto";
				}
				if (sdwidth==0)
				{
					sdwidth="Auto";
				}
				if (hdwidth==0)
				{
					hdwidth="Auto";
				}
				if (mobileheight==0)
				{
					mobileheight="Auto";
				}
				if (sdheight==0)
				{
					sdheight="Auto";
				}
				if (hdheight==0)
				{
					hdheight="Auto";
				}
				if (videoaspect==0)
				{
					videoaspect="Auto";
				}
				document.getElementById(mobilebitrate_id).value=mobilebitrate;
				document.getElementById(sdbitrate_id).value=sdbitrate;
				document.getElementById(hdbitrate_id).value=hdbitrate;
				document.getElementById(mobilewidth_id).value=mobilewidth;
				document.getElementById(sdwidth_id).value=sdwidth;
				document.getElementById(hdwidth_id).value=hdwidth;
				document.getElementById(mobileheight_id).value=mobileheight;
				document.getElementById(sdheight_id).value=sdheight;
				document.getElementById(hdheight_id).value=hdheight;
				document.getElementById(videoformat_id).value=videoformat;
				document.getElementById(audioformat_id).value=audioformat;
				document.getElementById(videoaspect_id).value=videoaspect;
				document.getElementById(preset_id).value=preset;
				
				document.getElementById(mobilebitrate_id).disabled=false;
				document.getElementById(sdbitrate_id).disabled=false;
				document.getElementById(hdbitrate_id).disabled=false;
				document.getElementById(mobilewidth_id).disabled=false;
				document.getElementById(sdwidth_id).disabled=false;
				document.getElementById(hdwidth_id).disabled=false;
				document.getElementById(mobileheight_id).disabled=false;
				document.getElementById(sdheight_id).disabled=false;
				document.getElementById(hdheight_id).disabled=false;
				document.getElementById(videoformat_id).disabled=false;
				document.getElementById(audioformat_id).disabled=false;
				document.getElementById(videoaspect_id).disabled=false;
				document.getElementById(preset_id).disabled=false;
				
			}
			*/
			
		}
	};			 
	xmlHttp.send(g_checkedstring);
}
function open_mass_edit_modal()
{
	var modal = document.getElementById('PanelModalMassEdit');
	//alert(g_total_ch_no);
	//g_checkedstring=get_total_checked_string(g_total_ch_no,0);
	//alert(g_checkedstring);
	g_checkedstring='1';
	//if (g_checkedstring=='0')
	//{
	//}else
	//{
		//alert("get_mass_first_channel");
		callezserver_get_mass_first_channel();
		modal.style.display = "block";
	//}
}
function close_mass_edit_modal() {
   var modal = document.getElementById('PanelModalMassEdit');
   modal.style.display = "none";
}
function callezserver_get_mass_first_series()
{
	
	var cgi_url;
	var category_id="mass_edit_seriescategory";
	var rating_id="mass_edit_rating";
	var season_no_id="mass_edit_season_no";
	var released_date_id="mass_edit_released_date";


   
	var category;
	var rating;
	var season_no;
	var released_date;

   	g_token=find_cookie_value("token");

	cgi_url = "/server/get_mass_first_series?token="+encodeURI(g_token)+"&flag="+Math.random();
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText.split("\r\n");
			var i=0;
			
			while (1)
			{			
	 	 		if (response[i]==0) break;
				//alert(response[i]);
			 	category=response[i].substring(6);
			 	//alert(category);
			 	i++;
			 	season_no=response[i].substring(6);
			 	//alert(season_no);
			 	i++;
			 	rating=response[i].substring(6);
			 	//alert(rating);
			 	i++;
			 	released_date=response[i].substring(6);
			 	//alert(released_date);
			 	i++;
			}
			
		
			document.getElementById(category_id).value=decodeURI(category);
			document.getElementById(season_no_id).value=season_no;
			document.getElementById(rating_id).value=rating;
			document.getElementById(released_date_id).value=released_date;
			
			
		}
	};			 
	xmlHttp.send(g_checkedstring);
}
function open_mass_edit_series_modal()
{
	var modal = document.getElementById('PanelModalMassEditSeries');
	//alert(g_total_ch_no);
	g_checkedstring=get_total_checked_string(g_total_series_no,0);
	//alert(g_checkedstring);
	if (g_checkedstring=='0')
	{
	}else
	{
		//alert("get_mass_first_channel");
		callezserver_get_mass_first_series();
		modal.style.display = "block";
	}
}
function close_mass_edit_series_modal() {
   var modal = document.getElementById('PanelModalMassEditSeries');
   modal.style.display = "none";
}
function callezserver_get_mass_first_movie()
{
	
	var cgi_url;
	var category_id="mass_edit_category";
	var quality_id="mass_edit_quality";
	var rentpoint_id="mass_edit_rentpoint";
	var buypoint_id="mass_edit_buypoint";
	var rentperiod_id="mass_edit_rentperiod";
	var ratingflag_id="mass_edit_ratingflag";
	var forwardflag_id="mass_edit_forwardflag";


   
	var category;
	var quality;
	var rentpoint;
	var buypoint;
	var rentperiod;
	var ratingflag;
	var forwardflag;
	//alert(category_id);
   	g_token=find_cookie_value("token");

	cgi_url = "/server/get_mass_first_movie?token="+encodeURI(g_token)+"&flag="+Math.random();
	//alert(cgi_url);
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText.split("\r\n");
			var i=0;
			
			while (1)
			{			
	 	 		if (response[i]==0) break;
			 	category=response[i].substring(6);
				//alert(category);			 	
			 	i++;
			 	rentpoint=response[i].substring(6);
			 	//alert(rentpoint);
			 	i++;
			 	buypoint=response[i].substring(6);
			 	//alert(buypoint);
			 	i++;
			 	ratingflag=response[i].substring(6);
			 	//alert(ratingflag);
			 	i++;
			 	quality=response[i].substring(6);
			 	//alert(quality);
			 	i++;
			 	rentperiod=response[i].substring(6);
			 	//alert(rentperiod);
			 	i++;
			 	forwardflag=response[i].substring(6);
			 	//alert(forwardflag);
			 	i++;
			 	
			 	
			}
			
			document.getElementById(category_id).value=decodeURI(category);;
			document.getElementById(quality_id).value=quality;
			document.getElementById(rentpoint_id).value=rentpoint;
			document.getElementById(buypoint_id).value=buypoint;
			document.getElementById(rentperiod_id).value=rentperiod;
			document.getElementById(ratingflag_id).value=ratingflag;
			document.getElementById(forwardflag_id).value=forwardflag;
	
			
		}
	};			 
	xmlHttp.send(g_checkedstring);
}
function open_mass_edit_movie_modal()
{
	var modal = document.getElementById('PanelModalMassEditMovie');
	//alert(g_total_ch_no);
	g_checkedstring=get_total_checked_string(g_total_movie_no,0);
	//alert(g_checkedstring);
	if (g_checkedstring=='0')
	{
	}else
	{
		//alert("get_mass_first_channel");
		callezserver_get_mass_first_movie();
		modal.style.display = "block";
	}
}
function close_mass_edit_movie_modal() {
   var modal = document.getElementById('PanelModalMassEditMovie');
   modal.style.display = "none";
}
function callezserver_get_mass_first_user()
{
	
	var cgi_url;
	var mass_edit_group_id="mass_edit_group";
	//var mass_edit_paymodel_id="mass_edit_paymodel";
	var mass_edit_isp_lock_id="mass_edit_isp_lock";
	var mass_edit_max_connection_id="mass_edit_max_connection";
	//var mass_edit_user_point_id="mass_edit_user_point";


   
	var group;
	var paymodel;
	var isp_lock;
	var max_connection;
	var user_point;
	
   	g_token=find_cookie_value("token");

	cgi_url = "/server/get_mass_first_user?token="+encodeURI(g_token)+"&flag="+Math.random();
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function() {

		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText.split("\r\n");
			var i=0;
			
			while (1)
			{			
	 	 		if (response[i]==0) break;
				group=response[i].substring(6);
			 	//alert(group);
			 	
			 	i++;
			 	max_connection=response[i].substring(6);
			 	//alert(max_connection);
			 	i++;
			 	paymodel=response[i].substring(6);
			 	//alert(paymodel);
			 	i++;
			 	user_point=response[i].substring(6);
			 	//alert(user_point);
			 	i++;
			 	isp_lock=response[i].substring(6);
			 	//alert(isp_lock);
			 	i++;
			}
			
			document.getElementById(mass_edit_group_id).value=group;;
//			document.getElementById(mass_edit_paymodel_id).value=paymodel;
			document.getElementById(mass_edit_isp_lock_id).value=isp_lock;
			document.getElementById(mass_edit_max_connection_id).value=max_connection;
//			document.getElementById(mass_edit_user_point_id).value=user_point;
			
		}
	};			 
	xmlHttp.send(g_checkedstring);
}
function open_mass_edit_user_modal()
{
	var modal = document.getElementById('PanelModalMassEditUsers');
	//alert(g_total_user_no);
	g_checkedstring=get_total_checked_string(g_user_no,0);
	//alert(g_checkedstring);
	if (g_checkedstring=='0')
	{
	}else
	{
		//alert("get_mass_first_channel");
		callezserver_get_mass_first_user();
		modal.style.display = "block";
	}
}
function close_mass_edit_user_modal() {
   var modal = document.getElementById('PanelModalMassEditUsers');
   modal.style.display = "none";
}
function open_more_user_modal(username)
{
	var modal = document.getElementById('PanelModalMoreUsers');
	//alert(g_total_user_no);
	//alert(g_checkedstring);
	g_username=username;
	
	call_Query_User_More();
	modal.style.display = "block";

}
function close_more_user_modal() {
   var modal = document.getElementById('PanelModalMoreUsers');
   modal.style.display = "none";
}		
function sort_channel_ascending()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
 	var content;
   //alert(response);
    if (response==0)
    {
   	alert("Sort Failed");
    	if (g_channel_name_order_flag==1)
    	{
    		g_channel_name_order_flag=0;
 		content = document.getElementById("channel_name_id");
 		content.innerHTML='<font face="Arial" size="2">Channel Name</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      '<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
   	}else if (g_channel_category_order_flag==1)
    	{
    		g_channel_category_order_flag=0;
  		content = document.getElementById("category_id");
 		content.innerHTML='<font face="Arial" size="2">Category</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
 	}
    }else if (response>0)
    {
    	g_show_off_channel=0;
   	g_channel_position=1;
   	g_channel_limit=g_constant_limit;
   	call_get_channels(g_channel_position,g_channel_limit);
    }
    	
  }
}
function callezserver_sort_channel_ascending(sortkey)
{
	var cgi_url;
	var content;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (sortkey=="name")
	{
		content = document.getElementById("channel_name_id");
		g_channel_name_order_flag=1;
		g_channel_category_order_flag=0;
	}else if (sortkey=="category")
	{
		content = document.getElementById("category_id");
		g_channel_name_order_flag=0;
		g_channel_category_order_flag=1;
	}
	content.innerHTML='<div class="loader"></div>';
	g_token=find_cookie_value("token");
	cgi_url = "/server/sort_channel_ascending?token="+encodeURI(g_token)+"&sortkey="+sortkey+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = sort_channel_ascending;
	xmlHttp.send(null);	
}
function sort_channel_descending()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
 	var content;
   //alert(response);
    if (response==0)
    {
  	alert("Sort Failed");
    	if (g_channel_name_order_flag==2)
    	{
    		g_channel_name_order_flag=0;
  		content = document.getElementById("channel_name_id");
  		content.innerHTML='<font face="Arial" size="2">Channel Name</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      '<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	     
  	}else if (g_channel_category_order_flag==2)
    	{
    		g_channel_category_order_flag=0;
 		content = document.getElementById("category_id");
 		content.innerHTML='<font face="Arial" size="2">Category</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      
   	}
     }else if (response>0)
    {
    	g_show_off_channel=0;
   	g_channel_position=1;
   	g_channel_limit=g_constant_limit;
  	call_get_channels(g_channel_position,g_channel_limit);
    }
    	
  }
}
function callezserver_sort_channel_descending(sortkey)
{
	var cgi_url;
	var content;
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (sortkey=="name")
	{
		content = document.getElementById("channel_name_id");
		g_channel_name_order_flag=2;
		g_channel_category_order_flag=0;
	}else if (sortkey=="category")
	{
		content = document.getElementById("category_id");
		g_channel_name_order_flag=0;
		g_channel_category_order_flag=2;
	}
	content.innerHTML='<div class="loader"></div>';
	g_token=find_cookie_value("token");
	cgi_url = "/server/sort_channel_descending?token="+encodeURI(g_token)+"&sortkey="+sortkey+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = sort_channel_descending;
	xmlHttp.send(null);	
}	

function open_channel_category_modal()
{
 	var cgi_url;
	bQuery_Channel_Status=0;
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/get_channel_category?token="+encodeURI(g_token)+"&icon=1"+"&serverid=1"+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) {
		 		var response = xmlHttp.responseText.split("\r\n");
		 		var i=0;
				var modal = document.getElementById('PanelModalChannelCategory');
				var channel_category_id= document.getElementById('channel_category');
				var channel_category_no_id= document.getElementById('total_no');
				
				var str;
				var categoryname;
			 	var categoryicon;
			 	g_total_channel_category_no=0;
				modal.style.display = "block";
				/*str='<font face="Arial" size="2">'+' <select size="10"  style="width: 500;padding:5;" name="channel_category_list" id=channel_category_list>';
		 		while (1)
				{
		 			if (response[i]==0) break;
		 			categoryname=response[i].substring(9);
		 			g_Channel_Categories_tems[i]=categoryname;
		 			g_total_channel_category_no++; 
			 	    	//alert(categoryname);
		 			if (i==0)
		 			{
			 			str+='<option style="padding: 2px" selected="selected" value="'+decodeURI(categoryname)+'">'+decodeURI(categoryname)+'</option>';
			 			 
		 			}else
		 			{
			 			str+='<option style="padding: 2px" value="'+decodeURI(categoryname)+'">'+decodeURI(categoryname)+'</option>';
			 		}
			 		i++;
			 	}
		 		str+='</select></font>';
		 		*/
		 		str='<div class="scroll-container"><font face="Arial" size="2">'+' <ul id="category_list" class="draggable-list"  style="list-style-type: none;width: 500;padding:5;" name="channel_category_list" id=channel_category_list>';
		 		//alert(g_categoryclickedItemValue);
		 		
		 		if (g_categoryclickedItemValue)
		 		{
					while (1)
					{
			 			if (response[i]==0) break;
			 			categoryname=response[i].substring(9);
			 			g_Channel_Categories_tems[g_total_channel_category_no]=categoryname;
			 			i++;
			 			
			 			categoryicon=response[i].substring(5);
			 			g_Channel_Categories_icons[g_total_channel_category_no]=categoryicon;
			 			g_total_channel_category_no++; 
			 			if (g_categoryclickedItemValue==categoryname)
			 			{
				 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: #aaa;padding: 5px;border: 1px solid #000;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
				    			    '</span>'+decodeURI(categoryname)+'</li>';
				 			
			 			}else
			 			{
				 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: white;padding: 5px;border: 1px solid #ccc;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
				 		}
				 		i++;
				 		i++;
				 	}
		 		}else
		 		{
					while (1)
					{
			 			if (response[i]==0) break;
			 			categoryname=response[i].substring(9);
			 			g_Channel_Categories_tems[g_total_channel_category_no]=categoryname;
			 			i++;
			 			categoryicon=response[i].substring(5);
			 			g_Channel_Categories_icons[g_total_channel_category_no]=categoryicon;
			 			g_total_channel_category_no++; 
			 			if (i==0)
			 			{
				 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: #aaa;padding: 5px;border: 1px solid #000;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
				 			g_categoryclickedItemValue=categoryname;
				 			
			 			}else
			 			{
				 			str += '<li draggable="true" style="display: flex; align-items: center; background-color: white; padding: 0px; border: 0px solid #ccc; margin-bottom: 5px; cursor: grab; transition: background-color 0.3s ease;" value="' + decodeURI(categoryname) + '">' +
							    '<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>' + decodeURI(categoryname) + '</li>';
    						}
				 		i++;
				 		i++;
				 	}
			 	}
			 	str+='</ul></font></div>';
			 	
		 		channel_category_id.innerHTML=str;
		 		channel_category_no_id.innerHTML='<font face="Arial" size="2">'+g_total_channel_category_no+'</font>';
		 		document.getElementById('Add').focus();
		 		sortable_list = document.getElementById("category_list");
				sortable_listItems = sortable_list.querySelectorAll("li");
				let draggedItem = null;
				
				
				sortable_list.addEventListener("dragstart", (event) => {
				  draggedItem = event.target;
				  draggedItem.classList.add("dragging");
				  event.dataTransfer.effectAllowed = "move";
				  event.dataTransfer.setData("text/html", draggedItem.innerHTML);
				});
				
				sortable_list.addEventListener("dragover", (event) => {
				  event.preventDefault();
				  const afterElement = getDragAfterElement(sortable_list, event.clientY);
				
				  if (afterElement == null) {
				    sortable_list.appendChild(draggedItem);
				  } else {
				    sortable_list.insertBefore(draggedItem, afterElement);
				  }
				});
				
				sortable_list.addEventListener("dragend", () => {
				  draggedItem.classList.remove("dragging");
				  updateItemIndexes();
				});
				// Add click event listeners to each item
				sortable_listItems.forEach((item) => {
				  item.addEventListener("click", (event) => {
				    sortable_listItems.forEach((item) => {
				    item.style.backgroundColor = "#fff";
				      item.classList.remove("clicked");
				    });
				    
				    event.currentTarget.classList.add("clicked");
				
				    // Show the clicked item's value
				    g_categoryclickedItemValue = event.currentTarget.innerText;
				    //alert(`Clicked Item Value: ${clickedItemValue}`);
				    event.currentTarget.style.backgroundColor = "#aaa";
				  });
				});


		 }		
	};
	xmlHttp.send(null);
}
function close_update_channel_category_modal() {
	var modal = document.getElementById('PanelModalChannelCategory');
	modal.style.display = "none";
	g_categoryclickedItemValue=null;
	g_token=find_cookie_value("token");
	

	var updatestr="";
	 var str;
	 const listItems = sortable_list.querySelectorAll("li");
	 listItems.forEach((item, index) => {
		str='{"id":"'+index+'","name":"'+item.innerText+'","icon":"'+g_Channel_Categories_icons[index]+'"}';
		//alert(str);
		if (updatestr)
		{
			updatestr=updatestr+','+str;
		}else
		{
			updatestr=updatestr+str;
		}
	});
	//alert(updatestr);
	cgi_url = "/server/write_category_json?token="+encodeURI(g_token)+"&type=1"+"&flag="+Math.random();
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) {
			
	 		call_get_channels(g_channel_position,g_channel_limit);
		}
	}
	xmlHttp.send(updatestr);
	

}
function close_channel_category_modal() {
	var modal = document.getElementById('PanelModalChannelCategory');
	modal.style.display = "none";
	g_categoryclickedItemValue=null;
	call_get_channels(g_channel_position,g_channel_limit);
}
function close_channel_modal() {
   var modal = document.getElementById('PanelModal');
   call_get_channels(g_channel_position,g_channel_limit);
   modal.style.display = "none";
}
function call_add_genre()
{
	var select = document.getElementById('genre_itemSelect');
	var selectedOption = select.options[select.selectedIndex];
	var text = genreObject[selectedOption.value];
	if (text !== '') {
		if (itemExists(selectedOption.value)) 
		{
			alert('Item already exists!');
		} else 
		{
			var listItem = createListItem(selectedOption.value);
			genre_items.push(selectedOption.value);
			document.getElementById('selectedItemsList').appendChild(listItem);
			select.selectedIndex = 0;
			//alert(genre_items);
		}
	}
}
function open_channel_more_modal(chno)
{
	var modal = document.getElementById('PanelModalChannelMore');
	g_ch_no=chno;
	call_Get_Server_IP(g_ch_no);
	genre_items=[];
	document.getElementById('selectedItemsList').innerHTML = '';
	modal.style.display = "block";
}
function close_channel_more_modal() {
   var modal = document.getElementById('PanelModalChannelMore');
   modal.style.display = "none";
}

function call_Add_Channel_Category()
{
 	var cgi_url;
 	var api_option;
 	var category_url =document.getElementById("add_category_url").value;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var newcategory = document.getElementById("newcategory").value;
	
	if (newcategory)
	{
		if (category_url.length>0)
		{
			cgi_url = "/server/add_channel_category?token="+encodeURI(g_token)+"&iconurl="+category_url+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}else
		{
			cgi_url = "/server/add_channel_category?token="+encodeURI(g_token)+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}
		
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		//alert(cgi_url);
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4) {
				
		 		var response = xmlHttp.responseText;
			 	
				if (category_url.length==0)
				{
			 		api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"channel_icon"+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
	
					call_Upload_Files(event,UPLOAD_CHANNEL_CATEGORY_ICON,api_option);
				}else
				{
					close_channel_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Added</font>';
			 			g_categoryclickedItemValue=newcategory;
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}


			}
		}
		xmlHttp.send(null);
	}

	
}

function call_Edit_Channel_Category()
{
 	var cgi_url;
	var currentcategory =g_categoryclickedItemValue;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	//var newcategory = prompt("Please enter new category:", currentcategory);
	var category_url =document.getElementById("edit_category_url").value;
	var newcategory = document.getElementById("editcategory").value;
	if (newcategory)
	{	
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		if (category_url.length>0)
		{
			cgi_url = "/server/edit_channel_category?token="+encodeURI(g_token)+"&currentcategory="+encodeURI(currentcategory)+"&newcategory="+encodeURI(newcategory)+"&iconurl="+category_url+"&flag="+Math.random();
		}else
		{
			cgi_url = "/server/edit_channel_category?token="+encodeURI(g_token)+"&currentcategory="+encodeURI(currentcategory)+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4) {
				
		 		var response = xmlHttp.responseText;
			 	
				if ((category_url.length==0) || (category_url.startsWith("upload")))
				{
					api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"channel_icon"+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
	
					call_Upload_Files(event,EDIT_UPLOAD_CHANNEL_CATEGORY_ICON,api_option);
				}else
				{
					close_channel_category_edit_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Updated</font>';
			 			g_categoryclickedItemValue=newcategory;
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
				}

		 	}
		};
		xmlHttp.send(null);
	}
	
}

function call_Del_Channel_Category()
{
 	var cgi_url;
 	var confirm_msg;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
 	var category=g_categoryclickedItemValue;
 	
	if (category.length>0)
	{	
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		cgi_url = "/server/del_channel_category?token="+encodeURI(g_token)+"&delcategory="+encodeURI(category)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4) {
				
		 		var response = xmlHttp.responseText;
		 	 	var add_button = document.getElementById('Add');
				var edit_button = document.getElementById('Edit');
				var del_button = document.getElementById('Del');
		 		open_channel_category_modal();
		 		if (response==1)
		 		{
		 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+category+' Deleted</font>'
		 		}
		 		add_button.disabled=false;
				edit_button.disabled=false;
				del_button.disabled=false;
		 	}
		};
		xmlHttp.send(null);
	}
}
function Get_Server_Multiple_IP()
{
 	var cgi_url;


   	g_token=find_cookie_value("token");
 
	 cgi_url = "/server/get_server_ip_list?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function(){
		if (xmlHttp.readyState == 4) {
		
			var response = xmlHttp.responseText.split("\r\n");
			var HTML_str='';
			var strlength=0;
			var i=0;
			var j=1;
		
			g_totoal_server_ip_no=0;
			g_server_ip_array[0]="127.0.0.1";
			//alert(g_server_ip_array[0]);
		 	while (1)
			{
		 	 	if (response[i]==0) break;
				//alert(response[i]);
			 	strlength=response[i].length;
			 	//alert(strlength);
		   	    	g_server_ip_array[j]=response[i].slice(3,strlength);
		   	    	//alert(g_server_ip_array[j]);
		  		i++;
		  		j++;
			}
			g_totoal_server_ip_no=i+1;
			//alert("Get_Server_Multiple_IP");
			//get_balancer();
		 	
		 }
	
	
	};
	 xmlHttp.send(null);

}	
function onstartinput()
{
	document.getElementById("importurl").style.color = '#000000';
}
function onstartxmltvinput()
{
	document.getElementById("new_xmltv_src").style.color = '#000000';
}

function onstart_channelcategory_add_input()
{
	document.getElementById("add_category_url").style.color = '#000000';
}
function onstart_channelcategory_edit_input()
{
	document.getElementById("edit_category_url").style.color = '#000000';
}
var genre_items = [];
var g_channel_genre;
var g_movie_genre;
var g_series_genre;
var genreObject = {};	
var MoviegenreObject = {};	
var SeriesgenreObject = {};	



function itemExists(text) {
    return genre_items.includes(text);
}

function createListItem(text) {
	var listItem = document.createElement('li');
	listItem.textContent = genreObject[text];
	
	var removeButton = document.createElement('span');
	removeButton.className = 'remove-button';
	removeButton.textContent = 'x';
	removeButton.addEventListener('click', function() {
	var itemIndex = genre_items.indexOf(text);
	if (itemIndex > -1) {
	genre_items.splice(itemIndex, 1);
	}
	listItem.remove();
	});
	
	listItem.appendChild(removeButton);
	return listItem;
}
function createMovieListItem(text) {
	var listItem = document.createElement('li');
	listItem.textContent = MoviegenreObject[text];
	
	var removeButton = document.createElement('span');
	removeButton.className = 'remove-button';
	removeButton.textContent = 'x';
	removeButton.addEventListener('click', function() {
	var itemIndex = genre_items.indexOf(text);
	if (itemIndex > -1) {
	genre_items.splice(itemIndex, 1);
	}
	listItem.remove();
	});
	
	listItem.appendChild(removeButton);
	return listItem;
}
function createSeriesListItem(text) {
	var listItem = document.createElement('li');
	listItem.textContent = SeriesgenreObject[text];
	
	var removeButton = document.createElement('span');
	removeButton.className = 'remove-button';
	removeButton.textContent = 'x';
	removeButton.addEventListener('click', function() {
	var itemIndex = genre_items.indexOf(text);
	if (itemIndex > -1) {
	genre_items.splice(itemIndex, 1);
	}
	listItem.remove();
	});
	
	listItem.appendChild(removeButton);
	return listItem;
}
			
function open_icon_edit_modal(type, edit_no,iconurl)
{
	var modal = document.getElementById('PanelModalICONURLEdit');
	modal.style.display = "block";	
	g_edit_no=edit_no;

	var edit_icon_url=document.getElementById('edit_icon_url');
	
	if (type==1) // channel
	{
		var chiconid="chicon"+g_edit_no
		edit_icon_url.value=document.getElementById(chiconid).value;
	}else if (type==2) // movie
	{
		var movie_iconid="iconpath"+g_edit_no;
		edit_icon_url.value=document.getElementById(movie_iconid).value;
	}else if (type==4) // QRCode
	{
		var QRCode_iconid="iconpath"+g_edit_no;
		edit_icon_url.value=document.getElementById(QRCode_iconid).value;
	}
			
	
}
function close_icon_edit_modal() {
   var modal = document.getElementById('PanelModalICONURLEdit');
   modal.style.display = "none";   
}
function call_Edit_ICON(icon_type)
{
 	var cgi_url;
	var edit_icon_url =document.getElementById("edit_icon_url").value;

	if (edit_icon_url.length>0)
	{
		cgi_url = "/server/update_content_icon?token="+encodeURI(g_token)+"&edit_no="+g_edit_no+"&type="+icon_type+"&iconurl="+edit_icon_url+"&flag="+Math.random();
	}else
	{
		cgi_url = "/server/update_content_icon?token="+encodeURI(g_token)+"&edit_no="+g_edit_no+"&type="+icon_type+"&flag="+Math.random();
	}
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) {
			
	 		var response = xmlHttp.responseText;
		 	
	 		if ((edit_icon_url.length==0) || (edit_icon_url.startsWith("file://upload")))
			{
				if (icon_type==1)
				{
					api_option = "/server/upload_files?token="+escape(g_token)+"&content_no="+g_edit_no+"&type="+"channel_icon_path"+"&flag="+Math.random();
	
					call_Upload_Files(event,UPLOAD_CHANNEL_ICON_PATH,api_option);
				
					
				}else if (icon_type==2)
				{
					api_option = "/server/upload_files?token="+escape(g_token)+"&content_no="+g_edit_no+"&type="+"movie_icon_path"+"&flag="+Math.random();
	
					call_Upload_Files(event,UPLOAD_MOVIE_ICON_PATH,api_option);
					
				}else if (icon_type==4)
				{
					api_option = "/server/upload_files?token="+escape(g_token)+"&content_no="+g_edit_no+"&type="+"QRCode_icon_path"+"&flag="+Math.random();
	
					call_Upload_Files(event,UPLOAD_QRCODE_ICON_PATH,api_option);
					
				}
			}else
			{
				if (icon_type==1)
				{
					var chiconid="chicon"+g_edit_no;
					var ch_icon_path_id="ch_icon_path_"+g_edit_no;
					if (edit_icon_url.length> 0) {
						document.getElementById(ch_icon_path_id).src=edit_icon_url.slice(7);
						document.getElementById(chiconid).value="file://"+edit_icon_url.slice(7);
				
					}
				}
				if (icon_type==2)
				{
					var movie_iconid="iconpath"+g_edit_no;
					var movie_icon_path_id="movie_icon_path_"+g_edit_no;
					if (edit_icon_url.length > 0) {
						document.getElementById(movie_icon_path_id).src=edit_icon_url.slice(7);
						document.getElementById(movie_iconid).value="file://"+edit_icon_url.slice(7);
			
				
					}
				}
				if (icon_type==4)
				{
					var QRCode_iconid="iconpath"+g_edit_no;
					var QRCode_icon_path_id="QRCode_icon_path_"+g_edit_no;
					if (edit_icon_url.length > 0) {
						document.getElementById(QRCode_icon_path_id).src=edit_icon_url.slice(7);
						document.getElementById(QRCode_iconid).value="file://"+edit_icon_url.slice(7);
			
				
					}
				}
			}
			
			close_icon_edit_modal();
			

	 	}
	};
	xmlHttp.send(null);
	
	
}
	
function get_channels()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var ch_no;
    var ch_name;
    var ch_src;
    var ch_icon;
    var ch_icon_path;
    var ch_category;
    var ch_type;
    var ch_status;
    var ch_bitrate;
    var ch_play_id;
    var ch_title="<p>"+"Channel List"+"</p>";
    var ch_list;
    var i=0;
    var j=0;
    var box_no=1;
	var ch_active_no=0;
	var total_no=0;
	var new_total_no;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content;
    var ezcontent= document.getElementById("content")
  //var detail = parent.document.getElementById("detail");
  var dvr_folder_on=0;
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var more_keyword=null;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_channel_position;
	var total_count=0;
	var cellsize="15%";
	 
	 
	var item ;
	var gi;
	 
	 
	for (gi = 0; gi < g_channel_genre.length; gi++) 
	 {
	  	item = g_channel_genre[gi];
	 	genreObject[item.id] = item.name;
	}
	g_start_search_option=2;

	//alert(g_channel_position);
	if (g_show_off_channel==0)
	{
		total_count=g_total_ch_no;
	}else if (g_show_off_channel==1)
	{
		total_count=g_off_channel_no;
	}
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="50%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Channel</b></font>';
	str+='</td>';
	
	str+='<td>';
	if ((g_search_text.length==0)|| g_SearchInput.value=='Search Channels...')
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Channels..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}else
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}
	str+='</td>';
	str+='<td>';
	str+='<div class="navbar" style="background-color: #F5F6F8">';
		if (g_show_off_channel==0)
		{
			str+='<div class="menudropoption">';
			    str+='<button class="dropbtn">No Filter '; 
			    str+='<i class="fa fa-caret-down"></i>';
			    str+='</button>';
			    str+='<div class="menudropdown-content">';
			    str+='<a href="javascript:callezserver_off_channel()">Off</a>';
			    str+='</div>';
			str+='</div>'; 
		}else if (g_show_off_channel==1)
		{
			str+='<div class="menudropoption">';
			    str+='<button class="dropbtn">Off '; 
			    str+='<i class="fa fa-caret-down"></i>';
			    str+='</button>';
			    str+='<div class="menudropdown-content">';
			      str+='<a href="javascript:callezserver_all_channel()">No Filter</a>';
			    str+='</div>';
			str+='</div>'; 
		}
		
	str+='</td>';	
	str += '<td>' +
       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
       '</select>' +
       '</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()">Add Channel</a>';
		str+='</div>'; 
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="Button_Server_CH_Inquery()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 
		str+='<div class="menudropdown">';
		    str+='<button class="dropbtn" style="background-color: #414D5F">'; 
		    str+='<i class="fa fa-caret-down"></i>';
		    str+='</button>';
		    str+='<div class="menudropdown-content">';
		      str+='<a href="javascript:open_channel_category_modal()">Category</a>';
		      if (g_search_text.length==0)
		      {
			      str+='<a href="javascript:open_mass_edit_modal()">Mass Edit</a>';
			      str+='<a href="javascript:open_mass_delete_channel_modal()">Mass Delete</a>';
			      
			      str+='<a id=channel_cut_field href="javascript:callezserver_move_selected_channel()">Move to</a>';
			      str+='<a href="javascript:callezserver_refresh_selected_channel()">Multi Refresh</a>';
		      }
		      str+='<a href="javascript:open_import_modal()">Import M3U</a>';
		      //str+='<a href="javascript:open_import_url_modal()">Stream Provider</a>';
		      str+='<a href="javascript:call_export_channel_definition()">Export as XML</a>';
		      if (g_transcoder_setting_option==1)
			{ 
				str+='<a href="javascript:open_transcoder_setting_modal()">Transcoder</a>'; 
			}
		    str+='</div>';
		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';

	
	document.getElementById("ezhead").innerHTML=str;
	//document.getElementById("page_no").value=g_constant_limit;	
	
	ezcontent.innerHTML='</div><div id="ezmenucontent"></div>';
	
	content = parent.document.getElementById("ezmenucontent");
	

	content.innerHTML="";
//	detail.innerHTML="";
	
	g_search_channel_item.value=null;

	 HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_ch_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td id="channel_name_id" width="100" align="center"><font face="Arial" size="2">Channel Name</font>';
	      if (g_channel_name_order_flag==0)
	      {
		      HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      '<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_channel_name_order_flag==1)
	      {
		      HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      '<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_channel_name_order_flag==2)
	      {
		      HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      '<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</a></font>';
	      }
	      HTML_str+='</td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="50" align="center"><font face="Arial" size="2">Icon</font></td>'+
	      '<td width="140" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td id="category_id" width="60" align="center"><font face="Arial" size="2">Main Category</font>';
	      if (g_channel_category_order_flag==0)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_channel_category_order_flag==1)
	      {
	      	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_channel_category_order_flag==2)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_channel_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
	      }
	      
	      HTML_str+='</td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Type</font></td>';
	      
	      if (g_Ezserver_Version==BALANCER)
	      {
	      	HTML_str+='<td width="120" align="center"><font face="Arial" size="2">Status</font></td>';
	      }else
	      {
	      	HTML_str+='<td width="120" align="center"><font face="Arial" size="2">Server</font></td>';
	      }
	      
	      HTML_str+='<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
 	 		'</tr>'+'<tr><td  colspan="11"><hr size="1" color="#66FFFF"></td></tr>';
 	
	while (1)
	{
 	 	if (response[i]==0) break;
		//alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
   	    	ch_no=response[i].slice(3,strlength);
     	 	strlength=response[i+1].length;
   	    	ch_name=response[i+1].slice(5,strlength);
     	 	strlength=response[i+2].length;
   	    	ch_src=response[i+2].slice(4,strlength);
     	 	strlength=response[i+3].length;
   	    	ch_icon=response[i+3].slice(5,strlength);
   	    	if (ch_icon.indexOf("file://")!==-1)
   	    	{
   	    		ch_icon_path=ch_icon.slice(7);
   	    	}else
   	    	{
   	    		ch_icon_path=ch_icon;
   	    	}
   	    	
     	 	strlength=response[i+4].length;
 	    	ch_category=response[i+4].slice(9,strlength);
     	 	strlength=response[i+5].length;
   	    	ch_type=response[i+5].slice(5,strlength);
   	    	if (ch_type.search("dvr")>=0)
   	    	{
   	    		dvr_folder_on=1;
   	    	}else
   	    	{
   	    		dvr_folder_on=0;
   	    	}
   	    	strlength=response[i+6].length;
  	    	ch_status=response[i+6].slice(7,strlength);
  	    	//alert(ch_status);
  	    	strlength=response[i+7].length;
  	    	ch_bitrate=response[i+7].slice(8,strlength);
   	    		
   	    	

 		i=i+8;
		total_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		   '<td width="20" align="center">';
		      if (g_channel_found_position==ch_no)
		      {
	 		HTML_str+=' <input type="checkbox" checked name=checkbox'+ch_no;
	 	      }else
	 	      {
	 		HTML_str+=' <input type="checkbox" name=checkbox'+ch_no;
	 	      }
	 	      HTML_str+=' id=checkbox'+ch_no+'></td>';

		      HTML_str+='<td width="20" align="center"><font face="Arial" size="2">'+ch_no+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input  style="padding: 5px;height:30;" type="text" title="'+ch_name+'" name="chname"'+
	 		' id=chname'+ch_no+
	 		' size="20" value="'+
//	 		decodeURI(ch_name)+'"/></font></td>'+
	 		unescape(ch_name)+'"/></font></td>'+
		       
			'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" title="'+ch_src+'" name="chsrc"'+
	 		' id=chsrc'+ch_no+
	 		' size="30" value="'+
	 		ch_src+'"/></font></td>'+
		      '<td width="'+"50px"+'" style="text-align: center; vertical-align: middle;">'+
		        '<a href="javascript:void(0)" onclick=open_icon_edit_modal("1","'+ch_no+'","'+ch_icon+'")>'+'<img id="ch_icon_path_'+ch_no+'" style="padding: 5px;width:35px; height:35px" src="'+ch_icon_path+'"</img>'+'</a>'+
	 		'</td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" title="'+ch_icon+'" name="chicon"'+
	 		' id=chicon'+ch_no+
	 		' size="25" value="'+
	 		ch_icon+'"/></font></td>';
	 		
		      
	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
			' <select  style="text-indent: 5;width:152;height:26;" size="1" name="chcategory" id=chcategory'+ch_no+'>';
	 		
	 		if (ch_category.length==0)
			{
				HTML_str+='<option selected="selected" value="">'+""+'</option>';
			}
			for (j=0;j<g_total_channel_category_no;j++)
			{
				if (g_Channel_Categories_tems[j]==unescape(ch_category))
				{
					HTML_str+='<option selected="selected" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
				}else
				{
					HTML_str+='<option value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
				}
				
			}
			HTML_str+='</select></font></td>';
		      HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		
			' <select style="text-indent: 5;width:152;height:26;"  size="1" name="chtype" id=chtype'+ch_no+'>';
			//alert(ch_type);
			if (ch_type.search("live")>=0)
			{
				HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("delay")>=0)
			{
				for (k=0;k<g_delaytime_array.length;k++)
				{
					
					if (ch_type.search(g_delayvalue_array[k])==0)
					{
						break;
					}
				}
				//alert(k);
				HTML_str+='<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					if (j!=k)
					{
						HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					}else 
					{
						HTML_str+='<option selected="selected" value="'+g_delayvalue_array[k]+'">'+g_delaytime_array[k]+'</option>';
					}
											
				}
			}else if (ch_type.search("dvr")>=0)
			{
				HTML_str+='<option selected="selected" value="dvr">'+"DVR"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("inactive")>=0)
			{
				HTML_str+='<option selected="selected" value="inactive">'+"Inactive"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("movie")>=0)
			{
				HTML_str+='<option selected="selected" value="movie">'+"Movie"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}
			/* else if (ch_type.search("hls")>=0)
			{
				HTML_str+='<option selected="selected" value="hls">'+"HLS"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}
			*/
			HTML_str+='</select></font></td>';
			
			//alert(ch_status);		

			if (ch_status.search("OFF")>=0)
			{
		      		HTML_str+='<td id=chstatus'+ch_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
			}else
			{
		      		HTML_str+='<td id=chstatus'+ch_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_status+'</font></td>';

			}
	      		HTML_str+='<td id=chbitrate'+ch_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_bitrate+'</font></td>';
	 		HTML_str+='<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=callServer_CH_Update("'+ch_no+'")><img src="/admin/save.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=open_channel_more_modal("'+ch_no+'")><img src="/admin/edit.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=call_Del_Channel("'+ch_no+'")><img src="/admin/del.png"></img></a></td>';
	 		
			HTML_str+='</tr>';
			
				
		    
		box_no++;
     	}

	//if (total_no>0)
	//{	
		new_total_no=Number(g_total_ch_no)+1;
		menustr1='<table width=100%><tr>';
		menustr1+='<td width="4%">';
		menustr1+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
    				menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>New Channel</b></font></td><td colspan=2 align=right id=add_channel_dialog_message name=add_channel_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">Channel at</font></td><td  width=25% height="23">'+
				' <font face="Arial" size="2">'+
				' <input  style="text-indent: 5;height:26;" type="text" name="chno"'+
				' id="chno"'+
				' size="16" value="'+
				new_total_no+
				'"/></font></td>';
				menustr1+='<td width=25%><font face="Arial" font size="2">Channel Name : </font></td><td  width=25%>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="text-indent: 5;height:26;"  type="text" name="chname"'+
				 	' id=chname'+
				 	' size="16"/'+
				 	'</font></td></tr>';
				menustr1+='<tr><td width=25%><font face="Arial" font size="2">Media Source : </font></td><td colspan=3>'+
				 		' <font face="Arial" size="2">'+
				 		' <input  style="text-indent: 5;height:26;" type="text" name="chsrc"'+
				 		' id=chsrc'+
				 		' size="61"/'+
				 		'</font></td></tr>';
				menustr1+='<tr><td  width=25%><font face="Arial" size="2">Icon Path : </font></td><td colspan=3 >'+
				 		' <font face="Arial" size="2">'+
				 		' <input  style="text-indent: 5;height:26;" type="text" name="chicon"'+
				 		' id=chicon'+
				 		' size="61"/'+
				 		'</font></td></tr>';
				
				 menustr1+='<tr><td><font face="Arial" size="2">Main Category : </font></td><td>'+
		 		' <select style="text-indent: 5;width:152;height:26;" size="1" name="chcategory" id=chcategory>';
				
				for (j=0;j<g_total_channel_category_no;j++)
				{
					if (j==0) 
					{
						menustr1+='<option style="padding: 2px" selected="selected" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
					}
					else
					{
						menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
					}
				}
				menustr1+='</select></font></td>';		
				menustr1+='<td><font face="Arial" size="2">Type : </font></td><td>'+
				 		' <font face="Arial" size="2">'+
						' <select style="text-indent: 5;width:152;height:26;" size="1" name="chtype" id=chtype>';
				 		
						menustr1+='<option selected="selected" value="live">'+"Live"+'</option>'+
						'<option style="padding: 2px" value="movie">'+"Movie"+'</option>'+
						'<option style="padding: 2px" value="dvr">'+"DVR"+'</option>'+
						//'<option value="hls">'+"HLS"+'</option>'+
						'<option style="padding: 2px" value="inactive">'+"Inactive"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							
							menustr1+='<option style="padding: 2px" value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							
						}
				menustr1+='</select></font></td></tr>';

				menustr1+='<tr><td colspan=2 width=50%><input id=add_new_channel_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add"  onclick=call_Add_Channel() name="Add" /></td>'+
				'<td align=right  colspan=2 width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_channel_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
		
			
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMassEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  width=75% colspan=3 align=left><font face="Arial" size="6"><b>Mass Edit Channels</b></font></td><td align=right id=mass_edit_channel_dialog_message name=mass_edit_channel_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				
				// Category	
				menustr1+='<tr><td><font face="Arial" size="2"><b>Choose one category</b></font></td><td colspan=3 width=75%>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_chcategory" id=mass_edit_chcategory>';
				
				menustr1+='<option style="padding: 2px" selected="selected" value="'+"All"+'">'+"All"+'</option>';
				for (j=0;j<g_total_channel_category_no;j++)
				{
					menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
				}
				menustr1+='</select></font></td></tr>';
				
				
				
  
  
				menustr1+='<tr>'+
				'<td  width=25% height="50">'+
				'<font face="Arial" size="2">On Demand</font>'+
				'</p>'+
				'</td>'+      
				'<td width=25%  height="50"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" id="mass_edit_cacheondemandflag"><span class="slider round"></span></label>'+
				'</td>'+
				'<td  width=25% height="50">'+
				'<font face="Arial" size="2">HLS</font>'+
				'</p>'+
				'</td>'+      
				'<td  width=25% height="50"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" id="mass_edit_HLSType"><span class="slider round"></span></label>'+
				'</td>'+
				'</tr>';
							
				menustr1+='</select></font></td></tr>';

			 		
				menustr1+='<tr><td><font face="Arial"> <font size="2">Input Adapter</font></td><td width=25% height="23">'+
				'<select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_input_adapter" id="mass_edit_input_adapter">';
		 		for (j=0;j<g_totoal_server_ip_no;j++)
				{
					//alert(g_server_ip_array[j]);
					//alert(netip);
					menustr1+='<option style="padding: 2px" value="'+g_server_ip_array[j]+'">'+g_server_ip_array[j]+'</option>';
					
					
				}
		 		menustr1+='</select></font></td>';	
				menustr1+='<td><font face="Arial" size="2">Type : </font></td><td>'+
				 		' <font face="Arial" size="2">'+
						' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_chtype" id=mass_edit_chtype>';
				 		
				menustr1+='<option selected="selected" value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					menustr1+='<option style="padding: 2px" value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
				menustr1+='</select></font></td></tr>';
				
				
			
		
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Buffer Size</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_buffer_size"'+
		 		' id="mass_edit_buffer_size"'+
		 		' size="16" value=""/></font>&nbsp;<img  align="center" title="SD: 8000&#013;HD:20000&#013;FHD:30000&#013;UHD:60000&#013;4K:80000&#013;8K:160000" width=12 height=12 src="/admin/info.png"></img></td>';
				
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Bitrate Tolerance</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_tolerance"'+
		 		' id="mass_edit_tolerance"'+
		 		' size="16" value=""/></font>&nbsp;<img  align="center" title="SD: 0&#013;HD/FHD/UHD/4K/8K:0.99" width=12 height=12 src="/admin/info.png"></img></td></tr>';
		 		
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Catch Up Days</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_catch_up_days"'+
		 		' id="mass_edit_catch_up_days"'+
		 		' size="16" value=""/></font></td>';
				
				menustr1+='<td><font face="Arial"><font size="2">Server</font></td><td  width="25%" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_forwardflag" id="mass_edit_forwardflag">';
				//menustr1+='<option selected="selected" value="0">0</option>'+
				//'<option style="padding: 2px" value="1">1</option>'+
				//'<option style="padding: 2px" value="2">2</option>'+
				//'<option style="padding: 2px" value="3">3</option>';
				menustr1+='<option selected="selected" value="0">Disabled</option>'+
				'<option value="1">Source Server</option>';
				
				// List BL into proxy mode
				var balancer_value=201;
				//alert(g_balancer.length);
				if (g_balancer.length>0)
				{
					for (i=0;i<g_balancer.length;i++)
					{
						item = g_balancer[i];
						//alert(item.name);
						menustr1+='<option value="'+balancer_value+'">'+item.name+'</option>'+
						balancer_value++;
					}
				}
				//
				menustr1+='</select></td></tr>';
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">User Agent</font></td>'+
				'<td colspan=3 width=75% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_http_user_agent"'+
		 		' id="mass_edit_http_user_agent"'+
		 		' size="61" value=""/></font></td></tr>';
				
				/* menustr1+='<tr><td><font face="Arial"> <font size="2">Input Adapter</font></td><td colspan=3 width=75% height="23">'+
				'<select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_input_adapter" id="mass_edit_input_adapter">';
		 		for (j=0;j<g_totoal_server_ip_no;j++)
				{
					//alert(g_server_ip_array[j]);
					//alert(netip);
					menustr1+='<option style="padding: 2px" value="'+g_server_ip_array[j]+'">'+g_server_ip_array[j]+'</option>';
					
					
				}
		 		menustr1+='</select></font></td></tr>';
		 		*/
	 						
				menustr1+='<tr><td colspan=2><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=callezserver_mass_edit_selected_channel() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_mass_edit_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				
				// Mass Delete
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMassDelete" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  width=75% colspan=3 align=left><font face="Arial" size="6"><b>Mass Delete</b></font></td><td align=right id=mass_delete_dialog_message name=mass_edit_delete_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				
				// Category	
				menustr1+='<tr><td><font face="Arial" size="2"><b>Choose one category</b></font></td><td colspan=3 width=75%>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="mass_delete_category" id=mass_delete_category>';
				
				menustr1+='<option style="padding: 2px" selected="selected" value="'+"All"+'">'+"All"+'</option>';
				// Need to change
				for (j=0;j<g_total_channel_category_no;j++)
				{
					menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
				}
				menustr1+='</select></font></td></tr>';
				
	 			// Need to change			
				menustr1+='<tr><td colspan=2><input id=delete_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Delete" onclick=callezserver_mass_delete_selected_channel() name="Delete" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_mass_delete_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalChannelCategory" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table align="center" cellspacing="10" align="center">';
				menustr1+='<tr><td align="left"><font face="Arial" size="6"><b>Category</b></font></td></td><td align=right id=category_dialog_message name=category_dialog_message></td><td id=total_no align="right"></tr>';
				menustr1+='<tr><td colspan="3"><hr size="1" color="#000000"></td></tr>';
				
				menustr1+='<tr><td colspan=2 id=channel_category></td>'+
				'<td>'+
				'<table>';
				menustr1+='<tr><td><input id="Add" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=open_channel_category_add_modal() name="Add" /></td></tr>';
				menustr1+='<tr><td><input id="Edit" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Edit" onclick=open_channel_category_edit_modal() name="Edit" /></td></tr>';
				menustr1+='<tr><td><input id="Del" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Del" onclick=call_Del_Channel_Category() name="Del" /></td></tr>';
				menustr1+='<tr><td><img style="margin-top:10px;width:100%;height:30;" src="/admin/move.png"></img></td></tr>';
				
				menustr1+='</table></td></tr>';
				
				menustr1+='<td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Save" onclick=close_update_channel_category_modal() name="Save" /></td>';
				menustr1+='<td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_channel_category_modal() name="Cancel" /></td>';
				menustr1+='<td width=10%></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				
				// Edit Category
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalChannelCategoryEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>Edit Category</b></font></td><td align=right id=channel_category_edit_dialog_message name=channel_category_edit_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
				// New Category Name
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Category:</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;color:#000000" type="text" name="editcategory"'+
		 		' id="editcategory"'+
		 		' size="40"></font></font></td></tr>';
		 		
								
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstart_channelcategory_edit_input()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="edit_category_url"'+
		 		' id="edit_category_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="edit_file_upload_form_channel_category_icon" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Edit_Channel_Category() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_channel_category_edit_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				// Add New Category
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalChannelCategoryAdd" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>New Category</b></font></td><td align=right id=channel_category_add_dialog_message name=channel_category_add_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
				// New Category Name
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Category:</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;color:#000000" type="text" name="newcategory"'+
		 		' id="newcategory"'+
		 		' size="40"></font></font></td></tr>';
		 		
								
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstart_channelcategory_add_input()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="add_category_url"'+
		 		' id="add_category_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="add_file_upload_form_channel_category_icon" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Channel_Category() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_channel_category_add_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
			
				// Edit ICON Path
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalICONURLEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>New / Edit Channel icon</b></font></td><td align=right id=icon_url_edit_dialog_message name=icon_url_edit_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
					
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;color:#00000" type="text" name="edit_icon_url"'+
		 		' id="edit_icon_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="file_upload" enctype="multipart/form-data">'+
				'<input type="file" name="Video"/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Edit_ICON(1) name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_icon_edit_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				
				menustr1+='<td width="100%">';
				menustr1+='<div id="PanelModalChannelMore" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left id=more_channel_name><font face="Arial" size="6"><b></b></font></td><td colspan=2 align=right id=save_channel_dialog_message name=save_channel_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	
	
				menustr1+='<tr>'+
				'<td  width=25% height="50">'+
				'<font face="Arial" size="2">On Demand</font>'+
				'</p>'+
				'</td>'+      
				'<td width=25%  height="50"><p align="left">'+
				'<label class="switch"><input type="checkbox" id="more_cacheondemandflag"><span class="slider round"></span></label>'+
				'</td>'+
				'<td  width=25% height="50">'+
				'<font face="Arial" size="2">HLS</font>'+
				'</p>'+
				'</td>'+      
				'<td  width=25% height="50"><p align="left">'+
				'<label class="switch"><input type="checkbox" id="more_hlstype"><span class="slider round"></span></label>'+
				'</td>'+
				'</tr>';
							
				menustr1+='</select></font></td></tr>';


				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Channel SID</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_sid"'+
		 		' id="more_sid"'+
		 		' size="16" value=""/></font></td>';
				
				menustr1+='<td width=25%><font face="Arial"> <font size="2">EPG Channel ID</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_epg_channel_id"'+
		 		' id="more_epg_channel_id"'+
		 		' size="16" value=""/></font></td></tr>';
		
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Buffer Size</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_buffersize"'+
		 		' id="more_buffersize"'+
		 		' size="16" value=""/></font>&nbsp;<img  align="center" title="SD: 8000&#013;HD:20000&#013;FHD:30000&#013;UHD:60000&#013;4K:80000&#013;8K:160000" width=12 height=12 src="/admin/info.png"></img></td>';
				
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Bitrate Tolerance</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_tolerance"'+
		 		' id="more_tolerance"'+
		 		' size="16" value=""/></font>&nbsp;<img  align="center" title="SD: 0&#013;HD/FHD/UHD/4K/8K:0.99" width=12 height=12 src="/admin/info.png"></img></td></tr>';
		 		
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Catch Up Days</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_catch_up_days"'+
		 		' id="more_catch_up_days"'+
		 		' size="16" value=""/></font></td>';
				
				menustr1+='<td><font face="Arial"><font size="2">Server</font></td><td  width="25%" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="more_forwardflag" id="more_forwardflag">';
				menustr1+='<option selected="selected" value="0">Disabled</option>'+
				'<option value="1">Source Server</option>';
				
				// List BL into proxy mode
				var balancer_value=201;
				//alert(g_balancer.length);
				if (g_balancer.length>0)
				{
					for (i=0;i<g_balancer.length;i++)
					{
						item = g_balancer[i];
						//alert(item.name);
						menustr1+='<option value="'+balancer_value+'">'+item.name+'</option>'+
						balancer_value++;
					}
				}
				//
				menustr1+='</select></td></tr>';
				
				menustr1+='<tr><td><font face="Arial"> <font size="2">Input Adapter</font></td><td width=25% height="23">'+
				'<select style="text-indent: 5;width:152;height:26;" size="1" name="input_adapter" id="input_adapter">';
		 		for (j=0;j<g_totoal_server_ip_no;j++)
				{
					//alert(g_server_ip_array[j]);
					//alert(netip);
					menustr1+='<option style="padding: 2px" value="'+g_server_ip_array[j]+'">'+g_server_ip_array[j]+'</option>';
					
					
				}
		 		menustr1+='</select></font></td>';
		 		
		 		menustr1+='<td  width=25% height="50">'+
				'<font face="Arial" size="2">AES Encryption</font>'+
				'</p>'+
				'</td>'+      
				'<td  width=25% height="50"><p align="left">'+
				'<label class="switch"><input type="checkbox" id="more_aestype"><span class="slider round"></span></label>'+
				'</td>'+
		 		'</tr>';

				if ((g_Ezserver_Version==BLOCKCHAIN_PUBLIC) || g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
				{
			 		menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Blockchain Region</font></td>'+
					'<td width=25% height="23">'+
			 		' <font face="Arial"> <font size="2">'+
			 		' <input  style="text-indent: 5;height:26;" type="text" name="more_bcregion"'+
			 		' id="more_bcregion"'+
			 		' size="16" value=""/></font>&nbsp;<img  align="center" title="Display streaming server area when system connection is overloaded" width=12 height=12 src="/admin/info.png"></img></td>';
					
					menustr1+='<td width=25%><font face="Arial"> <font size="2">Blockchain Group ID</font></td>'+
					'<td width=25% height="23">'+
			 		' <font face="Arial"> <font size="2">'+
			 		' <input  style="text-indent: 5;height:26;" type="text" name="more_bcgroup"'+
			 		' id="more_bcgroup"'+
			 		' size="16" value=""/></font>&nbsp;<img  align="center" title="Display streaming server Group ID when system connection is overloaded" width=12 height=12 src="/admin/info.png"></img></td></tr>';
		 		}
		 		// Gener
		 		menustr1+='<tr><td><font face="Arial" size="2">Sub Categories</font></td><td>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="genre_itemSelect" id=genre_itemSelect>';
				
				for (j=0;j<g_channel_genre.length;j++)
				{
					var genre_id=g_channel_genre[j].id;
					menustr1+='<option style="padding: 2px" value="'+genre_id+'">'+genreObject[genre_id]+'</option>';
				}
				menustr1+='</select></font></td><td colspan=2><button id="addItemButton" onclick=call_add_genre()>Add Item</button></td></tr>';
				menustr1+='<tr><td></td><td colspan=3><font face="Arial" size="2"><b><ul id="selectedItemsList"></ul></b></font></td></tr>';	
				
				menustr1+='<tr><td><font face="Arial"> <font size="2">User Agent</font></td><td colspan=3 width=75% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_http_user_agent"'+
		 		' id="more_http_user_agent"'+
		 		' size="61" value=""/></font></td></tr>';

				menustr1+='<tr><td><font face="Arial"> <font size="2">2nd URL</font></td><td colspan=3 width=75% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_sr2"'+
		 		' id="more_sr2"'+
		 		' size="61" value=""/></font></td></tr>';
		 		
		 		menustr1+='<tr><td><font face="Arial"><font size="2">3rd URL</font></td><td colspan=3 width=75% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;;" type="text" name="more_sr3"'+
		 		' id="more_sr3"'+
		 		' size="61" value=""/></font></td></tr>';
	 						
				menustr1+='<tr><td colspan=2><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=callServer_Save_Channel_More() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_channel_more_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalImport" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left id=more_channel_name><font face="Arial" size="6"><b>Import Channels</b></font></td><td colspan=2 align=right id=import_channel_dialog_message name=import_channel_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">Channel after</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="importchno"'+
		 		' id="importchno"'+
		 		'value="'+g_total_ch_no+'"'+
		 		' size="16" value=""/></font></td>';
		 		
				
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Server</font></td>'+
				'<td width=25%><select  style="text-indent: 5;width:152;height:26;" size="1" id="import_option">';
				menustr1+='<option selected="selected" value="0">Main Server</option>';
				menustr1+='<option value="1">Source Server</option>';

				balancer_value=201;
				//alert(g_balancer.length);
				if (g_balancer.length>0)
				{
					for (i=0;i<g_balancer.length;i++)
					{
						item = g_balancer[i];
						//alert(item.name);
						menustr1+='<option value="'+balancer_value+'">'+item.name+'</option>'+
						balancer_value++;
					}
				}
				menustr1+='</select></font></td></tr>';
				
		 		
		 		// Upload Local FIles
				menustr1+='<tr><td  width=25%>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td colspan=3><form id="file_upload_form_channel" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';
				

				menustr1+='<tr><td width=50% colspan=2><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Submit" onclick=call_import_channel_by_upload_file() name="Submit" /></td>'+
				'<td width=50%  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_import_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				/*
				// Import by URL
				
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalImportURL" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left id=more_channel_name><font face="Arial" size="6"><b>Import Channels</b></font></td><td colspan=2 align=right id=import_channel_dialog_message name=import_channel_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">Channel after</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="importurlchno"'+
		 		' id="importurlchno"'+
		 		'value="'+g_total_ch_no+'"'+
		 		' size="16" value=""/></font></td>';
		 		
				
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Server</font></td>'+
				'<td width=25%><select  style="text-indent: 5;width:152;height:26;" size="1" id="import_url_option">';
				menustr1+='<option selected="selected" value="0">Main Server</option>';
				menustr1+='<option value="1">Source Server</option>';

				balancer_value=201;
				//alert(g_balancer.length);
				if (g_balancer.length>0)
				{
					for (i=0;i<g_balancer.length;i++)
					{
						item = g_balancer[i];
						//alert(item.name);
						menustr1+='<option value="'+balancer_value+'">'+item.name+'</option>'+
						balancer_value++;
					}
				}
				menustr1+='</select></font></td></tr>';
				
		 		
		 		// HTTP URL
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td colspan=3 height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  oninput="onstartinput()" style="text-indent: 5;height:26;color:#cccccc" type="text" name="importurl"'+
		 		' id="importurl"'+
		 		' size="61" placeholder="http://serverip:port/get.php&username=test&password=1234&output=mpegts"/></font></td></tr>';
				
				

				menustr1+='<tr><td width=50% colspan=2><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Submit" onclick=call_import_channel_by_url() name="Submit" /></td>'+
				'<td width=50%  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_import_url_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				*/
				
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalTranscoder" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left id=more_channel_name><font face="Arial" size="6"><b>Transcoder Setting</b></font></td><td colspan=2 align=right id=transcoder_setting_dialog_message name=transcoder_setting_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	


				
		 		
				menustr1+='<tr><td width=25%><font face="Arial" size="2"><b>Choose one category</b></font></td><td colspan=3 width=75%>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" onchange="javascript:get_transcoder_setting_by_category();" name="transcoder_setting_chcategory" id=transcoder_setting_chcategory>';
				
				menustr1+='<option style="padding: 2px" selected="selected" value="'+"All"+'">'+"All"+'</option>';
				for (j=0;j<g_total_channel_category_no;j++)
				{
					menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
/*					if (j==0) 
					{
						menustr1+='<option style="padding: 2px" selected="selected" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
					}
					else
					{
						menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Channel_Categories_tems[j])+'">'+decodeURI(g_Channel_Categories_tems[j])+'</option>';
					}
					*/
				}
				menustr1+='</select></font></td></tr>';
				
				menustr1+='<tr><td  height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Transocding&nbsp;</font><img  align="center" title="Enable/Disable Transcoder" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td  height="23"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" id="transcoder_enable_option" onclick="javascript:change_all_transcoder_options()"><span class="slider round"></span></label>'+
				'</td>';
				menustr1+='<td  height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">ABR&nbsp;</font><img  align="center" title="ABR for m3u8 output" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td  height="23"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" id="abr"  onclick="javascript:change_2nd_3rd_option();"><span class="slider round"></span></label>'+
				'</td>'+'</tr>';
			
				
				
				menustr1+='<tr>'+
				'<td  height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">GPU&nbsp;</font><img  align="center" title="Hardware Encoding" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td  height="23"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" id="gpuffmpeg"><span class="slider round"></span></label>'+
				'</td>'+
				'<td  height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">CUDA&nbsp;</font><img  align="center" title="Nvidia Input decoding format" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td  height="23"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" id="cuda"><span class="slider round"></span></label>'+
				'</td>'+
				'</tr>';
			
			
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Video&nbsp;</font><img  align="center" title="Video output format" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><font face="Arial"> <font size="2">'+
						' <select style="width:120;height:30;border: 1px solid #cccccc;" size="1" name="videoformat" id="videoformat">'+
						
						'<option selected="selected" value="h264">h264</option>'+
						'<option value="h265">h265</option>'+
						'<option value="copy">copy</option>'+
						'</select></font>'+
				'</font>'+ 
				'</td>'+
				
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Audio&nbsp;</font><img  align="center" title="Audio output format" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"><font face="Arial"> <font size="2">'+
						' <select style="width:120;height:30;border: 1px solid #cccccc;" size="1" name="audioformat" id="audioformat">'+
						
						'<option selected="selected" value="aac">aac</option>'+
						'<option value="mp3">mp3</option>'+
						'<option value="copy">copy</option>'+
						'</select></font>'+
				
				'</td>'+
				'</tr>';
				
			
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Encoding Speed&nbsp;</font><img  align="center" title="Encoding speed" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><font face="Arial"> <font size="2">'+
						' <select style="width:120;height:30;border: 1px solid #cccccc;" size="1" name="preset" id="preset">'+
						
						'<option selected="selected" value="ultrafast">ultrafast</option>'+
					'<option value="superfast">superfast</option>'+
					'<option value="fast">fast</option>'+
					'<option value="medium">medium</option>'+
					'<option value="slow">slow</option>'+
				'</font>'+ 
				'</td>'+
				
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Aspect Ratio&nbsp;</font><img  align="center" title="Output vidoe screen aspect ration" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"><font face="Arial"> <font size="2">'+
						' <select style="width:120;height:30;border: 1px solid #cccccc;" size="1" name="videoaspect" id="videoaspect">'+
						
						'<option selected="selected" value="">Auto</option>'+
						'<option value="16:9">16:9</option>'+
						'<option value="4:3">4:3</option>'+
						'<option value="18:9">18:9</option>'+
						'<option value="21:9">21:9</option>'+
						'</select></font>'+
				
				'</td>'+
				'</tr>';
				
				// ABR Option
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	
				menustr1+='<tr><td id=abr_1st_option><font face="Arial" size="2"><b>ABR 1st Option</b></font></td><td colspan=3 width=75%>'+'</td></tr>';
			
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Resolution X&nbsp;</font><img  align="center" title="Output Resolution X (px)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="output_resoultion_x" id="output_resoultion_x" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Resolution Y&nbsp;</font><img  align="center" title="Output Resolution Y (px)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="output_resoultion_y" id="output_resoultion_y" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'</tr>';
			
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Output bitrate&nbsp;</font><img  align="center" title="Output streaming bitrate (Kbps)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="output_bitrate" id="output_bitrate" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'<td  height="23">'+
				'</td>'+      
				'<td  height="23">'+
				'</td>'+
				'</tr>';
			
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	
				menustr1+='<tr><td><font face="Arial" size="2"><b>ABR 2nd Option</b></font></td><td colspan=3 width=75%>'+'</td></tr>';
		 		
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Resolution X&nbsp;</font><img  align="center" title="2nd Output Resolution X (px)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="2nd_output_resoultion_x" id="2nd_output_resoultion_x" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Resolution Y&nbsp;</font><img  align="center" title="2nd Output Resolution Y (px)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="2nd_output_resoultion_y" id="2nd_output_resoultion_y" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'</tr>';
			
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Output bitrate&nbsp;</font><img  align="center" title="2nd Output streaming bitrate (Kbps)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="2nd_output_bitrate" id="2nd_output_bitrate" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'<td  height="23">'+
				'</td>'+      
				'<td  height="23">'+
				'</td>'+
				'</tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	
				menustr1+='<tr><td><font face="Arial" size="2"><b>ABR 3rd Option</b></font></td><td colspan=3 width=75%>'+'</td></tr>';
		 		
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Resolution X&nbsp;</font><img  align="center" title="3rd Output Resolution X (px)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="3rd_output_resoultion_x" id="3rd_output_resoultion_x" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Resolution Y&nbsp;</font><img  align="center" title="3rd Output Resolution Y (px)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="3rd_output_resoultion_y" id="3rd_output_resoultion_y" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'</tr>';
			
				menustr1+='<tr>'+
				'<td width="25%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Output bitrate&nbsp;</font><img  align="center" title="3rd Output streaming bitrate (Kbps)" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="25%" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input  style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="3rd_output_bitrate" id="3rd_output_bitrate" size="12/></font>'+
				'</font>'+ 
				'<font size="2">'+
				'</td>'+
				'<td  height="23">'+
				'</td>'+      
				'<td  height="23">'+
				'</td>'+
				'</tr>';
					
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	
				menustr1+='<tr>'+
				'<td width="45%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Input Custom Command&nbsp;</font><img  align="center" title="Extra transcoding input options" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="55%" colspan="3" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="custom_cmd" id="custom_cmd" size="66"/></font>'+
				'</font>'+ 
				'</td>'+
				'</tr>';
				menustr1+='<tr>'+
				'<td width="45%" height="23">'+
				'<p align="left" style="text-indent: 5"><font face="Arial" size="2">Output Custom Command&nbsp;</font><img  align="center" title="Extra transcoding output options" width=12 height=12 src="/admin/info.png"></img>'+
				'</p>'+
				'</td>'+      
				'<td width="55%" colspan="3" height="23"><p align="left"> <font face="Arial"> <font size="2"> <input style="text-indent: 5;height:30;border: 1px solid #cccccc;" type="text" name="output_custom_cmd" id="output_custom_cmd" size="66"/></font>'+
				'</font>'+ 
				'</td>'+
				'</tr>';			
				
				menustr1+='<tr>'+
				'<td colspan="2"  height="23">'+
			       	    '<p align="left" style="margin-left: 5;margin-top: 10"><button style="width:50%;height:30;background-color: #5089DE;color: #ffffff;" class="button button1" onclick="javascript:save_transcoder_setting();" name="Save" />Save</button>'+
				'<td  colspan="2" height="23">'+
			       	    '<p align="right" style="margin-right: 10;margin-top: 10"><button style="width:75%;height:30;background-color: #98A6AD;color: #ffffff;" class="button button1" onclick="javascript:close_transcoder_setting_modal();" name="Cancel" />Cancel</button>'+
				'</td>'+  
			
				'</font>'+
				
				'</tr>';
		 		

		 		
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';

		
		  menustr1+='</tr>'+
		      '</table>';
	
		if (total_count==0)
		{
			current_position=0;
			endposition=0;
		}else
		{
			endposition=current_position+total_no-1;
		}
		menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
		menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' channels</td>';
		position=1;
		limit=g_constant_limit;
		if (total_count>g_constant_limit)
	{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:call_get_first_channel('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:call_get_channels('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	 /*	content.innerHTML='<table width=99%><tr><td>'+
	  	'<font size="2" face="Arial">Channel Total: '+ total_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
	 	'<td><font face="Arial" size="2"> <input name="channel_search_field" id="channel_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
		   '<input type="button" value="Search" onclick="javascript:search_channel_name();" name="search_channel_name" /></font>'+
		   '<input type="button" value="Go to" onclick="javascript:goto_line_no(1);" name="goto_channel_no" /></font>'+	   
		   '</td></tr>'+
		'</table>'+HTML_str+'</table>'+menustr2;
		*/
		content.innerHTML=menustr1+HTML_str+'</table>'+menustr2;
		if (g_add_channel_flag==1)
		{
			open_modal();
		}
		g_add_channel_flag=0
		
		//g_total_ch_no=total_no;
		
		// alert(g_Query_Channel_Status_timer);
		bQuery_Channel_Status=1;
		//if (g_Query_Channel_Status_timer==0)
		//{
			//g_Query_Channel_Status_timer=setInterval(function(){callServer_Get_Channels_Status_Timer()},10*1000);
			// alert(g_Query_Channel_Status_timer);
		//} 
		g_SearchInput = document.getElementById("search_field");
	     	if (g_search_text.length>0)
	     	{
	     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
	     		g_SearchInput.focus();
	     	}
	     	
	//}
 }
}
function Get_Channel_Statistics()
{
 
 if (xmlHttp.readyState == 4) {


	var response = xmlHttp.responseText.split("\r\n");
	var ch_no;
	var ch_name;
	var ch_watched_no=0;
	var ch_uptime=0;
	var ch_status;
	var ch_bitrate;
	var i=0;
	var j=0;
	var total_ch_no=0;
	var ch_active_player_no=0;
	var HTML_str='';
	var strlength=0;
	var content;
	var menustr1;
	var cellsize="15%";

	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>'
	var action_width="80%";
	if (bMobileDevice)
	{
		action_width="20%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Channel Statistics</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:callServer_Get_Channel_Statistics()">Channel</a>';
			str+='</div>'; 
			str+='<div class="menudropdown" style="background-color: #E26498">' ;
			str+='<a href="javascript:callServer_Get_Movie_Statistics()">Movie</a>';
			str+='</div>'; 

		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">Statistics</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="callServer_Get_Channel_Statistics()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Channel</button>'; 
		str+='<button class="button" onclick="callServer_Get_Movie_Statistics()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Movie</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="10" align="center"><font face="Arial" size="2">No.</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">CH Name</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Today Watched_No.</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Active Player No.</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Uptime</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Status</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
	 	 '</tr>'+'<tr><td  colspan="7"><hr size="2" color="#66FFFF"></td></tr>';
	 	
		while (1)
		{
	 	 	if (response[i]==0) break;
			//alert(response[i]);
		 	strlength=response[i].length;
		 	//alert(strlength);
	   	    	ch_no=response[i].slice(3,strlength);
	     	 	strlength=response[i+1].length;
	   	    	ch_name=response[i+1].slice(5,strlength);
	     	 	strlength=response[i+2].length;
	   	    	ch_watched_no=response[i+2].slice(11,strlength);
	     	 	strlength=response[i+3].length;
	   	    	ch_active_player_no=response[i+3].slice(10,strlength);
	     	 	strlength=response[i+4].length;
	   	    	ch_uptime=response[i+4].slice(7,strlength);
	     	 	strlength=response[i+5].length;
	   	    	ch_status=response[i+5].slice(7,strlength);
	     	 	strlength=response[i+6].length;
	   	    	ch_bitrate=response[i+6].slice(8,strlength);
	   	    	
	  
	 		i=i+7;
			HTML_str+='<tr>'+
			      '<td width="10" align="center"><font face="Arial" size="2">'+ch_no+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+decodeURI(ch_name)+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_watched_no+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_active_player_no+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_uptime+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_status+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ch_bitrate+'</font></td></tr>';
			total_ch_no++;
	     }
	      //    content.innerHTML=HTML_str;
	      // alert(menu_main.innerHTML);
	      	      
	
	  	content.innerHTML=HTML_str+'</table>';
	 	
	 	 if (bGet_Channel_Statistics==1)
	   	{
			if (g_Get_Channel_Statistics_timer==0)
			{
				//g_Get_Channel_Statistics_timer=setInterval(function(){callServer_Get_Channel_Statistics_Timer()},10*1000);
				//alert(g_Get_Channel_Statistics_timer);
			}
		}
 	}


 
}
function callServer_Get_Channel_Statistics_Timer() {
	var content = parent.document.getElementById("content");
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	   	
   	
   	
   	if (bGet_Channel_Statistics==0)
	{
		clearInterval(g_Get_Channel_Statistics_timer);
		g_Get_Channel_Statistics_timer=0;
		// alert("Clear Status Timer");
	}else
	{
		bSystem_Inquery_Panel=0; 
		bQuery_Channel_Status=0;
		bQuery_Online_Player=0;
	   	g_token=find_cookie_value("token");
		if (g_token!=0)
		{
			cgi_url = "/server/get_channel_statistics?token="+encodeURI(g_token)+"&flag="+Math.random();
			content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Channel Statistics Loading...<p>';
			
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = Get_Channel_Statistics;
			xmlHttp.send(null);
		}
	}
	

}
function callServer_Get_Channel_Statistics() {
	var content = parent.document.getElementById("content");
	var cgi_url;
	   	
	bSystem_Inquery_Panel=0; 
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_channel_statistics?token="+encodeURI(g_token)+"&flag="+Math.random();
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Channel Statistics Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_Channel_Statistics;
		xmlHttp.send(null);
	}

}
function calllist_Auto_Get_Channel_Statistics(){
	
	bGet_Channel_Statistics=1;
	callServer_Get_Channel_Statistics();
}
function Query_One_Channel_Status()
{
	var ch_src_status;
	var ch_status;
	var ch_bitrate;
	var ch_src_bitrate;
	var item_name;
	var old_ch_status;
	var i;
	var strlength;
	
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText.split("\r\n");
		    	strlength=response[0].length;
		    	ch_status=response[0].slice(7,strlength);
		    	//alert(ch_status);
		
			ch_src_status="chstatus"+(g_ch_no); 
			item_name=document.getElementById(ch_src_status);
			//alert(item_name.innerHTML);
			if (ch_status.search("OFF")>=0)
			{
				item_name.innerHTML="<a href='javascript:void(0)'"+' onclick=callServer_Get_Channel_Dump_Info('+g_ch_no+')>'+
		      		'<font face="Arial" size="2" color="#FF0000">'+'<b>OFF</b>'+'</font></a>';
//		      		item_name.innerHTML='<font face="Arial" size="2" color="#FF0000">'+'<b>OFF</b>'+'</font>';
			}else if (ch_status.search("Connecting")>=0)
			{
				item_name.innerHTML="<a href='javascript:void(0)'"+' onclick=callServer_Get_Channel_Dump_Info('+g_ch_no+')>'+
		      		'<font face="Arial" size="2" color="#FF0000">'+'<b>Connecting</b>'+'</font></a>';
			}else
			{
		      		item_name.innerHTML='<font face="Arial" size="2">'+ch_status+'</font>';
		      		
			}
			
			strlength=response[1].length;
		    	ch_bitrate=response[1].slice(8,strlength);
		    	//alert(ch_bitrate);
		
			ch_src_bitrate="chbitrate"+(g_ch_no); 
			item_name=document.getElementById(ch_src_bitrate);
			//alert(item_name.innerHTML);
	      		item_name.innerHTML='<font face="Arial" size="2">'+'<b>'+ch_bitrate+'</b>'+'</font>';	
	}
}

function callServer_Query_One_Channel_Status(ch_no) {
 	var cgi_url;
	
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		g_ch_no=ch_no;
		cgi_url = "/server/query_status_one_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&flag="+Math.random();
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Query_One_Channel_Status;
		xmlHttp.send(null);
	}

}
function Get_Channel_Dump()
{
	
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText.split("\r\n");
		var channel_dump;
		var i=0;
		
		channel_dump="Channel Dump:"+'\n';
		while (1)
		{
			if (response[i]==0) break;
			channel_dump+=response[i]+'\n';
			i++;
		}
		alert(channel_dump);
		
	}
}
function callServer_Get_Channel_Dump_Info(ch_no) {
 	var cgi_url;
	
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		g_ch_no=ch_no;
		cgi_url = "/server/get_channel_dump?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&flag="+Math.random();
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_Channel_Dump;
		xmlHttp.send(null);
	}

}
function Get_Channel_Status()
{
	var ch_src_status;
	var ch_status;
	var ch_bitrate;
	var ch_src_bitrate;
	var item_name;
	var old_ch_status;
	var i;
	var strlength;
	var nchno;
	var chtype;
	var chtype_id;
	
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText.split("\r\n");
//		for (i=0,j=0;i<g_total_ch_no;i++,j++)
		for (i=g_channel_position,j=0;j<(g_channel_limit*2);i++,j++)
		{
		    	strlength=response[j].length;
		    	if (response[0].length==0)
		    	{
				clearInterval(g_Query_Channel_Status_timer);
				g_Query_Channel_Status_timer=0;
		    		break;
		    	}
		    	ch_status=response[j].slice(7,strlength);
		    	//alert(ch_status);
		
			ch_src_status="chstatus"+i; 
			item_name=document.getElementById(ch_src_status);
			//alert(item_name.innerHTML);
			if (ch_status.search("OFF")>=0)
			{
				chtype_id="chtype"+i;
				chtype=document.getElementById(chtype_id);
				//alert(chtype);
				//alert(chtype.value);
				nchno=i+1;
				if (chtype.value=="inactive")
				{
			      		item_name.innerHTML='<font face="Arial" size="2" color="#FF0000">'+'<b>OFF</b>'+'</font>';
				}else
				{
					item_name.innerHTML="<a href='javascript:void(0)'"+' onclick=callServer_Get_Channel_Dump_Info('+nchno+')>'+
			      		'<font face="Arial" size="2" color="#FF0000">'+'<b>OFF</b>'+'</font></a>';
		      		}
			}else if (ch_status.search("Connecting")>=0)
			{
				nchno=i+1;
				item_name.innerHTML="<a href='javascript:void(0)'"+' onclick=callServer_Get_Channel_Dump_Info('+nchno+')>'+
		      		'<font face="Arial" size="2" color="#FF0000">'+'<b>Connecting</b>'+'</font></a>';
			}else
			{
		      		item_name.innerHTML='<font face="Arial" size="2">'+ch_status+'</font>';
		      		
			}
			j++;
			strlength=response[j].length;
		    	ch_bitrate=response[j].slice(8,strlength);
		
			ch_src_bitrate="chbitrate"+i; 
			//alert(ch_src_bitrate);
		    	//alert(ch_bitrate);
			item_name=document.getElementById(ch_src_bitrate);
			//alert(item_name.innerHTML);
	      		item_name.innerHTML='<font face="Arial" size="2">'+'<b>'+ch_bitrate+'</b>'+'</font>';

			
				
		}
	}
}
function callServer_Get_Channels_Status_Timer() {
 	var cgi_url;
	
	
	if (bQuery_Channel_Status==0)
	{
		clearInterval(g_Query_Channel_Status_timer);
		g_Query_Channel_Status_timer=0;
		// alert("Clear Status Timer");
	}else
	{
		bSystem_Inquery_Panel=0; 
		bQuery_Online_Player=0;
		bGet_Channel_Statistics=0;
	   	g_token=find_cookie_value("token");
		if (g_token!=0)
		{
			cgi_url = "/server/get_channels_status?token="+encodeURI(g_token)+"&position="+g_channel_position+"&limit="+g_channel_limit+"&flag="+Math.random();

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

}

function Query_Channel_Status()
{
	var ch_src_status;
	var ch_status;
	var ch_bitrate;
	var ch_src_bitrate;
	var item_name;
	var old_ch_status;
	var i;
	var strlength;
	
	if (xmlHttp.readyState == 4) {
		var response = xmlHttp.responseText.split("\r\n");
		for (i=0,j=0;i<g_total_ch_no;i++,j++)
		{
		    	strlength=response[j].length;
		    	if (response[0].length==0)
		    	{
				clearInterval(g_Query_Channel_Status_timer);
				g_Query_Channel_Status_timer=0;
		    		break;
		    	}
		    	ch_status=response[j].slice(7,strlength);
		    	//alert(ch_status);
		
			ch_src_status="chstatus"+(i+1); 
			item_name=document.getElementById(ch_src_status);
			//alert(item_name.innerHTML);
			 if (ch_status.search("OFF")>=0)
			{
		      		item_name.innerHTML='<font face="Arial" size="2" color="#FF0000">'+'<b>OFF</b>'+'</font>';
			}else
			{
		      		item_name.innerHTML='<font face="Arial" size="2">'+ch_status+'</font>';
		      		
			}
			j++;
			strlength=response[j].length;
		    	ch_bitrate=response[j].slice(8,strlength);
		    	//alert(ch_bitrate);
		
			ch_src_bitrate="chbitrate"+(i+1); 
			item_name=document.getElementById(ch_src_bitrate);
			//alert(item_name.innerHTML);
	      		item_name.innerHTML='<font face="Arial" size="2">'+'<b>'+ch_bitrate+'</b>'+'</font>';

			
				
		}
	}
}
function callServer_Query_Channel_Status_Timer() {
 	var cgi_url;
	
	
	if (bQuery_Channel_Status==0)
	{
		clearInterval(g_Query_Channel_Status_timer);
		g_Query_Channel_Status_timer=0;
		// alert("Clear Status Timer");
	}else
	{
		bSystem_Inquery_Panel=0; 
		bQuery_Online_Player=0;
		bGet_Channel_Statistics=0;
	   	g_token=find_cookie_value("token");
		if (g_token!=0)
		{
			cgi_url = "/server/query_status_channel_list?token="+encodeURI(g_token)+"&flag="+Math.random();
			
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = Query_Channel_Status;
			xmlHttp.send(null);
		}
	}

}

function callServer_Query_Online_Player_Timer() {
 	var cgi_url;
	
	if (bQuery_Online_Player==0)
	{
		clearInterval(g_Query_Online_Player_timer);
		g_Query_Online_Player_timer=0;
		// alert("Clear Status Timer");
	}else
	{
		bSystem_Inquery_Panel=0; 
		bQuery_Channel_Status=0;
	   	g_token=find_cookie_value("token");
		if (g_token!=0)
		{
			cgi_url= "/player/get_player_list?token="+encodeURI(g_token)+"&position="+g_active_connection_position+"&limit="+g_active_connection_limit+"&flag="+Math.random();
			content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Player Information Loading...<p>';
			
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = list_active_player_info;
			xmlHttp.send(null);
		}
	}

}
function Cancel_Add_New_EPG()
{
	var content = parent.document.getElementById("content");
	content.innerHTML=g_content;
}
function Add_EPG_Info() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var item_save;
    var item_add;
    var item_del;
    var ch_no=g_ch_no;
    if (response==1)
    {
    	g_total_program_no++;
	callServer_Get_EPG_Info();
/*
  //  	alert("Sucessfully, Refresh Channels to active all channels");
 	g_item.value=g_temp;
	g_item.style.backgroundColor = "#ffffff";
	//alert(add_id_button.innerHTML);
	// callServer_CH_Inquery();
	item_save=document.getElementById("save_id_button");
	item_del=document.getElementById("del_id_button");
	item_add=document.getElementById("add_id_button");
	
	item_save.innerHTML='<td align="center">'+
		      "<a href='javascript:void(0)'"+
			' onclick=callServer_Update_EPG_Info("'+g_program_no+'")>'+
	      	      ' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
	item_del.innerHTML='<td width="50" align="center">'+
		      "<a href='javascript:void(0)'"+
			' onclick=call_Del_EPG_Info("'+g_program_no+'")>'+
	      	      ' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
	item_add.innerHTML='<td align="center">'+
		      "<a href='javascript:void(0)'"+
			' onclick=call_Add_New_EPG_Info("'+g_program_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
*/	      	      
  } else
    {
   	alert("Failed to Add EPG");
 	//	callServer_Get_EPG_Info();
   }
	      	      
	/*if (g_Channel_Edit_Mode==0) 
	{
	}*/
	
    }
}
function call_Add_EPG()
{

	var ch_no= document.getElementById("cur_ch_no").value;
	var starttime_id="starttime";
	var starttime;
	var stoptime_id="stoptime";
	var stoptime;
	var program_title_id="program_title";
	var program_title;
	var program_descrption_id="program_descrption";
	var program_descrption;
	var program_icon_id="program_icon";
	var program_icon;
	var program_rec_id="program_rec";
	var program_rec;
	var program_no_id="program_no";
	var program_no;

	var add_new_program_button=document.getElementById("add_new_program_button");
	var add_new_program_dialog_message=document.getElementById("add_new_program_dialog_message");
	var new_programitem;
	var new_programnameitem;

	var confirm_msg;
 	var cgi_url;

	g_item=document.getElementById(program_no_id);
	new_programitem=g_item;
	program_no = g_item.value;

	g_item=document.getElementById(starttime_id);
	starttime = g_item.value;
	if (starttime.length==0)
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Start Time is empty</font>';
		return;
	}else if ((starttime.length!=19) && (starttime.length!=5))
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Start Time Format error</font>';
		return;
	}
	if ((starttime=="hh:mm") || (starttime=="YYYY/MM/DD hh:mm:ss"))
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Start Time Format error</font>';
		return;
	}
		
	g_item=document.getElementById(stoptime_id);
	stoptime = g_item.value;
	if (stoptime.length==0)
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Stop Time is empty</font>';
		return;
	}else if ((stoptime.length!=19)&&(stoptime.length!=5))
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Stop Time Format error</font>';
		return;
	}
	if ((stoptime=="hh:mm") || (stoptime=="YYYY/MM/DD hh:mm:ss"))
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Stop Time Format error</font>';
		return;
	}
	
	g_item=document.getElementById(program_descrption_id);
	program_descrption = g_item.value;

	g_item=document.getElementById(program_icon_id);
	program_icon = g_item.value;
	
	g_item=document.getElementById(program_rec_id);
	program_rec = g_item.value;

	g_item=document.getElementById(program_title_id);
	new_programnameitem=g_item;
	program_title = g_item.value;
	if (program_title.length==0)
	{
		add_new_program_dialog_message.innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Program Title is empty</font>';
		return;
	}


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

	g_ch_no=ch_no;
	g_program_title=program_title;
	g_program_no=program_no;
	cgi_url = "/server/add_epg_info?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&program_no=" + encodeURI(program_no)+"&starttime=" + encodeURI(starttime)+ "&stoptime=" + encodeURI(stoptime)+ "&program_title=" + encodeURI(program_title)+ "&program_descrption=" + encodeURI(program_descrption)+ "&program_icon=" + encodeURI(program_icon)+ "&program_rec=" + encodeURI(program_rec)+"&flag="+Math.random();
 
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
	    		var response = xmlHttp.responseText;
		 	if (response==1)
	    		{
	    			g_total_program_no++;
		 		add_new_program_button.value="Add Next";
				new_add_total_no=g_total_program_no+1;
				add_new_program_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+program_title+' Added</font>';
				//alert(new_add_total_no);
				new_programitem.value=new_add_total_no;
				new_programnameitem.value="";
				new_programnameitem.focus();
			}else
			{
				add_new_program_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Add</font>';
			}
		}
	 };
	 xmlHttp.send(null);
	// g_temp=g_item.value;
	 //g_item.value=g_item.value+" (adding...)";
	 //g_item.style.backgroundColor = "#ff0000";
 


}
function call_Add_New_EPG_Info(program_no)
{
	var content = parent.document.getElementById("content");
	g_content=content.innerHTML;
	var program_active_no=g_total_program_no;
	var i, m;
	var starttime_id;
	var starttime;
	var stoptime_id;
	var stoptime;
	var program_title_id;
	var program_title;
	var program_descrption_id;
	var program_descrption;
	var program_icon_id;
	var program_icon;
	var program_rec_id;
	var program_rec;
	var HTML_Menu_Bar_Str="";
	var cur_month;
	var cur_temp_year;
	var cur_year;

	
	program_active_no++;
	cur_year=g_cur_year;
	cur_month=g_cur_month;
	//alert(program_active_no);
 
	HTML_Menu_Bar_Str='<td width="10%" align="right"><font face="Arial" size="2">Channel No.:</font></td>';
	HTML_Menu_Bar_Str+='<td width="5%" align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_ch_no" id=cur_ch_no>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+g_ch_no+'">'+g_ch_no+'</option>';
	for (i=1;i<=g_total_ch_no;i++)
	{
		if (i!=g_ch_no)
		{
			HTML_Menu_Bar_Str+='<option value="'+i+'">'+i+'</option>';
		}
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

	HTML_Menu_Bar_Str+='<td width="5%" align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_year" id=cur_year>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+g_cur_year+'">'+g_cur_year+'</option>';
	cur_temp_year=g_cur_year-1;
	for (i=0;i<5;i++)
	{
		index_year=cur_temp_year+i;
		if (g_cur_year!=index_year)
		{
			HTML_Menu_Bar_Str+='<option value="'+index_year+'">'+index_year+'</option>';
		}
		
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

 	HTML_Menu_Bar_Str+='<td width="5%" align="right">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_month" id=cur_month>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+cur_month+'">'+cur_month+'</option>';
	for (i=1;i<13;i++)
	{
		if (i!=cur_month)
		{
			if (i<10)
			{
				HTML_Menu_Bar_Str+='<option value="0'+i+'">0'+i+'</option>';
				
			}else
			{
				HTML_Menu_Bar_Str+='<option value="'+i+'">'+i+'</option>';
			}
		}
		
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

     HTML_Menu_Bar_Str+='<td width=80% align="left">';
      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_Get_EPG_Info_By_Month()>"+
      '<font size="2" face="Arial">Query</font></a>'+'&nbsp&nbsp&nbsp';
      HTML_Menu_Bar_Str+='</td>';
      HTML_str=  '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="60" align="center"><font face="Arial" size="2">No.</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Start Time(YYYY/MM/DD hh:mm:ss)</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Stop Time(YYYY/MM/DD hh:mm:ss)</font></td>'+
	      '<td width="260" align="center"><font face="Arial" size="2">Program Title</font></td>'+
	      '<td width="400" align="center"><font face="Arial" size="2">Program Description</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Record Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Record</font></td>'+
 	 '</tr>'+'<tr><td  colspan="8"><hr size="1" color="#66FFFF"></td></tr>';
 	 for (i=1,m=1;i<=program_active_no;i++,m++)
	{
		starttime_id="starttime"+m; 
		//alert(starttime_id);
		item_name=document.getElementById(starttime_id);
		// alert(item_name.value);
		starttime = item_name.value;
		
		stoptime_id="stoptime"+m; 
		item_name=document.getElementById(stoptime_id);
		// alert(item_name.value);
		stoptime = item_name.value;
		
		program_title_id="program_title"+m; 
		item_name=document.getElementById(program_title_id);
		// alert(item_name.value);
		program_title = item_name.value;
		
		program_descrption_id="program_descrption"+m; 
		item_name=document.getElementById(program_descrption_id);
		// alert(item_name.value);
		program_descrption = item_name.value;

		program_icon_id="program_icon"+m; 
		item_name=document.getElementById(program_icon_id);
		// alert(item_name.value);
		program_icon = item_name.value;

		program_rec_id="program_rec"+m; 
		item_name=document.getElementById(program_rec_id);
		// alert(item_name.value);
		program_rec = item_name.value;
		HTML_str=HTML_str+
		   '<tr>'+
		      '<td width="60" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="starttime"'+
	 		' id=starttime'+i+
	 		' size="19" value="'+
	 		starttime+'"/></font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="stoptime"'+
	 		' id=stoptime'+i+
	 		' size="19" value="'+
	 		stoptime+'"/></font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="program_title"'+
	 		' id=program_title'+i+
	 		' size="20" value="'+
	 		program_title+'"/></font></td>'+
		      '<td width="40" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="program_descrption"'+
	 		' id=program_descrption'+i+
	 		' size="40" value="'+
	 		program_descrption+'"/></font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="program_icon"'+
	 		' id=program_icon'+i+
	 		' size="20" value="'+
	 		program_icon+'"/></font></td>';
	 		
	 		HTML_str=HTML_str+
	 		'<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <select size="1" name="program_rec" '+'id=program_rec'+i+'>';
	 		if (program_rec=="ON")
	 		{
		      
		      		// alert(program_rec);
		 		HTML_str=HTML_str+'<option selected="selected" value="'+"ON"+'">'+"ON"+'</option>'+
		 		'<option value="'+"OFF"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else
 			{
		      		// alert(program_rec);
		 		HTML_str=HTML_str+'<option selected="selected" value="'+"OFF"+'">'+"OFF"+'</option>'+
		 		'<option value="'+"ON"+'">'+"ON"+'</option>'+'</select></font></td>';
 			}
	 		
	 		if (m==program_no)
			{
				save_keyword="Save";
				add_keyword="Add";
				del_keyword="Del";
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_Update_EPG_Info("'+i+'")>'+
				' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Del_EPG_Info("'+i+'")>'+
				' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Add_New_EPG_Info("'+i+'")>'+
				' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
				
				i++;
				starttime=cur_year+'/'+cur_month+'/'+'01 00:00:00';
				stoptime=cur_year+'/'+cur_month+'/'+'01 00:00:00';

			//	starttime="";
			//	stoptime="";
				program_title="";
				program_descrption="";
				program_icon="";
				
				HTML_str=HTML_str+
			   	'<tr>'+
			      '<td width="60" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
			      '<td width="20" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="starttime"'+
		 		' id=starttime'+i+
		 		' size="19" value="'+
		 		starttime+'"/></font></td>'+
			      '<td width="20" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="stoptime"'+
		 		' id=stoptime'+i+
		 		' size="19" value="'+
		 		stoptime+'"/></font></td>'+
			      '<td width="20" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="program_title"'+
		 		' id=program_title'+i+
		 		' size="20" value="'+
		 		program_title+'"/></font></td>'+
			      '<td width="40" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="program_descrption"'+
		 		' id=program_descrption'+i+
		 		' size="40" value="'+
		 		program_descrption+'"/></font></td>'+
			      '<td width="20" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="program_icon"'+
		 		' id=program_icon'+i+
		 		' size="20" value="'+
		 		program_icon+'"/></font></td>'+
		 		'<td width="20" align="center">'+
				' <font face="Arial" size="2">'+
		 		' <select size="1" name="program_rec" '+'id=program_rec'+i+'>'+
				'<option selected="selected" value="ON">ON</option>'+
				 '<option value="OFF">OFF</option>'+
				'</select></font></td>';
			      	HTML_str+='<td id=save_id_button width="80" align="center">'+
				      "<a href='javascript:void(0)'"+
				      ' onclick=call_Add_EPG("'+i+'")>'+
			      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
			      	      
				      '<td id=del_id_button width="80" align="center">'+		      
				      "<a href='javascript:void(0)'"+
				      ' onclick=Cancel_Add_New_EPG()>'+
			      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+
	
				      '<td id=add_id_button width="80" align="center">'+		      
				      ' <font face="Arial" size="2"></font></a></td>';
			}else
			{
				save_keyword="Save";
				add_keyword="Add";
				del_keyword="Del";
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_Update_EPG_Info("'+i+'")>'+
				' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Del_EPG_Info("'+i+'")>'+
				' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Add_New_EPG_Info("'+i+'")>'+
				' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
			}
							
			HTML_str+='</tr>';
		
	}
	
	content.innerHTML='<table width=99%><tr><td width=20%>'+
  	'<font size="2" face="Arial">Total: '+ program_active_no+'</td>'+HTML_Menu_Bar_Str+
 	'</tr></table>'+HTML_str+'</table>';
	//g_total_program_no=program_active_no;
}
function change_date_format()
{
	var program_rec_id=document.getElementById("program_rec");
	var starttime_id;
	var stoptime_id;
	
	if ((program_rec_id.value==2) ||
	    (program_rec_id.value==3) ||
	    (program_rec_id.value==4) ||
	    (program_rec_id.value==5) ||
	    (program_rec_id.value==6) ||
	    (program_rec_id.value==7) ||
	    (program_rec_id.value==8) ||
	    (program_rec_id.value==9))
	{
		starttime_id=document.getElementById("starttime");
		stoptime_id=document.getElementById("stoptime");
		starttime_id.value="hh:mm";
		stoptime_id.value="hh:mm";
	}else if (program_rec_id.value==1)
	{
		starttime_id=document.getElementById("starttime");
		stoptime_id=document.getElementById("stoptime");
		starttime_id.value="YYYY/MM/DD hh:mm:ss";
		stoptime_id.value="YYYY/MM/DD hh:mm:ss";
	}

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


	var response = xmlHttp.responseText.split("\r\n");
	var ch_no;
	var program_no=0;
	var starttime;
	var stoptime;
	var program_title;
	var program_descrption;
	var program_icon;
	var program_rec;
	var i=0;
	var j=0;
	var HTML_str='';
	var strlength=0;
	var content = parent.document.getElementById("content");
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	//var cur_year;
	var cur_month;
	var HTML_Menu_Bar_Str="";
	var index_year;
	var d=new Date();
	var cur_year=d.getFullYear();
	var cur_temp_year;

	//cur_year=g_cur_year;
	cur_month=g_cur_month;
	var content;
	var cellsize="15%";
	
	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>'
	var action_width="85%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>EPG</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()">Add Program</a>';
		str+='</div>'; 
		/* str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button onclick="callServer_Refresh_EPG_Info()" 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">EPG</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()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Add Program</button>'; 
		str+='<button class="button" onclick="callServer_Refresh_EPG_Info()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Refresh</button>'; 
	str+='</div>';                              
	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";

	 HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
	  '<tr>'+
	      '<td width="20" align="left"><p style="margin-left: 5"><font face="Arial" size="2">No.</font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Start Time</font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Stop Time</font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Program Title</font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Program Description</font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Record Icon Path</font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Record</font></td>'+
 	 '</tr>'+'<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
 	
	while (1)
	{
 	 	if (response[i]==0) 
 	 	{
 	 		//alert("finished");
 	 		break;
 	 	}
		//alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
   	    	starttime=response[i].slice(10,strlength);
     	 	strlength=response[i+1].length;
     	 	//alert(response[i+1]);
   	    	stoptime=response[i+1].slice(9,strlength);
     	 	strlength=response[i+2].length;
   	    	program_title=response[i+2].slice(6,strlength);
   	    	//alert(program_title);
      	 	strlength=response[i+3].length;
 	    	program_descrption=response[i+3].slice(12,strlength);
 	    	if (response[i+4].search("icon=")==0)
 	    	{
	     	 	strlength=response[i+4].length;
	 	    	program_icon=response[i+4].slice(5,strlength);
	     	 	strlength=response[i+5].length;
	 	    	program_rec=response[i+5].slice(4,strlength);
		    	i=i+6;
	    	}else
 	    	{
 	     	 	strlength=response[i+5].length;
	 	    	program_icon=response[i+5].slice(5,strlength);
	     	 	strlength=response[i+6].length;
	 	    	program_rec=response[i+7].slice(4,strlength);
		    	i=i+7;
	    		
 	    	}
  		program_no++;
		
		
		HTML_str=HTML_str+
		   '<tr>'+
		      '<td width="20" align="left"><p style="margin-left: 5"><font face="Arial" size="2">'+program_no+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="starttime"'+
	 		' id=starttime'+program_no+
	 		' size="15" value="'+
	 		starttime+'"/></font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="stoptime"'+
	 		' id=stoptime'+program_no+
	 		' size="15" value="'+
	 		stoptime+'"/></font></td>'+
			 		
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="program_title"'+
	 		' id=program_title'+program_no+
	 		' size="20" value="'+
//	 		program_title+'"/></font></td>'+
	 		unescape(program_title)+'"/></font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="program_descrption"'+
	 		' id=program_descrption'+program_no+
	 		' size="40" value="'+
//	 		program_descrption+'"/></font></td>'+
	 		unescape(program_descrption)+'"/></font></td>'+
//	 		decodeURI(program_descrption)+'"/></font></td>'+
//	 		decodeURIComponent(program_descrption)+'"/></font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="program_icon"'+
	 		' id=program_icon'+program_no+
	 		' size="20" value="'+
	 		program_icon+'"/></font></td>';
	 		
	 		HTML_str=HTML_str+
	 		'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="program_rec" '+'id=program_rec'+program_no+'>';
	 		if (program_rec==1)
	 		{
		      
		 		HTML_str=HTML_str+'<option selected="selected" style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==2)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option  selected="selected" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==3)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option  selected="selected" value="'+"3"+'">'+"MONDAY"+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==4)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==5)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==6)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==7)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" alue="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==8)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==9)
	 		{
		      
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else if (program_rec==0)
	 		{
		 		HTML_str=HTML_str+'<option style="padding: 2px" value="'+"1"+'">'+"ON"+'</option>'+
		 		'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option  selected="selected" style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}	
	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=callServer_Update_EPG_Info("'+program_no+'")><img src="/admin/save.png"></img></a>&nbsp;&nbsp;'+
			"<a href='javascript:void(0)'"+
			' onclick=onclick=call_Del_EPG_Info("'+program_no+'")><img src="/admin/del.png"></img></a>'+
	 		'</td>';	 	
			HTML_str+='</tr>';
			
				
		    
     }

	HTML_Menu_Bar_Str='<tr><td align="right"><font face="Arial" size="2">Channel</font></td>';
	HTML_Menu_Bar_Str+='<td align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_ch_no" id=cur_ch_no>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+g_ch_no+'">'+g_ch_no+'</option>';
//	alert(g_total_ch_no);
	for (i=1;i<=g_total_ch_no;i++)
	{
		if (i!=g_ch_no)
		{
			HTML_Menu_Bar_Str+='<option value="'+i+'">'+i+'</option>';
		}
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

	HTML_Menu_Bar_Str+='<td align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_year" id=cur_year>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+g_cur_year+'">'+g_cur_year+'</option>';
	cur_temp_year=g_cur_year-1;
	for (i=0;i<5;i++)
	{
		index_year=cur_temp_year+i;
		if (g_cur_year!=index_year)
		{
			HTML_Menu_Bar_Str+='<option value="'+index_year+'">'+index_year+'</option>';
		}
		
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

 	HTML_Menu_Bar_Str+='<td align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_month" id=cur_month>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+cur_month+'">'+cur_month+'</option>';
	for (i=1;i<13;i++)
	{
		if (i!=cur_month)
		{
			if (i<10)
			{
				HTML_Menu_Bar_Str+='<option value="0'+i+'">0'+i+'</option>';
				
			}else
			{
				HTML_Menu_Bar_Str+='<option value="'+i+'">'+i+'</option>';
			}
		}
		
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

     HTML_Menu_Bar_Str+='<td align="center">';
          HTML_Menu_Bar_Str+='<button style="width:100%;height:30;background-color: #0000ff;color: #ffffff;" class="button" onclick="javascript:callServer_Get_EPG_Info_By_Month();" />Query </button>';
     HTML_Menu_Bar_Str+='</td>';
    HTML_Menu_Bar_Str+='<td width=80% cospan=4 align="center">';
      HTML_Menu_Bar_Str+='</td>';
  
var newprogram_no=program_no+1;
      menustr1='<td width="4%">';
	menustr1+='<div id="PanelModal" class="modal">'+
		'<div class="modal-content">';
		menustr1+='<table align="center" cellspacing="10" align="center">';
		menustr1+='<tr><td colspan=2 align="left"><font face="Arial" size="6"><b>New Program</b></font></td><td colspan=2 align=right id=add_new_program_dialog_message name=add_new_program_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">Program No.</font></td><td width="25%" height="23">'+
		' <font face="Arial" size="2">'+
		' <input style="padding: 5px;height:30;" type="text" name="program_no"'+
		' id="program_no"'+
		' size="16" value="'+
		newprogram_no+
		'"/></font></td>';
		menustr1+='<td width="25%"><font face="Arial" size="2">Record by</font></td><td width="25%">'+
		 		' <font face="Arial" size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" onchange=change_date_format() size="1" name="program_rec" id=program_rec>';
		 		
				menustr1+='<option selected="selected" value="1">'+"ON"+'</option>'+
				'<option style="padding: 2px" value="'+"2"+'">'+"DAILY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"3"+'">'+"MONDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"4"+'">'+"TUESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"5"+'">'+"WEDNESDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"6"+'">'+"THURSDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"7"+'">'+"FRIDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"8"+'">'+"SATURDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"9"+'">'+"SUNDAY"+'</option>'+
	 			'<option style="padding: 2px" value="'+"0"+'">'+"OFF"+'</option>';
		menustr1+='</select></font></td></tr>';
		
		menustr1+='<tr><td><font face="Arial" font size="2">Start Time</font></td><td>'+
		 		' <font face="Arial" size="2">'+
			 	' <input style="padding: 5px;height:30;" type="text" name="starttime"'+
			 	' id=starttime'+
		 		' size="16" value="YYYY/MM/DD hh:mm:ss" oninput="change_released_date_input_color('+"'starttime'"+')"/></font></td>';
		menustr1+='<td><font face="Arial" size="2">Stop Time</font></td><td>'+
		 		' <font face="Arial" size="2">'+
		 		' <input style="padding: 5px;height:30;" type="text" name="stoptime"'+
		 		' id=stoptime'+
		 		' size="16" value="YYYY/MM/DD hh:mm:ss" oninput="change_released_date_input_color('+"'stoptime'"+')"/></font></td></tr>';
		
		menustr1+='<tr><td><font face="Arial" size="2">Title</font></td><td>'+
		 		' <font face="Arial" size="2">'+
		 		' <input style="padding: 5px;height:30;" type="text" name="program_title"'+
		 		' id=program_title'+
		 		' size="16"/'+
		 		'</font></td>';
		menustr1+='<td><font face="Arial" size="2">Icon URL</font></td><td>'+
		 		' <font face="Arial" size="2">'+
		 		' <input style="padding: 5px;height:30;" type="text" name="program_icon"'+
		 		' id=program_icon'+
		 		' size="16"/'+
		 		'</font></td></tr>';
		 		
		menustr1+='<tr><td><font face="Arial" size="2">Description</font></td><td colspan=3>'+
		 		' <font face="Arial" size="2">'+
		 		' <input style="padding: 5px;height:30;" type="text" name="program_descrption"'+
		 		' id=program_descrption'+
		 		' size="61"/'+
		 		'</font></td></tr>';


	//	menustr1+='<tr><td><input type="button" value="Add" onclick=call_Add_EPG() name="Save" /></td></tr></table>'+
	//	'</div>'+
	//'</div></td>';
		menustr1+='<tr><td colspan=2><input id=add_new_program_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_EPG() name="Add" /></td>'+
		'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_epg_modal() name="Cancel" /></td></tr>';
		menustr1+='</table>'+
		'</div>'+
		'</div></td>';	

	
  	content.innerHTML='<table width=100%><tr>'+
  	menustr1+'</tr>'+
  	HTML_Menu_Bar_Str+
  	//'<td width=7%>'+
  	//'<p style="margin-right: 5; margin-top: 10"><font size="2" face="Arial">Total: '+ program_no+
  	//'</td>'+
 	'</tr></table>'+HTML_str+'</table>';
	document.getElementById("starttime").style.color = "#cccccc";
	document.getElementById("stoptime").style.color = "#cccccc";
	
	g_total_program_no=program_no;
 
 }
}
function callServer_Get_EPG_Info() {
	var content = parent.document.getElementById("content");
	
	var cgi_url;
	var ch_no=1;
	var from_month;
	var to_month;
	var d=new Date();
	var cur_year=d.getFullYear();
	var cur_month=d.getMonth()+1;
	
	bSystem_Inquery_Panel=0; 
 	bQuery_Channel_Status=0;	
 	bQuery_Online_Player=0;
 	bGet_Channel_Statistics=0;
 
  	g_token=find_cookie_value("token");
   	g_ch_no=ch_no;
	if (g_token!=0)
	{
		g_ch_no=ch_no;
		from_month=cur_month;
		to_month=cur_month;
		g_cur_year=cur_year;
		//g_cur_month=cur_month;
		if (cur_month<10)
		{
			g_cur_month='0'+cur_month;
		}else
		{
			g_cur_month=cur_month;		
		}
		cgi_url = "/server/get_epg_info?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&from_year=" + encodeURI(cur_year)+ "&from_month=" + encodeURI(from_month)+ "&to_month=" + encodeURI(to_month)+"&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">EPG Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_EPG_Info;
		xmlHttp.send(null);
	}

}
var g_xmltv_position=1;
var g_total_xmltv_no=0;
var g_xmltv_limit=0;

function callServer_Add_XMLTV(){
	
  var xmltv_name;
 var xmltv_src;
 var xmltv_status=0;
  var g_item_name;
  var xmltv_no=g_total_xmltv_no+1;
//alert(g_total_xmltv_no)

 	var cgi_url;
	
 g_item=document.getElementById("new_xmltv_name");
 xmltv_name = g_item.value;
 if (xmltv_name.length==0)
 {
 	alert("Name is empty");
 	return;
 }
 //alert(xmltv_name);
 g_item_name=document.getElementById("new_xmltv_src");
 xmltv_src = g_item_name.value;
 //alert(xmltv_src);

  if (document.getElementById("new_xmltv_status").checked)
  {
  	xmltv_status=1;
  }
 //alert(xmltv_status);

cgi_url = "/server/add_xmltv?token="+encodeURI(g_token)+"&name=" + encodeURI(xmltv_name)+ "&src=" + xmltv_src+ "&status=" + encodeURI(xmltv_status)+"&flag="+Math.random();

	//alert(cgi_url);
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			    var response = xmlHttp.responseText;
			    //alert(response);
			    if (response==1)
			    {
			    	g_total_xmltv_no++;
			    	close_xmltv_modal();
				/*
				document.getElementById("add_new_xmltv_button").value="Add Next";
				var new_add_total_no=g_total_xmltv_no+1;
				add_xmltv_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+xmltv_name+' Added</font>';
				//alert(new_add_total_no);
				document.getElementById("new_xmltv_name").value="";
				document.getElementById("new_xmltv_name").focus();
				*/
			
			    } else
			    {
			   	alert("Failed to Add XMLTV");
			    }
		}
			 
	};
	 xmlHttp.send(null);
 
}
function callServer_XMLTV_Update(xmltv_no){
 var xmltv_name_id="xmltv_name"+xmltv_no; 
 var xmltv_src_id="xmltv_src"+xmltv_no; 
var xmltv_status_id="xmltv_status"+xmltv_no; 
  var xmltv_name;
 var xmltv_src;
 var xmltv_status=0;
  var g_item_name;


 	var cgi_url;
	
 g_item=document.getElementById(xmltv_name_id);
 xmltv_name = g_item.value;
 if (xmltv_name.length==0)
 {
 	alert("Name is empty");
 	return;
 }
 //alert(xmltv_name);
 g_item_name=document.getElementById(xmltv_src_id);
 xmltv_src = g_item_name.value;
 //alert(xmltv_src);
   if (document.getElementById(xmltv_status_id).checked==true)
  {
  	xmltv_status=1;
  }else
	{
		xmltv_status=0;
	}

// alert(xmltv_status);

cgi_url = "/server/update_xmltv?token="+encodeURI(g_token)+"&xmltv_no="+xmltv_no+"&name=" + encodeURI(xmltv_name)+ "&src=" + xmltv_src+ "&status=" + encodeURI(xmltv_status)+"&flag="+Math.random();

	//alert(cgi_url);
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			    var response = xmlHttp.responseText;
			    //alert(response);
			    if (response==1)
			    {

			
			    } else
			    {
			   	alert("Failed to Update XMLTV");
			    }
				g_item.value=g_temp;
				g_item.style.backgroundColor = "#ffffff";
		}
			 
	};
	 xmlHttp.send(null);
 	 g_temp=g_item.value;
 	 g_item.style.backgroundColor = "#ff0000";
 
}

function call_Del_XMLTV(xmltv_no)
{
  var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
 g_token=find_cookie_value("token");
var xmltv_name_id="xmltv_name"+xmltv_no; 
 confirm_msg="Delete XMLTV "+document.getElementById(xmltv_name_id).value+" ?";
 cgi_url = "/server/del_xmltv?token="+encodeURI(g_token)+"&xmltv_no="+xmltv_no+ "&flag="+Math.random();
 if (confirm(confirm_msg))
 {
 	
	
	 xmlHttp.open("GET", cgi_url, true);
	  xmlHttp.onreadystatechange = function() {
	  	if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response==1)
			{
				g_total_xmltv_no--;
				alert("Sucessfully");
			} else if (response==2)
			{
				alert("The previous channel is deleting.");		
			}else
			{
				alert("Failed to Delete Channel");
			}
			//alert(g_xmltv_position);
			//alert(g_xmltv_limit);
			callServer_Get_XMLTV_Info(g_xmltv_position,g_xmltv_limit);
    		}
	  };
	 xmlHttp.send(null);
 }


}

function Call_Server_Refresh_XMLTV()
{
  var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
 g_token=find_cookie_value("token");
 cgi_url = "/server/refresh_xmltv?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	
	 xmlHttp.open("GET", cgi_url, true);
	 
	 var str='<i class="fa fa-refresh fa-spin"></i>';
	    
	    
	 document.getElementById("xmltv_refresh_btn").innerHTML=str;
	 document.getElementById("xmltv_refresh_btn").disabled=true;
		    
	  xmlHttp.onreadystatechange = function() {
	  	if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response==1)
			{
					 var str='<i class="fa fa-refresh"></i>';
					 document.getElementById("xmltv_refresh_btn").innerHTML=str;
				 	 document.getElementById("xmltv_refresh_btn").disabled=false;


			}else
			{
				alert("Failed to Refresh Channel");
			}
    		}
	  };
	 xmlHttp.send(null);
 


}
function callServer_Update_Provider(provider_no){
	var provider_name_id="provider_name"+provider_no; 
	var provider_src_id="provider_src"+provider_no; 
	var provider_status_id="provider_status"+provider_no; 
	var provider_name;
	var provider_src;
	var provider_status=0;
	var g_item_name;


 	var cgi_url;
	
	g_item=document.getElementById(provider_name_id);
	provider_name = g_item.value;
	if (provider_name.length==0)
	{
		alert("Name is empty");
		return;
	}
	//alert(provider_name);
	g_item_name=document.getElementById(provider_src_id);
	provider_src = g_item_name.value;
	//alert(provider_src);
	if (document.getElementById(provider_status_id).checked==true)
	{
	provider_status=1;
	}else
	{
		provider_status=0;
	}


	cgi_url = "/server/update_provider?token="+encodeURI(g_token)+"&provider_no="+provider_no+"&name=" + encodeURI(provider_name)+ "&src=" + provider_src+ "&status=" + encodeURI(provider_status)+"&flag="+Math.random();

	//alert(cgi_url);
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			    var response = xmlHttp.responseText;
			    //alert(response);
			    if (response==1)
			    {

			
			    } else
			    {
			   	alert("Failed to Update provider");
			    }
				g_item.value=g_temp;
				g_item.style.backgroundColor = "#ffffff";
		}
			 
	};
	 xmlHttp.send(null);
 	 g_temp=g_item.value;
 	 g_item.style.backgroundColor = "#ff0000";
 
}

function call_Del_Provider(provider_no)
{
	var confirm_msg;
	var cgi_url;

	
 g_token=find_cookie_value("token");
var provider_name_id="provider_name"+provider_no; 
 confirm_msg="Delete provider "+document.getElementById(provider_name_id).value+" ?";
 cgi_url = "/server/del_provider?token="+encodeURI(g_token)+"&provider_no="+provider_no+ "&flag="+Math.random();
 if (confirm(confirm_msg))
 {
 	
	
	 xmlHttp.open("GET", cgi_url, true);
	  xmlHttp.onreadystatechange = function() {
	  	if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response==1)
			{
				g_total_provider_no--;
				alert("Sucessfully");
			} else if (response==2)
			{
				alert("The previous channel is deleting.");		
			}else
			{
				alert("Failed to Delete Channel");
			}
			//alert(g_provider_position);
			//alert(g_provider_limit);
			callServer_Get_Stream_Provider(g_provider_position,g_provider_limit);
    		}
	  };
	 xmlHttp.send(null);
 }


}
function call_Refresh_Provider(provider_no)
{
	var cgi_url;
	
 g_token=find_cookie_value("token");
  cgi_url = "/server/refresh_provider?token="+encodeURI(g_token)+"&provider_no="+provider_no+ "&flag="+Math.random();
 	var icon_id="provider_refresh"+provider_no;
 	var date_id="provider_date"+provider_no;
 	var str='<i class="fa fa-refresh fa-spin fa-lg"></i>';
 	document.getElementById(icon_id).innerHTML=str;
	document.getElementById(icon_id).disabled=true;
	
 	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response.length>0)
			{			
				var str='<i class="fa fa-refresh fa-lg"></i>';
				 document.getElementById(icon_id).innerHTML=str;
			 	 document.getElementById(icon_id).disabled=false;
			 	 const myObj= JSON.parse(response);
			 	 document.getElementById(date_id).innerText=myObj.update_date;
	
			}else
			{
				alert("Failed to Refresh Channel");
			}
		}
	};
	xmlHttp.send(null);
	 

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


    var response = xmlHttp.responseText.split("\r\n");
	var provider_name;
	var provider_src;
	var provider_date;
	var provider_status;

    var i=0;
    var j=0;
    var box_no=1;
	var total_no=0;
	var new_total_no;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content;
    var ezcontent= document.getElementById("content")
  //var detail = parent.document.getElementById("detail");
  var dvr_folder_on=0;
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var more_keyword=null;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_provider_position;
	var total_count=g_total_provider_no;
	var cellsize="18%";
	
	
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="75%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Provider List</b></font>';
	str+='</td>';
	
	
	str += '<td>' +
       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
       '</select>' +
       '</td>';

	str+='<td>';
	str+='<div class="navbar" style="background-color: #F5F6F8">';
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<a href="javascript:open_import_url_modal()">Add Provider</a>';
		    
		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';

	
	document.getElementById("ezhead").innerHTML=str;
	//parent.document.getElementById("page_no").value=g_constant_limit;	
	
	ezcontent.innerHTML='</div><div id="ezmenucontent"></div>';
	
	content = parent.document.getElementById("ezmenucontent");
	

	content.innerHTML="";
//	detail.innerHTML="";
	
	g_search_channel_item.value=null;

	 HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
	  '<tr>'+
	      //'<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_provider_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      
	      '<td width="200" align="center"><font face="Arial" size="2">Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">URL</font></td>'+
	      '<td width="140" align="center"><font face="Arial" size="2">Last Changed</font></td>'+
	      '<td width="120" align="center"><font face="Arial" size="2">Enabled</font></td>'+
	      
 	 '</tr>'+'<tr><td  colspan="7"><hr size="1" color="#66FFFF"></td></tr>';
 	
	var provider_no=current_position;
	while (1)
	{
 	 	if (response[i]==0) break;
		//alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
     	    	provider_name=response[i].slice(5,strlength);
     	    	
     	    	i++;
     	 	strlength=response[i].length;
   	    	provider_src=response[i].slice(4,strlength);
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	provider_date=response[i].slice(11,strlength);
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	provider_status=parseInt(response[i].slice(10,strlength));
   	    	
   	    	i++;
   	    	
   	    	
   	    	total_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">';
		   //'<td width="20" align="center">';
		      //HTML_str+=' <input type="checkbox" name=checkbox'+provider_no;
	 	      
	 	      //HTML_str+=' id=checkbox'+provider_no+'></td>';

		      HTML_str+='<td width="30" align="right"><font face="Arial" size="2">'+provider_no+'</font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input  style="padding: 5px;height:30;" type="text" title="'+provider_name+'" name="provider_name"'+
	 		' id=provider_name'+provider_no+
	 		' size="20" value="'+
	 		decodeURI(provider_name)+'"/></font></td>'+
		       
			'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" title="'+provider_src+'" name="provider_src"'+
	 		' id=provider_src'+provider_no+
	 		' size="80" value="'+
	 		provider_src+'"/></font></td>';
		   
			HTML_str += '<td width="' + cellsize + '" align="center">' +
				    '<font id="provider_date' + provider_no + '" face="Arial" size="2">' + provider_date + '</font>' +
				    '</td>';

	 		
		      
	 		
			
			//alert(ch_status);		

			if (provider_status==1)
			{
				HTML_str+='<td width="'+cellsize+'" align=center><label class="switch"><input type="checkbox" checked id="provider_status'+provider_no+'"><span class="slider round"></span></label>'
			}else
			{
				HTML_str+='<td width="'+cellsize+'" align=center><label class="switch"><input type="checkbox"  id="provider_status'+provider_no+'"><span class="slider round"></span></label>'

			}
	      		
	 		HTML_str+='<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=callServer_Update_Provider("'+provider_no+'")><img src="/admin/save.png"></img></a></td>';
	 		//HTML_str+='<td align="right">'+
	 		//"<a href='javascript:void(0)'"+
			//' onclick=call_Refresh_Provider("'+provider_no+'")><img id="provider_refresh'+provider_no+'" src="/admin/refresh.png"></img></a></td>';
			
			HTML_str += '<td align="right">' +
			    '<button id="provider_refresh' + provider_no + '" class="dropbtn" onclick="call_Refresh_Provider(\'' + provider_no + '\')">' +
			        '<i class="fa fa-refresh fa-lg"></i>' +
			    '</button>' +
			    '</td>';

			
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=call_Del_Provider("'+provider_no+'")><img src="/admin/del.png"></img></a></td>';
	 		
			HTML_str+='</tr>';
		provider_no++;	
				
		 
     	}
     	

	//if (total_no>0)
	//{	
		new_total_no=Number(total_no)+1;
		menustr1='<table width=100%><tr>';
		
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalImportURL" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left id=more_channel_name><font face="Arial" size="6"><b>Add Provider</b></font></td><td colspan=2 align=right id=import_channel_dialog_message name=import_channel_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	
	

				// Provider Name
				
		 		
		 		menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Provider</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="providername"'+
		 		' id="providername"'+
		 		' size="16" value=""/></font></td>'+
				'<td  width=25% height="50">'+
				'<font face="Arial" size="2">Enabled</font>'+
				'</p>'+
				'</td>'+      
				'<td width=25%  height="50"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" checked id="provider_status"><span class="slider round"></span></label>'+
				'</td>'+
				'</tr>';
				
		 		
				
			
		 		// After CH
				 menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Channel after</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="importurlchno"'+
		 		' id="importurlchno"'+
		 		'value="'+g_total_ch_no+'"'+
		 		' size="16" value=""/></font></td>';
		 		
				// Server Selection
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Server</font></td>'+
				'<td width=25%><select  style="text-indent: 5;width:152;height:26;" size="1" id="import_url_option">';
				menustr1+='<option selected="selected" value="0">Main Server</option>';
				menustr1+='<option value="1">Source Server</option>';

				balancer_value=201;
				//alert(g_balancer.length);
				if (g_balancer.length>0)
				{
					for (i=0;i<g_balancer.length;i++)
					{
						item = g_balancer[i];
						//alert(item.name);
						menustr1+='<option value="'+balancer_value+'">'+item.name+'</option>'+
						balancer_value++;
					}
				}
				menustr1+='</select></font></td></tr>';
				
		 		// HTTP URL
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td colspan=3 height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  oninput="onstartinput()" style="text-indent: 5;height:26;color:#cccccc" type="text" name="importurl"'+
		 		' id="importurl"'+
		 		' size="69" placeholder="http://serverip:port/get.php&username=test&password=1234&output=mpegts"/></font></td></tr>';
		 		
		 			

				menustr1+='<tr><td width=50% colspan=2><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_import_channel_by_url() name="Save" /></td>'+
				'<td width=50%  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_import_url_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
		
		  menustr1+='</tr>'+
		      '</table>';
	
		if (total_no==0)
		{
			current_position=0;
			endposition=0;
		}else
		{
			endposition=current_position+total_no-1;
		}
		
		//total_count=total_no;
		//alert(total_count);
		menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
		menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' Providers</td>';
		position=1;
		limit=g_constant_limit;
		if (total_count>g_constant_limit)
		{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:callServer_Get_Stream_Provider('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	 
		content.innerHTML=menustr1+HTML_str+'</table>'+menustr2;
		
		g_add_channel_flag=0
		bQuery_Channel_Status=1;
		
		
	
 }
}
function Get_XMLTV_Info()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
	var xmltv_name;
	var xmltv_src;
	var xmltv_date;
	var xmltv_status;

    var i=0;
    var j=0;
    var box_no=1;
	var total_no=0;
	var new_total_no;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content;
    var ezcontent= document.getElementById("content")
  //var detail = parent.document.getElementById("detail");
  var dvr_folder_on=0;
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var more_keyword=null;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_xmltv_position;
	var total_count=g_total_xmltv_no;
	var cellsize="18%";
	
	
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="75%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>XMLTV List</b></font>';
	str+='</td>';
	
	
	str += '<td>' +
       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
       '</select>' +
       '</td>';

	str+='<td>';
	str+='<div class="navbar" style="background-color: #F5F6F8">';
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<a href="javascript:open_xmltv_modal()">Add XMLTV</a>';
		    str+='<button id=xmltv_refresh_btn class="dropbtn" onclick="Call_Server_Refresh_XMLTV()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';

	
	document.getElementById("ezhead").innerHTML=str;
	//parent.document.getElementById("page_no").value=g_constant_limit;	
	
	ezcontent.innerHTML='</div><div id="ezmenucontent"></div>';
	
	content = parent.document.getElementById("ezmenucontent");
	

	content.innerHTML="";
//	detail.innerHTML="";
	
	g_search_channel_item.value=null;

	 HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
	  '<tr>'+
	      //'<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_XMLTV_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      
	      '<td width="200" align="center"><font face="Arial" size="2">Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">URL</font></td>'+
	      '<td width="140" align="center"><font face="Arial" size="2">Update date</font></td>'+
	      '<td width="120" align="center"><font face="Arial" size="2">State</font></td>'+
	      
 	 '</tr>'+'<tr><td  colspan="7"><hr size="1" color="#66FFFF"></td></tr>';
 	
	var xmltv_no=current_position;
	while (1)
	{
 	 	if (response[i]==0) break;
		//alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
     	    	xmltv_name=response[i].slice(5,strlength);
     	    	
     	    	i++;
     	 	strlength=response[i].length;
   	    	xmltv_src=response[i].slice(4,strlength);
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	xmltv_date=response[i].slice(11,strlength);
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	xmltv_status=parseInt(response[i].slice(10,strlength));
   	    	
   	    	i++;
   	    	
   	    	
   	    	total_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">';
		   //'<td width="20" align="center">';
		      //HTML_str+=' <input type="checkbox" name=checkbox'+xmltv_no;
	 	      
	 	      //HTML_str+=' id=checkbox'+xmltv_no+'></td>';

		      HTML_str+='<td width="30" align="right"><font face="Arial" size="2">'+xmltv_no+'</font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input  style="padding: 5px;height:30;" type="text" title="'+xmltv_name+'" name="xmltv_name"'+
	 		' id=xmltv_name'+xmltv_no+
	 		' size="20" value="'+
	 		decodeURI(xmltv_name)+'"/></font></td>'+
		       
			'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" title="'+xmltv_src+'" name="xmltv_src"'+
	 		' id=xmltv_src'+xmltv_no+
	 		' size="80" value="'+
	 		xmltv_src+'"/></font></td>'+
		   
			'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+xmltv_date+'</font></td>';
	 		
		      
	 		
			
			//alert(ch_status);		

			if (xmltv_status==1)
			{
				HTML_str+='<td width="'+cellsize+'" align=center><label class="switch"><input type="checkbox" checked id="xmltv_status'+xmltv_no+'"><span class="slider round"></span></label>'
			}else
			{
				HTML_str+='<td width="'+cellsize+'" align=center><label class="switch"><input type="checkbox"  id="xmltv_status'+xmltv_no+'"><span class="slider round"></span></label>'

			}
	      		
	 		HTML_str+='<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=callServer_XMLTV_Update("'+xmltv_no+'")><img src="/admin/save.png"></img></a></td>';
			
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=call_Del_XMLTV("'+xmltv_no+'")><img src="/admin/del.png"></img></a></td>';
	 		
			HTML_str+='</tr>';
		xmltv_no++;	
				
		 
     	}
     	

	//if (total_no>0)
	//{	
		new_total_no=Number(total_no)+1;
		menustr1='<table width=100%><tr>';
		menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalAddXMLTV" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left><font face="Arial" size="6"><b>Add XMLTV</b></font></td><td colspan=2 align=right id=add_xmltv_dialog_message name=add_xmltv_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">Name</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="new_xmltv_name"'+
		 		' id="new_xmltv_name"'+
		 		' size="16" value=""/></font></td>'+
				'<td  width=25% height="50">'+
				'<font face="Arial" size="2">State</font>'+
				'</p>'+
				'</td>'+      
				'<td width=25%  height="50"><p align="left"> <label class="switch">'+
				'<label class="switch"><input type="checkbox" checked id="new_xmltv_status"><span class="slider round"></span></label>'+
				'</td>'+
				'</tr>';
				
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">URL</font></td>'+
				'<td width=75% colspan=3 height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  oninput="onstartxmltvinput()" style="text-indent: 5;height:26;color:#cccccc" type="text" name="new_xmltv_src"'+
		 		' id="new_xmltv_src"'+
		 		' size="61" placeholder="http://serverip:port/getxmltv?username=test&password=1234"/></font></td></tr>';
		 		
		 		
				menustr1+='<tr><td width=50% colspan=2><input id=add_new_xmltv_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=callServer_Add_XMLTV("'+new_total_no+'") name="Add" /></td>'+
				'<td width=50%  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_xmltv_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';

		
		  menustr1+='</tr>'+
		      '</table>';
	
		if (total_no==0)
		{
			current_position=0;
			endposition=0;
		}else
		{
			endposition=current_position+total_no-1;
		}
		
		//total_count=total_no;
		//alert(total_count);
		menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
		menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' XMLTV</td>';
		position=1;
		limit=g_constant_limit;
		if (total_count>g_constant_limit)
		{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_channels('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:callServer_Get_XMLTV_Info('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	 
		content.innerHTML=menustr1+HTML_str+'</table>'+menustr2;
		
		g_add_channel_flag=0
		bQuery_Channel_Status=1;
		
		
	
 }
}

function callServer_Get_XMLTV_Info(position,limit) {
	var content = parent.document.getElementById("content");
	
	var cgi_url;
	var ch_no=1;
	var from_month;
	var to_month;
	var d=new Date();
	var cur_year=d.getFullYear();
	var cur_month=d.getMonth()+1;
	
	bSystem_Inquery_Panel=0; 
 	bQuery_Channel_Status=0;	
 	bQuery_Online_Player=0;
 	bGet_Channel_Statistics=0;
 	g_start_search_option=6;
 
  	g_token=find_cookie_value("token");
   	g_ch_no=ch_no;
	if (g_token!=0)
	{
		g_ch_no=ch_no;
		from_month=cur_month;
		to_month=cur_month;
		g_cur_year=cur_year;
		//g_cur_month=cur_month;
		if (cur_month<10)
		{
			g_cur_month='0'+cur_month;
		}else
		{
			g_cur_month=cur_month;		
		}
		g_xmltv_position=position;
		g_xmltv_limit=limit;

		cgi_url = "/server/get_xmltv_info?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">EPG Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_XMLTV_Info;
		xmlHttp.send(null);
	}

}
function callServer_Get_Stream_Provider(position,limit) {
	var content = parent.document.getElementById("content");
	
	var cgi_url;
	
	bSystem_Inquery_Panel=0; 
 	bQuery_Channel_Status=0;	
 	bQuery_Online_Player=0;
 	bGet_Channel_Statistics=0;
  
  	g_token=find_cookie_value("token");
   	
	if (g_token!=0)
	{
		
		g_provider_position=position;
		g_provider_limit=limit;

		cgi_url = "/server/get_stream_provider?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">EPG Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_Stream_Provider;
		xmlHttp.send(null);
	}

}
function Refresh_EPG(){
 
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
     if (response==1)
    {
 	callServer_Get_EPG_Info();
    }else
    {
   	alert("Failed to Refresh EPG");
    }
 }
 
}
/* function callServer_Refresh_EPG_Info()
{
	var cgi_url;
	var confirm_msg;

	
      	g_token=find_cookie_value("token");

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

	confirm_msg="Refresh EPG Information?";
	//if (confirm(confirm_msg))
	//{
		bQuery_Channel_Status=0;
	 	 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Refresh_EPG;
		 xmlHttp.send(null);
	//}
	

 	
}  
*/
function callServer_Get_EPG_Info_By_Month() {
	var content = parent.document.getElementById("content");
	var ch_no= document.getElementById("cur_ch_no").value;
	var cur_year= document.getElementById("cur_year").value;
	var from_month= document.getElementById("cur_month").value;
	var to_month= document.getElementById("cur_month").value;
	var cgi_url;
	
	bSystem_Inquery_Panel=0; 
 	bQuery_Channel_Status=0;
 	bQuery_Online_Player=0;
 	bGet_Channel_Statistics=0;
  	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		g_cur_year=parseInt(cur_year);
		g_cur_month=from_month;
		g_ch_no=ch_no;
		cgi_url = "/server/get_epg_info?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&from_year=" + encodeURI(cur_year)+ "&from_month=" + encodeURI(from_month)+ "&to_month=" + encodeURI(to_month)+"&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">EPG Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_EPG_Info;
		xmlHttp.send(null);
	}

}

function Update_EPG_Info() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    	//callServer_Get_EPG_Current_Info();
     } else
    {
   	alert("Failed to Update EPG.");
    }
	g_item.value=g_temp;
	g_item.style.backgroundColor = "#ffffff";
    }
}

function callServer_Update_EPG_Info(program_no) {
	
	var ch_no= document.getElementById("cur_ch_no").value;
	//var content = parent.document.getElementById("content");
	var starttime_id="starttime"+program_no;
	var starttime;
	var stoptime_id="stoptime"+program_no;
	var stoptime;
	var program_title_id="program_title"+program_no;
	var program_title;
	var program_descrption_id="program_descrption"+program_no;
	var program_descrption;
	var program_icon_id="program_icon"+program_no;
	var program_icon;
	var program_rec_id="program_rec"+program_no;
	var program_rec;

	var confirm_msg;
 	var cgi_url;

	g_item=document.getElementById(starttime_id);
	starttime = g_item.value;
	if (starttime.length==0)
	{
		alert("Start Time is empty");
		return;
	}else if ((starttime.length!=19) && (starttime.length!=5))
	{
		alert("Start Time Format error")
		return;
	}
	g_item=document.getElementById(stoptime_id);
	stoptime = g_item.value;
	if (stoptime.length==0)
	{
		alert("Stop Time is empty");
		return;
	}else if ((stoptime.length!=19)&&(stoptime.length!=5))
	{
		alert("Stop Time Format error")
		return;
	}
	g_item=document.getElementById(program_descrption_id);
	program_descrption = g_item.value;

	g_item=document.getElementById(program_icon_id);
	program_icon = g_item.value;

	g_item=document.getElementById(program_rec_id);
	program_rec = g_item.value;
		
	g_item=document.getElementById(program_title_id);
	program_title = g_item.value;
	if (program_title.length==0)
	{
		alert("Program Title is empty");
		return;
	}
	
	bSystem_Inquery_Panel=0; 
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/update_epg_info?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&program_no=" + encodeURI(program_no)+"&starttime=" + encodeURI(starttime)+ "&stoptime=" + encodeURI(stoptime)
 + "&program_title=" + encodeURI(program_title)+ "&program_descrption=" + encodeURI(program_descrption)+ "&program_icon=" + encodeURI(program_icon)+ "&program_rec=" + encodeURI(program_rec)+"&flag="+Math.random();
		
		//content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">EPG Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Update_EPG_Info;
		xmlHttp.send(null);
		 g_temp=g_item.value;
		 g_item.value=g_item.value+" (updating...)";
		 g_item.style.backgroundColor = "#ff0000";
	}

}
function After_Del_EPG(del_program_no){
	
	var content = parent.document.getElementById("content");
	g_content=content.innerHTML;
	var program_active_no=g_total_program_no;
	var i, m;
	var starttime_id;
	var starttime;
	var stoptime_id;
	var stoptime;
	var program_title_id;
	var program_title;
	var program_descrption_id;
	var program_descrption;
	var program_icon_id;
	var program_icon;
	var program_rec_id;
	var program_rec;
	var HTML_Menu_Bar_Str="";
	var cur_month;
	var cur_temp_year;
	var program_no=0;


	program_active_no--;
	
	cur_month=g_cur_month;
	
 
	HTML_Menu_Bar_Str='<td width="10%" align="right"><font face="Arial" size="2">Channel No.:</font></td>';
	HTML_Menu_Bar_Str+='<td width="5%" align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_ch_no" id=cur_ch_no>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+g_ch_no+'">'+g_ch_no+'</option>';
	for (i=1;i<=g_total_ch_no;i++)
	{
		if (i!=g_ch_no)
		{
			HTML_Menu_Bar_Str+='<option value="'+i+'">'+i+'</option>';
		}
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

	HTML_Menu_Bar_Str+='<td width="5%" align="center">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_year" id=cur_year>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+g_cur_year+'">'+g_cur_year+'</option>';
	cur_temp_year=g_cur_year-1;
	for (i=0;i<5;i++)
	{
		index_year=cur_temp_year+i;
		if (g_cur_year!=index_year)
		{
			HTML_Menu_Bar_Str+='<option value="'+index_year+'">'+index_year+'</option>';
		}
		
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

 	HTML_Menu_Bar_Str+='<td width="5%" align="right">'+
	' <font face="Arial"> <font size="2">'+
	' <select size="1" name="cur_month" id=cur_month>';
	HTML_Menu_Bar_Str+='<option selected="selected" value="'+cur_month+'">'+cur_month+'</option>';
	
	for (i=1;i<13;i++)
	{
		if (i!=cur_month)
		{
			if (i<10)
			{
				HTML_Menu_Bar_Str+='<option value="0'+i+'">0'+i+'</option>';
				
			}else
			{
				HTML_Menu_Bar_Str+='<option value="'+i+'">'+i+'</option>';
			}
		}
		
	}
	HTML_Menu_Bar_Str+='</select></font></td>';

     HTML_Menu_Bar_Str+='<td width=38% align="left">';
     HTML_Menu_Bar_Str+='<Input type="button" value="Query" onclick="javascript:callServer_Get_EPG_Info_By_Month();" />';
     HTML_Menu_Bar_Str+='</td>';
      HTML_str=  '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="60" align="left"><p style="margin-left: 5"><font face="Arial" size="2">No.</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Start Time<br>YYYY/MM/DD<br>hh:mm:ss</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Stop Time<br>YYYY/MM/DD<br>hh:mm:ss</font></td>'+
	      '<td width="10" align="center"></td>'+
	      '<td width="260" align="center"><font face="Arial" size="2">Program Title</font></td>'+
	      '<td width="400" align="center"><font face="Arial" size="2">Program Description</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Record Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Record</font></td>'+
 	 '</tr>'+'<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
	 for (i=1,m=1;i<=program_active_no;i++,m++)
	{
		if (m==del_program_no)
		{
			m++;
		}
		starttime_id="starttime"+m; 
		//alert(starttime_id);
		item_name=document.getElementById(starttime_id);
		// alert(item_name.value);
		starttime = item_name.value;
		
		stoptime_id="stoptime"+m; 
		item_name=document.getElementById(stoptime_id);
		// alert(item_name.value);
		stoptime = item_name.value;
		
		program_title_id="program_title"+m; 
		item_name=document.getElementById(program_title_id);
		// alert(item_name.value);
		program_title = item_name.value;
		
		program_descrption_id="program_descrption"+m; 
		item_name=document.getElementById(program_descrption_id);
		// alert(item_name.value);
		program_descrption = item_name.value;

		program_icon_id="program_icon"+m; 
		item_name=document.getElementById(program_icon_id);
		// alert(item_name.value);
		program_icon = item_name.value;

		program_rec_id="program_rec"+m; 
		item_name=document.getElementById(program_rec_id);
		// alert(item_name.value);
		program_rec = item_name.value;
		program_no++;
		HTML_str=HTML_str+
		   '<tr>'+
		      '<td width="60" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="starttime"'+
	 		' id=starttime'+i+
	 		' size="15" value="'+
	 		starttime+'"/></font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="stoptime"'+
	 		' id=stoptime'+i+
	 		' size="15" value="'+
	 		stoptime+'"/></font></td>'+
	 		'<td  style="cursor: pointer;" width="10">'+
			'<div class="dropdown">'+
				'<button class="dropbtn">'+
  				'<div class="bar1"></div>'+
  				'<div class="bar2"></div>'+
  				'<div class="bar3"></div>'+
				'</button>'+
  				'<div class="dropdown-content">'+
     					"<a href='javascript:void(0)'"+
					' onclick=callServer_Update_EPG_Info("'+program_no+'")>'+'<table><tr><td width=10%><img src="/admin/save.png"></td><td><font face="Arial" size="3"><b>Save</b></font></td></tr></table></a>'+
					"<a href='javascript:void(0)'"+
					' onclick=call_Del_EPG_Info("'+program_no+'")>'+'<table><tr><td width=10%><img src="/admin/del.png"></td><td><font face="Arial" size="3"><b>Delete</b></font></td></tr></table></a>'+
    					'</div>'+
			'</div>'+
	 		'</td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="program_title"'+
	 		' id=program_title'+i+
	 		' size="20" value="'+
	 		program_title+'"/></font></td>'+
		      '<td width="40" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="program_descrption"'+
	 		' id=program_descrption'+i+
	 		' size="40" value="'+
	 		program_descrption+'"/></font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="program_icon"'+
	 		' id=program_icon'+i+
	 		' size="20" value="'+
	 		program_icon+'"/></font></td>';
	 		
	 		HTML_str=HTML_str+
	 		'<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <select size="1" name="program_rec" '+'id=program_rec'+i+'>';
	 		if (program_rec=="ON")
	 		{
		      
		 		HTML_str=HTML_str+'<option selected="selected" value="'+"ON"+'">'+"ON"+'</option>'+
		 		'<option value="'+"OFF"+'">'+"OFF"+'</option>'+'</select></font></td>';
	 		}else
 			{
		 		HTML_str=HTML_str+'<option selected="selected" value="'+"OFF"+'">'+"OFF"+'</option>'+
		 		'<option value="'+"ON"+'">'+"ON"+'</option>'+'</select></font></td>';
 			}	 		
			
			HTML_str+='</tr>';
		
	}
	
	content.innerHTML='<table width=100%><tr><td width=30%>'+
  	'<p style="margin-left: 5; margin-top: 10"><Input type="button" value="Add" onclick="javascript:call_add_epg();" />'+
 	'&nbsp<Input type="button" value="Refresh" onclick="javascript:callServer_Refresh_EPG_Info();" />'+
	'</td>'+
  	HTML_Menu_Bar_Str+
  	'<td width=7%>'+
  	'<p style="margin-right: 5; margin-top: 10"><font size="2" face="Arial">Total: '+ program_no+
  	'</td>'+
 	'</tr></table>'+HTML_str+'</table>';
	g_total_program_no=program_active_no;
}

function close_epg_modal() {
   var modal = document.getElementById('PanelModal');
   modal.style.display = "none";
   callServer_Get_EPG_Info();
}
function Del_EPG_Info() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    	callServer_Get_EPG_Info();
   //   	alert("Del EPG Sucessfully");
   //	After_Del_EPG(g_program_no);
    } else
    {
   	alert("Failed to Del EPG.");
    }
 }
}
function call_Del_EPG_Info(program_no) {
	var confirm_msg;
 	var cgi_url;
	var ch_no= document.getElementById("cur_ch_no").value;
	var starttime_id="starttime"+program_no;
	var starttime;
	
	g_item=document.getElementById(starttime_id);
	starttime = g_item.value;
	if (starttime.length==0)
	{
		alert("Start Time is empty");
		return;
	}
	g_program_no=program_no;
		
	bSystem_Inquery_Panel=0; 
 	bQuery_Channel_Status=0;
 	bQuery_Online_Player=0;
 	bGet_Channel_Statistics=0;
  	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/del_epg_info?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&program_no=" + encodeURI(program_no)+"&starttime=" + encodeURI(starttime)+"&flag="+Math.random();
				
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Del_EPG_Info;
		xmlHttp.send(null);
	}

}
function Query_A_Movie_More()
{
  var str;
 
 var movie_no;
 var movie_name;
 var movie_description;
   var MovieDetailWindow;
   var rentpoint;
   var buypoint;
   var ratingflag;
   var quality;
   var rentperiod; 	
   var forwardflag;
	var prev_movie_no;
	var next_movie_no;
	var total_movie_no;
	var nObj;


  
}

function call_Query_A_Movie_More(movie_no)
{
  var confirm_msg;
  var cgi_url;
 var movie_no;
 var movie_name;
 var movie_description;
   var ratingflag;
   var quality;
   var rentperiod; 	
   var forwardflag;
   var g_movie_no;
	var rentpoint;
	var buypoint;

   	g_token=find_cookie_value("token");
	//movie_no=g_movie_no;
	 cgi_url = "/server/get_movie_more?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&flag="+Math.random();
	// 
	document.getElementById("save_movie_dialog_message").innerHTML='';
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText.split("\r\n");
			var strlength;
			var i;
	 		i=0;
	  		//alert(response[i]);
	
		 	strlength=response[i].length;
	   	    	movie_no=response[i].slice(8,strlength);
	

			i++;
	  		//alert(response[i]);
		 	strlength=response[i].length;
	   	    	movie_name=unescape(response[i].slice(5,strlength));
	   	 	//alert(movie_name);
	   	 	document.getElementById("more_movie_name").innerHTML='<font face="Arial" size="6"><b>'+movie_name+'</font>';
	   	    	
	 		
			i++;
	  		//alert(response[i]);
		 	strlength=response[i].length;
	   	    	movie_description=response[i].slice(12,strlength);
	   	    	document.getElementById("more_movie_description").value=movie_description;
	 	 	
			i++;
	  		//alert(response[i]);
		 	strlength=response[i].length;
		 	rentpoint=response[i].slice(10,strlength);
	   	    	document.getElementById("more_rentpoint").value=rentpoint;
	   	    	
	  	    	i++;
	  		//alert(response[i]);
	    	 	strlength=response[i].length;
	    	 	buypoint=response[i].slice(9,strlength);
	   	    	document.getElementById("more_buypoint").value=buypoint;
	
	   	    	i++;
	   		//alert(response[i]);
	   	 	strlength=response[i].length;
	   	    	ratingflag=response[i].slice(11,strlength);
	      	    	document.getElementById("more_ratingflag").value=ratingflag;
		    	
	   	    	i++;
	  		//alert(response[i]);
	    	 	strlength=response[i].length;
	   	    	quality=response[i].slice(8,strlength);
	   	    	document.getElementById("more_quality").value=quality;
	
	   	    	i++;
	  		//alert(response[i]);
		 	strlength=response[i].length;
	   	    	rentperiod=response[i].slice(11,strlength);
	    	    	document.getElementById("more_rentperiod").value=rentperiod;
	   	    	
	   	    	i++;
	  		//alert(response[i]);
		 	strlength=response[i].length;
	   	    	genre=response[i].slice(6,strlength);
	   	    	if (genre.length>0)
	   	    	{
		   	    	genre_items=genre.split(",");
		   	    	for (m=0;m<genre_items.length;m++)
		   	    	{
		   	    		var listItem = createMovieListItem(genre_items[m]);
					document.getElementById('selectedItemsList').appendChild(listItem);
				}
			}
	 	    	
	  	    	i++;
	  		//alert(response[i]);
		 	strlength=response[i].length;
	   	    	forwardflag=response[i].slice(8,strlength);
	    	    	document.getElementById("more_forwardflag").value=forwardflag;
		  }
	 };
	 xmlHttp.send(null);

}
function Save_Movie_More() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    	alert("Save Movie More Sucessfully");
    } else if (response==0)
    {
   	alert("Failed to Save Movie More");
    }
  }
}

function callServer_Save_Movie_More()
{

 
   var movie_description_id="more_movie_description";
   var ratingflag_id="more_ratingflag";
   var quality_id="more_quality";
   var rentperiod_id="more_rentperiod";
   var forwardflag_id="more_forwardflag";;
var movie_no=g_movie_no;

   var movie_description;
   var rentpoint;
   var buypoint;
   var ratingflag;
   var quality;
   var rentperiod;
   var forwardflag;
 	
	var rentpoint_id="more_rentpoint";
	var buypoint_id="more_buypoint";
	var rentpoint;
	var buypoint;

 
 

var confirm_msg;
 	var cgi_url;

	g_item=document.getElementById(rentpoint_id);
	rentpoint=g_item.value;
	g_item=document.getElementById(buypoint_id);
	buypoint=g_item.value;

	g_item=document.getElementById(movie_description_id);
	movie_description=g_item.value;
	g_item=document.getElementById(ratingflag_id);
	//alert(g_item.value);
	ratingflag=g_item.value;
	g_item=document.getElementById(quality_id);
	//alert(g_item.value);
	quality=g_item.value;
	g_item=document.getElementById(rentperiod_id);
	//alert(g_item.value);
	rentperiod=g_item.value;
	g_item=document.getElementById(forwardflag_id);
	// alert(g_item.value);
	forwardflag=g_item.value;

  	g_token=find_cookie_value("token");

 cgi_url = "/server/save_movie_more?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+
	"&rentpoint="+rentpoint+
	"&buypoint="+buypoint+
  "&description="+encodeURI(movie_description)+
  "&ratingflag="+ratingflag+
  "&quality="+quality+
  "&rentperiod="+rentperiod+
    "&genre="+genre_items+
    "&forward="+forwardflag;

  
 //alert(cgi_url);

 	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
	 		call_get_movies(g_movie_position,g_movie_limit);
	 		/*
		    var response = xmlHttp.responseText;
		    var save_movie_dialog_message=document.getElementById("save_movie_dialog_message");
		    if (response==1)
		    {
	 		var updated_date=new Date();
			
			save_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial"><b>'+String(updated_date.getHours()).padStart(2, "0")+":"+String(updated_date.getMinutes()).padStart(2, "0")+":"+String(updated_date.getSeconds()).padStart(2, "0")+' Updated</b></font>';
		    } else if (response==0)
		    {
			save_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial"><b>'+String(updated_date.getHours()).padStart(2, "0")+":"+String(updated_date.getMinutes()).padStart(2, "0")+":"+String(updated_date.getSeconds()).padStart(2, "0")+' Failed</b></font>';
		    }
		    */
		  }

	 }
	 xmlHttp.send(null);




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


    var response = xmlHttp.responseText.split("\r\n");
	var movie_no;
	var movie_name;
	var movie_src;
	var icon_path;
	var movie_category;
	var duration;
	var bitrate;
	var movie_status;
    var movie_play_id;
    var movie_title="<p>"+"Movie List"+"</p>";
    var move_list;
    var i=0;
    var j=0;
    var total_movie_no=0;
	var movie_active_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content = parent.document.getElementById("content");
  //var detail = parent.document.getElementById("detail");
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var nduration =0;


	content.innerHTML="";
//	detail.innerHTML="";
	
	g_search_movie_item.value=null;

	 HTML_str= '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="20" align="center"><input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_movie_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Movie Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Duration(min.)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
	      '<td width="80" align="center"><font face="Arial" size="2">Status</font></td>'+
 	 '</tr>'+'<tr><td  colspan="8"><hr size="1" color="#66FFFF"></td></tr>';
 
	while (1)
	{
 		//alert(response[i]);
	 	if (response[i]==0) break;
	 	strlength=response[i].length;
   	    	movie_no=response[i].slice(8,strlength);
   	    	
     	 	strlength=response[i+1].length;
     	 	movie_name=response[i+1].slice(5,strlength);
   	    	
     	 	strlength=response[i+2].length;
   	    	movie_src=response[i+2].slice(4,strlength);
   	    	
    	 	strlength=response[i+3].length;
   	    	icon_path=response[i+3].slice(4,strlength);
   	    	
     	 	strlength=response[i+4].length;
 	    	movie_category=response[i+4].slice(9,strlength);

   	    	
 	    	
     	 	strlength=response[i+5].length;
 	    	duration=response[i+5].slice(9,strlength);
 	    	nduration=parseFloat(duration);
 	    	nduration = nduration /60;
 	    	nduration =nduration.toFixed(3);

 	    	
     	 	strlength=response[i+6].length;
 	    	bitrate=response[i+6].slice(8,strlength);
 	    	
       	 	strlength=response[i+7].length;
 	    	movie_status=response[i+7].slice(7,strlength);
   	    		
   	    	

 		i=i+8;
		movie_active_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		   '<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+movie_no+
	 		' id=checkbox'+movie_no+'></td>'+
		      '<td width="20" align="center"><font face="Arial" size="2">'+movie_no+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="moviename"'+
	 		' id=moviename'+movie_no+
	 		' size="20" value="'+
	 		decodeURI(movie_name)+'"/></font></td>'+
		      '<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" title="'+movie_src+'" name="moviesrc"'+
	 		' id=moviesrc'+movie_no+
	 		' size="35" value="'+
	 		movie_src+'"/></font></td>'+		      
	 		'<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" title="'+icon_path+'" name="iconpath"'+
	 		' id=iconpath'+movie_no+
	 		' size="35" value="'+
	 		icon_path+'"/></font></td>'+
		      '<td width="10" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="moviecategory"'+
	 		' id=moviecategory'+movie_no+
	 		' size="15" value="'+
	 		decodeURI(movie_category)+'"/></font></td>'+
	 		'<td id=movieduration'+movie_no+' width="100" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		nduration+'</font></td>'+
		      '<td id=moviebitrate'+movie_no+' width="100" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		bitrate+'</font></td>';

	 		

			
			//alert(ch_status);		
			if (movie_status.search("1")>=0)
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="100" align="center"><font face="Arial" size="2">'+"ON"+'</font></td>';
			} else if (movie_status.search("0")>=0)
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
			} else if (movie_status.search("2")>=0)
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>RM</b>"+'</font></td>';
			}

			save_keyword="Save";
			refresh_keyword="Refresh";
			add_keyword="Add";
			del_keyword="Del";
			play_keyword="Play";
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_Movie("'+movie_no+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Copy_10_Movies("'+movie_no+'")>'+
			' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_Movie_Update("'+movie_no+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Movie("'+movie_no+'")>'+
			' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
			
			 HTML_str+='<td id=refreshmoviebutton'+movie_no+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Refresh_A_Movie("'+movie_no+'")>'+
			' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
			
			 HTML_str+='<td id=refreshmoviebutton'+movie_no+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_A_Movie_More("'+movie_no+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
			
			
			HTML_str+='<td align="left" id=movie_play_id'+movie_no+'>';
			HTML_str+="<a href='javascript:void(0)'"+
			' onclick=play_movie("'+movie_no+'")>'+
				' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';

			
							
			HTML_str+='</tr>';				
		   // alert(HTML_str);
		total_movie_no++;
     }
    //    content.innerHTML=HTML_str;
      // alert(menu_main.innerHTML);
  //    alert(HTML_str);
  	i=1;
	  if (total_movie_no==0)
	  {
		movie_src="";
		movie_name="";
		icon_path="";
		movie_category="";
		
	      HTML_str=HTML_str+'<tr>'+
	   '<td width="20" align="center">'+
 		' <input type="checkbox" name=checkbox'+i+
 		' id=checkbox'+movie_no+'></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="moviename"'+
		' id=moviename'+i+
		' size="20"/'+
		'</font></td>'+
	      '<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="moviesrc"'+
		' id=moviesrc'+i+
		' size="35"/'+
		'</font></td>'+
		'<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="iconpath"'+
		' id=iconpath'+i+
		' size="35"/'+
		'</font></td>'+
	      '<td width="10" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="moviecategory"'+
		' id=moviecategory'+i+
		' size="10"/'+
		'</font></td>';
		
	     
	
		HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+'0.0'+'</font></td>';
		HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+'0.0'+'</font></td>';
		HTML_str+='<td id=moviestatus'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
	      	HTML_str+='<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Movie("'+i+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	      
		      '<td id=copy_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+

		      '<td id=save_id_button align="center">'+		      
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Movie()>'+
	      	      ' <img border="0" id="delbutton" alt="Canel" title="Cancel" src="del_icon.PNG"></a></td>'+
	
		      '<td id=del_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      '<td id=refresh_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      '<td id=more_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      '<td id=play_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>';
			        	
  		}

      
      	      HTML_Menu_Bar_Str='<td id=movie_menu_bar>';

	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_movie()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_movie()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_movie()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	      }

	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_movie()>"+
	      '<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';

	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_movie()>"+
	      '<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
 
 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_Movie_Inquery()>"+
	      '<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_Movie_Inquery()>"+
	      '<font size="2" face="Arial">Query</font></a>'+'&nbsp&nbsp&nbsp';
	      
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_movie()>"+
		      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
	     // HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_movie_definition()>"+
	     // '<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';

 
		      
	      HTML_Menu_Bar_Str+='</td>';

  	content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Movie Total: '+ movie_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td><font face="Arial" size="2"> <input name="movie_search_field" id="movie_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_movie_name();" name="search_movie_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(2);" name="goto_movie_no" /></font>'+	   
	   '</td></tr>'+
	'</table>'+HTML_str+'</table>';
	g_total_movie_no=movie_active_no;
 
 }

 
}
function callServer_Movie_Inquery() {
  var content = parent.document.getElementById("content");

  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
	bSystem_Inquery_Panel=0; 
  	bQuery_Channel_Status=0;
  	bQuery_Online_Player=0;
  	bGet_Channel_Statistics=0;
 	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/query_movie_list?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Movie Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Movie_inquery;
		xmlHttp.send(null);
	}

}
/*
function call_get_movies(position,limit) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
   	g_token=find_cookie_value("token");
	g_movie_position=position;
	g_movie_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		cgi_url = "/server/get_movies?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&flag="+Math.random();

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

}
*/
/*
function call_get_series(position,limit) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
   	g_token=find_cookie_value("token");
	g_series_position=position;
	g_series_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		cgi_url = "/server/get_series?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&flag="+Math.random();

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

}
*/
function call_get_series_post() 
{
  	var cgi_url;
  	var i=0;
  	var folder_name;
  	var strlength;
   	if (xmlHttp.readyState == 4) {
   	var response = xmlHttp.responseText.split("\r\n");
  	g_total_series_category_no=0;
   		for (i=0;;i++)
	  	{
		    if (response[i]==0)
	  	    {
	  	    	break;
	 	    } else
	  	    {
	  	    	strlength=response[i].length;
		  	folder_name=response[i].substring(9);
	 	    	g_Series_Categories_tems[g_total_series_category_no]=folder_name; 
	 	    	i++;
	 	    	g_Series_Categories_icons[g_total_series_category_no]=response[i].substring(4);
	 	    	//alert(g_Movie_Categories_tems[g_total_series_category_no]);
	 	    	g_total_series_category_no++;
	 	    	i++;
	    	   } 
	      	}
	 	g_token=find_cookie_value("token");
  		if (g_token!=0)
		{
			cgi_url = "/server/get_series?token="+encodeURI(g_token)+"&position="+g_series_position+"&limit="+g_series_limit+"&flag="+Math.random();
	
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = get_series;
			xmlHttp.send(null);
		}
	}

}
function call_get_series(position,limit) 
{
  	var cgi_url;
	var cookieStr;
 
   	g_token=find_cookie_value("token");
	g_series_position=position;
	g_series_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		cgi_url = "/server/get_series_category?token="+encodeURI(g_token)+"&icon=1"+"&serverid=1"+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = call_get_series_post;
		xmlHttp.send(null);
	}

}
function sort_movie_ascending()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    //alert(response);
    if (response==0)
    {
     	alert("Sort Failed");
  	if (g_movie_name_order_flag==1)
    	{
    		g_movie_name_order_flag=0;
    		content = document.getElementById("movie_name_id");
    		content.innerHTML='<font face="Arial" size="2">Movie Name</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
  	}else if (g_movie_category_order_flag==1)
    	{
    		g_movie_category_order_flag=0;
    		content = document.getElementById("category_id");
 	      	content.innerHTML='<font face="Arial" size="2">Category</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
    	}
    }else if (response>0)
    {
    	g_movie_position=1;
   	g_movie_limit=g_constant_limit;
	call_get_movies(g_movie_position,g_movie_limit);
    }
    	
  }
}
function callezserver_sort_movie_ascending(sortkey)
{
	var cgi_url;
	var content;
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
   	if (sortkey=="name")
	{
		content = document.getElementById("movie_name_id");
		g_movie_name_order_flag=1;
		g_movie_category_order_flag=0;
	}else if (sortkey=="category")
	{
		content = document.getElementById("category_id");
		g_movie_name_order_flag=0;
		g_movie_category_order_flag=1;
	}	
	content.innerHTML='<div class="loader"></div>';
	g_token=find_cookie_value("token");
	cgi_url = "/server/sort_movie_ascending?token="+encodeURI(g_token)+"&sortkey="+sortkey+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = sort_movie_ascending;
	xmlHttp.send(null);	
}
function sort_movie_descending()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var content;
   //alert(response);
    if (response==0)
    {
   	alert("Sort Failed");
 	if (g_movie_name_order_flag==2)
    	{
    		g_movie_name_order_flag=0;
    		content = document.getElementById("movie_name_id");
  		content.innerHTML='<font face="Arial" size="2">Movie Name</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';

    	}else if (g_movie_category_order_flag==2)
    	{
    		g_movie_category_order_flag=0;
    		content = document.getElementById("category_id");
	      	content.innerHTML='<font face="Arial" size="2">Category</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
    	}
     }else if (response>0)
    {
   	g_movie_position=1;
   	g_movie_limit=g_constant_limit;
	call_get_movies(g_movie_position,g_movie_limit);
    }
    	
  }
}
function callezserver_sort_movie_descending(sortkey)
{
	var cgi_url;
	var content;
	
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (sortkey=="name")
	{
		content = document.getElementById("movie_name_id");
		g_movie_name_order_flag=2;
		g_movie_category_order_flag=0;
	}else if (sortkey=="category")
	{
		content = document.getElementById("category_id");
		g_movie_name_order_flag=0;
		g_movie_category_order_flag=2;
	}
	content.innerHTML='<div class="loader"></div>';
	g_token=find_cookie_value("token");
	cgi_url = "/server/sort_movie_descending?token="+encodeURI(g_token)+"&sortkey="+sortkey+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = sort_movie_descending;
	xmlHttp.send(null);	
}	
function Show_Movie_Category()
{
	var movie_category_id= document.getElementById('movie_category');
	var movie_category_no_id= document.getElementById('total_no');
	
	var str;
	var categoryname;
	var categoryicon;
 	
 	if (xmlHttp.readyState == 4) {
 		var response = xmlHttp.responseText.split("\r\n");
 		var i=0;
		var modal = document.getElementById('PanelModalMovieCategory');
		g_total_movie_category_no=0;
		modal.style.display = "block";
		/*
		str='<font face="Arial" size="2">'+' <select size="10"   style="width: 500;padding:5;" name="movie_category_list" id=movie_category_list>';
 		while (1)
		{
 			if (response[i]==0) break;
 			categoryname=response[i].substring(9);
 			g_Movie_Categories_tems[i]=categoryname; 
	 	    	g_total_movie_category_no++;
 			//alert(categoryname);
 			if (i==0)
 			{
	 			str+='<option  style="padding: 2px" selected="selected" value="'+decodeURI(categoryname)+'">'+decodeURI(categoryname)+'</option>';
 			}else
 			{
	 			str+='<option  style="padding: 2px" value="'+decodeURI(categoryname)+'">'+decodeURI(categoryname)+'</option>';
	 		}
	 		i++;
	 	}
 		str+='</select></font>';
 		movie_category_id.innerHTML=str;
 		movie_category_no_id.innerHTML='<font face="Arial" size="2">'+i+'</font>';
 		document.getElementById('Add').focus();
 		*/
 		
		str='<div class="scroll-container"><font face="Arial" size="2">'+' <ul id="category_list" class="draggable-list"  style="list-style-type: none;width: 500;padding:5;" name="movie_category_list" id=movie_category_list>';
		//alert(g_categoryclickedItemValue);
		if (g_categoryclickedItemValue)
		{
			while (1)
			{
	 			if (response[i]==0) break;
	 			categoryname=response[i].substring(9);
	 			g_Movie_Categories_tems[g_total_movie_category_no]=categoryname;
	 			i++;
	 			categoryicon=response[i].substring(5);
			 	g_Movie_Categories_icons[g_total_movie_category_no]=categoryicon;
	 			g_total_movie_category_no++; 
		 	    	//alert(categoryname);
	 			if (g_categoryclickedItemValue==categoryname)
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: #aaa;padding: 5px;border: 1px solid #000;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" selected="selected" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
	 			}else
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: white;padding: 5px;border: 1px solid #ccc;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 		}
		 		i++;
		 		i++;
		 	}
		}else
		{
			while (1)
			{
	 			if (response[i]==0) break;
	 			categoryname=response[i].substring(9);
	 			g_Movie_Categories_tems[g_total_movie_category_no]=categoryname;
	 			i++;
	 			categoryicon=response[i].substring(5);
			 	g_Movie_Categories_icons[g_total_movie_category_no]=categoryicon;
			 	
	 			g_total_movie_category_no++; 
		 	    	//alert(categoryname);
	 			if (i==0)
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: #aaa;padding: 5px;border: 1px solid #000;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" selected="selected" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 			g_categoryclickedItemValue=categoryname;
	 			}else
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: white;padding: 5px;border: 1px solid #ccc;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 		}
		 		i++;
		 		i++;
		 	}
		 }
	 	str+='</ul></font></div>';
 		movie_category_id.innerHTML=str;
 		movie_category_no_id.innerHTML='<font face="Arial" size="2">'+g_total_movie_category_no+'</font>';
 		document.getElementById('Add').focus();
 		sortable_list = document.getElementById("category_list");
		sortable_listItems = sortable_list.querySelectorAll("li");
		let draggedItem = null;
		
		
		sortable_list.addEventListener("dragstart", (event) => {
		  draggedItem = event.target;
		  draggedItem.classList.add("dragging");
		  event.dataTransfer.effectAllowed = "move";
		  event.dataTransfer.setData("text/html", draggedItem.innerHTML);
		});
		
		sortable_list.addEventListener("dragover", (event) => {
		  event.preventDefault();
		  const afterElement = getDragAfterElement(sortable_list, event.clientY);
		
		  if (afterElement == null) {
		    sortable_list.appendChild(draggedItem);
		  } else {
		    sortable_list.insertBefore(draggedItem, afterElement);
		  }
		});
		
		sortable_list.addEventListener("dragend", () => {
		  draggedItem.classList.remove("dragging");
		  updateItemIndexes();
		});
		// Add click event listeners to each item
		sortable_listItems.forEach((item) => {
		  item.addEventListener("click", (event) => {
		    sortable_listItems.forEach((item) => {
		    item.style.backgroundColor = "#fff";
		      item.classList.remove("clicked");
		    });
		    
		    event.currentTarget.classList.add("clicked");
		
		    // Show the clicked item's value
		    //const clickedItemValue = event.currentTarget.innerText;
		    //alert(`Clicked Item Value: ${clickedItemValue}`);
		    g_categoryclickedItemValue = event.currentTarget.innerText;
		    event.currentTarget.style.backgroundColor = "#aaa";
		  });
		});

 	}
 	
 	

}
function open_movie_category_modal()
{
 	var cgi_url;
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/get_movie_category?token="+encodeURI(g_token)+"&icon=1"+"&serverid=1"+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Show_Movie_Category;
	xmlHttp.send(null);
}
function close_movie_category_modal() {
   var modal = document.getElementById('PanelModalMovieCategory');
   g_categoryclickedItemValue=null;
   modal.style.display = "none";
}
function call_add_movie_genre()
{
	var select = document.getElementById('genre_itemSelect');
	var selectedOption = select.options[select.selectedIndex];
	var text = MoviegenreObject[selectedOption.value];
	if (text !== '') {
		if (itemExists(selectedOption.value)) 
		{
			alert('Item already exists!');
		} else 
		{
			var listItem = createMovieListItem(selectedOption.value);
			genre_items.push(selectedOption.value);
			document.getElementById('selectedItemsList').appendChild(listItem);
			select.selectedIndex = 0;
			//alert(genre_items);
		}
	}
}
function call_add_series_genre()
{
	var select = document.getElementById('genre_itemSelect');
	var selectedOption = select.options[select.selectedIndex];
	var text = SeriesgenreObject[selectedOption.value];
	if (text !== '') {
		if (itemExists(selectedOption.value)) 
		{
			alert('Item already exists!');
		} else 
		{
			var listItem = createSeriesListItem(selectedOption.value);
			genre_items.push(selectedOption.value);
			document.getElementById('selectedItemsList').appendChild(listItem);
			select.selectedIndex = 0;
		}
	}
}
function open_movie_more_modal(no)
{
	var modal = document.getElementById('PanelModalMovielMore');
	g_movie_no=no;
	call_Query_A_Movie_More(no);
	genre_items=[];
	document.getElementById('selectedItemsList').innerHTML = '';

	modal.style.display = "block";
}
function close_movie_more_modal() {
   var modal = document.getElementById('PanelModalMovielMore');
   modal.style.display = "none";
}

function close_update_movie_category_modal() {
	var modal = document.getElementById('PanelModalMovieCategory');
	modal.style.display = "none";
	g_categoryclickedItemValue=null;	
	
	
	var updatestr="";
	var str;
	const listItems = sortable_list.querySelectorAll("li");
	listItems.forEach((item, index) => {
	str='{"id":"'+index+'","name":"'+item.innerText+'","icon":"'+g_Movie_Categories_icons[index]+'"}';
	if (updatestr)
	{
		updatestr=updatestr+','+str;
	}else
	{
		updatestr=updatestr+str;
	}
	});
	cgi_url = "/server/write_category_json?token="+encodeURI(g_token)+"&type=2"+"&flag="+Math.random();
	
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) {
			call_get_movies(g_movie_position,g_movie_limit);
		}
	}
	xmlHttp.send(updatestr);
	
	
}
function open_movie_category_add_modal()
{
	var modal = document.getElementById('PanelModalMovieCategoryAdd');
	modal.style.display = "block";	
	
}
function close_movie_category_add_modal() {
   var modal = document.getElementById('PanelModalMovieCategoryAdd');
   var button=document.getElementById("submitbutton");
   button.disabled=false;
   button.value="Submit";
  // close_movie_category_modal();
   modal.style.display = "none";   
    open_movie_category_modal();
}
function open_movie_category_edit_modal()
{
	var modal = document.getElementById('PanelModalMovieCategoryEdit');
	modal.style.display = "block";	
	var category= document.getElementById('editcategory');
	var current_category_url=document.getElementById('edit_category_url');
	
	var i;
	category.value=g_categoryclickedItemValue;
	for (i=0;i<g_total_movie_category_no;i++)
	{
		if (g_categoryclickedItemValue==g_Movie_Categories_tems[i])
		{
			current_category_url.value=g_Movie_Categories_icons[i];
			current_category_url.style.color='#000000';
			break;
		}
	}
}
function close_movie_category_edit_modal() {
   var modal = document.getElementById('PanelModalMovieCategoryEdit');
   var button=document.getElementById("submitbutton");
   button.disabled=false;
   button.value="Save";
    modal.style.display = "none"; 
 //   document.getElementById('movie_category_edit_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial"></font>';
   open_movie_category_modal();
}
function onstart_moviecategory_add_input()
{
	document.getElementById("add_category_url").style.color = '#000000';
}
function onstart_moviecategory_edit_input()
{
	document.getElementById("edit_category_url").style.color = '#000000';
}
function call_Add_Movie_Category()
{
 	var cgi_url;
 	var api_option;
 	var category_url =document.getElementById("add_category_url").value;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var newcategory = document.getElementById("newcategory").value;
	
	if (newcategory)
	{
		if (category_url.length>0)
		{
			cgi_url = "/server/add_movie_category?token="+encodeURI(g_token)+"&iconurl="+category_url+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}else
		{
			cgi_url = "/server/add_movie_category?token="+encodeURI(g_token)+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}
		
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		//alert(cgi_url);
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4) {
				
		 		var response = xmlHttp.responseText;
			 	
				if (category_url.length==0)
				{
			 		api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"movie_icon"+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
	
					call_Upload_Files(event,UPLOAD_MOVIE_CATEGORY_ICON,api_option);
				}else
				{
					close_movie_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
					
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Added</font>';
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}


			}
		}
		xmlHttp.send(null);
	}

	
}

/*
function call_Add_Movie_Category()
{
 	var cgi_url;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var category = prompt("Please enter category:", "");

	if (category)
	{	
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		cgi_url = "/server/add_movie_category?token="+encodeURI(g_token)+"&newcategory="+encodeURI(category)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4) {
				
		 		var response = xmlHttp.responseText;
			 	var add_button = document.getElementById('Add');
				var edit_button = document.getElementById('Edit');
				var del_button = document.getElementById('Del');
				open_movie_category_modal();
				if (response==2)
		 		{
		 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+category+' Existed</font>';
		 		}else
		 		{
		 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+category+' Added</font>';
		 		}
		 		add_button.disabled=false;
				edit_button.disabled=false;
				del_button.disabled=false;
			}
		};
		xmlHttp.send(null);
	}
	
}
*/
function call_Edit_Movie_Category()
{
 	var cgi_url;
	var currentcategory =g_categoryclickedItemValue;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var category_url =document.getElementById("edit_category_url").value;
	var newcategory = document.getElementById("editcategory").value;
	if (newcategory)
	{	
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		if (category_url.length>0)
		{
			cgi_url = "/server/edit_movie_category?token="+encodeURI(g_token)+"&currentcategory="+encodeURI(currentcategory)+"&newcategory="+encodeURI(newcategory)+"&iconurl="+category_url+"&flag="+Math.random();
		}else
		{
			cgi_url = "/server/edit_movie_category?token="+encodeURI(g_token)+"&currentcategory="+encodeURI(currentcategory)+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			 if (xmlHttp.readyState == 4) {
			 	
		 		var response = xmlHttp.responseText;
			 	
				if ((category_url.length==0) || (category_url.startsWith("upload")))
				{
					api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"movie_icon"+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		
					call_Upload_Files(event,EDIT_UPLOAD_MOVIE_CATEGORY_ICON,api_option);
				}else
				{
					close_movie_category_edit_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		open_movie_category_modal();
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Updated</font>';
			 			g_categoryclickedItemValue=newcategory;
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}
				//close_movie_category_edit_modal();
		
		 	}
		};
		xmlHttp.send(null);
	}
	
}
function Del_Movie_Category()
{

}
function call_Del_Movie_Category()
{
 	var cgi_url;
	var confirm_msg;

	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
 	var category=g_categoryclickedItemValue;
	if (category.length>0)
	{	
			add_button.disabled=true;
			edit_button.disabled=true;
			del_button.disabled=true;
			g_token=find_cookie_value("token");
			cgi_url = "/server/del_movie_category?token="+encodeURI(g_token)+"&delcategory="+encodeURI(category)+"&flag="+Math.random();
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = function()
			{
				 if (xmlHttp.readyState == 4) {
				 	
			 		var response = xmlHttp.responseText;
			 	 	var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		open_movie_category_modal();
			 		if (response==1)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+category+' Deleted</font>'
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
			 	}
			};
			xmlHttp.send(null);
	}
}
function checked_folder_video()
{
	document.getElementById("movie_name_text").innerHTML='<font face="Arial" size="2" color="#cccccc"><b>Movie Name</b> : </font>';
	document.getElementById("moviename").disabled=true;
	//document.getElementById("movie_folder_recursively").innerHTML='<font face="Arial" size="2" color="#000000"><b>Recursively</b> : </font>';
	//document.getElementById("movie_folder_recursively_switch").disabled=false;
	
}
function checked_file_video()
{
	document.getElementById("movie_name_text").innerHTML='<font face="Arial" size="2" color="#000000"><b>Movie Name</b> : </font>';
	document.getElementById("moviename").disabled=false;
	//document.getElementById("movie_folder_recursively").innerHTML='<font face="Arial" size="2" color="#cccccc"><b>Recursively</b> : </font>';
	//document.getElementById("movie_folder_recursively_switch").disabled=true;
	//document.getElementById("movie_folder_recursively_switch").checked=false;
	
}
function callezserver_mass_edit_selected_movie()
{
	
	var cgi_url;
	var category_id="mass_edit_category";
	var quality_id="mass_edit_quality";
	var rentpoint_id="mass_edit_rentpoint";
	var buypoint_id="mass_edit_buypoint";
	var rentperiod_id="mass_edit_rentperiod";
	var ratingflag_id="mass_edit_ratingflag";
	var forwardflag_id="mass_edit_forwardflag";


   
	var category;
	var quality;
	var rentpoint;
	var buypoint;
	var rentperiod;
	var ratingflag;
	var forwardflag;
	
	var i=0;	
	
   	g_token=find_cookie_value("token");
   	
//alert(g_checkedstring);	
	if (g_checkedstring=='0')
	{
	}else
	{

		g_item=document.getElementById(category_id);
		//alert(g_item.value);
		category=g_item.value;
		g_item=document.getElementById(quality_id);
		//alert(g_item.value);
		quality=g_item.value;
		g_item=document.getElementById(rentpoint_id);
		//alert(g_item.value);
		rentpoint=g_item.value;
		g_item=document.getElementById(buypoint_id);
		//alert(g_item.value);
		buypoint=g_item.value;
		g_item=document.getElementById(rentperiod_id);
		//alert(g_item.value);
		rentperiod=g_item.value;
		g_item=document.getElementById(ratingflag_id);
		//alert(g_item.value);
		ratingflag=g_item.value;
		g_item=document.getElementById(forwardflag_id);
		//alert(g_item.value);
		forwardflag=g_item.value;
	
	   	g_token=find_cookie_value("token");
	
		cgi_url = "/server/edit_multiple_movies?token="+encodeURI(g_token)+
		"&category="+encodeURI(category)+
		"&rentpoint="+rentpoint+
		"&buypoint="+buypoint+
		"&ratingflag="+ratingflag+
		"&quality="+quality+
		"&rentperiod="+rentperiod+
		"&forward="+forwardflag;
		cgi_url +="&flag="+Math.random();
		//alert(cgi_url);
		 xmlHttp.open("POST", cgi_url, true);
		 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response!=1)
			{
				alert("Failed to Edit Movies");
			}
			close_mass_edit_movie_modal();
			call_get_movies(g_movie_position,g_movie_limit);
		    }
		};
				 
		xmlHttp.send(g_checkedstring);
	}
	

}
// Upload Files
function call_Upload_Files(evt,mediatype, api_option)
{
	var g_item_name;
	var formData;
	var flag;
	let fileInput;
 	//var cgi_url;
	g_item_name=document.getElementById("submitbutton");
	g_item_name.disabled=true;

	g_token=find_cookie_value("token");
	if (mediatype == UPLOAD_CHANNEL_ICON_PATH)
	{
		 fileInput = document.querySelector('#file_upload input[type="file"]');
		formData = new FormData(document.getElementById('file_upload'));
		
	}else if (mediatype == UPLOAD_MOVIE_ICON_PATH)
	{
		 fileInput = document.querySelector('#file_upload input[type="file"]');
		formData = new FormData(document.getElementById('file_upload'));
		
	}else if (mediatype == UPLOAD_QRCODE_ICON_PATH)
	{
		 fileInput = document.querySelector('#file_upload input[type="file"]');
		formData = new FormData(document.getElementById('file_upload'));
		
	}else if (mediatype == UPLOAD_CHANNEL_M3U)
	{
		formData = new FormData(document.getElementById('file_upload_form_channel'));
		
	}else if (mediatype == UPLOAD_MOVIE_M3U)
	{
		formData = new FormData(document.getElementById('file_upload_form_movie'));
	}else if (mediatype == UPLOAD_SERIES_M3U)
	{
		formData = new FormData(document.getElementById('file_upload_form_series'));
	}else if ((mediatype == UPLOAD_XTREAM_DB_USERS) || (mediatype == UPLOAD_XTREAM_DB_CONTENT) || (mediatype == UPLOAD_XTREAM_DB))
	{
		formData = new FormData(document.getElementById('file_upload_form_xtream_db'));
	}else if (mediatype == UPLOAD_CHANNEL_CATEGORY_ICON)
	{
		flag=mediatype;	
		formData = new FormData(document.getElementById('add_file_upload_form_channel_category_icon'));
	}else if (mediatype == EDIT_UPLOAD_CHANNEL_CATEGORY_ICON)
	{
		flag=mediatype;
		mediatype = UPLOAD_CHANNEL_CATEGORY_ICON;
		formData = new FormData(document.getElementById('edit_file_upload_form_channel_category_icon'));
	}else if (mediatype == UPLOAD_MOVIE_CATEGORY_ICON)
	{
		flag=mediatype;
		formData = new FormData(document.getElementById('add_file_upload_form_movie_category_icon'));
	}else if (mediatype == EDIT_UPLOAD_MOVIE_CATEGORY_ICON)
	{
		flag=mediatype;
		mediatype = UPLOAD_MOVIE_CATEGORY_ICON;
		formData = new FormData(document.getElementById('edit_file_upload_form_movie_category_icon'));
	}else if (mediatype == UPLOAD_SERIES_CATEGORY_ICON)
	{
		flag=mediatype;
		formData = new FormData(document.getElementById('file_upload_form_series_category_icon'));
	}else if (mediatype == EDIT_UPLOAD_SERIES_CATEGORY_ICON)
	{
		flag=mediatype;
		mediatype = UPLOAD_SERIES_CATEGORY_ICON;
		formData = new FormData(document.getElementById('edit_file_upload_form_series_category_icon'));
	}
	
	if (mediatype == UPLOAD_CHANNEL_ICON_PATH)
	{
		if (fileInput && fileInput.files && fileInput.files.length > 0) {
			let fileName = fileInput.files[0].name;
			var chiconid="chicon"+g_edit_no;
			var ch_icon_path_id="ch_icon_path_"+g_edit_no;
			
			document.getElementById(ch_icon_path_id).src="upload/"+fileName;
			document.getElementById(chiconid).value="upload/"+fileName;
	
		}
	}
	if (mediatype == UPLOAD_MOVIE_ICON_PATH)
	{
		if (fileInput && fileInput.files && fileInput.files.length > 0) {
			let fileName = fileInput.files[0].name;
			var movie_iconid="iconpath"+g_edit_no;
			var movie_icon_path_id="movie_icon_path_"+g_edit_no;
			
			document.getElementById(movie_icon_path_id).src="upload/"+fileName;
			document.getElementById(movie_iconid).value="upload/"+fileName;

	
		}
	}	
	if (mediatype == UPLOAD_QRCODE_ICON_PATH)
	{
		if (fileInput && fileInput.files && fileInput.files.length > 0) {
			let fileName = fileInput.files[0].name;
			var QRCode_iconid="iconpath"+g_edit_no;
			var QRCode_icon_path_id="QRCode_icon_path_"+g_edit_no;
			
			document.getElementById(QRCode_icon_path_id).src="upload/"+fileName;
			document.getElementById(QRCode_iconid).value="upload/"+fileName;

	
		}
	}
	let xhr = new XHR();
	
	xhr.uploadXHR().addEvt('progress', evt => {
        });
        
        xhr.addEvt('load', evt => {
            let req = evt.target;      
          
    })
  	 xmlHttp.open("POST", api_option, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			var responsexcdb = xmlHttp.responseText.split("\r\n");
			var item_save;
			var item_add;
			var item_copy;
			var item_del;
			var item_refresh;
			var item_more;
			var item_play;
			var addedNo;
			var temp;
			var g_item_name;
			var reMessage;
			
			if ((response>0) || (responsexcdb[0]>0) || (responsexcdb[1]>0) || (responsexcdb[2]>0))
			{
				addedNo=parseInt(response);
				//alert(addedNo);
				//alert(mediatype);
				if (mediatype == UPLOAD_CHANNEL_M3U)
				{
					var import_channel_dialog_message=document.getElementById("import_channel_dialog_message");
					//alert(import_channel_dialog_message);
					if (addedNo>1)
					{
						import_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' channels added</font>';
						g_total_ch_no=parseInt(g_total_ch_no)+parseInt(response);
					    	alert("Restart EZserver to get the newest channel list");
					}else if (addedNo==1)
					{
						import_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' channel added</font>';
						g_total_ch_no=parseInt(g_total_ch_no)+parseInt(response);
					    	alert("Restart EZserver to get the newest channel list");
					}else 
					{
						alert("Failed to Upload Files");
					}	 
				}else if (mediatype == UPLOAD_MOVIE_M3U)
				{
					var import_movie_dialog_message=document.getElementById("import_movie_dialog_message");
					if (response>0)
					{
						import_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' movies added</font>';
						
						g_total_movie_no=parseInt(g_total_movie_no)+parseInt(response);
					
					} else if (response==0)
					{
						//alert("Failed to Import Movie");
						import_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import Movie</font>';
					}
			        }else if (mediatype == UPLOAD_SERIES_M3U)
			        {
					var import_series_dialog_message=document.getElementById("import_series_dialog_message");
					if (response=="0")
					{
						//alert("Failed to Import");
						import_series_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import</font>';
					}else
					{
						g_total_series_no=parseInt(g_total_series_no)+parseInt(response);
						
						import_series_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' series added</font>';
						
						
					}
			        }else if (mediatype == UPLOAD_XTREAM_DB_USERS)
			        {
					var import_xtream_db_dialog_message=document.getElementById("import_xtream_db_dialog_message");
					if (response=="0")
					{
						//alert("Failed to Import");
						import_xtream_db_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import</font>';
					}else
					{
						
						g_user_no=parseInt(g_user_no)+parseInt(response);
						
						import_xtream_db_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' users added</font>';
						
						
					}
			        }else if (mediatype == UPLOAD_XTREAM_DB_CONTENT)
			        {
					var import_xtream_db_dialog_message=document.getElementById("import_xtream_db_dialog_message");
					if (response=="0")
					{
						//alert("Failed to Import");
						import_xtream_db_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import</font>';
					}else
					{
						g_total_ch_no=parseInt(g_total_ch_no)+parseInt(responsexcdb[0]);
						g_total_movie_no=parseInt(g_total_movie_no)+parseInt(responsexcdb[1]);
						g_total_series_no=parseInt(g_total_series_no)+parseInt(responsexcdb[2]);
						
						
						import_xtream_db_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+responsexcdb[0]+' channels,'+responsexcdb[1]+' movies,'+responsexcdb[2]+' series'+' added</font>';
						
						
					}
			        }else if (mediatype == UPLOAD_XTREAM_DB)
			        {
					var import_xtream_db_dialog_message=document.getElementById("import_xtream_db_dialog_message");
					if (responsexcdb[0]=="0")
					{
						//alert("Failed to Import");
						import_xtream_db_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import</font>';
					}else
					{
						
						g_user_no=parseInt(g_user_no)+parseInt(responsexcdb[0]);
						g_total_ch_no=parseInt(g_total_ch_no)+parseInt(responsexcdb[1]);
						g_total_movie_no=parseInt(g_total_movie_no)+parseInt(responsexcdb[2]);
						g_total_series_no=parseInt(g_total_series_no)+parseInt(responsexcdb[3]);
						
						import_xtream_db_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+responsexcdb[0]+' users,'+responsexcdb[1]+' channels,'+responsexcdb[2]+' movies,'+responsexcdb[3]+' series'+' added</font>';
						
						
					}
			        }
				g_item_name=document.getElementById("submitbutton");
				g_item_name.disabled=false;
			        g_item_name=document.getElementById("cancel_button");
				g_item_name.disabled=false;
				/*if ((flag==EDIT_UPLOAD_CHANNEL_CATEGORY_ICON) || (flag==EDIT_UPLOAD_MOVIE_CATEGORY_ICON) || (flag==EDIT_UPLOAD_SERIES_CATEGORY_ICON))
				{
					g_item_name.value="Save";
				}else
				{
					g_item_name.value="Submit";
				}
				*/
				if (flag==UPLOAD_CHANNEL_CATEGORY_ICON)
				{
					close_channel_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial"> Added</font>';
			 			g_categoryclickedItemValue=newcategory;
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}else if (flag==UPLOAD_MOVIE_CATEGORY_ICON)
				{
					close_movie_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
					
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning:'+' Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial"> Added</font>';
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}else if (flag==UPLOAD_SERIES_CATEGORY_ICON)
				{
					close_series_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial"> Added</font>';
			 		}
					add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
					
				}else if (flag==EDIT_UPLOAD_CHANNEL_CATEGORY_ICON)
				{
					close_channel_category_edit_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial"> Updated</font>';
			 			g_categoryclickedItemValue=newcategory;
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}else if (flag==EDIT_UPLOAD_MOVIE_CATEGORY_ICON)
				{
					close_movie_category_edit_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial"> Updated</font>';
			 			g_categoryclickedItemValue=newcategory;
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}else if (flag==EDIT_UPLOAD_SERIES_CATEGORY_ICON)
				{
					close_series_category_edit_modal();
					
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+'Updated</font>';
			 		}
					add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}
				
			} else
			{
				alert("Failed to Upload Files");
				g_item_name=document.getElementById("submitbutton");
				g_item_name.disabled=false;
			        g_item_name=document.getElementById("cancel_button");
				g_item_name.disabled=false;
				/*if ((flag==EDIT_UPLOAD_CHANNEL_CATEGORY_ICON) || (flag==EDIT_UPLOAD_MOVIE_CATEGORY_ICON) || (flag==EDIT_UPLOAD_SERIES_CATEGORY_ICON))
				{
					g_item_name.value="Save";
				}else
				{
					g_item_name.value="Submit";
				}
				*/
				
			}
		}
	 };
	 xmlHttp.upload.onprogress = function(evt)
	 {
		if (evt.lengthComputable) {  
	           var percentComplete = (evt.loaded / evt.total)*100;
	           var percentCompleteString;
	           var g_item_name;
	 	   g_item_name=document.getElementById("submitbutton");
	 	   
	           if (percentComplete<100)
	           {
		           percentCompleteString=percentComplete.toFixed()+'%';
		           if (mediatype == UPLOAD_XTREAM_DB)
	           	   {
		           	g_item_name.value="Uploading Xtream DB: "+percentCompleteString;
		           }else
		           {
		           	g_item_name.value="Uploading M3U: "+percentCompleteString;
		           }
	           }else if (percentComplete == 100)
	           {
	           	if (mediatype == UPLOAD_XTREAM_DB)
	           	{
		           g_item_name.value="Parsing";;
	           	}else
	           	{
		           g_item_name.value="Parsing";;
		        }
		           g_item_name=document.getElementById("cancel_button");
			   g_item_name.disabled=true;
	           }
	        }	 	
	 };
	 xmlHttp.send(formData);
	 evt.preventDefault();
}
// Upload Movies
function call_Upload_Movie(evt)
{
	
	
	var g_item_name;
 	var cgi_url;
	g_item_name=document.getElementById("AddUploadButton");
	g_item_name.disabled=true;

	g_token=find_cookie_value("token");
	
	cgi_url = "/server/upload_movies?token="+escape(g_token)+"&flag="+Math.random();
	let formData = new FormData(document.getElementById('file_upload_form'));
	
	let xhr = new XHR();
	
	xhr.uploadXHR().addEvt('progress', evt => {
        });
        
        xhr.addEvt('load', evt => {
            let req = evt.target;        
        })
	 xmlHttp.open("POST", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
		if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			var item_save;
			var item_add;
			var item_copy;
			var item_del;
			var item_refresh;
			var item_more;
			var item_play;
			var addedNo;
			var temp;
			var g_item_name;
			//var filetype=g_filetype;
			var reMessage;
			if (response>0)
			{
				addedNo=parseInt(response);
				if (addedNo>1)
				{
					reMessage=response+" movies uploaded";
					alert(reMessage);
				}else if (addedNo==1)
				{
					reMessage=response+" movie uploaded";
					alert(reMessage);
				}else 
				{
					alert("Failed to Upload Files");
				}
				temp=parseInt(g_total_movie_no)+addedNo;   	
				g_total_movie_no=temp.toString();
				if ((g_movie_position+g_constant_limit)<=g_total_movie_no)
				{
					if (((g_total_movie_no)%g_constant_limit)==1)
					{
						g_file_position=parseInt(g_total_movie_no);
					}
					g_file_limit=g_constant_limit;
				}else
				{
					g_file_limit=g_total_movie_no%g_constant_limit;
					if (g_file_limit==0) 
					{
						if (g_total_movie_no<g_file_position)
						{
							g_file_position=g_total_movie_no-g_constant_limit+addedNo;
						}
						g_file_limit=g_constant_limit;
					}
				}
				g_item_name=document.getElementById("AddUploadButton");
				g_item_name.value="Upload";
				g_item_name.disabled=false;
				
			} else
			{
				alert("Failed to Upload Files");
				g_item_name=document.getElementById("AddUploadButton");
				g_item_name.value="Upload";
				g_item_name.disabled=false;
			}
		
			
		    }	 	
	 };
	 xmlHttp.upload.onprogress = function(evt)
	 {
		if (evt.lengthComputable) {  
	           var percentComplete = (evt.loaded / evt.total)*100;
	           var percentCompleteString;
	           var g_item_name;
	           
	 	   g_item_name=document.getElementById("AddUploadButton");
	           percentCompleteString=percentComplete.toFixed()+'%';
	           g_item_name.value=percentCompleteString;
	        }	 	
	 };
	 xmlHttp.send(formData);
	 evt.preventDefault();
}

function open_upload_movie_modal()
{
	var modal = document.getElementById('PanelUploadModal');


	modal.style.display = "block";
	/*
	var cgi_url;
	
	g_filetype=filetype;
	g_token=find_cookie_value("token");
	cgi_url = "/server/get_file_category?token="+escape(g_token)+"&type="+filetype+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Add_New_File_Category;
	xmlHttp.send(null);
	*/
}
function close_upload_movie_modal() {
   var modal = document.getElementById('PanelUploadModal');
   modal.style.display = "none";
   Button_Server_Movie_Inquery();
}

function get_movies()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
	var movie_no;
	var movie_name;
	var movie_src;
	var icon_path;
	var movie_icon_path;
	var movie_category;
	var duration;
	var bitrate;
	var movie_status;
    var movie_play_id;
    var movie_title="<p>"+"Movie List"+"</p>";
    var move_list;
    var i=0;
    var j=0;
    var total_no=0;
	var movie_active_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content;
    var ezcontent= document.getElementById("content")
  //var detail = parent.document.getElementById("detail");
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var nduration =0;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_movie_position;
	var total_count=g_total_movie_no;
	var menustr1="";
	var menustr2="";
	var new_total_no;
	var cellsize="15%";
	
	g_start_search_option=3;
	for (gi = 0; gi < g_movie_genre.length; gi++) 
	 {
	  	item = g_movie_genre[gi];
	 	MoviegenreObject[item.id] = item.name;
	}
	

	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="60%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Movie</b></font>';
	str+='</td>';

	str+='<td>';
	if ((g_search_text.length==0)|| g_SearchInput.value=='Search Movies...')
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Movies..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}else
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}
	str+='</td>';
	str += '<td>' +
       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
       '</select>' +
       '</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()">Add Movie</a>';
		str+='</div>'; 
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="Button_Server_Movie_Inquery()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 
		str+='<div class="menudropdown">';
		    str+='<button class="dropbtn" style="background-color: #414D5F">'; 
		    str+='<i class="fa fa-caret-down"></i>';
		    str+='</button>';
		    str+='<div class="menudropdown-content">';
		      str+='<a href="javascript:open_movie_category_modal()">Category</a>';
		      if (g_search_text.length==0)
		      {
			      str+='<a href="javascript:open_mass_edit_movie_modal()">Mass Edit</a>';
			      str+='<a href="javascript:open_mass_delete_movie_modal()">Mass Delete</a>';
			      str+='<a id=movie_cut_field href="javascript:callezserver_move_selected_movie()">Move to</a>';
			      str+='<a href="javascript:callezserver_refresh_selected_movie()">Multi Refresh</a>';
		      }
		      str+='<a href="javascript:open_import_movie_modal()">Import M3U</a>';
		      str+='<a href="javascript:call_export_movie_definition()">Export as XML</a>';
		    str+='</div>';
		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;
	//parent.document.getElementById("page_no").value=g_constant_limit;		
	

	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";
	
	g_search_movie_item.value=null;

	 HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"><input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_movie_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td  id="movie_name_id" width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Movie Name</b></font>';
	      if (g_movie_name_order_flag==0)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_movie_name_order_flag==1)
	      {
	      	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_movie_name_order_flag==2)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
	      }
	      HTML_str+='</td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Media Source</font></b></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Icon</b></font></td>'+
	      '<td width="50" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td id="category_id" width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Main Category</b></font>';
	      if (g_movie_category_order_flag==0)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_movie_category_order_flag==1)
	      {
	      	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_movie_category_order_flag==2)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_movie_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
	      } 
	      HTML_str+='</td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Duration(min.)</b></font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Bitrate(Kbps)</b></font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Server</b></font></td>'+
 	 '</tr>'+'<tr><td  colspan="10"><hr size="1" color="#66FFFF"></td></tr>';
 
	while (1)
	{
 		//alert(response[i]);
	 	if (response[i]==0) break;
	 	strlength=response[i].length;
   	    	movie_no=response[i].slice(8,strlength);
   	    	
     	 	strlength=response[i+1].length;
     	 	movie_name=response[i+1].slice(5,strlength);
   	    	
     	 	strlength=response[i+2].length;
   	    	movie_src=response[i+2].slice(4,strlength);
   	    	
    	 	strlength=response[i+3].length;
   	    	icon_path=response[i+3].slice(4,strlength);
   	    	if (icon_path.indexOf("file://")!==-1)
   	    	{
   	    		movie_icon_path=icon_path.slice(7);
   	    	}else
   	    	{
   	    		movie_icon_path=icon_path;
   	    	}
   	    	
     	 	strlength=response[i+4].length;
 	    	movie_category=response[i+4].slice(9,strlength);

   	    	
 	    	
     	 	strlength=response[i+5].length;
 	    	duration=response[i+5].slice(9,strlength);
 	    	nduration=parseFloat(duration);
 	    	nduration = nduration /60;
 	    	nduration =nduration.toFixed(3);

 	    	
     	 	strlength=response[i+6].length;
 	    	bitrate=response[i+6].slice(8,strlength);
 	    	
       	 	strlength=response[i+7].length;
 	    	movie_status=response[i+7].slice(7,strlength);
   	    		
   	    	

 		i=i+8;
		movie_active_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		   '<td width="20" align="center">';
		      if (g_movie_found_position==movie_no)
		      {
	 		HTML_str+=' <input type="checkbox" checked name=checkbox'+movie_no;
	 	      }else
	 	      {
	 		HTML_str+=' <input type="checkbox" name=checkbox'+movie_no;
	 	      }
	 	      HTML_str+=' id=checkbox'+movie_no+'></td>';

	 		
		      HTML_str+='<td width="60" align="center"><font face="Arial" size="2">'+movie_no+'</font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" title="'+movie_name+'" name="moviename"'+
	 		' id=moviename'+movie_no+
	 		' size="20" value="'+
	 		unescape(movie_name)+'"/></font></td>'+
	 		
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;"  type="text" title="'+movie_src+'" name="moviesrc"'+
	 		' id=moviesrc'+movie_no+
	 		' size="50" value="'+
	 		movie_src+'"/></font></td>'+	
	 		'<td width="'+"50px"+'" style="text-align: center; vertical-align: middle;">'+
		        '<a href="javascript:void(0)" onclick=open_icon_edit_modal("2","'+movie_no+'","'+icon_path+'")>'+'<img id="movie_icon_path_'+movie_no+'" style="padding: 5px;width:35px; height:35px" src="'+movie_icon_path+'"</img>'+'</a>'+
	 		'</td>'+	      
	 		'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;"  type="text" title="'+icon_path+'" name="iconpath"'+
	 		' id=iconpath'+movie_no+
	 		' size="35" value="'+
	 		icon_path+'"/></font></td>';
		      
		      
	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
			' <select style="text-indent: 5;width:152;height:26;" size="1" name="moviecategory" id=moviecategory'+movie_no+'>';
	 		
			if (movie_category.length==0)
			{
				HTML_str+='<option selected="selected" value="">'+""+'</option>';
			}
			
			for (j=0;j<g_total_movie_category_no;j++)
			{
				if (g_Movie_Categories_tems[j]==unescape(movie_category))
				{
					HTML_str+='<option selected="selected" value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
				}else
				{
					HTML_str+='<option value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
				}
				
			}
			HTML_str+='</select></font></td>';
		
	 		HTML_str+='<td id=movieduration'+movie_no+' width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		nduration+'</font></td>'+
		      '<td id=moviebitrate'+movie_no+' width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		bitrate+'</font></td>';

	 		

			
			//alert(movie_status);		
			if (movie_status == "1")
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2">'+"ON"+'</font></td>';
			} else if (movie_status == "0")
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
			} else if (movie_status =="2")
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>RM</b>"+'</font></td>';
			}else if (movie_status == "3")
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2">'+"FWD"+'</font></td>';
			}else if (movie_status == "4")
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2">'+"VOD"+'</font></td>';
			}else
			{
		      		HTML_str+='<td id=moviestatus'+movie_no+' width="'+cellsize+'" align="center"><font face="Arial" size="2">'+movie_status+'</font></td>';
			}
	 		HTML_str+='<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=callServer_Movie_Update("'+movie_no+'")><img src="/admin/save.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=open_movie_more_modal("'+movie_no+'")><img src="/admin/edit.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=call_Del_Movie("'+movie_no+'")><img src="/admin/del.png"></img></a></td>';
			

		HTML_str+='</tr>';				
		   // alert(HTML_str);
		total_no++;
     }
    //    content.innerHTML=HTML_str;
      // alert(menu_main.innerHTML);
  //    alert(HTML_str);
  	i=1;
	//if (total_no>0)
	//{

		new_total_no=Number(g_total_movie_no)+1;
		menustr1='<table width=100%><tr>';
		menustr1+='<td width="4%">';
		menustr1+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>New Movie</b></font></td><td colspan=2 align=right id=add_movie_dialog_message name=add_movie_dialog_message></td></tr>';
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				'<td  colspan="4"><hr size="1" color="#000000"></td></tr>';
  				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2"><b>Movie a<b>t</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="movie_no"'+
		 		' id="movie_no"'+
		 		' size="16" value="'+
				new_total_no+
				'"/></font></td>';
				
				
								
				menustr1+='<td id=movie_name_text width=25%><font face="Arial"> <font size="2"><b>Movie Name</b></font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="moviename"'+
		 		' id="moviename"'+
		 		' size="16" value=""/></font></td></tr>';
				menustr1+='<tr><td colspan=2><label class="container"><font face="Arial"><b>File</b></font><input type="radio" checked="checked" name="radio" onclick="javascript:checked_file_video()"><span class="checkmark"></span></label></td>';
				menustr1+='<td colspan=2><label class="container"><font face="Arial"><b>Folder</b></font></font><input type="radio" name="radio"  onclick="javascript:checked_folder_video()"><span class="checkmark"></span></label></td></tr>';
 				menustr1+='<tr><td><font face="Arial" size="2"><b>Category</b></font></td><td>'+
		 		' <select style="text-indent: 5;width:142;height:26;" size="1" name="moviecategory" id=moviecategory>';
				
				for (j=0;j<g_total_movie_category_no;j++)
				{
					if (j==0) 
					{
						menustr1+='<option  style="padding: 2px" selected="selected" value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
					}else
					{
						menustr1+='<option  style="padding: 2px" value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
					}
				}
				menustr1+='</select></font></td>';	
				
  				//menustr1+='<td id="movie_folder_recursively"><font face="Arial" size="2" color="#cccccc"><b>Recursive Folder</b> : </font></td><td><label class="switch"><input type="checkbox" id="movie_folder_recursively_switch" disabled><span class="slider round"></span></label></td></tr>';

				menustr1+='<tr><td><font face="Arial"> <font size="2"><b>Rent Point</b></font></td><td width="25%" height="23">'+
				' <input style="text-indent: 5;height:26;" type="text" name="rentpoint"'+
		 		' id="rentpoint"'+
		 		' size="16" value=""/></font></td>';
		
				menustr1+='<td><font face="Arial"> <font size="2"><b>Buy Point</b></font></td><td width="25%" height="23">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="buypoint"'+
		 		' id="buypoint"'+
		 		' size="16" value=""/></font></td></tr>';


 
				menustr1+='<tr><td><font face="Arial" font size="2"><b>Media Source</b> : </font></td><td  colspan=3>'+
				 		' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;" type="text" name="moviesrc"'+
				 		' id=moviesrc'+
				 		' size="61"/>'+
				 		'</font></td></tr>';
				menustr1+='<tr><td><font face="Arial" size="2"><b>Icon Path</b> : </font></td><td id=movie_icon_path colspan=3>'+
				 		' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;" type="text" name="iconpath" list="moviename"'+
				 		' id=iconpath'+
				 		' onclick=get_TMDB_movie_name() size="61"/>'+
				 		'</font></td></tr>';
				 menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Description </font></td>'+
				'<td colspan=3 width=75% height="23">'+
		 		' <textarea maxlength="500" name="movie_description"'+
		 		' id="movie_description"'+
		 		' cols="61" rows="10">'+
		 		'</textarea></td></tr>';
				/*
				menustr1+='<tr><td><font face="Arial" size="2"><b>Category</b> : </font></td><td>'+
				 		' <font face="Arial" size="2">'+
				 		' <input type="text" name="moviecategory"'+
				 		' id=moviecategory'+
				 		' size="20"/'+
				 		'</font></td></tr>';
				 */
				
				menustr1+='<tr><td colspan=2 width=50% ><input id=add_new_movie_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add"  onclick=call_Add_Movie() name="Add" /></td>'+
				'<td colspan=2  width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_movie_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
			
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMassEditMovie" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>Mass Edit Movies</b></font></td><td colspan=2 align=right id=save_mass_movie_dialog_message name=save_mass_movie_dialog_message></td></tr>';
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				
				menustr1+='<tr><td><font face="Arial" size="2"><b>Category</b></font></td><td colspan=3>'+
		 		' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_category" id=mass_edit_category>';
				
				for (j=0;j<g_total_movie_category_no;j++)
				{
					if (j==0) 
					{
						menustr1+='<option  style="padding: 2px" selected="selected" value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
					}else
					{
						menustr1+='<option  style="padding: 2px" value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
					}
				}
				menustr1+='</select></font></td></tr>';	
								
				menustr1+='<tr><td><font face="Arial"> <font size="2">Rent Point</font></td><td width="25%" height="23">'+
				' <input style="text-indent: 5;height:26;" type="text" name="mass_edit_rentpoint"'+
		 		' id="mass_edit_rentpoint"'+
		 		' size="16" value=""/></font></td>';
		
				menustr1+='<td><font face="Arial"> <font size="2">Buy Point</font></td><td width="25%" height="23">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_buypoint"'+
		 		' id="mass_edit_buypoint"'+
		 		' size="16" value=""/></font></td></tr>';

				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Rent Period</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_rentperiod"'+
		 		' id="mass_edit_rentperiod"'+
		 		' size="16" value=""/></font></td>';
				
				menustr1+='<td><font face="Arial"><font size="2">Ratings</font></td><td  width="25%" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_ratingflag" id="mass_edit_ratingflag">';
				menustr1+='<option selected="selected" value="0">No Protection</option>'+
				'<option value="1">Protection</option>';
				menustr1+='</select></td></tr>';

				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Video Quality</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_quality" id="mass_edit_quality">';
				menustr1+=
				'<option  value="md">Mobile</option>'+
				'<option value="sd">SD</option>'+
				'<option value="hd">HD</option>';
				menustr1+='</select></td>';
				
				menustr1+='<td><font face="Arial"><font size="2">Proxy</font></td><td  width="25%" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_forwardflag" id="mass_edit_forwardflag">';
				//menustr1+='<option selected="selected" value="0">0</option>'+
				//'<option value="1">1</option>>';
				menustr1+='<option selected="selected" value="0">Disabled</option>'+
				'<option value="1">To Source URL</option>';
				menustr1+='</select></td></tr>';


				/* menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Description </font></td>'+
				'<td colspan=3 width=75% height="23">'+
		 		' <textarea maxlength="500" name="mass_edit_movie_description"'+
		 		' id="mass_edit_movie_description"'+
		 		' cols="61" rows="10">'+
		 		'</textarea></td></tr>';
		 		*/

				menustr1+='<tr><td colspan=2><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=callezserver_mass_edit_selected_movie() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_mass_edit_movie_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				
				'</div>'+
				'</div></td>';	
				
				// Mass Delete
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMassDelete" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  width=75% colspan=3 align=left><font face="Arial" size="6"><b>Mass Delete</b></font></td><td align=right id=mass_delete_dialog_message name=mass_edit_delete_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				
				// Category	
				menustr1+='<tr><td><font face="Arial" size="2"><b>Choose one category</b></font></td><td colspan=3 width=75%>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="mass_delete_category" id=mass_delete_category>';
				
				menustr1+='<option style="padding: 2px" selected="selected" value="'+"All"+'">'+"All"+'</option>';
				// Need to change
				for (j=0;j<g_total_movie_category_no;j++)
				{
					menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Movie_Categories_tems[j])+'">'+decodeURI(g_Movie_Categories_tems[j])+'</option>';
				}
				menustr1+='</select></font></td></tr>';
				
	 			// Need to change			
				menustr1+='<tr><td colspan=2><input id=delete_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Delete" onclick=callezserver_mass_delete_selected_movie() name="Delete" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_mass_delete_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				
				
				
				// Upload button
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelUploadModal" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>Upload Movies</b></font></td><td colspan=2 align=right id=add_movie_dialog_message name=add_movie_dialog_message></td></tr>';
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				'<td  colspan="4"><hr size="1" color="#000000"></td></tr>';
  				
				menustr1+='<tr><td colspan=2> <form id="file_upload_form" enctype="multipart/form-data">'+
				         '<font face="Arial" size="2">File : </font>'+'<input type="file" name="Video" multiple/>'+
					 '</form></td></tr>';
				
				menustr1+='<tr><td colspan=2 width=50% ><input id=AddUploadButton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Upload"  onclick=call_Upload_Movie(event) name="Upload" /></td>'+
				'<td colspan=2  width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_upload_movie_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
			
				menustr1+='<td width="4%">';
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMovieCategory" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table align="center" cellspacing="10" align="center">';
				menustr1+='<tr><td align="left"><font face="Arial" size="6"><b>Category</b></font></td><td align=right id=category_dialog_message name=category_dialog_message></td><td id=total_no align="right"></tr>';
				menustr1+='<tr><td  colspan="3"><hr size="1" color="#000000"></td></tr>';
				menustr1+='<tr><td colspan=2 id=movie_category></td>'+
				'<td>'+
				'<table>';
				menustr1+='<tr><td><input id="Add" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=open_movie_category_add_modal() name="Add" /></td></tr>';
				menustr1+='<tr><td><input id="Edit" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Edit" onclick=open_movie_category_edit_modal() name="Edit" /></td></tr>';
				menustr1+='<tr><td><input id="Del" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Del" onclick=call_Del_Movie_Category() name="Del" /></td></tr>';
				menustr1+='<tr><td><img style="margin-top:10px;width:100%;height:30;" src="/admin/move.png"></img></td></tr>';
				
				menustr1+='</table></td></tr>';
				
				
				menustr1+='<tr><td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Save" onclick=close_update_movie_category_modal() name="Save" /></td>';
				menustr1+='<td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_movie_category_modal() name="Cancel" /></td>';
				menustr1+='<td width=10%></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
			
			
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMovielMore" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr><td  colspan=2 align=left id=more_movie_name><font face="Arial" size="6"><b></b></font></td><td colspan=2 align=right id=save_movie_dialog_message name=save_movie_dialog_message></td></tr>';
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				
				menustr1+='<tr><td><font face="Arial"> <font size="2"><b>Rent Point</b></font></td><td width="25%" height="23">'+
				' <input style="text-indent: 5;height:26;" type="text" name="more_rentpoint"'+
		 		' id="more_rentpoint"'+
		 		' size="16" value=""/></font></td>';
		
				menustr1+='<td><font face="Arial"> <font size="2"><b>Buy Point</b></font></td><td width="25%" height="23">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_buypoint"'+
		 		' id="more_buypoint"'+
		 		' size="16" value=""/></font></td></tr>';

				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Rent Period</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="more_rentperiod"'+
		 		' id="more_rentperiod"'+
		 		' size="16" value=""/></font></td>';
				
				menustr1+='<td><font face="Arial"><font size="2">Ratings</font></td><td  width="25%" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="more_ratingflag" id="more_ratingflag">';
				menustr1+='<option selected="selected" value="0">No Protection</option>'+
				'<option value="1">Protection</option>';
				menustr1+='</select></td></tr>';

				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Video Quality</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="more_quality" id="more_quality">';
				menustr1+=
				'<option  value="md">Mobile</option>'+
				'<option value="sd">SD</option>'+
				'<option value="hd">HD</option>';
				menustr1+='</select></td>';
				
				menustr1+='<td><font face="Arial"><font size="2">Proxy</font></td><td  width="25%" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="more_forwardflag" id="more_forwardflag">';
				//menustr1+='<option selected="selected" value="0">0</option>'+
				//'<option value="1">1</option>>';
				menustr1+='<option selected="selected" value="0">Disabled</option>'+
				'<option value="1">Source Server</option>';
				
				// List BL into proxy mode
				var balancer_value=201;
				//alert(g_balancer.length);
				if (g_balancer.length>0)
				{
					for (i=0;i<g_balancer.length;i++)
					{
						item = g_balancer[i];
						//alert(item.name);
						menustr1+='<option value="'+balancer_value+'">'+item.name+'</option>'+
						balancer_value++;
					}
				}
				menustr1+='</select></td></tr>';

				// Movie Gener
		 		menustr1+='<tr><td><font face="Arial" size="2">Sub Categories</font></td><td>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="genre_itemSelect" id=genre_itemSelect>';
				
				for (j=0;j<g_movie_genre.length;j++)
				{
					var genre_id=g_movie_genre[j].id;
					menustr1+='<option style="padding: 2px" value="'+genre_id+'">'+MoviegenreObject[genre_id]+'</option>';
				}
				menustr1+='</select></font></td><td colspan=2><button id="addItemButton" onclick=call_add_movie_genre()>Add Item</button></td></tr>';
				menustr1+='<tr><td></td><td colspan=3><font face="Arial" size="2"><b><ul id="selectedItemsList"></ul></b></font></td></tr>';	

				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Description </font></td>'+
				'<td colspan=3 width=75% height="23">'+
		 		' <textarea maxlength="500" name="more_movie_description"'+
		 		' id="more_movie_description"'+
		 		' cols="61" rows="10">'+
		 		'</textarea></td></tr>';

				menustr1+='<tr><td colspan=2><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=callServer_Save_Movie_More() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_movie_more_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				
				'</div>'+
				'</div></td>';	
		      				
		      		menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalImport" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  colspan=2 align=left id=more_channel_name><font face="Arial" size="6"><b>Import Movies</b></font></td><td colspan=2 align=right id=import_movie_dialog_message name=import_movie_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">Movie after</font></td>'+
				'<td width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="importmovieno"'+
		 		' id="importmovieno"'+
		 		'value="'+g_total_movie_no+'"'+
		 		' size="16" value=""/></font></td>';
		 		
				
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Options</font></td>'+
				'<td width=25%><select  style="text-indent: 5;width:152;height:26;" size="1" id="import_option">'+
				'<option style="padding: 2px" value="0">'+"None"+'</option>'+
				'<option style="padding: 2px" value="1">'+"Proxy"+'</option>'+
				'</select></font></td></tr>';
				
				menustr1+='<tr><td width=100% colspan="4"><b>M3U from HTTP URL or Local File</b></td></tr>';	
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td><td colspan="2"></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=75% colspan=3 height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstartinput()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="importurl"'+
		 		' id="importurl"'+
		 		' size="61" placeholder="http://serverip:port/get.php&username=test&password=1234"/></font></td></tr>';
		 		
		 		// Upload Local FIles
				menustr1+='<tr><td  width=25%>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td colspan=3><form id="file_upload_form_movie" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';
		 		
				menustr1+='<tr><td width=50% colspan=2><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Submit" onclick=call_import_movie_definition() name="Submit" /></td>'+
				'<td width=50%  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_import_movie_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				// Edit Category
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMovieCategoryEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>Edit Category</b></font></td><td align=right id=movie_category_edit_dialog_message name=movie_category_edit_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
				// New Category Name
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Category:</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;color:#000000" type="text" name="editcategory"'+
		 		' id="editcategory"'+
		 		' size="40"></font></font></td></tr>';
		 		
								
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstart_moviecategory_add_input()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="edit_category_url"'+
		 		' id="edit_category_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="edit_file_upload_form_movie_category_icon" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Edit_Movie_Category() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_movie_category_edit_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				// Add New Category
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMovieCategoryAdd" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>New Category</b></font></td><td align=right id=movie_category_add_dialog_message name=movie_category_add_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
				// New Category Name
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Category:</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;color:#000000" type="text" name="newcategory"'+
		 		' id="newcategory"'+
		 		' size="40"></font></font></td></tr>';
		 		
								
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstart_moviecategory_add_input()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="add_category_url"'+
		 		' id="add_category_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="add_file_upload_form_movie_category_icon" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Movie_Category() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_movie_category_add_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				// Edit ICON Path
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalICONURLEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>New / Edit Channel icon</b></font></td><td align=right id=icon_url_edit_dialog_message name=icon_url_edit_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
					
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;color:#00000" type="text" name="edit_icon_url"'+
		 		' id="edit_icon_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="file_upload" enctype="multipart/form-data">'+
				'<input type="file" name="Video"/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Edit_ICON(2) name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_icon_edit_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';

		      menustr1+='</tr>'+
		      '</table>';
		      
		if (total_count==0)
		{
			current_position=0;
			endposition=0;
		}else
		{
			endposition=current_position+total_no-1;
		}
		menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
		menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' movies</td>';
		position=1;
		limit=g_constant_limit;
		if (total_count>g_constant_limit)
	{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:call_get_first_movie('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:call_get_movies('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	//}
  	
	content.innerHTML=menustr1+HTML_str+'</table>'+menustr2;
	g_SearchInput = document.getElementById("search_field");
     	if (g_search_text.length>0)
     	{
     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
     		g_SearchInput.focus();
     	}
	if (g_add_movie_flag==1)
	{
		open_modal();
	}else if (g_add_movie_flag==2)
	{
		open_upload_movie_modal();
	}
	g_add_movie_flag=0;
	
 }

 
}
function Show_Series_Category()
{
	var series_category_id= document.getElementById('series_category');
	var series_category_no_id= document.getElementById('total_no');
	
	var str;
	var categoryname;
 	var categoryicon;
 	
 	if (xmlHttp.readyState == 4) {
 		var response = xmlHttp.responseText.split("\r\n");
 		var i=0;
		var modal = document.getElementById('PanelModalSeriesCategory');
		g_total_series_category_no=0;
		modal.style.display = "block";
		/*
		str='<font face="Arial" size="2">'+' <select size="10"  style="width: 500;padding:5;" name="series_category_list" id=series_category_list>';
 		while (1)
		{
 			if (response[i]==0) break;
 			categoryname=response[i].substring(9);
 			g_Series_Categories_tems[i]=categoryname; 
	 	    	g_total_series_category_no++;
 			//alert(categoryname);
 			if (i==0)
 			{
	 			str+='<option style="padding: 2px" selected="selected" value="'+decodeURI(categoryname)+'">'+decodeURI(categoryname)+'</option>';
 			}else
 			{
	 			str+='<option style="padding: 2px" value="'+decodeURI(categoryname)+'">'+decodeURI(categoryname)+'</option>';
	 		}
	 		i++;
	 	}
 		str+='</select></font>';
 		series_category_id.innerHTML=str;
 		series_category_no_id.innerHTML='<font face="Arial" size="2">'+i+'</font>';
 		document.getElementById('Add').focus();	
 		*/
 		
 		// use drag way to move item -- start
 		str='<div class="scroll-container"><font face="Arial" size="2">'+' <ul id="category_list" class="draggable-list"  style="list-style-type: none;width: 500;padding:5;" name="series_category_list" id=series_category_list>';
		//alert(g_categoryclickedItemValue);
		if (g_categoryclickedItemValue)
		{
			while (1)
			{
	 			if (response[i]==0) break;
	 			categoryname=response[i].substring(9);
	 			g_Series_Categories_tems[g_total_series_category_no]=categoryname;
	 			i++;
			 	categoryicon=response[i].substring(5);
			 	g_Series_Categories_icons[g_total_series_category_no]=categoryicon;
			 	
	 			g_total_series_category_no++; 
		 	    	//alert(categoryname);
	 			if (g_categoryclickedItemValue==categoryname)
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: #aaa;padding: 5px;border: 1px solid #000;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" selected="selected" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 			
	 			}else
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: white;padding: 5px;border: 1px solid #ccc;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 		}
		 		i++;
		 		i++;
		 	}
		}else
		{
			while (1)
			{
	 			if (response[i]==0) break;
	 			categoryname=response[i].substring(9);
	 			g_Series_Categories_tems[g_total_series_category_no]=categoryname;
	 			i++;
			 	categoryicon=response[i].substring(5);
			 	g_Series_Categories_icons[g_total_series_category_no]=categoryicon;
			 	
	 			g_total_series_category_no++; 
		 	    	//alert(categoryname);
	 			if (i==0)
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: #aaa;padding: 5px;border: 1px solid #000;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" selected="selected" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 			g_categoryclickedItemValue=categoryname;
	 			}else
	 			{
		 			str+='<li draggable="true" style="display: flex; align-items: center;background-color: white;padding: 5px;border: 1px solid #ccc;margin-bottom: 5px;cursor: grab;transition: background-color 0.3s ease;" value="'+decodeURI(categoryname)+'">'+'<span style="display: inline-block; background-color: #F5F6F8; padding: 0; width: 30px; height: 30px;">' +
							    '<img src="' + categoryicon + '" style="height: 100%; width: 100%; object-fit: cover;"></img>' +
							    '</span>'+decodeURI(categoryname)+'</li>';
		 		}
		 		i++;
		 		i++;
		 	}
	 	}
	 	str+='</ul></font></div>';
 		series_category_id.innerHTML=str;
 		series_category_no_id.innerHTML='<font face="Arial" size="2">'+g_total_series_category_no+'</font>';
 		document.getElementById('Add').focus();
 		sortable_list = document.getElementById("category_list");
		sortable_listItems = sortable_list.querySelectorAll("li");
		let draggedItem = null;
		
		
		sortable_list.addEventListener("dragstart", (event) => {
		  draggedItem = event.target;
		  draggedItem.classList.add("dragging");
		  event.dataTransfer.effectAllowed = "move";
		  event.dataTransfer.setData("text/html", draggedItem.innerHTML);
		});
		
		sortable_list.addEventListener("dragover", (event) => {
		  event.preventDefault();
		  const afterElement = getDragAfterElement(sortable_list, event.clientY);
		
		  if (afterElement == null) {
		    sortable_list.appendChild(draggedItem);
		  } else {
		    sortable_list.insertBefore(draggedItem, afterElement);
		  }
		});
		
		sortable_list.addEventListener("dragend", () => {
		  draggedItem.classList.remove("dragging");
		  updateItemIndexes();
		});
		// Add click event listeners to each item
		sortable_listItems.forEach((item) => {
		  item.addEventListener("click", (event) => {
		    sortable_listItems.forEach((item) => {
		    item.style.backgroundColor = "#fff";
		      item.classList.remove("clicked");
		    });
		    
		    event.currentTarget.classList.add("clicked");
		
		    // Show the clicked item's value
		    //const clickedItemValue = event.currentTarget.innerText;
		    //alert(`Clicked Item Value: ${clickedItemValue}`);
		    event.currentTarget.style.backgroundColor = "#aaa";
		    g_categoryclickedItemValue = event.currentTarget.innerText;

		  });
		});
		// use drag way to move item -- end
 	}
 	
 	

}
function open_series_category_modal()
{
 	var cgi_url;
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/get_series_category?token="+encodeURI(g_token)+"&icon=1"+"&serverid=1"+"&flag="+Math.random();
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Show_Series_Category;
	xmlHttp.send(null);
}
function close_series_category_modal() {
   var modal = document.getElementById('PanelModalSeriesCategory');
   modal.style.display = "none";
   g_categoryclickedItemValue=null;
   call_get_series(g_series_position,g_series_limit);
}
function close_series_modal() {
   var modal = document.getElementById('PanelModal');
   modal.style.display = "none";
   //g_series_position=1;
   //g_series_limit=g_constant_limit;
   call_get_series(g_series_position,g_series_limit);
}

// Import Series S
function call_Import_Series()
{
 	var cgi_url;
	var importurl =document.getElementById("importurl").value;
	var importbutton=document.getElementById("submitbutton");
	var g_message;
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		alert("Only for Formal version");
		return;
	}

	importbutton.disabled=true;
	importbutton.value="Waiting";
	//var importstartingno =document.getElementById("importseriesno").value;
	if (importurl.length>0)
	{	
		g_token=find_cookie_value("token");
		cgi_url = "/server/import_series?token="+encodeURI(g_token)+"&importurl="+encodeURI(importurl)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			var import_series_dialog_message=document.getElementById("import_series_dialog_message");
			if (response=="0")
			{
				//alert("Failed to Import");
				import_series_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import</font>';
			}else
			{
				g_total_series_no=parseInt(g_total_series_no)+parseInt(response);
				
				import_series_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' series added</font>';
				
				
			}
			importbutton.disabled=false;
			importbutton.value="Submit";
			
			
		    }
		};
				 
		xmlHttp.send(null);
	}else
	{
		api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"series_m3u"+"&flag="+Math.random();

		call_Upload_Files(event,UPLOAD_SERIES_M3U,api_option);

		
	}
	
}
function open_series_import_modal()
{
	var modal = document.getElementById('PanelModalSeriesImport');
	modal.style.display = "block";	
	
}
function close_series_import_modal() {
   var modal = document.getElementById('PanelModalSeriesImport');
   var importbutton=document.getElementById("submitbutton");
   importbutton.disabled=false;
   importbutton.value="Submit";
 
   modal.style.display = "none";
   g_series_position=1;
   g_series_limit=g_constant_limit;
   call_get_series(g_series_position,g_series_limit);
   
}
// Import Series E
/* function close_update_series_category_modal() {
	var modal = document.getElementById('PanelModalSeriesCategory');
	modal.style.display = "none";
	g_categoryclickedItemValue=null;
	
	
	var updatestr="";
	var str;
	const listItems = sortable_list.querySelectorAll("li");
	listItems.forEach((item, index) => {
	str='{"id":"'+index+'","name":"'+item.innerText+'"}';
	
	if (updatestr)
	{
		updatestr=updatestr+','+str;
	}else
	{
		updatestr=updatestr+str;
	}
	});
	cgi_url = "/server/write_category_json?token="+encodeURI(g_token)+"&type=3"+"&len="+updatestr.length+"&category_list="+updatestr+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) {
			call_get_series(g_series_position,g_series_limit);
		}
	}
	xmlHttp.send(null);
		
	
}
*/
function close_update_series_category_modal() {
	var modal = document.getElementById('PanelModalSeriesCategory');
	modal.style.display = "none";
	g_categoryclickedItemValue=null;
	
	
	var updatestr="";
	var str;
	const listItems = sortable_list.querySelectorAll("li");
	listItems.forEach((item, index) => {
	str='{"id":"'+index+'","name":"'+item.innerText+'","icon":"'+g_Series_Categories_icons[index]+'"}';
	
	if (updatestr)
	{
		updatestr=updatestr+','+str;
	}else
	{
		updatestr=updatestr+str;
	}
	});
	cgi_url = "/server/write_category_json?token="+encodeURI(g_token)+"&type=3"+"&flag="+Math.random();
	
	
	xmlHttp.open("POST", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) {
			call_get_series(g_series_position,g_series_limit);
		}
	}
	xmlHttp.send(updatestr);
		
	
}
function open_series_category_add_modal()
{
	var modal = document.getElementById('PanelModalSeriesCategoryAdd');
	modal.style.display = "block";	
	
}
function close_series_category_add_modal() {
   var modal = document.getElementById('PanelModalSeriesCategoryAdd');
   var button=document.getElementById("submitbutton");
   button.disabled=false;
   button.value="Submit";
  // close_series_category_modal();
   modal.style.display = "none";   
   open_series_category_modal();
}
function open_series_category_edit_modal()
{
	var modal = document.getElementById('PanelModalSeriesCategoryEdit');
	modal.style.display = "block";	
	var category= document.getElementById('editcategory');
	var current_category_url=document.getElementById('edit_category_url');
	var i;
	category.value=g_categoryclickedItemValue;
	for (i=0;i<g_total_series_category_no;i++)
	{
		if (g_categoryclickedItemValue==g_Series_Categories_tems[i])
		{
			current_category_url.value=g_Series_Categories_icons[i];
			current_category_url.style.color='#000000';
			break;
		}
	}
}
function close_series_category_edit_modal() {
   var modal = document.getElementById('PanelModalSeriesCategoryEdit');
   var button=document.getElementById("submitbutton");
   button.disabled=false;
   button.value="Save";
    modal.style.display = "none";   
   open_series_category_modal();
}
function onstart_seriescategory_add_input()
{
	document.getElementById("add_category_url").style.color = '#000000';
}
function onstart_seriescategory_edit_input()
{
	document.getElementById("edit_category_url").style.color = '#000000';
}
function call_Add_Series_Category()
{
 	var cgi_url;
 	var api_option;
 	var category_url =document.getElementById("add_category_url").value;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var newcategory = document.getElementById("newcategory").value;
	
	if (newcategory)
	{
		if (category_url.length>0)
		{
			cgi_url = "/server/add_series_category?token="+encodeURI(g_token)+"&iconurl="+category_url+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}else
		{
			cgi_url = "/server/add_series_category?token="+encodeURI(g_token)+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}
		
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		//alert(cgi_url);
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			if (xmlHttp.readyState == 4) {
				
		 		var response = xmlHttp.responseText;
		 		/*
			 	var add_button = document.getElementById('Add');
				var edit_button = document.getElementById('Edit');
				var del_button = document.getElementById('Del');
				open_series_category_modal();
				if (response==2)
		 		{
		 			document.getElementById('series_category_add_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
		 		}else
		 		{
		 			document.getElementById('series_category_add_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Added</font>';
		 		}
		 		add_button.disabled=false;
				edit_button.disabled=false;
				del_button.disabled=false;
				*/
				if (category_url.length==0)
				{
			 		api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"series_icon"+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
	
					call_Upload_Files(event,UPLOAD_SERIES_CATEGORY_ICON,api_option);
				}else
				{
					close_series_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Added</font>';
			 		}
					add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
					
				}


			}
		}
		xmlHttp.send(null);
	}

	
}

/*
function call_Add_Series_Category()
{
 	var cgi_url;
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var category = prompt("Please enter category:", "");

	if (category)
	{	
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		cgi_url = "/server/add_series_category?token="+encodeURI(g_token)+"&newcategory="+encodeURI(category)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			 if (xmlHttp.readyState == 4) {
			 	
		 		var response = xmlHttp.responseText;
			 	var add_button = document.getElementById('Add');
				var edit_button = document.getElementById('Edit');
				var del_button = document.getElementById('Del');
				open_series_category_modal();
				if (response==2)
		 		{
		 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+category+' Existed</font>';
		 		}else
		 		{
		 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+category+' Added</font>';
		 		}
		 		add_button.disabled=false;
				edit_button.disabled=false;
				del_button.disabled=false;
			}
		};
		xmlHttp.send(null);
	}
	
}
*/
function call_Edit_Series_Category()
{
 	var cgi_url;
	var currentcategory =g_categoryclickedItemValue
	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
	var category_url =document.getElementById("edit_category_url").value;
	var newcategory = document.getElementById("editcategory").value;
	if (newcategory)
	{	
		add_button.disabled=true;
		edit_button.disabled=true;
		del_button.disabled=true;
		g_token=find_cookie_value("token");
		if (category_url.length>0)
		{
			cgi_url = "/server/edit_series_category?token="+encodeURI(g_token)+"&currentcategory="+encodeURI(currentcategory)+"&newcategory="+encodeURI(newcategory)+"&iconurl="+category_url+"&flag="+Math.random();
		}else
		{
			cgi_url = "/server/edit_series_category?token="+encodeURI(g_token)+"&currentcategory="+encodeURI(currentcategory)+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		}
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			 if (xmlHttp.readyState == 4) {
			 	
		 		var response = xmlHttp.responseText;
			 	/*
			 	var add_button = document.getElementById('Add');
				var edit_button = document.getElementById('Edit');
				var del_button = document.getElementById('Del');
		 		open_series_category_modal();
				if (response==2)
		 		{
		 			document.getElementById('series_category_edit_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: '+newcategory+' Existed</font>';
		 		}else
		 		{
		 			document.getElementById('series_category_edit_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+newcategory+' Updated</font>';
		 			g_categoryclickedItemValue=newcategory;
		 		}
		 		add_button.disabled=false;
				edit_button.disabled=false;
				del_button.disabled=false;
				*/
				if ((category_url.length==0) || (category_url.startsWith("upload")))
				{
					api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"series_icon"+"&newcategory="+encodeURI(newcategory)+"&flag="+Math.random();
		
					call_Upload_Files(event,EDIT_UPLOAD_SERIES_CATEGORY_ICON,api_option);
				}else
				{
					close_series_category_add_modal();
					var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
					if (response==2)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#ff0000 face="Arial">Warning: Existed</font>';
			 		}else
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+'Updated</font>';
			 		}
					add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
				}
		 	}
		};
		xmlHttp.send(null);
	}
	
}

function call_Del_Series_Category()
{
 	var cgi_url;
	var confirm_msg;

	var add_button = document.getElementById('Add');
	var edit_button = document.getElementById('Edit');
	var del_button = document.getElementById('Del');
 	var category=g_categoryclickedItemValue;
	if (category.length>0)
	{	
			add_button.disabled=true;
			edit_button.disabled=true;
			del_button.disabled=true;
			g_token=find_cookie_value("token");
			cgi_url = "/server/del_series_category?token="+encodeURI(g_token)+"&delcategory="+encodeURI(category)+"&flag="+Math.random();
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = function()
			{
				 if (xmlHttp.readyState == 4) {
				 	
			 		var response = xmlHttp.responseText;
			 	 	var add_button = document.getElementById('Add');
					var edit_button = document.getElementById('Edit');
					var del_button = document.getElementById('Del');
			 		open_series_category_modal();
			 		if (response==1)
			 		{
			 			document.getElementById('category_dialog_message').innerHTML='<font size=2 color=#000000 face="Arial">'+category+' Deleted</font>'
			 		}
			 		add_button.disabled=false;
					edit_button.disabled=false;
					del_button.disabled=false;
			 	}
			};
			xmlHttp.send(null);
	}
}
function change_released_date_input_color(timeid)
{
	document.getElementById(timeid).style.color = "#000000";
}
function change_iconurl_input_color()
{
	document.getElementById("iconpath").style.color = "#000000";
}
function change_season_no_input_color()
{
	document.getElementById("season_no").style.color = "#000000";
}
function Add_Series() {

  
}
function call_Add_Series()
{

	var series_src_no="series_no"; 
	var series_src_name="seriesname"; 
	var series_src_category="seriescategory"; 
	var icon_path_name="iconpath"; 
	var series_src_season_no="season_no"; 
	var series_src_rating="rating"; 
	var series_src_released_date="released_date"; 
	var series_src_description="description"; 

	var series_no;
	var series_name;
	var series_category;
	var icon_path;
	var series_season_no; 
	var series_rating; 
	var series_released_date; 
	var series_description; 
	var g_item_name;

 var add_new_series_button=document.getElementById("add_new_series_button");
 var add_series_dialog_message=document.getElementById("add_series_dialog_message");
var seriesnoitem;
 var seriesnameitem;
 
	var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
	g_item_name=document.getElementById(series_src_no);
	seriesnoitem=g_item_name;
	series_no = g_item_name.value;
	//alert(series_no);
	
	g_item_name=document.getElementById(series_src_name);
	seriesnameitem=g_item_name;
	series_name = g_item_name.value;
	//alert(series_name);
	if (series_name.length==0)
	{
	alert("Series Name is empty");
	return;
	}
	
	g_item_name=document.getElementById(series_src_category);
	series_category = g_item_name.value;
	//alert(series_category);
	g_item_name=document.getElementById(icon_path_name);
	icon_path = g_item_name.value;
	//alert(icon_path);
	g_item_name=document.getElementById(series_src_season_no);
	series_season_no = g_item_name.value;
	//alert(series_season_no);
	g_item_name=document.getElementById(series_src_rating);
	series_rating = g_item_name.value;
	//alert(series_rating);
	g_item_name=document.getElementById(series_src_released_date);
	series_released_date = g_item_name.value;
	//alert(series_released_date);
	g_item_name=document.getElementById(series_src_description);
	series_description = g_item_name.value;
	//alert(series_description);

	g_token=find_cookie_value("token");
	g_series_no=series_no;
	cgi_url = "/server/add_series?token="+encodeURI(g_token)+"&series_no="+encodeURI(series_no)+ "&series_name=" + encodeURI(series_name)+
	"&category=" + encodeURI(series_category)+ "&img=" + encodeURI(icon_path)+ "&rating=" + encodeURI(series_rating)+
	"&description=" + encodeURI(series_description)+
	"&season_no=" + series_season_no+ "&released_date=" + series_released_date+"&flag="+Math.random();
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
		    var item_save;
		    var item_add;
		   var item_copy;
		    var item_del;
		   var item_refresh;
		   var item_more;
		    var item_play;
		    if (response==1)
		    {
		    	g_total_series_no++;
		    	if ((g_series_position+g_constant_limit)<=g_total_series_no)
			{
				if (((g_total_series_no)%g_constant_limit)==1)
				{
					g_series_position=parseInt(g_total_series_no);
				}
				g_series_limit=g_constant_limit;
			}else
			{
				g_series_limit=g_total_series_no%g_constant_limit;
				if (g_series_limit==0) 
				{
					if (g_total_series_no<g_series_position)
					{
						g_series_position=g_total_series_no-g_constant_limit+1;
					}
					g_series_limit=g_constant_limit;
				}
			}
			close_series_modal();
			/*
			add_new_series_button.value="Add Next";
			var new_add_total_no=g_total_series_no+1;
			add_series_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+series_name+' Added</font>';
			//alert(new_add_total_no);
			seriesnoitem.value=new_add_total_no;
			seriesnameitem.value="";
			seriesnameitem.focus();
			*/
			//call_get_series(g_series_position,g_series_limit);
		   } else
		    {
		   	alert("Failed to Add Series");
		    }
		
			
		    }
	 };
	 xmlHttp.send(null);


}
function delete_selected_series() {

 
         if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		g_total_series_no-=g_selectedcounter;
		if (g_total_series_no<0) g_total_series_no=0;
		if ((g_series_position+g_constant_limit)<=g_total_series_no)
		{
			g_series_limit=g_constant_limit;
		}else
		{
			g_series_limit=g_total_series_no%g_constant_limit;
			if (g_series_limit==0) 
			{
				if (g_total_series_no>0)
				{
					if (g_total_series_no<g_series_position)
					{
						g_series_position=g_total_series_no-g_constant_limit+1;
					}
					g_series_limit=g_constant_limit;
				}else
				{
					g_series_limit=0;
				}
			}
		}

	}else
	{
		alert("Failed to Delete Files");
	}
	
	call_get_series(g_series_position,g_series_limit);
    }
}
function get_checked_series(total_no)
{
	var i=0;
	var chcheckbox;
	var checkboj;
	var checkedstring="";
	var seriesid;
	var series;
	g_selectedcounter=0;

 	for (i=1;i<=total_no;i++)
	{
		chcheckbox="checkbox"+i;
		checkboj=document.getElementById(chcheckbox);
		if (checkboj)
		{
			if (checkboj.checked==true)
			{
				g_selectedcounter++;
				seriesid="seriesname"+i;
				
				series=document.getElementById(seriesid).innerText;
				
				checkedstring+=series+"\r\n";
			}
		}
	}
	//alert(checkedstring);
	if (checkedstring.length==0)
	{
		//alert("4. No selected item");
	}
	
	return checkedstring;
}
function open_mass_delete_series_modal()
{
	var modal = document.getElementById('PanelModalMassDelete');
	checkedstring=get_checked_series(g_total_series_no);
	if (checkedstring=="")
	{
		modal.style.display = "block";
	}else
	{
	
		 confirm_msg="Delete Selected seriess?";
		 cgi_url = "/server/del_multiple_series?token="+encodeURI(g_token)+"&position="+g_series_position+"&bitstring="+checkedstring+ "&flag="+Math.random();
		 if (confirm(confirm_msg))
		 {	
			 xmlHttp.open("POST", cgi_url, true);
			 xmlHttp.onreadystatechange = delete_selected_series;
			 xmlHttp.send(checkedstring);
			
		 }
	 }
	
}

function callezserver_mass_delete_selected_series()
{
	var confirm_msg;
	var category=document.getElementById('mass_delete_category').value;
	var delbutton=document.getElementById('delete_button');
	
   	g_token=find_cookie_value("token");
   	
	 confirm_msg="Delete Selected "+category+"?";
	 cgi_url = "/server/del_multiple_series?token="+encodeURI(g_token)+"&position="+g_series_position+"&category="+category+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	if (delbutton)
	 	{
	 		delbutton.value="Waiting";
	 		delbutton.disabled=true;
	 	}	
		 xmlHttp.open("POST", cgi_url, true);
		 xmlHttp.onreadystatechange = function()
		 {
		 	if (xmlHttp.readyState == 4) {
				var response = xmlHttp.responseText;
				if (response>=1)
				{
					if (response>1)
					{
						g_selectedcounter=parseInt(response);
					}
					g_total_series_no-=g_selectedcounter;
					if (g_total_ch_no<0) g_total_ch_no=0;
					if ((g_series_position+g_constant_limit)<=g_total_ch_no)
					{
						g_series_limit=g_constant_limit;
					}else
					{
						g_series_limit=g_total_ch_no%g_constant_limit;
						if (g_series_limit==0)
						{
							if (g_total_ch_no>0)
							{
								if (g_total_ch_no<g_series_position)
								{
									g_series_position=g_total_ch_no-g_constant_limit+1;
								}
								g_series_limit=g_constant_limit;
							}else
							{
								g_series_limit=0;
							}
						}
					}
			
				}else
				{
					alert("Failed to Delete Users");
				}
				if (delbutton)
			 	{
			 		delbutton.value="Delete";
			 		delbutton.disabled=false;
			 	}
				call_get_series(g_series_position,g_series_limit);
		    	}
		 };
		 xmlHttp.send(checkedstring);
	 }
 


}
var g_cur_series_no;
var g_series_name;

function Get_Series_Profile() {

  if (xmlHttp.readyState == 4) {
		
		var season_no;
		var rating;
		var released_date;
		var iconpath;
		var szdescription;
		var seriescategory;
		var i=0;
		var j=0;
		var str;
		var groupname;
		var response = xmlHttp.responseText.split("\r\n");
		var modal = document.getElementById('PanelModalSeriesUpdate');
		modal.style.display = "block";
		while (1)
		{
		   	if (response[i]==0) break;
		   	//alert(response[i]);
			g_item=document.getElementById("update_series_no");
			g_item.innerHTML='<font face="Arial" size="2"><b>'+g_cur_series_no+'</b></font>';
		   	
			//alert(response[i]);
			strlength=response[i].length;
			g_series_name=response[i].slice(7,strlength);
			i=i+1;	
			g_item=document.getElementById("update_seriesname");
			g_item.value=g_series_name;
	
			//alert(response[i]);
			strlength=response[i].length;
			iconpath=response[i].slice(4,strlength);
			i=i+1;	
			g_item=document.getElementById("update_iconpath");
			g_item.value=iconpath;

			strlength=response[i].length;
			seriescategory=response[i].slice(9,strlength);
			//alert(seriescategory);
			i=i+1;	
		 	g_item=document.getElementById("update_seriescategory");
			g_item.value=decodeURI(seriescategory);


			//alert(response[i]);
			strlength=response[i].length;
			rating=response[i].slice(7,strlength);
			i=i+1;	
			g_item=document.getElementById("update_rating");
			g_item.value=rating;
		
			//alert(response[i]);
			strlength=response[i].length;
			szdescription=response[i].slice(12,strlength);
			i=i+1;	
			g_item=document.getElementById("update_description");
			g_item.value=szdescription;

			//alert(response[i]);
			strlength=response[i].length;
			season_no=response[i].slice(10,strlength);
			i=i+1;	
			g_item=document.getElementById("update_season_no");
			g_item.value=season_no;
			
			//alert(response[i]);
			strlength=response[i].length;
			released_date=response[i].slice(14,strlength);
			i=i+1;	
			g_item=document.getElementById("update_released_date");
			g_item.value=released_date;
			
			//alert(response[i]);
	     	 	strlength=response[i].length;
	   	    	genre=response[i].slice(6,strlength);
	   	    	//alert(genre);
	   	    	if (genre.length>0)
	   	    	{
		   	    	genre_items=genre.split(",");
		   	    	for (m=0;m<genre_items.length;m++)
		   	    	{
		   	    		var listItem = createSeriesListItem(genre_items[m]);
					document.getElementById('selectedItemsList').appendChild(listItem);
				}
			}			
			i=i+1;	
			
			
		}

	}
}
function open_modal_series_Update(series_no, seriesname)
{
	g_cur_series_no=series_no;
	//alert(g_cur_series_no);
		
	g_token=find_cookie_value("token");
	genre_items=[];
	document.getElementById('selectedItemsList').innerHTML = '';

 	var cgi_url = "/server/get_series_profile?token="+encodeURI(g_token)+"&name="+seriesname+
	 "&flag="+Math.random();
	//alert(cgi_url);	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Get_Series_Profile;
	 xmlHttp.send(null);

	
}
function Update_Series() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var item_save;
    var item_add;
   var item_copy;
    var item_del;
   var item_refresh;
   var item_more;
    var item_play;
    if (response==1)
    {
	call_get_series(g_series_position,g_series_limit);
   } else
    {
   	alert("Failed to Update Series");
    }

	
    }
}
function call_Update_Series()
{
	//var series_src_no="update_series_no"; 
	var series_src_name="update_seriesname"; 
	var series_src_category="update_seriescategory"; 
	var icon_path_name="update_iconpath"; 
	var series_src_season_no="update_season_no"; 
	var series_src_rating="update_rating"; 
	var series_src_released_date="update_released_date"; 
	var series_src_description="update_description"; 

	//var series_no;
	var series_name;
	var series_category;
	var icon_path;
	var series_season_no; 
	var series_rating; 
	var series_released_date; 
	var series_description; 
	var g_item_name;


	var cgi_url;
	
	//g_item_name=document.getElementById(series_src_no);
	//series_no = g_item_name.value;
	//alert(series_no);
	
	g_item_name=document.getElementById(series_src_name);
	series_name = g_item_name.value;
	//alert(series_name);
	if (series_name.length==0)
	{
	alert("Series Name is empty");
	return;
	}
	
	g_item_name=document.getElementById(series_src_category);
	series_category = g_item_name.value;
	//alert(series_category);
	g_item_name=document.getElementById(icon_path_name);
	icon_path = g_item_name.value;
	//alert(icon_path);
	g_item_name=document.getElementById(series_src_season_no);
	series_season_no = g_item_name.value;
	//alert(series_season_no);
	g_item_name=document.getElementById(series_src_rating);
	series_rating = g_item_name.value;
	//alert(series_rating);
	g_item_name=document.getElementById(series_src_released_date);
	series_released_date = g_item_name.value;
	//alert(series_released_date);
	g_item_name=document.getElementById(series_src_description);
	series_description = g_item_name.value;
	//alert(series_description);

	g_token=find_cookie_value("token");
	g_series_no=series_no;
	cgi_url = "/server/udpate_series_profile?token="+encodeURI(g_token)+ "&cur_name=" + encodeURI(g_series_name)+ "&series_name=" + encodeURI(series_name)+
	"&category=" + encodeURI(series_category)+ "&img=" + encodeURI(icon_path)+ "&rating=" + encodeURI(series_rating)+
	"&description=" + encodeURI(series_description)+
	"&season_no=" + series_season_no+ "&released_date=" + series_released_date+
	"&genre="+genre_items+
	"&flag="+Math.random();
	//alert(cgi_url);
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Update_Series;
	 xmlHttp.send(null);

	
}
function close_modal_series_Update()
{
	var modal = document.getElementById('PanelModalSeriesUpdate');
	modal.style.display = "none";
}
var g_cur_seriesname;
var g_series_movie_list_no;
var g_season_no;
var g_selected_episode_list_no;
var g_cur_season_no;

function Get_Episode_Movie_List() {

  if (xmlHttp.readyState == 4) {
		
		var i=0;
		var j=0;
		var str;
		var nTotalSelectedNo;
		var nTotalMovieNo;
		var response = xmlHttp.responseText.split("\r\n");
	   	str='<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+' <select size=20 multiple style="width: 180;" id="series_movie_list">';
		while (1)
		{
		   	if (response[i]==0) break;
			// Movie List
 			str+='<option value="'+response[i]+'">'+response[i]+'</option>';
 			i++;
		}
 		str+='</select></font></td>';
	   	g_item=document.getElementById("episode_movie_list");
		g_item.innerHTML=str;
		
		g_item=document.getElementById("episode_movie_list_no");
		g_item.innerHTML='<font face="Arial" size="2">Movie List(<b>'+i+'</b>):</font>';
		g_series_movie_list_no=i;
		   	

	}
}

function call_get_season_episode_response()
{
	 if (xmlHttp.readyState == 4) {
		
		var i=0;
		var str;
		var response = xmlHttp.responseText.split("\r\n");
		var Episocdename;
		var pIndex;
	   	
	   	str='<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+' <select size=20 multiple style="width: 180;padding:5;" name="selected_episode_list" id=selected_episode_list>';
 		while (1)
		{
		   	if (response[i]==0) break;
		   	//alert(response[i]);
		   	pIndex=response[i].lastIndexOf(" S");
		   	Episocdename=response[i].substring(pIndex+1);
 			str+='<option style="padding: 2px" value="'+Episocdename+'">'+Episocdename+'</option>';
 			i++;
 			//i++; // skip full name
		}
		//i=i/2;
		g_selected_episode_list_no=i;

		str+='</select></font></td>';
	   	g_item=document.getElementById("update_episode_list");
		g_item.innerHTML=str;
		g_item=document.getElementById("update_episode_list_no");
		g_item.innerHTML='<font face="Arial" size="2">Episode List(<b>'+i+'</b>):</font>';
		
	   	

	}
}
function call_get_season_episode()
{
	var season_no;
		
	//alert("1111111");
	g_token=find_cookie_value("token");
	g_item=document.getElementById("selected_season_list");
	//alert(g_item);
	season_no=g_item.value;
	g_cur_season_no=season_no;
	//alert(season_no);
	
	
	
 	var cgi_url = "/server/get_series_episode?token="+encodeURI(g_token)+"&name="+g_cur_seriesname+"&index="+season_no+
	 "&flag="+Math.random();
	//alert(cgi_url);	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = call_get_season_episode_response;
	 xmlHttp.send(null);

	
}
function Get_Series_Episode_Profile() {

  if (xmlHttp.readyState == 4) {
		
		var i=0;
		var j=0;
		var str;
		var response = xmlHttp.responseText.split("\r\n");
		var modal = document.getElementById('PanelModalEpisodeUpdate');
		modal.style.display = "block";
		g_item=document.getElementById("update_episode_no");
		g_item.innerHTML='<font face="Arial" size="2"><b>'+g_cur_series_no+'</b></font>';
	   	
		g_item=document.getElementById("update_series_episodename");
		g_item.innerHTML='<font face="Arial" size="2"><b>'+decodeURI(g_cur_seriesname)+'</b></font>';
	   	
		str='<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+' <select onchange=call_get_season_episode(); name="selected_season_list" id=selected_season_list>';
		for (j=1;j<=g_season_no;j++)
		{
			if (j==1) str+='<option selected="selected" value="'+j+'">'+"season "+j+'</option>';
			else str+='<option value="'+j+'">'+"season "+j+'</option>';
			
		}
		str+='</select></font></td></tr>';	
	   	g_item=document.getElementById("update_season_list");
		g_item.innerHTML=str;
				
	   	str='<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+' <select  size=20 multiple style="width: 180;padding:5;" name="selected_episode_list" id=selected_episode_list>';
		while (1)
		{
		   	if (response[i]==0) break;
		   	var pIndex=response[i].lastIndexOf(" S");
		   	var Episocdename=response[i].substring(pIndex+1);
 			str+='<option style="padding: 2px" value="'+Episocdename+'">'+Episocdename+'</option>';
  			i++;
 			//i++;
		}
		//i=i/2;
		str+='</select></font></td>';
	   	g_item=document.getElementById("update_episode_list");
		g_item.innerHTML=str;
		g_item=document.getElementById("update_episode_list_no");
		g_item.innerHTML='<font face="Arial" size="2">Episode List(<b>'+i+'</b>):</font>';
	   	g_selected_episode_list_no=i;
	   	
	   	/*g_token=find_cookie_value("token");

	 	var cgi_url = "/server/get_movie_list?token="+encodeURI(g_token)+"&flag="+Math.random();
		//alert(cgi_url);	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Get_Episode_Movie_List;
		 xmlHttp.send(null);
		 */
	}
}
function open_modal_Episode_Update(series_no,season_no, seriesname)
{
	g_cur_series_no=series_no;
	//alert(g_cur_series_no);
	g_cur_seriesname=seriesname;
	g_season_no=season_no;
	g_cur_season_no=1;
		
	g_token=find_cookie_value("token");

 	var cgi_url = "/server/get_series_episode?token="+encodeURI(g_token)+"&name="+seriesname+"&index=1"+
	 "&flag="+Math.random();
	//alert(cgi_url);	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Get_Series_Episode_Profile;
	 xmlHttp.send(null);

	
}
function Update_Episode() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var item_save;
    var item_add;
   var item_copy;
    var item_del;
   var item_refresh;
   var item_more;
    var item_play;
    if (response==1)
    {
//	call_get_series(g_series_position,g_series_limit);
  	alert("Update Series Sucessfully.");
 
   } else
    {
   	alert("Failed to Update Series");
    }

	
    }
}
function call_Update_Episode(seriesname)
{
	
	var confirm_msg;
	var cgi_url;
	var cookieStr;
	var checkedstring;
	
   	var mvoptions=document.getElementById("selected_episode_list");
 
	 var opt;
	// alert(g_selected_episode_list_no);
	 checkedstring="";
	 for (i=0;i<g_selected_episode_list_no;i++)
	 {
	 	opt=mvoptions[i];
	 	
	 	checkedstring+=opt.value+"\r\n";
	 }	
	// alert(g_cur_season_no);
	 g_token=find_cookie_value("token");
	//if (checkedstring.length==0)
	//{
	//}else
	//{
		//confirm_msg="Delete Selected Series?";
		cgi_url = "/server/udpate_series_episode?token="+encodeURI(g_token)+"&name="+g_cur_seriesname+"&index="+g_cur_season_no+ "&flag="+Math.random();
		//alert(cgi_url);
		//alert(checkedstring);
		xmlHttp.open("POST", cgi_url, true);
		xmlHttp.onreadystatechange = function()
		{
			
			if (xmlHttp.readyState == 4) {
			    var response = xmlHttp.responseText;
			  	var episode_update_dialog_message=document.getElementById("episode_update_dialog_message");
			   
			    if (response==1)
			    {
			//	call_get_series(g_series_position,g_series_limit);
			  //	alert("Update Series Sucessfully.");
			  	var updated_date=new Date();
				episode_update_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial"><b>'+String(updated_date.getHours()).padStart(2, "0")+":"+String(updated_date.getMinutes()).padStart(2, "0")+":"+String(updated_date.getSeconds()).padStart(2, "0")+' Updated</b></font>';

		
			 
			   } else
			    {
			   	//alert("Failed to Update Series");
			   	episode_update_dialog_message.innerHTML='<font face="Arial" size=2>Failed to Update</font>';
			  	
			    }
			
				
			    }
		};
		xmlHttp.send(checkedstring);
	
	//}
}
function close_modal_Episode_Update()
{
	var modal = document.getElementById('PanelModalEpisodeUpdate');
	modal.style.display = "none";
	call_get_series(g_series_position,g_series_limit);
}
function add_seriese_episocde()
{
 var mcoptions=document.getElementById("series_movie_list");
 var mvoptions=document.getElementById("selected_episode_list");
 
 var opt;
 //alert(g_selected_episode_list_no);
 for (i=0;i<g_series_movie_list_no;i++)
 {
 	opt=mcoptions[i];
 	//alert(opt.value);
 	//alert(opt.selected);
 	if (opt.selected)
 	{
 		//alert(opt.value);
 		var newoption=document.createElement("option");
 		newoption.text=opt.value;
 		mvoptions.add(newoption);
 		g_selected_episode_list_no++;
 					
 	}
 }
 //alert(g_selected_episode_list_no);
	g_item=document.getElementById("update_episode_list_no");
	g_item.innerHTML='<font face="Arial" size="2">Episode List(<b>'+g_selected_episode_list_no+'</b>):</font>';

}

function remove_series_episocde()
{
 var mvoptions=document.getElementById("selected_episode_list");
 
 var opt;
 //alert(g_selected_episode_list_no);
 for (i=g_selected_episode_list_no-1;i>=0;i--)
 {
 	opt=mvoptions[i];
 //	alert(opt.value);
 //	alert(opt.selected);
 	if (opt.selected)
 	{
 		//alert(opt.value);
 		mvoptions.remove(i);
 		g_selected_episode_list_no--;
 					
 	}
 }
 	g_item=document.getElementById("update_episode_list_no");
	g_item.innerHTML='<font face="Arial" size="2">Episode List(<b>'+g_selected_episode_list_no+'</b>):</font>';

}
function callezserver_mass_edit_selected_series()
{
	
	var cgi_url;
	var category_id="mass_edit_seriescategory";
	var season_no_id="mass_edit_season_no";
	var rating_id="mass_edit_rating";
	var released_date_id="mass_edit_released_date";
	
	


   
	var category;
	var season_no;
	var rating;
	var released_date;
	
	var i=0;	
	
   	g_token=find_cookie_value("token");
   	
//alert(g_checkedstring);	
	if (g_checkedstring=='0')
	{
	}else
	{

		g_item=document.getElementById(category_id);
		//alert(g_item.value);
		category=g_item.value;
		g_item=document.getElementById(season_no_id);
		//alert(g_item.value);
		season_no=g_item.value;
		g_item=document.getElementById(rating_id);
		//alert(g_item.value);
		rating=g_item.value;
		g_item=document.getElementById(released_date_id);
		//alert(g_item.value);
		released_date=g_item.value;

	
	   	g_token=find_cookie_value("token");
	
		cgi_url = "/server/edit_multiple_series?token="+encodeURI(g_token)+
		"&category="+category+
		"&season_no="+season_no+
		"&rating="+rating+
		"&released_date="+released_date;
		
		cgi_url +="&flag="+Math.random();
		//alert(cgi_url);
		 xmlHttp.open("POST", cgi_url, true);
		 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response!=1)
			{
				alert("Failed to Edit Movies");
			}
			close_mass_edit_series_modal();
			call_get_series(g_series_position,g_series_limit);
		    }
		};
				 
		xmlHttp.send(g_checkedstring);
	}
	

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


    var response = xmlHttp.responseText.split("\r\n");
	var series_no;
	var series_name;
	var series_category;
	var season_no;
	var released_date;
	var series_status;
    var series_play_id;
    var series_title="<p>"+"Series List"+"</p>";
    var series_list;
    var i=0;
    var j=0;
    var total_no=0;
	var series_active_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
    var content;
    	var ezcontent= document.getElementById("content")

  //var detail = parent.document.getElementById("detail");
	var refresh_keyword=null;
	var play_keyword=null;
	var save_keyword=null;
	var add_keyword=null;
	var del_keyword=null;
	var nduration =0;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_series_position;
	var total_count=g_total_series_no;
	var menustr1="";
	var menustr2="";
	var new_total_no;
	var k=0;
	var episode_no;
	var series_iconpath;
	var servername;
	
	var importurl;
	var importseriesno=g_total_series_no;
	var cellsize="18%";
	
	importurl='';
	g_start_search_option=4;
	for (gi = 0; gi < g_series_genre.length; gi++) 
	 {
	  	item = g_series_genre[gi];
	 	SeriesgenreObject[item.id] = item.name;
	}

	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="60%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Series</b></font>';
	str+='</td>';
	str+='<td>';
	if ((g_search_text.length==0)|| g_SearchInput.value=='Search Series...')
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Series..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}else
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}
	str+='</td>';	
	
	str += '<td>' +
       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
       '</select>' +
       '</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()">Add Series</a>';
		str+='</div>'; 
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="Button_Server_Series_Inquery()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 
		str+='<div class="menudropdown">';
		    str+='<button class="dropbtn" style="background-color: #414D5F">'; 
		    str+='<i class="fa fa-caret-down"></i>';
		    str+='</button>';
		    str+='<div class="menudropdown-content">';
		      str+='<a href="javascript:open_series_category_modal()">Category</a>';
		      if (g_search_text.length==0)
		      {
		     	 str+='<a href="javascript:open_mass_delete_series_modal()">Mass Delete</a>';
		      }
		      str+='<a href="javascript:open_series_import_modal()">Import M3U</a>';
		    str+='</div>';
		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;
	//parent.document.getElementById("page_no").value=g_constant_limit;	
	/*
	var menu_screen= document.getElementById("ezmenu");
	var search_field= document.getElementById("title_search_field");
	var search_button= document.getElementById("title_search_button");
	search_field.hidden=false;
	search_button.hidden=false;
		document.getElementById("menu_title_text").innerHTML='<font face="Arial" color=#000000 size="6">Series</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_series_category_modal()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Category</button>'; 
		str+='<button class="button" onclick="open_modal()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Add Series</button>'; 
		//str+='<button class="button" onclick="open_mass_edit_series_modal()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Mass Edit Series</button>'; 
		str+='<button class="button" onclick="callezserver_delete_selected_series('+g_total_series_no+')"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Del Series</button>'; 
		str+='<button class="button" onclick="open_series_import_modal()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Import Series</button>'; 
	str+='</div>';                              

	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");

	content.innerHTML="";
//	detail.innerHTML="";
	
	g_search_series_item.value=null;

	 HTML_str= '<table border="0" style="margin-top: 20px;" width=90% align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"><input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_series_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td  id="series_name_id" width="200" align="left"><font face="Arial" size="2">Series Name</font>';
	      if (g_series_name_order_flag==0)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_series_name_order_flag==1)
	      {
	      	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_series_name_order_flag==2)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
	      }
	      HTML_str+='</td>'+
	      '<td id="category_id" width="300" align="left"><font face="Arial" size="2">Main Category</font>';
	      if (g_series_category_order_flag==0)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_series_category_order_flag==1)
	      {
	      	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
	      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_descending("category") title="Z to A">'+'&#x25bc'+'</a></font>';
	      }else if (g_series_category_order_flag==2)
	      {
	      	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_series_ascending("category") title="A to Z">'+'&#x25b2'+'</a></font>'+
	      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
	      } 
	      HTML_str+='</td>'+
	      '<td align="center"><font face="Arial" size="2">Season no.</font></td>'+
	      '<td align="center"><font face="Arial" size="2">Episode</font></td>'+
	      '<td align="center"><font face="Arial" size="2">Released Date</font></td>'+
 	      '<td align="center"><font face="Arial" size="2">Server</font></td>'+
 	 '</tr>'+'<tr><td  colspan="8"><hr size="1" color="#66FFFF"></td></tr>';
 	series_no=current_position;
	while (1)
	{
 		//alert(response[i]);
	 	if (response[i]==0) break;
  	 	//series_no=k;
   	 	k++;
 	 	//strlength=response[i].length;
   	    	//series_no=response[i].slice(8,strlength);
   	    	
     	 	//strlength=response[i+1].length;
     	 	//series_name=response[i+1].slice(5,strlength);
   	    	
   	    	strlength=response[i].length;
     	 	series_name=response[i].slice(7,strlength);
     	 	i++;
    	 	strlength=response[i].length;
 	    	series_category=response[i].slice(9,strlength);
    	 	
    	 	i++;
    	 	strlength=response[i].length;
 	    	series_iconpath=response[i].slice(4,strlength);
 	    	
    	 	i++;
  	 	strlength=response[i].length;
 	    	season_no=response[i].slice(10,strlength);
 	    	
 	    	i++;
  	 	strlength=response[i].length;
 	    	episode_no=response[i].slice(8,strlength);
 	    	
    	 	i++;
 	 	strlength=response[i].length;
 	    	released_date=response[i].slice(14,strlength);
    	 	i++;
  	 	
 	 	strlength=response[i].length;
 	    	servername=response[i].slice(9,strlength);
    	 	i++;
   
 		
		series_active_no++;
		HTML_str=HTML_str+
		   '<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		   '<td width="20" align="center">';
		      if (g_series_found_position==series_no)
		      {
	 		HTML_str+=' <input type="checkbox" checked name=checkbox'+series_no;
	 	      }else
	 	      {
	 		HTML_str+=' <input type="checkbox" name=checkbox'+series_no;
	 	      }
	 	      HTML_str+=' id=checkbox'+series_no+'></td>';

	 		
		      HTML_str+='<td width="30" align="left" id=series_no><font face="Arial" size="2">'+series_no+'</font></td>';
			
			
			HTML_str+='<td width="'+cellsize+'" align="left" id="seriesname'+series_no+'">'+
			"<a href='javascript:void(0)'"+' onclick=open_modal_series_Update("'+series_no+'","'+encodeURI(series_name)+'")>'+
			' <font face="Arial" font size="2">'+
			decodeURI(series_name)+'</font></a>';

			series_no++;
			HTML_str+='<div id="PanelModalSeriesUpdate" class="modal">'+
			'<div class="modal-content">';
				
				HTML_str+='<table  cellpadding="0" cellspacing="10" align="center">';
				HTML_str+='<tr><td  id=series_name colspan=2 align=left><font face="Arial" size="6"><b></b></font></td><td colspan=2 align=right id=update_series_dialog_message name=update_series_dialog_message></td></tr>';
				HTML_str+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
    				HTML_str+='<tr><td width=25%><font face="Arial"><font size="2">Series at </font></td><td id="update_series_no" width=25%>'+
				'  <font face="Arial" size="2">'+
				'</font></td>';
				
				HTML_str+='<td width=25%><font face="Arial" font size="2">Series Name : </font></td><td  width=25%>'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="update_seriesname"'+
				 	' id=update_seriesname'+
				 	' size="16"/'+
				 	'</font></td></tr>';
				HTML_str+='<tr><td><font face="Arial" size="2">Main Category : </font></td><td>'+
		 		' <select style="text-indent: 5;width:152;height:26;" size="1" name="update_seriescategory" id=update_seriescategory>';
				for (j=0;j<g_total_series_category_no;j++)
				{
					if (j==0) 
					{
						HTML_str+='<option  style="padding: 2px" selected="selected" value="'+decodeURI(g_Series_Categories_tems[j])+'">'+decodeURI(g_Series_Categories_tems[j])+'</option>';
					}
					else
					{
						HTML_str+='<option  style="padding: 2px" value="'+unescape(g_Series_Categories_tems[j])+'">'+unescape(g_Series_Categories_tems[j])+'</option>';
					}
				}
				HTML_str+='</select></font></td>';	
				HTML_str+='<td><font face="Arial" font size="2">Season No. : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="update_season_no"'+
				 	' id=update_season_no'+
				 	' size="16" value="4" oninput="change_season_no_input_color()"/></font></td></tr>';
				HTML_str+='<tr><td><font face="Arial" font size="2">Rating : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="update_rating"'+
				 	' id=update_rating'+
				 	' size="16"/></font></td>';
				HTML_str+='<td><font face="Arial" font size="2">Released Date : </font></td><td width="11">'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="update_released_date"'+
				 	' id=update_released_date'+
			 		' size="16" value="MM/DD/YYYY" oninput="change_released_date_input_color('+"'released_date'"+')"/></font></td></tr>';

				HTML_str+='<tr><td><font face="Arial" size="2">Icon Path : </font></td><td colspan=3>'+
				 		' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;;" type="text" name="update_iconpath"'+
				 		' id=update_iconpath'+
				 		' size="61" value="file://media/pictures/action/1.jpg" oninput="change_iconurl_input_color()"/></font></td></tr>';
				 
				// Series Gener
		 		HTML_str+='<tr><td><font face="Arial" size="2">Sub Categories</font></td><td>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="genre_itemSelect" id=genre_itemSelect>';
				
				for (j=0;j<g_series_genre.length;j++)
				{
					var genre_id=g_series_genre[j].id;
					HTML_str+='<option style="padding: 2px" value="'+genre_id+'">'+SeriesgenreObject[genre_id]+'</option>';
				}
				HTML_str+='</select></font></td><td colspan=2><button id="addItemButton" onclick=call_add_series_genre()>Add Item</button></td></tr>';
				HTML_str+='<tr><td></td><td colspan=3><font face="Arial" size="2"><b><ul id="selectedItemsList"></ul></b></font></td></tr>';	
		
				HTML_str+='<tr><td><font face="Arial" size="2">Description : </font></td><td colspan=3>'+
				' <textarea maxlength="500" name="update_description"'+
		 		' id="update_description"'+
		 		' cols="61" rows="10">'+
		 		'</textarea></font></td></tr>';

				HTML_str+='<tr><td colspan=2><input id=add_new_series_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save"  onclick=call_Update_Series() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_series_modal() name="Cancel" /></td></tr>';
				HTML_str+='</table>'+
				'</div>'+
				'</div></td>';
				
    				/* HTML_str+='<table align="center" cellpadding="0" cellspacing="10" >';
    				HTML_str+='<tr><td><font face="Arial"><font size="2">series No. : </font></td><td id=update_series_no width="350" height="23">'+
				' <font face="Arial" size="2">'+series_active_no+
				'</font></td></tr>';
				
				HTML_str+='<tr><td><font face="Arial" font size="2">series Name : </font></td><td width="20">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="update_seriesname"'+
				 	' id=update_seriesname'+
				 	' size="50"/'+
				 	'</font></td></tr>';
				HTML_str+='<tr><td><font face="Arial" size="2">Category : </font></td><td>'+
		 		' <select size="1" name="update_seriescategory" id=update_seriescategory>';
				for (j=0;j<g_total_series_category_no;j++)
				{
					HTML_str+='<option value="'+decodeURI(g_Series_Categories_tems[j])+'">'+decodeURI(g_Series_Categories_tems[j])+'</option>';
					
				}
				HTML_str+='</select></font></td></tr>';	

				HTML_str+='<tr><td><font face="Arial" font size="2">Season No. : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="update_season_no"'+
				 	' id=update_season_no'+
				 	' size="2"></font></td></tr>';
				HTML_str+='<tr><td><font face="Arial" font size="2">Rating : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="update_rating"'+
				 	' id=update_rating'+
				 	' size="2"/></font></td></tr>';
				HTML_str+='<tr><td><font face="Arial" font size="2">Released Date : </font></td><td width="11">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="update_released_date"'+
				 	' id=update_released_date'+
			 		' size="12"></font></td></tr>';

				HTML_str+='<tr><td><font face="Arial" size="2">Icon Path : </font></td><td>'+
				 		' <font face="Arial" size="2">'+
				 		' <input type="text" name="iconpath"'+
				 		' id=update_iconpath'+
				 		' size="50"></font></td></tr>';
				 		
				
				HTML_str+='<tr><td><font face="Arial" size="2">Description : </font></td><td>'+
				' <textarea maxlength="500" name="update_description"'+
		 		' id="update_description"'+
		 		' cols="39" rows="10">'+
		 		'</textarea></font></td></tr>';
		 		
				HTML_str+='<tr><td></td><td><input type="button" value="Save" onclick=call_Update_Series() name="Save" /></td></tr>';
			
			
			
			HTML_str+='</table></div></div></td>';
			*/
			
				
		      HTML_str+='<td width="'+cellsize+'" align="left" id=seriescategory'+series_no+'>'+' <font face="Arial" size="2">'+unescape(series_category)+'</font></td>';
		      HTML_str+='<td width="'+cellsize+'" align="center" id=season_no'+series_no+'>'+' <font face="Arial" size="2">'+season_no+'</font></td>';
		      HTML_str+='<td width="'+cellsize+'" align="center" id=episodename'+series_no+'>'+' <font face="Arial" size="2">'+episode_no+'</font></td>';
		      
		     /* HTML_str+='<td width="'+cellsize+'" align="center" id="episodename'+series_no+'">'+
			"<a href='javascript:void(0)'"+' onclick=open_modal_Episode_Update("'+series_no+'","'+season_no+'","'+encodeURI(series_name)+'")>'+
			' <font face="Arial" font size="2">'+
			episode_no+'</font></a>';
			

			HTML_str+='<div id="PanelModalEpisodeUpdate" class="modal">'+
			'<div class="modal-content">';

    				HTML_str+='<table align="center" cellpadding="0" cellspacing="10">';
    				HTML_str+='<tr><td  width=22%><font face="Arial"><font size="2">Series No.</font></td>'+
    				'<td  width=22% id=update_episode_no  height="23">'+
				' <font face="Arial" size="2">'+series_active_no+
				'</font></td>';
				
				HTML_str+='<td  width=22%><font face="Arial" font size="2">Series Name</font></td>'+
				         '<td   width=22% id=update_series_episodename ></td>';
				 HTML_str+='<td width=12% id=episode_update_dialog_message name=episode_update_dialog_message></td></tr>';
				 	
				HTML_str+='<tr><td  width=22%><font face="Arial" font size="2">Series</font></td>'+
						'<td width=22% id=update_season_list></td>';
				
				HTML_str+='<td width=22% id=update_episode_list_no><font face="Arial" size="2">Episode List</font></td>';	
				HTML_str+='<td width=22%  id=update_episode_list></td>';
				HTML_str+='<td width=12%><input style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Del" onclick=remove_series_episocde() name="Del" /></td></tr>';	

				HTML_str+='<tr><td width=44% colspan=2><input style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Update_Episode("'+encodeURI(series_name)+'") name="Save" /></td>'+
				'<td width=44% colspan=2><input style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Cancel" onclick=close_series_modal() name="Cancel" /></td>';
				HTML_str+='<td width=12%></td></tr>';
			
			
			
			HTML_str+='</table></div></div></td>';
		      */
		      HTML_str+='<td width="'+cellsize+'" align="center" id=released_date'+series_no+'>'+' <font face="Arial" size="2">'+released_date+'</font></td>';
		      HTML_str+='<td width="'+cellsize+'" align="center" id=servername'+series_no+'>'+' <font face="Arial" size="2">'+servername+'</font></td>';
		     
	 		

		HTML_str+='</tr>';				
		//   alert(HTML_str);
		total_no++;
     }
    //    content.innerHTML=HTML_str;
      // alert(menu_main.innerHTML);
  //    alert(HTML_str);
  	i=1;
	//if (total_no>0)
	//{

		new_total_no=Number(g_total_series_no)+1;
		menustr1='<table width=100%><tr>';
		menustr1+='<td width="4%">';
		menustr1+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>New Series</b></font></td><td colspan=2 align=right id=add_series_dialog_message name=add_series_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">Series at </font></td><td width=25%>'+
				' <font face="Arial" size="2">'+
				' <input  style="text-indent: 5;height:26;;" type="text" name="series_no"'+
				' id="series_no"'+
				' size="16" value="'+
				new_total_no+
				'"/></font></td>';
				
				menustr1+='<td width=25%><font face="Arial" font size="2">Series Name : </font></td><td  width=25%>'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="seriesname"'+
				 	' id=seriesname'+
				 	' size="16"/'+
				 	'</font></td></tr>';
				menustr1+='<tr><td><font face="Arial" size="2">Category : </font></td><td>'+
		 		' <select style="text-indent: 5;width:152;height:26;" size="1" name="seriescategory" id=seriescategory>';
				for (j=0;j<g_total_series_category_no;j++)
				{
					if (j==0) 
					{
						menustr1+='<option  style="padding: 2px" selected="selected" value="'+decodeURI(g_Series_Categories_tems[j])+'">'+decodeURI(g_Series_Categories_tems[j])+'</option>';
					}
					else
					{
						menustr1+='<option  style="padding: 2px" value="'+unescape(g_Series_Categories_tems[j])+'">'+unescape(g_Series_Categories_tems[j])+'</option>';
					}
				}
				menustr1+='</select></font></td>';	
				menustr1+='<td><font face="Arial" font size="2">Season No. : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="season_no"'+
				 	' id=season_no'+
				 	' size="16" value="4" oninput="change_season_no_input_color()"/></font></td></tr>';
				menustr1+='<tr><td><font face="Arial" font size="2">Rating : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="rating"'+
				 	' id=rating'+
				 	' size="16"/></font></td>';
				menustr1+='<td><font face="Arial" font size="2">Released Date : </font></td><td width="11">'+
				 	' <font face="Arial" size="2">'+
				 	' <input  style="text-indent: 5;height:26;;" type="text" name="released_date"'+
				 	' id=released_date'+
			 		' size="16" value="MM/DD/YYYY" oninput="change_released_date_input_color('+"'released_date'"+')"/></font></td></tr>';

				menustr1+='<tr><td><font face="Arial" size="2">Icon Path : </font></td><td colspan=3>'+
				 		' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;;" type="text" name="iconpath"'+
				 		' id=iconpath'+
				 		' size="61" value="file://media/pictures/action/1.jpg" oninput="change_iconurl_input_color()"/></font></td></tr>';
				 		
				menustr1+='<tr><td><font face="Arial" size="2">Description : </font></td><td colspan=3>'+
				' <textarea maxlength="500" name="description"'+
		 		' id="description"'+
		 		' cols="61" rows="10">'+
		 		'</textarea></font></td></tr>';

				menustr1+='<tr><td colspan=2><input id=add_new_series_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add"  onclick=call_Add_Series() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_series_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';

		menustr1+='<td width="4%">';
			menustr1+='<div id="PanelModalMassEditSeries" class="modal">'+
				'<div class="modal-content">'+
				'<span onclick="javascript:close_mass_edit_series_modal();" class="close">&times;</span>';
    				menustr1+='<table align="center">';
    				
				
				 menustr1+='<tr><td><font face="Arial" size="2">Category : </font></td><td>'+
		 		' <select size="1" name="mass_edit_seriescategory" id=mass_edit_seriescategory>';
				
				for (j=0;j<g_total_series_category_no;j++)
				{
					if (j==0) 
					{
						menustr1+='<option selected="selected" value="'+decodeURI(g_Series_Categories_tems[j])+'">'+decodeURI(g_Series_Categories_tems[j])+'</option>';
					}
					else
					{
						menustr1+='<option value="'+unescape(g_Series_Categories_tems[j])+'">'+unescape(g_Series_Categories_tems[j])+'</option>';
					}
				}
				menustr1+='<tr><td><font face="Arial" font size="2">Season No. : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="mass_edit_season_no"'+
				 	' id=mass_edit_season_no'+
				 	' size="2"></font></td></tr>';
				menustr1+='<tr><td><font face="Arial" font size="2">Rating : </font></td><td width="2">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="mass_edit_rating"'+
				 	' id=mass_edit_rating'+
				 	' size="2"/></font></td></tr>';
				menustr1+='<tr><td><font face="Arial" font size="2">Released Date : </font></td><td width="11">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="mass_edit_released_date"'+
				 	' id=mass_edit_released_date'+
			 		' size="12"></font></td></tr>';
				menustr1+='<tr><td><input type="button" value="Save" onclick=callezserver_mass_edit_selected_series() name="Save" /></td></tr></table>'+
				'</div>'+
			'</div></td>';	
				
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalSeriesCategory" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table align="center" cellspacing="10" align="center">';
				menustr1+='<tr><td  align="left"><font face="Arial" size="6"><b>Category</b></font></td><td align=right id=category_dialog_message name=category_dialog_message></td><td id=total_no align="right"></tr>';
				menustr1+='<tr><td  colspan="3"><hr size="1" color="#000000"></td></tr>';
				menustr1+='<tr><td colspan=2 id=series_category></td>'+
				'<td>'+
				'<table>';
				menustr1+='<tr><td><input id="Add" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=open_series_category_add_modal() name="Add" /></td></tr>';
				menustr1+='<tr><td><input id="Edit" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Edit" onclick=open_series_category_edit_modal() name="Edit" /></td></tr>';
				menustr1+='<tr><td><input id="Del" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Del" onclick=call_Del_Series_Category() name="Del" /></td></tr>';
				menustr1+='<tr><td><img style="margin-top:10px;width:100%;height:30;" src="/admin/move.png"></img></td></tr>';
				
				menustr1+='</table></td></tr>';
				
				
				menustr1+='<tr><td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Save" onclick=close_update_series_category_modal() name="Save" /></td>';
				menustr1+='<td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_series_category_modal() name="Cancel" /></td>';
				menustr1+='<td width=10%></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				
				// Mass Delete
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalMassDelete" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td  width=75% colspan=3 align=left><font face="Arial" size="6"><b>Mass Delete</b></font></td><td align=right id=mass_delete_dialog_message name=mass_edit_delete_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';
				
				// Category	
				menustr1+='<tr><td><font face="Arial" size="2"><b>Choose one category</b></font></td><td colspan=3 width=75%>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="mass_delete_category" id=mass_delete_category>';
				
				menustr1+='<option style="padding: 2px" selected="selected" value="'+"All"+'">'+"All"+'</option>';
				// Need to change
				for (j=0;j<g_total_series_category_no;j++)
				{
					menustr1+='<option style="padding: 2px" value="'+decodeURI(g_Series_Categories_tems[j])+'">'+decodeURI(g_Series_Categories_tems[j])+'</option>';
				}
				menustr1+='</select></font></td></tr>';
				
	 			// Need to change			
				menustr1+='<tr><td colspan=2><input id=delete_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Delete" onclick=callezserver_mass_delete_selected_series() name="Delete" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_mass_delete_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalSeriesImport" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>Import Series</b></font></td><td align=right id=import_series_dialog_message name=import_series_dialog_message></td></tr>';
				
				menustr1+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';	
	
								
				menustr1+='<tr><td width=100% colspan="2"><b>M3U from HTTP URL or Local File</b></td></tr>';	
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstartinput()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="importurl"'+
		 		' id="importurl"'+
		 		' size="61" placeholder="http://serverip:port/get.php&username=test&password=1234"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="add_file_upload_form_series" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Submit" onclick=call_Import_Series() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_series_import_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				// Edit Category
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalSeriesCategoryEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>Edit Category</b></font></td><td align=right id=series_category_edit_dialog_message name=series_category_edit_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
				// New Category Name
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Category:</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;color:#000000" type="text" name="editcategory"'+
		 		' id="editcategory"'+
		 		' size="40"></font></font></td></tr>';
		 		
								
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstart_seriescategory_edit_input()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="edit_category_url"'+
		 		' id="edit_category_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="edit_file_upload_form_series_category_icon" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Edit_Series_Category() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_series_category_edit_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				// Add New Category
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalSeriesCategoryAdd" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>New Category</b></font></td><td align=right id=series_category_add_dialog_message name=series_category_add_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
				// New Category Name
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Category:</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;color:#000000" type="text" name="newcategory"'+
		 		' id="newcategory"'+
		 		' size="40"></font></font></td></tr>';
		 		
								
				menustr1+='<tr><td colspan="2"><hr size="1" color="#cccccc"></td></tr>';	
				menustr1+='<tr><td colspan="2"><b>ICON from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input oninput="onstart_seriescategory_add_input()"  style="text-indent: 5;height:26;color:#cccccc" type="text" name="add_category_url"'+
		 		' id="add_category_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="file_upload_form_series_category_icon" enctype="multipart/form-data">'+
				'<input type="file" name="Video" multiple/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Series_Category() name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_series_category_add_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';
				
				

		menustr1+='</tr></table>';
		if (total_count==0)
		{
			current_position=0;
			endposition=0;
		}else
		{
			endposition=current_position+total_no-1;
		}
		menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
		menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' seriess</td>';
		position=1;
		limit=g_constant_limit;
		if (total_count>g_constant_limit)
	{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:call_get_first_series('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:call_get_series('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:call_get_series('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	//}
  	//alert(menustr2);
	content.innerHTML=menustr1+HTML_str+'</table>'+menustr2;
	g_SearchInput = document.getElementById("search_field");
     	if (g_search_text.length>0)
     	{
     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
     		g_SearchInput.focus();
     	}
     	
	if (g_add_series_flag==1)
	{
		open_modal();
	}
	g_add_series_flag=0;
	document.getElementById("released_date").style.color = "#cccccc";
	document.getElementById("iconpath").style.color = "#cccccc";
	document.getElementById("season_no").style.color = "#cccccc";
	}

 
}
function Preview_Movie_inquery()
{
   var content = parent.document.getElementById("content");
    var str;
   var buffer;
   var i;
   var path;
   var trstart=0;
   var strtext;
   var video_path;
   var browser_name;
   var buffer_video_text;
   var media_text;
   var media_text_path;
   var movie_no;
  var movie_name;
   var subtitle_path;
   var icon_path;
   var movie_type;
   var movie_status;
 
 
 
  if (xmlHttp.readyState == 4) {
  var response = xmlHttp.responseText.split("\r\n");
   // alert(g_file_path);
     str='';
     strtext='';
  //    	  BrowserDetect.init();
  //	  browser_name=BrowserDetect.browser;
 	g_token=find_cookie_value("token");
 	if (g_token==0) return; 
 	//alert(g_token);


        for (i=0;;i+=8)
  	{
  //	   alert(response[i]);
	    if (response[i]==0)
  	    {
  	    	break;
 	    } else
  	    {
 	 	strlength=response[i].length;
   	    	movie_no=response[i].slice(8,strlength);
   	    	
     	 	strlength=response[i+1].length;
     	 	movie_name=response[i+1].slice(5,strlength);
   	    	
     	 	strlength=response[i+2].length;
   	    	movie_src=response[i+2].slice(4,strlength);
   	    	
    	 	strlength=response[i+3].length;
   	    	icon_path=response[i+3].slice(10,strlength);
   	    	//alert(icon_path);
     	 	strlength=response[i+4].length;
 	    	movie_category=response[i+4].slice(9,strlength);

   	    	
 	    	
     	 	strlength=response[i+5].length;
 	    	duration=response[i+5].slice(9,strlength);
 	    	nduration=parseFloat(duration);
 	    	nduration = nduration /60;
 	    	nduration =nduration.toFixed(3);

 	    	
     	 	strlength=response[i+6].length;
 	    	bitrate=response[i+6].slice(8,strlength);
 	    	
       	 	strlength=response[i+7].length;
 	    	movie_status=response[i+7].slice(7,strlength);
 
 		if (trstart==0)
  	    	{
  	    		str+='<tr>';
  	    		strtext+='<tr>';
  	    	} 
 		
		str+='<td width="16%" valign="middle" align="center" height="185">'+
		'<a style="text-decoration:none"'+ 
		"href='javascript:void(0)'"+
		//' onclick=play_movie_by_name("'+encodeURI(movie_name)+'","'+subtitle_path+'","'+movie_type+'")>'+
		' onclick=play_movie_by_name("'+encodeURI(movie_name)+'","'+encodeURI(movie_src)+'")>'+
		//' onclick=play_movie("'+movie_no+'")>'+
		'<img border="0" src="'+icon_path+'" width="140" height="200"></a></td>';
		strtext+='<td width="16%" valign="middle" align="center" height="23"><font size="2" color="#000000" face="Verdana">'+decodeURI(movie_name)+'</font></td>';

			
		

		trstart++;
		if (trstart==5)
  	    	{
  	    		str+='</tr>';
  	    		strtext+='</tr>';
  	    		str+=strtext;
  	    		strtext='';
  	    		trstart=0;
 	    		
  	    	}
	 		//alert(str);
   	    } 
      }
  	if (trstart!=0)
 	{
 	  	    		str+='</tr>';
	  	    		strtext+='</tr>';
	  	    		str+=strtext;
	}
	if (i==0)
	{
		str='<tr><td><p align="center"><b><i><font face="Arial" color="#FFFFFF" size="5">No Content</font></i></b></p>'+
     		'</td></tr>';
	}
	
 	content.innerHTML='<center><table border="0" cellpadding="10" cellspacing="0" width="100%">'+str+'</table></center>';
   }
}

function Preview_callServer_Movie_Inquery() {
  var content = parent.document.getElementById("content");

  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
	bSystem_Inquery_Panel=0; 
  	bQuery_Channel_Status=0;
  	bQuery_Online_Player=0;
  	bGet_Channel_Statistics=0;
 	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/query_movie_list?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Movie Information Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Preview_Movie_inquery;
		xmlHttp.send(null);
	}

}



function Set_Channel_update()
{
	add_cookie_value("ch_up_flag",1);
}
function Clear_Channel_update()
{
	add_cookie_value("ch_up_flag",0);
}
function Set_Movie_update()
{
	add_cookie_value("mv_up_flag",1);
}
function Clear_Movie_update()
{
	add_cookie_value("mv_up_flag",0);
}
function Cancel_Add_User()
{
	var content = parent.document.getElementById("content");
	content.innerHTML=g_content;

}
function Cancel_Add_Channel()
{
	var content = parent.document.getElementById("content");
	//g_Channel_Edit_Mode=0;
	content.innerHTML=g_content;
}
function Cancel_Add_Movie()
{
	var content = parent.document.getElementById("content");
	g_Movie_Edit_Mode=0;
	content.innerHTML=g_content;
}
function call_Edit_Movie()
{
	g_Movie_Edit_Mode=1;
	callServer_Movie_Inquery();
}

function call_Edit_Channel()
{
	//g_Channel_Edit_Mode=1;
	callServer_CH_Inquery();
}
/*function Refresh_OK_Msg(){
alert("Refresh Channel Sucessfully");
}
*/
function show_channel_menu_bar()
{
	var ch_menu_bar= document.getElementById("ch_menu_bar");
	
	if (ch_menu_bar!=null)
	{
 
      	      if (g_show_free_version==1)
      	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
	 	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	 
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
      	      }else
      	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_channel()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
	 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_channel()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	 
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_channel()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	
	      }
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_channel()>"+
	      '<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';

	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_channel()>"+
	      '<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';

	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_CH_Inquery()>"+
	      '<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
	      
	      HTML_Menu_Bar_Str="<a href='javascript:void(0)' onclick=callServer_CH_Inquery()>"+
	      '<font size="2" face="Arial">Auto Query</font></a>'+'&nbsp&nbsp&nbsp';

	      if (g_show_free_version==1)
	      {
	          HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
	          HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_channel()>"+
		      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
	      
	      //HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_channel_definition()>"+
	      //'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';
	      
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_channel()>"+
	      '<font size="2" face="Arial">Refresh All</font></a>';
		ch_menu_bar.innerHTML=HTML_Menu_Bar_Str;
	}
}
function show_movie_menu_bar()
{
	var movie_menu_bar= document.getElementById("movie_menu_bar");
	
	if (movie_menu_bar!=null)
	{
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_movie()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_movie()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_movie()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	      }


	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_movie()>"+
	      '<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';

	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_movie()>"+
	      '<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
 
 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_Movie_Inquery()>"+
	      '<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_Movie_Inquery()>"+
	      '<font size="2" face="Arial">Query</font></a>'+'&nbsp&nbsp&nbsp';
	      
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_movie()>"+
		      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
	            
	      //HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_movie_definition()>"+
	      //'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';

	      movie_menu_bar.innerHTML=HTML_Menu_Bar_Str;
	}
}
function ezserver_quit_refresh_channel(){
 
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;

    if (response==0)
    {
   	alert("Failed to finish Channels");
    }
	//g_Channel_Edit_Mode=0;
	g_Channel_Updated=0;
	show_channel_menu_bar();      
	callServer_CH_Inquery();	


 }
 
}
function callezserver_quit_updated_channel()
{
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
  var ch_menu_bar= document.getElementById("ch_menu_bar");

	
      	g_token=find_cookie_value("token");

	cgi_url = "/server/refresh_channel?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	alert("Need to wait 10 sec. to get new channel status.");
	if (g_Channel_Updated==1)
	{
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = ezserver_quit_refresh_channel;
		xmlHttp.send(null);
		ch_menu_bar.innerHTML='<font size="2" face="Arial">Refreshing</font>';

/*		confirm_msg="Channel Updated, Refresh Channles?";
		if (confirm(confirm_msg))
		{
		 	 xmlHttp.open("GET", cgi_url, true);
			 xmlHttp.onreadystatechange = ezserver_quit_refresh_channel;
			 xmlHttp.send(null);
		      ch_menu_bar.innerHTML='<font size="2" face="Arial">Refreshing</font>';
	
		}else
		{
			g_Channel_Updated=0;
			callServer_CH_Inquery();
		}
		*/
	}else
	{
		g_Channel_Updated=0;
		callServer_CH_Inquery();
	}
		
		
	

 	
} 
function ezserver_quit_refresh_movie(){
 
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;

    if (response==0)
    {
   	alert("Failed to finish Movies");
    }
	g_Movie_Edit_Mode=0;
	g_Movie_Updated=0;
	show_movie_menu_bar();      
	callServer_Movie_Inquery();	


 }
 
}
function callezserver_quit_updated_movie()
{
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
  var movie_menu_bar= document.getElementById("movie_menu_bar");

	
      	g_token=find_cookie_value("token");

	cgi_url = "/server/refresh_movie?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	if (g_Movie_Updated==1)
	{
		alert("Please wait to refresh movies...");
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = ezserver_quit_refresh_movie;
		xmlHttp.send(null);
		movie_menu_bar.innerHTML='<font size="2" face="Arial">Refreshing</font>';

	}else
	{
		g_Movie_Updated=0;
		callServer_Movie_Inquery();
	}
		
		
	

 	
} 
function ezserver_quit_movie(){
 
	g_Movie_Edit_Mode=0;
	if (g_Movie_Updated==1)
	{
		callezserver_quit_updated_movie();
		g_Movie_Updated=0;
	}else
	{
		callServer_Movie_Inquery();
	}
}
function Add_Movie(movie_no) {

  
}
function get_TMDB_movie_icon_path()
{
	var movie_pid=document.getElementById("movie_pid").value;
	//alert(movie_pid);
	cgi_url = "/server/get_TMDB_movie_icon_path?token="+encodeURI(g_token)+"&movie_pid="+movie_pid+"&flag="+Math.random();
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) 
		{
			var response = xmlHttp.responseText;
			if (response.length>0)
			{
				const myObj = JSON.parse(response);
				//alert(myObj.poster_path);
				var iconpath=g_TMDB_IMG_URL+"w500"+myObj.poster_path;
				//alert(iconpath);
				var menustr1=' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;" type="text" name="iconpath"'+
				 		' id=iconpath'+
				 		' onclick=get_TMDB_movie_name()'+
						' size="'+iconpath.length+'" value="'+iconpath+'"/>'+
				 		'</font>';
				document.getElementById("movie_icon_path").innerHTML=menustr1;
				document.getElementById("movie_description").value=myObj.overview;
			}
		}
	};
	xmlHttp.send(null);
	
}
function get_TMDB_movie_name()
{
	var movie_name=document.getElementById("moviename").value;
	cgi_url = "/server/get_TMDB_matched_movie_list?token="+encodeURI(g_token)+"&movie_name="+encodeURI(movie_name)+"&flag="+Math.random();
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = function()
	{
		if (xmlHttp.readyState == 4) 
		{
			var response = xmlHttp.responseText;
			if (response.length>0)
			{
				const myObj = JSON.parse(response);
				
				if (parseInt(myObj.total_results)>0)
				{
					var menustr1='<select style="text-indent: 5;height:26;" size="1" onchange=get_TMDB_movie_icon_path() name="movie_pid" id=movie_pid>';
					menustr1+='<option value="null">Select a Movie URL</option>';
					for (x=0;;x++) {
					    try {
					    	menustr1+='<option  style="padding: 2px" value="'+myObj.results[x].id+'">'+myObj.results[x].original_title+'</option>';
					    	
					    } catch(err)
					    {
					    	break;
					    }
					    
					}
					menustr1+='</select></font>';
					document.getElementById("movie_icon_path").innerHTML=menustr1;		
				}
			} else
			{
			}
		}
	};
	xmlHttp.send(null);
}
function call_Add_Movie()
{
 var add_new_movie_button=document.getElementById("add_new_movie_button");
 var add_movie_dialog_message=document.getElementById("add_movie_dialog_message");

 var movie_src_id="moviesrc"; 
 var movie_src_name="moviename"; 
  var movie_src_category="moviecategory"; 
var icon_path_name="iconpath"; 
var movie_src_no="movie_no"; 
//var folder_recursively_switch=0;
var filetype=0;

 var movie_src;
 var movie_category;
 var movie_name="";
 var movie_description=document.getElementById("movie_description").value;
 var icon_path;
 var g_item_name;
var movie_no;

	var rentpoint_id="rentpoint";
	var buypoint_id="buypoint";
	var rentpoint;
	var buypoint;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 var movienoitem=document.getElementById(movie_src_no);;
 var movienameitem;
 
   g_item_name=document.getElementById(movie_src_no);
 	movie_no = g_item_name.value;
	/*
	if (movie_no>(g_total_movie_no+1))
	{
		alert("Movie No. is invaild.");
		return;
	}
	*/
 g_item=document.getElementById(movie_src_id);
 movie_src = g_item.value;
 if (movie_src.length==0)
 {
 	alert("Media Source is empty");
 	return;
 }


 g_item_name=document.getElementById(movie_src_category);
 movie_category = g_item_name.value;


	 g_item_name=document.getElementById(movie_src_name);
	 movienameitem=g_item_name;
	if (g_item_name.disabled==false)
	{	 movie_name = g_item_name.value;
		 //alert(movie_name);
		 if (movie_name.length==0)
		 {
		 	alert("Movie Name is empty");
		 	return;
		 }
	 }else
	 {
	 	filetype=1;
	 }
	 
	 	g_item=document.getElementById(rentpoint_id);
	rentpoint=g_item.value;
	g_item=document.getElementById(buypoint_id);
	buypoint=g_item.value;

	// alert(filetype);
 g_item_name=document.getElementById(icon_path_name);
 icon_path = g_item_name.value;
 //folder_recursively_switch=Number(document.getElementById("movie_folder_recursively_switch").checked);
 folder_recursively_switch=1;

   	g_token=find_cookie_value("token");
g_movie_no=movie_no;
 confirm_msg="Add Movie "+movie_no+" Information?";
 if (filetype==1)
 {
 	cgi_url = "/server/add_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&rentpoint="+rentpoint+"&buypoint="+buypoint+ "&type=" +filetype+ "&Recursively=" + folder_recursively_switch+ "&src=" + encodeURI(movie_src)+ "&category=" + encodeURI(movie_category)+ "&img=" + encodeURI(icon_path)+"&flag="+Math.random();
 }else
 {
 	cgi_url = "/server/add_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&rentpoint="+rentpoint+"&buypoint="+buypoint+ "&movie_name=" + encodeURI(movie_name)+ "&src=" + encodeURI(movie_src)+ "&category=" + encodeURI(movie_category)+ "&img=" + encodeURI(icon_path)+"&description=" +encodeURI(movie_description)+"&flag="+Math.random();
 }
 //alert(cgi_url);
// if (confirm(confirm_msg))
// {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
		    var item_save;
		    var item_add;
		   var item_copy;
		    var item_del;
		   var item_refresh;
		   var item_more;
		    var item_play;
		    var sziret;
		    
		    if (response>0)
		    {
		    	//g_Movie_Updated=1;
		    	//Set_Movie_update();
		    	g_total_movie_no=parseInt(g_total_movie_no)+parseInt(response);
		    	if ((g_movie_position+g_constant_limit)<=g_total_movie_no)
			{
				if (((g_total_movie_no)%g_constant_limit)==1)
				{
					g_movie_position=parseInt(g_total_movie_no);
				}
				g_movie_limit=g_constant_limit;
			}else
			{
				g_movie_limit=g_total_movie_no%g_constant_limit;
				if (g_movie_limit==0) 
				{
					if (g_total_movie_no<g_movie_position)
					{
						g_movie_position=g_total_movie_no-g_constant_limit+1;
					}
					g_movie_limit=g_constant_limit;
				}
			}
				/* 
				add_new_movie_button.value="Add Next";
				new_add_total_no=parseInt(g_total_movie_no)+parseInt(response);
				add_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+movie_name+' Added</font>';
				//alert(new_add_total_no);
				movienoitem.value=new_add_total_no;
				movienameitem.value="";
				movienameitem.focus();
				*/
			close_movie_modal();
		
		} else if (response==-3)
		{
			alert("Do not support https link, please use Ubuntu 20.04 version and https panel link.");
		}else
		    {
		   	alert("Failed to Add Movie");
		 	//	g_Movie_Edit_Mode=1;
			//	callServer_Movie_Inquery();
		   }
		
			
		}
	 };
	 xmlHttp.send(null);
 //}


}

// need to edit add new channel in any position
function call_Add_New_Movie(movie_no)
{
	
	var HTML_str;
	//var ch_no;
	var len;
	var movie_refresh_button; 
	var movie_play_id;
	var movie_src_id; 
	var movie_src_name; 
	var movie_src_category; 
	var icon_path_name; 
	var movie_src_status; 
	var movie_src_duration;
	var movie_src_bitrate;
	
	var movie_src;
	var movie_name;
	var icon_path;
	var movie_category;
	var movie_status;
	var movie_duration;
	var movie_bitrate;
	
	var item_name;
	var i;
	var save_keyword="Save";
	var add_keyword="Add";
	var del_keyword="Del";
	var refresh_keyword="Refresh";
	var play_keyword="Play";
	var movie_active_no;
	var m;
	var k;
	
	var menustr2;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_movie_position;
	var total_count=g_total_movie_no;
	var pagelineno=0;
	var total_no=0;

	
	var content = parent.document.getElementById("content");
 	var movie_menu_bar= document.getElementById("movie_menu_bar");

	g_content=content.innerHTML;
	movie_active_no=g_total_movie_no;
	movie_active_no++;
	
		HTML_Menu_Bar_Str='<td id=movie_menu_bar>';
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_movie()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_movie()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_movie()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	      }


		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_movie()>"+
		'<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';
		
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_movie()>"+
		'<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
		
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_Movie_Inquery()>"+
		'<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_Movie_Inquery()>"+
		'<font size="2" face="Arial">Query</font></a>'+'&nbsp&nbsp&nbsp';
		
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_movie()>"+
		      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
		    
		//HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_movie_definition()>"+
		//'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';
		HTML_Menu_Bar_Str+='</td>';
	      
	  HTML_str= '<table border="0" align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_movie_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Movie Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Duration(min.)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
	      '<td width="80" align="center"><font face="Arial" size="2">Status</font></td>'+
 	 '</tr>'+'<tr><td  colspan="8"><hr size="1" color="#66FFFF"></td></tr>';
 	
//	for (i=1,m=1;i<=movie_active_no;i++,m++)
	pagelineno=parseInt(current_position)+parseInt(g_movie_limit)+1;
	for (i=current_position,m=current_position;i<pagelineno;i++,m++)
	{
	//	alert(i);
		movie_src_id="moviesrc"+m; 
		item_name=document.getElementById(movie_src_id);
		// alert(item_name.value);
		movie_src = item_name.value;
		
		movie_src_name="moviename"+m; 
		item_name=document.getElementById(movie_src_name);
		movie_name = item_name.value;

		icon_path_name="iconpath"+m; 
		item_name=document.getElementById(icon_path_name);
		icon_path = item_name.value;
		
		movie_src_category="moviecategory"+m; 
		item_name=document.getElementById(movie_src_category);
		movie_category = item_name.value;
		
		
		movie_src_status="moviestatus"+m; 
		item_name=document.getElementById(movie_src_status);
		movie_status = item_name.innerHTML;

		movie_src_duration="movieduration"+m; 
		item_name=document.getElementById(movie_src_duration);
		movie_duration = item_name.innerHTML;

		movie_src_bitrate="moviebitrate"+m; 
		item_name=document.getElementById(movie_src_bitrate);
		movie_bitrate = item_name.innerHTML;
		
		
//		alert(ch_status);
	
		HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
	      '<td width="20" align="center">'+
 		' <input type="checkbox" name=checkbox'+i+
 		' id=checkbox'+i+'></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviename"'+
 		' id=moviename'+i+
 		' size="20" value="'+
	 	movie_name+'"/'+
 		'</font></td>'+
	      '<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviesrc"'+
 		' id=moviesrc'+i+
 		' size="35" value="'+
	 	movie_src+'"/'+
 		'</font></td>'+
 		'<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="iconpath"'+
 		' id=iconpath'+i+
 		' size="35" value="'+
	 	icon_path+'"/'+
 		'</font></td>'+
	      '<td width="10" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviecategory"'+
 		' id=moviecategory'+i+
 		' size="10" value="'+
	 	movie_category+'"/'+
 		'</font></td>';
		HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_duration+'</font></td>';
		HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_bitrate+'</font></td>';

		total_no++;


					
		if (m==(movie_no))
		{
			HTML_str+='<td id=moviestatus'+i+' width="100" align="center">'+movie_status+'</td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_Movie("'+i+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Copy_10_Movies("'+i+'")>'+
			' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_Movie_Update("'+i+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			/*
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Movie("'+i+'")>'+
			' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Refresh_A_Movie("'+i+'")>'+
			' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
			*/
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_A_Movie_More("'+i+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
			
			
			/*
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=play_movie("'+i+'")>'+
			' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
			HTML_str+='</tr>';
			*/

			i++;
			
			movie_src="";
			movie_name="";
			icon_path="";
			movie_category="";
			
		      HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		      '<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+i+
	 		' id=checkbox'+i+'></td>'+
		      '<td width="60" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="moviename"'+
	 		' id=moviename'+i+
	 		' size="20"/'+
	 		'</font></td>'+
		      '<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="moviesrc"'+
	 		' id=moviesrc'+i+
	 		' size="35"/'+
	 		'</font></td>'+
	 		'<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="iconpath"'+
	 		' id=iconpath'+i+
	 		' size="35"/'+
	 		'</font></td>'+
		      '<td width="10" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="moviecategory"'+
	 		' id=moviecategory'+i+
	 		' size="10"/'+
	 		'</font></td>';
	 		
		     
		
			HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+'0.0'+'</font></td>';
			HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+'0.0'+'</font></td>';
			HTML_str+='<td id=moviestatus'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
		      	HTML_str+='<td id=add_id_button align="center">'+
			      "<a href='javascript:void(0)'"+
			      ' onclick=call_Add_Movie("'+i+'")>'+
		      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
		      	      
			      '<td id=copy_id_button align="center">'+		      
			      ' <font face="Arial" size="2"></font></a></td>'+
		      	      
			      '<td id=save_id_button align="center">'+		      
			      "<a href='javascript:void(0)'"+
			      ' onclick=Cancel_Add_Movie()>'+
		      	      ' <img border="0" id="delbutton" alt="Canel" title="Cancel" src="del_icon.PNG"></a></td>'+

			      /*
			      '<td id=del_id_button align="center">'+		      
			      ' <font face="Arial" size="2"></font></a></td>'+
			      '<td id=refresh_id_button align="center">'+		      
			      ' <font face="Arial" size="2"></font></a></td>'+
			      */
			      '<td id=more_id_button align="center">'+		      
			      ' <font face="Arial" size="2"></font></a></td>';
			     /* '<td id=play_id_button align="center">'+		      
			      ' <font face="Arial" size="2"></font></a></td>';
			      */
		      	      
		}else
		{
			HTML_str+='<td id=moviestatus'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_status+'</font></td>';
	
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_Movie("'+i+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Copy_10_Movies("'+i+'")>'+
			' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_Movie_Update("'+i+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			/*
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Movie("'+i+'")>'+
			' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
			 HTML_str+='<td id=refreshmoviebutton'+i+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Refresh_A_Movie("'+i+'")>'+
			' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
			*/
			 HTML_str+='<td id=morebutton'+i+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_A_Movie_More("'+i+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';

			/*
			HTML_str+='<td align="left" id=movie_play_id'+movie_no+'>';
			HTML_str+="<a href='javascript:void(0)'"+
			' onclick=play_movie("'+i+'")>'+
				' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
				*/
	
			
		}
		HTML_str+='</tr>';
	      	     
	      	      	
	}
     
     
//	alert(HTML_str);
	menustr1='<table width=100%><tr>';
	menustr1+='<td width=55%"></td>'+'<td width=45%>'+
	'<Input type="button" value="Refresh" onclick="javascript:callezserver_refresh_selected_movie();" />';
	
	if (g_show_free_version!=1)
	{
		menustr1+='<Input type="button" value="Import" onclick="javascript:call_import_movie();" />';
	}else
	{
		menustr1+='<Input disabled type="button" value="Import" onclick="javascript:call_import_movie();" />';
	}
	
	//menustr1+='<Input type="button" value="Export" onclick="javascript:call_export_movie_definition();" />'+
	menustr1+='<input type="button" value="Delete" onclick="javascript:callezserver_delete_selected_movie();" />'+
	'<input name="movie_search_field" id="movie_search_field" size="20" value="'+g_search_text+'"/></font><font face="Arial">';
	if (g_movie_found_position>0)
	{
	   menustr1+='<input type="button" value="Find Next" onclick="javascript:callServer_search_movie();" id="movie_search_button" name="search_movie" />';
	}else
	{
	   menustr1+='<input type="button" value="Search" onclick="javascript:callServer_search_movie();" id="movie_search_button" name="search_movie" />';
	}
	  menustr1+='</td></tr>'+
	      '</table>';

 	if (total_count==0)
	{
		current_position=0;
		endposition=0;
	}else
	{
		endposition=current_position+total_no-1;
	}
//	menustr2='<table width=100%><tr><td>'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of '+total_count+' users</td>';
	menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
	menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' movies</td>';
	position=1;
	limit=g_constant_limit;
	if (total_count>g_constant_limit)
	{	
		menustr2+='<td width="67%"><font face="Arial" size="2"><input type="button" value="First" onclick="javascript:call_get_first_movie('+position+','+limit+')"; /></font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input type="button" disabled value="Previous" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" value="Previous" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}
				}
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="0'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="'+j+'" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" value="Next" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input type="button" disabled value="Next" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input type="button" value="Last" onclick="javascript:call_get_movies('+position+','+limit+')"; /></font>';
		menustr2+='</td></tr></table>';
	}else
	{
		menustr2+='<td>';
	}
	/* content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Movie Total: '+ movie_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td> <font face="Arial" size="2"> <input name="movie_search_field" id="movie_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_movie_name();" name="search_movie_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(2);" name="goto_movie_no" /></font>'+	   
	   '</td></tr>'+
	'</table>'+HTML_str+'</table>'+menustr2;
	*/
	content.innerHTML=menustr1+HTML_str+'</table>'+menustr2;

   //    content.innerHTML=HTML_str+'</table>';
//      alert(ch_list_info.innerHTML);
   
		
}
function Copy_10_Movies() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var item_save;
    var item_add;
    var item_del;
   var item_refresh;
    var item_play;
    if (response==1)
    {
    	g_Movie_Updated=1;
    	Set_Movie_update();
    	//g_total_movie_no+=10;
    	g_total_movie_no=parseInt(g_total_movie_no)+parseInt(10);  
  	if ((g_movie_position+g_constant_limit)<=g_total_movie_no)
	{
		if (((g_total_movie_no)%g_constant_limit)==1)
		{
			g_movie_position=parseInt(g_total_movie_no);
		}
		g_movie_limit=g_constant_limit;
	}else
	{
		g_movie_limit=g_total_movie_no%g_constant_limit;
		if (g_movie_limit==0) 
		{
			if (g_total_movie_no<g_movie_position)
			{
				g_movie_position=g_total_movie_no-g_constant_limit+1;
			}
			g_movie_limit=g_constant_limit;
		}
	}    	
   	call_get_movies(g_movie_position,g_movie_limit);
 
   } else if (response==2)
   {
   	alert("This function is only for Enterprise version");
//		callServer_Movie_Inquery();
   	//call_get_movies(g_movie_position,g_movie_limit);

   }else
    {
   	alert("Failed to Copy 10 Movies");
// 		g_Movie_Edit_Mode=1;
//		callServer_Movie_Inquery();
   	//call_get_movies(g_movie_position,g_movie_limit);

   }

	
    }
}
function call_Copy_10_Movies(movie_no)
{
	var movie_counter=10;
	
	cgi_url = "/server/copy_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&movie_counter=" + encodeURI(movie_counter)+"&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Copy_10_Movies;
	 xmlHttp.send(null);
	
}
function old_call_Copy_10_Movies(movie_no)
{
	
	var HTML_str;
	//var ch_no;
	var len;
	var movie_refresh_button; 
	var movie_play_id;
	var movie_src_id; 
	var movie_src_name; 
	var movie_src_category; 
	var icon_path_name; 
	var movie_src_status; 
	var movie_src_duration;
	var movie_src_bitrate;
	
	var movie_src;
	var movie_name;
	var icon_path;
	var movie_category;
	var movie_status;
	var movie_duration;
	var movie_bitrate;
	
	var item_name;
	var i;
	var save_keyword="Save";
	var add_keyword="Add";
	var del_keyword="Del";
	var refresh_keyword="Refresh";
	var play_keyword="Play";
	var movie_active_no;
	var m;
	var k;
	var s;
	var movie_counter=10;

	
	var content = parent.document.getElementById("content");
 	var movie_menu_bar= document.getElementById("movie_menu_bar");

	g_content=content.innerHTML;
	movie_active_no=g_total_movie_no;
	movie_active_no+=movie_counter;
	
		HTML_Menu_Bar_Str='<td id=movie_menu_bar>';
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_movie()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_movie()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_movie()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	      }


		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_movie()>"+
		'<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';
		
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_movie()>"+
		'<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
		
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_Movie_Inquery()>"+
		'<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_Movie_Inquery()>"+
		'<font size="2" face="Arial">Query</font></a>'+'&nbsp&nbsp&nbsp';
		
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_movie()>"+
		      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
		    
		//HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_movie_definition()>"+
		//'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';
		HTML_Menu_Bar_Str+='</td>';
	      
	  HTML_str= '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_movie_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Movie Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Duration(min.)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
	      '<td width="80" align="center"><font face="Arial" size="2">Status</font></td>'+
 	 '</tr>'+'<tr><td  colspan="8"><hr size="1" color="#66FFFF"></td></tr>';
 	
	for (i=1,m=1;i<=movie_active_no;m++)
	{
	//	alert(i);
		movie_src_id="moviesrc"+m; 
		item_name=document.getElementById(movie_src_id);
		// alert(item_name.value);
		movie_src = item_name.value;
		
		movie_src_name="moviename"+m; 
		item_name=document.getElementById(movie_src_name);
		movie_name = item_name.value;

		icon_path_name="iconpath"+m; 
		item_name=document.getElementById(icon_path_name);
		icon_path = item_name.value;
		
		movie_src_category="moviecategory"+m; 
		item_name=document.getElementById(movie_src_category);
		movie_category = item_name.value;
		
		
		movie_src_status="moviestatus"+m; 
		item_name=document.getElementById(movie_src_status);
		movie_status = item_name.innerHTML;

		movie_src_duration="movieduration"+m; 
		item_name=document.getElementById(movie_src_duration);
		movie_duration = item_name.innerHTML;

		movie_src_bitrate="moviebitrate"+m; 
		item_name=document.getElementById(movie_src_bitrate);
		movie_bitrate = item_name.innerHTML;
		
		
//		alert(ch_status);
	
		HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
	      '<td width="20" align="center">'+
  		' <input type="checkbox" name=checkbox'+i+
 		' id=checkbox'+i+'></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviename"'+
 		' id=moviename'+i+
 		' size="20" value="'+
	 	movie_name+'"/'+
 		'</font></td>'+
	      '<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviesrc"'+
 		' id=moviesrc'+i+
 		' size="35" value="'+
	 	movie_src+'"/'+
 		'</font></td>'+
 		'<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="iconpath"'+
 		' id=iconpath'+i+
 		' size="35" value="'+
	 	icon_path+'"/'+
 		'</font></td>'+
	      '<td width="10" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviecategory"'+
 		' id=moviecategory'+i+
 		' size="10" value="'+
	 	movie_category+'"/'+
 		'</font></td>';
		HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_duration+'</font></td>';
		HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_bitrate+'</font></td>';


					
		if (m==(movie_no))
		{
			HTML_str+='<td id=moviestatus'+i+' width="100" align="center">'+movie_status+'</td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_Movie("'+i+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Copy_10_Movies("'+i+'")>'+
			' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_Movie_Update("'+i+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Movie("'+i+'")>'+
			' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Refresh_A_Movie("'+i+'")>'+
			' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_A_Movie_More("'+i+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=play_movie("'+i+'")>'+
			' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
			HTML_str+='</tr>';

			i++;
			for (s=1;s<=movie_counter;s++)
			{
				HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
			      '<td width="20" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="checkbox" name=checkbox'+i+
		 		' id=checkbox'+i+'></td>'+
			      '<td width="100" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
			      '<td width="20" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="moviename"'+
		 		' id=moviename'+i+
		 		' size="20" value="'+
			 	'('+s+')-'+movie_name+'"/'+
		 		'</font></td>'+
			      '<td width="200" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="moviesrc"'+
		 		' id=moviesrc'+i+
		 		' size="35" value="'+
			 	movie_src+'"/'+
		 		'</font></td>'+
		 		'<td width="200" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="iconpath"'+
		 		' id=iconpath'+i+
		 		' size="35" value="'+
			 	icon_path+'"/'+
		 		'</font></td>'+
			      '<td width="10" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="moviecategory"'+
		 		' id=moviecategory'+i+
		 		' size="10" value="'+
			 	movie_category+'"/'+
		 		'</font></td>';
				HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_duration+'</font></td>';
				HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_bitrate+'</font></td>';
				
				HTML_str+='<td id=moviestatus'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_status+'</font></td>';
		
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Add_New_Movie("'+i+'")>'+
				' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Copy_10_Movies("'+i+'")>'+
				' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_Movie_Update("'+i+'")>'+
				' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Del_Movie("'+i+'")>'+
				' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
				 HTML_str+='<td id=refreshmoviebutton'+i+' align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Refresh_A_Movie("'+i+'")>'+
				' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
				 HTML_str+='<td id=morebutton'+i+' align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Query_A_Movie_More("'+i+'")>'+
				' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
				
				HTML_str+='<td align="left" id=movie_play_id'+i+'>';
				HTML_str+="<a href='javascript:void(0)'"+
				' onclick=play_movie("'+i+'")>'+
					' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
				i++;
			}	
	 		
		    
		      	      
		}else
		{
			HTML_str+='<td id=moviestatus'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_status+'</font></td>';
	
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_Movie("'+i+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Copy_10_Movies("'+i+'")>'+
			' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=callServer_Movie_Update("'+i+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Del_Movie("'+i+'")>'+
			' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
			 HTML_str+='<td id=refreshmoviebutton'+i+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Refresh_A_Movie("'+i+'")>'+
			' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';

			 HTML_str+='<td id=morebutton'+i+' align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_A_Movie_More("'+i+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
			
			HTML_str+='<td align="left" id=movie_play_id'+i+'>';
			HTML_str+="<a href='javascript:void(0)'"+
			' onclick=play_movie("'+i+'")>'+
				' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
			i++;
	
			
		}
		HTML_str+='</tr>';
	      	     
	      	      	
	}
     
     
//	alert(HTML_str);
	content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Total: '+ movie_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td><font face="Arial" size="2"> <input name="movie_search_field" id="movie_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_movie_name();" name="search_movie_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(2);" name="goto_movie_no" /></font>'+	   
	   '</td></tr>'+
	'</table>'+HTML_str+'</table>';
	//alert(content.innerHTML);
   //    content.innerHTML=HTML_str+'</table>';
//      alert(ch_list_info.innerHTML);
   cgi_url = "/server/copy_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&movie_counter=" + encodeURI(movie_counter)+"&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Copy_10_Movies;
	 xmlHttp.send(null);
 
		
}


function Movie_update() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
  	Set_Movie_update();
  	g_Movie_Updated=1;
 //   	alert("Update Channel Sucessfully");
    } else
    {
   	alert("Failed to Update Movie");
    }
	g_item.value=g_temp;
	g_item.style.backgroundColor = "#ffffff";
    }
  //  setTimeout("callServer_CH_Inquery()",2000);
}

function callServer_Movie_Update(movie_no){
	
var movie_src_id="moviesrc"+movie_no; 
 var movie_src_name="moviename"+movie_no; 
 var icon_path_name="iconpath"+movie_no; 
 var movie_src_category="moviecategory"+movie_no; 
 var movie_src;
 var movie_name;
 var movie_category;
 var icon_path;
 var g_item_name;


 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var g_ch_play_id;
	var pid;
	
 g_item=document.getElementById(movie_src_id);
 movie_src = g_item.value;
 if (movie_src.length==0)
 {
 	alert("Media Source is empty");
 	return;
 }
// alert(movie_src);
 g_item_name=document.getElementById(movie_src_name);
 movie_name = g_item_name.value;
 if (movie_name.length==0)
 {
 	alert("Movie Name is empty");
 	return;
 }
// alert(movie_name);
 g_item_name=document.getElementById(movie_src_category);
 movie_category = g_item_name.value;
// alert(movie_category);
  g_item_name=document.getElementById(icon_path_name);
 icon_path = g_item_name.value;
// alert(icon_path_name);
 
 	g_token=find_cookie_value("token");

 confirm_msg="Update Movie "+movie_no+" Information?";
 cgi_url = "/server/update_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+
  "&movie_name=" + encodeURI(movie_name)+ "&src=" + encodeURI(movie_src)+ "&category=" + encodeURI(movie_category)+ 
  "&img=" + encodeURI(icon_path)+"&flag="+Math.random();
// alert(cgi_url);
 
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Movie_update;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	// g_item.value=g_item.value+" (updating...)";
	g_item.style.backgroundColor = "#ff0000";

 

}
function Refresh_A_Movie() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var movie_play_id="movie_play_id"+g_movie_no;
 var movie_status="moviestatus"+g_movie_no; 
  var movie_refresh_button="refreshmoviebutton"+g_movie_no; 
 
    if (response==1)
    {
 //   	alert("Refresh Channel Sucessfully");
	 g_status_item=document.getElementById(movie_status);
  
   		g_status_item.innerHTML='<font face="Arial" size="2">'+"ON"+'</font>';
     			
	g_item.style.backgroundColor = "#ffffff";

    } else if (response==2)
    {
   	alert("Already Refreshing Movie");
    }else if (response==3)
    {
   	alert("Movie is Refreshing.");
   	g_item.style.backgroundColor = "#ffffff";
    	
    }else if (response==0)
	{
		g_status_item.innerHTML='<font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font>';
		g_movie_play_id_item.innerHTML='<font face="Arial" size="2"></font>';
	g_item.style.backgroundColor = "#ffffff";
    }
    	
  	 g_item.value=g_movie_src;
  	 

  	 g_movie_play_id_item=document.getElementById(movie_play_id);
	g_movie_play_id_item.innerHTML="<a href='javascript:void(0)'"+
	      ' onclick=play_movie("'+g_movie_no+'")>'+
      	      ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a>';
   g_refresh_item=document.getElementById(movie_refresh_button);
 	g_refresh_item.innerHTML="<a href='javascript:void(0)'"+
	      ' onclick=call_Refresh_A_Movie("'+g_movie_no+'")>'+
      	      ' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a>';

  }
}

function call_Refresh_A_Movie(movie_no)
{
 var movie_src_id="moviesrc"+movie_no; 
 var movie_status="moviestatus"+movie_no; 
 var movie_refresh_button="refreshmoviebutton"+movie_no; 
 var movie_play_id="movie_play_id"+movie_no;

 var movie_src;
 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
 g_item=document.getElementById(movie_src_id);
g_status_item=document.getElementById(movie_status);
g_refresh_item=document.getElementById(movie_refresh_button);
g_movie_play_id_item=document.getElementById(movie_play_id);
	g_movie_no=movie_no;

 movie_src = g_item.value;
 g_movie_src=movie_src;
 	g_token=find_cookie_value("token");

 confirm_msg="Refresh Movie "+movie_no+" ?";
 cgi_url = "/server/refresh_a_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&flag="+Math.random();
 
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Refresh_A_Movie;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	g_item.style.backgroundColor = "#ff0000";
     	g_status_item.innerHTML='<font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font>';
     	g_refresh_item.innerHTML=' <img border="0" src="refreshing_icon.PNG">';
	//if (g_ch_play_id_item!=null) 
	g_movie_play_id_item.innerHTML='<font face="Arial" size="2"></font>';

 }
 

}
function After_Del_Movie(movie_no)
{
	
	var HTML_str;
	//var ch_no;
	var len;
	var movie_refresh_button; 
	var movie_play_id;
	var movie_src_id; 
	var movie_src_name; 
	var icon_path_name; 
	var movie_src_category; 
	var movie_src_status; 
	var movie_src_duration;
	var movie_src_bitrate;
	
	var movie_src;
	var movie_name;
	var movie_category;
	var icon_path;
	var movie_status;
	var movie_duration;
	var movie_bitrate;
	var item_name;
	var i;
	var save_keyword="Save";
	var add_keyword="Add";
	var del_keyword="Del";
	var refresh_keyword="Refresh";
	var play_keyword="Play";
	var ch_active_no;
	var m;
	var j;
	var k;

	
	var content = parent.document.getElementById("content");
 	var movie_menu_bar= document.getElementById("movie_menu_bar");

	
		HTML_Menu_Bar_Str='<td id=movie_menu_bar>';
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_movie()>"+
		      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_movie()>"+
		      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
	
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_movie()>"+
		      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';
	      }


		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_movie()>"+
		'<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';
		
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_movie()>"+
		'<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
		
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_Movie_Inquery()>"+
		'<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
		HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_Movie_Inquery()>"+
		'<font size="2" face="Arial">Query</font></a>'+'&nbsp&nbsp&nbsp';
		
	      if (g_show_free_version==1)
	      {
		      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
	      }else
	      {
		      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_movie()>"+
		      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
	      }
		    
		//HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_movie_definition()>"+
		//'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';
		      HTML_Menu_Bar_Str+='</td>';
	      
	  HTML_str= '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_movie_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Movie Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Duration(min.)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
	      '<td width="80" align="center"><font face="Arial" size="2">Status</font></td>'+
 	 '</tr>'+'<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
  	g_total_movie_no--;
	movie_active_no=g_total_movie_no;
 	
	for (i=1,m=1;i<=g_total_movie_no;i++,m++)
	{
		//alert(i);
		if (m==(movie_no))
		{
			m++;	      	      
		}
		movie_src_id="moviesrc"+m; 
		item_name=document.getElementById(movie_src_id);
		// alert(item_name.value);
		movie_src = item_name.value;
		
		movie_src_name="moviename"+m; 
		item_name=document.getElementById(movie_src_name);
		movie_name = item_name.value;
		
		icon_path_name="iconpath"+m; 
		item_name=document.getElementById(icon_path_name);
		icon_path = item_name.value;

		movie_src_category="moviecategory"+m; 
		item_name=document.getElementById(movie_src_category);
		movie_category = item_name.value;
		
		
		movie_src_status="moviestatus"+m; 
		item_name=document.getElementById(movie_src_status);
		movie_status = item_name.innerHTML;
		
		movie_src_duration="movieduration"+m; 
		item_name=document.getElementById(movie_src_duration);
		movie_duration = item_name.innerHTML;

		movie_src_bitrate="moviebitrate"+m; 
		item_name=document.getElementById(movie_src_bitrate);
		movie_bitrate = item_name.innerHTML;
		
//		alert(movie_status);
	
		HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
	      '<td width="20" align="center">'+
 		' <input type="checkbox" name=checkbox'+i+
 		' id=checkbox'+i+'></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviename"'+
 		' id=moviename'+i+
 		' size="20" value="'+
	 	movie_name+'"/'+
 		'</font></td>'+
	      '<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviesrc"'+
 		' id=moviesrc'+i+
 		' size="35" value="'+
	 	movie_src+'"/'+
 		'</font></td>'+
	      '<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="iconpath"'+
 		' id=iconpath'+i+
 		' size="35" value="'+
	 	icon_path+'"/'+
 		'</font></td>'+
	      '<td width="10" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="moviecategory"'+
 		' id=moviecategory'+i+
 		' size="10" value="'+
	 	movie_category+'"/'+
 		'</font></td>';
 		//alert(HTML_str);
 		
	
		HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_duration+'</font></td>';
		HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+movie_bitrate+'</font></td>';
		HTML_str+='<td id=moviestatus'+i+' width="100" align="center">'+movie_status+'</td>';		
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Add_New_Movie("'+i+'")>'+
		' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Copy_10_Movies("'+i+'")>'+
		' <img border="0" id="copybutton" alt="Copy 10 Movies" title="Copy 10 Movies" src="add_multiple_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=callServer_Movie_Update("'+i+'")>'+
		' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Del_Movie("'+i+'")>'+
		' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Refresh_A_Movie("'+i+'")>'+
		' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Query_A_Movie_More("'+i+'")>'+
		' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=play_movie("'+i+'")>'+
		' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
		
		HTML_str+='</tr>';
	}
     	i=1;
	if (movie_active_no==0)
	{
		movie_src="";
		movie_name="";
		icon_path="";
		movie_category="";
		
	      HTML_str=HTML_str+'<tr>'+
	      '<td width="20" align="center">'+
		' <input type="checkbox" name=checkbox'+i+
		' id=checkbox'+i+'></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="moviename"'+
		' id=moviename'+i+
		' size="20"/'+
		'</font></td>'+
	      '<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="moviesrc"'+
		' id=moviesrc'+i+
		' size="35"/'+
		'</font></td>'+
		'<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="iconpath"'+
		' id=iconpath'+i+
		' size="35"/'+
		'</font></td>'+
	      '<td width="10" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="moviecategory"'+
		' id=moviecategory'+i+
		' size="10"/'+
		'</font></td>';
		
	     
	
		HTML_str+='<td id=movieduration'+i+' width="100" align="center"><font face="Arial" size="2">'+'0.0'+'</font></td>';
		HTML_str+='<td id=moviebitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+'0.0'+'</font></td>';
		HTML_str+='<td id=moviestatus'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
	      	HTML_str+='<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Movie("'+i+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	      
		      '<td id=save_id_button align="center">'+		      
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Movie()>'+
	      	      ' <img border="0" id="delbutton" alt="Canel" title="Cancel" src="del_icon.PNG"></a></td>'+
	
		      '<td id=del_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      '<td id=refresh_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      '<td id=more_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      '<td id=play_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>';
			        	
  	} 
     
//	alert(HTML_str);
 	content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Movie Total: '+ movie_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td><font face="Arial" size="2"> <input name="movie_search_field" id="movie_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_movie_name();" name="search_movie_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(2);" name="goto_movie_no" /></font>'+	   
	   '</td></tr>'+
	'</table>'+HTML_str+'</table>';

//      alert(ch_list_info.innerHTML);
   
		
}
function Del_Movie() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    // 	Set_Movie_update();
    // 	g_Movie_Updated=1;
    	g_total_movie_no--;
  	alert("Sucessfully");
    } else
    {
   	alert("Failed to Delete Movie");
    }
    g_search_text="";
    call_get_movies(g_movie_position,g_movie_limit);
    
    	//g_Movie_Edit_Mode=1;
    	//After_Del_Movie(g_movie_no);
    	//callServer_CH_Inquery();
    }
}

function call_Del_Movie(movie_no)
{
 var movie_src_id="moviesrc"+movie_no; 
 var movie_src;
 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
 g_item=document.getElementById(movie_src_id);
 movie_src = g_item.value;
   	g_token=find_cookie_value("token");

 confirm_msg="Delete Movie "+movie_no+" ?";
 cgi_url = "/server/del_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(movie_no)+ "&flag="+Math.random();
 g_movie_no=movie_no;
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Del_Movie;
	 xmlHttp.send(null);
 }
 

}
function ezserver_quit_channel(){
 
	//g_Channel_Edit_Mode=0;
	callServer_CH_Inquery();
/*	g_Channel_Edit_Mode=0;
	if (g_Channel_Updated==1)
	{
		callezserver_quit_updated_channel();
		g_Channel_Updated=0;
	}else
	{
		callServer_CH_Inquery();
	}
	*/
}


/*
function callezserver_quit_refresh_channel()
{
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
  var ch_menu_bar= document.getElementById("ch_menu_bar");

	
      	g_token=find_cookie_value("token");

//	cgi_url = "/cgi-bin/cgi_ezserver?token="+encodeURI(g_token)+"&refresh_channel"+"&flag="+Math.random();
	cgi_url = "/server/refresh_channel?token="+encodeURI(g_token)+"&flag="+Math.random();
	
//	confirm_msg="Refresh Channles?";
//	if (confirm(confirm_msg))
//	{
	 	 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = ezserver_quit_refresh_channel;
		 xmlHttp.send(null);
	      ch_menu_bar.innerHTML='<font size="2" face="Arial">Refreshing</font>';

//	}
	

 	
} 
*/

function ezserver_refresh_movie(){
 
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var movie_menu_bar= document.getElementById("movie_menu_bar");
    if (response==1)
    {
  //  	alert("Refresh Movie Sucessfully");
    } else if (response==3)
    {
   	alert("Movies are Refreshing.");
    }else
    {
   	alert("Failed to Refresh Movie");
    }
    g_Movie_Edit_Mode=0;
 // setTimeout("callServer_CH_Inquery()",2000);
/*	if (response==1)
	{
	  setTimeout("Refresh_OK_Msg()",2000);
	}
*/
   callServer_Movie_Inquery();
   show_movie_menu_bar();   
 
 }
 
}

function Get_Movie_Statistics()
{
 
 if (xmlHttp.readyState == 4) {


	var response = xmlHttp.responseText.split("\r\n");
	var movie_no;
	var movie_name;
	var active_player_no=0;
	var i=0;
	var j=0;
	var total_movie_no=0;
	var HTML_str='';
	var strlength=0;
	var content;
	var menustr1;
	var cellsize="15%";

	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>'
	var action_width="80%";
	if (bMobileDevice)
	{
		action_width="20%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Movie Statistics</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:callServer_Get_Channel_Statistics()">Channel</a>';
			str+='</div>'; 
			str+='<div class="menudropdown" style="background-color: #E26498">' ;
			str+='<a href="javascript:callServer_Get_Movie_Statistics()">Movie</a>';
			str+='</div>'; 

		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">Statistics</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="callServer_Get_Channel_Statistics()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Channel</button>'; 
		str+='<button class="button" onclick="callServer_Get_Movie_Statistics()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Movie</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="'+cellsize+'" align="center"><font face="Arial" size="2">No.</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Movie Name</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Active Player No.</font></td>'+
	 	 '</tr>'+'<tr><td  colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
	 	
		while (1)
		{
	 	 	if (response[i]==0) break;
			//alert(response[i]);
		 	strlength=response[i].length;
	   	    	movie_no=response[i].slice(8,strlength);
	     	 	strlength=response[i+1].length;
	   	    	movie_name=response[i+1].slice(5,strlength);
	     	 	strlength=response[i+2].length;
	   	    	active_player_no=response[i+2].slice(10,strlength);
	   	    	
	  
	 		i=i+3;
			HTML_str=HTML_str+
			   '<tr>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+movie_no+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+decodeURI(movie_name)+'</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+active_player_no+'</font></td></tr>';
			total_movie_no++;
	     }
	      //    content.innerHTML=HTML_str;
	      // alert(menu_main.innerHTML);
	
	content.innerHTML=HTML_str+'</table>';
	 	
 	}
 

 
}
function callServer_Get_Movie_Statistics() {
	var content = parent.document.getElementById("content");
	var cgi_url;
	   	
	bSystem_Inquery_Panel=0; 
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
   	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		cgi_url = "/server/get_movie_statistics?token="+encodeURI(g_token)+"&flag="+Math.random();
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Movie Statistics Loading...<p>';
		
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Get_Movie_Statistics;
		xmlHttp.send(null);
	}

}
function callezserver_refresh_movie()
{
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
  var movie_menu_bar= document.getElementById("movie_menu_bar");

	
      	g_token=find_cookie_value("token");

	cgi_url = "/server/refresh_movie?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	//confirm_msg="Do you refresh all channles?";
	//if (confirm(confirm_msg))
	//{
	 	 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = ezserver_refresh_movie;
		 xmlHttp.send(null);
	      movie_menu_bar.innerHTML='<font size="2" face="Arial">Refreshing</font>';

	//}
	

 	
}
function ezserver_refresh_channel(){
 
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var ch_menu_bar= document.getElementById("ch_menu_bar");
    if (response==1)
    {
  //  	alert("Refresh Channel Sucessfully");
    } else if (response==3)
    {
   	alert("Channels are Refreshing.");
    }else
    {
   	alert("Failed to Refresh Channel");
    }
  //  g_Channel_Edit_Mode=0;
 // setTimeout("callServer_CH_Inquery()",2000);
/*	if (response==1)
	{
	  setTimeout("Refresh_OK_Msg()",2000);
	}
*/
   callServer_CH_Inquery();
   show_channel_menu_bar();   
     
   }
 
}
function callezserver_refresh_channel()
{
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
  var ch_menu_bar= document.getElementById("ch_menu_bar");

	
      	g_token=find_cookie_value("token");

//	cgi_url = "/cgi-bin/cgi_ezserver?token="+encodeURI(g_token)+"&refresh_channel"+"&flag="+Math.random();
	cgi_url = "/server/refresh_channel?token="+encodeURI(g_token)+"&flag="+Math.random();

	confirm_msg="Refresh all channels?";
	if (confirm(confirm_msg))
	{
		bQuery_Channel_Status=0;
	 	 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = ezserver_refresh_channel;
		 xmlHttp.send(null);
	      ch_menu_bar.innerHTML='<font size="2" face="Arial">Refreshing</font>';

	}
	

 	
}   


function call_Add_Channel()
{

 
 var ch_src_id="chsrc"; 
 var ch_icon_id="chicon"; 
 var ch_src_name="chname"; 
  var ch_src_category="chcategory"; 
var ch_src_type="chtype"; 
var ch_src_no="chno"; 
 var ch_src;
 var ch_icon;
 var ch_category;
 var ch_name;
 var ch_type;
 var ch_no;
 var g_item_name;
 var add_new_channel_button=document.getElementById("add_new_channel_button");
 var add_channel_dialog_message=document.getElementById("add_channel_dialog_message");
var channelnoitem=document.getElementById(ch_src_no);;;
 var channelnameitem;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
	bQuery_Channel_Status=0;
 
  g_item_name=document.getElementById(ch_src_no);
 	ch_no = g_item_name.value;
/*
alert(g_total_ch_no);
	if (ch_no>(g_total_ch_no+1))
	{
		alert("Channel No. is invaild.");
		return;
	}
	*/
 g_item=document.getElementById(ch_src_id);
 ch_src = g_item.value;
 if (ch_src.length==0)
 {
 	alert("Media Source is empty");
 	return;
 }
 g_item_name=document.getElementById(ch_icon_id);
 ch_icon = g_item_name.value;


 g_item_name=document.getElementById(ch_src_category);
 ch_category = g_item_name.value;

 g_item_name=document.getElementById(ch_src_name);
 channelnameitem=g_item_name;
 ch_name = g_item_name.value;
 if (ch_name.length==0)
 {
 	alert("Channel Name is empty");
 	return;
 }
 g_item_name=document.getElementById(ch_src_type);
 ch_type = g_item_name.value;



   	g_token=find_cookie_value("token");
g_ch_no=ch_no;
 confirm_msg="Add Channel "+ch_no+" Information?";
// cgi_url = "/server/channel_list_add?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&ch_name=" + encodeURI(ch_name)+ "&src=" + encodeURI(ch_src)+ "&category=" + encodeURI(ch_category)+ "&type=" + encodeURI(ch_type)+"&flag="+Math.random();
 cgi_url = "/server/add_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&ch_name=" + encodeURI(ch_name)+ "&src=" + encodeURI(ch_src)+ "&category=" + encodeURI(ch_category)+ "&icon=" + encodeURI(ch_icon)+ "&type=" + encodeURI(ch_type)+"&flag="+Math.random();

	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
		  if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
		    
		   if (response==1)
		    {
		    	//window.close();
		  	g_Channel_Updated=1;
		   	Set_Channel_update();
		     	g_total_ch_no++;
		 	if ((g_channel_position+g_constant_limit)<=g_total_ch_no)
			{
				if (((g_total_ch_no)%g_constant_limit)==1)
				{
					g_channel_position=parseInt(g_total_ch_no);
				}
				g_channel_limit=g_constant_limit;
			}else
			{
				g_channel_limit=g_total_ch_no%g_constant_limit;
				if (g_channel_limit==0) 
				{
					if (g_total_ch_no<g_channel_position)
					{
						g_channel_position=g_total_ch_no-g_constant_limit+1;
					}
					g_channel_limit=g_constant_limit;
				}
			}
			close_channel_modal();
			/*
			add_new_channel_button.value="Add Next";
			var new_add_total_no=g_total_ch_no+1;
			add_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+ch_name+' Added</font>';
			//alert(new_add_total_no);
			channelnoitem.value=new_add_total_no;
			channelnameitem.value="";
			channelnameitem.focus();
			*/

			//call_get_channels(g_channel_position,g_channel_limit);
		   } else if (response==-3)
		   {
		   	alert("Do not support https link, please use Ubuntu 20.04 version and https panel link.");
		   }else
		   {
		   	alert("Failed to Add Channel");
		   }
		
		    } 	
	 };
	 xmlHttp.send(null);
	// g_temp=g_item.value;
	// g_item.value=g_item.value+" (adding...)";
	// g_item.style.backgroundColor = "#ff0000";

}
function Copy_10_Channels() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
 	var dvr_folder_on=0;

  if (response==1)
    {
	g_total_ch_no=parseInt(g_total_ch_no)+parseInt(10);  
	if ((g_channel_position+g_constant_limit)<=g_total_ch_no)
	{
		if (((g_total_ch_no)%g_constant_limit)==1)
		{
			g_channel_position=parseInt(g_total_ch_no);
		}
		g_channel_limit=g_constant_limit;
	}else
	{
		g_channel_limit=g_total_ch_no%g_constant_limit;
		if (g_channel_limit==0) 
		{
			if (g_total_ch_no<g_channel_position)
			{
				g_channel_position=g_total_ch_no-g_constant_limit+1;
			}
			g_channel_limit=g_constant_limit;
		}
	}

	//call_get_channels(g_channel_position,g_channel_limit);
	      	      
   } else if (response==2)
   {
   	alert("This function is only for Enterprise version");
		//callServer_CH_Inquery();
		//call_get_channels(g_channel_position,g_channel_limit);
   }else
    {
   	alert("Failed to Add 10 Channels");
 		//g_Channel_Edit_Mode=1;
		//callServer_CH_Inquery();
		//call_get_channels(g_channel_position,g_channel_limit);
   }

    }
    bQuery_Channel_Status=1;
}
/*
function call_Copy_10_Channels(ch_no)
{
// var g_item_name;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var ch_counter=10; 

g_ch_no=ch_no;
 //confirm_msg="Copy 10 Channels?";
// cgi_url = "/server/channel_list_add?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&ch_name=" + encodeURI(ch_name)+ "&src=" + encodeURI(ch_src)+ "&category=" + encodeURI(ch_category)+ "&type=" + encodeURI(ch_type)+"&flag="+Math.random();
 cgi_url = "/server/copy_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&ch_counter="+encodeURI(ch_counter)+"&flag="+Math.random();
 //alert(cgi_url);
// if (confirm(confirm_msg))
 //{
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Copy_10_Channels;
	 xmlHttp.send(null);
	 //g_temp=g_item.value;
	// g_item.value=g_item.value+" (adding...)";
	 //g_item.style.backgroundColor = "#ff0000";
 //}


}
*/
function call_Copy_10_Channels(ch_no)
{
	var ch_counter=10;
	
	cgi_url = "/server/copy_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&ch_counter="+encodeURI(ch_counter)+"&flag="+Math.random();
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Copy_10_Channels;
	xmlHttp.send(null);
	
}
function old_call_Copy_10_Channels(ch_no)
{
	
	var HTML_str;
	//var ch_no;
	var len;
	var ch_refresh_button; 
	var ch_play_id;
	var ch_src_id; 
	var ch_icon_id; 
	var ch_src_name; 
	var ch_src_category; 
	var ch_src_type; 
	var ch_src_status; 
	var ch_src_bitrate; 
	
	var ch_src;
	var ch_icon;
	var ch_name;
	var ch_category;
	var ch_type;
	var ch_status;
	var ch_bitrate;
	var item_name;
	var i;
	var save_keyword="Save";
	var add_keyword="Add";
	var del_keyword="Del";
	var refresh_keyword="Refresh";
	var more_keyword="More";
	var play_keyword="Play";
	var ch_active_no;
	var m;
	var k;
	var dvr_folder_on=0;
	var HTML_str1;
	var ch_counter=10;
	var s;

	
	var content = parent.document.getElementById("content");
 	var ch_menu_bar= document.getElementById("ch_menu_bar");
//	alert(ch_no);
  //	bQuery_Channel_Status=0;
	g_content=content.innerHTML;
	ch_active_no=g_total_ch_no;
	ch_active_no+=ch_counter;
	
	bQuery_Channel_Status=0;
	
      HTML_Menu_Bar_Str='<td id=ch_menu_bar>';
      if (g_show_free_version==1)
      {
	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';

 	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
 
	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
      }else
      {
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_channel()>"+
	      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';

 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_channel()>"+
	      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
 
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_channel()>"+
	      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';

      }
      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_channel()>"+
      '<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';

      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_channel()>"+
      '<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
 
      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_CH_Inquery()>"+
      '<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';
      
  
      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_CH_Inquery()>"+
      '<font size="2" face="Arial">Auto Query</font></a>'+'&nbsp&nbsp&nbsp';

      if (g_show_free_version==1)
      {
          HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
      }else
      {
          HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_channel()>"+
	      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
      }
      
      //HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_channel_definition()>"+
      //'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';

      HTML_Menu_Bar_Str+='</td>';
	      
	  HTML_str= '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_ch_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="100" align="center"><font face="Arial" size="2">Channel Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="140" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Type</font></td>'+
	      '<td width="120" align="center"><font face="Arial" size="2">Status(Uptime)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
 	 '</tr>'+'<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
 	
	for (i=1,m=1;i<=ch_active_no;m++)
	{
		ch_src_id="chsrc"+m; 
		item_name=document.getElementById(ch_src_id);
		// alert(item_name.value);
		if (item_name)
		{
			ch_src = item_name.value;
	
			ch_icon_id="chicon"+m; 
			item_name=document.getElementById(ch_icon_id);
			ch_icon = item_name.value;
			
			ch_src_name="chname"+m; 
			item_name=document.getElementById(ch_src_name);
			ch_name = item_name.value;
			
			ch_src_category="chcategory"+m; 
			item_name=document.getElementById(ch_src_category);
			ch_category = item_name.value;
			
			ch_src_type="chtype"+m; 
			item_name=document.getElementById(ch_src_type);
			ch_type = item_name.value;
			
			ch_src_status="chstatus"+m; 
			item_name=document.getElementById(ch_src_status);
			ch_status = item_name.innerHTML;
	
			ch_src_bitrate="chbitrate"+m; 
			item_name=document.getElementById(ch_src_bitrate);
			ch_bitrate = item_name.innerHTML;
			
			
		    	if (ch_type.search("dvr")>=0)
	   	    	{
	   	    		dvr_folder_on=1;
	   	    	}else
	   	    	{
	   	    		dvr_folder_on=0;
	   	    	}
	 
	//		alert(ch_status);
		
			HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		      '<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+i+
	 		' id=checkbox'+i+'></td>'+
	 	       '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="chname"'+
	 		' id=chname'+i+
	 		' size="14" value="'+
		 	ch_name+'"/'+
	 		'</font></td>'+
		      '<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="chsrc"'+
	 		' id=chsrc'+i+
	 		' size="30" value="'+
		 	ch_src+'"/'+
	 		'</font></td>'+
		      '<td width="140" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="chicon"'+
	 		' id=chicon'+i+
	 		' size="20" value="'+
		 	ch_icon+'"/'+
	 		'</font></td>'+
		      '<td width="10" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="chcategory"'+
	 		' id=chcategory'+i+
	 		' size="10" value="'+
		 	ch_category+'"/'+
	 		'</font></td>'+
	 		
		      '<td width="60" align="center">'+
	 		' <font face="Arial" size="2">'+
			' <select size="1" name="chtype" id=chtype'+i+'>';
	 		
			//alert(ch_type);
			if (ch_type.search("live")>=0)
			{
				HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("delay")>=0)
			{
				for (k=0;k<g_delaytime_array.length;k++)
				{
					
					if (ch_type.search(g_delayvalue_array[k])==0)
					{
						break;
					}
				}
				//alert(k);
				HTML_str+='<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					if (j!=k)
					{
						HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					}else 
					{
						HTML_str+='<option selected="selected" value="'+g_delayvalue_array[k]+'">'+g_delaytime_array[k]+'</option>';
					}
											
				}
			}else if (ch_type.search("dvr")>=0)
			{
				HTML_str+='<option selected="selected" value="dvr">'+"DVR"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("inactive")>=0)
			{
				HTML_str+='<option selected="selected" value="inactive">'+"Inactive"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>';
				//'<option value="hls">'+"HLS"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}else if (ch_type.search("movie")>=0)
			{
				HTML_str+='<option selected="selected" value="movie">'+"Movie"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				//'<option value="hls">'+"HLS"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}
			/*
			else if (ch_type.search("hls")>=0)
			{
				HTML_str+='<option selected="selected" value="hls">'+"HLS"+'</option>'+
				'<option value="live">'+"Live"+'</option>'+
				'<option value="dvr">'+"DVR"+'</option>'+
				'<option value="movie">'+"Movie"+'</option>'+
				'<option value="inactive">'+"Inactive"+'</option>';
				for (j=0;j<g_delaytime_array.length;j++)
				{
					
					HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
					
				}
			}
			*/
			HTML_str+='</select></font></td>';
						
			if (m==(ch_no))
			{
				HTML_str+='<td id=chstatus'+i+' width="100" align="center">'+ch_status+'</td>';
				HTML_str+='<td id=chbitrate'+i+' width="100" align="center">'+ch_bitrate+'</td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Add_New_Channel("'+i+'")>'+
				' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Copy_10_Channels("'+i+'")>'+
				' <img border="0" id="copybutton" alt="Copy 10 channels" title="Copy 10 channels" src="add_multiple_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_CH_Update("'+i+'")>'+
				' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Del_Channel("'+i+'")>'+
				' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_Query_One_Channel_Status("'+i+'")>'+
				' <img border="0" id="querybutton" alt="Query" title="Query" src="query_icon.PNG"></a></td>';
				HTML_str+='<td id=refreshchannelbutton'+i+' align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Refresh_A_Channel("'+i+'")>'+
				' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Get_Server_IP("'+i+'")>'+
				' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
				
				HTML_str+='<td id=ch_play_id'+i+' align="center">';
				if (ch_src.search("rtmp")==0)
				{
				    HTML_str+="<a href='javascript:void(0)'"+
				    ' onclick=play_channel("'+i+'",'+'"flv"'+','+dvr_folder_on+')>'+
				    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
				}
				else
				{
				    HTML_str+="<a href='javascript:void(0)'"+
				    ' onclick=play_channel("'+i+'",'+'"ch"'+','+dvr_folder_on+')>'+
				    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
				}				
				HTML_str+='</tr>';
	
				i++;	
				for (s=1;s<=ch_counter;s++)
				{
					ch_status="Connecting";
					ch_bitrate=0;
					
					HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
				      '<td align="center">'+
			 		' <input type="checkbox" name=checkbox'+i+
			 		' id=checkbox'+i+'></td>'+
				      '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
				      '<td width="20" align="center">'+
			 		' <font face="Arial" size="2">'+
			 		' <input type="text" name="chname"'+
			 		' id=chname'+i+
			 		' size="14" value="'+
				 	'('+s+')-'+ch_name+'"/'+
			 		'</font></td>'+
				      '<td width="200" align="center">'+
			 		' <font face="Arial" size="2">'+
			 		' <input type="text" name="chsrc"'+
			 		' id=chsrc'+i+
			 		' size="30" value="'+
				 	ch_src+'"/'+
			 		'</font></td>'+
				      '<td width="140" align="center">'+
			 		' <font face="Arial" size="2">'+
			 		' <input type="text" name="chicon"'+
			 		' id=chicon'+i+
			 		' size="20" value="'+
				 	ch_icon+'"/'+
			 		'</font></td>'+
				      '<td width="10" align="center">'+
			 		' <font face="Arial" size="2">'+
			 		' <input type="text" name="chcategory"'+
			 		' id=chcategory'+i+
			 		' size="10" value="'+
				 	ch_category+'"/'+
			 		'</font></td>'+
			 		
				      '<td width="60" align="center">'+
			 		' <font face="Arial" size="2">'+
					' <select size="1" name="chtype" id=chtype'+i+'>';
			 		
					//alert(ch_type);
					if (ch_type.search("live")>=0)
					{
						HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
						'<option value="movie">'+"Movie"+'</option>'+
						'<option value="dvr">'+"DVR"+'</option>'+
						//'<option value="hls">'+"HLS"+'</option>'+
						'<option value="inactive">'+"Inactive"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							
							HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							
						}
					}else if (ch_type.search("delay")>=0)
					{
						for (k=0;k<g_delaytime_array.length;k++)
						{
							
							if (ch_type.search(g_delayvalue_array[k])==0)
							{
								break;
							}
						}
						//alert(k);
						HTML_str+='<option value="live">'+"Live"+'</option>'+
						'<option value="movie">'+"Movie"+'</option>'+
						'<option value="dvr">'+"DVR"+'</option>'+
						//'<option value="hls">'+"HLS"+'</option>'+
						'<option value="inactive">'+"Inactive"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							if (j!=k)
							{
								HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							}else 
							{
								HTML_str+='<option selected="selected" value="'+g_delayvalue_array[k]+'">'+g_delaytime_array[k]+'</option>';
							}
													
						}
					}else if (ch_type.search("dvr")>=0)
					{
						HTML_str+='<option selected="selected" value="dvr">'+"DVR"+'</option>'+
						'<option value="live">'+"Live"+'</option>'+
						'<option value="movie">'+"Movie"+'</option>'+
						//'<option value="hls">'+"HLS"+'</option>'+
						'<option value="inactive">'+"Inactive"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							
							HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							
						}
					}else if (ch_type.search("inactive")>=0)
					{
						HTML_str+='<option selected="selected" value="inactive">'+"Inactive"+'</option>'+
						'<option value="live">'+"Live"+'</option>'+
						'<option value="movie">'+"Movie"+'</option>'+
						'<option value="dvr">'+"DVR"+'</option>';
						//'<option value="hls">'+"HLS"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							
							HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							
						}
					}else if (ch_type.search("movie")>=0)
					{
						HTML_str+='<option selected="selected" value="movie">'+"Movie"+'</option>'+
						'<option value="live">'+"Live"+'</option>'+
						'<option value="dvr">'+"DVR"+'</option>'+
						//'<option value="hls">'+"HLS"+'</option>'+
						'<option value="inactive">'+"Inactive"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							
							HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							
						}
					}
					/* 
					else if (ch_type.search("hls")>=0)
					{
						HTML_str+='<option selected="selected" value="hls">'+"HLS"+'</option>'+
						'<option value="live">'+"Live"+'</option>'+
						'<option value="dvr">'+"DVR"+'</option>'+
						'<option value="movie">'+"Movie"+'</option>'+
						'<option value="inactive">'+"Inactive"+'</option>';
						for (j=0;j<g_delaytime_array.length;j++)
						{
							
							HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
							
						}
					}
					*/
					HTML_str+='</select></font></td>';
					HTML_str+='<td id=chstatus'+i+' width="100" align="center"><font face="Arial" size="2">'+ch_status+'</font></td>';
					HTML_str+='<td id=chbitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+ch_bitrate+'</font></td>';
					HTML_str+='<td align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=call_Add_New_Channel("'+i+'")>'+
					' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
					HTML_str+='<td align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=call_Copy_10_Channels("'+i+'")>'+
					' <img border="0" id="copybutton" alt="Copy 10 channels" title="Copy 10 channels" src="add_multiple_icon.PNG"></a></td>';
					HTML_str+='<td align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=callServer_CH_Update("'+i+'")>'+
					' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
					HTML_str+='<td align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=call_Del_Channel("'+i+'")>'+
					' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
					
					HTML_str+='<td align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=callServer_Query_One_Channel_Status("'+i+'")>'+
					' <img border="0" id="querybutton" alt="Query" title="Query" src="query_icon.PNG"></a></td>';
			
					HTML_str+='<td id=refreshchannelbutton'+i+' align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=call_Refresh_A_Channel("'+i+'")>'+
					' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
					HTML_str+='<td align="center">'+
					"<a href='javascript:void(0)'"+
					' onclick=call_Get_Server_IP("'+i+'")>'+
					' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
					
					HTML_str+='<td id=ch_play_id'+i+' align="center">';
					if (ch_src.search("rtmp")==0)
					{
					    HTML_str+="<a href='javascript:void(0)'"+
					    ' onclick=play_channel("'+i+'",'+'"flv"'+','+dvr_folder_on+')>'+
					    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
					}
					else
					{
					    HTML_str+="<a href='javascript:void(0)'"+
					    ' onclick=play_channel("'+i+'",'+'"ch"'+','+dvr_folder_on+')>'+
					    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
					}				
						
					
					HTML_str+='</tr>';
					i++;
				}
				
			
			}else
			{		
				HTML_str+='<td id=chstatus'+i+' width="100" align="center"><font face="Arial" size="2">'+ch_status+'</font></td>';
				HTML_str+='<td id=chbitrate'+i+' width="100" align="center"><font face="Arial" size="2">'+ch_bitrate+'</font></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Add_New_Channel("'+i+'")>'+
				' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Copy_10_Channels("'+i+'")>'+
				' <img border="0" id="copybutton" alt="Copy 10 channels" title="Copy 10 channels" src="add_multiple_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_CH_Update("'+i+'")>'+
				' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Del_Channel("'+i+'")>'+
				' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
				
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=callServer_Query_One_Channel_Status("'+i+'")>'+
				' <img border="0" id="querybutton" alt="Query" title="Query" src="query_icon.PNG"></a></td>';
		
				HTML_str+='<td id=refreshchannelbutton'+i+' align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Refresh_A_Channel("'+i+'")>'+
				' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
				HTML_str+='<td align="center">'+
				"<a href='javascript:void(0)'"+
				' onclick=call_Get_Server_IP("'+i+'")>'+
				' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
				
				HTML_str+='<td id=ch_play_id'+i+' align="center">';
				if (ch_src.search("rtmp")==0)
				{
				    HTML_str+="<a href='javascript:void(0)'"+
				    ' onclick=play_channel("'+i+'",'+'"flv"'+','+dvr_folder_on+')>'+
				    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
				}
				else
				{
				    HTML_str+="<a href='javascript:void(0)'"+
				    ' onclick=play_channel("'+i+'",'+'"ch"'+','+dvr_folder_on+')>'+
				    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
				}				
					
				
				HTML_str+='</tr>';
				i++;
			}
		}
	      	     
	      	      	
	}
     
     
//	alert(HTML_str);
	content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Channel Total: '+ch_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td> <font face="Arial" size="2"> <input name="channel_search_field" id="channel_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_channel_name();" name="search_channel_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(1);" name="goto_channel_no" /></font>'+	   
	   '</td></tr>'+'</table>'+HTML_str+'</table>';
	'</table>'+HTML_str+'</table>';

   //    content.innerHTML=HTML_str+'</table>';
//      alert(ch_list_info.innerHTML);
   	 cgi_url = "/server/copy_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+"&ch_counter="+encodeURI(ch_counter)+"&flag="+Math.random();
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Copy_10_Channels;
	 xmlHttp.send(null);

		
}

function CH_update() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var play_id_button="ch_play_id"+g_ch_no;
    var ch_src_id="chsrc"+g_ch_no; 
  var ch_src_type="chtype"+g_ch_no; 
 var ch_src;
  var ch_type;
 var g_item_name;
	var dvr_folder_on=0;
	
    if (response==1)
    {
  	Set_Channel_update();
  	g_Channel_Updated=1;
  	
  	
	/*item_play=document.getElementById(play_id_button);

	 g_item=document.getElementById(ch_src_id);
	 ch_src = g_item.value;
	 g_item_name=document.getElementById(ch_src_type);
	 ch_type = g_item_name.value;
    	if (ch_type.search("dvr")>=0)
    	{
    		dvr_folder_on=1;
    	}else
    	{
    		dvr_folder_on=0;
    	}	      	      
	if (ch_src.search("rtmp")==0)
	{
		item_play.innerHTML='<td align="center" id=ch_play_id'+g_ch_no+'>'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=play_channel("'+g_ch_no+'",'+'"flv"'+','+dvr_folder_on+')>'+		      
	      	      ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
	}
	else
	{
		item_play.innerHTML='<td align="center" id=ch_play_id'+g_ch_no+'>'+
		      "<a href='javascript:void(0)'"+
		    ' onclick=play_channel("'+g_ch_no+'",'+'"ch"'+','+dvr_folder_on+')>'+	      
	      	      ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
	}	
	*/	

 //   	alert("Update Channel Sucessfully");
    } else
    {
   	alert("Failed to Update Channel");
    }
	g_item.value=g_temp;
	g_item.style.backgroundColor = "#ffffff";
    }
 //   bQuery_Channel_Status=1;
//	if (g_Query_Channel_Status_timer==0)
	//{
		//g_Query_Channel_Status_timer=setInterval(function(){callServer_Get_Channels_Status_Timer()},10*1000);
		// alert(g_Query_Channel_Status_timer);
	//} 
  //  setTimeout("callServer_CH_Inquery()",2000);
}

function callServer_CH_Update(ch_no){
	
var ch_src_id="chsrc"+ch_no; 
var ch_icon_id="chicon"+ch_no; 
 var ch_src_name="chname"+ch_no; 
 var ch_src_category="chcategory"+ch_no; 
 var ch_src_type="chtype"+ch_no; 
 var ch_src;
 var ch_icon;
 var ch_name;
 var ch_category;
 var ch_type;
 var g_item_name;


 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var g_ch_play_id;
	var pid;
//alert("111111");	
 bQuery_Channel_Status=0;	
 g_ch_no=ch_no;
 g_item=document.getElementById(ch_src_id);
 ch_src = g_item.value;
 if (ch_src.length==0)
 {
 	alert("Media Source is empty");
 	return;
 }
 g_item_name=document.getElementById(ch_icon_id);
 ch_icon = g_item_name.value;

 g_item_name=document.getElementById(ch_src_name);
 ch_name = g_item_name.value;
 if (ch_name.length==0)
 {
 	alert("Channel Name is empty");
 	return;
 }
// alert(ch_name);
 g_item_name=document.getElementById(ch_src_category);
 ch_category = g_item_name.value;
  g_item_name=document.getElementById(ch_src_type);
 ch_type = g_item_name.value;
 	g_token=find_cookie_value("token");

 confirm_msg="Update Channel "+ch_no+" Information?";
// cgi_url = "/server/channel_list_update?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&ch_name=" + encodeURI(ch_name)+ "&src=" + encodeURI(ch_src)+ "&category=" + encodeURI(ch_category)+ "&type=" + encodeURI(ch_type)+"&flag="+Math.random();
// cgi_url = "/server/channel_list_update?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&ch_name=" + encodeURI(ch_name)+ "&src=" + ch_src+ "&category=" + encodeURI(ch_category)+ "&type=" + encodeURI(ch_type)+"&flag="+Math.random();
cgi_url = "/server/update_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&ch_name=" + encodeURI(ch_name)+ "&src=" + ch_src+ "&category=" + encodeURI(ch_category)+ "&icon=" + ch_icon+ "&type=" + encodeURI(ch_type)+"&flag="+Math.random();

	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = CH_update;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	// g_item.value=g_item.value+" (updating...)";
	g_item.style.backgroundColor = "#ff0000";

 

}
function Refresh_A_Channel() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var ch_play_id="ch_play_id"+g_ch_no;
 var ch_status="chstatus"+g_ch_no; 
 var ch_bitrate="chbitrate"+g_ch_no; 
 var ch_chtype="chtype"+g_ch_no; 
 var ch_type_value;
 var dvr_folder_on;
 var bitrate_item;
  
    if ((response==1) || (response==2))
    {
 //   	alert("Refresh Channel Sucessfully");
	 g_ch_play_id_item=document.getElementById(ch_play_id);
	 g_status_item=document.getElementById(ch_status);
	 bitrate_item=document.getElementById(ch_bitrate);
	 g_chtype_item=document.getElementById(ch_chtype);
	 ch_type_value=g_chtype_item.value;
 
     	if (ch_type_value.search("inactive")==0)
     	{
   		g_status_item.innerHTML='<font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font>';
   		//if (g_ch_play_id_item!=null)
   		//{
		g_ch_play_id_item.innerHTML='<font face="Arial" size="2"></font>';
		//}
		
	}else
	{
    		if (response==1)
    		{
    			g_status_item.innerHTML='<font face="Arial" size="2">'+"ON"+'</font>';
    		}else if (response==2)
		{
    			g_status_item.innerHTML='<font face="Arial" size="2" color="#0000FF">'+"Connecting"+'</font>';
		}
    			
		bitrate_item.innerHTML='<font face="Arial" size="2">'+"0"+'</font>';
    		
		if (ch_type_value.search("dvr")>=0)
	    	{
	    		dvr_folder_on=1;
	    	}else
	    	{
	    		dvr_folder_on=0;
	    	}	
	    	//if (g_ch_play_id_item!=null)
	        //{	
		if (g_ch_src.search("rtmp")==0)
		{
		    	 g_ch_play_id_item.innerHTML="<a href='javascript:void(0)'"+
		    ' onclick=play_channel("'+g_ch_no+'",'+'"flv"'+','+dvr_folder_on+')>'+
		    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a>';
		}
		else
		{
		    g_ch_play_id_item.innerHTML="<a href='javascript:void(0)'"+
		    ' onclick=play_channel("'+g_ch_no+'",'+'"ch"'+','+dvr_folder_on+')>'+
		    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a>';
		}
		//}
	}
     			
	g_item.style.backgroundColor = "#ffffff";

    }else if (response==3)
    {
   	alert("The Channel is connecting.");
   	g_item.style.backgroundColor = "#ffffff";
    	
    }else if (response==4)
    {
   	alert("Channels are Refreshing.");
   	g_item.style.backgroundColor = "#ffffff";
    	
    }else if (response==0)
	{
	alert("Failed to Refresh Channel");
	g_item.style.backgroundColor = "#ffffff";
	}
    	
  	 g_item.value=g_ch_src;
  	 
/*     	g_refresh_item.innerHTML='<td id=refreshchannelbutton'+g_ch_no+' width="50" align="center">'+
	      "<a href='javascript:void(0)'"+
	      ' onclick=call_Refresh_A_Channel("'+g_ch_no+'")>'+
      	      ' <font face="Arial" size="2">Refresh</font></a></td>';
  */
     	g_refresh_item.innerHTML="<a href='javascript:void(0)'"+
	      ' onclick=call_Refresh_A_Channel("'+g_ch_no+'")>'+
      	      ' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a>';

  }
}

function call_Refresh_A_Channel(ch_no)
{
 var ch_src_id="chsrc"+ch_no; 
 var ch_status="chstatus"+ch_no; 
 var ch_refresh_button="refreshchannelbutton"+ch_no; 
 var ch_play_id="ch_play_id"+ch_no;

 var ch_src;
 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
//	bQuery_Channel_Status=0;
 g_item=document.getElementById(ch_src_id);
g_status_item=document.getElementById(ch_status);
g_refresh_item=document.getElementById(ch_refresh_button);
g_ch_play_id_item=document.getElementById(ch_play_id);
	g_ch_no=ch_no;

 ch_src = g_item.value;
 g_ch_src=ch_src;
 	g_token=find_cookie_value("token");

 confirm_msg="Refresh Channel "+ch_no+" ?";
 cgi_url = "/server/refresh_a_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&flag="+Math.random();
 
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Refresh_A_Channel;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	g_item.style.backgroundColor = "#ff0000";
//     	g_status_item.innerHTML='<td id=chstatus'+ch_no+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
  //   	g_refresh_item.innerHTML='<td id=refreshchannelbutton'+ch_no+' width="50" align="center">'+' <font face="Arial" size="2">Waiting</font></td>';
     	g_status_item.innerHTML='<font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font>';
     	g_refresh_item.innerHTML=' <img border="0" alt="Refresh" src="refreshing_icon.PNG">';
	//if (g_ch_play_id_item!=null) 
	g_ch_play_id_item.innerHTML='<font face="Arial" size="2"></font>';

 }
 

}
function After_Del_Channel(ch_no)
{
	
	var HTML_str;
	//var ch_no;
	var len;
	var ch_refresh_button; 
	var ch_play_id;
	var ch_src_id; 
	var ch_src_icon; 
	var ch_src_name; 
	var ch_src_category; 
	var ch_src_type; 
	var ch_src_status; 
	
	var ch_src;
	var ch_icon;
	var ch_name;
	var ch_category;
	var ch_type;
	var ch_status;
	var item_name;
	var i;
	var save_keyword="Save";
	var add_keyword="Add";
	var del_keyword="Del";
	var refresh_keyword="Refresh";
	var more_keyword="More";
	var play_keyword="Play";
	var ch_active_no;
	var m;
	var j;
	var k;
	var dvr_folder_on=0;

	
	var content = parent.document.getElementById("content");
 	var ch_menu_bar= document.getElementById("ch_menu_bar");

	
      HTML_Menu_Bar_Str='<td id=ch_menu_bar>';
      
      if (g_show_free_version==1)
      {
	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Cut</font>'+'&nbsp&nbsp&nbsp';

 	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Copy</font>'+'&nbsp&nbsp&nbsp';
 
	      HTML_Menu_Bar_Str+='<font size="2" face="Arial">Paste</font>'+'&nbsp&nbsp&nbsp';
      }else
      {
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_cut_selected_channel()>"+
	      '<font size="2" face="Arial">Cut</font></a>'+'&nbsp&nbsp&nbsp';

 	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_copy_selected_channel()>"+
	      '<font size="2" face="Arial">Copy</font></a>'+'&nbsp&nbsp&nbsp';
 
	      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_paste_selected_channel()>"+
	      '<font size="2" face="Arial">Paste</font></a>'+'&nbsp&nbsp&nbsp';

      }
     HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_channel()>"+
      '<font size="2" face="Arial">Delete</font></a>'+'&nbsp&nbsp&nbsp';

      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callezserver_refresh_selected_channel()>"+
      '<font size="2" face="Arial">Refresh</font></a>'+'&nbsp&nbsp&nbsp';
      
      
      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=Preview_callServer_CH_Inquery()>"+
      '<font size="2" face="Arial">Preview</font></a>'+'&nbsp&nbsp&nbsp';

      HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=callServer_CH_Inquery()>"+
      '<font size="2" face="Arial">Auto Query</font></a>'+'&nbsp&nbsp&nbsp';

      if (g_show_free_version==1)
      {
          HTML_Menu_Bar_Str+='<font size="2" face="Arial">Import</font>'+'&nbsp&nbsp&nbsp';
      }else
      {
          HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_import_channel()>"+
	      '<font size="2" face="Arial">Import</font></a>'+'&nbsp&nbsp&nbsp';
      }
      
      //HTML_Menu_Bar_Str+="<a href='javascript:void(0)' onclick=call_export_channel_definition()>"+
      //'<font size="2" face="Arial">Export</font></a>'+'&nbsp&nbsp&nbsp';

      HTML_Menu_Bar_Str+='</td>';
	      
	  HTML_str= '<table border="0" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_total_ch_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>'+
	      '<td width="100" align="center"><font face="Arial" size="2">Channel Name</font></td>'+
	      '<td width="200" align="center"><font face="Arial" size="2">Media Source</font></td>'+
	      '<td width="140" align="center"><font face="Arial" size="2">Icon Path</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Main Category</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Type</font></td>'+
	      '<td width="120" align="center"><font face="Arial" size="2">Status(Uptime)</font></td>'+
	      '<td width="60" align="center"><font face="Arial" size="2">Bitrate(Kbps)</font></td>'+
 	 '</tr>'+'<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
 	g_total_ch_no--;
 	ch_active_no=g_total_ch_no;
 	
	for (i=1,m=1;i<=g_total_ch_no;i++,m++)
	{
		//alert(i);
		if (m==(ch_no))
		{
			m++;	      	      
		}
		ch_src_id="chsrc"+m; 
		item_name=document.getElementById(ch_src_id);
		// alert(item_name.value);
		ch_src = item_name.value;
		
		ch_src_name="chname"+m; 
		item_name=document.getElementById(ch_src_name);
		ch_name = item_name.value;
		
		ch_src_icon="chicon"+m; 
		item_name=document.getElementById(ch_src_icon);
		ch_icon = item_name.value;

		ch_src_category="chcategory"+m; 
		item_name=document.getElementById(ch_src_category);
		ch_category = item_name.value;
		
		ch_src_type="chtype"+m; 
		item_name=document.getElementById(ch_src_type);
		ch_type = item_name.value;
		
		ch_src_status="chstatus"+m; 
		item_name=document.getElementById(ch_src_status);
		ch_status = item_name.innerHTML;

		ch_src_bitrate="chbitrate"+m; 
		item_name=document.getElementById(ch_src_bitrate);
		ch_bitrate = item_name.innerHTML;
		
		if (ch_type.search("dvr")>=0)
   	    	{
   	    		dvr_folder_on=1;
   	    	}else
   	    	{
   	    		dvr_folder_on=0;
   	    	}
//		alert(ch_status);
	
		HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
	      '<td width="20" align="center">'+
 		' <input type="checkbox" name=checkbox'+i+
 		' id=checkbox'+i+'></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="chname"'+
 		' id=chname'+i+
 		' size="14" value="'+
	 	ch_name+'"/'+
 		'</font></td>'+
	      '<td width="200" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="chsrc"'+
 		' id=chsrc'+i+
 		' size="30" value="'+
	 	ch_src+'"/'+
 		'</font></td>'+
	      '<td width="140" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="chicon"'+
 		' id=chicon'+i+
 		' size="20" value="'+
	 	ch_icon+'"/'+
 		'</font></td>'+
	      '<td width="10" align="center">'+
 		' <font face="Arial" size="2">'+
 		' <input type="text" name="chcategory"'+
 		' id=chcategory'+i+
 		' size="10" value="'+
	 	ch_category+'"/'+
 		'</font></td>'+
 		
	      '<td width="60" align="center">'+
 		' <font face="Arial" size="2">'+
		' <select size="1" name="chtype" id=chtype'+i+'>';
 		
		HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
		'<option value="movie">'+"Movie"+'</option>'+
		'<option value="dvr">'+"DVR"+'</option>'+
		//'<option value="hls">'+"HLS"+'</option>'+
		'<option value="inactive">'+"Inactive"+'</option>';
		for (j=0;j<g_delaytime_array.length;j++)
		{
			
			HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
			
		}
		HTML_str+='</select></font></td>';
		
		HTML_str+='<td id=chstatus'+i+' width="100" align="center">'+ch_status+'</td>';
		HTML_str+='<td id=chbitrate'+i+' width="100" align="center">'+ch_bitrate+'</td>';
		
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Add_New_Channel("'+i+'")>'+
		' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Copy_10_Channels("'+i+'")>'+
		' <img border="0" id="copybutton" alt="Copy 10 channels" title="Copy 10 channels" src="add_multiple_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=callServer_CH_Update("'+i+'")>'+
		' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Del_Channel("'+i+'")>'+
		' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
		
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=callServer_Query_One_Channel_Status("'+i+'")>'+
		' <img border="0" id="querybutton" alt="Query" title="Query" src="query_icon.PNG"></a></td>';

		HTML_str+='<td id=refreshchannelbutton'+i+' align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Refresh_A_Channel("'+i+'")>'+
		' <img border="0" id="refreshbutton" alt="Refresh" title="Refresh" src="refresh_icon.PNG"></a></td>';
		HTML_str+='<td align="center">'+
		"<a href='javascript:void(0)'"+
		' onclick=call_Get_Server_IP("'+i+'")>'+
		' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';
		
		HTML_str+='<td id=ch_play_id'+i+' align="center">';
		if (ch_src.search("rtmp")==0)
		{
		    HTML_str+="<a href='javascript:void(0)'"+
		    ' onclick=play_channel("'+i+'",'+'"flv"'+','+dvr_folder_on+')>'+
		    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
		}
		else
		{
		    HTML_str+="<a href='javascript:void(0)'"+
		    ' onclick=play_channel("'+i+'",'+'"ch"'+','+dvr_folder_on+')>'+
		    ' <img border="0" id="playbutton" alt="Play" title="Play" src="play_icon.PNG"></a></td>';
		}				

		HTML_str+='</tr>';
	}

	if (ch_active_no==0)
	{	
		i=1;
		ch_src="";
		ch_icon="";
		ch_name="";
		ch_category="";
		ch_status="";
		ch_bitrate="";
	      HTML_str=HTML_str+'<tr>'+
	      '<td width="20" align="center">'+
		' <input type="checkbox" name=checkbox'+i+
		' id=checkbox'+i+'></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2">'+i+'</font></td>'+
	      '<td width="20" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chname"'+
		' id=chname'+i+
		' size="14"/'+
		'</font></td>'+
	      '<td width="200" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chsrc"'+
		' id=chsrc'+i+
		' size="30"/'+
		'</font></td>'+
	      '<td width="140" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chicon"'+
		' id=chicon'+i+
		' size="20"/'+
		'</font></td>'+
	      '<td width="10" align="center">'+
		' <font face="Arial" size="2">'+
		' <input type="text" name="chcategory"'+
		' id=chcategory'+i+
		' size="10"/'+
		'</font></td>'+
		
	      '<td width="60" align="center">'+
		' <font face="Arial" size="2">'+
		' <select size="1" name="chtype" id=chtype'+i+'>';
		
		HTML_str+='<option selected="selected" value="live">'+"Live"+'</option>'+
		'<option value="movie">'+"Movie"+'</option>'+
		'<option value="dvr">'+"DVR"+'</option>'+
		//'<option value="hls">'+"HLS"+'</option>'+
		'<option value="inactive">'+"Inactive"+'</option>';
		for (j=0;j<g_delaytime_array.length;j++)
		{
			
			HTML_str+='<option value="'+g_delayvalue_array[j]+'">'+g_delaytime_array[j]+'</option>';
			
		}
		HTML_str+='</select></font></td>';
	
		HTML_str+='<td id=chstatus'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+"<b>OFF</b>"+'</font></td>';
		HTML_str+='<td id=chbitrate'+i+' width="100" align="center"><font face="Arial" size="2" color="#FF0000">'+ch_bitrate+'</font></td>';
	      	HTML_str+=
	      		'<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Channel("'+i+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	
	      		'<td id=copy_id_button align="center">'+
		       ' <font face="Arial" size="2"></font></a></td>'+
	      	      
		      '<td id=save_id_button align="center">'+		      
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Channel()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+
	      	      
		      '<td id=del_id_button  align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
	
		      
		      '<td id=querystatusbutton align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
	
		      '<td id=refreshchannelbutton'+i+' align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      
		      '<td id=more_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
		      
		      '<td align="center" id=ch_play_id'+i+' align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>';

	}     
    
//	alert(HTML_str);
/*	content.innerHTML='<table width=99%><tr><td width=20%>'+
  	'<font size="2" face="Arial">Channel Total: '+ ch_active_no+'</td>'+HTML_Menu_Bar_Str+
 	'</tr></table>'+HTML_str+'</table>';
*/
	content.innerHTML='<table width=99%><tr><td>'+
  	'<font size="2" face="Arial">Channel Total: '+ch_active_no+'</td></tr><tr>'+HTML_Menu_Bar_Str+
 	'<td> <font face="Arial" size="2"> <input name="channel_search_field" id="channel_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_channel_name();" name="search_channel_name" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(1);" name="goto_channel_no" /></font>'+	 
	   '</td></tr>'+'</table>'+HTML_str+'</table>';

   //    content.innerHTML=HTML_str+'</table>';
//      alert(ch_list_info.innerHTML);
   
		
}
function Del_Channel() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
	//	Set_Channel_update();
	//	g_Channel_Updated=1;
	//	After_Del_Channel(g_ch_no);
	//	alert("Sucessfully, Refresh Channels to active all channels");
		g_total_ch_no--;
		alert("Sucessfully");
	} else if (response==2)
	{
		alert("The previous channel is deleting.");		
	}else
	{
		alert("Failed to Delete Channel");
	}
	g_search_text="";
	call_get_channels(g_channel_position,g_channel_limit);
	//g_Channel_Edit_Mode=1;
	//callServer_CH_Inquery();
    }
}

function call_Del_Channel(ch_no)
{
 var ch_src_id="chsrc"+ch_no; 
 var ch_src;
 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;

/*	if (g_total_ch_no==1)
	{
		alert("Warning: EZserver needs at least one channel.");
		return;
	}
	*/
bQuery_Channel_Status=0;
	
 g_item=document.getElementById(ch_src_id);
 ch_src = g_item.value;
   	g_token=find_cookie_value("token");

 confirm_msg="Delete Channel "+ch_no+" ?";
 cgi_url = "/server/del_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&flag="+Math.random();
 g_ch_no=ch_no;
 if (confirm(confirm_msg))
 {
 	
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Del_Channel;
	 xmlHttp.send(null);
 }


}

// Edit Commands
function get_checked_string(total_no,backgrond_type)
{
	var i=0;
	var chcheckbox;
	var checkboj;
	var checkedstring="";
	var emptyitem=1;
	var ch_src_name; 
	var movie_name;
	var username;
	g_selectedcounter=0;
 	for (i=1;i<=total_no;i++)
	{
		chcheckbox="checkbox"+i;
		//alert(i);
		checkboj=document.getElementById(chcheckbox);
		//alert(checkboj);
		if (checkboj)
		{
			if (checkboj.checked==true)
			{
				checkedstring=checkedstring+'1';
				g_selectedcounter++;
				//alert(checkedstring);
				emptyitem=0;
				if (backgrond_type==1)
				{
					ch_src_name="chname"+i; 
					g_item=document.getElementById(ch_src_name);
					g_item.style.backgroundColor = "#ff0000";
				}else if (backgrond_type==2)
				{
					movie_name="moviename"+i; 
					g_item=document.getElementById(movie_name);
					g_item.style.backgroundColor = "#ff0000";
				}else if (backgrond_type==3)
				{
					username="username"+i; 
					g_item=document.getElementById(username);
					g_item.style.backgroundColor = "#ff0000";
				}
					
			}else
			{
				checkedstring=checkedstring+'0';
			}
			//alert(checkedstring);
		}
			
		
	}
	if (emptyitem==1)
	{
		//alert("1. No selected item");
		checkedstring='0';
	}
	
	return checkedstring;
	

}
function get_total_checked_string(total_no,backgrond_type)
{
	var i=0;
	var chcheckbox;
	var checkboj;
	var checkedstring="";
	var emptyitem=1;
	var ch_src_name; 
	var movie_name;
	var username;
	g_selectedcounter=0;
 	for (i=1;i<=total_no;i++)
	{
		chcheckbox="checkbox"+i;
		//alert(i);
		checkboj=document.getElementById(chcheckbox);
		//alert(checkboj);
		if (checkboj)
		{
			if (checkboj.checked==true)
			{
				checkedstring=checkedstring+'1';
				g_selectedcounter++;
				//alert(checkedstring);
				emptyitem=0;
				if (backgrond_type==1)
				{
					ch_src_name="chname"+i; 
					g_item=document.getElementById(ch_src_name);
					g_item.style.backgroundColor = "#ff0000";
				}else if (backgrond_type==2)
				{
					movie_name="moviename"+i; 
					g_item=document.getElementById(movie_name);
					g_item.style.backgroundColor = "#ff0000";
				}else if (backgrond_type==3)
				{
					username="username"+i; 
					g_item=document.getElementById(username);
					g_item.style.backgroundColor = "#ff0000";
				}
					
			}else
			{
				checkedstring=checkedstring+'0';
			}
		}else
		{
			checkedstring=checkedstring+'0';
		}
		//alert(checkedstring);
			
		
	}
	if (emptyitem==1)
	{
		alert("2. No selected item");
		checkedstring='0';
	}
	
	return checkedstring;
	

}
function set_all_checked(total_no)
{
	var i;
	var chcheckbox;
	var checkboj;
	var checkflag;
	if (total_no>0)
	{
		checkboj=document.getElementById("checkallbox");
		checkflag=checkboj.checked;
		for (i=1;i<=total_no;i++)
		{
			chcheckbox="checkbox"+i;
			checkboj=document.getElementById(chcheckbox);
			if (checkboj)
			{
				checkboj.checked=checkflag;
			}
		}
	}	
}

function get_checked_no(total_no)
{
	var i=0;
	var chcheckbox;
	var checkboj;
	var emptyitem=1;
	var selectedcount=0;
 	var selectedno=0;
    
	if (total_no<=0)
	{
		return 0;
	}else
	{
		for (i=1;i<=total_no;i++)
		{
			chcheckbox="checkbox"+i;
		//		alert(i);
			checkboj=document.getElementById(chcheckbox);
		//		alert(checkboj);
			if (checkboj)
			{
				if (checkboj.checked==true)
				{
					emptyitem=0;
					selectedcount++;
					selectedno=i;
				}
			}		
		}
		if (emptyitem==1)
		{
			alert("3. No selected item");
			return 0;
		}else
		{
			if (selectedcount>1)
			{
				alert("Please select only one item.")
				return 0;
			}else
				{
					return selectedno;
				}			
		}
	}
}
function clear_checked_string(total_no)
{
	var i;
	var chcheckbox;
	var checkboj;
	var checkflag;
	checkboj=document.getElementById("checkallbox");
	checkboj.checked=false;
	if (total_no>0)
	{
		for (i=1;i<=total_no;i++)
		{
			chcheckbox="checkbox"+i;
			checkboj=document.getElementById(chcheckbox);
			if (checkboj)
			{
				checkboj.checked=false;
			}
		}
	}	
}
function clear_checked_red_background(total_no,backgrond_type)
{
	var i;
	var chcheckbox;
	var checkboj;
	var checkflag;
	var ch_src_name; 
	var movie_name;
	var username;
	checkboj=document.getElementById("checkallbox");
	if (total_no>0)
	{
		for (i=1;i<=total_no;i++)
		{
			chcheckbox="checkbox"+i;
			checkboj=document.getElementById(chcheckbox);
			if (checkboj)
			{
				if (backgrond_type==1)
				{
					ch_src_name="chname"+i; 
					g_item=document.getElementById(ch_src_name);
					g_item.style.backgroundColor = "#ffffff";
				}else if (backgrond_type==2)
				{
					movie_name="moviename"+i; 
					g_item=document.getElementById(movie_name);
					g_item.style.backgroundColor = "#ffffff";
				}else if (backgrond_type==3)
				{
					username="username"+i; 
					g_item=document.getElementById(username);
					g_item.style.backgroundColor = "#ffffff";
				}
			}
					
		}
	}	
}
// Channel Edit Commands
function callezserver_copy_selected_channel()
{
	g_checkedstring=get_checked_string(g_total_ch_no,1);
	g_copy_paste=1;
	clear_checked_string(g_total_ch_no);

}

function callezserver_cut_selected_channel()
{
	if (g_copy_paste==0)
	{
		g_checkedstring=get_checked_string(g_total_ch_no,1);
		if (g_checkedstring=='0')
		{
		}else
		{
			g_copy_paste=2;
	
			clear_checked_string(g_total_ch_no);
			g_channel_selected_position=g_channel_position;
			document.getElementById("channel_cut_field").innerHTML='<p align="left" style="margin-top: 0; margin-bottom: 0"><b>Paste</b>';
			document.getElementById("channel_cut_field").onclick= function(){javscript: callezserver_paste_selected_channel();};
		}
	}
}
function paste_selected_channel() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		if (g_copy_paste==1)
		{
			g_total_ch_no+=g_selectedcounter;
		}
	}else
	{
		alert("Failed to Paste Channel");
	}
	
	g_copy_paste=0;
	g_checkedstring='0'
	call_get_channels(g_channel_position,g_channel_limit);

    }
}

function callezserver_paste_selected_channel()
{
	var cgi_url;
	var content = parent.document.getElementById("content");
	var destination_no;


	bQuery_Channel_Status=0;
	destination_no=get_checked_no(g_total_ch_no);
	clear_checked_string(g_total_ch_no);
	if (destination_no==0)
	{
		confirm_msg="Contine to Select Position?";
		if (confirm(confirm_msg))
		{
		}else
		{
			clear_checked_red_background(g_total_ch_no,1);
			document.getElementById("channel_cut_field").value="Cut";
			document.getElementById("channel_cut_field").onclick= function(){javscript: callezserver_cut_selected_channel();};

		}
	}else
	{
		g_token=find_cookie_value("token");
		if (g_copy_paste==1)
		{
			cgi_url = "/server/copy_paste_multiple_channels?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_channel_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		}else if (g_copy_paste==2)
		{
			cgi_url = "/server/cut_paste_multiple_channels?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_channel_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		}else
		{
			return;
		}
			
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Paseting Selected Channels...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = paste_selected_channel;
		xmlHttp.send(null);
	}

}
function callezserver_move_selected_channel()
{
	var cgi_url;
	var content = parent.document.getElementById("content");
	var destination_no;
	
	g_checkedstring=get_checked_string(g_total_ch_no,1);
	destination_no=prompt("Move position after","1");
	
	bQuery_Channel_Status=0;
	//destination_no=get_checked_no(g_total_ch_no);
	clear_checked_string(g_total_ch_no);
	if (destination_no<=0)
	{
		confirm_msg="Position needs > 0";
		alert(confirm_msg)
		
		
	}else
	{
		g_token=find_cookie_value("token");
		cgi_url = "/server/cut_paste_multiple_channels?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_channel_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Paseting Selected Channels...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
				var response = xmlHttp.responseText;
				if (response==1)
				{
					if (g_copy_paste==1)
					{
						g_total_ch_no+=g_selectedcounter;
					}
				}else
				{
					alert("Failed to Paste Channel");
				}
				
				g_copy_paste=0;
				g_checkedstring='0'
				call_get_channels(g_channel_position,g_channel_limit);
			
			    }
		};
		xmlHttp.send(null);
	}

}
function delete_selected_channel() {

  /*
  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
	//	Set_Channel_update();
	//	g_Channel_Updated=1;
	//	After_Del_Channel(g_ch_no);
	// 	alert("Sucessfully, Refresh Channels to active all channels");
		g_total_ch_no-=g_selectedcounter;
	}else
	{
		alert("Failed to Delete Channel");
	}
	
	//g_Channel_Edit_Mode=1;
	callServer_CH_Inquery();
    }
    */
     if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		g_total_ch_no-=g_selectedcounter;
		if (g_total_ch_no<0) g_total_ch_no=0;
		if ((g_channel_position+g_constant_limit)<=g_total_ch_no)
		{
			g_channel_limit=g_constant_limit;
		}else
		{
			g_channel_limit=g_total_ch_no%g_constant_limit;
			if (g_channel_limit==0)
			{
				if (g_total_ch_no>0)
				{
					if (g_total_ch_no<g_channel_position)
					{
						g_channel_position=g_total_ch_no-g_constant_limit+1;
					}
					g_channel_limit=g_constant_limit;
				}else
				{
					g_channel_limit=0;
				}
			}
		}

	}else
	{
		alert("Failed to Delete Users");
	}
	
	call_get_channels(g_channel_position,g_channel_limit);
    }
}
function open_mass_delete_channel_modal()
{
	var modal = document.getElementById('PanelModalMassDelete');
	checkedstring=get_checked_string(g_total_ch_no,0);
	if (checkedstring=='0')
	{
		modal.style.display = "block";
	}else
	{
	
		 confirm_msg="Delete Selected Channels?";
		 cgi_url = "/server/del_multiple_channels?token="+encodeURI(g_token)+"&position="+g_channel_position+"&bitstring="+checkedstring+ "&flag="+Math.random();
		 if (confirm(confirm_msg))
		 {	
			 xmlHttp.open("GET", cgi_url, true);
			 xmlHttp.onreadystatechange = delete_selected_channel;
			 xmlHttp.send(null);
			
		 }
	 }
	
}
function close_mass_delete_modal() {
   var modal = document.getElementById('PanelModalMassDelete');
   modal.style.display = "none";
}
function callezserver_mass_delete_selected_channel()
{
	var confirm_msg;
	var category=document.getElementById('mass_delete_category').value;
	var delbutton=document.getElementById('delete_button');
	
   	g_token=find_cookie_value("token");
   	
	 confirm_msg="Delete Selected "+category+"?";
	 cgi_url = "/server/del_multiple_channels?token="+encodeURI(g_token)+"&position="+g_channel_position+"&category="+category+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	if (delbutton)
	 	{
	 		delbutton.value="Waiting";
	 		delbutton.disabled=true;
	 	}	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = function()
		 {
		 	if (xmlHttp.readyState == 4) {
				var response = xmlHttp.responseText;
				if (response>=1)
				{
					if (response>1)
					{
						g_selectedcounter=parseInt(response);
					}
					g_total_ch_no-=g_selectedcounter;
					if (g_total_ch_no<0) g_total_ch_no=0;
					if ((g_channel_position+g_constant_limit)<=g_total_ch_no)
					{
						g_channel_limit=g_constant_limit;
					}else
					{
						g_channel_limit=g_total_ch_no%g_constant_limit;
						if (g_channel_limit==0)
						{
							if (g_total_ch_no>0)
							{
								if (g_total_ch_no<g_channel_position)
								{
									g_channel_position=g_total_ch_no-g_constant_limit+1;
								}
								g_channel_limit=g_constant_limit;
							}else
							{
								g_channel_limit=0;
							}
						}
					}
			
				}else
				{
					alert("Failed to Delete Users");
				}
				if (delbutton)
			 	{
			 		delbutton.value="Delete";
			 		delbutton.disabled=false;
			 	}
				call_get_channels(g_channel_position,g_channel_limit);
		    	}
		 };
		 xmlHttp.send(null);
	 }
 


}
function callezserver_mass_edit_selected_channel()
{
	
	var cgi_url;
	var category_id="mass_edit_chcategory";
	var chtype_id="mass_edit_chtype";
	var netip_id="mass_edit_input_adapter";
	var buffersize_id="mass_edit_buffer_size";
	var tolerance_id="mass_edit_tolerance";
	var cacheondemandflag_id="mass_edit_cacheondemandflag";
	var catch_up_days_id="mass_edit_catch_up_days";
	var http_user_agent_id="mass_edit_http_user_agent";
	
	var forwardflag_id="mass_edit_forwardflag";;
	var bitratetypeflag_id="mass_edit_HLSType";
	var mobilebitrate_id="mass_edit_mobilebitrate";
	var sdbitrate_id="mass_edit_sdbitrate";
	var hdbitrate_id="mass_edit_hdbitrate";
	var mobilewidth_id="mass_edit_mobilewidth";
	var sdwidth_id="mass_edit_sdwidth";
	var hdwidth_id="mass_edit_hdwidth";
	var mobileheight_id="mass_edit_mobileheight";
	var sdheight_id="mass_edit_sdheight";
	var hdheight_id="mass_edit_hdheight";
	var videoformat_id="mass_edit_videoformat";
	var videoaspect_id="mass_edit_videoaspect";
	var audioformat_id="mass_edit_audioformat";
	var preset_id="mass_edit_preset";

   
	var category;
	var chtype;
	var buffersize;
	var tolerance;
	var forwardflag;
	var cacheondemandflag;
	var netip;
	var catch_up_days;
	var http_user_agent;
	var bitratetypeflagarray;
	var bitratetypeflag;
	var mobilebitrate;
	var sdbitrate;
	var hdbitrate;
	var mobilewidth;
	var sdwidth;
	var hdwidth;
	var mobileheight;
	var sdheight;
	var hdheight;
	var videoaspect;
	var preset;  
	var videoformat;
	var audioformat;
	var i=0;	
	
   	g_token=find_cookie_value("token");
   	
//alert(g_checkedstring);	
	if (g_checkedstring=='0')
	{
	}else
	{

		g_item=document.getElementById(category_id);
		//alert(g_item.value);
		category=g_item.value;
		g_item=document.getElementById(chtype_id);
		//alert(g_item.value);
		chtype=g_item.value;

		g_item=document.getElementById(http_user_agent_id);
		//alert(g_item.value);
		http_user_agent=g_item.value;
		
		g_item=document.getElementById(netip_id);
		//alert(g_item.value);
		netip=g_item.value;
		
		g_item=document.getElementById(buffersize_id);
		//alert(g_item.value);
		buffersize=g_item.value;
		if (buffersize == 0)
		{
			alert("Buffer size must be > 0.");
			return;
		}

		g_item=document.getElementById(tolerance_id);
		//alert(g_item.value);
		tolerance=g_item.value;
		
		g_item=document.getElementById(catch_up_days_id);
		//alert(g_item.value);
		catch_up_days=g_item.value;
		
		g_item=document.getElementById(forwardflag_id);
		//alert(g_item.value);
		forwardflag=g_item.value;
	
		g_item=document.getElementById(cacheondemandflag_id);
		//alert(g_item.value);
		if (g_item.checked==true)
		{
			cacheondemandflag=1;
		}else
		{
			cacheondemandflag=0;
		}
		g_item=document.getElementById(bitratetypeflag_id);
		//alert(g_item.value);
		if (g_item.checked==true)
		{
			bitratetypeflag=1;
		}else
		{
			bitratetypeflag=0;
		}
		
		
	
	
	
	
		/* bitratetypeflagarray=document.getElementById(bitratetypeflag_id);
		for (i=0;i<2;i++)
		{
			if (bitratetypeflagarray[i].checked)
			{
				bitratetypeflag=bitratetypeflagarray[i].value;
				//alert(bitratetypeflag);
			}
			
		}
		//alert(bitratetypeflag);
		if (bitratetypeflag==2)
		{
			g_item=document.getElementById(mobilebitrate_id);
			//alert(g_item.value);
			mobilebitrate=g_item.value;
			
			g_item=document.getElementById(sdbitrate_id);
			//alert(g_item.value);
			sdbitrate=g_item.value;
			
			g_item=document.getElementById(hdbitrate_id);
			//alert(g_item.value);
			hdbitrate=g_item.value;
			
			g_item=document.getElementById(mobilewidth_id);
			//alert(g_item.value);
			mobilewidth=g_item.value;
			if ((mobilewidth=="Auto") || (mobilewidth=="auto"))
			{
				mobilewidth=0;
			}
			g_item=document.getElementById(sdwidth_id);
			//alert(g_item.value);
			sdwidth=g_item.value;
			if ((sdwidth=="Auto") || (sdwidth=="auto"))
			{
				sdwidth=0;
			}
			
			g_item=document.getElementById(hdwidth_id);
			//alert(g_item.value);
			hdwidth=g_item.value;
			if ((hdwidth=="Auto") || (hdwidth=="auto"))
			{
				hdwidth=0;
			}
	
			g_item=document.getElementById(mobileheight_id);
			//alert(g_item.value);
			mobileheight=g_item.value;
			if ((mobileheight=="Auto") || (mobileheight=="auto"))
			{
				mobileheight=0;
			}
			
			g_item=document.getElementById(sdheight_id);
			//alert(g_item.value);
			sdheight=g_item.value;
			if ((sdheight=="Auto") || (sdheight=="auto"))
			{
				sdheight=0;
			}
			
			g_item=document.getElementById(hdheight_id);
			//alert(g_item.value);
			hdheight=g_item.value;
			if ((hdheight=="Auto") || (hdheight=="auto"))
			{
				hdheight=0;
			}
			
			g_item=document.getElementById(videoaspect_id);
			//alert(g_item.value);
			videoaspect=g_item.value;
			
		  	//alert(videoaspect);
			if (videoaspect=="Auto")
		  	{
		  		videoaspect='';
		  	}
		  	//alert(videoaspect);
			g_item=document.getElementById(preset_id);
			//alert(g_item.value);
			preset=g_item.value;
	
			g_item=document.getElementById(videoformat_id);
			//alert(g_item.value);
			videoformat=g_item.value;
			
			
	
			g_item=document.getElementById(audioformat_id);
			//alert(g_item.value);
			audioformat=g_item.value;
		}
		*/
	
	   	g_token=find_cookie_value("token");
	
		cgi_url = "/server/edit_multiple_channels?token="+encodeURI(g_token)+
		"&position="+g_channel_position+
		"&category="+category+
		"&type="+chtype+
		"&http_user_agent="+http_user_agent+
		"&netip="+netip+
		
		"&buffersize="+buffersize+
		"&tolerance="+tolerance+
		"&catch_up_days="+catch_up_days+
		"&forward="+forwardflag+
		"&cacheondemand="+cacheondemandflag+
		"&bitratetype="+bitratetypeflag;
		
		/*if (bitratetypeflag==2)
		{
		
		  cgi_url +="&video_format="+videoformat+
		  "&audio_format="+audioformat+
		  "&mobilebitrate="+mobilebitrate+
		  "&sdbitrate="+sdbitrate+
		  "&hdbitrate="+hdbitrate+
		  "&mobilewidth="+mobilewidth+
		  "&sdwidth="+sdwidth+
		  "&hdwidth="+hdwidth+
		  "&mobileheight="+mobileheight+
		  "&sdheight="+sdheight+
		  "&hdheight="+hdheight+
		  "&video_aspect="+videoaspect+
		  "&preset="+preset;
		}
		*/
		
		cgi_url +="&flag="+Math.random();
		//alert(cgi_url);
		 xmlHttp.open("POST", cgi_url, true);
		 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response!=1)
			{
				alert("Failed to Edit Channels");
			}
			close_mass_edit_modal();
			call_get_channels(g_channel_position,g_channel_limit);
		    }
		};
		xmlHttp.send(null);
				 
		//xmlHttp.send(g_checkedstring);
	}
	

}
function refresh_selected_channel() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
	//	Set_Channel_update();
	//	g_Channel_Updated=1;
	//	After_Del_Channel(g_ch_no);
		clear_checked_string(g_total_ch_no);
	 	alert("Sucessfully refresh channels");
	}else
	{
		alert("Failed to Delete Channel");
	}
	bQuery_Channel_Status=1;
	//if (g_Query_Channel_Status_timer==0)
	//{
		//g_Query_Channel_Status_timer=setInterval(function(){callServer_Get_Channels_Status_Timer()},10*1000);
		// alert(g_Query_Channel_Status_timer);

 
	//}
	//g_Channel_Edit_Mode=1;
	//callServer_CH_Inquery();
    }
}

function callezserver_refresh_selected_channel()
{
	var confirm_msg;
	var cgi_url;
	var cookieStr;
	var checkedstring;

	bQuery_Channel_Status=0;
   	g_token=find_cookie_value("token");
checkedstring=get_checked_string(g_total_ch_no,0);

 if (checkedstring=='0')
 {
 }else
{
		
	 confirm_msg="Refresh Selected Channels?";
	 cgi_url = "/server/refresh_multiple_channels?token="+encodeURI(g_token)+"&position="+g_channel_position+"&bitstring="+checkedstring+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = refresh_selected_channel;
		 xmlHttp.send(null);
		// g_temp=g_item.value;
		// g_item.value=g_item.value+" (del...)";
		//g_item.style.backgroundColor = "#ff0000";
	 }
 }


}
// Movie Edit Command
function callezserver_copy_selected_movie()
{
	g_checkedstring=get_checked_string(g_total_movie_no,2);
	g_copy_paste=1;
	clear_checked_string(g_total_movie_no);

}

function callezserver_cut_selected_movie()
{
	if (g_copy_paste==0)
	{
		g_checkedstring=get_checked_string(g_total_movie_no,2);
		if (g_checkedstring=='0')
		{
		}else
		{
			g_copy_paste=2;
			clear_checked_string(g_total_movie_no);
			g_movie_selected_position=g_movie_position;
			document.getElementById("movie_cut_field").innerHTML='<p align="left" style="margin-top: 0; margin-bottom: 0"><b>Paste</b>';
			document.getElementById("movie_cut_field").onclick= function(){javscript: callezserver_paste_selected_movie();};
		}
	}
}
function paste_selected_movie() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		if (g_copy_paste==1)
		{
			g_total_movie_no+=g_selectedcounter;
		}
	}else
	{
		alert("Failed to Paste Channel");
	}
	
	g_copy_paste=0;
	g_checkedstring='0'
	call_get_movies(g_movie_position,g_movie_limit);
    }
}

function callezserver_paste_selected_movie()
{
	var cgi_url;
	var content = parent.document.getElementById("content");
	var destination_no;


	destination_no=get_checked_no(g_total_movie_no);
	clear_checked_string(g_total_movie_no);
	if (destination_no==0)
	{
		confirm_msg="Contine to Select Position?";
		if (confirm(confirm_msg))
		{
		}else
		{
			clear_checked_red_background(g_total_movie_no,1);
			document.getElementById("movie_cut_field").value="  Cut  ";
			document.getElementById("movie_cut_field").onclick= function(){javscript: callezserver_cut_selected_movie();};
		}

	}else
	{
		g_token=find_cookie_value("token");
		if (g_copy_paste==1)
		{
			cgi_url = "/server/copy_paste_multiple_movies?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_movie_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		}else if (g_copy_paste==2)
		{
			cgi_url = "/server/cut_paste_multiple_movies?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_movie_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		}else
		{
			return;
		}
			
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Paseting Selected Movies...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = paste_selected_movie;
		xmlHttp.send(null);
	}

}
function callezserver_move_selected_movie()
{
	var cgi_url;
	var content = parent.document.getElementById("content");
	var destination_no;

	g_checkedstring=get_checked_string(g_total_movie_no,2);
	destination_no=prompt("Move position after","1");
	clear_checked_string(g_total_movie_no);
	if (destination_no<=0)
	{
		confirm_msg="Position needs > 0";
		alert(confirm_msg)

	}else
	{
		g_token=find_cookie_value("token");
		cgi_url = "/server/cut_paste_multiple_movies?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_movie_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		
			
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Paseting Selected Movies...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = paste_selected_movie;
		xmlHttp.send(null);
	}

}
function delete_selected_movie() {

         if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		g_total_movie_no-=g_selectedcounter;
		if (g_total_movie_no<0) g_total_movie_no=0;
		if ((g_movie_position+g_constant_limit)<=g_total_movie_no)
		{
			g_movie_limit=g_constant_limit;
		}else
		{
			g_movie_limit=g_total_movie_no%g_constant_limit;
			if (g_movie_limit==0) 
			{
				if (g_total_movie_no>0)
				{
					if (g_total_movie_no<g_movie_position)
					{
						g_movie_position=g_total_movie_no-g_constant_limit+1;
					}
					g_movie_limit=g_constant_limit;
				}else
				{
					g_movie_limit=0;
				}
			}
		}

	}else
	{
		alert("Failed to Delete Users");
	}
	
	call_get_movies(g_movie_position,g_movie_limit);
    }
}

function open_mass_delete_movie_modal()
{
	var modal = document.getElementById('PanelModalMassDelete');
	checkedstring=get_checked_string(g_total_movie_no,0);
	if (checkedstring=='0')
	{
		modal.style.display = "block";
	}else
	{
	
		 confirm_msg="Delete Selected movies?";
		 cgi_url = "/server/del_multiple_movies?token="+encodeURI(g_token)+"&position="+g_movie_position+"&bitstring="+checkedstring+ "&flag="+Math.random();
		 if (confirm(confirm_msg))
		 {	
			 xmlHttp.open("GET", cgi_url, true);
			 xmlHttp.onreadystatechange = delete_selected_movie;
			 xmlHttp.send(null);
			
		 }
	 }
	
}

function callezserver_mass_delete_selected_movie()
{
	var confirm_msg;
	var category=document.getElementById('mass_delete_category').value;
	var delbutton=document.getElementById('delete_button');
	
   	g_token=find_cookie_value("token");
   	
	 confirm_msg="Delete Selected "+category+"?";
	 cgi_url = "/server/del_multiple_movies?token="+encodeURI(g_token)+"&position="+g_movie_position+"&category="+category+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	if (delbutton)
	 	{
	 		delbutton.value="Waiting";
	 		delbutton.disabled=true;
	 	}	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = function()
		 {
		 	if (xmlHttp.readyState == 4) {
				var response = xmlHttp.responseText;
				if (response>=1)
				{
					if (response>1)
					{
						g_selectedcounter=parseInt(response);
					}
					g_total_movie_no-=g_selectedcounter;
					if (g_total_ch_no<0) g_total_ch_no=0;
					if ((g_movie_position+g_constant_limit)<=g_total_ch_no)
					{
						g_movie_limit=g_constant_limit;
					}else
					{
						g_movie_limit=g_total_ch_no%g_constant_limit;
						if (g_movie_limit==0)
						{
							if (g_total_ch_no>0)
							{
								if (g_total_ch_no<g_movie_position)
								{
									g_movie_position=g_total_ch_no-g_constant_limit+1;
								}
								g_movie_limit=g_constant_limit;
							}else
							{
								g_movie_limit=0;
							}
						}
					}
			
				}else
				{
					alert("Failed to Delete Movies");
				}
				if (delbutton)
			 	{
			 		delbutton.value="Delete";
			 		delbutton.disabled=false;
			 	}
				call_get_movies(g_movie_position,g_movie_limit);
		    	}
		 };
		 xmlHttp.send(null);
	 }
 


}
function refresh_selected_movie() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		clear_checked_string(g_total_movie_no);
	 	alert("Sucessfully refresh movies");
	}else
	{
		alert("Failed to Delete Channel");
	}
	call_get_movies(g_movie_position,g_movie_limit)
	//callServer_Movie_Inquery();
    }
}

function callezserver_refresh_selected_movie()
{
	var confirm_msg;
	var cgi_url;
	var cookieStr;
	var checkedstring;


   	g_token=find_cookie_value("token");
checkedstring=get_checked_string(g_total_movie_no,0);
//alert(checkedstring);
 if (checkedstring=='0')
 {
 }else
{		
	 confirm_msg="Refresh Selected Movies?";
	 cgi_url = "/server/refresh_multiple_movies?token="+encodeURI(g_token)+"&position="+g_movie_position+"&bitstring="+checkedstring+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = refresh_selected_movie;
		 xmlHttp.send(null);
	 }
 }


}
// User Edit Command
function callezserver_copy_selected_user()
{
	g_checkedstring=get_checked_string(g_user_no,3);
	g_copy_paste=1;
	clear_checked_string(g_user_no);

}

function callezserver_cut_selected_user()
{
	if (g_copy_paste==0)
	{
		//alert("callezserver_cut_selected_user");
		g_checkedstring=get_checked_string(g_user_no,3);
		if (g_checkedstring=='0')
		{
		}else
		{
			g_copy_paste=2;
			clear_checked_string(g_user_no);
			g_user_selected_position=g_user_position;
			document.getElementById("user_cut_field").innerHTML='<p align="left" style="margin-left: 0; margin-top: 0; margin-bottom: 0"><b>Paste</b>';
			document.getElementById("user_cut_field").onclick= function(){javscript: callezserver_paste_selected_user();};
		}
	}
}
function paste_selected_user() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		if (g_copy_paste==1)
		{
			g_user_no+=g_selectedcounter;
		}
	}else
	{
		alert("Failed to Paste User");
	}
	
	g_copy_paste=0;
	g_checkedstring='0'
	call_get_users_detail();
    }
}

function callezserver_paste_selected_user()
{
	var confirm_msg;
	var cgi_url;
	var content = parent.document.getElementById("content");
	var destination_no;
	
	//alert("callezserver_paste_selected_user");
	destination_no=get_checked_no(g_user_no);
	//alert(destination_no);
	clear_checked_string(g_user_no);
	if (destination_no==0)
	{
		confirm_msg="Contine to Select Position?";
		if (confirm(confirm_msg))
		{
		}else
		{
			clear_checked_red_background(g_user_no,3);
			document.getElementById("user_cut_field").value="  Cut  ";
			document.getElementById("user_cut_field").onclick= function(){javscript: callezserver_cut_selected_user();};

		}
	}else
	{
		g_token=find_cookie_value("token");
		if (g_copy_paste==1)
		{
			cgi_url = "/server/copy_paste_multiple_users?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_user_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		}else if (g_copy_paste==2)
		{
			cgi_url = "/server/cut_paste_multiple_users?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_user_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		}else
		{
			return;
		}
		//alert(cgi_url);	
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Paseting Selected Users...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = paste_selected_user;
		xmlHttp.send(null);
	}

}
function callezserver_move_selected_user()
{
	var confirm_msg;
	var cgi_url;
	var content = parent.document.getElementById("content");
	var destination_no;
	
	//alert("callezserver_paste_selected_user");
	g_checkedstring=get_checked_string(g_user_no,3);
	destination_no=prompt("Move position after","1");
	
	//alert(destination_no);
	clear_checked_string(g_user_no);
	if (destination_no<=0)
	{
		confirm_msg="Position needs > 0";
		alert(confirm_msg)
		
	}else
	{
		g_token=find_cookie_value("token");
		cgi_url = "/server/cut_paste_multiple_users?token="+encodeURI(g_token)+"&destination_no="+destination_no+"&position="+g_user_selected_position+"&bitstring="+g_checkedstring+ "&flag="+Math.random();
		
		//alert(cgi_url);	
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Paseting Selected Users...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = paste_selected_user;
		xmlHttp.send(null);
	}

}
function delete_selected_user() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response>0)
	{
		//alert(response);
		g_user_no=response;
		//alert(g_user_no);
		if (g_user_no<=0) g_user_no=1;
		if ((g_user_position+g_constant_limit)<=g_user_no)
		{
			g_user_limit=g_constant_limit;
		}else
		{
			g_user_limit=g_user_no%g_constant_limit;
			if (g_user_limit==0) 
			{
				if (g_user_no>0)
				{
					if (g_user_no<g_user_position)
					{
						g_user_position=g_user_no-g_constant_limit+1;
					}
					g_user_limit=g_constant_limit;
				}else
				{
					g_user_limit==0;
				}
			}
		}

	}else
	{
		alert("Failed to Delete Users");
	}
	
	call_get_users_detail();
    }
}

function callezserver_delete_selected_user()
{
	var confirm_msg;
	var cgi_url;
	var cookieStr;
	var checkedstring;
	var content = parent.document.getElementById("content");
	
   	g_token=find_cookie_value("token");
checkedstring=get_checked_string(g_user_no,0);
//alert(g_user_position);
//alert(checkedstring);
 if (checkedstring=='0')
 {
 }else
{
	 confirm_msg="Delete Selected Users?";
	 cgi_url = "/server/del_multiple_users?token="+encodeURI(g_token)+"&position="+g_user_position+"&bitstring="+checkedstring+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	
 	 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Deleting Selected Users...<p>';
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = delete_selected_user;
		 xmlHttp.send(null);
	 }
 }


}
function refresh_selected_user() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText;
	if (response==1)
	{
		clear_checked_string(g_user_no);
	 	alert("Sucessfully refresh users");
	} else
	{
		alert("Failed to Delete Channel");
	}
	call_get_all_user_detail();
    }
}

function callezserver_refresh_selected_user()
{
	var confirm_msg;
	var cgi_url;
	var cookieStr;
	var checkedstring;


   	g_token=find_cookie_value("token");
checkedstring=get_checked_string(g_user_no,0);
//alert(checkedstring);
 if (checkedstring=='0')
 {
 }else
{		
	 confirm_msg="Refresh Selected Movies?";
	 cgi_url = "/server/refresh_multiple_users?token="+encodeURI(g_token)+"&bitstring="+checkedstring+ "&flag="+Math.random();
	 if (confirm(confirm_msg))
	 {
	 	
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = refresh_selected_user;
		 xmlHttp.send(null);
	 }
 }


}


function callServer_Save_Channel_More()
{

  
  var sr2_id="more_sr2";
   var sr3_id="more_sr3";
  var sid_id="more_sid";
  var tolerance_id="more_tolerance";
 var buffersize_id="more_buffersize";
  var forwardflag_id="more_forwardflag";
  var bitratetypeflag_id="more_hlstype";
  var aes_id="more_aestype";
    var cacheondemandflag_id="more_cacheondemandflag";
      var netip_id="input_adapter";
	var catch_up_days_id="more_catch_up_days";
   var epg_channel_id_id="more_epg_channel_id";
   var http_user_agent_id="more_http_user_agent";

   var mobilebitrate_id="more_mobilebitrate";
   var sdbitrate_id="more_sdbitrate";
   var hdbitrate_id="more_hdbitrate";
   
   var sr2url;
   var sr3url;
  var sid;
  var tolerance;
  var buffersize;
  var forwardflag;
    var netip;
var cacheondemandflag;
  var catch_up_days;
  var epg_channel_id;
  var http_user_agent;
  var bitratetypeflagarray;
  var bitratetypeflag;
  var aes;
   var mobilebitrate;
   var sdbitrate;
   var hdbitrate;
   var nbitratetypeflag=0;

   var i=0;
 
 

var confirm_msg;
 	var cgi_url;



	ch_no=g_ch_no;
	g_item=document.getElementById(sr2_id);
	//alert(g_item.value);
	sr2url=g_item.value;
	g_item=document.getElementById(sr3_id);
	//alert(g_item.value);
	sr3url=g_item.value;
	
	g_item=document.getElementById(sid_id);
	//alert(g_item.value);
	sid=g_item.value;
	g_item=document.getElementById(tolerance_id);
	//alert(g_item.value);
	tolerance=g_item.value;
	g_item=document.getElementById(forwardflag_id);
	// alert(g_item.value);
	forwardflag=g_item.value;

	g_item=document.getElementById(buffersize_id);
 	buffersize=g_item.value;
	if (buffersize == 0)
	{
		alert("Buffer size must be > 0.");
		return;
	}
	g_item=document.getElementById(cacheondemandflag_id);
	//alert(g_item.value);
	if (g_item.checked)
	{
		cacheondemandflag=1;
	}else
	{
		cacheondemandflag=0;
	}
	//alert(bitratetypeflag_id);
	g_item=document.getElementById(netip_id);
  	netip=g_item.value;;

	g_item=document.getElementById(catch_up_days_id);
	//alert(g_item.value);
	catch_up_days=g_item.value;

	g_item=document.getElementById(epg_channel_id_id);
	//alert(g_item.value);
	epg_channel_id=g_item.value;

	g_item=document.getElementById(http_user_agent_id);
	//alert(g_item.value);
	http_user_agent=g_item.value;
	g_item=document.getElementById(bitratetypeflag_id);
	aes=document.getElementById(aes_id);
	if (g_item.checked)
	{
		bitratetypeflagarray=1;
	}else
	{
		bitratetypeflagarray==0;
	}
	if (aes.checked)
	{
		bitratetypeflagarray=4;
	}
	//alert(bitratetypeflagarray);
	/* bitratetypeflagarray=document.getElementById(bitratetypeflag_id);

	if (bitratetypeflag)
	{
		nbitratetypeflag=2;
		g_item=document.getElementById(mobilebitrate_id);
		//alert(g_item.value);
		mobilebitrate=g_item.value;
		
		g_item=document.getElementById(sdbitrate_id);
		//alert(g_item.value);
		sdbitrate=g_item.value;
		
		g_item=document.getElementById(hdbitrate_id);
		//alert(g_item.value);
		hdbitrate=g_item.value;
	}
	*/
   	g_token=find_cookie_value("token");

 confirm_msg="Save Channel: "+ch_no+" Information?";
 cgi_url = "/server/save_channel_more?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+
  "&sr2="+sr2url+
  "&sr3="+sr3url+
  "&netip="+netip+
  "&sid="+sid+
  "&tolerance="+tolerance+
  "&genre="+genre_items+
  "&forward="+forwardflag+
  "&bitratetype="+bitratetypeflagarray;
  
/*  if (bitratetypeflag)
  {
  	
	  cgi_url +="&mobilebitrate="+mobilebitrate+
	  "&sdbitrate="+sdbitrate+
	  "&hdbitrate="+hdbitrate;
  }
  */
  cgi_url +="&buffersize="+buffersize;
  cgi_url +="&cacheondemand="+cacheondemandflag;
  cgi_url +="&catch_up_days="+catch_up_days;
  cgi_url +="&http_user_agent="+http_user_agent;
  cgi_url +="&epg_channel_id="+encodeURI(epg_channel_id);
  cgi_url +="&flag="+Math.random();
  //alert(cgi_url);

	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
		 if (xmlHttp.readyState == 4) {
		 	call_get_channels(g_channel_position,g_channel_limit);
		   /* var response = xmlHttp.responseText;
		    if (response==1)
		    {
		    	var updated_date=new Date();
			var save_channel_dialog_message=document.getElementById("save_channel_dialog_message");
			save_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial"><b>'+String(updated_date.getHours()).padStart(2, "0")+":"+String(updated_date.getMinutes()).padStart(2, "0")+":"+String(updated_date.getSeconds()).padStart(2, "0")+' Updated</b></font>';

		    } else if (response==2)
		    {
		    	alert("Standard version does not support External transcoder");
		    }  else if (response==3)
		    {
		    	alert("Wrong DASH Transcoder path");
		    } else if (response==0)
		    {
		   	alert("Failed to Save Channel More");
		    }
		    */
		    
		  }	 	
	 };
	 xmlHttp.send(null);




}
function hide_cache_on_deamnd_enabled(ch_no)
{
  var bitratetypeflag_id="HLSType"+ch_no;
    var cacheondemandflag_id="cacheondemandflag"+ch_no;
var bitratetypeflagarray;
  var cacheondemandflag;

//alert(ch_no);
	/*
	g_item=document.getElementById(cacheondemandflag_id);
	//alert(g_item.value);
	cacheondemandflag=g_item.value;
	
	if (cacheondemandflag==1)
	{
		bitratetypeflagarray=document.getElementById(bitratetypeflag_id);
		bitratetypeflagarray[0].checked=true;
		hide_adaptive_option(ch_no)
	}
	*/
	/* 
	else
	{
		bitratetypeflagarray=document.getElementById(bitratetypeflag_id);
		bitratetypeflagarray[0].checked=true;
		show_adaptive_option(ch_no)
	}
	*/
}

function show_adaptive_option(ch_no)
{
    var cacheondemandflag_id="cacheondemandflag"+ch_no;
  var cacheondemandflag;
	var item_id;
	//alert(document.getElementById(cacheondemandflag_id));
	cacheondemandflag=document.getElementById(cacheondemandflag_id);
	//alert(cacheondemandflag);
	cacheondemandflag.value=0;
	item_id="mobilebitrate"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="sdbitrate"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="hdbitrate"+ch_no;
	document.getElementById(item_id).disabled=false;

	item_id="mobilewidth"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="sdwidth"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="hdwidth"+ch_no;
	document.getElementById(item_id).disabled=false;

	item_id="mobileheight"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="sdheight"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="hdheight"+ch_no;
	document.getElementById(item_id).disabled=false;

	item_id="videoformat"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="videoaspect"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="audioformat"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="preset"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	item_id="transcoder_extension"+ch_no;
	document.getElementById(item_id).disabled=false;
	
	
}
function hide_adaptive_option(ch_no)
{
	
	var item_id;
	var bitratetypeflag_id="HLSType"+ch_no;
	  var bitratetypeflagarray;
    var cacheondemandflag_id="cacheondemandflag"+ch_no;
  var cacheondemandflag;

	
	bitratetypeflagarray=document.getElementById(bitratetypeflag_id);
	if (bitratetypeflagarray[1].checked==true)
	{
		cacheondemandflag=document.getElementById(cacheondemandflag_id);
		cacheondemandflag.value=0;
	}
	
		
	item_id="mobilebitrate"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="sdbitrate"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="hdbitrate"+ch_no;
	document.getElementById(item_id).disabled=true;

	item_id="mobilewidth"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="sdwidth"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="hdwidth"+ch_no;
	document.getElementById(item_id).disabled=true;

	item_id="mobileheight"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="sdheight"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="hdheight"+ch_no;
	document.getElementById(item_id).disabled=true;

	item_id="videoformat"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="videoaspect"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="audioformat"+ch_no;
	document.getElementById(item_id).disabled=true;
	
	item_id="preset"+ch_no;
	document.getElementById(item_id).disabled=true;

	item_id="transcoder_extension"+ch_no;
	document.getElementById(item_id).disabled=true;

}
function mass_edit_show_adaptive_option()
{
    var cacheondemandflag_id="mass_edit_cacheondemandflag";
  var cacheondemandflag;
	var item_id;
	//alert(document.getElementById(cacheondemandflag_id));
	cacheondemandflag=document.getElementById(cacheondemandflag_id);
	//alert(cacheondemandflag);
	cacheondemandflag.value=0;
	for (j=0;j<5;j++)
	{
		if (j!=2)
		{
			bitratetypeflag_id="mass_edit_HLSType"+j;
			document.getElementById(bitratetypeflag_id).checked=false;
		}else
		{
			bitratetypeflag_id="mass_edit_HLSType"+2;
			document.getElementById(bitratetypeflag_id).checked=true;
		}
	
	}
	item_id="mass_edit_mobilebitrate";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_sdbitrate";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_hdbitrate";
	document.getElementById(item_id).disabled=false;

	item_id="mass_edit_mobilewidth";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_sdwidth";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_hdwidth";
	document.getElementById(item_id).disabled=false;

	item_id="mass_edit_mobileheight";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_sdheight";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_hdheight";
	document.getElementById(item_id).disabled=false;

	item_id="mass_edit_videoformat";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_videoaspect";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_audioformat";
	document.getElementById(item_id).disabled=false;
	
	item_id="mass_edit_preset";
	document.getElementById(item_id).disabled=false;
}
function mass_edit_hide_adaptive_option(bitratetypeflag)
{
	
	var item_id;
	var bitratetypeflag_id="HLSType";
	  var bitratetypeflagarray;
    var cacheondemandflag_id="mass_edit_cacheondemandflag";
  var cacheondemandflag;

	for (j=0;j<5;j++)
	{
		if (j!=bitratetypeflag)
		{
			bitratetypeflag_id="mass_edit_HLSType"+j;
			document.getElementById(bitratetypeflag_id).checked=false;
		}else
		{
			bitratetypeflag_id="mass_edit_HLSType"+bitratetypeflag;
			document.getElementById(bitratetypeflag_id).checked=true;
		}
	
	}
	
	cacheondemandflag=document.getElementById(cacheondemandflag_id);
	cacheondemandflag.value=0;
	
		
	item_id="mass_edit_mobilebitrate";
	//alert(document.getElementById(item_id));
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_sdbitrate";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_hdbitrate";
	document.getElementById(item_id).disabled=true;

	item_id="mass_edit_mobilewidth";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_sdwidth";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_hdwidth";
	document.getElementById(item_id).disabled=true;

	item_id="mass_edit_mobileheight";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_sdheight";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_hdheight";
	document.getElementById(item_id).disabled=true;

	item_id="mass_edit_videoformat";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_videoaspect";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_audioformat";
	document.getElementById(item_id).disabled=true;
	
	item_id="mass_edit_preset";
	document.getElementById(item_id).disabled=true;
	

}
function Query_A_Channel_More()
{
  var str;
 
 var ch_no;
 var ch_name;
   var ChannelDetailWindow;
   var srcurl;
   var sr2url;
   var sr3url;
   var sid;
   var tolerance;
   var forwardflag;
   var bitratetypeflag;
   var videoformat;
   var audioformat;
   var mobilebitrate;
   var sdbitrate;
   var hdbitrate;
   var mobilewidth;
   var sdwidth;
   var hdwidth;
   var mobileheight;
   var sdheight;
   var hdheight;
   var videoaspect;
   var preset;  
   var cacheondemandflag;
   var indicator_url;
   var netip;
   var catch_up_days;
   var epg_channel_id;
   var http_user_agent;
   var i;
   var j;
   var udpstr;
   var netipfound;
	var prev_ch_no;
	var next_ch_no;
	var total_ch_no;
	var nObj;
	var transcoder_extension;
	var transcoder_extension_option="";
	


  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText.split("\r\n");
  //		alert(response[0]);
 		i=0;

	 	strlength=response[i].length;
   	    	ch_no=response[i].slice(3,strlength);
   	    	

		i++;
	 	strlength=response[i].length;
   	    	ch_name=response[i].slice(5,strlength);
   	    	
    str="<head><title>"+decodeURI(ch_name)+" [CH "+ch_no+"]"+"</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body><table align="center">';
		
		i++;
	 	strlength=response[i].length;
   	    	srcurl=response[i].slice(4,strlength);
   	    	
  	    	i++;
    	 	strlength=response[i].length;
   	    	sr2url=response[i].slice(4,strlength);

   	    	i++;
    	 	strlength=response[i].length;
   	    	sr3url=response[i].slice(4,strlength);
   	    	
   	    	i++;
	 	strlength=response[i].length;
   	    	sid=response[i].slice(4,strlength);
 	    	
   	    	i++;
	 	strlength=response[i].length;
   	    	tolerance=response[i].slice(10,strlength);

  	    	i++;
	 	strlength=response[i].length;
   	    	forwardflag=response[i].slice(8,strlength);
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	bitratetypeflag=response[i].slice(12,strlength);
   	    	// alert(bitratetypeflag);
   	    	i++;
     	 	strlength=response[i].length;
   	    	videoformat=response[i].slice(13,strlength);

   	    	i++;
     	 	strlength=response[i].length;
   	    	audioformat=response[i].slice(13,strlength);
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	mobilebitrate=response[i].slice(14,strlength);
		// alert(mobilebitrate);
		
   	    	i++;
     	 	strlength=response[i].length;
   	    	sdbitrate=response[i].slice(10,strlength);
		// alert(sdbitrate);
		
   	    	i++;
     	 	strlength=response[i].length;
   	    	hdbitrate=response[i].slice(10,strlength);
		// alert(hdbitrate);
		// Mobile Width
     	    	i++;
     	 	strlength=response[i].length;
   	    	mobilewidth=response[i].slice(12,strlength);
		//alert(mobilewidth);
		
   	    	i++;
     	 	strlength=response[i].length;
   	    	sdwidth=response[i].slice(8,strlength);
		//alert(sdwidth);
		
   	    	i++;
     	 	strlength=response[i].length;
   	    	hdwidth=response[i].slice(8,strlength);
		//alert(hdwidth);
		// Mobile Height
     	    	i++;
     	 	strlength=response[i].length;
   	    	mobileheight=response[i].slice(13,strlength);
		//alert(mobileheight);
		
   	    	i++;
     	 	strlength=response[i].length;
   	    	sdheight=response[i].slice(9,strlength);
		//alert(sdheight);
		
   	    	i++;
     	 	strlength=response[i].length;
   	    	hdheight=response[i].slice(9,strlength);
		//alert(hdheight);

	    	i++;
	    	//alert(response[i]);
     	 	strlength=response[i].length;
   	    	videoaspect=response[i].slice(12,strlength);
   	    	//alert(videoaspect);

	    	i++;
     	 	strlength=response[i].length;
   	    	preset=response[i].slice(7,strlength);

  	    	i++;
     	 	strlength=response[i].length;
   	    	cacheondemandflag=response[i].slice(14,strlength);
 
  	    	i++;
     	 	strlength=response[i].length;
   	    	netip=response[i].slice(6,strlength);
   	    	//alert(netip);
   	    	
 	    	i++;
     	 	strlength=response[i].length;
   	    	catch_up_days=response[i].slice(14,strlength);

 	    	i++;
     	 	strlength=response[i].length;
   	    	epg_channel_id=decodeURI(response[i].slice(15,strlength));
   	    	
	    	i++;
     	 	strlength=response[i].length;
   	    	http_user_agent=response[i].slice(16,strlength);
   	    	
	    	i++;
     	 	strlength=response[i].length;
   	    	transcoder_extension_option=response[i].slice(21,strlength);
   	    	

 	    	i++;
     	 	strlength=response[i].length;
   	    	indicator_url=response[i].slice(13,strlength);
    	    	
    	    	

				
  		if (window.self.name=="ChannelDetailWindow")
   		{
   			nObj=window.self.document.getElementById("total_ch_no");
   			//alert(nObj);
   			//alert(nObj.innerText);
   			
   			total_ch_no=parseInt(nObj.innerText);
   			//alert(total_ch_no);
   		}else
   		{
   			total_ch_no=g_total_ch_no;
   		}
 		str+='<tr><td><font face="Arial"> <font size="2">Channel No. : </font></td><td width="450" height="23"><table><tr><td><font face="Arial"> <font size="2"><b>'+ch_no+'</b> / </font></td><td id=total_ch_no> <font size="2">'+total_ch_no+'</font></td></tr></table></td></tr>';
 		str+='<tr><td><font face="Arial"> <font size="2">Channel Name: </font></td><td width="450" height="23"><font face="Arial"> <font size="2"><b>'+decodeURI(ch_name)+'</b></font></td></tr>';
 		if (indicator_url==0)
 		{
 			str+='<tr><td><font face="Arial"> <font size="2" color="#FF0000"><b>Main URL: (Running)</b></font></td><td width="450" height="23"><font face="Arial"> <font size="2"><b>'+srcurl+'</b></font></td></tr>';
 		}else
 		{
 			str+='<tr><td><font face="Arial"> <font size="2">Main URL: </font></td><td width="450" height="23"><font face="Arial"> <font size="2"><b>'+srcurl+'</b></font></td></tr>';
 		}
 
 		if (indicator_url==1)
 		{
			str+='<tr><td><font face="Arial"> <font size="2" color="#FF0000"><b>2nd URL: (Running)</b></font></td><td width="450" height="23">';
 		}else
 		{
 			str+='<tr><td><font face="Arial"> <font size="2">2nd URL: </font></td><td width="450" height="23">';
 		}
 		str+=' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="sr2"'+
 		' id="sr2'+ch_no+'"'+
 		' size="80" value="'+
 		sr2url+
 		'"/></font></td></tr>';

		if (indicator_url==2)
		{
			str+='<tr><td><font face="Arial"> <font size="2" color="#FF0000"><b>3rd URL: (Running)</b></font></td><td width="450" height="23">';
 		}else
		{
 			str+='<tr><td><font face="Arial"> <font size="2">3rd URL: </font></td><td width="450" height="23">';
 		}
 		str+=' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="sr3"'+
 		' id="sr3'+ch_no+'"'+
 		' size="80" value="'+
 		sr3url+
 		'"/></font></td></tr>';
 		
 		str+='<tr><td><font face="Arial"> <font size="2">Channel SID: </font></td><td width="450" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="sid"'+
 		' id="sid'+ch_no+'"'+
 		' size="50" value="'+
 		sid+
 		'"/></font></td></tr>';

		str+='<tr><td><font face="Arial"> <font size="2">EPG Channel ID: </font></td><td width="450" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="epg_channel_id"'+
 		' id="epg_channel_id'+ch_no+'"'+
 		' size="50" value="'+
 		epg_channel_id+
 		'"/></font></td></tr>';
 		
 		str+='<tr><td><font face="Arial"> <font size="2">HTTP User Agent: </font></td><td width="450" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="http_user_agent"'+
 		' id="http_user_agent'+ch_no+'"'+
 		' size="50" value="'+
 		http_user_agent+
 		'"/></font></td></tr>';	
 			
 		str+='<tr><td><font face="Arial"> <font size="2">Multicast Adapter IP : </font></td><td width="450" height="23">'+
	 		' <font face="Arial"> <font size="2">';
		if (srcurl.search("udp://")==0)
 		{
 			udpstr=srcurl.slice(6);
 			if (udpstr.search(":")>0)
 			{
 				str+=' <select size="1" name="netip" id="netip'+ch_no+'">';
 			}else
 			{
				str+=' <select size="1" disabled name="netip" id="netip'+ch_no+'">';
 			}
		}else
		{
			str+=' <select size="1" disabled name="netip" id="netip'+ch_no+'">';
		}
			
		netipfound=0;
		if (window.self.name=="ChannelDetailWindow")
   		{
			for (j=0;j<window.opener.g_totoal_server_ip_no;j++)
			{
				//alert(g_server_ip_array[j]);
				//alert(netip);
				if (window.opener.g_server_ip_array[j]==netip)
				{
					str+='<option selected="selected" value="'+window.opener.g_server_ip_array[j]+'">'+window.opener.g_server_ip_array[j]+'</option>';
					netipfound=1;
				}else
				{
					str+='<option value="'+window.opener.g_server_ip_array[j]+'">'+window.opener.g_server_ip_array[j]+'</option>';
				}
				
			}
		}else
		{
			for (j=0;j<g_totoal_server_ip_no;j++)
			{
				//alert(g_server_ip_array[j]);
				//alert(netip);
				if (g_server_ip_array[j]==netip)
				{
					str+='<option selected="selected" value="'+g_server_ip_array[j]+'">'+g_server_ip_array[j]+'</option>';
					netipfound=1;
				}else
				{
					str+='<option value="'+g_server_ip_array[j]+'">'+g_server_ip_array[j]+'</option>';
				}
				
			}
		}
		if (netipfound==0)
		{
			str+='<option selected="selected" value="'+netip+'">'+netip+'</option>';
		}
		
 			
 		str+='</select></font></td></tr>';
 		


		str+='<tr><td><font face="Arial"> <font size="2">Bitrate Tolerance: </font></td><td width="450" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="tolerance"'+
 		' id="tolerance'+ch_no+'"'+
 		' size="5" value="'+
 		tolerance+
 		'"/></font></td></tr>';

  		str+='<tr><td><font face="Arial"> <font size="2">Catch Up Days: </font></td><td width="450" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="catch_up_days"'+
 		' id="catch_up_days'+ch_no+'"'+
 		' size="5" value="'+
 		catch_up_days+
 		'"/></font></td></tr>';
 		
 		 str+='<tr><td><font face="Arial"> <font size="2">Proxy Mode : </font></td><td width="450" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1" name="forwardflag" id="forwardflag'+ch_no+'">';
		if (forwardflag==0)
		{
			str+='<option selected="selected" value="0">0</option>';
			str+='<option value="1">1</option>';
			str+='<option value="2">2</option>';
			str+='<option value="3">3</option>';
		}else if (forwardflag==1)
		{
			str+='<option selected="selected" value="1">1</option>';
			str+='<option value="0">0</option>';
			str+='<option value="2">2</option>';
			str+='<option value="3">3</option>';

		}else if (forwardflag==2)
		{
			str+='<option selected="selected" value="2">2</option>';
			str+='<option value="0">0</option>';
			str+='<option value="1">1</option>';
			str+='<option value="3">3</option>';

		}else if (forwardflag==3)
		{
			str+='<option selected="selected" value="3">3</option>';
			str+='<option value="0">0</option>';
			str+='<option value="1">1</option>';
			str+='<option value="2">2</option>';

		}	 			
 		str+='</select></font></td></tr>';

		 str+='<tr><td><font face="Arial"> <font size="2">Cache On Demand : </font></td><td width="450" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1" onchange=hide_cache_on_deamnd_enabled('+ch_no+') name="cacheondemandflag" id="cacheondemandflag'+ch_no+'">';
		if (cacheondemandflag==0)
		{
			str+='<option selected="selected" value="0">0</option>';
			str+='<option value="1">1</option>';
		}
		else
		{
			str+='<option selected="selected" value="1">1</option>';
			str+='<option value="0">0</option>';
		}	 			
 		str+='</select></font></td></tr>';

		

 		 str+='<tr><td><font face="Arial"> <font size="2">HTTP Live Streaming : </font></td><td width="450" height="23">'+
	 		' <font face="Arial"> <font size="2">';
	 	if ((bitratetypeflag==0) || (bitratetypeflag==1)|| (bitratetypeflag==3)|| (bitratetypeflag==4))
	 	{
	 		if (bitratetypeflag==0)
	 		{
				 str+='<form id="HLSType'+ch_no+'"><p style="margin-top: 0; margin-bottom: 0"><input type="radio" value="0" onclick="javascript:hide_adaptive_option('+ch_no+')" checked name="HLSType">Disabled</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="4" onclick="javascript:hide_adaptive_option('+ch_no+')">AES-128 Encryption (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="1" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="3" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (External transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="2" onclick="javascript:show_adaptive_option('+ch_no+')">Adaptive Bitrate (External transcoder)</p></td></tr>';
		  	}else if (bitratetypeflag==1)
		  	{
				 str+='<form id="HLSType'+ch_no+'"><p style="margin-top: 0; margin-bottom: 0"><input type="radio" value="0"  name="HLSType" onclick="javascript:hide_adaptive_option('+ch_no+')">Disabled</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="4" onclick="javascript:hide_adaptive_option('+ch_no+')">AES-128 Encryption (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" checked value="1" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="3" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (External transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="2" onclick="javascript:show_adaptive_option('+ch_no+')">Adaptive Bitrate (External transcoder)</p></td></tr>';
		  	}else if (bitratetypeflag==3)
		  	{
				 str+='<form id="HLSType'+ch_no+'"><p style="margin-top: 0; margin-bottom: 0"><input type="radio" value="0"  name="HLSType" onclick="javascript:hide_adaptive_option('+ch_no+')">Disabled</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="4" onclick="javascript:hide_adaptive_option('+ch_no+')">AES-128 Encryption (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="1" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" checked value="3" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (External transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="2" onclick="javascript:show_adaptive_option('+ch_no+')">Adaptive Bitrate (External transcoder)</p></td></tr>';
		  	}else if (bitratetypeflag==4)
		  	{
				 str+='<form id="HLSType'+ch_no+'"><p style="margin-top: 0; margin-bottom: 0"><input type="radio" value="0"  name="HLSType" onclick="javascript:hide_adaptive_option('+ch_no+')">Disabled</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" checked value="4" onclick="javascript:hide_adaptive_option('+ch_no+')">AES-128 Encryption (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="1" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (Internal transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="3" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (External transcoder)</p>'+
				  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType"  value="2" onclick="javascript:show_adaptive_option('+ch_no+')">Adaptive Bitrate (External transcoder)</p></td></tr>';
		  	}
		  	
		  	
			str+='<tr><td><font face="Arial"> <font size="2">1st Bitrate (kbps): </font></td><td width="450" height="23"><table><tr><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="mobilebitrate"'+
	 		' id="mobilebitrate'+ch_no+'"'+
	 		' size="5" value="'+
	 		"0"+
	 		'"/></font></td>';
	 		
			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Resolution (px): </font></td><td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="mobilewidth"'+
	 		' id="mobilewidth'+ch_no+'"'+
	 		' size="5" value="Auto"/></font><font face="Arial"> <font size="2">x</font></td>';
	 		str+='<td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="mobileheight"'+
	 		' id="mobileheight'+ch_no+'"'+
	 		' size="5" value="Auto"/></font></td>';
	 		str+='</tr></table></td></tr>';
	 		
			str+='<tr><td><font face="Arial"> <font size="2">2nd Bitrate (kbps): </font></td><td width="450" height="23"><table><tr><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="sdbitrate"'+
	 		' id="sdbitrate'+ch_no+'"'+
	 		' size="5" value="'+
	 		"0"+
	 		'"/></font></td>';

			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Resolution (px): </font></td><td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="sdwidth"'+
	 		' id="sdwidth'+ch_no+'"'+
	 		' size="5" value="Auto"/></font><font face="Arial"> <font size="2">x</font></td>';
			str+='<td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="sdheight"'+
	 		' id="sdheight'+ch_no+'"'+
	 		' size="5" value="Auto"/></font></td>';
	 		str+='</tr></table></td></tr>';
	 		
			str+='<tr><td><font face="Arial"> <font size="2">3rd Bitrate (kbps): </font></td><td width="450" height="23"><table><tr><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="hdbitrate"'+
	 		' id="hdbitrate'+ch_no+'"'+
	 		' size="5" value="'+
	 		"0"+
	 		'"/></font></td>';

			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Resolution (px): </font></td><td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="hdwidth"'+
	 		' id="hdwidth'+ch_no+'"'+
	 		' size="5" value="Auto"/></font><font face="Arial"> <font size="2">x</font></td>';
			str+='<td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" disabled name="hdheight"'+
	 		' id="hdheight'+ch_no+'"'+
	 		' size="5" value="Auto"/></font></td>';
	 		str+='</tr></table></td></tr>';
	 		
			str+='<tr><td><font face="Arial"> <font size="2">Video Format : </font></td><td width="450" height="23"><table><tr><td>'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" disabled name="videoformat" id="videoformat'+ch_no+'">';
			
			str+='<option selected="selected" value="h264">h264</option>';
			str+='<option value="h264_qsv">h264_qsv</option>';
			str+='<option value="h264_nvenc">h264_nvenc</option>';
			str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
			str+='<option value="h265">h265</option>';
			str+='<option value="hevc_nvenc">h265_nvenc</option>';
			str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			str+='</select></font></td>';
			
			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Aspect Ratio : </font></td><td height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" disabled name="videoaspect" id="videoaspect'+ch_no+'">';
			
			str+='<option selected="selected" value="Auto">Auto</option>';
			str+='<option value="16:9">16:9</option>';
			str+='<option value="4:3">4:3</option>';
			str+='<option value="18:9">18:9</option>';
			str+='<option value="21:9">21:9</option>';
			str+='</select></font></td>';
			
			str+='</tr></table></td></tr>';
						
			 str+='<tr><td><font face="Arial"> <font size="2">Audio Format : </font></td><td width="450" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" disabled name="audioformat" id="audioformat'+ch_no+'">';
			
			str+='<option selected="selected" value="aac">aac</option>';
			str+='<option value="mp3">mp3</option>';
			str+='<option value="copy">copy</option>';

	 		str+='</select></font></td></tr>';

			str+='<tr><td><font face="Arial"> <font size="2">Encoding Speed : </font></td><td width="450" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" disabled name="preset" id="preset'+ch_no+'">';
			
			str+='<option selected="selected" value="ultrafast">ultrafast</option>';
			str+='<option value="superfast">superfast</option>';
			str+='<option value="fast">fast</option>';
			str+='<option value="medium">medium</option>';
			str+='<option value="slow">slow</option>';
						
	 		str+='</select></font></td></tr>';
	 		str+='<tr><td><font face="Arial"> <font size="2">Extension option: </font></td><td width="450" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input disabled type="text" name="transcoder_extension"'+
	 		' id="transcoder_extension'+ch_no+'"'+
	 		' size="50" value="'+
	 		transcoder_extension_option+
	 		'"/></font></td></tr>';

		}else if (bitratetypeflag==2)
		{
			
			str+='<form id="HLSType'+ch_no+'"><p style="margin-top: 0; margin-bottom: 0"><input type="radio" value="0"  name="HLSType" onclick="javascript:hide_adaptive_option('+ch_no+')">Disabled</p>'+
			  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="4" onclick="javascript:hide_adaptive_option('+ch_no+')">AES-128 Encryption (Internal transcoder)</p>'+
			  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="1" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (Internal transcoder)</p>'+
			  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" value="3" onclick="javascript:hide_adaptive_option('+ch_no+')">Constant Bitrate (External transcoder)</p>'+
			  '<p style="margin-top: 0; margin-bottom: 0"><input type="radio" name="HLSType" checked value="2" onclick="javascript:show_adaptive_option('+ch_no+')">Adaptive Bitrate (External transcoder)</p></td></tr>';
		
			if (mobilebitrate.length==0)
			{
				mobilebitrate="0";
			}
			if (sdbitrate.length==0)
			{
				sdbitrate="0";
			}
			if (hdbitrate.length==0)
			{
				hdbitrate="0";
			}
			str+='<tr><td><font face="Arial"> <font size="2">1st Bitrate (kbps): </font></td><td width="450" height="23"><table><tr><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="mobilebitrate"'+
	 		' id="mobilebitrate'+ch_no+'"'+
	 		' size="5" value="'+
	 		mobilebitrate+
	 		'"/></font></td>';
			if (mobilewidth==0)
			{
				mobilewidth="Auto";
			}
			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Resolution (px): </font></td><td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="mobilewidth"'+
	 		' id="mobilewidth'+ch_no+'"'+
	 		' size="5" value="'+
	 		mobilewidth+
	 		'"/></font><font face="Arial"> <font size="2">x</font></td>';

			if (mobileheight==0)
			{
				mobileheight="Auto";
			}
			str+='<td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="mobileheight"'+
	 		' id="mobileheight'+ch_no+'"'+
	 		' size="5" value="'+
	 		mobileheight+
	 		'"/></font></td>';
	 		str+='</tr></table></td></tr>';
	
			str+='<tr><td><font face="Arial"> <font size="2">2nd Bitrate (kbps): </font></td><td width="450" height="23"><table><tr><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="sdbitrate"'+
	 		' id="sdbitrate'+ch_no+'"'+
	 		' size="5" value="'+
	 		sdbitrate+
	 		'"/></font></td>';

			if (sdwidth==0)
			{
				sdwidth="Auto";
			}
			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Resolution (px): </font></td><td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="sdwidth"'+
	 		' id="sdwidth'+ch_no+'"'+
	 		' size="5" value="'+
	 		sdwidth+
	 		'"/></font><font face="Arial"> <font size="2">x</font></td>';

			if (sdheight==0)
			{
				sdheight="Auto";
			}
			str+='<td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="sdheight"'+
	 		' id="sdheight'+ch_no+'"'+
	 		' size="5" value="'+
	 		sdheight+
	 		'"/></font></td>';
	 		str+='</tr></table></td></tr>';
	
			str+='<tr><td><font face="Arial"> <font size="2">3rd Bitrate (kbps): </font></td><td width="450" height="23"><table><tr><td>'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="hdbitrate"'+
	 		' id="hdbitrate'+ch_no+'"'+
	 		' size="5" value="'+
	 		hdbitrate+
	 		'"/></font></td>';

			if (hdwidth==0)
			{
				hdwidth="Auto";
			}
			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Resolution (px): </font></td><td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="hdwidth"'+
	 		' id="hdwidth'+ch_no+'"'+
	 		' size="5" value="'+
	 		hdwidth+
	 		'"/></font><font face="Arial"> <font size="2">x</font></td>';

			if (hdheight==0)
			{
				hdheight="Auto";
			}
			str+='<td height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="hdheight"'+
	 		' id="hdheight'+ch_no+'"'+
	 		' size="5" value="'+
	 		hdheight+
	 		'"/></font></td>';
	 		str+='</tr></table></td></tr>';

			
			str+='<tr><td><font face="Arial"> <font size="2">Video Format : </font></td><td width="450" height="23"><table><tr><td>'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" name="videoformat" id="videoformat'+ch_no+'">';
			if (videoformat=="h264")
			{
				str+='<option selected="selected" value="h264">h264</option>';				
				str+='<option value="h264_qsv">h264_qsv</option>';
				str+='<option value="h264_nvenc">h264_nvenc</option>';
				str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
				str+='<option value="h265">h265</option>';
				str+='<option value="hevc_nvenc">h265_nvenc</option>';
				str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			}
			else if (videoformat=="h264_qsv")
			{
				str+='<option selected="selected" value="h264_qsv">h264_qsv</option>';				
				str+='<option value="h264">h264</option>';
				str+='<option value="h264_nvenc">h264_nvenc</option>';
				str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
				str+='<option value="h265">h265</option>';
				str+='<option value="hevc_nvenc">h265_nvenc</option>';
				str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			}else if (videoformat=="h264_nvenc")
			{
				
				str+='<option selected="selected" value="h264_nvenc">h264_nvenc</option>';				
				str+='<option value="h264">h264</option>';
				str+='<option value="h264_qsv">h264_qsv</option>';
				str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
				str+='<option value="h265">h265</option>';
				str+='<option value="hevc_nvenc">h265_nvenc</option>';
				str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			}else if (videoformat=="h264_cuda")
			{
				
				str+='<option selected="selected" value="h264_cuda">h264_cuda_nvenc</option>';				
				str+='<option value="h264">h264</option>';
				str+='<option value="h264_qsv">h264_qsv</option>';
				str+='<option value="h264_nvenc">h264_nvenc</option>';
				str+='<option value="h265">h265</option>';
				str+='<option value="hevc_nvenc">h265_nvenc</option>';
				str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			}
			else if (videoformat=="h265")
			{
				str+='<option selected="selected" value="h265">h265</option>';
				str+='<option value="h264">h264</option>';
				str+='<option value="h264_nvenc">h264_nvenc</option>';
				str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
				str+='<option value="h264_qsv">h264_qsv</option>';
				str+='<option value="hevc_nvenc">h265_nvenc</option>';
				str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			}
			else if (videoformat=="hevc_nvenc")
			{
				str+='<option selected="selected" value="hevc_nvenc">h265_nvenc</option>';				
				str+='<option value="h264">h264</option>';
				str+='<option value="h264_qsv">h264_qsv</option>';
				str+='<option value="h264_nvenc">h264_nvenc</option>';
				str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
				str+='<option value="h265">h265</option>';
				str+='<option value="hevc_cuda">h265_cuda_nvenc</option>';
			}else if (videoformat=="hevc_cuda")
			{
				str+='<option selected="selected" value="hevc_cuda">h265_cuda_nvenc</option>';				
				str+='<option value="h264">h264</option>';
				str+='<option value="h264_qsv">h264_qsv</option>';
				str+='<option value="h264_nvenc">h264_nvenc</option>';
				str+='<option value="h264_cuda">h264_cuda_nvenc</option>';
				str+='<option value="h265">h265</option>';
				str+='<option value="hevc_nvenc">h265_nvenc</option>';
			}
			str+='</select></font></td>';
			str+='<td><font face="Arial"> <font size="2">&nbsp;&nbsp;&nbsp;Aspect Ratio : </font></td><td height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" name="videoaspect" id="videoaspect'+ch_no+'">';
			if (videoaspect=="")
			{
				str+='<option selected="selected" value="Auto">Auto</option>';				
				str+='<option value="16:9">16:9</option>';
				str+='<option value="4:3">4:3</option>';
				str+='<option value="18:9">18:9</option>';
				str+='<option value="21:9">21:9</option>';
			}
			else if (videoaspect=="16:9")
			{
				str+='<option selected="selected" value="16:9">16:9</option>';				
				str+='<option value="Auto">Auto</option>';
				str+='<option value="4:3">4:3</option>';
				str+='<option value="18:9">18:9</option>';
				str+='<option value="21:9">21:9</option>';
			}else if (videoaspect=="4:3")
			{
				
				str+='<option selected="selected" value="4:3">4:3</option>';				
				str+='<option value="Auto">Auto</option>';
				str+='<option value="16:9">16:9</option>';
				str+='<option value="18:9">18:9</option>';
				str+='<option value="21:9">21:9</option>';
			}
			else if (videoaspect=="18:9")
			{
				str+='<option selected="selected" value="18:9">18:9</option>';
				str+='<option value="Auto">Auto</option>';
				str+='<option value="16:9">16:9</option>';
				str+='<option value="4:3">4:3</option>';
				str+='<option value="21:9">21:9</option>';
			}
			else if (videoaspect=="21:9")
			{
				str+='<option selected="selected" value="21:9">21:9</option>';	
				str+='<option value="Auto">Auto</option>';			
				str+='<option value="16:9">16:9</option>';
				str+='<option value="4:3">4:3</option>';
				str+='<option value="18:9">18:9</option>';
			}
			
			str+='</td></tr></table></td></tr>';
			
			 str+='<tr><td><font face="Arial"><font size="2">Audio Format : </font></td><td width="450" height="23">'+
		 		'<font face="Arial"><font size="2">'+
				'<select size="1" name="audioformat" id="audioformat'+ch_no+'">';
			if (audioformat=="aac")
			{
				str+='<option selected="selected" value="aac">aac</option>';
				str+='<option value="mp3">mp3</option>';
				str+='<option value="copy">copy</option>';
			}else if (audioformat=="mp3")
			{
				str+='<option selected="selected" value="mp3">mp3</option>';
				str+='<option value="aac">aac</option>';
				str+='<option value="copy">copy</option>';
			}else if (audioformat=="copy")
			{
				str+='<option selected="selected" value="copy">copy</option>';
				str+='<option value="aac">aac</option>';
				str+='<option value="mp3">mp3</option>';
			}
			str+='</select></font></td></tr>';	
			
			str+='<tr><td><font face="Arial"><font size="2">Encoding Speed : </font></td><td width="450" height="23">'+
		 		'<font face="Arial"><font size="2">'+
				'<select size="1" name="preset" id="preset'+ch_no+'">';
			if (preset=="ultrafast")
			{
				str+='<option selected="selected" value="ultrafast">ultrafast</option>';
				str+='<option value="superfast">superfast</option>';
				str+='<option value="fast">fast</option>';
				str+='<option value="medium">medium</option>';
				str+='<option value="slow">slow</option>';
			}
			else if (preset=="superfast")
			{
				str+='<option selected="selected" value="superfast">superfast</option>';
				str+='<option value="ultrafast">ultrafast</option>';
				str+='<option value="fast">fast</option>';
				str+='<option value="medium">medium</option>';
				str+='<option value="slow">slow</option>';
			}
			else if (preset=="fast")
			{
				str+='<option value="ultrafast">ultrafast</option>';
				str+='<option value="superfast">superfast</option>';
				str+='<option selected="selected" value="fast">fast</option>';
				str+='<option value="medium">medium</option>';
				str+='<option value="slow">slow</option>';
			}
			else if (preset=="medium")
			{
				str+='<option value="ultrafast">ultrafast</option>';
				str+='<option value="superfast">superfast</option>';
				str+='<option value="fast">fast</option>';
				str+='<option selected="selected" value="medium">medium</option>';
				str+='<option value="slow">slow</option>';
			}
			else if (preset=="slow")
			{
				str+='<option value="ultrafast">ultrafast</option>';
				str+='<option value="superfast">superfast</option>';
				str+='<option value="fast">fast</option>';
				str+='<option value="medium">medium</option>';
				str+='<option selected="selected" value="slow">slow</option>';
			}
						
	 		str+='</select></font></td></tr>';
	 		str+='<tr><td><font face="Arial"> <font size="2">Extension option: </font></td><td width="450" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="transcoder_extension"'+
	 		' id="transcoder_extension'+ch_no+'"'+
	 		' size="50" value="'+
	 		transcoder_extension_option+
	 		'"/></font></td></tr>';

		}  		


 		
    str+='<tr><td><input type="button" value="Save" onclick=callServer_Save_Channel_More("'+ch_no+'") id="C2" /></td>';
     if (parseInt(ch_no)>1)
    {
    	    prev_ch_no=parseInt(ch_no)-1;
	    str+='<td width="450"  height="23"><input type="button" value="Prev" onclick=call_Query_A_Channel_More("'+prev_ch_no+'") name="Prev" />';
    }else
    {
	    str+='<td width="450"  height="23"><input type="button" disabled value="Prev" onclick=call_Query_A_Channel_More("'+prev_ch_no+'") name="Prev" />';
    }
    if (parseInt(ch_no)<total_ch_no)
    {
    	    next_ch_no=parseInt(ch_no)+1;
	    str+='&nbsp&nbsp&nbsp<input type="button" value="Next" onclick=call_Query_A_Channel_More("'+next_ch_no+'") name="Next" />';
    }else
    {
    	    str+='&nbsp&nbsp&nbsp<input disabled type="button" value="Next" onclick=call_Query_A_Channel_More("'+next_ch_no+'") name="Next" />';
    }
    str+='&nbsp&nbsp&nbsp<input type="button" value="Copy" onclick=callServer_Get_Channel_Category("'+ch_no+'") name="Copy" />';
    str+='</td></tr>';
    	
    str+='</table></body>';  
    
  

  }
}

function call_Query_A_Channel_More(ch_no)
{
 var ch_src_id="chsrc"+ch_no; 
 var ch_src;
 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var m=0;
	
   	g_token=find_cookie_value("token");
	document.getElementById("save_channel_dialog_message").innerHTML='';
	

	 cgi_url = "/server/query_channel_more?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&flag="+Math.random();
	 g_ch_no=ch_no;
	
	 xmlHttp.open("GET", cgi_url, true);
	  xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText.split("\r\n");
		  		i=0;
		
			 	strlength=response[i].length;
		   	    	ch_no=response[i].slice(3,strlength);
		   	    	
		
				i++;
			 	strlength=response[i].length;
		   	    	ch_name=response[i].slice(5,strlength);
		   	    	document.getElementById("more_channel_name").innerHTML='<font face="Arial" size="5"><b>'+ch_name+'</b></font>';
		  		
				i++;
			 	strlength=response[i].length;
		   	    	srcurl=response[i].slice(4,strlength);
		   	    	
		  	    	i++;
		    	 	strlength=response[i].length;
		   	    	sr2url=response[i].slice(4,strlength);
		  	    	document.getElementById("more_sr2").value=sr2url;
		
		   	    	i++;
		    	 	strlength=response[i].length;
		   	    	sr3url=response[i].slice(4,strlength);
		     	    	document.getElementById("more_sr3").value=sr3url;
			    	
		   	    	i++;
			 	strlength=response[i].length;
		   	    	sid=response[i].slice(4,strlength);
		   	    	document.getElementById("more_sid").value=sid;
			    	
		   	    	i++;
			 	strlength=response[i].length;
		   	    	tolerance=response[i].slice(11,strlength);
		   	    	document.getElementById("more_buffersize").value=tolerance;
		 
		   	    	i++;
			 	strlength=response[i].length;
		   	    	tolerance=response[i].slice(10,strlength);
		   	    	document.getElementById("more_tolerance").value=tolerance;
		
		  	    	i++;
			 	strlength=response[i].length;
		   	    	forwardflag=response[i].slice(8,strlength);
		   	    	
		 	    	document.getElementById("more_forwardflag").value=forwardflag;
		   	    	
		   	    	i++;
		     	 	strlength=response[i].length;
		   	    	bitratetypeflag=response[i].slice(12,strlength);
		   	    	//alert(bitratetypeflag);
		   	    	if (bitratetypeflag==4)
		   	    	{
		   	    		document.getElementById("more_aestype").checked=true;
		   	    	}else
		   	    	{
		   	    		document.getElementById("more_aestype").checked=false;
			   	    	if (bitratetypeflag==1)
			   	    	{
			     	    		document.getElementById("more_hlstype").checked=true;
			 	    	}else
			 	    	{
			     	    		document.getElementById("more_hlstype").checked=false;
			 	    	}
		 	    	}
		   	    	i++;
		    
		   	    	i++;
		     	    	
		   	    	i++;
		     	 	strlength=response[i].length;
		   	    	mobilebitrate=response[i].slice(14,strlength);
				// alert(mobilebitrate);
				
		   	    	i++;
		     	 	strlength=response[i].length;
		   	    	sdbitrate=response[i].slice(10,strlength);
				// alert(sdbitrate);
				
		   	    	i++;
		     	 	strlength=response[i].length;
		   	    	hdbitrate=response[i].slice(10,strlength);
		   	    	i++;
		  		
		   	    	i++;
		    		
		   	    	i++;
		       	    	i++;
		    		
		   	    	i++;
		    		//alert(sdheight);
				
		   	    	i++;
		   
			    	i++;
		
			    	i++;
		  
		  	    	i++;
		     	 	strlength=response[i].length;
		   	    	cacheondemandflag=response[i].slice(14,strlength);
		   	    	if (cacheondemandflag==1)
		   	    	{
		   	    		document.getElementById("more_cacheondemandflag").checked=true;
		   	    	}else
		   	    	{
		   	    		document.getElementById("more_cacheondemandflag").checked=false;
		   	    	}
		 
		  	    	i++;
		     	 	strlength=response[i].length;
		   	    	netip=response[i].slice(6,strlength);
		   	    	//alert(netip);
		   	    	if (srcurl.match("udp://")==null)
		 		{
					document.getElementById("input_adapter").disabled=true;
				}else
				{
		 			document.getElementById("input_adapter").value=netip;
		 			document.getElementById("input_adapter").disabled=false;
				}
				
		   	    	
		 	    	i++;
		     	 	strlength=response[i].length;
		   	    	catch_up_days=response[i].slice(14,strlength);
		   	    	document.getElementById("more_catch_up_days").value=catch_up_days;
		
		 	    	i++;
		     	 	strlength=response[i].length;
		   	    	epg_channel_id=decodeURI(response[i].slice(15,strlength));
		     	    	document.getElementById("more_epg_channel_id").value=epg_channel_id;
			    	
			    	i++;
		     	 	strlength=response[i].length;
		   	    	http_user_agent=response[i].slice(16,strlength);
		      	    	document.getElementById("more_http_user_agent").value=http_user_agent;
		      	    	
			    	i++;
		     	 	strlength=response[i].length;
		   	    	genre=response[i].slice(6,strlength);
		   	    	if (genre.length>0)
		   	    	{
			   	    	genre_items=genre.split(",");
			   	    	for (m=0;m<genre_items.length;m++)
			   	    	{
			   	    		var listItem = createListItem(genre_items[m]);
						document.getElementById('selectedItemsList').appendChild(listItem);
					}
				}
			
		      	    	//document.getElementById("more_http_user_agent").value=http_user_agent;
		      	    	
		      	    	if ((g_Ezserver_Version==BLOCKCHAIN_PUBLIC) || g_Ezserver_Version==BLOCKCHAIN_PRIVATE)
				{
					i++;
				    	i++;
			     	 	strlength=response[i].length;
			   	    	bcregion=response[i].slice(10,strlength);
			      	    	document.getElementById("more_bcregion").value=bcregion;
			      	    	document.getElementById("more_bcregion").disabled=true;
	
				    	i++;
			     	 	strlength=response[i].length;
			   	    	bcgroup=response[i].slice(9,strlength);
			      	    	document.getElementById("more_bcgroup").value=bcgroup;
					document.getElementById("more_bcgroup").disabled=true;
				}

		 	    	
		  }	  	
	 };
	 xmlHttp.send(null);

}

function Copy_Channel_More()
{
 if (xmlHttp.readyState == 4) {

	var response = xmlHttp.responseText;
	alert("Copied sucessfully");
	window.close();

	
 }

}
function callServer_Copy_Channel_More(ch_no)
{
 	var cgi_url;
	var chcheckbox;
	var checkboj;
	var netip_checked=0;
	var tolerance_checked=0;
	var catch_up_days_checked=0;
	var forwardflag_checked=0;
	var cacheondemandflag_checkedg=0;
	var bitratetypeflag_checked=0;
	var http_user_agent_checked=0
	
	var categoryoptions=document.getElementById("channel_category");
	var iLen;
	var i;
	var bFirstItem=1;
	var selected_category='';
	
	//alert(ch_no);
	//alert(g_ch_no);
	g_ch_no=ch_no
	chcheckbox='netip_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			netip_checked=1;
		}
	}
	chcheckbox='tolerance_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			tolerance_checked=1;
		}
	}
	chcheckbox='catch_up_days_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			catch_up_days_checked=1;
		}
	}
	chcheckbox='forwardflag_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			forwardflag_checked=1;
		}
	}
	chcheckbox='cacheondemandflag_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			cacheondemandflag_checkedg=1;
		}
	}

	chcheckbox='http_user_agent_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			http_user_agent_checked=1;
		}
	}

	chcheckbox='bitratetypetext_chk'+g_ch_no;
	checkboj=document.getElementById(chcheckbox);
	if (checkboj)
	{
		if (checkboj.checked==true)
		{
			bitratetypeflag_checked=1;
		}
	}
	iLen=categoryoptions.length;
	for (i=0;i<iLen;i++)
	{
		opt=categoryoptions[i];
		//alert(opt.value);
		//alert(opt.selected);
		if (opt.selected)
		{
			//alert(opt.value);
			if (bFirstItem==0)
			{
			  selected_category+=','+opt.value;	
			}else
			{
				selected_category+=opt.value;	
				bFirstItem=0;
			}				
		}
	}
	if (selected_category.search('all')==0)
	{
		selected_category='all';
	}
	if (selected_category.length>0)
	{	
		g_token=find_cookie_value("token");
		cgi_url = "/server/copy_channel_more?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ 
		"&netip="+netip_checked+
		"&tolerance="+tolerance_checked+
		"&catch_up_days="+catch_up_days_checked+
		"&forwardflag="+forwardflag_checked+
		"&cacheondemandflag="+cacheondemandflag_checkedg+
		"&http_user_agentflag="+http_user_agent_checked+
		"&bitratetypeflag="+bitratetypeflag_checked+
		"&selected_category="+selected_category+
		"&flag="+Math.random();
		//alert(cgi_url);
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Copy_Channel_More;
		xmlHttp.send(null);
	 }else
	 {
	 	alert("Need to select at least one category.");
	 }

}

function Get_Channel_Category()
{
	 	var i;
		var total_category_no=0;
		var str;
		var UserDetailCopyWindow;
		var netip;
		var tolerance;
		var catch_up_days;
		var forwardflag;
		var cacheondemandflag;
		var bitratetypeflag;
		var bitratetypetext;
		var g_item;
		var bitratetypeflagarray;
		var http_user_agent;
		
		var tolerance_id="tolerance"+g_ch_no;
		var forwardflag_id="forwardflag"+g_ch_no;;
		var bitratetypeflag_id="HLSType"+g_ch_no;
		var cacheondemandflag_id="cacheondemandflag"+g_ch_no;
		var netip_id="netip"+g_ch_no;
		var catch_up_days_id="catch_up_days"+g_ch_no;
		var http_user_agent_id="http_user_agent"+g_ch_no;
		if (xmlHttp.readyState == 4) 
		{
			var response = xmlHttp.responseText.split("\r\n");
			if (g_token==0) return; 
			//alert(g_token);
			Channel_Categories_tems[total_category_no]="all"; 
			total_category_no++;
			for (i=0;;i++)
			{
			//  alert(response[i]);
			    if (response[i]==0)
			    {
			    	break;
			    } else
			    {
			    	strlength=response[i].length;
			  	folder_name=response[i].substring(9);
			    	Channel_Categories_tems[total_category_no]=encodeURI(folder_name); 
			    	total_category_no++;
			   } 
			}
			g_item=document.getElementById(tolerance_id);
			//alert(g_item.value);
			
			tolerance=g_item.value;
			g_item=document.getElementById(forwardflag_id);
			// alert(g_item.value);
			forwardflag=g_item.value;
			
			g_item=document.getElementById(cacheondemandflag_id);
			//alert(g_item.value);
			cacheondemandflag=g_item.value;
			//alert(bitratetypeflag_id);
			g_item=document.getElementById(netip_id);
			//alert(g_item.value);
			netip=g_item.value;
			
			g_item=document.getElementById(catch_up_days_id);
			//alert(g_item.value);
			catch_up_days=g_item.value;
			
			g_item=document.getElementById(http_user_agent_id);
			//alert(g_item.value);
			http_user_agent=g_item.value;
			
			bitratetypeflagarray=document.getElementById(bitratetypeflag_id);
			for (i=0;i<5;i++)
			{
				if (bitratetypeflagarray[i].checked)
				{
					bitratetypeflag=bitratetypeflagarray[i].value;
					//alert(bitratetypeflag);
				}
				
			}
			
			str="<head><title> CH "+g_ch_no+"</title>";
			
			str+="<link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body><table align="center">';
			str+='<tr><td><font face="Arial"><font size="2">Channel No. : </font></td><td width="200" height="23"><font face="Arial"> <font size="2"><b>'+g_ch_no+'</b></font></td></tr>';
			str+='<tr><td><table><tr><td><input type="checkbox" checked id=netip_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">Multicast Adapter IP : </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+netip+'<td></tr>';
			str+='<tr><td><table><tr><td><input type="checkbox" checked id=tolerance_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">Bitrate Tolerance: </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+tolerance+'<td></tr>';
			
			str+='<tr><td><table><tr><td><input type="checkbox" checked id=catch_up_days_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">Catch Up Days: </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+catch_up_days+'<td></tr>';
			
			
			
			 str+='<tr><td><table><tr><td><input type="checkbox" checked id=forwardflag_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">Proxy Mode : </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+forwardflag+'<td></tr>';
			
			
			 str+='<tr><td><table><tr><td><input type="checkbox" checked id=cacheondemandflag_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">Cache On Demand : </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+cacheondemandflag+'<td></tr>';
			
			 str+='<tr><td><table><tr><td><input type="checkbox" checked id=http_user_agent_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">HTTP User Agent: </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+http_user_agent+'<td></tr>';
			
			if (bitratetypeflag==0)
			{
				bitratetypetext='Disabled';
			}else if (bitratetypeflag==4)
			{
				bitratetypetext='AES-128 Encryption (Internal transcoder)';
			}else if (bitratetypeflag==1)
			{
				bitratetypetext='Constant Bitrate (Internal transcoder)';
			}else if (bitratetypeflag==3)
			{
				bitratetypetext='Constant Bitrate (External transcoder)';
			}else if (bitratetypeflag==2)
			{
				bitratetypetext='Adaptive Bitrate (External transcoder)';
			}
			
			 str+='<tr><td><table><tr><td><input type="checkbox" checked id=bitratetypetext_chk'+g_ch_no+'></td><td><font face="Arial"> <font size="2">HTTP Live Streaming : </font></td></tr></table></td><td width="200" height="23">'+
				' <font face="Arial"><font size="2">'+bitratetypetext+'<td></tr>';
			
			
			str+='<tr><td  colspan="2"><hr size="1" color="#66FFFF"></td></tr>';
			str+='<tr><td><font face="Arial"><font size="2">To Category : </font></td><td width="200" height="23">'+
			' <font face="Arial" size="2">'+' <select multiple style="width: 180;" name="channel_category" id=channel_category>';
			for (i=0;i<total_category_no;i++)
			{
				
				str+='<option value="'+Channel_Categories_tems[i]+'">'+Channel_Categories_tems[i]+'</option>';	
			}
			str+='</select></font></td></tr>';
			str+='<tr><td><input type="button" value="Copy" onclick=callServer_Copy_Channel_More("'+g_ch_no+'") name="Copy_B2" /></td><td></td></tr>';
			str+='</table>';
			UserDetailCopyWindow= window.open("", "", "top=200, left=300, width=500, height=360"); 
			UserDetailCopyWindow.document.write(str);
		}
}

function callServer_Get_Channel_Category(ch_no)
{
 	var cgi_url;
   	g_token=find_cookie_value("token");
	
	 cgi_url = "/server/get_channel_category?token="+encodeURI(g_token)+"&flag="+Math.random();
	 g_ch_no=ch_no;
	 //alert(cgi_url);
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Get_Channel_Category();
	 
	 xmlHttp.send(null);

}
function callServer_Get_Channel_Category1(ch_no)
{
 	alert("6666666666666");

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

	var response = xmlHttp.responseText.split("\r\n");
	var HTML_str='';
	var strlength=0;
	var i=0;
	var j=1;

	g_totoal_server_ip_no=0;
	g_server_ip_array[0]="127.0.0.1";
	//alert(g_server_ip_array[0]);
 	while (1)
	{
 	 	if (response[i]==0) break;
		//alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
   	    	g_server_ip_array[j]=response[i].slice(3,strlength);
   	    	//alert(g_server_ip_array[j]);
  		i++;
  		j++;
	}
	g_totoal_server_ip_no=i+1;
 	call_Query_A_Channel_More(g_ch_no);
 }

}

function call_Get_Server_IP(ch_no)
{
 var ch_src_id="chsrc"+ch_no; 
 var ch_src;
 var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;


   	g_token=find_cookie_value("token");
 
	 cgi_url = "/server/get_server_ip_list?token="+encodeURI(g_token)+"&ch_no="+encodeURI(ch_no)+ "&flag="+Math.random();
	 g_ch_no=ch_no;
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Get_Server_IP;
	 xmlHttp.send(null);

}
function Block_Player() {

  if (xmlHttp.readyState == 4) {
	    var response = xmlHttp.responseText;
	    var reloader_content;
	    if (response==1)
	    {
	    	calllist_active_player_info(g_active_connection_position,g_active_connection_limit);
	    } else
	    {
	   	alert("Failed to Block the player");
	    }

    }
}

function callServer_Block_Player(sessionno, protocoltype){

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
	//alert(protocoltype);
   	g_token=find_cookie_value("token");

	confirm_msg="Block Player ["+sessionno+"] ?";
	 if (confirm(confirm_msg))
	 {
 		cgi_url= "/player/block_player?token="+encodeURI(g_token)+"&sessionno="+encodeURI(sessionno)+"&protocol="+encodeURI(protocoltype)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Block_Player;
		xmlHttp.send(null);
	}
 
 

}
function Stop_Player() {

  if (xmlHttp.readyState == 4) {
	    var response = xmlHttp.responseText;
	    var reloader_content;
	    if (response==1)
	    {
	    	calllist_active_player_info(g_active_connection_position,g_active_connection_limit);
	    } else
	    {
	   	alert("Failed to Stop the player");
	    }

    }
}

function callServer_Stop_Player(sessionno, protocoltype){

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
	//alert(protocoltype);
   	g_token=find_cookie_value("token");

	confirm_msg="Stop Player ["+sessionno+"] ?";
	 if (confirm(confirm_msg))
	 {
 		cgi_url= "/player/stop_player?token="+encodeURI(g_token)+"&sessionno="+encodeURI(sessionno)+"&protocol="+encodeURI(protocoltype)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Stop_Player;
		xmlHttp.send(null);
	}
 
 

}

function open_user_agent_modal(no)
{
	var modal = document.getElementById('PanelModalUserAgent');
	modal.style.display = "block";
}
function close_user_agent_modal() {
   var modal = document.getElementById('PanelModalUserAgent');
   modal.style.display = "none";
}
function list_active_player_info()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var sessionnotext;
    var sessionno;
    var username;
    var p2p_seed;
    var playername;
    var watching_ch;
    var box_time;
    var box_ip;
    var box_ispname;
   var box_country;
    var box_group;
    var box_group_text;
    var eztbox_title="<p>"+"macid IP name"+"</p>";
    var eztbox_list;
    var i=0;
    var j=0;
    
    var box_no=g_active_connection_position;
	var eztbox_active_no=0;
	var ret=0;
	var HTML_title_str='';
	var HTML_str='';
	var macid_value;
	var total_count=0;
	var total_no=0
	var current_position=g_active_connection_position;
	var total_counttext;
	var menustr1;
	
  var content;
  var cellsize="10%";
  	var ezcontent= document.getElementById("content")
	g_start_search_option=5;

	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	str+='<td width="80%"><font face="Arial" color="#000000" size="4"><b>Connection</b></font>';
	str+='</td>';

	str+='<td>';
	//alert(g_search_text);
	if ((g_search_text.length==0)|| g_SearchInput.value=='Search Players...')
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Players..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}else
	{
	  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
	}
	str+='</td>';
	
	str += '<td>' +
       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
       '</select>' +
       '</td>';	

	str+='<td align="right">';
	str+='<div class="navbar" style="background-color: #F5F6F8">';
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="calllist_auto_active_player_info(true)">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;
	//alert(document.getElementById("page_no"));
	//alert(g_constant_limit);
	//document.getElementById("page_no").value=g_constant_limit;		
	//alert(document.getElementById("page_no").value);
	/*
	var menu_screen= document.getElementById("ezmenu");
	var search_field= document.getElementById("title_search_field");
	var search_button= document.getElementById("title_search_button");
	search_field.hidden=false;
	search_button.hidden=false;

	document.getElementById("menu_title_text").innerHTML='<font face="Arial" color=#000000 size="6">Connections</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="calllist_auto_active_player_info()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Refresh</button>'; 
	str+='</div>';                              

	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");

	content.innerHTML="";
	total_count=5;
	
	g_search_player_item.value=null;

	if (g_P2P_Option==0)
	{
		HTML_str= '<table border="0"   cellpadding="0" cellspacing="10" align="center">'+
		  '<tr>'+
		      '<td width="20" height="17" align="left"><p style="margin-left: 5"><font face="Arial" size="2">No.</font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>User</b></font></td>'+
		      '<td width="'+cellsize+' height="17" align="center"><font face="Arial" size="2"><b>Session</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>User Agent</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Watching CH/Moive</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Starting Time</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>IP</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>MAC ID</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>ISP</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Country</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Protocol</b></font></td>'+
		      '<td width="10" height="17" align="center"></td>'+
		      '<td width="10" height="17" align="center"></td>'+
	 	 '</tr>'+'<tr><td  colspan="13"><hr size="1" color="#66FFFF"></td></tr>';
	}else if (g_P2P_Option==1)
	{
			HTML_str= '<table border="0"   cellpadding="0" cellspacing="10" align="center">'+
		  '<tr>'+
		      '<td width="20" height="17" align="left"><p style="margin-left: 5"><font face="Arial" size="2">No.</font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>User</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>P2P Seed</b></font></td>'+
		      '<td width="'+cellsize+' height="17" align="center"><font face="Arial" size="2"><b>Session</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>User Agent</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Watching CH/Moive</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Starting Time</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>IP</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>MAC ID</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>ISP</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Country</b></font></td>'+
		      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Protocol</b></font></td>'+
		      '<td width="10" height="17" align="center"></td>'+
		      '<td width="10" height="17" align="center"></td>'+
	 	 '</tr>'+'<tr><td  colspan="13"><hr size="1" color="#66FFFF"></td></tr>';
	}	
 	i=0;
 	total_counttext=response[i];
	total_count=total_counttext.slice(12);
	//alert(total_count);
	i++;
 
	while (1)
	{
		if (response[i]==0) break;
		//alert(response[i]);
		sessionnotext=response[i];
		sessionno=sessionnotext.slice(10);
		//alert(sessionno);
		i++;
		username=response[i];
//		alert(username);
		ret=username.indexOf("username",0);
		//if (ret==-1) break;
		i++;
		if (response[10].match("WebRTC"))
		{
		}else
		{
			if (g_P2P_Option==1)
			{
				p2p_seed=response[i];
				i++;
			}
		}
		playername=response[i];
		i++;
		watching_ch=response[i];
		i++;
		box_time=response[i];
//		alert(box_time);
		i++;
		box_ip=response[i];
		//alert(box_ip)
		i++;
		box_macid=response[i];
		i++;
		box_ispname=response[i];
		i++;
		box_country=response[i];
		i++;
		box_group_text=response[i];
		i++;
		box_group=box_group_text.slice(6);
//		alert(box_group);
		//i=i+10;
		total_no++;
		j++;
		HTML_str+='<tr>'+
		      '<td width="20" height="18" align="left"><p style="margin-left: 5"><font face="Arial" size="2">'+box_no+'</font></td>'+
		      '<td id=username'+j+' width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+username.slice(9)+'</font></td>';
		if (response[10].match("WebRTC"))
		{
		}else
		{
			if (g_P2P_Option==1)
			{
				HTML_str+='<td id=username'+j+' width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+p2p_seed.slice(9)+'</font></td>';
			}	
		}	      
		HTML_str+='<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+sessionno+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+playername.slice(11)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+unescape(watching_ch.slice(12))+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_time.slice(12)+'</font></td>'+
		      '<td id=userip'+j+' width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_ip.slice(10)+'</font></td>'+
		      '<td id=usermac'+j+' width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_macid.slice(13)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_ispname.slice(8)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_country.slice(8)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_group+'</font></td>'+
		      '<td align="center">'+
		      " <a href='javascript:void(0)'"+' onclick=callServer_Stop_Player("'+sessionno+'","'+box_group+'")>'+
		      ' <img border="0" id="stopbutton" alt="Stop" title="Stop" src="/admin/stop_icon.PNG"></a></td>'+
		      '<td align="center">'+
		      " <a href='javascript:void(0)'"+' onclick=callServer_Block_Player("'+sessionno+'","'+box_group+'")>'+
		      ' <img border="0" id="blockbutton" alt="Block" title="Block" src="/admin/block_icon.PNG"></a></td>'+
		      '</tr>';
		box_no++;
     }

	g_active_player_no=total_count;
	/* menustr1='<table width=100%><tr>';
	menustr1+='<td width="4%">';
	menustr1+='<div id="PanelModalUserAgent" class="modal">'+
	'<div class="modal-content">';
	menustr1+='<table align="center" cellspacing="10" align="center">';
	menustr1+='<tr><td colspan=2 align="left"><font face="Arial" size="6"><b>user Agent</b></font></td><td id=total_no align="right"></td></tr>';
	menustr1+='<tr><td  colspan="3"><hr size="1" color="#000000"></td></tr>';
	menustr1+='<tr><td colspan=2 id=user_agent_list></td>'+
	'<td>'+
	'<table>';
	menustr1+='<tr><td><input id="Del" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Del" onclick=call_Del_User_Agent() name="Del" /></td></tr>';
	
	menustr1+='</table></td></tr>';
	
	
	menustr1+='<tr><td width=45%><input id="Add" style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_User_Agent() name="Add" /></td>'+
	'<td width=45%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_user_agent_modal() name="Cancel" /></td>';
	menustr1+='<td width=10%></td></tr>';
	menustr1+='</table>'+
	'</div>'+
	'</div></td>';
	
	menustr1+='</tr></table>';
  	*/
		if (total_count==0)
		{
			current_position=0;
			endposition=0;
		}else
		{
			endposition=current_position+total_no-1;
		}
		menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
		menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' connections</td>';
		position=1;
		limit=g_constant_limit;
		if (total_count>g_constant_limit)
	{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:calllist_active_player_info('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	 
	content.innerHTML=HTML_str+'</table>'+menustr2;
	g_SearchInput = document.getElementById("search_field");
     	if (g_search_text.length>0)
     	{
     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
     		g_SearchInput.focus();
     	}
	/*if (bQuery_Online_Player==1)
   	{
		if (g_Query_Online_Player_timer==0)
		{
			g_Query_Online_Player_timer=setInterval(function(){callServer_Query_Online_Player_Timer()},10*1000);
		  //	alert(g_Query_Online_Player_timer);
		}
	}
	*/
 }
}
function Block_Alert_Player() {

  if (xmlHttp.readyState == 4) {
	    var response = xmlHttp.responseText;
	    var reloader_content;
	    if (response==1)
	    {
	    	calllist_alert_player_info();
	    } else
	    {
	   	alert("Failed to Block the player");
	    }

    }
}

function callServer_Block_Alert_Player(sessionno, protocoltype){

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
	//alert(protocoltype);
   	g_token=find_cookie_value("token");

	confirm_msg="Block Player ["+sessionno+"] ?";
	 if (confirm(confirm_msg))
	 {
 		cgi_url= "/player/block_player?token="+encodeURI(g_token)+"&sessionno="+encodeURI(sessionno)+"&protocol="+encodeURI(protocoltype)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Block_Alert_Player;
		xmlHttp.send(null);
	}
 
 

}
function Stop_Alert_Player() {

  if (xmlHttp.readyState == 4) {
	    var response = xmlHttp.responseText;
	    var reloader_content;
	    if (response==1)
	    {
	    	calllist_alert_player_info();
	    } else
	    {
	   	alert("Failed to Stop the player");
	    }

    }
}

function callServer_Stop_Alert_Player(sessionno, protocoltype){

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
	//alert(protocoltype);
   	g_token=find_cookie_value("token");

	confirm_msg="Stop Player ["+sessionno+"] ?";
	 if (confirm(confirm_msg))
	 {
 		cgi_url= "/player/stop_player?token="+encodeURI(g_token)+"&sessionno="+encodeURI(sessionno)+"&protocol="+encodeURI(protocoltype)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = Stop_Alert_Player;
		xmlHttp.send(null);
	}
 
 

}
function list_alert_player_info(){
  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText.split("\r\n");
    var sessionnotext;
    var sessionno;
    var username;
    var playername;
    var watching_ch;
    var box_time;
    var box_watch_hour;
    var box_ip;
    var box_country;
    var box_group;
    var box_group_text;
    var eztbox_title="<p>"+"macid IP name"+"</p>";
    var eztbox_list;
    var i=0;
    var box_no=1;
	var eztbox_active_no=0;
	var ret=0;
	var HTML_title_str='';
	var HTML_str='';
	var macid_value;
 var content;
  var cellsize="10%";
  	var ezcontent= document.getElementById("content")
	g_start_search_option=6;
	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	str+='<td width="80%"><font face="Arial" color="#000000" size="4"><b>Alert Connections</b></font>';
	str+='</td>';
	
	str+='<td align="right">';
	str+='<div class="navbar" style="background-color: #F5F6F8">';
		
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="calllist_alert_player_info()">'; 
		    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");
	//var search_field= document.getElementById("title_search_field");
	//var search_button= document.getElementById("title_search_button");
	//search_field.hidden=false;
	//search_button.hidden=false;

	document.getElementById("menu_title_text").innerHTML='<font face="Arial" color=#000000 size="6">Alert Connections</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="calllist_alert_player_info()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Refresh</button>'; 
	str+='</div>';                              

	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");

	content.innerHTML="";
//	detail.innerHTML="";
	

	 HTML_title_str= '<table border="0" align="center" cellpadding="0" cellspacing="10">'+
	  '<tr>'+
	      '<td width="50" height="17" align="center"><font face="Arial" size="2">No.</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>User</b></font></td>'+
	      '<td width="'+cellsize+' height="17" align="center"><font face="Arial" size="2"><b>Session</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>User Agent</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Watching CH/Moive</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Starting Time</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Watch Hours</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>IP</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>MAC Address</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Country</b></font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2"><b>Protocol</b></font></td>'+
	   //   '<td width="100" height="17" align="center">'+
	    //  " <a href='javascript:void(0)' onclick=callServer_Reboot_All_Player()>"+
	    // ' <font face="Arial" size="2">Reboot All</font></a></td>'+
 	 '</tr>'+'<tr><td  colspan="11"><hr size="1" color="#66FFFF"></td></tr>';
	
	while (1)
	{
		if (response[i]==0) break;
		//alert(response[i]);
		sessionnotext=response[i];
		sessionno=sessionnotext.slice(10);
		//alert(sessionno);
		username=response[i+1];
//		alert(username);
		ret=username.indexOf("username",0);
		//if (ret==-1) break;
		playername=response[i+2];
		watching_ch=response[i+3];
		
		box_time=response[i+4];
		box_watch_hour=response[i+5];
//		alert(box_watch_hour);
//		alert(box_time);
		box_ip=response[i+6];
//		alert(box_ip)
		box_macid=response[i+7];
		box_country=response[i+8];
		box_group_text=response[i+9];
		box_group=box_group_text.slice(6);
//		alert(box_group);
		i=i+10;
		eztbox_active_no++;
		HTML_str='<tr>'+
		      '<td width="50" height="18" align="center"><font face="Arial" size="2">'+box_no+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+username.slice(9)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+sessionno+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+playername.slice(11)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+watching_ch.slice(12)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_time.slice(12)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><b><font face="Arial" size="2" color="#FF0000">'+box_watch_hour.slice(18)+'</font></b></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_ip.slice(10)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_macid.slice(13)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_country.slice(8)+'</font></td>'+
		      '<td width="'+cellsize+'" height="18" align="center"><font face="Arial" size="2">'+box_group+'</font></td>'+
		      '<td width="50" height="18" align="center">'+
		      " <a href='javascript:void(0)'"+' onclick=callServer_Stop_Alert_Player("'+sessionno+'","'+box_group+'")>'+
		      ' <img border="0" id="stopbutton" alt="Stop" title="Stop" src="/admin/stop_icon.PNG"></a></td>'+
		      '<td width="50" height="18" align="center">'+
		      " <a href='javascript:void(0)'"+' onclick=callServer_Block_Alert_Player("'+sessionno+'","'+box_group+'")>'+
		      ' <img border="0" id="blockbutton" alt="Block" title="Block" src="/admin/block_icon.PNG"></a></td>'+
		      '</tr>'+HTML_str;
		      
		box_no++;
     }
       // contentinnerHTML=HTML_str;
       HTML_str=HTML_title_str+HTML_str;
        
  	content.innerHTML=HTML_str;
	
	//alert(content.innerHTML);
    
 }
 
 
}


function reload_filter_information() {

  if (xmlHttp.readyState == 4) {
	    var response = xmlHttp.responseText;
	    var reloader_content;
	    if (response==1)
	    {
	    } else
	    {
	   	alert("Failed to Reload Filter Information");
	    }
 	reloader_content = document.getElementById("reload_filter_information");
 	reloader_content.innerHTML="<a href='javascript:void(0)'"+
	' onclick=call_reload_filter_information()>'+
	' <font face="Arial" size="2">Reload Filters</font></a>'

    }
}

function call_reload_filter_information(){

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
   	g_token=find_cookie_value("token");
 	var reloader_content = document.getElementById("reload_filter_information");

	confirm_msg="Reload Filter Information?";
	 if (confirm(confirm_msg))
	 {
 		cgi_url= "/server/reload_filter_information?token="+encodeURI(g_token)+"&flag="+Math.random();
		reloader_content.innerHTML='<font face="Arial" color="#FF0000" size="2">Reloading';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = reload_filter_information;
		xmlHttp.send(null);
	}
 
 

}
function calllist_auto_active_player_info(page_flag){
	var position=1;
	var limit=g_constant_limit;
	g_search__player_text=null;
	g_active_connection_position=position;
	if (page_flag)
	{
		g_constant_limit=parseInt(document.getElementById("page_no").value);
		//alert(g_constant_limit);
	}
	limit=g_constant_limit;
	g_active_connection_limit=limit;
	bQuery_Online_Player=1;
//	document.getElementById("title_search_field").value="";
    	if (g_System_timer)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
	}
	calllist_active_player_info(g_active_connection_position,g_active_connection_limit);
}
function calllist_active_player_info(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;
 	g_active_connection_position=position;
	g_active_connection_limit=limit;
	var content = parent.document.getElementById("content");

	if (g_token!=0)
	{
		if (g_search_text==null)
		{
			cgi_url= "/player/get_player_list?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&flag="+Math.random();
		}else
		{
			cgi_url= "/player/get_player_list?token="+encodeURI(g_token)+"&position="+position+"&limit="+limit+"&searchvalue=" +g_search_text+"&flag="+Math.random();
		}
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Player Information Loading...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = list_active_player_info;
		xmlHttp.send(null);
	}
 
 

}
function calllist_alert_player_info(){

	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;
	var content = parent.document.getElementById("content");

	if (g_token!=0)
	{
		cgi_url= "/player/get_alert_player_list?token="+encodeURI(g_token)+"&flag="+Math.random();
		content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Player Information Loading...<p>';
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = list_active_player_info;
		xmlHttp.send(null);
	}
 
 

}

function callServer_group_Inquery() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	g_token=find_cookie_value("token");

 cgi_url = "/server/query_group?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Group Information Loading...<p>';


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

}

function Cancel_Add_group()
{
	callServer_group_Inquery();
}


function Add_group() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
 //   	alert("Add Group Sucessfully");
    } else
    {
   	alert("Failed to Add Group");
    }
	callServer_group_Inquery();
    }
}
function call_Add_Group()
{

 var group_src_id="groupsrc"; 
 var group_mcsrc_id="groupmcsrc"; 
 var group_src_name="groupname"; 
 var group_peroid_id="group_peroid"; 
 var group_credit_unit_id="group_credit_unit"; 
 var group_connection_id="group_connection"; 
 var group_src;
 var group_mcsrc;
 var group_name;
 var group_peroid;
 var group_credit_unit;
 var g_item_name;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
 //g_item=document.getElementById(group_src_id);
 //group_src = g_item.value;

 //g_item=document.getElementById(group_mcsrc_id);
 //group_mcsrc = g_item.value;
group_src="all";
group_mcsrc="all";

 g_item_name=document.getElementById(group_src_name);
 group_name = g_item_name.value;

g_item_name=document.getElementById(group_peroid_id);
 group_peroid = g_item_name.value;

g_item_name=document.getElementById(group_credit_unit_id);
 group_credit_unit = g_item_name.value;

g_item_name=document.getElementById(group_connection_id);
 group_connection = g_item_name.value;


   	g_token=find_cookie_value("token");

 cgi_url = "/server/add_group?token="+encodeURI(g_token)+ "&group_name=" + encodeURI(group_name)+"&group_peroid=" + encodeURI(group_peroid)+"&group_credit_unit=" + encodeURI(group_credit_unit)+"&group_connection=" + encodeURI(group_connection)+ "&group_src=" + encodeURI(group_src)+ "&group_mcsrc=" + encodeURI(group_mcsrc)+"&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Add_group;
	 xmlHttp.send(null);
}


function call_Add_New_group()
{

var HTML_str;
var group_no;
var len;
g_total_group_no++;
   var content = parent.document.getElementById("content");

	HTML_str=content.innerHTML;
	//len=HTML_str.length-16;
	len=HTML_str.lastIndexOf("</tr>");
	if (len==-1)
	{
		len=HTML_str.lastIndexOf("</TR>");
	}	
//	alert(len);
	len+=5;
	HTML_str=HTML_str.slice(0,len);
	group_no=g_total_group_no;
	HTML_str=HTML_str+'<tr>'+
		      '<td width="100" align="center"><font face="Arial" size="2">'+group_no+'</font></td>'+
		      '<td width="20" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="groupname"'+
	 		' id=groupname'+group_no+
	 		' size="20"/'+
	 		'</font></td>';
		      
	 		
		      HTML_str+='<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <select size="1" style="width: 180;" name="groupsrc" id=groupsrc'+group_no+'>';
			HTML_str+='<option selected="selected" value="all">'+'all'+'</option>';
			HTML_str+='</select></font></td>';

		      HTML_str+='<td width="200" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <select size="1" style="width: 180;" name="groupmcsrc" id=groupmcsrc'+group_no+'>';
			HTML_str+='<option selected="selected" value="all">'+'all'+'</option>';
			HTML_str+='</select></font></td>';

		      HTML_str+='<td width="150" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="group_concurrentconnection"'+
	 		' id=group_concurrentconnection'+group_no+
	 		' size="3"/'+
	 		'</font></td>'+
		      '<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_group("'+group_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	      
		      '<td align="center">'+		      
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_group()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+
	      	      '</tr>';
//	alert(HTML_str);

	       content.innerHTML=HTML_str+'</table>';
  //      alert(ch_list_info.innerHTML);
   
		
}



function callServer_update_group(group_no){
	
var group_src_id="groupccsrc"+group_no; 
var group_mcsrc_id="groupmcsrc"+group_no; 
var group_scsrc_id="groupscsrc"+group_no; 
 var group_src_name="groupname"+group_no; 
 var group_peroid_id="groupperoid"+group_no; 
 var group_credit_unit_id="groupcreditunit"+group_no; 
 var group_connection_id="groupconnections"+group_no; 
 var group_src;
 var group_mcsrc;
 var group_name;
 var group_peroid;
 var group_credit_unit;
 var g_item_name;
 var ccoptions=document.getElementById(group_src_id);
 var mcoptions=document.getElementById(group_mcsrc_id);
 var scoptions=document.getElementById(group_scsrc_id);
 var opt;
 var i=0;
 var iLen;
 var bFirstItem=1;



var confirm_msg;
 	var cgi_url;
 
 g_item=document.getElementById(group_src_id);
 group_src = g_item.value;
 

	group_src='';
	iLen=ccoptions.length;
	 for (i=0;i<iLen;i++)
	 {
	 	opt=ccoptions[i];
	 	//alert(opt.value);
	 	//alert(opt.selected);
	 	if (opt.selected)
	 	{
	 		//alert(opt.value);
	 		if (bFirstItem==0)
	 		{
	 		  group_src+=','+opt.value;	
			}else
			{
				group_src+=opt.value;	
				bFirstItem=0;
			}				
	 	}
	 }
	// alert(group_src);
	 group_mcsrc='';
	iLen=mcoptions.length;
	bFirstItem=1;
	 for (i=0;i<iLen;i++)
	 {
	 	opt=mcoptions[i];
	 	//alert(opt.value);
	 	//alert(opt.selected);
	 	if (opt.selected)
	 	{
	 		//alert(opt.value);
	 		if (bFirstItem==0)
	 		{
	 		  group_mcsrc+=','+opt.value;	
			}else
			{
				group_mcsrc+=opt.value;	
				bFirstItem=0;
			}				
	 	}
	 }
	// alert(group_mcsrc);
	 
	group_scsrc='';
	iLen=scoptions.length;
	bFirstItem=1;
	 for (i=0;i<iLen;i++)
	 {
	 	opt=scoptions[i];
	 	//alert(opt.value);
	 	//alert(opt.selected);
	 	if (opt.selected)
	 	{
	 		//alert(opt.value);
	 		if (bFirstItem==0)
	 		{
	 		  group_scsrc+=','+opt.value;	
			}else
			{
				group_scsrc+=opt.value;	
				bFirstItem=0;
			}				
	 	}
	 }	
	// alert(group_scsrc);
	 g_item_name=document.getElementById(group_src_name);
	 group_name = g_item_name.value;
	
	g_item_name=document.getElementById(group_peroid_id);
	 group_peroid = g_item_name.value;
	g_item_name=document.getElementById(group_credit_unit_id);
	 group_credit_unit = g_item_name.value;
	g_item_name=document.getElementById(group_connection_id);
	 group_connection = g_item_name.value;
	
	    	g_token=find_cookie_value("token");
	
	 confirm_msg="Update Group "+group_no+" Information?";
	  cgi_url = "/server/update_group?token="+encodeURI(g_token)+"&group_no=" + encodeURI(group_no)+"&group_name=" + encodeURI(group_name)+"&group_peroid=" +encodeURI(group_peroid)+
	  "&group_credit_unit="+encodeURI(group_credit_unit)+"&group_connection="+encodeURI(group_connection)+
	   "&group_src=" + group_src+ "&group_mcsrc=" + group_mcsrc+ "&group_scsrc=" + group_scsrc+"&flag="+Math.random();
	//if (confirm(confirm_msg))
	// {
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = function ()
		 {
		  	if (xmlHttp.readyState == 4) {
			    var response = xmlHttp.responseText;
			    if (response==1)
			    {
			    	callServer_group_Inquery();    	
			    } else if (response==2)
			    {
			    	alert("Group not existed");
			    	callServer_group_Inquery();    	
			    }else
			    {
			   	alert("Failed to Update Group");
			    }
		    }	
		 };
		 xmlHttp.send(null);
	//}

}

function Del_group() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
  //   	alert("Delete Group Sucessfully");
    } else
    {
   	alert("Failed to Delete Group");
    }
    	callServer_group_Inquery();
    }
}

function call_Del_group(group_no)
{
 // var group_src_id="groupsrc"+group_no; 
 var group_src_name="groupname"+group_no; 
 var group_src;
 var group_name;
 var g_item_name;
 
  var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	
// g_item=document.getElementById(group_src_id);
// group_src = g_item.value;

 g_item_name=document.getElementById(group_src_name);
 group_name = g_item_name.value;
   	g_token=find_cookie_value("token");

 confirm_msg="Delete Group "+group_no+" Information?";
 cgi_url = "/server/del_group?token="+encodeURI(g_token)+ "&group_name=" + encodeURI(group_name)+ "&flag="+Math.random();
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Del_group;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	// g_item.value=g_item.value+" (del...)";
	//g_item.style.backgroundColor = "#ff0000";
 }
 

}



function Add_Multiple_User_Info() {

	if (xmlHttp.readyState == 4) 
	{
	    var response = xmlHttp.responseText;
	    var username_id;
	    //alert(response);
	    if (response==1)
	    {
	    	
	    	g_user_no=parseInt(g_user_no)+parseInt(g_multiple_user_no);
	    	if ((g_user_position+g_constant_limit)<=g_user_no)
		{
			if (((g_cur_userno)%g_constant_limit)==1)
			{
				g_user_position=parseInt(g_cur_userno);
			}
			g_user_limit=g_constant_limit;
		}else
		{
			g_user_limit=g_user_no%g_constant_limit;
			if (g_user_limit==0) 
			{
				if (g_user_no<g_user_position)
				{
					g_user_position=g_user_no-g_constant_limit+1;
				}
				g_user_limit=g_constant_limit;
			}
		}
	    	call_get_users(g_user_position,g_user_limit);
	    	//alert(g_username_item.value);
//	    	 	username_id="username"+g_cur_userno;
  //  	g_username_item=document.getElementById(username_id);
    //	alert(g_username_item.value);

	//	g_username_item.focus();
	//	g_username_item.style.backgroundColor = "#00ffff";
	  
	    } else if (response==0)
	    {
	   	alert("Failed to Add Multiple Users");
	    }else if (response==2)
   	   {
   		alert("This function is only for Enterprise version");
		call_get_users(g_user_position,g_user_limit);
 	   } else if (response==3)
	    {
	    	alert("Disk is error(FULL), Please contact administrator");
		call_get_users(g_user_position,g_user_limit);
	    }
	}
 
}
function call_Add_Multiple_User_detail(userno)
{
	var confirm_msg;
	var cgi_url;
	var multiple_user_no;
	var expiration_no;
	var expiration_unit;
	var group;
	//alert(userno);
	g_item=document.getElementById("multiple_user_no");
	multiple_user_no=g_item.value;
	if (multiple_user_no.length==0)
	{
		alert("Multiple User No. is empty");
		return;
	}
	g_multiple_user_no=multiple_user_no;
	//alert(multiple_user_no=g_item.value);
	g_item=document.getElementById("group");
	group=g_item.value;
	
	if (multiple_user_no.length==0)
	{
		alert("Multiple User No. is empty");
		return;
	}
	//alert(multiple_user_no);
	g_item=document.getElementById("expiration_no");
	expiration_no=g_item.value;
	if (expiration_no.length==0)
	{
		alert("'Expiration no.' is empty");
		return;
	}
	//alert(expiration_no);
	g_item=document.getElementById("expiration_unit");
	expiration_unit=g_item.value;

  	g_token=find_cookie_value("token");

	g_cur_userno=userno;
	//alert("111111111");
	//confirm_msg="Add Multiple Users?";
	cgi_url = "/server/add_multiple_user?token="+encodeURI(g_token)+"&userno="+encodeURI(userno)+"&group="+encodeURI(group)+"&multiple_user_no="+encodeURI(multiple_user_no)+"&expiration_no="+encodeURI(expiration_no)+"&expiration_unit="+encodeURI(expiration_unit)+
	"&flag="+Math.random();
	//alert(cgi_url);
//	if (confirm(confirm_msg))
//	{	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Add_Multiple_User_Info;
		 xmlHttp.send(null);
//	}
}
function call_Add_Multiple_User(userno) {
   var str;
   var groupname;
   var j;
  var AddMultipleUserWindow;
  var groupname;
  var content = parent.document.getElementById("content");
 	    var username_id;

	g_content=content.innerHTML;

 
	content.innerHTML="";
     str="<head><title>Add Multiple Users</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body><table align="center">';

  		
 		str+='<tr><td width="120"><font face="Arial"> <font size="2">Multiple User no.: </font></td><td width="100" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="multiple_user_no"'+
 		' id="multiple_user_no"'+
 		' size="5" value="'+
 		'10'+
 		'"/></font></td></tr>';
 		
  
  		str+='<td width="120"><font face="Arial"> <font size="2">Group: </font></td><td width="120" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" name="group" id=group>';
		for (j=0;j<g_total_group_no;j++)
		{
			groupname=g_groupname_array[j];
			if (j>0)
			{
				str+='<option value="'+groupname+'">'+groupname+'</option>';
			}
			else 
			{
				str+='<option selected="selected" value="'+groupname+'">'+groupname+'</option>';
			}	 			
		}
		str+='</select></font></td>';


		str+='<tr><td width="120"><font face="Arial"> <font size="2">Expiration Period: </font></td><td width="100" height="23">'+
 		' <font face="Arial"> <font size="2">'+
 		' <input type="text" name="expiration_no"'+
 		' id="expiration_no"'+
 		' size="10" value="'+
 		12+
 		'"/></font></td>';
 		
 		str+='<td width="100" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" name="expiration_unit" id=expiration_unit>'+
		'<option selected="selected" value="month">months</option>'+
		'<option value="year">years</option>'+'</td></tr>';
		
    str+='<tr><td><input type="button" value="Add" onclick=call_Add_Multiple_User_detail("'+userno+'") name="B2" /></td>'+
    '<td><input type="button" value="Cancel" onclick=Cancel_Add_User() name="B3" /></td>'+
    /*		      '<td id=del_id_button width="80" align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_User()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+
	      	      */
    '</tr></table></body>';  

  content.innerHTML=str;
      // 	 AddMultipleUserWindow= window.open("", "", "top=300, left=300, width=500, height=150"); 
	//AddMultipleUserWindow.document.write(str); 
	

}
function open_channel_category_add_modal()
{
	var modal = document.getElementById('PanelModalChannelCategoryAdd');
	modal.style.display = "block";	
	
}
function close_channel_category_add_modal() {
   var modal = document.getElementById('PanelModalChannelCategoryAdd');
   var button=document.getElementById("submitbutton");
   button.disabled=false;
   button.value="Add";
   modal.style.display = "none";   
   open_channel_category_modal();
}
function open_channel_category_edit_modal()
{
	var modal = document.getElementById('PanelModalChannelCategoryEdit');
	modal.style.display = "block";	
	var category= document.getElementById('editcategory');
	var current_category_url=document.getElementById('edit_category_url');
	var i;
	category.value=g_categoryclickedItemValue;
	for (i=0;i<g_total_channel_category_no;i++)
	{
		if (g_categoryclickedItemValue==g_Channel_Categories_tems[i])
		{
			current_category_url.value=g_Channel_Categories_icons[i];
			current_category_url.style.color='#000000';
			break;
		}
	}
	
}
function close_channel_category_edit_modal() {
   var modal = document.getElementById('PanelModalChannelCategoryEdit');
   var button=document.getElementById("submitbutton");
   button.disabled=false;
   button.value="Save";
    modal.style.display = "none";   
   open_channel_category_modal();
}
function close_import_xtream_db_modal() {
   var modal = document.getElementById('PanelModalImport');
   var importbutton=document.getElementById("submitbutton");
   
   importbutton.value="Submit";
   importbutton.disabled=false;
   modal.style.display = "none";
   g_user_position=1;
   g_user_limit=g_constant_limit;
   call_get_users(g_user_position,g_user_limit);
}
function call_import_xtream_db()
{
	var importbutton=document.getElementById("submitbutton");
	var xc_users_reseller=document.getElementById("xc_users_reseller");
	var xc_streams=document.getElementById("xc_streams");
	var api_option;
	var ncontent=1;
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		alert("Only for Formal version");
		return;
	}
	if ((xc_users_reseller.checked==true) && (xc_streams.checked==false))
	{
		ncontent=1;
	}else if ((xc_users_reseller.checked==false) && (xc_streams.checked==true))
	{
		ncontent=2;
	}else if ((xc_users_reseller.checked==true) && (xc_streams.checked==true))
	{
		ncontent=3;
	}
	importbutton.disabled=true;
	importbutton.value="Waiting";
	
	import_xtream_db_dialog_message.innerHTML='<i class="fa fa-refresh fa-spin"></i>';
	
	api_option = "/server/upload_files?token="+escape(g_token)+"&filetype="+"xtream_db"+"&content="+ncontent+"&flag="+Math.random();
	

	
	if ((xc_users_reseller.checked==true) && (xc_streams.checked==false))
	{
		call_Upload_Files(event,UPLOAD_XTREAM_DB_USERS,api_option);
	}else if ((xc_users_reseller.checked==false) && (xc_streams.checked==true))
	{
		call_Upload_Files(event,UPLOAD_XTREAM_DB_CONTENT,api_option);
	}else if ((xc_users_reseller.checked==true) && (xc_streams.checked==true))
	{
		call_Upload_Files(event,UPLOAD_XTREAM_DB,api_option);
	}

}
function callServer_Import_Xtream_DB() {
	var content = parent.document.getElementById("content");
	var menustr1='<table width=100%><tr>';
	menustr1+='<td width="4%">';
	menustr1+='<div id="PanelModalImport" class="modal">'+
	'<div class="modal-content">';
	menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
	menustr1+='<tr>'+
	'<td   colspan="2" align=left><font face="Arial" size="6"><b>Import Xtream DB</b></font></td><td   colspan="2" align=right id=import_xtream_db_dialog_message name=import_xtream_db_dialog_message></td></tr>';
	
	menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';	

	
	// Upload Local FIles
	menustr1+='<tr><td colspan="2" idth=50%>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td   colspan="2" width=50%><form id="file_upload_form_xtream_db" enctype="multipart/form-data">'+
	'<input type="file" name="Video" multiple/>'+
	'</form></td></tr>';

	// option for users, resellers and content
	menustr1+='<tr>'+
	'<td width="25%" height="23">'+
	'<p align="left"><font face="Arial" size="2">Users and Resellers</font>'+
	'</p>'+
	'</td>'+      
	'<td height="23"><p align="left">'+
	'<label class="switch"><input type="checkbox" checked id="xc_users_reseller"><span class="slider round"></span></label>'+
	'</td>'+
	
	'<td width="25%" height="23">'+
	'<p align="left"><font face="Arial" size="2">Channels, Movies and Series</font>'+
	'</p>'+
	'</td>'+      
	'<td height="23"><p align="left">'+
	'<label class="switch"><input type="checkbox" checked id="xc_streams"><span class="slider round"></span></label>'+
	'</td>'+

	'</tr>';


	menustr1+='<tr><td   colspan="2" width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Submit" onclick=call_import_xtream_db() name="Submit" /></td>'+
	'<td   colspan="2" width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_import_xtream_db_modal() id=cancel_button name="Cancel" /></td></tr>';
	menustr1+='</table>'+
	'</div>'+
	'</div></td>';
	 menustr1+='</tr>'+'</table>';
	 content.innerHTML=menustr1;
	var modal = document.getElementById('PanelModalImport');
	modal.style.display = "block";
}



function call_Add_User()
{
 var add_new_user_button=document.getElementById("add_new_user_button");
 var add_user_dialog_message=document.getElementById("add_user_dialog_message");
 var username_id="username"; 
 var password_id="password"; 
 var rating_password_id="rating_password"; 
 var group_id="group"; 
 var user_level_id="user_level"; 
 var expired_time_id="expired_time"; 
 var expired_time_id="expired_time"; 
 var userip_id="userip";
 var macid_id="macid";
 var user_no_id="userno";
 var szpassword;
 var user_level;
 var szrating_password;
 var szgroup;
 var expired_time;
 var expired_YY;
 var expired_MM;
 var expired_DD;
 //var paymodel;
 //var user_point;
 var userip;
 var macid;
 var username;
 var usern0;
 var d=new Date();
 var cur_year=d.getFullYear();
 var cur_month=d.getMonth()+1;
 var cur_date=d.getDate();

  var max_connection_id="max_connection";

  var max_connection;
var usernoitem;
var usernameitem;
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(user_no_id);
	usernoitem=g_item;
	user_no=g_item.value;
	/*
	if (user_no>(g_total_user_no+1))
	{
		alert("User No. is invaild.");
		return;
	}
	*/
	g_item=document.getElementById(macid_id);
	macid=g_item.value;
	g_item=document.getElementById(username_id);
	usernameitem=g_item;
	username=g_item.value;
	if (username.length==0)
	{
		alert("User name is empty");
		return;
	}
	g_item=document.getElementById(expired_time_id);
	expired_time=g_item.value;
	if (expired_time.length==0)
	{
		alert("Expired Time is empty");
		return;
	}else if (expired_time.length>10)
	{
		alert("Date Length is too long(>10)");
		return;
	}
	
	//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	//{
		g_item=document.getElementById(password_id);
		szpassword=g_item.value;
		if (szpassword.length==0)
		{
			if (!((macid=="mag") || (macid=="android") || (macid=="activecode")))
			{
				alert("Pawword is empty");
				return;
			}
		}
		if (szpassword==username)
		{
			alert("Password can not be same as Username");
			return;
			
		}
		g_item=document.getElementById(rating_password_id);
		szrating_password=g_item.value;
		/*
		pos=expired_time.indexOf('/');
		if (pos>0)
		{
			expired_MM=expired_time.substring(0,pos);
			expired_time_temp=expired_time.substring(pos+1);
			pos=expired_time_temp.indexOf('/');	
			expired_DD=expired_time_temp.substring(0,pos);
			expired_YY=expired_time_temp.substring(pos+1);
			if (expired_YY<cur_year)
			{
				alert_message="Expired Year should be >="+cur_year;
				alert(alert_message);
				return;
			}
			if ((expired_MM<1)||(expired_MM>12))
			{
				alert("Exipred Month should be between 1 and 12");
				return;
			}
			if ((expired_YY==cur_year)&&(expired_MM<cur_month))
			{
				alert_message="Expired Month should be >"+cur_month;
				alert(alert_message);
				return;
				
			}
			if ((expired_DD<1)||(expired_DD>31))
			{
				alert("Exipred Date should be between 1 and 30");
				return;
			}
			if ((expired_YY==cur_year)&&(expired_MM==cur_month)&&(expired_DD<cur_date))
			{
				alert_message="Expired Date should be >"+cur_date;
				alert(alert_message);
				return;
			}
		}
		*/
	/*
	}else if (g_user_authorization_mode==2)
	{
		szpassword=null;
	}
	*/

	//alert(szpassword);
	g_item=document.getElementById(group_id);
	szgroup=g_item.value;
	g_item=document.getElementById(user_level_id);
	user_level=g_item.value;
	//alert(user_level);
	g_item=document.getElementById(expired_time_id);
	expired_time=g_item.value;
	//alert(expired_time);
	//alert(szgroup);
//	g_item=document.getElementById(paymodel_id);
//	paymodel=g_item.value;
//	g_item=document.getElementById(user_point_id);
//	user_point=g_item.value;
	g_item=document.getElementById(userip_id);
	userip=g_item.value;
	
	g_item=document.getElementById(max_connection_id);
	max_connection=g_item.value;

   	g_token=find_cookie_value("token");

g_cur_userno=user_no;
 //confirm_msg="Add User: "+username+" Information?";
 cgi_url = "/server/add_user?token="+encodeURI(g_token)+"&userno="+encodeURI(user_no)+"&username="+encodeURI(username)+
  "&password="+szpassword+
  "&rating_password="+szrating_password+
  "&group="+szgroup+
  "&level="+user_level+
  "&expired_time="+expired_time+
 // "&paymodel="+paymodel+
 // "&user_point="+user_point+
  "&userip="+userip+
  "&macid="+macid+
  "&max_connection="+max_connection+
   "&flag="+Math.random();
 //  alert(cgi_url);

	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
		    var item_add;
		    var item_save;
		    var item_del;
		    var item_more;
		    var item_top_total_no;
		    var bAddFlag=false;
		    var new_add_total_no;
		  //  var item_bottom_total_no;
		    if (response==1)
		    {
		    //	alert("Add User Sucessfully");
		  	g_user_no++;
		  	if ((g_user_position+g_constant_limit)<=g_user_no)
			{
				if (((g_cur_userno)%g_constant_limit)==1)
				{
					g_user_position=parseInt(g_cur_userno);
				}
				g_user_limit=g_constant_limit;
			}else
			{
				g_user_limit=g_user_no%g_constant_limit;
				if (g_user_limit==0) 
				{
					if (g_user_no<g_user_position)
					{
						g_user_position=g_user_no-g_constant_limit+1;
					}
					g_user_limit=g_constant_limit;
				}
			}
			//bAddFlag = confirm("Sucessfully, continue to add new user?");
			//if (bAddFlag==true)
			//{
				add_new_user_button.value="Add Next";
				new_add_total_no=g_user_no+1;
				add_user_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+username+' Added</font>';
				//alert(new_add_total_no);
				usernoitem.value=new_add_total_no;
				usernameitem.value="";
				usernameitem.focus();
				
				
				

			//}else
			//{
				call_get_users(g_user_position,g_user_limit);
			//}
		 	
		    } else if (response==0)
		    {
		   	alert("Failed to Add User");
		   	//call_get_users();
		 	// 	call_get_users(g_user_position,g_user_limit);
		
		    } else if (response==2)
		    {
		    	alert("Disk is error(FULL), Please contact administrator");
		//	call_get_users();
		 	//call_get_users(g_user_position,g_user_limit);
		
		    }else if (response==3)
		    {
		   	//g_item.value=g_temp;
			//g_item.style.backgroundColor = "#ffffff";
		  	alert("The user is already in Database");
			//call_get_all_user();
		    }else if (response==4)
		    {
		   	//g_item.value=g_temp;
			//g_item.style.backgroundColor = "#ffffff";
		  	alert("Password does not allow the special character ':'");
		    }
		
		
		
			//alert(add_id_button.innerHTML);
		    }	 	
	 };	 	
	 xmlHttp.send(null);


}
function call_Add_New_User(userno) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
    	g_token=find_cookie_value("token");
	g_cur_userno=userno;
 cgi_url = "/server/query_group?token="+encodeURI(g_token)+"&flag="+Math.random();

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

}

function call_get_first_user(position, limit)
{
	g_user_found_position=0;
	call_get_users(position, limit);
}
function call_get_first_channel(position, limit)
{
	g_channel_found_position=0;
	call_get_channels(position, limit);
}
function call_get_first_movie(position, limit)
{
	g_movie_found_position=0;
	call_get_movies(position, limit);
}
function call_get_first_series(position, limit)
{
	g_movie_found_position=0;
	call_get_series(position, limit);
}

function call_Add_New_User_detail(userno)
{

var HTML_str;
var user_no;
var len;
var paymodel;
var str;
var content = parent.document.getElementById("content");
	
var user_active_no;
var i,j;
var username_id;
var password_id;
var group_id;
var expired_time_id;
var userip_id;
var macid_id;
var reseller_id;
var item_name;
var username;
var szpassword;
var szgroup;
var expired_time;
var userip;
var macid;
var reseller;

var groupname;
var expired_YY;
var expired_MM;
var expired_DD;
var d=new Date();
var cur_year=d.getFullYear();
var cur_month=d.getMonth()+1;
var cur_day=d.getDate();
var bexpired=0;
var pos;
var expired_time_temp;
var yearmsg;
var menustr1;
var menustr2;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_user_position;
	var total_count=g_user_no;
	var pagelineno=0;
	var total_no=0;

	g_content=content.innerHTML;

	user_active_no=total_count;
	user_active_no++;
	 HTML_str= '<table border="0" align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_user_no)></td>'+
	      '<td width="10%" align="center"><font face="Arial" size="2"></font></td>';
	//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
//	{
		HTML_str+='<td width="10%" align="center"><font face="Arial" size="2">User Name</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">Password</font></td>';
		HTML_str+='<td width="10%" align="center"><font face="Arial" size="2">Group</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">CH List</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">Movie List</font></td>'+
//		'<td width="10%" align="center"><font face="Arial" size="2">Expired Time</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">Expired Time</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">IP</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">MAC ID</font></td>'+
		'<td width="5%" align="center"><font face="Arial" size="2">Reseller</font></td>'+
		'</tr>'+'<tr><td  colspan="11"><hr size="1" color="#66FFFF"></td></tr>';
	/*
	}else if (g_user_authorization_mode==2)
	{
		HTML_str+='<td width="20%" align="center"><font face="Arial" size="2">PIN No.</font></td>';
		HTML_str+='<td width="10%" align="center"><font face="Arial" size="2">Group</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">CH List</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">Movie List</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">Expired Time</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">IP</font></td>'+
		'<td width="10%" align="center"><font face="Arial" size="2">MAC ID</font></td>'+
		'<td width="5%" align="center"><font face="Arial" size="2">Reseller</font></td>'+
		'</tr>'+'<tr><td  colspan="10"><hr size="1" color="#66FFFF"></td></tr>';
	}
	*/
//	for (i=1,m=1;i<=user_active_no;i++,m++)
//	for (i=1,m=1;i<=g_user_limit;i++,m++)
	pagelineno=parseInt(current_position)+parseInt(g_user_limit)+1;
	for (i=current_position,m=current_position;i<pagelineno;i++,m++)
	{
		
		HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">';
		
		
		username_id="username"+m; 
		item_name=document.getElementById(username_id);
		
		username = item_name.value;
		//alert(username);
		
		//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
		//{
			password_id="password"+m; 
			item_name=document.getElementById(password_id);
			szpassword = item_name.value;
		//}

		group_id="group"+m; 
		item_name=document.getElementById(group_id);
		szgroup = item_name.value;
		
		expired_time_id="expired_time"+m; 
		item_name=document.getElementById(expired_time_id);
		expired_time = item_name.value;
		
		userip_id="userip"+m; 
		item_name=document.getElementById(userip_id);
		userip = item_name.value;
			
		macid_id="macid"+m; 
		item_name=document.getElementById(macid_id);
		macid = item_name.value;
		
		reseller_id="reseller"+m; 
		item_name=document.getElementById(reseller_id);
		//alert(item_name.innerHTML);
		reseller = item_name.innerHTML;
		

		//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
		//{
		      HTML_str=HTML_str+'<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+i+
	 		' id=checkbox'+i+'></td>';
			HTML_str=HTML_str+'<td width="10%" align="center"><font face="Arial"> <font size="2">'+i+'</font></td>'+
			'<td width="10%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input readonly type="text" name="username"'+
			' id=username'+i+' size="12" value="'+
			username+'"/></font></td>'+
			
			'<td width="10%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="password"'+
			' id=password'+i+' size="12" value="'+
			szpassword+'"/></font></td>';
		/*
		}else if (g_user_authorization_mode==2)
		{
		      HTML_str=HTML_str+'<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+i+
	 		' id=checkbox'+i+'></td>';
			HTML_str=HTML_str+'<td width="10%" align="center"><font face="Arial"> <font size="2">'+i+'</font></td>'+
		      '<td width="20%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input readonly type="text" name="username"'+
			' id=username'+i+' size="36" value="'+
			username+'"/></font></td>';
		}
		*/
		
		
		HTML_str=HTML_str+'<td width="10%" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" name="group" id=group'+i+'>';
		for (j=0;j<g_total_group_no;j++)
		{
			groupname=g_groupname_array[j];
			//if (szgroup.search(groupname)==-1)
			if (szgroup!=(groupname))
			{
				HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
			}
			else 
			{
				if (szgroup.length==groupname.length)
				{
					HTML_str+='<option selected="selected" value="'+groupname+'">'+groupname+'</option>';
				}else
				{
					HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
				}
			}	 			
		}
		HTML_str+='</select></font></td>';
		
		HTML_str=HTML_str+'<td width="10%" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" onchange="call_download_user_chlist('+i+','+'chlist'+i+')" name="ch_list" id=chlist'+i+'>'+
		'<option value="-1">--</option>'+
		'<option value="enigma">Enigma</option>'+
		'<option value="enigma16">Enigma 1.6</option>'+
		'<option value="enigma(RTMP)">Enigma(RTMP)</option>'+
		'<option value="enigma16(RTMP)">Enigma 1.6(RTMP)</option>'+
		'<option value="enigma_no">Enigma(chno)</option>'+
		'<option value="enigma16_no">Enigma 1.6(chno)</option>'+
		'<option value="enigma_no(RTMP)">Enigma(RTMP/chno)</option>'+
		'<option value="enigma16_no(RTMP)">Enigma 1.6(RTMP/chno)</option>'+
		'<option value="m3u">m3u</option>'+
		'<option value="m3u_ts">m3u(MPEG TS)</option>'+
		'<option value="m3u_flv">m3u(FLV)</option>'+
		'<option value="m3u_no">m3u(chno)</option>'+
		'<option value="m3ue_no">m3u(chno with suffix)</option>'+
		'<option value="m3ue_name">m3u(chname with suffix)</option>'+
		'<option value="m3u_rtmp">m3u(RTMP)</option>'+
		'<option value="m3u8">m3u8</option>'+
		'<option value="octagon">octagon</option>'+
		'<option value="ariva">ariva</option>'+
		'<option value="xbmc">XBMC</option>'+
		'<option value="pure">Pure</option>'+
		'<option value="optumuss">Optumuss</option>'+
		'<option value="amiko">Amiko</option>'+
		'<option value="spark">Spark</option>'+
		'<option value="tiger">tiger</option>'+
		'<option value="Bluestar">Bluestar</option>'+
		'<option value="nstreamvod">nStreamVOD</option>'+
		'<option value="m3u_ott">OTT Player</option>'+
		'<option value="script_enigma">*Enigma Script*</option>'+
		'<option value="script_enigma16">*Enigma16 Script*</option>'+
		'<option value="script_mac_address">*MAC Address Script*</option>';
		HTML_str+='</select></font></td>';		
		                         
		HTML_str=HTML_str+'<td width="10%" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <select size="1" onchange="call_download_user_movielist('+i+','+'movielist'+i+')" name="movie_list" id=movielist'+i+'>'+
		'<option value="-1">--</option>'+
		'<option value="m3u">m3u (Movie)</option>'+
		'<option value="pure">Pure (Movie)</option>'+
		'<option value="ch_movie_m3u">m3u (Channel/Movie)</option>'+
		'<option value="Bluestar">Bluestar</option>'+
		'<option value="enigma">Enigma</option>'+
		'<option value="enigma16">Enigma 1.6</option>'+
		'<option value="nstreamvod">nStreamVOD</option>'+
 		'<option value="script_enigma">*Enigma Script*</option>'+
		'<option value="script_enigma16">*Enigma16 Script*</option>';
		HTML_str+='</select></font></td>';
		
		
	   	bexpired=0;
	 	pos=expired_time.indexOf('/');
	 	if (pos>0)
	 	{
			expired_MM=expired_time.substring(0,pos);
			expired_time_temp=expired_time.substring(pos+1);
			pos=expired_time_temp.indexOf('/');	
			expired_DD=expired_time_temp.substring(0,pos);
			expired_YY=expired_time_temp.substring(pos+1);
			//yearmsg=cur_year+'/'+cur_month+'/'+cur_day+'--'+expired_YY+'/'+expired_MM+'/'+expired_DD;
	   	    	//alert(yearmsg);
	
	   	    	if (cur_year<expired_YY)
	   	    	{
	   	    		bexpired=0;
	   	    	}else if (cur_year==expired_YY)
	   	    	{
		   	    	if (cur_month<expired_MM)
		   	    	{
		   	    		bexpired=0;
		   	    	}else if (cur_month==expired_MM)
		   	    	{	
			   	    	if (cur_day>expired_DD)
			   	    	{
			   	    		bexpired=1;
			   	    	}else
		   	    		{
		   	    			bexpired=0;
		   	    		}
		   	    	}else if (cur_month>expired_MM)
		   	    	{
		   	    		bexpired=1;
		   	    	}
		   	    	
	   	    	}else if (cur_year>expired_YY)
	    		{
	    			bexpired=1;
	    		}
    		}		
		if (bexpired==0)
		{	 		 		
		      HTML_str+='<td width="18%" align="center">'+
			' <font face="Arial"> <font size="2">'+
			' <input type="text" name="expired_time"'+
			' id=expired_time'+i+' size="12" value="'+
			expired_time+'"/></font></td>';		
		}else
		{
			
			HTML_str+='<td width="18%" align="center">'+
			' <font face="Arial"> <font size="2">'+
			' <input type="text" name="expired_time"  style="background:#ff0000"'+
			' id=expired_time'+i+' size="12" value="'+
			expired_time+'"/></font></td>';		
		
		}
		
		HTML_str+='<td width="10%" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <input type="text" name="userip"'+
		' id=userip'+i+' size="12" value="'+
		userip+'"/></font></td>';	 			
		
		HTML_str+='<td width="10%" align="center">'+
		' <font face="Arial"> <font size="2">'+
		' <input type="text" name="macid"'+
		' id=macid'+i+' size="12" value="'+
		macid+'"/></font></td>';	 			
		
		HTML_str+='<td id=reseller'+i+' width="10%" align="center">'+
		' <font face="Arial"> <font size="2">'+
		reseller+'</font></td>';	 			
		
		total_no++;
		if (m==userno)
		{
			
			 HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_User("'+i+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';

		      HTML_str+='<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_New_Multiple_User("'+i+'")>'+
	      	      ' <img border="0" id="addmultiplebutton" alt="Add Multiple Users" title="Add Multiple Users" src="add_multiple_icon.PNG"></a></td>';

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Update_User("'+i+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			if (username!="root")
			{
			      	HTML_str+='<td align="center">'+
			      "<a href='javascript:void(0)'"+
			      ' onclick=call_Del_User("'+i+'")>'+
			      ' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
			}
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_User_More("'+i+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td></tr>';

			i++;
			
			HTML_str+='<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
			      '<td width="20" align="center">'+
		 		' <input type="checkbox" name=checkbox'+i+
		 		' id=checkbox'+i+'></td>';
		      HTML_str=HTML_str+'<td width="10%" align="center"><font face="Arial" size="2">'+i+'</font></td>';
			//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
 			//{
			     HTML_str+='<td width="10%" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="username"'+
		 		' id=username'+i+' size="12"/></font></td>'+
	 		      '<td width="10%" align="center">'+
		 		'<font face="Arial" size="2">'+
		 		'<input type="text" name="password"'+
		 		'id=password'+i+' size="12"/></font></td>';
	 		/*}else if (g_user_authorization_mode==2)
 			{
			     HTML_str+='<td width="20%" align="center">'+
		 		' <font face="Arial" size="2">'+
		 		' <input type="text" name="username"'+
		 		' id=username'+i+' size="36"/></font></td>';
 			}
 			*/
	 			

		      HTML_str+='<td width="10%" align="center">'+
	 		'<font face="Arial" size="2">'+
			'<select size="1" name="group" id=group'+i+'>';
			
	 		for (j=0;j<g_total_group_no;j++)
	 		{
	 			groupname=g_groupname_array[j];
 				HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
	 		}
	  		HTML_str+='</select></font></td>';
	  		
	  		HTML_str=HTML_str+'<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1">'+
 			'<option value="-1">--</option>'+
			'<option value="enigma">Enigma</option>'+
			'<option value="enigma16">Enigma 1.6</option>'+
			'<option value="enigma(RTMP)">Enigma(RTMP)</option>'+
			'<option value="enigma16(RTMP)">Enigma 1.6(RTMP)</option>'+
			'<option value="enigma_no">Enigma(chno)</option>'+
			'<option value="enigma16_no">Enigma 1.6(chno)</option>'+
			'<option value="enigma_no(RTMP)">Enigma(RTMP/chno)</option>'+
			'<option value="enigma16_no(RTMP)">Enigma 1.6(RTMP/chno)</option>'+
			'<option value="m3u">m3u</option>'+
			'<option value="m3u_ts">m3u(MPEG TS)</option>'+
			'<option value="m3u_flv">m3u(FLV)</option>'+
			'<option value="m3u_no">m3u(chno)</option>'+
			'<option value="m3ue_no">m3u(chno with suffix)</option>'+
			'<option value="m3ue_name">m3u(chname with suffix)</option>'+
			'<option value="m3u_rtmp">m3u(RTMP)</option>'+
			'<option value="m3u8">m3u8</option>'+
 			'<option value="octagon">octagon</option>'+
			'<option value="ariva">ariva</option>'+
 			'<option value="xbmc">XBMC</option>'+
 			'<option value="pure">Pure</option>'+
			'<option value="optumuss">Optumuss</option>'+
			'<option value="amiko">Amiko</option>'+
			'<option value="spark">Spark</option>'+
			'<option value="tiger">Tiger</option>'+
			'<option value="Bluestar">Bluestar</option>'+
			'<option value="nstreamvod">nStreamVOD</option>'+
 			'<option value="m3u_ott">OTT Player</option>'+
			'<option value="script_enigma">*Enigma Script*</option>'+
			'<option value="script_enigma16">*Enigma16 Script*</option>'+
			'<option value="script_mac_address">*MAC Address Script*</option>';
	  		HTML_str+='</select></font></td>';
	 		 		
	  		HTML_str=HTML_str+'<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1">'+
 			'<option value="-1">--</option>'+
			'<option value="m3u">m3u (Movie)</option>'+
			'<option value="pure">Pure (Movie)</option>'+
			'<option value="ch_movie_m3u">m3u (Channel/Movie)</option>'+
			'<option value="Bluestar">Bluestar</option>'+
			'<option value="enigma">Enigma</option>'+
			'<option value="enigma16">Enigma 1.6</option>'+
 			'<option value="nstreamvod">nStreamVOD</option>'+
 			'<option value="script_enigma">*Enigma Script*</option>'+
			'<option value="script_enigma16">*Enigma16 Script*</option>';
	  		HTML_str+='</select></font></td>';

		      HTML_str+='<td width="18%" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="expired_time"'+
	 		' id=expired_time'+i+' size="12"/></font></td>'; 		

		      HTML_str+='<td width="10%" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="userip"'+
	 		' id=userip'+i+' size="12"/></font></td>';

		      HTML_str+='<td width="10%" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="macid"'+
	 		' id=macid'+i+' size="12"/></font></td>';

		      HTML_str+='<td id=reseller'+i+' align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>';
	 		
		      
		       HTML_str+='<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_User("'+i+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	      	      	      
		      '<td id=copy_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+

		      '<td id=save_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>'+
	      	      
		      '<td id=del_id_button width="80" align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_User()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+

		      '<td id=more_id_button align="center">'+		      
		      ' <font face="Arial" size="2"></font></a></td>';
		      
		      
	      	}else
		{	  
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Add_New_User("'+i+'")>'+
			' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>';

		      HTML_str+='<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_New_Multiple_User("'+i+'")>'+
	      	      ' <img border="0" id="addmultiplebutton" alt="Add Multiple Users" title="Add Multiple Users" src="add_multiple_icon.PNG"></a></td>';
	      	      

			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Update_User("'+i+'")>'+
			' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
			if (username!="root")
			{
			      	HTML_str+='<td align="center">'+
			      "<a href='javascript:void(0)'"+
			      ' onclick=call_Del_User("'+i+'")>'+
			      ' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
			}
			
			HTML_str+='<td align="center">'+
			"<a href='javascript:void(0)'"+
			' onclick=call_Query_User_More("'+i+'")>'+
			' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>';

		}
		HTML_str+='</tr>';
				
	}
	HTML_str=HTML_str+'</table>';
       //  alert(user_list_info.innerHTML);
      // alert(HTML_str);
  	menustr1='<table width=100%><tr>';
/* 		if (g_show_free_version==1)
		{
			menustr1+='<td><font face="Arial" size="2">Cut</font>'+'&nbsp&nbsp&nbsp'+
	 	      '<font face="Arial" size="2">Copy</font>'+'&nbsp&nbsp&nbsp'+
	 	      '<font face="Arial" size="2">Paste</font>'+'&nbsp&nbsp&nbsp';
		}else
		{
			menustr1+="<td> <a href='javascript:void(0)' onclick=callezserver_cut_selected_user()>"+
	 	      '<font face="Arial" size="2">Cut</font></a>'+'&nbsp&nbsp&nbsp'+
	 	      "<a href='javascript:void(0)' onclick=callezserver_copy_selected_user()>"+
	 	      '<font face="Arial" size="2">Copy</font></a>'+'&nbsp&nbsp&nbsp'+
	 	      "<a href='javascript:void(0)' onclick=callezserver_paste_selected_user()>"+
	 	      '<font face="Arial" size="2">Paste</font></a>'+'&nbsp&nbsp&nbsp';
		}
			
		
	      menustr1+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_user()>"+
 	      '<font face="Arial" size="2">Delete</font></a>'+'&nbsp&nbsp&nbsp'+
	      //"<a href='javascript:void(0)' onclick=call_export_user_profile()>"+
	      //'<font face="Arial" size="2">Export</font></a>'+'&nbsp&nbsp&nbsp'+
	      '</td><td><font face="Arial" size="2"> <input name="user_search_field" id="user_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_user();" name="search_user" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(3);" name="goto_user_no" /></font>'+	   
	   '</td></tr>'+
	      '</table>';
	      */
      	      menustr1+='<td width=55%"></td>'+'<td width=45%>'+
 	      //'<Input type="button" value="Export" onclick="javascript:call_export_user_profile();" />'+
 	      '<input type="button" value="Delete" onclick="javascript:callezserver_delete_selected_user();" />'+
	      '<input name="user_search_field" id="user_search_field" size="20" value="'+g_search_text+'"/></font><font face="Arial">'+
	   '<input type="button" value="Search" onclick="javascript:callServer_search_user();" name="search_user" />'+
	   '</td></tr>'+
	      '</table>';

      	//content.innerHTML=menustr1+HTML_str;
	if (total_count==0)
	{
		current_position=0;
		endposition=0;
	}else
	{
		endposition=current_position+total_no-1;
	}
//	menustr2='<table width=100%><tr><td>'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of '+total_count+' users</td>';
	menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
	menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' users</td>';
	position=1;
	limit=g_constant_limit;
	if (total_count>g_constant_limit)
	{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input type="button" value="First" onclick="javascript:call_get_first_user('+position+','+limit+')"; /></font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input type="button" disabled value="Previous" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" value="Previous" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{			
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}
				}
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="background-color:#ff0000" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" value="Next" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input type="button" disabled value="Next" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input type="button" value="Last" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
		menustr2+='</td></tr></table>';
	}else
	{
		menustr2+='<td>';
	}
      	content.innerHTML=menustr1+HTML_str+menustr2;
      	//alert(content.innerHTML);

}
function Del_User_Info() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    	g_user_no--;
    	alert("Delete User Sucessfully");
    } else if (response==2)
    {
     	alert("Disk is error(FULL), Please contact administrator");  	
    } else if (response==0)
    {
   	alert("Failed to Delete User");
    }
    g_search_text="";
    call_get_users(g_user_position,g_user_limit);
  }
}

/*
function call_Del_User(user_no)
{
 var username_id="username"+user_no; 
 var username;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
 
	g_item=document.getElementById(username_id);
	username=g_item.value;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Delete User: "+username+" Information?";
// cgi_url = "/server/del_user?token="+encodeURI(g_token)+"&user_no="+encodeURI(user_no)+"&username="+encodeURI(username)+"&flag="+Math.random();
 cgi_url = "/server/del_user?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_User_Info;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	 g_item.value=g_item.value+" (del...)";
	g_item.style.backgroundColor = "#ff0000";
 }
 

}
*/
function call_Del_User(username)
{
	var confirm_msg;
 	var cgi_url;
   	g_token=find_cookie_value("token");

 confirm_msg="Delete "+username+"?";
 cgi_url = "/server/del_user?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_User_Info;
	 xmlHttp.send(null);
 }
 

}

//function callServer_Save_More(user_no,username)
function callServer_Save_More()
{

   var rating_password_id="more_rating_password";
   var user2ndip_id="more_user2ndip";
   var user3rdip_id="more_user3rdip";
   var user4thip_id="more_user4thip";
   var user5thip_id="more_user5thip";
   var level_id="more_level";
   var max_connection_id="more_max_connection";
   //var paymodel_id="paymodel";
   //var user_point_id="user_point";
   var isp_lock_id="more_isp_lock";
   var smart_phone_id="more_smart_phone";
   var tablet_id="more_tablet";
   var desktop_id="more_desktop";
   var tv_id="more_tv";
   var first_name_id="more_first_name";
   var last_name_id="more_last_name";
   var address_id="more_address";
   var city_id="more_city";
   var zip_id="more_zip";
   var tel_id="more_tel";
   var email_id="more_email";
   
   var user2ndip;
   var user3rdip;
   var user4thip;
   var user5thip;

   var rating_password;
   var level;
   var max_connection;
   var paymodel;
   var user_point;
   var isp_lock;
   var smart_phone;
   var tablet;
   var desktop;
   var tv;
   var first_name;
   var last_name;
   var address;
   var city;
   var zip;
   var tel;
   var email;
 

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
	username=document.getElementById("more_username").innerText;
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		if (username == "root")
		{
			alert("Only for Formal version");
			return;
		}
	}	


	//alert(username);
	g_item=document.getElementById(user2ndip_id);
	user2ndip=g_item.value;
	
	g_item=document.getElementById(user3rdip_id);
	user3rdip=g_item.value;
	
	g_item=document.getElementById(user4thip_id);
	user4thip=g_item.value;
	
	g_item=document.getElementById(user5thip_id);
	user5thip=g_item.value;

	g_item=document.getElementById(rating_password_id);
	rating_password=g_item.value;

	g_item=document.getElementById(level_id);
	level=g_item.value;
	
	g_item=document.getElementById(max_connection_id);
	max_connection=g_item.value;

	//g_item=document.getElementById(paymodel_id);
	//paymodel=g_item.value;

	//g_item=document.getElementById(user_point_id);
	//user_point=g_item.value;

	g_item=document.getElementById(isp_lock_id);
	isp_lock=g_item.value;

	g_item=document.getElementById(smart_phone_id);
//	alert(g_item);
	smart_phone=g_item.value;
	
	g_item=document.getElementById(tablet_id);
	tablet=g_item.value;
//	g_item=document.getElementById(desktop_id);
//	desktop=g_item.value;
//	g_item=document.getElementById(tv_id);
//	tv=g_item.value;
	g_item=document.getElementById(first_name_id);
	first_name=g_item.value;
	g_item=document.getElementById(last_name_id);
	last_name=g_item.value;
	g_item=document.getElementById(address_id);
	address=g_item.value;
	g_item=document.getElementById(city_id);
	city=g_item.value;
	g_item=document.getElementById(zip_id);
	zip=g_item.value;
	g_item=document.getElementById(tel_id);
	tel=g_item.value;
	g_item=document.getElementById(email_id);
	email=g_item.value;

   	g_token=find_cookie_value("token");

 confirm_msg="Save User: "+username+" Information?";
 cgi_url = "/server/save_user_more?token="+encodeURI(g_token)+"&username="+encodeURI(username)+
  "&user2ndip="+user2ndip+
  "&user3rdip="+user3rdip+
  "&user4thip="+user4thip+
  "&user5thip="+user5thip+
  "&rating_password="+rating_password+
  "&level="+level+
  "&max_connection="+max_connection+
  "&paymodel="+paymodel+
  "&user_point="+user_point+
  "&isp_lock="+isp_lock+
  "&smart_phone="+smart_phone+
  "&tablet="+tablet+
  "&desktop="+desktop+
  "&tv="+tv+
  "&first_name="+first_name+
  "&last_name="+last_name+
  "&address="+address+
  "&city="+city+
  "&zip="+zip+
  "&tel="+tel+
  "&email="+email+
   "&flag="+Math.random();
 //  alert(cgi_url);
 //if (confirm(confirm_msg))
 //{

	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() {
	 	if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
		    if (response==1)
		    {
		    	//alert("Save User More Sucessfully");
		    	//close_more_user_modal();
		    	var updated_date=new Date();
		    	var save_user_dialog_message=document.getElementById("save_user_dialog_message");
			save_user_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial"><b>'+String(updated_date.getHours()).padStart(2, "0")+":"+String(updated_date.getMinutes()).padStart(2, "0")+":"+String(updated_date.getSeconds()).padStart(2, "0")+' Updated</b></font>';

		    } else if (response==2)
		    {
		    	alert("Disk is error(FULL), Please contact administrator");
		    } else if (response==0)
		    {
		   	alert("Failed to Save User More");
		    }
		  }
	 };
	 xmlHttp.send(null);

 //}


}
function Query_User_More() {
   var str;
   var i;
   var username;
   var user2ndip;
   var user3rdip;
   var user4thip;
   var user5thip;
   var level;
   var max_connection;
   var cur_connection;
   var rating_password;
   var paymodel;
   var paymodel_option;
   var user_point;
   var isp_lock;
   var isp_name;
   var smart_phone;
   var tablet;
   var desktop;
   var tv;
   var first_name;
   var last_name;
   var address;
   var city;
   var zip;
   var tel;
   var email;
   var UserDetailWindow
   	var prev_user_no;
	var next_user_no;
	var total_user_no;
	var nObj;

   // var detail = parent.document.getElementById("detail");
	

	// detail.innerHTML="";

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText.split("\r\n");
     str="<head><title>EZserver Subscriber</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body><table align="center">';
  //   str='';
 //		alert(response[0]);
 		i=0;
	 	strlength=response[i].length;
   	    	username=response[i].slice(9,strlength);
   	    	
   	    	document.getElementById("more_username").innerHTML='<font face="Arial" size="5"><b>'+username+'</b></font>';
  	    	//document.getElementById("more_username").value=username;
   	    	i++;
    	 	strlength=response[i].length;
   	    	user2ndip=response[i].slice(10,strlength);
  	    	document.getElementById("more_user2ndip").value=user2ndip;
  	    	i++;
  	    	//alert(response[i]);
    	 	strlength=response[i].length;
   	    	user3rdip=response[i].slice(10,strlength);
  	    	document.getElementById("more_user3rdip").value=user3rdip;
  	    	
  	    	i++;
    	 	strlength=response[i].length;
   	    	user4thip=response[i].slice(10,strlength);
     	    	document.getElementById("more_user4thip").value=user4thip;
	    	
  	    	i++;
  	    	//alert(response[i]);
    	 	strlength=response[i].length;
   	    	user5thip=response[i].slice(10,strlength);
     	    	document.getElementById("more_user5thip").value=user5thip;

  	    	i++;
    	 	strlength=response[i].length;
   	    	rating_password=response[i].slice(16,strlength);
    	    	document.getElementById("more_rating_password").value=rating_password;

  	    	i++;
    	 	strlength=response[i].length;
   	    	level=response[i].slice(6,strlength);
    	    	document.getElementById("more_level").value=level;

 	    	i++;
    	 	strlength=response[i].length;
   	    	max_connection=response[i].slice(14,strlength);
   	    	document.getElementById("more_max_connection").value=max_connection;
   	    	if (g_Ezserver_Version==BALANCER)
		{
			document.getElementById("more_max_connection").disabled=true;
		}
  
 	    	i++;
    	 	strlength=response[i].length;
   	    	cur_connection=response[i].slice(14,strlength);
   	    	document.getElementById("more_active_connection").innerText=cur_connection;
 
		i++;

	    	
   	    	i++;
   	    	i++;
  	    	strlength=response[i].length;
   	    	isp_lock=response[i].slice(9,strlength);
   	    	i++;
 
		if (isp_lock=="OFF")
 		{
  	    		document.getElementById("more_isp_lock").value=isp_lock;
		}else if (isp_lock=="ON")
 		{
	 	 	strlength=response[i].length;
	   	    	isp_name=response[i].slice(9,strlength);
	   	    	document.getElementById("more_isp_lock").value=isp_name;
	   	    	
		}
     	    	i++;
     	    	//alert(response[i]);
	 	strlength=response[i].length;
 	    	smart_phone=response[i].slice(12,strlength);
  	    	document.getElementById("more_smart_phone").value=smart_phone;
  	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	tablet=response[i].slice(7,strlength);
  	    	document.getElementById("more_tablet").value=tablet;
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	desktop=response[i].slice(8,strlength);
  	    //	document.getElementById("more_desktop").value=desktop;
   	    	
   	    	i++;
     	 	strlength=response[i].length;
   	    	tv=response[i].slice(3,strlength);
  	    //	document.getElementById("more_tv").value=tv;
   	    	
   	    	i++;
    	 	strlength=response[i].length;
   	    	first_name=response[i].slice(11,strlength);
  	    	document.getElementById("more_first_name").value=first_name;
   	    	
   	    	i++;
    	 	strlength=response[i].length;
   	    	last_name=response[i].slice(10,strlength);
  	    	document.getElementById("more_last_name").value=last_name;
   	    	
   	    	i++;
    	 	strlength=response[i].length;
   	    	address=response[i].slice(8,strlength);
  	    	document.getElementById("more_address").value=address;
   	    	
   	    	i++;
    	 	strlength=response[i].length;
   	    	city=response[i].slice(5,strlength);
  	    	document.getElementById("more_city").value=city;
   	    	
   	    	i++;
    	 	strlength=response[i].length;
   	    	zip=response[i].slice(4,strlength);
  	    	document.getElementById("more_zip").value=zip;
   	    	 	    	
   	    	i++;
   	 	strlength=response[i].length;
   	    	tel=response[i].slice(4,strlength);
  	    	document.getElementById("more_tel").value=tel;
   	    	
   	    	i++;
   	 	strlength=response[i].length;
   	    	email=response[i].slice(6,strlength);
  	    	document.getElementById("more_email").value=email;
 
  		
  	/*	if (window.self.name=="UserDetailWindow")
   		{
   			nObj=window.self.document.getElementById("total_user_no");
   			//alert(nObj);
   			//alert(nObj.innerText);
   			
   			total_user_no=parseInt(nObj.innerText);
   			//alert(total_user_no);
   		}else
   		{
   			total_user_no=g_user_no;
   		}
   		*/
   		total_user_no=g_user_no;
//  		str+='<tr><td><font face="Arial"> <font size="2">User : </font></td><td width="350" height="23"><table><tr><td><font face="Arial"> <font size="2"><b>'+username+'</b> - '+g_cur_userno+' /</font></td><td id=total_user_no> <font size="2">'+total_user_no+'</font></td></tr></table></td></tr>';
 		
   	/*if (window.self.name=="UserDetailWindow")
   	{
   		window.self.document.body.innerHTML=str;
   	}else
   	{
   		if (g_UserDetailWindow && !g_UserDetailWindow.closed)
   		{
   			g_UserDetailWindow.focus();
   		}else
   		{
	  		UserDetailWindow= window.open("", "UserDetailWindow", "top=100, left=200, width=600, height=650"); 
	 		UserDetailWindow.document.write(str);
	 		g_UserDetailWindow=UserDetailWindow;
 		}
   	}
   	*/
  			

  }
}

function call_Query_User_More(user_no)
{
 //var username_id="username";
 var username;

var confirm_msg;
 	var cgi_url;
	var cookieStr;

    	var save_user_dialog_message=document.getElementById("save_user_dialog_message");
	save_user_dialog_message.innerHTML='';


	//g_item=document.getElementById(username_id);
	username=g_username;
	//g_username=username;
	g_cur_userno=user_no;
	//alert(g_cur_userno);
	//g_user_no=user_no;
	
   	g_token=find_cookie_value("token");

// confirm_msg="Get User: "+username+" more Information?";
 cgi_url = "/server/query_user_more?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 = Query_User_More;
	 xmlHttp.send(null);
 //}
 

}
function call_Query_User_More_by_UserNo(user_no)
{
 	var cgi_url;
	g_cur_userno=user_no;
	//alert(g_cur_userno);
	
   	g_token=find_cookie_value("token");

 cgi_url = "/server/query_user_more?token="+encodeURI(g_token)+"&user_no="+user_no+"&flag="+Math.random();
  // alert(cgi_url);
// if (confirm(confirm_msg))
// {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Query_User_More;
	 xmlHttp.send(null);
 //}
 

}
function Stop_User_Connections() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    	alert("Stop connections");
    } else if (response==0)
    {
   	alert("Failed to Stop connections");
    }
    }
}
function call_stop_user_connections(username,conno)
{
 //var username_id="username"+user_no; 
 //var username;

var confirm_msg;
 	var cgi_url;
	var cookieStr;

 
	//g_item=document.getElementById(username_id);
	//alert(g_item);
	//username=g_item.value;
	g_username=username;
//	alert(g_username);
	//g_user_no=user_no;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Stop User("+username+") "+conno+" connections?";
 cgi_url = "/server/stop_user_connections?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 = Stop_User_Connections;
	 xmlHttp.send(null);
}
 

}
function Update_User_Info() {

 
}

//function call_Update_User(user_no,username,szpassword,expired_time,paymodel,user_point)
function call_Update_User(user_no)
{
 var username_id="username"+user_no; 
 var password_id="password"+user_no; 
 var group_id="group"+user_no; 
 var expired_time_id="expired_time"+user_no; 
 //var paymodel_id="paymodel"+user_no; 
 //var user_point_id="user_point"+user_no;
 var userip_id="userip"+user_no;
 var macid_id="macid"+user_no;

 var szpassword;
 var szgroup;
 var expired_time;
 //var paymodel;
 //var user_point;
 var username;
 var userip;
 var macid;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 var d=new Date();
 var cur_year=d.getFullYear();
 var cur_month=d.getMonth()+1;
 var cur_date=d.getDate();
 var alert_message;
 
	g_item=document.getElementById(macid_id);
	macid=g_item.value;

	g_item=document.getElementById(username_id);
	username=g_item.value;
	if (username.length==0)
	{
		alert("User name is empty");
		return;
	}
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		if (username == "root")
		{
			alert("Only for Formal version");
			return;
		}
	}	
	g_item=document.getElementById(expired_time_id);
	expired_time=g_item.value;
	if (expired_time.length==0)
	{
		alert("Expired Time is empty");
		return;
	}else if (expired_time.length>10)
	{
		alert("Date Length is too long(>10)");
		return;
	}
	
	//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	 //{
		g_item=document.getElementById(password_id);
		szpassword=g_item.value;
		if (szpassword.length==0)
		{
			if (!((macid=="mag") || (macid=="android") || (macid=="activecode")))
			{
				alert("Pawword is empty");
				return;
			}
			
		}

		pos=expired_time.indexOf('/');
		if (pos>0)
		{
			expired_MM=expired_time.substring(0,pos);
			expired_time_temp=expired_time.substring(pos+1);
			pos=expired_time_temp.indexOf('/');	
			expired_DD=expired_time_temp.substring(0,pos);
			expired_YY=expired_time_temp.substring(pos+1);
			
				//	alert_message=cur_year+'/'+cur_month+'/'+cur_date+'--'+expired_YY+'/'+expired_MM+'/'+expired_DD;
		   	    	//alert(alert_message);
		
			if (expired_YY<cur_year)
			{
				alert_message="Expired Year should be >="+cur_year;
				alert(alert_message);
				return;
			}
			if ((expired_MM<1)||(expired_MM>12))
			{
				alert("Exipred Month should be between 1 and 12");
				return;
			}
			if ((expired_YY==cur_year)&&(expired_MM<cur_month))
			{
				alert_message="Expired Month should be >"+cur_month;
				alert(alert_message);
				return;
				
			}
			if ((expired_DD<1)||(expired_DD>31))
			{
				alert("Exipred Date should be between 1 and 30");
				return;
			}
			if ((expired_YY==cur_year)&&(expired_MM==cur_month)&&(expired_DD<cur_date))
			{
				alert_message="Expired Date should be >"+cur_date;
				alert(alert_message);
				return;
			}
		}		
		
	/*}else if (g_user_authorization_mode==2)
	{
		szpassword=null;
	}
	*/
		


	
	g_item=document.getElementById(group_id);
	szgroup=g_item.value;
//	alert(szgroup);
//	g_item=document.getElementById(paymodel_id);
//	paymodel=g_item.value;
//	g_item=document.getElementById(user_point_id);
//	user_point=g_item.value;
	g_item=document.getElementById(userip_id);
	userip=g_item.value;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Update User: "+username+" Information?";
// cgi_url = "/server/update_user?token="+encodeURI(g_token)+"&user_no="+encodeURI(user_no)+"&username="+encodeURI(username)+
 cgi_url = "/server/update_user?token="+encodeURI(g_token)+"&username="+encodeURI(username)+
  "&password="+szpassword+
  "&group="+szgroup+
  "&expired_time="+expired_time+
//  "&paymodel="+paymodel+
//  "&user_point="+user_point+
  "&userip="+userip+
  "&macid="+macid+
   "&flag="+Math.random();
  // alert(cgi_url);

	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
		 if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
		    if (response==1)
		    {
		    	
		    } else if (response==2)
		    {
		    	alert("Disk is error(FULL), Please contact administrator");
		    } else if (response==0)
		    {
		   	alert("Failed to Update User");
		    }else if (response==3)
		    {
		   	alert("Primay Key can not be changed");
			call_get_all_user();
		    } else if (response==4)
		    {
		  	alert("Password does not allow the special character ':'");
		    }
			g_item.value=g_temp;
			g_item.style.backgroundColor = "#ffffff";
		    }	 	
	 };
	 xmlHttp.send(null);
	 g_item=document.getElementById(expired_time_id);
	 g_temp=g_item.value;
	 //g_item.value=g_item.value+" (updating...)";
	g_item.style.backgroundColor = "#ff0000";

 

}


//function call_get_all_user() {
function call_get_all_user_detail() {
 

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;

   var content = parent.document.getElementById("content");
 	
	content.innerHTML="";

  	
  	g_token=find_cookie_value("token");
 cgi_url = "/server/query_all_user?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">User Information Loading...<p>';

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

}
function call_get_users_detail() {
 

	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	

  // var content = parent.document.getElementById("content");
 	
	// content.innerHTML="";

  	
  	g_token=find_cookie_value("token");
  	if (g_expired_user==0)
  	{
 		cgi_url = "/server/get_users?token="+encodeURI(g_token)+"&position="+g_user_position+"&1imit="+g_user_limit+"&flag="+Math.random();
 	}else if (g_expired_user==1)
 	{
		cgi_url = "/server/get_users?token="+encodeURI(g_token)+"&position="+g_user_position+"&1imit="+g_user_limit+"&expired=1"+"&flag="+Math.random();
 	}
// content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">User Information Loading...<p>';

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

}
function user_authorization_mode()
{
if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	    g_user_authorization_mode=response;
	    
	    callServer_System_Inquery();
	    

    }
}

function call_user_authorization_mode() {
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
  	
  	g_token=find_cookie_value("token");

	 cgi_url = "/server/query_user_authorization?token="+encodeURI(g_token)+"&flag="+Math.random();
	  xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = user_authorization_mode;
	 xmlHttp.send(null);

}  

function call_get_all_user(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 = group_inquery_item;
		xmlHttp.send(null);
	}

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

}

function call_Add_Work_Folder()
{
 var add_work_folder_button=document.getElementById("add_work_folder_button");
 var add_folder_dialog_message=document.getElementById("add_folder_dialog_message");
 var servername; 
 var foldertype;
 var selectedpath="";
 var folder_enabled=0;;
var usernoitem;
var usernameitem;
var confirm_msg;
 	var cgi_url;
	var alert_message;

	
	servername=document.getElementById("selectedbl").value;;
	foldertype=document.getElementById("foldertype").value;;
	selectedpath=document.getElementById("selectedpath").value;;
	if (selectedpath.length==0)
	{
		alert("Selected Path is empty");
		return;
	}
	if (document.getElementById("folder_enabled").checked)
	{
		folder_enabled=1;
	}
 cgi_url = "/server/add_node_work_folder?token="+encodeURI(g_token)+"&server_name="+encodeURI(servername)+
 "&type="+encodeURI(foldertype)+
 "&directory="+encodeURI(selectedpath)+
 "&status="+encodeURI(folder_enabled)+
   "&flag="+Math.random();
 //  alert(cgi_url);

	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() 
	 {
		if (xmlHttp.readyState == 4) 
		{
		    var response = xmlHttp.responseText;
		    /* var item_add;
		    var item_save;
		    var item_del;
		    var item_more;
		    var item_top_total_no;
		    var bAddFlag=false;
		    var new_add_total_no;
		    */
		  //  var item_bottom_total_no;
		    if (response>0)
		    {
		    //	alert("Add User Sucessfully");
		  	/* g_folder_no++;
		  	if ((g_folder_position+g_constant_limit)<=g_folder_no)
			{
				if (((g_cur_folderno)%g_constant_limit)==1)
				{
					g_folder_position=parseInt(g_cur_folderno);
				}
				g_folder_limit=g_constant_limit;
			}else
			{
				g_folder_limit=g_folder_no%g_constant_limit;
				if (g_folder_limit==0) 
				{
					if (g_folder_no<g_folder_position)
					{
						g_folder_position=g_folder_no-g_constant_limit+1;
					}
					g_folder_limit=g_constant_limit;
				}
			}
			*/
			/*add_work_folder_button.value="Add Next";
			add_folder_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+selectedpath+' Added</font>';
			document.getElementById("selectedpath").value="";
			document.getElementById("selectedpath").focus();
			*/
			//alert(g_total_movie_no);
			//alert(response);
			if (foldertype == "Movie")
			{
				g_total_movie_no=g_total_movie_no+parseInt(response);
				//alert(g_total_movie_no);
			}else if (foldertype == "Series")
			{
				g_total_series_no=g_total_series_no+parseInt(response);
			}
			close_work_folder_modal();		 	
		    } else if (response==0)
		    {
		   	alert("Failed to Add Folder");		
		    } else if (response==2)
		    
		    {
		  	alert("The folder is already in Database");
		    }
		 }	 	
	 };	 	
	 xmlHttp.send(null);


}

function call_Update_Work_Folder()
{
 var update_work_folder_button=document.getElementById("update_work_folder_button");
 var update_folder_dialog_message=document.getElementById("update_folder_dialog_message");
 var servername; 
 var foldertype;
 var selectedpath="";
 var folder_enabled=0;;
var usernoitem;
var usernameitem;
 	var cgi_url;
	var alert_message;

	
	servername=document.getElementById("updateselectedbl").value;;
	foldertype=document.getElementById("updatefoldertype").value;;
	selectedpath=document.getElementById("updateselectedpath").value;;
	if (selectedpath.length==0)
	{
		alert("Selected Path is empty");
		return;
	}
	if (document.getElementById("updateenabled").checked)
	{
		folder_enabled=1;
	}
 cgi_url = "/server/update_node_work_folder?token="+encodeURI(g_token)+"&server_name="+encodeURI(servername)+
 "&type="+encodeURI(foldertype)+
 "&directory="+encodeURI(selectedpath)+
 "&status="+encodeURI(folder_enabled)+
   "&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() 
	 {
		if (xmlHttp.readyState == 4) 
		{
		    var response = xmlHttp.responseText;
		    if (response==1)
		    {
			update_folder_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+selectedpath+' Updated</font>'; 	
		    } else if (response==0)
		    {
		   	alert("Failed to Update Folder");		
		    }
		 }	 	
	 };	 	
	 xmlHttp.send(null);


}

function call_Del_Work_Folder(i)
{
	var cgi_url;
	var confirm_msg="Delete Work Folder?";
	
	if (confirm(confirm_msg))
	{	
	 cgi_url = "/server/delete_node_work_folder?token="+encodeURI(g_token)+"&server_name="+encodeURI(JSONWorkFolder.folder[i].server_name)+
	 "&type="+encodeURI(JSONWorkFolder.folder[i].type)+"&directory="+encodeURI(JSONWorkFolder.folder[i].directory)+
	   "&flag="+Math.random();
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = function() 
		 {
			if (xmlHttp.readyState == 4) 
			{
			    var response = xmlHttp.responseText;
			    if (response==1)
			    {
			    	callServer_get_work_folder(g_work_folder_position,g_work_folder_limit);
			    } else if (response==0)
			    {
			   	alert("Failed to Delete Folder");		
			    }
			 }	 	
		 };	 	
		 xmlHttp.send(null);
	 }


}

function call_Refresh_Work_Folder(i)
{
	var cgi_url;
	 cgi_url = "/server/refresh_node_work_folder?token="+encodeURI(g_token)+"&server_name="+encodeURI(JSONWorkFolder.folder[i].server_name)+
	 "&type="+encodeURI(JSONWorkFolder.folder[i].type)+"&directory="+encodeURI(JSONWorkFolder.folder[i].directory)+
	   "&flag="+Math.random();
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = function() 
		 {
			if (xmlHttp.readyState == 4) 
			{
			    var response = xmlHttp.responseText.split("\r\n");;
			   // if (response==1)
			   // {
			   	//alert(response[0]);
			   	//alert(response[1]);
			    	JSONWorkFolder.folder[i].last_run=response[0];
			    	callServer_get_work_folder(g_work_folder_position,g_work_folder_limit);
			    	if (JSONWorkFolder.folder[i].type == "Movie")
			    	{
			    		g_total_movie_no=g_total_movie_no+parseInt(response[1]);	
			    	}else if (JSONWorkFolder.folder[i].type == "Series")
			    	{
			    		g_total_series_no=g_total_series_no+parseInt(response[1]);
				}
			
			   //// } else if (response==0)
			    //{
			   //	alert("Failed to Refresh Folder");		
			   // }
			 }	 	
		 };	 	
		 xmlHttp.send(null);


}
function login_blockchain_server(serverip)
{
	var newurl='http://'+serverip+':'+window.location.port+'/';
	 window.location.href=newurl; 
}
function callServer_get_blockchain_nodes(position,limit) {
  	var cgi_url;
	var response;
	var i;
	
   	g_token=find_cookie_value("token");
	g_blockchain_nodes_position=position;
	g_blockchain_nodes_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		cgi_url = "/server/get_blockchain_nodes?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function ()
		 {
		 	if (xmlHttp.readyState == xmlHttp.HEADERS_RECEIVED) {
		 		
		 	}else if (xmlHttp.readyState == xmlHttp.LOADING) {
		 		response = xmlHttp.responseText;
		 		
		    	}else if (xmlHttp.readyState == xmlHttp.DONE) {	
		    		JSONBlockchain= JSON.parse(response);
		    		var menustr1;
				var menustr2;
				var endposition;
				var position;
				var limit;
				var curren_sequence_no;
				var total_sequence;
				var start_sequence_no;
				var current_position=g_blockchain_nodes_position;
				var total_count=0;
				var index_no;
				var ezcontent= document.getElementById("content");
				var cellsize="15%";
				var total_no=0;
				var NodeType;

			
				ezcontent.innerHTML='<div id="ezmenucontent"></div>';
				var content;
				g_start_search_option=1;
				
				var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
				str+='<tr>'
				var action_width="70%";
				if (bMobileDevice)
				{
					action_width="10%";
				}
				str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Nodes</b></font>';
				str+='</td>';
			
				/*
				str+='<td>';
				if ((g_search_text.length==0)|| g_SearchInput.value=='Search Users...')
				{
				  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Users..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
				}else
				{
				  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
				}
				str+='</td>';
				*/
				
				str += '<td>' +
			       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
			       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
			       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
			       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
			       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
			       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
			       '</select>' +
			       '</td>';
				
				str+='<td>';
				str+='<div class="navbar" style="background-color: #F5F6F8">';
				/*	str+='<div id=blockchain_sync_btn class="menudropdown"  style="background-color: #E26498">';
					    str+='<a href="javascript:sync_blockchain_nodes()">Sync Nodes</a>';
					    str+='</button>';
					str+='</div>'; 
					*/
					str+='<div id=blockchain_refresh_btn class="menudropdown"  style="background-color: #E26498">';
					    str+='<button class="dropbtn" onclick="Refresh_Server_blockchain()">'; 
					    str+='<i class="fa fa-refresh"></i>';
					    str+='</button>';
					str+='</div>'; 
					
				str+='</td>';
				
				
				
				
				str+='</tr>';
				str+='</table>';
				//alert(str);
				
				//str='<font size=4>Users</font>';
				document.getElementById("ezhead").innerHTML=str;
				//parent.document.getElementById("page_no").value=g_constant_limit;
			
				
				 
				//g_search_user_item.value=null;
				content = parent.document.getElementById("ezmenucontent");
				HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">';
			        HTML_str+='<tr>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">No.</font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Type</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>IP</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Region</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Group ID</b></font></td>';
				HTML_str+='</tr>';
				
				HTML_str+='<tr><td  colspan="5"><hr size="1" color="#66FFFF"></td></tr>';
				total_count=JSONBlockchain.nodes.length;    
				
			 	index_no=current_position;
			 	for (i=0;i<JSONBlockchain.nodes.length;i++)
			    	{
			    		
			    		HTML_str+='<tr>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+index_no+'</font></td>';
			 		if (JSONBlockchain.nodes[i].type==0)
			 		{
			 			NodeType="User Server";
			 		}else if (JSONBlockchain.nodes[i].type==1)
			 		{
			 			NodeType="Content Server";
			 		}else if (JSONBlockchain.nodes[i].type==2)
			 		{
			 			NodeType="Reverse Proxy Server";
			 		}else if (JSONBlockchain.nodes[i].type==3)
			 		{
			 			NodeType="Proxy Server";
			 		}else if (JSONBlockchain.nodes[i].type==4)
			 		{
			 			NodeType="Player";
			 		}
			  		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+NodeType+'</font></td>';
			  		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONBlockchain.nodes[i].ip+'</font></td>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONBlockchain.nodes[i].region+'</font></td>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONBlockchain.nodes[i].group+'</font></td>';
					HTML_str+='<td width="14%"  align="center"><div>'+"<a href='javascript:void(0)'"+' onclick=login_blockchain_server("'+JSONBlockchain.nodes[i].ip+'")><img src="/admin/login.png"></img></a></td>';				
					HTML_str+='</tr>';
			    		total_no++;
					index_no++;
			
				}
			
			  
			        HTML_str=HTML_str+'</table>';
			        
			        menustr1="";
				/*
				menustr1='<table width=50%><tr>';
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelEditBlockchainNodeModal" class="modal">'+
						'<div class="modal-content">';
						menustr1+='<table  align="center"  cellpadding="5"  cellspacing="7">';
						menustr1+='<tr>'+
						'<td align=left><font face="Arial" size="6"><b>New Folder</b></font></td><td align=right id=add_folder_dialog_message name=add_folder_dialog_message></td></tr>';
			 		
				 		menustr1+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';
			
						
						
						menustr1+='<tr><td width="50%"><font face="Arial" size="2">Folder Type</font></td><td width="50%">'+
				 		' <select style="text-indent: 5;width:100%;height:26;" size="1" name="foldertype" id=foldertype>';
						menustr1+='<option  style="padding: 2px" selected="selected" value="'+"Series"+'">'+"Series"+'</option>';
						menustr1+='<option  style="padding: 2px"  value="'+"Movie"+'">'+"Movie"+'</option>';
						menustr1+='</select></font></td></tr>';
						
						menustr1+='<tr><td width="50%"><font face="Arial" font size="2">Selected path</font></td><td width="50%">'+
							 	' <font face="Arial" size="2">'+
							 	' <input style="text-indent: 5;height:26;" type="text" name="selectedpath"'+
							 	' id=selectedpath'+
							 	' size="50"/'+
							 	'</font></td></tr>';
						menustr1+='<tr><td width="50%" height="23">'+
						'<p align="left" ><font face="Arial" size="2">Enabled</font>'+
						'</p>'+
						'</td>'+      
						'<td height="23"><p align="left">'+
						'<label class="switch"><input type="checkbox" checked id="folder_enabled"><span class="slider round"></span></label>'+
						'</td></tr>';
						
						menustr1+='<tr><td><input id=add_blockchain_node_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Sync" onclick=call_Sync_blockchain_node() name="Sync" /></td>'+
						'<td align=right ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_blockchain_node_modal() name="Cancel" /></td></tr>';
						menustr1+='</table></div>'+
					'</div></td>';	
				menustr1+='</tr></table>';	
				*/     	
				
				if (total_count==0)
				{
					current_position=0;
					endposition=0;
				}else
				{
					endposition=current_position+total_no-1;
				}
				menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
				menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' nodes</td>';
				position=1;
				limit=g_constant_limit;
				
				if (total_count>g_constant_limit)
				{
					menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:call_get_first_user('+position+','+limit+')"; /> </font>';
				
					if (current_position-g_constant_limit<0)
					{
							
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						position=current_position-g_constant_limit;
						if ((position+g_constant_limit)<=total_count)
						{
							limit=g_constant_limit;
						}else
						{
							limit=total_count%g_constant_limit;
							if (limit==0) limit=g_constant_limit;
						}
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
					// user sequence
					total_sequence=Math.floor(total_count/g_constant_limit);
					//alert(total_sequence);
					if ((total_count%g_constant_limit) > 0)
					{
						total_sequence++;
					}
					
					curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
					//alert(curren_sequence_no);
					if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
					{
						start_sequence_no=total_sequence-g_sequence_constant_limit;
					}else
					{
						start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
					}
					//alert(start_sequence_no);
					if (start_sequence_no<=0) start_sequence_no=1;
					//if (total_sequence<g_sequence_constant_limit)
					//{
					//	start_sequence_no=1;
					//}
					for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
					{
						if (j>=total_sequence)
						{
							position=i;
							limit=total_count%g_constant_limit;
							
							if (limit==0) limit=g_constant_limit;
							if (j<10)
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}else
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}
							//menustr2+='</td>';
							break;
						}
						if (k<=g_sequence_constant_limit)
						{
							position=i;
							limit=g_constant_limit;
							if (j<10)
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}else
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}
							i+=g_constant_limit;
						}else
						{
							//menustr2+='</td>';
							break;
						}
						
						
					}
					if (endposition+1<=total_count)
					{
						position=endposition+1;
						if ((position+g_constant_limit)<=total_count)
						{
							limit=g_constant_limit;
						}else
						{
							limit=total_count%g_constant_limit;
							if (limit==0) limit=g_constant_limit;
						}
						menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
					if ((total_count%g_constant_limit)==0)
					{
						position=total_count-g_constant_limit+1;
						limit=g_constant_limit;
					}else
					{
						position=total_count-(total_count%g_constant_limit)+1;
						limit=total_count%g_constant_limit;
						if (limit==0) limit=g_constant_limit;
					}
					menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
				}else
				{
					menustr2+='<td>';
				}
				menustr2+='</td></tr></table>';
				
			      	content.innerHTML=menustr1+HTML_str+menustr2;
			     	g_SearchInput = document.getElementById("search_field");
			     	if (g_search_text.length>0)
			     	{
			     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
			     		g_SearchInput.focus();
			     	}
 			}	
		 };
		xmlHttp.send(null);
	}

}
function callServer_get_work_folder(position,limit) {
  	var cgi_url;
	var response;
	var i;
	
   	g_token=find_cookie_value("token");
	g_work_folder_position=position;
	g_work_folder_limit=limit;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
	if (g_token!=0)
	{
		cgi_url = "/server/get_work_folder?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function ()
		 {
		 	if (xmlHttp.readyState == xmlHttp.HEADERS_RECEIVED) {
		 		
		 	}else if (xmlHttp.readyState == xmlHttp.LOADING) {
		 		response = xmlHttp.responseText;
		 		
		    	}else if (xmlHttp.readyState == xmlHttp.DONE) {	
		    		JSONWorkFolder= JSON.parse(response);
		    		var menustr1;
				var menustr2;
				var endposition;
				var position;
				var limit;
				var curren_sequence_no;
				var total_sequence;
				var start_sequence_no;
				var current_position=g_work_folder_position;
				var total_count=0;
				var folder_no;
				var ezcontent= document.getElementById("content");
				var cellsize="15%";
				var total_no=0;

			
				ezcontent.innerHTML='<div id="ezmenucontent"></div>';
				var content;
				g_start_search_option=1;
				
				var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
				str+='<tr>'
				var action_width="50%";
				if (bMobileDevice)
				{
					action_width="10%";
				}
				str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Folder</b></font>';
				str+='</td>';
			
				str+='<td>';
				if ((g_search_text.length==0)|| g_SearchInput.value=='Search Users...')
				{
				  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Users..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
				}else
				{
				  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
				}
				str+='</td>';
				
				str += '<td>' +
			       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
			       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
			       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
			       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
			       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
			       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
			       '</select>' +
			       '</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_work_folder_modal()">Add Folder</a>';
				str+='</div>'; 		
					
				str+='</td>';
				
				
				str+='</tr>';
				str+='</table>';
				//alert(str);
				
				//str='<font size=4>Users</font>';
				document.getElementById("ezhead").innerHTML=str;
				//parent.document.getElementById("page_no").value=g_constant_limit;
			
				
				 
				g_search_user_item.value=null;
				content = parent.document.getElementById("ezmenucontent");
				HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
				  '<tr>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">NO#</font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>TYPE</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>SERVER NAME</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>DIRECTORY</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>LAST RUN</b></font></td>';
				HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>STATUS</b></font></td>';
				HTML_str+='</tr>'+'<tr><td  colspan="6"><hr size="1" color="#66FFFF"></td></tr>';
				total_count=JSONWorkFolder.total_count;     	
			 	folder_no=current_position;
			 	for (i=0;i<JSONWorkFolder.total_count;i++)
			    	{
			    		const dateObj = new Date(JSONWorkFolder.folder[i].last_run * 1000);
					const year = dateObj.getFullYear();
					const month = ("0" + (dateObj.getMonth() + 1)).slice(-2);
					const day = ("0" + dateObj.getDate()).slice(-2);
					const hour = ("0" + dateObj.getHours()).slice(-2);
					const minute = ("0" + dateObj.getMinutes()).slice(-2);
					const second = ("0" + dateObj.getSeconds()).slice(-2);
					const dateString = `${year}-${month}-${day} ${hour}:${minute}:${second}`;
					
			    		HTML_str+='<tr>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+folder_no+'</font></td>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONWorkFolder.folder[i].type+'</font></td>';
			  		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONWorkFolder.folder[i].server_name+'</font></td>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONWorkFolder.folder[i].directory+'</font></td>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+dateString+'</font></td>';
			 		HTML_str+='<td width="14%" align="center"><font face="Arial"> <font size="2">'+JSONWorkFolder.folder[i].status+'</font></td>';
					HTML_str+='<td width="14%"  align="right"><div>'+
			 		"<a href='javascript:void(0)'"+
					' onclick=call_Edit_Work_Folder("'+i+'")><img src="/admin/edit.png"></img></a></td>';
					HTML_str+='<td>'+"<a href='javascript:void(0)'"+
					' onclick=call_Refresh_Work_Folder("'+i+'")><img src="/admin/refresh.png"></img></a></td>';
					HTML_str+='<td  align="left">'+"<a href='javascript:void(0)'"+
					' onclick=call_Del_Work_Folder("'+i+'")><img src="/admin/del.png"></img></a></td>';
					HTML_str+='</tr>';
			    		total_no++;
					folder_no++;
			
				}
			
			  
			        HTML_str=HTML_str+'</table>';
			        //new_total_no=Number(JSONWorkFolder.total_count)+1;
			        
			        menustr1="";
			     	menustr1='<table width=50%><tr>';
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelWorkFolderModal" class="modal">'+
						'<div class="modal-content">';
						menustr1+='<table  align="center"  cellpadding="5"  cellspacing="7">';
						menustr1+='<tr>'+
						'<td align=left><font face="Arial" size="6"><b>New Folder</b></font></td><td align=right id=add_folder_dialog_message name=add_folder_dialog_message></td></tr>';
			 		
				 		menustr1+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';
			
						menustr1+='<tr><td width="50%" height="23">'+
						'<p align="left" ><font face="Arial" size="2">Server Name</font>'+
						'</p>'+
						'</td>'+  
						'<td width="50%">'+
						' <font face="Arial"> <font size="2">'+
						' <select style="text-indent: 5;width:100%;height:26;" size="1" name="selectedbl" id="selectedbl">';
						for (j=0;j<JSONWorkFolder.node.length;j++)
						{
							if (j==0)
							{
								menustr1+='<option selected="selected" value="'+JSONWorkFolder.node[j]+'">'+JSONWorkFolder.node[j]+'</option>';
							}else
							{
								menustr1+='<option value="'+JSONWorkFolder.node[j]+'">'+JSONWorkFolder.node[j]+'</option>';
							}
								 			
						}
						menustr1+='</select></font></td></tr>';
						
						
						
						menustr1+='<tr><td width="50%"><font face="Arial" size="2">Folder Type</font></td><td width="50%">'+
				 		' <select style="text-indent: 5;width:100%;height:26;" size="1" name="foldertype" id=foldertype>';
						menustr1+='<option  style="padding: 2px" selected="selected" value="'+"Series"+'">'+"Series"+'</option>';
						menustr1+='<option  style="padding: 2px"  value="'+"Movie"+'">'+"Movie"+'</option>';
						menustr1+='</select></font></td></tr>';
						
						menustr1+='<tr><td width="50%"><font face="Arial" font size="2">Selected path</font></td><td width="50%">'+
							 	' <font face="Arial" size="2">'+
							 	' <input style="text-indent: 5;height:26;" type="text" name="selectedpath"'+
							 	' id=selectedpath'+
							 	' size="50"/'+
							 	'</font></td></tr>';
						menustr1+='<tr><td width="50%" height="23">'+
						'<p align="left" ><font face="Arial" size="2">Enabled</font>'+
						'</p>'+
						'</td>'+      
						'<td height="23"><p align="left">'+
						'<label class="switch"><input type="checkbox" checked id="folder_enabled"><span class="slider round"></span></label>'+
						'</td></tr>';
						
						menustr1+='<tr><td><input id=add_work_folder_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Work_Folder() name="Save" /></td>'+
						'<td align=right ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_work_folder_modal() name="Cancel" /></td></tr>';
						menustr1+='</table></div>'+
					'</div></td>';
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelUpdateWorkFolderModal" class="modal">'+
						'<div class="modal-content">';
						menustr1+='<table  align="center"  cellpadding="5"  cellspacing="7">';
						menustr1+='<tr>'+
						'<td align=left><font face="Arial" size="6"><b>Update Folder</b></font></td><td align=right id=update_folder_dialog_message name=update_folder_dialog_message></td></tr>';
			 		
				 		menustr1+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';
			
						menustr1+='<tr><td width="50%" height="23">'+
						'<p align="left" ><font face="Arial" size="2">Server Name</font>'+
						'</p>'+
						'</td>'+  
						'<td width="50%">'+
						' <font face="Arial"> <font size="2">'+
						' <select style="text-indent: 5;width:100%;height:26;" size="1" name="updateselectedbl" id="updateselectedbl">';
						for (j=0;j<JSONWorkFolder.node.length;j++)
						{
							if (j==0)
							{
								menustr1+='<option selected="selected" value="'+JSONWorkFolder.node[j]+'">'+JSONWorkFolder.node[j]+'</option>';
							}else
							{
								menustr1+='<option value="'+JSONWorkFolder.node[j]+'">'+JSONWorkFolder.node[j]+'</option>';
							}
								 			
						}
						menustr1+='</select></font></td></tr>';
						
						
						
						menustr1+='<tr><td width="50%"><font face="Arial" size="2">Folder Type</font></td><td width="50%">'+
				 		' <select style="text-indent: 5;width:100%;height:26;" size="1" name="updatefoldertype" id=updatefoldertype>';
						menustr1+='<option  style="padding: 2px" selected="selected" value="'+"Series"+'">'+"Series"+'</option>';
						menustr1+='<option  style="padding: 2px"  value="'+"Movie"+'">'+"Movie"+'</option>';
						menustr1+='</select></font></td></tr>';
						
						menustr1+='<tr><td width="50%"><font face="Arial" font size="2">Selected path</font></td><td width="50%">'+
							 	' <font face="Arial" size="2">'+
							 	' <input style="text-indent: 5;height:26;" type="text" name="updateselectedpath"'+
							 	' id=updateselectedpath'+
							 	' size="50"/'+
							 	'</font></td></tr>';
						menustr1+='<tr><td width="50%" height="23">'+
						'<p align="left" ><font face="Arial" size="2">Enabled</font>'+
						'</p>'+
						'</td>'+      
						'<td height="23"><p align="left">'+
						'<label class="switch"><input type="checkbox" checked id="updateenabled"><span class="slider round"></span></label>'+
						'</td></tr>';
						
						menustr1+='<tr><td><input id=update_work_folder_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Update_Work_Folder() name="Save" /></td>'+
						'<td align=right ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_update_work_folder_modal() name="Cancel" /></td></tr>';
						menustr1+='</table></div>'+
					'</div></td>';				
				menustr1+='</tr></table>';
				if (total_count==0)
				{
					current_position=0;
					endposition=0;
				}else
				{
					endposition=current_position+total_no-1;
				}
				menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
				menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' folders</td>';
				position=1;
				limit=g_constant_limit;
				
				if (total_count>g_constant_limit)
				{
					menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:call_get_first_user('+position+','+limit+')"; /> </font>';
				
					if (current_position-g_constant_limit<0)
					{
							
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						position=current_position-g_constant_limit;
						if ((position+g_constant_limit)<=total_count)
						{
							limit=g_constant_limit;
						}else
						{
							limit=total_count%g_constant_limit;
							if (limit==0) limit=g_constant_limit;
						}
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
					// user sequence
					total_sequence=Math.floor(total_count/g_constant_limit);
					//alert(total_sequence);
					if ((total_count%g_constant_limit) > 0)
					{
						total_sequence++;
					}
					
					curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
					//alert(curren_sequence_no);
					if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
					{
						start_sequence_no=total_sequence-g_sequence_constant_limit;
					}else
					{
						start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
					}
					//alert(start_sequence_no);
					if (start_sequence_no<=0) start_sequence_no=1;
					//if (total_sequence<g_sequence_constant_limit)
					//{
					//	start_sequence_no=1;
					//}
					for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
					{
						if (j>=total_sequence)
						{
							position=i;
							limit=total_count%g_constant_limit;
							
							if (limit==0) limit=g_constant_limit;
							if (j<10)
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}else
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}
							//menustr2+='</td>';
							break;
						}
						if (k<=g_sequence_constant_limit)
						{
							position=i;
							limit=g_constant_limit;
							if (j<10)
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}else
							{
								if (j==curren_sequence_no)
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}else
								{
									menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
								}
							}
							i+=g_constant_limit;
						}else
						{
							//menustr2+='</td>';
							break;
						}
						
						
					}
					if (endposition+1<=total_count)
					{
						position=endposition+1;
						if ((position+g_constant_limit)<=total_count)
						{
							limit=g_constant_limit;
						}else
						{
							limit=total_count%g_constant_limit;
							if (limit==0) limit=g_constant_limit;
						}
						menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
					if ((total_count%g_constant_limit)==0)
					{
						position=total_count-g_constant_limit+1;
						limit=g_constant_limit;
					}else
					{
						position=total_count-(total_count%g_constant_limit)+1;
						limit=total_count%g_constant_limit;
						if (limit==0) limit=g_constant_limit;
					}
					menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
				}else
				{
					menustr2+='<td>';
				}
				menustr2+='</td></tr></table>';
				
			      	content.innerHTML=menustr1+HTML_str+menustr2;
			     	g_SearchInput = document.getElementById("search_field");
			     	if (g_search_text.length>0)
			     	{
			     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
			     		g_SearchInput.focus();
			     	}
 			}	
		 };
		xmlHttp.send(null);
	}

}


function Download_User_Chlist() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
      /* if ((response==1))
    {
	    		alert("For security, root can not create channel list");
    }else*/
    if ((response==0))
    {
	    		alert("Can not create channel list");
    }else
    {
	    if (response.length>0)
	    
	    {
	    	window.onbeforeunload=function(){null};
	    	window.location =response; 
	    	window.onbeforeunload = function() {
			if (find_cookie_value("token"))
			{
		        	return "Are you sure you want to leave?";
		        }
		 }
	    }else
	    	{
	    		alert("Can not create channel list");
	    	}
	    	
    }
}
}
function getlink_download(fileName, text) {
  var element = document.createElement('a');
  element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
  element.setAttribute('download', fileName);

  element.style.display = 'none';
  document.body.appendChild(element);

  element.click();

  document.body.removeChild(element);
}
/*function copy2clipboard(){
   
const inputElement = document.querySelector('#myInput');
inputElement.select();
document.execCommand('copy');
   
}
*/
 function copy2clipboard(txt){
	var  copyText = prompt("Copy URL into Clipboard", txt);
	document.getElementById("search_field").value=copyText;
	var inputElement = document.querySelector('#search_field');
	inputElement.select();
	document.execCommand('copy');
	document.getElementById("search_field").value="";
	
}

function call_download_user_chlist(user_no,sObj)
{
 var username_id="username"+user_no; 
 var password_id="password"+user_no;
 var username;
 var szpassword;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var getlinkurl;
	var getxmltvurl;
	var getlinkfilename;
 
 	if (g_user_authorization_mode>0)
 	{
		g_item=document.getElementById(username_id);
		username=g_item.value;
	}
	else
	{
		username="free";
	}		
	if (sObj.value=="getxmltv")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getxmltvurl="https://"+location.hostname+":"+g_httpport+"/getxmltv?username="+username+":password="+szpassword;
			}else if (location.protocol == 'http:') {
				getxmltvurl="http://"+location.hostname+":"+g_httpport+"/getxmltv?username="+username+":password="+szpassword;
			}
		}
		/*else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getxmltvurl="https://"+location.hostname+":"+g_httpport+"/getxmltv?username="+username;
			}else if (location.protocol == 'http:') {
				getxmltvurl="http://"+location.hostname+":"+g_httpport+"/getxmltv?username="+username;
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getxmltvurl="https://"+location.hostname+":"+g_httpport+"/getxmltv?flag";
			}else if (location.protocol == 'http:') {
				getxmltvurl="http://"+location.hostname+":"+g_httpport+"/getxmltv?flag";
			}
		}
		copy2clipboard(getxmltvurl);
		//getlink_download(getlinkfilename,getlinkurl);
	}else if (sObj.value=="m3u_getlink")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u";
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?type=m3u";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?type=m3u";
			}
		}
		getlinkfilename="ezserver_ch_list("+username+").txt";
		copy2clipboard(getlinkurl);
		//getlink_download(getlinkfilename,getlinkurl);
	}else if (sObj.value=="m3u8_getlink")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=hls";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=hls";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=hls";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=hls";
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?type=hls";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?type=hls";
			}
		}
		getlinkfilename="ezserver_ch_list("+username+").txt";
		copy2clipboard(getlinkurl);
//		getlink_download(getlinkfilename,getlinkurl);
	}else if (sObj.value=="mpd_getlink")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=mpd";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=mpd";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=mpd";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=mpd";
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?type=mpd";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?type=mpd";
			}
		}
		getlinkfilename="ezserver_ch_list("+username+").txt";
		copy2clipboard(getlinkurl);
//		getlink_download(getlinkfilename,getlinkurl);
	}else if (sObj.value=="m3u_getphp")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/get.php?username="+username+"&password="+szpassword+"&type=m3u&output=mpegts";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/get.php?username="+username+"&password="+szpassword+"&type=m3u&output=mpegts";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/get.php?username="+username+"&type=m3u&output=mpegts";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/get.php?username="+username+"&type=m3u&output=mpegts";
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/get.php?utype=m3u&output=mpegts";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/get.php?utype=m3u&output=mpegts";
			}
		}
		getlinkfilename="ezserver_ch_list("+username+").txt";
		copy2clipboard(getlinkurl);
		//getlink_download(getlinkfilename,getlinkurl);
	}else
	{
		g_token=find_cookie_value("token");
		//alert(user_no);
		//alert(sObj.value);
	 	cgi_url = "/server/call_download_user_chlist?token="+encodeURI(g_token)+"&hostname="+location.hostname+"&username="+encodeURI(username)+"&ch_list_type="+sObj.value+"&flag="+Math.random();
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Download_User_Chlist;
		 xmlHttp.send(null); 
	 }

}
function Download_User_Movielist() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
      /* if ((response==1))
    {
	    		alert("For security, root can not create movie list");
    }else*/
    if ((response==0))
    {
	    		alert("Can not create movie list");
    }else
    {
	    if (response.length>0)
	    
	    {
	    	window.onbeforeunload=function(){null};
	    	window.location =response; 
	    	window.onbeforeunload = function() {
			if (find_cookie_value("token"))
			{
		        	return "Are you sure you want to leave?";
		        }
		 } 
	    }else
	    	{
	    		alert("Can not create movie list");
	    	}
	    	
    }
}
}
function call_download_user_movielist(user_no,sObj)
{
 var username_id="username"+user_no; 
 var password_id="password"+user_no;
 var username;
 var szpassword;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 	var getlinkurl;
	var getlinkfilename;

 
	g_item=document.getElementById(username_id);
	username=g_item.value;
/* 	if (g_user_authorization_mode>0)
 	{
		g_item=document.getElementById(username_id);
		username=g_item.value;
	}else
	{
		username="free";
	}
*/
	if (sObj.value=="m3u_getlink")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u&content=movie";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u&content=movie";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
				if (location.protocol == 'https:') {
					getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u&content=movie";
				}else if (location.protocol == 'http:') {
					getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u&content=movie";
				}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
				if (location.protocol == 'https:') {
					getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?type=m3u&content=movie";
				}else if (location.protocol == 'http:') {
					getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?type=m3u&content=movie";
				}
		}
		getlinkfilename="ezserver_movie_list("+username+").txt";
		copy2clipboard(getlinkurl);
//		getlink_download(getlinkfilename,getlinkurl);
	}else if (sObj.value=="m3u_series_getlink")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u&content=series";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u&content=series";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u&content=series";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u&content=series";
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?type=m3u&content=series";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?type=m3u&content=series";
			}
		}
		getlinkfilename="ezserver_series_list("+username+").txt";
		copy2clipboard(getlinkurl);
//		getlink_download(getlinkfilename,getlinkurl);
	}else if (sObj.value=="m3u_all_getlink")
	{
		if (g_user_authorization_mode==1)
		{
			g_item=document.getElementById(password_id);
			szpassword=g_item.value;
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u&content=all";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&password="+szpassword+"&type=m3u&content=all";
			}
		}
		/*
		else if (g_user_authorization_mode==2)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u&content=all";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?username="+username+"&type=m3u&content=all";
			}
		}
		*/
		else if (g_user_authorization_mode==0)
		{
			if (location.protocol == 'https:') {
				getlinkurl="https://"+location.hostname+":"+g_httpport+"/getlink?type=m3u&content=all";
			}else if (location.protocol == 'http:') {
				getlinkurl="http://"+location.hostname+":"+g_httpport+"/getlink?type=m3u&content=all";
			}
		}
		getlinkfilename="ezserver_all_list("+username+").txt";
		copy2clipboard(getlinkurl);
//		getlink_download(getlinkfilename,getlinkurl);
	}else
	{
	   	g_token=find_cookie_value("token");
		//alert(user_no);
		//alert(sObj.value);
	 	cgi_url = "/server/call_download_user_movielist?token="+encodeURI(g_token)+"&hostname="+location.hostname+"&username="+encodeURI(username)+"&movie_list_type="+sObj.value+"&flag="+Math.random();
		
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Download_User_Movielist;
		 xmlHttp.send(null); 
	 }

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

    var response = xmlHttp.responseText.split("\r\n");
     var username;
    var szpassword;
    var szgroup;
    var expired_timel
   // var paymodel;
  //  var paymodel_option;
  //  var user_point;
    var userip;
    var macid;
    var reseller;
    var user_title="<p>"+"User List"+"</p>";
    var user_list;
    var i=0;
    var user_no=1;
	var total_user_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
   var content = parent.document.getElementById("content");
  //var detail = parent.document.getElementById("detail");
  var expired_YY;
  var expired_MM;
  var expired_DD;
  var d=new Date();
  	var cur_year=d.getFullYear();
  	var cur_month=d.getMonth()+1;
  	var cur_day=d.getDate();
  	var bexpired=0;
  	var pos;
  	var expired_time_temp;
  	var yearmsg;
  	var menustr1;
	var menustr2;
	content.innerHTML="";
	//detail.innerHTML="";
	g_search_user_item.value=null;
	
	content.innerHTML="";
	 HTML_str= '<table border="0"  cellpadding="0" cellspacing="10" align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_user_no)></td>'+
	      '<td width="10%" align="center"><font face="Arial" size="2"></font></td>';
	     // if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	    //  {
		     HTML_str+='<td width="10%" align="center"><font face="Arial" size="2">User Name<br>(Primary Key)</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">Password</font></td>';
		      HTML_str+='<td width="10%" align="center"><font face="Arial" size="2">Group</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">CH List</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">Movie List</font></td>'+
//		      '<td width="10%" align="center"><font face="Arial" size="2">Expired Time</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">Expired Time</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">IP</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">MAC ID</font></td>'+
		      '<td width="5%" align="center"><font face="Arial" size="2">Reseller</font></td>'+
	 	 '</tr>'+'<tr><td  colspan="11"><hr size="1" color="#66FFFF"></td></tr>';
	     /*
	      }else if (g_user_authorization_mode==2)
	      {
	      	     HTML_str+='<td width="20%" align="center"><font face="Arial" size="2">PIN No.(Primary Key)</font></td>';
		      HTML_str+='<td width="10%" align="center"><font face="Arial" size="2">Group</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">CH List</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">Movie List</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">Expired Time</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">IP</font></td>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">MAC ID</font></td>'+
		      '<td width="5%" align="center"><font face="Arial" size="2">Reseller</font></td>'+
	 	 '</tr>'+'<tr><td  colspan="10"><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);
     	 	strlength=response[i+1].length;
   	    	szpassword=response[i+1].slice(9,strlength);
    	 	strlength=response[i+2].length;
   	    	szgroup=response[i+2].slice(6,strlength);
	 	strlength=response[i+3].length;
   	    	expired_time=response[i+3].slice(13,strlength);

	   	bexpired=0;
	 	pos=expired_time.indexOf('/');
	 	if (pos>0)
	 	{
			expired_MM=expired_time.substring(0,pos);
			expired_time_temp=expired_time.substring(pos+1);
			pos=expired_time_temp.indexOf('/');	
			expired_DD=expired_time_temp.substring(0,pos);
			expired_YY=expired_time_temp.substring(pos+1);
			//yearmsg=cur_year+'/'+cur_month+'/'+cur_day+'--'+expired_YY+'/'+expired_MM+'/'+expired_DD;
	   	    	//alert(yearmsg);
	
	   	    	if (cur_year<expired_YY)
	   	    	{
	   	    		bexpired=0;
	   	    	}else if (cur_year==expired_YY)
	   	    	{
		   	    	if (cur_month<expired_MM)
		   	    	{
		   	    		bexpired=0;
		   	    	}else if (cur_month==expired_MM)
		   	    	{	
			   	    	if (cur_day>expired_DD)
			   	    	{
			   	    		bexpired=1;
			   	    	}else
		   	    		{
		   	    			bexpired=0;
		   	    		}
		   	    	}else if (cur_month>expired_MM)
		   	    	{
		   	    		bexpired=1;
		   	    	}
		   	    	
	   	    	}else if (cur_year>expired_YY)
	    		{
	    			bexpired=1;
	    		}
    		}else
    		{
    			bexpired=2;
    		}
    			
    	
   	    	
   	    	
     	 	//strlength=response[i+4].length;
     	 	
   	    	//paymodel=response[i+4].slice(9,strlength);
	 	//strlength=response[i+5].length;
   	    	//user_point=response[i+5].slice(11,strlength);
	 	strlength=response[i+4].length;
   	    	userip=response[i+4].slice(7,strlength);
	 	strlength=response[i+5].length;
   	    	macid=response[i+5].slice(6,strlength);
	 	strlength=response[i+6].length;
   	    	reseller=response[i+6].slice(9,strlength);
 
 		i=i+7;
		      HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		      '<td width="20" align="center">'+
	 		' <input type="checkbox" name=checkbox'+user_no+
	 		' id=checkbox'+user_no+'></td>';
	 		
		//   if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
		//   {
		      HTML_str=HTML_str+'<td width="10%" align="center"><font face="Arial"> <font size="2">'+user_no+'</font></td>'+
		      '<td width="10%" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		' <input type="text" name="username"'+
	 		' id=username'+user_no+' size="12" value="'+
	 		username+'"/></font></td>'+
	 		
		      '<td width="10%" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		' <input type="text" name="password"'+
	 		' id=password'+user_no+' size="12" value="'+
	 		szpassword+'"/></font></td>';
		/*   }else if (g_user_authorization_mode==2)
	 		{
		 		HTML_str=HTML_str+'<td width="10%" align="center"><font face="Arial"> <font size="2">'+user_no+'</font></td>'+
			      '<td width="20%" align="center">'+
		 		' <font face="Arial" font size="2">'+
		 		' <input type="text" name="username"'+
		 		' id=username'+user_no+' size="36" value="'+
		 		username+'"/></font></td>';
	 		}
	 		*/
	 		

		      HTML_str=HTML_str+'<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1" name="group" id=group'+user_no+'>';
	 		for (j=0;j<g_total_group_no;j++)
	 		{
	 			groupname=g_groupname_array[j];
	 			//if (szgroup.search(groupname)==-1)
	 			if (szgroup!=(groupname))
	 			{
	 				HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
	 			}
	 			else 
	 			{
	 				if (szgroup.length==groupname.length)
	 				{
	 					HTML_str+='<option selected="selected" value="'+groupname+'">'+groupname+'</option>';
	 				}else
	 				{
	 					HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
	 				}
	 			}	 			
	 		}
	  		HTML_str+='</select></font></td>';
	  		
	  		HTML_str=HTML_str+'<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1" onchange="call_download_user_chlist('+user_no+','+'chlist'+user_no+')" name="ch_list" id=chlist'+user_no+'>'+
 			'<option value="-1">--</option>'+
			'<option value="enigma">Enigma</option>'+
			'<option value="enigma16">Enigma 1.6</option>'+
			'<option value="enigma(RTMP)">Enigma(RTMP)</option>'+
			'<option value="enigma16(RTMP)">Enigma 1.6(RTMP)</option>'+
			'<option value="enigma_no">Enigma(chno)</option>'+
			'<option value="enigma16_no">Enigma 1.6(chno)</option>'+
			'<option value="enigma_no(RTMP)">Enigma(RTMP/chno)</option>'+
			'<option value="enigma16_no(RTMP)">Enigma 1.6(RTMP/chno)</option>'+
			'<option value="m3u">m3u</option>'+
			'<option value="m3u_getlink">m3u(getlink)</option>'+
			'<option value="m3u8">m3u8</option>'+
			'<option value="m3u8_getlink">m3u8(getlink API)</option>'+
		//	'<option value="mpd">mpd</option>'+
		//	'<option value="mpd_getlink">mpd(getlink API)</option>'+
			'<option value="m3u_getphp">m3u(get.php)</option>'+
			'<option value="getxmltv">getxmltv</option>'+
			'<option value="m3u_ts">m3u(MPEG TS)</option>'+
			'<option value="m3u_flv">m3u(FLV)</option>'+
			'<option value="m3u_no">m3u(chno)</option>'+
			'<option value="m3ue_no">m3u(chno with suffix)</option>'+
			'<option value="m3ue_name">m3u(chname with suffix)</option>'+
			'<option value="m3u_rtmp">m3u(RTMP)</option>'+
			'<option value="octagon">octagon</option>'+
			'<option value="ariva">ariva</option>'+
 			'<option value="xbmc">XBMC</option>'+
 			'<option value="pure">Pure</option>'+
			'<option value="optumuss">Optumuss</option>'+
			'<option value="amiko">Amiko</option>'+
			'<option value="spark">Spark</option>'+
			'<option value="tiger">Tiger</option>'+
			'<option value="Bluestar">Bluestar</option>'+
			'<option value="nstreamvod">nStreamVOD</option>'+
 			'<option value="m3u_ott">OTT Player</option>'+
			'<option value="script_enigma">*Enigma Script*</option>'+
			'<option value="script_enigma16">*Enigma16 Script*</option>'+
			'<option value="script_mac_address">*MAC Address Script*</option>';
	  		HTML_str+='</select></font></td>';		
	  		                         
 			HTML_str=HTML_str+'<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select size="1" onchange="call_download_user_movielist('+user_no+','+'movielist'+user_no+')" name="movie_list" id=movielist'+user_no+'>'+
 			'<option value="-1">--</option>'+
			'<option value="m3u">m3u (Movie)</option>'+
			'<option value="pure">Pure (Movie)</option>'+
			'<option value="m3u_getlink">m3u(Movie-getlink API)</option>'+
			'<option value="ch_movie_m3u">m3u (Channel/Movie)</option>'+
			'<option value="m3u_all_getlink">m3u(Channel/Movie-getlink API)</option>'+
			'<option value="Bluestar">Bluestar</option>'+
			'<option value="enigma">Enigma</option>'+
			'<option value="enigma16">Enigma 1.6</option>'+
 			'<option value="nstreamvod">nStreamVOD</option>'+
 			'<option value="script_enigma">*Enigma Script*</option>'+
			'<option value="script_enigma16">*Enigma16 Script*</option>';
	  		HTML_str+='</select></font></td>';
	  		
	  		
	  		if (bexpired==0)
	  		{	 		 		
			      HTML_str+='<td width="18%" align="center">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input type="text" name="expired_time"'+
		 		' id=expired_time'+user_no+' size="12" value="'+
		 		expired_time+'"/></font></td>';		
	 		}else if (bexpired==1)
	 		{
	 			
	 			HTML_str+='<td width="18%" align="center">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input type="text" name="expired_time"  style="background:#ff0000"'+
		 		' id=expired_time'+user_no+' size="12" value="'+
		 		expired_time+'"/></font></td>';		

	 		}else if (bexpired==2)
	 		{
	 			
	 			HTML_str+='<td width="18%" align="center">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input type="text" name="expired_time"  style="background:#ffff00"'+
		 		' id=expired_time'+user_no+' size="12" value="'+
		 		expired_time+'"/></font></td>';		

	 		}
	 	
	 		HTML_str+='<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="userip"'+
	 		' id=userip'+user_no+' size="12" value="'+
	 		userip+'"/></font></td>';	 			

	 		HTML_str+='<td width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="macid"'+
	 		' id=macid'+user_no+' size="12" value="'+
	 		macid+'"/></font></td>';	 			

	 		HTML_str+='<td id=reseller'+user_no+' width="10%" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
	 		reseller+'</font></td>'+	 			
	 		
		    
		      '<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_New_User("'+user_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+

		      '<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_New_Multiple_User("'+user_no+'")>'+
	      	      ' <img border="0" id="addmultiplebutton" alt="Add Multiple Users" title="Add Multiple Users" src="add_multiple_icon.PNG"></a></td>'+

		      '<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Update_User("'+user_no+'")>'+
	      	      ' <img border="0" id="savebutton" alt="Save" title="Save" src="save_icon.PNG"></a></td>';
		      if (username!="root")
		      {
			      	HTML_str+='<td align="center">'+
			      "<a href='javascript:void(0)'"+
			      ' onclick=call_Del_User("'+user_no+'")>'+
		      	      ' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>';
	      	      }
	      	      
		      HTML_str+='<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Query_User_More("'+user_no+'")>'+
	      	      ' <img border="0" id="morebutton" alt="More" title="More" src="more_icon.PNG"></a></td>'+
		    '</tr>';
		total_user_no++;
		user_no++;
		//alert(HTML_str);
    }
        HTML_str=HTML_str+'</table>';
       //  alert(user_list_info.innerHTML);
   	g_user_no=total_user_no;
 	menustr1='<table width=100%><tr><td id=total_no_top_id>'+'<font face="Arial"> <font size="2">User Total: '+ g_user_no+'</td></tr><tr>';
		if (g_show_free_version==1)
		{
			menustr1+='<td><font face="Arial" size="2">Cut</font>'+'&nbsp&nbsp&nbsp'+
	 	      '<font face="Arial" size="2">Copy</font>'+'&nbsp&nbsp&nbsp'+
	 	      '<font face="Arial" size="2">Paste</font>'+'&nbsp&nbsp&nbsp';
		}else
		{
			menustr1+="<td> <a href='javascript:void(0)' onclick=callezserver_cut_selected_user()>"+
	 	      '<font face="Arial" size="2">Cut</font></a>'+'&nbsp&nbsp&nbsp'+
	 	      "<a href='javascript:void(0)' onclick=callezserver_copy_selected_user()>"+
	 	      '<font face="Arial" size="2">Copy</font></a>'+'&nbsp&nbsp&nbsp'+
	 	      "<a href='javascript:void(0)' onclick=callezserver_paste_selected_user()>"+
	 	      '<font face="Arial" size="2">Paste</font></a>'+'&nbsp&nbsp&nbsp';
		}
			
		
 	      menustr1+="<a href='javascript:void(0)' onclick=callezserver_delete_selected_user()>"+
 	      '<font face="Arial" size="2">Delete</font></a>'+'&nbsp&nbsp&nbsp'+
 	      "<a href='javascript:void(0)' onclick=callezserver_refresh_selected_user()>"+
 	      '<font face="Arial" size="2">Refresh</font></a>'+'&nbsp&nbsp&nbsp'+
	      //"<a href='javascript:void(0)' onclick=call_export_user_profile()>"+
	      //'<font face="Arial" size="2">Export</font></a>'+'&nbsp&nbsp&nbsp'+
	      '</td><td><font face="Arial" size="2"> <input name="user_search_field" id="user_search_field" size="20"/></font><font face="Arial"><font size="2"></font>'+
	   '<input type="button" value="Search" onclick="javascript:search_user();" name="search_user" /></font>'+
	   '<input type="button" value="Go to" onclick="javascript:goto_line_no(3);" name="goto_user_no" /></font>'+	   
	   '</td></tr>'+
	      '</table>';
      	content.innerHTML=menustr1+HTML_str;
/*   	menustr2='<table width=99%><tr><td id=total_user_no_bottom_id width=20%>'+'<font face="Arial"> <font size="2">Total: '+ g_user_no+'</td>'+
 	      "<td width=75% align=right> <a href='javascript:void(0)' onclick=call_get_all_user()>"+
 	      ' <font face="Arial" size="2">Refresh</font></a>'+
	      "<td width=80% align=right> <a href='javascript:void(0)' onclick=call_export_user_profile()>"+
	      ' <font face="Arial" size="2">Export</font></a>'+
	      '</td></tr></table>';
	      */
 }

 
}
function cleanup_expired_user()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    var alertmessage;
    
    if (response==0)
    {
   	alert("No expired users");
    } else if (response>0)
    {
	g_user_no-=parseInt(response);
	if (g_user_no<=0) g_user_no=1;
	if ((g_user_position+g_constant_limit)<=g_user_no)
	{
		g_user_limit=g_constant_limit;
	}else
	{
		g_user_limit=g_user_no%g_constant_limit;
		if (g_user_limit==0) 
		{
			if (g_user_no>0)
			{
				if (g_user_no<g_user_position)
				{
					g_user_position=g_user_no-g_constant_limit+1;
				}
				g_user_limit=g_constant_limit;
			}else
			{
				g_user_limit==0;
			}
		}
	}
    	if (response==1)
    	{
    		alertmessage="Cleanup "+ response +" expired user";
    	}else
    	{
    		alertmessage="Cleanup "+ response +" expired users";
    	}
  	alert(alertmessage);
     }
     call_get_users_detail();
    	
  }
}
function callezserver_cleanup_expired_user()
{
 	var cgi_url;
	var confirm_msg;
	
  	g_token=find_cookie_value("token");
	confirm_msg="Cleanup Expired Users?";
	if (confirm(confirm_msg))
	{
	 cgi_url = "/server/cleanup_expired_users?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = cleanup_expired_user;
	 xmlHttp.send(null);	
	}
}
function callezserver_get_all_user() {

	g_expired_user=0;
	g_user_position=1;
	g_user_limit=g_constant_limit;
	call_get_users(g_user_position,g_user_limit);

}
function get_expired_user()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    //alert(response);
    if (response==0)
    {
   	alert("No expired user");
    }else if (response>0)
    {
	g_expired_user_no=response;
    	g_expired_user=1;
    	g_user_position=1;
    	if (g_expired_user_no>g_constant_limit)
    	{
    		g_user_limit=g_constant_limit;
    	}else
    	{
    		g_user_limit=g_expired_user_no;
    	}
	call_get_users(g_user_position,g_user_limit);
    }
    	
  }
}
function callezserver_get_expired_user()
{
	var cgi_url;
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/get_expired_user_no?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = get_expired_user;
	xmlHttp.send(null);	
}
function Save_User_Setting()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    //alert(response);
    if (response==0)
    {
   	alert("User Setting Failed");
    }else if (response==1)
    {
	alert("User Setting Sucessfully");
    }  	
    close_setting_modal();
  }
}
function call_Save_User_Setting()
{
	var isp_lock_id="isp_lock";
	var isp_lock_flag;
 	var cgi_url;

	g_item=document.getElementById(isp_lock_id);
	isp_lock_flag=g_item.value;
   	g_token=find_cookie_value("token");
	cgi_url = "/server/save_user_setting?token="+encodeURI(g_token)+"&isp_lock_flag="+isp_lock_flag+"&flag="+Math.random();
 //  alert(cgi_url);
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Save_User_Setting;
	 xmlHttp.send(null);
}
function sort_user_ascending()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    	var content;

    //alert(response);
    if (response==0)
    {
    	alert("Sort Failed");
   	if (g_user_name_order_flag==1)
    	{
    		g_user_name_order_flag=0;
  		content = document.getElementById("user_name_id");
 		content.innerHTML='<font face="Arial" size="2">User Name</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
  	}else if (g_user_group_order_flag==1)
    	{
    		g_user_group_order_flag=0;
		content = document.getElementById("group_id");
		content.innerHTML='<font face="Arial" size="2">Group</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("group") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("group") title="Z to A">'+'&#x25bc'+'</a></font>';
     	}else if (g_user_expired_date_order_flag==1)
    	{
    		g_user_expired_date_order_flag=0;
    		content = document.getElementById("time_expired_id");
   		content.innerHTML='<font face="Arial" size="2">Expired Time</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("expired_time") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("expired_time") title="Z to A">'+'&#x25bc'+'</a></font>';
	}
    }else if (response>0)
    {
	g_expired_user=0;
	g_user_position=1;
	g_user_limit=g_constant_limit;
	call_get_users(g_user_position,g_user_limit);    }
    	
  }
}
function callezserver_sort_user_ascending(sortkey)
{
	var cgi_url;
	var content;
	g_token=find_cookie_value("token");
	cgi_url = "/server/sort_user_ascending?token="+encodeURI(g_token)+"&sortkey="+sortkey+"&flag="+Math.random();
	if (sortkey=="name")
	{
		content = document.getElementById("user_name_id");
		g_user_name_order_flag=1;
		g_user_group_order_flag=0;
		g_user_expired_date_order_flag=0;
	}else if (sortkey=="group")
	{
		content = document.getElementById("group_id");
		g_user_name_order_flag=0;
		g_user_group_order_flag=1;
		g_user_expired_date_order_flag=0;
	}else if (sortkey=="expired_time")
	{
		content = document.getElementById("time_expired_id");
		g_user_name_order_flag=0;
		g_user_group_order_flag=0;
		g_user_expired_date_order_flag=1;
	}
	content.innerHTML='<div class="loader"></div>';
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = sort_user_ascending;
	xmlHttp.send(null);	
}
function sort_user_descending()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    	var content;

    //alert(response);
    if (response==0)
    {
     	alert("Sort Failed");
  	if (g_user_name_order_flag==2)
    	{
   		g_user_name_order_flag=0;
 		content = document.getElementById("user_name_id");
 		content.innerHTML='<font face="Arial" size="2">User Name</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
		      
    	}else if (g_user_group_order_flag==2)
    	{
    		g_user_group_order_flag=0;
		content = document.getElementById("group_id");
		content.innerHTML='<font face="Arial" size="2">Group</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("group") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("group") title="Z to A">'+'&#x25bc'+'</a></font>';
		      
    	}else if (g_user_expired_date_order_flag==2)
    	{
  		g_user_expired_date_order_flag=0;
  		content = document.getElementById("time_expired_id");
  		content.innerHTML='<font face="Arial" size="2">Expired Time</font><font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("expired_time") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("expired_time") title="Z to A">'+'&#x25bc'+'</a></font>';
		      
    	}
    }else if (response>0)
    {
	g_expired_user=0;
	g_user_position=1;
	g_user_limit=g_constant_limit;
	call_get_users(g_user_position,g_user_limit);    }
    	
  }
}
function callezserver_sort_user_descending(sortkey)
{
	var cgi_url;
	var content;
	g_token=find_cookie_value("token");
	cgi_url = "/server/sort_user_descending?token="+encodeURI(g_token)+"&sortkey="+sortkey+"&flag="+Math.random();
	if (sortkey=="name")
	{
		content = document.getElementById("user_name_id");
		g_user_name_order_flag=2;
		g_user_group_order_flag=0;
		g_user_expired_date_order_flag=0;
	}else if (sortkey=="group")
	{
		content = document.getElementById("group_id");
		g_user_name_order_flag=0;
		g_user_group_order_flag=2;
		g_user_expired_date_order_flag=0;
	}else if (sortkey=="expired_time")
	{
		content = document.getElementById("time_expired_id");
		g_user_name_order_flag=0;
		g_user_group_order_flag=0;
		g_user_expired_date_order_flag=2;
	}
	content.innerHTML='<div class="loader"></div>';
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = sort_user_descending;
	xmlHttp.send(null);	
}
function callezserver_mass_edit_selected_users()
{
	
	var cgi_url;
	var mass_edit_group_id="mass_edit_group";
	//var mass_edit_paymodel_id="mass_edit_paymodel";
	var mass_edit_isp_lock_id="mass_edit_isp_lock";
	var mass_edit_max_connection_id="mass_edit_max_connection";
	//var mass_edit_user_point_id="mass_edit_user_point";


   
	var group;
	//var paymodel;
	var isp_lock;
	var max_connection;
	//var user_point;
	
	
	var i=0;	
	
   	g_token=find_cookie_value("token");
   	
//alert(g_checkedstring);	
	if (g_checkedstring=='0')
	{
	}else
	{

		g_item=document.getElementById(mass_edit_group_id);
		//alert(g_item.value);
		group=g_item.value;
//		g_item=document.getElementById(mass_edit_paymodel_id);
		//alert(g_item.value);
//		paymodel=g_item.value;
		g_item=document.getElementById(mass_edit_isp_lock_id);
		//alert(g_item.value);
		isp_lock=g_item.value;
		g_item=document.getElementById(mass_edit_max_connection_id);
		//alert(g_item.value);
		max_connection=g_item.value;
	//	g_item=document.getElementById(mass_edit_user_point_id);
		//alert(g_item.value);
	//	user_point=g_item.value;

	
	   	g_token=find_cookie_value("token");
	
		cgi_url = "/server/edit_multiple_users?token="+encodeURI(g_token)+
		"&group="+group+
		 // "&paymodel="+paymodel+
		  "&isp_lock="+isp_lock+
		  "&max_connection="+max_connection;
		//  "&user_point="+user_point;
		cgi_url +="&flag="+Math.random();
		//alert(cgi_url);
		 xmlHttp.open("POST", cgi_url, true);
		 xmlHttp.onreadystatechange = function() {
	
		 if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
			if (response!=1)
			{
				alert("Failed to Edit Movies");
			}
			
			close_mass_edit_user_modal();
			call_get_users(g_user_position,g_user_limit);
		    }
		};
				 
		xmlHttp.send(g_checkedstring);
	}
	

}	
function change_trial_date_format (sObj)
{
	var szid=document.getElementById("exipre_time_option");
	if (sObj.value=="5")
	{
		szid.innerHTML=' <font face="Arial"> <font size="2">'+
		' <select style="text-indent: 5;width:152;height:26;" size="1" id=expired_time>'+
		'<option style="background-color: white" value="1">1 hour</option>'+
		'<option style="background-color: white" value="2">2 hours</option>'+
		'<option style="background-color: white" value="3">3 hours</option>'+
		'<option style="background-color: white" value="4">4 hours</option>'+
		'<option style="background-color: white" value="5">5 hours</option>'+
		'<option style="background-color: white" value="6">6 hours</option>'+
		'<option style="background-color: white" value="7">7 hours</option>'+
		'<option style="background-color: white" value="8">8 hours</option>'+
		'<option style="background-color: white" value="9">9 hours</option>'+
		'<option style="background-color: white" value="10">10 hours</option>'+
		'<option style="background-color: white" value="11">11 hours</option>'+
		'<option style="background-color: white" value="12">12 hours</option>';
	}else
	{
		szid.innerHTML=' <font face="Arial"> <font size="2">'+
		' <select style="text-indent: 5;width:152;height:26;" size="1" id=expired_time>'+
		'<option style="background-color: white" value="30">1 month</option>'+
		'<option style="background-color: white" value="60">2 month</option>'+
		'<option style="background-color: white" value="90">3 month</option>'+
		'<option style="background-color: white" value="120">4 month</option>'+
		'<option style="background-color: white" value="150">5 month</option>'+
		'<option style="background-color: white" value="180">6 month</option>'+
		'<option style="background-color: white" value="210">7 month</option>'+
		'<option style="background-color: white" value="240">8 month</option>'+
		'<option style="background-color: white" value="270">9 month</option>'+
		'<option style="background-color: white" value="300">10 month</option>'+
		'<option style="background-color: white" value="330">11 month</option>'+
		'<option style="background-color: white" value="360">1 year</option>'+
		'<option style="background-color: white" value="720">2 year</option>'+
		'<option style="background-color: white" value="1080">3 year</option>'+
		'<option style="background-color: white" value="1440">4 year</option>'+
		'<option style="background-color: white" value="1800">5 year</option>';
	}
}
function get_users()
{
 
  if (xmlHttp.readyState == 4) {

    var response = xmlHttp.responseText.split("\r\n");
     var username;
    var szpassword;
    var szgroup;
    var expired_timel
   // var paymodel;
  //  var paymodel_option;
  //  var user_point;
    var userip;
    var macid;
    var reseller;
    var user_title="<p>"+"User List"+"</p>";
    var user_list;
    var i=0;
    var j=0;
    var k=0;
    var user_no=1;
	var total_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
	var ezcontent= document.getElementById("content");
	//  var iconwidth=20;
  //var iconheight=20;

   var content;
  var expired_YY;
  var expired_MM;
  var expired_DD;
  var d=new Date();
  	var cur_year=d.getFullYear();
  	var cur_month=d.getMonth()+1;
  	var cur_day=d.getDate();
  	var bexpired=0;
  	var pos;
  	var expired_time_temp;
  	var yearmsg;
  	var menustr1;
	var menustr2;
	var endposition;
	var position;
	var limit;
	var curren_sequence_no;
	var total_sequence;
	var start_sequence_no;
	var current_position=g_user_position;
	var total_count=0;
	var max_connection=1;
	var new_total_no;
	var ranpass;
	var cellsize="11%";
	//detail.innerHTML="";
	// var iconwidth=25;
  	//var iconheight=25;

	if (g_expired_user==0)
	{
		total_count=g_user_no;
	}else if (g_expired_user==1)
	{
		total_count=g_expired_user_no;
	}
	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	//var menu_screen= document.getElementById("ezmenu");
	//alert(document.getElementById("ezhead"));
	//document.getElementById("ezhead").innerHTML='<font face="Arial" color=#000000 size="6"><b>User1</b></font>';
	
	
//	var search_field= document.getElementById("title_search_field");
	//var search_button= document.getElementById("title_search_button");
//	search_field.hidden=false;
	//search_button.hidden=false;
	g_start_search_option=1;
	
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="50%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>User</b></font>';
	str+='</td>';
	if (g_Ezserver_Version==BALANCER)
	{
		str+='<td>';
		  	str+='<input type="text" id="search_field" size=0 style="opacity: 0.5;text-indent: 5;margin-left: 0;width=0;height:0;border-color: #c7c7c7; border-style: solid; border-width: 0">';
		str+='</td>';
	}else
	{
		str+='<td>';
		if ((g_search_text.length==0)|| g_SearchInput.value=='Search Users...')
		{
		  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()"  size="20" value="Search Users..." style="opacity: 0.5;text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
		}else
		{
		  	str+='<input type="text" id="search_field" onkeyup="SearchInput()" onblur="CloseSearch()" onclick="ClearSearchInput()" size="20" value="'+g_search_text+'" style="text-indent: 5;margin-left: 0;height:48;border-color: #c7c7c7; border-style: solid; border-width: 1">';
		}
		str+='</td>';
		str+='<td>';
		str+='<div class="navbar" style="background-color: #F5F6F8">';
			if (g_expired_user==0)
			{
				str+='<div class="menudropoption">';
				    str+='<button class="dropbtn">No Filter '; 
				    str+='<i class="fa fa-caret-down"></i>';
				    str+='</button>';
				    str+='<div class="menudropdown-content">';
				     // str+='<a href="javascript:()">Active</a>';
				      str+='<a href="javascript:callezserver_get_expired_user()">Expired</a>';
				    str+='</div>';
				str+='</div>'; 
			}else if (g_expired_user==1)
			{
				str+='<div class="menudropoption">';
				    str+='<button class="dropbtn">Expired '; 
				    str+='<i class="fa fa-caret-down"></i>';
				    str+='</button>';
				    str+='<div class="menudropdown-content">';
				      str+='<a href="javascript:callezserver_get_all_user()">No Filter</a>';
				     // str+='<a href="javascript:callezserver_delete_selected_user()">Active</a>';
				    str+='</div>';
				str+='</div>'; 
			}
			
		str+='</td>';
		
		str += '<td>' +
	       '<select style="text-indent: 5px; width: 100px; height: 48px; border-color: #c7c7c7; border-style: solid; border-width: 1px;" id="page_no" onchange="change_page_no()">' +
	       '<option value="10" ' + (g_constant_limit === 10 ? 'selected' : '') + '>10</option>' +
	       '<option value="20" ' + (g_constant_limit === 20 ? 'selected' : '') + '>20</option>' +
	       '<option value="50" ' + (g_constant_limit === 50 ? 'selected' : '') + '>50</option>' +
	       '<option value="100" ' + (g_constant_limit === 100 ? 'selected' : '') + '>100</option>' +
	       '<option value="1000" ' + (g_constant_limit === 1000 ? 'selected' : '') + '>1000</option>' +
	       '</select>' +
	       '</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_user_modal()">Add User</a>';
		str+='</div>'; 
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		str+='<button class="dropbtn" onclick="callezserver_get_all_user()">'; 
		
		str+='<i class="fa fa-refresh"></i>';
		str+='</button>';
		str+='</div>'; 
		str+='<div class="menudropdown">';
		str+='<button class="dropbtn" style="background-color: #414D5F">'; 
		str+='<i class="fa fa-caret-down"></i>';
		str+='</button>';
		str+='<div class="menudropdown-content">';
		if (g_search_text.length==0)
		{
			str+='<a href="javascript:open_mass_edit_user_modal()">Mass Edit</a>';
			str+='<a href="javascript:callezserver_delete_selected_user()">Mass Delete</a>';
			str+='<a id=user_cut_field href="javascript:callezserver_move_selected_user()">Move to</a>';
			str+='<a href="javascript:open_setting_modal()">Mass ISP Locked</a>';
		}
		str+='<a href="javascript:call_export_user_profile()">Export as XML</a>';
		str+='</div>';
		str+='</div>'; 
			
			
		str+='</td>';
	}
	
	
	str+='</tr>';
	str+='</table>';
	//alert(str);
	
	//str='<font size=4>Users</font>';
	document.getElementById("ezhead").innerHTML=str;
	
	if (g_Ezserver_Version==BALANCER)
	{
		
	}else
	{
		//parent.document.getElementById("page_no").value=g_constant_limit;
		
	}

	
	 
	g_search_user_item.value=null;
	content = parent.document.getElementById("ezmenucontent");
	/*if(/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)){
		menu_screen.style="width: 200px";
		var content_width=(window.innerWidth-menu_screen.clientWidth)/window.innerWidth;
		content_width="width: "+Math.floor(content_width*100)+'%';
		content.style=content_width;
	}
	*/
	
//	 HTML_str= '<table border="0"  cellpadding="0" cellspacing="10" align="center">'+
	 HTML_str= '<table border="0" style="margin-top: 20px;" width=100% align="center">'+
	  '<tr>'+
	      '<td width="20" align="center"> <input type="checkbox" name="checkallbox" id=checkallbox  onclick=set_all_checked(g_user_no)></td>'+
	      '<td width="20" align="center"><font face="Arial" size="2"></font></td>';
	     // if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	      //{
		     HTML_str+='<td id="user_name_id" width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>User ID</b></font>';
		     if (g_user_name_order_flag==0)
		     {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_name_order_flag==1)
		     {
		     	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_name_order_flag==2)
		     {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
		      }
		      HTML_str+='</td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Password</b></font></td>';
		      HTML_str+='<td id="group_id" width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Bouquet</b></font>';
		      if (g_user_group_order_flag==0)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("group") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("group") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_group_order_flag==1)
		      {
		     	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("group") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_group_order_flag==2)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("group") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
		      }
		      HTML_str+='</td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Channel List</b></font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Movie / Series List</b></font></td>'+
		      '<td id="time_expired_id" width="10%" align="center"><font face="Arial" size="2"><b>Expired Time</b></font>';
		      if (g_user_expired_date_order_flag==0)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("expired_time") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("expired_time") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_expired_date_order_flag==1)
		      {
		     	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("expired_time") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_expired_date_order_flag==2)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("expired_time") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
		      }
		      HTML_str+='</td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Authentication IP</b></font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Authentication MAC</b></font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Owner</b></font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"></font></td>'+
	 	 '</tr>'+'<tr><td  colspan="12"><hr size="1" color="#66FFFF"></td></tr>';
	      /*
	      }else if (g_user_authorization_mode==2)
	      {
	      	     HTML_str+='<td id="user_name_id" width="'+cellsize+'" align="center"><font face="Arial" size="2">PIN No.';
		     if (g_user_name_order_flag==0)
		     {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_name_order_flag==1)
		     {
		     	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("name") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_name_order_flag==2)
		     {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("name") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
		      }
		      HTML_str+='<td id="group_id" width="'+cellsize+'" align="center"><font face="Arial" size="2">Group';
		      if (g_user_group_order_flag==0)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("group") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("group") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_group_order_flag==1)
		      {
		     	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("group") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_group_order_flag==2)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("group") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
		      }
		      HTML_str+='</td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">CH List</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Movie List</font></td>'+
		      '<td  id="time_expired_id" width="10%" align="center"><font face="Arial" size="2">Expired Time</font>';
		      if (g_user_expired_date_order_flag==0)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("expired_time") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("expired_time") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_expired_date_order_flag==1)
		      {
		     	HTML_str+='<font face="Arial" size="2" color="#cccccc">'+'&#x25b2'+'</font>'+
		      	'<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_descending("expired_time") title="Z to A">'+'&#x25bc'+'</a></font>';
		      }else if (g_user_expired_date_order_flag==2)
		      {
		     	HTML_str+='<font face="Arial" size="2">'+"<a href='javascript:void(0)'"+' style="text-decoration: none; color: #000000" onclick=callezserver_sort_user_ascending("expired_time") title="A to Z">'+'&#x25b2'+'</a></font>'+
		      	'<font face="Arial" size="2" color="#cccccc">'+'&#x25bc'+'</font>';
		      }
		      HTML_str+='</td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">IP</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">MAC ID</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Owner</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"></font></td>'+
	 	 '</tr>'+'<tr><td  colspan="12"><hr size="1" color="#66FFFF"></td></tr>';
	      }
	      */
	      	
 	user_no=current_position;
 	
 	while (1)
	{
 	 	if (response[i]==0) break;
		//alert(response[i]);
	 	strlength=response[i].length;
   	    	username=response[i].slice(9,strlength);
     	 	strlength=response[i+1].length;
   	    	szpassword=response[i+1].slice(9,strlength);
    	 	strlength=response[i+2].length;
   	    	szgroup=response[i+2].slice(6,strlength);
	 	strlength=response[i+3].length;
   	    	expired_time=response[i+3].slice(13,strlength);

	   	bexpired=0;
	 	pos=expired_time.indexOf('/');
	 	if (pos>0)
	 	{
			expired_MM=expired_time.substring(0,pos);
			expired_time_temp=expired_time.substring(pos+1);
			pos=expired_time_temp.indexOf('/');	
			expired_DD=expired_time_temp.substring(0,pos);
			expired_YY=expired_time_temp.substring(pos+1);
			//yearmsg=cur_year+'/'+cur_month+'/'+cur_day+'--'+expired_YY+'/'+expired_MM+'/'+expired_DD;
	   	    	//alert(yearmsg);
	
	   	    	if (cur_year<expired_YY)
	   	    	{
	   	    		bexpired=0;
	   	    	}else if (cur_year==expired_YY)
	   	    	{
		   	    	if (cur_month<expired_MM)
		   	    	{
		   	    		bexpired=0;
		   	    	}else if (cur_month==expired_MM)
		   	    	{	
			   	    	if (cur_day>expired_DD)
			   	    	{
			   	    		bexpired=1;
			   	    	}else
		   	    		{
		   	    			bexpired=0;
		   	    		}
		   	    	}else if (cur_month>expired_MM)
		   	    	{
		   	    		bexpired=1;
		   	    	}
		   	    	
	   	    	}else if (cur_year>expired_YY)
	    		{
	    			bexpired=1;
	    		}
    		}else
    		{
    			bexpired=2;
    		}
    			
    	
   	    	
   	    	
     	 	//strlength=response[i+4].length;
     	 	
   	    	//paymodel=response[i+4].slice(9,strlength);
	 	//strlength=response[i+5].length;
   	    	//user_point=response[i+5].slice(11,strlength);
	 	strlength=response[i+4].length;
   	    	userip=response[i+4].slice(7,strlength);
	 	strlength=response[i+5].length;
   	    	macid=response[i+5].slice(6,strlength);
	 	strlength=response[i+6].length;
   	    	reseller=response[i+6].slice(9,strlength);
 
 		i=i+7;

		      HTML_str=HTML_str+'<tr onmouseover="ChangeBackgroundColor(this)" onmouseout="RestoreBackgroundColor(this)">'+
		      '<td width="20" align="center">';
		      
	 		HTML_str+=' <input type="checkbox" name=checkbox'+user_no;
	 		HTML_str+=' id=checkbox'+user_no+'></td>';
	 		
		  // if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
		   //{
		      HTML_str=HTML_str+'<td width="20" align="center"><font face="Arial"> <font size="2">'+user_no+'</font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		' <input style="margin:2px;padding: 3px;height:26;" readonly type="text" name="username"'+
	 		' id=username'+user_no+' size="12" value="'+
	 		username+'"/></font></td>'+
	 		
		      '<td width="10%" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="password"'+
	 		' id=password'+user_no+' size="12" value="'+
	 		szpassword+'"/></font></td>';
		   /*
		   }else if (g_user_authorization_mode==2)
	 		{
		 		HTML_str=HTML_str+'<td width="10%" align="center"><font face="Arial"> <font size="2">'+user_no+'</font></td>'+
			      '<td width="'+cellsize+'" align="center">'+
		 		' <font face="Arial" font size="2">'+
		 		' <input style="padding: 5px;height:26;" readonly ype="text" name="username"'+
		 		' id=username'+user_no+' size="36" value="'+
		 		username+'"/></font></td>';
		 	}
		 */
	 		

		      HTML_str=HTML_str+'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select  style="text-indent: 5;width:120;height:26;" size="1" name="group" id=group'+user_no+'>';
	 		for (j=0;j<g_total_group_no;j++)
	 		{
	 			groupname=g_groupname_array[j];
	 			
	 			//if (szgroup.search(groupname)==-1)
	 			if (szgroup!=(groupname))
	 			{
	 				HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
	 			}
	 			else 
	 			{
	 				if (szgroup.length==groupname.length)
	 				{
	 					HTML_str+='<option selected="selected" value="'+groupname+'">'+groupname+'</option>';
	 				}else
	 				{
	 					HTML_str+='<option value="'+groupname+'">'+groupname+'</option>';
	 				}
	 			}	 			
	 		}
	  		HTML_str+='</select></font></td>';
	  		
	  		HTML_str=HTML_str+'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select  style="text-indent: 5;width:120;height:26;" size="1" onchange="call_download_user_chlist('+user_no+','+'chlist'+user_no+')" name="ch_list" id=chlist'+user_no+'>'+
 			'<option value="-1">--</option>'+
			'<option value="m3u">m3u</option>'+
			'<option value="m3u8">m3u8</option>'+
			'<option value="mpd">mpd</option>'+
			'<option value="m3u_getlink">m3u(API)</option>'+
			'<option value="m3u8_getlink">m3u8(API)</option>'+
		<!--	'<option value="mpd_getlink">mpd(API)</option>'+ --!>
			'<option value="m3u_getphp">m3u(get.php)</option>'+
			'<option value="getxmltv">getxmltv</option>'+
			'<option value="enigma">Enigma</option>'+
			'<option value="enigma16">Enigma 1.6</option>'+
			'<option value="enigma(RTMP)">Enigma(RTMP)</option>'+
			'<option value="enigma16(RTMP)">Enigma 1.6(RTMP)</option>'+
			'<option value="enigma_no">Enigma(chno)</option>'+
			'<option value="enigma16_no">Enigma 1.6(chno)</option>'+
			'<option value="enigma_no(RTMP)">Enigma(RTMP/chno)</option>'+
			'<option value="enigma16_no(RTMP)">Enigma 1.6(RTMP/chno)</option>'+
			'<option value="m3u_pure_name">m3u (No Encoded)</option>'+
			'<option value="m3u_ts">m3u(MPEG TS)</option>'+
			'<option value="m3u_flv">m3u(FLV)</option>'+
			'<option value="m3u_no">m3u(chno)</option>'+
			'<option value="m3ue_no">m3u(chno with suffix)</option>'+
			'<option value="m3ue_name">m3u(chname with suffix)</option>'+
			'<option value="m3u8_pure_name">m3u8(No Encoded)</option>'+
			'<option value="m3u_rtmp">m3u(RTMP)</option>'+
			'<option value="octagon">octagon</option>'+
			'<option value="ariva">ariva</option>'+
 			'<option value="xbmc">XBMC</option>'+
 			'<option value="pure">Pure</option>'+
			'<option value="optumuss">Optumuss</option>'+
			'<option value="amiko">Amiko</option>'+
			'<option value="spark">Spark</option>'+
			'<option value="tiger">Tiger</option>'+
			'<option value="Bluestar">Bluestar</option>'+
			'<option value="nstreamvod">nStreamVOD</option>'+
 			'<option value="m3u_ott">OTT Player</option>'+
			'<option value="script_enigma">*Enigma Script*</option>'+
			'<option value="script_enigma16">*Enigma16 Script*</option>'+
			'<option value="script_mac_address">*MAC Address Script*</option>';
	  		HTML_str+='</select></font></td>';		
	  		                         
 			HTML_str=HTML_str+'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
			' <select style="text-indent: 5;width:120;height:26;" size="1" onchange="call_download_user_movielist('+user_no+','+'movielist'+user_no+')" name="movie_list" id=movielist'+user_no+'>'+
 			'<option value="-1">--</option>'+
			'<option value="m3u">m3u (Movie)</option>'+
			'<option value="pure">Pure (Movie)</option>'+
			'<option value="m3u_getlink">m3u(Movie-getlink API)</option>'+
			'<option value="m3u_series_getlink">m3u(Series-getlink API)</option>'+
			'<option value="ch_movie_m3u">m3u (Channel/Movie)</option>'+
			'<option value="m3u_all_getlink">m3u(All-getlink API)</option>'+
			'<option value="Bluestar">Bluestar</option>'+
			'<option value="enigma">Enigma</option>'+
			'<option value="enigma16">Enigma 1.6</option>'+
 			'<option value="nstreamvod">nStreamVOD</option>'+
			'<option value="script_enigma">*Enigma Script*</option>'+
			'<option value="script_enigma16">*Enigma16 Script*</option>';
	  		HTML_str+='</select></font></td>';
	  		
	  		
	  		if (bexpired==0)
	  		{	 		 		
			      HTML_str+='<td width="'+cellsize+'" align="center">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;" type="text" name="expired_time"'+
		 		' id=expired_time'+user_no+' size="10" value="'+
		 		expired_time+'"/></font></td>';		
	 		}else if (bexpired==1)
	 		{
	 			
	 			HTML_str+='<td width="'+cellsize+'" align="center">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;background:#ff0000;" type="text" name="expired_time"'+
		 		' id=expired_time'+user_no+' size="10" value="'+
		 		expired_time+'"/></font></td>';		

	 		}else if (bexpired==2)
	 		{
	 			
	 			HTML_str+='<td width="'+cellsize+'" align="center">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;background:#ffff00;" type="text" name="expired_time"'+
		 		' id=expired_time'+user_no+' size="10" value="'+
		 		expired_time+'"/></font></td>';		

	 		}
	 	
	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="text-indent: 5;height:26;" type="text" name="userip"'+
	 		' id=userip'+user_no+' size="12" value="'+
	 		userip+'"/></font></td>';	 			

	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style=" text-indent: 5;height:26;" type="text" name="macid"'+
	 		' id=macid'+user_no+' size="12" value="'+
	 		macid+'"/></font></td>';	 			

	 		HTML_str+='<td id=reseller'+user_no+' width="'+cellsize+'" align="center">'+
	 		' <font face="Arial"> <font size="2">'+
	 		reseller+'</font></td>';
	 		HTML_str+='<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=call_Update_User("'+user_no+'")><img src="/admin/save.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=open_more_user_modal("'+username+'")><img src="/admin/edit.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=call_Del_User("'+username+'")><img src="/admin/del.png"></img></a></td>';
	 		
		      
		      
		      HTML_str+='</tr>';
		total_no++;
		user_no++;
		//alert(HTML_str);
    }
  
        HTML_str=HTML_str+'</table>';
        new_total_no=Number(g_user_no)+1;
        //new_total_no=total_no+1;
       //  alert(user_list_info.innerHTML);
   	//total_count=total_no;
  // 	g_total_user_no=total_no;
// 	menustr1='<table width=100%><tr><td id=total_no_top_id>'+'<font face="Arial"> <font size="2">User Total: '+ total_count+'</td></tr><tr>';
 //  alert(version_date);
   menustr1="";
     	menustr1='<table width=100%><tr>';
	menustr1+='<td width="4%">';
		menustr1+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  align="center"  cellpadding="5"  cellspacing="7">';
    				menustr1+='<tr>'+
				'<td  id=new_user_text colspan=2 align=left><font face="Arial" size="6"><b>New User</b></font></td><td colspan=2 align=right id=add_user_dialog_message name=add_user_dialog_message></td></tr>';
	 		
		 		menustr1+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';

    				menustr1+='<tr><td><font face="Arial"><font size="2">User at </font></td><td width=25% height="23">'+
				' <font face="Arial" size="2">'+
				' <input style="text-indent: 5;height:26;" type="text" name="userno"'+
				' id="userno"'+
				' size="16" value="'+
				new_total_no+
				'"/></font></td>';
				
	 			//if ((g_user_authorization_mode==1) || (g_user_authorization_mode==0))
	 			//{
					menustr1+='<td id=username_text width=25%><font face="Arial" font size="2">User Name</font></td><td  width=25%>'+
					 	' <font face="Arial" size="2">'+
					 	' <input style="text-indent: 5;height:26;" type="text" name="username"'+
					 	' id=username'+
					 	' size="16"/'+
					 	'</font></td></tr>';
					ranpass=Math.floor(Math.random() * 10000000000) + 1;
					menustr1+='<tr><td width=25%><font face="Arial" font size="2">Password</font></td><td width=25%>'+
					 		' <font face="Arial" size="2">'+
					 		' <input style="text-indent: 5;height:26;" type="text" name="password"'+
					 		' id=password'+
					 		' size="16"/ value="'+
					 		ranpass+
					 		'"/>'+
					 		'</font></td>';
					menustr1+='<td width=25%><font face="Arial" font size="2">Rating Password</font></td><td width=25%>'+
					 		' <font face="Arial" size="2">'+
					 		' <input style="text-indent: 5;height:26;" type="text" name="rating_password"'+
					 		' id=rating_password'+
					 		' size="16"/ value="'+
					 		ranpass+
					 		'"/>'+
					 		'</font></td></tr>';
				/*
				}else if (g_user_authorization_mode==2)
				{
					menustr1+='<td width=25%><font face="Arial" font size="2">User Name</font></td><td  width=25%>'+
					 	' <font face="Arial" size="2">'+
					 	' <input style="text-indent: 5;height:26;" type="text" name="username"'+
					 	' id=username'+
					 	' size="16"/'+
					 	'</font></td></tr>';			
				}
				*/		
				menustr1+='<tr><td width=25%><font face="Arial" font size="2">Bouquet</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 value="'+groupname+'">'+groupname+'</option>';
		 		}
	  			menustr1+='</select></font></td>';
	  			
				menustr1+='<td width=25%><font face="Arial"> <font size="2">Level</font></td><td  width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" onchange="change_trial_date_format('+'user_level'+')" size="1" name="user_level" id="user_level">';
				menustr1+='<option selected="selected" value="0">'+"User"+'</option>'+
				'<option value="5">'+"Trial"+'</option>'+
				'<option value="1">'+"Administrator"+'</option>'+
				'<option value="2">'+"Super Reseller"+'</option>'+
				'<option value="3">'+"Reseller"+'</option>'+
				'<option value="4">'+"Restreamer"+'</option>';
				menustr1+='</select></font></td></tr>';

				menustr1+='<tr><td width=25%><font face="Arial" size="2">Expired Time</font></td>';
				menustr1+='<td  width=25% id=exipre_time_option width="350">'+
			 		' <font face="Arial"> <font size="2">'+
					' <select style="text-indent: 5;width:152;height:26;" size="1" id=expired_time>'+
		 			'<option style="background-color: white" value="30">1 month</option>'+
					'<option style="background-color: white" value="60">2 month</option>'+
					'<option style="background-color: white" value="90">3 month</option>'+
					'<option style="background-color: white" value="120">4 month</option>'+
					'<option style="background-color: white" value="150">5 month</option>'+
					'<option style="background-color: white" value="180">6 month</option>'+
					'<option style="background-color: white" value="210">7 month</option>'+
					'<option style="background-color: white" value="240">8 month</option>'+
					'<option style="background-color: white" value="270">9 month</option>'+
					'<option style="background-color: white" value="300">10 month</option>'+
					'<option style="background-color: white" value="330">11 month</option>'+
					'<option style="background-color: white" value="360">1 year</option>'+
					'<option style="background-color: white" value="720">2 year</option>'+
					'<option style="background-color: white" value="1080">3 year</option>'+
					'<option style="background-color: white" value="1440">4 year</option>'+
					'<option style="background-color: white" value="1800">5 year</option>';
				menustr1+='</select></font></td>';
				menustr1+='';

				menustr1+='<td width=25%><font face="Arial"> <font size="2">Connection Limit</font></td><td  width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input style="text-indent: 5;height:26;" type="text" name="max_connection"'+
		 		' id="max_connection"'+
		 		' size="16" value="'+
		 		max_connection+
		 		'"/></font></td></tr>';
				
				menustr1+='<tr><td width=25%><font face="Arial" size="2">IP</font></td><td width=25%>'+
				 		' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;" type="text" name="userip"'+
				 		' id=userip'+
				 		' size="16"/>'+
				 		'</font></td>';
				menustr1+='<td id=macid_text width=25%><font face="Arial" size="2">MAC ID</font></td><td width=25%>'+
				 		' <font face="Arial" size="2">'+
				 		' <input style="text-indent: 5;height:26;" type="text" name="macid"'+
				 		' id=macid'+
				 		' size="16"/>'+
				 		'</font></td></tr>';
				menustr1+='<tr><td colspan=2><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_User() name="Save" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_user_modal() name="Cancel" /></td></tr>';
				menustr1+='</table></div>'+
			'</div></td>';

		menustr1+='<td width="4%">';
			menustr1+='<div id="PanelModalMassEditUsers" class="modal">'+
				'<div class="small-modal-content">';
    				menustr1+='<table align="center" cellpadding="5"  cellspacing="7">';
    				menustr1+='<tr>'+
				'<td colspan=2 align=left><font face="Arial" size="6"><b>Edit Users</b></font></td></tr>';
	 			//'<td colspane=2 align=left><font face="Arial" size="6"><b>Edit Users</b></font></td><td width=10% align=right id=mass_edit_user_dialog_message name=mass_edit_user_dialog_message></td></tr>';
	 		
				menustr1+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';
				 menustr1+='<tr><td width=50%><font face="Arial" size="2">Group : </font></td><td width=50%>'+
		 		' <select  style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_group" id=mass_edit_group>';
				
				for (j=0;j<g_total_group_no;j++)
				{
					menustr1+='<option value="'+g_groupname_array[j]+'">'+g_groupname_array[j]+'</option>';
				}
				
	 			
				/* menustr1+='<tr><td><font face="Arial"> <font size="2">Pay Model: </font></td><td width="350" height="23">'+
			 		' <font face="Arial"> <font size="2">'+
					' <select size="1" name="mass_edit_paymodel" id="mass_edit_paymodel">';
			 		for (j=0;j<3;j++)
			 		{
			 			paymodel_option=g_paymodel_array[j];
		 				menustr1+='<option value="'+paymodel_option+'">'+paymodel_option+'</option>';
			 			 			
			 		}
		 		menustr1+='</select></font></td></tr>';
		 		*/
		 		
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">ISP Lock: </font></td><td  width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="mass_edit_isp_lock" id="mass_edit_isp_lock">';
	 			menustr1+='<option value="OFF">'+"OFF"+'</option>'+
				'<option value="ON">'+"ON"+'</option>';
				menustr1+='</select></font></td></tr>';
			
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">Connections Limit</font></td><td  width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;" type="text" name="mass_edit_max_connection"'+
		 		' id="mass_edit_max_connection"'+
		 		' size="16" value=""/></font></td></tr>';
 
		 		/* menustr1+='<tr><td><font face="Arial"> <font size="2">User Point: </font></td><td width="350" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input type="text" name="mass_edit_user_point"'+
		 		' id="mass_edit_user_point"'+
		 		' size="16" value=""/></font></td></tr>';
		 		*/
				
				menustr1+='<tr><td width=50%><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=callezserver_mass_edit_selected_users() name="Save" /></td>'+
				'<td width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_mass_edit_user_modal() name="Cancel" /></td></tr>';
				menustr1+='</table></div>'+

				//menustr1+='<tr><td><input type="button" value="Save" onclick=callezserver_mass_edit_selected_users() name="Save" /></td></tr></table>'+
				//'</div>'+
			'</div></td>';	
	menustr1+='<td width="4%">';
	menustr1+='<div id="PanelModalSetting" class="modal">'+
			'<div class="small-modal-content">';
			menustr1+='<table align="center" cellpadding="5"  cellspacing="7">';
			menustr1+='<tr><td colspan=2 align=left><font face="Arial" size="6"><b>User Setting</b></font></td></tr>';
	 		menustr1+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';	
 			menustr1+='<tr><td><font face="Arial" font size="2">ISP Locked : </font></td><td>'+
			 	'<font face="Arial" size="2">'+
				'<select  style="text-indent: 5;width:152;height:26;" size="1" name="isp_lock" id=isp_lock>';
			menustr1+='<option value="1">'+'Enable All Users'+'</option>';
			menustr1+='<option selected="selected" value="0">'+'Disable All Users'+'</option>';
	 		menustr1+='</select></font></td></tr>';
  			
			//menustr1+='<tr><td><input type="button" value="Save" onclick=call_Save_User_Setting() name="Save" /></td></tr></table>'+

			menustr1+='<tr><td width=50%><input id=add_new_user_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Save_User_Setting() name="Save" /></td>'+
			'<td width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_setting_modal() name="Cancel" /></td></tr>';
			menustr1+='</table></div>'+

			'</div>'+
		'</div></td>';
		
		menustr1+='<td width="4%">';
			menustr1+='<div id="PanelModalMoreUsers" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table align="center"  cellpadding="5"  cellspacing="7">';
    				
			menustr1+='<tr>'+
			'<td  colspan=2 align=left id=more_username><font face="Arial" size="6"><b>'+username+'</b></font></td><td colspan=2 align=right id=save_user_dialog_message name=save_user_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">First Name</font></td><td width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_first_name"'+
	 		' id="more_first_name"'+
	 		' size="16" value=""/></font></td>';
	 		
	 		menustr1+='<td width=25%><font face="Arial"><font size="2">Last Name</font></td><td  align=right width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;;" type="text" name="more_last_name"'+
	 		' id="more_last_name"'+
	 		' size="16" value=""/></font></td></tr>';
	 		
	 		
	
			menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Rating Password</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_rating_password"'+
	 		' id="more_rating_password"'+
	 		' size="16" value=""/></font></td>';
	
	 		menustr1+='<td width=25%><font face="Arial"><font size="2">Level: </font></td><td  align=right  width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="more_level" id="more_level">';
			if (g_Ezserver_Version==BALANCER)
			{
				menustr1+='<option selected="selected" value="1">'+"Administrator"+'</option>';
				menustr1+='</select></font></td></tr>';
			}else
			{
			menustr1+='<option selected="selected" value="0">'+"User"+'</option>'+
				'<option value="5">'+"Trial"+'</option>'+
				'<option value="1">'+"Administrator"+'</option>'+
				'<option value="2">'+"Super Reseller"+'</option>'+
				'<option value="3">'+"Reseller"+'</option>'+
				'<option value="4">'+"Restreamer"+'</option>';
				menustr1+='</select></font></td></tr>';
			}
				

			menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Connection Limit</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_max_connection"'+
	 		' id="more_max_connection"'+
	 		' size="16" value=""/></font></td>';
	
	 		menustr1+='<td width=25%><font face="Arial"> <font size="2">Connections</font></td><td  width=25% align=left style="text-indent: 10;height:26;" id=more_active_connection width="350" height="23">'+
	 		' <font face="Arial"> <font size="2"></font></td></tr>';

			menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">IP 2</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="text-indent: 5;height:26;" type="text" name="more_user2ndip"'+
	 		' id="more_user2ndip"'+
	 		' size="16" value=""/></font></td>';
	
			menustr1+='<td width=25%><font face="Arial"><font size="2">IP 3</font></td><td  align=right  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="text-indent: 5;height:26;" type="text" name="more_user3rdip"'+
	 		' id="more_user3rdip"'+
	 		' size="16" value=""/></font></td></tr>';
	
			menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">IP 4</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="text-indent: 5;height:26;"  type="text" name="more_user4thip"'+
	 		' id="more_user4thip"'+
	 		' size="16" value=""/></font></td>';
	
			menustr1+='<td width=25%><font face="Arial"><font size="2">IP 5</font></td><td  align=right  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_user5thip"'+
	 		' id="more_user5thip"'+
	 		' size="16" value=""/></font></td></tr>';
	 			
	  		
	 		/* menustr1+='<tr><td><font face="Arial"> <font size="2">Pay Model: </font></td><td width="350" height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select size="1" name="paymodel" id="paymodel">';
		 		for (j=0;j<3;j++)
		 		{
		 			paymodel_option=g_paymodel_array[j];
		 			if (paymodel.search(paymodel_option)==-1)
		 			{
		 				menustr1+='<option value="'+paymodel_option+'">'+paymodel_option+'</option>';
		 			}
		 			else
		 			{
		 				menustr1+='<option selected="selected" value="'+paymodel_option+'">'+paymodel_option+'</option>';
		 			}	 			
		 		}
	 		menustr1+='</select></font></td></tr>';
		 		*/
	
			
	
	 		menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">ISP Lock</font></td><td  width=25% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
				' <select style="text-indent: 5;width:152;height:26;" size="1" name="more_isp_lock" id="more_isp_lock">';
			menustr1+='<option selected="selected" value="OFF">'+"OFF"+'</option>'+
				'<option value="ON">'+"ON"+'</option>';
			menustr1+='</select></font></td>';
	  		menustr1+='<td width=25%><font face="Arial"><font size="2">Email: </font></td><td  align=right   width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_email"'+
	 		' id="more_email"'+
	 		' size="16" value=""/></font></td></tr>';
			
			/* menustr1+='<tr><td><font face="Arial"> <font size="2">User Point</font></td><td width="350" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input type="text" name="user_point"'+
	 		' id="user_point"'+
	 		' size="16" value=""/></font></td></tr>';
	 		*/
	
	
	 		menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Mobile Phone</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_smart_phone"'+
	 		' id="more_smart_phone"'+
	 		' size="16" value=""/></font></td>';
	
	 		menustr1+='<td width=25%><font face="Arial"><font size="2">WhatsApp</font></td><td  align=right  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_tablet"'+
	 		' id="more_tablet"'+
	 		' size="16" value=""/></font></td></tr>';
	
			/* menustr1+='<tr><td><font face="Arial"> <font size="2">Desktop ID</font></td><td width="350" height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_desktop"'+
	 		' id="more_desktop"'+
	 		' size="16" value=""/></font></td>';
	
	 		menustr1+='<td width=25%><font face="Arial"><font size="2">TV ID</font></td><td  align=right  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_tv"'+
	 		' id="more_tv"'+
	 		' size="16" value=""/></font></td></tr>';
	 		*/
	 		
	 		menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">Adress</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_address"'+
	 		' id="more_address"'+
	 		' size="16" value=""/></font></td>';
	 		
	 		menustr1+='<td width=25%><font face="Arial"><font size="2">City: </font></td><td  align=right   width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_city"'+
	 		' id="more_city"'+
	 		' size="16" value=""/></font></td></tr>';
	 		
	 		menustr1+='<tr><td width=25%><font face="Arial"> <font size="2">ZIP</font></td><td  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input style="text-indent: 5;height:26;"  type="text" name="more_zip"'+
	 		' id="more_zip"'+
	 		' size="16" value=""/></font></td>';
	 		
	 		menustr1+='<td width=25%><font face="Arial"><font size="2">Home Tel</font></td><td  align=right  width=25% height="23">'+
	 		' <font face="Arial"> <font size="2">'+
	 		' <input  style="text-indent: 5;height:26;" type="text" name="more_tel"'+
	 		' id="more_tel"'+
	 		' size="16" value=""/></font></td></tr>';
	  
	 	   	menustr1+='<tr ><td  width=25% colspan=2><font  face="Arial"><input type="button" style="width:100%;height:30;margin-top:10px;background-color: #5089DE;color: #ffffff;" value="Save" onclick=callServer_Save_More() name="Save" /></font></td>'+
	 	   	'<td align=right  width=25% colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_more_user_modal() name="Cancel" /></td></tr>';
	 
		    	
				
		
				menustr1+='</table>'+
				'</div>'+
			'</div></td>';	
			
	
	  menustr1+='</tr>'+
	  '</table>';
	//}
	if (total_count==0)
	{
		current_position=0;
		endposition=0;
	}else
	{
		endposition=current_position+total_no-1;
	}
	menustr2='<table width=100%><tr><td width="13%" align="right">'+'<font face="Arial"> <font size="2">Showing '+ current_position+' to '+endposition+' of </td>';
	menustr2+='<td width="20%" id=total_no_top_id>'+'<font face="Arial"> <font size="2">'+total_count+' users</td>';
	position=1;
	limit=g_constant_limit;
	
	if (total_count>g_constant_limit)
	{
		menustr2+='<td width="67%"><font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226A" onclick="javascript:call_get_first_user('+position+','+limit+')"; /> </font>';
	
		if (current_position-g_constant_limit<0)
		{
				
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" disabled value=&lt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
		}else
		{
			position=current_position-g_constant_limit;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value=&lt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
		}
		// user sequence
		total_sequence=Math.floor(total_count/g_constant_limit);
		//alert(total_sequence);
		if ((total_count%g_constant_limit) > 0)
		{
			total_sequence++;
		}
		
		curren_sequence_no=Math.floor(current_position/g_constant_limit)+1;
		//alert(curren_sequence_no);
		if ((total_sequence-curren_sequence_no)<g_sequence_constant_limit)
		{
			start_sequence_no=total_sequence-g_sequence_constant_limit;
		}else
		{
			start_sequence_no=curren_sequence_no-(g_sequence_constant_limit/2);
		}
		//alert(start_sequence_no);
		if (start_sequence_no<=0) start_sequence_no=1;
		//if (total_sequence<g_sequence_constant_limit)
		//{
		//	start_sequence_no=1;
		//}
		for (i=(start_sequence_no-1)*g_constant_limit+1,j=start_sequence_no,k=1;;j++,k++)
		{
			if (j>=total_sequence)
			{
				position=i;
				limit=total_count%g_constant_limit;
				
				if (limit==0) limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
				}
				//menustr2+='</td>';
				break;
			}
			if (k<=g_sequence_constant_limit)
			{
				position=i;
				limit=g_constant_limit;
				if (j<10)
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="0'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
				}else
				{
					if (j==curren_sequence_no)
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;color:#ffffff;background-color:#1E90FF" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}else
					{
						menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="'+j+'" onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
					}
				}
				i+=g_constant_limit;
			}else
			{
				//menustr2+='</td>';
				break;
			}
			
			
		}
		if (endposition+1<=total_count)
		{
			position=endposition+1;
			if ((position+g_constant_limit)<=total_count)
			{
				limit=g_constant_limit;
			}else
			{
				limit=total_count%g_constant_limit;
				if (limit==0) limit=g_constant_limit;
			}
			menustr2+='<font face="Arial" size="2"><input type="button" style="border: none;width:40;height:40;" value=&gt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
		}else
		{
			menustr2+='<font face="Arial" size="2"><input  style="border: none;width:40;height:40;" type="button" disabled value=&gt; onclick="javascript:call_get_users('+position+','+limit+')"; /> </font>';
		}
		if ((total_count%g_constant_limit)==0)
		{
			position=total_count-g_constant_limit+1;
			limit=g_constant_limit;
		}else
		{
			position=total_count-(total_count%g_constant_limit)+1;
			limit=total_count%g_constant_limit;
			if (limit==0) limit=g_constant_limit;
		}
		menustr2+='<font face="Arial" size="2"><input style="border: none;width:40;height:40;" type="button" value="&#x226B" onclick="javascript:call_get_users('+position+','+limit+')"; /></font>';
	}else
	{
		menustr2+='<td>';
	}
	menustr2+='</td></tr></table>';
	
      	content.innerHTML=menustr1+HTML_str+menustr2;
      	if (g_Ezserver_Version==BALANCER)
      	{
      	}else
      	{
	      	if (g_add_user_flag>=1)
	      	{
	       		open_user_modal();
	      	}
	     	g_add_user_flag=0;
	     	g_SearchInput = document.getElementById("search_field");
	     	if (g_search_text.length>0)
	     	{
	     		g_SearchInput.setSelectionRange(g_SearchInput.value.length, g_SearchInput.value.length);
	     		g_SearchInput.focus();
	     	}
     	}
 }

 
}


function blacklist_remove_all()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
      if (response==1)
    {
	 callServer_blacklist_Inquery();
    } else
    {
   	alert("Failed to Remove All");
   }
// g_remove_all_button.innerHTML='<font face="Arial" size="2">Remove</font>';
    	
  }
}

function call_blacklist_remove_all() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
  	g_token=find_cookie_value("token");
 	//g_remove_all_button= document.getElementById("blacklist_remove_all");
 	confirm_msg="Remove All?";
	if (confirm(confirm_msg))
	{
	 cgi_url = "/server/remove_all_black_list?token="+encodeURI(g_token)+"&flag="+Math.random();
	
     	 //g_remove_all_button.innerHTML='<font size="2" face="Arial">Removing</font>';
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = blacklist_remove_all;
	 xmlHttp.send(null);
	 }

}
function blacklist_remove_ip()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
	// g_blacklist_remove_item.innerHTML='<font face="Arial" size="2">Remove</font>';
	 callServer_blacklist_Inquery();
    } else
    {
   	alert("Failed to Remove");
 	callServer_blacklist_Inquery();

//  	g_blacklist_remove_item.innerHTML='<font face="Arial" size="2">Remove</font>';
  }
    	
  }
}
function callServer_blacklist_remove_ip(ip) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var confirm_msg;
	
	blacklist_ip_remove_button="blacklist_ip_remove_button="+ip;
// alert(blacklist_ip_remove_button);
//    var detail = parent.document.getElementById("detail");
	g_blacklist_remove_item=document.getElementById(blacklist_ip_remove_button);
  	g_token=find_cookie_value("token");
	confirm_msg="Remove "+ip+" ?";
	if (confirm(confirm_msg))
	{
	 cgi_url = "/server/remove_ip_black_list?token="+encodeURI(g_token)+"&ipaddress="+ip+"&flag="+Math.random();
	// alert(cgi_url);
	
	g_blacklist_remove_item.innerHTML='<font face="Arial" size="2">Removing</font>';
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = blacklist_remove_ip;
	 xmlHttp.send(null);
	 }

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


    var response = xmlHttp.responseText.split("\r\n");
 /*   var group_no;
    var group_name;
    var group_concurrent_connection;
    var group_src;
    var group_title="<p>"+"Group List"+"</p>";
    var group_list;
   */
   var ip_no;
   var username;
   var ip;
   var macid;
   var country;
    var i=0;
 	var blacklist_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
 var content;
	var cellsize="17%";
	
	var ezcontent= document.getElementById("content");
	ezcontent.innerHTML='</div><div id="ezmenucontent"></div>';
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	var action_width="80%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Blacklist</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:call_blacklist_remove_all()">Delete All</a>';
		    
		    str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="callServer_blacklist_Inquery()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 

		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">Blacklist</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="callServer_blacklist_Inquery()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Refresh</button>'; 
		str+='<button class="button" onclick="call_blacklist_remove_all()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Del All</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="10" height="17" align="center"><font face="Arial" size="2">No.</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2">User</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2">IP</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2">MAC Address</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2">Country</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2">Failed Login times</font></td>'+
	      '<td width="'+cellsize+'" height="17" align="center"><font face="Arial" size="2">Available Login times</font></td>'+
 	      '</tr>'+'<tr><td  colspan="7"><hr size="1" color="#66FFFF"></td></tr>';
 	

	 while (1)
	{
//		alert(response[i]);
 	 	if (response[i]==0) break;
	 	strlength=response[i].length;
	 	//alert(strlength);
   	    	ip_no=response[i].slice(3,strlength);
   	    	//alert(ip_no);
     	 	strlength=response[i+1].length;
   	    	username=response[i+1].slice(9,strlength);

     	 	strlength=response[i+2].length;
   	    	ip=response[i+2].slice(3,strlength);
   	    	//alert(ip);
   	    	
    	 	strlength=response[i+3].length;
   	    	macid=response[i+3].slice(6,strlength);
   	    	
    	 	
    	 	strlength=response[i+4].length;
   	    	country=response[i+4].slice(8,strlength);
   	    	//alert(country);
   	    	
   	 	strlength=response[i+5].length;
   	    	tryno=response[i+5].slice(6,strlength);

   	 	strlength=response[i+6].length;
   	    	availno=response[i+6].slice(8,strlength);
 
 		i=i+7;
		blacklist_no++;
		HTML_str=HTML_str+
		   '<tr>'+
		      '<td width="10" align="center"><font face="Arial" size="2">'+ip_no+'</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+username+'</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+ip+'</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+macid+'</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+country+'</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+tryno+'</font></td>'+
		      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">'+availno+'</font></td>'+

		      '<td id=blacklist_ip_remove_button='+ip+' align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=callServer_blacklist_remove_ip("'+ip+'")>'+
	      	      ' <img border="0" id="delbutton" alt="Remove" title="Remove" src="/admin/del.png"></a></td>'+
		    '</tr>';
		   // alert(HTML_str);
     }
        //detail.innerHTML=HTML_str;
      // alert(menu_main.innerHTML);
  
  	content.innerHTML=HTML_str;
 	      
 }

 
}

function callServer_blacklist_Inquery() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	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_black_list?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Blacklist Loading...<p>';


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

}
function Disable_Balancer_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    
 	 var balancer_header_item=document.getElementById("balancer_header");
	 balancer_header_item.innerHTML='<font face="Arial" size="2"><input type="radio" value="V1" checked name="R1" onclick="javascript:checked_disable_balancer()"><b>Disabled</b><input type="radio" name="R1" value="V3" onclick="javascript:checked_master_balancer()"><b>By Geo. Location</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_edge_balancer()"><b>By Max. Streaming No.</b></font>';
    	callServer_balancer_Inquery();
    }
 
}
function Checked_Master_Balancer_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
 	 var balancer_header_item=document.getElementById("balancer_header");
	 balancer_header_item.innerHTML='<font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_balancer()"><b>Disabled</b><input type="radio" name="R1" value="V3" checked onclick="javascript:checked_master_balancer()"><b>By Geo. Location</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_edge_balancer()"><b>By Max. Streaming No.</b></font>';
    	callServer_balancer_Inquery();
    }
 
}
function Checked_Edge_Balancer_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
	 var balancer_header_item=document.getElementById("balancer_header");
	 balancer_header_item.innerHTML='<font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_balancer()"><b>Disabled</b><input type="radio" name="R1" value="V3" onclick="javascript:checked_master_balancer()"><b>By Geo. Location</b><input type="radio" name="R1" value="V4" checked onclick="javascript:checked_edge_balancer()"><b>By Max. Streaming No.</b></font>';
  	callServer_balancer_Inquery();
    }
 
}

function checked_disable_balancer()
{
	 confirm_msg="Disable Balancer?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/disable_balancer?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Disable_Balancer_Respponse;
		 xmlHttp.send(null);
		 var balancer_header_item=document.getElementById("balancer_header");
		 balancer_header_item.innerHTML='<font face="Arial" size="2"><b>Updating</b></font>';
	 }else
	{
		callServer_balancer_Inquery();
	}
	 	
 }
function checked_master_balancer()
{
	 confirm_msg="Change to by Geo. Location?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/checked_master_balancer?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Checked_Master_Balancer_Respponse;
		 xmlHttp.send(null);
		 var balancer_header_item=document.getElementById("balancer_header");
		 balancer_header_item.innerHTML='<font face="Arial" size="2"><b>Updating</b></font>';
	} else
 	{
 		callServer_balancer_Inquery();
 	}
}
function checked_edge_balancer()
{
	 confirm_msg="Change to By Max. Streaming No.";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/checked_edge_balancer?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Checked_Edge_Balancer_Respponse;
		 xmlHttp.send(null);
		 var balancer_header_item=document.getElementById("balancer_header");
		 balancer_header_item.innerHTML='<font face="Arial" size="2"><b>Updating</b></font>';
	} else
 	{
 		callServer_balancer_Inquery();
 	}
}

function Cancel_Add_Balancer()
{
	callServer_balancer_Inquery();

}
function Update_Blancer() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    //alert(response);
    if (response==1)
    {
    //	alert("Add Server Sucessfully");
    } else if (response==0)
    {
   	alert("Failed to Update Server");
    } else if (response==2)
    {
    	alert("Disk is error(FULL), Please contact administrator");
    }else if (response==3)
    {
    	alert("The Server is already in Database");
    }

	g_item.value=g_temp;
	g_item.style.backgroundColor = "#ffffff";
	//alert(add_id_button.innerHTML);
//	callServer_balancer_Inquery();
    }
}

function call_Update_Blancer(balancer_index)
{

	var servername_id="servername"+balancer_index;
	var username_id="username"+balancer_index;
	var szpassword_id="password"+balancer_index;
	var server_domain_id="server_domain"+balancer_index;
	var server_ip_id="server_ip"+balancer_index;
	var panel_port_id="panel_port"+balancer_index;
	var country_id="country"+balancer_index;
	var servername;
	var username;
	var szpassword;
	var server_domain;
	var server_ip;
	var panel_port;
	var country;
	var confirm_msg;
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	var pos;
	var alert_message;

 	g_item=document.getElementById(servername_id);
	servername=g_item.value;
	g_item=document.getElementById(username_id);
	username=g_item.value;
	g_item=document.getElementById(szpassword_id);
	szpassword=g_item.value;
	g_item=document.getElementById(server_domain_id);
	server_domain=g_item.value;
	g_item=document.getElementById(server_ip_id);
	server_ip=g_item.value;
	g_item=document.getElementById(panel_port_id);
	panel_port=g_item.value;
	g_item=document.getElementById(country_id);
	country=g_item.value;
	if (servername.length==0)
	{
		alert("Slave Server Name is empty");
		return;
	}

   	g_token=find_cookie_value("token");

	cgi_url = "/server/update_balancer?token="+encodeURI(g_token)+"&index="+balancer_index+"&servername="+encodeURI(servername)+
	"&username="+encodeURI(username)+
	"&password="+encodeURI(szpassword)+
	"&server_domain="+encodeURI(server_domain)+
	"&server_ip="+encodeURI(server_ip)+
	"&panel_port="+encodeURI(panel_port)+
	"&country="+encodeURI(country)+
	"&flag="+Math.random();
	//  alert(cgi_url);
	confirm_msg="Update Server "+servername+" ?";
	
	
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange = function() {
			if (xmlHttp.readyState == 4) {
			    var response = xmlHttp.responseText;
			    //alert(response);
			    if (response==1)
			    {
			    	
			    	bl_update_index=Number(balancer_index)-1;
			    	
			    	g_balancer[bl_update_index].name=servername;
			    
			    } else if (response==0)
			    {
			   	alert("Failed to Update Server");
			    } else if (response==2)
			    {
			    	alert("Disk is error(FULL), Please contact administrator");
			    }else if (response==3)
			    {
			    	alert("The Server is already in Database");
			    }
			
				g_item.value=g_temp;
				g_item.style.backgroundColor = "#ffffff";
			    }
		};
		xmlHttp.send(null);
		g_temp=g_item.value;
		g_item.style.backgroundColor = "#ff0000";
	


}

function call_Add_Blancer()
{

var servername_id="servername";
var username_id="username";
var szpassword_id="password";
var server_domain_id="server_domain";
var server_ip_id="server_ip";
var panel_port_id="panel_port";
var country_id="country";
var servername;
var username;
var szpassword;
var server_ip;
var panel_port;
var country;

	var add_balancer_button=document.getElementById("add_balancer_button");
	var add_balancer_dialog_message=document.getElementById("add_balancer_dialog_message");
	//var new_balanceritem;
	var new_balancernameitem;



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;
	var bl_index;


 	g_item=document.getElementById(servername_id);
 	new_balancernameitem=g_item;
	servername=g_item.value;
	g_item=document.getElementById(username_id);
	username=g_item.value;
	g_item=document.getElementById(szpassword_id);
	szpassword=g_item.value;
	g_item=document.getElementById(server_domain_id);
	server_domain=g_item.value;
	g_item=document.getElementById(server_ip_id);
	server_ip=g_item.value;
	g_item=document.getElementById(panel_port_id);
	panel_port=g_item.value;
	g_item=document.getElementById(country_id);
	country=g_item.value;
	if (servername.length==0)
	{
		alert("Slave Server Name is empty");
		return;
	}
	if (username.length==0)
	{
		alert("Admin. Name is empty");
		return;
	}
	if (szpassword.length==0)
	{
		alert("Password is empty");
		return;
	}
	if (server_ip.length==0)
	{
		alert("IP is empty");
		return;
	}
	if (panel_port.length==0)
	{
		alert("Panel Port is empty");
		return;
	}
	if (country.length==0)
	{
		alert("Country is empty");
		return;
	}
   	g_token=find_cookie_value("token");

  cgi_url = "/server/add_balancer?token="+encodeURI(g_token)+"&servername="+encodeURI(servername)+
 "&username="+encodeURI(username)+
 "&password="+encodeURI(szpassword)+
 "&server_domain="+encodeURI(server_domain)+
 "&server_ip="+encodeURI(server_ip)+
 "&panel_port="+encodeURI(panel_port)+
 "&country="+encodeURI(country)+
 "&flag="+Math.random();
  // alert(cgi_url);
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function()
	 {
	 	if (xmlHttp.readyState == 4) {
		    var response = xmlHttp.responseText;
			    if (response==1)
			    {
			    	bl_index=g_balancer.length+1;
			    	
				g_balancer.push({id: bl_index,name: servername});
				close_balancer_modal();
			    	/*
			    	add_balancer_button.value="Add Next";
				//var new_add_total_no=newreseller_no+1;
				add_balancer_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+servername+' Added</font>';
				//alert(new_add_total_no);
				//new_balanceritem.value=new_add_total_no;
				new_balancernameitem.value="";
				new_balancernameitem.focus();
				*/
				
			 	//callServer_balancer_Inquery();   
			    } else if (response==0)
			    {
			   	alert("Failed to Add Server");
			    } else if (response==2)
			    {
			    	alert("Disk is error(FULL), Please contact administrator");
			    }else if (response==3)
			    {
			    	alert("Server name is already in use.");
			    }
		    }
	 };
	 xmlHttp.send(null);


}

function call_Add_New_Balancer()
{

var HTML_str;
var user_no;
var len;
var servername;
var username;
var szpassword;
var userip;
var panel_port;
var country;var str;
var content = parent.document.getElementById("content");
	

	g_balancer_server_no++;

	HTML_str=content.innerHTML;
	//alert(HTML_str);
	//len=HTML_str.length-16;
	len=HTML_str.lastIndexOf("<TABLE");
	
	if (len==-1)
	{
		len=HTML_str.lastIndexOf("<table");
	}
		
		//HTML_str=HTML_str.slice(800,len);
		//alert(HTML_str);
//	alert(len);
	//len+=6;
	HTML_str=HTML_str.slice(0,len);

	user_no=g_balancer_server_no;
//	alert(HTML_str);
	HTML_str=HTML_str+'<tr><td><table><tr>';
			HTML_str+='<td width="5%" align="center"><font face="Arial"> <font size="2">'+user_no+'</font></td>';
			HTML_str+='<td width="15%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="servername"'+
			' id=servername'+user_no+' size="20"></font></td>';

	
			HTML_str+='<td width="10%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="username"'+
			' id=username'+user_no+' size="12" value=root></font></td>';
			
			HTML_str+='<td width="20%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="password"'+
			' id=password'+user_no+' size="20"></font></td>';
	
			HTML_str+='<td width="10%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="server_ip"'+
			' id=server_ip'+user_no+' size="12" value=192.168.0.8></font></td>';
	
			HTML_str+='<td width="10%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="panel_port"'+
			' id=panel_port'+user_no+' size="12" value=18000></font></td>';
	
			HTML_str+='<td width="15%" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input type="text" name="country"'+
			' id=country'+user_no+' size="20"></font></td>';
			
			HTML_str+='<td width="10%" align="center" id=server_status'+user_no+'>'+
				'<b><font color="#FF0000" face="Arial" size="2">OFF</font></b></td>';	
	 		
		      HTML_str+='<td id=add_id_button align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Blancer("'+user_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a></td>'+
	      	      
		      '<td align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Balancer()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+

		    '</tr></table></td></tr>';
	//alert(HTML_str);

	       content.innerHTML=HTML_str+'</table>';
  //      alert(user_list_info.innerHTML);
   
		
}



function call_Del_Balancer(user_no)
{
var servername_id="servername"+user_no;
var servername;
var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
 
	g_item=document.getElementById(servername_id);
	servername=g_item.value;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Delete Server: "+servername+" ?";
 cgi_url = "/server/del_balancer?token="+encodeURI(g_token)+"&servername="+encodeURI(servername)+"&flag="+Math.random();
  // alert(cgi_url);
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    var response = xmlHttp.responseText;
		    //alert(response);
		    if (response==1)
		    {
		    	g_balancer = g_balancer.filter(item => item.name !== servername);
		    	alert("Delete Server Sucessfully");
		    } else if (response==2)
		    {
		     	alert("Disk is error(FULL), Please contact administrator");  	
		    } else if (response==0)
		    {
		   	alert("Failed to Delete Server");
		    }
		    	callServer_balancer_Inquery();
		    
                }
         };
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	 g_item.value=g_item.value+" (del...)";
	g_item.style.backgroundColor = "#ff0000";
 }
 

}

function Query_Edge_Server() {

  if (xmlHttp.readyState == 4) {
	var response = xmlHttp.responseText.split("\r\n");
	var servername_id="servername"+g_edge_server_no;
	var username_id="username"+g_edge_server_no;
	var szpassword_id="password"+g_edge_server_no;
	var server_domain_id="server_domain"+g_edge_server_no;
	var server_ip_id="server_ip"+g_edge_server_no;
	var panel_port_id="panel_port"+g_edge_server_no;
	var country_id="country"+g_edge_server_no;
	var max_connection_no_id="max_connection_no"+g_edge_server_no;
	var free_conneciton_no_id="free_conneciton_no"+g_edge_server_no;
	var server_status_id="server_status"+g_edge_server_no;
	
	var servername_id_item=document.getElementById(servername_id);
	var username_id_item=document.getElementById(username_id);
	var szpassword_id_item=document.getElementById(szpassword_id);
	var server_domain_id_item=document.getElementById(server_domain_id);
	var server_ip_id_item=document.getElementById(server_ip_id);
	var panel_port_id_item=document.getElementById(panel_port_id);
	var country_id_item=document.getElementById(country_id);
	var max_connection_no_id_item=document.getElementById(max_connection_no_id);
	var free_conneciton_no_id_item=document.getElementById(free_conneciton_no_id);
	var server_status_id_item=document.getElementById(server_status_id);
	
	var servername;
	var username;
	var szpassword;
	var server_domain;
	var userip;
	var panel_port;
	var country;
	var max_connection_no;
	var free_conneciton_no;
	var server_status;
	var i;
	
	i=0;
 	strlength=response[i].length;
    	servername=response[i].slice(11,strlength);
    	//alert(servername);
 	strlength=response[i+1].length;
    	username=response[i+1].slice(9,strlength);
    	//alert(username);
 	strlength=response[i+2].length;
    	szpassword=response[i+2].slice(9,strlength);
    	//alert(szpassword);
   	server_domain=response[i+3].slice(14);
 	strlength=response[i+4].length;
    	server_ip=response[i+4].slice(10,strlength);
    	//alert(server_ip);
 	strlength=response[i+5].length;
    	panel_port=response[i+5].slice(11,strlength);
    	//alert(panel_port);
 	strlength=response[i+6].length;
    	country=response[i+6].slice(8,strlength);
    	//alert(country);
 	strlength=response[i+7].length;
    	max_connection_no=response[i+7].slice(13,strlength);

 	strlength=response[i+8].length;
    	free_conneciton_no=response[i+8].slice(8,strlength);

 	strlength=response[i+9].length;
    	server_status=response[i+9].slice(14,strlength);
    	
     	
     
        servername_id_item.value=servername;
	username_id_item.value=username;
	szpassword_id_item.value=szpassword;
	server_domain_id_item.value=server_domain;
	server_ip_id_item.value=server_ip;
	panel_port_id_item.value=panel_port;
	country_id_item.value=country;
	max_connection_no_id_item.innerHTML='<font face="Arial" size="2">'+max_connection_no+'</font>';
	free_conneciton_no_id_item.innerHTML='<font face="Arial" size="2">'+free_conneciton_no+'</font>';
	if (server_status==1)
	{
		server_status_id_item.innerHTML='<font face="Arial" size="2">ON</font>';
	}else if (server_status==2)
	{
		server_status_id_item.innerHTML='<font color="#00FF00" face="Arial" size="2">Checking</font>';
	}
	else {
		server_status_id_item.innerHTML='<b><font color="#FF0000" face="Arial" size="2">OFF</font></b>';
	}
	servername_id_item.style.backgroundColor= "#ffffff";
		
   }
}

//nction call_Del_User(user_no,username,szpassword,expired_time,paymodel,user_point)
function call_Query_Edge_Server(user_no)
{
var servername_id="servername"+user_no;
var servername;
var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
 
	g_item=document.getElementById(servername_id);
	servername=g_item.value;
	
	g_edge_server_no=user_no;
	
	
   	g_token=find_cookie_value("token");

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

	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Query_Edge_Server;
	 xmlHttp.send(null);
	g_item.style.backgroundColor = "#ff0000";

}
function close_balancer_modal() {
   var modal = document.getElementById('PanelModal');
   modal.style.display = "none";
   callServer_balancer_Inquery();
}
function balancer_inquery()
{
 
  if (xmlHttp.readyState == 4) {


	var response = xmlHttp.responseText.split("\r\n");
	var balancertype;
	var servername;
	var username;
	var szpassword;
	var userip;
	var panel_port;
	var country;
	var max_connection_no;
	var free_conneciton_no;
	var server_status;
	var server_domain;
	var user_title="<p>"+"User List"+"</p>";
	var user_list;
	var i=0;
	var user_no=1;
	var total_user_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
	var content = parent.document.getElementById("content");
	var menustr;

	var content;
	var cellsize="9%";
	var inputcellsize="10";
	
	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>'
	var action_width="80%";
	if (bMobileDevice)
	{
		action_width="10%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>Balancer</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()">Add Balancer</a>';
		str+='</div>'; 
		str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="Button_Server_balancer_Inquery()">'; 
		    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">Load Balancer</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()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Add BL</button>'; 
		str+='<button class="button" onclick="callServer_balancer_Inquery()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Refresh</button>'; 
	str+='</div>';                              
	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";
	
	HTML_str= '<table border="0" align="center" cellpadding="5"  cellspacing="7">';
	strlength=response[0].length;
	balancertype=response[0].slice(13,strlength);
	//alert(balancertype);
	if (balancertype==0)
	{		
		 HTML_str+= '<tr><td id=balancer_header colspan="10"><font face="Arial" size="2"><input type="radio" value="V1" checked name="R1" onclick="javascript:checked_disable_balancer()"><b>Disabled</b><input type="radio" name="R1" value="V3" onclick="javascript:checked_master_balancer()"><b>By Geo. Location</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_edge_balancer()"><b>By Max. Streaming No.</b></font></td></tr>';
	}else if (balancertype==2)
	{
		 HTML_str+= '<tr><td id=balancer_header colspan="10"><font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_balancer()"><b>Disabled</b><input type="radio" name="R1" value="V3" onclick="javascript:checked_master_balancer()"><b>By Geo. Location</b><input type="radio" name="R1" value="V4" checked onclick="javascript:checked_edge_balancer()"><b>By Max. Streaming No.</b></font></td></tr>';
	}else if (balancertype==1)
	{
		 HTML_str+= '<tr><td id=balancer_header colspan="10"><font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_balancer()"><b>Disabled</b><input type="radio" name="R1" value="V3" checked onclick="javascript:checked_master_balancer()"><b>By Geo. Location</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_edge_balancer()"><b>By Max. Streaming No.</b></font></td></tr>';
	}else if (balancertype==-1)
	{
		alert("For Enterprise Version Only...");
	}
	if (balancertype!=-1)
	{
		i=i+1;	
		HTML_str+='</tr>'+'<tr><td  colspan="11"><hr size="1" color="#66FFFF"></td></tr>';
		  HTML_str+='<tr>'+
		      '<td width="10" align="left"><p style="margin-left: 5"><font face="Arial" size="2">No.</font></td>';
			     HTML_str+='<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Slave Server Name</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Admin. Name</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Password</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Domain Name</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">IP</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Panel Port</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Country</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Max Connection</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Free Connection</font></td>'+
			      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2">Status</font></td>'+
		 	 '</tr>'+'<tr><td  colspan="11"><hr size="1" color="#66FFFF"></td></tr>';
		      
		      	
	 	i=1;
		while (1)
		{
		 	if (response[i]==0) break;
			//alert(response[i]);
		 	strlength=response[i].length;
		    	servername=response[i].slice(11,strlength);
		    	//alert(servername);
		 	strlength=response[i+1].length;
		    	username=response[i+1].slice(9,strlength);
		    	//alert(username);
		 	strlength=response[i+2].length;
		    	szpassword=response[i+2].slice(9,strlength);
		    	//alert(szpassword);
		 	strlength=response[i+3].length;
		    	server_ip=response[i+3].slice(10,strlength);
		    	//alert(server_ip);
		 	strlength=response[i+4].length;
		    	panel_port=response[i+4].slice(11,strlength);
		    	//alert(panel_port);
		 	strlength=response[i+5].length;
		    	country=response[i+5].slice(8,strlength);
		    	//max_connection_no(country);
		 	strlength=response[i+6].length;
		    	max_connection_no=response[i+6].slice(13,strlength);
		    	//alert(max_connection_no);
		 	strlength=response[i+7].length;
		    	free_conneciton_no=response[i+7].slice(8,strlength);		    	
		    	//alert(free_conneciton_no)
		 	strlength=response[i+8].length;
		    	server_status=response[i+8].slice(14,strlength);
		    	//alert(server_status);
		    	server_domain=response[i+9].slice(14);
		
			i=i+10;
			HTML_str+='<tr>';
			HTML_str+='<td width="10" align="left"><p style="margin-left: 5"><font face="Arial"> <font size="2">'+user_no+'</font></td>';
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="servername"'+
			' id=servername'+user_no+' size="'+inputcellsize+'" value="'+
			servername+'"/></font></td>';
				
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="username"'+
			' id=username'+user_no+' size="'+inputcellsize+'" value="'+
			username+'"/></font></td>';
			
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="password"'+
			' id=password'+user_no+' size="'+inputcellsize+'" value="'+
			szpassword+'"/></font></td>';
	
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="server_domain"'+
			' id=server_domain'+user_no+' size="'+inputcellsize+'" value="'+
			server_domain+'"/></font></td>';

			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="server_ip"'+
			' id=server_ip'+user_no+' size="'+inputcellsize+'" value="'+
			server_ip+'"/></font></td>';
	
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="panel_port"'+
			' id=panel_port'+user_no+' size="'+inputcellsize+'" value="'+
			panel_port+'"/></font></td>';
	
			HTML_str+='<td width="'+cellsize+'" align="center">'+
			' <font face="Arial" font size="2">'+
			' <input style="padding: 5px;height:30;" type="text" name="country"'+
			' id=country'+user_no+' size="'+inputcellsize+'" value="'+
			country+'"/></font></td>';
		 		
			HTML_str+='<td width="'+cellsize+'" align="center" id=max_connection_no'+user_no+'>'+
			'<font face="Arial" size="2">'+max_connection_no+'</font></td>';
			HTML_str+='<td width="'+cellsize+'" align="center" id=free_conneciton_no'+user_no+'>'+
			'<font face="Arial" color="#0000FF" size="2">'+free_conneciton_no+'</font></td>';
			if (server_status==1)
			{
				HTML_str+='<td width="'+cellsize+'" align="center" id=server_status'+user_no+'>'+
				'<font face="Arial" size="2">ON</font></td>';
			}else if (server_status==2)
			{
				HTML_str+='<td width="'+cellsize+'" align="center" id=server_status'+user_no+'>'+
				'<font color="#00FF00" face="Arial" size="2">Checking</font></td>';
			}
			else {
				HTML_str+='<td width="'+cellsize+'" align="center" id=server_status'+user_no+'>'+
				'<b><font color="#FF0000" face="Arial" size="2">OFF</font></b></td>';
			}
			 HTML_str+='<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=call_Update_Blancer("'+user_no+'")><img src="/admin/save.png"></img></a></td>';
			HTML_str+='<td>'+"<a href='javascript:void(0)'"+
			' onclick=call_Del_Balancer("'+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>';
		if (balancertype>0)
		{
		menustr='<table width=100%><tr>';
		menustr+='<td width="4%">';
		menustr+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
    				
    				menustr+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>New Balancer</b></font></td><td colspan=2 align=right id=add_balancer_dialog_message name=add_balancer_dialog_message></td></tr>';
				menustr+='<tr><td  colspan="4"><hr size="1" color="#000000"></td></tr>';

				menustr+='<tr><td><font face="Arial" font size="2">Slaver Name: </font></td><td>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="servername"'+
				 	' id=servername'+
				 	' size="16"/'+
				 	'</font></td>';
				menustr+='<td><font face="Arial" font size="2">Admin. Name: </font></td><td>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="username"'+
				 	' id=username'+
				 	' size="16"/'+
				 	'</font></td></tr>';
				menustr+='<tr><td><font face="Arial" font size="2">Password: </font></td><td>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="password"'+
				 	' id=password'+
				 	' size="16"/'+
				 	'</font></td>';
				menustr+='<td><font face="Arial" font size="2">Domain: </font></td><td>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="server_domain"'+
				 	' id=server_domain'+
				 	' size="16"/'+
				 	'</font></td></tr>';
				menustr+='<tr><td><font face="Arial" font size="2">IP: </font></td><td >'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="server_ip"'+
				 	' id=server_ip'+
				 	' size="16"/'+
				 	'</font></td>';
				menustr+='<td><font face="Arial" font size="2">Panel port: </font></td><td>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="panel_port"'+
				 	' id=panel_port'+
				 	' size="16"/'+
				 	'</font></td></tr>';
				menustr+='<tr><td><font face="Arial" font size="2">Country: </font></td><td>'+
				 	' <font face="Arial" size="2">'+
				 	' <input style="padding: 5px;height:30;" type="text" name="country"'+
				 	' id=country'+
				 	' size="16"/'+
				 	'</font></td>';
				menustr+='<td></td><td>'+
				 	'</td></tr>';
				
				menustr+='<tr><td colspan=2><input id=add_balancer_button style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Blancer() name="Add" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_balancer_modal() name="Cancel" /></td></tr>';
				menustr+='</table>'+
				'</div>'+
				'</div></td>';	

				//menustr+='<tr><td><input type="button" value="Add" onclick=call_Add_Blancer() name="Save" /></td></tr></table>'+
				//'</div>'+
			//'</div></td>';
			
		menustr+='</tr></table>';
		      
		      
		 }else
	 	{
			menustr='<table width=100%><tr><td width=100% align=right></td>'+
			'</tr></table>';
	 	}
		 	
		 content.innerHTML=menustr+HTML_str;
		 if (g_add_balancer_flag==1)
		{
			open_modal();
		}
		g_add_balancer_flag=0;
		g_balancer_server_no=total_user_no;
	}
 }

 
}
function callServer_balancer_Inquery() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	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_balancer_list?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Balancer Loading...<p>';


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

}
function create_enigma_chlist()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
     if (response.length>1)
    {
    	alert(response);
    }else
    {		
  	alert("Failed to Create");
   }
   callServer_group_Inquery();
    	
    	
  }
}
function create_m3u8_ch_list()
{
 
 if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response.length>1)
    {
    	alert(response);
    }else
    {		
  	alert("Failed to Create");
   }
   callServer_group_Inquery();
    	
  }
}
function create_xbmc_ch_list()
{
 
 if (xmlHttp.readyState == 4) {
   var response = xmlHttp.responseText;
     if (response.length>1)
    {
   	alert(response);
    }else
    {		
  	alert("Failed to Create");
   }
   callServer_group_Inquery();
    	
    	
  }
}

function call_create_enigma_chlist() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	g_token=find_cookie_value("token");
  	var service_type;
  	
  	service_type=prompt("Please enter Service Type","1:0:1:0:0:0:0:0:0:0");
  	if (service_type!=null)
  	{

	 cgi_url = "/server/create_enigma_ch_list?token="+encodeURI(g_token)+"&hostname="+location.hostname+"&enigma_serveice_parm="+service_type+"&flag="+Math.random();
	 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Creating Enigma Channel List...<p>';
	
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = create_enigma_chlist;
	 xmlHttp.send(null);
	 }

}
function call_create_m3u8_chlist() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	g_token=find_cookie_value("token");

 cgi_url = "/server/create_m3u8_ch_list?token="+encodeURI(g_token)+"&hostname="+location.hostname+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Creating M3U8 Channel List...<p>';


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

}
function call_create_xbmc_chlist() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	g_token=find_cookie_value("token");

 cgi_url = "/server/create_xbmc_ch_list?token="+encodeURI(g_token)+"&hostname="+location.hostname+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Creating XBMC Channel List...<p>';


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

}

function group_inquery()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var group_no;
    var group_name;
    var group_peroid;
    var group_credit_unit;
    var group_connections=1;
    var group_src;
    var group_mc_src;
    var group_sc_src;
    var group_title="<p>"+"Group List"+"</p>";
    var group_list;
    var i=0;
 	var group_active_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
	var str;
	var cc_name;
	var cc_selected;
	var mc_name;
	var mc_selected;
	var sc_name;
	var sc_selected;
	var menustr1;
 //   var detail = parent.document.getElementById("detail");
	var content;
	var cellsize="8%";
	var categorycellsize="20%";
	var QRCode_icon_path="";
	var icon_path;
	
	var ezcontent= document.getElementById("content");
	ezcontent.innerHTML='<div id="ezmenucontent"></div>';
	/* var menu_screen= document.getElementById("ezmenu");
	document.getElementById("menu_title_text").innerHTML='<font face="Arial" color=#000000 size="6">Group</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()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Add Group</button>'; 
	str+='</div>';                              
	menu_screen.innerHTML=str; 
	*/
	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>Bouquet</b></font>';
	}else
	{
		str+='<td width="80%"><font face="Arial" color="#000000" size="4"><b>Bouquet</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()">Add Bouquet</a>';
		    str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="Button_Server_group_Inquery()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 

		str+='</div>'; 
		
	str+='</td>';
	
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;
	
	content = parent.document.getElementById("ezmenucontent");
	//content = parent.document.getElementById("ezmenucontent");
	//content.innerHTML="";

	//content.innerHTML="";
	 HTML_str= '<table border="0"   cellpadding="0" cellspacing="10" align="center">'+
	  '<tr>'+
	      '<td width="100" align="center"><font face="Arial" size="2"><b></font></b></td>'+
	      '<td width="'+cellsize+'" align="cneter"><font face="Arial" size="2"><b>Bouquet Name</b></font></td>'+
	      '<td width="'+categorycellsize+'" align="center"><font face="Arial" size="2"><b>Channel Category</b></font></td>'+
	      '<td width="'+categorycellsize+'" align="center"><font face="Arial" size="2"><b>Movie Category</b></font></td>'+
 	      '<td width="'+categorycellsize+'" align="center"><font face="Arial" size="2"><b>Series Category</b></font></td>'+
 	      '<td width="'+categorycellsize+'" align="center"><font face="Arial" size="2"><b>Period(days)</b></font></td>'+
 	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Credit unit</b></font></td>'+
	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>QRCode</b></font></td>'+
 	      '<td width="'+cellsize+'" align="center"><font face="Arial" size="2"><b>Connections</b></font></td>'+
 	 '</tr>';
 	 HTML_str+='<tr><td colspan="3"></td><td  colspan="6"><font face="Arial" size="2">(Hold Ctrl or Shift to select multiple categories)</font></td></tr>';
 	HTML_str+='<tr><td  colspan="9"><hr size="1" color="#66FFFF"></td></tr>';
 	
	while (1)
	{
 	 	if (response[i]==0) break;
//		alert(response[i]);
	 	strlength=response[i].length;
	 	//alert(strlength);
   	    	group_no=response[i].slice(3,strlength);
     	 	strlength=response[i+1].length;
   	    	group_name=response[i+1].slice(5,strlength);
    	 	
    	    	
     	 	strlength=response[i+2].length;
   	    	group_src=response[i+2].slice(7,strlength);

     	 	strlength=response[i+3].length;
  	    	group_mc_src=response[i+3].slice(7,strlength);
  
     	 	strlength=response[i+4].length;
  	    	group_sc_src=response[i+4].slice(7,strlength);
  	    	
	 	strlength=response[i+5].length;
   	    	group_peroid=response[i+5].slice(7,strlength);
  
    	 	strlength=response[i+6].length;
   	    	group_credit_unit=response[i+6].slice(5,strlength);

   	 	strlength=response[i+7].length;
   	    	icon_path=response[i+7].slice(4,strlength);
   	    	
   	    	if (icon_path.indexOf("file://")!==-1)
   	    	{
   	    		QRCode_icon_path=icon_path.slice(7);
   	    	}else
   	    	{
   	    		QRCode_icon_path=icon_path;
   	    		
   	    	}

    	 	strlength=response[i+8].length;
   	    	group_connections=response[i+8].slice(11,strlength);
   	    	//alert(group_connections);
   
 		i=i+9;
		group_active_no++;
		HTML_str=HTML_str+
		   '<tr>'+
		      '<td width="20" align="center"><font face="Arial" size="2">'+group_no+'</font></td>'+
		      '<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;" type="text" name="groupname"'+
	 		' id=groupname'+group_no+
	 		' size="16" value="'+
	 		group_name+'"/></font></td>';
				 		
		     	HTML_str+='<td width="'+categorycellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+' <select multiple style="text-indent: 5;min-width: 180px;" name="groupccsrc" id=groupccsrc'+group_no+'>';
	 		while (1)
	 		{
	 			str=group_src.search('=');
	 			if (str>0)
	 			{
	 				cc_name=group_src.substring(0,str);
	 				cc_selected=group_src.substring(str+1,str+2);
	 				//alert(mc_name);
	 				//alert(mc_selected);
	 				if (cc_selected==1)
	 				{
	 					HTML_str+='<option style="padding: 2px" selected="selected" value="'+cc_name+'">'+decodeURI(cc_name)+'</option>';
	 				}else
	 				{
	 					HTML_str+='<option style="padding: 2px" value="'+cc_name+'">'+decodeURI(cc_name)+'</option>';
	 				}
	 				group_src=group_src.substring(str+3);
	 			}else
	 				break;
	 			
	 		}
			HTML_str+='</select></font></td>';    
			HTML_str+='<td width="'+categorycellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+' <select multiple style="text-indent: 5;min-width: 180px;" name="groupmcsrc" id=groupmcsrc'+group_no+'>';
	 		while (1)
	 		{
	 			str=group_mc_src.search('=');
	 			if (str>0)
	 			{
	 				mc_name=group_mc_src.substring(0,str);
	 				mc_selected=group_mc_src.substring(str+1,str+2);
	 				//alert(mc_name);
	 				//alert(mc_selected);
	 				if (mc_selected==1)
	 				{
	 					HTML_str+='<option style="padding: 2px" selected="selected" value="'+mc_name+'">'+decodeURI(mc_name)+'</option>';
	 				}else
	 				{
	 					HTML_str+='<option style="padding: 2px" value="'+mc_name+'">'+decodeURI(mc_name)+'</option>';
	 				}
	 				group_mc_src=group_mc_src.substring(str+3);
	 			}else
	 				break;
	 			
	 		}
			HTML_str+='</select></font></td>';
	 		
	 		HTML_str+='<td width="'+categorycellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+' <select multiple style="text-indent: 5;min-width: 180px;" name="groupscsrc" id=groupscsrc'+group_no+'>';
	 		while (1)
	 		{
	 			str=group_sc_src.search('=');
	 			if (str>0)
	 			{
	 				sc_name=group_sc_src.substring(0,str);
	 				sc_selected=group_sc_src.substring(str+1,str+2);
	 				//alert(sc_name);
	 				//alert(sc_selected);
	 				if (sc_selected==1)
	 				{
	 					HTML_str+='<option style="padding: 2px" selected="selected" value="'+sc_name+'">'+decodeURI(sc_name)+'</option>';
	 				}else
	 				{
	 					HTML_str+='<option style="padding: 2px" value="'+sc_name+'">'+unescape(sc_name)+'</option>';
	 				}
	 				group_sc_src=group_sc_src.substring(str+3);
	 			}else
	 				break;
	 			
	 		}
			HTML_str+='</select></font></td>';
	 		
	 		HTML_str+='<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30; type="text" name="groupperoid"'+
	 		' id=groupperoid'+group_no+
	 		' size="3" value="'+
	 		group_peroid+'"/></font></td>'+
	 		'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30; type="text" name="groupcreditunit"'+
	 		' id=groupcreditunit'+group_no+
	 		' size="3" value="'+
	 		group_credit_unit+'"/></font></td>'+
	 		'<td width="'+"50px"+'" style="text-align: center; vertical-align: middle;">'+
		        '<a href="javascript:void(0)" onclick=open_icon_edit_modal("4","'+group_no+'","'+icon_path+'")>'+'<img id="QRCode_icon_path_'+group_no+'" style="padding: 5px;width:35px; height:35px" src="'+QRCode_icon_path+'"</img>'+'</a>'+
	 		'</td>'+
	 		'<td width="'+cellsize+'" align="center" style="display:none;">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30;"  type="text" title="'+icon_path+'" name="iconpath"'+
	 		' id=iconpath'+group_no+
	 		' size="3" value="'+
	 		icon_path+'"/></font></td>'+
	 		'<td width="'+cellsize+'" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input style="padding: 5px;height:30; type="text" name="groupconnections"'+
	 		' id=groupconnections'+group_no+
	 		' size="5" value="'+
	 		group_connections+'"/></font></td>'+
			'<td align="right">'+
	 		"<a href='javascript:void(0)'"+
			' onclick=callServer_update_group("'+group_no+'")><img src="/admin/save.png"></img></a></td>'+
			'<td>'+"<a href='javascript:void(0)'"+
			' onclick=onclick=call_Del_group("'+group_no+'")><img src="/admin/del.png"></img></a>'+
	 		'</td>';
		      
		    '</tr>';
     }
        //detail.innerHTML=HTML_str;
      // alert(menu_main.innerHTML);
  
  	menustr1='<td width="4%">';
		menustr1+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
    								
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr><td  colspan=2 align=left><font face="Arial" size="6"><b>New Bouquet</b></font></td><td colspan=2 align=right id=add_group_dialog_message name=add_group_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">Bouquet Name</font></td><td width="25%" height="23">'+
				' <font face="Arial" size="2">'+
				' <input  style="padding: 5px;height:30;" type="text" name="groupname"'+
				' id="groupname"'+
				' size="16" />'+
				'</font></td>';
				menustr1+='<td width="25%"><font face="Arial" size="2">Max Connection</font></td><td width="25%">'+
				 		' <font face="Arial" size="2">'+
				 		' <input  style="padding: 5px;height:30;" type="text" name="group_connection"'+
				 		' id=group_connection'+
				 		' size="16"/>'+
				 		'</font></td></tr>';
				
			
			
				menustr1+='<tr><td width="25%"><font face="Arial" size="2">Period(days) : </font></td><td width="25%">'+
				 		' <font face="Arial" size="2">'+
				 		' <input  style="padding: 5px;height:30;" type="text" name="group_peroid"'+
				 		' id=group_peroid'+
				 		' size="16"/>'+
				 		'</font></td>';

				menustr1+='<td width="25%"><font face="Arial" size="2">Credit Unit</font></td><td width="25%">'+
				 		' <font face="Arial" size="2">'+
				 		' <input  style="padding: 5px;height:30;" type="text" name="group_credit_unit"'+
				 		' id=group_credit_unit'+
				 		' size="16"/>'+
				 		'</font></td></tr>';
			
				menustr1+='<tr><td colspan=2><input style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Group() name="Add" /></td>'+
				'<td align=right  colspan=2><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_modal() name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';	
				// QRCode path
				menustr1+='<td width="4%">';
				menustr1+='<div id="PanelModalICONURLEdit" class="modal">'+
				'<div class="modal-content">';
    				menustr1+='<table  cellpadding="0" cellspacing="10" align="center">';
				menustr1+='<tr>'+
				'<td align=left><font face="Arial" size="6"><b>New / Edit QRCode</b></font></td><td align=right id=icon_url_edit_dialog_message name=icon_url_edit_dialog_message></td></tr>';
				
				menustr1+='<tr><td colspan="2"><hr size="1" color="#000000"></td></tr>';	
					
				menustr1+='<tr><td colspan="2"><b>QRCode from URL or Local File</b></td></tr>';	
				// HTTP URL
				menustr1+='<tr><td width=50%><font face="Arial"> <font size="2">HTTP URL</font></td>'+
				'<td width=50% height="23">'+
		 		' <font face="Arial"> <font size="2">'+
		 		' <input  style="text-indent: 5;height:26;color:#00000" type="text" name="edit_icon_url"'+
		 		' id="edit_icon_url"'+
		 		' size="40" placeholder="http://"/></font></td></tr>';
		 		// Upload Local FIles
				menustr1+='<tr><td>'+'<font face="Arial" size="2">Local File : </font>'+'</td><td><form id="file_upload" enctype="multipart/form-data">'+
				'<input type="file" name="Video"/>'+
				'</form></td></tr>';

			
				menustr1+='<tr><td width=50%><input id=submitbutton style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Save" onclick=call_Edit_ICON(4) name="Submit" /></td>'+
				'<td width=50% ><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_icon_edit_modal() id=cancel_button name="Cancel" /></td></tr>';
				menustr1+='</table>'+
				'</div>'+
				'</div></td>';

			
  	content.innerHTML='<table width=100%><tr>'+
 	menustr1+
	'</tr></table>'+HTML_str+'<tr><td><p style="margin-top: 100"></td></tr></table>';
	g_total_group_no=group_active_no;
	if (g_add_group_flag==1)
	{
		open_modal();
	}
	g_add_group_flag=0;
	 
 }

 
}

function callServer_group_Inquery() {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
//    var detail = parent.document.getElementById("detail");
	var content = parent.document.getElementById("content");
  	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_group?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">Group Information Loading...<p>';


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

}
function 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+9;
		group_active_no++;
	}
	g_total_group_no=group_active_no;
 	call_get_users_detail();
 }

 
}

function group_inquery_item_for_add()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var group_name;
    var i=0;
	var group_active_no=0;
	
	while (1)
	{
 	 	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+8;
		group_active_no++;
	}
	g_total_group_no=group_active_no;
 	call_Add_New_User_detail(g_cur_userno);
 }

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


    var response = xmlHttp.responseText.split("\r\n");
    var group_name;
    var i=0;
	var group_active_no=0;
	
	while (1)
	{
 	 	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+5;
		group_active_no++;
	}
	g_total_group_no=group_active_no;
 	call_Add_Multiple_User(g_cur_userno);
 }

 
}
function call_Add_New_Multiple_User(userno) {
  	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
    	g_token=find_cookie_value("token");
	g_cur_userno=userno;

  //	username_id="username"+userno;
    //	g_username_item=document.getElementById(username_id);

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

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

}
function server_shutdown(){
  var login_status = document.getElementById("login_status");

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
      if (response==1)
    {
//	 login_status.innerHTML='<font face="Arial" color="#FF0000" size="4">EZserver Closed</font>';  
    	alert("Shutdown Ezserver Sucessfully");
    } else
    {
   	alert("Failed to Restart EZserver");
    }
 }
}
function callserver_shutdown()
{
// var login_status = document.getElementById("login_status");
// var ret=login_status.innerHTML.search("Logout");
   var shutdown_status = document.getElementById("content");
var confirm_msg="Shutdown Ezserver?";
 var login_area = document.getElementById("login_area");
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;

	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;

      	g_token=find_cookie_value("token");
      	if (g_token!=0)
      	{

		cgi_url = "/server/shutdown?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		if (confirm(confirm_msg))
		{
			shutdown_status.innerHTML='';
			// login_status.innerHTML='<font face="Arial" color="#FF0000" size="4">EZserver Closing...</font>';  
			 xmlHttp.open("GET", cgi_url, true);
			 xmlHttp.onreadystatechange = server_shutdown;
			 xmlHttp.send(null);
		}
	}
 	
}
function restart_ezserver(){
  var restart_status = document.getElementById("content");

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
      if (response==1)
    {
    	alert("Restarted EZserver and re-login Sucessfully");
 	login();
   } else
    {
   	alert("Failed to Restart EZserver");
     }
  //   restart_status.innerHTML='<p align="center"><font face="Arial" size="3"><a style="text-decoration:none" '+"href='javascript:void(0)'"+' onclick=callserver_restart()>Restart</a></font>';  
 }
}
function callserver_restart()
{
  var restart_status = document.getElementById("content");
// var ret=login_status.innerHTML.search("Logout");
 var confirm_msg="Restart EZserver?";
 //var login_area = document.getElementById("login_area");
	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
	bSystem_Inquery_Panel=0;
	bQuery_Channel_Status=0;
	bQuery_Online_Player=0;
	bGet_Channel_Statistics=0;
      	g_token=find_cookie_value("token");
      	if (g_token!=0)
      	{

		cgi_url = "/server/restart_ezserver?token="+encodeURI(g_token)+"&flag="+Math.random();
		
		if (confirm(confirm_msg))
		{
			// login_status.innerHTML='<font face="Arial" color="#FF0000" size="4">EZserver Closing...</font>';  
			 xmlHttp.open("GET", cgi_url, true);
			 xmlHttp.onreadystatechange = restart_ezserver;
			 xmlHttp.send(null);
			 restart_status.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="2">Restarting</font>'; 
		}

	}
 	
}
function open_middleware_windows()
{
	var middleware_url='http://'+location.host+'/middleware/index.htm';
	window.open(middleware_url);

}
function get_uptime()
{
   var home_field= parent.document.getElementById("home_field");
    var strlength;
 
   
	if (xmlHttp.readyState == 4) 
	{
		var response = xmlHttp.responseText;
		
		if (response.length>0)
		{
   			home_field.innerHTML="<a href='javascript:void(0)' onclick=show_uptime()>"+'<font face="Arial" size="2">'+response+'</font>'+'<a>';
   		}else
   		{
   			// clearInterval(g_server_timer);
   		}
   			
   		

	}

}
function show_uptime()
{
	var time_delay=5000;

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

	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange =get_uptime ;
	xmlHttp.send(null);
	
	//setTimeout("show_uptime()",time_delay);
}
function draw_static_progress_bar(canvas_id, used_no, total_no)
{
	var c = document.getElementById(canvas_id);
	var ctx = c.getContext("2d");
	var npercent=Math.ceil(used_no*100/total_no);
	var szpercent=npercent+"%";
	
	
	ctx.fillStyle = "#0000aa";	
	ctx.fillRect(0,0,npercent,16);
	
	ctx.font = "12px Arial";
	ctx.fillStyle = "#000000";
	ctx.fillText(szpercent, npercent+5, c.height/2+5);

	//ctx.fillRect(0,0,progress_bar_width,16);
	//ctx.fillStyle = "#888888";

	/*	ctx.fillStyle = "#000000";
	ctx.fillText(g_total_ch_no, progress_bar_total_no_posx, c.height/2+5);
	*/
	//ctx.fillText(szpercent, c.width/2, c.height/2);
}
function system_info_inquery()
{
    
	if (xmlHttp.readyState == 4) 
	{
    		
		var str;
		var i=0;
  		var content = parent.document.getElementById("content");
  		var ezcontent = parent.document.getElementById("ezcontent");
  		
  		var static_mac_address;
  		var static_network_interface;
  		var static_pagination_limit_number;
  		var static_p2p_option;
  		var static_movie_number;
 		var static_series_number;
  		var static_channel_number
  		var mac_address=null;
  		var network_interface=null;
  		var content;
  		var ez_button;
  		var main_button;
  		var add_cuet_at;
  		var add_cuet;
  		var free_version_flag=0;
  		var static_user_number=0;
  		var active_connection_no=0;
  		var active_channel_no=0;
  		
  		var act_str1;
  		var act_str2;
  		var act_str3;
  		var act_str4;
  		var field_object;
		var filter_flag=0;
		var active_balancer_no=0;
		var mac_flag=0;
		var start_time;
		var group_no=0;
 		var download_bw;
		var upload_bw;
		var total_memory="N/A";
		var free_memory="N/A";;
		var disk_use="N/A";;
		var load_average="N/A";;
		var blacklist_no;
		var active_movies_no=0;
		var active_series_no=0;
		var alert_connection_no=0;
		var coltype;

		var response = xmlHttp.responseText;
		//alert(response);
		if (response.length>0)
		{
   		
			JSONSystemInfo= JSON.parse(response);
	
			version_date=JSONSystemInfo.version_date;
			if (version_date.search("Public")>0)
			{
				g_Ezserver_Version = BLOCKCHAIN_PUBLIC;
				g_workfoldermenuOBj.style.display = "none";
				
			}else if (version_date.search("Private")>0)
			{
				g_Ezserver_Version = BLOCKCHAIN_PRIVATE;
				//g_workfoldermenuOBj.style.display = "none";
				g_blockchain_menuOBj.hidden=false;
				
			}else if (version_date.search("free")>0)
			{
				g_Ezserver_Version = BLOCKCHAIN_FREE;
				g_workfoldermenuOBj.style.display = "none";
			}else if (version_date.search("Balancer ")==0)
			{
				g_Ezserver_Version = BALANCER;
//				document.getElementById("import_xtream_db").style.display = "none";
				//document.getElementById("balancermenu").style.display = "none";
				document.getElementById("add_user_button").style.display = "none";
				document.getElementById("add_android_user_button").style.display = "none";
				document.getElementById("add_mag_user_button").style.display = "none";
				document.getElementById("add_active_code_button").style.display = "none";
				document.getElementById("add_reseller_button").style.display = "none";
				document.getElementById("manage_reseller_button").style.display = "none";
				g_workfoldermenuOBj.style.display = "none";
				g_cloud_menuOBj.hidden=true;
				
			}else if (version_date.search("Standard ")==0)
			{
				g_Ezserver_Version = BLOCKCHAIN_STANDARD;
				//document.getElementById("import_xtream_db").style.display = "none";
				//document.getElementById("balancermenu").style.display = "none";
				//document.getElementById("add_user_button").style.display = "none";
				//document.getElementById("add_android_user_button").style.display = "none";
				//document.getElementById("add_mag_user_button").style.display = "none";
				//document.getElementById("add_active_code_button").style.display = "none";
				document.getElementById("add_reseller_button").style.display = "none";
				document.getElementById("manage_reseller_button").style.display = "none";
				g_workfoldermenuOBj.style.display = "none";
				
				
			}
			//alert(JSONSystemInfo.node_type);
			document.getElementById("version_id").innerHTML = '<font face="Arial" color="#ffffff" size="6">'+'Ezserver '+version_date+'</font>';
			if (JSONSystemInfo.node_type.length>0)
			{
				document.getElementById("menu_title_text").innerHTML = '<font face="Arial" color="#ffff00" size="3">'+JSONSystemInfo.node_type+'('+location.hostname+')</font>';
			}
			//document.getElementById("login_count_text").innerHTML = '<font face="Arial" color="#ffff00" size="3">Login Times: '+JSONSystemInfo.Login_Times+'</font>';
			
			
			mac_address=JSONSystemInfo.mac_address;
			network_interface=JSONSystemInfo.network_interface;
			start_time=JSONSystemInfo.start_time;
			g_uptime=JSONSystemInfo.uptime;
			
			group_no=parseInt(JSONSystemInfo.group_no);
			g_user_no=parseInt(JSONSystemInfo.user_no);
			g_expired_user_no=parseInt(JSONSystemInfo.expired_user_no);
			active_connection_no=parseInt(JSONSystemInfo.active_connection_no);
			alert_connection_no=parseInt(JSONSystemInfo.alert_connection_no);
			blacklist_no=parseInt(JSONSystemInfo.blacklist_no);
			g_total_ch_no=parseInt(JSONSystemInfo.total_ch_no);
			active_channel_no=parseInt(JSONSystemInfo.active_channel_no);
			g_total_movie_no=parseInt(JSONSystemInfo.total_movie_no);
			g_total_series_no=parseInt(JSONSystemInfo.total_series_no);
			active_series_no=g_total_series_no;
			active_movies_no=parseInt(JSONSystemInfo.active_movies_no);
			g_constant_limit=parseInt(JSONSystemInfo.constant_limit);
			g_total_xmltv_no=parseInt(JSONSystemInfo.total_xmltv_no);
			g_total_provider_no=parseInt(JSONSystemInfo.total_provider_no);
			//alert(g_total_xmltv_no);
			
			g_P2P_Option=parseInt(JSONSystemInfo.P2P_Option);
			if (JSONSystemInfo.transcoder_setting_option)
			{
				g_transcoder_setting_option= 1;
			}
			filter_flag=JSONSystemInfo.filter_flag;
			g_balancer_no=parseInt(JSONSystemInfo.balancer_no);
			g_plus=parseInt(JSONSystemInfo.plus);
			
			/*if (g_plus==1)
			{
				g_balancer_menuOBj.hidden=false;
			}
			*/
			//g_balancer=JSONSystemInfo.balancer;
			g_TMDB_IMG_URL=JSONSystemInfo.TMDB_IMG_URL;
			download_bw=JSONSystemInfo.download_bw;
			memory=JSONSystemInfo.memory;
			upload_bw=JSONSystemInfo.upload_bw;
			disk_use=JSONSystemInfo.disk_use;		
			load_average=JSONSystemInfo.load_average;
			g_channel_genre=JSONSystemInfo.genre;
			g_movie_genre=JSONSystemInfo.movie_genre;
			g_series_genre=JSONSystemInfo.series_genre;
			
	  		
			str='';
			if (bMobileDevice)
			{
				coltype="column-1";
			}else
			{
				coltype="column-3";
			}
			str+='<div class="row">';
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<a href="javascript:calllist_auto_active_player_info(false)"><img src="/admin/dashborard_rect.png" style="width:100%;"></a>';
					  str+='<div class="center-left"><img src="/admin/play.PNG" width=35 height=35></img></div>';
					  str+='<div class="center-text-right"><b>'+active_connection_no+'</b></div>';
					  str+='<div class="center-right">Online Connections</div>';
				  str+='</div>';
			  str+='</div>';
			  var active_user=parseInt(g_user_no)-parseInt(g_expired_user_no);
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<a href="javascript:Button_get_all_user()()"><img src="/admin/dashborard_rect_user.png" style="width:100%;"></a>';
					  str+='<div class="center-left"><img src="/admin/user.PNG" width=35 height=35></img></div>';
					  str+='<div class="center-text-right"><b>'+active_user+'</b></div>';
					  str+='<div class="center-right">Active Users</div>';
				  str+='</div>';
			  str+='</div>';
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<a href="javascript:Button_Server_CH_Inquery()"><img src="/admin/dashborard_rect_channel.png" style="width:100%;"></a>';
					  str+='<div class="center-left"><img src="/admin/channel.PNG" width=35 height=35></img></div>';
					  str+='<div class="center-text-right"><b>'+active_channel_no+'</b></div>';
					  str+='<div class="center-right">Active Channels</div>';
				  str+='</div>';
			  str+='</div>';
			  
		       str+='<div class="row">';
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<a href="javascript:Button_alert_player_info()"><img src="/admin/dashborard_rect_alert.png"   style="width:100%;"></a>';
					  str+='<div class="center-left"><img src="/admin/alert.PNG" width=35 height=35></img></div>';
					  str+='<div class="center-text-right"><b>'+alert_connection_no+'</b></div>';
					  str+='<div class="center-right">Alert Connections</div>';
				  str+='</div>';
			  str+='</div>';
			  
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<img src="/admin/dashborard_rect_upload.png"   style="width:100%;">';
					  str+='<div class="center-left"><img src="/admin/net_output.PNG" width=35 height=35></img></div>';
					  str+='<div class="center-text-right"><b>'+download_bw+'</b> <font size=2>Mbps</font></div>';
					  str+='<div class="center-right">Network Output</div>';
				  str+='</div>';
			  str+='</div>';
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<img src="/admin/dashborard_rect_download.png"   style="width:100%;">';
					  str+='<div class="center-left"><img src="/admin/net_input.PNG" width=35 height=35></img></div>';
					  str+='<div class="center-text-right"><b>'+upload_bw+'</b> <font size=2>Mbps</font></div>';
					  str+='<div class="center-right">Network Input</div>';
				  str+='</div>';
			  str+='</div>';
			str+='</div>';
			
			if (bMobileDevice)
			{
				coltype="column-1";
			}else
			{
				coltype="column-2";
			}
		       str+='<div class="row">';
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<center><canvas id="CPUChart" style="width:50%;max-width:900px"></canvas>';
					  
				  str+='</div>';
			  str+='</div>';
			  
			  str+='<div class="'+coltype+'">';
				  str+='<div class="container_img">';
					  str+='<canvas id="NetworkChart" style="width:50%;max-width:900px"></canvas>';
				  str+='</div>';
			  str+='</div>';
			str+='</div>';
			
			
			content.innerHTML=str;
			fill_cpu_menory_disk();
			draw_cpu_menory_disk();
			draw_network();
			
			
			g_active_channel_no=active_channel_no;
			//alert(g_totoal_server_ip_no);
			if (g_totoal_server_ip_no == 0)
			{
				
				Get_Server_Multiple_IP();
			}
			//else
			//{
				//get_balancer();
			//}
			
		}else {
  			bSystem_Inquery_Panel=0;
  			clearInterval(g_System_timer);	
  			g_System_timer=0;		
		    	g_token=find_cookie_value("token");
		  	g_user_id=find_cookie_value("userid");
		  	g_password=find_cookie_value("password");
		 	 cgi_url = "/token/destroytoken?token="+encodeURI(g_token)+"&flag="+Math.random();
			 xmlHttp.open("GET", cgi_url, true);
			 xmlHttp.onreadystatechange = login_out_return;
			 xmlHttp.send(null);
		}
						

	}

}
/*
async function callServer_System_Inquery_Timer()
{
	var time_delay=5000;
	g_start_search_option=0;
	
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	str+='<td width="50%"><font face="Arial" color="#000000" size="4"><b>DashBoard --- </b>Uptime '+g_uptime+'</font>';
	str+='</td>';
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;;
	
	if (bSystem_Inquery_Panel==0)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
		// alert("Clear Status Timer");
	}else
	{
		bQuery_Channel_Status=0;
		bQuery_Online_Player=0;
		bGet_Channel_Statistics=0;
	    	cgi_url= "/server/json_system_info?token="+encodeURI(g_token)+"&flag="+Math.random();
		const response = await new Promise((resolve, reject) => {
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange =system_info_inquery ;
			xmlHttp.send(null);
		});
		
		if (g_System_timer==0)
		{
			g_System_timer=setInterval(function(){callServer_System_Inquery_Timer()},60*1000);
		}
	}	
	//setTimeout("show_uptime()",time_delay);
}

async function get_balancer() {
    var g_url = "/server/get_balancer?token=" + encodeURI(g_token) + "&flag=" + Math.random();
    
    console.log("get_balancer URL: " + g_url);
    g_token = find_cookie_value("token");
    if (g_token != 0) {
        console.log("Token found, making request...");
        const response = await new Promise((resolve, reject) => {
            xmlHttp.open("GET", g_url, true);
            xmlHttp.onreadystatechange = function() {
                if (xmlHttp.readyState == 4) {
                    console.log("XMLHttpRequest completed. Status: " + xmlHttp.status);
                    var response = xmlHttp.responseText;
                    console.log("Response: " + response);
                    if (response.length > 0) {
                        JSONSystemInfo = JSON.parse(response);
                        g_balancer = JSONSystemInfo.balancer;
                        console.log("Balancer set: " + g_balancer);
                    }
                    resolve(response);
                }
            };
            xmlHttp.send(null);
        });
    } else {
        console.log("Token not found.");
    }
}

async function callServer_System_Inquery() {
    console.log("Calling callServer_System_Inquery...");
    bSystem_Inquery_Panel = 1;
    await callServer_System_Inquery_Timer();
    console.log("After callServer_System_Inquery_Timer, calling get_balancer...");
    await get_balancer();
    console.log("get_balancer call completed.");
}
*/
function callServer_System_Inquery_Timer()
{
	var time_delay=5000;
 //	var search_field= document.getElementById("title_search_field");
//	var search_button= document.getElementById("title_search_button");
//	search_field.hidden=true;
//	search_button.hidden=true;
	g_start_search_option=0;
	
	var str='<table align="center" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">';
	str+='<tr>'
	str+='<td width="50%"><font face="Arial" color="#000000" size="4"><b>DashBoard --- </b>Uptime '+g_uptime+'</font>';
	str+='</td>';
	str+='</tr>';
	str+='</table>';
	document.getElementById("ezhead").innerHTML=str;;
	
	if (bSystem_Inquery_Panel==0)
	{
		clearInterval(g_System_timer);
		g_System_timer=0;
		// alert("Clear Status Timer");
	}else
	{
		bQuery_Channel_Status=0;
		bQuery_Online_Player=0;
		bGet_Channel_Statistics=0;
	    	cgi_url= "/server/json_system_info?token="+encodeURI(g_token)+"&flag="+Math.random();
	
		xmlHttp.open("GET", cgi_url, true);
		xmlHttp.onreadystatechange =system_info_inquery ;
		xmlHttp.send(null);
		if (g_System_timer==0)
		{
			g_System_timer=setInterval(function(){callServer_System_Inquery_Timer()},60*1000);
		}
	}	
	//setTimeout("show_uptime()",time_delay);
}

function get_balancer()
{

	var g_url = "/server/get_balancer?token="+encodeURI(g_token)+"&flag="+Math.random();
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		 xmlHttp.open("GET", g_url, true);
		 xmlHttp.onreadystatechange = function(){
		 if (xmlHttp.readyState == 4) {
			var response = xmlHttp.responseText;
		        //alert(response);
		        if (response.length>0)
		        {
			   JSONSystemInfo= JSON.parse(response);
			   g_balancer=JSONSystemInfo.balancer;
			   callServer_Init();
			}
		  }
 		};
		xmlHttp.send(null);
	}
}
function callServer_System_Inquery()
{
	bSystem_Inquery_Panel=1;
	callServer_System_Inquery_Timer();
	
	
}
function show_hide_credit_option(user_no)
{
	
	var item_id;
	var item;
	var creditflag_id="checkedflag"+user_no;
	var creditflag;


//	alert(creditflag_id);
	creditflag=document.getElementById(creditflag_id);
//	alert(creditflag);
	if (creditflag.checked==true)
	{	
		item_id="credit"+user_no;
		//item=document.getElementById(item_id)
		//alert(item.value);
		document.getElementById(item_id).disabled=false;
		item_id="credit_unit"+user_no;
		document.getElementById(item_id).disabled=false;
	}else
	{
		item_id="credit"+user_no;
		//item=document.getElementById(item_id)
		//alert(item.value);
		document.getElementById(item_id).disabled=true;
		item_id="credit_unit"+user_no;
		document.getElementById(item_id).disabled=true;
	}
		
}







function call_Add_New_Reseller()
{

var HTML_str;
var user_no;
var len;
var paymodel;
var str;
  var content = parent.document.getElementById("content");
	

	g_reseller_no++;

	HTML_str=content.innerHTML;
	//alert(HTML_str);
	//len=HTML_str.length-16;
	len=HTML_str.lastIndexOf("<TABLE");
	
	if (len==-1)
	{
		len=HTML_str.lastIndexOf("<table");
	}
		
		//HTML_str=HTML_str.slice(800,len);
		//alert(HTML_str);
//	alert(len);
	//len+=6;
	HTML_str=HTML_str.slice(0,len);

	user_no=g_reseller_no;
//	alert(HTML_str);
	HTML_str=HTML_str+'<tr><td><table><tr>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">'+user_no+'</font></td>';
			HTML_str+='<td width="20%" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="username"'+
	 		' id=username'+user_no+' size="36"/></font></td>';
 			
	
	 		
		      HTML_str+='<td id=add_id_button align="left">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Reseller("'+user_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a>'+
	      	      
		      //'<td align="left">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Reseller()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="de.png"></a></td>'+

		    '</tr></table></td></tr>';
	//alert(HTML_str);

	       content.innerHTML=HTML_str+'</table>';
  //      alert(user_list_info.innerHTML);
   
		
}

function Disable_Player_Filter_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    
    	call_player_filter();
    }
 
}
function Checked_Rejected_Player_Filter_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    	call_player_filter();
    }
 
}
function Checked_Accepted_Player_Filter_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    	call_player_filter();
    }
 
}

function checked_disable_player_filter()
{
	 confirm_msg="Disable User Agent ?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/disable_player_filter?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Disable_Player_Filter_Respponse;
		 xmlHttp.send(null);
	 }else
	{
		call_player_filter();
	}
	 	
 }
function checked_rejected_player_filter()
{
	 confirm_msg="Change Mode to Rejected Mode?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/checked_rejected_player_filter?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Checked_Rejected_Player_Filter_Respponse;
		 xmlHttp.send(null);
	} else
 	{
 		call_player_filter();
 	}
}
function checked_accepted_player_filter()
{
	 confirm_msg="Change Mode to Accepted Mode?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/checked_accepted_player_filter?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Checked_Accepted_Player_Filter_Respponse;
		 xmlHttp.send(null);
	} else
 	{
 		call_player_filter();
 	}
}

function get_player_filter()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var playername;
    var szpassword;
    var user_title="<p>"+"Reseller List"+"</p>";
    var user_list;
    var i=0;
    var user_no=1;
	var total_user_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
   var content = parent.document.getElementById("content");
 
  	var menustr;
  	var playerfiltertype;

	var content;
	var cellsize="15%";
	
	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>'
	var action_width="80%";
	if (bMobileDevice)
	{
		action_width="20%";
	}
	str+='<td width="'+action_width+'"><font face="Arial" color="#000000" size="4"><b>User Agent</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()">Add User Agent</a>';
		    
		    str+='<div class="menudropdown"  style="background-color: #E26498">';
		    str+='<button class="dropbtn" onclick="call_player_filter()">'; 
		    str+='<i class="fa fa-refresh"></i>';
		    str+='</button>';
		str+='</div>'; 

		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">User Agent</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()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Add</button>'; 
		str+='<button class="button" onclick="call_player_filter()"><p align="left" style="margin-left: 15; margin-top: 0; margin-bottom: 0">Refresh</button>'; 
	str+='</div>';                              
	menu_screen.innerHTML=str; 
	*/
	content = parent.document.getElementById("ezmenucontent");
	content.innerHTML="";
	
	 HTML_str= '<table border="0"  cellpadding="0" cellspacing="10" align="center">';
	
	while (1)
	{
 	 	if (response[i]==0) break;
//		alert(response[i]);
		if (i==0)
		{
		 	strlength=response[i].length;
	   	    	playerfiltertype=response[i].slice(17,strlength);
	   	    	//alert(playerfiltertype);
	   	    	if (playerfiltertype==0)
	   	    	{
	   	    		
				 HTML_str+= '<tr><td colspan="3"><font face="Arial" size="2"><input type="radio" value="V1" checked name="R1" onclick="javascript:checked_disable_player_filter()"><b>Disabled Mode</b><input type="radio" name="R1" value="V3" onclick="javascript:checked_rejected_player_filter()"><b>Rejected Mode</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_accepted_player_filter()"><b>Accepted Mode</b></font></td></tr>';
			        HTML_str+='</tr>'+'<tr><td  colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
	   	    	}else if (playerfiltertype==1)
	   	    	{
				 HTML_str+= '<tr><td width=100% align=center colspan="3"><font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_player_filter()"><b>Disabled Mode</b><input type="radio" name="R1" value="V3" onclick="javascript:checked_rejected_player_filter()"><b>Rejected Mode</b><input type="radio" name="R1" value="V4" checked onclick="javascript:checked_accepted_player_filter()"><b>Accepted Mode</b></font></td></tr>';
			        HTML_str+='</tr>'+'<tr><td width=100% align=center colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
			      HTML_str+='<tr>'+'<td width="10%" align="center"><font face="Arial" size="2">No.</font></td>';
			      HTML_str+='<td width="20%" align="center"><font face="Arial" size="2"><b>Player Name</b></font></td></tr>';
	   	    	}else if (playerfiltertype==2)
	   	    	{
				 HTML_str+= '<tr><td width=100% align=center colspan="3"><font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_player_filter()"><b>Disabled Mode</b><input type="radio" name="R1" value="V3" checked onclick="javascript:checked_rejected_player_filter()"><b>Rejected Mode</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_accepted_player_filter()"><b>Accepted Mode</b></font></td></tr>';
			        HTML_str+='</tr>'+'<tr><td width=100% align=center   colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
			      HTML_str+='<tr>'+'<td width="10%" align="center"><font face="Arial" size="2">No.</font></td>';
			      HTML_str+='<td width="20%" align="center"><font face="Arial" size="2"><b>Player Name</b></font></td></tr>';
	   	    	}  
	   	    	i=i+1;	
		       // HTML_str+='</tr>'+'<tr><td  colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
	  		
		}else
		{
		 	strlength=response[i].length;
	   	    	playername=response[i].slice(11,strlength);
	 		i=i+1;
			HTML_str=HTML_str+
			   '<tr>';
		//alert(user_no);
	 		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=playername'+user_no+'>'+
	 		' <font face="Arial" font size="2">'+decodeURI(playername)+'</font></td>'+	
		      '<td width="'+cellsize+'" align="left">'+
			      "<a href='javascript:void(0)'"+
			      ' onclick=call_Del_Player_Filter("'+user_no+'")>'+
		      	      ' <img border="0" id="delbutton" alt="Del" title="Delete" src="/admin/del.png"></a></td>'+
			    '</tr>';
			total_user_no++;
			user_no++;
			//alert(HTML_str);
		}
    	}
        HTML_str=HTML_str+'</table>';
       //  alert(user_list_info.innerHTML);
       if (playerfiltertype==0)
       {
       		menustr='<table cellpadding="0" cellspacing="10" align="center"><tr><td width=20%></td></tr></table>';
      	}else
	{
		menustr='<table cellpadding="0" cellspacing="10" align="center"><tr>';
	    
	      	menustr+='<td width="4%">';
		menustr+='<div id="PanelModal" class="modal">'+
				'<div class="modal-content">';
		    		menustr+='<table align="center" cellspacing="10" align="center">';
				menustr+='<tr><td align="left"><font face="Arial" size="6"><b>New User Agent</b></font></td><td></td></tr>';
				menustr+='<tr><td  colspan="2"><hr size="1" color="#000000"></td></tr>';
		 				
				menustr+='<tr><td  width="25%"><font face="Arial" font size="2">User Agent: </font></td><td width="75%">'+
				 	' <font face="Arial" size="2">'+
				 	' <input type="text" name="playername"'+
				 	' id=playername'+
				 	' size="36"/'+
				 	'</font></td></tr>';			
		menustr+='<tr><td width=50%><input style="margin-top:10px;width:100%;height:30;background-color: #5089DE;color: #ffffff;" type="button" value="Add" onclick=call_Add_Player_Filter() name="Add" /></td>'+
		'<td  width=50%><input type="button" style="margin-top:10px;width:100%;height:30;background-color: #98A6AD;color: #ffffff;" value="Cancel" onclick=close_modal() name="Cancel" /></td></tr>';
		menustr+='</table>'+
		'</div>'+
		'</div></td>';	

		//menustr+='<td  valign="top"><p style="margin-top: 10"><Input type="button" value="Refresh" onclick="javascript:call_player_filter();" />'+
	      //'</td>'+
		//'<td align=right width=10%>'+'<p style="margin-right: 5"><font face="Arial"> <font size="2">Total: '+ total_user_no+'</td>'+
		'</tr></table>';
      }
	 content.innerHTML=menustr+HTML_str;
	g_player_filter_no=total_user_no;
 }

 
}
function call_player_filter() {
 	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_player_filter?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">User Agent Loading...<p>';

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

}
function Cancel_Add_Player_Filter()
{
	call_player_filter();

}

function Add_Player_Filter() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
     } else if (response==0)
    {
   	alert("Failed to Add User Agent");
    } else if (response==2)
    {
    	alert("Disk is error(FULL), Please contact administrator");
    }else if (response==3)
    {
    	alert("The User Agent is already in Database");
    }

	call_player_filter();
    }
}

function call_Add_Player_Filter(user_no)
{

 var playername_id="playername"; 
 var playername;
 
 	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(playername_id);
	playername=g_item.value;
	if (playername.length==0)
	{
		alert("User Agent is empty");
		return;
	}

   	g_token=find_cookie_value("token");

 cgi_url = "/server/add_player_filter_item?token="+encodeURI(g_token)+"&playername="+encodeURI(playername)+"&flag="+Math.random();
 //  alert(cgi_url);
 	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Add_Player_Filter;
	 xmlHttp.send(null);


}

function call_Add_New_Player_Filter()
{

var HTML_str;
var user_no;
var len;
var paymodel;
var str;
  var content = parent.document.getElementById("content");
	

	g_player_filter_no++;

	HTML_str=content.innerHTML;
	//alert(HTML_str);
	//len=HTML_str.length-16;
	len=HTML_str.lastIndexOf("<TABLE");
	
	if (len==-1)
	{
		len=HTML_str.lastIndexOf("<table");
	}
		
		//HTML_str=HTML_str.slice(800,len);
		//alert(HTML_str);
//	alert(len);
	//len+=6;
	HTML_str=HTML_str.slice(0,len);

	user_no=g_player_filter_no;
//	alert(HTML_str);
	HTML_str=HTML_str+'<tr><td><table><tr>'+
		      '<td width="10%" align="center"><font face="Arial" size="2">'+user_no+'</font></td>';
			HTML_str+='<td width="20%" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="playername"'+
	 		' id=playername'+user_no+' size="36"/></font></td>';
 			
	
	 		
		      HTML_str+='<td id=add_id_button align="left">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Player_Filter("'+user_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a>'+
	      	      
		    //  '<td width="80" align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Player_Filter()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+

		    '</tr></table></td></tr>';
	//alert(HTML_str);

	       content.innerHTML=HTML_str+'</table>';
  //      alert(user_list_info.innerHTML);
   
		
}
function Del_Player_Filter() {

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

function call_Del_Player_Filter(user_no)
{
 var playername_id="playername"+user_no; 
 var playername;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
 
	g_item=document.getElementById(playername_id);
	playername=g_item.innerText;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Delete User Agent: "+playername+"?";
 cgi_url = "/server/del_player_filter_item?token="+encodeURI(g_token)+"&playername="+encodeURI(playername)+"&flag="+Math.random();
 //  alert(cgi_url);
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Del_Player_Filter;
	 xmlHttp.send(null);
 }
 

}
function Disable_Mac_Blocker_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    
    	call_mac_blocker();
    }
 
}

function Checked_Accepted_Mac_Blocker_Respponse() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    	call_mac_blocker();
    }
 
}

function checked_disable_mac_blocker()
{
	 confirm_msg="Disable MAC ID Blocker ?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/disable_mac_blocker?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Disable_Mac_Blocker_Respponse;
		 xmlHttp.send(null);
	 }else
	{
		call_mac_blocker();
	}
	 	
}

function checked_accepted_mac_blocker()
{
	 confirm_msg="Change Mode to Accepted Mode?";
	 if (confirm(confirm_msg))
	 {
		 cgi_url = "/server/checked_accepted_mac_blocker?token="+encodeURI(g_token)+"&flag="+Math.random();	
		 xmlHttp.open("GET", cgi_url, true);
		 xmlHttp.onreadystatechange = Checked_Accepted_Mac_Blocker_Respponse;
		 xmlHttp.send(null);
	} else
 	{
 		call_mac_blocker();
 	}
}

function get_mac_blocker()
{
 
 if (xmlHttp.readyState == 4) {


    var response = xmlHttp.responseText.split("\r\n");
    var macid;
    var szpassword;
    var user_title="<p>"+"MAC ID List"+"</p>";
    var user_list;
    var i=0;
    var user_no=1;
	var total_user_no=0;
	var HTML_str='';
	var strlength=0;
	var pos=0;
   var content = parent.document.getElementById("content");
 
  	var menustr;
  	var macblockertype;

	content.innerHTML="";
	//detail.innerHTML="";
	
	content.innerHTML="";
	 HTML_str= '<table border="0" width=100% cellpadding="3" align="center">';
	
	while (1)
	{
 	 	if (response[i]==0) break;
//		alert(response[i]);
		if (i==0)
		{
		 	strlength=response[i].length;
	   	    	macblockertype=response[i].slice(15,strlength);
	   	    	//alert(playerfiltertype);
	   	    	if (macblockertype==0)
	   	    	{
	   	    		
				 HTML_str+= '<tr><td colspan="3"><font face="Arial" size="2"><input type="radio" value="V1" checked name="R1" onclick="javascript:checked_disable_mac_blocker()"><b>Disabled Mode</b><input type="radio" name="R1" value="V4" onclick="javascript:checked_accepted_mac_blocker()"><b>Accepted Mode</b></font></td></tr>';
			        HTML_str+='</tr>'+'<tr><td  colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
	   	    	}else if (macblockertype==1)
	   	    	{
				 HTML_str+= '<tr><td colspan="3"><font face="Arial" size="2"><input type="radio" value="V1" name="R1" onclick="javascript:checked_disable_mac_blocker()"><b>Disabled Mode</b><input type="radio" name="R1" value="V4" checked onclick="javascript:checked_accepted_mac_blocker()"><b>Accepted Mode</b></font></td></tr>';
			        HTML_str+='</tr>'+'<tr><td colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
			      HTML_str+='<tr>'+'<td width="10%" align="center"><font face="Arial" size="2">No.</font></td>';
			      HTML_str+='<td width="50%" align="center"><font face="Arial" size="2">Accepted MAC ID (Format 12 bytes: aa:bb:cc:dd:ee:ff--->aabbccddeeff)</font></td></tr>';
	   	    	}  
	   	    	i=i+1;	
		        HTML_str+='</tr>'+'<tr><td  colspan="3"><hr size="1" color="#66FFFF"></td></tr>';
	  		
		}else
		{
		 	strlength=response[i].length;
	   	    	macid=response[i].slice(6,strlength);
	 		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="50%" align="center">'+
	 		' <font face="Arial" font size="2">'+
	 		' <input type="text" name="macid"'+
	 		' id=macid'+user_no+' size="36" value="'+
	 		macid+'"/></font></td>'+	
			      '<td align="left">'+
			      "<a href='javascript:void(0)'"+
			      ' onclick=call_Del_Mac_Blocker("'+user_no+'")>'+
		      	      ' <img border="0" id="delbutton" alt="Del" title="Delete" src="del_icon.PNG"></a></td>'+
			    '</tr>';
			total_user_no++;
			user_no++;
			//alert(HTML_str);
		}
    	}
        HTML_str=HTML_str+'</table>';
       //  alert(user_list_info.innerHTML);
       if (macblockertype==0)
       {
 		menustr='<table width=99%><tr><td width=20%>'+'<font face="Arial"> <font size="2">Total: '+ total_user_no+'</td></tr></table>';
      	}else
	{
		menustr='<table width=99%><tr><td width=20%>'+'<font face="Arial"> <font size="2">Total: '+ total_user_no+'</td>'+
	      /*
	      "<td width=80% align=right> <a href='javascript:void(0)' onclick=call_mac_blocker()>"+
	      ' <font face="Arial" size="2">Refresh</font></a>'+
	      "<td width=80% align=right> <a href='javascript:void(0)' onclick=call_Add_New_Mac_Blocker()>"+
	      ' <font face="Arial" size="2">Add</font></a>'+
	*/
	     "<td width=80% align=right>"+
	      '<Input type="button" value="Refresh" onclick="javascript:call_mac_blocker();" />'+
 	      '<Input type="button" value="Add" onclick="javascript:call_Add_New_Mac_Blocker();" />'+	     
	      '</td></tr></table>';
      }
	 content.innerHTML=menustr+HTML_str+menustr;
	g_mac_blocker_no=total_user_no;
 }

 
}
function call_mac_blocker() {
 	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_mac_blocker?token="+encodeURI(g_token)+"&flag="+Math.random();
 content.innerHTML='<p align="center"><font face="Arial" color="#FF0000" size="4">MAC Address Loading...<p>';

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

}
function Cancel_Add_Mac_Blocker()
{
	call_mac_blocker();

}

function Add_Mac_Blocker() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response==1)
    {
    //	alert("Add MAC ID Sucessfully");
    } else if (response==0)
    {
   	alert("Failed to Add MAC ID");
    } else if (response==2)
    {
    	alert("Disk is error(FULL), Please contact administrator");
    }else if (response==3)
    {
    	alert("The MAC ID is already in Database");
    }

	g_item.value=g_temp;
	g_item.style.backgroundColor = "#ffffff";
	//alert(add_id_button.innerHTML);
	call_mac_blocker();
    }
}

function call_Add_Mac_Blocker(user_no)
{

 var macid_id="macid"+user_no; 
 var macid;
 


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(macid_id);
	macid=g_item.value;
	if (macid.length==0)
	{
		alert("MAC ID is empty");
		return;
	}else if (macid.length!=12)
	{
		alert("MAC ID Lenght must be 12 bytes");
		return;		
	}
	

   	g_token=find_cookie_value("token");

 confirm_msg="Add MAC ID: "+macid+" ?";
 cgi_url = "/server/add_mac_blocker_item?token="+encodeURI(g_token)+"&macid="+encodeURI(macid)+"&flag="+Math.random();
 //  alert(cgi_url);
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Add_Mac_Blocker;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	 g_item.value=g_item.value+" (Adding...)";
	g_item.style.backgroundColor = "#ff0000";
 }


}

function call_Add_New_Mac_Blocker()
{

var HTML_str;
var user_no;
var len;
var paymodel;
var str;
  var content = parent.document.getElementById("content");
	

	g_mac_blocker_no++;

	HTML_str=content.innerHTML;
	//alert(HTML_str);
	//len=HTML_str.length-16;
	len=HTML_str.lastIndexOf("<TABLE");
	
	if (len==-1)
	{
		len=HTML_str.lastIndexOf("<table");
	}
		
		//HTML_str=HTML_str.slice(800,len);
		//alert(HTML_str);
//	alert(len);
	//len+=6;
	HTML_str=HTML_str.slice(0,len);

	user_no=g_mac_blocker_no;
//	alert(HTML_str);
	HTML_str=HTML_str+'<tr><td><table><tr>'+
		      '<td width="18%" align="center"><font face="Arial" size="2">'+user_no+'</font></td>';
			HTML_str+='<td width="42%" align="center">'+
	 		' <font face="Arial" size="2">'+
	 		' <input type="text" name="macid"'+
	 		' id=macid'+user_no+' size="36"/></font></td>';
 			
	
	 		
		      HTML_str+='<td id=add_id_button width="80" align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=call_Add_Mac_Blocker("'+user_no+'")>'+
	      	      ' <img border="0" id="addbutton" alt="Add" title="Add" src="add_icon.PNG"></a>'+
	      	      
		      //'<td width="40" align="center">'+
		      "<a href='javascript:void(0)'"+
		      ' onclick=Cancel_Add_Mac_Blocker()>'+
	      	      ' <img border="0" id="delbutton" alt="Cancel" title="Cancel" src="del_icon.PNG"></a></td>'+

		    '</tr></table></td></tr>';
	//alert(HTML_str);

	       content.innerHTML=HTML_str+'</table>';
  //      alert(user_list_info.innerHTML);
   
		
}
function Del_Mac_Blocker() {

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

function call_Del_Mac_Blocker(user_no)
{
 var macid_id="macid"+user_no; 
 var macid;

var confirm_msg;
 	var cgi_url;
	var cookieStr;
	var firstpos;
	var endpos;
 
 
	g_item=document.getElementById(macid_id);
	macid=g_item.value;
	
   	g_token=find_cookie_value("token");

 confirm_msg="Delete MAC ID: "+macid+" ?";
 cgi_url = "/server/del_mac_blocker_item?token="+encodeURI(g_token)+"&macid="+encodeURI(macid)+"&flag="+Math.random();
  // alert(cgi_url);
 if (confirm(confirm_msg))
 {
	
	 xmlHttp.open("GET", cgi_url, true);
	 xmlHttp.onreadystatechange = Del_Mac_Blocker;
	 xmlHttp.send(null);
	 g_temp=g_item.value;
	 g_item.value=g_item.value+" (del...)";
	g_item.style.backgroundColor = "#ff0000";
 }
 

}

function Export_User_Profile() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response.length>0)  
    {
     	window.onbeforeunload=function(){null};
	    	window.location =response; 
	    	window.onbeforeunload = function() {
			if (find_cookie_value("token"))
			{
		        	return "Are you sure you want to leave?";
		        }
		 } 
    }
  }
}
function call_export_user_profile()
{
	var cgi_url;
	
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/export_user_profile?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Export_User_Profile;
	xmlHttp.send(null); 

}
function Export_Channel_Definition() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response.length>0)
    
    {
    	window.onbeforeunload=function(){null};
	    	window.location =response; 
	    	window.onbeforeunload = function() {
			if (find_cookie_value("token"))
			{
		        	return "Are you sure you want to leave?";
		        }
		 } 
    }
}
}

function call_export_channel_definition()
{
	var cgi_url;
	
	bQuery_Channel_Status=0;
	g_token=find_cookie_value("token");
	cgi_url = "/server/export_channel_definition?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Export_Channel_Definition;
	xmlHttp.send(null); 

}

function change_all_transcoder_options()
{
	if (document.getElementById("transcoder_enable_option").checked==true)
	{
		document.getElementById("abr").disabled=false;
		document.getElementById("gpuffmpeg").disabled=false;
		document.getElementById("cuda").disabled=false;
		document.getElementById("videoformat").disabled=false;
	   	document.getElementById("audioformat").disabled=false;
		document.getElementById("preset").disabled=false;
		document.getElementById("videoaspect").disabled=false;
		document.getElementById("output_resoultion_x").disabled=false;
		document.getElementById("output_resoultion_y").disabled=false;
		document.getElementById("output_bitrate").disabled=false;
		document.getElementById("abr").disabled=false;
		document.getElementById("gpuffmpeg").disabled=false;
		document.getElementById("cuda").disabled=false;
		document.getElementById("custom_cmd").disabled=false;
		document.getElementById("output_custom_cmd").disabled=false;
	}else
	{
		document.getElementById("abr").disabled=true;
		document.getElementById("gpuffmpeg").disabled=true;
		document.getElementById("cuda").disabled=true;
		document.getElementById("videoformat").disabled=true;
	   	document.getElementById("audioformat").disabled=true;
		document.getElementById("preset").disabled=true;
		document.getElementById("videoaspect").disabled=true;
		document.getElementById("output_resoultion_x").disabled=true;
		document.getElementById("output_resoultion_y").disabled=true;
		document.getElementById("output_bitrate").disabled=true;
		document.getElementById("2nd_output_resoultion_x").disabled=true;
		document.getElementById("2nd_output_resoultion_y").disabled=true;
		document.getElementById("2nd_output_bitrate").disabled=true;
		document.getElementById("3rd_output_resoultion_x").disabled=true;
		document.getElementById("3rd_output_resoultion_y").disabled=true;
		document.getElementById("3rd_output_bitrate").disabled=true;
		document.getElementById("custom_cmd").disabled=true;
		document.getElementById("output_custom_cmd").disabled=true;
		
		document.getElementById("abr").checked=false;
		document.getElementById("gpuffmpeg").checked=false;
		document.getElementById("cuda").checked=false;
		document.getElementById("output_bitrate").value='0';
	}

}

function change_2nd_3rd_option()
{
	//alert(document.getElementById("abr").checked);
	if (document.getElementById("abr").checked==true)
	{
		document.getElementById("2nd_output_resoultion_x").disabled=false;
		document.getElementById("2nd_output_resoultion_y").disabled=false;
		document.getElementById("2nd_output_bitrate").disabled=false;
		document.getElementById("3rd_output_resoultion_x").disabled=false;
		document.getElementById("3rd_output_resoultion_y").disabled=false;
		document.getElementById("3rd_output_bitrate").disabled=false;
	}else
	{
		document.getElementById("2nd_output_resoultion_x").disabled=true;
		document.getElementById("2nd_output_resoultion_y").disabled=true;
		document.getElementById("2nd_output_bitrate").disabled=true;
		document.getElementById("3rd_output_resoultion_x").disabled=true;
		document.getElementById("3rd_output_resoultion_y").disabled=true;
		document.getElementById("3rd_output_bitrate").disabled=true;
	}

}

function get_transcoder_setting_by_category()
{

	var url = "/server/get_transcoder_config?token="+encodeURI(g_token)+
	"&category=" + document.getElementById("transcoder_setting_chcategory").value+"&flag="+Math.random();
		
		
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		 xmlHttp.open("GET", url, true);
		 xmlHttp.onreadystatechange = function(){
		 	if (xmlHttp.readyState == 4) {
			    var response= xmlHttp.responseText.split("\r\n");
			    var i=0;
			    var the_1st_bitrate;
			    var the_2nd_bitrate;
			    var the_3rd_bitrate;
									
			   	
				
				if (response[i]=="1")
				{
			   		document.getElementById("gpuffmpeg").checked=true;
			   	}else
			   	{
			   		document.getElementById("gpuffmpeg").checked=false;
			    	}
				i++;
				if (response[i]=="1")
				{
			   		document.getElementById("cuda").checked=true;
			   	}else
			   	{
			   		document.getElementById("cuda").checked=false;
			   	}
				i++;
				document.getElementById("videoformat").value=response[i];
				i++;
			   	document.getElementById("audioformat").value=response[i];
				i++;
				document.getElementById("preset").value=response[i];
				i++;
				document.getElementById("videoaspect").value=response[i];
				i++;
				//alert(response[i]);
				if (response[i]==0)
				{
					document.getElementById("output_resoultion_x").value="Auto";
				}else
				{
					document.getElementById("output_resoultion_x").value=response[i];
				}
				i++;
				
				if (response[i]==0)
				{
					document.getElementById("output_resoultion_y").value="Auto";
				}else
				{
					document.getElementById("output_resoultion_y").value=response[i];
				}
				i++;
				document.getElementById("output_bitrate").value=response[i];
				the_1st_bitrate=response[i];
				i++;
				
// 2nd
				if (response[i]==0)
				{
					document.getElementById("2nd_output_resoultion_x").value="Auto";
				}else
				{
					document.getElementById("2nd_output_resoultion_x").value=response[i];
				}
				i++;
				if (response[i]==0)
				{
					document.getElementById("2nd_output_resoultion_y").value="Auto";
				}else
				{
					document.getElementById("2nd_output_resoultion_y").value=response[i];
				}
				i++;
				
				the_2nd_bitrate=response[i];
				document.getElementById("2nd_output_bitrate").value=response[i];
				i++;
// 3rd
				if (response[i]==0)
				{
					document.getElementById("3rd_output_resoultion_x").value="Auto";
				}else
				{
					document.getElementById("3rd_output_resoultion_x").value=response[i];
				}
				i++;
				if (response[i]==0)
				{
					document.getElementById("3rd_output_resoultion_y").value="Auto";
				}else
				{
					document.getElementById("3rd_output_resoultion_y").value=response[i];
				}
				i++;
				
				the_3rd_bitrate=response[i];
				document.getElementById("3rd_output_bitrate").value=response[i];
				i++;

				
				if ((the_2nd_bitrate==0) && (the_3rd_bitrate==0))
				{
					
					document.getElementById("abr").checked=false;
					document.getElementById("2nd_output_resoultion_x").disabled=true;
					document.getElementById("2nd_output_resoultion_y").disabled=true;
					document.getElementById("2nd_output_bitrate").disabled=true;
					document.getElementById("3rd_output_resoultion_x").disabled=true;
					document.getElementById("3rd_output_resoultion_y").disabled=true;
					document.getElementById("3rd_output_bitrate").disabled=true;
				}else
				{
					document.getElementById("abr").checked=true;
					document.getElementById("2nd_output_resoultion_x").disabled=false;
					document.getElementById("2nd_output_resoultion_y").disabled=false;
					document.getElementById("2nd_output_bitrate").disabled=false;
					document.getElementById("3rd_output_resoultion_x").disabled=false;
					document.getElementById("3rd_output_resoultion_y").disabled=false;
					document.getElementById("3rd_output_bitrate").disabled=false;
				}
				document.getElementById("custom_cmd").value =response[i];
				i++;
			
				document.getElementById("output_custom_cmd").value =response[i];
				i++;
				if (the_1st_bitrate==0)
				{
					document.getElementById("transcoder_enable_option").checked=false;
					change_all_transcoder_options();
				}else
				{
					document.getElementById("transcoder_enable_option").checked=true;
					change_all_transcoder_options();
				}
			   	
				
			 
			  }
		 };
		 xmlHttp.send(null);
	}
}
function open_transcoder_setting_modal()
{
	var modal = document.getElementById('PanelModalTranscoder');
	modal.style.display = "block";

	var url = "/server/get_transcoder_config?token="+encodeURI(g_token)+"&category=" + document.getElementById("transcoder_setting_chcategory").value+"&flag="+Math.random();
		
		
	g_token=find_cookie_value("token");
	if (g_token!=0)
	{
		 xmlHttp.open("GET", url, true);
		 xmlHttp.onreadystatechange = function(){
		 	if (xmlHttp.readyState == 4) {
			    var response= xmlHttp.responseText.split("\r\n");
			    var i=0;
			    var the_1st_bitrate;
			    var the_2nd_bitrate;
			    var the_3rd_bitrate;
									
			   	
				
				if (response[i]=="1")
				{
			   		document.getElementById("gpuffmpeg").checked=true;
			   	}else
			   	{
			   		document.getElementById("gpuffmpeg").checked=false;
			    	}
				i++;
				if (response[i]=="1")
				{
			   		document.getElementById("cuda").checked=true;
			   	}else
			   	{
			   		document.getElementById("cuda").checked=false;
			   	}
				i++;
				document.getElementById("videoformat").value=response[i];
				i++;
			   	document.getElementById("audioformat").value=response[i];
				i++;
				document.getElementById("preset").value=response[i];
				i++;
				document.getElementById("videoaspect").value=response[i];
				i++;
				//alert(response[i]);
				if (response[i]==0)
				{
					document.getElementById("output_resoultion_x").value="Auto";
				}else
				{
					document.getElementById("output_resoultion_x").value=response[i];
				}
				i++;
				
				if (response[i]==0)
				{
					document.getElementById("output_resoultion_y").value="Auto";
				}else
				{
					document.getElementById("output_resoultion_y").value=response[i];
				}
				i++;
				document.getElementById("output_bitrate").value=response[i];
				the_1st_bitrate=response[i];
				i++;
				
// 2nd
				if (response[i]==0)
				{
					document.getElementById("2nd_output_resoultion_x").value="Auto";
				}else
				{
					document.getElementById("2nd_output_resoultion_x").value=response[i];
				}
				i++;
				if (response[i]==0)
				{
					document.getElementById("2nd_output_resoultion_y").value="Auto";
				}else
				{
					document.getElementById("2nd_output_resoultion_y").value=response[i];
				}
				i++;
				
				the_2nd_bitrate=response[i];
				document.getElementById("2nd_output_bitrate").value=response[i];
				i++;
// 3rd
				if (response[i]==0)
				{
					document.getElementById("3rd_output_resoultion_x").value="Auto";
				}else
				{
					document.getElementById("3rd_output_resoultion_x").value=response[i];
				}
				i++;
				if (response[i]==0)
				{
					document.getElementById("3rd_output_resoultion_y").value="Auto";
				}else
				{
					document.getElementById("3rd_output_resoultion_y").value=response[i];
				}
				i++;
				
				the_3rd_bitrate=response[i];
				document.getElementById("3rd_output_bitrate").value=response[i];
				i++;

				
				if ((the_2nd_bitrate==0) && (the_3rd_bitrate==0))
				{
					
					document.getElementById("abr").checked=false;
					document.getElementById("2nd_output_resoultion_x").disabled=true;
					document.getElementById("2nd_output_resoultion_y").disabled=true;
					document.getElementById("2nd_output_bitrate").disabled=true;
					document.getElementById("3rd_output_resoultion_x").disabled=true;
					document.getElementById("3rd_output_resoultion_y").disabled=true;
					document.getElementById("3rd_output_bitrate").disabled=true;
				}else
				{
					document.getElementById("abr").checked=true;
					document.getElementById("2nd_output_resoultion_x").disabled=false;
					document.getElementById("2nd_output_resoultion_y").disabled=false;
					document.getElementById("2nd_output_bitrate").disabled=false;
					document.getElementById("3rd_output_resoultion_x").disabled=false;
					document.getElementById("3rd_output_resoultion_y").disabled=false;
					document.getElementById("3rd_output_bitrate").disabled=false;
				}
				document.getElementById("custom_cmd").value =response[i];
				i++;
				document.getElementById("output_custom_cmd").value =response[i];
				i++;
			
				if (the_1st_bitrate==0)
				{
					document.getElementById("transcoder_enable_option").checked=false;
					change_all_transcoder_options();
				}else
				{
					document.getElementById("transcoder_enable_option").checked=true;
					change_all_transcoder_options();
				}
				

			   	
				
			 
			  }
		 };
		 xmlHttp.send(null);
	}
}
function close_transcoder_setting_modal() {
   var modal = document.getElementById('PanelModalTranscoder');
   
    modal.style.display = "none";
}
function save_transcoder_setting() {

	
	var bgpuflag= document.getElementById("gpuffmpeg").checked;
	var bcudaflag= document.getElementById("cuda").checked;
	var videoformat= document.getElementById("videoformat").value;
	var audioformat= document.getElementById("audioformat").value;
	var preset= document.getElementById("preset").value;
	var videoaspect= document.getElementById("videoaspect").value;
	var custom_cmd= document.getElementById("custom_cmd").value;
	var output_custom_cmd= document.getElementById("output_custom_cmd").value;
	var output_resoultion_x=document.getElementById("output_resoultion_x").value;
	var output_resoultion_y=document.getElementById("output_resoultion_y").value;
	var output_bitrate= document.getElementById("output_bitrate").value;
	var the_2nd_output_resoultion_x=0;
	var the_2nd_output_resoultion_y=0;
	var the_2nd_output_bitrate=0;
	var the_3rd_output_resoultion_x=0;
	var the_3rd_output_resoultion_y=0;
	var the_3rd_output_bitrate=0;
	
	if (document.getElementById("abr").checked==true)
	{
		the_2nd_output_resoultion_x=document.getElementById("2nd_output_resoultion_x").value;
		the_2nd_output_resoultion_y=document.getElementById("2nd_output_resoultion_y").value;
		the_2nd_output_bitrate= document.getElementById("2nd_output_bitrate").value;
		the_3rd_output_resoultion_x=document.getElementById("3rd_output_resoultion_x").value;
		the_3rd_output_resoultion_y=document.getElementById("3rd_output_resoultion_y").value;
		the_3rd_output_bitrate= document.getElementById("3rd_output_bitrate").value;
	}
	
	document.getElementById("transcoder_setting_dialog_message").innerHTML="";
	
	if ((document.getElementById("transcoder_enable_option").checked==true)&&(output_bitrate<=0))
	{
		document.getElementById("transcoder_setting_dialog_message").innerHTML='<font face="Arial" color=#ff0000 size="2"><b>Warning: Output bitrate must > 0</b></font>';
		
		return;
	}
	var gpuflag;
	var cudaflag;;
	if (bgpuflag)
	{
		gpuflag="1";
	}else
	{
		gpuflag="0";
	}
	if (bcudaflag)
	{
		cudaflag="1";
	}else
	{
		cudaflag="0";
	}
	if ((gpuflag==0)&&(bcudaflag))
	{
		document.getElementById("transcoder_setting_dialog_message").innerHTML='<font face="Arial" color=#ff0000 size="2"><b>Warning: Enable GPU, too</b></font>';
		
		return;		
	}
	
   	g_token=find_cookie_value("token");
	var g_url = "/server/save_transcoder_config?token="+encodeURI(g_token)+
	"&category=" + document.getElementById("transcoder_setting_chcategory").value+
	"&gpuflag=" + encodeURI(gpuflag)+
	"&cudaflag=" + encodeURI(cudaflag)+
	"&videoformat=" + encodeURI(videoformat)+
	"&audioformat=" + encodeURI(audioformat)+
	"&preset=" + encodeURI(preset)+
	"&videoaspect=" + encodeURI(videoaspect)+
	"&mobile_width=" + encodeURI(output_resoultion_x)+
	"&mobile_height=" + encodeURI(output_resoultion_y)+
	"&output_bitrate=" + encodeURI(output_bitrate)+
	
	"&sd_width=" + encodeURI(the_2nd_output_resoultion_x)+
	"&sd_height=" + encodeURI(the_2nd_output_resoultion_y)+
	"&sd_output_bitrate=" + encodeURI(the_2nd_output_bitrate)+
	
	"&hd_width=" + encodeURI(the_3rd_output_resoultion_x)+
	"&hd_height=" + encodeURI(the_3rd_output_resoultion_y)+
	"&hd_output_bitrate=" + encodeURI(the_3rd_output_bitrate)+
	
	"&custom_cmd=" + encodeURI(custom_cmd)+
	"&output_custom_cmd=" + encodeURI(output_custom_cmd);
	

	
	g_url+="&flag="+Math.random();
    	var confirm_msg="Update Setting?";
	if (g_token!=0)
	{
		if (confirm(confirm_msg))
		{
		   	document.getElementById("transcoder_setting_dialog_message").innerHTML='<font face="Arial" color=#ff0000 size="2"><b>Updating</b></font>';	
			xmlHttp.open("GET", g_url, true);
			
			// Setup a function for the server to run when it's done
				xmlHttp.onreadystatechange = function()
				{
					 if (xmlHttp.readyState == 4) {
					    var response = xmlHttp.responseText;
					   document.getElementById("transcoder_setting_dialog_message").innerHTML='<font face="Arial" color=#ff0000 size="2"><b>Updated</b></font>';
					   }
				}
			
			
			// Send the request
			xmlHttp.send(null);
		}
	}
}
function open_import_modal(no)
{
	var modal = document.getElementById('PanelModalImport');
	modal.style.display = "block";
}
function close_import_modal() {
   var modal = document.getElementById('PanelModalImport');
   var importbutton=document.getElementById("submitbutton");
   
   importbutton.disabled=false;
   importbutton.value="Submit";
   modal.style.display = "none";
   callezserver_all_channel();
}
function open_import_url_modal(no)
{
	var modal = document.getElementById('PanelModalImportURL');
	modal.style.display = "block";
}
function close_import_url_modal() {
	var modal = document.getElementById('PanelModalImportURL');
	var importbutton=document.getElementById("submitbutton");
   
	importbutton.disabled=false;
	importbutton.value="Save";
	modal.style.display = "none";
	var limit=g_constant_limit;
	g_provider_limit=g_constant_limit;
	callServer_Get_Stream_Provider(g_provider_position,g_provider_limit);
}
function call_import_channel_by_upload_file()
{
	var cgi_url;
	var importchno_id="importchno";
	var import_option_id="import_option";
	
	var importchno;
	var import_option;
	var import_server;
	var total_ch_no=0;
	var importbutton=document.getElementById("submitbutton");
	var api_option;

	importbutton.disabled=true;
	importbutton.value="Waiting";
	
	g_item=document.getElementById(importchno_id);
	//alert(g_item.value);
	importchno=g_item.value;
	total_ch_no=importchno;
	g_item=document.getElementById(import_option_id);
	//alert(g_item.value);
	import_option=g_item.value;
	
	

	api_option = "/server/upload_files?token="+escape(g_token)+"&ch_no="+encodeURI(importchno)+"&import_option="+encodeURI(import_option)+"%&filetype="+"channel_m3u"+"&flag="+Math.random();

	call_Upload_Files(event,UPLOAD_CHANNEL_M3U,api_option);
	
		

}
function createRandomString(length) {
    const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    let result = '';
    for (let i = 0; i < length; i++) {
        const randomIndex = Math.floor(Math.random() * characters.length);
        result += characters[randomIndex];
    }
    return result;
}
function call_import_channel_by_url()
{
	var cgi_url;
	var providername_id="providername"
	var importchno_id="importurlchno";
	var importurl_id="importurl";
	var import_option_id="import_url_option";
	var providername;
	var importchno;
	var importurl;
	var import_option;
	var total_ch_no=0;
	var provider_status=0;
	var importbutton=document.getElementById("submitbutton");
	var api_option;
	
	if (document.getElementById("provider_status").checked)
	{
		provider_status=1;
	}
	importbutton.disabled=true;
	importbutton.value="Waiting";
	
	
	g_item=document.getElementById(providername_id);
	//alert(g_item.value);
	providername=g_item.value;
	if (providername.length==0)
	{
		providername=createRandomString(10);
	}
	g_item=document.getElementById(importchno_id);
	//alert(g_item.value);
	importchno=g_item.value;
	total_ch_no=importchno;
	g_item=document.getElementById(importurl_id);
	//alert(g_item.value);
	importurl=g_item.value;
	g_item=document.getElementById(import_option_id);
	//alert(g_item.value);
	import_option=g_item.value;
	
	if (importurl.length>0)
	{
		if (importchno>=0)
		{
			bSystem_Inquery_Panel=0;
			bQuery_Channel_Status=0;
			bQuery_Online_Player=0;
			bGet_Channel_Statistics=0;
		
			g_token=find_cookie_value("token");
			//alert(total_ch_no);
			if (total_ch_no==0)
			{
				importchno=0;
			}
			
			cgi_url = "/server/import_channel?token="+encodeURI(g_token)+"&providername="+encodeURI(providername)+"&ch_no="+encodeURI(importchno)+"&ch_url="+encodeURI(importurl)+"&import_option="+encodeURI(import_option)+"&status="+encodeURI(provider_status)+"&flag="+Math.random();
			//alert(cgi_url);
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = function()
			{
				if (xmlHttp.readyState == 4) {
				    var response = xmlHttp.responseText;
				    //alert(response);
				    	 var import_channel_dialog_message=document.getElementById("import_channel_dialog_message");
				    if (response>0)
				    {
					import_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' channels added</font>';
					g_total_ch_no=parseInt(g_total_ch_no)+parseInt(response);
				    	alert("Restart Ezserver after all providers added");
				    	importbutton.disabled=false;
					importbutton.value="Submit";
				    	close_import_url_modal();
				    } else if (response==0)
				    {
				   	//alert("Failed to Import Channel");
					import_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import Channel</font>';
					importbutton.disabled=false;
					importbutton.value="Submit";
				    }
					
				}
			};
			xmlHttp.send(null); 
		}else
		{
			alert("ch no. < 0");
		}
	}

}
function call_import_channel_definition()
{
	var cgi_url;
	var importchno_id="importchno";
	var importurl_id="importurl";
	var import_option_id="import_option";
	var importchno;
	var importurl;
	var import_option;
	var total_ch_no=0;
	var importbutton=document.getElementById("submitbutton");
	var api_option;
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		alert("Only for Formal version");
		return;
	}
	importbutton.disabled=true;
	importbutton.value="Waiting";
	
	g_item=document.getElementById(importchno_id);
	//alert(g_item.value);
	importchno=g_item.value;
	total_ch_no=importchno;
	g_item=document.getElementById(importurl_id);
	//alert(g_item.value);
	importurl=g_item.value;
	g_item=document.getElementById(import_option_id);
	//alert(g_item.value);
	import_option=g_item.value;
	
	if (importurl.length>0)
	{
		if (importchno>=0)
		{
			bSystem_Inquery_Panel=0;
			bQuery_Channel_Status=0;
			bQuery_Online_Player=0;
			bGet_Channel_Statistics=0;
		
			g_token=find_cookie_value("token");
			//alert(total_ch_no);
			if (total_ch_no==0)
			{
				importchno=0;
			}
			
			cgi_url = "/server/import_channel?token="+encodeURI(g_token)+"&ch_no="+encodeURI(importchno)+"&ch_url="+encodeURI(importurl)+"&import_option="+encodeURI(import_option)+"&flag="+Math.random();
			//alert(cgi_url);
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = function()
			{
				if (xmlHttp.readyState == 4) {
				    var response = xmlHttp.responseText;
				    //alert(response);
				    	 var import_channel_dialog_message=document.getElementById("import_channel_dialog_message");
				    if (response>0)
				    {
					import_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' channels added</font>';
					g_total_ch_no=parseInt(g_total_ch_no)+parseInt(response);
				    	alert("Restart EZserver to get the newest channel list");
				    } else if (response==0)
				    {
				   	//alert("Failed to Import Channel");
					import_channel_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import Channel</font>';
				    }
					importbutton.disabled=false;
					importbutton.value="Submit";
				}
			};
			xmlHttp.send(null); 
		}else
		{
			alert("ch no. < 0");
		}
	}else
	{
		api_option = "/server/upload_files?token="+escape(g_token)+"&ch_no="+encodeURI(importchno)+"&import_option="+encodeURI(import_option)+"%&filetype="+"channel_m3u"+"&flag="+Math.random();

		call_Upload_Files(event,UPLOAD_CHANNEL_M3U,api_option);
	}
		

}
function call_import_movie_definition()
{
	var cgi_url;
	var importmovieno_id="importmovieno";
	var importurl_id="importurl";
	var importmovieno;
	var importurl;
	var import_option_id="import_option";
	var import_option;
	if ((location.hostname == "51.75.72.169") || (location.hostname == "5.75.144.94") || (location.hostname == "www.imoviecity.com"))
	{
		alert("Only for Formal version");
		return;
	}

	var importbutton=document.getElementById("submitbutton");
	importbutton.disabled=true;
	importbutton.value="Waiting";

	g_item=document.getElementById(importmovieno_id);
	//alert(g_item.value);
	importmovieno=g_item.value;
	g_item=document.getElementById(importurl_id);
	//alert(g_item.value);
	importurl=g_item.value;

	g_item=document.getElementById(import_option_id);
	//alert(g_item.value);
	import_option=g_item.value;

	if(importmovieno>=0)
	{
		if (importurl.length>0)
		{
			if (g_total_movie_no==0)
			{
				importmovieno=0;
			}
			
			bSystem_Inquery_Panel=0;
			bQuery_Channel_Status=0;
			bQuery_Online_Player=0;
			bGet_Channel_Statistics=0;
		
			g_token=find_cookie_value("token");
			cgi_url = "/server/import_movie?token="+encodeURI(g_token)+"&movie_no="+encodeURI(importmovieno)+"&import_option="+encodeURI(import_option)+"&movie_url="+encodeURI(importurl)+"&flag="+Math.random();
			
			xmlHttp.open("GET", cgi_url, true);
			xmlHttp.onreadystatechange = function()
			{
				  if (xmlHttp.readyState == 4) {
				    var response = xmlHttp.responseText;
				    	var import_movie_dialog_message=document.getElementById("import_movie_dialog_message");
				    if (response>0)
				    {
					import_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">'+response+' movies added</font>';
					
					g_total_movie_no=parseInt(g_total_movie_no)+parseInt(response);
	
				    } else if (response==0)
				    {
				   	//alert("Failed to Import Movie");
					import_movie_dialog_message.innerHTML='<font size=2 color=#000000 face="Arial">Failed to Import Movie</font>';
				    }
				     }
					importbutton.value="Submit";
				    	importbutton.disabled=false;
			};
			xmlHttp.send(null); 
		}else
		{
			api_option = "/server/upload_files?token="+escape(g_token)+"&movie_no="+encodeURI(importmovieno)+"&import_option="+encodeURI(import_option)+"&filetype="+"movie_m3u"+"&flag="+Math.random();	
			call_Upload_Files(event,UPLOAD_MOVIE_M3U,api_option);
			
		}
	}
		

}
function call_import_channel()
{
	var str;
	var importurl;
	var importchno=g_total_ch_no;
	importurl='';
 
	str="<head><title>Import Channel</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body><table align="center">';
	str+='<tr><td><font face="Arial"> <font size="2">Import M3U URL : </font></td><td width="350" height="23">'+
	' <input type="text" name="importurl"'+
	' id="importurl"'+
	' size="64" value="'+
	importurl+
	'"/></font></td></tr>';
	str+='<tr><td><font face="Arial"> <font size="2">After CH No. : </font></td><td width="350" height="23">'+
	' <input type="text" name="importchno"'+
	' id="importchno"'+
	' size="3" value="'+
	importchno+
	'"/></font></td></tr>';
	str+='<tr><td><font face="Arial"> <font size="2">Options : </font></td><td><select size="1" id="import_option">'+
		'<option value="0">'+"None"+'</option>'+
		'<option value="1">'+"Proxy Mode 1"+'</option>'+
		'<option value="2">'+"Proxy Mode 2"+'</option>'+
		'<option value="3">'+"Proxy Mode 3"+'</option>'+
		'<option selected="selected" value="4">'+"Cache on demand"+'</option>'+
		'</select></font></td></tr>';
 		
    str+='<tr><td><input type="button" value="Import" onclick=call_import_channel_definition() name="B2" /></td></tr></table></body>';  
   // alert(str);
 //alert(g_total_ch_no);
       	 UserDetailWindow= window.open("", "", "top=100, left=100, width=700, height=130"); 
	UserDetailWindow.document.write(str); 

}		


function Export_Movie_Definition() {

  if (xmlHttp.readyState == 4) {
    var response = xmlHttp.responseText;
    if (response.length>0)
    
    {
    	window.onbeforeunload=function(){null};
	    	window.location =response; 
	    	window.onbeforeunload = function() {
			if (find_cookie_value("token"))
			{
		        	return "Are you sure you want to leave?";
		        }
		 } 
    }
}
}
function call_export_movie_definition()
{
	var cgi_url;
	
	
	g_token=find_cookie_value("token");
	cgi_url = "/server/export_movie_definition?token="+encodeURI(g_token)+"&flag="+Math.random();
	
	xmlHttp.open("GET", cgi_url, true);
	xmlHttp.onreadystatechange = Export_Movie_Definition;
	xmlHttp.send(null); 

}

function open_import_movie_modal(no)
{
	var modal = document.getElementById('PanelModalImport');
	modal.style.display = "block";
}
function close_import_movie_modal() {
   var modal = document.getElementById('PanelModalImport');
   var importbutton=document.getElementById("submitbutton");
   
   importbutton.value="Submit";
   importbutton.disabled=false;
   modal.style.display = "none";
   g_movie_position=1;
   g_movie_limit=g_constant_limit;
   call_get_movies(g_movie_position,g_movie_limit);
}

function call_import_movie()
{
	var str;
	var importurl;
	var importmovieno=g_total_movie_no;
	
	importurl='';
 
	str="<head><title>Import Movie</title><link rel='stylesheet' type='text/css' href='menu.css'/>"+'<script src="menu.js"></script></head><body><table align="center">';
	str+='<tr><td><font face="Arial"> <font size="2">Import M3U URL : </font></td><td width="350" height="23">'+
	' <input type="text" name="importurl"'+
	' id="importurl"'+
	' size="64" value="'+
	importurl+
	'"/></font></td></tr>';
	str+='<tr><td><font face="Arial"> <font size="2">After Movie No. : </font></td><td width="350" height="23">'+
	' <input type="text" name="importmovieno"'+
	' id="importmovieno"'+
	' size="3" value="'+
	importmovieno+
	'"/></font></td></tr>';

 	str+='<tr><td><font face="Arial"> <font size="2">Options : </font></td><td><select size="1" id="import_option">'+
		'<option value="0">'+"None"+'</option>'+
		'<option value="1">'+"Proxy"+'</option>'+
		'</select></font></td></tr>';
		
    str+='<tr><td><input type="button" value="Import" onclick=call_import_movie_definition() name="B2" /></td></tr></table></body>';  
  //  alert(str);
 
       	 UserDetailWindow= window.open("", "", "top=100, left=100, width=700, height=130"); 
	UserDetailWindow.document.write(str); 
}


function getDragAfterElement(container, y) {
  const draggableElements = [...container.querySelectorAll("li:not(.dragging)")];

  return draggableElements.reduce((closest, element) => {
    const box = element.getBoundingClientRect();
    const offset = y - box.top - box.height / 2;
    if (offset < 0 && offset > closest.offset) {
      return { offset: offset, element: element };
    } else {
      return closest;
    }
  }, { offset: Number.NEGATIVE_INFINITY }).element;
}

function updateItemIndexes() {
  const listItems = sortable_list.querySelectorAll("li");

	
  listItems.forEach((item, index) => {
    item.setAttribute("data-index", index + 1);
    
  });
}


		