// preload images
var menu_0 = new Image();
menu_0.src = "gfx/menu_up.gif";
    
var menu_1 = new Image();
menu_1.src = "gfx/menu_down.gif";

var arrow_0 = new Image();
arrow_0.src = "gfx/arrow-up.gif";
var arrow_1 = new Image();
arrow_1.src = "gfx/arrow-down.gif";
var arrow_2 = new Image();
arrow_2.src = "gfx/arrow-up-w.gif";
var arrow_3 = new Image();
arrow_3.src = "gfx/arrow-down-w.gif";


/**
 * animates the main heading button rollovers
 */
function mainHeadSel(sel) {
	if (sel==1) document.getElementById('mainHead1').className='mainHeadSel';
	else document.getElementById('mainHead1').className='mainHead';
	if (sel==2) document.getElementById('mainHead2').className='mainHeadSel';
	else document.getElementById('mainHead2').className='mainHead';
	if (sel==3) document.getElementById('mainHead3').className='mainHeadSel';
	else document.getElementById('mainHead3').className='mainHead';		
}



/**
 * capture the 'Enter' key
 */
function isEnter(e){ 
	var characterCode;
	if(e && e.which){ 
		e = e;
		characterCode = e.which;
	}
	else{
		e = event;
		characterCode = e.keyCode;
	}
	if(characterCode == 13){ 
		return true; 
	}
}



/**
 * Relative to absolute using base tag
 * @param url
 */
function to(url) {
    var base = document.getElementsByTagName("base")[0].getAttribute("href");
    document.location.href = base + url;
}

/**
 * Open a popup window
 * @param url
 * @param name
 */
function popup(url, name) {
    var base = document.getElementsByTagName("base")[0].getAttribute("href");
    window.open(base + url, name, 'width=650,height=545,scrollbars=yes,resizable=yes').focus();
}

var facebook_init = false;

/**
 * Save a Facebook Like
 */
function storelike(type,id,user) {
 	var desturl = "ajax/thumbs!"+(user==1?"rate":"FBlike")+".mygeni";
 	$.ajax({
 		url: desturl,
        data: "eid="+id+"&etype="+type+"&rating=1",
        dataType: "script",
        cache: false,
        success: function(html) {
        }
    });
} 

/**
 * Save a Facebook Share
 */
function storeshare(shortcode) {
 	$.ajax({
 		url: "ajax/thumbs!storeshare.mygeni",
        data: "etype="+shortcode,
        dataType: "script",
        cache: false,
        success: function(html) {
        }
    });
} 

/**
 * Send a feed into FaceBook with new API
 *
 */
function fbfeed4(title,source,url,desc,type,iimage,shortcode){
	if (facebook_init) {
  		if (iimage.length>0) {
	    	FB.ui(
			{
				method: 'feed',
			    name: title,
			    link: url,
			    picture: iimage,
			    caption: '{*actor*} discovered this ' + type + source + ' on Mygeni.',
			    description: desc
			}, function(response) {
     			if (response && response.post_id) { storeshare(shortcode); }
     			else {}
   			}
			);	
  		}
  		else {
	        FB.ui(
			{
				method: 'feed',
			    name: title,
			    link: url,
			    caption: '{*actor*} discovered this ' + type + source + ' on Mygeni.',
			    description: desc
			}, function(response) {
     			if (response && response.post_id) { storeshare(shortcode); }
     			else {}
   			}
			);	
		}
  	}
}


/**
 * Send a feed into FaceBook from discovering it
 *
 */
