function getObj(name) 
{   if (document.getElementById) { return document.getElementById(name); }
			else if (document.all)       { return document.all[name]; }
			else if (document.layers)    { return document.layers[name]; }
}


function offsetLeft(el)
  { 
    x = el.offsetLeft
    for (e = el.offsetParent; e; e = e.offsetParent)
      x += e.offsetLeft;
    return x
  } 

 function offsetTop(el)
  {
    y = el.offsetTop
    for (e = el.offsetParent; e; e = e.offsetParent)
      y += e.offsetTop;
    return y
 } 
 

preload_image_object = new Image();
preload_image_object.src = "images/ajax-loader.gif";
function lock_screen(no_lock_screen){
    new Element('div').setProperty('id', 'lock_screen_content').inject(document.body);	
	if(!no_lock_screen){
		new Element('div').setProperty('id', 'lock_screen').inject(document.body);
		 lock_screen= $('lock_screen');
		 lock_screen.className="lock_screen";
		 lock_screen.align="center";
		 lock_screen.setStyles({
				"left": '0px',
				"top": '0px',
				"height": '0px',
				"width": '0px',
				"display":'block'
			});
		 lock_screen.setStyles({
				"height": window.getScrollHeight() + 'px',
				"width": window.getScrollWidth() + 'px'
		  });
	}
	  screen_content = $("lock_screen_content");	
	  screen_content.className="content";
	  screen_content.innerHTML = '<img src="images/ajax-loader.gif" valign="absmiddle"><br> <b>Processing data. Please wait</b>'
	  SC_position();
	  
	  //if the browsers is Firefox, Chrome, etc
		if (window.addEventListener){
		  window.addEventListener('scroll', SC_position, true);
		  window.addEventListener('resize', SC_position, true);  
		}
		//if its Windows Explorer
		else if (window.attachEvent){
		  window.attachEvent('onscroll', SC_position);
		  window.attachEvent('onresize', SC_position);
		}

	  return true;				  
}
function unlock_screen(){
	  //if the browsers is Firefox, Chrome, etc
	     if($('lock_screen')) $('lock_screen').destroy();
		 $("lock_screen_content").destroy();
		if (window.addEventListener){
		  window.removeEventListener('scroll', SC_position, true);
		  window.removeEventListener('resize', SC_position, true);  
		}
		//if its Windows Explorer
		else if (window.attachEvent){
		  window.detachEvent ('onscroll', SC_position);
		  window.detachEvent ('onresize', SC_position);
		}
		

}
function SC_position(){
	$('lock_screen_content').set('morph', {
		duration: 75
	});
	$('lock_screen_content').morph({
		width: '200px',
		left: (window.getScrollLeft() + (window.getWidth() - 200) / 2) + 'px',
		top: (window.getScrollTop() + (window.getHeight() - 200) / 2) + 'px'
	});	

}




var window_alert;
var window_alert_content;
var total_notifications=0;
function json_notifications(window_alert_id){
	window_alert = $(window_alert_id);
	window_alert_content = $(window_alert_id+"_content");
	var request = new Request.JSON({
			url: 'user_notifications.php',
			onComplete: function(jsonObj) {
				//addImages(jsonObj.notifications);
				if($type(jsonObj)=="object"){
					notifications =jsonObj.notifications;
					total_notifications = jsonObj.total;
					if(total_notifications>0){
						window_alert_content.innerHTML="";
						notifications.each(function(notify) {
							html  = " <div class='notify' id='notify_" + notify.notifytype_id + "_" + notify.notify_grouped + "'>";
							html += " <a class='delete fl' href='javascript:void(0);' onClick=\"parent.deleteNotify('" + notify.notifytype_id + "', '" + notify.notify_grouped + "');\">X</a> <div class='desc'> <img src='./images/icons/" + notify.notify_icon + "' border='0'  class='icon'><a href=\"" + notify.notify_url + "\">" + notify.notify_desc + " </a></div>";
							html += "</div>";
							//alert(html);
							window_alert_content.innerHTML += html;
						});
						window_alert_position();
						window_alert.style.display="block";
						//window_alert_position();
					}
					else window_alert.style.display="none";
				}
				else window_alert.style.display="none";
			}
		}).send();
	
	window.onscroll = window_alert_position;	
	window.onresize = function(){  window_alert_position();	  }
}

function window_alert_position(){
	window_alert.set('morph', {
		duration: 75
	});
	window_alert.morph({
		width: '250px',
		left: (window.getScrollLeft() + window.getWidth() - 254 ) + 'px',
		top: (window.getScrollTop() + window.getHeight() - window_alert.getHeight() ) + 'px'
	});	

}

