// JavaScript Document
/*  *///////////////////////////////
function MySpace(mode)
{
	var opt = {
		method:'post', 
		postBody:'action=mySpace',
		onSuccess: function (t) { 
			var data = t.responseText.split("|");	   
			$('title').innerHTML = data[0];
			$('list').innerHTML = data[1];
			if (mode){
			  $('atitle').innerHTML = data[2];
			  $('alist').innerHTML = data[3];
			}
		},
		onLoading: function() {}
	}
	new Ajax.Request('libraries/myspaceajax.php', opt);  	
}

/*  *///////////////////////////////
function editAccSetting(index)
{
	var opt = {
		method:'post', 
		postBody:'action=editaccsetting&index=' + index,
		onSuccess: function (t) { 
			var data = t.responseText.split("|");	  
			$('title').innerHTML = data[0];
			$('list').innerHTML = data[1];
		},
		onLoading: function() {
		    $('list').innerHTML = '<div class="show-load"></div>'; 	
		}
	}
	new Ajax.Request('libraries/myspaceajax.php', opt);  	
}

/*  *///////////////////////////////
function updateAccInfo(type)
{
	var opt = {
		method:'post', 
		postBody:'action=updateinfo&type=' + type + '&' + Form.serialize('accform'),
		onSuccess: function (t) { 
		  $('updateMsg').innerHTML = t.responseText;
		},
		onLoading: function() { }   
	}
	new Ajax.Request('libraries/myspaceajax.php', opt);  
}

/*Delete User Account*//////////////////////////////
function delacc(msg)
{
   input_box=confirm(msg);
	if (input_box==true)
	{ 
		var opt = {
			method:'post', 
			postBody:'action=delacc',
			onSuccess: function (t) { 
				$('updateMsg').innerHTML = t.responseText;
				window.location = 'main.php';
			},
			onLoading: function() {}
		}

		new Ajax.Request('libraries/myspaceajax.php', opt); 
	}
	else
	{
		return;
	}
}