function fbfeed33(title,source,url,desc,type,iimage,shortcode){
	if (iimage.length>0) {
		var obj = {
	    	method: 'feed',
	        link: url,
	        picture: iimage,
	        name: title,
	        caption: 'Recent '+type+' posted on Mygeni.',
	        description: desc
	     };
	}
	else {
		var obj = {
		    method: 'feed',
		    link: url,
		    name: title,
		    caption: 'Recent '+type+' posted on Mygeni.',
		    description: desc
		};
	}
	
    function callback(response) {
    	if (response) storeshare(shortcode);            	
    }
	
	FB.ui(obj, callback);
}
function fbfeed3(title,source,url,desc,type,iimage,shortcode){
		window.fbAsyncInit = function() {
			FB.init({ appId: '91766323656',
				status: true,
				cookie: true,
				xfbml: true,
				oauth: true});
			function updateButton(response) {
				if (response.authResponse) {
					//user is already logged in and connected
					fbfeed33(title,source,url,desc,type,iimage,shortcode);
				} 
				else {
					//user is not connected to your app or logged out
					FB.login(function(response) {
						if (response.authResponse) {
							fbfeed33(title,source,url,desc,type,iimage,shortcode);
						} 
						else {
							//user cancelled login or did not grant authorization
						}
					}, {scope:'publish_stream'});
				}
			}

			// run once with current status and whenever the status changes
			FB.getLoginStatus(updateButton);
		};

		(function() {
			var e = document.createElement('script'); e.async = true;
			e.src = document.location.protocol
			+ '//connect.facebook.net/en_US/all.js';
			document.getElementById('fb-root').appendChild(e);
		}());
}



/**
 * Send a feed into FaceBook after creating it
 *
 */
function fbfeed55(title,target,url,desc,sex,type,iimage,comment){
	if (iimage.length>0) {
		var obj = {
	    	method: 'feed',
	        link: url,
	        picture: iimage,
	        name: title,
	        caption: 'Recent '+type+' posted into '+target+' on Mygeni.',
	        description: desc
	     };
	}
	else {
		var obj = {
		    method: 'feed',
		    link: url,
		    name: title,
		    caption: 'Recent '+type+' posted into '+target+' on Mygeni.',
		    description: desc
		};
	}
	
    function callback(response) {
    }
	
	FB.ui(obj, callback);
}
function fbfeed(title,target,url,desc,sex,type,iimage,comment){
	window.fbAsyncInit = function() {
		FB.init({ appId: '91766323656',
			status: true,
			cookie: true,
			xfbml: true,
			oauth: true});
		function updateButton(response) {
			if (response.authResponse) {
				//user is already logged in and connected
				fbfeed55(title,target,url,desc,sex,type,iimage,comment);
			} 
			else {
				//user is not connected to your app or logged out
				FB.login(function(response) {
					if (response.authResponse) {
						fbfeed55(title,target,url,desc,sex,type,iimage,comment);
					} 
					else {
						//user cancelled login or did not grant authorization
					}
				}, {scope:'publish_stream'});
			}
		}

		// run once with current status and whenever the status changes
		FB.getLoginStatus(updateButton);
	};

	(function() {
		var e = document.createElement('script'); e.async = true;
		e.src = document.location.protocol
		+ '//connect.facebook.net/en_US/all.js';
		document.getElementById('fb-root').appendChild(e);
	}());	
}

/**
 * Blob of functions for sending a post to a FaceBook Page
 *
 */
var pagesSent = 0;
function fbfeed22(title,url,desc,type,iimage,comment,target){
	var targets = new Array();
	targets = target.split(',');
	pagesSent = 0;
	for (var t = 0; t<targets.length; t++) {
		if (iimage.length>0) {
			var obj = {
		    	method: 'feed',
		        link: url,
		        picture: iimage,
		        name: title,
		        caption: 'Recent '+type+' posted on Mygeni.',
		        description: desc,
		        to: targets[t],
		        from: targets[t]
		     };
		}
		else {
			var obj = {
			    method: 'feed',
			    link: url,
			    name: title,
			    caption: 'Recent '+type+' posted on Mygeni.',
			    description: desc,
			    to: targets[t],
			    from: targets[t]
			};
		}
	
	    function callback(response) {
	    	if (response && response.post_id) pagesSent++;
	        document.getElementById('FBPageTargetStatus').innerHTML="Successfully posted on " + pagesSent + " FaceBook page" + (pagesSent!=1 ? "s":"") + ".";            	
	    }
	
		FB.ui(obj, callback);
	}
}
function fbfeed2(title,url,desc,type,iimage,comment,target){
		window.fbAsyncInit = function() {
			FB.init({ appId: '91766323656',
				status: true,
				cookie: true,
				xfbml: true,
				oauth: true});
			function updateButton(response) {
				if (response.authResponse) {
					//user is already logged in and connected
					fbfeed22(title,url,desc,type,iimage,comment,target);
				} 
				else {
					//user is not connected to your app or logged out
					FB.login(function(response) {
						if (response.authResponse) {
							fbfeed22(title,url,desc,type,iimage,comment,target);
						} 
						else {
							//user cancelled login or did not grant authorization
						}
					}, {scope:'publish_stream'});
				}
			}

			// run once with current status and whenever the status changes
			FB.getLoginStatus(updateButton);
		};

		(function() {
			var e = document.createElement('script'); e.async = true;
			e.src = document.location.protocol
			+ '//connect.facebook.net/en_US/all.js';
			document.getElementById('fb-root').appendChild(e);
		}());
}

