//On load page, init the timer which check if the there are anchor changes each 300 ms  
//$().ready(function(){  
   //  setInterval("checkAnchor()", 300);  
//});
function perfSearch() {
	var searchString = $('#search_box').val();
	if($('#readFollowed').hasClass("active")) {
		$.ajax({
			url: 'services/searchPosts.php',
			type: 'POST',
			dataType: 'html',
			data: {
				search: searchString
			},
			success: function(data, textStatus, xhr) {
				$('#readCollect').html(data);
			},
			error: function(xhr, textStatus, errorThrown) {
	    		console.log(errorThrown);
			}
		});
	}
	if($('#grabAllRecsByCategory').hasClass('active')) {
		$.ajax({
			url: 'services/searchRecs.php',
			type: 'POST',
			dataType: 'html',
			data: {
				search: searchString
			},
			success: function(data, textStatus, xhr) {
				$('#readDiscover').html(data);
			},
			error: function(xhr, textStatus, errorThrown) {
	    		console.log(errorThrown);
			}
		});
	} else {
		$.ajax({
			url: 'services/searchTrends.php',
			type: 'POST',
			dataType: 'html',
			data: {
				search: searchString
			},
			success: function(data, textStatus, xhr) {
				$('#readDiscover').html(data);
			},
			error: function(xhr, textStatus, errorThrown) {
	    		console.log(errorThrown);
			}
		});
	}
}

function getFileName(){
	var splitAt = location.href.lastIndexOf('\\') > location.href.lastIndexOf('/') ? location.href.lastIndexOf('\\') : location.href.lastIndexOf('/');
	var filename = location.href.substr(splitAt+1,location.href.length);
	var currentAnchor = null;
	return filename;	
}
//Function which chek if there are anchor changes, if there are, sends the ajax petition  
/*function checkAnchor(){  
	//Check if it has changes  
	if(currentAnchor != document.location.hash){  
		currentAnchor = document.location.hash;  
		//if there is not anchor, the loads the default section  
		if(!currentAnchor)  
			query = "section=home";  
		else {  
			//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2  
			var splits = currentAnchor.substring(1).split('&');  
    		//Get the section
			var section = splits[0];  
			delete splits[0];
			//Create the params string  
			var params = splits.join('&');  
			var query = "section=" + section + params;  
		}  
		//Send the petition  
		$.get("landingContent.php",query, function(data){  
			$("#content").html(data);  
		});  
	}  
}

function submitForm(dataFile, formData, completeFunction){
	var keyValueArray;
	var completeFunction;
	$.ajax({
	  url: dataFile,
	  type: 'POST',
	  dataType: 'html',
	  data: formData,
	  success: completeFunction,
	  error: function(xhr, textStatus, errorThrown) {
	    console.log(errorThrown)
	  }
	});

}
*/

