var DragUtil = new Object();
DragUtil.getUserAgent = navigator.userAgent;
DragUtil.isGecko = DragUtil.getUserAgent.indexOf("Gecko") != -1;
DragUtil.isOpera = DragUtil.getUserAgent.indexOf("Opera") != -1;
DragUtil.reCalculate = function(el) {	
	for( var i = 0 ; i < DragUtil.dragArray.length; i++ ) 
	{
		var ele = DragUtil.dragArray[i];
		var position = Position.positionedOffset(ele.elm);
		ele.elm.pagePosLeft = position[0];
		ele.elm.pagePosTop = position[1];
	}
	};
	DragUtil.ghostElement = null ;
	DragUtil.getGhostElement = function(){	
		if(!DragUtil.ghostElement){
			DragUtil.ghostElement = document.createElement("DIV");
			DragUtil.ghostElement.className = "modbox";
			DragUtil.ghostElement.style.border = "1px dotted #aaa";
			DragUtil.ghostElement.innerHTML = "&nbsp;";	
			}	
			return DragUtil.ghostElement;
		};
	var initDrag = function() {	
		var tmpElements = document.getElementsByClassName('drag_div');	
		DragUtil.dragArray = new Array();	
		for(var i = 0 ; i < tmpElements.length ; i++){
			var tmpElement = tmpElements[i];
			var tmpElementId = tmpElement.id;
			var tmpHeaderElementId = tmpElement.id + '_h';
			DragUtil.dragArray[i] = new DragDrop(tmpHeaderElementId , tmpElementId);	
			}
		};
			
			
var _TAG=false;
			
function loading(){
	$("#loading").show();
}
			
function closediv(div){
	$(div).hide();
}	
			
function bar_on(){
	var bar = $('#loading_bar');
	if (bar){
		bar.html('<img src="../misc/images/loading_bar.gif" />');
	}
}

function bar_off(){
	var bar = $('#loading_bar');
	if (bar){
		bar.html('');
	}
}

function reloadPage(){
	location.reload();
}

/*Ajax load page */
function getPage(url,o){
	var request_url=url;
	var divId=o;
//	var myAjax = new Ajax.Updater(divId, request_url,{	  method  : "get",	  evalScripts: true  });
	$.ajax({
		  type: "GET",
		  url: request_url,
		  success:function(msg){
		  	$('#'+divId).html(msg);
		  }
	}); 
}
/*Trim string*/		
function trim(str) {
	return str.replace(/^\s*(.*?)[\s\n]*$/g, '$1');
}
/*display one div*/			
function showwindow(url,width){
	var content = $("#windowcontent");
	$("#windowcontent").show();
	content.html('<div id="clarityDiv"></div>'
		+ '<div id="window" style="width:'+width+'px">'
		+ '<div id="window_content">'
		+ '</div>'
		+ '</div>');			
	getPage(url,'window_content');	
}

function mcalendar(url){
	getPage(url,'window_content');
}

function viewnewsroom(url){
	$('#windowcontent').show();
	window.location.href = url;
}

function check_user_id(){
	var Email = $("#email").val();
//	var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:show_user_check_message});
	$.ajax({
		  type: "GET",
		  url: 'check_user_id.php',
		  data: 'email='+Email,
		  success:function(msg){
		  	$('#email_message').hide();
			$('#user_id_message').html(msg);
		  }
	}); 
}



function check_serial_number(){
	var serial_number = $("#serial_number").val();
	var pars='serial_number='+serial_number;
//	var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:show_serial_number_message});
	$.ajax({
		  type: "GET",
		  url: 'ajax_check_serial_number.php',
		  data: 'serial_number='+serial_number,
		  success:function(msg){
			$('#serial_number_message').html(msg);
			$('#serial_number_message').show();
		  }
	});
}



function check_admin_user_id(){
	var operator_id = $("#operator_id").val();
//	var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:show_admin_user_check_message});
	$.ajax({
		  type: "GET",
		  url: 'check_user_id.php',
		  data: 'operator_id='+operator_id,
		  success:function(msg){
			$('#user_id_message').html(msg);
		  }
	});
}



function check_referred_by(){
	var user_id = $("#referred_by").val();
//	var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:show_referred_message});
	$.ajax({
		  type: "GET",
		  url: 'check_referred_by.php',
		  data: 'user_id='+user_id,
		  success:function(msg){
			$('#referred_by_message').html(msg);
		  }
	});
}