/*  *///////////////////////////////
function editMyProfile(index,type)
{
	var opt = {
		method:'post', 
		postBody:'action=editprofile&index=' + index + '&type=' + type,
		onSuccess: function (t) { 
			$('list').innerHTML =  t.responseText; 
		},
		onLoading: function() {}
	}
	new Ajax.Request('libraries/myspaceajax.php', opt);  	
}
/*  *///////////////////////////////
function addLanguage(id)
{
	   var opt = {
			method:'post', 
			postBody:'action=addLanguage&no=' + id,
			onSuccess: function(t) {  	
			    $('alang_' + id).innerHTML = t.responseText;
			},
			onLoading: function() {  }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
}

/* Refresh load country state*//////////////////////////////
function showStateInput(t)
{
  		if (t.value == 0) Element.show('other_state');
  		else Element.hide('other_state');
}

/*  *///////////////////////////////
function createProfile(index,id)
{
	   var opt = {
			method:'post', 
			postBody:'action=editprofile&index= ' + index + ' &id=' + id,
			onSuccess: function(t) { 
			  var data = t.responseText.split("|");
              $('main_title').innerHTML = data[0]; 
			  $('main').innerHTML = data[1];  
			  $('member_title').innerHTML = data[2];
			  $('member').innerHTML = data[3];
			},
			onLoading: function() { }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);  
}


/*  *///////////////////////////////
function editProfileData(n,id,type)
{      
	   var msg = "Please select the option!";
	   if (n == 1){
		  if($F('Gender') == 0){ 
			$('gender_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('Gender').style.border = '1px red solid';
		    return;
		  } 
		  else {
		    $('gender_check').innerHTML = '';
		    $('Gender').style.border = '1px green solid';
		  }
		  
		  if($F('Race') == 0){ 
		  	$('race_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('Race').style.border = '1px red solid';
		    return;
		  } 
		  else {
		    $('race_check').innerHTML = '';
		    $('Race').style.border = '1px green solid';
		  }
		  
		  if($F('language_s1') == 0){ 
		  	$('language_1_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('language_s1').style.border = '1px red solid';
		    return;
		  } 
		  else {
		    $('language_1_check').innerHTML = '';
		    $('language_s1').style.border = '1px green solid';
		  }
		  
		  if($F('Relationship') == 0){ 
			$('relationship_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('Relationship').style.border = '1px red solid';
		    return;
		  } 
		  else {
		    $('relationship_check').innerHTML = '';
		    $('Relationship').style.border = '1px green solid';
		  }
		  
		  if($F('country') == 0){ 
		    $('country_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('country').style.border = '1px red solid';
		    return;
		  }
		  else {
		    $('country_check').innerHTML = '';
		    $('country').style.border = '1px green solid';
		  }
		  
		  if ($F('states') == 0) {
			$('state_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('states').style.border = '1px red solid';
			return; 
		  }
		  else {
		    $('state_check').innerHTML = '';
		    $('states').style.border = '1px green solid';
		  }
		  
		  if ($F('country') == 70) {
		     if ($F('city') == 0) {
				$('city_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
				$('city').style.border = '1px red solid';
				return; 
			  }
			  else {
				$('city_check').innerHTML = '';
				$('city').style.border = '1px green solid';
			  }
		  }
		  else {
			  if ($F('area').length == 0) {
				$('area_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
				$('area').style.border = '1px red solid';
				return; 
			  }
			  else {
				$('area_check').innerHTML = '';
				$('area').style.border = '1px green solid';
			  }
		  }
		  
		  if($F('Month') == 0 || $F('birth_Day') == 0 || $F('birth_Year') == 0){ 
			$('date_check').innerHTML = ' <img src="./images/error.png" /> ' + msg;
		    $('Month').style.border = '1px red solid';
			$('birth_Day').style.border = '1px red solid';
			$('birth_Year').style.border = '1px red solid';
		    return;
		  } 
		  else {
		    $('date_check').innerHTML = '';
		    $('Month').style.border = '1px green solid';
			$('birth_Day').style.border = '1px green solid';
			$('birth_Year').style.border = '1px green solid';
		  }
	   }
	   
	   var opt = {
			method:'post', 
			postBody:'action=updateprofile&index=' + n + '&id=' + id + '&' + Form.serialize('updateform'),
			onSuccess: function(t) {  			   
				if (n == 1) {
					if (type == 1) {
						$('profileUpdateMsg').innerHTML = t.responseText;
						editMyProfile(2,1);
					}
					else if (type == 2) createProfile(2,id);
				}
				else if (n == 2) {
				    if (type == 1) $('profileUpdateMsg').innerHTML = t.responseText;
				    else if (type == 2 ) finishProfile(id);
				}
			},
			onLoading: function() {  
				$('profileUpdateMsg').innerHTML  = '<div class="show-load-small"></div>';
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
}
/*  *///////////////////////////////
function chgbirthday(uid)
{
	   var opt = {
			method:'post', 
			postBody:'action=chgbirthday&id=' + $F('Gender') + '&uid='+ uid,
			onSuccess: function(t) {  			   
			    $('chgbd').innerHTML = t.responseText;

			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}


/*  *///////////////////////////////
function showPhotoManager(id)
{
	   var opt = {
			method:'post', 
			postBody:'action=photoManager&id=' + id,
			onSuccess: function(t) {  			   
			    var data = t.responseText.split("|");
		        $('title').innerHTML =data[0];
	            $('list').innerHTML =data[1];
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}
/*  *///////////////////////////////
function showEditGallery()
{
	   if ($F('select_galleries') == 0) return ;
	   if ($F('select_galleries') == 'private') return;
	   
	   var opt = {
			method:'post', 
			postBody:'action=editGalleryName&id=' + $F('select_galleries'),
			onSuccess: function(t) {  
		        $('edit_gallery').innerHTML = t.responseText;
			},
			onLoading: function() {
			   $('edit_gallery').innerHTML = '<img src="images/loader.gif" class="icon">';
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
}
/*  *///////////////////////////////
function loadMyGallery()
{
	   var opt = {
			method:'post', 
			postBody:'action=photoManager&id=' + $F('select_galleries'),
			onSuccess: function(t) {  			   
			    var data = t.responseText.split("|");
		        $('title').innerHTML =data[0];
	            $('list').innerHTML =data[1];
			},
			onLoading: function() {
			    $('list').innerHTML = '<div class="show-load"></div>'; 	
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}
/*  *///////////////////////////////
function loadMyVideo()
{
	   var opt = {
			method:'post', 
			postBody:'action=videoManager&id=' + $F('select_video'),
			onSuccess: function(t) {  			   
	            $('col-two').innerHTML = t.responseText;
			},
			onLoading: function() {
			    $('list').innerHTML = '<div class="show-load"></div>'; 	
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}
/*  *///////////////////////////////
function setCode(type)
{	
		if ($F('code').length < 1) return;
		var opt = {
			method:'post', 
			postBody:'action=setCode&type=' + type + '&code=' + $F('code'),
			onSuccess: function(t) {  	
			   // var data = t.responseText.split("|");
				$('code').value = '';
				$('codemsg').innerHTML = t.responseText;
			},
			onLoading: function() {
			    $('codemsg').innerHTML = '<img src="images/loader.gif" class="icon">';
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}
/*  *///////////////////////////////
function exeAction(gid)
{
		if ($F('select_action') == 0 || $F('select_action') > 0) var at ='movei';
		else if ($F('select_action') == 'private') var at ='setpp';
		else if ($F('select_action') == 'unset') var at ='unsetpp';
		else if ($F('select_action') == 'soft') var at ='softi';
		else if ($F('select_action') == 'delete') var at ='delsi';
		else if ($F('select_action') == 'change') var at ='setproi';
		else return;
		
		var opt = {
			method:'post', 
			postBody:'action=photoManager&act=' + at + '&id=' + gid + '&' + Form.serialize('move_image_form'+gid),
			onSuccess: function(t) {  			   
				var data = t.responseText.split("|");
		        $('title').innerHTML =data[0];
	            $('list').innerHTML =data[1];
			},
			onLoading: function() {
				$('list').innerHTML = '<div class="show-load"></div>'; 
		    }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
		
}

/*  *///////////////////////////////
function exeVidAction(gid)
{
		if ($F('select_action') == 'private') var at ='setpv';
		else if ($F('select_action') == 'unset') var at ='unsetpv';
		else if ($F('select_action') == 'delete') var at ='delsv';
		else return;

		var opt = {
			method:'post', 
			postBody:'action=videoManager&act=' + at + '&' + Form.serialize('move_video_form'),
			onSuccess: function(t) {  
				$('col-two').innerHTML = t.responseText;
			},
			onLoading: function() {
				$('list').innerHTML = '<div class="show-load"></div>'; 
		    }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
		
}
/*  *///////////////////////////////
function addGallery()
{
       	if($F('gallery') == ''){ 
		   return;
		}
		
		var opt = {
			method:'post', 
			postBody:'action=addGallery&name=' + $F('gallery'),
			onSuccess: function(t) {  			   
			    $('edit_gallery').innerHTML = t.responseText;
				$('gallery').value = '';
			},
			onLoading: function() {
               	$('edit_gallery').innerHTML = '<img src="images/loader.gif" class="icon">';
		    }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}
/*  *///////////////////////////////
function updateName(gid)
{
  	    if($F('gallery_name') == ''){ 
		    return;
		}
		
		var opt = {
			method:'post', 
			postBody:'action=updGallery&gid=' + gid + '&name=' + $F('gallery_name'),
			onSuccess: function(t) {  			   
			    $('edit_gallery').innerHTML = t.responseText;
				showPhotoManager(gid);
			},
			onLoading: function() {
               	$('edit_gallery').innerHTML = '<img src="images/loader.gif" class="icon">';	
		    }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
}
/*  *///////////////////////////////
function deleteGallery(gid)
{
  	    var opt = {
			method:'post', 
			postBody:'action=delGallery&gid=' + gid,
			onSuccess: function(t) {  			   
				 $('edit_gallery').innerHTML = t.responseText;
				 showPhotoManager(0);
			},
			onLoading: function() {
               	 $('edit_gallery').innerHTML = '<img src="images/loader.gif" class="icon">';
		    }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
}
/*  *///////////////////////////////
function cancelEdit(gid)
{
        var opt = {
			method:'post', 
			postBody:'action=reloadGalleryName',
			onSuccess: function(t) {  			   
				 $('edit_gallery').innerHTML = t.responseText;
			},
			onLoading: function() {
               	 $('edit_gallery').innerHTML = '<img src="images/loader.gif" class="icon">';
		    }
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
}

/*  *///////////////////////////////
function deleteImage(gid,iid,delmsg)
{
	input_box=confirm(delmsg);
	if (input_box==true)
	{ 
	   var opt = {
			method:'post', 
			postBody:'action=photoManager&act=deli&id=' + gid + '&iid=' + iid,
			onSuccess: function(t) {  			   
			    var data = t.responseText.split("|");
		        $('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
			},
			onLoading: function() {
			   $('list').innerHTML = '<div class="show-load"></div>'; 	
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
	}
}

/*  *///////////////////////////////
function editImage(iid)
{
 		var opt = {
			method:'post', 
			postBody:'action=editImage&iid=' + iid,
			onSuccess: function(t) {  		
			    var data = t.responseText.split("|");
		        $('title').innerHTML =data[0];
	            $('list').innerHTML =data[1];
			},
			onLoading: function() {
				$('list').innerHTML = '<div class="show-load"></div>'; 	
			}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	 	
}
/*  *///////////////////////////////
function saveImgInfo(iid)
{		
		var opt = {
			method:'post', 
			postBody:'action=saveImageInfo&iid=' + iid + '&' + Form.serialize('edit_image_form'),
			onSuccess: function(t) {  			   			
			    var data = t.responseText.split("|");
				if (data[0] == 0){
				   alert(data[1]);
				}
				else {	
				   showPhotoManager(0);
				}
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	 	
}
/*  *///////////////////////////////
function showVideoManager()
{
	    var opt = {
			method:'post', 
			postBody:'action=videoManager',
			onSuccess: function(t) {  			   
				$('col-two').innerHTML = t.responseText;
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);		
}
/*  *///////////////////////////////
function editVideo(vid)
{
 		var opt = {
			method:'post', 
			postBody:'action=editVideo&vid=' + vid,
			onSuccess: function(t) {  			   
				$('col-two').innerHTML = t.responseText; 
				Element.show('col-two');	
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	 	
}
/*  *///////////////////////////////
function saveVidInfo(vid)
{
		var opt = {
			method:'post', 
			postBody:'action=saveVideoInfo&vid=' + vid + '&' + Form.serialize('edit_video_form'),
			onSuccess: function(t) {  			   
				var data = t.responseText.split("|");
				if (data[0] == 0){
				   alert(data[1]);
				}
				else {	
				   showVideoManager();
				}
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	 	
}
/*  *///////////////////////////////
function deleteVideo(vid,delmsg)
{
    input_box=confirm(delmsg);
    if (input_box==true)
	{ 		   
	   var opt = {
			method:'post', 
			postBody:'action=videoManager&act=delv&vid=' + vid,
			onSuccess: function(t) {  			   
				$('col-two').innerHTML = t.responseText;
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);	
	}
}

/*  *///////////////////////////////
function managePlace()
{
        var opt = {
			method:'post', 
			postBody:'action=listMyPlace',
			onSuccess: function(t) {  			   
                var data = t.responseText.split("|");
				$('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function postPlace()
{   
	  var opt = {
			method:'post', 
			postBody:'action=writePlace',
			onSuccess: function(t) {  			   
                var data = t.responseText.split("|");
				$('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
				editorSetup(0);
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function editPlace(tid)
{
		var opt = {
			method:'post', 
			postBody:'action=editPlace&tid=' + tid,
			onSuccess: function(t) {  			   
   				var data = t.responseText.split("|");
				$('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
				editorSetup(0);
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function savePlace(mode,tid)
{
        var myText = tinyMCE.activeEditor.getContent().replace(/\+/g, "&#43");
	    myText = myText.replace(/\\/g, "&#92");
		myText = myText.replace(/'/g, "&#39");
	    myText = escape(myText);

 		if (myText == '') return;
		
		var opt = {
			method:'post', 
			postBody:'action=savePlace&tid=' + tid + '&con=' + myText + '&' + Form.serialize('post_place_form'),
			onSuccess: function(t) {  	
				var data = t.responseText.split("|");
				if (data[0] == 0){
				   alert(data[1]);
				}
				else {	
				   managePlace();
				}			
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}

/*  *///////////////////////////////
function deletePlace(tid,mode,delmsg)
{
    input_box=confirm(delmsg);
    if (input_box==true)
	{ 	
        var opt = {
			method:'post', 
			postBody:'action=deletePlace&tid=' + tid,
			onSuccess: function(t) {  			   
	            if (mode == 1) Effect.Fade('place_' + tid);
				else if (mode == 2) managePlace();
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
	}
}

/*  *///////////////////////////////
function manageForum()
{
        var opt = {
			method:'post', 
			postBody:'action=listMyTopic',
			onSuccess: function(t) {  			   
				var data = t.responseText.split("|");
				$('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function postTopic()
{   
	  var opt = {
			method:'post', 
			postBody:'action=writeTopic',
			onSuccess: function(t) {  			   
				var data = t.responseText.split("|");
				$('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
				editorSetup(0);
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}


/*  *///////////////////////////////
function saveTopic(mode,tid)
{
        var myText = tinyMCE.activeEditor.getContent().replace(/\+/g, "&#43");
	    myText = myText.replace(/\\/g, "&#92");
		myText = myText.replace(/'/g, "&#39");
	    myText = escape(myText);

 		if (myText == '') return;
		
		var opt = {
			method:'post', 
			postBody:'action=saveTopic&tid=' + tid + '&con=' + myText + '&' + Form.serialize('post_topic_form'),
			onSuccess: function(t) {  	
				var data = t.responseText.split("|");
				if (data[0] == 0){
				   alert(data[1]);
				}
				else {	
				   manageForum();
				}			
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function editTopic(tid)
{
		var opt = {
			method:'post', 
			postBody:'action=editTopic&tid=' + tid,
			onSuccess: function(t) {  			   
	            var data = t.responseText.split("|");
				$('title').innerHTML = data[0];
	            $('list').innerHTML = data[1];
				editorSetup(0);
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function deleteTopic(tid,mode,delmsg)
{
    input_box=confirm(delmsg);
    if (input_box==true)
	{ 	
        var opt = {
			method:'post', 
			postBody:'action=deleteTopic&tid=' + tid,
			onSuccess: function(t) {  			   
	            if (mode == 1) Effect.Fade('topic_' + tid);
				else if (mode == 2) manageForum();
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
	}
}
/*  *///////////////////////////////
function attachFile(id,type)
{
	  var opt = {
			method:'post', 
			postBody:'action=attachFile&tid=' + id + '&type=' + type,
			onSuccess: function(t) {  	
				$('attpicList').innerHTML = t.responseText;
			},
			onLoading: function() {
				$('attpicList').innerHTML = '<div class="show-load"></div>';
			}
	  }
	  new Ajax.Request('libraries/myspaceajax.php', opt);
}
/*  *///////////////////////////////
function deleteFile(id,type,delmsg)
{
    input_box=confirm(delmsg);
    if (input_box==true)
	{ 	
        var opt = {
			method:'post', 
			postBody:'action=deleteFile&fid=' + id + '&type=' + type,
			onSuccess: function(t) {  	
			    attachFile(id,type);
			},
			onLoading: function() {}
		}
		new Ajax.Request('libraries/myspaceajax.php', opt);
	}
}

