var tagging=false;
var tagging_initialized=false;
var ajax_done=false;
var frameWidth=166;
var frameHeight=166;
var activePersonID=-2;
var activeImageMouseX;
var activeImageMouseY;
var pid=0;
var photo_tags = [];
var friend_list=[];
var user=0;
var ptyid=0;
var ajax_setter_uri='tag.php';
var ajax_setter_del_comments='comment_del.php';
var ajax_innerpage_url='ajax_displaypic.php';
var ajax_innerpagetag_url='ajax_tagload.php';
//var ajax_getter_uri='get_tag_options_ajax.php';
function shortName()
   {   list ='';
   
	    for(i=0;i<friend_list.length;i++)
		{
			friend = friend_list[i];
			list += "<span class=\"inputcheckbox\"><input type=\"radio\" name=\"name\"  id=\"name"+(i+2)+"\" value=\""+friend[0]+"\"  />"+friend[1]+"</span></br>";
		}
		ge("userlist").innerHTML=list;
   }
var ua={ie:function(){return this._ie;},firefox:function(){return this._firefox;},opera:function(){return this._opera;},safari:function(){return this._safari;},windows:function(){return this._windows;},osx:function(){return this._osx;},populate:function(){var agent=/(?:MSIE.(\d+\.\d+))|(?:(?:Firefox|GranParadiso).(\d+\.\d+))|(?:Opera.(\d+\.\d+))|(?:AppleWebKit.(\d+\.\d+))/.exec(navigator.userAgent);var os=/(Mac OS X;)|(Windows;)/.exec(navigator.userAgent);if(agent){ua._ie=agent[1]?parseFloat(agent[1]):NaN;ua._firefox=agent[2]?parseFloat(agent[2]):NaN;ua._opera=agent[3]?parseFloat(agent[3]):NaN;ua._safari=agent[4]?parseFloat(agent[4]):NaN;}else{ua._ie=ua._firefox=ua._opera=ua._safari=NaN;}
if(os){ua._osx=!!os[1];ua._windows=!!os[2];}else{ua._osx=ua._windows=false;}}};

function resetSelector(){hide('selector');hide('tagframe');activePersonID=-2;activePersonName="";
populateSelector();}
function populateSelector(){
return 0;
}
function elementX(obj){var left=obj.offsetLeft;var op=obj.offsetParent;while(obj.parentNode&&document.body!=obj.parentNode){obj=obj.parentNode;left-=obj.scrollLeft;if(op==obj){if(ua.safari()<500&&obj.tagName=='TR'){left+=obj.firstChild.offsetLeft;}else{left+=obj.offsetLeft;}
op=obj.offsetParent;}}
return left;}
function elementY(obj){var top=obj.offsetTop;var op=obj.offsetParent;while(obj.parentNode&&document.body!=obj.parentNode){obj=obj.parentNode;top-=obj.scrollTop;if(op==obj){if(ua.safari()<500&&obj.tagName=='TR'){top+=obj.firstChild.offsetTop;}else{top+=obj.offsetTop;}
op=obj.offsetParent;}}
return top;}