function onConnected() {

	showDiv('FBisconnected',true);
	showDiv('FBstatus',false);

	var uid = null;
	FB.api(
	  {
		method: 'fql.query',
		query: 'SELECT uid,name FROM user WHERE uid=me()'
	  },
	  function(response) {
		uid = response[0].uid;
		document.getElementById('name').innerHTML="<b>"+response[0].name+"</b>";

		var pids = "";
		var str = "";

		FB.api(
		{
			method: 'fql.query',
			query: 'SELECT page_id FROM page_admin WHERE uid=me()'
		},
		function(rows) {
			var n = 0;
			while (rows!=null && rows[n]!=null) {
				if (pids!="") pids += ",";
				pids += rows[n].page_id;
		   		n++;
		   	}
		   	if (pids!="") {



				FB.api(
				{
					method: 'fql.query',
					query: "SELECT page_id,name,fan_count FROM page WHERE page_id IN (" + pids + ")"
				},
				function(rows) {
					var n = 0;
					while (rows!=null && rows[n]!=null) {
						str += "<div class=\"summary_facebook\"><div class=\"right\">target here &nbsp;<input type=\"checkbox\" onclick=\"if (this.checked) { FBtarget('1',"+rows[n].page_id+"); } else { FBtarget('0',"+rows[n].page_id+"); }\"></div><b>" + rows[n].name + "</b>";
						if (rows[n].fan_count!='') {
							str += " - " + rows[n].fan_count + " fan";
							if (rows[n].fan_count!='1') str += "s";
						}
						str += "</div>"
						n++;
			    	}
			    	document.getElementById('fbtargetlist').innerHTML='Please note that only <b>published pages made public</b> can be targeted.<br /><br />'+str;
			    	document.getElementById('fbpagesfound').innerHTML="("+n+")";
			    	showDiv("getp",false);
				});


		   	}
		   	else {
					document.getElementById('fbtargetlist').innerHTML="You are not an admin of any FaceBook Pages.";
			}
		});
	  });
}


function getPages(){
	 FB.login(function(response) {
	   if (response.authResponse) {
			onConnected();
	   }
	 }, {scope: 'manage_pages'});
}

function soConnect(){
	  window.fbAsyncInit = function() {
	    FB.init({
	      appId      : '91766323656', // App ID
	      channelURL : 'www.mygeni.org/channel.jsp', // Channel File
	      status     : true, // check login status
	      cookie     : true, // enable cookies to allow the server to access the session
	      oauth      : true, // enable OAuth 2.0
	      xfbml      : true  // parse XFBML
	    });

	    // Additional initialization code here
	    FB.getLoginStatus(function(response) {
		  if (response.authResponse) {
		    // logged in and connected user, someone you know
			showDiv("getp",true);
		  } else {
		    // no user session available, someone you dont know
		    onNotConnected();
		  }
	});
	  };

	  // Load the SDK Asynchronously
	  (function(d){
	     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
	     js = d.createElement('script'); js.id = id; js.async = true;
	     js.src = "//connect.facebook.net/en_US/all.js";
	     d.getElementsByTagName('head')[0].appendChild(js);
	  }(document));
}

