function add_dream(did,uid,url){
	if(!uid){
		location.href='./?action=sign_in&backUrl='+url;
	}else{

		/*$.get("./chk.php?sp=get_bucket", function(data){
		  jQuery.facebox('<table width="100%" border="0" cellspacing="0" cellpadding="3" align="center"><tr><td width="100">Choose a List:</td><td><select name="bucketid" id="bucketid"><option value="0">My Bucket List </option>'+data+'</select></td></tr><tr><td>&nbsp;</td><td><input type="image" name="imageField" id="imageField" src="images/btn/submit.gif" onclick="add_new_dream('+did+','+uid+');"/></td></tr></table>');
		}); */
		location.href='./?action=create_dream&did='+did;
	}
}

function add_new_dream(did,uid){
           $.ajax({ 
				url: "./chk.php?sp=add_dream",
				data:{did:did,uid:uid,bucketid:$('#bucketid option:selected').val()},
				type:      "post",
				success:   function(rs){
					          if(rs=='1'){
								jQuery.facebox('<div style="height:30px"></div><div style="text-align:center;">Dream Added Successfully.</div><div style="height:30px"></div>');
							  }else{
								jQuery.facebox('<div style="height:30px"></div><div style="text-align:center;">This Dream already in your dream list.</div><div style="height:30px"></div>');
							  }
						   }
			});
}

function add_event(id){
$.ajax({ 
		url: "./chk.php?sp=add_event",
		data:{id:id},
		type:      "post",
		success:   function(rs){
					if(rs!='2'){
						jQuery.facebox('<div style="text-align:center;"><p>&nbsp;</p><p>Added Successfully.</p><p>&nbsp;</p></div>');
					}else{
						jQuery.facebox('<div style="text-align:center;"><p>&nbsp;</p><p>This event already in your event list.</p><p>&nbsp;</p></div>');
					}
				   }
	  });
}

function del_dream(id,style){
	$.ajax({ 
		url: "./chk.php?sp=del_dream",
		data:{id:id},
		type:      "post",
		success:   function(rs){
					if(style=='popup'){
						jQuery.facebox('<div style="text-align:center;"><p>&nbsp;</p><p>Deleted Successfully.</p><p>&nbsp;</p></div>');
					}else{
						location.reload();
					}
				   }
	  });
}

function del_bucket(id, customerid){
	$.ajax({ 
		url: "./chk.php?sp=del_bucket",
		data:{id:id, customerid:customerid},
		type:      "post",
		success:   function(rs){
						location.reload();
				   }
	  });
}

function multSelect( eid ) {
	var map = {}, obj = document.getElementById( eid ), opts = obj.getElementsByTagName('option');

	function setMap() { for (var i = 0; i < obj.options.length; i ++) { map[ i ] = false; } }
	
	obj.onclick = function(){
		var index = this.selectedIndex, opt = obj.options[ index ];
		
		if(map[ index ]) {
			map[ index ] = false;
			opt.selected = false;
		} else {
			for(var key in map) { map[ key ] = false; }
			 
			map[ index ] = true;
			opt.selected = true;
		}
	}
}