function copy_properties(u,v){for(var k in v){u[k]=v[k];}
return u;}
function htmlspecialchars(text){if(typeof(text)=='undefined'||!text.toString){return'';}
if(text===false){return'0';}else if(text===true){return'1';}
return text.toString().replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/'/g,'&#039;').replace(/</g,'&lt;').replace(/>/g,'&gt;');}

function findX(obj)
{var curleft=0;if(obj.offsetParent){while(obj.offsetParent){curleft+=obj.offsetLeft
obj=obj.offsetParent;}}
else if(obj.x)
curleft+=obj.x;return curleft;}
function findY(obj)
{var curtop=0;if(obj.offsetParent){while(obj.offsetParent){curtop+=obj.offsetTop
obj=obj.offsetParent;}}
else if(obj.y)
curtop+=obj.y;return curtop;}
function mousePosX(e)
{var posx=0;if(!e)var e=window.event;if(e.pageX)
posx=e.pageX;else if(e.clientX&&document.body.scrollLeft)
posx=e.clientX+document.body.scrollLeft;else if(e.clientX&&document.documentElement.scrollLeft)
posx=e.clientX+document.documentElement.scrollLeft;else if(e.clientX)
posx=e.clientX;return posx;}
function mousePosY(e)
{var posy=0;if(!e)var e=window.event;if(e.pageY)
posy=e.pageY;else if(e.clientY&&document.body.scrollTop)
posy=e.clientY+document.body.scrollTop;else if(e.clientY&&document.documentElement.scrollTop)
posy=e.clientY+document.documentElement.scrollTop;else if(e.clientY)
posy=e.clientY;return posy;}

function showNameFrame(percentX,percentY,context){var snf_image=ge('myphoto');var snf_nameFrame=ge('nameframe');snf_nameFrame.innerHTML=context;snf_nameFrame.style.left=snf_nameFrame.style.top='-10000px';show('nameframe');var snf_x=Math.min(Math.max((percentX*snf_image.width/100)-frameWidth/2,0),snf_image.width-frameWidth);var snf_y=Math.min(Math.max((percentY*snf_image.height/100)-frameHeight/2,0),snf_image.height-frameHeight);snf_nameFrame.style.left=findX(snf_image)+snf_x+(frameWidth-snf_nameFrame.offsetWidth)/2+'px';snf_nameFrame.style.top=findY(snf_image)+snf_y+frameHeight-snf_nameFrame.offsetHeight-8+"px";}
function hideNameFrame(){hide('nameframe');}

var tag_mouse_move_counter=0;var tag_current_frame_index=-1;
function findTag(event){if(!event){hideNameFrame();tag_current_frame_index=-1;return;}else if(!document.onmousemove){document.onmousemove=function(){findTag()};}else if(event){event.cancelBubble=true;}
if(tag_mouse_move_counter++%3!=0){return;}
var ft_image=ge('myphoto');var ft_activeImageMouseX=mousePosX(event)-findX(ft_image);var ft_activeImageMouseY=mousePosY(event)-findY(ft_image);var frame_percent_x=frameWidth/ft_image.width/2*100;var frame_percent_y=frameHeight/ft_image.height/2*100;var frame_min_x=frameWidth/2/ft_image.width*100;var frame_min_y=frameHeight/2/ft_image.height*100;var percent_x=ft_activeImageMouseX/ft_image.width*100;var percent_y=ft_activeImageMouseY/ft_image.height*100;var min_dist=-1;var min_index=-1;var dist;var dx;var dy;if(photo_tags){for(var i=0,il=photo_tags.length;i<il;i++){dx=Math.abs(Math.min(Math.max(frame_min_x,photo_tags[i][0]),100-frame_min_x)-percent_x);dy=Math.abs(Math.min(Math.max(frame_min_y,photo_tags[i][1]),100-frame_min_y)-percent_y);if(dx<=frame_percent_x&&dy<=frame_percent_y){dist=Math.pow(dx,2)+Math.pow(dy,2);if(min_dist==-1||dist<min_dist){min_dist=dist;min_index=i;}}}
if(min_index!=-1){if(tag_current_frame_index!=min_index){showNameFrame(photo_tags[min_index][0],photo_tags[min_index][1],photo_tags[min_index][2]);}}else{hideNameFrame();}
tag_current_frame_index=min_index;}}

function imageMouseUp(){if(tagging){ge('myphoto').focus();ge('myphoto').select();} }
function imageMouseDown(event,image){if(tagging){activeImageMouseX=mousePosX(event)-findX(image);activeImageMouseY=mousePosY(event)-findY(image);updateFrame(image,activeImageMouseX,activeImageMouseY);return false;}}
function frameMouseDown(event)
{if(tagging){image=ge('myphoto');activeImageMouseX=mousePosX(event)-findX(image);activeImageMouseY=mousePosY(event)-findY(image);updateFrame(image,activeImageMouseX,activeImageMouseY);}}
function frameMouseUp()
{if(tagging){ge('name1').focus();ge('name1').select();}}
function updateFrame(image,imageMouseX,imageMouseY)
{imageMinX=findX(image);imageMinY=findY(image);imageMaxX=imageMinX+image.width;imageMaxY=imageMinY+image.height;frameX=findX(image)+imageMouseX;frameY=findY(image)+imageMouseY;if(frameX<imageMinX+(frameWidth/2))
frameX=imageMinX+(frameWidth/2);if(frameY<imageMinY+(frameHeight/2))
frameY=imageMinY+(frameHeight/2);if(frameX>imageMaxX-(frameWidth/2))
frameX=imageMaxX-(frameWidth/2);if(frameY>imageMaxY-(frameHeight/2))
frameY=imageMaxY-(frameHeight/2);var tagMinX=frameX-(frameWidth/2)+10;var tagMinY=frameY-(frameHeight/2)+10;ge('tagframe').style.left=tagMinX+"px";ge('tagframe').style.top=tagMinY+"px";if(imageMouseX<300){ge('selector').style.left=(tagMinX+frameWidth+16)+"px";}else{ge('selector').style.left=(tagMinX-190)+"px";}
ge('selector').style.top=tagMinY+"px";if(ajax_done){populateSelector();}
show('selector');show('tagframe');}

function hide(){for(var i=0;i<arguments.length;i++){var element=ge(arguments[i]);if(element&&element.style)element.style.display='none';}
return false;}

function show(){for(var i=0;i<arguments.length;i++){var element=ge(arguments[i]);if(element&&element.style)element.style.display='';}
return false;}

function $$(){var el=ge.apply(null,arguments);if(!el){Util.warn('Tried to get element %q, but it is not present in the page. (Use ge() '+'to test for the presence of an element.)',arguments[0]);}
return el;}

function Vector2(x,y,domain){copy_properties(this,{x:x,y:y,domain:domain||'pure'});};copy_properties(Vector2.prototype,{x:function(){return this.x;},y:function(){return this.y;},toString:function(){return'('+this.x+', '+this.y+')';},add:function(vx,vy){var x=this.x,y=this.y,l=arguments.length;if(l==1){if(vx.domain!='pure'){vx=vx.convertTo(this.domain);}
x+=vx.x;y+=vx.y;}else if(l==2){x+=vx;y+=arguments[1];}else{Util.warn('Vector2.add called with %d arguments, should be one (a vector) or '+'two (x and y coordinates).',l);}
return new Vector2(x,y,this.domain);},sub:function(v){var x=this.x,y=this.y,l=arguments.length;if(l==1){if(v.domain!='pure'){v=v.convertTo(this.domain);}
x-=v.x;y-=v.y;}else if(l==2){x-=v;y-=arguments[1];}else{Util.warn('Vector2.add called with %d arguments, should be one (a vector) or '+'two (x and y coordinates).',l);}
return new Vector2(x,y,this.domain);},distanceTo:function(v){return this.sub(v).magnitude();},magnitude:function(){return Math.sqrt((this.x*v.x)+(this.y*v.y));},toViewportCoordinates:function(){return this.convertTo('viewport');},toDocumentCoordinates:function(){return this.convertTo('document');},convertTo:function(newDomain){if(newDomain!='pure'&&newDomain!='viewport'&&newDomain!='document'){Util.error('Domain %q is not valid; legitimate coordinate domains are %q, %q, '+'%q.','pure','viewport','document');return new Vector2(0,0);}
if(newDomain==this.domain){return new Vector2(this.x,this.y,this.domain);}
if(newDomain=='pure'){return new Vector2(this.x,this.y);}
if(this.domain=='pure'){Util.error('Unable to covert a pure vector to %q coordinates; a pure vector is '+'abstract and does not exist in any document coordinate system. If '+'you need to hack around this, create the vector explicitly in some '+'document coordinate domain, by passing a third argument to the '+'constructor. But you probably don\'t, and are just using the class '+'wrong. Stop doing that.',newDomain);return new Vector2(0,0);}
var o=Vector2.getScrollPosition('document');var x=this.x,y=this.y;if(this.domain=='document'){x-=o.x;y-=o.y;}else{x+=o.x;y+=o.y;}
return new Vector2(x,y,newDomain);},setElementPosition:function(el){var p=this.convertTo('document');el.style.left=p.x+'px';el.style.top=p.y+'px';return this;},setElementDimensions:function(el){el.style.width=this.x+'px';el.style.height=this.y+'px';return this;}});copy_properties(Vector2,{domainError:function(){Util.error('You MUST provide a coordinate system domain to Vector2.* functions. '+'Available domains are %q and %q. See the documentation for more '+'information.','document','viewport');},getEventPosition:function(e,domain){domain=domain||'document';e=event_get(e);return(new Vector2(mouseX(e),mouseY(e),'document').convertTo(domain));},getScrollPosition:function(domain){domain=domain||'document';return(new Vector2(pageScrollX(),pageScrollY(),'document').convertTo(domain));},getElementPosition:function(el,domain){domain=domain||'document';return(new Vector2(elementX(el),elementY(el),'document').convertTo(domain));},getElementDimensions:function(el){var x=el.offsetWidth||0;var y=el.offsetHeight||0;return new Vector2(x,y);},getViewportDimensions:function(){var x=(window&&window.innerWidth)||(document&&document.documentElement&&documentElement.clientWidth)||(document&&document.body&&document.body.clientWidth)||0;var y=(window&&window.innerHeight)||(document&&document.documentElement&&documentElement.clientHeight)||(document&&document.body&&document.body.clientHeight)||0;return new Vector2(x,y);},getDocumentDimensions:function(){var x=(document&&document.body&&document.body.scrollWidth)||(document&&document.documentElement&&document.documentElement.scrollWidth)||0;var y=(document&&document.body&&document.body.scrollHeight)||(document&&document.documentElement&&document.documentElement.scrollHeight)||0;return new Vector2(x,y);},scrollTo:function(v){if(!(v instanceof Vector2)){v=new Vector2(Vector2.getScrollPosition().x,Vector2.getElementPosition($$(v)).y,'document');}
v=v.toDocumentCoordinates();if(window.scrollTo){window.scrollTo(v.x,v.y);}}});


function ge(id)
{
	if(typeof(id)=='undefined'){Util.error('Tried to get an undefined element!');return null;}
     var obj;
	 if(typeof(id)=='string')
	 {
		 obj=document.getElementById(id);
	//   if(!(ua.ie()>=7)){return obj;}
         if(!obj){return null;}
	     else if(typeof(obj.id)=='string'&&obj.id==id){return obj;}
	     else{
			 var candidates=document.getElementsByName(id);
	         if(!candidates||!candidates.length){return null;}
             var maybe=[];
	         for(var ii=0;ii<candidates.length;ii++)
	          {
		     var c=candidates[ii];if(!c.id&&id){continue;}
             if(typeof(c.id)=='string'&&c.id!=id){continue;}
             maybe.push(candidates[ii]);
	        }
		   if(maybe.length!=1)
		   {
			 Util.error('ge() failed in a bizarre complicated edge case. Check comments.');
			 return null;
			}
          return maybe[0];
	     }
	 }else{return id;}
  return null;
}

function focusInstructions(){Vector2.scrollTo(Vector2.getElementPosition(ge('tagging_instructions'),'document').sub(0,8));}
function hide_tagging_ui(href){tagging=false;hide('tagging_instructions');ge('myphoto').style.cursor='';hide('selector');hide('tagframe');}

function show_tagging_ui(party_id,photo_id,user_id)
 { pid=photo_id;
   user=user_id;
   ptyid=party_id;
   tagging=true; 
show('tagging_instructions');
ge('myphoto').style.cursor='crosshair';
ge('tagging_instructions_status_message').innerHTML='';
show('tagging_instructions_default_message');
focusInstructions();
}
function show_comment(party_id,photo_id,user_id)
 { pid=photo_id;
   user=user_id;
   ptyid=party_id;
   tagging=true; 
show('tagging_instructions');
ge('myphoto').style.cursor='crosshair';
ge('tagging_instructions_status_message').innerHTML='';
show('tagging_instructions_default_message');
focusInstructions();
}



function tagHit(){
  if(activePersonID==-2)
   {
	 var activePersonName='';
	 var name = document.getElementsByTagName("input");
	 for(i=1;i<=name.length;i++){
	 if(ge("name"+i).checked){
	 activePersonName=ge("name"+i).value;
	 break;
	 }else{
		ge('tagging_instructions_default_message').innerHTML='<font color="#FF0033">Please select one option for tag.</font>'; 
	 }
	 } //for
	//alert(activePersonName);
    activePersonNameEscaped=htmlspecialchars(activePersonName);
	tagImage=ge('myphoto');
    percentX=(activeImageMouseX*100)/tagImage.width;
	percentY=(activeImageMouseY*100)/tagImage.height;
     
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
  		    //alert(req.responseText);
			 eval(req.responseJS.phototags);
			ge("phototags").innerHTML='<script type="text/javascript">'+req.responseJS.phototags+'</script>';
			ge("photocaption").innerHTML=req.responseJS.photocaption;
			cancelHit();
			// alert(req.responseJS.photoid+req.responseJS.userid+req.responseJS.name+req.responseJS.action+req.responseJS.x+req.responseJS.y);
             }
	  } // end responce
	  		if(photo_tags.length>10)
			{
			//successMessage='';
			hide('tagging_instructions_default_message');
			ge('tagging_instructions_status_message').innerHTML="<font color=\"#FF0033\">Unable to save tag. A photo may only have up to 10 tags. To add a new tag, you must first remove one of the existing tags on the photo.</font>";
			focusInstructions();
			return false;
			}
		  else{ 
           // Prepare request object (automatically choose GET or POST).
            req.open(null, ajax_setter_uri, true);
           // Send data to backend.
            req.send( {'pictureid':pid,'partyid':ptyid,'taggedby':user,'taggedid':activePersonNameEscaped,'action':'add','x':percentX,'y':percentY} );
			
			hide('tagging_instructions_default_message');
	        ge('tagging_instructions_status_message').innerHTML='You can continue to the photo below. When you are done, click the "Done Tagging" button to resume browsing.';
			focusInstructions();  
 		 }  //end else
	   }
   }
   
