var dDate=new Date();
dDate.setDate(dDate.getDate()+50);
var globalspan = null;
var bookmarkControl = null;

function setCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}


function getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else
    begin += 2;
  var end = document.cookie.indexOf(";", begin);
  if (end == -1)
    end = dc.length;
  return unescape(dc.substring(begin + prefix.length, end));
}

function deleteCookie(name, path, domain) {
  if (getCookie(name)) {
    document.cookie = name + "=" +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function userlogin(st,type,urlname,urldesc,urltitle)
{
  		var flag=0;
		if( $F('usernamelogin').length <= 0 ) 
		{        
				$('usernameloginmsg').innerHTML="Username is required !" 
				new Effect.Highlight('usernameloginmsg');
				new Effect.Highlight('usernamelogin');
				return false
		 }
		 else if( $F('passwordlogin').length <= 0 )
		 {
				$('usernameloginmsg').innerHTML="&nbsp;&nbsp;"
				$('passwordloginmsg').innerHTML="Password is required !" 
				new Effect.Highlight('passwordloginmsg');
				new Effect.Highlight('passwordlogin');
			   	return false
		 }
				$('usernameloginmsg').innerHTML="&nbsp;&nbsp;"
				$('passwordloginmsg').innerHTML="&nbsp;&nbsp;"
				AjaxRequest.get( 
				{ 
				'url':WEB_ROOT+'ajax_st.php?call=userlogin&from='+$F('usernamelogin')+'&pass='+$F('passwordlogin')+'&rememberme='+$F('signinchek'),
				'onLoading':function(req){$('userloginstatus').innerHTML='<img src='+WEB_ROOT+'images/loading.gif /> Requesting content...'},
				'onSuccess':function(req){ 
				$('userloginstatus').innerHTML="";
				if(req.responseText == 'not_exists'){
										document.getElementById('userloginstatus').innerHTML='Wrong Username <b>('+$F('usernamelogin')+')</b> or Password !';
										new Effect.Highlight('userloginstatus');
									}else if(req.responseText=='logged_in' || req.responseText=='logged_in_cookie'){
										document.getElementById('userloginstatus').innerHTML="&nbsp;&nbsp;";
										//setCookie("uid",$F('usernamelogin'));
										flag=1;
										if(st=='AddBrowserLink')
											window.location=WEB_ROOT+"index.php?st="+st+"&type="+type+"&urlname="+encodeURIComponent(urlname)+"&urldesc="+encodeURIComponent(urldesc)+"&urltitle="+encodeURIComponent(urltitle);
										else
											window.location=WEB_ROOT+'index.php';
									}else if(req.responseText == 'In_activate'){
										document.getElementById('userloginstatus').innerHTML="This New account needs to be activated.<br>Enter your Activation code into the activation field below to activate your account!";
										Tagger('Activationkeylayer')
										new Effect.Highlight('userloginstatus');
									}
									},
				'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				} 
				); 
				return false;
  }
function ActivationKey()
 { 
     if(($F('Susername').length <= 0) && ( $F('SEmail').length <= 0) )
	 {
			 $('ActivationKeymsg').innerHTML= "Please Enter Either Username or email address !"
			 new Effect.Highlight('ActivationKeymsg');
			 return false
	 }
	 AjaxRequest.get( 
			{ 
			'url':'ajax_st.php?call=ActivationKey&from='+$F('Susername')+'&email='+$F('SEmail'),
			'onLoading':function(req){$('ActivationKeymsg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif /> Requesting content...'},
			'onSuccess':function(req){ 
						if(req.responseText == 'Mail_sent_no'){
							$('ActivationKeymsg').innerHTML='Soon you will receive an email from us and follow the instructions there to activate your Startaid.com Account!';
						}else if(req.responseText == 'Mail_sent_yes'){
							$('ActivationKeymsg').innerHTML="Your StartAid.com account information has been sent to your email account successfully!"
                        }else
							$('ActivationKeymsg').innerHTML= "That account was not found, please try another Username or Email address. "
							new Effect.Highlight('ActivationKeymsg');
						},
			'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
			} 
			);
 }
 function activateaccount()
 {
			if(($F('Ausername').length <= 0) )
			{
			  $('activateaccountmsg').innerHTML= "Random Code Number can not be left blank  !"
			  new Effect.Highlight('activateaccountmsg');
			  new Effect.Highlight('Ausername');
			 return false
			}
			AjaxRequest.get( 
				{ 
				'url':'ajax_st.php?call=activateaccount&from='+$F('Ausername'),
				'onLoading':function(req){$('activateaccountmsg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif /> Requesting content...'},
				'onSuccess':function(req){ 
									if(req.responseText != '')
									{
										$('activateaccountmsg').innerHTML=req.responseText;
										new Effect.Highlight('activateaccountmsg');
										
									} 
									$('activateaccountmsg').innerHTML=req.responseText;
									},
				'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				} 
				); 
	 }
function checkuserlogin(){
	
	AjaxRequest.get( 
		{ 
		'url':'ajax_st.php?call=username&from='+$F('usernamelogin'),
		'onLoading':function(req){$('usernameloginmsg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif /> Requesting content...'},
		'onSuccess':function(req){ 
			if(req.responseText=='exists'){
				document.getElementById('usernameloginmsg').innerHTML='User name <b>'+$F('usernamelogin')+'</b> alredy taken';
				$F('usernamelogin').value=""
				new Effect.Highlight('usernameloginmsg');
			}else 
				document.getElementById('usernameloginmsg').innerHTML=""
			},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		} 
		); 
}
function logout() 
{
   AjaxRequest.get( 
		{ 
		'url':WEB_ROOT+'ajax_st.php?call=ulogout',
		'onSuccess':function(req){ 
			if(req.responseText=='cookies_unset')
			{
				window.location=WEB_ROOT+'index.php';
			}
			},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		} 
		); 
}
function showhint(unm,cond)// verify username existance
{
	if(cond=='username')
	{
	  AjaxRequest.get(
				{
					'url':'ajax_st.php?call=username&from='+unm,
					'onLoading':function(req){$('loadimg').innerHTML="<img src="+WEB_ROOT+"images/loading.gif>"},
					'onSuccess':function(req)
					{ 
						   if(req.responseText=='exists') 
						   {
							  document.getElementById('uhint').innerHTML= "<font color='#FF0000'>\' "+unm+" \' has been taken. </font>";
						   }	   
						   else
						   {
							  document.getElementById('uhint').innerHTML= "";
						   }
						   $('loadimg').innerHTML="";
					}
				}
			);
   }
}
function verify_email()
{
	if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test( $F('email') )))
	{
		$('msgmail').innerHTML="<font color='#FF0000'>Enter correct e-mail address.</font>";
		new Effect.Highlight('msgmail')
		new Effect.Highlight('email')
	}
	else
	{
		$('msgmail').innerHTML="";
	}
}

function signup()
{
	if($F('upusername').length<=0)
	{
		$('uhint').innerHTML="<font color='#FF0000'>Username is required !</font>"
		new Effect.Highlight('uhint')
		new Effect.Highlight('upusername')
	}
	else if($F('pwd').length<=0)
	{
		$('message').innerHTML="<font color='#FF0000'>Password is required !</font>"
		new Effect.Highlight('message')
		new Effect.Highlight('pwd')
	}
	else if($F('cpassword').length<=0)
	{
		$('message').innerHTML="<font color='#FF0000'>Confirm Password is required !</font>"
		new Effect.Highlight('message')
		new Effect.Highlight('cpassword')
	}
	else if($F('pwd') != $F('cpassword') )
	{
			$('message').innerHTML="<font color='#FF0000'>Password does not match !</font>";
			new Effect.Highlight('message')
			new Effect.Highlight('pwd')
			new Effect.Highlight('cpassword')
	}
	else if($F('email').length<=0)
	{
		$('msgmail').innerHTML="<font color='#FF0000'>Email is Required !</font>";
		new Effect.Highlight('msgmail')
		new Effect.Highlight('email')
	}
	else if($F('imgcode').length<=0)
	{
		$('imgcodemsg').innerHTML="<font color='#FF0000'>Image code is required !</font>";
		new Effect.Highlight('imgcodemsg')
		new Effect.Highlight('imgcode')
	}
	else if($F('imgcode')!=$F('imgcodeval'))
	{
		$('imgcodemsg').innerHTML="<font color='#FF0000'>Image code does not match !</font>";
		new Effect.Highlight('imgcodemsg');   
	}
	else// goes for registration entry to table
	{
			 AjaxRequest.get(
				{
					'url':"ajax_st.php?call=signup&upunm="+$F('upusername')+"&passwd="+$F('pwd')+"&email="+$F('email'),
					'onLoading':function (req){$('loadimg').innerHTML="<img src="+WEB_ROOT+"images/loading.gif>"},
					'onSuccess':function(req)
					{ 
					   if(req.responseText=='inserted') 
					   {
						  window.location="index.php?st=hstep4";
					   }	   
					   else if(req.responseText=='duplicate')
					   {
						  $('topmsg').innerHTML= "<font color='#FF0000'>Duplicate Username !</font>";
						  new Effect.Highlight('topmsg');
						  new Effect.Highlight('upusername');
					   }
					   else
					   {
							$('msgmail').innerHTML="<font color='#FF0000'>The Email ["+$F('email')+"] has already been taken. !</font>";
							new Effect.Highlight('msgmail');
							new Effect.Highlight('email');   
					   }
					   $('loadimg').innerHTML="";
					}
			}
			);
 }
}
function matchpasswd()
{
	if( $F('pwd') != $F('cpassword') )
	{
		new Effect.Highlight('pwd')
		new Effect.Highlight('cpassword')
		$('message').innerHTML="<font color='#FF0000'>Password does not match !</font>";
		new Effect.Highlight('message')
	}
	else
	{
		$('message').innerHTML="";
	}
}
function imgcodeverify(st)
{
	if(st==1)
	{
	   AjaxRequest.get(
				{
					'url':"call=codeimage&st=1",
					'onLoading':function (req){$('loadimg').innerHTML="<img src="+WEB_ROOT+"images/loading.gif>"},
					'onSuccess':function(req)
					{ 
						if(req.responseText=='updated')
						{
							$('codeimage').innerHTML=req.responseText;
						}
					}
			}
			);
	}
	else if(st==2)
	{
			 if($F('imgcode')!=$F('imgcodeval'))
	   	     {
			   $('imgcodemsg').innerHTML="<font color='#FF0000'>Image code is required !</font>";
			   new Effect.Highlight('imgcodemsg');   
	 	     }
		     else
  			   $('imgcodemsg').innerHTML="";
   }
}

function Specialcharacterblock(e)
{
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /[\[\]{}\(\)\|\\\+\=\*\&\^\%\$\#\@\~\!\~\`\;\:\'\"\>\<\,\ ]/;
	return !reg.test(keychar);
}
function PercentageCharBlock(e)
{
	//alert("I am here");
	var key = window.event ? e.keyCode : e.which;
	var keychar = String.fromCharCode(key);
	reg = /%/;
	//return !reg.test(keychar);
}
/***************************Add New Link************************************************************************************/


var xmlhttpObject;
function checkvalidurl()
{
	
	var chk = valid_url($F('newurl'));
	if(chk==0)
	{
		$('allmsg').innerHTML="<font color='#FF0000'>Enter Correct URL.</font>";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('newurl');
		return false;
	}
	else   //generate thumbnail image
	{	
		$('allmsg').innerHTML="";
		AjaxRequest.get( 
			{ 
				'url':'ajax_st.php?call=generateimage&newurl='+encodeURIComponent($F('newurl')),
				'onLoading':function(req){$('thumbimg').innerHTML='<img src='+WEB_ROOT+'images/Loadimg.gif>'},
				'onSuccess':function(req)
					{ 
						if(!req.aborted)
						{
							if(req.responseText!='' && req.responseText!='null')
								$('thumbimg').innerHTML="<img src="+WEB_ROOT+"urlimage/HQ_"+req.responseText+">";
							else
								$('thumbimg').innerHTML="<img src="+WEB_ROOT+"images/unable_to_gen.gif>"; 
						}
					},
				'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
			
			} 
		);
		
	}
	//alert("Complete");
	
	return false;
}
function checktitle()
{
	if($F('urltitle').length>0)	
		$('allmsg').innerHTML="";
	else
	{
		$('allmsg').innerHTML="Enter Title of URL.";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('urltitle');
	}
}
function AddLinkcheckDesc()
{
	if(($F('urldesc').length)>=1000)
	{
		$('urldesc').value=$F('urldesc').substring($F('urldesc').indexOf('):')+1,999);
		$('allmsg').innerHTML="Description text Should not more than 1000 character.";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('urldesc');
		$('addnewlinkSubmitbutton').disabled = false;
		return false;
	}
}
function checkaddnewlink(st,mantab,subtab,back_link)
{
	var chk = 1;
	var stk = '';
	
	if(chk==0)
	{
		$('allmsg').innerHTML="Enter Correct URL.";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('newurl');
		return false;
	}
	else if($F('urltitle').length<=0)
	{
		$('allmsg').innerHTML="Enter Title of URL.";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('urltitle');
		return false;
	}
	else
	{  
		
		
		if(st=='insert'){
			URL=WEB_ROOT+'ajax_st.php?call=checkduplink&newurl='+encodeURIComponent($F('newurl'))+'&status=insert';
		    $('addnewlinkSubmitbutton').disabled = 'true';
			
		}else if(st=='update'){
			URL=WEB_ROOT+'ajax_st.php?call=checkduplink&newurl='+encodeURIComponent($F('newurl'))+'&status=update'+'&urlid='+$F('urlid');
			  $('addnewlinkSubmitbutton').disabled = 'true';
		}else if(st=='sggroup'){
			 $('addnewlinkSubmitbutton').disabled = 'true';
			URL=WEB_ROOT+'ajax_st.php?call=SGcheckduplink&newurl='+encodeURIComponent($F('newurl'))+'&urlid='+$F('urlid');
		}
		
		//alert("in the function");
		AjaxRequest.abortAll();
		$('thumbimg').innerHTML="<img src="+WEB_ROOT+"images/unable_to_gen.gif>";
		AjaxRequest.get( 
			{ 
			'url':URL,
			'onLoading':function(req){AjaxRequest.abortAll();$('linkloading').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req){ 
				if(req.responseText!="OK")
				{
					if(confirm(req.responseText))
					{
						if(st=='insert')
						{
							insertdata('insert',mantab,subtab,back_link);
						}
						else if(st=='update')
						{
							insertdata('update',mantab,subtab,back_link);
						}
						else if(st=='sggroup')
						{
							insertdata('sggroup',mantab,subtab,back_link);
						}
					}
				}
				else
				{
						if(st=='insert')
						{
							insertdata('insert',mantab,subtab,back_link);
						}
						else if(st=='update')
						{
							insertdata('update',mantab,subtab,back_link);
						}
						else if(st=='sggroup')
						{
							insertdata('sggroup',mantab,subtab,back_link);
						}
				}
					$('linkloading').innerHTML="";
				},
			'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
			} 
			
		);
		//when duplicate not found
		//alert("I am here");
		return false;
	}
}
function insertdata(pick,mantab,subtab,back_link)
{
	 if(($F('urldesc').length)>=1000){
		  $('urldesc').value=$F('urldesc').substring($F('urldesc').indexOf('):')+1,999);
		  $('allmsg').innerHTML="Description text Should not more than 1000 character.";
			new Effect.Highlight('allmsg');
			new Effect.Highlight('urldesc');
			$('addnewlinkSubmitbutton').disabled = false;
		  return false;
		  }
	 if(($F('urltitle').length)>=150){
	  $('urltitle').value=$F('urltitle').substring($F('urltitle').indexOf('):')+1,150);
	    $('allmsg').innerHTML="Title text Should not more than 150 character.";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('urltitle');
		$('addnewlinkSubmitbutton').disabled = false;
		return false;
	  }
	 var urldesc=$F('urldesc').substring($F('urldesc').indexOf('):')+1,999);
	 var urltitle=$F('urltitle').substring($F('urltitle').indexOf('):')+1,150);
   if(pick=='insert')
	{
		var urlval=WEB_ROOT+'ajax_st.php?call=addnewlink&newurl='+encodeURIComponent($F('newurl'))+'&urltitle='+encodeURIComponent(urltitle)+'&urltags='+$F('urltags')+'&urldesc='+encodeURIComponent(urldesc)+'&urlstatus='+$F('urlstatus')+'&urlfavorite='+$F('urlfavorite')+'&status='+pick+'&categoryid='+$F('categoryid');
	}
	else if(pick=='update')
	{
		if($F('img_type')=='server')
			var snaptype='S';
		else
			var snaptype='U';
		var urlval=WEB_ROOT+'ajax_st.php?call=addnewlink&newurl='+encodeURIComponent($F('newurl'))+'&urltitle='+encodeURIComponent(urltitle)+'&urltags='+encodeURIComponent($F('urltags'))+'&urldesc='+encodeURIComponent(urldesc)+'&urlstatus='+encodeURIComponent($F('urlstatus'))+'&urlfavorite='+$F('urlfavorite')+'&status='+pick+'&urlid='+$F('urlid')+'&snaptype='+snaptype+'&categoryid='+$F('categoryid');
	}
	else if(pick=='sggroup')
	{
		if($F('img_type')=='server')
			var snaptype='S';
		else
			var snaptype='U';
		var urlval=WEB_ROOT+'ajax_st.php?call=sgaddnewlink&newurl='+encodeURIComponent($F('newurl'))+'&urltitle='+encodeURIComponent(urltitle)+'&urltags='+$F('urltags')+'&urldesc='+encodeURIComponent(urldesc)+'&status='+pick+'&urlid='+$F('urlid')+'&snaptype='+snaptype+'&categoryid='+$F('categoryid');
	}
	AjaxRequest.abortAll();	
	AjaxRequest.post( 
			{ 		
			'url':urlval,
			'onLoading':function(req){$('linkloading').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req){
				if(req.responseText=='inserted')
						{
							if(getCookie("UserAddnewlink")===$F('urlid'))
							{
								var tempuser=getCookie("UserName");
								setCookie("UserAddnewlink","");
								setCookie("UserName","");
								new Ajax.Updater('maincontainer', WEB_ROOT+'tempuser_links.php?tempuser='+tempuser, {onLoading:function(request){}, onComplete:function(request){return false;}});
								return false;
							}
							else if(getCookie("QuickBookmarkStatus")==='Fine')
							{
								var urlname=getCookie("QuickBookmarkLink");
								setCookie("QuickBookmarkStatus","");
								window.location=urlname;
							}
							else
							{   
					if(LEFT_MAIN_TABS=='MyCategories'){
						clicklink_sidetab('MyCategories','treeviewmanage',WEB_ROOT+'my_tree_view_manage.php');
					}else{
						clicklink('tabmainmenu','siadecontenar',LEFT_MAIN_TABS);}
								if(LEFT_MAIN_TABS=='MyCategories')
								{
									var pagename=WEB_ROOT+'manage_links.php?orderby=urldate&ascdesc=desc&catid='+$F('categoryid');
									var nexttab="ManagedLinks";
								}
								else if(LEFT_MAIN_TABS=='MyTags' || LEFT_MAIN_TABS=='PublicTags')
								{
									var pagename=WEB_ROOT+'mytag_listview_startpage.php?linkstatus=all&orderby=urldate&ascdesc=desc';
									var nexttab="ManagedLinks";
								}
								clicklink_secont(RIGHT_MAIN_TABS,nexttab,pagename);
							}
						}
						else if(req.responseText=='updated')
						{
							clicklink_sidetab('MyCategories','treeviewmanage',WEB_ROOT+'my_tree_view_manage.php');
							clicklink_secont(mantab,subtab,back_link)
							
							//alert($F('categoryid'))
						}
						
						$('linkloading').innerHTML='';
				},
			'onError':function(req){ alert('Re Enter in description text and submit again');
			$('linkloading').innerHTML='';
			}
			} 
			);
		return false;
}
	
function spellchecking(st)
{
	if($F('urldesc').length>=1 && st==1)
	{
		AjaxRequest.get( 
		{ 
		'url':WEB_ROOT+'ajax_st.php?call=spellcheck&spelldata='+$F('urldesc'),
		'onLoading':function(req){$('spellerror').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req){ 
			$('spellerror').innerHTML=req.responseText;
			setupSpeling(1);
			},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		} 
		);
	}
	if($F('urltitle').length>=1 && st==2)
	{
		AjaxRequest.get( 
		{ 
		'url':WEB_ROOT+'ajax_st.php?call=spellcheck&spelldata='+$F('urltitle'),
		'onLoading':function(req){$('spelltitle').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req){ 
			$('spelltitle').innerHTML=req.responseText;
			
			setupSpeling(2);
			},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		} 
		);
	}
	if($F('urltags').length>=1 && st==3)
	{
		AjaxRequest.get( 
		{ 
		'url':WEB_ROOT+'ajax_st.php?call=spellcheck&spelldata='+$F('urltags'),
		'onLoading':function(req){$('spelltags').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req){ 
			$('spelltags').innerHTML=req.responseText;
			setupSpeling(3);
			},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		} 
		);
	}
}


function setupSpeling(boxst) 
{
    // Loop through span tags adding magic right menu to them
    spans = document.getElementsByTagName('span');
    for (var i = 0; i<spans.length; i++) 
	{
	    var span = spans[i];
        if (span.className=='speling') 
		{
            // Attach magic events
           		span.suggestions=span.title;
           	 	span.title='Click to correct spelling';
            	addEvent(span,'click',function(e){
                var pos=getMousePosition(e);
                var target=getTarget(e);
                var suggestions=target.suggestions;
                var word=target.firstChild.nodeValue;
                // alert('Word: '+word+' Suggestions: '+suggestions);
                // alert('X: '+pos.x+' Y: '+pos.y+' Corrections: '+targ.title);
                // Destroy menu if it already exists
                if (spelingMenu != null) 
				{
                    document.getElementsByTagName('body')[0].removeChild(spelingMenu);
                    spelingMenu=null;
                }
                var globalspan = this;
                var menu = makeMenu(word, suggestions, pos,boxst);
                document.getElementsByTagName('body')[0].appendChild(menu);
                spelingMenu = menu;
            });
        }
    }
}

/***************************************************************************************************************/
function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, true);
    return true;
  } else if (obj.attachEvent){
    var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
    return false;
  }
}

function removeEvent(elm, evType, fn)
{
  if (elm.removeEventListener){
    elm.removeEventListener(evType, fn, true);
    return true;
  } else if (elm.detachEvent){
    var r = elm.detachEvent("on"+evType, fn);
    return r;
  } else {
    return false;
  }
}

function isRightClick(e)
{
    var rightclick;
	// Tests if an event is a right-click - see http://www.xs4all.nl/~ppk/js/events_properties.html
	if (!e) var e = window.event;
	if (e.which) rightclick = (e.which == 3);
	else if (e.button) rightclick = (e.button == 2);
	return rightclick;
}

/*function getTarget(e)
{
	var targ;
	if (!e) var e = window.event;
	if (e.target) targ = e.target;
	else if (e.srcElement) targ = e.srcElement;
	// Nasty mozilla specific code - IE returns a span but Moz sometimes returns the text node
    if (targ.nodeType == 3) {
        targ = targ.parentNode;
    }
	return targ;
}*/
function getTarget(e)
{
	var targ;
	if(checkBrowser() == "ie")
	{
		targ = window.event.srcElement;
	}
	else
	{
		targ = e.target;
	}
	return targ;
};
function checkBrowser()
{
	var theAgent = navigator.userAgent.toLowerCase();
	if(theAgent.indexOf("msie") != -1)
	{
		if(theAgent.indexOf("opera") != -1)
		{
			return "opera";
		}
		else
		{
			return "ie";
		}
	}
	else if(theAgent.indexOf("netscape") != -1)
	{
		return "netscape";
	}
	else if(theAgent.indexOf("firefox") != -1)
	{
		return "firefox";
	}
	else if(theAgent.indexOf("mozilla/5.0") != -1)
	{
		return "mozilla";
	}
	else if(theAgent.indexOf("\/") != -1)
	{
		if(theAgent.substr(0,theAgent.indexOf('\/')) != 'mozilla')
		{
			return navigator.userAgent.substr(0,theAgent.indexOf('\/'));
		}
		else
		{
			return "netscape";
		} 
	}
	else if(theAgent.indexOf(' ') != -1)
	{
		return navigator.userAgent.substr(0,theAgent.indexOf(' '));
	}
	else
	{ 
		return navigator.userAgent;
	}
} // end checkBrowser

//-------------------
function getMousePosition(e)
{
	var pos = {x: 0, y: 0};
	if (!e) var e = window.event;
	if (e.pageX || e.pageY)
	{
		pos.x = e.pageX;
		pos.y = e.pageY;
	}
	else if (e.clientX || e.clientY)
	{
		pos.x = e.clientX + document.body.scrollLeft;
		pos.y = e.clientY + document.body.scrollTop;
	}
	return pos;
}
function makeMenu(word, suggestions, pos,boxst) 
{
    var words = new Array();
    words = suggestions.split(', ');
	menu = document.createElement('div'); 
	menu.id="menudiv";
	menu.style.position = "absolute"; 
	menu.style.left = (pos.x - 10);
	menu.style.top = (pos.y - 10); 
	menu.className = 'spelingMenu'; 
    // Make sure this item has at least one suggestion
    if (words[0] == '') {
        // Add "None available" notice
        var none = document.createElement('div');
        none.appendChild(document.createTextNode('None available'));
        menu.appendChild(none);
    }
    for (var i = 0; i < 5; i++) 
	{	// restricting the suggestion to only five words
        var item = document.createElement('a');
        item.href = 'javascript:void(0);';
        var newword = words[i];
        var text = document.createTextNode(newword);
        item.word = newword;
        item.appendChild(text);
        menu.appendChild(item);
        // Add event - at the moment this works on the textarea with id="speling"
       // var textarea = document.getElementById('speling');
	           // Add event - at the moment this works on the textarea with id="speling"
		if(boxst==1)
	        var textarea=document.getElementById('urldesc');
		else if(boxst==2)
			var textarea=document.getElementById('urltitle');
		else if(boxst==3)
			var textarea=document.getElementById('urltags');

      	  addEvent(item, 'click', function(e) {
            var re = new RegExp('(\\W|^)'+word+'(\\W|$)', 'gim');;
            
			
			textarea.value = textarea.value.replace(re, '$1'+getTarget(e).word+'$2');
			document.getElementById(word+'_spellcheckspan').innerHTML=getTarget(e).word;
			document.getElementById(word+'_spellcheckspan').className="";
            // Change the span to have the correct text as well
			  //globalspan.firstChild.nodeValue=getTarget(e).word;
              //globalspan.className=''; 
            // Now close the menu
            document.getElementsByTagName('body')[0].removeChild(menu);
            spelingMenu = null;
        });
    }
    // Add "cancel" button
    var cancel = document.createElement('div');
    cancel.className = 'cancel';
    cancel.appendChild(document.createTextNode('cancel'));
    addEvent(cancel, 'click', function(e) {
        document.getElementsByTagName('body')[0].removeChild(spelingMenu);
        spelingMenu = null;
    });
    menu.appendChild(cancel);
    return menu;
}

var spelingMenu = null;

addEvent(window, "load", setupSpeling);
/******************************************Manage Links*******************************************************************/
function deletelink(urlid,mantab,subtab,container)
{
	if(confirm('Do you want to delete this link?'))
	 {      AjaxRequest.get(
				{
					'url':'ajax_st.php?call=deletelink&urlid='+urlid,
					'onLoading':function (req){
						new Effect.Opacity(container, {duration:0.2, from:1.0, to:0.5});
					//$(container).innerHTML='<img src=images/loading.gif';
					},
					'onSuccess':function(req)
					{ 
						if(req.responseText=='deleted')
						{  
							new Effect.SlideUp(container); 
							//Element.remove(container,{duration:0.5});							 
						}
				   }
			}
			);
			}
	}
function editaddedlink(mantab,subtab,back_link,linkid,sggroup)
{	
	//clicklink_sidetab("MyCategories","treeview",WEB_ROOT+"my_tree_view.php");
	clicklink_sidetab('MyCategories','treeviewmanage','my_tree_view_manage.php');
	clicklink_secont("addnewlink","",WEB_ROOT+'editlink.php?urlid='+linkid+'&sggroup='+sggroup+'&back_link='+encodeURIComponent(back_link)+'&mantab='+mantab+'&subtab='+subtab);
}
function manageaddnewlink()
{
	clicklink_sidetab('MyCategories','treeviewmanage','my_tree_view_manage.php');
	clicklink_secont('addnewlink','','addnewlink.php');
}
function chgurlstatus(urlid,st,orderby,ascdesc,page,pgname,memstatus)
{
	if(st=='favorite')
		var url='ajax_st.php?call=chgurlstatus&urlid='+urlid+'&status='+st+'&memstatus='+memstatus;
	else if(st=='private')
		var url='ajax_st.php?call=chgurlstatus&urlid='+urlid+'&status='+st+'&memstatus='+memstatus;
	if(st=='positive')
		var url='ajax_st.php?call=chgurlstatus&urlid='+urlid+'&status='+st+'&memstatus='+memstatus;
	else if(st=='negative')
		var url='ajax_st.php?call=chgurlstatus&urlid='+urlid+'&status='+st+'&memstatus='+memstatus;
	AjaxRequest.get(
				{
					'url':url,
					'onLoading':function (req){},
					'onSuccess':function(req)
					{ 
						if(st=='favorite')	
						{
							new Effect.Highlight($('StarImg'+urlid));
							new Effect.Opacity($('StarImg'+urlid), {duration:1.0, from:0.5, to:1.0});
							swap_image('StarImg'+urlid,'star_active.gif','star_symbol.gif');
						}
						else if(st=='private')
						{
							new Effect.Highlight($('LockImg'+urlid));
							new Effect.Opacity($('LockImg'+urlid), {duration:1.0, from:0.5, to:1.0});
							swap_image('LockImg'+urlid,'lock_symbol.gif','lock_active.gif');
						}
						else
						//if(req.responseText=='updated')
						{
							new Ajax.Updater('maincontainer', pgname+'?orderby='+orderby+'&ascdesc='+ascdesc+'&page='+page, {onLoading:function(request){}, onComplete:function(request){}})//$('startimg').innerHTML=''}})
						}
					}
				}
			);
}

/*************************************************************************************************************/

/******************************manage link order by *************************************************************/
function managelink_orderby(imgnm,order)
{   
	var imageobj = document.getElementById(imgnm+'_order')
	imageobj.src='images/'+imageobj.name+'_active.gif';
	clicklink_secont("mylink","ManagedLinks",WEB_ROOT+'manage_links.php?orderby='+imgnm+'&ascdesc='+order)
	//new Ajax.Updater('maincontainer', WEB_ROOT+'manage_links.php?orderby='+imgnm+'&ascdesc='+order, {onLoading:function(request){$('loadingimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){
	
	//$('loadingimg').innerHTML=''
	//}})
	

}

function mylinkstartpage_orderby(fieldname,ascdesc,page)
{
	new Ajax.Updater('maincontainer', 'mytag_listview_startpage.php?orderby='+fieldname+'&ascdesc='+ascdesc+'&page='+page, {onLoading:function(request){$('startimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('startimg').innerHTML=''}})							
}
function email_push_link(urlid,back_link,mantab,subtab)
{
	//new Ajax.Updater('maincontainer', 'email_or_push_this_link_to_a_friend.php?urlid='+urlid+'&back_link='+encodeURIComponent(back_link), {onLoading:function(request){$('loadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('loadimg').innerHTML=''}})
	new Effect.ScrollTo('ScrollTop');
	clicklink_secont(mantab,subtab,WEB_ROOT+'email_or_push_this_link_to_a_friend.php?urlid='+urlid+'&back_link='+encodeURIComponent(back_link)+'&mantab='+mantab+'&subtab='+subtab)
}
//coding of 12 july 2006 ***********************************
function uploadcheck(st,Layer)
{
	if(st=='1')
	{
		AjaxRequest.get({
					'url':'ajax_st.php?call=generateimage&newurl='+encodeURIComponent($F('newurl'))+'&status=serverimage',
					'onLoading':function(req){$('thumbimg').innerHTML='<img src=images/Loadimg.gif>'},
					'onSuccess':function(req)
					{
						if(req.responseText!='')
							$('thumbimg').innerHTML="<img src=urlimage/"+req.responseText+">";
						else
							$('thumbimg').innerHTML="<img src='images/unable_to_gen.gif'>";
					}
					});	
	}
}
function refresh_snapshot()
{
	AjaxRequest.get({
					'url':'ajax_st.php?call=generateimage&newurl='+encodeURIComponent($F('newurl'))+'&status=refresh',
					'onLoading':function(req){$('thumbimg').innerHTML='<img src='+WEB_ROOT+'images/Loadimg.gif>'},
					'onSuccess':function(req)
					{
						if(req.responseText!='')
							$('thumbimg').innerHTML="<img src="+WEB_ROOT+"urlimage/"+req.responseText+">";
						else
							$('thumbimg').innerHTML="<img src="+WEB_ROOT+"images/unable_to_gen.gif>";
					}
					});	
}
function upload()
{
 		alert("alersdfasdf")
}
//****************************************************************

/**********Change password in Edit Profile page******************/
function chgpasswdcheck()
{
	if($F('newpasswd')!=$F('rnewpasswd'))
	{
		$('loadimg').innerHTML='New passwords does\'t match.';
		new Effect.Highlight('loadimg');
		new Effect.Highlight('newpasswd');
		new Effect.Highlight('rnewpasswd');
	}
	else
		$('loadimg').innerHTML='';
}
function oldpassword(passwd)
{
	AjaxRequest.get({
		'url':'ajax_st.php?call=oldpassword&passwd='+passwd,
		'onLoading':function(req){$('loadimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('loadimg').innerHTML='';	
			if(req.responseText!='correct')
			{
				$('loadimg').innerHTML='Please enter correct old password.';
				new Effect.Highlight('loadimg');
				new Effect.Highlight('oldpasswd');
			}
		}
		});
}
function validate_profile()
{
	if($F('oldpasswd').length<=0)
	{
		$('loadimg').innerHTML='Please enter old password.';
		new Effect.Highlight('loadimg');
		new Effect.Highlight('oldpasswd');
	}
	else if($F('newpasswd').length<=0)
	{
		$('loadimg').innerHTML='Please enter new password.';
		new Effect.Highlight('loadimg');
		new Effect.Highlight('newpasswd');
	}
	else if($F('rnewpasswd').length<=0)
	{
		$('loadimg').innerHTML='Please re-enter new password.';
		new Effect.Highlight('loadimg');
		new Effect.Highlight('rnewpasswd');
	}
	else if($F('newpasswd')!=$F('rnewpasswd'))
	{
		$('loadimg').innerHTML='New passwords does\'t match.';
		new Effect.Highlight('loadimg');
		new Effect.Highlight('newpasswd');
		new Effect.Highlight('rnewpasswd');
	}
	else
	{
		AjaxRequest.get({
		'url':'ajax_st.php?call=changepassword&oldpasswd='+$F('oldpasswd')+'&newpasswd='+$F('newpasswd'),
		'onLoading':function(req){$('loadimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('loadimg').innerHTML='';	
			if(req.responseText=='updated')
			{
				$('loadimg').innerHTML='Password changed successfully !';
				new Effect.Highlight('loadimg');
				$('oldpasswd').value='';
				$('newpasswd').value='';
				$('rnewpasswd').value='';
			}
			else
			{
				$('loadimg').innerHTML='Please re-check your old password !';
				new Effect.Highlight('loadimg');
			}
			
		}
		});
	}
}
/*****************end********************************************/
///*************My tag cloud text color************/
function openstartpage(tag,st,sgid)
{
	if(st=='usermytag')
	{
		clicklink_secont("tagresult","",WEB_ROOT+'userpublictagslinks.php?status=first&username='+sgid+'&tagname='+tag);
	}
	if(st=='mytag')	
	{	
		/*setCookie("tags",tag);
		setCookie("sharegroup","");
		clicklink('topmenu','maincontainer','mylink');
		new Ajax.Updater('maincontainer', WEB_ROOT+'mytag_listview_startpage.php', {onLoading:function(request){$('loadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'}, onComplete:function(request){$('loadimg').innerHTML=''}})
		*/
		setCookie("rtags",replaceAll(tag.trim()," ","_9_a_"));
		clicklink_secont('mylink','ManagedLinks',WEB_ROOT+'mytag_listview_startpage.php?tags='+replaceAll(tag.trim()," ","_9_a_"));
		//for related tags
				AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=privaterelatedtag&tagname='+replaceAll(tag.trim()," ","_9_a_"),
				'onLoading':function(req){$('loadsideimage').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req)
				{
					$('loadsideimage').innerHTML='';
					if(req.responseText!='')
					{
						$('relatedtagsdiv').style.display='inline';
						$('relatedtags').innerHTML=req.responseText;
					}
					else
					{
						$('relatedtagsdiv').style.display='none';
					}
				}
				});
	}
	if(st=='sharegroup')
	{
		/*clicklink('topmenu','maincontainer','mylink');
		setCookie("tags",tag);
		setCookie("sharegroup","sharegrp");
		setCookie("sgid",sgid);
		new Ajax.Updater('maincontainer', WEB_ROOT+'mytag_listview_startpage.php', {onLoading:function(request){$('loadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'}, onComplete:function(request){$('loadimg').innerHTML=''}})
		*/
		setCookie("rtags",replaceAll(tag.trim()," ","_9_a_"));		
		clicklink_secont('mylink','ManagedLinks',WEB_ROOT+'mytag_listview_startpage.php?tags='+replaceAll(tag.trim()," ","_9_a_")+'&sharegroup=sharegrp&sgid='+sgid);
		AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=privaterelatedtag&tagname='+replaceAll(tag.trim()," ","_9_a_")+'&status=sharegroup&sgid='+sgid,
			'onLoading':function(req){$('loadsideimage').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('loadsideimage').innerHTML='';
				if(req.responseText!='')
				{
					$('relatedtagsdiv').style.display='inline';
					$('relatedtags').innerHTML=req.responseText;
				}
				else
				{
					$('relatedtagsdiv').style.display='none';
				}
			}
			});
	}
	if(st=='public')// this section is basically for public tags
	{
		setCookie("tags",replaceAll(tag.trim()," ","_9_a_"));	
		setCookie("rtags","");
		clicklink_secont('tagresult','',WEB_ROOT+'publictagslinks.php?status=first&tags='+replaceAll(tag.trim()," ","_9_a_")+'&rtags='+getCookie('rtags'));
		//if(sgid=='cloud')
		//{
			AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=PublicTagsCloud&tagname='+replaceAll(tag.trim()," ","_9_a_"),
				'onLoading':function(req){$('loadsideimage').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req)
				{
					$('loadsideimage').innerHTML='';
					if(req.responseText!='')
					{
						$('relatedtagsdiv').style.display='inline';
						$('relatedtags').innerHTML=req.responseText;
					}
					else
					{
						$('relatedtagsdiv').style.display='none';
					}
				}
				});
		//}
	}
}
String.prototype.trim = function() {
a = this.replace(/^\s+/, '');
return a.replace(/\s+$/, '');
};
function PublicRelatedTags(tagname)
{
	if(getCookie("rtags")==null || getCookie("rtags")=='')
	{
		setCookie("rtags",getCookie("tags"));
		var tak=getCookie("rtags")+" *"+tagname;
		setCookie("rtags",tak);
	}
	else
	{
		var tak=getCookie("rtags")+" *"+tagname;	
		setCookie("rtags",tak);
	}	
	setCookie("tags",getCookie("tags")+" *"+tagname);
	clicklink_secont('tagresult','','publictagslinks.php?status=rtags&rtags='+getCookie('rtags'));
	AjaxRequest.get({
		'url':'ajax_st.php?call=PublicTagsCloud&tagname='+getCookie('rtags')+'&status=rtags',
		'onLoading':function(req){$('loadsideimage').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('loadsideimage').innerHTML='';
			if(req.responseText!='')
			{
				$('relatedtagsdiv').style.display='inline';
				$('relatedtags').innerHTML=req.responseText;
			}
			else
			{
				$('relatedtagsdiv').style.display='none';
			}
		}
		});
}
function PrivateRelatedTags(tagname,status,sgid)
{

	var tak=getCookie("rtags")+" *"+tagname;	
	setCookie("rtags",tak);
	if(status=='sharegroup')
	{
		clicklink_secont('mylink','ManagedLinks',WEB_ROOT+'mytag_listview_startpage.php?status=related&tags='+getCookie("rtags")+'&sharegroup=sharegrp&sgid='+sgid);
	}
	else
	{
		clicklink_secont('mylink','ManagedLinks',WEB_ROOT+'mytag_listview_startpage.php?status=related&tags='+getCookie("rtags"));
	}
	AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=privaterelatedtag&tagname='+getCookie("rtags")+'&tagstatus=rtags&status='+status+'&sgid='+sgid,
				'onLoading':function(req){$('loadsideimage').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req)
				{
					$('loadsideimage').innerHTML='';
					if(req.responseText!='')
					{
						$('relatedtagsdiv').style.display='inline';
						$('relatedtags').innerHTML=req.responseText;
					}
					else
					{
						$('relatedtagsdiv').style.display='none';
					}
				}
				});
}
function make_orderby(fieldname,ascdesc,page,status,pagename)
{
	if(pagename=='publicfullcloud.php')
	{
		var fval='publictag_fullcloud_orderby';
		var oval='publictag_fullcloud_ascdesc';
	}
	else if(pagename=='publicfulltree.php')
	{
		var fval='publictag_fulltree_orderby';
		var oval='publictag_fulltree_ascdesc';
	}
	else if(pagename=='publichottree.php')
	{
		var fval='publictag_hottree_orderby';
		var oval='publictag_hottree_ascdesc';
	}
	else if(pagename=='publickcloud.php')
	{
		var fval='publictag_hotcloud_orderby';
		var oval='publictag_hotcloud_ascdesc';
	}
	else if(pagename=='mytagcloud.php')
	{
		var fval='mytag_cloudview_orderby';
		var oval='mytag_cloudview_ascdesc';
	}
	else if(pagename=='mytaglistview.php')
	{
		var fval='mytag_listview_orderby';
		var oval='mytag_listview_ascdesc';
	}
	else if(pagename=='mytagstree.php')
	{
		var fval='mytag_treeview_orderby';
		var oval='mytag_treeview_ascdesc';
	}

	if(status=='mytagcloud')
	{
		new Ajax.Updater('siadecontenar',pagename+'?orderby='+fieldname+'&ascdesc='+ascdesc+'&page='+page, {onLoading:function(request){$('tagloading').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('loadingimg').innerHTML=''}})							
		pagewise_orderby(fieldname,fval);
		pagewise_orderby(ascdesc,oval);
	}
}
function allpublictagslinks(linkstatus,sgid)
{
	if(linkstatus=='phottree' || linkstatus=='photcloud')
	{
		clicklink_secont('pHotLinks','','publictagslinks.php?pstatus=all&linkstatus='+linkstatus)
	}
	else if(linkstatus=='pfullcloud' || linkstatus=='pfulltree')
	{
		clicklink_secont('pAllLinks','','publictagslinks.php?pstatus=all&linkstatus='+linkstatus)
	}
	else if(linkstatus=='mylinks')
	{
		clicklink_secont('mylink','ManagedLinks','mytag_listview_startpage.php?linkstatus=all')
	}
	else if(linkstatus=='sharegroup')
	{
		clicklink_secont('mylink','ManagedLinks','mytag_listview_startpage.php?linkstatus=sharegroup&shgrpid='+sgid)
	}	
}
//*****************end**************************/
function SlideEditProfile(Layer)
{
	if($(Layer).style.display=="none")
	{
		$(Layer).style.display='inline';
		AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=SlideEditProfile',
			'onSuccess':function(req)
			{
				$(Layer).innerHTML=req.responseText;
			}
			});	
	}
	else
	{
		Effect.SlideUp(Layer)
	}
}
function SlideEditMessage(Layer)
{
	if($(Layer).style.display=="none")
	{
		Effect.SlideDown(Layer)
	}
	else
	{
		Effect.SlideUp(Layer)
	}
}