function deleteNotify(notifytype_id, notify_grouped) {
  $('ajaxframe').src = 'user_notifications.php?task=notify_delete&notifytype_id='+notifytype_id+'&notify_grouped='+notify_grouped;
}
function deleteNotifyConfirm(notifytype_id, notify_grouped) {
  el = $("notify_" + notifytype_id + "_" + notify_grouped) ;
  el.style.display="none";
  total_notifications--;
  if(total_notifications==0){
	  window_alert.style.display="none";
  }
  else  window_alert_position();
}

function checksearch(p, nmax, error1, error2){
	var search_p = p.value;
	if(isFinite(search_p))
	{
		if(search_p<1)	
		{
			alert (error1);
			p.value="";
			p.focus();
			return false;
		}
		if(search_p >nmax)
		{
			alert (error2+" "+nmax);
			p.value="";
			p.focus();
			return false;
		}
	}
	else
	{
		alert (error1);
		p.value="";
		p.focus();
		return false;
	}
	return true;
}

function FAC_show(html){
	document.write(html);	
}
function ys_showinfo2(visible,user,page) {
	  newdiv2= document.getElementById('infodiv2')//.innerHTML;
      newdiv2.style.top = ($(window).getScroll().y + 100) + "px";//document.body.scrollTop;
      if(visible){
      	newdiv2.style.display="";
        action_show = new sack(); 

        action_show.requestFile = "user_friends_add.php";
        action_show.setVar("user",user);
		action_show.setVar("ajax",1);
		action_show.setVar("page_goto",page);
        content_id = getObj('popup_results');
        content_id.innerHTML = '<center><img src="images/ajax-loader.gif" valign="absmiddle"><br> <b>Please wait ... data loading</b></center>';
		action_show.onCompletion = function(){
        	getObj('popup_results').innerHTML= action_show.response;
        }              
      }
      else  newdiv2.style.display="none";
      action_show.runAJAX();
}

function ys_showinfo3(visible,params,page) {
	  newdiv2= document.getElementById('infodiv2')//.innerHTML;
      newdiv2.style.top = ($(window).getScroll().y + 100) + "px";//document.body.scrollTop;
      if(visible){
      	newdiv2.style.display="";
        action_show = new sack(); 

        action_show.requestFile = page;
		
		//anhduong them vao cac param cho file can request
		for(key in params){
			action_show.setVar(key,params[key]);	
		}	
        
        content_id = getObj('popup_results');
        content_id.innerHTML = '<center><img src="images/ajax-loader.gif" valign="absmiddle"><br> <b>Please wait ... data loading</b></center>';
		action_show.onCompletion = function(){
        	getObj('popup_results').innerHTML= action_show.response;
        }              
      }
      else  newdiv2.style.display="none";
      action_show.runAJAX();
}