function check_is_feed(){
	$('#is_feed_message').html('<img src="../misc/images/loading_bar.gif>');
	var content_url = $("#url").val();
	var provider_id = $("#provider_id").val();
	$('#promptsave').hide();
	$.ajax({
		type: "GET",
		url: 'check_is_feed.php',
		data: 'url='+content_url+'&provider_id='+provider_id,
		success:function(msg){
			var o = eval('(' + msg + ')'); 
			var status = o.Status;			
			$('#is_feed_message').html(o.message);
			if (status == 'success') {
				$('#rssbody').html('');
				$('#rsslist').append(o.table);
				$('#promptsave').show();
			}
		}
	});
}


function checkpromotion(){
	var promotioncode = $('#promotioncode').val();
//	var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:promotioncode_message});
	$.ajax({
		  type: "GET",
		  url: 'checkpromotion.php',
		  data: 'code='+promotioncode,
		  success:function(msg){
			$('#promotioncode_message').html(msg);
		  }
	});
}


function refresh_rss_feed(){
	var rssURL = $("#url").val();
	var Category_ID = $('#category_id').val();
	var Feed_ID = $('#item_id').val();
	var Provider_ID = $('#provider_id').val();
	
	if (rssURL == '' || Category_ID == '' || Feed_ID == '' || Provider_ID == '')	{
		$('#update_feed_message').html('URL or Category_ID or Feed_ID not exists.');
	}else{
		$.ajax({
		  type: "GET",
		  url: 'update_media_feed.php',
		  data: "rssurl="+rssURL+"&category_id="+Category_ID+"&feed_id="+Feed_ID+"&provider_id="+Provider_ID,
		  success:function(msg){
			$('#update_feed_message').html(msg);
		  }
	});
	}
}



function check_credit_card_number(){
	var Card_Type_ID = $('#card_type_id').val();
	var Card_Number = $('#card_number').val();
	var Expiration_Month = $('#expiration_month').val();
	var Expiration_Year = $('#expiration_year').val();
	var card_type_id_message = $('#card_type_id_message');
	var card_number_message = $('#card_number_message');

	var Holder_Name = $('#holder_name');
	if (Holder_Name.val() != ''){
		$('#holder_name_message').hide();
	}else{
		$('#holder_name_message').show();
	}

	var Security_Code = $('#security_code');
	if (Security_Code.val() != ''){
		$('#security_code_message').hide();
	}else{
		$('#security_code_message').show();
	}

	if (Card_Type_ID == ''){
		card_type_id_message.show();
		card_type_id_message.html('Please Select Card Type.');
		return false;
	}else if (Card_Number == ''){
		card_number_message.show();
		card_type_id_message.hide();
		card_number_message.html('Credit card number can not be empty.');
	}else{
		var post_check_number_message = $('#post_check_number_message');
		post_check_number_message.hide();
		card_number_message.hide();
		card_type_id_message.hide();
		var url = '../user/check_credit_number.php';
//		var pars = 'card_type_id='+Card_Type_ID+'&card_number='+Card_Number+'&expiration_month='+Expiration_Month+'&expiration_year='+Expiration_Year;
//		var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:show_card_number_message});
		$.ajax({
			  type: "GET",
			  url: url,
			  data: 'card_type_id='+Card_Type_ID+'&card_number='+Card_Number+'&expiration_month='+Expiration_Month+'&expiration_year='+Expiration_Year,
			  success:function(msg){
				$('#card_number_message').show();
				$('#card_number_message').html(msg);
			  }
		});
	}
}



