var selectedTabFontStart = "<font class='newsfontselected'>" ;
var selectedArticleTabFontStart = "<font class='articlefontselected'>" ;
var selectedTabFontEnd = "</font>" ;
var loadImage = "<center> <img src='/ajax-loader-indicator-lite.gif'></center>";

var newsTabIndex=0;
var friendsTabIndex=1;
var picturesTabIndex=2;
var commentTabIndex=3;

var newsTabTitle="News";
var friendsTabTitle="Friends";
var picturesTabTitle="Pictures";
var commentTabTitle="Comments";

var tabTitle = new Array();
tabTitle[newsTabIndex] = newsTabTitle;
tabTitle[friendsTabIndex] = friendsTabTitle;
tabTitle[picturesTabIndex] = picturesTabTitle;
tabTitle[commentTabIndex] = commentTabTitle;

var requestObject = new Array();
requestObject[newsTabIndex]=getProfileRemoteObject();
requestObject[friendsTabIndex]=getProfileRemoteObject();
requestObject[picturesTabIndex]=getProfileRemoteObject();
requestObject[commentTabIndex]=getProfileRemoteObject();

var oldTd = "tdTab1";
var currentTd = "tdTab2";

var oldTabIndex = 1;
var currentTabIndex = 2;

var oldTab="tab1";
var currentTab="tab2";

var oldContentDivId = "content1";
var currentContentDivId = "content2";

var oldClickedOn = "tdMainProfile";
var mainProfileRequested = false;
var personalInfoRequested = false;
var settingsRequested = false;

function mouseOver(div){
	div.style.backgroundColor='#ECEFF5';
	//div.style.color='#3B5998';
	//div.style.fontWeight='bold';
}

function mouseOut(div){
	div.style.backgroundColor='#ffffff';
	//div.style.color='#0077BB';
	//div.style.fontWeight='normal';
}

function mouseClick(div1, div2){
	document.getElementById(oldClickedOn).style.fontWeight="normal";
	document.getElementById(oldClickedOn).style.color="#0077BB";
	document.getElementById(div1).style.fontWeight="bold";
	document.getElementById(div1).style.color="darkBlue";
	oldClickedOn = div1;
	document.getElementById("mainProfile").style.display="none";
	document.getElementById("personalProfile").style.display="none";
	document.getElementById("settings").style.display="none";
	document.getElementById(div2).style.display="";
	if(div2 == 'mainProfile' && mainProfileRequested == false){
		getMainProfile();
		mainProfileRequested = true;
	}
	if(div2 == 'personalProfile' && personalInfoRequested == false){
		getPersonalProfile();
		personalInfoRequested = true;
	}
	if(div2 == 'settings' && settingsRequested == false){
		getSettings();
		settingsRequested = true;
	}
}

function getMainProfile(){
	url ='/blog/profile/editProfile';
	//alert(url);
	sendRequestCallFunctionAfter("mainProfile", url, 1, "updatePersonalInfo()");
}

function getPersonalProfile(){
	url ='/blog/profile/editPersonalInfo';
	sendRequestCallFunctionAfter("personalProfile", url, 1, "updatePersonalInfo()");
}

function getSettings(){
	url ='/blog/profile/editAccountSettings';
	sendRequestCallFunctionAfter("settings", url, 1, "updatePersonalInfo()");
}

function setPicturePrivacy(val){
	picture_privacyVal = val;
}

function setProfilePrivacy(val){
	profile_privacyVal = val;
	//alert(val);
}

function setBlogPrivacy(val){
	blog_privacyVal = val;
}

function setNewsPrivacy(val){
	news_privacyVal = val;
}
//var year =0; var month =0; var day=0
function resetPersonalInfo(){
	if(document.personalForm && document.personalForm.year)
		year = document.personalForm.year.value;
	if(document.personalForm && document.personalForm.month)
		month = document.personalForm.month.value;
	if(document.personalForm && document.personalForm.day)
		day = document.personalForm.day.value;
	alert(year + " " + month + " " + day);
}