function onNotConnected() {
	showDiv('FBisconnected',0);
	showDiv('FBstatus',0);
}

function checkFBtargets(formname){
	var cool = false;
	var fbptargets = document.getElementById('FBtargets').value;
	if (fbptargets.length>0) {
		 FB.ensureInit ( function () {
		 FB.Facebook.apiClient.fql_query("SELECT uid,publish_stream FROM permissions WHERE uid IN (" + fbptargets + ")",
			function(rows) {
				var n = 0;
				fbptargets+=",";
				while (rows!=null && rows[n]!=null) {
					if (rows[n].publish_stream==1) {
						fbptargets = fbptargets.replace(rows[n].uid+",","");
					}
					n++;
		    	}
		    	fbptargets = fbptargets.substring(0,fbptargets.length-1);
		    	if (fbptargets!="") {
		    		FB.Connect.showPermissionDialog("publish_stream",function(perms) { if (perms) { aggregate(); document.getElementById(formname).submit(); } },true,[fbptargets]);
		    	}
	     		else {	aggregate();
	     				document.getElementById(formname).submit();
	     		}
		}) });
	}
	else cool = true;
	return cool;
}



/**
 * General show / hide
 */
function showDiv(item,show) {
	item = document.getElementById(item);
	if (item!=null) {
		item.style.visibility= (show==1 ? 'visible' : 'hidden');
		item.style.display= (show==1 ? 'block' : 'none');
	}
}


/**
 * Clears the interest rows when targeting content
 */
function clearAll(total){
for (h=1; h<=total; h++){
	document.getElementById('intimacy'+h).style.visibility='hidden';
	document.getElementById('intname'+h).style.visibility='visible';
	document.getElementById('inttab'+h).style.visibility='visible';
}}


/**
 * Swaps the login password field with a text version
 */
    function switchto(q){
        if (q){
            document.getElementById('password').style.display="none";
            document.getElementById('passwordd').style.display="inline";
            document.getElementById('passwordd').focus();
        } else {
            document.getElementById('passwordd').style.display="none";
            document.getElementById('password').style.display="inline";
        }
   }


/**
 * Open a popup window in an iframe
 * @param url
 *
 */
function popdialog(url, height) {
    if (url != 0) {
        var widt = 0;
        var heig = 0;
        if (window.innerWidth) {//if browser supports window.innerWidth
            widt = window.innerWidth;
            heig = window.innerHeight;
        }
        else if (document.all) {//else if browser supports document.all (IE 4+)
            widt = document.body.clientWidth;
            heig = document.body.clientHeight;
        }
        var iebody = (document.compatMode && document.compatMode != "BackCompat") ? document.documentElement : document.body
        var offsetY = document.all ? iebody.scrollTop : pageYOffset;
        poppy = document.getElementById("popdialog");
        poppy.style.width = '530px';
        poppy.style.height = (height + 30) + 'px';
        poppy.style.left = ((widt - 530) / 2) + 'px';
        document.getElementById("innerpop").style.height = (height + 10) + 'px';
        document.getElementById("shadowpop").style.height = (height + 22) + 'px';
        //alert("height = "+height+" heig= "+heig+" offset="+offsetY);
        poppy.style.top = ((heig - height) / 2 + offsetY) + 'px';
        document.getElementById("popup_iframe").src = encodeURI(url);
        document.getElementById("popup_iframe").style.height = height + 'px';
        poppy.style.display = '';
        poppy.style.visibility = 'visible';
    }
    else {
        poppy = parent.document.getElementById("popdialog");
        poppy.style.width = '0px';
        poppy.style.height = '0px';
        parent.document.getElementById("popup_iframe").src = '';
        poppy.style.display = 'none';
        poppy.style.visibility = 'hidden';
    }
}


/**
 * Collapse/expand menu items
 */
