// JavaScript Document

function autoSuggest()
{
	var keyword = $('brandFinder').value;
	new Ajax.Request('inc/ajax.php?do=search&keyword=' + keyword,
					 {
						 onSuccess: function(html) {
							var response = html.responseText;
							if(response!=""){
								$('results').update(response);
								$('results').show();
							} else {
								$('results').hide();
							}
						 }
					 });
}
function selectBrand(brand)
{
	$('brandFinder').value = brand;
	$('results').hide();
}



function displayPopup(ele)
{
	$('overlay').observe('click', (function() { closePopup('add2friends'); }));
	//$$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'hidden' });
	var objBody = $$('body')[0];
	objBody.setStyle({ overflow:'hidden' });
	$('popup-friends-image').src = "";
	$('popup-friends-name').update();
	
	var info = ele.href;
	var index = info.indexOf("add2friends");
	var sliced = info.slice(index);
	var memberId = sliced.slice(sliced.indexOf("=") + 1);
	new Ajax.Request('func/getMemberInfo.php',{
					 method:"post",
					 parameters: { "memberId":memberId },
					 onSuccess: function(html) {
						 var json = html.responseText.evalJSON();
						 var name = json.name;
						 var image = json.image;
						$('popup-friends-image').src = image;
						$('popup-friends-name').update(name);
					 },
					 onFailure: function() { alert("Failed"); }
					 });
	
	
	var arrayPageSize = getPageSize();
	$('overlay').setStyle({ width: arrayPageSize[0] + 'px', height: arrayPageSize[1] + 'px' });
	new Effect.Appear('overlay', { duration: 0.2, from: 0.0, to: 0.8 });

	var arrayPageScroll = document.viewport.getScrollOffsets();
	var lightboxTop = arrayPageScroll[1] + ((document.viewport.getHeight() / 2) - 75);
	var lightboxLeft = arrayPageScroll[0];
	$('popup-friends').setStyle({ top: lightboxTop + 'px', left: lightboxLeft+(arrayPageSize[0]/2)-200 + 'px' });
	new Effect.Appear('popup-friends', { duration: 0.5, from: 0.0, to: 1.0 });
}
function closePopup()
{
	new Effect.Fade('overlay', { duration: 0.2 });
	new Effect.Fade('popup-friends', { duration: 0.2 });
		var objBody = $$('body')[0];
		objBody.setStyle({ overflow:'auto' });
       $$('select', 'object', 'embed').each(function(node){ node.style.visibility = 'visible' });
}
function add2Friends()
{
	$('add2FriendsForm').request( { onSuccess:function(html) {  }});
	closePopup();
}

function getPageSize()
{
	        
	     var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = window.innerWidth + window.scrollMaxX;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		
		if (self.innerHeight) {	// all except Explorer
			if(document.documentElement.clientWidth){
				windowWidth = document.documentElement.clientWidth; 
			} else {
				windowWidth = self.innerWidth;
			}
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = xScroll;		
		} else {
			pageWidth = windowWidth;
		}

		return [pageWidth,pageHeight];
	}