var popupStatus = 0;
var openPop = "";
function loadPopup(popId){  
//loads popup only if it is disabled  
	if(popupStatus==0){  
		$("#bgModalCover").css({  
		"opacity": "0.7"  
		});  
		$("#bgModalCover").fadeIn("slow");  
		$(popId).fadeIn("slow");  
		openPop = popId;
		popupStatus = 1;  
	}  
}
function disablePopup(){  
	//disables popup only if it is enabled  
	if(popupStatus==1){  
		$("#bgModalCover").fadeOut("slow");  
		$(openPop).fadeOut("slow");  
		popupStatus = 0;  
	}
}
function centerPopup(popId){  
	//request data for centering  
	var windowWidth = document.documentElement.clientWidth;  
	var windowHeight = document.documentElement.clientHeight;  
	var popupHeight = $(popId).height();  
	var popupWidth = $(popId).width();  
	//centering  
	$(popId).css({  
		"position": "absolute",  
		"top": windowHeight/2-popupHeight/2,  
		"left": windowWidth/2-popupWidth/2  
	});  
	//only need force for IE6  
	$("#bgModalCover").css({  
		"height": windowHeight  
	});  
}
function rateRec(rating, rec, user, rewrite) {
	var nds = "user_id=" + user + "&rec_id=" + rec + "&rating="  + rating;
	$.ajax({
		type: "POST",
		url: "services/rate.php",
		data: nds,
		success: function(data) {
			var htmlStr = "";
			htmlStr = data;
			$(rewrite).html(htmlStr);
		}
	});
}
function getItemByTypeAndId(iType,iId, sT){
	centerPopup("#shareItem");
	loadPopup("#shareItem");
	hoverImage('.hover-buton');
	var htmlStr = '<div class="share-center">';
	htmlStr += '	<div class="minifieldrow"><input type="text" name="email" class="msgbox" id="shareemailinput" placeholder="email@email.com" value="email@email.com"></input></div>';
	htmlStr += '	<img class="hover-button" src="assets/images/btn-share_email.png" onclick="shareProx(\''+iType+'\','+iId+',\'EMAIL\')" />';
	htmlStr += '	<img class="hover-button" src="assets/images/btn-share_message.png" onclick="shareProx(\''+iType+'\','+iId+',\'MESSAGE\')" />';
	if(sT) {
		htmlStr += '	<img class="hover-button" src="assets/images/btn-share_twitter.png" onclick="shareProx(\''+iType+'\','+iId+',\'TWITTER\')" />';
	}
	htmlStr += '</div>';
	htmlStr += '<div class="cleared"></div>';
	$('#shareItemContent').html(htmlStr);
	hoverImage('.hover-button');
}
function shareProx(iType, iId, sType) {
	shareItem(iType, iId, sType, $('#shareemailinput').val());
}
function shareItem(iType,iId,sType,emailAddr){
	$.ajax({
		url: 'landingContent.php',
		type: 'POST',
		dataType: 'html',
		data: {
			section: 'sendShare',
			itemType: iType,
			itemId: iId,
			shareType: sType,
			email: emailAddr
		},
		success: function(data, textStatus, xhr) {
			$('#shareItemContent').html(data);
		},
		error: function(xhr, textStatus, errorThrown) {
	    console.log(errorThrown);
		}
	});
	
}
function activatePop(userId, userName, userImage) {
	centerPopup("#followPop");
	loadPopup("#followPop");
	var htmlStr = '<div class="follow-image"><img src="'+userImage+'"/></div>';
	htmlStr += '<div class="follow-right">';
	htmlStr += '	<div class="follow-text">Do you want to follow<br/>' + userName + '?</div>';
	htmlStr += '	<div class="follow-buttons"><yesLink onclick="submitFollow(' + userId + ')"><img class="hover-button" src="assets/images/btn-yes.png" /></yesLink> <noLink onclick="disablePopup()"><img class="hover-button" src="assets/images/btn-no.png" /></noLink></div>';
	htmlStr += '</div>';
	htmlStr += '<div class="cleared"></div>';
	$('#followPopContent').html(htmlStr);
	hoverImage('.hover-button');
}
function submitFollow(userId) {
	var htmlStr = "";
	var muid = "";
	htmlStr = "<div class='followForm'>please wait while your request is processed.</div>";
	$("#followPopContent").html(htmlStr);
	var dataString = "requestStr=get_user_id";
	//$.post("services/sessionInfo.php",query, function(data, userId){$.post("services/follow");});
	var query = "section=uid";
	$.ajax({
		url: 'landingContent.php',
		type: 'POST',
		dataType: 'html',
		data: {
			section: 'uid'
		},
	  	success: function(data, textStatus, xhr) {
			htmlStr = "<div class='followForm'>" + data + "</div>";
			$("#followPopContent").html(htmlStr);
			$.ajax({
				type: "POST",
				url: "services/followUser.php",
				data: {
					user_id: data,
					followId: userId,
					returnType: 'HTML'
				},
				success: function(data1) {
					var htmlStr = "";
					htmlStr = "<br><div class='followForm'>" + data1 + " " + muid + "</div>";
					$("#followPopContent").html(htmlStr);
					if(getFileName() == 'contacts.php'){
						fetchContent('.horizontal-scroll-area', 0, 'grabAllUsersCL');
					}
				}
			});
		},
		error: function(xhr, textStatus, errorThrown) {
			console.log(errorThrown);
		}
	});
}
function setMessageRead(msgID){
	$.ajax({
		url: 'landingContent.php',
		type: 'POST',
		dataType: 'html',
		data: {
			msgID: msgID
		},
		success: function(data, textStatus, xhr) {
	    	console.log(data);
		},
		error: function(xhr, textStatus, errorThrown) {
			console.log(errorThrown);
		}
	});
}
function fetchContent(divId, limiter, sectionId, menu) {
	$.ajax({
		url: 'landingContent.php',
		type: 'POST',
		dataType: 'html',
		data: {
			section: sectionId,
			limiter: limiter,
			menu: menu
		},
		success: function(data, textStatus, xhr) {
			$(divId).html(data);
			hoverImage('.hover-button');
		},
		error: function(xhr, textStatus, errorThrown) {
	    console.log(errorThrown);
		}
	});
}