function addweather(){
	var City_Code = $('#city_code').val();
	var City_or_Zip = $('#city_or_zip').val();

	if (City_or_Zip == ''){
		alert('Please enter any city in the world or the five gigit U.S. Zip .');
		return false;
	}else{
		$('#addweatherloaing').show();
//		var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:addweather_message});
		$.ajax({
			  type: "GET",
			  url: '../user/ajax_weather.php',
			  data: 'city_or_zip='+City_or_Zip+'&city_code='+City_Code,
			  success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;
				if (status == 'error'){
					alert(o.error);
				}else if(status == 'search'){
					$('#cityselect').html(o.html);
					$('#addweatherloaing').hide();
					return false;
				}else if (status == 'success')	{
					alert('The city information you entered is valid. Click Add to insert city to the list.');
					$('#addweatherloaing').hide();
					/*
					var newdiv = $(document.createElement("div")).addClass("TableBody").html('<ul>'
						+'<li style="width:34%; ">'+o.Location+'</li>'
						+'<li class="LiRightLine" style="width:20%;">'+o.Delete+'</li>'
						+'</ul>');	
					newdiv.appendTo("#weavercontent");			
					//document.getElementById("weavercontent").appendChild(newdiv);
					$('#cityselect').html('');
					$('#weather_form').hide();
					$('#addweatherloaing').hide();
					*/
				}else{

				}
				$('#addweatherloaing').hide();
			  }
		});
	}
}

function addtheater(){
	var City_or_Zip = $('#theater_zip_code').val();
	if (City_or_Zip == ''){
		alert('Please enter any city in the world or the five gigit U.S. Zip .');
		return false;
	}else{
		$('#addtheaterloaing').show();
		$.ajax({
			  type: "GET",
			  url: '../user/ajax_theater.php',
			  data: 'city_or_zip='+City_or_Zip,
			  success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;
			
				if (status == 'error'){
					alert(o.error);
				}else if (status == 'success')	{
					alert(o.message);

					var newdiv = $(document.createElement("div")).addClass("TableBody").html('<ul>'
						+'<li style="width:34%; ">'+o.Location+'</li>'
						+'<li class="LiRightLine" style="width:20%;">'+o.Delete+'</li>'
						+'</ul>');	
					newdiv.appendTo("#theatercontent");			
					$('#theater_cityselect').html('');
					$('#theater_form').hide();
					$('#addtheaterloaing').hide();
				}else{
				
				}
				$('#addtheaterloaing').hide();
			  }
		});
	}
}

function addaddress(){
	var address = $('#tra_address').val();
	var city = $('#tra_city').val();
	var state = $('#tra_state option:selected').text();
	var zipcode = $('#tra_zipcode').val();
	//alert('test '+zipcode);
	if (zipcode == ''){
		alert('Please enter any city in the world or the five gigit U.S. Zip .');
		return false;
	}else{
		$('#addaddressloaing').show();
		$.ajax({
			  type: "GET",
			  url: '../user/ajax_address.php',
			  data: 'address='+address+'&city='+city+'&state='+state+'&zipcode='+zipcode,
			  success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;
			
				if (status == 'error'){
					alert(o.error);
					$('#tra_city').val(o.city);
					$('#tra_state').val(o.state);
				}else if (status == 'success')	{
					alert(o.message);		
						var newdiv = $(document.createElement("div")).addClass("TableBody").html('<ul>'
							+'<li style="width:30%; ">'+o.address+'</li>'
							+'<li class="LiRightLine" style="width:20%;">'+o.city+'</li>'
							+'<li class="LiRightLine" style="width:10%;">'+o.state+'</li>'
							+'<li class="LiRightLine" style="width:15%;">'+o.zipcode+'</li>'
							+'<li class="LiRightLine" style="width:15%;">'+o.Delete+'</li>'
							+'</ul>');	
						newdiv.appendTo("#trafficcontent");	

					$('#traffic_form').hide();
					$('#addaddressloaing').hide();
				}else{
				
				}
				$('#addaddressloaing').hide();
			  }
		});
	}
}

function disable_address(id){
	if ($('#'+id).attr('checked')==undefined)
	{
		//{window.location = "../user/addaddress.php?enable=f&id="+id+"&action=edit";}
		$.ajax({
			type: "GET",
			url: '../user/addaddress.php',
			data: 'enable=f&id='+id+'&action=edit',
			success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;
				if (status == 'error'){
					alert(o.error);
				}else if (status == 'success') {
					alert(o.message);
				}
			}
		});	
	} else {
		//{window.location = "../user/addaddress.php?enable=t&id="+id+"&action=edit";}
		$.ajax({
			type: "GET",
			url: '../user/addaddress.php',
			data: 'enable=t&id='+id+'&action=edit',
			success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;
				if (status == 'error'){
					alert(o.error);
				}else if (status == 'success') {
					alert(o.message);
				}
			}
		});	
	}	
}