function cancelHit()
{resetSelector();}

function deleteTag(tagid,party_id,photo_id,user_id)
{
   pid=photo_id;
   user=user_id;
   ptyid=party_id;
   
   var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
      if (req.readyState == 4) 
		{
		//alert(req.responseText);
	 eval(req.responseJS.phototags);
	ge("phototags").innerHTML='<script type="text/javascript">'+req.responseJS.phototags+'</script>';
	ge("photocaption").innerHTML=req.responseJS.photocaption;
		 }
	  } // end responce
	  
	 // Prepare request object (automatically choose GET or POST).
     req.open(null, ajax_setter_uri, true);
     // Send data to backend.
     req.send( {'tagid':tagid,'pictureid':pid,'partyid':ptyid,'action':'del','taggedby':user} );
	 hide('tagging_instructions_default_message');
	 ge('tagging_instructions_status_message').innerHTML='Tag deleted form photo.';
    focusInstructions();  
}
/******************* video tagging ================================*/
function deletevTag(tagid,video_id,user_id)
{
   vid=video_id;
   user=user_id;
   
   var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
      if (req.readyState == 4) 
		{
			ge("videocaption").innerHTML=req.responseJS.videocaption;
		 }
	  } // end responce
	  
	 // Prepare request object (automatically choose GET or POST).
     req.open(null, ajax_setter_uri, true);
     // Send data to backend.
     req.send( {'tagid':tagid,'videoid':vid,'action':'delvideotag','taggedby':user} );
	 ge('tag_video_frame_msg').innerHTML='Tag deleted form Video.';
    focusInstructions();  
}