function updatePersonalInfo(){
	if(document.personalForm && document.personalForm.year)
		document.personalForm.year.value=yearVal;
	if(document.personalForm && document.personalForm.month)
		document.personalForm.month.value=monthVal;
	if(document.personalForm && document.personalForm.day)
		document.personalForm.day.value=dayVal;
	if(document.profileForm && document.profileForm.education)
		document.profileForm.education.value=educationVal;
		
	if(document.getElementById("profile_privacy" + profile_privacyVal))
		document.getElementById("profile_privacy" + profile_privacyVal).checked=true;
	
	if(document.getElementById("blog_privacy" + blog_privacyVal))
		document.getElementById("blog_privacy" + blog_privacyVal).checked=true;
		
	if(document.getElementById("news_privacy" + news_privacyVal))
		document.getElementById("news_privacy" + news_privacyVal).checked=true;
		
	if(document.getElementById("picture_privacy" + picture_privacyVal))
		document.getElementById("picture_privacy" + picture_privacyVal).checked=true;
}

function submitAbout(){
params = "education=" + document.getElementById("education").value;
params = params +  "&line=" + document.getElementById("line").value;
params = params +  "&about=" + document.getElementById("about").value;
params =  params + "&what_like=" + document.getElementById("what_like").value;
params =  params + "&interest=" + document.getElementById("interest").value;
params =  params + "&book=" + document.getElementById("book").value;
params =  params + "&movie=" + document.getElementById("movie").value;
params =  params + "&tv=" + document.getElementById("tv").value;
params =  params + "&music=" + document.getElementById("music").value;
params =  params + "&people=" + document.getElementById("people").value;
params =  params + "&celebrity=" + document.getElementById("celebrity").value;
params =  params + "&politic=" + document.getElementById("politic").value;
params =  params + "&job=" + document.getElementById("job").value;

url = '/blog/profile/saveExtendedProfile.php';
//alert(url);
sendPostRequest("mainProfile", url, params, 1);
mainProfileRequested = false;
}

function submitInfo(){
params = "year=" + document.getElementById("year").value;
params = params +  "&month=" + document.getElementById("month").value;
params = params +  "&day=" + document.getElementById("day").value;
params =  params + "&address=" + document.getElementById("address").value;
params =  params + "&city=" + document.getElementById("city").value;
params =  params + "&province=" + document.getElementById("province").value;
params =  params + "&country=" + document.getElementById("country").value;
params =  params + "&postal_code=" + document.getElementById("postal_code").value;
params =  params + "&home_phone=" + document.getElementById("home_phone").value;
params =  params + "&work_phone=" + document.getElementById("work_phone").value;
params =  params + "&cell_phone=" + document.getElementById("cell_phone").value;


url = '/blog/profile/savePersonalInfo.php';
//alert(url);
sendPostRequest("personalProfile", url, params, 1);
personalInfoRequested = false;
}

function updatePrivacy(){
	params = "profile_privacy=" + profile_privacyVal;
	params = params + "&blog_privacy=" + blog_privacyVal;
	params = params + "&news_privacy=" + news_privacyVal;
	params = params + "&picture_privacy=" + picture_privacyVal;

	url = '/blog/profile/saveAccountSettings.php';
	//alert(params);
	sendPostRequest("settings", url, params, 1);
	settingsRequested = false;
}

function share(){
	document.getElementById('shareInnerWindow').innerHTML = document.getElementById('shareInnerWindowBackup').innerHTML;
	centerElement("shareDiv",500, 400);
}

function sendShare(theId){
	theEmail = document.getElementById('shareEmailText').value;
	if(theEmail == '')
		return;
		
	sendPostRequest('shareInnerWindow', "/blog/friend/shareFriends", "email=" + theEmail + "&id=" + theId, 1);
}

function tabClicked(index, tdId, titleId, divId){
	//alert(index + "," + tdId +"," + titleId + "," + divId);
	if(index == currentTabIndex)
		return;
	oldTabIndex = currentTabIndex;
	currentTabIndex = index;
	
	oldTd = currentTd;
	currentTd = tdId;
	
	oldTab = currentTab;
	currentTab = titleId;
	//alert(currentTab); alert(oldTab);
	currentTdElem = document.getElementById(currentTd);
	oldTdElem = document.getElementById(oldTd);
	
	currentTabElem = document.getElementById(currentTab);
	oldTabElem = document.getElementById(oldTab);
	
	currentTabElem.innerHTML = selectedTabFontStart + tabTitle[index] + selectedTabFontEnd;
	oldTabElem.innerHTML = tabTitle[oldTabIndex];
	
	currentTdElem.style.backgroundColor='white';
	currentTdElem.style.borderTopWidth='1px';
	currentTdElem.style.borderBottomWidth='0px';
	//if(index ==0)
	//	currentTdElem.style.borderLeftWidth = "1px";
	if(index ==3)
		currentTdElem.style.borderRightWidth = "1px";
	oldTdElem.style.backgroundColor='#ECEFF5';
	oldTdElem.style.color='#6D84B4';
	oldTdElem.style.borderBottomWidth='1px';

	
	document.getElementById(currentContentDivId).style.display="none";
	document.getElementById(divId).style.display="";
	oldAContentDivId = currentContentDivId;
	currentContentDivId = divId;
	if(currentTabIndex ==1){
		document.getElementById("viewAllDiv").innerHTML ="All Friends";
	}
	if(currentTabIndex ==2){
		document.getElementById("viewAllDiv").innerHTML ="All Pictures";
	}
	if(currentTabIndex ==3){
		document.getElementById("viewAllDiv").innerHTML ="All Comments";
	}
}