function delete_address(id){
	if(confirm('delete thisaddress?'))
	{window.location = "../user/addaddress.php?id="+id+"&action=del";}
}

function addalbum(){
	var album_name = $('#album_name').val();
	var provider_id = $('#provider_id').val();

	if (album_name == ''){
		alert('Please enter  album name .');
		return false;
	}
	if (provider_id == ''){
		alert('Please select a album source .');
		return false;
	}else{
		var url = '../user/ajax_album.php';
		$('#addalbumloaing').show();
		$.ajax({
			  type: "GET",
			  url: url,
			  data: 'album_name='+album_name+'&provider_id='+provider_id,
			  success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;
			
				if (status == 'error'){
					alert(o.error);
				}else if(status == 'search'){
					$('#albumselect').html(o.html);
				}else if (status == 'success')	{
					alert(o.message);
					var newdiv = $(document.createElement("div")).addClass("TableBody").html('<ul>'
						+'<li style="width:25%; ">'+o.Logo+'</li>'
						+'<li style="width:25%; ">'+o.Albumname+'</li>'
						+'<li class="LiRightLine" style="width:25%;">'+o.Delete+'</li>'
						+'</ul>');
					newdiv.appendTo("#albumcontent");
					//document.getElementById("albumcontent").appendChild(newdiv);
					$('#albumselect').html('');
					$('#album_form').hide();
					$('#addalbumloaing').hide();
				}else{
				
				}
				$('#addalbumloaing').hide();
			  }
		});
	}
}

/*This is for ajax_weather dropdown area*/
function get_city(){
	$('#city_or_zip').val($("#cities option:selected").text());
}

function delte_weather_city(id){
	if(confirm('delete this weather?'))
	{window.location = "../user/addweather.php?id="+id+"&action=del";}
}

function delete_theater_city(id){
	if(confirm('delete this theater?'))
	{window.location = "../user/addtheater.php?id="+id+"&action=del";}
}

function addcable(){
	var whataddress = document.getElementById('addressradio_1').checked;
	var Ctv_Account_Number = document.getElementById('ctv_account_number').value;
	var Ctv_Provider_ID = document.getElementById('ctv_provider_id').value;
	var Address_1 = document.getElementById("address_1").value;
	var Address_2 = document.getElementById("address_2").value;
	var City = document.getElementById("city").value;
	var State = document.getElementById("state").value;
	var ZipCode = document.getElementById("zipcode").value;
	var Country = document.getElementById("country").value;
	var Ctv_Address_ID = document.getElementById("ctv_address_id").value;

	if (whataddress == true){
		whataddress = 1;
	}else{
		whataddress = 0;
	}
//	var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:addcable_message});
	$.ajax({
		  type: "GET",
		  url: '../user/addcable.php',
		  data: 'whataddress='+whataddress+'&ctv_account_number='+Ctv_Account_Number+'&ctv_provider_id='+Ctv_Provider_ID+'&address_1='+Address_1+'&address_2='+Address_2+'&city='+City+'&state='+State+'&zipcode='+ZipCode+'&country='+Country+'&ctv_address_id='+Ctv_Address_ID,
		  success:function(msg){
			alert(msg);
		  }
	});
}
////////////////////////////////////////////////////////////////////////////

function invitefriend(){
	var Referee = document.getElementById('referee').value;
	var Email = document.getElementById('email').value;
	var Message = document.getElementById('message').value;
	if (Referee == ''){
		alert('Referee is required.');
	}else if (Email == '')	{
		alert('Email is required.');
	}else{
		if (is_email(Email) == false){
			alert('Please input a valid email address!');
		}else{
			var invitebutton = document.getElementById('invitebutton');
			//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onCreate:function(){bar_on();invitebutton.disabled=true;},onSuccess:function(){bar_off();invitebutton.disabled=false;},onComplete:invitefriend_message});

			$.ajax({
				  type: "GET",
				  url: '../user/ajax_invitefriend.php',
				  data: 'referee='+Referee+'&email='+Email+'&message='+Message,
				  beforeSend:function(){
					  bar_on();
					  invitebutton.disabled=true;
				  },
				  success:function(){
					  bar_off();
					  invitebutton.disabled=false;
				  },
				  complete:function(msg){
					  invitefriend_message(msg);
				  }
			}); 

		}
	}
}