function tag_video_frame(){
	hide('tag_video_frame_msg');
    show('tag_video_frame');
}

function tag_video(video_id,tagedby){
    var vid = video_id;
	user = tagedby;
	taged_userid= ge('freind_list').options[ge('freind_list').selectedIndex].value;
	    
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
			//alert(req.responseText);
			ge("videocaption").innerHTML=req.responseJS.videocaption;
             }
	  }
	  
       req.open(null, ajax_setter_uri, true);
       // Send data to backend.
      req.send( {'videoid':vid,'taggedby':user,'taggedid':taged_userid,'action':'addvideotag'} );
	 hide('tag_video_frame');
	 show('tag_video_frame_msg');
	 ge('tag_video_frame_msg').innerHTML='Video is taged successful.';
	 
 }
/*================== added by rama krishna ==========================*/
function emailtofriend()
	{
    ge('tagging_instructions_status_message').innerHTML='';
    show('send_email_to_friend');
   // ge('send_email_to_friend').innerHTML='';
	}
function hideemailtofriend(href){tagging=false;hide('send_email_to_friend');ge('tagging_instructions_status_message').style.cursor='';hide('selector');}
/*================== Image tag commenting ==========================*/
function tag_comments()
	{
    ge('tagging_instructions_status_message').innerHTML='';
    show('comments');
   // ge('send_email_to_friend').innerHTML='';
	}