function setContacts() {
	var containerWidth = $('.boxcontent').width();
	var containerHeight = $('.boxcontent').height();
	var record = $('.rolodex-record');
	var recordCount = record.size();
	var recordWidth = record.width();
	var recordHeight = record.height();
	var rowLimit = Math.floor(containerHeight / recordHeight);
	var recordsPerRow = Math.round(recordCount / rowLimit);

	if(recordsPerRow % 2 == 1){
		recordsPerRow = recordsPerRow + 1;
	}
	if(recordCount >= 4){
		minWidth = 4;
	}else{
		minWidth = 3;
	}
	var scrollAreaWidth = recordsPerRow * recordWidth;
	$('.horizontal-scroll-area').css({
		'width': scrollAreaWidth,
		'min-width': recordWidth * minWidth,
		'height': containerHeight -20
	});
}

function doSetDims() {
	if ($(window).width() > 1400) {
		$('div.fullsite').width(1400);
	} else {
		$('div.fullsite').width('100%');
	}
	doSetWidths();
	doSetHeight();
	if(getFileName() == 'contacts.php'){
		setContacts()
	}
}

function doSetWidths() {
	var offersMiddle = $('.offersdiv .middle-jl');
	var contentBlockWidth = $('#contentblock').width();
	if(getFileName() == 'contacts.php'){
		$('#col-3').width($('#contentblock').width() - 28);
		$('.middle').width($('#col-3').width() - (50 * 2));
	}else{
		$('.middle').width($('#col-1').width() - (50 * 2));
	}
	offersMiddle.width(contentBlockWidth  - 511);
	offersMiddle.find('.contentSubBox-jl').width(contentBlockWidth  - 443)
	offersMiddle.find('.scrollable').width(offersMiddle.width() + 8)
	
	$('.h-rule-black').width($('div.fullsite').width() - 60);
	$('.contentSubBox').width($('.middle').width() + 96 - 28);
	$('.ui-selectmenu').width($('.middle').width() + 96 - 28 - 10);
	$('.ui-selectmenu-menu').width($('.middle').width() + 96 - 28);
}
function doSetHeight() {
	if($(window).width() < 762){
		var headerItemsHeight = ($(window).height() - $('#topblock').height() - 10 - ($('.jldiv').height() * 2))+18;
	}else{
		var headerItemsHeight = ($(window).height() - $('#topblock').height() - 10 - $('.jldiv').height())-12;		
	}
	
	$('#contentblock').height(headerItemsHeight);
	$('.sh-m-m').height($('#contentblock').height() - (50 * 2));
	$('.sh-m-l').height($('#contentblock').height() - (50 * 2));
	$('.sh-m-r').height($('#contentblock').height() - (50 * 2));
	if(getFileName() == 'contacts.php'){
		$('.boxcontent').height($('#contentblock').height() - 109);
	}else{
		$('.boxcontent').height($('#contentblock').height() - (50 * 2) - 24);
	}
}
function unFollowUserModal(fid, userName, userImage) {
	centerPopup("#unFollowPop");
	loadPopup("#unFollowPop");
	var htmlStr = '<div class="follow-image"><img src="'+userImage+'"/></div>';
	htmlStr += '<div class="follow-right">';
	htmlStr += '	<div class="follow-text">Do you want to follow<br/>' + userName + '?</div>';
	htmlStr += '	<div class="follow-buttons"><yesLink onclick="confirmUnFollowUser(' + fid + ')"><img class="hover-button" src="assets/images/btn-yes.png" /></yesLink> <noLink onclick="disablePopup()"><img class="hover-button" src="assets/images/btn-no.png" /></noLink></div>';
	htmlStr += '</div>';
	htmlStr += '<div class="cleared"></div>';
	$('#unFollowPopContent').html(htmlStr);
	hoverImage('.hover-button');
}
function confirmUnFollowUser(fid) {
	var htmlStr = "";
	var muid = "";
	htmlStr = "<div class='followForm'>please wait while your request is processed.</div>";
	$("#followPopContent").html(htmlStr);
	var dataString = "requestStr=get_user_id";
	//$.post("services/sessionInfo.php",query, function(data, userId){$.post("services/follow");});
	var query = "section=uid";
	$.ajax({
		url: 'landingContent.php',
		type: 'POST',
		dataType: 'html',
		data: {
			section: 'removeFollowed',
			fid: fid
		},
	  	success: function(data, textStatus, xhr) {
			disablePopup();
			fetchContent('.horizontal-scroll-area', 0, 'grabAllUsers');
		},
		error: function(xhr, textStatus, errorThrown) {
			console.log(errorThrown);
		}
	});
}
function messageUsr(uid, cid, userName){
	centerPopup("#replyMessagePop");
	loadPopup("#replyMessagePop");
	var htmlStr = "<div class='login-sub'>\n";
	htmlStr += '<div class="message-panel">';
	htmlStr += '	<div class="reply-submit-result-box"></div>';
	htmlStr += '	<form id="reply-message-form" class="message-form" method="POST" action="services/message.php">';
	htmlStr += '		<div class="label-row">';
	htmlStr += '			<label for="compose-msg-recipient"><span><img src="assets/images/lbl-form-recipient.png" /></span></label>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="field-row">';
	htmlStr += '			<input name="not_applicable" class="textbox" disabled value="'+ userName +'" />';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '		<div class="label-row">';
	htmlStr += '			<label for="compose-msg-title"><span><img src="assets/images/lbl-form-subject.png" /></span></label>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="field-row">';
	htmlStr += '			<input name="subject" id="compose-msg-title" class="textbox" />';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '		<div class="label-row">';
	htmlStr += '			<label for="message-body"><span><img src="assets/images/lbl-form-message.png" /></span></label>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="field-row">';
	htmlStr += '			<textarea name="body" id="message-body"></textarea>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '		<div class="form-button-container">';
	htmlStr += '			<input type="hidden" name="loginType" value="LOCAL" />';
	htmlStr += '			<input type="hidden" name="to_id" value="'+ cid +'" />';
	htmlStr += '			<input type="hidden" name="id" value="'+ uid +'" />';
	htmlStr += '			<input type="hidden" name="returnType" value="HTML" />';
	htmlStr += '			<input type="button" class="compose-msg-send" id="reply-msg-form" value="SEND" />';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '	</form>';
	htmlStr += '	<div class="cleared"></div>';
	htmlStr += '</div>';
	$("#replyMessagePopContent").html(htmlStr);
}
function messageRespondPop(respondToMsgId, replyToStr, replyToId, subjectTxt, uid) {
	centerPopup("#replyMessagePop");
	loadPopup("#replyMessagePop");
	var htmlStr = "<div class='login-sub'>\n";
	htmlStr += '<div class="message-panel">';
	htmlStr += '	<div class="reply-submit-result-box"></div>';
	htmlStr += '	<form id="reply-message-form" class="message-form" method="POST" action="services/message.php">';
	htmlStr += '		<div class="label-row">';
	htmlStr += '			<label for="compose-msg-recipient"><span><img src="assets/images/lbl-form-recipient.png" /></span></label>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="field-row">';
	htmlStr += '			<input name="not_applicable" class="textbox" disabled value="'+ replyToStr +'" />';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '		<div class="label-row">';
	htmlStr += '			<label for="compose-msg-title"><span><img src="assets/images/lbl-form-subject.png" /></span></label>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="field-row">';
	htmlStr += '			<input name="subject" id="compose-msg-title" class="textbox" />';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '		<div class="label-row">';
	htmlStr += '			<label for="message-body"><span><img src="assets/images/lbl-form-message.png" /></span></label>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="field-row">';
	htmlStr += '			<textarea name="body" id="message-body"></textarea>';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '		<div class="form-button-container">';
	htmlStr += '			<input type="hidden" name="loginType" value="LOCAL" />';
	htmlStr += '			<input type="hidden" name="to_id" value="'+ replyToId +'" />';
	htmlStr += '			<input type="hidden" name="id" value="'+ uid +'" />';
	htmlStr += '			<input type="hidden" name="reply" value="YES" />';
	htmlStr += '			<input type="hidden" name="reply_id" value="'+ respondToMsgId +'" />';
	htmlStr += '			<input type="hidden" name="returnType" value="HTML" />';
	htmlStr += '			<input type="button" class="compose-msg-send" id="reply-msg-form" value="SEND" />';
	htmlStr += '		</div>';
	htmlStr += '		<div class="cleared"></div>';
	htmlStr += '	</form>';
	htmlStr += '	<div class="cleared"></div>';
	htmlStr += '</div>';
	$("#replyMessagePopContent").html(htmlStr);
}
function messageDelete(msgid, direction, MC) {
	centerPopup("#deleteMessagePop");
	loadPopup("#deleteMessagePop");
	var htmlStr = '<div class="follow-center">';
	htmlStr += '	<div class="follow-text">Do you wish to Delete this</div>';
	htmlStr += '	<div class="follow-buttons"><yesLink class="confirmDeleteMessage" id="'+msgid+'~'+direction+'~'+MC+'"><img class="hover-button" src="assets/images/btn-yes.png" /></yesLink> <noLink onclick="disablePopup()"><img class="hover-button" src="assets/images/btn-no.png" /></noLink></div>';
	htmlStr += '</div>';
	htmlStr += '<div class="cleared"></div>';
	$('#deleteMessagePopContent').html(htmlStr);
	hoverImage('.hover-button');

}
function deletePost(postType, post_id) {
	centerPopup("#deleteMessagePop");
	loadPopup("#deleteMessagePop");
	var htmlStr = '<div class="follow-center">';
	htmlStr += '	<div class="follow-text">Do you wish to Delete this</div>';
	var innerStr = "'" + postType + "', '" + post_id + "'";
	htmlStr += '	<div class="follow-buttons"><yesLink onclick="confPostDelete(' + innerStr + ')" class="" id="'+postType+'~'+post_id+'"><img class="hover-button" src="assets/images/btn-yes.png" /></yesLink> <noLink onclick="disablePopup()"><img class="hover-button" src="assets/images/btn-no.png" /></noLink></div>';
	htmlStr += '</div>';
	htmlStr += '<div class="cleared"></div>';
	$('#deleteMessagePopContent').html(htmlStr);
	hoverImage('.hover-button');

}