//****************Share Group Information ***********************/
function DisplaySG()
{
	$('AddSG').style.display='inline';
}
function CloseSGAdd(sgid)
{
	if(sgid=='om')
	{
		$F('sgname').value='';
		$('AddSG').style.display='none';
	}
	else
	{
		$(sgid+'SaveCloseButton').style.display='none';	
		$(sgid+'EditSG').style.display='none';
		$(sgid+'EditButton').style.display='inline';
		$(sgid+'OwnerFriend').innerHTML='';
		$(sgid+'OwnerFriend').style.display='none';
		$(sgid+'SgOwnerList').innerHTML='';
		$(sgid+'SgOwnerList').style.display='none';
	}
}
function AddNewShareGroup()
{
	if($F('sgname').length>2)
	{
		AjaxRequest.get({
		'url':WEB_ROOT+'ajax_st.php?call=checkdupsg&sgname='+$F('sgname')+'&status=add',
		'onLoading':function(req){$('sgimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req)
		{
			if(req.responseText=='duplicate')
			{
				$('sgimg').innerHTML="Share Group name already exits !";
				new Effect.Highlight('sgimg');
				new Effect.Highlight('sgname');
			}
			else
			{
				$F('sgname').value='';
				clicklink_secont("mylink","ShareGroup",WEB_ROOT+'manage_share_groups.php');
				//new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})
			}
		}
		});
	}
	else
	  	alert("Share Group name should be more than two character !")
}

function SearchSGName()
{
	if($F('searchdata').length>0)
	{
		AjaxRequest.get({
		'url':'ajax_st.php?call=SearchSGName&searchdata='+$F('searchdata'),
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='';
			$('searchResult').innerHTML=req.responseText;
		}
		});
	}
}
function ApplyForAccess(sgid)
{
	AjaxRequest.get({
		'url':'ajax_st.php?call=ApplyForAccess&sgid='+sgid,
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML=req.responseText;
			//new Effect.Highlight('sgimg');
			new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})	
		}
		});
}
function EditableSG(sgid)
{
	//$(sgid+'EditSGName').style.display='none';	
	$(sgid+'SaveCloseButton').style.display='inline';	
	$(sgid+'EditSG').style.display='inline';
	$(sgid+'EditButton').style.display='none';
}
function SaveEditSG(sgid)
{
	if($F(sgid+'Editbox').length>=3)
	{
		if(confirm("Are You Sure !"))		
		{
		AjaxRequest.get({
			'url':'ajax_st.php?call=SaveEditSG&sgid='+sgid+'&SGName='+$F(sgid+'Editbox'),
			'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
			'onSuccess':function(req)
			{
				//$(sgid+'EditSGName').style.display='inline';	
				$(sgid+'EditSG').style.display='none';
				new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})							
			}
			});
		}
	}
	else
		alert("Share Group name should be more than two character !");
}
function ChangeSGType(sgid,apptuname,accesstype)
{
	if(accesstype=='delmeb')
		var take=confirm("Are you sure ?\n Do you want to delete it?")
	else
		var take=true;
	if(take)
	{
		AjaxRequest.get({
		'url':'ajax_st.php?call=ChangeSGType&sgid='+sgid+'&apptuname='+apptuname+'&accesstype='+accesstype,
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='';
			new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})							
		}
		});
	}
}
function DeleteShareGroup(sgid)
{
	if(confirm("Are you sure?\n Do you want to delete this Share Group"))
	{
		AjaxRequest.get({
		'url':'ajax_st.php?call=DeleteShareGroup&sgid='+sgid,
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='';
			new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})	
		}
		});
	}
}
function ApplicantApproval(appliedby,sgid,apptid,option)
{
	if(confirm("Do you want to "+option+" this applicant request ?"))
	{
		AjaxRequest.get({
		'url':'ajax_st.php?call=ApplicantApproval&sgid='+sgid+'&appliedby='+appliedby+'&apptid='+apptid+'&option='+option,
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='';
			new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})
		}
		});
	}
}
function DeletePendingMYSG(pendid,st)
{
	if(st=='mypending')
	{
	 AjaxRequest.get({
		'url':'ajax_st.php?call=DeletePendingMYSG&pendid='+pendid,
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='';
			new Ajax.Updater('maincontainer', 'manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})
		}
		});
	}
}
function ShowMessageDiv(sgdivid,st)
{
	if(st=='show' && $(sgdivid).style.display=="none")
		Effect.SlideDown(sgdivid);
	else if(st=='hide')
	{
		Effect.SlideUp(sgdivid);
		$('sgimg').innerHTML='';
	}
}
function SendSGMessage(sendby,sgid)
{
	if($F('SGmessage'+sgid).length>1)
	{
	  AjaxRequest.get({
		'url':'ajax_st.php?call=SendSGMessage&sendby='+sendby+'&sgid='+sgid+'&sgmsg='+$F('SGmessage'+sgid),
		'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='Your message sent successfully.';
			$('SGmessage'+sgid).value='';
			new Effect.Highlight('sgimg')
		}
		});
	}
	else
	{
		alert("Message length should have more than one characters !");
	}
}
function share_group_friend(fri_id){
	AjaxRequest.get( 
				{ 
				'url':'ajax_st.php?call=addfriend&friend_id='+encodeURIComponent(fri_id),
				'onLoading':function(req){$('sgimg').innerHTML='<img src=images/loading.gif>'},
				'onSuccess':function(req)
				{
	new Ajax.Updater('maincontainer','manage_share_groups.php', {onLoading:function(request){$('sgimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('sgimg').innerHTML=''}})
				},
				'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				} 
				);  
}

//****************End of share group***********************/
//*****************Bulletin Board Section*****************/

function PostBBmessage(userid)
{
	if($F('BBMessage').length>0)
	{
		if($F('BBMessage').indexOf('):')===-1)
			var msg=$F('BBMessage');
		else
			var msg=$F('BBMessage').substring($F('BBMessage').indexOf('):')+2,$F('BBMessage').length);
		
		var friend = $('friends1').options[$('friends1').selectedIndex].value
		var pass;
		var sendTo;
		//alert($('msgstatus').value)
		if(!friend)
		{
			if(($('msgstatus').value == '*check*') || (!$('msgstatus').value))
			{
				alert("Please select a friend from the list to send message");
				pass = false;
			}
			else
			{
				pass 	= true ;
				sendTo 	= $('msgstatus').value ;
			}
		}
		else
		{
			pass 	= true ;
			sendTo 	= friend ;
		}
		
		if(pass)
		{
			AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=PostBBmessage&sendby='+userid+'&sgmsg='+$F('BBMessage')+'&status=' + sendTo ,
				'onLoading':function(req){$('loadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req)
				{
					$('loadimg').innerHTML='';
					new Insertion.Top('BBSubLayer','<div id="bmsg'+req.responseText+'"><b><a class=bluebold href="'+WEB_ROOT+'/'+userid+'/">'+userid+'</a>&nbsp;:&nbsp;</b> '+msg+'<br><span style="font-size:10px">0 seconds ago <b><a href="javascript:void(0)" class="cloud" onclick="Deletemessage('+req.responseText+',bmsg'+req.responseText+')">delete</a></b></span></div>');
					new Effect.Highlight('bmsg'+req.responseText);
					$('BBMessage').value='';
				}
				});
		}
		
	}
}
function Replymessage(Nm)
{
	$('BBMessage').focus();
	$('BBMessage').value = "(msg|"+Nm+"): ";
	$('msgstatus').value=Nm;
}
function Deletemessage(msgid,Layer)
{
	AjaxRequest.get(
	  {
		'url':'ajax_st.php?call=Deletemessage&msgid='+msgid,
		'onSuccess':function(req)
		{
			new Effect.SlideUp(Layer); 
		}
	  }
	);
}
function Blockusermess(userblocked,msgid,Layer)
{
	if(confirm("Are you sure ?\n You want to block user "+userblocked))
	{
		AjaxRequest.get({
		'url':'ajax_st.php?call=Blockusermess&userblocked='+userblocked,
		'onLoading':function(req){$('loadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('loadimg').innerHTML='';
			Deletemessage(msgid,Layer);
		}
		});
	}
}
function ScrapUpdate()
{     if(($F('scraptxt').length)>=1500){
		  $('scraptxt').value=$F('scraptxt').substring($F('scraptxt').indexOf('):')+1,1499);
		  alert('Scrap text should not more than 1500 character');
		  }
	   var msg=$F('scraptxt').substring($F('scraptxt').indexOf('):')+1,1499);
		AjaxRequest.post({
		'url':'ajax_st.php?call=ScrapUpdate&scrapdata='+encodeURIComponent(msg),
		'onLoading':function(req){$('scrapimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>Updating........'},
		'onSuccess':function(req)
		{
			new Effect.Highlight('scraptxt');
			$('scrapimg').innerHTML='';
		},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		});
		return false;
}

//******************End of bulletin***********************/
//******************My tags tree view*********************/
function ShowSubTags(tagname,tagid,img1,img2,img3,img4)
{
	setCookie("tagstring",tagname);
	if($('maintag'+tagid).style.display=='none')
	{
		AjaxRequest.get({
			'url':'ajax_st.php?call=ShowSubTags&tagname='+tagname+'&maintagid='+tagid,
			'onLoading':function(req){$('treetagimg'+tagid).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('treetagimg'+tagid).innerHTML='';
				swapAndslidplus('maintag'+tagid,img1,img2,img3,img4);
				$('maintag'+tagid).innerHTML=req.responseText;
			}
		});	
	}
	else
	{
		$('maintag'+tagid).innerHTML='';
		swapAndslidplus('maintag'+tagid,img1,img2,img3,img4);
	}
}
function swapAndslidplus(Layer,img1,img2,img3,img4)
{
	var dDate=new Date();
	dDate.setDate(dDate.getDate()+50);
	if($(Layer).style.display=="none")
	{
		Element.show(Layer)
		setCookie(Layer,"display",dDate);
		$(Layer+'Action').src=WEB_ROOT+"images/"+img1;
		$(Layer+'arrow').src=WEB_ROOT+"images/"+img4;
	}
	else
	{
		Element.hide(Layer)
		setCookie(Layer,"-",dDate);
		$(Layer+'Action').src =WEB_ROOT+"images/"+img2;
		$(Layer+'arrow').src=WEB_ROOT+"images/"+img3;
	}
}
function EditTagTreeview(tagid,oldtag,st)
{
	if(st=='show')
	{
		$('EditTagTree'+tagid).style.display='inline';
		$('MainTagTreeDiv'+tagid).style.display='none';
	}
	else if(st=='save')
	{
				AjaxRequest.get( 
				{ 
					'url':'ajax_st.php?call=EditTagTreeview&oldtag='+oldtag+'&newtag='+$F('Edittag'+tagid),
					'onLoading':function(req){$('editimg'+tagid).innerHTML='<img src=images/loading.gif>';},
					'onSuccess':function(req)
					{
						$('editimg'+tagid).innerHTML='';
						new Ajax.Updater('siadecontenar','mytagstree.php', {onLoading:function(request){$('mainloadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('mainloadimg').innerHTML=''}})
						$('EditTagTree'+tagid).style.display='none';
					},
					'onError':function(req)
					{
						alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
					}
				} 
				);  
	}
	else if(st=='delete')
	{
		if(confirm("Are You Sure? \n"))
		{
				AjaxRequest.get( 
				{ 
					'url':'ajax_st.php?call=DeleteTagTreeview&oldtag='+oldtag+'&tagid='+tagid,
					'onLoading':function(req){	$('editimg'+tagid).innerHTML='<img src=images/loading.gif>';},
					'onSuccess':function(req)
					{
						$('editimg'+tagid).innerHTML='';
						new Ajax.Updater('siadecontenar','mytagstree.php', {onLoading:function(request){$('mainloadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('mainloadimg').innerHTML=''}})
						$('EditTagTree'+tagid).style.display='none';
					},
					'onError':function(req)
					{
						alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
					}
				} 
				);  
		}
	}
	else if(st=='hide')
	{
		$('EditTagTree'+tagid).style.display='none';
		$('MainTagTreeDiv'+tagid).style.display='inline';
	}
}

function MytreeTagStatus(tagid,st)
{
	if(st=='favorite')	
		var url='ajax_st.php?call=MytreeTagStatus&memstatus=personal&status=favorite&tagid='+tagid;
	else if(st=='locking')
		var url='ajax_st.php?call=MytreeTagStatus&memstatus=personal&status=locking&tagid='+tagid;
	AjaxRequest.get( 
				{ 
					'url':url,
					'onLoading':function(req){$('mainloadimg').innerHTML='<img src=images/loading.gif>';},
					'onSuccess':function(req)
					{
						if(st=='favorite')	
						{
							new Effect.Highlight($('StarImg'+tagid));
							new Effect.Opacity($('StarImg'+tagid), {duration:1.0, from:0.5, to:1.0});
							swap_image('StarImg'+tagid,'star_active.gif','star_symbol.gif');
						}
						else if(st=='locking')
						{
							new Effect.Highlight($('LockImg'+tagid));
							new Effect.Opacity($('LockImg'+tagid), {duration:1.0, from:0.5, to:1.0});
							swap_image('LockImg'+tagid,'lock_symbol.gif','lock_active.gif');
						}
						$('mainloadimg').innerHTML='';
						//new Ajax.Updater('siadecontenar','mytagstree.php', {onLoading:function(request){$('mainloadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('mainloadimg').innerHTML=''}})
					},
					'onError':function(req)
					{
						alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
					}
				} 
				);  
}
//managing subtags
function EditSubTagTreeview(maintagid,tagid,oldtag,st)
{
	if(st=='show')
	{
		$('EditSubTagTree'+maintagid+tagid).style.display='inline';
		$('MainSubTagTreeDiv'+maintagid+tagid).style.display='none';
	}
	else if(st=='save')
	{
				AjaxRequest.get( 
				{ 
					'url':'ajax_st.php?call=EditTagTreeview&oldtag='+oldtag+'&newtag='+$F('EditSubtag'+tagid),
					'onLoading':function(req){		$('subeditimg'+tagid).innerHTML='<img src=images/loading.gif>';	},
					'onSuccess':function(req)
					{
						$('subeditimg'+tagid).innerHTML='';
						new Ajax.Updater('siadecontenar','mytagstree.php', {onLoading:function(request){$('mainloadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('mainloadimg').innerHTML=''}})
						$('EditSubTagTree'+maintagid+tagid).style.display='none';
					},
					'onError':function(req)
					{
						alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
					}
				} 
				);  
	}
	else if(st=='delete')
	{
		if(confirm("Are You Sure? \n"))
		{
				AjaxRequest.get( 
				{ 
					'url':'ajax_st.php?call=DeleteTagTreeview&oldtag='+oldtag+'&tagid='+tagid,
					'onLoading':function(req){	$('subeditimg'+tagid).innerHTML='<img src=images/loading.gif>';},
					'onSuccess':function(req)
					{
						$('subeditimg'+tagid).innerHTML='';
						new Ajax.Updater('siadecontenar','mytagstree.php', {onLoading:function(request){$('mainloadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('mainloadimg').innerHTML=''}})
						$('EditSubTagTree'+maintagid+tagid).style.display='none';
					},
					'onError':function(req)
					{
						alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
					}
				} 
				);  
		}
	}
	else if(st=='hide')
	{
		$('EditSubTagTree'+maintagid+tagid).style.display='none';
		$('MainSubTagTreeDiv'+maintagid+tagid).style.display='inline';
	}
}
function DisplaySubTagsPlus(tag,st,sgid,tagid,maintagid)
{
	//alert("="+tag+" ="+st+"= "+sgid+" ="+tagid+" ="+maintagid+"=")
	//setCookie("tagstring",getCookie("tagstring")+"+ "+tag);
	setCookie("tagstring",getCookie("tagstring")+"*"+tag);
	if(maintagid=='sgsend')
		var url='ajax_st.php?call=SGShowSubTags&status=duptag&tagname='+tag+'&tagdivid='+tagid;
	else
		var url='ajax_st.php?call=ShowSubTags&status=duptag&tagname='+tag+'&maintagid='+maintagid;
	AjaxRequest.get({
			'url':url,
			'onLoading':function(req){$('mainloadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('mainloadimg').innerHTML='&nbsp;';
				if(maintagid=='sgsend')
				{
					$(tagid).innerHTML='&nbsp;';
					$(tagid).innerHTML=req.responseText;
					var strtag=replaceAll(getCookie('tagstring'),"*","+");
					$('sgsubtagsplusok').innerHTML=replaceAll(strtag,"_9_a_"," ");//getCookie('tagstring').replace('*','+','gi');
				}
				else
				{
					$('maintag'+maintagid).innerHTML='&nbsp;';
					$('maintag'+maintagid).innerHTML=req.responseText;
					strtag=replaceAll(getCookie('tagstring'),'*','+')
					$('subtagsplusok'+maintagid).innerHTML=replaceAll(strtag,"_9_a_"," ");//getCookie('tagstring').replace('*',"+",'gi');
				}
			}
		});	
	if(st=='mytag')	
	{	
		clicklink_secont('mylink','ManagedLinks','mytag_listview_startpage.php?tags='+tag)
	}
	if(st=='sharegroup')
	{
		clicklink_secont('mylink','ManagedLinks','mytag_listview_startpage.php?tags='+tag+'&sharegroup=sharegrp&sgid='+sgid);
	}
	$('mainloadimg').innerHTML='&nbsp;';
}
function replaceAll( str, from, to )
{
	var idx = str.indexOf( from );
	while ( idx > -1 )
	{
		str = str.replace( from, to );
		idx = str.indexOf( from );
	}
	return str;
}
//manage share group
function EditOwnerFriend(ownername,sgid)
{ 
    var ulobj=$(sgid+'SgOwnerList');
	ulist=ulobj.getElementsByTagName("div")
	for(i=0;i<ulist.length;i++)
	{
		ulist[i].style.display="inline";
	}
	$(sgid+ownername+'OwnerEdit').style.display="none";
	AjaxRequest.get({
		'url':'ajax_st.php?call=EditOwnerFriend&sgid='+sgid+'&ownername='+ownername,
		'onLoading':function(req){$('sgimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('sgimg').innerHTML='';
			$(sgid+'OwnerFriend').innerHTML=req.responseText;
			$(sgid+'OwnerFriend').style.display='inline';
		}
	});	
}
function AddOwnerFriend(fname,sgid,ownname,imgstatus,fndid)
{
	AjaxRequest.get({
			'url':'ajax_st.php?call=AddOwnerFriend&sgid='+sgid+'&fname='+fname+'&imgstatus='+imgstatus,
			'onLoading':function(req){$('sgimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('sgimg').innerHTML='';
				$(sgid+'OwnerFriend').innerHTML=req.responseText;
				$(sgid+'OwnerFriend').style.display='inline';
				//$('FriendImage'+fndid).src=img;
				AjaxRequest.get({
					'url':'ajax_st.php?call=ShowOwnerList&sgid='+sgid,
					'onLoading':function(req){$('sgimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
					'onSuccess':function(req)
					{
						$(sgid+'SgOwnerList').innerHTML=req.responseText;
						$('sgimg').innerHTML='';
					}
				});		
				
			}
		});	
}
function ShowOwnerList(sgid)
{
	if($(sgid+'SgOwnerList').style.display=='none')	
	{
		AjaxRequest.get({
			'url':'ajax_st.php?call=ShowOwnerList&sgid='+sgid,
			'onLoading':function(req){$('sgimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$(sgid+'SgOwnerList').innerHTML=req.responseText;
				Tagger(sgid+'SgOwnerList');
				$('sgimg').innerHTML='';
			}
		});		
	}
	else
	{
		Tagger(sgid+'SgOwnerList');
	}
}
function SendMsgToMFriends(sendto,from,status,val)
{
	if(status=='hide')
	{
		SlideEditProfile(val+'SendMsgdiv');
		$('FriendMsg'+val).value='';
		$('fmsgloading').innerHTML='';
	}
	else if(status=='show')
	{
		$('fmsgloading').innerHTML='';
		AjaxRequest.get({
			'url':'ajax_st.php?call=SendMsgToMFriends&sendto='+sendto+'&from='+from+'&fmessage='+$F('FriendMsg'+val),
			'onLoading':function(req){$('fmsgloading').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('FriendMsg'+val).value='';
				$('fmsgloading').innerHTML=req.responseText;				
				new Effect.Highlight('fmsgloading');
			}
		});		
	}
	else
	{
		$('fmsgloading').innerHTML='';
	}
}
function DeleteLeftFriends(fname)
{
	$('fmsgloading').innerHTML='';
	if(confirm("Are you sure ?"))
	{
		AjaxRequest.get({
				'url':'ajax_st.php?call=DeleteLeftFriends&friendname='+fname,
				'onLoading':function(req){$('fmsgloading').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req)
				{
					new Ajax.Updater('friends', 'mf_ff_ff.php', {onLoading:function(request){$('friends').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){}})
					$('fmsgloading').innerHTML='';
				}
			});		
	}
}
function InviteYourFriends(username)
{
	AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=InviteYourFriends&friendemail='+$F('Invitemail')+'&Invitemsg='+$F('InviteMessage')+'&username='+username,
				'onLoading':function(req)
				{
					new Effect.Opacity('Inviteimg', {duration:0.2, from:1.0, to:0.5});
					$('Inviteimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>';
				},
				'onSuccess':function(req)
				{
					if($F('Invitemail').length<=0)
						$('Inviteimg').innerHTML='<span id="Fadetxt">Can\'t send invitation mail without email address.<span>';
					else
						$('Inviteimg').innerHTML='<span id="Fadetxt">An invitation email has been sent out. The person will be automatically added as your friend once they join StartAid.<span>';
					new Effect.Opacity('Inviteimg', {duration:0.2, from:0.5, to:1.0});
					new Effect.Highlight('Inviteimg');
					new Effect.Fade('Fadetxt',{duration:20.0});
					$('Invitemail').value='';
				}
			});		
}
function CompactViewStartpage()
{
    var ulobj=$('ManagedLinks');
	ulist=ulobj.getElementsByTagName("a")[0];
	alert(ulist.getAttribute("href"));
}
function Sharegrouptreetags(sgid)
{
  if($('ShareGrouptag'+sgid).style.display=='none')
  {
		AjaxRequest.get
		({
			'url':'ajax_st.php?call=Sharegrouptreetags&sgid='+sgid,
			'onLoading':function(req)	{$('mainloadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('sgtagarrowimg'+sgid).src=WEB_ROOT+"images/arrow_blue_vertical.gif";
				$('ShareGrouptag'+sgid).innerHTML=req.responseText;
				$('mainloadimg').innerHTML='';
				$('ShareGrouptag'+sgid).style.display='inline';
			}
		});		
  }
  else
  {
		$('sgtagarrowimg'+sgid).src = WEB_ROOT+"images/arrow_blue.gif";
		$('ShareGrouptag'+sgid).style.display='none';
  }
}
function SGShowSubTags(sgid,tagname,tagid,img1,img2,img3,img4)
{
	setCookie("tagstring",tagname);
	if($('maintag'+tagid).style.display=='none')
	{
		AjaxRequest.get({
			'url':'ajax_st.php?call=SGShowSubTags&tagname='+tagname+'&maintagid='+tagid+'&tagdivid=maintag'+tagid+'&sgid='+sgid,
			'onLoading':function(req){$('treetagimg'+tagid).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('treetagimg'+tagid).innerHTML='';
				swapAndslidplus('maintag'+tagid,img1,img2,img3,img4);
				$('maintag'+tagid).innerHTML=req.responseText;				
			}
		});	
	}
	else
		swapAndslidplus('maintag'+tagid,img1,img2,img3,img4);
}
/********************************************************/
function MytreeListStatus(tagid,st,page)
{
	if(st=='favorite')	
		var url='ajax_st.php?call=MytreeTagStatus&memstatus=personal&status=favorite&tagid='+tagid;
	else if(st=='locking')
		var url='ajax_st.php?call=MytreeTagStatus&memstatus=personal&status=locking&tagid='+tagid;
	AjaxRequest.get( 
				{ 
					'url':url,
					'onLoading':function(req){$('mainloadimg').innerHTML='<img src=images/loading.gif>';},
					'onSuccess':function(req)
					{
						if(st=='favorite')	
						{
							new Effect.Highlight($('StarImg'+tagid));
							new Effect.Opacity($('StarImg'+tagid), {duration:1.0, from:0.5, to:1.0});
							swap_image('StarImg'+tagid,'star_active.gif','star_symbol.gif');
						}
						else if(st=='locking')
						{
							new Effect.Highlight($('LockImg'+tagid));
							new Effect.Opacity($('LockImg'+tagid), {duration:1.0, from:0.5, to:1.0});
							swap_image('LockImg'+tagid,'lock_symbol.gif','lock_active.gif');
						}
						$('mainloadimg').innerHTML='';
						//new Ajax.Updater('siadecontenar',page, {onLoading:function(request){$('mainloadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('mainloadimg').innerHTML=''}})
					},
					'onError':function(req)
					{
						alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
					}
				} 
				);  
}
function mytagslistSG(sgid)
{
	if($(sgid+'SGlistview').style.display=='none')
	{
		AjaxRequest.get( 
			{ 
				'url':'ajax_st.php?call=mytagslistSG&sgid='+sgid,
				'onLoading':function(req){$('mainloadimg').innerHTML='<img src=images/loading.gif>';},
				'onSuccess':function(req)
				{
					$(sgid+'SGlistview').innerHTML=req.responseText;
					Tagger(sgid+'SGlistview');
					$('mainloadimg').innerHTML='';
				},
				'onError':function(req)
				{
					alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
				}
			} 
			);
	}
	else
		Tagger(sgid+'SGlistview');
}
function PublicTreeSubTags(tagname,tagid,img1,img2,img3,img4)
{
	setCookie("treetag","");
	setCookie("treetag",tagname);
	if($('subtags'+tagid).style.display=='none')
	{
		AjaxRequest.get({
			'url':'ajax_st.php?call=PublicTreeSubTags&tagname='+tagname+'&maintagid='+tagid,
			'onLoading':function(req){$('loadsideimage').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				swapAndslidplus('subtags'+tagid,img1,img2,img3,img4);
				$('subtags'+tagid).innerHTML=req.responseText;
				$('loadsideimage').innerHTML='';
			}
		});	
	}
	else
		swapAndslidplus('subtags'+tagid,img1,img2,img3,img4);
}
function openpublictreetag(tag,tagid,maintagid)
{
	setCookie("tags",tag);
	var cook=getCookie("treetag")+" *"+tag;
	setCookie("treetag",cook);
	/*clicklink('topmenu','maincontainer','tagresult');
	new Ajax.Updater('maincontainer','publictagslinks.php?status=first&tags='+tag, {onLoading:function(request){$('loadimg').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){$('loadimg').innerHTML=''}})		*/
	clicklink_secont('tagresult','',WEB_ROOT+'publictagslinks.php?status=first&tags='+getCookie('treetag'));	
	AjaxRequest.get({
		'url':'ajax_st.php?call=PublicTreeSubTags&tagname='+tag+'&status=rtree&counter='+tagid+'&maintagid='+maintagid,
		'onLoading':function(req){$('loadsideimage').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
		'onSuccess':function(req)
		{
			$('loadsideimage').innerHTML='';
			$('subtags'+maintagid).innerHTML=req.responseText;
			var data=replaceAll(getCookie("treetag"),'*','+');
			$('treerelatedtags'+maintagid).innerHTML=replaceAll(data,'_9_a_',' ');
		}
	});	
}
function FriendLinks(mantab,subtab,self, page,orderby,ascdesc,fieldname)
{
	if($('friendsimage').src==WEB_ROOT+'images/img_13.gif')
	{
		setCookie("Cokfrdimage","");
		$('friendsimage').src=WEB_ROOT+'images/img13.gif';
		if(fieldname!='')
			pagewise_orderby('',fieldname);
		new Effect.ScrollTo('ScrollTop');
		if(mantab!='')
			clicklink_secont(mantab,subtab,self+'?page='+page+'&orderby='+orderby+'&ascdesc='+ascdesc+'&status=fsd')
	}
	else if($('friendsimage').src==WEB_ROOT+'images/img13.gif')
	{
		setCookie("Cokfrdimage","friend");
		$('friendsimage').src=WEB_ROOT+'images/img_13.gif';
		if(fieldname!='')
			pagewise_orderby('friends',fieldname);
		new Effect.ScrollTo('ScrollTop');
		if(mantab!='')
			clicklink_secont(mantab,subtab,self+'?page='+page+'&orderby='+orderby+'&ascdesc='+ascdesc+'&status=friends')
	}
}
function get_votes(id,type,back_link,loadingimage,finalstate)
{
	if(type == 'P')
		var url=WEB_ROOT+'ajax_st.php?call=votes&status=positive&back_link='+encodeURIComponent(back_link)+'&url='+encodeURIComponent(id)+'&finalstatus='+finalstate;
	else if(type == 'N')
		var url=WEB_ROOT+'ajax_st.php?call=votes&status=negative&back_link='+encodeURIComponent(back_link)+'&url='+encodeURIComponent(id)+'&finalstatus='+finalstate;
		AjaxRequest.get( 
				{ 
				'url':url,
				'onLoading':function(req)
				{
					if(type=='N')
						new Effect.Opacity($('votesup_'+id), {duration:0.2, from:1.0, to:0.5});
					else if(type=='P')
						new Effect.Opacity($('votesdown_'+id), {duration:0.2, from:1.0, to:0.5});
				},
				'onSuccess':function(req){
					new Ajax.Updater('maincontainer', back_link, {onLoading:function(request){}, onComplete:function(request){}});
					if(type=='P')
						new Effect.Opacity($('votesup_'+id), {duration:0.2, from:0.5, to:1.0});
					else if(type=='N')
						new Effect.Opacity($('votesdown_'+id), {duration:0.2, from:0.5, to:1.0});
				},
				'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				} 
				);
}
function hotlink_orderby(maintab,subtab,orderby,page,self)
{
	clicklink_secont(maintab,subtab,self+'?page='+page+'&orderby='+orderby)
}
function TopContributorLinks(username)
{
	setCookie("TopContributorLinksname",username);
	clicklink('topmenu','maincontainer','TopContributorLinks');	
}
function usersectionPagging(mantab,subtab,self, page,orderby,ascdesc)
{ 
	clicklink_sidetab(mantab,subtab,self+'?page='+PAGES+'&orderby='+orderby+'&ascdesc='+ascdesc)
}
function UsersShowSubTags(username,tagname,tagid,img1,img2,img3,img4)
{
	setCookie("tagstring",tagname);
	if($('maintag'+tagid).style.display=='none')
	{
		AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=UsersShowSubTags&tagname='+tagname+'&maintagid='+tagid+'&username='+username,
			'onLoading':function(req){$('treetagimg'+tagid).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('treetagimg'+tagid).innerHTML='';
				swapAndslidplus('maintag'+tagid,img1,img2,img3,img4);
				$('maintag'+tagid).innerHTML=req.responseText;
			}
		});	
	}
	else
		swapAndslidplus('maintag'+tagid,img1,img2,img3,img4);
}
function UsersDisplaySubTagsPlus(username,tag,st,sgid,tagid,maintagid)
{
	setCookie("tagstring",getCookie("tagstring")+"*"+tag);
	var url=WEB_ROOT+'ajax_st.php?call=UsersShowSubTags&status=duptag&tagname='+tag+'&maintagid='+maintagid+'&username='+username;
	AjaxRequest.get({
			'url':url,
			'onLoading':function(req){$('mainloadimg').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req)
			{
				$('mainloadimg').innerHTML='&nbsp;';
				if(maintagid=='sgsend')
				{
					$(tagid).innerHTML='&nbsp;';
					$(tagid).innerHTML=req.responseText;
					var data=replaceAll(getCookie('tagstring'),'*',' +');
					$('sgsubtagsplusok').innerHTML=replaceAll(data,'_9_a_',' ');
				}
				else
				{
					$('maintag'+maintagid).innerHTML='&nbsp;';
					$('maintag'+maintagid).innerHTML=req.responseText;
					var data=replaceAll(getCookie('tagstring'),'*',' +');
					$('subtagsplusok'+maintagid).innerHTML=replaceAll(data,'_9_a_',' ');
				}
			}
		});	
	if(st=='mytag')	
	{	
		//setCookie("tags",tag);
		clicklink_secont("tagresult","",WEB_ROOT+'userpublictagslinks.php?status=first&username='+username+'&tagname='+getCookie('tagstring'));
	}
	$('mainloadimg').innerHTML='&nbsp;';
}
function ExtraSearcgOptions(arrowid)
{
	if($(arrowid).style.display=='none')
	{
		AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=ExtraSearcgOptions',
			'onSuccess':function(req)
			{
				$(arrowid).innerHTML=req.responseText;
				Tagger(arrowid);
				if (document.all) { Droppables.drops = [] }
				searchDragAndDrop('searchdragdropdiv','dsearchflag','searchoption');
			}
			});	
	}
	else
	{
		Tagger(arrowid);
	}
}
// making droppable and draggable for adding new links 
function makeMyTreeElementdroppable()
{
	 var mydrag = new Draggable("addnewlinkdiv", {revert:true,overlap:'vertical',handle:'dragid'});

	new CAPXOUS.AutoComplete("urltags", function() 
		{
        return "autocomplete.php?typing=" + this.text.value+'&status=tag';
    });
	new Effect.ScrollTo('ScrollTop');
}
function adddragnewlink(element,dropon,event)
{
	var catid = (($(dropon.id).getAttribute("id"))).split('_');
		if(catid[0]=='subcatdrag' || catid[0]=='droprow')
		{
			if($('insertstatus').value=='sggroup')
			{
				//alert("You can\'t insert share group link into personal links !")
				// not allowing share group link to be added in personal group
			}
			else
			{
				$('categoryid').value=catid[1];
				checkaddnewlink($('insertstatus').value,"mylink","ManagedLinks",WEB_ROOT+'manage_links.php?orderby=urldate&ascdesc=desc&catid='+catid[1]); // for update share group links
				var dDate=new Date();
				dDate.setDate(dDate.getDate()+50);
				setCookie("TreeCategoryName",'txtshowCategory'+catid[1],dDate);
			}
		}
		else if(catid[0]=='shargroupcat')
		{
			if($('insertstatus').value=='insert' || $('insertstatus').value=='update')
			{
				addnewlinkinSG(catid[1],catid[2]) // for adding new link directly into sg_site table
			}
			else
			{
				checkaddnewlink($('insertstatus').value,"mylink","ManagedLinks",WEB_ROOT+'manage_links.php?orderby=urldate&ascdesc=desc&catid='+catid[1]); //for update share group links
				var dDate=new Date();
				dDate.setDate(dDate.getDate()+50);
				setCookie("TreeCategoryName",'txtshowCategory'+catid[1],dDate);
			}
		}
}
function addnewlinkinSG(first,second)
{
	var chk=valid_url($F('newurl'));
	var stk='';
	if(chk==0)
	{
		$('allmsg').innerHTML="<font color='#FF0000'>Enter Correct URL.</font>";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('newurl');
		return false;
	}
	else if($F('urltitle').length<=0)
	{
		$('allmsg').innerHTML="<font color='#FF0000'>Enter Title of URL.</font>";
		new Effect.Highlight('allmsg');
		new Effect.Highlight('urltitle');
		return false;
	}
	else
	{
		var urlval=WEB_ROOT+'ajax_st.php?call=addnewlinkinSG&newurl='+encodeURIComponent($F('newurl'))+'&urltitle='+$F('urltitle')+'&urltags='+$F('urltags')+'&urldesc='+$F('urldesc')+'&sgid='+first+'&categoryid='+second;
		AjaxRequest.get({
			'url':urlval,
			'onSuccess':function(req)
			{
				$('newurl').value='http://';
				$('urltitle').value='';
				$('urltags').value='';
				$('urldesc').value='';
				$('allmsg').innerHTML=req.responseText;
				new Effect.Highlight('allmsg');
			}
			});	
	}
}
function titledescriptionvote(urlid,type,urlname,oldurlid,backlink,mantab,subtab)
{
	AjaxRequest.get({
		'url':WEB_ROOT+'ajax_st.php?call=titledescriptionvote&type='+type+'&urlid='+urlid+'&urlname='+urlname,
		'onSuccess':function(req)
		{
			list_of_starter(oldurlid,backlink,mantab,subtab);
		}
		});	
}
function AddFanAsFriend(fname)
{
	AjaxRequest.get({
	'url':WEB_ROOT+'ajax_st.php?call=AddFanAsFriend&fname='+fname,
	'onSuccess':function(req)
	{
		new Ajax.Updater('friends', 'mf_ff_ff.php', {onLoading:function(request){$('friends').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){}})
	}
	});	
}
function AddFanAsFriend2(fname,uname)
{
			AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=AddFanAsFriend2&fname='+fname+'&uname='+uname,
			'onSuccess':function(req)
			{
				window.location=WEB_ROOT+'index.php';
			}
			});	
}
function SearchRemoveFriend(fname)
{
	AjaxRequest.get({
	'url':WEB_ROOT+'ajax_st.php?call=SearchRemoveFriend&fname='+fname,
	'onLoading':function(req){$('friendshints').innerHTML=loadstatustext},
	'onSuccess':function(req)
	{
					$('friendshints').innerHTML="You have Successfully Deleted <strong>"+fname+"</strong> from your friend list"
					new Effect.Highlight('friendshints');
					var Layer1=fname+'_addremove1';
					var Layer2=fname+'_addremove2';
					if($(Layer1).style.display=="none")
						{
							$(Layer1).style.display="inline"
							$(Layer2).style.display="none"
						}
						else
						{
							$(Layer1).style.display="none"
							$(Layer2).style.display="inline"
						}		
						new Ajax.Updater('friends', 'mf_ff_ff.php', {onLoading:function(request){$('friends').innerHTML='<img src=images/loading.gif>'}, onComplete:function(request){}})
	},
	'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	});	

}
function DeleteMyLinks(linkid,status,container)
{
	if(status=='sharegrp')
	{
		 if(confirm('Do you want to delete this link?'))
		 { 
			 AjaxRequest.get( 
					{ 
					'url':'ajax_st.php?call=sharegroppdeletelink&urlid='+encodeURIComponent(linkid),	
					'onLoading':function(req){						
						new Effect.Opacity(container, {duration:0.8, from:1.0, to:0.5});
						},
					'onSuccess':function(req){
						if(req.responseText=='updated')
							{  
								new Effect.SlideUp(container); 
							}		
						},
					'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
					} 
					);
		 }
	}
	else
	{
			if(confirm('Do you want to delete this link?'))
		    {
				new Effect.Opacity(container, {duration:.8, from:1.0, to:0.5});
				AjaxRequest.get(
				{
					'url':'ajax_st.php?call=deletelink&urlid='+linkid,
					'onLoading':function (req){
						
					},
					'onSuccess':function(req)
					{ 
						if(req.responseText=='deleted')
						{  
							//Element.remove($('MyLinks'+linkid),{duration:1.0})
							new Effect.SlideUp(container); 
						}
				   }
				}
				);
			}
	}
}

function User_addnewlink(urlid,username)
{
	setCookie("UserAddnewlink",urlid);
	setCookie("UserName",username);
	new Ajax.Updater('maincontainer',WEB_ROOT+'editlink.php?urlid='+urlid+'&addtype=insert', {onLoading:function(request){}, onComplete:function(request){}});		
}


function cloudPagging(mantab,subtab,self, page,orderby,ascdesc)
{
	if(page=='0'){
		
		if($F('Topnumber')!='###'){
			if($F('Topnumber')==''){
				PAGES = 1 * 1 ;
			}else
			PAGES = $F('Topnumber') * 1;
	    }
		
	}else{
		PAGES=page;
	}
	if(isNaN(PAGES) == false){
	PAGE = PAGES;
	if (PAGE < 1) PAGE = 1;
	new Effect.ScrollTo('ScrollTop');
	if(mantab!='')
		clicklink_sidetab(mantab,subtab,self+'?page='+PAGES+'&orderby='+orderby+'&ascdesc='+ascdesc)
	else
		alert("wrong")
	}
	return;
}
function pagewise_orderby(divid,st)
{
	AjaxRequest.get(
			{
				'url':WEB_ROOT+'ajax_st.php?call=viewsetting&view='+divid+'&columnname='+st,
				'onLoading':function (req){},
				'onSuccess':function(req)
				{ 
				},
				'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		}
		);
}
function CloseOpenTab(tabid)
{
	$(tabid).style.display='none';
	clicklink('topmenu','maincontainer',RIGHT_MAIN_TABS);
}
function plugins_setting(plugin,radio,username)
{
	if(plugin=='startaid_logo')
	{
		if($('startaid_logo').checked==true)
		{
			var fvalue='Y';
			$('logoimage').innerHTML="<a href='http://www.startaid.com/'><img src="+WEB_ROOT+"images/startaid_plugins.gif border='0' align='absmiddle'></a>";
		}
		else
		{
			var fvalue='N'
			$('logoimage').innerHTML='';
		}
	}
	else if(plugin=='tags_num')
	{
		var fvalue=$('tagsperpage').value;
	}
	else if(plugin=='sorting_type')
	{
		var fvalue=radio;
	}
	else if(plugin=='sort_order')
	{
		var fvalue=radio;
	}
	AjaxRequest.get(
			{
				'url':WEB_ROOT+'ajax_st.php?call=plugins&fieldname='+plugin+'&fvalue='+fvalue,
				'onSuccess':function(req)
				{ 
					$('Simpletextarea').value="<script type='text/javascript' src=\""+WEB_ROOT+"user/"+username+"/cloud.js\"></script>";
					new Ajax.Updater('tag_cloud', WEB_ROOT+'plugins_clouds.php?username='+username+'&page_status=plugins', {onLoading:function(request){new Effect.Opacity('tag_cloud', {duration:1.0, from:0.5, to:1.0});}, onComplete:function(request){ $('tag_cloud').innerHTML=request.responseText; return false;}});
				},
				'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		}
		);
}
function change_category_style_on_click(boxid)
{
	var ulobj=document.getElementById('Treeeviewrepresent')
	var ulist=ulobj.getElementsByTagName("input") 
	for(var k=0; k < ulist.length; k++)
	{
		if( ulist[k].className== "hightlightCategory" )
		ulist[k].style.color="#3D7CB2";
	}
	$(boxid).style.color="#CC0000";
	if(getCookie("TreeCategoryName_"+SID)!=boxid && getCookie("TreeCategoryName_"+SID)!= null)
	{
		$(getCookie("TreeCategoryName_"+SID)).style.color="#3D7CB2";
	}
	var dDate=new Date();
	dDate.setDate(dDate.getDate()+50);
	setCookie("TreeCategoryName_"+SID,boxid,dDate);
}
function extra_information(Layer)
{

	if($(Layer).style.display=="none")
	{
		new Effect.Appear(Layer);
		//$(Layer).style.display='inline';
		$(Layer+'Action').src = WEB_ROOT+"images/arrow_blue_vertical.gif";
	}
	else
	{
		$(Layer).style.display='none';
		//new Effect.Fold(Layer);
		$(Layer+'Action').src = WEB_ROOT+"images/arrow_blue.gif";
	}
}

function BookmarkControl(url_id,uid,status,back_link,show)
{
	
	Layer = 'startpgtools_'+url_id;
	Layer1 = 'startpgtoolsInner'+url_id;
	layer3 = 'width'+url_id;
	layer4 = 'setwidth'+url_id
		var allsubtab=document.getElementById("page")
		liallsubtab =allsubtab.getElementsByTagName("div")
		for(var k=0; k < liallsubtab.length; k++ )
		{
		if(liallsubtab[k].className == "onmousetrack")
		{
			arr2 = liallsubtab[k].id.split('_');
			//$('width'+arr2[1]).style.width  = '0px';
	    	$('startpgtoolsLoading'+arr2[1]).innerHTML = ""
			$('setwidth'+arr2[1]).innerHTML = ""
			liallsubtab[k].style.display="none"
		
		}
		}
   if( show == 'show' )
	{
		//$(layer3).style.width  =  '200px';
		 $(layer4).innerHTML = "<img src='images/spacer.gif' width='70' height=5 >";
		$(Layer).style.display = 'inline';
		if( $(Layer1) == undefined )
		 {
			AjaxRequest.get({
					'url':WEB_ROOT+'ajax_st.php?call=fetchDetailInfo&url_id='+url_id+'&uid='+uid+'&status='+status+'&back_link='+back_link,
					'onLoading':function (req){$('startpgtoolsLoading'+url_id).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
					'onSuccess':function(req){ 
					
					 $(Layer).innerHTML=req.responseText; 
					
					$('startpgtoolsLoading'+url_id).innerHTML="<img src='images/spacer.gif' width='70' height=5 >";
					},
					'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
				  }); 
		 }
		
	}
	else if( show == 'hide' )
	{
	   	//$(layer3).style.width  =  '0px';
		//$('startpgtoolsLoading'+url_id).innerHTML = ""
		//Element.hide($(Layer),{duration:1.0})
		//$(Layer).style.display='none';
	}
	
	return false;
}

function editCategory(catId)
{
	var textLayer 			= $('nameContainer_' + catId )
	var inputFieldLayer 	= $('editDiv_' + catId )
	var editLayer 	= $('editIconDiv_' + catId )
	var starLayer	= $('starDiv_' + catId);
	var deleteLayer	= $('deleteDiv_' + catId);
	
	if(textLayer.style.display == 'none')
	{
		textLayer.style.display 		= 'inline';
		inputFieldLayer.style.display 	= 'none';
		starLayer.style.display			= 'inline';
		deleteLayer.style.display 		= 'none';				
	}
	else
	{
		textLayer.style.display 		= 'none';
		inputFieldLayer.style.display 	= 'inline';		
		starLayer.style.display			= 'none';
		deleteLayer.style.display 		= 'inline';		
	}	
}

function updateCategory(catId)
{
	AjaxRequest.get( 
		{ 
		'url':WEB_ROOT+'ajax_st.php?call=EditCategory&catId='+catId+'&textvalue='+$F("inputField_"+catId),
		'onLoading':function(req){$('requesting_wait').innerHTML='<img src='+WEB_ROOT+'images/loading.gif>  Requesting content...'},
		'onSuccess':function(req){
			$('nameContainer_' + catId).innerHTML = "<a href=\'#\' class=\"bluebold\" onclick=\"new Effect.ScrollTo(\'topofmenu\');openinmaincontainer(\'" + WEB_ROOT + "manage_links.php?catid=" + catId + "\')\" ondblclick=\"editCategory(" + catId + ")\">" + $F("inputField_"+catId) + "</a>";
			//$('inputField_'+catId).value=$F("inputField_"+catId)
			editCategory(catId);
			$('requesting_wait').innerHTML=''
		},
		'onError':function(req){ alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		} 
		);

}

function OptimizationCategoryView(cat_id,expandable,uid,orderby,ascdesc,level)
{
	var layer = "subcat"+cat_id;
	var img1  = 'tree_closede.gif';
	var img2  = 'tree_opened.gif';
	var layer2= "OptimizationSubCategory"+cat_id
	
	 if(expandable=='N')
	 {
	 cattabs=$('Createcategory')
	 liallsubtab =cattabs.getElementsByTagName("div")
	  for(var k=0; k < liallsubtab.length; k++ )
		{
			if(liallsubtab[k].className=="expandcollapsed"){
			liallsubtab[k].style.display="none"
			container=liallsubtab[k].id;
			$(container+'Action').src = WEB_ROOT+"images/"+img2;
			$(container+'Aero').src = WEB_ROOT+"images/tree_smallup.gif";
		}
		}
	 }
	
	if($(layer).style.display=="none"){
	    
		Element.show(layer)
		if( $(layer2) == undefined )
		 {
		   AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=OptimizationCategoryView&cat_id='+cat_id+'&expandable='+expandable+'&uid='+uid+'&orderby='+orderby+'&ascdesc='+ascdesc+'&level='+level,
				'onLoading':function (req){$(layer).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req){ 
				 $(layer).innerHTML=req.responseText; 
					if (document.all) { Droppables.drops = [] }
					makeDraggableLink();
					makedraganddropobject();
				},
				'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
			  }); 
		 }
		
		
		$(layer+'Action').src = WEB_ROOT+"images/"+img1;
		$(layer+'Aero').src = WEB_ROOT+"images/tree_smalldown.gif";
	}else{
		Element.hide(layer)
		$(layer+'Action').src = WEB_ROOT+"images/"+img2;
		$(layer+'Aero').src = WEB_ROOT+"images/tree_smallup.gif";
	}
	 
		
}

function optimiz_edit_category(cat_id,expandable,uid,orderby,ascdesc,cat_username,cat_name,adminuser)
{
	var container 		= "editcategorydiv" + cat_id;
	var containertext 	= 'editcategoryname'  + cat_id;
	//var imageid       = 'editcopyjointimage'+cat_id
	var layer2  		= "optimizededitcategorydiv"  + cat_id;
	
	if($(container).style.display=='inline')
	{
		$(container).style.display='none';
		$(containertext).style.display='inline';
	}
	else
	{
		
		if( $(layer2) == undefined )
		{
			AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=OptimizEditCategory&cat_id='+cat_id+'&expandable='+expandable+'&uid='+uid+'&orderby'+orderby+'&ascdesc='+ascdesc+'&cat_username='+cat_username+'&cat_name='+cat_name+'&adminuser'+adminuser,
				'onLoading':function (req){$(container).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req){ 
				 $(container).innerHTML=req.responseText; 
				},
				'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
			});
		}
		$(container).style.display='inline';
		$(containertext).style.display='none';
	}

}

function edit_category(cat_id,uid,cat_name)
{
	
}
function optimiz_edit_category_sub(subcat_id,expandable, uid, orderby, ascdesc, cat_username, subcat_name, adminuser,level)
{
	var container = "editcategorydiv"+subcat_id;
	var containertext = 'editcategoryname'+subcat_id;
	//var imageid       = 'editcopyjointimage'+cat_id
	var layer2  = "optimizededitcategorydiv"+subcat_id
	
	if($(container).style.display=='inline')
	{
		$(container).style.display='none';
		$(containertext).style.display='inline';
	}else{
		
		if( $(layer2) == undefined )
		{
		 AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=OptimizEditSubCategory&subcat_id='+subcat_id+'&expandable='+expandable+'&uid='+uid+'&orderby'+orderby+'&ascdesc='+ascdesc+'&cat_username='+cat_username+'&subcat_name='+subcat_name+'&adminuser'+adminuser+'&level='+level,
			'onLoading':function (req){$(container).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req){ 
			 $(container).innerHTML=req.responseText; 
			},
			'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		  });
		}
	$(container).style.display='inline';
	$(containertext).style.display='none';
	}

}
	
	
	
function OptimizationShareGroupCategoryView(sgid,sgcategoryid,orderby,ascdesc,expandable,utype)
{
	//onclick="OptimizationShareGroupCategoryView('sgsubcat_<?=$sgcategoryid?>','tree_closede.gif','tree_opened.gif','<?=$expandable?>')"
	var layer = "sgsubcat_"+sgcategoryid;
	var img1  = 'tree_closede.gif';
	var img2  = 'tree_opened.gif';
	var layer2= "OptimizationShareGRoupSubCategory"+sgcategoryid
	
	if($(layer).style.display=="none"){
	    
		Element.show(layer)
		if( $(layer2) == undefined )
		 {
		   AjaxRequest.get({
				'url':WEB_ROOT+'ajax_st.php?call=shreGroupSubCategory&sgid='+sgid+'&sgcategoryid='+sgcategoryid+'&orderby='+orderby+'&ascdesc='+ascdesc+'&expandable='+expandable+'&utype='+utype,
				'onLoading':function (req){$(layer).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
				'onSuccess':function(req){ 
				 $(layer).innerHTML=req.responseText; 
				 if (document.all) { Droppables.drops = [] }
					makeDraggableLink();
					makedraganddropobject();
				},
				'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
			  }); 
		 }
		
		
		$(layer+'Action').src = WEB_ROOT+"images/"+img1;
		$(layer+'Aero').src = WEB_ROOT+"images/tree_smalldown.gif";
	}else{
		Element.hide(layer)
		$(layer+'Action').src = WEB_ROOT+"images/"+img2;
		$(layer+'Aero').src = WEB_ROOT+"images/tree_smallup.gif";
	}
	 
		
}
function optimiz_edit_category_shregroup(sgcategoryid,sgcategory)
{
	var container = "sgeditcategorydiv"+sgcategoryid;
	var containertext = 'sgeditcategoryname'+sgcategoryid;
	//var imageid       = 'editcopyjointimage'+cat_id
	var layer2  = "optimizededitsharegroupcategorydiv"+sgcategoryid
	
	if($(container).style.display=='inline')
	{
		$(container).style.display='none';
		$(containertext).style.display='inline';
	}else{
		
		if( $(layer2) == undefined )
		{
		 AjaxRequest.get({
			'url':WEB_ROOT+'ajax_st.php?call=OptimizEditShareCategory&sgcategoryid='+sgcategoryid+'&sgcategory='+sgcategory,
			'onLoading':function (req){$(container).innerHTML='<img src='+WEB_ROOT+'images/loading.gif>'},
			'onSuccess':function(req){ 
			 $(container).innerHTML=req.responseText; 
			},
			'onError':function(req){alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		  });
		}
	$(container).style.display='inline';
	$(containertext).style.display='none';
	}

}
	
function setViewCookie(loading)
{
	//alert("I am here :"+loading);
	var cookieDate = new Date();
	cookieDate.setTime(cookieDate.getTime() + 30 * 24 * 60 * 60 * 1000) ;
	//cookieDate.setTime(cookieDate.getTime()+30000) ;
	var View = getCookie('pageView');
	//alert("Cookie value is " + View);
	if(View)
	{
		if(loading)
		{
			if(View != 'simple' && View != 'advanced')
			{
				//alert("I am loading");
				setCookie('pageView', 'simple', cookieDate , null , null , null);
			}
		}
		else
		{
			
			if(View == 'simple')
			{
				//alert("I am advanced :"+loading);
				setCookie('pageView', 'advanced', cookieDate , null , null , null);
				xmlHttp=GetXmlHttpObject()
				xmlHttp.open("GET",'ajax_st.php?call=setPageViewCookie&value=A',true)
				xmlHttp.send(null)
				/*var myAjax = new Ajax.Request(
																	   'ajax_st.php?call=setPageViewCookie&value=A',
																	   {
																		 method: 'post'														 																		 
																	   });*/
				return 'advanced' ;
			}
			else if(View == 'advanced')
			{
				//alert("I am simple :"+loading);
				setCookie('pageView', 'simple', cookieDate , null , null , null);
				xmlHttp=GetXmlHttpObject()
				xmlHttp.open("GET",'ajax_st.php?call=setPageViewCookie&value=S',true)
				xmlHttp.send(null)
				/*var myAjax = new Ajax.Request(
																	   'ajax_st.php?call=setPageViewCookie&value=S',
																	   {
																		 method: 'post'															 																		 
																	   });*/
				return 'simple' ;
			}
			else
			{
				setCookie('pageView', 'simple', cookieDate , null , null , null);
				xmlHttp=GetXmlHttpObject()
				xmlHttp.open("GET",'ajax_st.php?call=setPageViewCookie&value=S',true)
				xmlHttp.send(null)
				/*var myAjax = new Ajax.Request(
																	   'ajax_st.php?call=setPageViewCookie&value=S',
																	   {
																		 method: 'post'														 																		 
																	   });*/
				return 'simple' ;
			}
		}
	}
	else
	{
		setCookie('pageView', 'simple', cookieDate , null , null , null);
		xmlHttp=GetXmlHttpObject()
		xmlHttp.open("GET",'ajax_st.php?call=setPageViewCookie&value=S',true)
		xmlHttp.send(null)
		/*var myAjax = new Ajax.Request(
																	   'ajax_st.php?call=setPageViewCookie&value=S',
																	   {
																		 method: 'post'	

																	   });*/
		
		return 'simple' ;
	}
}
//setViewCookie(true);

function toggleView()
{
	setViewCookie(false);
	location.href = WEB_ROOT;
}

function setLinkCookie(loading)
{
	var cookieDate = new Date();
	cookieDate.setTime(cookieDate.getTime() + 365 * 24 * 60 * 60 * 1000) ;
	
	var View = getCookie('linkView');
	//alert("Cookie of link view " + View);
	if(View)
	{
		if(loading)
		{
			if(View != 'list' && View != 'thumb')
			{
				//alert("I am loading");
				setCookie('linkView', 'list', cookieDate , null , null , null);
			}
		}
		else
		{
			
			if(View == 'list')
			{
				
				setCookie('linkView', 'thumb', cookieDate , null , null , null);
				return 'thumb' ;
			}
			else if(View == 'thumb')
			{
				//alert("I am here");
				setCookie('linkView', 'list', cookieDate , null , null , null);
				return 'list' ;
			}
			else
			{
				setCookie('linkView', 'list', cookieDate , null , null , null);
				return 'list' ;
			}
		}
	}
	else
	{
		setCookie('linkView', 'list', cookieDate , null , null , null);
		return 'list' ;
	}
}

setLinkCookie(true);

function toggleLinkView()
{
	//alert("I am here");
	//alert();
	setLinkCookie(false);
	location.href = WEB_ROOT;
}

function GetXmlHttpObject()
{
	var xmlHttp=null;
	
	try
	{
	 // Firefox, Opera 8.0+, Safari
	 	xmlHttp=new XMLHttpRequest();
	}
	catch (e)
	{
		 // Internet Explorer
		 try
		 {
		  	xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		 }
		 catch (e)
		 {
		  	xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		 }
	 }
	return xmlHttp;
}