function deleteComment(commentid,party_id,photo_id,user_id)
{	
   pid=photo_id;
   user=user_id;
   ptyid=party_id;
   
   var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
      if (req.readyState == 4) 
		{
	ge('success_comment').innerHTML=req.responseText;
		 }
	  } // end responce
	  
	 // Prepare request object (automatically choose GET or POST).
     req.open(null, ajax_setter_del_comments , true);
     // Send data to backend.
     req.send( {'commentid':commentid,'pictureid':pid,'partyid':ptyid,'action':'del','taggedby':user} );
	 hide('tagging_instructions_default_message');
	 ge('tagging_instructions_status_message').innerHTML='Comment deleted form photo.';
    focusInstructions();  
}

function validateemail()
	{
     var email=ge('friend_email').value;
//var email = document.getElementById('friend_email');

	 if(email=="") 
		{
		 hideemailtofriend();
	 return true;
		}else if(isValidEmail(email)) 
		{
			//alert("correct email");
			send_email();
			hideemailtofriend();
          return true;
		}else{
			jAlert("Please enter a valid email id ");
			document.getElementById('friend_email').focus();
			return false;

		}

	}
	

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}

function send_email(){
  	 
	friend_email=ge('friend_email').value;
	partyid=ge('party_id').value;
	pictureid=ge('picture_id').value;
	    
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
			ge('success').innerHTML=req.responseText;
			
             }
	  }
	  
           // Prepare request object (automatically choose GET or POST).
            req.open(null, 'sendmail.php', true);
           // Send data to backend.
		  req.send( {'email':friend_email,'partyid':partyid,'pictureid':pictureid} );
				  
	  
   }
   //validate comments
   function validate_comment()
	{
     var comment=ge('comment').value;
//var email = document.getElementById('friend_email');

		 if(comment=="") 
		{
			jAlert("Please enter comment")
			 return false;
		}
		else
		{
			  hidecomment();
			  send_comments();
			  return true;
		}
	}
   //comments on all pictures
   
   function send_comments(){
  	 
	tag_comment=ge('comment').value;
	partyid=ge('party_id').value;
	pictureid=ge('picture_id').value;
	userid=ge('user_id').value;
	    
   	 var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
			ge('success_comment').innerHTML=req.responseText;
			
             }
	  }
	  
           // Prepare request object (automatically choose GET or POST).
            req.open(null, 'send_comment.php', true);
           // Send data to backend.
		  req.send( {'tag_comment':tag_comment,'partyid':partyid,'pictureid':pictureid,'userid':userid} );

   }
   
   function hidecomment(href){tagging=false;hide('comments');ge('tagging_instructions_status_message').style.cursor='';hide('selector');}
   
   function username_available()
   {
	  var username=document.getElementById("user_name");
	  if(isValidEmail(username.value))
	  {
		  
		  var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
               if (req.readyState == 4) 
			  {
				  if(req.responseText!="")
				  {
				  ge('account').innerHTML=req.responseText;
				  }
             }
	       }
	  
           // Prepare request object (automatically choose GET or POST).
          req.open(null, 'sendmail.php', true);
           // Send data to backend.
		  req.send( {'username':username.value} );
		  
	  }else{
		  jAlert("Not a valid username");
		  return false;
	  }
		  
   }
   
   function saveuserevent(eventid,statusid)
   {
	   
	    var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
				 if(statusid==2)
				 {
					 jAlert(req.responseText)
			//ge("bein").innerHTML = "&nbsp;&nbsp;"+req.responseText;
				 }else{
					  jAlert(req.responseText)
			//ge("beat").innerHTML = "&nbsp;&nbsp;"+req.responseText;
				 }
			
             }
	  }
	  
           // Prepare request object (automatically choose GET or POST).
            req.open(null, 'saveevent.php', true);
           // Send data to backend.
		  req.send( {'event':eventid,'status':statusid} );
				  
   }

  function send_reply(msg_id)
  {
  var sender = document.getElementById("sender_id").value;
  var recipient = document.getElementById("recipient_id").value;
  var rmsg = document.getElementById("re_msg").value;
  //jAlert("this is reply"+rmsg);
  if(rmsg < 5)
  {
	  jAlert("Enter Some Information");
	  return false;
  }
  document.getElementById(msg_id).innerHTML="";

   var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
			jAlert(req.responseText);
			
             }
	  }
	  
           // Prepare request object (automatically choose GET or POST).
            req.open(null, 'savereply.php', true);
           // Send data to backend.
		  req.send( {'senderid':sender,'recipientid':recipient,'msgid':rmsg} );
   //jAlert("sender "+sender+" reci "+recipient+"  msg "+rmsg)
  }