function show(source) {

    source = document.getElementById(source);

    // all uls in this menu item
    var uls = source.getElementsByTagName("ul");

    if (uls.length == 0)
        return;

    for (var i = 0; i < uls.length; i++) {
        // show/hide submenus
        uls[i].style.display =
        uls[i].style.display == "block" ?
        "none" : "block";
    }

    var imgs = source.getElementsByTagName("img");

    // change arrow image
    imgs[0].src = uls[0].style.display == "block" ? menu_1.src : menu_0.src;

}

/**
 * Collapse/expand folding box
 * @param source
 */
function box(source) {

    // all images in control div (=source)
    var images = source.getElementsByTagName("img");

    // all divs in control divs parent.
    var divs = source.parentNode.getElementsByTagName("div");

    // content div is 2nd child of parent.
    var content = divs[1];

    // arrow image is 1st image in control_div (=source)
    var arrow = images[0];

    // show/hide box content
    content.style.display =
    content.style.display == "block" ?
    "none" : "block";

    // change arrow image
    if (arrow!=null) {
    	arrow.src =
    	content.style.display == "block" ?
    	arrow_1.src : arrow_0.src;
    }
}

function box2(source) {

    // all images in control div (=source)
    var images = source.getElementsByTagName("img");

    // all divs in control divs parent.
    var divs = source.parentNode.getElementsByTagName("div");

    // content div is 2nd child of parent.
    var content = divs[3];

    // arrow image is 1st image in control_div (=source)
    var arrow = images[0];

    // show/hide box content
    content.style.display =
    content.style.display == "block" ?
    "none" : "block";

    // change arrow image
    arrow.src =
    content.style.display == "block" ?
    arrow_3.src : arrow_2.src;
}



/**
 * Swap image source using preloaded image reference
 *
 * @param source image
 * @param target image
 */
function swap(source, target) {
    source.src = target.src;
}

/**
 * Navi cube functions
 */
 
function navselect(selected) {
	for (h = 1; h <= number; h++) {
    	if (selected==0) selected=current;
    	if (h==selected) {
    		if (h==uncat) document.getElementById('intname'+h).style.backgroundColor='#C8C8C8';
    		else document.getElementById('intname'+h).style.backgroundColor='#E0EFF6';
    	}
    	else { 
    		if (h==uncat) document.getElementById('intname'+h).style.backgroundColor='#D9D9D9';
    		else document.getElementById('intname'+h).style.backgroundColor='white';
    	}	 
	}
} 

/**
 * Club nav functions
 */
 
function clubselect(selected) {
	for (h = 1; h <= number; h++) {
    	if (selected==0) selected=current;
    	if (h==selected) {
    		if (h<firstmember) document.getElementById('clubb'+h).style.backgroundColor='#E1BCCC';
    		else document.getElementById('clubb'+h).style.backgroundColor='#CDCDCD';
    	}
    	else { 
    		document.getElementById('clubb'+h).style.backgroundColor='white';
    	}	 
	}
} 	


/**
 * Club page nav
 */
function pageselect(selected) {
	for (var h = 1; h <= numpages; h++) {
    	var colr = '#daf3ea';
    	var getcolr = getStyle('tinypage','backgroundColor');
    	if (getcolr) colr=getcolr;
    	if (selected==0) selected=currentpage;
    	if (h==selected) document.getElementById('ppage'+h).style.backgroundColor=colr;
    	else document.getElementById('ppage'+h).style.backgroundColor='white';
	}
} 	

/**
 * Get style property
 */
function getStyle(el,prop){
	var prop2="";
	var x = document.getElementById(el);
	for (h=0;h<prop.length;h++){
		var t = prop.charAt(h);
		if (t.toUpperCase()==t) prop2=prop2+"-"+t.toLowerCase();
		else prop2=prop2+t;
	}
	
	if (x.currentStyle) var y = x.currentStyle[prop];
	else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(prop);
	if (!y) {
		if (x.currentStyle) var y = x.currentStyle[prop2];
		else if (window.getComputedStyle) var y = document.defaultView.getComputedStyle(x,null).getPropertyValue(prop2);
	}
	
	return y;
}