function confPostDelete(postType, post_id){
	postDeleteFunction = function(data1) {
		disablePopup();
		if($("#readFollowed").hasClass("active")) {
			fetchContent('#readCollect', 0, 'readFollowed');							
		}
	}
	$.ajax({
		type: "POST",
		url: "services/ajaxActions.php",
		data: {
			'function': 'deletePost',
			type: postType,
			id: post_id
		},
		success: postDeleteFunction
	});
}
function confirmPostDelete(dataString){
	dataArray = dataString.split('~');
	var msgid = dataArray[0];
	var direction = dataArray[1];
	var MC = dataArray[2];
	if (MC == '1'){
		postDeleteFunction = function(data1) {
			var selectedMessageTab = $('#messages-navigation').find('.active').attr('id');
			fetchContent('#messages-list', 0, selectedMessageTab);							
		}
	}else{
		postDeleteFunction = function(data1) {
			if($("#messages_incoming").hasClass("active_tab")) {
				fetchContent('.messages_sub', 0, 'incomingMessages');							
			} else {
				fetchContent('.messages_sub', 0, 'outgoingMessages');
			}
		}
	}
	$.ajax({
		type: "POST",
		url: "services/ajaxActions.php",
		data: {
			'function': 'deleteMessage',
			msg_id: msgid,
			direction: direction
		},
		success: postDeleteFunction
	});
}