function reply(sender,recipient,pos)
	{
	 var sender_id = sender;var recipient_id = recipient;var msg_id = pos;var htmlform ='';
	 htmlform +='<input type="hidden" name="sender_id" id="sender_id" value="'+sender_id+'" /><input type="hidden" name="recipient_id" id="recipient_id" value="'+recipient_id+'" /><center><textarea name="msg" id="re_msg" rows="4" cols="40" class="textarea"></textarea><br><br><img  src="images/btn_new_submit.gif" id="reply" onclick="javascript: checkreply(\''+pos+'\')" /></center>';
	 document.getElementById(msg_id).innerHTML=htmlform;
	}
function checkreply(pos)
{
	var msg = document.getElementById("re_msg").value.length;
  if(msg < 2)
  {
	  jAlert("Enter Some information");
	  return false;
  }else{
	  send_reply(pos);
	  
  }
}
function HideOrShowStuff(regionToHide)
{
    if (document.getElementById)
    {
        // Hide all regions
		document.getElementById('description').style.display = 'none';
        document.getElementById('articles').style.display = 'none';
        document.getElementById('reviews').style.display = 'none';
		document.getElementById('music').style.display = 'none';
		document.getElementById('events').style.display = 'none';
        // Display the requested region
		if(regionToHide==0)
		{
        document.getElementById("description").style.display = 'block';
		}else if(regionToHide==1)
		{
		document.getElementById("articles").style.display = 'block';
		}else if(regionToHide==2)
		{
		document.getElementById("reviews").style.display = 'block';
		}else if(regionToHide==3)
		{
		document.getElementById("music").style.display = 'block';
		}else if(regionToHide==4)
		{
		document.getElementById("events").style.display = 'block';
		}
    }
    else
    {
        jAlert('Sorry, your browser doesn\'t support this');
    }
}