/**
 * General expand div function
 */
function expanddiv(source,target,firsttext,secondtext,map) {
	if (document.getElementById(target).style.visibility!='visible'){
		document.getElementById(target).style.visibility='visible';
		document.getElementById(target).style.display='block';
		document.getElementById(source).innerHTML=secondtext;
	}
	else {
		document.getElementById(target).style.visibility='hidden';
		document.getElementById(target).style.display='none';
		document.getElementById(source).innerHTML=firsttext;
	}	
	if (map==1) {
		if (document.getElementById('map_canvas_hidden').style.display=='block') load();
		else GUnload();
	}
}

/**
 * Proposal nav functions
 */
 
function propselect(selected) {
	for (h = 1; h <= pnumber; h++) {
    	if (selected==0) selected=pcurrent;
    	if (h==selected) {
    		if (h<firstactive) document.getElementById('propp'+h).style.backgroundColor='#CDCDCD';
    		else document.getElementById('propp'+h).style.backgroundColor='#D3EEB5';
    	}
    	else { 
    		document.getElementById('propp'+h).style.backgroundColor='white';
    	}	 
	}
} 	


/**
 * Tour functions
 */

var currently=0;
var destination=0;
var scrollprog=0;

function setDest(inc){
	if (inc!=currently) {
		destination=inc;
		prog=1;	
		if (currently==0) var button=document.getElementById('con').style;
		if (currently==-660) var button=document.getElementById('rel').style;
		if (currently==-1320) var button=document.getElementById('int').style;
		if (currently==-1980) var button=document.getElementById('cre').style;
		if (currently==-2640) var button=document.getElementById('ext').style;
		button.backgroundImage = '';
		button.color = '#FFF';
		setTimeout("scrollit();",1);
	}
}

function scrollit(){
	scrollprog++;
	if (destination<currently) var posleft = currently-(currently-destination)*scrollprog/20;
	else var posleft = currently+(destination-currently)*scrollprog/20;
	document.getElementById('container').style.left=posleft+'px';
	if (scrollprog==20) {
		scrollprog=0;
		currently=destination;
		destination=0;
		if (currently==0) var button=document.getElementById('con').style;
		if (currently==-660) var button=document.getElementById('rel').style;
		if (currently==-1320) var button=document.getElementById('int').style;
		if (currently==-1980) var button=document.getElementById('cre').style;
		if (currently==-2640) var button=document.getElementById('ext').style;
		button.backgroundImage = 'url(gfx/tour_nav_active.gif)';
		button.backgroundRepeat = 'no-repeat';
		button.backgroundPosition = 'center 6px';
		button.color = '#999';
	}
	else {
		setTimeout("scrollit();",1);
	}
}


/**
 * Compiles the targets array for new content items
 */
function targetit(inti,ig,typ) {
	if (typ=='i') {
		if (inti!='0') {
			interest_targets.push(ig); }
		else { 
			for (var h in interest_targets) { if (interest_targets[h]==ig) interest_targets.splice(h,1); }
			}
	}
	if (typ=='pl') {
		if (inti!='0') {
			public_page_targets.push(ig); }
		else { 
			for (var h in public_page_targets) { if (public_page_targets[h]==ig) public_page_targets.splice(h,1); }
			}
	}
	if (typ=='pr') {
		if (inti!='0') {
			private_page_targets.push(ig); }
		else { 
			for (var h in private_page_targets) { if (private_page_targets[h]==ig) private_page_targets.splice(h,1); }
			}
	}	
	if (typ=='r') {
		if (inti!='0') {
			proposal_targets.push(ig); }
		else {
			for (var h in proposal_targets) { if (proposal_targets[h]==ig) proposal_targets.splice(h,1); } 
			}
	}	
	
	if (public_page_targets.length>0 || (intimacy==0 && (interest_targets.length>0 || public_page_targets.length>0 || proposal_targets.length>0))) {	
					document.getElementById('toTweet').style.visibility = 'visible';
					document.getElementById('toTweet').style.display = 'block'; }
	else {			document.getElementById('toTweet').style.visibility = 'hidden';
					document.getElementById('toTweet').style.display = 'none'; }
}