function getNews(viewer, owner){
	var url="getPersonalNews.php?viewer=" + viewer + "&owner=" + owner;
	sendProfileRequest(newsTabIndex, requestObject[newsTabIndex], url);
}

function getProfileRemoteObject() {
	var req;
	if(window.XMLHttpRequest){
		// Firefox, Safari, Opera...
		req = new XMLHttpRequest();
	} else if(window.ActiveXObject) {
		// Internet Explorer 5+ 
		req = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		alert('Problem creating the XMLHttpRequest object'); 
	}
	return req;
}

function getComments(divId, owner){
	var url="getProfileComments.php?owner=" + owner;
	sendProfileRequest(commentTabIndex, requestObject[commentTabIndex], url);
}

function sendProfileRequest(tabIndex, http, divId, theLink) {
	http.open('GET', theLink, true);
	http.onreadystatechange = function() {
		if(http.readyState == 4 && http.status == 200) { 
			response = http.responseText;
			if(response) {
				//translateXML(tabIndex, divId, http.responseXML);
			}
		}
	}
	http.send(null);
	
}

//4169643311 506 620 

function askQuestion(){
	document.getElementById("questionTextAreaDiv").innerHTML = '<textarea id="question" style="padding:5px;color:#333333;font-size:12px;border:solid #eeeeee 1px; width:100%;height:160px;overflow:auto"></textarea>';
	document.getElementById("questionButtonDiv").style.display="";
	centerElement("questionDiv", 570, 370);
}

function sendQuestion(id){
	subjectVal = "A Question";
	recommendationVal = document.getElementById("question").value; 
	message1= subjectVal + "\n" + recommendationVal;
	//alert(message1);
	sendPostRequest('questionTextAreaDiv', "/blog/message/submitMessage", "id= " + id +  "&message="+message1, 1);
	document.getElementById("questionButtonDiv").style.display="none";
}

function comment(){
	document.getElementById("commentTextAreaDiv").innerHTML = '<textarea id="comment" style="padding:5px;color:#333333;font-size:12px;border:solid #eeeeee 1px; width:100%;height:160px;overflow:auto"></textarea>';
	document.getElementById("commentButtonDiv").style.display = "";
	centerElement("commentDiv", 570, 370);
}

function sendComment(id){
	commentVal = document.getElementById("comment").value;
	//alert(message1);
	sendPostRequest('commentTextAreaDiv', "/blog/comment/sendComment", "id= " + id +  "&comment="+commentVal, 1);
	document.getElementById("commentButtonDiv").style.display="none";
}

function sendMessage(id){
	if(document.getElementById("message")){
		message1 = document.getElementById("message").value;
		sendPostRequest('messageContentDiv', "/blog/message/submitMessage", "id= " + id +  "&message="+message1, 1);
		document.getElementById("messageButtonDiv").innerHTML="";
	}
}

function openMessageWindow(){
	document.getElementById("messageContentDiv").innerHTML=
		"<textarea id='message' style='padding:5px;color:#333333;font-size:12px;border:solid #eeeeee 1px; width:100%;height:160px;overflow:auto'></textarea>";
	document.getElementById("messageButtonDiv").innerHTML=document.getElementById("messageButtonDivBackup").innerHTML;
	centerElement("messageDiv", 570, 370);
}

function recommend(str){
	document.getElementById("recommendationDiv").innerHTML = '<textarea id="recommendation" style="padding:5px;color:#333333;font-size:12px;border:solid #eeeeee 1px; width:100%;height:160px;overflow:auto"></textarea>';
	document.getElementById("recommendSubject").innerHTML=str;
	document.getElementById("recommendButtonDiv").style.display="";
	centerElement("recommendDiv", 570, 370);
}