function smile_emoticon(){
	html = "";
	html +=	'<img src="./images/smiles_yahoo/1.gif" alt="happy" onclick="insert_code(\':) \')">';
	html +=	'<img src="./images/smiles_yahoo/2.gif" alt="sad" onclick="insert_code(\':( \')">';
    html +='<img src="./images/smiles_yahoo/3.gif" alt="winking" onclick="insert_code(\';) \')">';
	html +=	'<img src="./images/smiles_yahoo/4.gif" alt="big grin" onclick="insert_code(\':D \')">';
	html +=	'<img src="./images/smiles_yahoo/5.gif" alt="batting eyelashes" onclick="insert_code(\';;) \')">';
	html +=	'<img src="./images/smiles_yahoo/6.gif" alt="big hug" onclick="insert_code(\'>:D< \')">';
	html +=	'<img src="./images/smiles_yahoo/7.gif" alt="confused" onclick="insert_code(\':-/ \')">';
	html +=	'<img src="./images/smiles_yahoo/8.gif" alt="love struck" onclick="insert_code(\':x \')">';
	//html +=	'<img src="./images/smiles_yahoo/9.gif" alt="blushing" onclick="insert_code(\':\"\> \')">'; 
	html +=	'<img src="./images/smiles_yahoo/10.gif" alt="tongue" onclick="insert_code(\':P \')">';
	html +=	'<img src="./images/smiles_yahoo/11.gif" alt="kiss" onclick="insert_code(\':-* \')">';
	html +=	'<img src="./images/smiles_yahoo/12.gif" alt="broken heart" onclick="insert_code(\'=(( \')">';
	html +=	'<img src="./images/smiles_yahoo/13.gif" alt="surprise" onclick="insert_code(\':-O \')">';
	html +=	'<img src="./images/smiles_yahoo/14.gif" alt="angry" onclick="insert_code(\'X( \')">';
	html +=	'<img src="./images/smiles_yahoo/15.gif" alt="smug" onclick="insert_code(\':> \')">';
	html +=	'<img src="./images/smiles_yahoo/16.gif" alt="cool" onclick="insert_code(\'B-) \')">';
	html +=	'<img src="./images/smiles_yahoo/17.gif" alt="worried" onclick="insert_code(\':-S \')">';
	html +=	'<img src="./images/smiles_yahoo/18.gif" alt="whew!" onclick="insert_code(\'#:-S \')">';
	html +=	'<img src="./images/smiles_yahoo/19.gif" alt="devil" onclick="insert_code(\'>:) \')">';  
	html +=	'<img src="./images/smiles_yahoo/20.gif" alt="crying" onclick="insert_code(\':(( \')">';
	html +=	'<img src="./images/smiles_yahoo/21.gif" alt="laughing" onclick="insert_code(\':)) \')">';
	html +=	'<img src="./images/smiles_yahoo/22.gif" alt="straight face" onclick="insert_code(\':| \')">';
	html +=	'<img src="./images/smiles_yahoo/23.gif" alt="raised eyebrows" onclick="insert_code(\'/:) \')">';
	html +=	'<img src="./images/smiles_yahoo/24.gif" alt="rolling on the floor" onclick="insert_code(\'=)) \')">';
	html +=	'<img src="./images/smiles_yahoo/25.gif" alt="angel" onclick="insert_code(\'O:-) \')">';
	html +=	'<img src="./images/smiles_yahoo/26.gif" alt="nerd" onclick="insert_code(\':-B \')">';
	html +=	'<img src="./images/smiles_yahoo/27.gif" alt="talk to the hand" onclick="insert_code(\'=; \')">';
	html +=	'<img src="./images/smiles_yahoo/28.gif" alt="sleepy" onclick="insert_code(\'I-) \')">';
	html +=	'<img src="./images/smiles_yahoo/29.gif" alt="rolling eyes" onclick="insert_code(\'8-| \')">';
	html +=	'<img src="./images/smiles_yahoo/30.gif" alt="loser" onclick="insert_code(\'L-) \')">';
	html +=	'<img src="./images/smiles_yahoo/31.gif" alt="sick" onclick="insert_code(\':-&amp; \')">';
	html +=	'<img src="./images/smiles_yahoo/32.gif" alt="don&#039t tell anyone" onclick="insert_code(\':-$ \')">';
	html +=	'<img src="./images/smiles_yahoo/33.gif" alt="no talking" onclick="insert_code(\'[-( \')">';
	html +=	'<img src="./images/smiles_yahoo/34.gif" alt="clown" onclick="insert_code(\':O) \')">';
	html +=	'<img src="./images/smiles_yahoo/35.gif" alt="silly" onclick="insert_code(\'8-} \')">';
	html +=	'<img src="./images/smiles_yahoo/36.gif" alt="party" onclick="insert_code(\'<:-P \')">';
	html +=	'<img src="./images/smiles_yahoo/37.gif" alt="yawn" onclick="insert_code(\'(:| \')">';			
	html +=	'<img src="./images/smiles_yahoo/38.gif" alt="drooling" onclick="insert_code(\'=P~ \')">';
	html +=	'<img src="./images/smiles_yahoo/39.gif" alt="thinking" onclick="insert_code(\':-? \')">';
	html +=	'<img src="./images/smiles_yahoo/40.gif" alt="d&#039oh" onclick="insert_code(\'#-o \')">';
	html +=	'<img src="./images/smiles_yahoo/41.gif" alt="applause" onclick="insert_code(\'=D> \')">';
	html +=	'<img src="./images/smiles_yahoo/42.gif" alt="nail biting" onclick="insert_code(\':-SS \')">';	
	html +=	'<img src="./images/smiles_yahoo/43.gif" alt="hypnotized" onclick="insert_code(\'@-) \')">';
	html +=	'<img src="./images/smiles_yahoo/44.gif" alt="liar" onclick="insert_code(\':^o \')">';
	html +=	'<img src="./images/smiles_yahoo/45.gif" alt="waiting" onclick="insert_code(\':-w \')">';
	html +=	'<img src="./images/smiles_yahoo/46.gif" alt="sigh" onclick="insert_code(\':-< \')">';	
	html +=	'<img src="./images/smiles_yahoo/47.gif" alt="phbbbbt" onclick="insert_code(\'>:P \')">';	
	html +=	'<img src="./images/smiles_yahoo/48.gif" alt="cowboy" onclick="insert_code(\'<):) \')">';
	html +=	'<img src="./images/smiles_yahoo/100.gif" alt="on the phone" onclick="insert_code(\':)] \')">';
	html +=	'<img src="./images/smiles_yahoo/101.gif" alt="call me" onclick="insert_code(\':-c \')">';
	html +=	'<img src="./images/smiles_yahoo/102.gif" alt="at wits&#039 end" onclick="insert_code(\'~X( \')">';
	html +=	'<img src="./images/smiles_yahoo/103.gif" alt="wave" onclick="insert_code(\':-h \')">';
	html +=	'<img src="./images/smiles_yahoo/104.gif" alt="time out" onclick="insert_code(\':-t \')">';
	html +=	'<img src="./images/smiles_yahoo/105.gif" alt="day dreaming" onclick="insert_code(\'8-> \')">';
	html +=	'<img src="./images/smiles_yahoo/109.gif" alt="I don&#039t want to see" onclick="insert_code(\'X_X \')">';
	html +=	'<img src="./images/smiles_yahoo/110.gif" alt="hurry up!" onclick="insert_code(\':!! \')">';
	html +=	'<img src="./images/smiles_yahoo/111.gif" alt="rock on!" onclick="insert_code(\'\\\\m/ \')">';
	html +=	'<img src="./images/smiles_yahoo/112.gif" alt="thumbs down" onclick="insert_code(\':-q \')">';
	html +=	'<img src="./images/smiles_yahoo/113.gif" alt="thumbs up" onclick="insert_code(\':-bd \')">';
	html +=	'<img src="./images/smiles_yahoo/114.gif" alt="it wasn&#039t me" onclick="insert_code(\'^#(^ \')">';
	html +=	'<img src="./images/smiles_yahoo/pirate_2.gif" alt="pirate*" onclick="insert_code(\':ar! \')">';
   	document.write(html);
} 