function search()
{
  //jAlert("You Entered "+document.getElementById("searchkey").value);
  var word = document.getElementById("searchkey").value;
  //jAlert(word);
  var req = new JsHttpRequest();
       // Code automatically called on load finishing.
      req.onreadystatechange = function() {
            if (req.readyState == 4) 
			{
			//jAlert(req.responseText);
			 // innerHTML(req.responseText);
			  ge("results").innerHTML = req.responseText;
			  ge("results").style.display="block"
             }
	  }
	  
           // Prepare request object (automatically choose GET or POST).
            req.open(null, 'mysearch.php', true);
           // Send data to backend.
		  req.send( {'word':word} );
	
}

/**** Function to show image detail with out page load ****/
function load_inner_imgdetail(aid,pid)
{
   
   var req1 = new JsHttpRequest();
    // Code automatically called on load finishing.
     req1.onreadystatechange = function() {
		 if (req1.readyState == 4) {
eval(req1.responseJS.phototags);

//  eval(req1.responseJS.photodesc);
	ge("inner_main").innerHTML=req1.responseJS.photodesc;
	eval(req1.responseJS.frndlist);
	
		 }else if (req1.readyState < 4){
		ge("inner_main").innerHTML='<table width="650" border="0" align="center" cellpadding="0" cellspacing="0"><tr>   <td height="550" valign="middle" align="center"> <img src="images/ajax-loader.gif"> </td></tr></table>';	 
		 }
	  } // end responce
	  
	 // Prepare request object (automatically choose GET or POST).
     req1.open(null, ajax_innerpage_url, true);
     // Send data to backend.
     req1.send( {'partyid':aid,'photo':pid} );
}
/** End Function ***/