function sendRecommendation(id){
	subjectVal = document.getElementById("recommendSubject").innerHTML;
	recommendationVal = document.getElementById("recommendation").value;
	message1= subjectVal + "\n" + recommendationVal;
	sendPostRequest('recommendationDiv', "/blog/message/submitMessage", "id= " + id +  "&message="+message1, 1);
	document.getElementById("recommendButtonDiv").style.display="none";
	
}

function recommendBook(){
	recommend("<b>Recommend </b>a book");
}

function recommendMovie(){
	recommend("<b>Recommend </b>a movie");
}
function recommendTv(){
	recommend("<b>Recommend </b>a TV show");
}
function recommendActivity(){
	recommend("<b>Recommend </b>an activity");
}

function recommendGroup(){
	recommend("<b>Recommend </b>a group");
}

function recommendBlog(){
	recommend("<b>Recommend </b>a blog");
}

function recommendTravel(){
	recommend("<b>Recommend </b>a travel destination");
}

function recommendBlogToFriend(){
	//alert("This function is not yet working.");
	centerElement("shortFriendsListDiv", 460,500);
	url="/blog/friend/getFriendsShortList?start=0&per_page=10";
	//alert(url);
	sendRequest("shortFriendsListDivInnerWindow", url);
}

function sendBlogToFriend(id1,fname,lname){
	url="/blog/friend/sendBlogToFriend?id=" + id1 + "&fname=" + fname + "&lname=" + lname;
	//alert(url);
	sendRequest("shortFriendsListSendBlogInfo", url);
}

function getFriendsShortList(per_page, start_number){
	url = "/blog/friend/getFriendsShortList?per_page=" + per_page + "&start=" + start_number + "&count=" + document.getElementById("numFriendsDiv").innerHTML;
	
	sendRequest("shortFriendsListDivInnerWindow", url);
}

function addToFriends(id, fname, lname){
	document.getElementById("friendIdDiv").innerHTML=id;
	document.getElementById("addToFriendsContainerInnerWindow").innerHTML=document.getElementById("addToFriendsBackup").innerHTML;
	document.getElementById("friendName").innerHTML = fname + " " + lname;
	centerElement("addToFriendsContainer", 500, 400);	
}

function sendFriendRequest(){
	theId = document.getElementById("friendIdDiv").innerHTML;
	url="/blog/friend/addToFriend?id=" + theId;
	//alert(url);
	sendRequest("addToFriendsContainerInnerWindow", url);
}

function addToBestFriends(id, fname, lname){
	document.getElementById("friendIdDiv").innerHTML=id;
	document.getElementById("addToFriendsContainerInnerWindow").innerHTML=document.getElementById("addToBestFriendsBackup").innerHTML;
	document.getElementById("bestFriendName").innerHTML = fname + " " + lname;
	centerElement("addToFriendsContainer", 500, 400);	
}

function sendBestFriendRequest(){
	theId = document.getElementById("friendIdDiv").innerHTML;
	url="/blog/friend/addToBestFriend?id=" + theId;
	sendRequest("addToFriendsContainerInnerWindow", url);
}

function addToFamily(id, fname, lname){
	document.getElementById("friendIdDiv").innerHTML=id;
	document.getElementById("addToFriendsContainerInnerWindow").innerHTML=document.getElementById("addToFamilyBackup").innerHTML;
	document.getElementById("familyName").innerHTML = fname + " " + lname;
	centerElement("addToFriendsContainer", 500, 400);	
}

function sendFamilyRequest(){
	theId = document.getElementById("friendIdDiv").innerHTML;
	url="/blog/friend/addToFamily?id=" + theId;
	sendRequest("addToFriendsContainerInnerWindow", url);
}

function addToFavorites(id, fname, lname){
	document.getElementById("friendIdDiv").innerHTML=id;
	document.getElementById("addToFriendsContainerInnerWindow").innerHTML=document.getElementById("addToFavoriteBackup").innerHTML;
	document.getElementById("favoriteName").innerHTML = fname + " " + lname;
	centerElement("addToFriendsContainer", 500, 400);
}

function sendFavoriteRequest(){
	theId = document.getElementById("friendIdDiv").innerHTML;
	url="/blog/favorite/addToFavourites.php?id=" + theId;
	sendRequest("addToFriendsContainerInnerWindow", url);
}