function openPage(url, vHeight, vWidth)
{ 
	 winDef = 'status=yes,resizable=no,scrollbars=yes,fullscreen=no,titlebar=no,height='.concat(vHeight).concat(',').concat('width=').concat(vWidth).concat(',');
	 winDef = winDef.concat('top=').concat((screen.height - vHeight)/2).concat(',');
	 winDef = winDef.concat('left=').concat((screen.width - vWidth)/2);
	 
	 var winmedia ;
	 winmedia= window.open(url,'music_popup', winDef);
	 winmedia.focus();
     return false;

}

function openPageOpener(url){
	opener= window.open(url);
	opener.focus();
	return false;
}


// COMMENT
    var emoticon_status = 0;
    function show_div_emoticon(){
        if(emoticon_status){
            document.getElementById('div_emoticon').style.display="none";
            emoticon_status=0;
        }
        else{
            document.getElementById('div_emoticon').style.display="block";
            emoticon_status=1;
        }
    }
    
    function insert_code2(myValue1,myValue2){

        var myField = document.getElementById('comment_body');
        
        if (document.selection) {
            theSelection = document.selection.createRange().text;
            if (theSelection) 
            {
                document.selection.createRange().text = myValue1 + theSelection + myValue2;
                myField.focus();
                theSelection = '';
            }
            eval(v+"++;");            
        }
        else
        {
            start_sel = myField.selectionStart;
            end_sel = myField.selectionEnd;
            if((myField.value).substring(start_sel, end_sel) != '')
            {
                myField.value = (myField.value).substring(0, start_sel) + myValue1 + (myField.value).substring(start_sel, end_sel) + myValue2 + (myField.value).substring(end_sel, myField.textLength);
                myField.selectionStart = start_sel;
                myField.selectionEnd = end_sel + (myValue1.length + myValue2.length);
                return;
            }
            else{
                myField.value += myValue1 + myValue2;
            }
        }
    }

    function set_quote_comment(text){
        myField = document.getElementById('comment_body');
        myField.value ="";
        removeText(myField );
        myField.value=text;
    }
	function removeText(commentBody) {
	  if(comment_changed == 0) {
		commentBody.value='';
		commentBody.style.color='#000000';
		comment_changed = 1;
	  }
	}
	function insert_code(myValue){
		myField = document.getElementById('comment_body');
		removeText(myField );
		if (document.selection) {
			myField.focus();
			sel = document.selection.createRange();
			sel.text = myValue;
		}
		//Mozilla/firefox/Netscape 7+ support
		else if (myField.selectionStart || myField.selectionStart == '0') {
			var startPos = myField.selectionStart;
			var endPos = myField.selectionEnd;
			myField.value = myField.value.substring(0, startPos)+ myValue+ myField.value.substring(endPos, myField.value.length);
			myField.setSelectionRange(endPos+myValue.length, endPos+myValue.length);
		} 
		else {
			myField.value += myValue;
		}
	}