function invitefriend_message(originalRequest){
	//var Status = originalRequest.responseText.evalJSON();
	var Status = eval('(' + originalRequest + ')');
	var r = Status.Status;
	if (r == 1)	{
		alert('Please input a valid email address!');
	}else if (r == 2)	{
		//success
		alert('successfully sent invitations to your friends.');
		//document.getElementById('inviteafriend').style.display = 'none';

		var newdiv = $(document.createElement("ul")).addClass('body');
		var newli1 = $(document.createElement("li"));
		var newli2 = $(document.createElement("li"));
		var newli3 = $(document.createElement("li"));
		newli1.width('30%');
		newli2.width('30%');
		newli3.width('30%');


		var newli1Text = $(document.createTextNode(Status.Referee));
		var newli2Text = $(document.createTextNode(Status.Email));
		var newli3Text = $(document.createTextNode(Status.Message));

		newdiv.appendChild(newli1);
		newli1.appendChild(newli1Text);

		newdiv.appendChild(newli2);
		newli2.appendChild(newli2Text);

		newdiv.appendChild(newli3);
		newli3.appendChild(newli3Text);
		
		newdiv.appendTo("#newreferrail");
		//document.getElementById("newreferrail").appendChild(newdiv);

	}else if(r == 3){
		alert('SMTP server error.');
	}else if(r == 4){
		alert('database error.');
	}else if(r == 5){
		alert('Referee and Email is required.');
	}else if(r == 6){
		alert('you has invited.');
	}else if(r == 7){
		alert('You can only invite 5 friends.');
	}else if(r == 8){
		alert('this email have been registered.');
	}else{
	
	}
}

function edituserinfo(divid,user_id){
	var tr = $('#tr_'+user_id);	
	$('#'+divid).html('<img src="/misc/images/loading.gif">');
	if (tr.attr("class") == 'TableBody3'){
		//tr.toggleClass('TableBody_Over');
		tr.addClass('TableBody_Over');
		var url = 'ajax_edituserinfo.php?user_id='+user_id;
		getPage(url,divid);		
	}else{
		tr.removeClass('TableBody_Over');
		$('#'+divid).html('');
	}	
}

function updateuserinfo(user_id){
	//var user_id = $('#user_id').val();
	var Screen_Name = $('#'+user_id+'_'+'screen_name').val();
	var First_Name = $('#'+user_id+'_'+'first_name').val();
	var Last_Name = $('#'+user_id+'_'+'last_name').val();
	var Is_Owner = $('#is_owner').val();
	var Is_Activate = $('#is_activate').val();
	var MPAA_Rating = $('#mpaa_rating').val();
	var Start_Time = $('#'+user_id+'_'+'start_time').val();
	var End_Time = $('#'+user_id+'_'+'end_time').val();
	var Passwords = $('#'+user_id+'_'+'password').val();
	var Email = $('#'+user_id+'_'+'email').val();

	var Start_Time_to = $('#start_time_to').val();
	var End_Time_to = $('#end_time_to').val();

	var error = 0;

	if (Screen_Name == ''){
		alert('Screen Name is empty.');
		error++;
	}

	if (user_id == '')
	{
		alert('something error.');
		error++;
	}

	if (First_Name == '')
	{
		alert('First Name is required.');
		error++;
	}

	if (Last_Name == '')
	{
		alert('Last Name is required.');
		error++;
	}

	if (error > 0)
	{
		return false;
	}else{
		//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:updateuserinfo_message});
		$('#modifyuserbutton').hide();
		$('#modifyuserload').show();
		$.ajax({
			  type: "GET",
			  url: '../user/ajax_updateuserinfo.php',
			  data: 'user_id='+user_id+'&screen_name='+Screen_Name+'&first_name='+First_Name+'&last_name='+Last_Name
				  +'&is_owner='+Is_Owner+'&is_activate='+Is_Activate+'&mpaa_rating='+MPAA_Rating
				  +'&start_time='+Start_Time+'&end_time='+End_Time+'&passwords='+Passwords+'&email='+Email+'&start_time_to='+Start_Time_to+'&end_time_to='+End_Time_to,
			  success:function(msg){
				  updateuserinfo_message(msg);
			  }
		}); 
	}
}