function confirmMessageDelet(dataString){
	dataArray = dataString.split('~');
	var msgid = dataArray[0];
	var direction = dataArray[1];
	var MC = dataArray[2];
	if (MC == '1'){
		postDeleteFunction = function(data1) {
			var selectedMessageTab = $('#messages-navigation').find('.active').attr('id');
			fetchContent('#messages-list', 0, selectedMessageTab);							
		}
	}else{
		postDeleteFunction = function(data1) {
			if($("#messages_incoming").hasClass("active_tab")) {
				fetchContent('.messages_sub', 0, 'incomingMessages');							
			} else {
				fetchContent('.messages_sub', 0, 'outgoingMessages');
			}
		}
	}
	$.ajax({
		type: "POST",
		url: "services/ajaxActions.php",
		data: {
			'function': 'deleteMessage',
			msg_id: msgid,
			direction: direction
		},
		success: postDeleteFunction
	});
}
function openMessages() {
	fetchContent('#write', 0, 'message');
	fetchContent('.messages_sub', 0, 'incomingMessages');
}
function splitImage(image){
	var imageExtSplit = $(image).attr('src').split('.');
	var imageType = imageExtSplit[0].split('-');
	var imageBase = imageType[0]+'-'+imageType[1];
	return imageBase;
}
function hoverImage(imageLoc){
	$(imageLoc).hover(function() {
		$(this).attr('src', splitImage(this)+'-hover.png');
	}, function() {
		$(this).attr('src', splitImage(this)+'.png');
	});
}
function scrollAreaWidth(){
	slideCount = $('.scrollable .items .offerSlide').size();
	SlideWidth = $('.scrollable .items .offerSlide').width();
	$('.scrollable .items').width(slideCount * SlideWidth);
}