function loadTag(party_id,photo_id)
{
   pid=photo_id;
   ptyid=party_id;
   var req = new JsHttpRequest();
    // Code automatically called on load finishing.
    req.onreadystatechange = function() {
      if (req.readyState == 4) 
		{
		//	jAlert(req.responseJS.phototags);
		//jAlert(req.responseText);
	 eval(req.responseJS.phototags);
	//  eval(req.responseJS.photocaption);
			ge("phototags").innerHTML='<script type="text/javascript">'+req.responseJS.phototags+'</script>';
			ge("photocaption").innerHTML=req.responseJS.photocaption;
		 }
	  } // end responce
	  
	 // Prepare request object (automatically choose GET or POST).
     req.open(null, ajax_innerpagetag_url, true);
     // Send data to backend.
     req.send( {'pictureid':pid,'partyid':ptyid} );
//    focusInstructions();  
}

function get_shortName(frnd_list)
   {   
   list ='';
	    for(i=0;i<frnd_list.length;i++)
		{
			friend = frnd_list[i];
			list += "<span class=\"inputcheckbox\"><input type=\"radio\" name=\"name\"  id=\"name"+(i+2)+"\" value=\""+friend[0]+"\"  />"+friend[1]+"</span></br>";
		}
		ge("userlist").innerHTML=list;
   }

   function fbshare(SERVER,partyid,pictureid){

	 window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(SERVER+'displaypic.php?partyid='+partyid+'&photo='+pictureid),
             'sharer','toolbar=0,status=0,width=626,height=436');
	return false;
}