function updateuserinfo_message(originalRequest){     
    //var o = originalRequest.responseText.evalJSON(); 
	var o = eval('(' + originalRequest + ')');
	if (o.Status == 5)	{
		alert('Account Updated Successfully.');
		var User_Row = $('#user_'+o.user_id);
		User_Row.html('');
		var Userinfo_Row = $('#tr_'+o.user_id);
		Userinfo_Row.removeClass('TableBody_Over');
		Userinfo_Row.addClass('TableBody3');
		var Name_Row = $('#Name_'+o.user_id);
		Name_Row.html(o.First_Name+ ' '+o.Last_Name);

		var Is_Owner_Row = $('#Is_Owner_'+o.user_id);
		Is_Owner_Row.html(o.Is_Owner);

		var Is_Activate_Row = $('#Is_Activate_'+o.user_id);
		Is_Activate_Row.html(o.Is_Activate);

		var MPAA_Rating_Row = $('#MPAA_Rating_'+o.user_id);
		MPAA_Rating_Row.html(o.MPAA_Rating);

		var On_Off_Time_Row = $('#On_Off_Time_'+o.user_id);
		On_Off_Time_Row.html(o.Start_Time+ ' / '+o.End_Time);		
	}else if(o.Status == 3 || o.Status == 4){
		alert('Time Format error.');
		$('#modifyuserbutton').show();
	}else{
		alert(o.Status);
		$('#modifyuserbutton').show();
	}	
	$('#modifyuserload').hide();
}

function addnewuser(divid){
	var url = 'ajax_edituserinfo.php';
	getPage(url,divid);
}

function adduserinfo(){
	var Screen_Name = $('#screen_name').val();
	var First_Name = $('#first_name').val();
	var Last_Name = $('#last_name').val();
	var Is_Owner = $('#is_owner').val();
	var MPAA_Rating = $('#mpaa_rating').val();
	var Start_Time = $('#start_time').val();
	var End_Time = $('#end_time').val();
	var Passwords = $('#password').val();
	var Email = $('#email').val();

	var Start_Time_to = $('#start_time_to').val();
	var End_Time_to = $('#end_time_to').val();
	
	var error = 0;

	if (First_Name == '')
	{
		alert('First Name is required.');
		error++;
	}

	if (Last_Name == '')
	{
		alert('Last Name is required.');
		error++;
	}

	if (Email == '')
	{
		//alert('Email format error.');
		//error++;
	}

	if (Passwords == '')
	{
		alert('Password is required.');
		error++;
	}

	if (error > 0)
	{
		return false;
	}else{
		//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:adduserinfo_message});
		//hide button 
		$('#adduserbutton').hide();
		//show loading gif
		$('#adduserload').show();
		$.ajax({
			  type: "GET",
			  url: '../user/ajax_updateuserinfo.php',
			  data: $('#form_user_info').serializeArray(),
			  success:function(msg){
				  adduserinfo_message(msg);
			  }
		}); 
	}
}

function adduserinfo_message(originalRequest){
    var o = eval('(' + originalRequest + ')');
	if (o.Status == 5)	{
		var User_Row = $(document.getElementById('addnewuser'));
		User_Row.html('');		
		var newdiv = '<div id="tr_'+o.user_id+'" onclick="edituserinfo(\'user_'+o.user_id+'\',\''+o.user_id+'\');" style="cursor: pointer;" class="TableBody3">'+'<ul>'
			+'<li style="width:21%" id="Name_'+o.user_id+'">'+o.First_Name+' '+o.Last_Name+'</li>'
			+'<li style="width:15%" id="Is_Owner_'+o.user_id+'">'+o.Is_Owner+'</li>'
			+'<li style="width:10%" id="Is_Activate_'+o.user_id+'">'+o.Is_Activate+'</li>'
			+'<li style="width:15%" id="MPAA_Rating_'+o.user_id+'">'+o.MPAA_Rating+'</li>'
			+'<li style="width:22%" id="On_Off_Time_'+o.user_id+'">'+o.Start_Time+' / '+o.End_Time+'</li>'
			+'<li style="width:15%" id="Balance_'+o.user_id+'">'+ '0' +'</li>'
			+'</ul></div>'
			+'<div id="user_'+o.user_id+'" class="TableBody_Over_contents"></div>';
		$("#Table2").append(newdiv);
		$('#addnewuser').hide();
		alert('Add user successfully.');
		//document.getElementById("Table2").appendChild(newdiv);		
	}else if(o.Status == 1) {
		alert('First Name is Required.');
		$('#adduserbutton').show();
	}else if(o.Status == 2){
		alert('Last Name is required.');
		$('#adduserbutton').show();
	}else if(o.Status == 3 || o.Status == 4){
		alert('Time format is incorrect.');
		$('#adduserbutton').show();
	}else{
		alert(o.Status);
		$('#adduserbutton').show();
	}	
	$('#adduserload').hide();
}