function equalHeight(group) {
    tallest = 0;
    group.each(function() {
        thisHeight = $(this).height();
        if(thisHeight > tallest) {
            tallest = thisHeight;
        }
    });
    group.height(tallest);
}

function boxFix(box){
	var contentWidth = $(box + ' .box-middle-content').width();
	var contentHeight = $(box + ' .box-middle-content').height();
	var boxWidth = contentWidth + 28;
	var hdrFtrWidth = contentWidth - 40;
	$(box).css('min-width', boxWidth);
	$(box + ' .box-middle-left, ' + box + ' .box-middle-right').height(contentHeight);
	$(box + ' .box-top-middle, ' + box + ' .box-bottom-middle').width(hdrFtrWidth);
}

function viewerWidthFix(){
	var container = $('#site-container');
	var columnHolder = $('.column-holder');
	var siteColumn = $('.column-box');
	var columnCount = $('.column-box').size();
	var windowWidth = $(window).width();
	var totalColumnWidth = 0;
	var columnWidth = new Array();
	var marginOffset = 0;
	var resizeWidth = 1380;
	var offerCSS;
	var col0CSS = {
		clear: 'both'
	};
	var col1CSS = {
		'float': 'left',
		margin: '0px -10px 0px 0px'
	}
	var col2CSS = {
		'float': 'left',
	}
	var col3CSS = {
		'float': 'right'
	}
	var col4CSS = {
		'float': 'left',
		margin: '-28px 0px 0px 0px'
	}
	var col5CSS = {
		margin: '-28px 0px 0px 0px',
	}
	var col6CSS = {
		margin: '-40px 0px 0px 0px'
	}

	if(getFileName() == 'landing.php'){
		columnWidth = [1247,830,419];
		if(columnWidth[0] <= windowWidth){
			columnHolder.width(columnWidth[0]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col1CSS);
			siteColumn.eq(2).css(col2CSS);
		}else if(columnWidth[1] <= windowWidth){
			columnHolder.width(columnWidth[1]);
			siteColumn.eq(0).css(col2CSS);
			siteColumn.eq(1).css(col3CSS);
			siteColumn.eq(2).css(col4CSS);
		}else if(columnWidth[2] <= windowWidth){
			columnHolder.width(columnWidth[2]);
			siteColumn.eq(0).css(col0CSS);
			siteColumn.eq(1).css(col5CSS);
			siteColumn.eq(2).css(col5CSS);
		}
	}else if(getFileName() == 'messages.php'){
		columnWidth = [995,505];
		if(columnWidth[0] <= windowWidth){
			columnHolder.width(columnWidth[0]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col2CSS);
		}else if(columnWidth[1] <= windowWidth){
			columnHolder.width(columnWidth[1]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col6CSS);
		}
	}else if(getFileName() == 'feeds.php'){
		columnWidth = [1379,969,570];
		if(columnWidth[0] <= windowWidth){
			columnHolder.width(columnWidth[0]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col1CSS);
			siteColumn.eq(2).css(col2CSS);
		}else if(columnWidth[1] <= windowWidth){
			columnHolder.width(columnWidth[1]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col2CSS);
			siteColumn.eq(2).css(col5CSS);
		}else if(columnWidth[2] <= windowWidth){
			columnHolder.width(columnWidth[2]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col5CSS);
			siteColumn.eq(2).css(col5CSS);
		}
	}else if(getFileName() == 'recs.php'){
		columnWidth = [1379,969,570];
		if(columnWidth[0] <= windowWidth){
			columnHolder.width(columnWidth[0]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col1CSS);
			siteColumn.eq(2).css(col2CSS);
		}else if(columnWidth[1] <= windowWidth){
			columnHolder.width(columnWidth[1]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col2CSS);
			siteColumn.eq(2).css(col5CSS);
		}else if(columnWidth[2] <= windowWidth){
			columnHolder.width(columnWidth[2]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col5CSS);
			siteColumn.eq(2).css(col5CSS);
		}
	}else if(getFileName() == 'rolo.php'){
		columnWidth = [1380,775];
		columnHolder.width(columnWidth[0]);
		if(columnWidth[0] > windowWidth && columnWidth[1] <= windowWidth){
			$('#rolodex-box .box-middle-content').width(windowWidth-31);
			$('#rolodex-box .rolodex-content').width(windowWidth-31);
		}else if(columnWidth[1] > windowWidth){
			$('#rolodex-box .box-middle-content').width(columnWidth[1]-31);
			$('#rolodex-box .rolodex-content').width(columnWidth[1]-31);			
		}
	}else if(getFileName() == 'settings.php'){
		columnWidth = [1297,868,439];
		if(columnWidth[0] <= windowWidth){
			columnHolder.width(columnWidth[0]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col1CSS);
			siteColumn.eq(2).css(col2CSS);
		}else if(columnWidth[1] <= windowWidth){
			columnHolder.width(columnWidth[1]);
			siteColumn.eq(0).css(col1CSS);
			siteColumn.eq(1).css(col2CSS);
			siteColumn.eq(2).css(col5CSS);
		}else if(columnWidth[2] <= windowWidth){
			columnHolder.width(columnWidth[2]);
			siteColumn.eq(0).css(col2CSS);
			siteColumn.eq(1).css(col5CSS);
			siteColumn.eq(2).css(col5CSS);
		}
	}else if(getFileName() == 'about.php'){
		columnWidth = [400];
		columnHolder.width(columnWidth[0]);
	}else if(getFileName() == 'help.php'){
		columnWidth = [400];
		columnHolder.width(columnWidth[0]);
	}else if(getFileName() == 'legal.php'){
		columnWidth = [400];
		columnHolder.width(columnWidth[0]);
	}

	if(columnCount == 3){
	}else if(columnCount == 2){
	}

	if(windowWidth >= 1380){
		resizeWidth = 1380;
		offerCSS = {
			margin: '0px 0px 0px -10px'
		}
	}else if(windowWidth < 1380 && windowWidth > 768){
		offerCSS = col5CSS;
		resizeWidth = windowWidth;
	}else{
		offerCSS = col5CSS;
		resizeWidth = 768;
	}
	container.css('width', resizeWidth);
	$('#offers-box').css(offerCSS)
	$('#pctBar').width(resizeWidth-28);
}
function textBoxCharLimit(charLimit,charWarning,display,button) {
	$(display).html(charLimit)
	$('textarea').unbind().keyup(function() {
		if(document.activeElement.type === 'textarea'){
			var text = $(this).val();
			var charCount = text.length;
			var remainder = charLimit - charCount;

			if(remainder > charWarning){
				$(display).html(remainder).removeClass('negative');
				$(button).show()
			}else{
				$(display).html(remainder).addClass('negative');
				if(remainder < 0){
					$(button).hide()					
				}else{
					$(button).show()
				}
			}
		}
	});
}
function setMapByMenu(selectedLocation){
	if(selectedLocation != null){
		if(selectedLocation == 'Los Angeles'){
			var cityLocation = new google.maps.LatLng(33.93,-118.40);
			var altitude = 9;
		}
		if(selectedLocation == 'New York'){
			var cityLocation = new google.maps.LatLng(40.77, -73.98);
			var altitude = 9;
		}
		if(selectedLocation == 'Boston'){
			var cityLocation = new google.maps.LatLng(42.37, -71.03);
			var altitude = 11;
		}
		
	}else{
		var cityLocation = new google.maps.LatLng(40.77, -73.98);
	}
	  var myOptions = {
	    zoom: altitude,
	    scrollwheel: false,
	    navigationControl: false,
	    mapTypeControl: false,
	    scaleControl: false,
	    draggable: false,
	    disableDefaultUI: true,
	    center: cityLocation,
	    mapTypeId: google.maps.MapTypeId.ROADMAP
	  };
	  var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);
}