/**
 * Intimacy slider during targeting
 */
function setIntimacy(x) {
	var w = 0; var col ='';
	if (x==0) { w = 242; col = '#EFEFEF'; }
	if (x==2) { w = 162; col = '#91A7AF'; }
	if (x==3) { w = 79; col = '#F8E077'; }
	if (x==4) { w = 0; col = '#EE585F'; }
	document.getElementById('scale').style.width=w+'px';
	document.getElementById('scale').style.backgroundColor=col;
	document.getElementById('bob').style.left=(7+w)+'px';
	intimacy = x;
	if (public_page_targets.length>0 || (intimacy==0 && (interest_targets.length>0 || public_page_targets.length>0 || proposal_targets.length>0))) {	
					document.getElementById('toTweet').style.visibility = 'visible';
					document.getElementById('toTweet').style.display = 'block'; }
	else {			document.getElementById('toTweet').style.visibility = 'hidden';
					document.getElementById('toTweet').style.display = 'none'; }	
}

/**
 * Makes a string from the targeted entities for new content items
 */
function aggregate(){
	var targetz='';
	
	if ((private_page_targets.length > 0 || proposal_targets.length > 0) && (interest_targets.length == 0 && public_page_targets.length == 0) && intimacy == 0) intimacy = 1;
	
	for (var h in public_page_targets) {
		targetz+=public_page_targets[h]+'-p,';
	}
	for (var h in private_page_targets) {
		targetz+=private_page_targets[h]+'-p,';
	}
	for (var h in interest_targets) {
		targetz+=interest_targets[h]+'-i,';
	}
	for (var h in proposal_targets) {
		targetz+=proposal_targets[h]+'-r,';
	}
			
	if (targetz != '') document.getElementById('targets').value = intimacy + targetz;
}

/**
 * Assembles FaceBook page targets list
 */
function FBtarget(yes,id){
	var t = document.getElementById('FBtargets').value;
	if (yes==1) {
		if (t.length>0) t += "," + id;
		else t = id;
	}
	else {
		t += ",";
		t = t.replace(id+",","");
		t = t.substring(0,t.length-1);
	}
	document.getElementById('FBtargets').value=t;
}


/**
 * Hides the new user help bubbles
 */
function hideHelp(helpid) {
            $.ajax({
                url: "ajax/help.mygeni",
                data: "helpid="+helpid,
                dataType: "script",
                cache: false,
                success: function(html) {
                }
            });
}   


/**
 * Animates the star ratings input field
 */
function pink(star,special){
	if ((set==0 && special==0) || (set==1 && special==1)) {
		allwhite(1);
		for (i = 0; i <= 9; i++) {
			if (i%2==0) {
				if (star>i) document.getElementById('star'+(i+1)).src=leftpink.src;
			}
			if (i%2==1) {
				if (star>i) document.getElementById('star'+(i+1)).src=rightpink.src;
			}
		}
	}
}
function allwhite(special){
	if (set==0 || (set==1 && special==1)) {
		for (i = 1; i <= 10; i++) {
			if (i%2==1) document.getElementById('star'+i).src=leftwhite.src;
			if (i%2==0) document.getElementById('star'+i).src=rightwhite.src;
		}
	}
}


/**
 * Toggles the registration screen
 */
var reglogOpen = false;
var regProg = -510;
function toggleReg(){
	reglogOpen=!reglogOpen;
	document.getElementById('openreg').style.display=(reglogOpen?'none':'block');
	document.getElementById('closereg').style.display=(!reglogOpen?'none':'block');
	if (regProg==-510 || regProg==0) setTimeout("moveReg()",8);
}
function moveReg(){
	regProg+=(reglogOpen?51:-51);
	document.getElementById('reglog').style.top=regProg+'px';
	if (regProg>-510 && regProg<0) setTimeout("moveReg()",8);
} 