function suspendaccount(user_id){
	//var user_id = $('#user_id').val();
	//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:suspendaccount_message});
	$('#modifyuserbutton').hide();
	$('#modifyuserload').show();
	$.ajax({
		  type: "GET",
		  url: '../user/ajax_suspendaccount.php',
		  data: 'user_id='+user_id,
		  success:function(msg){
			  suspendaccount_message(msg);
		  }
	});
}

function suspendaccount_message(originalRequest){
	var o = eval('(' + originalRequest + ')');
	if (o.Status == 1)	{
		var Is_Activate_Row = $('#Is_Activate_'+o.user_id);
		Is_Activate_Row.html(o.Is_Activate);
	}else{
		alert(o.Status);
		$('#modifyuserbutton').show();
	}
	var User_Row = $('#user_'+o.user_id);
	User_Row.html('');
	var Userinfo_Row = $('#tr_'+o.user_id);
	Userinfo_Row.addClass('TableBody3');
	Userinfo_Row.removeClass('TableBody_Over');
	$('#modifyuserload').hide();
}

function deleteaccount(user_id){
	//var user_id = $('#user_id').val();
	//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:deleteaccount_message});
	$('#modifyuserbutton').hide();
	$('#modifyuserload').show();
	$.ajax({
		  type: "GET",
		  url: '../user/ajax_deleteaccount.php',
		  data: 'user_id='+user_id,
		  success:function(msg){
			  deleteaccount_message(msg);
		  }
	});
}

function deleteaccount_message(originalRequest){
	var o = eval('(' + originalRequest + ')');
	if (o.Status == 1)	{
		//alert(o.Status);
		var User_Row = $('#user_'+o.user_id);
		User_Row.html('');
		User_Row.hide();
		var Userinfo_Row = $('#tr_'+o.user_id);
		Userinfo_Row.addClass('hidediv');
	}else{
		alert(o.Status);
	}
	$('#modifyuserbutton').show();
	$('#modifyuserload').hide();
}

function authorize_friend(){
	var Email = $('#authorized_email').val();
	var Screen_Name = $('#screen_name').val();

	if (Email == ''){
		alert('Please Enter Email.');
	}else if(is_email(Email) == false){
		alert('Email format is incorrect.');
	}else if(Screen_Name == ''){
		alert('Please Enter Screen Name.');
	}else{
		//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:authorize_friend_message});
		$.ajax({
			  type: "GET",
			  url: '../user/ajax_authorize_friend.php',
			  data: 'email='+Email+'&screen_name='+Screen_Name,
			  success:function(msg){
				  authorize_friend_message(msg);
			  }
		});
	}
}

function authorize_friend_message(originalRequest){
	var o = eval('(' + originalRequest + ')');
	var search_result = $('#search_result');
	var s = o.Status;
	if (s == 11){
		search_result.html('Can not Authorized to youself.');
	}else if (s == 1){
		search_result.html('Please Enter Email.');
	}else if (s == 2)	{
		search_result.html('Email format is incorrect.');
	}else if(s == 3){
		//search_result.html('User Not Found.'); 
		search_result.html('This email is not in Qtv records!');
	}else if(s == 4){
		search_result.html('Screen Name is incorrect.');
	}else if(s == 5){
		alert('Successfully Authorized friend.');
		window.location = '../user/sharing.php?type=friends';
	}else if(s == 6){
		alert('Faild update.');
	}else if(s == 7){
		search_result.html('You had add this friend');
	}else{
	
	}
}

function favorite_sharing_active(user_id){
	//var myAjax=new Ajax.Request(url,{method:'get',parameters:pars,onComplete:favorite_sharing_active_message});
	$.ajax({
		  type: "GET",
		  url: '../user/ajax_authorize_friend_active.php',
		  data: 'guest_id='+user_id,
		  success:function(msg){
			  favorite_sharing_active_message(msg);
		  }
	});
}