function setMap(){
	var initialLocation;
	var newyork = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
	var browserSupportFlag =  new Boolean();

	function initializeMap() {
	  var myOptions = {
	    zoom: 10,
	    scrollwheel: false,
	    navigationControl: false,
	    mapTypeControl: false,
	    scaleControl: false,
	    draggable: false,
	    disableDefaultUI: true,
	    mapTypeId: google.maps.MapTypeId.ROADMAP
	  };
	  var map = new google.maps.Map(document.getElementById('map-canvas'), myOptions);

	  // Try W3C Geolocation (Preferred)
	  if(navigator.geolocation) {
	    browserSupportFlag = true;
	    navigator.geolocation.getCurrentPosition(function(position) {
	      initialLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
	      map.setCenter(initialLocation);
	    }, function() {
	      handleNoGeolocation(browserSupportFlag);
	    });
	  // Try Google Gears Geolocation
	  } else if (google.gears) {
	    browserSupportFlag = true;
	    var geo = google.gears.factory.create('beta.geolocation');
	    geo.getCurrentPosition(function(position) {
	      initialLocation = new google.maps.LatLng(position.latitude,position.longitude);
	      map.setCenter(initialLocation);
	    }, function() {
	      handleNoGeoLocation(browserSupportFlag);
	    });
	  // Browser doesn't support Geolocation
	  } else {
	    browserSupportFlag = false;
	    handleNoGeolocation(browserSupportFlag);
	  }

	  function handleNoGeolocation(errorFlag) {
	    if (errorFlag == true) {
	      alert("Geolocation service failed.");
	      initialLocation = newyork;
	    } else {
	      alert("Your browser doesn't support geolocation. We've placed you in New York.");
	      initialLocation = newyork;
	    }
	    map.setCenter(initialLocation);
	  }
	}
	initializeMap();
}
function deleteAccountCurrentSession(){
	$.ajax({
	  	url: 'services/ajaxActions.php',
	  	type: 'POST',
	  	dataType: 'html',
	  	data: {
			'function': 'deleteAccount'
		},
	  	success: function(data, textStatus, xhr) {
			if(data == 'deleted'){
				
			}else{
				
			}
			location.href='index.php?da=true'
	  	},
	  	error: function(xhr, textStatus, errorThrown) {
			
	  	}
	});
	
}
function discoverFeedCheck(submittedForm) {
	var discoverType = $('#discoverBox .boxtabsbar').find('.active').attr('id');
	if (submittedForm == 'submit-rec-form' && discoverType == 'grabAllRecsByCategory'){
		discoverCat = $('#recSelectBox select').val();
		fetchContent('#readDiscover', 0, discoverType, discoverCat);
	}
	if (submittedForm == 'submit-trend-form' && discoverType == 'grabAllTrendsByCategory'){
		discoverCat = $('#trendSelectBox select').val();
		fetchContent('#readDiscover', 0, discoverType, discoverCat);
	}
}
function dropDownMenuReskin(menuElement){
	$(menuElement).selectmenu({
		transferClasses: true,
		style: 'dropdown',
		menuWidth: null,
		handleWidth: 26,
		maxHeight: 400,
		icons: null,
		format: null
	});
}
function uploadButtonReskin(button,resultContainer,pageVar, imgClass){
	var ULbutton = $(button), interval;
	var ULbuttonDefaultText = ULbutton.text();
	var resultContainer = $(resultContainer);
	var imageViewer = $(imgClass);
	new AjaxUpload(ULbutton, {
		action: 'upload.php', 
		data: {
			page : pageVar
		},
		onSubmit : function(file, ext){
			if (! (ext && /^(jpg|png|jpeg|gif)$/i.test(ext))){
					resultContainer.html('Invalid file type, please select an image.');
					return false;
			}
			ULbutton.text('Uploading');
			this.disable();

			interval = window.setInterval(function(){
				var text = ULbutton.text();
				if (text.length < 13){
					ULbutton.text(text + '.');
				} else {
					ULbutton.text('Uploading');
				}
			}, 200);
		},
		onComplete: function(file, response){
			ULbutton.text(ULbuttonDefaultText);
			window.clearInterval(interval);
			this.enable();
			resultContainer.html(file + ' Uploaded.');
			imageViewer.html(' '+'<img src="'+response+'"/><input type="hidden" name="image" value="' + response + '"');
		}
	});
	$(button).live('click',function(e){
		e.preventDefault();
	});
}