function chooseLook(choice)
{
	if(choice == "a" || choice == "b")
	{
		$('lookChoice').value = choice;
		$('lookForm').submit();
	} 
}
function ratePicture(num)
{
	if(num > 0 || num < 11)
	{
		$('rateChoice').value = num;
		$('rateForm').submit();
	} 
}
function addComment()
{
			/*
			<div class="comment-row">
    <div class="comment-row-avatar">
		<img src="image.php?image=/images/memberPhotos/3-ChristinaAguileraStripped.jpg&amp;width=70&amp;height=70&amp;cropratio=1:1"><br>
* 		<a href="member.php?memberId=3">Brad</a>
	</div>
    <div class="comment-row-text">
		Good CD
	</div>
</div> <!-- END comment-row -->
<div class="clear"></div>

<div class="comment-row">
    <div class="comment-row-author">Posted by <a href="member.php?memberId=3">Brad</a>  Sat Feb 7, 2009 10:58 PM | <a href="reportabuse" onclick="javascript: reportAbuse('41'); return false;">Report Abuse</a></div>
</div> <!-- END comment-row -->
<div class="clear"></div>

							
							image.php?image=/<?=Imager::getImgUrlById($member['profilePicId'])?>&width=70&height=70&cropratio=1:1"
			*/
	$('addCommentForm').request(
		{
			onSuccess: function(html)
			{
				var IE = document.all?true:false;
				$('add-comment').fade();
				var json = html.responseText.evalJSON();
				if(!IE)
				{
					if(json.expert == 1)
						var expert = Builder.node("img", { src:"images/expert-image.gif", width:"15", height:"19", alt:"Expert Indicator", 'border':"0" });
					else
						var expert = "";
					var div = Builder.node('div', { className:'comment-row' },
								[
									Builder.node('div', { className:'comment-row-avatar' },
									[
										Builder.node('img', { src:"image.php?image=/" + json.url + "&width=70&height=70&cropratio=1:1", alt:json.alt }),
										Builder.node('br'),
										Builder.node('a', { href:"member.php?memberId=" + json.memberId },
										[
											expert,
											Builder.node("span", json.memberName )
										])
									]),
									Builder.node('div', { className:'comment-row-text' },
									[
										json.comment
									])
								]);
					var author =  Builder.node('div', { className:'comment-row' },
								[
									Builder.node('div', { className:'comment-row-author' },
									[
										Builder.node('span','Posted by '),
										Builder.node('a', { href:"member.php?memberId=" + json.memberId }, json.memberName ),
										Builder.node('span'," " + json.dateTime + " | "),
										Builder.node('a', { href:"reportabuse", onclick:"javascript: reportAbuse('" + json.commentId + "'); return false;" }, "Report Abuse")
									])
								]);
	
					
					var newDiv = Builder.node('div');
					newDiv.appendChild(div);
					newDiv.appendChild(Builder.node('br', { className:'clear'}, ' '));
					newDiv.appendChild(author);
					newDiv.appendChild(Builder.node('br', { className:'clear'}, ' '));
					$('new-comment').insert(newDiv, { position:'after' });
				}
				else
				{
					if(json.expert == 1)
						var expert = "<img src=\"images/expert-image.gif\" width=\"15\" height=\"19\" alt=\"Expert Indicator\" border=\"0\" /> ";
					else
						var expert = "";
					var text = "<div class=\"comment-row\"><div class=\"comment-row-avatar\"><img src=\"image.php?image=/"
					text += json.url;
					text += "&amp;width=70&amp;height=70&amp;cropratio=1:1\"><br>";
					text += expert;
					text += "<a href=\"member.php?memberId="
					text += json.memberId;
					text += "\">";
					text += json.memberName;
					text += "</a></div><div class=\"comment-row-text\">";
					text += json.comment;
					text += "</div></div> <!-- END comment-row --><div class=\"clear\"></div><div class=\"comment-row\"><div class=\"comment-row-author\">Posted by <a href=\"member.php?memberId="
					text += json.memberId;
					text += "\">";
					text += json.memberName;
					text += "</a>  ";
					text += json.dateTime;
					text += " | <a href=\"reportabuse\" onclick=\"javascript: reportAbuse('";
					text += json.commentId;
					text += "'); return false;\">Report Abuse</a></div></div> <!-- END comment-row --><div class=\"clear\"></div>";
					$('new-comment').update(text);
				}
			}
		});
}

function showTag(tagId,coord1,coord2)
{
	$('tagBallon'+tagId).setStyle({ left:coord1+'px', top:coord2+'px' });
	$('tagBallon'+tagId).show();
}
function showSplitTag(side,tagId,coord1,coord2)
{
	$('tagBallon'+side+tagId).setStyle({ left:coord1+'px', top:coord2+'px' });
	$('tagBallon'+side+tagId).show();
}
function hideSplitTag(side,tagId)
{
	$('tagBallon'+side+tagId).hide();
}
function hideTag(tagId)
{
	$('tagBallon'+tagId).hide();
}
function deleteTag(tagId)
{
	$('deleteTagId').value = tagId;
	$('deleteTagsForm').submit();
}

function flagpicture( imageId )
{
	var url = "inc/ajax.php?do=flagpicture&imageId=" + imageId;
	new Ajax.Request( url, {
					 onSuccess: function(html) {
					 }
					 });
}