function favorite_sharing_active_message(originalRequest){
	var o = eval('(' + originalRequest + ')');
	//alert(o.Status);
}

function check_operator_pwd(){
	var pwd = $("#pwd").val();
	$.ajax({
		  type: "GET",
		  url: '../user/ajax_check_operator.php',
		  data: 'pwd='+pwd,
		  success:function(msg){		  	
			var o = eval('(' + msg + ')');
			var status = o.Status;
			if (status == 'error'){
				alert(o.error);
			}else if (status == 'success'){
				var closedlglink = $(document.getElementById('closedlg'));
				closedlglink.click();
				//$(document.getElementById('form_check_pwd')).submit();
				delete_media_item();
			}else{
				alert('error');
			}	
		  }
	});
}

function delete_media_item(){
	$.ajax({
		  type: "GET",
		  url: '../user/ajax_delete_media_item.php',
		  data: $('#form_check_pwd').serializeArray(),
		  success:function(msg){
			  var o = eval('(' + msg + ')');
			  var status = o.Status;
			  if (status == 'error'){
				alert(o.error);
				}else if (status == 'success'){
					alert(o.message);
					reloadPage();
				}
		  }
	});

}

/**This is used in user login page to check whether there is*/
/**Child user for this email. If there is , then ask user to */
/**Fill with the screen name input*/

function check_user_on_email(){
	var Email = $('#email').val();
	var email_message = $('#email_message');
	if (Email == ''){
		email_message.html('Email is Required.');
	}else{
		email_message.html('');
		var url = 'user/ajax_check_user_on_email.php';
		$.ajax({
			  type: "GET",
			  url: url,
			  data: 'email='+Email,
			  success:function(msg){
			  	check_user_on_email_message(msg);
			  }
		}); 
	}
}

/*Call back function of check_user_on_email*/
function check_user_on_email_message(originalRequest){
	var o = eval('(' + originalRequest + ')'); 
	if (o.Status == 3){
		$('#Screen_Name_ID').show();
		$('#screen_name').focus();
	}else{
		$('#Screen_Name_ID').hide();
		$('#password').focus();
	}
}

function create_media_item_urls(){
	var mi_url = $('#mi_url').val();
	var mi_resolutionX = $('#mi_resolutionX').val();
	var mi_resolutionY = $('#mi_resolutionY').val();
	var mi_bits_rate = $('#mi_bits_rate').val();	
	var provider_id = $('#provider_id').val();	
	var category_id = $('#category_id').val();	
	var item_id = $('#item_id').val();
	if (mi_url == ''){
		alert('Please enter Url.');
		return false;
	}else{
		$.ajax({
			  type: "GET",
			  url: '../category/ajax_media_item_urls.php',
			  data: 'a=add'+'&url='+mi_url+'&resx='+mi_resolutionX+'&resy='+mi_resolutionY+'&rate='+mi_bits_rate+'&provider_id='+provider_id
				   +'&category_id='+category_id+'&item_id='+item_id,
			  success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;			
				if (status == 'error'){
					alert(o.message);
				}else if (status == 'success')	{
					if (item_id=='') {
						$('#item_id').val(o.item_id);						
					}					
					alert(o.message);
					$('#urls_content').html(o.divcontent);	
					$('#mi_url').val('');
					$('#mi_resolutionX').val('');
					$('#mi_resolutionY').val('');
					$('#mi_bits_rate').val('');
				}else{
				
				}
			  }
		});
	}
}

function delete_media_item_urls(item_id,sub_id){
		$.ajax({
			  type: "GET",
			  url: '../category/ajax_media_item_urls.php',
			  data: 'a=del'+'&item_id='+item_id+'&sub_id='+sub_id,
			  success:function(msg){
				var o = eval('(' + msg + ')'); 
				var status = o.Status;	
				if (status == 'error'){
					alert(o.message);
				}else if (status == 'success')	{			
					alert(o.message);
					$('#urls_content').html(o.divcontent);
					$('#mi_url').val('');
					$('#mi_resolutionX').val('');
					$('#mi_resolutionY').val('');
					$('#mi_bits_rate').val('');
				}else{
					alert(o.message);
				}
			  }
		});	
}